diff --git a/game/src/chunk/chunkman.c b/game/src/chunk/chunkman.c index d1508b5..d5dbe77 100644 --- a/game/src/chunk/chunkman.c +++ b/game/src/chunk/chunkman.c @@ -117,6 +117,12 @@ chunkman_tick (vec3 position) { for (int x = cx - render_distance - 1; x <= cx + render_distance + 1; ++x) { + /* Check in a circle instead of a square. */ + if ((x - cx) * (x - cx) + (z - cz) * (z - cz) > (render_distance+1)*(render_distance+1)) + { + continue; + } + uint64_t now = SDL_GetPerformanceCounter (); elapsed_us = (double) (now - start) * 1000000.0 / (double) freq; @@ -136,6 +142,11 @@ chunkman_tick (vec3 position) { for (int x = cx - render_distance; x <= cx + render_distance; ++x) { + if ((x - cx) * (x - cx) + (z - cz) * (z - cz) > render_distance*render_distance) + { + continue; + } + uint64_t now = SDL_GetPerformanceCounter (); elapsed_us = (double) (now - start) * 1000000.0 / (double) freq; @@ -148,9 +159,9 @@ chunkman_tick (vec3 position) { chunkman_generate_ChunkMesh_at (x, z); } - } } } +} void chunkman_render (vec3 position, vec4 planes[6]) @@ -181,6 +192,11 @@ chunkman_render (vec3 position, vec4 planes[6]) { for (int x = cx - render_distance; x <= cx + render_distance; ++x) { + if ((x - cx) * (x - cx) + (z - cz) * (z - cz) > render_distance*render_distance) + { + continue; + } + ChunkMesh *mesh = chunkman_get_ChunkMesh_at (x, z); if (mesh != NULL) { @@ -206,10 +222,10 @@ chunkman_render (vec3 position, vec4 planes[6]) ChunkMesh_render (mesh, flags_get ("wireframe_enabled")); n_frame_chunks++; } - } } +} - bound = false; +bound = false; } Chunk * diff --git a/game/src/graphics.c b/game/src/graphics.c index ff84fda..3674f45 100644 --- a/game/src/graphics.c +++ b/game/src/graphics.c @@ -4,7 +4,7 @@ extern vec3 camera_position; extern int last_time; SDL_Window *sdl_window; -int render_distance = 1; +int render_distance = 2; static SDL_GLContext gl_context; @@ -119,6 +119,7 @@ graphics_render () avg_elapsed = 0; avg_counter = 0; last_check_perf = now; + INFO ("Dynamic render distance check: render distance %d, average ms: %.2f", render_distance, avg / 10000.0); } }