diff options
| author | Aaditya Dhruv <[email protected]> | 2026-01-30 00:17:39 -0600 |
|---|---|---|
| committer | Aaditya Dhruv <[email protected]> | 2026-01-30 00:17:39 -0600 |
| commit | 8150b91d4076d15f8df5cd66acc1b8076a2ee1a9 (patch) | |
| tree | fe74fd18e409a215ed05074efe29b3b0a465bfd5 /src/chunk.h | |
| parent | 3729fe29b862a8b1d58967c45942535e7087b73b (diff) | |
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
Diffstat (limited to 'src/chunk.h')
| -rw-r--r-- | src/chunk.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/chunk.h b/src/chunk.h index 4d06f5f..ac24a2d 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -22,6 +22,31 @@ struct chunk { vec2 coord; }; +/** + * Generate a chunk at coords for the given world. Memory allocation for chunk is + * handled by the function. + * + */ 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); +/** + * Load a chunk to the given coordinates. Essentially, a chunk only knows of + * it's local coordinate system. We want to load this particular chunk to a + * location in WORLD coordinates, which is what coord is. This vec2 will be + * used to translate the blocks that constitute the chunk + * @param chunk Chunk to load + * @param coord coordinates in world space + */ +void chunk_load(struct chunk* chunk, int coord[2]); +/** + * Unload a chunk. Delete GPU data, not the chunk data itself + * + * @param chunk Chunk to load + */ +void chunk_unload(struct chunk* chunk); +/* + * Similar to block_draw, this dispatches calls to OpenGL to draw the chunk. + * Technically this wraps block_draw, so block_draw is the one doing all the work + * @param chunk Chunk to draw + * @param shader Shader to pass to block_draw + */ +void chunk_draw(struct chunk* chunk, struct shader* shader); |
