summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2026-01-31 03:22:27 -0600
committerAaditya Dhruv <[email protected]>2026-01-31 03:22:27 -0600
commit7f13b0abaa76a5e90674d5733f8162f02ceab693 (patch)
treee280ad2a4a881e79d2519f2558dcab6a36d5b389 /src/world.c
parent0c3e1f450f591d871c2779504b4113daf891fd1b (diff)
Rework chunk rendering to get a 100x performance boost!
- Switching to semi-chunk mesh rendering just 100x the framerate, it was running at around 100fps for 3 CHUNK_DISTANCE, and pushing it above would make it drop to 30. Now it runs at 9000 frames per second with CHUNK_DISTANCE of 8, probably can push it even more - What is bizarre is this is just from the reduction in draw calls, I still need to implement face culling for invisible blocks (simple) and frustrum culling (using AABB) or maybe octrees - Block is way way more simplifed, it's just metadata about a coordinate in the chunk block array - All rendering and mesh generation code is handled by chunks. There is a VAO, single VBO and EBO for each chunk. The data buffer is loaded into the GPU with a chunk_load, and it stays like that until it is loaded again. chunk_load is called if we move chunks, in engine_update. Here we unload existing chunks, then load the new ones
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/world.c b/src/world.c
index 41fdd17..4ce248b 100644
--- a/src/world.c
+++ b/src/world.c
@@ -5,7 +5,7 @@
#include <string.h>
// LOAD_DISTANCE determines how many chunks are loaded on world creation
-#define LOAD_DISTANCE 4
+#define LOAD_DISTANCE 10
int world_init(int32_t seed, struct world** world) {
srand(seed);
@@ -13,8 +13,8 @@ int world_init(int32_t seed, struct world** world) {
memset(wld, 0, sizeof(struct world));
wld->seed = seed;
//TODO: Improve loading here
- for (int i = 0; i < LOAD_DISTANCE; i++) {
- for (int j = 0; j < LOAD_DISTANCE; j++) {
+ for (int i = -LOAD_DISTANCE; i <= LOAD_DISTANCE; i++) {
+ for (int j = -LOAD_DISTANCE; j <= LOAD_DISTANCE; j++) {
struct chunk* chunk;
int coords[2] = { i, j };
world_get_chunk(wld, coords, &chunk);