wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src Makefile.am multiplayer.cpp playlev...


From: Yann Dirson
Subject: [Wesnoth-cvs-commits] wesnoth/src Makefile.am multiplayer.cpp playlev...
Date: Tue, 22 Mar 2005 17:09:28 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Yann Dirson <address@hidden>    05/03/22 22:09:28

Modified files:
        src            : Makefile.am multiplayer.cpp playlevel.cpp 
                         race.cpp replay.cpp replay.hpp team.cpp 
                         unit.cpp 
Added files:
        src            : random.cpp random.hpp 

Log message:
        split a new rng class out of replay, sanitized a bit the deps using this

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/random.cpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/random.hpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/Makefile.am.diff?tr1=1.85&tr2=1.86&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer.cpp.diff?tr1=1.149&tr2=1.150&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.188&tr2=1.189&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/race.cpp.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/replay.cpp.diff?tr1=1.96&tr2=1.97&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/replay.hpp.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/team.cpp.diff?tr1=1.83&tr2=1.84&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.129&tr2=1.130&r1=text&r2=text

Patches:
Index: wesnoth/src/Makefile.am
diff -u wesnoth/src/Makefile.am:1.85 wesnoth/src/Makefile.am:1.86
--- wesnoth/src/Makefile.am:1.85        Mon Mar 21 21:45:43 2005
+++ wesnoth/src/Makefile.am     Tue Mar 22 22:09:27 2005
@@ -85,6 +85,7 @@
        preferences.cpp \
        publish_campaign.cpp \
        race.cpp \
+       random.cpp \
        replay.cpp \
        reports.cpp \
        sdl_utils.cpp \
@@ -173,6 +174,7 @@
        preferences.hpp \
        publish_campaign.hpp \
        race.hpp \
+       random.hpp \
        replay.hpp \
        reports.hpp \
        scoped_resource.hpp \
@@ -263,6 +265,7 @@
        playturn.cpp \
        preferences.cpp \
        race.cpp \
+       random.cpp \
        replay.cpp \
        reports.cpp \
        sdl_utils.cpp \
@@ -343,6 +346,7 @@
        playturn.hpp \
        preferences.hpp \
        race.hpp \
+       random.hpp \
        replay.hpp \
        reports.hpp \
        sdl_utils.hpp \
