]> git.tdb.fi Git - libs/game.git/commitdiff
Send spawns of newly-created entities in deferred_tick
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Jun 2023 21:02:40 +0000 (00:02 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 17 Jun 2023 21:44:51 +0000 (00:44 +0300)
Spawn info won't have been set in the component_create event for the
zygote.

source/game/replicator.cpp
source/game/replicator.h

index a24e629340a669689bb951de403611b175a0ce26..64769e76b1554b936fc536e023ff028b194f2a13 100644 (file)
@@ -42,6 +42,16 @@ void Replicator::add_target_player(unsigned id)
                send_spawn(e, id);
 }
 
+void Replicator::deferred_tick()
+{
+       for(ReplicatedEntity &e: entities)
+               if(!e.visible_to_players)
+               {
+                       send_spawn(e, -1);
+                       e.visible_to_players = true;
+               }
+}
+
 void Replicator::component_created(const Events::ComponentCreated &event)
 {
        if(Handle<Zygote> zygote = dynamic_handle_cast<Zygote>(event.component))
@@ -49,8 +59,7 @@ void Replicator::component_created(const Events::ComponentCreated &event)
                Handle<Entity> entity = zygote->get_entity();
                Handle<Transform> transform = entity->get_transform();
                auto i = lower_bound_member(entities, transform, &ReplicatedEntity::transform);
-               i = entities.emplace(i, entity, transform, zygote);
-               send_spawn(*i, -1);
+               entities.emplace(i, entity, transform, zygote);
        }
 }
 
index 573a5fc6ba9831bfef67bac6708d88fd72938cbc..6742593dbbcd219cd5d8540704f1abc78ed617a3 100644 (file)
@@ -22,6 +22,7 @@ private:
                Handle<Entity> entity;
                Handle<Transform> transform;
                Handle<Zygote> zygote;
+               bool visible_to_players = false;
        };
 
        EventObserver observer;
@@ -38,6 +39,7 @@ public:
        void add_target_player(unsigned);
 
        void tick(Time::TimeDelta) override { }
+       void deferred_tick() override;
 
 private:
        void component_created(const Events::ComponentCreated &);