Pull request #136 Merge remote-tracking branch 'origin/master' into FixNetworkBugs
# Conflicts: # src/Engine/Network/Client.cpp
This commit is contained in:
@@ -107,7 +107,6 @@ private:
|
|||||||
void parseDoubleJump(Packet& packet);
|
void parseDoubleJump(Packet& packet);
|
||||||
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||||
void parseSnapshot(Packet& packet);
|
void parseSnapshot(Packet& packet);
|
||||||
void UpdateLocalCapturePointHUD(EntityWrapper capturePointHUD);
|
|
||||||
void identifyPacketLoss();
|
void identifyPacketLoss();
|
||||||
void hasServerTimedOut();
|
void hasServerTimedOut();
|
||||||
EntityID createPlayer();
|
EntityID createPlayer();
|
||||||
|
|||||||
@@ -367,9 +367,6 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
// Update entity
|
// Update entity
|
||||||
if (m_World->HasComponent(localEntityID, componentType)) {
|
if (m_World->HasComponent(localEntityID, componentType)) {
|
||||||
// TODO Fix memory leak here
|
// TODO Fix memory leak here
|
||||||
if (localEntity.Name() == "CapturePointHUD") {
|
|
||||||
UpdateLocalCapturePointHUD(localEntity);
|
|
||||||
}
|
|
||||||
SharedComponentWrapper newComponent = createSharedComponent(packet, localEntityID, componentInfo);
|
SharedComponentWrapper newComponent = createSharedComponent(packet, localEntityID, componentInfo);
|
||||||
bool shouldApply = true;
|
bool shouldApply = true;
|
||||||
// Apply potential filter function
|
// Apply potential filter function
|
||||||
@@ -397,7 +394,11 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
if (serverParentID == EntityID_Invalid) {
|
if (serverParentID == EntityID_Invalid) {
|
||||||
newLocalEntityID = m_World->CreateEntity(EntityID_Invalid);
|
newLocalEntityID = m_World->CreateEntity(EntityID_Invalid);
|
||||||
} else {
|
} else {
|
||||||
newLocalEntityID = m_World->CreateEntity(m_ServerIDToClientID.at(serverParentID));
|
if (serverClientMapsHasEntity(serverParentID)) {
|
||||||
|
newLocalEntityID = m_World->CreateEntity(m_ServerIDToClientID.at(serverParentID));
|
||||||
|
} else {
|
||||||
|
newLocalEntityID = m_World->CreateEntity(EntityID_Invalid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_World->SetName(newLocalEntityID, serverEntityName);
|
m_World->SetName(newLocalEntityID, serverEntityName);
|
||||||
insertIntoServerClientMaps(serverEntityID, newLocalEntityID);
|
insertIntoServerClientMaps(serverEntityID, newLocalEntityID);
|
||||||
@@ -407,7 +408,7 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
}
|
}
|
||||||
// Parent logic
|
// Parent logic
|
||||||
// This should be enough beacause we know that the entities arives in pre-order (there will always be a parent)
|
// This should be enough beacause we know that the entities arives in pre-order (there will always be a parent)
|
||||||
if (serverParentID != EntityID_Invalid) {
|
if (serverParentID != EntityID_Invalid && serverClientMapsHasEntity(serverParentID)) {
|
||||||
EntityID localEntityID = m_ServerIDToClientID.at(serverEntityID);
|
EntityID localEntityID = m_ServerIDToClientID.at(serverEntityID);
|
||||||
if (m_World->GetParent(localEntityID) != m_ServerIDToClientID.at(serverParentID)) {
|
if (m_World->GetParent(localEntityID) != m_ServerIDToClientID.at(serverParentID)) {
|
||||||
m_World->SetParent(localEntityID, m_ServerIDToClientID.at(serverParentID));
|
m_World->SetParent(localEntityID, m_ServerIDToClientID.at(serverParentID));
|
||||||
@@ -417,18 +418,6 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
parseSpawnEvents();
|
parseSpawnEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Client::UpdateLocalCapturePointHUD(EntityWrapper capturePointHUD)
|
|
||||||
{
|
|
||||||
//auto children = m_World->GetChildren(capturePointHUD.ID);
|
|
||||||
//for (auto it = children.first; it != children.second; it++) {
|
|
||||||
// it->first
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//EntityWrapper& localHUD = m_LocalPlayer.FirstChildByName("HUD").FirstChildByName("CapturePointHUD");
|
|
||||||
//m_World->GetComponentPools()
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::disconnect()
|
void Client::disconnect()
|
||||||
{
|
{
|
||||||
m_IsConnected = false;
|
m_IsConnected = false;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void Server::Update()
|
|||||||
PlayerDefinition localArea;
|
PlayerDefinition localArea;
|
||||||
localArea.Endpoint = boost::asio::ip::udp::endpoint();
|
localArea.Endpoint = boost::asio::ip::udp::endpoint();
|
||||||
m_ServerlistRequest.Receive(packet, localArea);
|
m_ServerlistRequest.Receive(packet, localArea);
|
||||||
if(packet.GetMessageType() == MessageType::ServerlistRequest) {
|
if (packet.GetMessageType() == MessageType::ServerlistRequest) {
|
||||||
packet.ReadPrimitive<int>(); // Pop size
|
packet.ReadPrimitive<int>(); // Pop size
|
||||||
packet.ReadPrimitive<int>(); // Pop MsgType
|
packet.ReadPrimitive<int>(); // Pop MsgType
|
||||||
packet.ReadPrimitive<int>(); // Pop packet ID
|
packet.ReadPrimitive<int>(); // Pop packet ID
|
||||||
@@ -76,7 +76,7 @@ void Server::Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if players have disconnected
|
// Check if players have disconnected
|
||||||
for (int i = 0; i < m_PlayersToDisconnect.size(); i++) {
|
for (int i = 0; i < m_PlayersToDisconnect.size(); i++) {
|
||||||
disconnect(m_PlayersToDisconnect.at(i));
|
disconnect(m_PlayersToDisconnect.at(i));
|
||||||
}
|
}
|
||||||
m_PlayersToDisconnect.clear();
|
m_PlayersToDisconnect.clear();
|
||||||
@@ -136,7 +136,7 @@ void Server::parseMessageType(Packet& packet)
|
|||||||
parseOnPlayerDamage(packet);
|
parseOnPlayerDamage(packet);
|
||||||
break;
|
break;
|
||||||
case MessageType::PlayerTransform:
|
case MessageType::PlayerTransform:
|
||||||
parsePlayerTransform(packet);
|
parsePlayerTransform(packet);
|
||||||
break;
|
break;
|
||||||
case MessageType::OnDoubleJump:
|
case MessageType::OnDoubleJump:
|
||||||
parseDoubleJump(packet);
|
parseDoubleJump(packet);
|
||||||
@@ -194,43 +194,41 @@ void Server::addPlayersToPacket(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
|
// 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
|
||||||
// HACK: Also checked CapturePointHUD for now. (this would get out of sync);
|
// HACK: Also checked CapturePointHUD for now. (this would get out of sync);
|
||||||
EntityWrapper childEntity(m_World, childEntityID);
|
EntityWrapper childEntity(m_World, childEntityID);
|
||||||
if (!shouldSendToClient(childEntity)) {
|
if (shouldSendToClient(childEntity)) {
|
||||||
continue;
|
// Write EntityID and parentsID and Entity name
|
||||||
}
|
packet.WritePrimitive(childEntityID);
|
||||||
|
packet.WritePrimitive(entityID);
|
||||||
// Write EntityID and parentsID and Entity name
|
packet.WriteString(m_World->GetName(childEntityID));
|
||||||
packet.WritePrimitive(childEntityID);
|
// Write components to child
|
||||||
packet.WritePrimitive(entityID);
|
int numberOfComponents = 0;
|
||||||
packet.WriteString(m_World->GetName(childEntityID));
|
for (auto& i : worldComponentPools) {
|
||||||
// Write components to child
|
if (i.second->KnowsEntity(childEntityID)) {
|
||||||
int numberOfComponents = 0;
|
numberOfComponents++;
|
||||||
for (auto& i : worldComponentPools) {
|
}
|
||||||
if (i.second->KnowsEntity(childEntityID)) {
|
|
||||||
numberOfComponents++;
|
|
||||||
}
|
}
|
||||||
}
|
// Write how many components should be read
|
||||||
// Write how many components should be read
|
packet.WritePrimitive(numberOfComponents);
|
||||||
packet.WritePrimitive(numberOfComponents);
|
for (auto& i : worldComponentPools) {
|
||||||
for (auto& i : worldComponentPools) {
|
// If the entity exist in the pool
|
||||||
// If the entity exist in the pool
|
if (i.second->KnowsEntity(childEntityID)) {
|
||||||
if (i.second->KnowsEntity(childEntityID)) {
|
ComponentWrapper componentWrapper = i.second->GetByEntity(childEntityID);
|
||||||
ComponentWrapper componentWrapper = i.second->GetByEntity(childEntityID);
|
// ComponentType
|
||||||
// ComponentType
|
packet.WriteString(componentWrapper.Info.Name);
|
||||||
packet.WriteString(componentWrapper.Info.Name);
|
// Loop through fields
|
||||||
// Loop through fields
|
for (auto& componentField : componentWrapper.Info.FieldsInOrder) {
|
||||||
for (auto& componentField : componentWrapper.Info.FieldsInOrder) {
|
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
|
||||||
ComponentInfo::Field_t fieldInfo = componentWrapper.Info.Fields.at(componentField);
|
if (fieldInfo.Type == "string") {
|
||||||
if (fieldInfo.Type == "string") {
|
std::string& value = componentWrapper[componentField];
|
||||||
std::string& value = componentWrapper[componentField];
|
packet.WriteString(value);
|
||||||
packet.WriteString(value);
|
} else {
|
||||||
} else {
|
packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride);
|
||||||
packet.WriteData(componentWrapper.Data + fieldInfo.Offset, fieldInfo.Stride);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Go to to your children
|
// Go to to your children
|
||||||
addChildrenToPacket(packet, childEntityID);
|
addPlayersToPacket(packet, childEntityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,8 +456,7 @@ bool Server::OnInputCommand(const Events::InputCommand & e)
|
|||||||
}
|
}
|
||||||
isReadingData = !isReadingData;
|
isReadingData = !isReadingData;
|
||||||
m_SaveDataTimer = std::clock();
|
m_SaveDataTimer = std::clock();
|
||||||
}
|
} else if (e.Command == "KickPlayer" && e.Value > 0) {
|
||||||
else if (e.Command == "KickPlayer" && e.Value > 0) {
|
|
||||||
kick(0);
|
kick(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,8 +601,15 @@ void Server::parsePlayerTransform(Packet& packet)
|
|||||||
|
|
||||||
bool Server::shouldSendToClient(EntityWrapper childEntity)
|
bool Server::shouldSendToClient(EntityWrapper childEntity)
|
||||||
{
|
{
|
||||||
|
auto children = m_World->GetChildren(childEntity.ID);
|
||||||
|
for (auto it = children.first; it != children.second; it++) {
|
||||||
|
EntityWrapper child(m_World, it->second);
|
||||||
|
if(child.HasComponent("CapturePoint")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|
||||||
|| childEntity.HasComponent("CapturePoint") || childEntity.FirstParentWithComponent("CapturePoint").Valid();
|
|| childEntity.HasComponent("CapturePoint");
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerID Server::GetPlayerIDFromEndpoint()
|
PlayerID Server::GetPlayerIDFromEndpoint()
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
|
|||||||
, PureSystem("CapturePoint")
|
, PureSystem("CapturePoint")
|
||||||
{
|
{
|
||||||
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
|
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
|
if (!IsClient) {
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
|
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
|
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +18,9 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
|
|||||||
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
|
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
|
||||||
void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt)
|
void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt)
|
||||||
{
|
{
|
||||||
|
if (IsClient) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m_WinnerWasFound) {
|
if (m_WinnerWasFound) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user