Index: wesnoth/src/multiplayer.cpp
diff -u wesnoth/src/multiplayer.cpp:1.149 wesnoth/src/multiplayer.cpp:1.150
--- wesnoth/src/multiplayer.cpp:1.149   Tue Mar 22 12:53:23 2005
+++ wesnoth/src/multiplayer.cpp Tue Mar 22 22:09:27 2005
@@ -1,4 +1,4 @@
-/* $Id: multiplayer.cpp,v 1.149 2005/03/22 12:53:23 j_daniel Exp $ */
+/* $Id: multiplayer.cpp,v 1.150 2005/03/22 22:09:27 ydirson Exp $ */
 /*
    Copyright (C)
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -25,6 +25,7 @@
 #include "network.hpp"
 #include "playlevel.hpp"
 #include "preferences.hpp"
+#include "random.hpp"
 #include "replay.hpp"
 #include "video.hpp"
 
@@ -326,6 +327,7 @@
 void start_server(display& disp, const config& game_config, game_data& data,
                mp::controller default_controller, bool is_server)
 {
+       const set_random_generator generator_setter(&recorder);
        mp::chat chat;
        config gamelist;
 
@@ -335,6 +337,7 @@
 void start_client(display& disp, const config& game_config, game_data& data,
                const std::string host)
 {
+       const set_random_generator generator_setter(&recorder);
        const network::manager net_manager;
 
        mp::chat chat;
Index: wesnoth/src/playlevel.cpp
diff -u wesnoth/src/playlevel.cpp:1.188 wesnoth/src/playlevel.cpp:1.189
--- wesnoth/src/playlevel.cpp:1.188     Sun Mar 20 16:27:44 2005
+++ wesnoth/src/playlevel.cpp   Tue Mar 22 22:09:28 2005
@@ -1,4 +1,4 @@
-/* $Id: playlevel.cpp,v 1.188 2005/03/20 16:27:44 ydirson Exp $ */
+/* $Id: playlevel.cpp,v 1.189 2005/03/22 22:09:28 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -31,6 +31,7 @@
 #include "playlevel.hpp"
 #include "playturn.hpp"
 #include "preferences.hpp"
+#include "random.hpp"
 #include "replay.hpp"
 #include "scoped_resource.hpp"
 #include "sound.hpp"
@@ -124,6 +125,8 @@
                game_state& state_of_game,
                const std::vector<config*>& story)
 {
+       const set_random_generator generator_setter(&recorder);
+
        //guarantee the cursor goes back to 'normal' at the end of the level
        const cursor::setter cursor_setter(cursor::NORMAL);
 
Index: wesnoth/src/race.cpp
diff -u wesnoth/src/race.cpp:1.17 wesnoth/src/race.cpp:1.18
--- wesnoth/src/race.cpp:1.17   Fri Mar 11 02:40:00 2005
+++ wesnoth/src/race.cpp        Tue Mar 22 22:09:28 2005
@@ -1,7 +1,7 @@
 #include "global.hpp"
 
 #include "race.hpp"
-#include "replay.hpp"
+#include "random.hpp"
 #include "serialization/string_utils.hpp"
 
 #include <cstdlib>
Index: wesnoth/src/replay.cpp
diff -u wesnoth/src/replay.cpp:1.96 wesnoth/src/replay.cpp:1.97
--- wesnoth/src/replay.cpp:1.96 Wed Mar 16 21:49:37 2005
+++ wesnoth/src/replay.cpp      Tue Mar 22 22:09:28 2005
@@ -1,4 +1,4 @@
-/* $Id: replay.cpp,v 1.96 2005/03/16 21:49:37 ydirson Exp $ */
+/* $Id: replay.cpp,v 1.97 2005/03/22 22:09:28 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -165,49 +165,15 @@
        unit_map_ref = NULL;
 }
 
+// FIXME: this one now has to be assigned with set_random_generator
+// from play_level or similar.  We should surely hunt direct
+// references to it from this very file and move it out of here.
 replay recorder;
 
-namespace {
-
-replay* random_generator = &recorder;
-
-struct set_random_generator {
-
-       set_random_generator(replay* r) : old_(random_generator)
-       {
-               random_generator = r;
-       }
-
-       ~set_random_generator()
-       {
-               random_generator = old_;
-       }
-
-private:
-       replay* old_;
-};
-
-}
-
-int get_random()
-{
-       return random_generator->get_random();
-}
-
-const config* get_random_results()
-{
-       return random_generator->get_random_results();
-}
-
-void set_random_results(const config& cfg)
-{
-       random_generator->set_random_results(cfg);
-}
-
-replay::replay() : pos_(0), current_(NULL), random_(NULL), skip_(0)
+replay::replay() : pos_(0), current_(NULL), skip_(0)
 {}
 
-replay::replay(const config& cfg) : cfg_(cfg), pos_(0), current_(NULL), 
random_(NULL), skip_(0)
+replay::replay(const config& cfg) : cfg_(cfg), pos_(0), current_(NULL), 
skip_(0)
 {}
 
 config& replay::get_config()
@@ -484,47 +450,6 @@
        return current_ = &cfg_.add_child("command");
 }
 
-int replay::get_random()
-{
-       if(random_ == NULL) {
-               return rand();
-       }
-
-       //random numbers are in a 'list' meaning that each random
-       //number contains another random numbers unless it's at
-       //the end of the list. Generating a new random number means
-       //nesting a new node inside the current node, and making
-       //the current node the new node
-       config* const random = random_->child("random");
-       if(random == NULL) {
-               const int res = rand();
-               random_ = &random_->add_child("random");
-
-               char buf[100];
-               sprintf(buf,"%d",res);
-               (*random_)["value"] = buf;
-
-               return res;
-       } else {
-               const int res = atol((*random)["value"].c_str());
-               random_ = random;
-               return res;
-       }
-}
-
-const config* replay::get_random_results() const
-{
-       wassert(random_ != NULL);
-       return random_->child("results");
-}
-
-void replay::set_random_results(const config& cfg)
-{
-       wassert(random_ != NULL);
-       random_->clear_children("results");
-       random_->add_child("results",cfg);
-}
-
 void replay::start_replay()
 {
        pos_ = 0;
Index: wesnoth/src/replay.hpp
diff -u wesnoth/src/replay.hpp:1.29 wesnoth/src/replay.hpp:1.30
--- wesnoth/src/replay.hpp:1.29 Thu Mar 10 21:42:04 2005
+++ wesnoth/src/replay.hpp      Tue Mar 22 22:09:28 2005
@@ -1,4 +1,4 @@
-/* $Id: replay.hpp,v 1.29 2005/03/10 21:42:04 ydirson Exp $ */
+/* $Id: replay.hpp,v 1.30 2005/03/22 22:09:28 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -18,6 +18,7 @@
 #include "config.hpp"
 #include "gamestatus.hpp"
 #include "map.hpp"
+#include "random.hpp"
 #include "unit.hpp"
 
 struct verification_manager
@@ -26,12 +27,7 @@
        ~verification_manager();
 };
 
-int get_random();
-
-const config* get_random_results();
-void set_random_results(const config& cfg);
-
-class replay
+class replay: public rng
 {
 public:
        replay();
@@ -75,10 +71,6 @@
 
        void undo();
 
-       int get_random();
-       const config* get_random_results() const;
-       void set_random_results(const config& cfg);
-
        void start_replay();
        config* get_next_action();
 
@@ -110,7 +102,6 @@
        unsigned int pos_;
 
        config* current_;
-       config* random_;
 
        game_state saveInfo_;
 
Index: wesnoth/src/team.cpp
diff -u wesnoth/src/team.cpp:1.83 wesnoth/src/team.cpp:1.84
--- wesnoth/src/team.cpp:1.83   Sat Mar 19 21:26:30 2005
+++ wesnoth/src/team.cpp        Tue Mar 22 22:09:28 2005
@@ -1,4 +1,4 @@
-/* $Id: team.cpp,v 1.83 2005/03/19 21:26:30 gruikya Exp $ */
+/* $Id: team.cpp,v 1.84 2005/03/22 22:09:28 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -18,7 +18,6 @@
 #include "gamestatus.hpp"
 #include "log.hpp"
 #include "network.hpp"
-#include "replay.hpp"
 #include "team.hpp"
 #include "util.hpp"
 #include "wassert.hpp"
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.129 wesnoth/src/unit.cpp:1.130
--- wesnoth/src/unit.cpp:1.129  Sat Mar 19 22:18:18 2005
+++ wesnoth/src/unit.cpp        Tue Mar 22 22:09:28 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.129 2005/03/19 22:18:18 gruikya Exp $ */
+/* $Id: unit.cpp,v 1.130 2005/03/22 22:09:28 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -19,7 +19,7 @@
 #include "log.hpp"
 #include "pathfind.hpp"
 #include "preferences.hpp"
-#include "replay.hpp"
+#include "random.hpp"
 #include "unit.hpp"
 #include "unit_types.hpp"
 #include "util.hpp"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]