1) Renamed clock.?pp (which stored the class TimedRace) to

world_status.?pp (storing the class WorldStatus).
2) Fixed end of race in case that player kart is last
   (race would never end till esc is pressed).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4668 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-02-08 12:59:03 +00:00
parent 261ff94bb9
commit 9a68e6e130
13 changed files with 94 additions and 139 deletions

View File

@ -172,8 +172,6 @@ supertuxkart_SOURCES = \
lisp/parser.hpp \
lisp/writer.cpp \
lisp/writer.hpp \
modes/clock.cpp \
modes/clock.hpp \
modes/follow_the_leader.cpp \
modes/follow_the_leader.hpp \
modes/linear_world.cpp \
@ -186,6 +184,8 @@ supertuxkart_SOURCES = \
modes/three_strikes_battle.hpp \
modes/world.cpp \
modes/world.hpp \
modes/world_status.cpp \
modes/world_status.hpp \
network/character_confirm_message.hpp \
network/character_info_message.hpp \
network/character_selected_message.hpp \

View File

@ -560,10 +560,6 @@
<Filter
Name="modes"
>
<File
RelativePath="..\..\modes\clock.cpp"
>
</File>
<File
RelativePath="..\..\modes\follow_the_leader.cpp"
>
@ -588,6 +584,10 @@
RelativePath="..\..\modes\world.cpp"
>
</File>
<File
RelativePath="..\..\modes\world_status.cpp"
>
</File>
</Filter>
<Filter
Name="items"
@ -1378,10 +1378,6 @@
<Filter
Name="modes"
>
<File
RelativePath="..\..\modes\clock.hpp"
>
</File>
<File
RelativePath="..\..\modes\follow_the_leader.hpp"
>
@ -1406,6 +1402,10 @@
RelativePath="..\..\modes\world.hpp"
>
</File>
<File
RelativePath="..\..\modes\world_status.hpp"
>
</File>
</Filter>
<Filter
Name="items"

View File

@ -54,7 +54,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
void Item::setType(ItemType type)
{
m_type = type;
m_rotate = type!=ITEM_BUBBLEGUM;
m_rotate = true;//type!=ITEM_BUBBLEGUM;
} // setType
//-----------------------------------------------------------------------------
@ -74,6 +74,8 @@ void Item::switchTo(ItemType type, scene::IMesh *mesh)
*/
void Item::switchBack()
{
if(m_original_type==ITEM_NONE)
printf("XX");
assert(m_original_type!=ITEM_NONE);
setType(m_original_type);
m_original_type = ITEM_NONE;
@ -151,10 +153,20 @@ void Item::update(float dt)
m_coord.setHPR(m_coord.getHPR()+rotation);
m_node->setRotation(m_coord.getHPR().toIrrHPR());
m_node->setPosition(m_coord.getXYZ().toIrrVector());
return;
core::quaternion q;
q.rotationFromTo(core::vector3df(0,1,0), m_normal.toIrrVector());
core::quaternion q2;
static float t=0;
t += dt;
q2.fromAngleAxis(t, m_normal.toIrrVector());
core::quaternion all=q*q2;
core::vector3df euler;
all.toEuler(euler);
m_node->setRotation(euler);
return;
#ifdef xx
btQuaternion q(Vec3(0,0,1), t*0.1f);
btQuaternion q_orig(m_normal, 0);
@ -163,6 +175,7 @@ void Item::update(float dt)
float y, p, r;
m.getEuler(y, p, r);
m_node->setRotation(Vec3(y, p, r).toIrrHPR());
#endif
}
} // update

View File

