This commit is contained in:
2016-02-12 04:03:22 +01:00
parent a15e01596a
commit 787eecce26
2 changed files with 24 additions and 7 deletions
+1
View File
@@ -89,6 +89,7 @@ private:
EventRelay<Server, Events::ComponentDeleted> m_EComponentDeleted;
bool OnComponentDeleted(const Events::ComponentDeleted& e);
void parsePlayerTransform(Packet& packet);
bool shouldSendToClient(EntityWrapper childEntity);
};
#endif
+16
View File
@@ -185,11 +185,18 @@ void Server::addInputCommandsToPacket(Packet& packet)
void Server::addChildrenToPacket(Packet & packet, EntityID entityID)
{
// HACK: Only sync players for now, since the map turned out to be TOO LARGE to send in one snapshot and Simon's computer shits itself
EntityWrapper entity(m_World, entityID);
if (entityID != EntityID_Invalid && !shouldSendToClient(entity)) {
return;
}
auto itPair = m_World->GetChildren(entityID);
std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools();
// Loop through every child
for (auto it = itPair.first; it != itPair.second; it++) {
EntityID childEntityID = it->second;
// Write EntityID and parentsID and Entity name
packet.WritePrimitive(childEntityID);
packet.WritePrimitive(entityID);
@@ -435,21 +442,25 @@ bool Server::OnPlayerSpawned(const Events::PlayerSpawned & e)
bool Server::OnEntityDeleted(const Events::EntityDeleted & e)
{
if (!e.Cascaded) {
if (shouldSendToClient(EntityWrapper(m_World, e.DeletedEntity))) {
Packet packet = Packet(MessageType::EntityDeleted);
packet.WritePrimitive<EntityID>(e.DeletedEntity);
broadcast(packet);
}
}
return false;
}
bool Server::OnComponentDeleted(const Events::ComponentDeleted & e)
{
if (!e.Cascaded) {
if (shouldSendToClient(EntityWrapper(m_World, e.Entity))) {
Packet packet = Packet(MessageType::ComponentDeleted);
packet.WritePrimitive<EntityID>(e.Entity);
packet.WriteString(e.ComponentType);
broadcast(packet);
}
}
return false;
}
@@ -484,3 +495,8 @@ void Server::parsePlayerTransform(Packet& packet)
}
}
}
bool Server::shouldSendToClient(EntityWrapper childEntity)
{
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid();
}