Skip to content

Conversation

@Mcrtin
Copy link
Collaborator

@Mcrtin Mcrtin commented Nov 30, 2025

This is a preview of how the chunk impl could look like.
TODO:
- current chunk gen tests aren't passing (so not that important xD)
- i'd like to, instead of making changes on chunks, use chunk sections
- net positions should get integrated into the newly added position structs
- the position structs need docs more functions and overall a glowup
- Passing dims as strings sucks. (also, why do we not use &'static str instead of cloning?)
- why do we use arcs in thu chunk impl?
- why do we sanitize BlockStateId
- ...
for now this has to suffice.a
the actual changes include:

  • add position structs
  • remove dim and pos from chunk

@Mcrtin Mcrtin marked this pull request as ready for review December 2, 2025 20:36
@Mcrtin
Copy link
Collaborator Author

Mcrtin commented Dec 2, 2025

(currently can't do runtime tests)

@Mcrtin Mcrtin requested a review from ReCore-sys December 6, 2025 10:26
@Mcrtin
Copy link
Collaborator Author

Mcrtin commented Dec 6, 2025

i fixed (most of) the bugs with @NanCunChild

@NanCunChild
Copy link
Contributor

;) remains a few bugs, cuz it is bug nest and hard to figure out what exactly happens.

@ReCore-sys
Copy link
Collaborator

image not quite @Mcrtin @NanCunChild

@ReCore-sys
Copy link
Collaborator

Nvm that was from an old world save, regenerated the world and it looks ok now. Will properly review the code tomorrow.

Copy link
Collaborator

@ReCore-sys ReCore-sys left a comment

Choose a reason for hiding this comment

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

Looks fine, just a couple questions about some choices made.

#[derive(Clone, Copy)]
pub struct BlockPos {
/// (i26, i12, i26)
pub pos: IVec3,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would using the simd version be possible? Might allow for cleaner conversions from/to player positions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there is a simd version?


impl ChunkPos {
pub const fn new(x: i32, z: i32) -> Self {
assert!(x < 1 << 22);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are these bitshifts doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the bitshifts (1 << 22), I believe this aligns with the previous discussion about using 22-bit widths for world coordinates to enforce boundaries and optimize storage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

a Network position may only be at most 64 bit (divided between xyz) where x is at most 24 bit iirc so the chunk x pos may only be 22 bit. this is important for the pack() feature ChunkPos provides where we assume these bounds.


#[derive(Clone, Copy)]
pub struct BlockPos {
/// (i26, i12, i26)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is using the packed format really worth it? I'd be worried about how that'd impact the CPU's native data type handling. This data type would largely be an intermediate bit of data so a few extra bytes won't make all that much of a difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @ReCore-sys on the packed format concern. For BlockPos which is used heavily in logic calculations, the CPU overhead of unpacking might outweigh the memory savings. Maybe we should keep the packed format only for storage/networking structs, but use native types for internal logic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we aren't using the packed format... it just uses an ivec3 under the hood; the comment is just there to make the bounds clear, that we have to assure to be able to send it to the client via networkPosition


impl ChunkColumnPos {
pub const fn new(x: u8, z: u8) -> Self {
assert!(x < 16);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In non-debug builds should we just truncate down to 0-15?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i was wondering if we should but i want const evaluations to error at comp time and i couldn't really figure out a better way

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.

3 participants