@ -30,7 +30,7 @@ FollowTheLeaderRace::FollowTheLeaderRace() : LinearWorld()
{
m_leader_intervals = stk_config->m_leader_intervals;
m_use_highscores = false; // disable high scores
TimedRace::setClockMode(COUNTDOWN, m_leader_intervals[0]);
setClockMode(COUNTDOWN, m_leader_intervals[0]);
}
//-----------------------------------------------------------------------------
@ -43,16 +43,18 @@ FollowTheLeaderRace::~FollowTheLeaderRace()
#pragma mark clock events
#endif
//-----------------------------------------------------------------------------
/** Called when a kart must be eliminated.
*/
void FollowTheLeaderRace::countdownReachedZero()
{
if(m_leader_intervals.size()>1)
m_leader_intervals.erase(m_leader_intervals.begin());
TimedRace::setTime(m_leader_intervals[0]);
WorldStatus::setTime(m_leader_intervals[0]);
int kart_number;
// If the leader kart is not the first kart, remove the first
// kart, otherwise remove the last kart.
int position_to_remove = m_kart[0]->getPosition()==1
? getCurrentNumKarts() : 1;
? getCurrentNumKarts() : 1;
const int kart_amount = m_kart.size();
for (kart_number=0; kart_number<kart_amount; kart_number++)
{
@ -101,41 +103,13 @@ bool FollowTheLeaderRace::isRaceOver()
return getCurrentNumKarts()==2 || getCurrentNumPlayers()==0;
} // isRaceOver
//-----------------------------------------------------------------------------
void FollowTheLeaderRace::onGo()
{
// 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();
}
}
//-----------------------------------------------------------------------------
void FollowTheLeaderRace::terminateRace()
{
LinearWorld::terminateRace();
}
#if 0
#pragma mark -
#pragma mark overridden from World
#endif
//-----------------------------------------------------------------------------
void FollowTheLeaderRace::update(float delta)
{
LinearWorld::update(delta);
}
//-----------------------------------------------------------------------------
void FollowTheLeaderRace::restartRace()
{
LinearWorld::restartRace();
m_leader_intervals.clear();
m_leader_intervals = stk_config->m_leader_intervals;
TimedRace::setClockMode(COUNTDOWN, m_leader_intervals[0]);
WorldStatus::setClockMode(COUNTDOWN, m_leader_intervals[0]);
} // restartRace
//-----------------------------------------------------------------------------

View File

@ -26,16 +26,13 @@ class FollowTheLeaderRace : public LinearWorld
std::vector<float> m_leader_intervals; // time till elimination in follow leader
public:
FollowTheLeaderRace();
FollowTheLeaderRace();
virtual ~FollowTheLeaderRace();
// clock events
virtual void countdownReachedZero();
virtual void onGo();
virtual void terminateRace();
// overriding World methods
virtual void update(float delta);
virtual void restartRace();
virtual std::string getIdent() const;
virtual bool useFastMusicNearEnd() const { return false; }

View File

