First pass chunk loading.

This commit is contained in:
2025-06-13 13:33:27 -05:00
parent bb1c7259ca
commit 49989e0272
9 changed files with 269 additions and 102 deletions

View File

@ -8,6 +8,7 @@
#include "chunk.h"
#include "util/memory.h"
#include "assert/assert.h"
#include "world/world.h"
chunkmap_t CHUNK_MAP;
@ -175,14 +176,23 @@ void chunkLoad(chunk_t *chunk, const uint16_t x, const uint16_t y) {
chunk->x = x;
chunk->y = y;
if(
((x % 2 == 0) && (y % 2 == 0)) ||
((x % 2 == 1) && (y % 2 == 1))
) {
memorySet(chunk->tiles, 1, sizeof(chunk->tiles));
} else {
if(x >= WORLD_WIDTH || y >= WORLD_HEIGHT) {
memorySet(chunk->tiles, 0, sizeof(chunk->tiles));
return;
}
const uint8_t *chunkLayerBase = WORLD_CHUNKS_BASE[y * WORLD_WIDTH + x];
if(chunkLayerBase == NULL) {
memorySet(chunk->tiles, 0, sizeof(chunk->tiles));
return;
}
printf("Loading chunk at (%u, %u)\n", x, y);
memoryCopy(
chunk->tiles,
chunkLayerBase,
sizeof(chunk->tiles)
);
}
void chunkUnload(chunk_t *chunk) {

View File

@ -35,13 +35,13 @@ void overworldUpdate() {
if(OVERWORLD_CAMERA_X < RENDER_WIDTH / 2) {
x = 0;
} else {
x = (OVERWORLD_CAMERA_X - (RENDER_WIDTH / 2)) / (CHUNK_WIDTH * TILE_WIDTH);
x = (OVERWORLD_CAMERA_X - (RENDER_WIDTH / 2)) / (CHUNK_WIDTH*TILE_WIDTH);
}
if(OVERWORLD_CAMERA_Y < RENDER_HEIGHT / 2) {
y = 0;
} else {
y = (OVERWORLD_CAMERA_Y - (RENDER_HEIGHT / 2)) / (CHUNK_HEIGHT * TILE_HEIGHT);
y = (OVERWORLD_CAMERA_Y -(RENDER_HEIGHT / 2)) / (CHUNK_HEIGHT*TILE_HEIGHT);
}
chunkMapSetPosition(x, y);