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