summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2026-01-27 22:35:54 -0600
committerAaditya Dhruv <[email protected]>2026-01-27 22:35:54 -0600
commit17cd7420e9d2432d56f9c69c6e4a8ab665ef4b9b (patch)
tree7bcfc1d05b9b058240799d714ea0674f5eed58f3 /src/world.c
parent186889aaa18426d31c268735a4d34b494234f421 (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/world.c')
-rw-r--r--src/world.c28
1 files changed, 28 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+
+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;
+}