Renamted SynchronizationProtocol to LatencyProtocol.

This commit is contained in:
hiker 2016-11-28 08:45:17 +11:00
parent 6053ad207f
commit de0f153f0c
8 changed files with 39 additions and 39 deletions

View File

@ -24,7 +24,7 @@
#include "network/network_config.hpp" #include "network/network_config.hpp"
#include "network/network_player_profile.hpp" #include "network/network_player_profile.hpp"
#include "network/protocol_manager.hpp" #include "network/protocol_manager.hpp"
#include "network/protocols/synchronization_protocol.hpp" #include "network/protocols/latency_protocol.hpp"
#include "network/race_event_manager.hpp" #include "network/race_event_manager.hpp"
#include "network/stk_host.hpp" #include "network/stk_host.hpp"
#include "network/stk_peer.hpp" #include "network/stk_peer.hpp"
@ -318,9 +318,9 @@ void ClientLobby::update(float dt)
screen->push(); screen->push();
m_state = SELECTING_KARTS; m_state = SELECTING_KARTS;
Protocol *p = new SynchronizationProtocol(); Protocol *p = new LatencyProtocol();
p->requestStart(); p->requestStart();
Log::info("LobbyProtocol", "SynchronizationProtocol started."); Log::info("LobbyProtocol", "LatencyProtocol started.");
} }
break; break;
case SELECTING_KARTS: case SELECTING_KARTS:
@ -617,7 +617,7 @@ void ClientLobby::startingRaceNow()
NetworkString *ns = getNetworkString(2); NetworkString *ns = getNetworkString(2);
ns->addUInt8(LE_STARTED_RACE); ns->addUInt8(LE_STARTED_RACE);
sendToServer(ns, /*reliable*/true); sendToServer(ns, /*reliable*/true);
terminateSynchronizationProtocol(); terminateLatencyProtocol();
} // startingRaceNow } // startingRaceNow
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
#include "network/protocols/synchronization_protocol.hpp" #include "network/protocols/latency_protocol.hpp"
#include "network/event.hpp" #include "network/event.hpp"
#include "network/network_config.hpp" #include "network/network_config.hpp"
@ -17,7 +17,7 @@
* for a message requires the protocol lock) - causing at least two frames * for a message requires the protocol lock) - causing at least two frames
* of significanlty delayed pings :( * of significanlty delayed pings :(
*/ */
SynchronizationProtocol::SynchronizationProtocol() LatencyProtocol::LatencyProtocol()
: Protocol(PROTOCOL_SYNCHRONIZATION) : Protocol(PROTOCOL_SYNCHRONIZATION)
{ {
unsigned int size = STKHost::get()->getPeerCount(); unsigned int size = STKHost::get()->getPeerCount();
@ -26,17 +26,17 @@ SynchronizationProtocol::SynchronizationProtocol()
m_total_diff.resize(size, 0); m_total_diff.resize(size, 0);
m_average_ping.resize(size, 0); m_average_ping.resize(size, 0);
m_pings_count = 0; m_pings_count = 0;
} // SynchronizationProtocol } // LatencyProtocol
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
SynchronizationProtocol::~SynchronizationProtocol() LatencyProtocol::~LatencyProtocol()
{ {
} // ~SynchronizationProtocol } // ~LatencyProtocol
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SynchronizationProtocol::setup() void LatencyProtocol::setup()
{ {
Log::info("SynchronizationProtocol", "Ready !"); Log::info("LatencyProtocol", "Ready !");
} // setup } // setup
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -45,7 +45,7 @@ void SynchronizationProtocol::setup()
* is a reply to a previous ping request. The server will keep track of * is a reply to a previous ping request. The server will keep track of
* average latency. * average latency.
*/ */
bool SynchronizationProtocol::notifyEventAsynchronous(Event* event) bool LatencyProtocol::notifyEventAsynchronous(Event* event)
{ {
if (event->getType() != EVENT_TYPE_MESSAGE) if (event->getType() != EVENT_TYPE_MESSAGE)
return true; return true;
@ -80,7 +80,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
response->addUInt8(0).addUInt32(sequence); response->addUInt8(0).addUInt32(sequence);
event->getPeer()->sendPacket(response, false); event->getPeer()->sendPacket(response, false);
delete response; delete response;
Log::verbose("SynchronizationProtocol", "Answering sequence %u at %lf", Log::verbose("LatencyProtocol", "Answering sequence %u at %lf",
sequence, StkTime::getRealTime()); sequence, StkTime::getRealTime());
} }
else // receive response to a ping request else // receive response to a ping request
@ -89,7 +89,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
assert(NetworkConfig::get()->isServer()); assert(NetworkConfig::get()->isServer());
if (sequence >= m_pings[peer_id].size()) if (sequence >= m_pings[peer_id].size())
{ {
Log::warn("SynchronizationProtocol", Log::warn("LatencyProtocol",
"The sequence# %u isn't known.", sequence); "The sequence# %u isn't known.", sequence);
return true; return true;
} }
@ -99,7 +99,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
m_average_ping[peer_id] = m_average_ping[peer_id] =
(int)((m_total_diff[peer_id]/m_successed_pings[peer_id])*1000.0); (int)((m_total_diff[peer_id]/m_successed_pings[peer_id])*1000.0);
Log::debug("SynchronizationProtocol", Log::debug("LatencyProtocol",
"Peer %d sequence %d ping %u average %u at %lf", "Peer %d sequence %d ping %u average %u at %lf",
peer_id, sequence, peer_id, sequence,
(unsigned int)((current_time - m_pings[peer_id][sequence])*1000), (unsigned int)((current_time - m_pings[peer_id][sequence])*1000),
@ -120,7 +120,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
* started. The measured times can be used later to estimate the latency * started. The measured times can be used later to estimate the latency
* between server and client. * between server and client.
*/ */
void SynchronizationProtocol::asynchronousUpdate() void LatencyProtocol::asynchronousUpdate()
{ {
float current_time = float(StkTime::getRealTime()); float current_time = float(StkTime::getRealTime());
if (NetworkConfig::get()->isServer() && current_time > m_last_time+1) if (NetworkConfig::get()->isServer() && current_time > m_last_time+1)
@ -131,7 +131,7 @@ void SynchronizationProtocol::asynchronousUpdate()
NetworkString *ping_request = NetworkString *ping_request =
getNetworkString(5); getNetworkString(5);
ping_request->addUInt8(1).addUInt32(m_pings[i].size()); ping_request->addUInt8(1).addUInt32(m_pings[i].size());
Log::verbose("SynchronizationProtocol", Log::verbose("LatencyProtocol",
"Added sequence number %u for peer %d at %lf", "Added sequence number %u for peer %d at %lf",
m_pings[i].size(), i, StkTime::getRealTime()); m_pings[i].size(), i, StkTime::getRealTime());
m_pings[i] [ m_pings_count ] = current_time; m_pings[i] [ m_pings_count ] = current_time;

View File

@ -1,5 +1,5 @@
#ifndef SYNCHRONIZATION_PROTOCOL_HPP #ifndef LATENCY_PROTOCOL_HPP
#define SYNCHRONIZATION_PROTOCOL_HPP #define LATENCY_PROTOCOL_HPP
#include "network/protocol.hpp" #include "network/protocol.hpp"
#include "utils/cpp2011.hpp" #include "utils/cpp2011.hpp"
@ -7,7 +7,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
class SynchronizationProtocol : public Protocol class LatencyProtocol : public Protocol
{ {
private: private:
std::vector<std::map<uint32_t, double> > m_pings; std::vector<std::map<uint32_t, double> > m_pings;
@ -23,8 +23,8 @@ private:
public: public:
SynchronizationProtocol(); LatencyProtocol();
virtual ~SynchronizationProtocol(); virtual ~LatencyProtocol();
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE; virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE; virtual void setup() OVERRIDE;
@ -33,6 +33,6 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {} virtual void update(float dt) OVERRIDE {}
}; // class SynchronizationProtocol }; // class LatencyProtocol
#endif // SYNCHRONIZATION_PROTOCOL_HPP #endif // LATENCY_PROTOCOL_HPP

View File

@ -27,7 +27,7 @@
#include "network/protocols/controller_events_protocol.hpp" #include "network/protocols/controller_events_protocol.hpp"
#include "network/protocols/game_events_protocol.hpp" #include "network/protocols/game_events_protocol.hpp"
#include "network/protocols/kart_update_protocol.hpp" #include "network/protocols/kart_update_protocol.hpp"
#include "network/protocols/synchronization_protocol.hpp" #include "network/protocols/latency_protocol.hpp"
#include "network/race_event_manager.hpp" #include "network/race_event_manager.hpp"
#include "network/stk_host.hpp" #include "network/stk_host.hpp"
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
@ -131,13 +131,13 @@ void LobbyProtocol::loadWorld()
} // loadWorld } // loadWorld
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Terminates the SynchronizationProtocol. /** Terminates the LatencyProtocol.
*/ */
void LobbyProtocol::terminateSynchronizationProtocol() void LobbyProtocol::terminateLatencyProtocol()
{ {
Protocol *p = ProtocolManager::getInstance() Protocol *p = ProtocolManager::getInstance()
->getProtocol(PROTOCOL_SYNCHRONIZATION); ->getProtocol(PROTOCOL_SYNCHRONIZATION);
SynchronizationProtocol *sp = dynamic_cast<SynchronizationProtocol*>(p); LatencyProtocol *sp = dynamic_cast<LatencyProtocol*>(p);
if (sp) if (sp)
sp->requestTerminate(); sp->requestTerminate();
} // stopSynchronizationProtocol } // stopLatencyProtocol

View File

@ -95,7 +95,7 @@ public:
virtual void update(float dt) = 0; virtual void update(float dt) = 0;
virtual void finishedLoadingWorld() = 0; virtual void finishedLoadingWorld() = 0;
virtual void loadWorld(); virtual void loadWorld();
void terminateSynchronizationProtocol(); void terminateLatencyProtocol();
virtual void requestKartSelection(uint8_t player_id, virtual void requestKartSelection(uint8_t player_id,
const std::string &kart_name) const std::string &kart_name)
{ {

View File

@ -26,7 +26,7 @@
#include "network/network_player_profile.hpp" #include "network/network_player_profile.hpp"
#include "network/protocols/get_public_address.hpp" #include "network/protocols/get_public_address.hpp"
#include "network/protocols/connect_to_peer.hpp" #include "network/protocols/connect_to_peer.hpp"
#include "network/protocols/synchronization_protocol.hpp" #include "network/protocols/latency_protocol.hpp"
#include "network/protocol_manager.hpp" #include "network/protocol_manager.hpp"
#include "network/race_event_manager.hpp" #include "network/race_event_manager.hpp"
#include "network/stk_host.hpp" #include "network/stk_host.hpp"
@ -365,9 +365,9 @@ void ServerLobby::startSelection(const Event *event)
m_state = SELECTING; m_state = SELECTING;
WaitingForOthersScreen::getInstance()->push(); WaitingForOthersScreen::getInstance()->push();
Protocol *p = new SynchronizationProtocol(); Protocol *p = new LatencyProtocol();
p->requestStart(); p->requestStart();
Log::info("LobbyProtocol", "SynchronizationProtocol started."); Log::info("LobbyProtocol", "LatencyProtocol started.");
} // startSelection } // startSelection
@ -913,7 +913,7 @@ void ServerLobby::startedRaceOnClient(Event *event)
if (m_client_ready_count.getData() == m_game_setup->getPlayerCount()) if (m_client_ready_count.getData() == m_game_setup->getPlayerCount())
{ {
m_state = DELAY_SERVER; m_state = DELAY_SERVER;
terminateSynchronizationProtocol(); terminateLatencyProtocol();
} }
m_client_ready_count.unlock(); m_client_ready_count.unlock();
} // startedRaceOnClient } // startedRaceOnClient

View File

@ -217,13 +217,13 @@ void STKHost::create()
* LocalPlayerController for each kart. Each remote player gets a * LocalPlayerController for each kart. Each remote player gets a
* NULL ActivePlayer (the ActivePlayer is only used for assigning the input * NULL ActivePlayer (the ActivePlayer is only used for assigning the input
* device to each kart, achievements and highscores, so it's not needed for * device to each kart, achievements and highscores, so it's not needed for
* remote players). It will also start the SynchronizationProtocol, * remote players). It will also start the LatencyProtocol,
* RaceEventManager and then load the world. * RaceEventManager and then load the world.
* TODO: * TODO:
* Once the server has received all * Once the server has received all
* messages in notifyEventAsynchronous(), it will call startCountdown() * messages in notifyEventAsynchronous(), it will call startCountdown()
* in the SynchronizationProtocol. The SynchronizationProtocol is * in the LatencyProtocol. The LatencyProtocol is
* sending regular (once per second) pings to the clients and measure * sending regular (once per second) pings to the clients and measure
* the averate latency. Upon starting the countdown this information * the averate latency. Upon starting the countdown this information
* is included in the ping request, so the clients can start the countdown * is included in the ping request, so the clients can start the countdown
@ -231,7 +231,7 @@ void STKHost::create()
* *
* Once the countdown is 0 (or below), the Synchronization Protocol will * Once the countdown is 0 (or below), the Synchronization Protocol will
* start the protocols: KartUpdateProtocol, ControllerEventsProtocol, * start the protocols: KartUpdateProtocol, ControllerEventsProtocol,
* GameEventsProtocol. Then the SynchronizationProtocol is terminated * GameEventsProtocol. Then the LatencyProtocol is terminated
* which indicates to the main loop to start the actual game. * which indicates to the main loop to start the actual game.
*/ */