fix chunk loading based on player position

This commit is contained in:
2026-06-25 22:29:13 -05:00
parent 454b8a91ba
commit 0c8c0d24ba
+10 -7
View File
@@ -45,14 +45,17 @@ errorret_t rpgCameraUpdate(void) {
vec3 pos;
rpgCameraGetPosition(pos);
worldpos_t worldPos = {
(worldunit_t)pos[0],
(worldunit_t)pos[1],
(worldunit_t)pos[2]
// Round to the nearest chunk center rather than flooring, so the
// loaded window is always most centered on what the camera sees.
// 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){
.x = chunkPos.x - (MAP_CHUNK_WIDTH / 2),
.y = chunkPos.y - (MAP_CHUNK_HEIGHT / 2),