Fix 2658 by separating networking code from main loop.
This commit is contained in:
parent
94346ae64d
commit
fda3afad93
@ -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<SynchronizationProtocol*>(
|
||||
ProtocolManager::getInstance()->getProtocol(PROTOCOL_SYNCHRONIZATION));
|
||||
if (!protocol)
|
||||
{
|
||||
World::getWorld()->updateTime(dt);
|
||||
}
|
||||
World::getWorld()->updateTime(dt);
|
||||
}
|
||||
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
@ -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;
|
||||
|
@ -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 <irrlicht.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** 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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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{}
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user