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


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src game.cpp
Date: Fri, 03 Dec 2004 20:36:51 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    04/12/04 01:30:30

Modified files:
        src            : game.cpp 

Log message:
        fixed crash bug when loading game (#11208 - internal)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.170&tr2=1.171&r1=text&r2=text

Patches:
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.170 wesnoth/src/game.cpp:1.171
--- wesnoth/src/game.cpp:1.170  Fri Dec  3 04:33:56 2004
+++ wesnoth/src/game.cpp        Sat Dec  4 01:30:30 2004
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.170 2004/12/03 04:33:56 Sirp Exp $ */
+/* $Id: game.cpp,v 1.171 2004/12/04 01:30:30 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -331,8 +331,9 @@
        bool new_campaign();
        bool play_multiplayer();
        bool change_language();
-
-       void play_game();
+
+       enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
+       void play_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
 
 private:
        game_controller(const game_controller&);
@@ -796,8 +797,29 @@
                return false;
        }
 
-       try {
-               ::load_game(units_data_,game,state_);
+       try {
+               //to load a save file, we first load the file in, then we 
re-parse game
+               //data with the save's #defines, and then we finally parse the 
save file,
+               //with the game data ready to go.
+               config cfg;
+               read_save_file(game,cfg);
+
+               defines_map_.clear();
+               defines_map_[cfg["difficulty"]] = preproc_define();
+
+               if(defines_map_.count("NORMAL")) {
+                       defines_map_["MEDIUM"] = preproc_define();
+               }
+
+               const std::string& campaign_define = cfg["campaign_define"];
+               if(campaign_define.empty() == false) {
+                       defines_map_[campaign_define] = preproc_define();
+               }
+
+               refresh_game_cfg();
+
+               state_ = read_game(units_data_,&cfg);
+               
                if(state_.version != game_config::version) {
                        const int res = gui::show_dialog(disp(),NULL,"",
                                              _("This save is from a different 
version of the game. Do you want to try to load it?"),
@@ -807,8 +829,6 @@
                        }
                }
 
-               defines_map_.clear();
-               defines_map_[state_.difficulty] = preproc_define();
        } catch(gamestatus::error& e) {
                std::cerr << "caught load_game_failed\n";
                gui::show_dialog(disp(),NULL,"",
@@ -1322,10 +1342,12 @@
 {
        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();
+                       game_config_.clear();
+
+                       std::vector<line_source> line_src;
+                       
read_game_cfg(defines_map_,line_src,game_config_,use_caching_);
 
                        const config* const units = game_config_.child("units");
                        if(units != NULL) {
@@ -1340,17 +1362,19 @@
        }
 }
 
-void game_controller::play_game()
-{
-       if(state_.campaign_define.empty() == false) {
-               defines_map_[state_.campaign_define] = preproc_define();
-       }
+void game_controller::play_game(RELOAD_GAME_DATA reload)
+{
+       if(reload == RELOAD_DATA) {
+               if(state_.campaign_define.empty() == false) {
+                       defines_map_[state_.campaign_define] = preproc_define();
+               }
 
-       if(defines_map_.count("NORMAL")) {
-               defines_map_["MEDIUM"] = preproc_define();
-       }
+               if(defines_map_.count("NORMAL")) {
+                       defines_map_["MEDIUM"] = preproc_define();
+               }
        
-       refresh_game_cfg();
+               refresh_game_cfg();
+       }
 
        const binary_paths_manager bin_paths_manager(game_config_);
 
@@ -1517,7 +1541,8 @@
                        res = gui::show_title(game.disp(),tips_of_day,&ntip);
                }
                tips_of_day.clear();
-
+
+               game_controller::RELOAD_GAME_DATA should_reload = 
game_controller::RELOAD_DATA;
                std::cerr << "title screen returned result\n";
                if(res == gui::QUIT_GAME) {
                        std::cerr << "quitting game...\n";
@@ -1525,7 +1550,9 @@
                } else if(res == gui::LOAD_GAME) {
                        if(game.load_game() == false) {
                                continue;
-                       }
+                       }
+
+                       should_reload = game_controller::NO_RELOAD_DATA;
                } else if(res == gui::TUTORIAL) {
                        game.set_tutorial();
                } else if(res == gui::NEW_CAMPAIGN) {
@@ -1551,7 +1578,7 @@
                        continue;
                }
                
-               game.play_game();
+               game.play_game(should_reload);
        }
 
        return 0;




reply via email to

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