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:
parent
068eb8ece2
commit
6ee751e3c3
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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",
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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; }
|
||||
};
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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 )
|
||||
|
@ -96,7 +96,7 @@ private:
|
||||
#endif
|
||||
|
||||
public:
|
||||
FileManager(char *argv[]);
|
||||
FileManager();
|
||||
~FileManager();
|
||||
void reInit();
|
||||
void dropFileSystem();
|
||||
|
@ -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"
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "karts/controller/controller.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class Camera;
|
||||
class Player;
|
||||
class SFXBase;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
1145
src/main.cpp
1145
src/main.cpp
File diff suppressed because it is too large
Load Diff
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
67
src/utils/command_line.cpp
Normal file
67
src/utils/command_line.cpp
Normal 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
121
src/utils/command_line.hpp
Normal 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
|
Loading…
Reference in New Issue
Block a user