From 9a68e6e1308b61873cf838ecfd40719639e482c1 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Mon, 8 Feb 2010 12:59:03 +0000 Subject: [PATCH] 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 --- src/Makefile.am | 4 +-- src/ide/vc9/supertuxkart.vcproj | 16 ++++----- src/items/item.cpp | 17 +++++++-- src/modes/follow_the_leader.cpp | 38 ++++---------------- src/modes/follow_the_leader.hpp | 5 +-- src/modes/standard_race.cpp | 28 ++------------- src/modes/standard_race.hpp | 3 -- src/modes/three_strikes_battle.cpp | 23 ++++--------- src/modes/three_strikes_battle.hpp | 1 - src/modes/world.cpp | 42 +++++++++++++++-------- src/modes/world.hpp | 12 +++---- src/modes/{clock.cpp => world_status.cpp} | 31 ++++++++--------- src/modes/{clock.hpp => world_status.hpp} | 13 ++++--- 13 files changed, 94 insertions(+), 139 deletions(-) rename src/modes/{clock.cpp => world_status.cpp} (91%) rename src/modes/{clock.hpp => world_status.hpp} (97%) diff --git a/src/Makefile.am b/src/Makefile.am index 7fef5eefc..6e02c4b0f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index 439857860..f8416e3ef 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -560,10 +560,6 @@ - - @@ -588,6 +584,10 @@ RelativePath="..\..\modes\world.cpp" > + + - - @@ -1406,6 +1402,10 @@ RelativePath="..\..\modes\world.hpp" > + + 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 diff --git a/src/modes/follow_the_leader.cpp b/src/modes/follow_the_leader.cpp index 3e012a907..4965eb550 100644 --- a/src/modes/follow_the_leader.cpp +++ b/src/modes/follow_the_leader.cpp @@ -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_numberresetBrakes(); - } -} -//----------------------------------------------------------------------------- -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 //----------------------------------------------------------------------------- diff --git a/src/modes/follow_the_leader.hpp b/src/modes/follow_the_leader.hpp index d10bc3bc2..b9119ac6f 100644 --- a/src/modes/follow_the_leader.hpp +++ b/src/modes/follow_the_leader.hpp @@ -26,16 +26,13 @@ class FollowTheLeaderRace : public LinearWorld std::vector 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; } diff --git a/src/modes/standard_race.cpp b/src/modes/standard_race.cpp index 57f79da16..6109d23e3 100644 --- a/src/modes/standard_race.cpp +++ b/src/modes/standard_race.cpp @@ -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; iresetBrakes(); - } -} // 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() ) diff --git a/src/modes/standard_race.hpp b/src/modes/standard_race.hpp index 2063756f0..42ef28c35 100644 --- a/src/modes/standard_race.hpp +++ b/src/modes/standard_race.hpp @@ -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; diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index e90b1c848..987077790 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -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; iresetBrakes(); - } -} // 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 //----------------------------------------------------------------------------- diff --git a/src/modes/three_strikes_battle.hpp b/src/modes/three_strikes_battle.hpp index a580795b5..13be07e0d 100644 --- a/src/modes/three_strikes_battle.hpp +++ b/src/modes/three_strikes_battle.hpp @@ -46,7 +46,6 @@ public: virtual ~ThreeStrikesBattle(); // clock events - virtual void onGo(); virtual bool isRaceOver(); virtual void terminateRace(); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 87f12da9c..e3455d567 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -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; iresetBrakes(); + } +} // 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; iresetInputState(); -} +} // pause /* EOF */ diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 7c757c2dd..4ddda112c 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -22,7 +22,7 @@ #include -#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 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 diff --git a/src/modes/clock.cpp b/src/modes/world_status.cpp similarity index 91% rename from src/modes/clock.cpp rename to src/modes/world_status.cpp index 9bdfd0c05..847278333 100644 --- a/src/modes/clock.cpp +++ b/src/modes/world_status.cpp @@ -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; } diff --git a/src/modes/clock.hpp b/src/modes/world_status.hpp similarity index 97% rename from src/modes/clock.hpp rename to src/modes/world_status.hpp index ff5e4c450..a3d1f92eb 100644 --- a/src/modes/clock.hpp +++ b/src/modes/world_status.hpp @@ -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 && - m_phase