Cubyz icon indicating copy to clipboard operation
Cubyz copied to clipboard

Merge ServerChunk.updateBlockXYZ functions

Open codemob-dev opened this issue 3 weeks ago • 9 comments

Removes some redundant code and should make it easier to add different update modes/conditions in the future. (eg. mergeOrReplace to prevent branches from fully replacing leaves)

codemob-dev avatar Dec 02 '25 15:12 codemob-dev

if ur adding flags, we should have them as a one optional argument at the end of the function

SpellDigger avatar Dec 02 '25 17:12 SpellDigger

we should have them as a one optional argument at the end of the function

That isn't the standard for zig, this isn't c.

codemob-dev avatar Dec 02 '25 17:12 codemob-dev

standard or not, having to specify 2 non-optional enums as the first 2 arguments of a function just makes it annoying the fact ur putting the zig standard over making ones life easier is just evil, also im 100% sure ive seen a zig function in std that has flags like i described

SpellDigger avatar Dec 02 '25 17:12 SpellDigger

I agree that this is ugly as hell. In general parameterizing functions like this is discouraged in clean code guidelines and would mean function should be split into smaller ones, instead of merging into bigger one.

Argmaster avatar Dec 02 '25 17:12 Argmaster

I agree that this is ugly as hell. In general parameterizing functions like this is discouraged in clean code guidelines and would mean function should be split into smaller ones, instead of merging into bigger one.

this 🙏 having a function that does it all is ok... as long as its organized in a way that wont make it annoying but if we are getting forced to slap 2 enums in the first 2 arguments having the functions split is just a better option

SpellDigger avatar Dec 02 '25 17:12 SpellDigger

Aight, before I actually start thinking, I wanted to link this issue #1342 for sake of information propagation.

Argmaster avatar Dec 02 '25 19:12 Argmaster

In general parameterizing functions like this is discouraged in clean code guidelines and would mean function should be split into smaller ones

Maybe, but here you would end up with 6 smaller ones (if we added the mergeOrReplace mode) with a lot of shared code, and one of the call sites gets much simpler when doing this.

codemob-dev avatar Dec 02 '25 20:12 codemob-dev

I think we should keep generation and regular update functions separate. I would even suggest to make them entirely separate structs, since generation should use the fast path more often, in the future that will include e.g. precalculating the chunk palette indices for a newly added block, instead of recalculating them for every single block that's added. In general there should be more bulk options.

IntegratedQuantum avatar Dec 04 '25 16:12 IntegratedQuantum

Also, at least for the non-generation version, these functions should probably also be refactored to use the BlockPos instead of world-scale relative positions.

IntegratedQuantum avatar Dec 04 '25 17:12 IntegratedQuantum