Author: zaroth
Date: Thu Jun  9 11:52:50 2011
New Revision: 49811

URL: http://svn.gna.org/viewcvs/wesnoth?rev=49811&view=rev
Log:
Added resolution and nogui options to commandline_options.

Modified:
    trunk/src/commandline_options.cpp
    trunk/src/commandline_options.hpp
    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=49811&r1=49810&r2=49811&view=diff
==============================================================================
--- trunk/src/commandline_options.cpp (original)
+++ trunk/src/commandline_options.cpp Thu Jun  9 11:52:50 2011
@@ -131,6 +131,7 @@
                ("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.")
+               ("resolution,r", po::value<std::string>(), "sets the screen 
resolution. <arg> should have format XxY. Example: --resolution 800x600")
                ;
 
        po::options_description logging_opts("Logging options");
@@ -146,6 +147,7 @@
        multiplayer_opts.add_options()
                ("multiplayer,m", "Starts a multiplayer game. There are 
additional options that can be used as explained below:")
                ("ai-config", po::value<std::vector<std::string> 
>()->composing(), "arg should have format side:value\nselects a configuration 
file to load for this side.")
+               ("nogui", "runs the game without the GUI.")
                ;
 
        po::options_description preprocessor_opts("Preprocessor mode options");
@@ -212,6 +214,8 @@
                new_widgets = true;
        if (vm.count("nocache"))
                nocache = true;
+       if (vm.count("nogui"))
+               nogui = true;
        if (vm.count("path"))
                path = true;
        if (vm.count("preprocess"))
@@ -226,6 +230,8 @@
                preprocess_input_macros = 
vm["preprocess-input-macros"].as<std::string>();
        if (vm.count("preprocess-output-macros"))
                preprocess_output_macros = 
vm["preprocess-output-macros"].as<std::string>();
+       if (vm.count("resolution"))
+               parse_resolution_(vm["resolution"].as<std::string>());
        if (vm.count("rng-seed"))
                rng_seed = vm["rng-seed"].as<unsigned int>();
        if (vm.count("screenshot"))
@@ -242,6 +248,27 @@
                with_replay = true;
 }
 
+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));
+       }
+}
+
+void commandline_options::parse_resolution_ ( const std::string& 
resolution_string )
+{
+       const std::vector<std::string> tokens = utils::split(resolution_string, 
'x');
+       if (tokens.size() != 2)
+               {} // TODO throw a meaningful exception
+       int xres = lexical_cast<int>(tokens[0]);
+       int yres = lexical_cast<int>(tokens[1]);
+       resolution = boost::tuple<int,int>(xres,yres);
+}
+
 std::vector<boost::tuple<int,std::string> > 
commandline_options::parse_to_int_string_tuples_(const std::vector<std::string> 
&strings)
 {
        std::vector<boost::tuple<int,std::string> > vec;
@@ -251,7 +278,7 @@
                const std::vector<std::string> tokens = utils::split(s, ':');
                if (tokens.size()!=2)
                {
-                        //TODO throw meaningful exception
+                        //TODO throw a meaningful exception
                }
                elem.get<0>() = lexical_cast<int>(tokens[0]);
                        //TODO catch exception and pack in meaningful something
@@ -261,17 +288,6 @@
        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=49811&r1=49810&r2=49811&view=diff
==============================================================================
--- trunk/src/commandline_options.hpp (original)
+++ trunk/src/commandline_options.hpp Thu Jun  9 11:52:50 2011
@@ -160,6 +160,7 @@
        bool with_replay;
 private:
        void parse_log_domains_(const std::string &domains_string, const int 
severity);
+       void parse_resolution_ (const std::string &resolution_string);
        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_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_controller.cpp?rev=49811&r1=49810&r2=49811&view=diff
==============================================================================
--- trunk/src/game_controller.cpp (original)
+++ trunk/src/game_controller.cpp Thu Jun  9 11:52:50 2011
@@ -144,7 +144,12 @@
                        ++fps;
                }
                preferences::set_draw_delay(fps);
-       } 
+       }
+       if (cmdline_opts_.nogui) {
+               no_gui_ = true;
+               no_sound = true;
+               preferences::disable_preferences_save();
+       }
        if (cmdline_opts_.multiplayer)
                multiplayer_mode_ = true;
        if (cmdline_opts_.new_storyscreens)
@@ -156,6 +161,14 @@
                gui2::new_widgets = true;
        if (cmdline_opts_.nocache)
                cache_.set_use_cache(false);
+       if (cmdline_opts_.resolution) {
+               const int xres = cmdline_opts_.resolution->get<0>();
+               const int yres = cmdline_opts_.resolution->get<1>();
+               if(xres > 0 && yres > 0) {
+                       const std::pair<int,int> resolution(xres,yres);
+                       preferences::set_resolution(resolution);
+               }
+       }
        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;
@@ -174,25 +187,6 @@
                const std::string val(argv_[arg_]);
                if(val.empty()) {
                        continue;
-               }
-               else if(val == "--resolution" || val == "-r") {
-                       if(arg_+1 != argc_) {
-                               ++arg_;
-                               const std::string val(argv_[arg_]);
-                               const std::vector<std::string> res = 
utils::split(val, 'x');
-                               if(res.size() == 2) {
-                                       const int xres = 
lexical_cast_default<int>(res.front());
-                                       const int yres = 
lexical_cast_default<int>(res.back());
-                                       if(xres > 0 && yres > 0) {
-                                               const std::pair<int,int> 
resolution(xres,yres);
-                                               
preferences::set_resolution(resolution);
-                                       }
-                               }
-                       }
-               } else if(val == "--nogui") {
-                       no_gui_ = true;
-                       no_sound = true;
-                       preferences::disable_preferences_save();
                }
                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=49811&r1=49810&r2=49811&view=diff
==============================================================================
--- trunk/src/tests/test_commandline_options.cpp (original)
+++ trunk/src/tests/test_commandline_options.cpp Thu Jun  9 11:52:50 2011
@@ -198,11 +198,13 @@
                "--new-syntax",
                "--new-widgets",
                "--nocache",
+               "--nogui",
                "--path",
                "--preprocess", "preppathfoo", "preptargfoo",
                "--preprocess-defines=DEFFOO,DEFBAR",
                "--preprocess-input-macros=inmfoo",
                "--preprocess-output-macros=outmfoo",
+               "--resolution=800x600",
                "--rng-seed=1234",
                "--screenshot", "mapfoo", "outssfoo",
                "--validcache",
@@ -258,7 +260,7 @@
        BOOST_CHECK(co.max_fps && *co.max_fps == 100);
        BOOST_CHECK(co.nocache);
        BOOST_CHECK(!co.nodelay);
-       BOOST_CHECK(!co.nogui);
+       BOOST_CHECK(co.nogui);
        BOOST_CHECK(!co.nomusic);
        BOOST_CHECK(!co.nosound);
        BOOST_CHECK(co.new_storyscreens);
@@ -276,7 +278,8 @@
        BOOST_CHECK(!co.proxy_password);
        BOOST_CHECK(!co.proxy_port);
        BOOST_CHECK(!co.proxy_user);
-       BOOST_CHECK(!co.resolution);
+       BOOST_CHECK(co.resolution);
+       BOOST_CHECK(co.resolution->get<0>() == 800 && co.resolution->get<1>() 
== 600);
        BOOST_CHECK(co.rng_seed && *co.rng_seed == 1234);
        BOOST_CHECK(!co.server);
        BOOST_CHECK(co.screenshot && co.screenshot_map_file && 
co.screenshot_output_file);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to