2008-09-21 21:52:28 -04:00
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2015-03-29 20:31:42 -04:00
|
|
|
// Copyright (C) 2004-2015 SuperTuxKart-Team
|
2008-09-21 21:52:28 -04:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2010-02-08 07:59:03 -05:00
|
|
|
#include "modes/world_status.hpp"
|
2009-01-05 17:51:02 -05:00
|
|
|
|
2016-10-27 06:33:42 -04:00
|
|
|
#include "main_loop.hpp"
|
2010-07-06 19:10:47 -04:00
|
|
|
#include "audio/music_manager.hpp"
|
2008-09-21 21:52:28 -04:00
|
|
|
#include "audio/sfx_base.hpp"
|
2014-09-17 07:38:21 -04:00
|
|
|
#include "audio/sfx_manager.hpp"
|
2009-06-11 06:00:43 -04:00
|
|
|
#include "config/stk_config.hpp"
|
2014-02-25 20:52:16 -05:00
|
|
|
#include "config/user_config.hpp"
|
2012-05-08 03:07:15 -04:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2010-05-10 19:53:32 -04:00
|
|
|
#include "guiengine/modaldialog.hpp"
|
2012-03-19 16:21:11 -04:00
|
|
|
#include "karts/abstract_kart.hpp"
|
2010-07-06 19:10:47 -04:00
|
|
|
#include "modes/world.hpp"
|
2016-03-31 17:51:39 -04:00
|
|
|
#include "network/network_config.hpp"
|
2016-11-25 06:17:24 -05:00
|
|
|
#include "network/protocols/client_lobby.hpp"
|
2016-11-22 17:39:33 -05:00
|
|
|
#include "network/protocols/server_lobby.hpp"
|
2017-01-23 16:05:46 -05:00
|
|
|
#include "network/rewind_manager.hpp"
|
2016-03-31 17:51:39 -04:00
|
|
|
#include "network/race_event_manager.hpp"
|
2010-07-06 19:10:47 -04:00
|
|
|
#include "tracks/track.hpp"
|
2008-09-21 21:52:28 -04:00
|
|
|
|
2012-05-08 03:07:15 -04:00
|
|
|
#include <irrlicht.h>
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-08 07:59:03 -05:00
|
|
|
WorldStatus::WorldStatus()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2010-07-06 19:10:47 -04:00
|
|
|
m_clock_mode = CLOCK_CHRONO;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2014-09-17 07:38:21 -04:00
|
|
|
m_prestart_sound = SFXManager::get()->createSoundSource("pre_start_race");
|
|
|
|
m_start_sound = SFXManager::get()->createSoundSource("start_race");
|
|
|
|
m_track_intro_sound = SFXManager::get()->createSoundSource("track_intro");
|
2010-07-06 19:10:47 -04:00
|
|
|
|
2016-05-02 05:32:04 -04:00
|
|
|
m_play_track_intro_sound = UserConfigParams::m_music;
|
|
|
|
m_play_ready_set_go_sounds = true;
|
2016-03-31 17:51:39 -04:00
|
|
|
m_play_racestart_sounds = true;
|
|
|
|
m_server_is_ready = false;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2011-09-07 21:27:04 -04:00
|
|
|
IrrlichtDevice *device = irr_driver->getDevice();
|
2014-08-30 12:34:44 -04:00
|
|
|
|
|
|
|
if (device->getTimer()->isStopped())
|
|
|
|
device->getTimer()->start();
|
2010-02-08 07:59:03 -05:00
|
|
|
} // WorldStatus
|
2009-08-23 11:42:58 -04:00
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-09 04:24:45 -05:00
|
|
|
/** Resets all status information, used when starting a new race.
|
|
|
|
*/
|
2010-02-08 07:59:03 -05:00
|
|
|
void WorldStatus::reset()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2010-02-09 04:24:45 -05:00
|
|
|
m_time = 0.0f;
|
2017-01-23 16:05:46 -05:00
|
|
|
m_adjust_time_by = 0.0f;
|
2008-09-21 21:52:28 -04:00
|
|
|
m_auxiliary_timer = 0.0f;
|
2016-07-08 11:43:12 -04:00
|
|
|
m_count_up_timer = 0.0f;
|
|
|
|
|
2016-05-02 15:53:34 -04:00
|
|
|
m_engines_started = false;
|
|
|
|
|
2010-07-06 19:10:47 -04:00
|
|
|
// Using SETUP_PHASE will play the track into sfx first, and has no
|
|
|
|
// other side effects.
|
2015-02-08 19:15:48 -05:00
|
|
|
m_phase = UserConfigParams::m_race_now ? MUSIC_PHASE : SETUP_PHASE;
|
|
|
|
|
2015-02-08 19:56:56 -05:00
|
|
|
// Parts of the initialisation-phase are skipped so do it here
|
2015-02-08 19:15:48 -05:00
|
|
|
if (UserConfigParams::m_race_now)
|
|
|
|
{
|
|
|
|
// Setup music and sound
|
2016-12-13 01:14:29 -05:00
|
|
|
if (Weather::getInstance())
|
|
|
|
Weather::getInstance()->playSound();
|
2015-02-08 19:15:48 -05:00
|
|
|
|
|
|
|
// Start engines
|
|
|
|
for (unsigned int i = 0; i < World::getWorld()->getNumKarts(); i++)
|
|
|
|
World::getWorld()->getKart(i)->startEngineSFX();
|
|
|
|
}
|
|
|
|
|
2010-06-06 23:31:41 -04:00
|
|
|
m_previous_phase = UNDEFINED_PHASE;
|
2010-07-06 19:10:47 -04:00
|
|
|
// Just in case that the game is reset during the intro phase
|
|
|
|
m_track_intro_sound->stop();
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2011-09-07 21:27:04 -04:00
|
|
|
IrrlichtDevice *device = irr_driver->getDevice();
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2014-09-01 21:57:48 -04:00
|
|
|
if (device->getTimer()->isStopped())
|
2014-08-30 12:34:44 -04:00
|
|
|
device->getTimer()->start();
|
2015-02-08 19:56:56 -05:00
|
|
|
|
|
|
|
// Set the right music
|
2016-12-12 15:53:33 -05:00
|
|
|
Track::getCurrentTrack()->startMusic();
|
2016-10-27 06:33:42 -04:00
|
|
|
// In case of a networked race the race can only start once
|
2016-11-25 06:17:24 -05:00
|
|
|
// all protocols are up. This flag is used to wait for
|
|
|
|
// a confirmation before starting the actual race.
|
|
|
|
m_server_is_ready = false;
|
2009-08-23 11:42:58 -04:00
|
|
|
} // reset
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-09 04:24:45 -05:00
|
|
|
/** Destructor of WorldStatus.
|
|
|
|
*/
|
2010-02-08 07:59:03 -05:00
|
|
|
WorldStatus::~WorldStatus()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2014-10-12 17:26:45 -04:00
|
|
|
m_prestart_sound->deleteSFX();
|
|
|
|
m_start_sound->deleteSFX();
|
|
|
|
m_track_intro_sound->deleteSFX();
|
2011-09-07 21:27:04 -04:00
|
|
|
IrrlichtDevice *device = irr_driver->getDevice();
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2014-09-01 21:57:48 -04:00
|
|
|
if (device->getTimer()->isStopped())
|
2014-08-30 12:34:44 -04:00
|
|
|
device->getTimer()->start();
|
2010-02-08 07:59:03 -05:00
|
|
|
} // ~WorldStatus
|
2009-08-23 11:42:58 -04:00
|
|
|
|
2016-10-27 06:33:42 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** 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
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-09 04:24:45 -05:00
|
|
|
/** Sets the clock mode and the initial time of the world clock.
|
|
|
|
* \param mode The new clock mode.
|
|
|
|
* \param initial_time The new initial time for the world clock.
|
|
|
|
*/
|
2010-02-08 07:59:03 -05:00
|
|
|
void WorldStatus::setClockMode(const ClockType mode, const float initial_time)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2010-02-26 14:09:05 -05:00
|
|
|
m_clock_mode = mode;
|
2008-09-21 21:52:28 -04:00
|
|
|
m_time = initial_time;
|
2009-08-23 11:42:58 -04:00
|
|
|
} // setClockMode
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-17 06:59:51 -05:00
|
|
|
/** Called when the race is finished, but it still leaves some time
|
|
|
|
* for an end of race animation, and potentially let some more AI karts
|
|
|
|
* finish the race.
|
2010-02-09 04:24:45 -05:00
|
|
|
*/
|
2010-02-17 06:59:51 -05:00
|
|
|
void WorldStatus::enterRaceOverState()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2010-07-22 18:49:56 -04:00
|
|
|
// Don't enter race over if it's already race over
|
2014-08-30 12:34:44 -04:00
|
|
|
if (m_phase == DELAY_FINISH_PHASE || m_phase == RESULT_DISPLAY_PHASE ||
|
|
|
|
m_phase == FINISH_PHASE)
|
2010-07-22 18:49:56 -04:00
|
|
|
return;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2010-02-17 06:59:51 -05:00
|
|
|
m_phase = DELAY_FINISH_PHASE;
|
|
|
|
m_auxiliary_timer = 0.0f;
|
|
|
|
} // enterRaceOverState
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Called when it's really over (delay over if any). This function must be
|
|
|
|
* called after all stats were updated from the different modes!
|
|
|
|
*/
|
|
|
|
void WorldStatus::terminateRace()
|
|
|
|
{
|
|
|
|
} // terminateRace
|
2009-08-23 11:42:58 -04:00
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-08-31 02:31:59 -04:00
|
|
|
/** Update, called once per frame. Called early on before physics are
|
|
|
|
* updated.
|
|
|
|
* \param dt Time step.
|
|
|
|
*/
|
|
|
|
void WorldStatus::update(float dt)
|
|
|
|
{
|
|
|
|
} // update
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Updates the world time and clock (which might be running backwards), and
|
|
|
|
* all status information, called once per frame at the end of the main
|
|
|
|
* loop.
|
2010-02-09 04:24:45 -05:00
|
|
|
* \param dt Duration of time step.
|
|
|
|
*/
|
2016-08-31 02:31:59 -04:00
|
|
|
void WorldStatus::updateTime(const float dt)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2014-08-30 12:34:44 -04:00
|
|
|
switch (m_phase)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
// Note: setup phase must be a separate phase, since the race_manager
|
|
|
|
// checks the phase when updating the camera: in the very first time
|
|
|
|
// step dt is large (it includes loading time), so the camera might
|
|
|
|
// tilt way too much. A separate setup phase for the first frame
|
|
|
|
// simplifies this handling
|
|
|
|
case SETUP_PHASE:
|
2013-05-29 18:04:35 -04:00
|
|
|
m_auxiliary_timer = 0.0f;
|
2010-07-06 19:10:47 -04:00
|
|
|
m_phase = TRACK_INTRO_PHASE;
|
2014-08-30 12:23:59 -04:00
|
|
|
|
2016-05-02 05:32:04 -04:00
|
|
|
if (m_play_track_intro_sound)
|
2012-06-16 15:41:21 -04:00
|
|
|
{
|
2011-02-28 11:19:43 -05:00
|
|
|
m_track_intro_sound->play();
|
2012-06-16 15:41:21 -04:00
|
|
|
}
|
2014-08-30 12:23:59 -04:00
|
|
|
|
2016-12-13 01:14:29 -05:00
|
|
|
if (Weather::getInstance())
|
2014-08-30 12:23:59 -04:00
|
|
|
{
|
2016-12-13 01:14:29 -05:00
|
|
|
Weather::getInstance()->playSound();
|
2014-08-30 12:23:59 -04:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Do not increase time
|
2010-07-06 19:10:47 -04:00
|
|
|
case TRACK_INTRO_PHASE:
|
2011-07-07 21:22:43 -04:00
|
|
|
m_auxiliary_timer += dt;
|
2014-07-28 19:16:32 -04:00
|
|
|
|
|
|
|
if (UserConfigParams::m_artist_debug_mode &&
|
2017-06-13 18:28:06 -04:00
|
|
|
!NetworkConfig::get()->isNetworking() &&
|
2016-10-08 21:50:26 -04:00
|
|
|
race_manager->getNumberOfKarts() -
|
|
|
|
race_manager->getNumSpareTireKarts() == 1 &&
|
2014-07-28 19:16:32 -04:00
|
|
|
race_manager->getTrackName() != "tutorial")
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
2014-07-28 19:16:32 -04:00
|
|
|
m_auxiliary_timer += dt * 6;
|
2014-08-30 12:34:44 -04:00
|
|
|
}
|
2014-07-28 19:16:32 -04:00
|
|
|
|
2011-07-07 21:22:43 -04:00
|
|
|
// Work around a bug that occurred on linux once:
|
2014-09-17 07:38:21 -04:00
|
|
|
// the SFXManager::get() kept on reporting that it is playing,
|
2011-07-07 21:22:43 -04:00
|
|
|
// while it was not - so STK would never reach the ready
|
|
|
|
// ... phase. Since the sound effect is about 3 seconds
|
|
|
|
// long, we use the aux timer to force the next phase
|
|
|
|
// after 3.5 seconds.
|
2014-10-13 17:05:04 -04:00
|
|
|
if (m_track_intro_sound->getStatus() == SFXBase::SFX_PLAYING &&
|
2014-08-30 12:34:44 -04:00
|
|
|
m_auxiliary_timer < 3.5f)
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Do not increase time
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2013-12-01 23:27:55 -05:00
|
|
|
// Wait before ready phase if sounds are disabled
|
2014-08-30 12:34:44 -04:00
|
|
|
if (!UserConfigParams::m_sfx && m_auxiliary_timer < 3.0f)
|
2010-07-06 19:10:47 -04:00
|
|
|
return;
|
2016-05-02 15:53:34 -04:00
|
|
|
|
|
|
|
if (!m_play_track_intro_sound)
|
|
|
|
{
|
|
|
|
startEngines();
|
|
|
|
if (m_auxiliary_timer < 3.0f)
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Do not increase time
|
2016-05-02 15:53:34 -04:00
|
|
|
}
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2011-07-07 21:22:43 -04:00
|
|
|
m_auxiliary_timer = 0.0f;
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2016-05-02 05:32:04 -04:00
|
|
|
if (m_play_ready_set_go_sounds)
|
2014-08-30 12:34:44 -04:00
|
|
|
m_prestart_sound->play();
|
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
// In a networked game the client needs to wait for a notification
|
2016-11-25 06:17:24 -05:00
|
|
|
// from the server that all clients and the server are ready to
|
|
|
|
// start the game. The server will actually wait for all clients
|
|
|
|
// to confirm that they have started the race before starting
|
|
|
|
// itself. In a normal race, this phase is skipped and the race
|
|
|
|
// starts immediately.
|
|
|
|
m_phase = NetworkConfig::get()->isNetworking() ? WAIT_FOR_SERVER_PHASE
|
|
|
|
: READY_PHASE;
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Don't increase time
|
|
|
|
case WAIT_FOR_SERVER_PHASE:
|
2016-11-25 06:17:24 -05:00
|
|
|
{
|
|
|
|
// This stage is only reached in case of a networked game.
|
|
|
|
// A client waits for a message from the server that it can
|
|
|
|
// start the race (i.e. that all clients and the server have
|
|
|
|
// loaded the world). The server waits for a confirmation from
|
|
|
|
// each client that they have started (to guarantee that the
|
|
|
|
// server is running with a local time behind all clients).
|
|
|
|
if (!m_server_is_ready) return;
|
|
|
|
|
|
|
|
m_phase = READY_PHASE;
|
2018-02-17 23:39:05 -05:00
|
|
|
auto cl = LobbyProtocol::get<ClientLobby>();
|
2016-11-25 06:17:24 -05:00
|
|
|
if (cl)
|
|
|
|
cl->startingRaceNow();
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Don't increase time
|
2016-11-25 06:17:24 -05:00
|
|
|
}
|
2008-09-21 21:52:28 -04:00
|
|
|
case READY_PHASE:
|
2016-11-22 01:57:15 -05:00
|
|
|
startEngines();
|
2016-11-15 16:48:04 -05:00
|
|
|
|
2014-08-30 12:34:44 -04:00
|
|
|
if (m_auxiliary_timer > 1.0)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2016-05-02 05:32:04 -04:00
|
|
|
if (m_play_ready_set_go_sounds)
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
|
|
|
m_prestart_sound->play();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_phase = SET_PHASE;
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
m_auxiliary_timer += dt;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
// In artist debug mode, when without opponents, skip the
|
|
|
|
// ready/set/go counter faster
|
2017-01-03 16:18:41 -05:00
|
|
|
if (UserConfigParams::m_artist_debug_mode &&
|
|
|
|
!NetworkConfig::get()->isNetworking() &&
|
2016-10-08 21:50:26 -04:00
|
|
|
race_manager->getNumberOfKarts() -
|
|
|
|
race_manager->getNumSpareTireKarts() == 1 &&
|
2013-01-16 21:20:12 -05:00
|
|
|
race_manager->getTrackName() != "tutorial")
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
2011-07-01 19:59:25 -04:00
|
|
|
m_auxiliary_timer += dt*6;
|
2014-08-30 12:34:44 -04:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Do not increase time
|
2014-08-30 12:34:44 -04:00
|
|
|
case SET_PHASE:
|
|
|
|
if (m_auxiliary_timer > 2.0)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
// set phase is over, go to the next one
|
2014-08-30 12:34:44 -04:00
|
|
|
m_phase = GO_PHASE;
|
2016-05-02 05:32:04 -04:00
|
|
|
if (m_play_ready_set_go_sounds)
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
|
|
|
m_start_sound->play();
|
|
|
|
}
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2008-10-04 13:32:40 -04:00
|
|
|
// event
|
|
|
|
onGo();
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
m_auxiliary_timer += dt;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
// In artist debug mode, when without opponents,
|
|
|
|
// skip the ready/set/go counter faster
|
2013-01-16 21:20:12 -05:00
|
|
|
if (UserConfigParams::m_artist_debug_mode &&
|
2016-10-08 21:50:26 -04:00
|
|
|
race_manager->getNumberOfKarts() -
|
|
|
|
race_manager->getNumSpareTireKarts() == 1 &&
|
2013-01-16 21:20:12 -05:00
|
|
|
race_manager->getTrackName() != "tutorial")
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
2011-07-01 19:59:25 -04:00
|
|
|
m_auxiliary_timer += dt*6;
|
2014-08-30 12:34:44 -04:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
return; // Do not increase time
|
2008-09-21 21:52:28 -04:00
|
|
|
case GO_PHASE :
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2015-02-10 01:07:46 -05:00
|
|
|
if (m_auxiliary_timer>2.5f && music_manager->getCurrentMusic() &&
|
|
|
|
!music_manager->getCurrentMusic()->isPlaying())
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
2015-02-10 01:07:46 -05:00
|
|
|
music_manager->startMusic();
|
2014-08-30 12:34:44 -04:00
|
|
|
}
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2014-08-30 12:34:44 -04:00
|
|
|
if (m_auxiliary_timer > 3.0f) // how long to display the 'go' message
|
2011-09-13 20:48:49 -04:00
|
|
|
{
|
2014-08-30 12:34:44 -04:00
|
|
|
m_phase = MUSIC_PHASE;
|
2011-09-13 20:48:49 -04:00
|
|
|
}
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2008-10-04 14:50:45 -04:00
|
|
|
m_auxiliary_timer += dt;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
// In artist debug mode, when without opponents,
|
|
|
|
// skip the ready/set/go counter faster
|
2013-06-19 20:40:03 -04:00
|
|
|
if (UserConfigParams::m_artist_debug_mode &&
|
2016-10-08 21:50:26 -04:00
|
|
|
race_manager->getNumberOfKarts() -
|
|
|
|
race_manager->getNumSpareTireKarts() == 1 &&
|
2013-06-19 20:40:03 -04:00
|
|
|
race_manager->getTrackName() != "tutorial")
|
2014-08-30 12:34:44 -04:00
|
|
|
{
|
2011-07-01 19:59:25 -04:00
|
|
|
m_auxiliary_timer += dt*6;
|
2014-08-30 12:34:44 -04:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
break; // Now the world time starts
|
2008-10-04 14:50:45 -04:00
|
|
|
case MUSIC_PHASE:
|
2015-02-08 19:15:48 -05:00
|
|
|
// Start the music here when starting fast
|
|
|
|
if (UserConfigParams::m_race_now)
|
|
|
|
{
|
2015-02-10 01:07:46 -05:00
|
|
|
music_manager->startMusic();
|
2015-02-08 19:15:48 -05:00
|
|
|
UserConfigParams::m_race_now = false;
|
|
|
|
}
|
2008-10-06 09:40:11 -04:00
|
|
|
// how long to display the 'music' message
|
2014-08-30 12:34:44 -04:00
|
|
|
if (m_auxiliary_timer>stk_config->m_music_credit_time)
|
|
|
|
{
|
|
|
|
m_phase = RACE_PHASE;
|
|
|
|
}
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
m_auxiliary_timer += dt;
|
|
|
|
break;
|
2010-05-10 19:53:32 -04:00
|
|
|
case RACE_PHASE:
|
|
|
|
// Nothing to do for race phase, switch to delay finish phase
|
2013-05-29 18:04:35 -04:00
|
|
|
// happens when
|
2010-05-10 19:53:32 -04:00
|
|
|
break;
|
2014-08-30 12:34:44 -04:00
|
|
|
case DELAY_FINISH_PHASE:
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_auxiliary_timer += dt;
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2010-05-10 19:53:32 -04:00
|
|
|
// Change to next phase if delay is over
|
2014-08-30 12:34:44 -04:00
|
|
|
if (m_auxiliary_timer > stk_config->m_delay_finish_time)
|
2010-05-10 19:53:32 -04:00
|
|
|
{
|
2010-06-07 17:40:45 -04:00
|
|
|
m_phase = RESULT_DISPLAY_PHASE;
|
|
|
|
terminateRace();
|
2010-05-10 19:53:32 -04:00
|
|
|
}
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2010-05-10 19:53:32 -04:00
|
|
|
break;
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
2014-08-30 12:34:44 -04:00
|
|
|
case RESULT_DISPLAY_PHASE:
|
2013-02-03 17:31:24 -05:00
|
|
|
{
|
2010-05-10 19:53:32 -04:00
|
|
|
break;
|
2013-02-03 17:31:24 -05:00
|
|
|
}
|
2008-09-21 21:52:28 -04:00
|
|
|
case FINISH_PHASE:
|
2010-05-10 19:53:32 -04:00
|
|
|
// Nothing to do here.
|
|
|
|
break;
|
2013-12-01 23:27:55 -05:00
|
|
|
case GOAL_PHASE:
|
|
|
|
// Nothing to do here as well.
|
|
|
|
|
2010-05-10 19:53:32 -04:00
|
|
|
default: break;
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
2016-03-31 22:10:38 -04:00
|
|
|
|
2016-10-15 20:28:48 -04:00
|
|
|
IrrlichtDevice *device = irr_driver->getDevice();
|
2017-06-04 19:46:34 -04:00
|
|
|
|
2014-08-30 12:34:44 -04:00
|
|
|
switch (m_clock_mode)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2010-02-09 04:24:45 -05:00
|
|
|
case CLOCK_CHRONO:
|
2016-10-15 20:28:48 -04:00
|
|
|
if (!device->getTimer()->isStopped())
|
|
|
|
{
|
2017-06-04 19:46:34 -04:00
|
|
|
m_time += dt;
|
|
|
|
m_count_up_timer += dt;
|
2016-10-15 20:28:48 -04:00
|
|
|
}
|
2008-09-21 21:52:28 -04:00
|
|
|
break;
|
2010-02-09 04:24:45 -05:00
|
|
|
case CLOCK_COUNTDOWN:
|
2010-02-26 14:09:05 -05:00
|
|
|
// stop countdown when race is over
|
2010-05-10 19:53:32 -04:00
|
|
|
if (m_phase == RESULT_DISPLAY_PHASE || m_phase == FINISH_PHASE)
|
2010-02-26 14:09:05 -05:00
|
|
|
{
|
|
|
|
m_time = 0.0f;
|
2016-07-08 11:43:12 -04:00
|
|
|
m_count_up_timer = 0.0f;
|
2010-02-26 14:09:05 -05:00
|
|
|
break;
|
|
|
|
}
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2016-10-15 20:28:48 -04:00
|
|
|
if (!device->getTimer()->isStopped())
|
|
|
|
{
|
2017-06-04 19:46:34 -04:00
|
|
|
m_time -= dt;
|
|
|
|
m_count_up_timer += dt;
|
2016-10-15 20:28:48 -04:00
|
|
|
}
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
if(m_time <= 0.0)
|
|
|
|
{
|
2008-10-04 13:32:40 -04:00
|
|
|
// event
|
|
|
|
countdownReachedZero();
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
2013-05-29 18:04:35 -04:00
|
|
|
|
2010-02-26 14:09:05 -05:00
|
|
|
break;
|
2008-09-21 21:52:28 -04:00
|
|
|
default: break;
|
2016-03-31 17:51:39 -04:00
|
|
|
} // switch m_phase
|
2010-02-09 04:24:45 -05:00
|
|
|
} // update
|
|
|
|
|
2017-01-23 16:05:46 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** If the server requests that a client's time should be adjusted,
|
|
|
|
* smoothly change the clock speed of this client to go a bit faster
|
|
|
|
* or slower till the overall adjustment was reached.
|
|
|
|
* \param dt Original time step size.
|
|
|
|
*/
|
|
|
|
float WorldStatus::adjustDT(float dt)
|
|
|
|
{
|
|
|
|
// If request, adjust world time to go ahead (adjust>0) or
|
|
|
|
// slow down (<0). This is done in 5% of dt steps so that the
|
|
|
|
// user will not notice this.
|
2017-06-13 18:27:34 -04:00
|
|
|
const float FRACTION = 0.10f; // fraction of dt to be adjusted
|
2017-01-23 16:05:46 -05:00
|
|
|
float time_adjust;
|
|
|
|
if (m_adjust_time_by >= 0) // make it run faster
|
|
|
|
{
|
|
|
|
time_adjust = dt * FRACTION;
|
|
|
|
if (time_adjust > m_adjust_time_by) time_adjust = m_adjust_time_by;
|
|
|
|
if (m_adjust_time_by > 0)
|
|
|
|
Log::verbose("info", "At %f %f adjusting time by %f dt %f to dt %f for %f",
|
|
|
|
World::getWorld()->getTime(), StkTime::getRealTime(),
|
2017-06-13 18:27:34 -04:00
|
|
|
time_adjust, dt, dt - time_adjust, m_adjust_time_by);
|
2017-01-23 16:05:46 -05:00
|
|
|
}
|
|
|
|
else // m_adjust_time negative, i.e. will go slower
|
|
|
|
{
|
|
|
|
time_adjust = -dt * FRACTION;
|
|
|
|
if (time_adjust < m_adjust_time_by) time_adjust = m_adjust_time_by;
|
|
|
|
Log::verbose("info", "At %f %f adjusting time by %f dt %f to dt %f for %f",
|
|
|
|
World::getWorld()->getTime(), StkTime::getRealTime(),
|
2017-06-13 18:27:34 -04:00
|
|
|
time_adjust, dt, dt - time_adjust, m_adjust_time_by);
|
2017-01-23 16:05:46 -05:00
|
|
|
}
|
|
|
|
m_adjust_time_by -= time_adjust;
|
2017-06-13 18:27:34 -04:00
|
|
|
dt -= time_adjust;
|
2017-01-23 16:05:46 -05:00
|
|
|
return dt;
|
|
|
|
} // adjustDT
|
|
|
|
|
2016-03-31 17:51:39 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Called on the client when it receives a notification from the server that
|
2016-11-15 16:48:04 -05:00
|
|
|
* all clients (and server) are ready to start the race. The server will
|
|
|
|
* then additionally wait for all clients to report back that they are
|
|
|
|
* starting, which guarantees that the server is running far enough behind
|
|
|
|
* clients time that at server time T all events from the clients at time
|
|
|
|
* T have arrived, minimising rollback impact.
|
2016-03-31 17:51:39 -04:00
|
|
|
*/
|
|
|
|
void WorldStatus::startReadySetGo()
|
|
|
|
{
|
|
|
|
m_server_is_ready = true;
|
|
|
|
} // startReadySetGo
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-09 04:24:45 -05:00
|
|
|
/** Sets the time for the clock.
|
|
|
|
* \param time New time to set.
|
|
|
|
*/
|
2010-02-08 07:59:03 -05:00
|
|
|
void WorldStatus::setTime(const float time)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_time = time;
|
2010-02-09 04:24:45 -05:00
|
|
|
} // setTime
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-05-10 19:53:32 -04:00
|
|
|
/** Pauses the game and switches to the specified phase.
|
|
|
|
* \param phase Phase to switch to.
|
|
|
|
*/
|
|
|
|
void WorldStatus::pause(Phase phase)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2014-08-30 12:34:44 -04:00
|
|
|
assert(m_previous_phase == UNDEFINED_PHASE);
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
m_previous_phase = m_phase;
|
2010-05-10 19:53:32 -04:00
|
|
|
m_phase = phase;
|
2011-09-05 00:14:50 -04:00
|
|
|
IrrlichtDevice *device = irr_driver->getDevice();
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2018-02-17 02:21:26 -05:00
|
|
|
if (!device->getTimer()->isStopped() &&
|
|
|
|
!NetworkConfig::get()->isNetworking())
|
2014-08-30 12:34:44 -04:00
|
|
|
device->getTimer()->stop();
|
2010-02-09 04:24:45 -05:00
|
|
|
} // pause
|
|
|
|
|
2008-09-21 21:52:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-05-10 19:53:32 -04:00
|
|
|
/** Switches back from a pause state to the previous state.
|
|
|
|
*/
|
2010-02-08 07:59:03 -05:00
|
|
|
void WorldStatus::unpause()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2010-05-10 19:53:32 -04:00
|
|
|
m_phase = m_previous_phase;
|
|
|
|
// Set m_previous_phase so that we can use an assert
|
|
|
|
// in pause to detect incorrect pause/unpause sequences.
|
2010-06-06 23:31:41 -04:00
|
|
|
m_previous_phase = UNDEFINED_PHASE;
|
2011-09-05 00:14:50 -04:00
|
|
|
IrrlichtDevice *device = irr_driver->getDevice();
|
2014-08-30 12:34:44 -04:00
|
|
|
|
2018-02-17 02:21:26 -05:00
|
|
|
if (device->getTimer()->isStopped() &&
|
|
|
|
!NetworkConfig::get()->isNetworking())
|
2014-08-30 12:34:44 -04:00
|
|
|
device->getTimer()->start();
|
2010-06-06 23:31:41 -04:00
|
|
|
} // unpause
|