@ -23,7 +23,7 @@
//-----------------------------------------------------------------------------
StandardRace::StandardRace() : LinearWorld()
{
TimedRace::setClockMode(CHRONO);
WorldStatus::setClockMode(CHRONO);
} // StandardRace
//-----------------------------------------------------------------------------
@ -36,35 +36,11 @@ StandardRace::~StandardRace()
#pragma mark clock events
#endif
//-----------------------------------------------------------------------------
void StandardRace::onGo()
{
// 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();
}
} // onGo
//-----------------------------------------------------------------------------
void StandardRace::terminateRace()
{
LinearWorld::terminateRace();
} // terminateRace
#if 0
#pragma mark -
#pragma mark overridden from World
#endif
//-----------------------------------------------------------------------------
void StandardRace::restartRace()
{
LinearWorld::restartRace();
} // restartRace
//-----------------------------------------------------------------------------
/** Called once per frame to update race specific data structures.
* \param dt TIme step size.
@ -72,7 +48,7 @@ void StandardRace::restartRace()
void StandardRace::update(float dt)
{
LinearWorld::update(dt);
if(!TimedRace::isRacePhase()) return;
if(!WorldStatus::isRacePhase()) return;
// All karts are finished
if(race_manager->getFinishedKarts() >= race_manager->getNumKarts() )

View File

@ -31,13 +31,10 @@ public:
virtual ~StandardRace();
// clock events
virtual void onGo();
virtual bool isRaceOver();
virtual void terminateRace();
// overriding World methods
virtual void update(float delta);
virtual void restartRace();
virtual void getDefaultCollectibles(int& collectible_type, int& amount);
virtual bool haveBonusBoxes();
virtual std::string getIdent() const;

View File

@ -26,7 +26,7 @@
//-----------------------------------------------------------------------------
ThreeStrikesBattle::ThreeStrikesBattle() : World()
{
TimedRace::setClockMode(CHRONO);
WorldStatus::setClockMode(CHRONO);
m_use_highscores = false;
World::init();
@ -59,17 +59,6 @@ ThreeStrikesBattle::~ThreeStrikesBattle()
delete[] m_kart_display_info;
} // ~ThreeStrikesBattle
//-----------------------------------------------------------------------------
void ThreeStrikesBattle::onGo()
{
// 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();
}
} // onGo
//-----------------------------------------------------------------------------
void ThreeStrikesBattle::terminateRace()
@ -82,7 +71,7 @@ void ThreeStrikesBattle::terminateRace()
{
if(!m_kart[i]->hasFinishedRace())
{
m_kart[i]->raceFinished(TimedRace::getTime());
m_kart[i]->raceFinished(WorldStatus::getTime());
} // if !hasFinishedRace
} // for i
@ -103,7 +92,7 @@ void ThreeStrikesBattle::kartHit(const int kart_id)
// check if kart is 'dead'
if(m_kart_info[kart_id].m_lives < 1)
{
m_kart[kart_id]->raceFinished(TimedRace::getTime());
m_kart[kart_id]->raceFinished(WorldStatus::getTime());
removeKart(kart_id);
}
@ -150,9 +139,9 @@ void ThreeStrikesBattle::updateKartRanks()
for( unsigned int n = 0; n < NUM_KARTS-1; ++n )
{
const int this_karts_time = m_kart[karts_list[n]]->hasFinishedRace() ?
(int)m_kart[karts_list[n]]->getFinishTime() : (int)TimedRace::getTime();
(int)m_kart[karts_list[n]]->getFinishTime() : (int)WorldStatus::getTime();
const int next_karts_time = m_kart[karts_list[n+1]]->hasFinishedRace() ?
(int)m_kart[karts_list[n+1]]->getFinishTime() : (int)TimedRace::getTime();
(int)m_kart[karts_list[n+1]]->getFinishTime() : (int)WorldStatus::getTime();
bool swap = false;
@ -186,7 +175,7 @@ void ThreeStrikesBattle::enterRaceOverState(const bool delay)
// Add the results for the remaining kart
for(int i=0; i<(int)race_manager->getNumKarts(); i++)
if(!m_kart[i]->isEliminated())
race_manager->RaceFinished(m_kart[i], TimedRace::getTime());
race_manager->RaceFinished(m_kart[i], WorldStatus::getTime());
} // enterRaceOverState
//-----------------------------------------------------------------------------

View File

@ -46,7 +46,6 @@ public:
virtual ~ThreeStrikesBattle();
// clock events
virtual void onGo();
virtual bool isRaceOver();
virtual void terminateRace();

View File

@ -58,11 +58,11 @@
* after the constructor. Those functions can be called in the init()
* function, which is called immediately after the constructor.
*/
World::World() : TimedRace()
World::World() : WorldStatus()
{
m_physics = NULL;
m_race_gui = NULL;
TimedRace::setClockMode( CHRONO );
WorldStatus::setClockMode( CHRONO );
} // World
// ----------------------------------------------------------------------------
@ -234,15 +234,29 @@ World::~World()
sound_manager -> stopMusic();
} // ~World
//-----------------------------------------------------------------------------
/** Called when 'go' is being displayed for the first time. Here the brakes
* of the karts are released.
*/
void World::onGo()
{
// 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();
}
} // onGo
//-----------------------------------------------------------------------------
void World::terminateRace()
{
updateHighscores();
TimedRace::pause();
// TODO - race results GUI
//menu_manager->pushMenu(MENUID_RACERESULT);
WorldStatus::pause();
unlock_manager->raceFinished();
}
} // terminateRace
//-----------------------------------------------------------------------------
/** Waits till each kart is resting on the ground
*
@ -323,7 +337,7 @@ void World::resetAllKarts()
void World::update(float dt)
{
if(history->replayHistory()) dt=history->getNextDelta();
TimedRace::update(dt);
WorldStatus::update(dt);
// Clear race state so that new information can be stored
race_state->clear();
@ -342,7 +356,7 @@ void World::update(float dt)
// The order of updates is rather important: if track update would
// be called before kart update, then the check manager (called from
// track update) will be using the old kart position to determine
// e.g. if a kart has started a new line. But linear world (from
// e.g. if a kart has crossed a new line. But linear world (from
// which this is called in case of a race) will be using the new
// position of the karts to determine the driveline quad a kart
// is on. So if a kart just arrived at quad 0 (meaning the distance
@ -477,7 +491,7 @@ void World::removeKart(int kart_number)
// ignored in all loops). Important:world->getCurrentNumKarts() returns
// the number of karts still racing. This value can not be used for loops
// over all karts, use race_manager->getNumKarts() instead!
race_manager->RaceFinished(kart, TimedRace::getTime());
race_manager->RaceFinished(kart, WorldStatus::getTime());
kart->eliminate();
m_eliminated_karts++;
@ -492,7 +506,7 @@ void World::getDefaultCollectibles(int& collectible_type, int& amount )
//-----------------------------------------------------------------------------
void World::restartRace()
{
TimedRace::reset();
WorldStatus::reset();
m_faster_music_active = false;
m_eliminated_karts = 0;
m_eliminated_players = 0;
@ -521,17 +535,17 @@ void World::pause()
{
sound_manager->pauseMusic();
sfx_manager->pauseAll();
TimedRace::pause();
}
WorldStatus::pause();
} // pause
//-----------------------------------------------------------------------------
void World::unpause()
{
sound_manager->resumeMusic() ;
sfx_manager->resumeAll();
TimedRace::unpause();
WorldStatus::unpause();
for(unsigned int i=0; i<m_player_karts.size(); i++)
m_player_karts[i]->resetInputState();
}
} // pause
/* EOF */

