1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-10-06 09:07:19 +02:00

Use Boost to parse command line arguments (#177)

There are still some rough edges, first version to send in for
discussion.
This commit is contained in:
Sven Stucki 2016-09-01 19:04:21 +02:00
parent 243c3d7c4c
commit 431e218a64
3 changed files with 61 additions and 37 deletions

View File

@ -11,6 +11,7 @@ addons:
- libsndfile-dev
- libopenal-dev
- libboost-filesystem-dev
- libboost-program-options-dev
# Dependencies for BUILD_TESTS
- libboost-test-dev
# Dependencies for BUILD_VIEWER

View File

@ -1,4 +1,4 @@
find_package(Boost REQUIRED)
find_package(Boost COMPONENTS program_options REQUIRED)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GitSHA1.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp" @ONLY)
@ -45,6 +45,7 @@ include_directories(
target_link_libraries(rwgame
rwengine
inih
${Boost_LIBRARIES}
${OPENGL_LIBRARIES}
${BULLET_LIBRARIES}
${SDL2_LIBRARY}

View File

@ -24,6 +24,7 @@
#include <objects/VehicleObject.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/program_options.hpp>
#include <functional>
#include "GitSHA1.h"
@ -49,39 +50,60 @@ RWGame::RWGame(int argc, char* argv[])
bool fullscreen = false;
bool newgame = false;
bool test = false;
std::string startSave;
std::string startSave;
std::string benchFile;
for( int i = 1; i < argc; ++i )
// Define and parse command line options
namespace po = boost::program_options;
po::options_description desc("Available options");
desc.add_options()
("help", "Show this help message")
("width,w", po::value<size_t>(), "Game resolution width in pixel")
("height,h", po::value<size_t>(), "Game resolution height in pixel")
("fullscreen,f", "Enable fullscreen mode")
("newgame,n", "Directly start a new game")
("test,t", "To be used with -n, starts in a test location instead")
("load,l", po::value<std::string>(), "Load save file")
("benchmark,b", po::value<std::string>(), "Run benchmark and store results in file")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if( vm.count("help") )
{
if( boost::iequals( "-w", argv[i] ) && i+1 < argc )
{
w = std::atoi(argv[i+1]);
}
if( boost::iequals( "-h", argv[i] ) && i+1 < argc )
{
h = std::atoi(argv[i+1]);
}
if( boost::iequals( "-f", argv[i] ))
{
fullscreen = true;
}
if( strcmp( "--newgame", argv[i] ) == 0 )
{
newgame = true;
}
if( strcmp( "--test", argv[i] ) == 0 )
{
test = true;
}
if( strcmp( "--load", argv[i] ) == 0 && i+1 < argc )
{
startSave = argv[i+1];
}
if( strcmp( "--benchmark", argv[i]) == 0 && i+1 < argc )
{
benchFile = argv[i+1];
}
// TODO: This is a hack
std::cout << desc << std::endl;
throw std::runtime_error("Terminate");
}
if( vm.count("width") )
{
w = vm["width"].as<size_t>();
}
if( vm.count("height") )
{
h = vm["height"].as<size_t>();
}
if( vm.count("fullscreen") )
{
fullscreen = true;
}
if( vm.count("newgame") )
{
newgame = true;
}
if( vm.count("test") )
{
test = true;
}
if( vm.count("load") )
{
startSave = vm["load"].as<std::string>();
}
if( vm.count("benchmark") )
{
benchFile = vm["benchmark"].as<std::string>();
}
if (SDL_Init(SDL_INIT_VIDEO) < 0)
@ -151,10 +173,10 @@ RWGame::RWGame(int argc, char* argv[])
loading->setNextState(new IngameState(this,true));
}
}
else if( ! startSave.empty() )
{
loading->setNextState(new IngameState(this,true, startSave));
}
else if( ! startSave.empty() )
{
loading->setNextState(new IngameState(this,true, startSave));
}
else
{
loading->setNextState(new MenuState(this));
@ -231,7 +253,7 @@ void RWGame::loadGame(const std::string& savename)
delete state->script;
state = nullptr;
log.info("Game", "Loading game " + savename);
log.info("Game", "Loading game " + savename);
newGame();
@ -642,7 +664,7 @@ void RWGame::render(float alpha, float time)
cutscene->tracks.duration);
cutsceneTime += GAME_TIMESTEP * alpha;
glm::vec3 cameraPos = cutscene->tracks.getPositionAt(cutsceneTime),
targetPos = cutscene->tracks.getTargetAt(cutsceneTime);
targetPos = cutscene->tracks.getTargetAt(cutsceneTime);
float zoom = cutscene->tracks.getZoomAt(cutsceneTime);
viewCam.frustum.fov = glm::radians(zoom);
float tilt = cutscene->tracks.getRotationAt(cutsceneTime);