Added new class to handle command line parameters, which

simplifies parameter handling in main (e.g. it's not
necessary to list and ignore parameters in the 2nd
pass, when they were handled in the first pass).
Removed some command line options for which there
is a guy (e.g. --weather), or which are not really
useful (--list-karts). 

All parameters to options must now consistently be
specified using '=', e.g.: --log=1 and --kart=tux.

Also removed support for 'classic' camera (which was
not used anymore). Removed now unneccessary #include
in user_config.hpp, which made some #include changes
in other files necessary.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14939 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2014-01-06 12:23:16 +00:00
parent 068eb8ece2
commit 6ee751e3c3
27 changed files with 722 additions and 743 deletions

View File

@ -117,8 +117,8 @@ src/items/projectile_manager.cpp
src/items/rubber_ball.cpp
src/items/rubber_band.cpp
src/items/swatter.cpp
src/karts/abstract_kart_animation.cpp
src/karts/abstract_kart.cpp
src/karts/abstract_kart_animation.cpp
src/karts/cannon_animation.cpp
src/karts/controller/ai_base_controller.cpp
src/karts/controller/ai_properties.cpp
@ -249,8 +249,8 @@ src/states_screens/help_screen_3.cpp
src/states_screens/help_screen_4.cpp
src/states_screens/kart_selection.cpp
src/states_screens/main_menu_screen.cpp
src/states_screens/networking_lobby.cpp
src/states_screens/network_kart_selection.cpp
src/states_screens/networking_lobby.cpp
src/states_screens/offline_kart_selection.cpp
src/states_screens/online_profile_achievements.cpp
src/states_screens/online_profile_base.cpp
@ -260,13 +260,13 @@ src/states_screens/online_profile_settings.cpp
src/states_screens/online_screen.cpp
src/states_screens/online_user_search.cpp
src/states_screens/options_screen_audio.cpp
src/states_screens/options_screen_input2.cpp
src/states_screens/options_screen_input.cpp
src/states_screens/options_screen_input2.cpp
src/states_screens/options_screen_players.cpp
src/states_screens/options_screen_ui.cpp
src/states_screens/options_screen_video.cpp
src/states_screens/race_gui_base.cpp
src/states_screens/race_gui.cpp
src/states_screens/race_gui_base.cpp
src/states_screens/race_gui_overworld.cpp
src/states_screens/race_result_gui.cpp
src/states_screens/race_setup_screen.cpp
@ -305,6 +305,7 @@ src/tracks/track_object.cpp
src/tracks/track_object_manager.cpp
src/tracks/track_object_presentation.cpp
src/tracks/track_sector.cpp
src/utils/command_line.cpp
src/utils/constants.cpp
src/utils/crash_reporting.cpp
src/utils/debug.cpp
@ -335,8 +336,8 @@ src/animations/animation_base.hpp
src/animations/ipo.hpp
src/animations/three_d_animation.hpp
src/audio/dummy_sfx.hpp
src/audio/music_dummy.hpp
src/audio/music.hpp
src/audio/music_dummy.hpp
src/audio/music_information.hpp
src/audio/music_manager.hpp
src/audio/music_ogg.hpp
@ -344,8 +345,8 @@ src/audio/sfx_base.hpp
src/audio/sfx_buffer.hpp
src/audio/sfx_manager.hpp
src/audio/sfx_openal.hpp
src/challenges/challenge_data.hpp
src/challenges/challenge.hpp
src/challenges/challenge_data.hpp
src/challenges/game_slot.hpp
src/challenges/unlock_manager.hpp
src/config/device_config.hpp
@ -359,7 +360,6 @@ src/graphics/CBatchingMesh.hpp
src/graphics/explosion.hpp
src/graphics/glow.hpp
src/graphics/glwrap.hpp
src/graphics/gpuparticles.h
src/graphics/hardware_skinning.hpp
src/graphics/hit_effect.hpp
src/graphics/hit_sfx.hpp
@ -403,11 +403,11 @@ src/guiengine/scalable_font.hpp
src/guiengine/screen.hpp
src/guiengine/skin.hpp
src/guiengine/widget.hpp
src/guiengine/widgets.hpp
src/guiengine/widgets/bubble_widget.hpp
src/guiengine/widgets/button_widget.hpp
src/guiengine/widgets/check_box_widget.hpp
src/guiengine/widgets/dynamic_ribbon_widget.hpp
src/guiengine/widgets.hpp
src/guiengine/widgets/icon_button_widget.hpp
src/guiengine/widgets/label_widget.hpp
src/guiengine/widgets/list_widget.hpp
@ -419,8 +419,8 @@ src/guiengine/widgets/spinner_widget.hpp
src/guiengine/widgets/text_box_widget.hpp
src/input/binding.hpp
src/input/device_manager.hpp
src/input/input_device.hpp
src/input/input.hpp
src/input/input_device.hpp
src/input/input_manager.hpp
src/input/wiimote.hpp
src/input/wiimote_manager.hpp
@ -442,8 +442,8 @@ src/items/projectile_manager.hpp
src/items/rubber_ball.hpp
src/items/rubber_band.hpp
src/items/swatter.hpp
src/karts/abstract_kart_animation.hpp
src/karts/abstract_kart.hpp
src/karts/abstract_kart_animation.hpp
src/karts/cannon_animation.hpp
src/karts/controller/ai_base_controller.hpp
src/karts/controller/ai_properties.hpp
@ -455,8 +455,8 @@ src/karts/controller/player_controller.hpp
src/karts/controller/skidding_ai.hpp
src/karts/explosion_animation.hpp
src/karts/ghost_kart.hpp
src/karts/kart_gfx.hpp
src/karts/kart.hpp
src/karts/kart_gfx.hpp
src/karts/kart_model.hpp
src/karts/kart_properties.hpp
src/karts/kart_properties_manager.hpp
@ -579,8 +579,8 @@ src/states_screens/help_screen_3.hpp
src/states_screens/help_screen_4.hpp
src/states_screens/kart_selection.hpp
src/states_screens/main_menu_screen.hpp
src/states_screens/networking_lobby.hpp
src/states_screens/network_kart_selection.hpp
src/states_screens/networking_lobby.hpp
src/states_screens/offline_kart_selection.hpp
src/states_screens/online_profile_achievements.hpp
src/states_screens/online_profile_base.hpp
@ -590,13 +590,13 @@ src/states_screens/online_profile_settings.hpp
src/states_screens/online_screen.hpp
src/states_screens/online_user_search.hpp
src/states_screens/options_screen_audio.hpp
src/states_screens/options_screen_input2.hpp
src/states_screens/options_screen_input.hpp
src/states_screens/options_screen_input2.hpp
src/states_screens/options_screen_players.hpp
src/states_screens/options_screen_ui.hpp
src/states_screens/options_screen_video.hpp
src/states_screens/race_gui_base.hpp
src/states_screens/race_gui.hpp
src/states_screens/race_gui_base.hpp
src/states_screens/race_gui_overworld.hpp
src/states_screens/race_result_gui.hpp
src/states_screens/race_setup_screen.hpp
@ -627,8 +627,8 @@ src/tracks/check_sphere.hpp
src/tracks/check_structure.hpp
src/tracks/graph_node.hpp
src/tracks/lod_node_loader.hpp
src/tracks/quad_graph.hpp
src/tracks/quad.hpp
src/tracks/quad_graph.hpp
src/tracks/quad_set.hpp
src/tracks/terrain_info.hpp
src/tracks/track.hpp
@ -638,6 +638,7 @@ src/tracks/track_object_manager.hpp
src/tracks/track_object_presentation.hpp
src/tracks/track_sector.hpp
src/utils/aligned_array.hpp
src/utils/command_line.hpp
src/utils/constants.hpp
src/utils/crash_reporting.hpp
src/utils/debug.hpp

