timestep logic added, but is not used.
This commit is contained in:
@@ -89,7 +89,7 @@ private:
|
|||||||
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 parseOnInputCommand(Packet& packet);
|
void parseOnInputCommand(Packet& packet);
|
||||||
void publishInputCommands(double dt);
|
void publishInputCommands();
|
||||||
void identifyPacketLoss();
|
void identifyPacketLoss();
|
||||||
void hasServerTimedOut();
|
void hasServerTimedOut();
|
||||||
EntityID createPlayer();
|
EntityID createPlayer();
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ private:
|
|||||||
int checkTimeOutInterval = 100;
|
int checkTimeOutInterval = 100;
|
||||||
int m_NextPlayerID = 0;
|
int m_NextPlayerID = 0;
|
||||||
std::vector<Events::InputCommand> m_InputCommandsToBroadcast;
|
std::vector<Events::InputCommand> m_InputCommandsToBroadcast;
|
||||||
|
std::vector<Events::InputCommand> m_InputCommandsToPublish;
|
||||||
//Timers
|
//Timers
|
||||||
std::clock_t m_StartPingTime;
|
std::clock_t m_StartPingTime;
|
||||||
|
|
||||||
@@ -82,6 +83,7 @@ private:
|
|||||||
void parseTCPConnect(Packet & packet);
|
void parseTCPConnect(Packet & packet);
|
||||||
void parseDisconnect();
|
void parseDisconnect();
|
||||||
bool shouldSendToClient(EntityWrapper childEntity);
|
bool shouldSendToClient(EntityWrapper childEntity);
|
||||||
|
void publishInputCommands();
|
||||||
|
|
||||||
// Debug event
|
// Debug event
|
||||||
EventRelay<Server, Events::InputCommand> m_EInputCommand;
|
EventRelay<Server, Events::InputCommand> m_EInputCommand;
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ void Client::Connect(std::string address, int port)
|
|||||||
void Client::Update(double dt)
|
void Client::Update(double dt)
|
||||||
{
|
{
|
||||||
m_EventBroker->Process<Client>();
|
m_EventBroker->Process<Client>();
|
||||||
m_TimeStamp += dt;
|
//m_TimeStamp += dt;
|
||||||
publishInputCommands(dt);
|
publishInputCommands();
|
||||||
while (m_Unreliable.IsSocketAvailable()) {
|
while (m_Unreliable.IsSocketAvailable()) {
|
||||||
// Packet will get real data in receive
|
// Packet will get real data in receive
|
||||||
Packet packet(MessageType::Invalid);
|
Packet packet(MessageType::Invalid);
|
||||||
@@ -74,8 +74,9 @@ void Client::Update(double dt)
|
|||||||
sendInputCommands();
|
sendInputCommands();
|
||||||
m_TimeSinceSentInputs = std::clock();
|
m_TimeSinceSentInputs = std::clock();
|
||||||
}
|
}
|
||||||
// HACK: Send absolute player positions for now to avoid desync until we have reliable messages
|
// HACK: Send absolute player positions for now to avoid desync until we have reliable messages.
|
||||||
//sendLocalPlayerTransform();
|
// Reliable messages and timestamps did not fix it.
|
||||||
|
sendLocalPlayerTransform();
|
||||||
|
|
||||||
hasServerTimedOut();
|
hasServerTimedOut();
|
||||||
}
|
}
|
||||||
@@ -307,6 +308,13 @@ void Client::parseSnapshot(Packet& packet)
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
// Read timestamp
|
||||||
|
double remoteTimestamp = packet.ReadPrimitive<double>();
|
||||||
|
//if (abs(remoteTimestamp - m_TimeStamp) > 0.100) {
|
||||||
|
// m_TimeStamp = remoteTimestamp;
|
||||||
|
// LOG_INFO("Resynced remote and local timestamp");
|
||||||
|
//}
|
||||||
|
|
||||||
// Read world state
|
// Read world state
|
||||||
while (packet.DataReadSize() < packet.Size()) {
|
while (packet.DataReadSize() < packet.Size()) {
|
||||||
EntityID serverEntityID = packet.ReadPrimitive<EntityID>();
|
EntityID serverEntityID = packet.ReadPrimitive<EntityID>();
|
||||||
@@ -382,12 +390,12 @@ void Client::parseOnInputCommand(Packet & packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::publishInputCommands(double dt)
|
void Client::publishInputCommands()
|
||||||
{
|
{
|
||||||
std::vector<Events::InputCommand> notPublishedEvents;
|
std::vector<Events::InputCommand> notPublishedEvents;
|
||||||
for (int i = 0; i < m_ReceivedInputCommands.size(); i++) {
|
for (int i = 0; i < m_ReceivedInputCommands.size(); i++) {
|
||||||
if (m_ReceivedInputCommands.at(i).TimeStamp < m_TimeStamp) {
|
if (m_ReceivedInputCommands.at(i).TimeStamp < m_TimeStamp) {
|
||||||
m_EventBroker->Publish(m_ReceivedInputCommands.at(i).TimeStamp);
|
m_EventBroker->Publish(m_ReceivedInputCommands.at(i));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
notPublishedEvents.push_back(m_ReceivedInputCommands.at(i));
|
notPublishedEvents.push_back(m_ReceivedInputCommands.at(i));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "Network/Server.h"
|
#include "Network/Server.h"
|
||||||
|
|
||||||
Server::Server(World* world, EventBroker* eventBroker, int port)
|
Server::Server(World* world, EventBroker* eventBroker, int port)
|
||||||
: Network(world, eventBroker)
|
: Network(world, eventBroker)
|
||||||
{
|
{
|
||||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
@@ -30,6 +30,7 @@ void Server::Update(double dt)
|
|||||||
{
|
{
|
||||||
m_EventBroker->Process<Server>();
|
m_EventBroker->Process<Server>();
|
||||||
m_TimeStamp += dt;
|
m_TimeStamp += dt;
|
||||||
|
publishInputCommands();
|
||||||
PlayerDefinition pd;
|
PlayerDefinition pd;
|
||||||
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
|
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
|
||||||
for (auto& kv : m_ConnectedPlayers) {
|
for (auto& kv : m_ConnectedPlayers) {
|
||||||
@@ -118,7 +119,7 @@ void Server::parseMessageType(Packet& packet)
|
|||||||
parseOnPlayerDamage(packet);
|
parseOnPlayerDamage(packet);
|
||||||
break;
|
break;
|
||||||
case MessageType::PlayerTransform:
|
case MessageType::PlayerTransform:
|
||||||
// parsePlayerTransform(packet);
|
parsePlayerTransform(packet);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -146,6 +147,7 @@ void Server::sendSnapshot()
|
|||||||
{
|
{
|
||||||
Packet packet(MessageType::Snapshot);
|
Packet packet(MessageType::Snapshot);
|
||||||
//addInputCommandsToPacket(packet);
|
//addInputCommandsToPacket(packet);
|
||||||
|
packet.WritePrimitive(m_TimeStamp/*+ somePingvalue + offset*/);
|
||||||
addChildrenToPacket(packet, EntityID_Invalid);
|
addChildrenToPacket(packet, EntityID_Invalid);
|
||||||
unreliableBroadcast(packet);
|
unreliableBroadcast(packet);
|
||||||
}
|
}
|
||||||
@@ -280,7 +282,7 @@ void Server::parseTCPConnect(Packet & packet)
|
|||||||
// Read packet ID
|
// Read packet ID
|
||||||
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
m_PreviousPacketID = m_PacketID; // Set previous packet id
|
||||||
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
m_PacketID = packet.ReadPrimitive<int>(); //Read new packet id
|
||||||
|
|
||||||
LOG_INFO("Parsing connections");
|
LOG_INFO("Parsing connections");
|
||||||
// Check if player is already connected
|
// Check if player is already connected
|
||||||
// Ska vara till lagd i TCPServer receive
|
// Ska vara till lagd i TCPServer receive
|
||||||
@@ -333,6 +335,7 @@ void Server::disconnect(PlayerID playerID)
|
|||||||
e.PlayerID = playerID;
|
e.PlayerID = playerID;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
//m_World->DeleteEntity(m_ConnectedPlayers[playerID].EntityID);
|
//m_World->DeleteEntity(m_ConnectedPlayers[playerID].EntityID);
|
||||||
|
// TODO Kolla Anders crashade efter timeout med break point
|
||||||
m_ConnectedPlayers[playerID].TCPSocket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
m_ConnectedPlayers[playerID].TCPSocket->shutdown(boost::asio::ip::tcp::socket::shutdown_both);
|
||||||
m_ConnectedPlayers[playerID].TCPSocket->close();
|
m_ConnectedPlayers[playerID].TCPSocket->close();
|
||||||
m_World->DeleteEntity(m_ConnectedPlayers[playerID].EntityID);
|
m_World->DeleteEntity(m_ConnectedPlayers[playerID].EntityID);
|
||||||
@@ -375,8 +378,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,8 +469,8 @@ 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>();
|
||||||
e.TimeStamp = packet.ReadPrimitive<double>();
|
e.TimeStamp = packet.ReadPrimitive<double>();
|
||||||
/* m_EventBroker->Publish(e);*/
|
/* m_EventBroker->Publish(e);*/
|
||||||
|
m_InputCommandsToPublish.push_back(e);
|
||||||
if (e.Command == "PrimaryFire" || e.Command == "Reload") {
|
if (e.Command == "PrimaryFire" || e.Command == "Reload") {
|
||||||
m_InputCommandsToBroadcast.push_back(e);
|
m_InputCommandsToBroadcast.push_back(e);
|
||||||
}
|
}
|
||||||
@@ -518,6 +520,20 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
|
|||||||
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid();
|
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::publishInputCommands()
|
||||||
|
{
|
||||||
|
std::vector<Events::InputCommand> notPublishedEvents;
|
||||||
|
for (int i = 0; i < m_InputCommandsToPublish.size(); i++) {
|
||||||
|
if (m_InputCommandsToPublish.at(i).TimeStamp < m_TimeStamp) {
|
||||||
|
m_EventBroker->Publish(m_InputCommandsToPublish.at(i));
|
||||||
|
} else {
|
||||||
|
LOG_INFO("Did not instantly publish command");
|
||||||
|
notPublishedEvents.push_back(m_InputCommandsToPublish.at(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_InputCommandsToPublish = notPublishedEvents;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerID Server::GetPlayerIDFromEndpoint()
|
PlayerID Server::GetPlayerIDFromEndpoint()
|
||||||
{
|
{
|
||||||
// check both tcp and udp connection
|
// check both tcp and udp connection
|
||||||
|
|||||||
@@ -16,14 +16,8 @@ PlayerMovementSystem::~PlayerMovementSystem()
|
|||||||
void PlayerMovementSystem::Update(double dt)
|
void PlayerMovementSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
updateMovementControllers(dt);
|
updateMovementControllers(dt);
|
||||||
if (IsServer) {
|
if (LocalPlayer.Valid()) {
|
||||||
for (auto& kv : m_PlayerInputControllers) {
|
updateVelocity(LocalPlayer, dt);
|
||||||
updateVelocity(kv.first, dt);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (LocalPlayer.Valid()) {
|
|
||||||
updateVelocity(LocalPlayer, dt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user