mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(server): send entity position updates to all sessions
This commit is contained in:
@@ -46,6 +46,7 @@ private:
|
|||||||
void send_all_entities(std::shared_ptr<Session>& session);
|
void send_all_entities(std::shared_ptr<Session>& session);
|
||||||
void update_ai();
|
void update_ai();
|
||||||
void update_move();
|
void update_move();
|
||||||
|
void update_send();
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
EntityID create_entity_in_factory(Args&&... args) {
|
EntityID create_entity_in_factory(Args&&... args) {
|
||||||
auto entity = m_registry.create();
|
auto entity = m_registry.create();
|
||||||
|
|||||||
@@ -29,14 +29,35 @@ void ServerEntityManager::update() {
|
|||||||
handle_task();
|
handle_task();
|
||||||
update_ai();
|
update_ai();
|
||||||
update_move();
|
update_move();
|
||||||
|
|
||||||
|
update_send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerEntityManager::update_ai() { WanderAISystem::update(m_registry); }
|
void ServerEntityManager::update_ai() { WanderAISystem::update(m_registry); }
|
||||||
|
|
||||||
void ServerEntityManager::update_move() {
|
void ServerEntityManager::update_move() {
|
||||||
SpeedSystem::update(
|
SpeedSystem::update(
|
||||||
static_cast<float>(m_world.get_per_tick_time()) / 1000.0f, m_registry);
|
static_cast<float>(m_world.get_per_tick_time()) / 1000.0f, m_registry);
|
||||||
PhysicalSystem::update(m_world, m_registry);
|
PhysicalSystem::update(m_world, m_registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerEntityManager::update_send() {
|
||||||
|
auto sessions = m_world.get_all_session();
|
||||||
|
auto view = m_registry.view<Entity, BaseServerCreature>();
|
||||||
|
|
||||||
|
for (auto& e : view) {
|
||||||
|
auto [entity, creature] = view.get<Entity, BaseServerCreature>(e);
|
||||||
|
Arena arena;
|
||||||
|
auto* p = Arena::Create<S2CEntityUpdate>(&arena);
|
||||||
|
p->set_id(entity.id);
|
||||||
|
Tools::set_net_pos(p, creature.transform.position.value);
|
||||||
|
|
||||||
|
for (auto& s : sessions) {
|
||||||
|
s->send(make_packet(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ServerEntityManager::handle_task() {
|
void ServerEntityManager::handle_task() {
|
||||||
TaskPair pair;
|
TaskPair pair;
|
||||||
while (m_tasks.try_pop(pair)) {
|
while (m_tasks.try_pop(pair)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user