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/chunk.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/chunk.h') diff --git a/src/chunk.h b/src/chunk.h index 87c33fa..4d06f5f 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -1,21 +1,27 @@ #pragma once #include "block.h" #include "world.h" -#include "junk/vector.h" #include -enum biome { - JUNK_BIOME_PLAINS, -}; #define CHUNK_WIDTH 16 #define CHUNK_LENGTH 16 #define CHUNK_HEIGHT 128 +enum biome { + JUNK_BIOME_PLAINS, +}; + + +//NOTE: Forward declare world here. There is a circular dependency between +// chunk and world, and the order in which compiler sees them causes issues. +// World.c compiles -> includes world.h -> first line is include chunk.h -> struct world +// is used here, which messes it up. Forward declare to avoid errors +struct world; struct chunk { struct block* blocks[CHUNK_WIDTH][CHUNK_LENGTH][CHUNK_HEIGHT]; enum biome biome; vec2 coord; }; -int chunk_gen(struct world* world, struct chunk* chunk); +int chunk_gen(struct world* wld, vec2 coord, struct chunk** chunk); int chunk_gen_structures(void* neighbor_data, struct chunk* chunk); int chunk_gen_terrain(void* neighbor_data, struct chunk* chunk); -- cgit