Skip to content

Conversation

@IntegratedQuantum
Copy link
Member

fixes #1453

return;
}

const movedEntry = storage.items[dataIndex];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, cool, so what's the plan for unloading block entities when chunk they come from gets unloaded? Do you just iterate all the block entities whenever a chunk is unloaded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just iterate over the chunk hashmap

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I guess, why did I remove it the way I did...?
Was it because there is no direct external access for deleting? So caller will have to explicitly call proper callback and separately clear hash map entry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I guess, why did I remove it the way I did...?

To keep the list sparse, which is no longer needed due to using the SparseSet.

const mesh_storage = main.renderer.mesh_storage;

pub const BlockEntityIndex = u32;
pub const BlockEntityIndex = enum(u32) {
Copy link
Contributor

@OneAvargeCoder193 OneAvargeCoder193 May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just be

pub const BlockEntityIndex = main.utils.DenseId(u32);

Copy link
Collaborator

@Argmaster Argmaster May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw it was a very poor choice of name I suggested, since this is an ID used to index sparse array in many contexts (xD)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw it was a very poor choice of name I suggested

Please suggest a better name in a PR then, or make an issue for it.

Copy link
Collaborator

@Argmaster Argmaster May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, after this PR gets merged

Copy link
Collaborator

@Argmaster Argmaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that part is mostly fine, but since BEs are no longer cleaning up after themselves shouldn't you add cleanup code next to onBreakClient and alike callbacks that add and remove BEs to chunk hash maps? Some of them are already called in code.

@IntegratedQuantum
Copy link
Member Author

I think that part is mostly fine, but since BEs are no longer cleaning up after themselves shouldn't you add cleanup code next to onBreakClient and alike callbacks that add and remove BEs to chunk hash maps? Some of them are already called in code.

I don't really understand the problem. BlockEntityDataStorage.add calls chunk.blockPosToEntityDataMap.put and BlockEntityDataStorage.remove calls chunk.blockPosToEntityDataMap.fetchRemove

@Argmaster
Copy link
Collaborator

I don't really understand the problem. BlockEntityDataStorage.add calls chunk.blockPosToEntityDataMap.put and BlockEntityDataStorage.remove calls chunk.blockPosToEntityDataMap.fetchRemove

Hmm I see, alr then its all fine ig.

@Argmaster
Copy link
Collaborator

Apparently my brain already garbage collected my understanding of block entity system :3

@IntegratedQuantum IntegratedQuantum merged commit a480955 into master May 20, 2025
1 check passed
Argmaster pushed a commit to Argmaster/Cubyz that referenced this pull request May 21, 2025
@IntegratedQuantum IntegratedQuantum deleted the blockEntity_SparseSet branch June 7, 2025 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The current BlockEntity system can crash on unloading

4 participants