View File

@ -22,6 +22,7 @@
#include <string>
#include "config/user_config.hpp"
#include "utils/no_copy.hpp"
#include "utils/types.hpp"
#include <irrString.h>
using namespace irr;

View File

@ -19,6 +19,7 @@
#include "config/saved_grand_prix.hpp"
#include "io/xml_node.hpp"
#include "karts/kart_properties_manager.hpp"
#include "utils/ptr_vector.hpp"
#include "utils/string_utils.hpp"

View File

@ -46,7 +46,6 @@
using irr::core::stringc;
using irr::core::stringw;
#include "graphics/camera.hpp"
#include "io/xml_writer.hpp"
#include "utils/constants.hpp"
#include "utils/no_copy.hpp"
@ -528,9 +527,6 @@ namespace UserConfigParams
// not saved to file
// ---- Networking
PARAM_PREFIX IntUserConfigParam m_server_port
PARAM_DEFAULT( IntUserConfigParam(7321, "server_port",
"Information about the port to listen on.") );
PARAM_PREFIX IntUserConfigParam m_server_max_players
PARAM_DEFAULT( IntUserConfigParam(16, "server_max_players",
@ -666,10 +662,6 @@ namespace UserConfigParams
PARAM_DEFAULT( IntUserConfigParam(0, "reverse_look_threshold",
"If the kart is driving backwards faster than this value,\n"
"switch automatically to reverse camera (set to 0 to disable).") );
PARAM_PREFIX IntUserConfigParam m_camera_style
PARAM_DEFAULT( IntUserConfigParam(Camera::CS_MODERN,
"camera_style", "Camera Style") );
PARAM_PREFIX StringUserConfigParam m_item_style
PARAM_DEFAULT( StringUserConfigParam("items", "item_style",

View File

@ -15,6 +15,8 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/callbacks.hpp"
#include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/wind.hpp"
#include "guiengine/engine.hpp"

View File

@ -71,13 +71,6 @@ Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL)
m_target_speed = 10.0f;
m_rotation_range = 0.4f;
m_rotation_range = 0.0f;
// TODO: Make this per user too if the one above goes that way.
switch(UserConfigParams::m_camera_style)
{
case 1: m_camera_style = CS_CLASSIC; break;
case 0:
default: m_camera_style = CS_MODERN; break;
}
reset();
} // Camera
@ -373,16 +366,6 @@ void Camera::getCameraSettings(float *above_kart, float *cam_angle,
switch(m_mode)
{
case CM_NORMAL:
if(m_camera_style==CS_CLASSIC)
{
*above_kart = 0.3f;
*cam_angle = kp->getCameraBackwardUpAngle();
*sideway = 0.0f;
*distance = -1.5f*m_distance;
*smoothing = true;
break;
}
// Fall through to falling mode.
case CM_FALLING:
{
if(UserConfigParams::m_camera_debug==2)

View File

@ -59,11 +59,6 @@ public:
CM_FALLING
};
enum Style {
CS_MODERN, //!< Flexible link between kart and camera
CS_CLASSIC, //!< Fixed position style, like STK v0.6
};
private:
/** The camera scene node. */
scene::ICameraSceneNode *m_camera;
@ -117,10 +112,6 @@ private:
/** Velocity of the target of the camera, only used for end camera. */
core::vector3df m_target_velocity;
/* Whether we should use the pre-0.7 camera style or the
* modern style. Should default to modern. */
Style m_camera_style;
/** List of all cameras. */
static std::vector<Camera*> m_all_cameras;

View File

@ -102,7 +102,7 @@ void generateLifetimeSizeDirection(scene::IParticleEmitter *emitter, float &life
{
float sizeMin = emitter->getMinStartSize().Height;
float sizeMax = emitter->getMaxStartSize().Height;
float lifetime_range = emitter->getMaxLifeTime() - emitter->getMinLifeTime();
float lifetime_range = float(emitter->getMaxLifeTime() - emitter->getMinLifeTime());
lifetime = os::Randomizer::frand() * lifetime_range;
lifetime += emitter->getMinLifeTime();

View File

@ -2,19 +2,24 @@
#define GPUPARTICLES_H
#include "graphics/glwrap.hpp"
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
#include <ISceneManager.h>
#include <IParticleSystemSceneNode.h>
namespace irr { namespace video{ class ITexture; } }
GLuint getTextureGLuint(irr::video::ITexture *tex);
class GPUParticle : public scene::ISceneNode {
class GPUParticle : public scene::ISceneNode
{
protected:
video::SMaterial fakemat;
virtual void simulate() = 0;
virtual void draw() = 0;
public:
GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr, ITexture *tex);
GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr,
video::ITexture *tex);
virtual void render();
virtual void OnRegisterSceneNode();
};
@ -79,7 +84,7 @@ protected:
virtual void draw();
public:
PointEmitter(scene::ISceneNode *parent,
scene::ISceneManager* mgr, ITexture *tex,
scene::ISceneManager* mgr, video::ITexture *tex,
const core::vector3df& dir,
u32 minParticlesPerSecond,
u32 maxParticlesPerSecond,
@ -109,7 +114,7 @@ protected:
virtual void simulate();
virtual void draw();
public:
RainNode(scene::ISceneManager* mgr, ITexture *tex);
RainNode(scene::ISceneManager* mgr, video::ITexture *tex);
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual u32 getMaterialCount() const { return 1; }
};

View File

@ -2161,7 +2161,8 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos, float energy,
}
else
{
return m_scene_manager->addLightSceneNode(m_scene_manager->getRootSceneNode(), pos, video::SColor(1., r, g, b));
return m_scene_manager->addLightSceneNode(m_scene_manager->getRootSceneNode(),
pos, video::SColor(1.0f, r, g, b));
}
}

View File

@ -18,12 +18,13 @@
#include "post_processing.hpp"
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/mlaa_areamap.hpp"
#include "graphics/shaders.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/kart_model.hpp"
#include "modes/world.hpp"

View File

@ -18,7 +18,9 @@
#include "audio/sfx_base.hpp"
#include "audio/sfx_manager.hpp"
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/gpuparticles.h"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/material.hpp"
@ -30,9 +32,9 @@
#include "utils/constants.hpp"
#include "utils/random_generator.hpp"
#include <ISceneManager.h>
#include <SMeshBuffer.h>
#include "graphics/gpuparticles.h"
using namespace video;
using namespace scene;

View File

@ -25,6 +25,7 @@
#include "graphics/material_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "tracks/track_manager.hpp"
#include "utils/command_line.hpp"
#include "utils/log.hpp"
#include "utils/string_utils.hpp"
@ -105,7 +106,7 @@ FileManager* file_manager = 0;
* exists) changed in reInit().
*
*/
FileManager::FileManager(char *argv[])
FileManager::FileManager()
{
m_subdir_name.resize(ASSET_COUNT);
m_subdir_name[CHALLENGE ] = "challenges";
@ -144,8 +145,8 @@ FileManager::FileManager(char *argv[])
// This is esp. useful for Visual Studio, since it's not necessary
// to define the working directory when debugging, it works automatically.
std::string root_dir;
if(m_file_system->existFile(argv[0]))
exe_path = m_file_system->getFileDir(argv[0]);
if(m_file_system->existFile(CommandLine::getExecName().c_str()))
exe_path = m_file_system->getFileDir(CommandLine::getExecName().c_str());
if(exe_path.size()==0 || exe_path[exe_path.size()-1]!='/')
exe_path += "/";
if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL )

View File

@ -96,7 +96,7 @@ private:
#endif
public:
FileManager(char *argv[]);
FileManager();
~FileManager();
void reInit();
void dropFileSystem();

View File

@ -21,6 +21,7 @@
#include "audio/sfx_base.hpp"
#include "audio/sfx_manager.hpp"
#include "config/stk_config.hpp"
#include "io/xml_node.hpp"
#include "items/attachment.hpp"
#include "items/projectile_manager.hpp"
#include "karts/abstract_kart.hpp"

View File

@ -25,6 +25,7 @@
#include "karts/controller/controller.hpp"
class AbstractKart;
class Camera;
class Player;
class SFXBase;

View File

@ -19,6 +19,8 @@
#include "karts/explosion_animation.hpp"
#include "audio/sfx_manager.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/camera.hpp"
#include "items/attachment.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/kart_properties.hpp"

View File

@ -18,6 +18,8 @@
#include "karts/rescue_animation.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/camera.hpp"
#include "graphics/referee.hpp"
#include "items/attachment.hpp"
#include "karts/abstract_kart.hpp"

View File

@ -196,6 +196,7 @@
#include "states_screens/dialogs/message_dialog.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/command_line.hpp"
#include "utils/constants.hpp"
#include "utils/crash_reporting.hpp"
#include "utils/leak_check.hpp"
@ -388,7 +389,7 @@ void handleXmasMode()
// ----------------------------------------------------------------------------
/** Prints help for command line options to stdout.
*/
void cmdLineHelp(char* invocation)
void cmdLineHelp()
{
Log::info("main",
"Usage: %s [OPTIONS]\n\n"
@ -399,49 +400,37 @@ void cmdLineHelp(char* invocation)
"menu.\n"
" -R, --race-now Same as -N but also skip the ready-set-go phase"
" and the music.\n"
" -t, --track NAME Start at track NAME (see --list-tracks).\n"
" --gp NAME Start the specified Grand Prix.\n"
" --stk-config FILE use ./data/FILE instead of "
" -t, --track=NAME Start at track NAME.\n"
" --gp=NAME Start the specified Grand Prix.\n"
" --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n"
" -l, --list-tracks Show available tracks.\n"
" -k, --numkarts NUM Number of karts on the racetrack.\n"
" --kart NAME Use kart number NAME (see --list-karts).\n"
" -k, --numkarts=NUM Number of karts on the racetrack.\n"
" --kart=NAME Use kart number NAME.\n"
" --ai=a,b,... Use the karts a, b, ... for the AI.\n"
" --list-karts Show available karts.\n"
" --laps N Define number of laps to N.\n"
" --mode N N=1 novice, N=2 driver, N=3 racer.\n"
" --type N N=0 Normal, N=1 Time trial, N=2 FTL\n"
" --laps=N Define number of laps to N.\n"
" --mode=N N=1 novice, N=2 driver, N=3 racer.\n"
" --type=N N=0 Normal, N=1 Time trial, N=2 FTL\n"
" --reverse Play track in reverse (if allowed)\n"
// TODO: add back "--players" switch
// " --players n Define number of players to between 1 and 4.\n"
" -f, --fullscreen Select fullscreen display.\n"
" -w, --windowed Windowed display (default).\n"
" -s, --screensize WxH Set the screen size (e.g. 320x200).\n"
" -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 "
" --trackdir=DIR A directory from which additional tracks are "
"loaded.\n"
" --animations=n Play karts' animations (All: 2, Humans only: 1,"
" Nobody: 0).\n"
" --gfx=n Play other graphical effects like impact stars "
"dance,\n"
" water animations or explosions (Enable: 1, "
"Disable: 0).\n"
" --weather=n Show weather effects like rain or snow (0 or 1 "
"as --gfx).\n"
" --camera-style=n Flexible (0) or hard like v0.6 (1) kart-camera "
"link.\n"
" --profile-laps=n Enable automatic driven profile mode for n "
"laps.\n"
" --profile-time=n Enable automatic driven profile mode for n "
"seconds.\n"
" --no-graphics Do not display the actual race.\n"
" --with-profile Enables the profile mode.\n"
" --demo-mode t Enables demo mode after t seconds idle time in "
" --demo-mode=t Enables demo mode after t seconds idle time in "
"main menu.\n"
" --demo-tracks t1,t2 List of tracks to be used in demo mode. No\n"
" --demo-tracks=t1,t2 List of tracks to be used in demo mode. No\n"
" spaces are allowed in the track names.\n"
" --demo-laps n Number of laps in a demo.\n"
" --demo-karts n Number of karts to use in a demo.\n"
" --demo-laps=n Number of laps in a demo.\n"
" --demo-karts=n Number of karts to use in a demo.\n"
" --ghost Replay ghost data together with one player kart.\n"
// " --history Replay history file 'history.dat'.\n"
// " --history=n Replay history file 'history.dat' using:\n"
@ -458,7 +447,8 @@ void cmdLineHelp(char* invocation)
" -h, --help Show this help.\n"
"\n"
"You can visit SuperTuxKart's homepage at "
"http://supertuxkart.sourceforge.net\n\n", invocation
"http://supertuxkart.sourceforge.net\n\n",
CommandLine::getExecName().c_str()
);
} // cmdLineHelp
@ -470,119 +460,66 @@ void cmdLineHelp(char* invocation)
* track_manager, since their search path might be extended by command
* line options).
*/
int handleCmdLinePreliminary(int argc, char **argv)
int handleCmdLinePreliminary()
{
int n;
for(int i=1; i<argc; i++)
if( CommandLine::has("--help") || CommandLine::has("-help") ||
CommandLine::has("-h") )
{
if(argv[i][0] != '-') continue;
if (!strcmp(argv[i], "--help" ) ||
!strcmp(argv[i], "-help" ) ||
!strcmp(argv[i], "-h" ) )
{
cmdLineHelp(argv[0]);
cmdLineHelp();
exit(0);
}
else if(!strcmp(argv[i], "--gamepad-visualisation") ||
!strcmp(argv[i], "--gamepad-visualization") )
{
if( CommandLine::has("--gamepad-visualisation") ||
CommandLine::has("--gamepad-visualization") )
UserConfigParams::m_gamepad_visualisation=true;
}
else if ( !strcmp(argv[i], "--debug=memory") )
{
if( CommandLine::has("--debug=memory"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY;
}
else if ( !strcmp(argv[i], "--debug=addons") )
{
if( CommandLine::has("--debug=addons"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_ADDONS;
}
else if ( !strcmp(argv[i], "--debug=gui") )
{
if( CommandLine::has("--debug=mgui"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_GUI;
}
else if ( !strcmp(argv[i], "--debug=flyable") )
{
if( CommandLine::has("--debug=flyable"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_FLYABLE;
}
else if ( !strcmp(argv[i], "--debug=misc") )
{
if( CommandLine::has("--debug=mist"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MISC;
}
else if ( sscanf(argv[i], "--xmas=%d", &n) )
{
UserConfigParams::m_xmas_mode = n;
}
else if( !strcmp(argv[i], "--no-console"))
{
UserConfigParams::m_log_errors_to_console=false;
}
else if( !strcmp(argv[i], "--console"))
{
if(CommandLine::has("--console"))
UserConfigParams::m_log_errors_to_console=true;
}
else if( !strcmp(argv[i], "--log=nocolor"))
if(CommandLine::has("--no-console"))
UserConfigParams::m_log_errors_to_console=false;
if(CommandLine::has("--log=nocolor"))
{
Log::disableColor();
Log::verbose("main", "Colours disabled.\n");
Log::verbose("main", "Colours disabled.");
}
else if(sscanf(argv[i], "--log=%d",&n)==1)
{
Log::setLogLevel(n);
}
else if ( !strcmp(argv[i], "--debug=all") )
{
if(CommandLine::has("--debug=all") )
UserConfigParams::m_verbosity |= UserConfigParams::LOG_ALL;
}
else if( (!strcmp(argv[i], "--stk-config")) && i+1<argc )
std::string s;
if( CommandLine::has( "--stk-config", &s))
{
stk_config->load(file_manager->getAsset(argv[i+1]));
Log::info("main", "STK config will be read from %s.\n",argv[i+1] );
i++;
stk_config->load(file_manager->getAsset(s));
Log::info("main", "STK config will be read from %s.",s);
}
else if( !strcmp(argv[i], "--trackdir") && i+1<argc )
{
TrackManager::addTrackSearchDir(argv[i+1]);
i++;
}
else if( !strcmp(argv[i], "--kartdir") && i+1<argc )
{
KartPropertiesManager::addKartSearchDir(argv[i+1]);
i++;
}
else if( !strcmp(argv[i], "--no-graphics") || !strncmp(argv[i], "--list-", 7) ||
!strcmp(argv[i], "-l" ))
if( CommandLine::has( "--trackdir", &s))
TrackManager::addTrackSearchDir(s);
if( CommandLine::has( "--kartdir", &s))
KartPropertiesManager::addKartSearchDir(s);
if( CommandLine::has( "--no-graphics") ||
CommandLine::has("-l" ) )
{
ProfileWorld::disableGraphics();
UserConfigParams::m_log_errors_to_console=true;
}
#if !defined(WIN32) && !defined(__CYGWIN)
else if ( !strcmp(argv[i], "--fullscreen") || !strcmp(argv[i], "-f"))
{
// Check that current res is not blacklisted
std::ostringstream o;
o << UserConfigParams::m_width << "x"
<< UserConfigParams::m_height;
std::string res = o.str();
if (std::find(UserConfigParams::m_blacklist_res.begin(),
UserConfigParams::m_blacklist_res.end(),res)
== UserConfigParams::m_blacklist_res.end())
UserConfigParams::m_fullscreen = true;
else
Log::warn("main", "Resolution %s has been blacklisted, so it "
"is not available!\n", res.c_str());
}
else if ( !strcmp(argv[i], "--windowed") || !strcmp(argv[i], "-w"))
{
UserConfigParams::m_fullscreen = false;
}
#endif
else if ( (!strcmp(argv[i], "--screensize") || !strcmp(argv[i], "-s") )
&& i+1<argc)
if(CommandLine::has("--screensize", &s) ||
CommandLine::has("-s", &s) )
{
//Check if fullscreen and new res is blacklisted
int width, height;
if (sscanf(argv[i+1], "%dx%d", &width, &height) == 2)
if (sscanf(s.c_str(), "%dx%d", &width, &height) == 2)
{
// Reassemble the string in case that the original width or
// height contained a leading 0
std::ostringstream o;
o << width << "x" << height;
std::string res = o.str();
@ -595,14 +532,13 @@ int handleCmdLinePreliminary(int argc, char **argv)
UserConfigParams::m_width = width;
UserConfigParams::m_prev_height =
UserConfigParams::m_height = height;
Log::verbose("main", "You choose to use %dx%d.\n",
Log::verbose("main", "You choose to use %dx%d.",
(int)UserConfigParams::m_width,
(int)UserConfigParams::m_height );
}
else
Log::warn("main", "Resolution %s has been blacklisted, so "
"it is not available!\n", res.c_str());
i++;
"it is not available!", res.c_str());
}
else
{
@ -610,8 +546,28 @@ int handleCmdLinePreliminary(int argc, char **argv)
"given as WIDTHxHEIGHT");
}
}
else if (strcmp(argv[i], "--version") == 0 ||
strcmp(argv[i], "-v" ) == 0 )
//#if !defined(WIN32) && !defined(__CYGWIN)
if(CommandLine::has("--fullscreen") || CommandLine::has("-f"))
{
// Check that current res is not blacklisted
std::ostringstream o;
o << UserConfigParams::m_width << "x" << UserConfigParams::m_height;
std::string res = o.str();
if (std::find(UserConfigParams::m_blacklist_res.begin(),
UserConfigParams::m_blacklist_res.end(),res)
== UserConfigParams::m_blacklist_res.end())
UserConfigParams::m_fullscreen = true;
else
Log::warn("main", "Resolution %s has been blacklisted, so it "
"is not available!", res.c_str());
}
if(CommandLine::has("--windowed") || CommandLine::has("-w"))
UserConfigParams::m_fullscreen = false;
//#endif
if(CommandLine::has("--version") || CommandLine::has("-v"))
{
Log::info("main", "==============================");
Log::info("main", "SuperTuxKart, %s.", STK_VERSION ) ;
@ -619,78 +575,89 @@ int handleCmdLinePreliminary(int argc, char **argv)
Log::info("main", "SuperTuxKart, SVN revision number '%s'.",
SVNVERSION ) ;
#endif
// IRRLICHT_VERSION_SVN
Log::info("main", "Irrlicht version %i.%i.%i (%s)",
IRRLICHT_VERSION_MAJOR , IRRLICHT_VERSION_MINOR,
IRRLICHT_VERSION_REVISION, IRRLICHT_SDK_VERSION );
Log::info("main", "==============================");
} // --verbose or -v
}
int n;
if(CommandLine::has("--xmas", &n))
UserConfigParams::m_xmas_mode = n;
if(CommandLine::has("--log", &n))
Log::setLogLevel(n);
return 0;
} // handleCmdLinePreliminary
// ============================================================================
/** Handles command line options.
* \param argc Number of command line options
* \param argv Command line options.
*/
int handleCmdLine(int argc, char **argv)
int handleCmdLine()
{
// Some generic variables used in scanning:
int n;
char s[1024];
std::string s;
bool try_login = false;
irr::core::stringw login, password;
for(int i=1; i<argc; i++)
{
if(!strcmp(argv[i], "--gamepad-debug"))
{
if(CommandLine::has("--gamepad-debug"))
UserConfigParams::m_gamepad_debug=true;
}
else if (!strcmp(argv[i], "--wiimote-debug"))
{
if(CommandLine::has("--wiimote-debug"))
UserConfigParams::m_wiimote_debug = true;
}
else if (!strcmp(argv[i], "--tutorial-debug"))
{
if(CommandLine::has("--tutorial-debug"))
UserConfigParams::m_tutorial_debug = true;
}
else if(sscanf(argv[i], "--track-debug=%d",&n)==1)
{
if(CommandLine::has( "--track-debug",&n))
UserConfigParams::m_track_debug=n;
}
else if(!strcmp(argv[i], "--track-debug"))
{
if(CommandLine::has( "--track-debug"))
UserConfigParams::m_track_debug=1;
}
else if(!strcmp(argv[i], "--material-debug"))
{
if(CommandLine::has("--material-debug"))
UserConfigParams::m_material_debug = true;
}
else if(!strcmp(argv[i], "--ftl-debug"))
{
if(CommandLine::has("--ftl-debug"))
UserConfigParams::m_ftl_debug = true;
}
else if(UserConfigParams::m_artist_debug_mode &&
!strcmp(argv[i], "--camera-wheel-debug"))
if(CommandLine::has("--slipstream-debug"))
UserConfigParams::m_slipstream_debug=true;
if(CommandLine::has("--rendering-debug"))
UserConfigParams::m_rendering_debug=true;
if(CommandLine::has("--ai-debug"))
AIBaseController::enableDebug();
if(UserConfigParams::m_artist_debug_mode)
{
if(CommandLine::has("--camera-wheel-debug"))
UserConfigParams::m_camera_debug=2;
}
else if(UserConfigParams::m_artist_debug_mode &&
!strcmp(argv[i], "--camera-debug"))
{
if(CommandLine::has("--camera-debug"))
UserConfigParams::m_camera_debug=1;
}
else if(UserConfigParams::m_artist_debug_mode &&
!strcmp(argv[i], "--physics-debug"))
{
if(CommandLine::has("--physics-debug"))
UserConfigParams::m_physics_debug=1;
if(CommandLine::has("--check-debug"))
UserConfigParams::m_check_debug=true;
}
else if(!strcmp(argv[i], "--kartsize-debug"))
// Networking command lines
if(CommandLine::has("--server") )
{
NetworkManager::getInstance<ServerNetworkManager>();
Log::info("main", "Creating a server network manager.");
} // -server
if(CommandLine::has("--max-players", &n))
UserConfigParams::m_server_max_players=n;
if(CommandLine::has("--login", &s) )
{
login = s.c_str();
try_login = true;
} // --login
if(CommandLine::has("--password", &s))
password = s.c_str();
// Race parameters
if(CommandLine::has("--kartsize-debug"))
{
for(unsigned int i=0;
i<kart_properties_manager->getNumberOfKarts(); i++)
@ -706,175 +673,93 @@ int handleCmdLine(int argc, char **argv)
km->getMasterKartModel().getHeight(),
km->getMasterKartModel().getModel()
->getMeshBufferCount());
}
}
else if(UserConfigParams::m_artist_debug_mode &&
!strcmp(argv[i], "--check-debug"))
{
UserConfigParams::m_check_debug=true;
}
else if(!strcmp(argv[i], "--slipstream-debug"))
{
UserConfigParams::m_slipstream_debug=true;
}
else if(!strcmp(argv[i], "--rendering-debug"))
{
UserConfigParams::m_rendering_debug=true;
}
else if(!strcmp(argv[i], "--ai-debug"))
{
AIBaseController::enableDebug();
}
else if(sscanf(argv[i], "--port=%d",&n))
{
UserConfigParams::m_server_port = n;
}
else if( !strcmp(argv[i], "--server") )
{
NetworkManager::getInstance<ServerNetworkManager>();
Log::info("main", "Creating a server network manager.");
}
else if( sscanf(argv[i], "--max-players=%d", &n) )
{
UserConfigParams::m_server_max_players=n;
}
else if( sscanf(argv[i], "--login=%1023s", s) )
{
login = s;
try_login = true;
}
else if( sscanf(argv[i], "--password=%1023s", s) )
{
password = s;
}
else if ( sscanf(argv[i], "--gfx=%d", &n) )
{
if (n)
{
UserConfigParams::m_graphical_effects = true;
}
else
{
UserConfigParams::m_graphical_effects = false;
}
}
else if ( sscanf(argv[i], "--weather=%d", &n) )
{
if (n)
{
UserConfigParams::m_weather_effects = true;
}
else
{
UserConfigParams::m_weather_effects = false;
}
}
else if ( sscanf(argv[i], "--animations=%d", &n) )
{
UserConfigParams::m_show_steering_animations = n;
}
} // for i
} // --kartsize-debug
else if ( sscanf(argv[i], "--camera-style=%d", &n) )
{
UserConfigParams::m_camera_style = n;
}
else if( (!strcmp(argv[i], "--kart") && i+1<argc ))
if(CommandLine::has("--kart", &s))
{
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
if (!unlock_manager->getCurrentSlot()->isLocked(argv[i+1]))
if (!unlock_manager->getCurrentSlot()->isLocked(s))
{
const KartProperties *prop =
kart_properties_manager->getKart(argv[i+1]);
kart_properties_manager->getKart(s);
if(prop)
{
UserConfigParams::m_default_kart = argv[i+1];
UserConfigParams::m_default_kart = s;
// if a player was added with -N, change its kart.
// Otherwise, nothing to do, kart choice will be picked
// up upon player creation.
if (StateManager::get()->activePlayerCount() > 0)
{
race_manager->setLocalKartInfo(0, argv[i+1]);
race_manager->setLocalKartInfo(0, s);
}
Log::verbose("main", "You chose to use kart '%s'.",
argv[i+1] ) ;
i++;
s.c_str() ) ;
}
else
{
Log::warn("main", "Kart '%s' not found, ignored.",
argv[i+1]);
i++; // ignore the next parameter, otherwise STK will abort
s.c_str());
}
}
else // kart locked
{
Log::warn("main", "Kart '%s' has not been unlocked yet.",
argv[i+1]);
Log::warn("main",
"Use --list-karts to list available karts.");
s.c_str());
return 0;
} // if kart locked
}
else if( sscanf(argv[i], "--ai=%1023s", s)==1)
} // if --kart
if(CommandLine::has("--ai", &s))
{
const std::vector<std::string> l=
StringUtils::split(std::string(s),',');
const std::vector<std::string> l=StringUtils::split(std::string(s),',');
race_manager->setDefaultAIKartList(l);
// Add 1 for the player kart
race_manager->setNumKarts(l.size()+1);
}
else if( (!strcmp(argv[i], "--mode") && i+1<argc ))
} // --ai
if(CommandLine::has( "--mode", &s))
{
int n = atoi(argv[i+1]);
int n = atoi(s.c_str());
if(n<0 || n>RaceManager::DIFFICULTY_LAST)
Log::warn("main", "Invalid difficulty '%s' - ignored.\n",
argv[i+1]);
s.c_str());
else
race_manager->setDifficulty(RaceManager::Difficulty(n));
i++;
}
else if( (!strcmp(argv[i], "--type") && i+1<argc ))
} // --mode
if(CommandLine::has("--type", &n))
{
switch (atoi(argv[i+1]))
switch (n)
{
case 0: race_manager
->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
case 0: race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
break;
case 1: race_manager
->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
case 1: race_manager->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
break;
case 2: race_manager
->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER);
case 2: race_manager->setMinorMode(RaceManager::MINOR_MODE_FOLLOW_LEADER);
break;
default:
Log::warn("main", "Invalid race type '%d' - ignored.",
atoi(argv[i+1]));
Log::warn("main", "Invalid race type '%d' - ignored.", n);
}
i++;
}
else if( !strcmp(argv[i], "--reverse"))
{
race_manager->setReverseTrack(true);
}
else if( (!strcmp(argv[i], "--track") || !strcmp(argv[i], "-t"))
&& i+1<argc )
} // --type
if(CommandLine::has("--track", &s) || CommandLine::has("-t", &s))
{
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
if (!unlock_manager->getCurrentSlot()->isLocked(argv[i+1]))
if (!unlock_manager->getCurrentSlot()->isLocked(s))
{
race_manager->setTrack(argv[i+1]);
race_manager->setTrack(s);
Log::verbose("main", "You choose to start in track '%s'.",
argv[i+1] );
s.c_str());
Track* t = track_manager->getTrack(argv[i+1]);
if (t == NULL)
Track* t = track_manager->getTrack(s);
if (!t)
{
Log::warn("main", "Can't find track named '%s'.",
argv[i+1]);
Log::warn("main", "Can't find track named '%s'.", s.c_str());
}
else if (t->isArena())
{
@ -898,121 +783,68 @@ int handleCmdLine(int argc, char **argv)
else
{
Log::warn("main", "Track '%s' has not been unlocked yet.",
argv[i+1]);
Log::warn("main", "Use --list-tracks to list available "
"tracks.");
s.c_str());
return 0;
}
i++;
}
else if( (!strcmp(argv[i], "--gp")) && i+1<argc)
} // --track
if(CommandLine::has("--gp", &s))
{
race_manager->setMajorMode(RaceManager::MAJOR_MODE_GRAND_PRIX);
const GrandPrixData *gp =
grand_prix_manager->getGrandPrix(argv[i+1]);
const GrandPrixData *gp = grand_prix_manager->getGrandPrix(s);
if (gp == NULL)
if (!gp)
{
Log::warn("main", "There is no GP named '%s'.", argv[i+1]);
Log::warn("main", "There is no GP named '%s'.", s.c_str());
return 0;
}
race_manager->setGrandPrix(*gp);
i++;
}
else if( (!strcmp(argv[i], "--numkarts") || !strcmp(argv[i], "-k")) &&
i+1<argc )
} // --gp
if(CommandLine::has("--numkarts", &n) ||CommandLine::has("-k", &n))
{
UserConfigParams::m_num_karts = atoi(argv[i+1]);
UserConfigParams::m_num_karts = n;
if(UserConfigParams::m_num_karts > stk_config->m_max_karts)
{
Log::warn("main",
"Number of karts reset to maximum number %d.",
Log::warn("main", "Number of karts reset to maximum number %d.",
stk_config->m_max_karts);
UserConfigParams::m_num_karts = stk_config->m_max_karts;
}
race_manager->setNumKarts( UserConfigParams::m_num_karts );
Log::verbose("main", "%d karts will be used.",
(int)UserConfigParams::m_num_karts);
i++;
}
else if( !strcmp(argv[i], "--list-tracks") || !strcmp(argv[i], "-l") )
{
} // --numkarts
Log::info("main", " Available tracks:" );
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
for (size_t i = 0; i != track_manager->getNumberOfTracks(); i++)
{
const Track *track = track_manager->getTrack(i);
const char * locked = "";
if ( unlock_manager->getCurrentSlot()
->isLocked(track->getIdent()) )
{
locked = " (locked)";
}
Log::info("main", "%-18s: %ls %s",
track->getIdent().c_str(),
track->getName(), locked);
//}
}
Log::info("main", "Use --track N to choose track.");
exit(0);
}
else if( !strcmp(argv[i], "--list-karts") )
{
Log::info("main", " Available karts:");
for (unsigned int i = 0;
i < kart_properties_manager->getNumberOfKarts(); i++)
{
const KartProperties* KP =
kart_properties_manager->getKartById(i);
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
const char * locked = "";
if (unlock_manager->getCurrentSlot()->isLocked(KP->getIdent()))
locked = "(locked)";
Log::info("main", " %-10s: %ls %s", KP->getIdent().c_str(),
KP->getName(), locked);
}
exit(0);
}
else if ( !strcmp(argv[i], "--no-start-screen")
|| !strcmp(argv[i], "-N") )
{
if(CommandLine::has( "--no-start-screen") ||
CommandLine::has("-N") )
UserConfigParams::m_no_start_screen = true;
}
else if ( !strcmp(argv[i], "--race-now")
|| !strcmp(argv[i], "-R") )
if(CommandLine::has("--race-now") || CommandLine::has("-R"))
{
UserConfigParams::m_no_start_screen = true;
UserConfigParams::m_race_now = true;
}
else if ( !strcmp(argv[i], "--laps") && i+1<argc )
} // --race-now
if(CommandLine::has("--laps", &s))
{
int laps = atoi(argv[i+1]);
int laps = atoi(s.c_str());
if (laps < 0)
{
Log::error("main", "Invalid number of laps: %s.\n", argv[i+1] );
Log::error("main", "Invalid number of laps: %s.\n", s.c_str());
return 0;
}
else
{
Log::verbose("main", "You choose to have %d laps.", laps);
race_manager->setNumLaps(laps);
i++;
}
}
else if( sscanf(argv[i], "--profile-laps=%d", &n)==1)
} // --laps
if(CommandLine::has("--profile-laps=", &n))
{
if (n < 0)
{
Log::error("main", "Invalid number of profile-laps: %i.\n", n );
Log::error("main", "Invalid number of profile-laps: %i.", n );
return 0;
}
else
@ -1022,18 +854,17 @@ int handleCmdLine(int argc, char **argv)
ProfileWorld::setProfileModeLaps(n);
race_manager->setNumLaps(n);
}
}
else if( sscanf(argv[i], "--profile-time=%d", &n)==1)
} // --profile-laps
if(CommandLine::has("--profile-time", &n))
{
Log::verbose("main", "Profiling: %d seconds.", n);
UserConfigParams::m_no_start_screen = true;
ProfileWorld::setProfileModeTime((float)n);
race_manager->setNumLaps(999999); // profile end depends on time
}
else if( !strcmp(argv[i], "--no-graphics") )
{
}
else if( !strcmp(argv[i], "--with-profile") )
} // --profile-time
if(CommandLine::has("--with-profile") )
{
// Set default profile mode of 1 lap if we haven't already set one
if (!ProfileWorld::isProfileMode()) {
@ -1041,105 +872,72 @@ int handleCmdLine(int argc, char **argv)
ProfileWorld::setProfileModeLaps(1);
race_manager->setNumLaps(1);
}
}
else if( !strcmp(argv[i], "--ghost"))
{
} // --with-profile
if(CommandLine::has("--ghost"))
ReplayPlay::create();
}
else if( sscanf(argv[i], "--history=%d", &n)==1)
if(CommandLine::has("--history", &n))
{
history->doReplayHistory( (History::HistoryReplayMode)n);
// Force the no-start screen flag, since this initialises
// the player structures correctly.
UserConfigParams::m_no_start_screen = true;
} // --history=%d
}
else if( !strcmp(argv[i], "--history") )
if(CommandLine::has("--history")) // handy default for --history=1
{
history->doReplayHistory(History::HISTORY_POSITION);
// Force the no-start screen flag, since this initialises
// the player structures correctly.
UserConfigParams::m_no_start_screen = true;
} // --history
}
else if( !strcmp(argv[i], "--demo-mode") && i+1<argc)
// Demo mode
if(CommandLine::has("--demo-mode", &s))
{
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
float t;
StringUtils::fromString(argv[i+1], t);
StringUtils::fromString(s, t);
DemoWorld::enableDemoMode(t);
// The default number of laps is taken from ProfileWorld and
// is 0. So set a more useful default for demo mode.
DemoWorld::setNumLaps(2);
i++;
}
else if( !strcmp(argv[i], "--demo-laps") && i+1<argc)
} // --demo-mode
if(CommandLine::has("--demo-laps", &n))
{
// Note that we use a separate setting for demo mode to avoid the
// problem that someone plays a game, and in further demos then
// the wrong (i.e. last selected) number of laps would be used
DemoWorld::setNumLaps(atoi(argv[i+1]));
i++;
}
else if( !strcmp(argv[i], "--demo-karts") && i+1<argc)
DemoWorld::setNumLaps(n);
} // --demo-laps
if(CommandLine::has("--demo-karts", &n))
{
// Note that we use a separate setting for demo mode to avoid the
// problem that someone plays a game, and in further demos then
// the wrong (i.e. last selected) number of karts would be used
DemoWorld::setNumKarts(atoi(argv[i+1]));
i++;
}
else if( !strcmp(argv[i], "--demo-tracks") && i+1<argc)
{
DemoWorld::setTracks(StringUtils::split(std::string(argv[i+1]),
','));
i++;
}
DemoWorld::setNumKarts(n);
} // --demo-karts
if(CommandLine::has("--demo-tracks", &s))
DemoWorld::setTracks(StringUtils::split(s,','));
#ifdef ENABLE_WIIUSE
else if( !strcmp(argv[i], "--wii"))
{
if(CommandLine::has("--wii"))
WiimoteManager::enable();
}
#endif
// 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], "--stk-config")&& i+1<argc ) { i++; }
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], "--debug=memory" ) ) {}
else if( !strcmp(argv[i], "--debug=addons" ) ) {}
else if( !strcmp(argv[i], "--debug=gui" ) ) {}
else if( !strcmp(argv[i], "--debug=flyable") ) {}
else if( !strcmp(argv[i], "--debug=misc" ) ) {}
else if( !strcmp(argv[i], "--debug=all" ) ) {}
else if ( sscanf(argv[i], "--xmas=%d", &n) ) {}
else if( !strcmp(argv[i], "--log=nocolor" ) ) {}
else if( sscanf(argv[i], "--log=%d",&n )==1 ) {}
else if( !strcmp(argv[i], "--no-console" ) ) {}
else if( !strcmp(argv[i], "--console" ) ) {}
else if( !strcmp(argv[i], "--screensize") ||
!strcmp(argv[i], "-s") ) {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], "--version") || !strcmp(argv[i], "-v")) {}
#ifdef __APPLE__
// on OS X, sometimes the Finder will pass a -psn* something parameter
// to the application
else if( strncmp(argv[i], "-psn", 3) == 0) {}
// to the application --> ignore it
CommandLine::has("-psn");
#endif
else
{
// invalid param needs to go to console
UserConfigParams::m_log_errors_to_console = true;
Log::error("main", "Invalid parameter: %s.\n", argv[i] );
cmdLineHelp(argv[0]);
cleanSuperTuxKart();
return 0;
}
} // for i <argc
CommandLine::reportInvalidParameters();
if(UserConfigParams::m_no_start_screen)
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
@ -1169,10 +967,10 @@ int handleCmdLine(int argc, char **argv)
//=============================================================================
/** Initialises the minimum number of managers to get access to user_config.
*/
void initUserConfig(char *argv[])
void initUserConfig()
{
irr_driver = new IrrDriver();
file_manager = new FileManager(argv);
file_manager = new FileManager();
user_config = new UserConfig(); // needs file_manager
const bool config_ok = user_config->loadConfig();
if (UserConfigParams::m_language.toString() != "system")
@ -1349,32 +1147,33 @@ bool ShowDumpResults(const wchar_t* dump_path,
#pragma comment(linker, "/SUBSYSTEM:console")
#endif
// ----------------------------------------------------------------------------
int main(int argc, char *argv[] )
{
#ifdef BREAKPAD
google_breakpad::ExceptionHandler eh(L"C:\\Temp", NULL, ShowDumpResults,
NULL, google_breakpad::ExceptionHandler::HANDLER_ALL);
#endif
CommandLine::init(argc, argv);
CrashReporting::installHandlers();
srand(( unsigned ) time( 0 ));
try {
// Check for "--root COLON:SEPARATED:LIST" parameter
for(int i=0; i<argc-1; i++)
try
{
if(!strcmp(argv[i],"--root"))
std::string s;
if(CommandLine::has("--root", &s))
{
FileManager::addRootDirs(argv[i+1]);
}
FileManager::addRootDirs(s);
}
// 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(argv); // argv passed so config file can be
// found more reliably
initUserConfig();
handleCmdLinePreliminary(argc, argv);
handleCmdLinePreliminary();
initRest();
@ -1432,7 +1231,7 @@ int main(int argc, char *argv[] )
"banana.png") );
//handleCmdLine() needs InitTuxkart() so it can't be called first
if(!handleCmdLine(argc, argv)) exit(0);
if(!handleCmdLine()) exit(0);
// load the network manager
// If the server has been created (--server option), this will do nothing (just a warning):

View File

@ -20,6 +20,7 @@
#include "audio/music_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/user_config.hpp"
#include "graphics/camera.hpp"
#include "items/powerup_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "states_screens/race_gui_base.hpp"

View File

@ -23,6 +23,7 @@
#include <IMeshSceneNode.h>
#include "audio/music_manager.hpp"
#include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"

View File

@ -21,6 +21,7 @@
#include "states_screens/race_gui_base.hpp"
#include "audio/music_manager.hpp"
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"

View File

@ -20,6 +20,7 @@
#include <algorithm>
#include "io/xml_node.hpp"
#include "karts/abstract_kart.hpp"
#include "modes/linear_world.hpp"
#include "modes/world.hpp"

View File

@ -1635,6 +1635,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
if (!irr_driver->isGLSL())
{
scene::ILightSceneNode *sun = (scene::ILightSceneNode *) m_sun;
sun->setLightType(video::ELT_DIRECTIONAL);
// The angle of the light is rather important - let the sun

View File

@ -0,0 +1,67 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2008-2013 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "utils/command_line.hpp"
#include "config/user_config.hpp"
#include "utils/log.hpp"
std::vector<std::string> CommandLine::m_argv;
std::string CommandLine::m_exec_name="";
/** The constructor takes the standard C arguments argc and argv and
* stores the information internally.
* \param argc Number of arguments (in argv).
* \param argv Array of char* with all command line arguments.
*/
void CommandLine::init(unsigned int argc, char *argv[])
{
m_exec_name = argv[0];
for(unsigned int i=1; i<argc; i++)
m_argv.push_back(argv[i]);
} // CommandLine
// ----------------------------------------------------------------------------
bool CommandLine::has(const std::string &option)
{
std::vector<std::string>::iterator i;
for(i=m_argv.begin(); i!=m_argv.end(); i++)
{
if(*i==option)
{
m_argv.erase(i);
return true;
}
} // for i in m_argv
return false;
} // has
// ----------------------------------------------------------------------------
/** Reports any parameters that have not been handled yet to be an error.
*/
void CommandLine::reportInvalidParameters()
{
for(unsigned int i=0; i<m_argv.size(); i++)
{
// invalid param needs to go to console
UserConfigParams::m_log_errors_to_console = true;
Log::error("CommandLine", "Invalid parameter: %s.", m_argv[i].c_str() );
}
} // reportInvalidParameters

121
src/utils/command_line.hpp Normal file
View File

@ -0,0 +1,121 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2011-2013 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_COMMAND_LINE_HPP
#define HEADER_COMMAND_LINE_HPP
#include "utils/string_utils.hpp"
#include <string>
#include <vector>
/** A small class to manage the 'argv' parameters of a program. That includes
* the name of the executable (argv[0]) and all command line parameters.
* Example usage
* \code
* CommandLine::init(argc, argv);
* if( CommandLine::has("--help") ||
* CommandLine::has("-h") ) ...
* int n;
* if(CommandLine::has("--log", &n))
* Log::setLogLevel(n);
* ...
* CommandLine::reportInvalidParameters();
* \endcode
* The two 'has' functions will remove a parameter from the list of all
* parameters, so any parameters remaining at the end are invalid
* parameters, which will be listed by reportInvalidParameters.
*/
class CommandLine
{
private:
/** The array with all command line options. */
static std::vector<std::string> m_argv;
/** Name of the executable. */
static std::string m_exec_name;
// ------------------------------------------------------------------------
/** Searches for an option 'option=XX'. If found, *t will contain 'XX'.
* If the value was found, the entry is removed from the list of all
* command line arguments.
* \param option The option (must include '-' or '--' as required).
* \param t Address of a variable to store the value.
* \param format The '%' format to sscanf the value in t with.
* \return true if the value was found, false otherwise.
*/
static bool has(const std::string &option, void *t, const char* const format)
{
if(m_argv.size()==0) return false;
std::string equal=option+"="+format;
std::vector<std::string>::iterator i;
for(i=m_argv.begin(); i<m_argv.end(); i++)
{
if(sscanf(i->c_str(), equal.c_str(), t)==1)
{
m_argv.erase(i);
return true;
}
}
return false;
} // has
public:
static void init(unsigned int argc, char *argv[]);
static void reportInvalidParameters();
static bool has(const std::string &option);
// ------------------------------------------------------------------------
/** Searches for an option 'option=XX'. If found, *t will contain 'XX'.
* If the value was found, the entry is removed from the list of all
* command line arguments. This is the interface for any integer
* values (i.e. using %d as format while scanning).
* \param option The option (must include '-' or '--' as required).
* \param t Address of a variable to store the value.
* \param format The '%' format to sscanf the value in t with.
* \return true if the value was found, false otherwise.
*/
static bool has(const std::string &option, int *t)
{
return has(option, t, "%d");
}
// ------------------------------------------------------------------------
/** Searches for an option 'option=XX'. If found, *t will contain 'XX'.
* If the value was found, the entry is removed from the list of all
* command line arguments. This is the interface for a std::string
* \param option The option (must include '-' or '--' as required).
* \param t Address of a variable to store the value.
* \param format The '%' format to sscanf the value in t with.
* \return true if the value was found, false otherwise.
*/
static bool has(const std::string &option, std::string *t)
{
char s[1024];
if(has(option, s, "%1023s"))
{
*t = s;
return true;
}
return false;
} // has<std::string>
// ------------------------------------------------------------------------
/** Returns the name of the executable. */
static const std::string& getExecName() { return m_exec_name; }
}; // CommandLine
#endif