diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 2db85e3e5..2a3d103cd 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -34,7 +34,6 @@ #include "network/protocol_manager.hpp" #include "network/race_event_manager.hpp" #include "network/stk_host.hpp" -#include "network/protocols/synchronization_protocol.hpp" #include "online/request_manager.hpp" #include "race/history.hpp" #include "race/race_manager.hpp" @@ -291,15 +290,7 @@ void MainLoop::run() if (World::getWorld() ) { - // In case of networking world we can only start the timing once the - // SynchronizationProtocol has disappeared (which indicates that all - // other protocols necessary for running a game are running). - SynchronizationProtocol* protocol = static_cast( - ProtocolManager::getInstance()->getProtocol(PROTOCOL_SYNCHRONIZATION)); - if (!protocol) - { - World::getWorld()->updateTime(dt); - } + World::getWorld()->updateTime(dt); } PROFILER_POP_CPU_MARKER(); diff --git a/src/main_loop.hpp b/src/main_loop.hpp index eff1f520f..48d215546 100644 --- a/src/main_loop.hpp +++ b/src/main_loop.hpp @@ -28,7 +28,10 @@ typedef unsigned long Uint32; class MainLoop { private: + /** True if the main loop should exit. */ bool m_abort; + + /** True if the frame rate should be throttled. */ bool m_throttle_fps; Uint32 m_curr_time; diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index 9a5f78304..7dcfa8f54 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -17,6 +17,7 @@ #include "modes/world_status.hpp" +#include "main_loop.hpp" #include "audio/music_manager.hpp" #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" @@ -32,21 +33,6 @@ #include -//----------------------------------------------------------------------------- -/** Starts the kart engines. - */ -void WorldStatus::startEngines() -{ - if (m_engines_started) - return; - - m_engines_started = true; - for (unsigned int i = 0; i < World::getWorld()->getNumKarts(); i++) - { - World::getWorld()->getKart(i)->startEngineSFX(); - } -} - //----------------------------------------------------------------------------- WorldStatus::WorldStatus() { @@ -65,6 +51,7 @@ WorldStatus::WorldStatus() if (device->getTimer()->isStopped()) device->getTimer()->start(); + m_ready_to_race = false; } // WorldStatus //----------------------------------------------------------------------------- @@ -105,6 +92,10 @@ void WorldStatus::reset() // Set the right music World::getWorld()->getTrack()->startMusic(); + // In case of a networked race the race can only start once + // all protocols are up. This flag waits for that, and is + // set by + m_ready_to_race = !NetworkConfig::get()->isNetworking(); } // reset //----------------------------------------------------------------------------- @@ -121,6 +112,21 @@ WorldStatus::~WorldStatus() device->getTimer()->start(); } // ~WorldStatus +//----------------------------------------------------------------------------- +/** Starts the kart engines. + */ +void WorldStatus::startEngines() +{ + if (m_engines_started) + return; + + m_engines_started = true; + for (unsigned int i = 0; i < World::getWorld()->getNumKarts(); i++) + { + World::getWorld()->getKart(i)->startEngineSFX(); + } +} // startEngines + //----------------------------------------------------------------------------- /** Sets the clock mode and the initial time of the world clock. * \param mode The new clock mode. @@ -173,6 +179,10 @@ void WorldStatus::update(float dt) */ void WorldStatus::updateTime(const float dt) { + // In case of a networked race wait till all necessary protocols are + // ready before progressing the timer + if (!m_ready_to_race) return; + switch (m_phase) { // Note: setup phase must be a separate phase, since the race_manager diff --git a/src/modes/world_status.hpp b/src/modes/world_status.hpp index eb821d7c8..d94ede6c1 100644 --- a/src/modes/world_status.hpp +++ b/src/modes/world_status.hpp @@ -94,6 +94,9 @@ protected: /** If the start race should be played, disabled in cutscenes. */ bool m_play_racestart_sounds; + /** A flag that causes the world to wait in case of a networking race + * till all protocols are up and running. */ + bool m_ready_to_race; private: /** Sound to play at the beginning of a race, during which a * a camera intro of the track can be shown. */ @@ -194,6 +197,8 @@ public: // ------------------------------------------------------------------------ /** Get the time since start regardless of which way the clock counts */ float getTimeSinceStart() const { return m_count_up_timer; } + // ------------------------------------------------------------------------ + void setReadyToRace() { m_ready_to_race = true; } }; // WorldStatus diff --git a/src/network/protocols/game_events_protocol.cpp b/src/network/protocols/game_events_protocol.cpp index 0bcf6a8d9..66f520981 100644 --- a/src/network/protocols/game_events_protocol.cpp +++ b/src/network/protocols/game_events_protocol.cpp @@ -33,6 +33,15 @@ GameEventsProtocol::~GameEventsProtocol() { } // ~GameEventsProtocol +// ---------------------------------------------------------------------------- +/** Once the GameEventsProtocol is ready, signal the world that the timer + * can start. +*/ +void GameEventsProtocol::setup() +{ + World::getWorld()->setReadyToRace(); +} // setup + // ---------------------------------------------------------------------------- bool GameEventsProtocol::notifyEvent(Event* event) { diff --git a/src/network/protocols/game_events_protocol.hpp b/src/network/protocols/game_events_protocol.hpp index c847d5db1..f793d3228 100644 --- a/src/network/protocols/game_events_protocol.hpp +++ b/src/network/protocols/game_events_protocol.hpp @@ -27,7 +27,7 @@ public: void kartFinishedRace(const NetworkString &ns); void startReadySetGo(); void receivedReadySetGo(); - virtual void setup() OVERRIDE {}; + virtual void setup() OVERRIDE; virtual void update(float dt) OVERRIDE {}; virtual void asynchronousUpdate() OVERRIDE{} // ------------------------------------------------------------------------