From 8150b91d4076d15f8df5cd66acc1b8076a2ee1a9 Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Fri, 30 Jan 2026 00:17:39 -0600 Subject: Update chunk rendering, improve chunk loading - On world_init, LOAD_CHUNK amount of chunks are preloaded - Chunks are loaded around the player's current chunk, in a square shape. The size of the shape is controlled by CHUNK_DISTANCE - Allow chunks struct to be independent of a position. We load a chunk TO a position in the world chunk grid (x, y). This allows us to "wrap" chunks, so we have an endless world, but we are really just wrapping around --- src/engine.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/engine.h') diff --git a/src/engine.h b/src/engine.h index 2eb7518..0633bcc 100644 --- a/src/engine.h +++ b/src/engine.h @@ -2,12 +2,21 @@ #include "window.h" #include "shader.h" #include "junk/vector.h" +// CHUNK_DISTANCE is essentially render distance, it shows you how many chunks +// around the user you can see +// The number of loaded chunks can be determined as follows: +// We want a square around curr_chunk, and a side of the square will be 1 +// (center chunk) + 2 * CHUNK_DISTANCE (either side of center) +// loaded chunks = (1 + CHUNK_DISTANCE * 2)^2 +#define CHUNK_DISTANCE 5 + struct engine { struct window* window; struct shader* shader; - struct vector* objects; struct camera* camera; int game_loop; + int curr_chunk[2]; + struct world* world; }; /** -- cgit