Author: jhinrichs
Date: Tue Apr  7 21:37:01 2009
New Revision: 34615

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34615&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and 
loading.
Move start-of-scenario save into the new savegame architecture.

Modified:
    trunk/src/gamestatus.cpp
    trunk/src/gamestatus.hpp
    trunk/src/playcampaign.cpp
    trunk/src/savegame.cpp
    trunk/src/savegame.hpp

Modified: trunk/src/gamestatus.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=34615&r1=34614&r2=34615&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Tue Apr  7 21:37:01 2009
@@ -915,27 +915,6 @@
                write_save_index();
        } catch(io_exception& e) {
                throw game::save_game_failed(e.what());
-       }
-}
-
-// Throws game::save_game_failed
-void save_game(const game_state& gamestate)
-{
-       std::string filename = gamestate.label;
-       if(preferences::compress_saves()) {
-               filename += ".gz";
-       }
-
-       scoped_ostream os(open_save_game(filename));
-       std::stringstream ss;
-       {
-               config_writer out(ss, preferences::compress_saves());
-               write_game(out, gamestate.snapshot, gamestate);
-               finish_save_game(out, gamestate, gamestate.label);
-       }
-       (*os) << ss.str();
-       if (!os->good()) {
-               throw game::save_game_failed(_("Could not write to file"));
        }
 }
 

Modified: trunk/src/gamestatus.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=34615&r1=34614&r2=34615&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Tue Apr  7 21:37:01 2009
@@ -333,9 +333,6 @@
 void load_game(const std::string& name, game_state& gamestate, std::string* 
error_log);
 void load_game_summary(const std::string& name, config& cfg_summary, 
std::string* error_log);
 
-/** Throws gamestatus::save_game_failed. */
-void save_game(const game_state& gamestate);
-
 /** Delete a savegame. */
 void delete_game(const std::string& name);
 

Modified: trunk/src/playcampaign.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playcampaign.cpp?rev=34615&r1=34614&r2=34615&view=diff
==============================================================================
--- trunk/src/playcampaign.cpp (original)
+++ trunk/src/playcampaign.cpp Tue Apr  7 21:37:01 2009
@@ -571,11 +571,9 @@
 #endif /* TINY_GUI */
                                        {
                                                try {
-                                                       //Add the player 
section to the starting position so we can get the correct recall list
-                                                       //when loading the 
replay later on
-                                                       
write_players(gamestate, gamestate.starting_pos);
-
-                                                       save_game(gamestate);
+                                                       scenariostart_savegame 
save(gamestate);
+                                                       save.save_game();
+                                                       //save_game(gamestate);
                                                } 
catch(game::save_game_failed&) {
                                                        
gui::show_error_message(disp, _("The game could not be saved"));
                                                        retry = true;

Modified: trunk/src/savegame.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=34615&r1=34614&r2=34615&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Tue Apr  7 21:37:01 2009
@@ -160,6 +160,19 @@
        filename.erase(std::remove_if(filename.begin(), filename.end(),
                    dialogs::is_illegal_file_char), filename.end());
        filename_ = filename;
+}
+
+scenariostart_savegame::scenariostart_savegame(game_state &gamestate) 
+       : savegame(gamestate) 
+{
+       set_filename(gamestate.label);
+}
+
+void scenariostart_savegame::before_save()
+{
+       //Add the player section to the starting position so we can get the 
correct recall list
+       //when loading the replay later on
+       write_players(gamestate(), gamestate().starting_pos);
 }
 
 replay_savegame::replay_savegame(game_state &gamestate) 

Modified: trunk/src/savegame.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=34615&r1=34614&r2=34615&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Tue Apr  7 21:37:01 2009
@@ -50,8 +50,6 @@
        static SDL_sem* sem_;
 };
 
-/** Autosave */
-std::string save_autosave(unsigned turn, const config& snapshot, game_state& 
gamestate);
 class savegame
 {
 public:
@@ -130,6 +128,15 @@
        virtual void create_filename();
 };
 
+class scenariostart_savegame : public savegame
+{
+public:
+       scenariostart_savegame(game_state& gamestate);
+
+private:
+       virtual void before_save();
+};
+
 ///** Autosave */
 //std::string save_autosave(unsigned turn, const config& snapshot, game_state& 
gamestate);
 //


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

Reply via email to