From 17cd7420e9d2432d56f9c69c6e4a8ab665ef4b9b Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Tue, 27 Jan 2026 22:35:54 -0600 Subject: Add World and multi-chunk rendering - More than 1 chunk can now be rendered with the help of the world struct - Block coords are now in world space, not local space - Engine init code cleaned up for cleaner world/chunk handling --- src/world.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/world.c (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c new file mode 100644 index 0000000..e81f100 --- /dev/null +++ b/src/world.c @@ -0,0 +1,28 @@ +#include "world.h" +#include +#include + +int world_init(int32_t seed, struct world** world) { + srand(seed); + struct world* wld = malloc(sizeof(struct world)); + memset(wld, 0, sizeof(struct world)); + wld->seed = seed; + for (int i = 0; i < WORLD_WIDTH; i++) { + for (int j = 0; j < WORLD_LENGTH; j++) { + struct chunk* chunk; + vec2 coords = { i, j }; + chunk_gen(wld, coords, &chunk); + wld->chunks[i][j] = chunk; + + } + } + *world = wld; + return 0; +} + +int world_get_chunk(struct world* world, vec2 coord, struct chunk** chunk) { + int x = (int)coord[0] % WORLD_WIDTH; + int y = (int)coord[1] % WORLD_LENGTH; + *chunk = world->chunks[x][y]; + return 0; +} -- cgit