Repository navigation
Saplings 2: Engine capabilities - #3813
DellieDelta wants to merge 42 commits into
Conversation
6e9a828 to
9b47a38
Compare
5cf0a11 to
1475272
Compare
| } | ||
|
|
||
| fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: ?Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64) void { | ||
| pub fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: ?Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64) void { |
There was a problem hiding this comment.
Related to the above comment: This should be a separate function for calling it outside of generation.
e.g. outside of generation, the chunk parameter is unused.
There was a problem hiding this comment.
I split it into two functions but there's some code repetition that I had a hard time combining. The problem is that almost all variables defined at the start are needed again at the end, and only the function call in the middle that places the blueprint is different. Maybe you have an idea on how to approach this?
|
The Reason my saplings PR never got finished, was because of perfomance Issues. on a flat world, you can select a large rectangle with the wand, and fill it with saplings all at once and then try running around, after a while you will not be able to pick up/drop items anymore etc. |
|
I talked with Quantum yesterday about the We both thought that having an attribute like But at that point you're thinking in time anyway, so I think I was a little worried about ambiguity, because the attribute name doesn't tell you that it's pinned to the default tickspeed. But at the same time, there's already the expectation that changing the tickspeed makes plants grow faster or slower, so I think it's fine. And it's easy enough to figure out by looking at the code |
From what I saw the issue was with performance spikes, but that got fixed throughout the PR. I tested it, but block dropping/picking up is only a little slower if you make a very big sapling field with a selection wand. So should be fine |
|
I implemented what I talked about in #3813 (comment) |
| }; | ||
|
|
||
| pub fn paste(self: Blueprint, pos: Vec3i, flags: PasteFlags) void { | ||
| pub fn paste(self: Blueprint, pos: Vec3i, flags: PasteFlags, mode: PasteMode) void { |
There was a problem hiding this comment.
Why not merge the PasteMode into the PasteFlags struct?
If you make it a packed struct, you can also keep the switch case and elevate the entire struct to comptime.
Also in my opinion the name Flags for option structs is kind of misleading, as flags usually only allow bool parameters.
| const childRotation = blueprintRotation.getChildRotation(seed, child.rotation, childBlock.direction()); | ||
| _placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), childRotation, worldPos, seed); | ||
| } | ||
| } |
There was a problem hiding this comment.
Instead of duplicating this function, could this also be a comptime parameter?
|
|
||
| result.spawnChancePerBlockTick = averageSecondsPerBlockTick/averageSpawnSeconds; | ||
| if (result.spawnChancePerBlockTick > 1) { | ||
| std.log.err("spawnChancePerBlockTick is over 100% for spawn_structure event. Increase averageSpawnSeconds to be at least {}", .{averageSecondsPerBlockTick}); |
There was a problem hiding this comment.
That you calculate a chance here is an implementation detail that the addon creator shouldn't need to know about, please reword the error without it.
Instead maybe mention that it's bound by the default tick speed.
| }; | ||
|
|
||
| const tickedBlocksInChunkPerSecond = server.world_zig.defaultTickSpeed*server.updatesPerSec; | ||
| const blocksInChunk: f32 = 32*32*32; |
There was a problem hiding this comment.
Please use the proper constant chunk.chunkVolume here as well.
| pub fn finishBlockCallbacks(zonElements: Assets.ZonHashMap) void { | ||
| var i: u16 = 0; | ||
| while (i < size) : (i += 1) { | ||
| registerCallbacks(i, zonElements.get(_id[i]) orelse continue); |
There was a problem hiding this comment.
This is now called twice, once in finishBlocks, once here. Looks like you messed up the rebase after 91fc0e0

Continuation of #2585, thanks @tillpp for your good work!
The goal of this PR is only to give the engine the capabilities for saplings. Discussion is still open in #546, so I'll leave the implementation for a follow-up PR. Before merging I'll also remove the sapling item