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

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

[Wesnoth-cvs-commits] wesnoth/src game.cpp gamestatus.hpp gamestatus.cpp


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src game.cpp gamestatus.hpp gamestatus.cpp
Date: Fri, 03 Dec 2004 00:03:49 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    04/12/03 04:33:56

Modified files:
        src            : game.cpp gamestatus.hpp gamestatus.cpp 

Log message:
        made it so #ifdefing units according to campaign #defines works properly

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.169&tr2=1.170&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.hpp.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.cpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text

Patches:
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.169 wesnoth/src/game.cpp:1.170
--- wesnoth/src/game.cpp:1.169  Thu Dec  2 21:57:27 2004
+++ wesnoth/src/game.cpp        Fri Dec  3 04:33:56 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.169 2004/12/02 21:57:27 silene Exp $ */
+/* $Id: game.cpp,v 1.170 2004/12/03 04:33:56 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -337,6 +337,8 @@
 private:
        game_controller(const game_controller&);
        void operator=(const game_controller&);
+
+       void refresh_game_cfg();
 
        void download_campaigns();
        void upload_campaign(const std::string& campaign, network::connection 
sock);
@@ -370,7 +372,7 @@
        std::string loaded_game_;
        bool loaded_game_show_replay_;
 
-       preproc_map defines_map_;
+       preproc_map defines_map_, old_defines_map_;
 };
 
 game_controller::game_controller(int argc, char** argv, bool use_sound)
@@ -576,16 +578,8 @@
        if(multiplayer_mode_) {
                defines_map_["MULTIPLAYER"] = preproc_define();
        }
-       std::vector<line_source> line_src;
 
-       try {
-               log_scope("loading config");
-               read_game_cfg(defines_map_,line_src,game_config_,use_caching_);
-       } catch(config::error& e) {
-               gui::show_dialog(disp(),NULL,"","Error loading game 
configuration files: '" + e.message + "' (The game will now exit)",
-                                gui::MESSAGE);
-               throw e;
-       }
+       refresh_game_cfg();
 
        game_config::load_config(game_config_.child("game_config"));
 
@@ -593,11 +587,6 @@
 
        paths_manager_.set_paths(game_config_);
 
-       const config* const units = game_config_.child("units");
-       if(units != NULL) {
-               units_data_.set_config(*units);
-       }
-
        return true;
 }
 
@@ -1238,10 +1227,8 @@
        }
        
        try {
-               defines_map_[state_.campaign_define] = preproc_define();
-               std::vector<line_source> line_src;
-               config game_config;
-               read_game_cfg(defines_map_,line_src,game_config,use_caching_);
+               defines_map_[state_.campaign_define] = preproc_define();
+               refresh_game_cfg();
                
                if(res >= 2) {
                        std::vector<std::string> chat;
@@ -1250,10 +1237,10 @@
                        const std::string controller = (res == 2 ? "network" : 
(res == 3 ? "human" : "ai"));
                        const bool is_server = res == 2;
 
-                       multiplayer_game_setup_dialog 
mp_dialog(disp(),units_data_,game_config,state_,is_server,controller);
+                       multiplayer_game_setup_dialog 
mp_dialog(disp(),units_data_,game_config_,state_,is_server,controller);
                        lobby::RESULT res = lobby::CONTINUE;
                        while(res == lobby::CONTINUE) {
-                               res = 
lobby::enter(disp(),game_data,game_config,&mp_dialog,chat);
+                               res = 
lobby::enter(disp(),game_data,game_config_,&mp_dialog,chat);
                        }
 
                        if(res == lobby::CREATE) {
@@ -1265,7 +1252,7 @@
                                host = preferences::official_network_host();
                        }
 
-                       
play_multiplayer_client(disp(),units_data_,game_config,state_,host);
+                       
play_multiplayer_client(disp(),units_data_,game_config_,state_,host);
                }
        } catch(gamestatus::load_game_failed& e) {
                gui::show_dialog(disp(),NULL,"","error loading the game: " + 
e.message,gui::OK_ONLY);
@@ -1330,6 +1317,28 @@
 
        return false;
 }
+
+void game_controller::refresh_game_cfg()
+{
+       try {
+               if(old_defines_map_.empty() || defines_map_ != 
old_defines_map_) {
+                       std::vector<line_source> line_src;
+                       
read_game_cfg(defines_map_,line_src,game_config_,use_caching_);
+
+                       units_data_.clear();
+
+                       const config* const units = game_config_.child("units");
+                       if(units != NULL) {
+                               units_data_.set_config(*units);
+                       }
+
+                       old_defines_map_ = defines_map_;
+               }
+       } catch(config::error& e) {
+               gui::show_dialog(disp(),NULL,"","Error loading game 
configuration files: '" + e.message + "' (The game will now exit)", 
gui::MESSAGE);
+               throw e;
+       }
+}
 
 void game_controller::play_game()
 {
@@ -1340,31 +1349,13 @@
        if(defines_map_.count("NORMAL")) {
                defines_map_["MEDIUM"] = preproc_define();
        }
+       
+       refresh_game_cfg();
 
-       //make a new game config item based on the difficulty level
-       std::vector<line_source> line_src;
-       config game_config;
-       
-       try {
-               read_game_cfg(defines_map_,line_src,game_config,use_caching_);
-       } catch(config::error& e) {
-               gui::show_dialog(disp(),NULL,"","Error loading game 
configuration files: '" + e.message + "' (The game will now exit)", 
gui::MESSAGE);
-               throw e;
-       }
-
-       const binary_paths_manager bin_paths_manager(game_config);
-
-       const config* const units = game_config.child("units");
-       if(units == NULL) {
-               std::cerr << "ERROR: Could not find game configuration files\n";
-               std::cerr << game_config.write();
-               return;
-       }
-
-       game_data units_data(*units);
+       const binary_paths_manager bin_paths_manager(game_config_);
 
        try {
-               const LEVEL_RESULT result = 
::play_game(disp(),state_,game_config,units_data,video_);
+               const LEVEL_RESULT result = 
::play_game(disp(),state_,game_config_,units_data_,video_);
                if(result == VICTORY) {
                        the_end(disp());
                        about::show_about(disp());
Index: wesnoth/src/gamestatus.cpp
diff -u wesnoth/src/gamestatus.cpp:1.49 wesnoth/src/gamestatus.cpp:1.50
--- wesnoth/src/gamestatus.cpp:1.49     Mon Nov 22 21:18:26 2004
+++ wesnoth/src/gamestatus.cpp  Fri Dec  3 04:33:56 2004
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.cpp,v 1.49 2004/11/22 21:18:26 silene Exp $ */
+/* $Id: gamestatus.cpp,v 1.50 2004/12/03 04:33:56 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -405,25 +405,33 @@
        remove((get_saves_dir() + "/" + name).c_str());
        remove((get_saves_dir() + "/" + modified_name).c_str());
 }
+
+void read_save_file(const std::string& name, config& cfg)
+{
+       std::string modified_name = name;
+       std::replace(modified_name.begin(),modified_name.end(),' ','_');
+
+       //try reading the file both with and without underscores
+       std::string file_data = read_file(get_saves_dir() + "/" + 
modified_name);
+       if(file_data.empty()) {
+               file_data = read_file(get_saves_dir() + "/" + name);
+       }
+
+       cfg.clear();
+       cfg.read(file_data);
+
+       if(cfg.empty()) {
+               std::cerr << "Could not parse file data into config\n";
+               throw gamestatus::load_game_failed();
+       }
+}
 
 void load_game(const game_data& data, const std::string& name, game_state& 
state)
 {
-       log_scope("load_game");
-       std::string modified_name = name;
-       std::replace(modified_name.begin(),modified_name.end(),' ','_');
-
-       //try reading the file both with and without underscores
-       std::string file_data = read_file(get_saves_dir() + "/" + 
modified_name);
-       if(file_data.empty()) {
-               file_data = read_file(get_saves_dir() + "/" + name);
-       }
-
-       config cfg(file_data);
-
-       if(cfg.empty()) {
-               std::cerr << "Could not parse file data into config\n";
-               throw gamestatus::load_game_failed();
-       }
+       log_scope("load_game");
+
+       config cfg;
+       read_save_file(name,cfg);
        
        state = read_game(data,&cfg);
 }
Index: wesnoth/src/gamestatus.hpp
diff -u wesnoth/src/gamestatus.hpp:1.33 wesnoth/src/gamestatus.hpp:1.34
--- wesnoth/src/gamestatus.hpp:1.33     Sun Oct  3 18:00:15 2004
+++ wesnoth/src/gamestatus.hpp  Fri Dec  3 04:33:56 2004
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.hpp,v 1.33 2004/10/03 18:00:15 gruikya Exp $ */
+/* $Id: gamestatus.hpp,v 1.34 2004/12/03 04:33:56 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -188,6 +188,8 @@
 std::vector<save_info> get_saves_list();
 
 enum WRITE_GAME_MODE { WRITE_SNAPSHOT_ONLY, WRITE_FULL_GAME };
+
+void read_save_file(const std::string& name, config& cfg);
 
 game_state read_game(const game_data& data, const config* cfg);
 void write_game(const game_state& game, config& cfg, WRITE_GAME_MODE 
mode=WRITE_FULL_GAME);




reply via email to

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