diff --git a/src/Makefile.am b/src/Makefile.am index a16cac11d..572fbeb36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -175,6 +175,8 @@ supertuxkart_SOURCES = \ modes/follow_the_leader.hpp \ modes/linear_world.cpp \ modes/linear_world.hpp \ + modes/profile_world.cpp \ + modes/profile_world.hpp \ modes/standard_race.cpp \ modes/standard_race.hpp \ modes/three_strikes_battle.cpp \ diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index 85c65d325..a3e4831fc 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -388,6 +388,10 @@ RelativePath="..\..\modes\linear_world.cpp" > + + @@ -1118,6 +1122,10 @@ RelativePath="..\..\modes\linear_world.hpp" > + + diff --git a/src/karts/player_kart.cpp b/src/karts/player_kart.cpp index 3149569bc..f83d862d1 100644 --- a/src/karts/player_kart.cpp +++ b/src/karts/player_kart.cpp @@ -2,7 +2,7 @@ // // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2004-2005 Steve Baker -// Copyright (C) 2006 Joerg Henrichs, Steve Baker +// Copyright (C) 2006-2009 Joerg Henrichs, Steve Baker // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -24,21 +24,22 @@ #include "audio/sfx_manager.hpp" #include "config/player.hpp" #include "graphics/camera.hpp" -#include "states_screens/race_gui.hpp" #include "input/input_manager.hpp" #include "items/item.hpp" #include "modes/world.hpp" #include "race/history.hpp" +#include "states_screens/race_gui.hpp" #include "utils/constants.hpp" #include "utils/translation.hpp" -PlayerKart::PlayerKart(const std::string& kart_name, int position, ActivePlayer *player, - const btTransform& init_pos, int player_index) : +PlayerKart::PlayerKart(const std::string& kart_name, int position, + ActivePlayer *player, const btTransform& init_pos, + unsigned int player_index) : Kart(kart_name, position, init_pos) { m_player = player; m_penalty_time = 0.0f; - m_camera = new Camera(player_index, this); + m_camera = RaceManager::getWorld()->getRaceGUI()->addCamera(player_index, this); m_camera->setMode(Camera::CM_NORMAL); m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT ); @@ -215,7 +216,6 @@ void PlayerKart::steer(float dt, int steer_val) //----------------------------------------------------------------------------- void PlayerKart::update(float dt) { - m_camera->update(dt); // Don't do steering if it's replay. In position only replay it doesn't // matter, but if it's physics replay the gradual steering causes // incorrect results, since the stored values are already adjusted. diff --git a/src/karts/player_kart.hpp b/src/karts/player_kart.hpp index 03531cd08..1690cfb46 100644 --- a/src/karts/player_kart.hpp +++ b/src/karts/player_kart.hpp @@ -50,9 +50,10 @@ private: void steer(float, int); public: - PlayerKart(const std::string& kart_name, - int position, ActivePlayer *_player, - const btTransform& init_pos, int player_index); + PlayerKart(const std::string& kart_name, + int position, ActivePlayer *_player, + const btTransform& init_pos, + unsigned int player_index); ~PlayerKart (); int earlyStartPenalty () { return m_penalty_time>0; } ActivePlayer *getPlayer () { return m_player; } diff --git a/src/modes/follow_the_leader.cpp b/src/modes/follow_the_leader.cpp index 037fabc0b..30ac80445 100644 --- a/src/modes/follow_the_leader.cpp +++ b/src/modes/follow_the_leader.cpp @@ -128,14 +128,17 @@ void FollowTheLeaderRace::restartRace() m_leader_intervals.clear(); m_leader_intervals = stk_config->m_leader_intervals; TimedRace::setClockMode(COUNTDOWN, m_leader_intervals[0]); -} +} // restartRace + //----------------------------------------------------------------------------- -std::string FollowTheLeaderRace::getInternalCode() const +/** Returns the internal identifier for this kind of race. + */ +std::string FollowTheLeaderRace::getIdent() const { return "FOLLOW_LEADER"; } //----------------------------------------------------------------------------- -KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo() +RaceGUI::KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo() { LinearWorld::getKartsDisplayInfo(); m_kart_display_info[0].special_title = _("Leader"); diff --git a/src/modes/follow_the_leader.hpp b/src/modes/follow_the_leader.hpp index 49a1155e6..8d423b5e9 100644 --- a/src/modes/follow_the_leader.hpp +++ b/src/modes/follow_the_leader.hpp @@ -19,6 +19,7 @@ #define _follow_the_leader_hpp_ #include "modes/linear_world.hpp" +#include "states_screens/race_gui.hpp" class FollowTheLeaderRace : public LinearWorld { @@ -35,9 +36,9 @@ public: // overriding World methods virtual void update(float delta); virtual void restartRace(); - virtual std::string getInternalCode() const; + virtual std::string getIdent() const; virtual bool useFastMusicNearEnd() const { return false; } - virtual KartIconDisplayInfo* getKartsDisplayInfo(); + virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo(); virtual bool raceHasLaps(){ return false; } diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 3162d20e4..517bc495b 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -39,7 +39,7 @@ void LinearWorld::init() World::init(); const unsigned int kart_amount = m_kart.size(); - m_kart_display_info = new KartIconDisplayInfo[kart_amount]; + m_kart_display_info = new RaceGUI::KartIconDisplayInfo[kart_amount]; for(unsigned int n=0; ngetNumKarts(); for(unsigned int i = 0; i < kart_amount ; i++) { - KartIconDisplayInfo& rank_info = m_kart_display_info[i]; + RaceGUI::KartIconDisplayInfo& rank_info = m_kart_display_info[i]; Kart* kart = m_kart[i]; // reset color @@ -346,7 +346,7 @@ KartIconDisplayInfo* LinearWorld::getKartsDisplayInfo() // we now know the best time of the lap. fill the remaining bits of info for(unsigned int i = 0; i < kart_amount ; i++) { - KartIconDisplayInfo& rank_info = m_kart_display_info[i]; + RaceGUI::KartIconDisplayInfo& rank_info = m_kart_display_info[i]; KartInfo& kart_info = m_kart_info[i]; Kart* kart = m_kart[i]; diff --git a/src/modes/linear_world.hpp b/src/modes/linear_world.hpp index bbcc62e9e..ad743df35 100644 --- a/src/modes/linear_world.hpp +++ b/src/modes/linear_world.hpp @@ -18,11 +18,10 @@ #ifndef HEADER_LINEAR_WORLD_HPP #define HEADER_LINEAR_WORLD_HPP -#include "modes/world.hpp" #include -struct KartIconDisplayInfo; - +#include "modes/world.hpp" +#include "states_screens/race_gui.hpp" /* * A 'linear world' is a subcategory of world used in 'standard' races, i.e. * with a start line and a road that loops. This includes management of drivelines @@ -54,7 +53,7 @@ private: }; protected: - KartIconDisplayInfo* m_kart_display_info; + RaceGUI::KartIconDisplayInfo* m_kart_display_info; /** Linear races can trigger rescues for one additional reason : shortcuts. * It may need to do some specific world before calling the generic Kart::forceRescue @@ -88,7 +87,7 @@ public: void setTimeAtLapForKart(float t, const int kart_id); float getTimeAtLapForKart(const int kart_id) const; - virtual KartIconDisplayInfo* getKartsDisplayInfo(); + virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo(); virtual void moveKartAfterRescue(Kart* kart, btRigidBody* body); virtual void terminateRace(); diff --git a/src/modes/profile_world.cpp b/src/modes/profile_world.cpp new file mode 100644 index 000000000..8471e5802 --- /dev/null +++ b/src/modes/profile_world.cpp @@ -0,0 +1,73 @@ +// $Id: profile_world.cpp 3882 2009-08-18 11:05:40Z davemk $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009 Joerg Henrichs +// +// 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. + +#include "modes/profile_world.hpp" +#include "robots/default_robot.hpp" + +//----------------------------------------------------------------------------- +/** Prints the profile statistic and exits!! + */ +ProfileWorld::~ProfileWorld() +{ + float min_t=999999.9f, max_t=0.0, av_t=0.0; + for ( Karts::size_type i = 0; i < m_kart.size(); ++i) + { + max_t = std::max(max_t, m_kart[i]->getFinishTime()); + min_t = std::min(min_t, m_kart[i]->getFinishTime()); + av_t += m_kart[i]->getFinishTime(); + printf("%s start %d end %d time %f\n", + m_kart[i]->getName().c_str(),(int)i, + m_kart[i]->getPosition(), + m_kart[i]->getFinishTime()); + } + printf("min %f max %f av %f\n",min_t, max_t, av_t/m_kart.size()); + std::exit(-2); +} // ~ProfileWorld + +//----------------------------------------------------------------------------- +/** Creates a kart, having a certain position, starting location, and local + * and global player id (if applicable). + * \param kart_ident Identifier of the kart to create. + * \param index Index of the kart. + * \param local_player_id If the kart is a player kart this is the index of + * this player on the local machine. + * \param global_player_id If the akrt is a player kart this is the index of + * this player globally (i.e. including network players). + * \param init_pos The start XYZ coordinates. + */ +Kart *ProfileWorld::createKart(const std::string &kart_ident, int index, + int local_player_id, int global_player_id, + const btTransform &init_pos) +{ + // Create a camera for the last kart (since this way more of the + // karts can be seen. + Kart *newkart = new DefaultRobot(kart_ident, index+1, init_pos, m_track); + if(index==race_manager->getNumKarts()-1) + { + // The pointer to the camera does not have to be stored, since it + // the camera for robots is not modified. + RaceManager::getWorld()->getRaceGUI()->addCamera(index, newkart); + } + //m_local_player_karts[index] = static_cast(newkart); + //m_player_karts[index] = static_cast(newkart); + m_local_player_karts.clear(); + m_player_karts.clear(); + return newkart; +} // createKart + diff --git a/src/modes/profile_world.hpp b/src/modes/profile_world.hpp new file mode 100644 index 000000000..eb1cededf --- /dev/null +++ b/src/modes/profile_world.hpp @@ -0,0 +1,39 @@ +// $Id: profile_world.hpp 3849 2009-08-13 11:12:26Z hikerstk $ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009 Joerg Henrichs +// +// 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. + +#ifndef HEADER_PROFILE_WORLD_HPP +#define HEADER_PROFILE_WORLD_HPP + +#include "modes/standard_race.hpp" + +class Kart; + +class ProfileWorld : public StandardRace +{ + virtual Kart *createKart(const std::string &kart_ident, int index, + int local_player_id, int global_player_id, + const btTransform &init_pos); + +public: + virtual ~ProfileWorld(); + /** Returns identifier for this world. */ + virtual std::string getInternalCode() const {return "PROFILE"; } +}; + +#endif diff --git a/src/modes/standard_race.cpp b/src/modes/standard_race.cpp index 6af6e3889..e7ef1664b 100644 --- a/src/modes/standard_race.cpp +++ b/src/modes/standard_race.cpp @@ -24,13 +24,12 @@ StandardRace::StandardRace() : LinearWorld() { TimedRace::setClockMode(CHRONO); - LinearWorld::init(); -} +} // StandardRace //----------------------------------------------------------------------------- StandardRace::~StandardRace() { -} +} // ~StandardRace #if 0 #pragma mark - @@ -47,12 +46,13 @@ void StandardRace::onGo() { m_kart[i]->resetBrakes(); } -} +} // onGo + //----------------------------------------------------------------------------- void StandardRace::terminateRace() { LinearWorld::terminateRace(); -} +} // terminateRace #if 0 #pragma mark - @@ -63,7 +63,8 @@ void StandardRace::terminateRace() void StandardRace::restartRace() { LinearWorld::restartRace(); -} +} // restartRace + //----------------------------------------------------------------------------- void StandardRace::update(float delta) { @@ -74,7 +75,6 @@ void StandardRace::update(float delta) if(race_manager->getFinishedKarts() >= race_manager->getNumKarts() ) { TimedRace::enterRaceOverState(); - if(UserConfigParams::m_profile<0) printProfileResultAndExit(); unlock_manager->raceFinished(); } // if all karts are finished @@ -86,7 +86,7 @@ void StandardRace::update(float delta) // to give the AI some time to get non-estimated timings TimedRace::enterRaceOverState(true /* delay */); } -} +} // update //----------------------------------------------------------------------------- void StandardRace::getDefaultCollectibles(int& collectible_type, int& amount) @@ -98,18 +98,24 @@ void StandardRace::getDefaultCollectibles(int& collectible_type, int& amount) amount = race_manager->getNumLaps(); } else World::getDefaultCollectibles(collectible_type, amount); -} +} // getDefaultCollectibles + //----------------------------------------------------------------------------- -bool StandardRace::enableBonusBoxes() +/** Returns if this mode supports bonus boxes or not. + */ +bool StandardRace::haveBonusBoxes() { // in time trial mode, don't use bonus boxes return race_manager->getMinorMode() != RaceManager::MINOR_MODE_TIME_TRIAL; -} +} // haveBonusBoxes + //----------------------------------------------------------------------------- -std::string StandardRace::getInternalCode() const +/** Returns an identifier for this race. + */ +std::string StandardRace::getIdent() const { if(race_manager->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL) return "STD_TIMETRIAL"; else return "STANDARD"; -} +} // getIdent diff --git a/src/modes/standard_race.hpp b/src/modes/standard_race.hpp index c8a6e94bf..a515480b6 100644 --- a/src/modes/standard_race.hpp +++ b/src/modes/standard_race.hpp @@ -38,8 +38,8 @@ public: virtual void update(float delta); virtual void restartRace(); virtual void getDefaultCollectibles(int& collectible_type, int& amount); - virtual bool enableBonusBoxes(); - virtual std::string getInternalCode() const; + virtual bool haveBonusBoxes(); + virtual std::string getIdent() const; }; #endif diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index 7f7866671..90835d0d5 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -39,7 +39,7 @@ ThreeStrikesBattle::ThreeStrikesBattle() : World() } const unsigned int kart_amount = m_kart.size(); - m_kart_display_info = new KartIconDisplayInfo[kart_amount]; + m_kart_display_info = new RaceGUI::KartIconDisplayInfo[kart_amount]; for(unsigned int n=0; nsetPosition(-1); }// next kart -} +} // ThreeStrikesBattle + //----------------------------------------------------------------------------- ThreeStrikesBattle::~ThreeStrikesBattle() { delete[] m_kart_display_info; -} +} // ~ThreeStrikesBattle + //----------------------------------------------------------------------------- void ThreeStrikesBattle::onGo() { @@ -67,8 +69,9 @@ void ThreeStrikesBattle::onGo() { m_kart[i]->resetBrakes(); } -} +} // onGo //----------------------------------------------------------------------------- + void ThreeStrikesBattle::terminateRace() { updateKartRanks(); @@ -84,7 +87,8 @@ void ThreeStrikesBattle::terminateRace() } // for i World::terminateRace(); -} +} // terminateRace + //----------------------------------------------------------------------------- void ThreeStrikesBattle::kartHit(const int kart_id) { @@ -109,12 +113,16 @@ void ThreeStrikesBattle::kartHit(const int kart_id) sound_manager->switchToFastMusic(); m_faster_music_active = true; } -} +} // kartHit + //----------------------------------------------------------------------------- -std::string ThreeStrikesBattle::getInternalCode() const +/** Returns the internal identifier for this race. + */ +std::string ThreeStrikesBattle::getIdent() const { return "BATTLE_3_STRIKES"; -} +} // getIdent + //----------------------------------------------------------------------------- void ThreeStrikesBattle::updateKartRanks() { @@ -160,7 +168,8 @@ void ThreeStrikesBattle::updateKartRanks() m_kart[ karts_list[n] ]->setPosition( n+1 ); } delete [] karts_list; -} +} // updateKartRank + //----------------------------------------------------------------------------- void ThreeStrikesBattle::update(float delta) { @@ -178,7 +187,8 @@ void ThreeStrikesBattle::update(float delta) TimedRace::enterRaceOverState(); return; } -} +} // update + //----------------------------------------------------------------------------- void ThreeStrikesBattle::restartRace() { @@ -193,15 +203,15 @@ void ThreeStrikesBattle::restartRace() // no positions in this mode m_kart[n]->setPosition(-1); }// next kart -} -//void ThreeStrikesBattle::getDefaultCollectibles(int& collectible_type, int& amount) +} // restartRace + //----------------------------------------------------------------------------- -KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo() +RaceGUI::KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo() { const unsigned int kart_amount = race_manager->getNumKarts(); for(unsigned int i = 0; i < kart_amount ; i++) { - KartIconDisplayInfo& rank_info = m_kart_display_info[i]; + RaceGUI::KartIconDisplayInfo& rank_info = m_kart_display_info[i]; // reset color rank_info.lap = -1; @@ -237,7 +247,8 @@ KartIconDisplayInfo* ThreeStrikesBattle::getKartsDisplayInfo() } return m_kart_display_info; -} +} // getKartDisplayInfo + //----------------------------------------------------------------------------- void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body) { @@ -281,7 +292,8 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart, btRigidBody* body) body->setCenterOfMassTransform(pos); -} +} // moveKartAfterRescue + //----------------------------------------------------------------------------- void ThreeStrikesBattle::raceResultOrder( int* order ) { @@ -295,7 +307,8 @@ void ThreeStrikesBattle::raceResultOrder( int* order ) assert(pos < (int)num_karts); order[pos] = kart_id; } -} +} // raceResultOrder + //----------------------------------------------------------------------------- bool ThreeStrikesBattle::acceptPowerup(const int type) const { @@ -303,5 +316,5 @@ bool ThreeStrikesBattle::acceptPowerup(const int type) const if(type == POWERUP_PARACHUTE || type == POWERUP_ANVIL || type == POWERUP_ZIPPER) return false; return true; -} +} // acceptPowerup diff --git a/src/modes/three_strikes_battle.hpp b/src/modes/three_strikes_battle.hpp index 41192ef6e..0b2400adf 100644 --- a/src/modes/three_strikes_battle.hpp +++ b/src/modes/three_strikes_battle.hpp @@ -20,10 +20,10 @@ #ifndef THREE_STRIKES_HPP #define THREE_STRIKES_HPP -#include "modes/world.hpp" #include -struct KartIconDisplayInfo; +#include "modes/world.hpp" +#include "states_screens/race_gui.hpp" struct BattleInfo { @@ -32,7 +32,7 @@ struct BattleInfo class ThreeStrikesBattle : public World { - KartIconDisplayInfo* m_kart_display_info; + RaceGUI::KartIconDisplayInfo* m_kart_display_info; /** This vector contains an 'BattleInfo' struct for every kart in the race. */ @@ -52,12 +52,12 @@ public: //virtual void getDefaultCollectibles(int& collectible_type, int& amount); //virtual bool enableBonusBoxes(); virtual bool useFastMusicNearEnd() const { return false; } - virtual KartIconDisplayInfo* getKartsDisplayInfo(); + virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo(); virtual bool raceHasLaps(){ return false; } virtual void moveKartAfterRescue(Kart* kart, btRigidBody* body); virtual bool acceptPowerup(const int type) const; - virtual std::string getInternalCode() const; + virtual std::string getIdent() const; virtual void kartHit(const int kart_id); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index ba614de1a..ba4852076 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -52,6 +52,11 @@ #include "utils/string_utils.hpp" //----------------------------------------------------------------------------- +/** Constructor. Note that in the constructor it is not possible to call any + * functions that use RaceManager::getWorld(), since this is only defined + * after the constructor. Those functions can be called in the init() + * function, which is called immediately after the constructor. + */ World::World() : TimedRace() { m_physics = NULL; @@ -59,9 +64,12 @@ World::World() : TimedRace() } // World // ---------------------------------------------------------------------------- +/** This function is called after the World constructor. In init() functions + * can be called that use RaceManager::getWorld(). The init function is + * called immediately after the constructor. + */ void World::init() { - RaceManager::setWorld(this); race_state = new RaceState(); m_track = NULL; m_faster_music_active = false; @@ -106,24 +114,11 @@ void World::init() for(unsigned int i=0; igetNumKarts(); i++) { btTransform init_pos=m_track->getStartTransform(i); - Kart* newkart; const std::string& kart_ident = race_manager->getKartIdent(i); int local_player_id = race_manager->getKartLocalPlayerId(i); int global_player_id = race_manager->getKartGlobalPlayerId(i); - if(UserConfigParams::m_profile) - { - // Create a camera for the last kart (since this way more of the - // karts can be seen. - newkart = new DefaultRobot(kart_ident, i+1, init_pos, m_track, - (i==race_manager->getNumKarts()-1) ? 0 : -1); - // FIXME: does this actually work??? - m_local_player_karts[0] = static_cast(newkart); - } - else - { - newkart = createKart(kart_ident, i, local_player_id, - global_player_id, init_pos); - } // if !UserConfigParams::m_profile + Kart* newkart = this->createKart(kart_ident, i, local_player_id, + global_player_id, init_pos); m_kart.push_back(newkart); newkart->setWorldKartId(m_kart.size()-1); } // for i @@ -137,7 +132,7 @@ void World::init() if(!history->replayHistory()) history->initRecording(); network_manager->worldLoaded(); -} // World +} // init //----------------------------------------------------------------------------- /** Creates a kart, having a certain position, starting location, and local @@ -208,7 +203,7 @@ Kart* World::loadRobot(const std::string& kart_name, int position, } // loadRobot //----------------------------------------------------------------------------- - World::~World() +World::~World() { delete m_race_gui; delete race_state; @@ -355,7 +350,7 @@ HighscoreEntry* World::getHighscores() const { if(!m_use_highscores) return NULL; - const HighscoreEntry::HighscoreType type = "HST_" + getInternalCode(); + const HighscoreEntry::HighscoreType type = "HST_" + getIdent(); HighscoreEntry* highscores = highscore_manager->getHighscoreEntry(type, @@ -432,23 +427,6 @@ void World::updateHighscores() delete []index; } // updateHighscores -//----------------------------------------------------------------------------- -void World::printProfileResultAndExit() -{ - float min_t=999999.9f, max_t=0.0, av_t=0.0; - for ( Karts::size_type i = 0; i < m_kart.size(); ++i) - { - max_t = std::max(max_t, m_kart[i]->getFinishTime()); - min_t = std::min(min_t, m_kart[i]->getFinishTime()); - av_t += m_kart[i]->getFinishTime(); - printf("%s start %d end %d time %f\n", - m_kart[i]->getName().c_str(),(int)i, - m_kart[i]->getPosition(), - m_kart[i]->getFinishTime()); - } - printf("min %f max %f av %f\n",min_t, max_t, av_t/m_kart.size()); - std::exit(-2); -} // printProfileResultAndExit //----------------------------------------------------------------------------- /** Called in follow-leader-mode to remove the last kart diff --git a/src/modes/world.hpp b/src/modes/world.hpp index b814dfe12..b6c179c2f 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -28,10 +28,10 @@ #include "network/network_kart.hpp" #include "physics/physics.hpp" #include "race/highscores.hpp" +#include "states_screens/race_gui.hpp" #include "utils/random_generator.hpp" class SFXBase; -struct KartIconDisplayInfo; class btRigidBody; class Track; class RaceGUI; @@ -107,13 +107,12 @@ protected: void removeKart (int kart_number); Kart* loadRobot (const std::string& kart_name, int position, const btTransform& init_pos); - void printProfileResultAndExit(); void estimateFinishTimes(); - +public: virtual Kart *createKart(const std::string &kart_ident, int index, int local_player_id, int global_player_id, const btTransform &init_pos); - +protected: /** Pointer to the track. The track is managed by world. */ Track* m_track; @@ -128,7 +127,7 @@ public: /** call just after instanciating. can't be moved to the contructor as child classes must be instanciated, otherwise polymorphism will fail and the results will be incorrect */ - void init(); + virtual void init(); virtual ~World(); virtual void update(float delta); @@ -169,10 +168,10 @@ public: */ virtual bool enableBonusBoxes(){ return true; } - /** Each game mode should have a unique internal code. Override + /** Each game mode should have a unique identifier. Override * this method in child classes to provide it. */ - virtual std::string getInternalCode() const = 0; + virtual std::string getIdent() const = 0; virtual bool useFastMusicNearEnd() const { return true; } @@ -194,7 +193,7 @@ public: /** Called by the code that draws the list of karts on the race GUI * to know what needs to be drawn in the current mode */ - virtual KartIconDisplayInfo* getKartsDisplayInfo() = 0; + virtual RaceGUI::KartIconDisplayInfo* getKartsDisplayInfo() = 0; /** Since each mode will have a different way of deciding where a rescued * kart is dropped, this method will be called and each mode can implement it. diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index c67098765..7e71b734b 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -30,6 +30,7 @@ #include "input/input_manager.hpp" #include "karts/kart_properties_manager.hpp" #include "modes/follow_the_leader.hpp" +#include "modes/profile_world.hpp" #include "modes/standard_race.hpp" #include "modes/world.hpp" #include "modes/three_strikes_battle.hpp" @@ -38,30 +39,26 @@ RaceManager* race_manager= NULL; +World *RaceManager::m_world=NULL; //----------------------------------------------------------------------------- -World* world = NULL; -World* RaceManager::getWorld() -{ - return world; -} /** Call to set the world, or call setWorld(NULL) to delete the current world. */ -void RaceManager::setWorld(World* world_arg) +void RaceManager::setWorld(World* world) { - if(world != NULL) delete world; - world = world_arg; + assert(!m_world); + m_world = world; } Track* RaceManager::getTrack() { - return world->getTrack(); + return m_world->getTrack(); } Kart* RaceManager::getPlayerKart(const unsigned int n) { - return world->getPlayerKart(n); + return m_world->getPlayerKart(n); } Kart* RaceManager::getKart(const unsigned int n) { - return world->getKart(n); + return m_world->getKart(n); } //----------------------------------------------------------------------------- @@ -77,6 +74,7 @@ RaceManager::RaceManager() m_active_race = false; m_score_for_position = stk_config->m_scores; m_coin_target = 0; + m_world = NULL; setTrack("jungle"); setNumLocalPlayers(0); //setLocalKartInfo(0, "tux"); @@ -255,11 +253,21 @@ void RaceManager::startNextRace() // variable world. Admittedly a bit ugly, but simplifies // handling of objects which get created in the constructor // and need world to be defined. - if(m_minor_mode==MINOR_MODE_FOLLOW_LEADER) new FollowTheLeaderRace(); - else if(m_minor_mode==MINOR_MODE_QUICK_RACE || m_minor_mode==MINOR_MODE_TIME_TRIAL) new StandardRace(); - else if(m_minor_mode==MINOR_MODE_3_STRIKES) new ThreeStrikesBattle(); - else{ fprintf(stderr,"Could not create given race mode\n"); assert(0); } - + if (UserConfigParams::m_profile) + m_world = new ProfileWorld(); + else if(m_minor_mode==MINOR_MODE_FOLLOW_LEADER) + m_world = new FollowTheLeaderRace(); + else if(m_minor_mode==MINOR_MODE_QUICK_RACE || + m_minor_mode==MINOR_MODE_TIME_TRIAL) + m_world = new StandardRace(); + else if(m_minor_mode==MINOR_MODE_3_STRIKES) + m_world = new ThreeStrikesBattle(); + else + { + fprintf(stderr,"Could not create given race mode\n"); + assert(0); + } + m_world->init(); // Save the current score and set last time to zero. This is necessary // if someone presses esc after finishing a gp, and selects restart: // The race is rerun, and the points and scores get reset ... but if @@ -385,8 +393,8 @@ void RaceManager::exitRace() // FIXME - back to main menu // menu_manager->switchToMainMenu(); } - delete world; - world = 0; + delete m_world; + m_world = NULL; m_track_number = 0; m_active_race = false; } // exitRace @@ -426,7 +434,7 @@ void RaceManager::rerunRace() m_kart_status[i].m_score = m_kart_status[i].m_last_score; m_kart_status[i].m_overall_time -= m_kart_status[i].m_last_time; } - world->restartRace(); + m_world->restartRace(); } // rerunRace /* EOF */ diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index d8839be77..8a6fa4287 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -143,6 +143,9 @@ private: unsigned int m_num_finished_players; int m_coin_target; + /** The race manager manages the world, i.e. maintains + * this world pointer. */ + static World *m_world; void startNextRace(); // start a next race friend bool operator< (const KartStatus& left, const KartStatus& right) @@ -153,7 +156,7 @@ private: public: bool m_active_race; //True if there is a race - static World* getWorld(); + static World* getWorld() {return m_world;} static void setWorld(World* world); static Track* getTrack(); static Kart* getPlayerKart(const unsigned int n); diff --git a/src/robots/default_robot.cpp b/src/robots/default_robot.cpp index 285b166ea..3b17fc20a 100644 --- a/src/robots/default_robot.cpp +++ b/src/robots/default_robot.cpp @@ -37,7 +37,6 @@ #ifdef AI_DEBUG #include "graphics/irr_driver.hpp" #endif -#include "graphics/camera.hpp" #include "modes/linear_world.hpp" #include "network/network_manager.hpp" #include "race/race_manager.hpp" @@ -47,10 +46,9 @@ DefaultRobot::DefaultRobot(const std::string& kart_name, int position, const btTransform& init_pos, - const Track *track, int camera_number ) : + const Track *track) : AutoKart( kart_name, position, init_pos ) { - m_camera = camera_number >=0 ? new Camera(camera_number, this) : NULL; m_kart_length = m_kart_properties->getKartModel()->getLength(); m_kart_width = m_kart_properties->getKartModel()->getWidth(); m_track = RaceManager::getTrack(); diff --git a/src/robots/default_robot.hpp b/src/robots/default_robot.hpp index cdcd85fab..48a2747e8 100644 --- a/src/robots/default_robot.hpp +++ b/src/robots/default_robot.hpp @@ -28,7 +28,6 @@ class Track; class LinearWorld; class QuadGraph; class irr::scene::ISceneNode; -class Camera; class DefaultRobot : public AutoKart { @@ -154,10 +153,6 @@ private: * is targeting at. */ irr::scene::ISceneNode *m_debug_sphere; - /** A camera that can be attached to a robot. This is mainly a debugging - * tool, used in working on the AI and in doing profile runs. Otherwise - * this variable is not used. */ - Camera *m_camera; /** The minimum steering angle at which the AI adds skidding. Lower values * tend to improve the line the AI is driving. This is used to adjust for * different AI levels. @@ -192,8 +187,7 @@ private: public: DefaultRobot(const std::string& kart_name, int position, - const btTransform& init_pos, const Track *track, - int camera_number=-1); + const btTransform& init_pos, const Track *track); ~DefaultRobot(); void update (float delta) ; void reset (); diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index e6095089d..3744cae64 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -25,12 +25,14 @@ using namespace irr; #include "audio/sound_manager.hpp" #include "config/user_config.hpp" +#include "graphics/camera.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material_manager.hpp" #include "io/file_manager.hpp" #include "input/input.hpp" #include "input/input_manager.hpp" #include "karts/kart_properties_manager.hpp" +#include "modes/world.hpp" #include "race/race_manager.hpp" #include "tracks/track.hpp" #include "utils/constants.hpp" @@ -148,6 +150,17 @@ void RaceGUI::createRegularPolygon(unsigned int n, float radius, } // createRegularPolygon +//----------------------------------------------------------------------------- +/** Adds a camera. The number of cameras determines e.g. if split screen is + * used. + */ +Camera *RaceGUI::addCamera(unsigned int index, Kart *kart) +{ + Camera *camera = new Camera(index, kart); + m_cameras.push_back(camera); + return camera; +} // addCamera + //----------------------------------------------------------------------------- /** Called before rendering, so no direct output to the screen can be done * here. @@ -155,6 +168,9 @@ void RaceGUI::createRegularPolygon(unsigned int n, float radius, */ void RaceGUI::update(float dt) { + std::vector::iterator i; + for(i=m_cameras.begin(); i!=m_cameras.end(); i++) + (*i)->update(dt); cleanupMessages(dt); } // update @@ -709,7 +725,7 @@ void RaceGUI::drawStatusText() if(!RaceManager::getWorld()->isRacePhase()) return; - KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo(); + RaceGUI::KartIconDisplayInfo* info = RaceManager::getWorld()->getKartsDisplayInfo(); for(unsigned int pla = 0; pla < num_players; pla++) { @@ -769,7 +785,9 @@ void RaceGUI::drawStatusText() plunger_x+plunger_size, offset_y+plunger_size); const core::rect source(core::position2d(0,0), t->getOriginalSize()); - irr_driver->getVideoDriver()->draw2DImage(t, dest, source); + irr_driver->getVideoDriver()->draw2DImage(t, dest, source, 0, + &video::SColor(255,255,255,255), + true); } } // next player diff --git a/src/states_screens/race_gui.hpp b/src/states_screens/race_gui.hpp index 4fdb39bbe..1542369fd 100644 --- a/src/states_screens/race_gui.hpp +++ b/src/states_screens/race_gui.hpp @@ -29,31 +29,30 @@ using namespace irr; #include "config/player.hpp" -#include "graphics/material.hpp" -#include "karts/kart.hpp" -#include "karts/player_kart.hpp" -#include "modes/world.hpp" -#include "race/race_manager.hpp" +class Camera; class InputMap; +class Kart; +class Material; class RaceSetup; -/** - * Used to display the list of karts and their times or - * whatever other info is relevant to the current mode. - */ -struct KartIconDisplayInfo -{ - std::string time; - float r, g, b; - std::string special_title; - /** Current lap of this kart, or -1 if irrelevant - */ - int lap; -}; - class RaceGUI { +public: + /** + * Used to display the list of karts and their times or + * whatever other info is relevant to the current mode. + */ + struct KartIconDisplayInfo + { + std::string time; + float r, g, b; + std::string special_title; + /** Current lap of this kart, or -1 if irrelevant + */ + int lap; + }; // KartIconDisplayInfo + private: class TimedMessage { @@ -63,6 +62,7 @@ private: video::SColor m_color; // color of message int m_font_size; // size const Kart *m_kart; + // ----------------------------------------------------- // std::vector needs standard copy-ctor and std-assignment op. // let compiler create defaults .. they'll do the job, no // deep copies here .. @@ -75,14 +75,16 @@ private: m_kart = kart; m_remaining_time = ( time < 0.0f ) ? -1.0f : time; m_color = color; - } + } // TimedMessage + // ----------------------------------------------------- // in follow leader the clock counts backwards bool done(const float dt) { m_remaining_time -= dt; return m_remaining_time < 0; - } - }; + } // done + }; // TimedMessage + // --------------------------------------------------------- Material *m_speed_meter_icon; Material *m_speed_bar_icon; @@ -95,9 +97,11 @@ private: /** Musical notes icon (for music description and credits) */ Material *m_music_icon; + // Minimap related variables + // ------------------------- /** The mini map of the track. */ video::ITexture *m_mini_map; - /** The size of a single marker in pixels, must be a power of 2. */ + /** The size of a single marker in pixels, must be a power of 2. */ int m_marker_rendered_size; /** The size of a single marker on the screen for AI karts, @@ -126,7 +130,8 @@ private: /** Distance of map from bottom of screen. */ int m_map_bottom; - + /** The list of all cameras. */ + std::vector m_cameras; void createMarkerTexture(); void createRegularPolygon(unsigned int n, float radius, @@ -160,6 +165,7 @@ public: ~RaceGUI(); void render(); void update(float dt); + Camera *addCamera(unsigned int index, Kart *kart); void addMessage(const std::string &m, const Kart *kart, float time, int fonst_size, const video::SColor &color=video::SColor(255, 255, 0, 255)); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index bd5462bc2..2e1fede76 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -744,7 +744,7 @@ void Track::loadTrackModel() video::ITexture* t=irrMaterial.getTexture(j); if(!t) continue; core::matrix4 *m = &irrMaterial.getTextureMatrix(j); - m_animated_textures.push_back(new MovingTexture(m, 0.5f, 0.5f)); + m_animated_textures.push_back(new MovingTexture(m, 0.05f, 0.05f)); } // for j