From 30b4060fb51c4859766eb0426552bc2a902ad8bc Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Wed, 5 Aug 2026 15:15:01 +0800 Subject: [PATCH] perf(render): skip entities outside loaded chunks --- include/Cubed/gameplay/client_world.hpp | 3 +++ src/gameplay/client_world.cpp | 7 +++++++ src/render/world_renderer.cpp | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/include/Cubed/gameplay/client_world.hpp b/include/Cubed/gameplay/client_world.hpp index 9bdcf15..6b63faa 100644 --- a/include/Cubed/gameplay/client_world.hpp +++ b/include/Cubed/gameplay/client_world.hpp @@ -94,6 +94,9 @@ public: void receive_voice_message(VoiceMsg& msg); bool enable_voice_chat() const; int get_per_tick_time() const override; + + bool is_render(const glm::vec3& pos) const; + template void register_timer(std::string_view id, float threshold, Fn&& f) { m_timers.emplace(std::piecewise_construct, diff --git a/src/gameplay/client_world.cpp b/src/gameplay/client_world.cpp index f99079f..7fe4da9 100644 --- a/src/gameplay/client_world.cpp +++ b/src/gameplay/client_world.cpp @@ -725,6 +725,13 @@ void ClientWorld::receive_voice_message(VoiceMsg& msg) { } bool ClientWorld::enable_voice_chat() const { return m_voice_chat.load(); } int ClientWorld::get_per_tick_time() const { return m_per_tick_time; } + +bool ClientWorld::is_render(const glm::vec3& pos) const { + ChunkPos p = get_chunk_pos(pos.x, pos.z); + chunk_cacc cacc; + return m_chunks.find(cacc, p); +} + void ClientWorld::send_chat_message(ChatMessage& message) { Arena arena; auto msg = Arena::Create(&arena); diff --git a/src/render/world_renderer.cpp b/src/render/world_renderer.cpp index 82d6686..629c186 100644 --- a/src/render/world_renderer.cpp +++ b/src/render/world_renderer.cpp @@ -300,6 +300,10 @@ void WorldRenderer::shadow_entity(ClientWorld& world, auto view = registry.view(); for (auto entity : view) { auto& creature = view.get(entity); + auto pos = creature.transform.position.value; + if (!world.is_render(pos)) { + continue; + } auto& t = view.get(entity); float yaw = std::atan2(t.direction.value.x, t.direction.value.z); @@ -724,6 +728,10 @@ void WorldRenderer::render_entity(ClientWorld& world) { auto view = registry.view(); for (auto entity : view) { auto& creature = view.get(entity); + auto pos = creature.transform.position.value; + if (!world.is_render(pos)) { + continue; + } auto& t = view.get(entity); float yaw = std::atan2(t.direction.value.x, t.direction.value.z); m_renderer.model_renderer().render_model(creature.model,