{
event_source.emit<Events::PossessionChanged>(i->entity, p.get_player_id());
if(i->visible_to_players && is_server())
- send_possession(*i, -1);
+ send_possession(*i, 0);
}
p.clear_changed();
}
for(ReplicatedEntity &e: entities)
if(!e.visible_to_players)
{
- send_spawn(e, -1);
+ send_spawn(e, 0);
e.visible_to_players = true;
}
}
}
}
-void Replicator::send_spawn(const ReplicatedEntity &re, int target)
+void Replicator::send_spawn(const ReplicatedEntity &re, unsigned target)
{
- if(target<0 && players.empty())
+ if(!target && players.empty())
return;
const SpawnInfo &info = re.zygote->get_spawn_info();
message.position = tf.position;
message.rotation = tf.rotation;
message.scale = tf.scale;
-
- if(target>=0)
- networking.send(target, message);
- else
- {
- for(unsigned p: players)
- networking.send(p, message);
- }
+ send(target, message);
info.spawner->notify_spawn_sent(re.entity, target);
send_possession(re, target);
}
-void Replicator::send_possession(const ReplicatedEntity &re, int target)
+void Replicator::send_possession(const ReplicatedEntity &re, unsigned target)
{
- if(target<0 && players.empty())
+ if(!target && players.empty())
return;
Messages::GrantPossession grant;
grant.entity_id = re.zygote->get_entity_id();
grant.player_id = re.possessed->get_player_id();
-
- if(target>=0)
- networking.send(target, grant);
- else
- {
- for(unsigned p: players)
- networking.send(p, grant);
- }
+ send(target, grant);
}
void Replicator::receive(const Messages::SpawnEntity &message)
private:
void component_created(const Events::ComponentCreated &);
- void send_spawn(const ReplicatedEntity &, int);
- void send_possession(const ReplicatedEntity &, int);
+ void send_spawn(const ReplicatedEntity &, unsigned);
+ void send_possession(const ReplicatedEntity &, unsigned);
void receive(const Messages::SpawnEntity &) override;
void receive(const Messages::GrantPossession &) override;
template<typename P>
void Replicator::send(unsigned target, const P &packet)
{
- networking.send(target, packet);
+ if(target)
+ networking.send(target, packet);
+ else
+ send(packet);
}
} // namespace Msp::Game