refactor(gameplay): update systems per entity with chunk check

Refactor server entity update flow to process entities individually,
skipping those whose chunk is not loaded. System update methods now
accept a single entity instead of iterating the full registry view,
and `ServerWorld::get_chunk_ref_count` is added to determine if an
entity's chunk is active.
This commit is contained in:
2026-08-05 10:00:52 +08:00
parent abf1f4db7d
commit 0ffa2804d1
10 changed files with 145 additions and 118 deletions

View File

@@ -10,18 +10,18 @@ constexpr double MOVE_PROBABILITY = 0.01;
} // namespace
namespace Cubed {
void WanderAISystem::update(entt::registry& registry) {
auto view =
registry.view<AIBase, WanderAITag, BaseServerCreature, MoveBoost>();
void WanderAISystem::update(entt::registry& registry, entt::entity e) {
if (!registry.all_of<AIBase, WanderAITag, BaseServerCreature, MoveBoost>(
e)) {
return;
}
for (auto e : view) {
auto [ai, creature, move_boost] =
view.get<AIBase, BaseServerCreature, MoveBoost>(e);
++ai.count;
if (ai.count >= ai.interval) {
ai.count = 0;
do_ai(creature, move_boost);
}
auto [ai, creature, move_boost] =
registry.get<AIBase, BaseServerCreature, MoveBoost>(e);
++ai.count;
if (ai.count >= ai.interval) {
ai.count = 0;
do_ai(creature, move_boost);
}
}