1) Added --kartdir directive, allowing loading of
additional karts from other directories. 2) Fixed potential bug (--track might have allowed you to run a locked track) 3) --list-tracks and --list-karts can now keep on running (before STK would be ended) - but they are slower now 4) Renamed all kartname.irrkart file to kart.xml. I realised too late that those files had not been converted to xml yet. It will be fixed later. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3930 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "challenges/challenge_data.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@@ -76,29 +77,28 @@ UnlockManager::UnlockManager()
|
||||
|
||||
// Load challenges from .../data/karts
|
||||
// -----------------------------------
|
||||
std::set<std::string> dirs;
|
||||
file_manager->listFiles(dirs, file_manager->getKartDir(),
|
||||
/*is_full_path*/ true);
|
||||
const std::vector<std::string> *all_kart_dirs =
|
||||
kart_properties_manager->getAllKartDirs();
|
||||
|
||||
// Find out which characters are available and load them
|
||||
for(std::set<std::string>::iterator i = dirs.begin();
|
||||
i != dirs.end(); i++)
|
||||
for(std::vector<std::string>::const_iterator dir = all_kart_dirs->begin();
|
||||
dir != all_kart_dirs->end(); dir++)
|
||||
{
|
||||
std::string challenge_file;
|
||||
try
|
||||
std::set<std::string> all_files;
|
||||
file_manager->listFiles(all_files, *dir, /*is_full_path*/ true);
|
||||
for(std::set<std::string>::iterator file=all_files.begin();
|
||||
file!=all_files.end(); file++)
|
||||
{
|
||||
challenge_file = file_manager->getKartFile((*i)+".challenge");
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
(void)e; // remove warning about unused variable
|
||||
continue;
|
||||
}
|
||||
FILE *f=fopen(challenge_file.c_str(),"r");
|
||||
if(!f) continue;
|
||||
fclose(f);
|
||||
addChallenge(new ChallengeData(challenge_file));
|
||||
} // for i
|
||||
if(!StringUtils::hasSuffix(*file,".challenge")) continue;
|
||||
std::string filename=*dir+"/"+*file;
|
||||
FILE *f=fopen(filename.c_str(), "r");
|
||||
if(f)
|
||||
{
|
||||
fclose(f);
|
||||
addChallenge(new ChallengeData(filename));
|
||||
} // if file
|
||||
} // for file in files
|
||||
} // for dir in all_karts_dirs
|
||||
|
||||
// Challenges from .../data/grandprix
|
||||
// ----------------------------------
|
||||
|
||||
@@ -178,7 +178,7 @@ void IrrDriver::changeResolution()
|
||||
material_manager->reInit();
|
||||
|
||||
powerup_manager -> loadPowerups();
|
||||
kart_properties_manager -> loadKartData();
|
||||
kart_properties_manager -> loadAllKarts();
|
||||
item_manager -> loadDefaultItems();
|
||||
projectile_manager -> loadData();
|
||||
attachment_manager -> loadModels();
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
@@ -129,7 +130,8 @@ FileManager::FileManager()
|
||||
fprintf(stderr, "Data files will be fetched from: '%s'\n",
|
||||
m_root_dir.c_str() );
|
||||
|
||||
TrackManager::addTrackDir(m_root_dir+"/data/tracks");
|
||||
TrackManager::addTrackSearchDir(m_root_dir+"/data/tracks");
|
||||
KartPropertiesManager::addKartSearchDir(m_root_dir+"/data/karts");
|
||||
pushTextureSearchPath(m_root_dir+"/data/textures");
|
||||
pushModelSearchPath (m_root_dir+"/data/models" );
|
||||
pushMusicSearchPath (m_root_dir+"/data/music" );
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/mesh_tools.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
|
||||
float KartModel::UNDEFINED = -99.9f;
|
||||
@@ -100,10 +99,9 @@ void KartModel::attachModel(scene::IAnimatedMeshSceneNode **node)
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Loads the 3d model and all wheels.
|
||||
*/
|
||||
void KartModel::loadModels(const std::string &kart_ident)
|
||||
void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
{
|
||||
std::string full_path = file_manager->getKartFile(m_model_filename,
|
||||
kart_ident);
|
||||
std::string full_path = kart_properties.getKartDir()+"/"+m_model_filename;
|
||||
m_mesh = irr_driver->getAnimatedMesh(full_path);
|
||||
Vec3 min, max;
|
||||
MeshTools::minMax3D(m_mesh, &min, &max);
|
||||
@@ -139,8 +137,8 @@ void KartModel::loadModels(const std::string &kart_ident)
|
||||
// depend on the size of the model.
|
||||
for(unsigned int i=0; i<4; i++)
|
||||
{
|
||||
std::string full_wheel = file_manager->getKartFile(m_wheel_filename[i],
|
||||
kart_ident);
|
||||
std::string full_wheel =
|
||||
kart_properties.getKartDir()+"/"+m_wheel_filename[i];
|
||||
m_wheel_model[i] = irr_driver->getMesh(full_wheel);
|
||||
// FIXME: wheel handling still missing.
|
||||
} // for i<4
|
||||
|
||||
@@ -29,6 +29,8 @@ using namespace irr;
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
|
||||
class KartProperties;
|
||||
|
||||
/** This class stores a 3D kart model. It takes especially care of attaching
|
||||
* the wheels, which are loaded as separate objects. The wheels can turn
|
||||
* and (for the front wheels) rotate. The implementation is dependent on the
|
||||
@@ -101,7 +103,7 @@ public:
|
||||
KartModel();
|
||||
~KartModel();
|
||||
void loadInfo(const lisp::Lisp* lisp);
|
||||
void loadModels(const std::string &kart_ident);
|
||||
void loadModels(const KartProperties &kart_properties);
|
||||
void attachModel(scene::IAnimatedMeshSceneNode **node);
|
||||
scene::IAnimatedMesh* getModel() const { return m_mesh; }
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ float KartProperties::UNDEFINED = -99.9f;
|
||||
* Otherwise the defaults are taken from STKConfig (and since they are all
|
||||
* defined, it is guaranteed that each kart has well defined physics values.
|
||||
*/
|
||||
KartProperties::KartProperties() : m_icon_material(0)
|
||||
KartProperties::KartProperties(const std::string &filename) : m_icon_material(0)
|
||||
{
|
||||
m_name = "Tux";
|
||||
m_ident = "tux";
|
||||
@@ -77,6 +77,9 @@ KartProperties::KartProperties() : m_icon_material(0)
|
||||
m_color = video::SColor(255, 0, 0, 0);
|
||||
m_shape = 32; // close enough to a circle.
|
||||
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
|
||||
// The default constructor for stk_config uses filename=""
|
||||
if(filename!="")
|
||||
load(filename);
|
||||
} // KartProperties
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -90,11 +93,8 @@ KartProperties::~KartProperties()
|
||||
* \param filename Filename to load.
|
||||
* \param node Name of the lisp node to load the data from
|
||||
* (default: tuxkart-kart)
|
||||
* \param dont_load_models If set does not load the actual kart models, used
|
||||
* when only printing kart information to stdout.
|
||||
*/
|
||||
void KartProperties::load(const std::string &filename, const std::string &node,
|
||||
bool dont_load_models)
|
||||
void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
{
|
||||
|
||||
// Get the default values from STKConfig:
|
||||
@@ -119,7 +119,8 @@ void KartProperties::load(const std::string &filename, const std::string &node,
|
||||
}
|
||||
#else
|
||||
const lisp::Lisp* root = 0;
|
||||
m_ident = StringUtils::getBasename(StringUtils::removeExtension(filename));
|
||||
m_root = StringUtils::getPath(filename);
|
||||
m_ident = StringUtils::getBasename(m_root);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -163,40 +164,35 @@ void KartProperties::load(const std::string &filename, const std::string &node,
|
||||
/*is_full+path*/false,
|
||||
/*make_permanent*/true);
|
||||
|
||||
// Load model, except when called as part of --list-karts
|
||||
if(!dont_load_models)
|
||||
// Only load the model if the .kart file has the appropriate version,
|
||||
// otherwise warnings are printed.
|
||||
if(m_version>=1)
|
||||
m_kart_model.loadModels(*this);
|
||||
if(m_gravity_center_shift.getX()==UNDEFINED)
|
||||
{
|
||||
// Only load the model if the .kart file has the appropriate version,
|
||||
// otherwise warnings are printed.
|
||||
if(m_version>=1)
|
||||
m_kart_model.loadModels(m_ident);
|
||||
if(m_gravity_center_shift.getX()==UNDEFINED)
|
||||
{
|
||||
m_gravity_center_shift.setX(0);
|
||||
m_gravity_center_shift.setY(0);
|
||||
// Default: center at the very bottom of the kart.
|
||||
m_gravity_center_shift.setZ(m_kart_model.getHeight()*0.5f);
|
||||
}
|
||||
m_kart_model.setDefaultPhysicsPosition(m_gravity_center_shift,
|
||||
m_wheel_radius);
|
||||
m_wheel_base = fabsf( m_kart_model.getWheelPhysicsPosition(0).getY()
|
||||
-m_kart_model.getWheelPhysicsPosition(2).getY());
|
||||
m_angle_at_min = asinf(m_wheel_base/m_min_radius);
|
||||
m_angle_at_max = asinf(m_wheel_base/m_max_radius);
|
||||
if(m_max_speed_turn == m_min_speed_turn)
|
||||
m_speed_angle_increase = 0.0;
|
||||
else
|
||||
m_speed_angle_increase = (m_angle_at_min - m_angle_at_max)
|
||||
/ (m_max_speed_turn - m_min_speed_turn);
|
||||
m_gravity_center_shift.setX(0);
|
||||
m_gravity_center_shift.setY(0);
|
||||
// Default: center at the very bottom of the kart.
|
||||
m_gravity_center_shift.setZ(m_kart_model.getHeight()*0.5f);
|
||||
}
|
||||
m_kart_model.setDefaultPhysicsPosition(m_gravity_center_shift,
|
||||
m_wheel_radius);
|
||||
m_wheel_base = fabsf( m_kart_model.getWheelPhysicsPosition(0).getY()
|
||||
-m_kart_model.getWheelPhysicsPosition(2).getY());
|
||||
m_angle_at_min = asinf(m_wheel_base/m_min_radius);
|
||||
m_angle_at_max = asinf(m_wheel_base/m_max_radius);
|
||||
if(m_max_speed_turn == m_min_speed_turn)
|
||||
m_speed_angle_increase = 0.0;
|
||||
else
|
||||
m_speed_angle_increase = (m_angle_at_min - m_angle_at_max)
|
||||
/ (m_max_speed_turn - m_min_speed_turn);
|
||||
|
||||
|
||||
// Useful when tweaking kart parameters
|
||||
if(UserConfigParams::m_print_kart_sizes)
|
||||
printf("%s:\twidth: %f\tlength: %f\theight: %f\n",getIdent().c_str(),
|
||||
m_kart_model.getWidth(), m_kart_model.getLength(),
|
||||
m_kart_model.getHeight());
|
||||
|
||||
} // if
|
||||
// Useful when tweaking kart parameters
|
||||
if(UserConfigParams::m_print_kart_sizes)
|
||||
printf("%s:\twidth: %f\tlength: %f\theight: %f\n",getIdent().c_str(),
|
||||
m_kart_model.getWidth(), m_kart_model.getLength(),
|
||||
m_kart_model.getHeight());
|
||||
|
||||
file_manager->popTextureSearchPath();
|
||||
file_manager->popModelSearchPath();
|
||||
@@ -330,6 +326,7 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
root->get("camera-distance", &m_camera_distance);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
{
|
||||
lisp->get("version", m_version);
|
||||
|
||||
@@ -43,7 +43,8 @@ class XMLNode;
|
||||
class KartProperties
|
||||
{
|
||||
private:
|
||||
|
||||
/** Base directory for this kart. */
|
||||
std::string m_root;
|
||||
Material *m_icon_material; /**< The icon texture to use. */
|
||||
/** The kart model and wheels. It is mutable since the wheels of the
|
||||
* KartModel can rotate and turn, but otherwise the kart_properties
|
||||
@@ -163,15 +164,14 @@ private:
|
||||
std::vector<float> m_gear_switch_ratio,
|
||||
m_gear_power_increase;
|
||||
|
||||
void load (const std::string &filename,
|
||||
const std::string &node="tuxkart-kart");
|
||||
|
||||
public:
|
||||
KartProperties ();
|
||||
KartProperties (const std::string &filename="");
|
||||
~KartProperties ();
|
||||
void getAllData (const lisp::Lisp* lisp);
|
||||
void getAllData (const XMLNode * root);
|
||||
void load (const std::string &filename,
|
||||
const std::string &node="tuxkart-kart",
|
||||
bool dont_load_models=false);
|
||||
void checkAllSet(const std::string &filename);
|
||||
|
||||
float getMaxSteerAngle (float speed) const;
|
||||
@@ -260,6 +260,8 @@ public:
|
||||
float getCameraMaxAccel () const {return m_camera_max_accel; }
|
||||
float getCameraMaxBrake () const {return m_camera_max_brake; }
|
||||
float getCameraDistance () const {return m_camera_distance; }
|
||||
/** Returns the full path where the files for this kart are stored. */
|
||||
const std::string& getKartDir () const {return m_root; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <stdio.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "challenges/unlock_manager.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
@@ -32,12 +33,17 @@
|
||||
|
||||
KartPropertiesManager *kart_properties_manager=0;
|
||||
|
||||
std::vector<std::string> KartPropertiesManager::m_kart_search_path;
|
||||
|
||||
/** Constructor, only clears internal data structures. */
|
||||
KartPropertiesManager::KartPropertiesManager()
|
||||
{
|
||||
m_all_groups.clear();
|
||||
} // KartPropertiesManager
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Destructor. Removes all allocated data.
|
||||
*/
|
||||
KartPropertiesManager::~KartPropertiesManager()
|
||||
{
|
||||
for(KartPropertiesVector::iterator i = m_karts_properties.begin();
|
||||
@@ -50,6 +56,17 @@ KartPropertiesManager::~KartPropertiesManager()
|
||||
}
|
||||
} // ~KartPropertiesManager
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Adds a directory from which karts are loaded. The kart manager checks if
|
||||
* either this directory itself contains a kart, and if any subdirectory
|
||||
* contains a kart.
|
||||
* \param dir The directory to add.
|
||||
*/
|
||||
void KartPropertiesManager::addKartSearchDir(const std::string &s)
|
||||
{
|
||||
m_kart_search_path.push_back(s);
|
||||
} // addKartSearchDir
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void KartPropertiesManager::removeTextures()
|
||||
{
|
||||
@@ -62,55 +79,67 @@ void KartPropertiesManager::removeTextures()
|
||||
} // removeTextures
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void KartPropertiesManager::loadKartData(bool dont_load_models)
|
||||
/** Loads all kart properties and models.
|
||||
*/
|
||||
void KartPropertiesManager::loadAllKarts()
|
||||
{
|
||||
std::set<std::string> result;
|
||||
file_manager->listFiles(result, file_manager->getKartDir(),
|
||||
/*is_full_path*/ true);
|
||||
|
||||
// Find out which characters are available and load them
|
||||
for(std::set<std::string>::iterator i = result.begin();
|
||||
i != result.end(); ++i)
|
||||
m_all_kart_dirs.clear();
|
||||
for(std::vector<std::string>::const_iterator dir=m_kart_search_path.begin();
|
||||
dir!=m_kart_search_path.end(); dir++)
|
||||
{
|
||||
std::string kart_file;
|
||||
try
|
||||
{
|
||||
kart_file = file_manager->getKartFile((*i)+".irrkart");
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
(void)e; // remove warning about unused variable
|
||||
continue;
|
||||
}
|
||||
FILE *f=fopen(kart_file.c_str(),"r");
|
||||
if(!f) continue;
|
||||
fclose(f);
|
||||
KartProperties* kp = new KartProperties();
|
||||
kp->load(kart_file, "tuxkart-kart", dont_load_models);
|
||||
// First check if there is a kart in the current directory
|
||||
// -------------------------------------------------------
|
||||
if(loadKart(*dir)) continue;
|
||||
|
||||
// If the version of the kart file is not supported,
|
||||
// ignore this .kart file
|
||||
if(kp->getVersion()<stk_config->m_min_kart_version ||
|
||||
kp->getVersion()>stk_config->m_max_kart_version)
|
||||
// If not, check each subdir of this directory.
|
||||
// --------------------------------------------
|
||||
std::set<std::string> result;
|
||||
file_manager->listFiles(result, *dir, /*is_full_path*/ true);
|
||||
for(std::set<std::string>::const_iterator subdir=result.begin();
|
||||
subdir!=result.end(); subdir++)
|
||||
{
|
||||
fprintf(stderr, "Warning: kart '%s' is not supported by this binary, ignored.\n",
|
||||
kp->getIdent().c_str());
|
||||
delete kp;
|
||||
continue;
|
||||
}
|
||||
|
||||
m_karts_properties.push_back(kp);
|
||||
m_kart_available.push_back(true);
|
||||
const std::vector<std::string>& groups=kp->getGroups();
|
||||
for(unsigned int g=0; g<groups.size(); g++)
|
||||
{
|
||||
if(m_groups.find(groups[g])==m_groups.end())
|
||||
{
|
||||
m_all_groups.push_back(groups[g]);
|
||||
}
|
||||
m_groups[groups[g]].push_back(m_karts_properties.size()-1);
|
||||
}
|
||||
loadKart(*dir+"/"+*subdir);
|
||||
} // for all files in the currently handled directory
|
||||
} // for i
|
||||
} // loadAllKarts
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Loads a single kart and (if not disabled) the oorresponding 3d model.
|
||||
* \param filename Full path to the kart config file.
|
||||
*/
|
||||
bool KartPropertiesManager::loadKart(const std::string &dir)
|
||||
{
|
||||
std::string config_filename=dir+"/kart.xml";
|
||||
FILE *f=fopen(config_filename.c_str(), "r");
|
||||
if(!f) return false;
|
||||
fclose(f);
|
||||
|
||||
KartProperties* kart_properties = new KartProperties(config_filename);
|
||||
|
||||
// If the version of the kart file is not supported,
|
||||
// ignore this .kart file
|
||||
if( kart_properties->getVersion()<stk_config->m_min_kart_version ||
|
||||
kart_properties->getVersion()>stk_config->m_max_kart_version)
|
||||
{
|
||||
fprintf(stderr, "Warning: kart '%s' is not supported by this binary, ignored.\n",
|
||||
kart_properties->getIdent().c_str());
|
||||
delete kart_properties;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_karts_properties.push_back(kart_properties);
|
||||
m_kart_available.push_back(true);
|
||||
const std::vector<std::string>& groups=kart_properties->getGroups();
|
||||
for(unsigned int g=0; g<groups.size(); g++)
|
||||
{
|
||||
if(m_groups.find(groups[g])==m_groups.end())
|
||||
{
|
||||
m_all_groups.push_back(groups[g]);
|
||||
}
|
||||
m_groups[groups[g]].push_back(m_karts_properties.size()-1);
|
||||
}
|
||||
m_all_kart_dirs.push_back(dir);
|
||||
return true;
|
||||
} // loadKartData
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -29,7 +29,14 @@ class KartProperties;
|
||||
class KartPropertiesManager
|
||||
{
|
||||
private:
|
||||
/** The list of all directories in which to search for karts. */
|
||||
static std::vector<std::string> m_kart_search_path;
|
||||
/** All directories from which karts were loaded. Needed by unlock_manager
|
||||
* to load all challenges. */
|
||||
std::vector<std::string> m_all_kart_dirs;
|
||||
/** List of all kart groups. */
|
||||
std::vector<std::string> m_all_groups;
|
||||
/** Mapping of group names to list of kart indices in each group. */
|
||||
std::map<std::string, std::vector<int> > m_groups;
|
||||
/** Vector containing kart numbers that have been selected in multiplayer
|
||||
* games. This it used to ensure the same kart can not be selected more
|
||||
@@ -38,6 +45,7 @@ private:
|
||||
/** Contains a flag for each kart indicating wether it is available on
|
||||
* all clients or not. */
|
||||
std::vector<bool> m_kart_available;
|
||||
bool loadKart(const std::string &dir);
|
||||
protected:
|
||||
|
||||
typedef std::vector<KartProperties*> KartPropertiesVector;
|
||||
@@ -45,14 +53,14 @@ protected:
|
||||
KartPropertiesVector m_karts_properties;
|
||||
|
||||
public:
|
||||
KartPropertiesManager();
|
||||
~KartPropertiesManager();
|
||||
|
||||
KartPropertiesManager();
|
||||
~KartPropertiesManager();
|
||||
static void addKartSearchDir (const std::string &s);
|
||||
const KartProperties* getKartById (int i) const;
|
||||
const KartProperties* getKart (const std::string &ident) const;
|
||||
const int getKartId (const std::string &ident) const;
|
||||
int getKartByGroup (const std::string& group, int i) const;
|
||||
void loadKartData (bool dont_load_models=false);
|
||||
void loadAllKarts ();
|
||||
const unsigned int getNumberOfKarts () const {return (unsigned int)m_karts_properties.size();}
|
||||
const std::vector<std::string>&
|
||||
getAllGroups () const {return m_all_groups; }
|
||||
@@ -70,6 +78,9 @@ public:
|
||||
bool testAndSetKart(int kartid);
|
||||
std::vector<std::string> getRandomKartList(int count, RemoteKartInfoList& existing_karts);
|
||||
void removeTextures ();
|
||||
/** Returns all directories from which karts were loaded. */
|
||||
const std::vector<std::string>* getAllKartDirs() const
|
||||
{ return &m_all_kart_dirs; }
|
||||
};
|
||||
|
||||
extern KartPropertiesManager *kart_properties_manager;
|
||||
|
||||
77
src/main.cpp
77
src/main.cpp
@@ -100,7 +100,7 @@ void cmdLineHelp (char* invocation)
|
||||
" -s, --screensize WxH Set the screen size (e.g. 320x200).\n"
|
||||
" -v, --version Show version of SuperTuxKart.\n"
|
||||
" --trackdir DIR A directory from which additional tracks are loaded.\n"
|
||||
// should not be used by unaware users:
|
||||
// should not be used by unaware users:u
|
||||
// " --profile Enable automatic driven profile mode for 20 seconds.\n"
|
||||
// " --profile=n Enable automatic driven profile mode for n seconds.\n"
|
||||
// " if n<0 --> (-n) = number of laps to drive.
|
||||
@@ -123,7 +123,11 @@ void cmdLineHelp (char* invocation)
|
||||
|
||||
//=============================================================================
|
||||
/** For base options that don't need much to be inited (and, in some cases,
|
||||
* that need to be read before initing stuff.
|
||||
* that need to be read before initing stuff) - it only assumes that
|
||||
* user config is loaded (necessary to check for blacklisted screen
|
||||
* resolutions), but nothing else (esp. not kart_properties_manager and
|
||||
* track_manager, since their search path might be extended by command
|
||||
* line options).
|
||||
*/
|
||||
int handleCmdLinePreliminary(int argc, char **argv)
|
||||
{
|
||||
@@ -141,7 +145,12 @@ int handleCmdLinePreliminary(int argc, char **argv)
|
||||
}
|
||||
else if( !strcmp(argv[i], "--trackdir") && i+1<argc )
|
||||
{
|
||||
TrackManager::addTrackDir(argv[i+1]);
|
||||
TrackManager::addTrackSearchDir(argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if( !strcmp(argv[i], "--kartdir") && i+1<argc )
|
||||
{
|
||||
KartPropertiesManager::addKartSearchDir(argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
#if !defined(WIN32) && !defined(__CYGWIN)
|
||||
@@ -351,16 +360,9 @@ int handleCmdLine(int argc, char **argv)
|
||||
}
|
||||
|
||||
fprintf ( stdout, "Use --track N to choose track.\n\n");
|
||||
delete track_manager;
|
||||
track_manager = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if( !strcmp(argv[i], "--list-karts") )
|
||||
{
|
||||
bool dont_load_models=true;
|
||||
kart_properties_manager->loadKartData(dont_load_models) ;
|
||||
|
||||
fprintf ( stdout, " Available karts:\n" );
|
||||
for (unsigned int i = 0; NULL != kart_properties_manager->getKartById(i); i++)
|
||||
{
|
||||
@@ -368,8 +370,6 @@ int handleCmdLine(int argc, char **argv)
|
||||
fprintf (stdout, "\t%10s: %s\n", KP->getIdent().c_str(), KP->getName().c_str());
|
||||
}
|
||||
fprintf ( stdout, "\n" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if ( !strcmp(argv[i], "--no-start-screen")
|
||||
|| !strcmp(argv[i], "-N") )
|
||||
@@ -453,22 +453,12 @@ int handleCmdLine(int argc, char **argv)
|
||||
}
|
||||
// these commands are already processed in handleCmdLinePreliminary, but repeat this
|
||||
// just so that we don't get error messages about unknown commands
|
||||
else if( !strcmp(argv[i], "--trackdir") && i+1<argc )
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else if ( !strcmp(argv[i], "--fullscreen") || !strcmp(argv[i], "-f"))
|
||||
{
|
||||
}
|
||||
else if ( !strcmp(argv[i], "--windowed") || !strcmp(argv[i], "-w"))
|
||||
{
|
||||
}
|
||||
else if ( !strcmp(argv[i], "--screensize") || !strcmp(argv[i], "-s") )
|
||||
{
|
||||
}
|
||||
else if ( !strcmp(argv[i], "--version") || !strcmp(argv[i], "-v") )
|
||||
{
|
||||
}
|
||||
else if( !strcmp(argv[i], "--trackdir") && i+1<argc ) i++;
|
||||
else if( !strcmp(argv[i], "--kartdir") && i+1<argc ) i++;
|
||||
else if ( !strcmp(argv[i], "--fullscreen") || !strcmp(argv[i], "-f")) {}
|
||||
else if ( !strcmp(argv[i], "--windowed") || !strcmp(argv[i], "-w")) {}
|
||||
else if ( !strcmp(argv[i], "--screensize") || !strcmp(argv[i], "-s")) {}
|
||||
else if ( !strcmp(argv[i], "--version") || !strcmp(argv[i], "-v")) {}
|
||||
else
|
||||
{
|
||||
fprintf ( stderr, "Invalid parameter: %s.\n\n", argv[i] );
|
||||
@@ -486,12 +476,14 @@ int handleCmdLine(int argc, char **argv)
|
||||
} /* handleCmdLine */
|
||||
|
||||
//=============================================================================
|
||||
void initPreliminary()
|
||||
/** Initialises the minimum number of managers to get access to user_config.
|
||||
*/
|
||||
void initUserConfig()
|
||||
{
|
||||
file_manager = new FileManager();
|
||||
translations = new Translations();
|
||||
user_config = new UserConfig();
|
||||
} // initPreliminary
|
||||
translations = new Translations(); // needs file_manager
|
||||
user_config = new UserConfig(); // needs file_manager
|
||||
} // initUserConfig
|
||||
|
||||
//=============================================================================
|
||||
void initRest()
|
||||
@@ -500,7 +492,7 @@ void initRest()
|
||||
sound_manager = new SoundManager();
|
||||
sfx_manager = new SFXManager();
|
||||
// The order here can be important, e.g. KartPropertiesManager needs
|
||||
// defaultKartProperties.
|
||||
// defaultKartProperties, which are defined in stk_config.
|
||||
history = new History ();
|
||||
material_manager = new MaterialManager ();
|
||||
track_manager = new TrackManager ();
|
||||
@@ -516,7 +508,6 @@ void initRest()
|
||||
|
||||
stk_config->load(file_manager->getConfigFile("stk_config.xml"));
|
||||
track_manager->loadTrackList();
|
||||
unlock_manager = new UnlockManager();
|
||||
sound_manager->addMusicToTracks();
|
||||
|
||||
race_manager = new RaceManager ();
|
||||
@@ -564,7 +555,6 @@ void cleanTuxKart()
|
||||
|
||||
//=============================================================================
|
||||
|
||||
|
||||
int main(int argc, char *argv[] )
|
||||
{
|
||||
try {
|
||||
@@ -572,14 +562,13 @@ int main(int argc, char *argv[] )
|
||||
// only needed for bullet debugging.
|
||||
glutInit(&argc, argv);
|
||||
#endif
|
||||
|
||||
initPreliminary();
|
||||
// Init the minimum managers so that user config exists, then
|
||||
// handle all command line options that do not need (or must
|
||||
// not have) other managers initialised:
|
||||
initUserConfig();
|
||||
handleCmdLinePreliminary(argc, argv);
|
||||
|
||||
initRest();
|
||||
|
||||
//handleCmdLine() needs InitTuxkart() so it can't be called first
|
||||
if(!handleCmdLine(argc, argv)) exit(0);
|
||||
|
||||
if (UserConfigParams::m_log_errors) //Enable logging of stdout and stderr to logfile
|
||||
{
|
||||
@@ -606,7 +595,8 @@ int main(int argc, char *argv[] )
|
||||
|
||||
main_loop = new MainLoop();
|
||||
material_manager -> loadMaterial ();
|
||||
kart_properties_manager -> loadKartData ();
|
||||
kart_properties_manager -> loadAllKarts ();
|
||||
unlock_manager = new UnlockManager();
|
||||
projectile_manager -> loadData ();
|
||||
powerup_manager -> loadPowerups ();
|
||||
item_manager -> loadDefaultItems();
|
||||
@@ -616,7 +606,10 @@ int main(int argc, char *argv[] )
|
||||
IrrlichtDevice* device = irr_driver->getDevice();
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
GUIEngine::init(device, driver, StateManager::get());
|
||||
|
||||
|
||||
//handleCmdLine() needs InitTuxkart() so it can't be called first
|
||||
if(!handleCmdLine(argc, argv)) exit(0);
|
||||
|
||||
if(!UserConfigParams::m_no_start_screen)
|
||||
{
|
||||
StateManager::get()->pushMenu("main.stkgui");
|
||||
|
||||
@@ -52,7 +52,7 @@ TrackManager::~TrackManager()
|
||||
* contains a track.
|
||||
* \param dir The directory to add.
|
||||
*/
|
||||
void TrackManager::addTrackDir(const std::string &dir)
|
||||
void TrackManager::addTrackSearchDir(const std::string &dir)
|
||||
{
|
||||
m_track_search_path.push_back(dir);
|
||||
} // addTrackDir
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
TrackManager();
|
||||
~TrackManager();
|
||||
|
||||
static void addTrackDir(const std::string &dir);
|
||||
static void addTrackSearchDir(const std::string &dir);
|
||||
/** Returns a list of all directories that contain a track. */
|
||||
const std::vector<std::string>* getAllTrackDirs() const
|
||||
{ return &m_all_track_dirs; }
|
||||
|
||||
Reference in New Issue
Block a user