]> git.tdb.fi Git - libs/game.git/commitdiff
Add a callback when an entity is spawned over the network
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Jun 2023 21:54:38 +0000 (00:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 17 Jun 2023 21:54:38 +0000 (00:54 +0300)
It can be used by the owner of the spawner to send additional packets
to initialize the entity.

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

index 5fbc08ee28d46ba6f85bf637428fd596815da002..94bdc272a9e252a496ddbf30d4997a6ca1485fc1 100644 (file)
@@ -87,6 +87,7 @@ void Replicator::send_spawn(const ReplicatedEntity &re, int target)
        message.position = tf.position;
        message.rotation = tf.rotation;
        message.scale = tf.scale;
+
        if(target>=0)
                networking.send(target, message);
        else
@@ -94,6 +95,8 @@ void Replicator::send_spawn(const ReplicatedEntity &re, int target)
                for(unsigned p: players)
                        networking.send(p, message);
        }
+
+       info.spawner->notify_spawn_sent(re.entity, target);
 }
 
 void Replicator::receive(const Messages::SpawnEntity &message)
index 9c0c3e647d0eca77654dd826f5a68522ee562953..5053999f0534c43219ee48081d8e5dff636e0db8 100644 (file)
@@ -51,4 +51,9 @@ void Spawner::spawn(const SpawnableType &type, const string &setup_name, const T
        handler.spawned(move(entity));
 }
 
+void Spawner::notify_spawn_sent(Handle<Entity> entity, unsigned target) const
+{
+       handler.spawn_sent(entity, target);
+}
+
 } // namespace Msp::Game
index 0473e71d10b57181cc38b1e4c619197ab189ebbb..f3f48cf8f69623591a184de4781f1688e68bea15 100644 (file)
@@ -24,6 +24,7 @@ class MSPGAME_API SpawningHandler
 {
 public:
        virtual void spawned(Owned<Entity>) = 0;
+       virtual void spawn_sent(Handle<Entity>, unsigned) { }
 };
 
 
@@ -75,6 +76,9 @@ public:
 
 private:
        void spawn(const SpawnableType &, const std::string &, const TransformValues &);
+
+public:
+       void notify_spawn_sent(Handle<Entity>, unsigned) const;
 };