View File

@ -22,7 +22,7 @@
#include <vector>
#include "modes/clock.hpp"
#include "modes/world_status.hpp"
#include "network/network_kart.hpp"
#include "physics/physics.hpp"
#include "race/highscores.hpp"
@ -76,7 +76,7 @@ class Track;
* RaceManager).
*/
class World : public TimedRace
class World : public WorldStatus
{
public:
typedef std::vector<Kart*> Karts;
@ -118,6 +118,8 @@ protected:
/** Pointer to the race GUI. The race GUI is handedl by world. */
RaceGUI *m_race_gui;
virtual void onGo();
public:
World();
@ -152,8 +154,6 @@ public:
float getFastestLapTime() const { return m_fastest_lap; }
void setFastestLap(Kart *k, float time) {m_fastest_kart=k;m_fastest_lap=time; }
HighscoreEntry* getHighscores() const;
float getTime() const { return TimedRace::getTime(); }
Phase getPhase() const { return TimedRace::getPhase(); }
virtual void terminateRace();
@ -180,8 +180,8 @@ public:
* The code that draws the timer should call this first to know
* whether the game mode wants a timer drawn
*/
bool shouldDrawTimer() const { return TimedRace::isRacePhase() &&
TimedRace::getClockMode() != CLOCK_NONE; }
bool shouldDrawTimer() const { return isRacePhase() &&
getClockMode() != CLOCK_NONE; }
/** called when a bonus box is hit, to determine which types of powerups are allowed
in each game mode. By default all are accepted, override in child classes to get

View File

@ -15,7 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "modes/clock.hpp"
#include "modes/world_status.hpp"
#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
@ -24,7 +24,7 @@
#include "states_screens/dialogs/race_over_dialog.hpp"
//-----------------------------------------------------------------------------
TimedRace::TimedRace()
WorldStatus::WorldStatus()
{
m_mode = CHRONO;
m_time = 0.0f;
@ -36,10 +36,10 @@ TimedRace::TimedRace()
// FIXME - is it a really good idea to reload and delete the sound every race??
m_prestart_sound = sfx_manager->newSFX(SFXManager::SOUND_PRESTART);
m_start_sound = sfx_manager->newSFX(SFXManager::SOUND_START);
} // TimedRace
} // WorldStatus
//-----------------------------------------------------------------------------
void TimedRace::reset()
void WorldStatus::reset()
{
m_time = 0.0f;
m_auxiliary_timer = 0.0f;
@ -48,21 +48,21 @@ void TimedRace::reset()
} // reset
//-----------------------------------------------------------------------------
TimedRace::~TimedRace()
WorldStatus::~WorldStatus()
{
sfx_manager->deleteSFX(m_prestart_sound);
sfx_manager->deleteSFX(m_start_sound);
} // ~TimedRace
} // ~WorldStatus
//-----------------------------------------------------------------------------
void TimedRace::setClockMode(const ClockType mode, const float initial_time)
void WorldStatus::setClockMode(const ClockType mode, const float initial_time)
{
m_mode = mode;
m_time = initial_time;
} // setClockMode
//-----------------------------------------------------------------------------
void TimedRace::enterRaceOverState(const bool delay)
void WorldStatus::enterRaceOverState(const bool delay)
{
if(m_phase == DELAY_FINISH_PHASE || m_phase == FINISH_PHASE) return; // we already know
@ -79,7 +79,7 @@ void TimedRace::enterRaceOverState(const bool delay)
} // enterRaceOverState
//-----------------------------------------------------------------------------
void TimedRace::update(const float dt)
void WorldStatus::update(const float dt)
{
switch(m_phase)
{
@ -133,13 +133,10 @@ void TimedRace::update(const float dt)
if(m_auxiliary_timer < stk_config->m_delay_finish_time) break;
m_phase = FINISH_PHASE;
new RaceOverDialog(0.6f, 0.9f);
break;
// NOTE: no break, fall through to FINISH_PHASE handling!!
}
case FINISH_PHASE:
// event
new RaceOverDialog(0.6f, 0.9f);
terminateRace();
return;
default: break; // default for RACE_PHASE, LIMBO_PHASE
@ -164,18 +161,18 @@ void TimedRace::update(const float dt)
}
}
//-----------------------------------------------------------------------------
void TimedRace::setTime(const float time)
void WorldStatus::setTime(const float time)
{
m_time = time;
}
//-----------------------------------------------------------------------------
void TimedRace::pause()
void WorldStatus::pause()
{
m_previous_phase = m_phase;
m_phase = LIMBO_PHASE;
}
//-----------------------------------------------------------------------------
void TimedRace::unpause()
void WorldStatus::unpause()
{
m_phase = m_previous_phase;
}

View File

@ -54,7 +54,7 @@ enum Phase {
* A class that manages the clock (countdown, chrono, etc.) Also manages stuff
* like the 'ready/set/go' text at the beginning or the delay at the end of a race.
*/
class TimedRace
class WorldStatus
{
protected:
SFXBase *m_prestart_sound;
@ -66,7 +66,6 @@ protected:
float m_time;
ClockType m_mode;
Phase m_phase;
/**
@ -74,21 +73,21 @@ protected:
*/
Phase m_previous_phase;
public:
TimedRace();
virtual ~TimedRace();
WorldStatus();
virtual ~WorldStatus();
void reset();
// Note: GO_PHASE is both: start phase and race phase
bool isStartPhase() const { return m_phase<GO_PHASE; }
bool isStartPhase() const { return m_phase<GO_PHASE; }
bool isRacePhase() const { return m_phase>=GO_PHASE &&
m_phase<FINISH_PHASE; }
m_phase<FINISH_PHASE; }
/** While the race menu is being displayed, m_phase is limbo, and
* m_previous_phase is finish. So we have to test this case, too. */
bool isFinishPhase() const { return m_phase==FINISH_PHASE ||
(m_phase==LIMBO_PHASE &&
m_previous_phase==FINISH_PHASE);}
const Phase getPhase() const { return m_phase; }
const Phase getPhase() const { return m_phase; }
/**
* Counts time during the initial 'ready/set/go' phase, or at the end of a race.