fix chunk loading based on player position

This commit is contained in:
2026-06-25 22:29:13 -05:00
parent 454b8a91ba
commit 0c8c0d24ba
+9 -6
View File
@@ -45,13 +45,16 @@ errorret_t rpgCameraUpdate(void) {
vec3 pos; vec3 pos;
rpgCameraGetPosition(pos); rpgCameraGetPosition(pos);
worldpos_t worldPos = {
(worldunit_t)pos[0], // Round to the nearest chunk center rather than flooring, so the
(worldunit_t)pos[1], // loaded window is always most centered on what the camera sees.
(worldunit_t)pos[2] // Adding half the chunk dimension before flooring snaps at the
// midpoint of each chunk instead of at the boundary.
chunkpos_t chunkPos = {
.x = (chunkunit_t)floorf(pos[0] / CHUNK_WIDTH + 0.5f),
.y = (chunkunit_t)floorf(pos[1] / CHUNK_HEIGHT + 0.5f),
.z = (chunkunit_t)floorf(pos[2] / CHUNK_DEPTH + 0.5f)
}; };
chunkpos_t chunkPos;
worldPosToChunkPos(&worldPos, &chunkPos);
errorChain(mapPositionSet((chunkpos_t){ errorChain(mapPositionSet((chunkpos_t){
.x = chunkPos.x - (MAP_CHUNK_WIDTH / 2), .x = chunkPos.x - (MAP_CHUNK_WIDTH / 2),