Fixed network bug sorta

This commit is contained in:
Tleety
2016-02-12 06:00:42 +01:00
parent d357e365cb
commit 1e04244590
2 changed files with 12 additions and 16 deletions
+2 -3
View File
@@ -181,13 +181,12 @@ void Client::parseSpawnEvents()
std::vector<Events::PlayerSpawned> tempSpawn; std::vector<Events::PlayerSpawned> tempSpawn;
for (int i = 0; i < m_PlayerSpawnEvents.size(); i++) { for (int i = 0; i < m_PlayerSpawnEvents.size(); i++) {
Events::PlayerSpawned e; Events::PlayerSpawned e;
if (!serverClientMapsHasEntity(m_PlayerSpawnEvents.at(i).Player.ID) || if (!serverClientMapsHasEntity(m_PlayerSpawnEvents.at(i).Player.ID)) {
!serverClientMapsHasEntity(m_PlayerSpawnEvents.at(i).Spawner.ID)) {
tempSpawn.push_back(m_PlayerSpawnEvents.at(i)); tempSpawn.push_back(m_PlayerSpawnEvents.at(i));
continue; continue;
} }
e.Player = EntityWrapper(m_World, m_ServerIDToClientID.at(m_PlayerSpawnEvents.at(i).Player.ID)); e.Player = EntityWrapper(m_World, m_ServerIDToClientID.at(m_PlayerSpawnEvents.at(i).Player.ID));
e.Spawner = EntityWrapper(m_World, m_ServerIDToClientID.at(m_PlayerSpawnEvents.at(i).Spawner.ID)); //e.Spawner = EntityWrapper(m_World, m_ServerIDToClientID.at(m_PlayerSpawnEvents.at(i).Spawner.ID));
e.PlayerID = -1; e.PlayerID = -1;
e.PlayerName = m_PlayerSpawnEvents.at(i).PlayerName; e.PlayerName = m_PlayerSpawnEvents.at(i).PlayerName;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
+9 -12
View File
@@ -165,17 +165,16 @@ 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 (!entity.Valid() || !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;
// 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 childEntity(m_World, childEntityID);
if (!shouldSendToClient(childEntity)) {
continue;
}
// Write EntityID and parentsID and Entity name // Write EntityID and parentsID and Entity name
packet.WritePrimitive(childEntityID); packet.WritePrimitive(childEntityID);
@@ -398,11 +397,9 @@ 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) {
if (shouldSendToClient(EntityWrapper(m_World, e.DeletedEntity))) { Packet packet = Packet(MessageType::EntityDeleted);
Packet packet = Packet(MessageType::EntityDeleted); packet.WritePrimitive<EntityID>(e.DeletedEntity);
packet.WritePrimitive<EntityID>(e.DeletedEntity); reliableBroadcast(packet);
reliableBroadcast(packet);
}
} }
return false; return false;
} }
@@ -458,7 +455,7 @@ void Server::parseOnInputCommand(Packet& packet)
e.Player = EntityWrapper(m_World, m_ConnectedPlayers.at(player).EntityID); e.Player = EntityWrapper(m_World, m_ConnectedPlayers.at(player).EntityID);
e.Value = packet.ReadPrimitive<float>(); e.Value = packet.ReadPrimitive<float>();
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
if (e.Command == "PrimaryFire") { if (e.Command == "PrimaryFire" || e.Command == "Reload") {
m_InputCommandsToBroadcast.push_back(e); m_InputCommandsToBroadcast.push_back(e);
} }
//LOG_INFO("Server::parseOnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID); //LOG_INFO("Server::parseOnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);