Bugfix/code cleanup: the loading time was counted as countdown time
in certain circumstances (e.g. when setting up a new race from the race menu). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1474 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
646e98684a
commit
7550f687da
@ -46,7 +46,6 @@ GameManager* game_manager = 0;
|
||||
GameManager::GameManager() :
|
||||
m_abort(false),
|
||||
m_frame_count(0),
|
||||
m_started(false),
|
||||
m_curr_time(m_prev_time),
|
||||
m_prev_time(SDL_GetTicks())
|
||||
{
|
||||
@ -64,19 +63,12 @@ void GameManager::run()
|
||||
material_manager->getMaterial("st_title_screen.rgb")->getIndex();
|
||||
|
||||
bool music_on = false;
|
||||
m_curr_time = SDL_GetTicks();
|
||||
while(!m_abort)
|
||||
{
|
||||
sdl_input();
|
||||
|
||||
// Now the screen may have changed and
|
||||
// needs to be updated.
|
||||
if(m_started) m_prev_time = m_curr_time;
|
||||
else if( race_manager->raceIsActive() )
|
||||
{
|
||||
m_prev_time = SDL_GetTicks();
|
||||
m_started = true;
|
||||
}
|
||||
|
||||
m_prev_time = m_curr_time;
|
||||
m_curr_time = SDL_GetTicks();
|
||||
|
||||
if (!music_on && !race_manager->raceIsActive())
|
||||
@ -88,10 +80,11 @@ void GameManager::run()
|
||||
if (race_manager->raceIsActive())
|
||||
{
|
||||
music_on = false;
|
||||
scene->draw((m_curr_time - m_prev_time ) * 0.001f);
|
||||
float dt = (m_curr_time - m_prev_time ) * 0.001f;
|
||||
scene->draw(dt);
|
||||
if ( world->getPhase() != World::LIMBO_PHASE)
|
||||
{
|
||||
world->update((m_curr_time - m_prev_time ) * 0.001f);
|
||||
world->update(dt);
|
||||
|
||||
if(user_config->m_profile)
|
||||
{
|
||||
|
@ -29,7 +29,6 @@ private:
|
||||
bool m_abort;
|
||||
|
||||
int m_frame_count;
|
||||
bool m_started;
|
||||
Uint32 m_curr_time;
|
||||
Uint32 m_prev_time;
|
||||
|
||||
|
@ -908,23 +908,25 @@ void RaceGUI::drawStatusText (const RaceSetup& raceSetup, const float dt)
|
||||
glEnable ( GL_BLEND );
|
||||
|
||||
glOrtho ( 0, user_config->m_width, 0, user_config->m_height, 0, 100 ) ;
|
||||
switch (world->m_ready_set_go)
|
||||
switch (world->getPhase())
|
||||
{
|
||||
case 2: font_race->PrintShadow(_("Ready!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
230, 170, 160);
|
||||
break;
|
||||
case 1: font_race->PrintShadow(_("Set!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
230, 230, 160);
|
||||
break;
|
||||
case 0: font_race->PrintShadow(_("Go!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
100, 210, 100);
|
||||
break;
|
||||
case World::READY_PHASE: font_race->PrintShadow(_("Ready!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
230, 170, 160);
|
||||
break;
|
||||
case World::SET_PHASE: font_race->PrintShadow(_("Set!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
230, 230, 160);
|
||||
break;
|
||||
case World::GO_PHASE: font_race->PrintShadow(_("Go!"), 90,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
Font::CENTER_OF_SCREEN,
|
||||
100, 210, 100);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
|
||||
for(int i = 0; i < 10; ++i)
|
||||
@ -933,7 +935,7 @@ void RaceGUI::drawStatusText (const RaceSetup& raceSetup, const float dt)
|
||||
font_race->Print(world->m_debug_text[i].c_str(),
|
||||
20, 20, 200 -i*20, 100, 210, 100);
|
||||
}
|
||||
if(world->getPhase()==World::START_PHASE)
|
||||
if(world->isStartPhase())
|
||||
{
|
||||
for(int i=0; i<raceSetup.getNumPlayers(); i++)
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ void PlayerKart::update(float dt)
|
||||
|
||||
m_controls.accel = m_accel_val / 32768.0f;
|
||||
|
||||
if(world->getPhase()==World::START_PHASE)
|
||||
if(world->isStartPhase())
|
||||
{
|
||||
if(m_controls.accel!=0.0 || m_controls.brake!=false ||
|
||||
m_controls.fire|m_controls.wheelie|m_controls.jump)
|
||||
|
@ -88,7 +88,7 @@ DefaultRobot::DefaultRobot( const KartProperties *kart_properties,
|
||||
//line, then move forward while turning.
|
||||
void DefaultRobot::update( float delta )
|
||||
{
|
||||
if( world->getPhase() == World::START_PHASE )
|
||||
if( world->isStartPhase())
|
||||
{
|
||||
handle_race_start();
|
||||
AutoKart::update( delta );
|
||||
@ -481,7 +481,7 @@ void DefaultRobot::handle_rescue(const float DELTA)
|
||||
|
||||
// check if kart is stuck
|
||||
if(getVehicle()->getRigidBody()->getLinearVelocity().length()<2.0f &&
|
||||
!isRescue() && world->getPhase() != World::START_PHASE )
|
||||
!isRescue() && !world->isStartPhase())
|
||||
{
|
||||
m_time_since_stuck += DELTA;
|
||||
if(m_time_since_stuck > 2.0f)
|
||||
|
@ -62,7 +62,7 @@ World::World(const RaceSetup& raceSetup_) : m_race_setup(raceSetup_)
|
||||
{
|
||||
delete world;
|
||||
world = this;
|
||||
m_phase = START_PHASE;
|
||||
m_phase = SETUP_PHASE;
|
||||
|
||||
m_track = NULL;
|
||||
|
||||
@ -91,7 +91,9 @@ World::World(const RaceSetup& raceSetup_) : m_race_setup(raceSetup_)
|
||||
|
||||
// Load the track models - this must be done before the karts so that the
|
||||
// karts can be positioned properly on (and not in) the tracks.
|
||||
printf("begin loading track\n");
|
||||
loadTrack() ;
|
||||
printf("endloading track\n");
|
||||
|
||||
int pos = 0;
|
||||
int playerIndex = 0;
|
||||
@ -158,16 +160,7 @@ World::World(const RaceSetup& raceSetup_) : m_race_setup(raceSetup_)
|
||||
const std::string& MUSIC_NAME= track_manager->getTrack(m_race_setup.m_track)->getMusic();
|
||||
if (MUSIC_NAME.size()>0) sound_manager->playMusic(MUSIC_NAME);
|
||||
|
||||
if(user_config->m_profile)
|
||||
{
|
||||
m_ready_set_go = -1;
|
||||
m_phase = RACE_PHASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_phase = START_PHASE; // profile starts without countdown
|
||||
m_ready_set_go = 3;
|
||||
}
|
||||
m_phase = user_config->m_profile ? RACE_PHASE : SETUP_PHASE;
|
||||
|
||||
#ifdef HAVE_GHOST_REPLAY
|
||||
m_replay_recorder.initRecorder( m_race_setup.getNumKarts() );
|
||||
@ -254,13 +247,7 @@ void World::resetAllKarts()
|
||||
void World::update(float dt)
|
||||
{
|
||||
if(user_config->m_replay_history) dt=history->GetNextDelta();
|
||||
|
||||
checkRaceStatus();
|
||||
// this line was before checkRaceStatus. but m_clock is set to 0.0 in
|
||||
// checkRaceStatus on start, so m_clock would not be synchronized and the
|
||||
// first delta would not be added .. that would cause a gap in
|
||||
// replay-recording
|
||||
m_clock += dt;
|
||||
updateRaceStatus(dt);
|
||||
|
||||
if( getPhase() == FINISH_PHASE )
|
||||
{
|
||||
@ -326,7 +313,7 @@ void World::update(float dt)
|
||||
#ifdef HAVE_GHOST_REPLAY
|
||||
// we start recording after START_PHASE, since during start-phase m_clock is incremented
|
||||
// normally, but after switching to RACE_PHASE m_clock is set back to 0.0
|
||||
if( m_phase != START_PHASE )
|
||||
if( m_phase == GO_PHASE )
|
||||
{
|
||||
m_replay_recorder.pushFrame();
|
||||
if( m_p_replay_player ) m_p_replay_player->showReplayAt( m_clock );
|
||||
@ -423,39 +410,42 @@ bool World::loadReplayHumanReadable( std::string const &filename )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void World::checkRaceStatus()
|
||||
void World::updateRaceStatus(float dt)
|
||||
{
|
||||
if (m_clock > 1.0 && m_ready_set_go == 0)
|
||||
{
|
||||
m_ready_set_go = -1;
|
||||
}
|
||||
else if (m_clock > 2.0 && m_ready_set_go == 1)
|
||||
{
|
||||
m_ready_set_go = 0;
|
||||
m_phase = RACE_PHASE;
|
||||
m_clock = 0.0f;
|
||||
sound_manager->playSfx(SOUND_START);
|
||||
// Reset the brakes now that the prestart phase is over
|
||||
// (braking prevents the karts from sliding downhill)
|
||||
for(unsigned int i=0; i<m_kart.size(); i++)
|
||||
{
|
||||
m_kart[i]->resetBrakes();
|
||||
}
|
||||
switch (m_phase) {
|
||||
case SETUP_PHASE: m_clock=0.0f; m_phase=READY_PHASE;
|
||||
dt = 0.0f; // solves the problem of adding track loading time
|
||||
break; // loading time, don't play sound yet
|
||||
case READY_PHASE: if(m_clock==0.0) // play sound at beginning of next frame
|
||||
sound_manager->playSfx(SOUND_PRESTART);
|
||||
if(m_clock>1.0)
|
||||
{
|
||||
m_phase=SET_PHASE;
|
||||
sound_manager->playSfx(SOUND_PRESTART);
|
||||
}
|
||||
break;
|
||||
case SET_PHASE : if(m_clock>2.0)
|
||||
{
|
||||
m_phase=GO_PHASE;
|
||||
m_clock=0.0f;
|
||||
sound_manager->playSfx(SOUND_START);
|
||||
// Reset the brakes now that the prestart
|
||||
// phase is over (braking prevents the karts
|
||||
// from sliding downhill)
|
||||
for(unsigned int i=0; i<m_kart.size(); i++)
|
||||
{
|
||||
m_kart[i]->resetBrakes();
|
||||
}
|
||||
#ifdef HAVE_GHOST_REPLAY
|
||||
// push positions at time 0.0 to replay-data
|
||||
m_replay_recorder.pushFrame();
|
||||
// push positions at time 0.0 to replay-data
|
||||
m_replay_recorder.pushFrame();
|
||||
#endif
|
||||
}
|
||||
else if (m_clock > 1.0 && m_ready_set_go == 2)
|
||||
{
|
||||
sound_manager->playSfx(SOUND_PRESTART);
|
||||
m_ready_set_go = 1;
|
||||
}
|
||||
else if (m_clock > 0.0 && m_ready_set_go == 3)
|
||||
{
|
||||
sound_manager->playSfx(SOUND_PRESTART);
|
||||
m_ready_set_go = 2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GO_PHASE : if(m_clock>1.0) m_phase=RACE_PHASE; break;
|
||||
default : break;
|
||||
} // switch
|
||||
m_clock += dt;
|
||||
|
||||
/*if all players have finished, or if only one kart is not finished when
|
||||
not in time trial mode, the race is over. Players are the last in the
|
||||
@ -523,7 +513,7 @@ void World::checkRaceStatus()
|
||||
} // if !raceIsFinished
|
||||
} // for i
|
||||
}
|
||||
} // checkRaceStatus
|
||||
} // updateRaceStatus
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void World::updateRacePosition ( int k )
|
||||
@ -597,9 +587,8 @@ void World::loadTrack()
|
||||
//-----------------------------------------------------------------------------
|
||||
void World::restartRace()
|
||||
{
|
||||
m_ready_set_go = 3;
|
||||
m_clock = 0.0f;
|
||||
m_phase = START_PHASE;
|
||||
m_phase = SETUP_PHASE;
|
||||
|
||||
for ( Karts::iterator i = m_kart.begin(); i != m_kart.end() ; ++i )
|
||||
{
|
||||
|
@ -46,9 +46,15 @@ public:
|
||||
RaceSetup m_race_setup;
|
||||
|
||||
enum Phase {
|
||||
// The traffic light is shown and all players stay in position
|
||||
START_PHASE,
|
||||
// The traffic light turned green and all driver, drive around the track
|
||||
// Game setup, e.g. track loading
|
||||
SETUP_PHASE,
|
||||
// 'Ready' is displayed
|
||||
READY_PHASE,
|
||||
// 'Set' is displayed
|
||||
SET_PHASE,
|
||||
// 'Go' is displayed, but this is already race phase
|
||||
GO_PHASE,
|
||||
// the actual race has started, no ready/set/go is displayed anymore
|
||||
RACE_PHASE,
|
||||
// All players have finished, now wait a certain amount of time for AI
|
||||
// karts to finish. If they do not finish in that time, finish the race
|
||||
@ -60,8 +66,6 @@ public:
|
||||
LIMBO_PHASE,
|
||||
};
|
||||
|
||||
int m_ready_set_go;
|
||||
|
||||
Track* m_track;
|
||||
|
||||
/** debug text that will be overlaid to the screen */
|
||||
@ -70,6 +74,7 @@ public:
|
||||
World(const RaceSetup& raceSetup);
|
||||
virtual ~World();
|
||||
void update(float delta);
|
||||
bool isStartPhase() const {return m_phase<=GO_PHASE;}
|
||||
void restartRace();
|
||||
void disableRace(); // Put race into limbo phase
|
||||
|
||||
@ -100,6 +105,7 @@ public:
|
||||
|
||||
void pause();
|
||||
void unpause();
|
||||
|
||||
private:
|
||||
Karts m_kart;
|
||||
float m_finish_delay_start_time;
|
||||
@ -112,7 +118,7 @@ private:
|
||||
|
||||
void updateRacePosition( int k );
|
||||
void loadTrack();
|
||||
void checkRaceStatus();
|
||||
void updateRaceStatus(float dt);
|
||||
void resetAllKarts();
|
||||
Kart* loadRobot(const KartProperties *kart_properties, int position,
|
||||
sgCoord init_pos);
|
||||
|
Loading…
Reference in New Issue
Block a user