From ace475138a4d7d19cfcd545672be0d5e460a9fe0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 18 Jun 2023 00:54:38 +0300 Subject: [PATCH] Add a callback when an entity is spawned over the network It can be used by the owner of the spawner to send additional packets to initialize the entity. --- source/game/replicator.cpp | 3 +++ source/game/spawner.cpp | 5 +++++ source/game/spawner.h | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/source/game/replicator.cpp b/source/game/replicator.cpp index 5fbc08e..94bdc27 100644 --- a/source/game/replicator.cpp +++ b/source/game/replicator.cpp @@ -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) diff --git a/source/game/spawner.cpp b/source/game/spawner.cpp index 9c0c3e6..5053999 100644 --- a/source/game/spawner.cpp +++ b/source/game/spawner.cpp @@ -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, unsigned target) const +{ + handler.spawn_sent(entity, target); +} + } // namespace Msp::Game diff --git a/source/game/spawner.h b/source/game/spawner.h index 0473e71..f3f48cf 100644 --- a/source/game/spawner.h +++ b/source/game/spawner.h @@ -24,6 +24,7 @@ class MSPGAME_API SpawningHandler { public: virtual void spawned(Owned) = 0; + virtual void spawn_sent(Handle, unsigned) { } }; @@ -75,6 +76,9 @@ public: private: void spawn(const SpawnableType &, const std::string &, const TransformValues &); + +public: + void notify_spawn_sent(Handle, unsigned) const; }; -- 2.45.2