Renamted SynchronizationProtocol to LatencyProtocol.
This commit is contained in:
parent
6053ad207f
commit
de0f153f0c
@ -1,5 +1,5 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/network_player_profile.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/stk_host.hpp"
|
||||
#include "network/stk_peer.hpp"
|
||||
@ -318,9 +318,9 @@ void ClientLobby::update(float dt)
|
||||
screen->push();
|
||||
m_state = SELECTING_KARTS;
|
||||
|
||||
Protocol *p = new SynchronizationProtocol();
|
||||
Protocol *p = new LatencyProtocol();
|
||||
p->requestStart();
|
||||
Log::info("LobbyProtocol", "SynchronizationProtocol started.");
|
||||
Log::info("LobbyProtocol", "LatencyProtocol started.");
|
||||
}
|
||||
break;
|
||||
case SELECTING_KARTS:
|
||||
@ -617,7 +617,7 @@ void ClientLobby::startingRaceNow()
|
||||
NetworkString *ns = getNetworkString(2);
|
||||
ns->addUInt8(LE_STARTED_RACE);
|
||||
sendToServer(ns, /*reliable*/true);
|
||||
terminateSynchronizationProtocol();
|
||||
terminateLatencyProtocol();
|
||||
} // startingRaceNow
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "network/protocols/synchronization_protocol.hpp"
|
||||
#include "network/protocols/latency_protocol.hpp"
|
||||
|
||||
#include "network/event.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
@ -17,8 +17,8 @@
|
||||
* for a message requires the protocol lock) - causing at least two frames
|
||||
* of significanlty delayed pings :(
|
||||
*/
|
||||
SynchronizationProtocol::SynchronizationProtocol()
|
||||
: Protocol(PROTOCOL_SYNCHRONIZATION)
|
||||
LatencyProtocol::LatencyProtocol()
|
||||
: Protocol(PROTOCOL_SYNCHRONIZATION)
|
||||
{
|
||||
unsigned int size = STKHost::get()->getPeerCount();
|
||||
m_pings.resize(size, std::map<uint32_t,double>());
|
||||
@ -26,17 +26,17 @@ SynchronizationProtocol::SynchronizationProtocol()
|
||||
m_total_diff.resize(size, 0);
|
||||
m_average_ping.resize(size, 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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -45,7 +45,7 @@ void SynchronizationProtocol::setup()
|
||||
* is a reply to a previous ping request. The server will keep track of
|
||||
* average latency.
|
||||
*/
|
||||
bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
bool LatencyProtocol::notifyEventAsynchronous(Event* event)
|
||||
{
|
||||
if (event->getType() != EVENT_TYPE_MESSAGE)
|
||||
return true;
|
||||
@ -80,7 +80,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
response->addUInt8(0).addUInt32(sequence);
|
||||
event->getPeer()->sendPacket(response, false);
|
||||
delete response;
|
||||
Log::verbose("SynchronizationProtocol", "Answering sequence %u at %lf",
|
||||
Log::verbose("LatencyProtocol", "Answering sequence %u at %lf",
|
||||
sequence, StkTime::getRealTime());
|
||||
}
|
||||
else // receive response to a ping request
|
||||
@ -89,7 +89,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
assert(NetworkConfig::get()->isServer());
|
||||
if (sequence >= m_pings[peer_id].size())
|
||||
{
|
||||
Log::warn("SynchronizationProtocol",
|
||||
Log::warn("LatencyProtocol",
|
||||
"The sequence# %u isn't known.", sequence);
|
||||
return true;
|
||||
}
|
||||
@ -99,7 +99,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
m_average_ping[peer_id] =
|
||||
(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_id, sequence,
|
||||
(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
|
||||
* between server and client.
|
||||
*/
|
||||
void SynchronizationProtocol::asynchronousUpdate()
|
||||
void LatencyProtocol::asynchronousUpdate()
|
||||
{
|
||||
float current_time = float(StkTime::getRealTime());
|
||||
if (NetworkConfig::get()->isServer() && current_time > m_last_time+1)
|
||||
@ -131,7 +131,7 @@ void SynchronizationProtocol::asynchronousUpdate()
|
||||
NetworkString *ping_request =
|
||||
getNetworkString(5);
|
||||
ping_request->addUInt8(1).addUInt32(m_pings[i].size());
|
||||
Log::verbose("SynchronizationProtocol",
|
||||
Log::verbose("LatencyProtocol",
|
||||
"Added sequence number %u for peer %d at %lf",
|
||||
m_pings[i].size(), i, StkTime::getRealTime());
|
||||
m_pings[i] [ m_pings_count ] = current_time;
|
@ -1,5 +1,5 @@
|
||||
#ifndef SYNCHRONIZATION_PROTOCOL_HPP
|
||||
#define SYNCHRONIZATION_PROTOCOL_HPP
|
||||
#ifndef LATENCY_PROTOCOL_HPP
|
||||
#define LATENCY_PROTOCOL_HPP
|
||||
|
||||
#include "network/protocol.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
@ -7,7 +7,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class SynchronizationProtocol : public Protocol
|
||||
class LatencyProtocol : public Protocol
|
||||
{
|
||||
private:
|
||||
std::vector<std::map<uint32_t, double> > m_pings;
|
||||
@ -23,8 +23,8 @@ private:
|
||||
|
||||
|
||||
public:
|
||||
SynchronizationProtocol();
|
||||
virtual ~SynchronizationProtocol();
|
||||
LatencyProtocol();
|
||||
virtual ~LatencyProtocol();
|
||||
|
||||
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
|
||||
virtual void setup() OVERRIDE;
|
||||
@ -33,6 +33,6 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void update(float dt) OVERRIDE {}
|
||||
|
||||
}; // class SynchronizationProtocol
|
||||
}; // class LatencyProtocol
|
||||
|
||||
#endif // SYNCHRONIZATION_PROTOCOL_HPP
|
||||
#endif // LATENCY_PROTOCOL_HPP
|
@ -27,7 +27,7 @@
|
||||
#include "network/protocols/controller_events_protocol.hpp"
|
||||
#include "network/protocols/game_events_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/stk_host.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
@ -131,13 +131,13 @@ void LobbyProtocol::loadWorld()
|
||||
} // loadWorld
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Terminates the SynchronizationProtocol.
|
||||
/** Terminates the LatencyProtocol.
|
||||
*/
|
||||
void LobbyProtocol::terminateSynchronizationProtocol()
|
||||
void LobbyProtocol::terminateLatencyProtocol()
|
||||
{
|
||||
Protocol *p = ProtocolManager::getInstance()
|
||||
->getProtocol(PROTOCOL_SYNCHRONIZATION);
|
||||
SynchronizationProtocol *sp = dynamic_cast<SynchronizationProtocol*>(p);
|
||||
LatencyProtocol *sp = dynamic_cast<LatencyProtocol*>(p);
|
||||
if (sp)
|
||||
sp->requestTerminate();
|
||||
} // stopSynchronizationProtocol
|
||||
} // stopLatencyProtocol
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
virtual void update(float dt) = 0;
|
||||
virtual void finishedLoadingWorld() = 0;
|
||||
virtual void loadWorld();
|
||||
void terminateSynchronizationProtocol();
|
||||
void terminateLatencyProtocol();
|
||||
virtual void requestKartSelection(uint8_t player_id,
|
||||
const std::string &kart_name)
|
||||
{
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "network/network_player_profile.hpp"
|
||||
#include "network/protocols/get_public_address.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/race_event_manager.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
@ -365,9 +365,9 @@ void ServerLobby::startSelection(const Event *event)
|
||||
m_state = SELECTING;
|
||||
WaitingForOthersScreen::getInstance()->push();
|
||||
|
||||
Protocol *p = new SynchronizationProtocol();
|
||||
Protocol *p = new LatencyProtocol();
|
||||
p->requestStart();
|
||||
Log::info("LobbyProtocol", "SynchronizationProtocol started.");
|
||||
Log::info("LobbyProtocol", "LatencyProtocol started.");
|
||||
|
||||
} // startSelection
|
||||
|
||||
@ -913,7 +913,7 @@ void ServerLobby::startedRaceOnClient(Event *event)
|
||||
if (m_client_ready_count.getData() == m_game_setup->getPlayerCount())
|
||||
{
|
||||
m_state = DELAY_SERVER;
|
||||
terminateSynchronizationProtocol();
|
||||
terminateLatencyProtocol();
|
||||
}
|
||||
m_client_ready_count.unlock();
|
||||
} // startedRaceOnClient
|
||||
|
@ -217,13 +217,13 @@ void STKHost::create()
|
||||
* LocalPlayerController for each kart. Each remote player gets a
|
||||
* NULL ActivePlayer (the ActivePlayer is only used for assigning the input
|
||||
* 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.
|
||||
|
||||
* TODO:
|
||||
* Once the server has received all
|
||||
* 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
|
||||
* the averate latency. Upon starting the countdown this information
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user