mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
perf(render): skip entities outside loaded chunks
This commit is contained in:
@@ -94,6 +94,9 @@ public:
|
|||||||
void receive_voice_message(VoiceMsg& msg);
|
void receive_voice_message(VoiceMsg& msg);
|
||||||
bool enable_voice_chat() const;
|
bool enable_voice_chat() const;
|
||||||
int get_per_tick_time() const override;
|
int get_per_tick_time() const override;
|
||||||
|
|
||||||
|
bool is_render(const glm::vec3& pos) const;
|
||||||
|
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void register_timer(std::string_view id, float threshold, Fn&& f) {
|
void register_timer(std::string_view id, float threshold, Fn&& f) {
|
||||||
m_timers.emplace(std::piecewise_construct,
|
m_timers.emplace(std::piecewise_construct,
|
||||||
|
|||||||
@@ -725,6 +725,13 @@ void ClientWorld::receive_voice_message(VoiceMsg& msg) {
|
|||||||
}
|
}
|
||||||
bool ClientWorld::enable_voice_chat() const { return m_voice_chat.load(); }
|
bool ClientWorld::enable_voice_chat() const { return m_voice_chat.load(); }
|
||||||
int ClientWorld::get_per_tick_time() const { return m_per_tick_time; }
|
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) {
|
void ClientWorld::send_chat_message(ChatMessage& message) {
|
||||||
Arena arena;
|
Arena arena;
|
||||||
auto msg = Arena::Create<ChatMsg>(&arena);
|
auto msg = Arena::Create<ChatMsg>(&arena);
|
||||||
|
|||||||
@@ -300,6 +300,10 @@ void WorldRenderer::shadow_entity(ClientWorld& world,
|
|||||||
auto view = registry.view<BaseClientCreature, RenderTransform>();
|
auto view = registry.view<BaseClientCreature, RenderTransform>();
|
||||||
for (auto entity : view) {
|
for (auto entity : view) {
|
||||||
auto& creature = view.get<BaseClientCreature>(entity);
|
auto& creature = view.get<BaseClientCreature>(entity);
|
||||||
|
auto pos = creature.transform.position.value;
|
||||||
|
if (!world.is_render(pos)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto& t = view.get<RenderTransform>(entity);
|
auto& t = view.get<RenderTransform>(entity);
|
||||||
float yaw = std::atan2(t.direction.value.x, t.direction.value.z);
|
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<BaseClientCreature, RenderTransform>();
|
auto view = registry.view<BaseClientCreature, RenderTransform>();
|
||||||
for (auto entity : view) {
|
for (auto entity : view) {
|
||||||
auto& creature = view.get<BaseClientCreature>(entity);
|
auto& creature = view.get<BaseClientCreature>(entity);
|
||||||
|
auto pos = creature.transform.position.value;
|
||||||
|
if (!world.is_render(pos)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto& t = view.get<RenderTransform>(entity);
|
auto& t = view.get<RenderTransform>(entity);
|
||||||
float yaw = std::atan2(t.direction.value.x, t.direction.value.z);
|
float yaw = std::atan2(t.direction.value.x, t.direction.value.z);
|
||||||
m_renderer.model_renderer().render_model(creature.model,
|
m_renderer.model_renderer().render_model(creature.model,
|
||||||
|
|||||||
Reference in New Issue
Block a user