diff options
| author | Aaditya Dhruv <[email protected]> | 2026-01-27 22:35:54 -0600 |
|---|---|---|
| committer | Aaditya Dhruv <[email protected]> | 2026-01-27 22:35:54 -0600 |
| commit | 17cd7420e9d2432d56f9c69c6e4a8ab665ef4b9b (patch) | |
| tree | 7bcfc1d05b9b058240799d714ea0674f5eed58f3 /src/chunk.c | |
| parent | 186889aaa18426d31c268735a4d34b494234f421 (diff) | |
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
Diffstat (limited to 'src/chunk.c')
| -rw-r--r-- | src/chunk.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/chunk.c b/src/chunk.c index 77c2301..982882d 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -17,10 +17,28 @@ void _chunk_plains_gen(struct chunk* chunk); -int chunk_gen(struct world* world, struct chunk *chunk) { - // struct chunk neighbor = {0}; +int chunk_gen(struct world* world, vec2 coord, struct chunk **chunk) { + *chunk = malloc(sizeof(struct chunk)); + memcpy((*chunk)->coord,coord, sizeof(vec2)); + // struct chunk* neighbor_top = { 0 }; + // struct chunk* neighbor_bottom = { 0 }; + // struct chunk* neighbor_left = { 0 }; + // struct chunk* neighbor_right = { 0 }; + // vec2 top = { 0, 1 }; + // vec2 bottom = { 0, -1 }; + // vec2 left = { -1, 0 }; + // vec2 right = { 1, 0 }; + // glm_vec2_add(top, coord, top); + // glm_vec2_add(bottom, coord, bottom); + // glm_vec2_add(left, coord, left); + // glm_vec2_add(right, coord, right); + // world_get_chunk(world, top, &neighbor_top); + // world_get_chunk(world, bottom, &neighbor_bottom); + // world_get_chunk(world, left, &neighbor_left); + // world_get_chunk(world, right, &neighbor_right); + // world_get_chunk(world, chunk->coord, &neighbor); - _chunk_plains_gen(chunk); + _chunk_plains_gen(*chunk); // switch (chunk->biome) { // case JUNK_BIOME_PLAINS: // _ @@ -95,13 +113,11 @@ void _chunk_plains_gen(struct chunk* chunk) { int z_final = (z1 + z2) / 2; for (int h = 0; h < z_final; h++) { struct block* blk = malloc(sizeof(struct block)); - vec3 pos = {x, h, -y - 1}; + // Adjust block coordinates with global chunk coordinates + vec3 pos = {x + (CHUNK_WIDTH * chunk->coord[0]), h, -y - 1 - (CHUNK_LENGTH * chunk->coord[1])}; block_init(pos, blk); chunk->blocks[x][y][h] = blk; } } } - fprintf(stderr, "POI Coords\n"); - glm_vec3_print(poi1, stderr); - glm_vec3_print(poi2, stderr); } |
