mail[Wesnoth-commits] r37216 - in /trunk/src: game.cpp mouse_events.cpp random.cpp rng.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by kailoran on July 24, 2009 - 15:07:
Author: ilor
Date: Fri Jul 24 15:06:50 2009
New Revision: 37216

URL: http://svn.gna.org/viewcvs/wesnoth?rev=37216&view=rev
Log:
add a --no-srng command line option to disable server-side RNG support to 
allow potential OOS debugging without having to rebuild

Modified:
    trunk/src/game.cpp
    trunk/src/mouse_events.cpp
    trunk/src/random.cpp
    trunk/src/rng.hpp

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=37216&r1=37215&r2=37216&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Fri Jul 24 15:06:50 2009
@@ -442,6 +442,8 @@
 #else
                        std::cerr << "Option --dummy-locales ignored: support 
was not compiled in.\n";
 #endif
+               } else if(val == "--no-srng") {
+                       rand_rng::disable_server_rng();
                } else if(val[0] == '-') {
                        std::cerr << "unknown option: " << val << std::endl;
                        throw config::error("unknown option");
@@ -1773,6 +1775,8 @@
                        << "  --nocache                    disables caching 
of game data.\n"
                        << "  --nomusic                    runs the game 
without music.\n"
                        << "  --nosound                    runs the game 
without sounds and music.\n"
+                       << "  --no-srng                    disable 
server-side RNG support (will cause OOS\n"
+                       << "                               errors unless 
every player uses it)\n"
                        << "  --path                       prints the path to 
the data directory and exits.\n"
                        << "  -r, --resolution XxY         sets the screen 
resolution. Example: -r 800x600\n"
                        << "  --rng-seed <number>          seeds the random 
number generator with number\n"
@@ -1887,7 +1891,7 @@
                                return 2;
                        }
                        srand(lexical_cast_default<unsigned int>(argv[arg]));
-               }
+               }
        }
 
        // Not the most intuitive solution, but I wanted to leave current 
semantics for now

Modified: trunk/src/mouse_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=37216&r1=37215&r2=37216&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Fri Jul 24 15:06:50 2009
@@ -676,10 +676,10 @@
 
                gui().draw();
                recorder.add_attack(attacker_loc, defender_loc, 
att.attack_num, def.attack_num);
-               if (network::nconnections() == 0) {
+               rand_rng::invalidate_seed();
+               if (rand_rng::has_valid_seed()) { //means SRNG is disabled
                        perform_attack(attacker_loc, defender_loc, 
att.attack_num, def.attack_num, rand());
                } else {
-                       rand_rng::invalidate_seed();
                        
rand_rng::set_new_seed_callback(boost::bind(&mouse_handler::perform_attack,
                                this, attacker_loc, defender_loc, 
att.attack_num, def.attack_num, _1));
                }

Modified: trunk/src/random.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/random.cpp?rev=37216&r1=37215&r2=37216&view=diff
==============================================================================
--- trunk/src/random.cpp (original)
+++ trunk/src/random.cpp Fri Jul 24 15:06:50 2009
@@ -57,6 +57,7 @@
   rand_rng::seed_t last_seed;
   bool seed_valid = false;
   boost::function<void (rand_rng::seed_t)> new_seed_callback;
+  bool srng_disabled = false;
 }
 
 
@@ -107,8 +108,8 @@
 
 bool has_valid_seed()
 {
-       //in a SP game the seed is always valid
-       return (network::nconnections() == 0) || seed_valid;
+       //if the SRNG is disabled or we're in a SP game the seed is always 
valid
+       return srng_disabled || (network::nconnections() == 0) || seed_valid;
 }
 
 seed_t get_last_seed()
@@ -126,6 +127,11 @@
 {
        DBG_RND << "clear_new_seed_callback\n";
        new_seed_callback = NULL;
+}
+
+void disable_server_rng()
+{
+       srng_disabled = true;
 }
 
 

Modified: trunk/src/rng.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/rng.hpp?rev=37216&r1=37215&r2=37216&view=diff
==============================================================================
--- trunk/src/rng.hpp (original)
+++ trunk/src/rng.hpp Fri Jul 24 15:06:50 2009
@@ -82,6 +82,12 @@
  */
 void clear_new_seed_callback();
 
+/**
+ * Disable server RNG support, will cause OOS if playing MP with a client 
with
+ * SRNG enabled. For debugging purposes, should be removed before 1.8.0
+ */
+void disable_server_rng();
+
 } // ends rand_rng namespace
 
 #endif




Related Messages


Powered by MHonArc, Updated Fri Jul 24 15:41:33 2009