From 340fc185487f8db8ed23884458e8c6356b1c85cb Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 22 Jan 2009 12:02:40 +0000 Subject: [PATCH] 1) Applied Jonan's patch to fix the layout for many files. 2) Moved STK specific extensions to bullet out of bullet src tree. 3) Started to move more files into separate subdirs. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3027 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/Makefile.am | 46 ++-- src/audio/music_information.cpp | 8 +- src/bullet/src/Makefile.am | 4 - src/bullet/src/btBulletDynamicsCommon.h | 2 - src/callback_manager.cpp | 2 +- src/callback_manager.hpp | 7 +- src/challenges/challenge.cpp | 77 +++--- src/challenges/challenge.hpp | 27 +- src/challenges/challenge_data.cpp | 18 +- src/challenges/challenge_data.hpp | 10 +- src/file_manager.cpp | 2 - src/flyable.hpp | 6 +- src/grand_prix_data.cpp | 2 +- src/gui/grand_prix_select.cpp | 2 +- src/gui/track_sel.cpp | 2 +- src/gui/widget.cpp | 7 +- src/ide/vc9/bullet_lib.vcproj | 16 -- src/ide/vc9/supertuxkart.vcproj | 128 ++++++---- src/items/plunger.cpp | 1 + src/karts/kart.cpp | 7 +- src/karts/kart.hpp | 132 +++++----- src/karts/moveable.cpp | 49 ++-- src/karts/moveable.hpp | 80 +++--- src/loader.cpp | 2 +- src/main.cpp | 2 +- src/modes/world.cpp | 4 +- src/network/connect_message.cpp | 2 +- .../Vehicle => physics}/btKart.cpp | 14 +- .../Vehicle/btKart.h => physics/btKart.hpp} | 9 +- .../btUprightConstraint.cpp | 8 +- .../btUprightConstraint.hpp} | 8 +- src/physics/kart_motion_state.hpp | 100 ++++---- src/{ => physics}/moving_physics.cpp | 0 src/{ => physics}/moving_physics.hpp | 0 src/physics/physics.cpp | 35 ++- src/physics/physics.hpp | 58 ++--- src/race_manager.cpp | 2 +- src/{ => replay}/replay_base.cpp | 0 src/{ => replay}/replay_base.hpp | 0 src/{ => replay}/replay_buffer_tpl.hpp | 0 src/{ => replay}/replay_buffers.cpp | 0 src/{ => replay}/replay_buffers.hpp | 0 src/{ => replay}/replay_player.cpp | 0 src/{ => replay}/replay_player.hpp | 0 src/{ => replay}/replay_recorder.cpp | 0 src/{ => replay}/replay_recorder.hpp | 0 src/terrain_info.cpp | 17 +- src/terrain_info.hpp | 26 +- src/track.cpp | 10 +- src/{ => tracks}/track_manager.cpp | 2 +- src/{ => tracks}/track_manager.hpp | 6 +- src/user_config.cpp | 211 +++++----------- src/user_config.hpp | 236 +++++++++--------- src/utils/random_generator.cpp | 25 +- src/utils/random_generator.hpp | 26 +- src/utils/vec3.hpp | 29 ++- 56 files changed, 709 insertions(+), 758 deletions(-) rename src/{bullet/src/BulletDynamics/Vehicle => physics}/btKart.cpp (99%) rename src/{bullet/src/BulletDynamics/Vehicle/btKart.h => physics/btKart.hpp} (89%) rename src/{bullet/src/BulletDynamics/ConstraintSolver => physics}/btUprightConstraint.cpp (95%) rename src/{bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.h => physics/btUprightConstraint.hpp} (90%) rename src/{ => physics}/moving_physics.cpp (100%) rename src/{ => physics}/moving_physics.hpp (100%) rename src/{ => replay}/replay_base.cpp (100%) rename src/{ => replay}/replay_base.hpp (100%) rename src/{ => replay}/replay_buffer_tpl.hpp (100%) rename src/{ => replay}/replay_buffers.cpp (100%) rename src/{ => replay}/replay_buffers.hpp (100%) rename src/{ => replay}/replay_player.cpp (100%) rename src/{ => replay}/replay_player.hpp (100%) rename src/{ => replay}/replay_recorder.cpp (100%) rename src/{ => replay}/replay_recorder.hpp (100%) rename src/{ => tracks}/track_manager.cpp (100%) rename src/{ => tracks}/track_manager.hpp (96%) diff --git a/src/Makefile.am b/src/Makefile.am index a4726b217..df069bcce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -139,11 +139,7 @@ supertuxkart_SOURCES = \ race_manager.hpp \ string_utils.cpp \ string_utils.hpp \ - track_manager.cpp \ - track_manager.hpp \ callback.hpp \ - moving_physics.hpp \ - moving_physics.cpp \ moving_texture.hpp \ moving_texture.cpp \ callback_manager.cpp \ @@ -244,13 +240,6 @@ supertuxkart_SOURCES = \ gui/feature_unlocked.hpp \ gui/font.hpp \ gui/font.cpp \ - physics/physics.cpp \ - physics/physics.hpp \ - physics/kart_motion_state.hpp \ - robots/default_robot.cpp \ - robots/default_robot.hpp \ - robots/track_info.cpp \ - robots/track_info.hpp \ modes/follow_the_leader.cpp \ modes/follow_the_leader.hpp \ modes/standard_race.cpp \ @@ -263,15 +252,32 @@ supertuxkart_SOURCES = \ modes/linear_world.hpp \ modes/three_strikes_battle.cpp \ modes/three_strikes_battle.hpp \ - replay_buffer_tpl.hpp \ - replay_buffers.hpp \ - replay_buffers.cpp \ - replay_base.hpp \ - replay_base.cpp \ - replay_player.hpp \ - replay_player.cpp \ - replay_recorder.hpp \ - replay_recorder.cpp + physics/btKart.cpp \ + physics/btKart.hpp \ + physics/btUprightConstraint.cpp \ + physics/btUprightConstraint.hpp \ + physics/moving_physics.hpp \ + physics/moving_physics.hpp \ + physics/moving_physics.cpp \ + physics/moving_physics.cpp \ + physics/physics.cpp \ + physics/physics.hpp \ + physics/kart_motion_state.hpp \ + robots/default_robot.cpp \ + robots/default_robot.hpp \ + robots/track_info.cpp \ + robots/track_info.hpp \ + tracks/track_manager.cpp \ + tracks/track_manager.hpp \ + replay/replay_buffer_tpl.hpp \ + replay/replay_buffers.hpp \ + replay/replay_buffers.cpp \ + replay/replay_base.hpp \ + replay/replay_base.cpp \ + replay/replay_player.hpp \ + replay/replay_player.cpp \ + replay/replay_recorder.hpp \ + replay/replay_recorder.cpp # This is a VERY ugly work-around for a compiler bug: if static_ssg s compiled with -O2 # (more particularly: with -fregmove, which is part of -O2), it will causes the kart diff --git a/src/audio/music_information.cpp b/src/audio/music_information.cpp index 2a9a181af..5d95a4558 100755 --- a/src/audio/music_information.cpp +++ b/src/audio/music_information.cpp @@ -21,14 +21,14 @@ #include -#include "audio/music_ogg.hpp" -#include "lisp/lisp.hpp" -#include "lisp/parser.hpp" #include "string_utils.hpp" -#include "track_manager.hpp" #include "translation.hpp" #include "user_config.hpp" #include "track.hpp" +#include "audio/music_ogg.hpp" +#include "lisp/lisp.hpp" +#include "lisp/parser.hpp" +#include "tracks/track_manager.hpp" #if defined(WIN32) && !defined(__CYGWIN__) # define snprintf _snprintf diff --git a/src/bullet/src/Makefile.am b/src/bullet/src/Makefile.am index c00fe886f..cfd8c777a 100644 --- a/src/bullet/src/Makefile.am +++ b/src/bullet/src/Makefile.am @@ -199,8 +199,6 @@ libbulletdynamics_a_SOURCES = \ BulletDynamics/ConstraintSolver/btSolverBody.h \ BulletDynamics/ConstraintSolver/btSolverConstraint.h \ BulletDynamics/ConstraintSolver/btTypedConstraint.cpp \ - BulletDynamics/ConstraintSolver/btUprightConstraint.h \ - BulletDynamics/ConstraintSolver/btUprightConstraint.cpp \ BulletDynamics/ConstraintSolver/btTypedConstraint.h \ BulletDynamics/Dynamics/btContinuousDynamicsWorld.cpp \ BulletDynamics/Dynamics/btContinuousDynamicsWorld.h \ @@ -212,8 +210,6 @@ libbulletdynamics_a_SOURCES = \ BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp \ BulletDynamics/Dynamics/btSimpleDynamicsWorld.h \ BulletDynamics/Dynamics/Bullet-C-API.cpp \ - BulletDynamics/Vehicle/btKart.cpp \ - BulletDynamics/Vehicle/btKart.h \ BulletDynamics/Vehicle/btRaycastVehicle.cpp \ BulletDynamics/Vehicle/btRaycastVehicle.h \ BulletDynamics/Vehicle/btVehicleRaycaster.h \ diff --git a/src/bullet/src/btBulletDynamicsCommon.h b/src/bullet/src/btBulletDynamicsCommon.h index 05f6418e2..ce9bb1d96 100644 --- a/src/bullet/src/btBulletDynamicsCommon.h +++ b/src/bullet/src/btBulletDynamicsCommon.h @@ -30,7 +30,6 @@ subject to the following restrictions: #include "BulletDynamics/ConstraintSolver/btConeTwistConstraint.h" #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" -#include "BulletDynamics/ConstraintSolver/btUprightConstraint.h" #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h" ///Optional ODE quickstep constraint solver, redistributed under ZLib license @@ -39,7 +38,6 @@ subject to the following restrictions: ///Vehicle simulation, with wheel contact simulated by raycasts #include "BulletDynamics/Vehicle/btRaycastVehicle.h" -#include "BulletDynamics/Vehicle/btKart.h" diff --git a/src/callback_manager.cpp b/src/callback_manager.cpp index 75c4a43fa..52067a67b 100644 --- a/src/callback_manager.cpp +++ b/src/callback_manager.cpp @@ -18,7 +18,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "callback_manager.hpp" -#include "moving_physics.hpp" +#include "physics/moving_physics.hpp" CallbackManager *callback_manager=NULL; diff --git a/src/callback_manager.hpp b/src/callback_manager.hpp index d4c54b20a..41842e307 100644 --- a/src/callback_manager.hpp +++ b/src/callback_manager.hpp @@ -17,13 +17,14 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef CALLBACK_MANAGER_H -#define CALLBACK_MANAGER_H +#ifndef CALLBACK_MANAGER_HPP +#define CALLBACK_MANAGER_HPP #include #include "btBulletDynamicsCommon.h" #include "callback.hpp" -#include "moving_physics.hpp" + +class MovingPhysics; // It might actually be enough to have only two different values: track (which // get deleted and loaded more than one), and everything else, which only diff --git a/src/challenges/challenge.cpp b/src/challenges/challenge.cpp index 783320ce5..17dd23a0c 100755 --- a/src/challenges/challenge.cpp +++ b/src/challenges/challenge.cpp @@ -20,48 +20,16 @@ #include "translation.hpp" #include "challenges/challenge.hpp" #include "race_manager.hpp" -#include "track_manager.hpp" #include "track.hpp" +#include "grand_prix_manager.hpp" #include "karts/kart_properties_manager.hpp" #include "karts/kart_properties.hpp" -#include "grand_prix_manager.hpp" +#include "tracks/track_manager.hpp" #if defined(WIN32) && !defined(__CYGWIN__) # define snprintf _snprintf #endif - -Challenge::Challenge(std::string id, std::string name) : - m_state(CH_INACTIVE), m_Id(id), m_Name(name) -{ -} // Challenge - -//----------------------------------------------------------------------------- -/** Loads the state for a challenge object (esp. m_state), and calls the - * virtual function loadState for additional information - */ -void Challenge::load(const lisp::Lisp* config) -{ - const lisp::Lisp* subnode= config->getLisp(getId()); - if(!subnode) return; - - // See if the challenge is solved (it's activated later from the - // unlock_manager). - bool finished=false; - subnode->get("solved", finished); - m_state = finished ? CH_SOLVED : CH_INACTIVE; - if(!finished) loadState(subnode); -} // load - -//----------------------------------------------------------------------------- -void Challenge::save(lisp::Writer* writer) -{ - writer->beginList(getId()); - writer->write("solved", isSolved()); - if(!isSolved()) saveState(writer); - writer->endList(getId()); -} // save - //----------------------------------------------------------------------------- void Challenge::addUnlockTrackReward(std::string track_name) { @@ -70,6 +38,7 @@ void Challenge::addUnlockTrackReward(std::string track_name) feature.type = UNLOCK_TRACK; m_feature.push_back(feature); } + //----------------------------------------------------------------------------- void Challenge::addUnlockModeReward(std::string internal_mode_name, std::string user_mode_name) { @@ -79,6 +48,7 @@ void Challenge::addUnlockModeReward(std::string internal_mode_name, std::string feature.user_name = user_mode_name; m_feature.push_back(feature); } + //----------------------------------------------------------------------------- void Challenge::addUnlockGPReward(std::string gp_name) { @@ -87,6 +57,7 @@ void Challenge::addUnlockGPReward(std::string gp_name) feature.type = UNLOCK_GP; m_feature.push_back(feature); } + //----------------------------------------------------------------------------- void Challenge::addUnlockDifficultyReward(std::string internal_name, std::string user_name) { @@ -96,6 +67,7 @@ void Challenge::addUnlockDifficultyReward(std::string internal_name, std::string feature.user_name = user_name; m_feature.push_back(feature); } + //----------------------------------------------------------------------------- void Challenge::addUnlockKartReward(std::string internal_name, std::string user_name) { @@ -105,19 +77,20 @@ void Challenge::addUnlockKartReward(std::string internal_name, std::string user_ feature.user_name = user_name; m_feature.push_back(feature); } + //----------------------------------------------------------------------------- const std::string Challenge::getUnlockedMessage() const { std::string unlocked_message; - + const unsigned int amount = (unsigned int)m_feature.size(); for(unsigned int n=0; n0) unlocked_message+='\n'; - + char message[128]; - + // write message depending on feature type switch(m_feature[n].type) { @@ -125,7 +98,7 @@ const std::string Challenge::getUnlockedMessage() const { // {} avoids compiler warning Track* track = track_manager->getTrack( m_feature[n].name ); snprintf(message, 127, _("New track '%s'\nnow available"), _(track->getName()) ); - break; + break; } case UNLOCK_MODE: snprintf(message, 127, _("New game mode\n'%s'\nnow available"), m_feature[n].user_name.c_str() ); @@ -146,6 +119,32 @@ const std::string Challenge::getUnlockedMessage() const } // switch unlocked_message += message; } // for n - + return unlocked_message; } + +//----------------------------------------------------------------------------- +/** Loads the state for a challenge object (esp. m_state), and calls the + * virtual function loadState for additional information + */ +void Challenge::load(const lisp::Lisp* config) +{ + const lisp::Lisp* subnode= config->getLisp(getId()); + if(!subnode) return; + + // See if the challenge is solved (it's activated later from the + // unlock_manager). + bool finished=false; + subnode->get("solved", finished); + m_state = finished ? CH_SOLVED : CH_INACTIVE; + if(!finished) loadState(subnode); +} // load + +//----------------------------------------------------------------------------- +void Challenge::save(lisp::Writer* writer) +{ + writer->beginList(getId()); + writer->write("solved", isSolved()); + if(!isSolved()) saveState(writer); + writer->endList(getId()); +} // save diff --git a/src/challenges/challenge.hpp b/src/challenges/challenge.hpp index 47b4a67bf..60b6cf5de 100755 --- a/src/challenges/challenge.hpp +++ b/src/challenges/challenge.hpp @@ -17,8 +17,8 @@ // 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_CHALLENGE_H -#define HEADER_CHALLENGE_H +#ifndef HEADER_CHALLENGE_HPP +#define HEADER_CHALLENGE_HPP #include #include @@ -36,7 +36,7 @@ enum REWARD_TYPE struct UnlockableFeature { - std::string name; // itnernal name + std::string name; // internal name std::string user_name; // not all types of feature have one REWARD_TYPE type; }; @@ -44,6 +44,7 @@ struct UnlockableFeature // A base class for all challenges class Challenge { +private: enum {CH_INACTIVE, // challenge not yet possible CH_ACTIVE, // challenge possible, but not yet solved CH_SOLVED} m_state; // challenge was solved @@ -56,15 +57,17 @@ public: Challenge(std::string id, std::string name); Challenge() {m_Id=""; m_Name="";m_state=CH_INACTIVE;} virtual ~Challenge() {}; - const std::string& getId() const { return m_Id; } - const std::string& getName() const { return m_Name; } - void setName(const std::string& s) { m_Name = s; } - void setId(const std::string& s) { m_Id = s; } - void addUnlockTrackReward(std::string track_name); - void addUnlockModeReward(std::string internal_mode_name, std::string user_mode_name); - void addUnlockGPReward(std::string gp_name); - void addUnlockDifficultyReward(std::string internal_name, std::string user_name); - void addUnlockKartReward(std::string internal_name, std::string user_name); + const std::string + &getId() const { return m_Id; } + const std::string + &getName() const { return m_Name; } + void setName(const std::string& s) { m_Name = s; } + void setId(const std::string& s) { m_Id = s; } + void addUnlockTrackReward(std::string track_name); + void addUnlockModeReward(std::string internal_mode_name, std::string user_mode_name); + void addUnlockGPReward(std::string gp_name); + void addUnlockDifficultyReward(std::string internal_name, std::string user_name); + void addUnlockKartReward(std::string internal_name, std::string user_name); const std::string getUnlockedMessage() const; const std::vector& diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index 71a823a93..2b2619582 100755 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -24,17 +24,16 @@ #include "translation.hpp" #include "grand_prix_data.hpp" #include "grand_prix_manager.hpp" -#include "track_manager.hpp" #include "karts/kart.hpp" #include "lisp/lisp.hpp" #include "lisp/parser.hpp" #include "modes/linear_world.hpp" +#include "tracks/track_manager.hpp" #if defined(WIN32) && !defined(__CYGWIN__) # define snprintf _snprintf #endif - ChallengeData::ChallengeData(const std::string& filename) { m_filename = filename; @@ -72,7 +71,7 @@ ChallengeData::ChallengeData(const std::string& filename) m_major = RaceManager::MAJOR_MODE_SINGLE; else error("major"); - + lisp->get("minor", mode); if(mode=="timetrial") m_minor = RaceManager::MINOR_MODE_TIME_TRIAL; @@ -91,9 +90,9 @@ ChallengeData::ChallengeData(const std::string& filename) setChallengeDescription(s); if(!lisp->get("karts", m_num_karts) ) error("karts"); // Position is optional except in GP and FTL - if(!lisp->get("position", m_position) && + if(!lisp->get("position", m_position) && //RaceManager::getWorld()->areKartsOrdered() ) // FIXME - order and optional are not the same thing - (m_minor==RaceManager::MINOR_MODE_FOLLOW_LEADER || + (m_minor==RaceManager::MINOR_MODE_FOLLOW_LEADER || m_major==RaceManager::MAJOR_MODE_GRAND_PRIX)) error("position"); lisp->get("difficulty", s); @@ -115,13 +114,13 @@ ChallengeData::ChallengeData(const std::string& filename) if(!lisp->get("track", m_track_name )) error("track"); if(!lisp->get("laps", m_num_laps ) && m_minor!=RaceManager::MINOR_MODE_FOLLOW_LEADER) - error("laps"); + error("laps"); } else // GP { if(!lisp->get("gp", m_gp_id )) error("gp"); } - + getUnlocks(lisp, "unlock-track", UNLOCK_TRACK); getUnlocks(lisp, "unlock-gp", UNLOCK_GP ); getUnlocks(lisp, "unlock-mode", UNLOCK_MODE ); @@ -275,6 +274,7 @@ bool ChallengeData::raceFinished() if(m_time>0.0f && kart->getFinishTime()>m_time) return false; // too slow return true; } // raceFinished + // ---------------------------------------------------------------------------- bool ChallengeData::grandPrixFinished() { @@ -291,6 +291,6 @@ bool ChallengeData::grandPrixFinished() const int rank = race_manager->getKartFinalGPRank(kart->getWorldKartId()); //printf("getting rank for %s : %i \n", kart->getName().c_str(), rank ); if( rank != 0 ) return false; - - return true; + + return true; } // grandPrixFinished diff --git a/src/challenges/challenge_data.hpp b/src/challenges/challenge_data.hpp index 27c97da8a..b4e8ce0a6 100755 --- a/src/challenges/challenge_data.hpp +++ b/src/challenges/challenge_data.hpp @@ -17,8 +17,8 @@ // 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_CHALLENGE_DATA_H -#define HEADER_CHALLENGE_DATA_H +#ifndef HEADER_CHALLENGE_DATA_HPP +#define HEADER_CHALLENGE_DATA_HPP #include #include @@ -27,7 +27,7 @@ #include "challenges/challenge.hpp" #include "race_manager.hpp" -class ChallengeData : public Challenge +class ChallengeData : public Challenge { private: RaceManager::MajorRaceModeType m_major; @@ -42,8 +42,8 @@ private: int m_energy; std::vector m_depends_on; std::vector m_unlock; - std::string m_filename; + void getUnlocks(const lisp::Lisp *lisp, const char* type, REWARD_TYPE reward); void error(const char *id) const; @@ -55,4 +55,4 @@ public: virtual bool grandPrixFinished(); }; // ChallengeData -#endif +#endif // HEADER_CHALLENGE_DATA_HPP diff --git a/src/file_manager.cpp b/src/file_manager.cpp index ed635d150..91b9b269a 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -42,8 +42,6 @@ #include #include "file_manager.hpp" #include "btBulletDynamicsCommon.h" -#include "moving_physics.hpp" -#include "moving_texture.hpp" #include "translation.hpp" #include "material_manager.hpp" #include "string_utils.hpp" diff --git a/src/flyable.hpp b/src/flyable.hpp index a935b3959..b21e00304 100644 --- a/src/flyable.hpp +++ b/src/flyable.hpp @@ -17,10 +17,9 @@ // 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_FLYABLE_H -#define HEADER_FLYABLE_H +#ifndef HEADER_FLYABLE_HPP +#define HEADER_FLYABLE_HPP -#include "moving_physics.hpp" #include "terrain_info.hpp" #include "audio/sfx_manager.hpp" #include "items/powerup_manager.hpp" @@ -28,6 +27,7 @@ class FlyableInfo; class Kart; +class MovingPhysics; class Flyable : public Moveable, public TerrainInfo { diff --git a/src/grand_prix_data.cpp b/src/grand_prix_data.cpp index 52f23b989..b561af339 100644 --- a/src/grand_prix_data.cpp +++ b/src/grand_prix_data.cpp @@ -25,7 +25,7 @@ #include "lisp/lisp.hpp" #include "grand_prix_data.hpp" #include "string_utils.hpp" -#include "track_manager.hpp" +#include "tracks/track_manager.hpp" GrandPrixData::GrandPrixData(const std::string filename) { diff --git a/src/gui/grand_prix_select.cpp b/src/gui/grand_prix_select.cpp index f4b25e702..97a1a4822 100644 --- a/src/gui/grand_prix_select.cpp +++ b/src/gui/grand_prix_select.cpp @@ -22,11 +22,11 @@ #include "widget_manager.hpp" #include "menu_manager.hpp" #include "race_manager.hpp" -#include "track_manager.hpp" #include "material_manager.hpp" #include "unlock_manager.hpp" #include "translation.hpp" #include "grand_prix_manager.hpp" +#include "tracks/track_manager.hpp" enum WidgetTokens { diff --git a/src/gui/track_sel.cpp b/src/gui/track_sel.cpp index fbdbf56a9..7e44fab3c 100644 --- a/src/gui/track_sel.cpp +++ b/src/gui/track_sel.cpp @@ -20,12 +20,12 @@ #include "track_sel.hpp" #include "widget_manager.hpp" #include "race_manager.hpp" -#include "track_manager.hpp" #include "track.hpp" #include "menu_manager.hpp" #include "user_config.hpp" #include "translation.hpp" #include "unlock_manager.hpp" +#include "tracks/track_manager.hpp" #if defined(WIN32) && !defined(__CYGWIN__) # define snprintf _snprintf diff --git a/src/gui/widget.cpp b/src/gui/widget.cpp index ecf43b2e8..fbc1faece 100644 --- a/src/gui/widget.cpp +++ b/src/gui/widget.cpp @@ -19,15 +19,16 @@ #include "widget.hpp" +#include +#include + //FIXME: this should be removed when the scrolling is cleaned #include "user_config.hpp" #include "constants.hpp" -#include "track_manager.hpp" #include "material_manager.hpp" #include "track.hpp" -#include -#include +#include "tracks/track_manager.hpp" const int Widget::MAX_SCROLL = 1000000; diff --git a/src/ide/vc9/bullet_lib.vcproj b/src/ide/vc9/bullet_lib.vcproj index 796804c5d..8a18b7d88 100755 --- a/src/ide/vc9/bullet_lib.vcproj +++ b/src/ide/vc9/bullet_lib.vcproj @@ -487,10 +487,6 @@ RelativePath="..\..\bullet\src\BulletDynamics\ConstraintSolver\btTypedConstraint.cpp" > - - - - @@ -1089,10 +1081,6 @@ RelativePath="..\..\bullet\src\BulletDynamics\ConstraintSolver\btTypedConstraint.h" > - - - - diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index 3bb52aed6..0a293389a 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -735,10 +735,6 @@ RelativePath="../../../src\material_manager.cpp" > - - @@ -747,22 +743,6 @@ RelativePath="../../../src\race_manager.cpp" > - - - - - - - - @@ -795,10 +775,6 @@ RelativePath="../../../src\track.cpp" > - - @@ -1106,6 +1082,18 @@ + + + + + + @@ -1199,6 +1187,34 @@ > + + + + + + + + + + + + + + - - - - - - - - - - @@ -1369,10 +1365,6 @@ RelativePath="../../../src\track.hpp" > - - @@ -1780,6 +1772,14 @@ + + + + @@ -1845,6 +1845,38 @@ > + + + + + + + + + + + + + + + + setErp(1.0f); m_uprightConstraint->setLimitSoftness(1.0f); m_uprightConstraint->setDamping(0.0f); - RaceManager::getWorld()->getPhysics()->addKart(this, m_vehicle); + RaceManager::getWorld()->getPhysics()->addKart(this); //create the engine sound if(m_engine_sound) @@ -316,7 +317,7 @@ void Kart::reset() // physics world. Add it again. if(m_eliminated || m_rescue) { - RaceManager::getWorld()->getPhysics()->addKart(this, m_vehicle); + RaceManager::getWorld()->getPhysics()->addKart(this); } m_attachment.clear(); @@ -968,7 +969,7 @@ void Kart::endRescue() // let the mode decide where to put the kart RaceManager::getWorld()->moveKartAfterRescue(this, m_body); - RaceManager::getWorld()->getPhysics()->addKart(this, m_vehicle); + RaceManager::getWorld()->getPhysics()->addKart(this); } // endRescue //----------------------------------------------------------------------------- diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 3414212ec..63ff8ca12 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -26,25 +26,27 @@ #include "btBulletDynamicsCommon.h" #include "terrain_info.hpp" +#include "items/attachment.hpp" +#include "items/powerup.hpp" #include "karts/moveable.hpp" #include "karts/kart_properties.hpp" #include "karts/kart_control.hpp" -#include "items/attachment.hpp" -#include "items/powerup.hpp" #include "karts/kart_model.hpp" +#include "physics/btKart.hpp" class SkidMarks; class Item; class Smoke; class Nitro; class SFXBase; +class btUprightConstraint; class Kart : public TerrainInfo, public Moveable { private: btTransform m_reset_transform; // reset position unsigned int m_world_kart_id; // index of kart in world - float m_skidding; /**< Accumulated skidding factor. */ + float m_skidding; ///< Accumulated skidding factor. protected: Attachment m_attachment; @@ -59,63 +61,58 @@ protected: * This reduction is accumulated in m_max_speed_reduction. */ float m_max_speed_reduction; float m_power_reduction; - float m_max_gear_rpm; //maximum engine rpm's for the current gear + float m_max_gear_rpm; /** 0 - the number it contains is the time left before removing plunger */ - float m_view_blocked_by_plunger; - - float m_speed; + /** When a kart has its view blocked by the plunger, this variable will be + * > 0 the number it contains is the time left before removing plunger. */ + float m_view_blocked_by_plunger; + float m_speed; + float m_current_gear_ratio; + bool m_rescue; + bool m_eliminated; - float m_current_gear_ratio; - bool m_rescue; - bool m_eliminated; - - SFXBase *m_engine_sound; - SFXBase *m_beep_sound; - SFXBase *m_crash_sound; - SFXBase *m_skid_sound; - SFXBase *m_goo_sound; - float m_time_last_crash; + SFXBase *m_engine_sound; + SFXBase *m_beep_sound; + SFXBase *m_crash_sound; + SFXBase *m_skid_sound; + SFXBase *m_goo_sound; + float m_time_last_crash; protected: float m_rescue_pitch, m_rescue_roll; @@ -129,22 +126,45 @@ public: unsigned int getWorldKartId() const { return m_world_kart_id; } void setWorldKartId(unsigned int n) { m_world_kart_id=n; } void loadData(); - virtual void updateGraphics (const Vec3& off_xyz, const Vec3& off_hpr); + virtual void updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr); const KartProperties* - getKartProperties () const { return m_kart_properties; } - void setKartProperties (const KartProperties *kp) - { m_kart_properties=kp; } - void attach (attachmentType attachment_, float time) - { m_attachment.set(attachment_, time); } - void setPowerup (PowerupType t, int n) - { m_powerup.set(t, n); } - virtual void setPosition (int p) - { m_race_position = p; } - - Attachment *getAttachment () { return &m_attachment; } - void setAttachmentType (attachmentType t, float time_left=0.0f, - Kart*k=NULL) - { m_attachment.set(t, time_left, k); } + getKartProperties() const { return m_kart_properties; } + // ------------------------------------------------------------------------ + /** Sets the kart properties. */ + void setKartProperties(const KartProperties *kp) + { + m_kart_properties=kp; + } + // ------------------------------------------------------------------------ + /** Sets the attachment and time it stays attached. */ + void attach(attachmentType attachment_, float time) + { + m_attachment.set(attachment_, time); + } + // ------------------------------------------------------------------------ + /** Sets a new powerup. */ + void setPowerup (PowerupType t, int n) + { + m_powerup.set(t, n); + } + // ------------------------------------------------------------------------ + /** Sets the position in race this kart has (1<=p<=n). */ + virtual void setPosition(int p) + { + m_race_position = p; + } + // ------------------------------------------------------------------------ + Attachment *getAttachment() + { + return &m_attachment; + } + // ------------------------------------------------------------------------ + void setAttachmentType(attachmentType t, float time_left=0.0f, Kart*k=NULL) + { + m_attachment.set(t, time_left, k); + } + // ------------------------------------------------------------------------ + Powerup *getPowerup () { return &m_powerup; } int getNumPowerup () const { return m_powerup.getNum();} float getEnergy () const { return m_collected_energy;} diff --git a/src/karts/moveable.cpp b/src/karts/moveable.cpp index e69fb7e3e..c017db52c 100644 --- a/src/karts/moveable.cpp +++ b/src/karts/moveable.cpp @@ -45,12 +45,20 @@ Moveable::~Moveable() // FIXME LEAK: what about model? ssgDeRefDelete(m_model_transform) } // ~Moveable +//----------------------------------------------------------------------------- +void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) +{ + Vec3 xyz=getXYZ()+off_xyz; + Vec3 hpr=getHPR()+off_hpr; + sgCoord c=Coord(xyz, hpr).toSgCoord(); + + m_model_transform->setTransform(&c); +} // updateGraphics + //----------------------------------------------------------------------------- // The reset position must be set before calling reset void Moveable::reset() { - m_material_hot = NULL; - m_normal_hot = NULL; if(m_body) { m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0)); @@ -62,9 +70,20 @@ void Moveable::reset() } // reset //----------------------------------------------------------------------------- -void Moveable::createBody(float mass, btTransform& trans, +void Moveable::update(float dt) +{ + m_motion_state->getWorldTransform(m_transform); + m_velocityLC = getVelocity()*getTrans().getBasis(); + m_hpr.setHPR(m_transform.getBasis()); + + updateGraphics(Vec3(0,0,0), Vec3(0,0,0)); + m_first_time = false ; +} // update + + +//----------------------------------------------------------------------------- +void Moveable::createBody(float mass, btTransform& trans, btCollisionShape *shape) { - btVector3 inertia; shape->calculateLocalInertia(mass, inertia); m_transform = trans; @@ -95,25 +114,3 @@ void Moveable::setTrans(const btTransform &t) m_transform=t; m_motion_state->setWorldTransform(t); } // setTrans - -//----------------------------------------------------------------------------- -void Moveable::update(float dt) -{ - m_motion_state->getWorldTransform(m_transform); - m_velocityLC = getVelocity()*getTrans().getBasis(); - m_hpr.setHPR(m_transform.getBasis()); - - updateGraphics(Vec3(0,0,0), Vec3(0,0,0)); - m_first_time = false ; -} // update - -//----------------------------------------------------------------------------- -void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) -{ - Vec3 xyz=getXYZ()+off_xyz; - Vec3 hpr=getHPR()+off_hpr; - sgCoord c=Coord(xyz, hpr).toSgCoord(); - - m_model_transform->setTransform(&c); -} // updateGraphics - diff --git a/src/karts/moveable.hpp b/src/karts/moveable.hpp index 43b57a894..9e4e3a9cc 100644 --- a/src/karts/moveable.hpp +++ b/src/karts/moveable.hpp @@ -18,8 +18,8 @@ // 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_MOVEABLE_H -#define HEADER_MOVEABLE_H +#ifndef HEADER_MOVEABLE_HPP +#define HEADER_MOVEABLE_HPP #define _WINSOCKAPI_ #include @@ -36,50 +36,66 @@ class Material; #define MAX_ITEMS_COLLECTED 20 -class Moveable +class Moveable { private: - btVector3 m_velocityLC; /* velocity in kart coordinates */ + btVector3 m_velocityLC; /**getLinearVelocity();} - const btVector3 &getVelocityLC() const {return m_velocityLC; } + Moveable(); + virtual ~Moveable(); + ssgTransform *getModelTransform() {return m_model_transform; } + virtual const btVector3 + &getVelocity() const {return m_body->getLinearVelocity();} + const btVector3 + &getVelocityLC() const {return m_velocityLC; } virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); } - const Vec3& getXYZ () const {return (Vec3&)m_transform.getOrigin();} - const Vec3& getHPR () const {return m_hpr; } - const btQuaternion getRotation() const {return m_transform.getRotation(); } - void setXYZ (const Vec3& a) {m_transform.setOrigin(a); - m_motion_state->setWorldTransform(m_transform);} - void setRotation (const btQuaternion&a){m_transform.setRotation(a); - m_motion_state->setWorldTransform(m_transform);} - void setXYZRotation(const Vec3& xyz, const btQuaternion& a) - {m_transform.setRotation(a); - m_transform.setOrigin(xyz); - m_motion_state->setWorldTransform(m_transform);} - const sgVec4* getNormalHOT () const {return m_normal_hot; } + const Vec3& getXYZ() const {return (Vec3&)m_transform.getOrigin();} + const Vec3& getHPR() const {return m_hpr; } + const btQuaternion + getRotation() const {return m_transform.getRotation(); } + + /** Sets the XYZ coordinates of the moveable. */ + void setXYZ(const Vec3& a) + { + m_transform.setOrigin(a); + m_motion_state->setWorldTransform(m_transform); + } + // ------------------------------------------------------------------------ + /** Sets the rotation of this moveable. */ + void setRotation(const btQuaternion&a) + { + m_transform.setRotation(a); + m_motion_state->setWorldTransform(m_transform); + } + // ------------------------------------------------------------------------ + /** Sets XYZ position and rotation of this moveable. */ + void setXYZRotation(const Vec3& xyz, const btQuaternion& a) + { + m_transform.setRotation(a); + m_transform.setOrigin(xyz); + m_motion_state->setWorldTransform(m_transform); + } + // ------------------------------------------------------------------------ + virtual void handleZipper () {}; virtual void updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr); - virtual void handleZipper () {}; - virtual void reset (); - virtual void update (float dt) ; - btRigidBody* getBody () const {return m_body; } + virtual void reset(); + virtual void update(float dt) ; + btRigidBody *getBody() const {return m_body; } void createBody(float mass, btTransform& trans, btCollisionShape *shape); - const btTransform& getTrans() const {return m_transform;} - void setTrans (const btTransform& t); + const btTransform + &getTrans() const {return m_transform;} + void setTrans(const btTransform& t); } ; // class Moveable diff --git a/src/loader.cpp b/src/loader.cpp index d596da024..ec8f5be7e 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -33,11 +33,11 @@ #endif #include "loader.hpp" -#include "moving_physics.hpp" #include "moving_texture.hpp" #include "material_manager.hpp" #include "file_manager.hpp" #include "material.hpp" +#include "physics/moving_physics.hpp" Loader* loader = 0; diff --git a/src/main.cpp b/src/main.cpp index 582584cc4..e768ae442 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ #include "user_config.hpp" #include "unlock_manager.hpp" -#include "track_manager.hpp" +#include "tracks/track_manager.hpp" #include "track.hpp" #include "race_manager.hpp" #include "file_manager.hpp" diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 4f859b036..c87365794 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -25,7 +25,6 @@ #include "file_manager.hpp" #include "track.hpp" -#include "track_manager.hpp" #include "race_manager.hpp" #include "user_config.hpp" #include "callback_manager.hpp" @@ -45,10 +44,11 @@ #include "karts/auto_kart.hpp" #include "karts/player_kart.hpp" #include "karts/kart_properties_manager.hpp" +#include "modes/world.hpp" #include "network/network_manager.hpp" #include "network/race_state.hpp" #include "robots/default_robot.hpp" -#include "modes/world.hpp" +#include "tracks/track_manager.hpp" #if defined(WIN32) && !defined(__CYGWIN__) # define snprintf _snprintf diff --git a/src/network/connect_message.cpp b/src/network/connect_message.cpp index 6162b50b8..f58e909b4 100755 --- a/src/network/connect_message.cpp +++ b/src/network/connect_message.cpp @@ -27,8 +27,8 @@ #endif #include "user_config.hpp" -#include "track_manager.hpp" #include "karts/kart_properties_manager.hpp" +#include "tracks/track_manager.hpp" // ---------------------------------------------------------------------------- /** Creates the connect message. It includes the id of the client (currently diff --git a/src/bullet/src/BulletDynamics/Vehicle/btKart.cpp b/src/physics/btKart.cpp similarity index 99% rename from src/bullet/src/BulletDynamics/Vehicle/btKart.cpp rename to src/physics/btKart.cpp index 87aff4ba9..02527e8f5 100644 --- a/src/bullet/src/BulletDynamics/Vehicle/btKart.cpp +++ b/src/physics/btKart.cpp @@ -9,18 +9,16 @@ * It is provided "as is" without express or implied warranty. */ -#include "LinearMath/btVector3.h" -#include "btKart.h" +#include "physics/btKart.hpp" +#include "LinearMath/btMinMax.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btQuaternion.h" #include "BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.h" #include "BulletDynamics/ConstraintSolver/btJacobianEntry.h" -#include "LinearMath/btQuaternion.h" #include "BulletDynamics/Dynamics/btDynamicsWorld.h" -#include "btVehicleRaycaster.h" -#include "btWheelInfo.h" -#include "LinearMath/btMinMax.h" - - +#include "BulletDynamics/Vehicle/btVehicleRaycaster.h" +#include "bulletDynamics/Vehicle/btWheelInfo.h" #include "BulletDynamics/ConstraintSolver/btContactConstraint.h" struct btWheelContactPoint; diff --git a/src/bullet/src/BulletDynamics/Vehicle/btKart.h b/src/physics/btKart.hpp similarity index 89% rename from src/bullet/src/BulletDynamics/Vehicle/btKart.h rename to src/physics/btKart.hpp index 546e73055..b3525c6a7 100644 --- a/src/bullet/src/BulletDynamics/Vehicle/btKart.h +++ b/src/physics/btKart.hpp @@ -8,13 +8,10 @@ * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ -#ifndef BT_KART_H -#define BT_KART_H +#ifndef HEADER_BT_KART_HPP +#define HEADER_BT_KART_HPP -#include "BulletDynamics/Dynamics/btRigidBody.h" -#include "btVehicleRaycaster.h" -#include "LinearMath/btAlignedObjectArray.h" -#include "btRaycastVehicle.h" +#include "btBulletDynamicsCommon.h" class btDynamicsWorld; struct btWheelInfo; diff --git a/src/bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.cpp b/src/physics/btUprightConstraint.cpp similarity index 95% rename from src/bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.cpp rename to src/physics/btUprightConstraint.cpp index c51768d45..43d607332 100644 --- a/src/bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.cpp +++ b/src/physics/btUprightConstraint.cpp @@ -15,11 +15,13 @@ subject to the following restrictions: */ -#include "btUprightConstraint.h" +#include "physics/btUprightConstraint.hpp" + +#include +#include + #include "BulletDynamics/Dynamics/btRigidBody.h" #include "LinearMath/btTransformUtil.h" -#include -#include "stdio.h" //! //! diff --git a/src/bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.h b/src/physics/btUprightConstraint.hpp similarity index 90% rename from src/bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.h rename to src/physics/btUprightConstraint.hpp index f324ce39a..17ec2da23 100644 --- a/src/bullet/src/BulletDynamics/ConstraintSolver/btUprightConstraint.h +++ b/src/physics/btUprightConstraint.hpp @@ -14,12 +14,12 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef UPRIGHT_CONSTRAINT_H -#define UPRIGHT_CONSTRAINT_H +#ifndef HEADER_UPRIGHT_CONSTRAINT_HPP +#define HEADER_UPRIGHT_CONSTRAINT_HPP #include "LinearMath/btVector3.h" -#include "btJacobianEntry.h" -#include "btTypedConstraint.h" +#include "BulletDynamics/ConstraintSolver/btJacobianEntry.h" +#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h" class btRigidBody; diff --git a/src/physics/kart_motion_state.hpp b/src/physics/kart_motion_state.hpp index 0a667a81d..ea480f2e7 100644 --- a/src/physics/kart_motion_state.hpp +++ b/src/physics/kart_motion_state.hpp @@ -16,53 +16,53 @@ // 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_KART_MOTION_STATE_HPP -#define HEADER_KART_MOTION_STATE_HPP - -#include "LinearMath/btMotionState.h" - -/** This is a very simple motion state implementation for bullet, which does - * not support any transformation from physics transform to graphics - * transform. - */ - -class KartMotionState : public btMotionState -{ -private: - btTransform m_center_of_mass; - -public: - /** Constructor. - * \param start_trans An optional start transformation. Defaults to - * identity. - */ - KartMotionState(const btTransform& start_trans = btTransform::getIdentity()) - : m_center_of_mass(start_trans) - - { - } // KartMotionState - - // ------------------------------------------------------------------------ - /** Returns the current world transform. - * \param center_of_mass The btTransform object that stores the current - * transformation. - */ - virtual void getWorldTransform(btTransform& center_of_mass) const - { - center_of_mass = m_center_of_mass; - } // getWorldTransform - - // ------------------------------------------------------------------------ - /** Synchronizes world transform from physics to user. - * Bullet calls the update of worldtransform for active objects. - * \param new_trans The new transformation for the object. - */ - virtual void setWorldTransform(const btTransform &new_trans) - { - m_center_of_mass = new_trans; - } // setWorldTransform - -}; // KartMotionState - -#endif // HEADER_KART_MOTION_STATE + +#ifndef HEADER_KART_MOTION_STATE_HPP +#define HEADER_KART_MOTION_STATE_HPP + +#include "LinearMath/btMotionState.h" + +/** This is a very simple motion state implementation for bullet, which does + * not support any transformation from physics transform to graphics + * transform. + */ + +class KartMotionState : public btMotionState +{ +private: + btTransform m_center_of_mass; + +public: + /** Constructor. + * \param start_trans An optional start transformation. Defaults to + * identity. + */ + KartMotionState(const btTransform& start_trans = btTransform::getIdentity()) + : m_center_of_mass(start_trans) + + { + } // KartMotionState + + // ------------------------------------------------------------------------ + /** Returns the current world transform. + * \param center_of_mass The btTransform object that stores the current + * transformation. + */ + virtual void getWorldTransform(btTransform& center_of_mass) const + { + center_of_mass = m_center_of_mass; + } // getWorldTransform + + // ------------------------------------------------------------------------ + /** Synchronizes world transform from physics to user. + * Bullet calls the update of worldtransform for active objects. + * \param new_trans The new transformation for the object. + */ + virtual void setWorldTransform(const btTransform &new_trans) + { + m_center_of_mass = new_trans; + } // setWorldTransform + +}; // KartMotionState + +#endif // HEADER_KART_MOTION_STATE_HPP diff --git a/src/moving_physics.cpp b/src/physics/moving_physics.cpp similarity index 100% rename from src/moving_physics.cpp rename to src/physics/moving_physics.cpp diff --git a/src/moving_physics.hpp b/src/physics/moving_physics.hpp similarity index 100% rename from src/moving_physics.hpp rename to src/physics/moving_physics.hpp diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index c19e7a883..e794d12c8 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -21,6 +21,7 @@ #include "user_config.hpp" #include "network/race_state.hpp" +#include "physics/btUprightConstraint.hpp" #include "utils/ssg_help.hpp" #include "track.hpp" @@ -30,8 +31,8 @@ */ Physics::Physics() : btSequentialImpulseConstraintSolver() { - m_collision_conf = new btDefaultCollisionConfiguration(); - m_dispatcher = new btCollisionDispatcher(m_collision_conf); + m_collision_conf = new btDefaultCollisionConfiguration(); + m_dispatcher = new btCollisionDispatcher(m_collision_conf); } // Physics //----------------------------------------------------------------------------- @@ -41,17 +42,17 @@ Physics::Physics() : btSequentialImpulseConstraintSolver() */ void Physics::init(const Vec3 &world_min, const Vec3 &world_max) { - m_axis_sweep = new btAxisSweep3(world_min, world_max); - m_dynamics_world = new btDiscreteDynamicsWorld(m_dispatcher, - m_axis_sweep, - this, - m_collision_conf); + m_axis_sweep = new btAxisSweep3(world_min, world_max); + m_dynamics_world = new btDiscreteDynamicsWorld(m_dispatcher, + m_axis_sweep, + this, + m_collision_conf); m_dynamics_world->setGravity(btVector3(0.0f, 0.0f, -RaceManager::getTrack()->getGravity())); #ifdef HAVE_GLUT if(user_config->m_bullet_debug) { - m_debug_drawer=new GLDebugDrawer(); + m_debug_drawer = new GLDebugDrawer(); m_debug_drawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe); m_dynamics_world->setDebugDrawer(m_debug_drawer); } @@ -68,7 +69,6 @@ Physics::~Physics() delete m_axis_sweep; delete m_dispatcher; delete m_collision_conf; - } // ~Physics // ----------------------------------------------------------------------------- @@ -77,10 +77,10 @@ Physics::~Physics() * \param kart The kart to add. * \param vehicle The raycast vehicle object. */ -void Physics::addKart(const Kart *kart, btKart *vehicle) +void Physics::addKart(const Kart *kart) { m_dynamics_world->addRigidBody(kart->getBody()); - m_dynamics_world->addVehicle(vehicle); + m_dynamics_world->addVehicle(kart->getVehicle()); m_dynamics_world->addConstraint(kart->getUprightConstraint()); } // addKart @@ -102,9 +102,9 @@ void Physics::removeKart(const Kart *kart) */ void Physics::update(float dt) { - // Bullet can report the same collision more than once (up to 4 + // Bullet can report the same collision more than once (up to 4 // contact points per collision. Additionally, more than one internal - // substep might be taken, resulting in potentially even more + // substep might be taken, resulting in potentially even more // duplicates. To handle this, all collisions (i.e. pair of objects) // are stored in a vector, but only one entry per collision pair // of objects. @@ -154,7 +154,7 @@ void Physics::update(float dt) //----------------------------------------------------------------------------- /** Handles the special case of two karts colliding with each other, which means - * that bombs must be passed on. If both karts have a bomb, they'll explode + * that bombs must be passed on. If both karts have a bomb, they'll explode * immediately. This function is called from physics::update on the server * (and if no networking is used), and from race_state on the client to replay * what happened on the server. @@ -164,7 +164,7 @@ void Physics::update(float dt) void Physics::KartKartCollision(Kart *kartA, Kart *kartB) { kartA->crashed(kartB); // will play crash sound for player karts - kartB->crashed(kartA); + kartB->crashed(kartA); Attachment *attachmentA=kartA->getAttachment(); Attachment *attachmentB=kartB->getAttachment(); @@ -175,7 +175,7 @@ void Physics::KartKartCollision(Kart *kartA, Kart *kartB) { attachmentA->setTimeLeft(0.0f); attachmentB->setTimeLeft(0.0f); - } + } else // only A has a bomb, move it to B (unless it was from B) { if(attachmentA->getPreviousOwner()!=kartB) @@ -321,15 +321,14 @@ void Physics::draw() * \param color Colour to use. */ void Physics::debugDraw(float m[16], btCollisionShape *s, const btVector3 color) - { #ifdef HAVE_GLUT m_shape_drawer.drawOpenGL(m, s, color, 0); // btIDebugDraw::DBG_DrawWireframe); // btIDebugDraw::DBG_DrawAabb); #endif - } // debugDraw + // ----------------------------------------------------------------------------- /* EOF */ diff --git a/src/physics/physics.hpp b/src/physics/physics.hpp index e9af6f87f..ae503d57b 100644 --- a/src/physics/physics.hpp +++ b/src/physics/physics.hpp @@ -17,8 +17,8 @@ // 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_PHYSICS_H -#define HEADER_PHYSICS_H +#ifndef HEADER_PHYSICS_HPP +#define HEADER_PHYSICS_HPP #include #include @@ -37,19 +37,10 @@ class Kart; class Physics : public btSequentialImpulseConstraintSolver { private: - btDynamicsWorld *m_dynamics_world; - Kart *m_kart; -#ifdef HAVE_GLUT - GLDebugDrawer *m_debug_drawer; - GL_ShapeDrawer m_shape_drawer; -#endif - btCollisionDispatcher *m_dispatcher; - btBroadphaseInterface *m_axis_sweep; - btDefaultCollisionConfiguration *m_collision_conf; - // Bullet can report the same collision more than once (up to 4 + // Bullet can report the same collision more than once (up to 4 // contact points per collision. Additionally, more than one internal - // substep might be taken, resulting in potentially even more + // substep might be taken, resulting in potentially even more // duplicates. To handle this, all collisions (i.e. pair of objects) // are stored in a vector, but only one entry per collision pair // of objects. @@ -61,23 +52,21 @@ private: class CollisionPair { public: const UserPointer *a, *b; - + // The entries in Collision Pairs are sorted: if a projectile // is included, it's always 'a'. If only two karts are reported // the first kart pointer is the smaller one CollisionPair(const UserPointer *a1, const UserPointer *b1) { - if(a1->is(UserPointer::UP_KART) && + if(a1->is(UserPointer::UP_KART) && b1->is(UserPointer::UP_KART) && a1>b1) { - a=b1;b=a1; - } else { - a=a1; b=b1; - } + a=b1;b=a1; + } else { + a=a1; b=b1; + } }; // CollisionPair - bool operator==(const CollisionPair p) { - return (p.a==a && p.b==b); - } // operator== - }; // CollisionPair - // ------------------------------------------------------------------------ + bool operator==(const CollisionPair p) {return (p.a==a && p.b==b);} + }; // CollisionPair + // This class is the list of collision objects, where each collision // pair is stored as most once. class CollisionList : public std::vector { @@ -88,20 +77,28 @@ private: if((*i)==p) return; } std::vector::push_back(p); - }; // push_back + }; // push_back public: void push_back(const UserPointer* a, const UserPointer*b) { push_back(CollisionPair(a, b)); } - }; // CollisionList - // ------------------------------------------------------------------------ - CollisionList m_all_collisions; + }; // CollisionList + + btDynamicsWorld *m_dynamics_world; +#ifdef HAVE_GLUT + GLDebugDrawer *m_debug_drawer; + GL_ShapeDrawer m_shape_drawer; +#endif + btCollisionDispatcher *m_dispatcher; + btBroadphaseInterface *m_axis_sweep; + btDefaultCollisionConfiguration *m_collision_conf; + CollisionList m_all_collisions; public: Physics (); ~Physics (); void init (const Vec3 &min_world, const Vec3 &max_world); - void addKart (const Kart *k, btKart *v); + void addKart (const Kart *k); void addBody (btRigidBody* b) {m_dynamics_world->addRigidBody(b);} void removeKart (const Kart *k); void removeBody (btRigidBody* b) {m_dynamics_world->removeRigidBody(b);} @@ -118,6 +115,5 @@ public: btIDebugDraw* debugDrawer, btStackAlloc* stackAlloc, btDispatcher* dispatcher); }; -#endif -/* EOF */ +#endif // HEADER_PHYSICS_HPP diff --git a/src/race_manager.cpp b/src/race_manager.cpp index 78fc92e1d..d64d5aa98 100644 --- a/src/race_manager.cpp +++ b/src/race_manager.cpp @@ -21,7 +21,6 @@ #include -#include "track_manager.hpp" #include "unlock_manager.hpp" #include "modes/world.hpp" #include "scene.hpp" @@ -33,6 +32,7 @@ #include "modes/standard_race.hpp" #include "modes/follow_the_leader.hpp" #include "modes/three_strikes_battle.hpp" +#include "tracks/track_manager.hpp" RaceManager* race_manager= NULL; diff --git a/src/replay_base.cpp b/src/replay/replay_base.cpp similarity index 100% rename from src/replay_base.cpp rename to src/replay/replay_base.cpp diff --git a/src/replay_base.hpp b/src/replay/replay_base.hpp similarity index 100% rename from src/replay_base.hpp rename to src/replay/replay_base.hpp diff --git a/src/replay_buffer_tpl.hpp b/src/replay/replay_buffer_tpl.hpp similarity index 100% rename from src/replay_buffer_tpl.hpp rename to src/replay/replay_buffer_tpl.hpp diff --git a/src/replay_buffers.cpp b/src/replay/replay_buffers.cpp similarity index 100% rename from src/replay_buffers.cpp rename to src/replay/replay_buffers.cpp diff --git a/src/replay_buffers.hpp b/src/replay/replay_buffers.hpp similarity index 100% rename from src/replay_buffers.hpp rename to src/replay/replay_buffers.hpp diff --git a/src/replay_player.cpp b/src/replay/replay_player.cpp similarity index 100% rename from src/replay_player.cpp rename to src/replay/replay_player.cpp diff --git a/src/replay_player.hpp b/src/replay/replay_player.hpp similarity index 100% rename from src/replay_player.hpp rename to src/replay/replay_player.hpp diff --git a/src/replay_recorder.cpp b/src/replay/replay_recorder.cpp similarity index 100% rename from src/replay_recorder.cpp rename to src/replay/replay_recorder.cpp diff --git a/src/replay_recorder.hpp b/src/replay/replay_recorder.hpp similarity index 100% rename from src/replay_recorder.hpp rename to src/replay/replay_recorder.hpp diff --git a/src/terrain_info.cpp b/src/terrain_info.cpp index db61b4996..0f8c9497a 100644 --- a/src/terrain_info.cpp +++ b/src/terrain_info.cpp @@ -24,6 +24,13 @@ #include "constants.hpp" #include "track.hpp" +TerrainInfo::TerrainInfo(int frequency) +{ + m_HoT_frequency=frequency; + m_HoT_counter=frequency; +} + +//----------------------------------------------------------------------------- TerrainInfo::TerrainInfo(const Vec3 &pos, int frequency) { m_HoT_frequency = frequency; @@ -37,8 +44,8 @@ void TerrainInfo::update(const Vec3& pos) m_HoT_counter++; if(m_HoT_counter>=m_HoT_frequency) { - RaceManager::getTrack()->getTerrainInfo(pos, &m_HoT, - &m_normal, &m_material); + RaceManager::getTrack()->getTerrainInfo(pos, &m_HoT, + &m_normal, &m_material); m_normal.normalize(); m_HoT_counter = 0; } @@ -56,13 +63,9 @@ float TerrainInfo::getTerrainPitch(float heading) const { // (x,y,0). (x,y,0) is normalised, so are the coordinates of the plane, // simplifying the computation of the scalar product. float pitch = ( m_normal.getX()*X + m_normal.getY()*Y ); // use ( x,y,0) - + // The actual angle computed above is between the normal and the (x,y,0) // line, so to compute the actual angles 90 degrees must be subtracted. pitch = acosf(pitch) - NINETY_DEGREE_RAD; return pitch; } // getTerrainPitch - -// ----------------------------------------------------------------------------- - -/* EOF */ diff --git a/src/terrain_info.hpp b/src/terrain_info.hpp index b1918f6c3..afe50f58f 100644 --- a/src/terrain_info.hpp +++ b/src/terrain_info.hpp @@ -17,8 +17,8 @@ // 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_TERRAIN_INFO_H -#define HEADER_TERRAIN_INFO_H +#ifndef HEADER_TERRAIN_INFO_HPP +#define HEADER_TERRAIN_INFO_HPP #include "material.hpp" #include "utils/vec3.hpp" @@ -36,16 +36,16 @@ private: float m_HoT; // height of terrain public: - TerrainInfo(int frequency=1) {m_HoT_frequency=frequency; - m_HoT_counter=frequency; } - TerrainInfo(const Vec3 &pos, int frequency=1); - virtual ~TerrainInfo() {}; - virtual void update(const Vec3 &pos); - float getHoT() const { return m_HoT; } - const Material *getMaterial() const { return m_material; } - const Vec3 &getNormal() const { return m_normal; } - float getTerrainPitch(float heading) const; + TerrainInfo(int frequency=1); + TerrainInfo(const Vec3 &pos, int frequency=1); + virtual ~TerrainInfo() {}; -}; // TerrainInfo + virtual void update(const Vec3 &pos); -#endif + float getHoT() const {return m_HoT; } + const Material *getMaterial() const {return m_material;} + const Vec3 &getNormal() const {return m_normal; } + float getTerrainPitch(float heading) const; +}; // TerrainInfo + +#endif // HEADER_TERRAIN_INFO_HPP diff --git a/src/track.cpp b/src/track.cpp index f67a832bf..e60da9db0 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -28,20 +28,20 @@ #include "file_manager.hpp" #include "loader.hpp" #include "string_utils.hpp" -#include "lisp/lisp.hpp" -#include "lisp/parser.hpp" #include "stk_config.hpp" #include "translation.hpp" #include "scene.hpp" -#include "moving_physics.hpp" -#include "modes/world.hpp" #include "material_manager.hpp" #include "isect.hpp" #include "user_config.hpp" +#include "audio/sound_manager.hpp" #include "items/item.hpp" #include "items/item_manager.hpp" +#include "lisp/lisp.hpp" +#include "lisp/parser.hpp" +#include "modes/world.hpp" +#include "physics/moving_physics.hpp" #include "race_manager.hpp" -#include "audio/sound_manager.hpp" #include "utils/ssg_help.hpp" #if defined(WIN32) && !defined(__CYGWIN__) diff --git a/src/track_manager.cpp b/src/tracks/track_manager.cpp similarity index 100% rename from src/track_manager.cpp rename to src/tracks/track_manager.cpp index 5738e706c..18a59686a 100644 --- a/src/track_manager.cpp +++ b/src/tracks/track_manager.cpp @@ -25,8 +25,8 @@ #include "track_manager.hpp" #include "track.hpp" #include "stk_config.hpp" -#include "audio/sound_manager.hpp" #include "translation.hpp" +#include "audio/sound_manager.hpp" TrackManager* track_manager = 0; diff --git a/src/track_manager.hpp b/src/tracks/track_manager.hpp similarity index 96% rename from src/track_manager.hpp rename to src/tracks/track_manager.hpp index c656ad6a4..33cbea86c 100644 --- a/src/track_manager.hpp +++ b/src/tracks/track_manager.hpp @@ -17,8 +17,8 @@ // 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_TRACKMANAGER_H -#define HEADER_TRACKMANAGER_H +#ifndef HEADER_TRACK_MANAGER_HPP +#define HEADER_TRACK_MANAGER_HPP #include #include @@ -66,4 +66,4 @@ public: extern TrackManager* track_manager; -#endif +#endif // HEADER_TRACK_MANAGER_HPP diff --git a/src/user_config.cpp b/src/user_config.cpp index 6434c69a2..5aaa2a127 100644 --- a/src/user_config.cpp +++ b/src/user_config.cpp @@ -159,34 +159,27 @@ void UserConfig::setDefaults() Input(Input::IT_KEYBOARD, SDLK_UP), Input(Input::IT_MOUSEBUTTON, 4), Input(Input::IT_STICKMOTION, 0, 1, Input::AD_NEGATIVE)); - set(GA_CURSOR_DOWN, Input(Input::IT_KEYBOARD, SDLK_DOWN), Input(Input::IT_MOUSEBUTTON, 5), Input(Input::IT_STICKMOTION, 0, 1, Input::AD_POSITIVE)); - set(GA_CURSOR_LEFT, Input(Input::IT_KEYBOARD, SDLK_LEFT), Input(Input::IT_STICKMOTION, 0, 0, Input::AD_NEGATIVE)); - set(GA_CURSOR_RIGHT, Input(Input::IT_KEYBOARD, SDLK_RIGHT), Input(Input::IT_STICKMOTION, 0, 0, Input::AD_POSITIVE)); - set(GA_CLEAR_MAPPING, Input(Input::IT_KEYBOARD, SDLK_BACKSPACE), Input(Input::IT_STICKBUTTON, 0, 2)); - set(GA_INC_SCROLL_SPEED, Input(Input::IT_KEYBOARD, SDLK_PLUS)); set(GA_INC_SCROLL_SPEED_FAST, Input(Input::IT_KEYBOARD, SDLK_PAGEDOWN)); - set(GA_DEC_SCROLL_SPEED, Input(Input::IT_KEYBOARD, SDLK_MINUS)); set(GA_DEC_SCROLL_SPEED_FAST, Input(Input::IT_KEYBOARD, SDLK_PAGEUP)); - set(GA_TOGGLE_FULLSCREEN, Input(Input::IT_KEYBOARD, SDLK_F9)); set(GA_LEAVE_RACE, @@ -212,44 +205,26 @@ void UserConfig::setDefaults() // b) prevent loading those defaults if config file contains any bindings /* Player 1 default input settings */ - set(GA_P1_LEFT, - Input(Input::IT_KEYBOARD, SDLK_LEFT)); - set(GA_P1_RIGHT, - Input(Input::IT_KEYBOARD, SDLK_RIGHT)); - set(GA_P1_ACCEL, - Input(Input::IT_KEYBOARD, SDLK_UP)); - set(GA_P1_BRAKE, - Input(Input::IT_KEYBOARD, SDLK_DOWN)); - set(GA_P1_NITRO, - Input(Input::IT_KEYBOARD, SDLK_l)); - set(GA_P1_DRIFT, - Input(Input::IT_KEYBOARD, SDLK_k)); - set(GA_P1_RESCUE, - Input(Input::IT_KEYBOARD, SDLK_h)); - set(GA_P1_FIRE, - Input(Input::IT_KEYBOARD, SDLK_SPACE)); - set(GA_P1_LOOK_BACK, - Input(Input::IT_KEYBOARD, SDLK_j)); + set(GA_P1_LEFT, Input(Input::IT_KEYBOARD, SDLK_LEFT)); + set(GA_P1_RIGHT, Input(Input::IT_KEYBOARD, SDLK_RIGHT)); + set(GA_P1_ACCEL, Input(Input::IT_KEYBOARD, SDLK_UP)); + set(GA_P1_BRAKE, Input(Input::IT_KEYBOARD, SDLK_DOWN)); + set(GA_P1_NITRO, Input(Input::IT_KEYBOARD, SDLK_l)); + set(GA_P1_DRIFT, Input(Input::IT_KEYBOARD, SDLK_k)); + set(GA_P1_RESCUE, Input(Input::IT_KEYBOARD, SDLK_h)); + set(GA_P1_FIRE, Input(Input::IT_KEYBOARD, SDLK_SPACE)); + set(GA_P1_LOOK_BACK, Input(Input::IT_KEYBOARD, SDLK_j)); /* Player 2 default input settings */ - set(GA_P2_LEFT, - Input(Input::IT_KEYBOARD, SDLK_a)); - set(GA_P2_RIGHT, - Input(Input::IT_KEYBOARD, SDLK_d)); - set(GA_P2_ACCEL, - Input(Input::IT_KEYBOARD, SDLK_w)); - set(GA_P2_BRAKE, - Input(Input::IT_KEYBOARD, SDLK_s)); - set(GA_P2_NITRO, - Input(Input::IT_KEYBOARD, SDLK_LSHIFT)); - set(GA_P2_DRIFT, - Input(Input::IT_KEYBOARD, SDLK_CAPSLOCK)); - set(GA_P2_RESCUE, - Input(Input::IT_KEYBOARD, SDLK_q)); - set(GA_P2_FIRE, - Input(Input::IT_KEYBOARD, SDLK_LCTRL)); - set(GA_P2_LOOK_BACK, - Input(Input::IT_KEYBOARD, SDLK_LALT)); + set(GA_P2_LEFT, Input(Input::IT_KEYBOARD, SDLK_a)); + set(GA_P2_RIGHT, Input(Input::IT_KEYBOARD, SDLK_d)); + set(GA_P2_ACCEL, Input(Input::IT_KEYBOARD, SDLK_w)); + set(GA_P2_BRAKE, Input(Input::IT_KEYBOARD, SDLK_s)); + set(GA_P2_NITRO, Input(Input::IT_KEYBOARD, SDLK_LSHIFT)); + set(GA_P2_DRIFT, Input(Input::IT_KEYBOARD, SDLK_CAPSLOCK)); + set(GA_P2_RESCUE, Input(Input::IT_KEYBOARD, SDLK_q)); + set(GA_P2_FIRE, Input(Input::IT_KEYBOARD, SDLK_LCTRL)); + set(GA_P2_LOOK_BACK, Input(Input::IT_KEYBOARD, SDLK_LALT)); // If the same key is used for more than one player, the setting // is overwritten when reading back the file. To allow us to have @@ -259,44 +234,26 @@ void UserConfig::setDefaults() #undef DEFAULTS_FOR_PLAYER34 #ifdef DEFAULTS_FOR_PLAYER34 /* Player 3 default input settings */ - set(GA_P3_LEFT, - Input(Input::IT_KEYBOARD, SDLK_f)); - set(GA_P3_RIGHT, - Input(Input::IT_KEYBOARD, SDLK_h)); - set(GA_P3_ACCEL, - Input(Input::IT_KEYBOARD, SDLK_t)); - set(GA_P3_BRAKE, - Input(Input::IT_KEYBOARD, SDLK_g)); - set(GA_P3_NITRO, - Input(Input::IT_KEYBOARD, SDLK_c)); - set(GA_P3_DRIFT, - Input(Input::IT_KEYBOARD, SDLK_v)); - set(GA_P3_RESCUE, - Input(Input::IT_KEYBOARD, SDLK_r)); - set(GA_P3_FIRE, - Input(Input::IT_KEYBOARD, SDLK_b)); - set(GA_P3_LOOK_BACK, - Input(Input::IT_KEYBOARD, SDLK_n)); + set(GA_P3_LEFT, Input(Input::IT_KEYBOARD, SDLK_f)); + set(GA_P3_RIGHT, Input(Input::IT_KEYBOARD, SDLK_h)); + set(GA_P3_ACCEL, Input(Input::IT_KEYBOARD, SDLK_t)); + set(GA_P3_BRAKE, Input(Input::IT_KEYBOARD, SDLK_g)); + set(GA_P3_NITRO, Input(Input::IT_KEYBOARD, SDLK_c)); + set(GA_P3_DRIFT, Input(Input::IT_KEYBOARD, SDLK_v)); + set(GA_P3_RESCUE, Input(Input::IT_KEYBOARD, SDLK_r)); + set(GA_P3_FIRE, Input(Input::IT_KEYBOARD, SDLK_b)); + set(GA_P3_LOOK_BACK, Input(Input::IT_KEYBOARD, SDLK_n)); /* Player 4 default input settings */ - set(GA_P4_LEFT, - Input(Input::IT_KEYBOARD, SDLK_j)); - set(GA_P4_RIGHT, - Input(Input::IT_KEYBOARD, SDLK_l)); - set(GA_P4_ACCEL, - Input(Input::IT_KEYBOARD, SDLK_i)); - set(GA_P4_BRAKE, - Input(Input::IT_KEYBOARD, SDLK_k)); - set(GA_P4_NITRO, - Input(Input::IT_KEYBOARD, SDLK_m)); - set(GA_P4_DRIFT, - Input(Input::IT_KEYBOARD, SDLK_COMMA)); - set(GA_P4_RESCUE, - Input(Input::IT_KEYBOARD, SDLK_u)); - set(GA_P4_FIRE, - Input(Input::IT_KEYBOARD, SDLK_PERIOD)); - set(GA_P4_LOOK_BACK, - Input(Input::IT_KEYBOARD, SDLK_SLASH)); + set(GA_P4_LEFT, Input(Input::IT_KEYBOARD, SDLK_j)); + set(GA_P4_RIGHT, Input(Input::IT_KEYBOARD, SDLK_l)); + set(GA_P4_ACCEL, Input(Input::IT_KEYBOARD, SDLK_i)); + set(GA_P4_BRAKE, Input(Input::IT_KEYBOARD, SDLK_k)); + set(GA_P4_NITRO, Input(Input::IT_KEYBOARD, SDLK_m)); + set(GA_P4_DRIFT, Input(Input::IT_KEYBOARD, SDLK_COMMA)); + set(GA_P4_RESCUE, Input(Input::IT_KEYBOARD, SDLK_u)); + set(GA_P4_FIRE, Input(Input::IT_KEYBOARD, SDLK_PERIOD)); + set(GA_P4_LOOK_BACK, Input(Input::IT_KEYBOARD, SDLK_SLASH)); #endif } // setDefaults @@ -354,7 +311,6 @@ int UserConfig::CheckAndCreateDir() printf("Config directory '%s' successfully created.\n",DIRNAME.c_str()); return 2; } - } // CheckAndCreateDir // ----------------------------------------------------------------------------- @@ -377,7 +333,7 @@ void UserConfig::loadConfig(const std::string& filename) catch(std::exception& e) { (void)e; // avoid warning about unreferenced local variable - printf("Config file '%s' does not exist, it will be created.\n", + printf("Config file '%s' does not exist, it will be created.\n", filename.c_str()); // This will initialise the last input configuration with the // default values from the current (=default) player input @@ -461,13 +417,13 @@ void UserConfig::loadConfig(const std::string& filename) /*get resolution width/height*/ lisp->get("width", m_width); lisp->get("height", m_height); - lisp->get("prev_width", m_prev_width); - lisp->get("prev_height", m_prev_height); - lisp->get("prev_windowed", m_prev_windowed); + lisp->get("prev_width", m_prev_width); + lisp->get("prev_height", m_prev_height); + lisp->get("prev_windowed", m_prev_windowed); //detect if resolution change previously crashed STK - lisp->get("crash_detected", m_crashed); + lisp->get("crash_detected", m_crashed); // blacklisted resolutions - lisp->getVector("blacklisted_resolutions", + lisp->getVector("blacklisted_resolutions", m_blacklist_res); /*Get default number of karts, number of laps, and difficulty. */ lisp->get("karts", m_num_karts); @@ -507,9 +463,9 @@ void UserConfig::loadConfig(const std::string& filename) } std::string name; reader->get("name", name); - if (configFileVersion <= 3) + if (configFileVersion <= 3) { - // For older config files, replace the default player + // For older config files, replace the default player // names "Player %d" with the user name char sDefaultName[10]; snprintf(sDefaultName, sizeof(sDefaultName), @@ -524,14 +480,14 @@ void UserConfig::loadConfig(const std::string& filename) reader->get("lastKartId", lastKartId); m_player[i].setLastKartId(lastKartId); - // Don't read the key bindings from a config file earlier than - // version 5. These config files contain (unused) keybindings for - // jumping, so it is possible that the same key is used for + // Don't read the key bindings from a config file earlier than + // version 5. These config files contain (unused) keybindings for + // jumping, so it is possible that the same key is used for // jumping for player 1 and something else for another player. // In this case jumping for player one would be disabled (see - // unsetDuplicates). To be on the safe side, old key bindings + // unsetDuplicates). To be on the safe side, old key bindings // are just discarded. - if (configFileVersion <= 4) + if (configFileVersion <= 4) { m_warning=_("Old config file found, check your key bindings!"); } // configFileVersion <= 4 @@ -545,8 +501,8 @@ void UserConfig::loadConfig(const std::string& filename) // Leave those in for backwards compatibility (i.e. config files // with jump/wheelie). If jump/wheelie are not defined, nothing // happens (the same input is read again). - readPlayerInput(reader, nitro_name, KA_NITRO, i); - readPlayerInput(reader, drift_name, KA_DRIFT, i); + readPlayerInput(reader, nitro_name, KA_NITRO, i); + readPlayerInput(reader, drift_name, KA_DRIFT, i); } // for i < PLAYERS // Read the last input device configurations. It is important that this @@ -554,7 +510,6 @@ void UserConfig::loadConfig(const std::string& filename) // is given, the last config is initialised with the current player // config. readLastInputConfigurations(lisp); - } catch(std::exception& e) { @@ -563,12 +518,10 @@ void UserConfig::loadConfig(const std::string& filename) fprintf(stderr, "\n"); } - delete root; } // loadConfig // ----------------------------------------------------------------------------- - void UserConfig::readStickConfigs(const lisp::Lisp *r) { std::string temp; @@ -597,9 +550,7 @@ void UserConfig::readStickConfigs(const lisp::Lisp *r) m_stickconfigs.push_back(sc); } } - } - } // readStickConfigs // ----------------------------------------------------------------------------- @@ -611,7 +562,7 @@ void UserConfig::readStickConfigs(const lisp::Lisp *r) */ void UserConfig::readLastInputConfigurations(const lisp::Lisp *reader) { - const lisp::Lisp* nodeReader = reader + const lisp::Lisp* nodeReader = reader ? reader->getLisp("last-input-configurations") : NULL; // No last input configuration specified. Use the current player mappings @@ -649,7 +600,6 @@ void UserConfig::readLastInputConfigurations(const lisp::Lisp *reader) m_last_input_configuration[device_name].m_input[ka] = input; } // for ka=KA_FIRST, KA_LAST } // for ibeginList(node); @@ -981,7 +922,7 @@ std::string UserConfig::getInputAsString(const Input &input) { char msg[MAX_MESSAGE_LENGTH]; std::ostringstream stm; - + switch (input.type) { case Input::IT_NONE: @@ -1011,9 +952,9 @@ std::string UserConfig::getInputAsString(const Input &input) default: snprintf(msg, sizeof(msg), _("Invalid")); } - + stm << msg; - + return stm.str(); } // GetKeyAsString @@ -1120,13 +1061,13 @@ std::string UserConfig::getInputDeviceName(int player_index) const { case Input::IT_KEYBOARD : { // config name: keyboard+player_index std::ostringstream s; - s<<"keyboard-"<m_id; + case Input::IT_STICKMOTION : config_name=m_stickconfigs[left_input.id0]->m_id; break; case Input::IT_MOUSEBUTTON : case Input::IT_MOUSEMOTION : config_name="mouse"; break; @@ -1134,6 +1075,7 @@ std::string UserConfig::getInputDeviceName(int player_index) const } // switch left_input.type return config_name; } // getInputDeviceName + // ----------------------------------------------------------------------------- void UserConfig::setInput(int player_index, KartAction ka, const Input &input) { @@ -1141,7 +1083,7 @@ void UserConfig::setInput(int player_index, KartAction ka, const Input &input) + player_index * KC_COUNT + ka), input); - // Now save the (complete) current configuration as the last used + // Now save the (complete) current configuration as the last used // configuration for the input device that is defined for the left // action. First determine the name of the device, and then // copy the configuration. @@ -1159,8 +1101,8 @@ void UserConfig::setInput(int player_index, KartAction ka, const Input &input) // to change the left axis for a gamepad anymore. if(i==KA_LEFT) continue; Input last_inp = m_last_input_configuration[device_name].m_input[(KartAction)i]; - if(last_inp.type==Input::IT_STICKBUTTON || - last_inp.type==Input::IT_STICKHAT || + if(last_inp.type==Input::IT_STICKBUTTON || + last_inp.type==Input::IT_STICKHAT || last_inp.type==Input::IT_STICKMOTION ) { // in case of joystick, adjust the joystick index - in case // that there are two joystickts with the same name @@ -1177,7 +1119,7 @@ void UserConfig::setInput(int player_index, KartAction ka, const Input &input) // We change an entry (but not left) --> save as new 'last configuration' for(int i=KA_FIRST; i<=KA_LAST; i++) { - m_last_input_configuration[device_name].m_input[(KartAction)i] = + m_last_input_configuration[device_name].m_input[(KartAction)i] = getInput(player_index, (KartAction)i); } // for i=KA_FIRST, KA_LAST } // ka!=KA_LEFT @@ -1234,7 +1176,7 @@ ActionMap *UserConfig::newIngameActionMap() // (in MenuManager) and RaceGUI needs race_manager, too. // TODO: Reorder ingame GameAction values so that they start with - // the fixed ones. This would allow simpler looking code here. + // the fixed ones. This would allow simpler looking code here. GameAction gaEnd = GA_NULL; @@ -1282,24 +1224,3 @@ bool UserConfig::isFixedInput(Input::InputType type, int id0, int id1, int id2) return false; } // isFixedInput - -// ----------------------------------------------------------------------------- -void UserConfig::addStickConfig(StickConfig *sc) -{ - m_stickconfigs.push_back(sc); -} // addStickConfig - -// ----------------------------------------------------------------------------- -const std::vector *UserConfig::getStickConfigs() const -{ - return &m_stickconfigs; -} // getStickConfigs -// ----------------------------------------------------------------------------- - -UserConfig::StickConfig::StickConfig(const std::string &newId) - : m_id(newId) -{ - // Nothing else to do. -} - -/*EOF*/ diff --git a/src/user_config.hpp b/src/user_config.hpp index 6669c8557..2dfb4e86c 100644 --- a/src/user_config.hpp +++ b/src/user_config.hpp @@ -18,8 +18,8 @@ // 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_USERCONFIG_HPP -#define HEADER_USERCONFIG_HPP +#ifndef HEADER_USER_CONFIG_HPP +#define HEADER_USER_CONFIG_HPP #define PLAYERS 4 @@ -59,18 +59,17 @@ class UserConfig { public: /** Stores information about joystick and gamepads. */ - class StickConfig - { - public: - std::string m_id; - int m_preferredIndex; - int m_deadzone; - StickConfig(const std::string &id); - - }; + class StickConfig + { + public: + std::string m_id; + int m_preferredIndex; + int m_deadzone; + StickConfig(const std::string &id) : m_id(id) {} + }; private: - // This class stores the last used input configuration (i.e. which action + // This class stores the last used input configuration (i.e. which action // is used for left, right, ..., look back) for a certain input // device (i.e. keyboard, joystick, ...) struct InputConfiguration @@ -84,25 +83,25 @@ private: std::string getInputDeviceName(int player_index) const; - std::vector m_stickconfigs; - - typedef struct - { - int count; - Input inputs[4]; - } InputMapEntry; - + std::vector m_stickconfigs; + + typedef struct + { + int count; + Input inputs[4]; + } InputMapEntry; + /** Filename of the user config file. */ std::string m_filename; - - /** Stores the GameAction->Input mappings in a way that is suitable for - * quick modification of the mappings. Internally this allows multiple - * Input instances per GameAction but the public methods allow only one - * mapping. - * - * It is named after what is put in as values. - */ - InputMapEntry m_input_map[GA_COUNT]; + + /** Stores the GameAction->Input mappings in a way that is suitable for + * quick modification of the mappings. Internally this allows multiple + * Input instances per GameAction but the public methods allow only one + * mapping. + * + * It is named after what is put in as values. + */ + InputMapEntry m_input_map[GA_COUNT]; void setFilename (); int CheckAndCreateDir(); @@ -121,67 +120,67 @@ private: /** Index of current background image. */ int m_background_index; - void readStickConfigs(const lisp::Lisp *); + void readStickConfigs(const lisp::Lisp *); void readLastInputConfigurations(const lisp::Lisp *); - void writeStickConfigs(lisp::Writer *); + void writeStickConfigs(lisp::Writer *); void writeLastInputConfigurations(lisp::Writer *); - void readPlayerInput(const lisp::Lisp *, + void readPlayerInput(const lisp::Lisp *, const std::string& node, - KartAction ka, - int); + KartAction ka, + int); - void writePlayerInput(lisp::Writer *, + void writePlayerInput(lisp::Writer *, const std::string &node, - KartAction, - int); + KartAction, + int); void readInputNode(const lisp::Lisp *, const std::string &node, - GameAction); + GameAction); Input readInput(const lisp::Lisp* nodeReader); void writeInputNode(lisp::Writer *, const std::string &node, - GameAction); + GameAction); - void writeInput(lisp::Writer *writer, const Input &input); + void writeInput(lisp::Writer *writer, const Input &input); - /** Iterates through the input mapping and unsets all - * where the given input occurs. - * - * This makes sure an input is not bound multiple times. - */ - void unsetDuplicates(GameAction, const Input &); - - /** Creates an GameAction->Input mapping with one Input */ - void set(GameAction, const Input &); - - /** Creates an GameAction->Input mapping with two Inputs */ - void set(GameAction, const Input &, const Input &); - - /** Creates an GameAction->Input mapping with three Inputs */ - void set(GameAction, const Input &, const Input &, const Input &); - - /** Creates an GameAction->Input mapping with four Inputs */ - void set(GameAction, const Input &, const Input &, const Input &, const Input &); + /** Iterates through the input mapping and unsets all + * where the given input occurs. + * + * This makes sure an input is not bound multiple times. + */ + void unsetDuplicates(GameAction, const Input &); - std::string getInputAsString(const Input &); + /** Creates an GameAction->Input mapping with one Input */ + void set(GameAction, const Input &); - /** Creates an ActionMap for the GameAction values of the specified - * range. - */ - ActionMap *newActionMap(const int, const int); - - /** Sets the Input for the given GameAction. Includes a check for - * duplicates and automatic removing of the other candidate(s). - * - * For use when reading from file. - */ - void setInput(GameAction, const Input &); + /** Creates an GameAction->Input mapping with two Inputs */ + void set(GameAction, const Input &, const Input &); + + /** Creates an GameAction->Input mapping with three Inputs */ + void set(GameAction, const Input &, const Input &, const Input &); + + /** Creates an GameAction->Input mapping with four Inputs */ + void set(GameAction, const Input &, const Input &, const Input &, const Input &); + + std::string getInputAsString(const Input &); + + /** Creates an ActionMap for the GameAction values of the specified + * range. + */ + ActionMap *newActionMap(const int, const int); + + /** Sets the Input for the given GameAction. Includes a check for + * duplicates and automatic removing of the other candidate(s). + * + * For use when reading from file. + */ + void setInput(GameAction, const Input &); public: enum UC_Mode {UC_ENABLE, UC_DISABLE, UC_TEMPORARY_DISABLE}; @@ -202,28 +201,29 @@ public: std::string m_item_style; std::string m_username; std::string m_background_music; - std::string m_kart_group; //< Kart group used last - std::string m_track_group; //< Track group used last - std::string m_last_track; //< name of the last track used + std::string m_kart_group; /**< Kart group used last. */ + std::string m_track_group; /**< Track group used last. */ + std::string m_last_track; /**< name of the last track used. */ std::string m_server_address; int m_server_port; bool m_use_kph; int m_width; int m_height; - int m_prev_width; - int m_prev_height; - bool m_prev_windowed; - bool m_crashed; - std::vector m_blacklist_res; + int m_prev_width; + int m_prev_height; + bool m_prev_windowed; + bool m_crashed; + std::vector + m_blacklist_res; Player m_player[PLAYERS]; bool m_log_errors; - UserConfig(); - UserConfig(const std::string& filename); - ~UserConfig(); + UserConfig(); + UserConfig(const std::string& filename); + ~UserConfig(); void setDefaults(); void setMusic(int m) { m_music = m; } - void setSFX (int m) { m_sfx = m; } + void setSFX(int m) { m_sfx = m; } bool doMusic() const { return m_music == UC_ENABLE;} bool doSFX() const { return m_sfx == UC_ENABLE;} /** Sets the default number of karts. This is only used to store @@ -243,52 +243,50 @@ public: void setDefaultNumDifficulty(int n) { m_difficulty = n; } /** Returns the default difficulty. */ int getDefaultDifficulty() const { return m_difficulty; } - void nextBackgroundIndex(); /** Get the index of the background image. */ - int getBackgroundIndex() const { return m_background_index; } + int getBackgroundIndex() const { return m_background_index; } - void loadConfig(); - void loadConfig(const std::string& filename); - void saveConfig(); - void saveConfig(const std::string& filename); - - void addStickConfig(UserConfig::StickConfig *); - - const std::vector *getStickConfigs() const; + void loadConfig(); + void loadConfig(const std::string& filename); + void saveConfig() { saveConfig(m_filename); } + void saveConfig(const std::string& filename); + void addStickConfig(UserConfig::StickConfig *sc) + {m_stickconfigs.push_back(sc);} + const std::vector + *getStickConfigs() const { return &m_stickconfigs; } - - /** Retrieves a human readable string of the mapping for a GameAction */ + + /** Retrieves a human readable string of the mapping for a GameAction */ std::string getMappingAsString(GameAction); - /** Retrieves a human readable string of the mapping for the given - * player and KartAction. - */ - std::string getMappingAsString(int, KartAction); - - /** Sets the Input for the given Player and KartAction. Includes a check - * for duplicates and automatic removing of the other candidate(s). - * - * For use when sensing input. - */ - void setInput(int player_number, KartAction ka, const Input &i0); - + /** Retrieves a human readable string of the mapping for the given + * player and KartAction. + */ + std::string getMappingAsString(int, KartAction); + + /** Sets the Input for the given Player and KartAction. Includes a check + * for duplicates and automatic removing of the other candidate(s). + * + * For use when sensing input. + */ + void setInput(int player_number, KartAction ka, const Input &i0); const Input &getInput(int player_index, KartAction ka) const; - /** Clears the mapping for a given Player and KartAction. */ - void clearInput(int, KartAction); - - bool isFixedInput(Input::InputType, int, int, int); - const std::string& getWarning() {return m_warning;} - void resetWarning() {m_warning="";} - void setWarning(std::string& warning) {m_warning=warning;} + /** Clears the mapping for a given Player and KartAction. */ + void clearInput(int, KartAction); + bool isFixedInput(Input::InputType, int, int, int); + const std::string + &getWarning() { return m_warning; } + void resetWarning() { m_warning=""; } + void setWarning(std::string& warning) { m_warning=warning; } + + /** Creates ActionMap for use in menu mode. */ + ActionMap *newMenuActionMap(); + + /** Creates ActionMap for use in ingame mode. */ + ActionMap *newIngameActionMap(); - /** Creates ActionMap for use in menu mode. */ - ActionMap *newMenuActionMap(); - - /** Creates ActionMap for use in ingame mode. */ - ActionMap *newIngameActionMap(); - }; diff --git a/src/utils/random_generator.cpp b/src/utils/random_generator.cpp index 85e2d69cf..5d563a5ba 100644 --- a/src/utils/random_generator.cpp +++ b/src/utils/random_generator.cpp @@ -20,7 +20,6 @@ #include "random_generator.hpp" #include -#include #include std::vector RandomGenerator::m_all_random_generators; @@ -28,7 +27,7 @@ std::vector RandomGenerator::m_all_random_generators; RandomGenerator::RandomGenerator() { m_a = 1103515245; - m_c = 12345; + m_c = 12345; m_all_random_generators.push_back(this); m_random_value = 3141591; std::srand((unsigned int)std::time(0)); @@ -42,32 +41,19 @@ std::vector RandomGenerator::generateAllSeeds() { int seed = rand(); all_seeds.push_back(seed); + m_all_random_generators[i]->seed(seed); } - seedAll(all_seeds); return all_seeds; - } // generateAllSeeds -// ---------------------------------------------------------------------------- -void RandomGenerator::seedAll(std::vector all_seeds) -{ - for(unsigned int i=0; iseed(all_seeds[i]); - } -} // seed -// ---------------------------------------------------------------------------- -void RandomGenerator::seed(int s) -{ - m_random_value = s; -} // seed +#if 0 // ---------------------------------------------------------------------------- int RandomGenerator::get(int n) { // This generator is (currently) not good enough, i.e. it often gives // long sequences of same numbers. And the seeding is not done (the - // mid term goal is to synchronise all random number generators on + // mid term goal is to synchronise all random number generators on // client and server to make less communication necessary). // For now: just use standard random numbers: return rand() % n; @@ -81,5 +67,4 @@ int RandomGenerator::get(int n) #endif } // get -// ---------------------------------------------------------------------------- - +#endif // if 0 diff --git a/src/utils/random_generator.hpp b/src/utils/random_generator.hpp index 440eeb01f..aacd4cc47 100644 --- a/src/utils/random_generator.hpp +++ b/src/utils/random_generator.hpp @@ -17,12 +17,13 @@ // 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_RANDOM_NUMBER_H -#define HEADER_RANDOM_NUMBER_H +#ifndef HEADER_RANDOM_GENERATOR_HPP +#define HEADER_RANDOM_GENERATOR_HPP +#include #include -/** A random number generator. Each objects that needs a random number uses +/** A random number generator. Each objects that needs a random number uses its own number random generator. They are all seeded with number provided by the server. This guarantees that in a network game all 'random' values are actually identical among all machines. @@ -32,18 +33,17 @@ class RandomGenerator { private: - unsigned int m_random_value; - unsigned int m_a, m_c; + unsigned int m_random_value; + unsigned int m_a, m_c; static std::vector m_all_random_generators; + public: - RandomGenerator(); - static void seedAll(std::vector all_seeds); + RandomGenerator(); + std::vector generateAllSeeds(); - void seed(int s); /** Returns a pseudo random number between 0 and n-1 inclusive */ - int get (int n); - - -}; // RandomGenerator -#endif + int get(int n) {return rand() % n; } + void seed(int s) {m_random_value = s;} +}; // RandomGenerator +#endif // HEADER_RANDOM_GENERATOR_HPP diff --git a/src/utils/vec3.hpp b/src/utils/vec3.hpp index dd6ca7970..ee54e3e35 100755 --- a/src/utils/vec3.hpp +++ b/src/utils/vec3.hpp @@ -29,22 +29,21 @@ class Vec3 : public btVector3 { private: inline float clampToUnity(float f) {return f<-1?f:(f>1?1:f);} - void setPitchRoll(const Vec3 &normal); + void setPitchRoll(const Vec3 &normal); + public: - inline Vec3(sgVec3 a) : btVector3(a[0], a[1], a[2]) {} - inline Vec3(const btVector3& a) : btVector3(a) {} - inline Vec3() : btVector3() {} - inline Vec3(float x, float y, float z) - : btVector3(x,y,z) {} - inline Vec3(float x) : btVector3(x,x,x) {} - /** Sets the heading, and computes pitch and roll dependent - * on the normal it is displayed on. - * \param heading The heading to set. - * \param normal The normal from which pitch and roll - should be computed. */ - inline Vec3(float heading, const Vec3& normal) - {m_x=heading; - setPitchRoll(normal);} + inline Vec3(sgVec3 a) : btVector3(a[0], a[1], a[2]) {} + inline Vec3(const btVector3& a) : btVector3(a) {} + inline Vec3() : btVector3() {} + inline Vec3(float x, float y, float z) : btVector3(x,y,z) {} + inline Vec3(float x) : btVector3(x,x,x) {} + /** Sets the heading, and computes pitch and roll dependent + * on the normal it is displayed on. + * \param heading The heading to set. + * \param normal The normal from which pitch and roll should be computed. */ + inline Vec3(float heading, const Vec3& normal) + {m_x=heading; + setPitchRoll(normal);} void setHPR(const btMatrix3x3& m); inline const float operator[](int n) const {return *(&m_x+n); }