From e57736f1b3bf1cc2f46276bdba3b62b7b6365ff7 Mon Sep 17 00:00:00 2001 From: 0undefined Date: Tue, 3 Mar 2026 02:17:23 +0100 Subject: Cull blocks --- state_mainstate/src/mainstate.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'state_mainstate/src/mainstate.c') diff --git a/state_mainstate/src/mainstate.c b/state_mainstate/src/mainstate.c index fc3a2a8..172f3a7 100644 --- a/state_mainstate/src/mainstate.c +++ b/state_mainstate/src/mainstate.c @@ -261,7 +261,7 @@ void mainstate_init(Window *restrict w, mainstate_state *state, void* arg) { /// Setup the camera // Set the position (it is zero initialized) - glm_vec3_copy((vec3){CHUNK_WIDTH / 2.f, CHUNK_HEIGHT / 4.f + 4.f, CHUNK_LENGTH / 2.f}, state->c.pos); + glm_vec3_copy((vec3){CHUNK_WIDTH * WORLD_WIDTH / 2.f, CHUNK_HEIGHT / 4.f + 4.f, CHUNK_LENGTH * WORLD_LENGTH / 2.f}, state->c.pos); // Copy to the desired position glm_vec3_copy(state->c.pos, state->cam_pos); @@ -330,6 +330,8 @@ void mainstate_init(Window *restrict w, mainstate_state *state, void* arg) { } gen_terrain(state->world); + usize total = 0; + usize culled = 0; for (isize i = 0; i < WORLD_SIZE * CHUNK_SIZE; i++) { if (state->world[i] == BLOCK_none) continue; @@ -349,7 +351,14 @@ void mainstate_init(Window *restrict w, mainstate_state *state, void* arg) { Transform t = { .position = {(float)x, (float)y, (float)z}, }; - switch (state->world[i]) { + if (state->world[i] & ((1 << 5) - 1)) { + total++; + } + if (SURROUNDED(state->world[i])) { + culled++; + continue; + } + switch (state->world[i] & ((1 << 5) - 1)) { case BLOCK_grass: if (-1 == renderbatch_add(&(state->terrain), &(state->objects[0]), &t)) { ERROR("Failed to add model 0 to render batch!"); @@ -366,6 +375,8 @@ void mainstate_init(Window *restrict w, mainstate_state *state, void* arg) { } } + INFO("Culled %u / %u (%.2f)", culled, total, (float)culled / (float)total); + // Create the render object from the buffer renderbatch_refresh(&(state->terrain)); state->terrain.renderobj = RenderObject_new( -- cgit v1.3