WIP
This commit is contained in:
@@ -89,6 +89,7 @@ private:
|
|||||||
EventRelay<Server, Events::ComponentDeleted> m_EComponentDeleted;
|
EventRelay<Server, Events::ComponentDeleted> m_EComponentDeleted;
|
||||||
bool OnComponentDeleted(const Events::ComponentDeleted& e);
|
bool OnComponentDeleted(const Events::ComponentDeleted& e);
|
||||||
void parsePlayerTransform(Packet& packet);
|
void parsePlayerTransform(Packet& packet);
|
||||||
|
bool shouldSendToClient(EntityWrapper childEntity);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -185,11 +185,18 @@ void Server::addInputCommandsToPacket(Packet& packet)
|
|||||||
|
|
||||||
void Server::addChildrenToPacket(Packet & packet, EntityID entityID)
|
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);
|
auto itPair = m_World->GetChildren(entityID);
|
||||||
std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools();
|
std::unordered_map<std::string, ComponentPool*> worldComponentPools = m_World->GetComponentPools();
|
||||||
// Loop through every child
|
// Loop through every child
|
||||||
for (auto it = itPair.first; it != itPair.second; it++) {
|
for (auto it = itPair.first; it != itPair.second; it++) {
|
||||||
EntityID childEntityID = it->second;
|
EntityID childEntityID = it->second;
|
||||||
|
|
||||||
// Write EntityID and parentsID and Entity name
|
// Write EntityID and parentsID and Entity name
|
||||||
packet.WritePrimitive(childEntityID);
|
packet.WritePrimitive(childEntityID);
|
||||||
packet.WritePrimitive(entityID);
|
packet.WritePrimitive(entityID);
|
||||||
@@ -435,9 +442,11 @@ bool Server::OnPlayerSpawned(const Events::PlayerSpawned & e)
|
|||||||
bool Server::OnEntityDeleted(const Events::EntityDeleted & e)
|
bool Server::OnEntityDeleted(const Events::EntityDeleted & e)
|
||||||
{
|
{
|
||||||
if (!e.Cascaded) {
|
if (!e.Cascaded) {
|
||||||
Packet packet = Packet(MessageType::EntityDeleted);
|
if (shouldSendToClient(EntityWrapper(m_World, e.DeletedEntity))) {
|
||||||
packet.WritePrimitive<EntityID>(e.DeletedEntity);
|
Packet packet = Packet(MessageType::EntityDeleted);
|
||||||
broadcast(packet);
|
packet.WritePrimitive<EntityID>(e.DeletedEntity);
|
||||||
|
broadcast(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -445,10 +454,12 @@ bool Server::OnEntityDeleted(const Events::EntityDeleted & e)
|
|||||||
bool Server::OnComponentDeleted(const Events::ComponentDeleted & e)
|
bool Server::OnComponentDeleted(const Events::ComponentDeleted & e)
|
||||||
{
|
{
|
||||||
if (!e.Cascaded) {
|
if (!e.Cascaded) {
|
||||||
Packet packet = Packet(MessageType::ComponentDeleted);
|
if (shouldSendToClient(EntityWrapper(m_World, e.Entity))) {
|
||||||
packet.WritePrimitive<EntityID>(e.Entity);
|
Packet packet = Packet(MessageType::ComponentDeleted);
|
||||||
packet.WriteString(e.ComponentType);
|
packet.WritePrimitive<EntityID>(e.Entity);
|
||||||
broadcast(packet);
|
packet.WriteString(e.ComponentType);
|
||||||
|
broadcast(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -484,3 +495,8 @@ void Server::parsePlayerTransform(Packet& packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Server::shouldSendToClient(EntityWrapper childEntity)
|
||||||
|
{
|
||||||
|
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user