Author: zaroth
Date: Thu Jun 9 11:52:47 2011
New Revision: 49810
URL: http://svn.gna.org/viewcvs/wesnoth?rev=49810&view=rev
Log:
Added --screenshot and --log to commandline_options. This makes game.cpp
completely migrated to using of the new class.
Modified:
trunk/src/commandline_options.cpp
trunk/src/commandline_options.hpp
trunk/src/game.cpp
trunk/src/game_controller.cpp
trunk/src/tests/test_commandline_options.cpp
Modified: trunk/src/commandline_options.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/commandline_options.cpp?rev=49810&r1=49809&r2=49810&view=diff
==============================================================================
--- trunk/src/commandline_options.cpp (original)
+++ trunk/src/commandline_options.cpp Thu Jun 9 11:52:47 2011
@@ -17,6 +17,7 @@
#include "foreach.hpp"
#include "serialization/string_utils.hpp"
#include "util.hpp"
+#include "lua/llimits.h"
namespace po = boost::program_options;
@@ -115,12 +116,12 @@
("gunzip", po::value<std::string>(), "decompresses a file
(<arg>.gz) in gzip format and stores it without the .gz suffix. <arg>.gz will
be removed.")
("gzip", po::value<std::string>(), "compresses a file (<arg>)
in gzip format, stores it as <arg>.gz and removes <arg>.")
("help,h", "prints this message and exits.")
- ("load,l", po::value<std::string>(), "loads the save <arg> from
the standard save game directory.\nWhen launching the map editor via -e, the
map <arg> is loaded, relative to the current directory. If it is a directory,
the editor will start with a load map dialog opened there.")
- ("logdomains",
po::value<std::string>()->implicit_value(std::string()), "lists defined log
domains (only the ones containing <arg> filter if provided) and exits.")
+ ("load,l", po::value<std::string>(), "loads the save <arg> from
the standard save game directory. When launching the map editor via -e, the map
<arg> is loaded, relative to the current directory. If it is a directory, the
editor will start with a load map dialog opened there.")
("new-syntax", "enables the new campaign syntax parsing.")
("nocache", "disables caching of game data.")
("path", "prints the path to the data directory and exits.")
("rng-seed", po::value<unsigned int>(), "seeds the random
number generator with number <arg>. Example: --rng-seed 0")
+ ("screenshot", po::value<two_strings>()->multitoken(), "takes
two arguments: <map> <output>. Saves a screenshot of <map> to <output> without
initializing a screen. Editor must be compiled in for this to work.")
("validcache", "assumes that the cache is valid. (dangerous)")
("version,v", "prints the game's version number and exits.")
("with-replay", "replays the file loaded with the --load
option.")
@@ -130,6 +131,15 @@
("bpp", po::value<int>(), "sets BitsPerPixel value. Example:
--bpp 32")
("fps", "displays the number of frames per second the game is
currently running at, in a corner of the screen.")
("max-fps", po::value<int>(), "the maximum fps the game tries
to run at. Values should be between 1 and 1000, the default is 50.")
+ ;
+
+ po::options_description logging_opts("Logging options");
+ logging_opts.add_options()
+ ("logdomains",
po::value<std::string>()->implicit_value(std::string()), "lists defined log
domains (only the ones containing <arg> filter if such is provided) and exits.")
+ ("log-error", po::value<std::string>(), "sets the severity
level of the specified log domain(s) to 'error'. <arg> should be given as comma
separated list of domains, wildcards are allowed. Example:
--log-error=network,gui/*,engine/enemies")
+ ("log-warning", po::value<std::string>(), "sets the severity
level of the specified log domain(s) to 'warning'. Similar to --log-error.")
+ ("log-info", po::value<std::string>(), "sets the severity level
of the specified log domain(s) to 'info'. Similar to --log-error.")
+ ("log-debug", po::value<std::string>(), "sets the severity
level of the specified log domain(s) to 'debug'. Similar to --log-error.")
;
po::options_description multiplayer_opts("Multiplayer options");
@@ -150,7 +160,7 @@
("new-storyscreens", "")
("new-widgets", "")
;
-
visible_.add(general_opts).add(display_opts).add(multiplayer_opts).add(preprocessor_opts);
+
visible_.add(general_opts).add(display_opts).add(logging_opts).add(multiplayer_opts).add(preprocessor_opts);
all_.add(visible_).add(hidden_);
@@ -180,6 +190,14 @@
help = true;
if (vm.count("load"))
load = vm["load"].as<std::string>();
+ if (vm.count("log-error"))
+ parse_log_domains_(vm["log-error"].as<std::string>(),0);
+ if (vm.count("log-warning"))
+ parse_log_domains_(vm["log-warning"].as<std::string>(),1);
+ if (vm.count("log-info"))
+ parse_log_domains_(vm["log-info"].as<std::string>(),2);
+ if (vm.count("log-debug"))
+ parse_log_domains_(vm["log-debug"].as<std::string>(),3);
if (vm.count("logdomains"))
logdomains = vm["logdomains"].as<std::string>();
if (vm.count("max-fps"))
@@ -210,6 +228,12 @@
preprocess_output_macros =
vm["preprocess-output-macros"].as<std::string>();
if (vm.count("rng-seed"))
rng_seed = vm["rng-seed"].as<unsigned int>();
+ if (vm.count("screenshot"))
+ {
+ screenshot = true;
+ screenshot_map_file =
vm["screenshot"].as<two_strings>().get<0>();
+ screenshot_output_file =
vm["screenshot"].as<two_strings>().get<1>();
+ }
if (vm.count("validcache"))
validcache = true;
if (vm.count("version"))
@@ -237,6 +261,17 @@
return vec;
}
+void commandline_options::parse_log_domains_(const std::string
&domains_string, const int severity)
+{
+ const std::vector<std::string> domains = utils::split(domains_string,
',');
+ foreach (const std::string& domain, domains)
+ {
+ if (!log)
+ log = std::vector<boost::tuple<int, std::string> >();
+ log->push_back(boost::tuple<int, std::string>(severity,domain));
+ }
+}
+
std::ostream& operator<<(std::ostream &os, const commandline_options&
cmdline_opts)
{
os << "Usage: " << cmdline_opts.argv_[0] << " [<options>]
[<data-directory>]\n";
Modified: trunk/src/commandline_options.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/commandline_options.hpp?rev=49810&r1=49809&r2=49810&view=diff
==============================================================================
--- trunk/src/commandline_options.hpp (original)
+++ trunk/src/commandline_options.hpp Thu Jun 9 11:52:47 2011
@@ -159,6 +159,7 @@
/// True if --with-replay was given on the command line. Shows replay
of the loaded file.
bool with_replay;
private:
+ void parse_log_domains_(const std::string &domains_string, const int
severity);
std::vector<boost::tuple<int,std::string> >
parse_to_int_string_tuples_(const std::vector<std::string> &strings);
int argc_;
char **argv_;
Modified: trunk/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=49810&r1=49809&r2=49810&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Thu Jun 9 11:52:47 2011
@@ -162,9 +162,7 @@
};
/** Process commandline-arguments */
-static int process_command_args(int argc, char** argv, const
commandline_options& cmdline_opts) {
- const std::string program = argv[0];
- game_config::wesnoth_program_dir = directory_name(program);
+static int process_command_args(const commandline_options& cmdline_opts) {
preprocess_options preproc;
// Options that don't change behaviour based on any others should be
checked alphabetically below.
@@ -214,6 +212,18 @@
std::cout << cmdline_opts;
return 0;
}
+ if(cmdline_opts.log) {
+ for(std::vector<boost::tuple<int, std::string>
>::const_iterator it=cmdline_opts.log->begin(); it!=cmdline_opts.log->end();
++it)
+ {
+ const std::string log_domain = it->get<1>();
+ const int severity = it->get<0>();
+ if (!lg::set_log_domain_severity(log_domain, severity))
+ {
+ std::cerr << "unknown log domain: " <<
log_domain << '\n';
+ return 2;
+ }
+ }
+ }
if(cmdline_opts.logdomains) {
std::cout << lg::list_logdomains(*cmdline_opts.logdomains);
return 0;
@@ -257,6 +267,10 @@
}
if(cmdline_opts.rng_seed) {
srand(*cmdline_opts.rng_seed);
+ }
+ if(cmdline_opts.screenshot) {
+ static char opt[] = "SDL_VIDEODRIVER=dummy";
+ SDL_putenv(opt);
}
if(cmdline_opts.version) {
std::cout << "Battle for Wesnoth" << " " <<
game_config::version << "\n";
@@ -355,47 +369,6 @@
std::cerr << "preprocessing finished. Took "<< SDL_GetTicks() -
startTime << " ticks.\n";
return 0;
- }
-
- //parse arguments that shouldn't require a display device
- int arg;
- for(arg = 1; arg != argc; ++arg) {
- const std::string val(argv[arg]);
- if(val.empty()) {
- continue;
- } else if (val == "--screenshot" ) {
- if(!(argc > arg + 2)) {
- std::cerr << "format of " << val << " command:
" << val << " <map file> <output file>\n";
- return 2;
- }
- static char opt[] = "SDL_VIDEODRIVER=dummy";
- SDL_putenv(opt);
- } else if (val.substr(0, 6) == "--log-") {
- size_t p = val.find('=');
- if (p == std::string::npos) {
- std::cerr << "unknown option: " << val << '\n';
- return 2;
- }
- std::string s = val.substr(6, p - 6);
- int severity;
- if (s == "error") severity = 0;
- else if (s == "warning") severity = 1;
- else if (s == "info") severity = 2;
- else if (s == "debug") severity = 3;
- else {
- std::cerr << "unknown debug level: " << s <<
'\n';
- return 2;
- }
- while (p != std::string::npos) {
- size_t q = val.find(',', p + 1);
- s = val.substr(p + 1, q == std::string::npos ?
q : q - (p + 1));
- if (!lg::set_log_domain_severity(s, severity)) {
- std::cerr << "unknown debug domain: "
<< s << '\n';
- return 2;
- }
- p = q;
- }
- }
}
// Not the most intuitive solution, but I wanted to leave current
semantics for now
@@ -432,7 +405,8 @@
srand(time(NULL));
commandline_options cmdline_opts = commandline_options(argc,argv);
- int finished = process_command_args(argc, argv,cmdline_opts);
+ game_config::wesnoth_program_dir = directory_name(argv[0]);
+ int finished = process_command_args(cmdline_opts);
if(finished != -1) {
return finished;
}
Modified: trunk/src/game_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_controller.cpp?rev=49810&r1=49809&r2=49810&view=diff
==============================================================================
--- trunk/src/game_controller.cpp (original)
+++ trunk/src/game_controller.cpp Thu Jun 9 11:52:47 2011
@@ -156,6 +156,15 @@
gui2::new_widgets = true;
if (cmdline_opts_.nocache)
cache_.set_use_cache(false);
+ if (cmdline_opts_.screenshot) {
+ //TODO it could be simplified to use cmdline_opts_ directly if
there is no other way to enter screenshot mode
+ screenshot_map_ = *cmdline_opts_.screenshot_map_file;
+ screenshot_filename_ = *cmdline_opts_.screenshot_output_file;
+ no_sound = true;
+ screenshot_mode_ = true;
+ preferences::disable_preferences_save();
+ force_bpp_ = 32;
+ }
if (cmdline_opts_.validcache)
cache_.set_force_valid_cache(true);
if (cmdline_opts_.with_replay)
@@ -184,18 +193,6 @@
no_gui_ = true;
no_sound = true;
preferences::disable_preferences_save();
- }
- else if(val == "--screenshot") {
- if(arg_+2 != argc_) {
- ++arg_;
- screenshot_map_ = argv_[arg_];
- ++arg_;
- screenshot_filename_ = argv_[arg_];
- no_sound = true;
- screenshot_mode_ = true;
- preferences::disable_preferences_save();
- force_bpp_ = 32;
- }
}
else if(val == "--smallgui") {
game_config::small_gui = true;
Modified: trunk/src/tests/test_commandline_options.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/test_commandline_options.cpp?rev=49810&r1=49809&r2=49810&view=diff
==============================================================================
--- trunk/src/tests/test_commandline_options.cpp (original)
+++ trunk/src/tests/test_commandline_options.cpp Thu Jun 9 11:52:47 2011
@@ -187,6 +187,10 @@
"--gzip=gzipfoo",
"--help",
"--load=loadfoo",
+ "--log-error=errfoo,errbar/*",
+ "--log-warning=warnfoo,warnfoo/bar",
+ "--log-info=infofoo",
+ "--log-debug=dbgfoo,dbgbar,dbg/foo/bar/baz",
"--logdomains=filterfoo",
"--max-fps=100",
"--multiplayer",
@@ -200,6 +204,7 @@
"--preprocess-input-macros=inmfoo",
"--preprocess-output-macros=outmfoo",
"--rng-seed=1234",
+ "--screenshot", "mapfoo", "outssfoo",
"--validcache",
"--version",
"--with-replay"
@@ -226,7 +231,16 @@
BOOST_CHECK(co.gunzip && *co.gunzip == "gunzipfoo.gz");
BOOST_CHECK(co.gzip && *co.gzip == "gzipfoo");
BOOST_CHECK(co.help);
- BOOST_CHECK(!co.log);
+ BOOST_CHECK(co.log);
+ BOOST_CHECK(co.log->size()==8);
+ BOOST_CHECK(co.log->at(0).get<0>() == 0 && co.log->at(1).get<0>() == 0);
+ BOOST_CHECK(co.log->at(0).get<1>() == "errfoo" &&
co.log->at(1).get<1>() == "errbar/*");
+ BOOST_CHECK(co.log->at(2).get<0>() == 1 && co.log->at(3).get<0>() == 1);
+ BOOST_CHECK(co.log->at(2).get<1>() == "warnfoo" &&
co.log->at(3).get<1>() == "warnfoo/bar");
+ BOOST_CHECK(co.log->at(4).get<0>() == 2);
+ BOOST_CHECK(co.log->at(4).get<1>() == "infofoo");
+ BOOST_CHECK(co.log->at(5).get<0>() == 3 && co.log->at(6).get<0>() == 3
&& co.log->at(7).get<0>() == 3);
+ BOOST_CHECK(co.log->at(5).get<1>() == "dbgfoo" &&
co.log->at(6).get<1>() == "dbgbar" && co.log->at(7).get<1>() ==
"dbg/foo/bar/baz");
BOOST_CHECK(co.load && *co.load == "loadfoo");
BOOST_CHECK(co.logdomains && *co.logdomains == "filterfoo");
BOOST_CHECK(co.multiplayer);
@@ -265,9 +279,8 @@
BOOST_CHECK(!co.resolution);
BOOST_CHECK(co.rng_seed && *co.rng_seed == 1234);
BOOST_CHECK(!co.server);
- BOOST_CHECK(!co.screenshot);
- BOOST_CHECK(!co.screenshot_map_file);
- BOOST_CHECK(!co.screenshot_output_file);
+ BOOST_CHECK(co.screenshot && co.screenshot_map_file &&
co.screenshot_output_file);
+ BOOST_CHECK(*co.screenshot_map_file == "mapfoo" &&
*co.screenshot_output_file == "outssfoo");
BOOST_CHECK(!co.smallgui);
BOOST_CHECK(!co.test);
BOOST_CHECK(co.validcache);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits