Author: jhinrichs
Date: Tue Apr 21 23:15:59 2009
New Revision: 35103

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35103&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and 
loading.
Remove autosaving from menu_handler.

Modified:
    trunk/src/menu_events.cpp
    trunk/src/menu_events.hpp
    trunk/src/playsingle_controller.cpp
    trunk/src/savegame.cpp
    trunk/src/savegame.hpp

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=35103&r1=35102&r2=35103&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Tue Apr 21 23:15:59 2009
@@ -599,22 +599,6 @@
                                gui::message_dialog(*gui_, "", msg).show();
                        }
                }
-       }
-
-       void menu_handler::autosave() const
-       {
-               if(game_config::disable_autosave)
-                       return;
-
-               Uint32 start, end;
-               start = SDL_GetTicks();
-
-               autosave_savegame save(gamestate_, level_, *gui_, teams_, 
units_, status_, map_, preferences::compress_saves());
-               save.save_game(gui_);
-
-               end = SDL_GetTicks();
-               LOG_NG << "Milliseconds to save " << save.filename() << ": " << 
end - start << "\n";
-               
savegame_manager::remove_old_auto_saves(preferences::autosavemax(), 
preferences::INFINITE_AUTO_SAVES);
        }
 
        void menu_handler::preferences()

Modified: trunk/src/menu_events.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.hpp?rev=35103&r1=35102&r2=35103&view=diff
==============================================================================
--- trunk/src/menu_events.hpp (original)
+++ trunk/src/menu_events.hpp Tue Apr 21 23:15:59 2009
@@ -115,7 +115,6 @@
        void do_command(const std::string& str, const unsigned int team_num, 
mouse_handler& mousehandler);
        void do_ai_formula(const std::string& str, const unsigned int team_num, 
mouse_handler& mousehandler);
        void clear_undo_stack(const unsigned int team_num);
-       void autosave() const;
        bool has_team() const;
 protected:
        void add_chat_message(const time_t& time, const std::string& speaker,
@@ -130,8 +129,6 @@
        //void do_speak(const std::string& message, bool allies_only);
        void do_recruit(const std::string& name, const unsigned int team_num, 
const map_location& last_hex);
 //     std::vector<std::string> create_unit_table(const 
statistics::stats::str_int_map& m,unsigned int team);
-       void save_game_internal(const std::string& filename, bool 
write_snapshot, bool display_message);
-       //void write_game_snapshot(config& start) const;
        bool has_friends() const;
        bool clear_shroud(const unsigned int team_num);
        static void change_controller(const std::string& side, const 
std::string& controller);

Modified: trunk/src/playsingle_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playsingle_controller.cpp?rev=35103&r1=35102&r2=35103&view=diff
==============================================================================
--- trunk/src/playsingle_controller.cpp (original)
+++ trunk/src/playsingle_controller.cpp Tue Apr 21 23:15:59 2009
@@ -670,7 +670,8 @@
        gui_->draw(true,true);
 
        if (save) {
-               menu_handler_.autosave();
+               autosave_savegame save(gamestate_, level_, *gui_, teams_, 
units_, status_, map_, preferences::compress_saves());
+               save.autosave(game_config::disable_autosave, 
preferences::autosavemax(), preferences::INFINITE_AUTO_SAVES);
        }
 
        if(preferences::turn_bell()) {

Modified: trunk/src/savegame.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=35103&r1=35102&r2=35103&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Tue Apr 21 23:15:59 2009
@@ -496,8 +496,14 @@
 void savegame::save_game(display* gui)
 {
        try {
+               Uint32 start, end;
+               start = SDL_GetTicks();
+
                before_save();
                save_game_internal(filename_);
+
+               end = SDL_GetTicks();
+               LOG_SAVE << "Milliseconds to save " << filename_ << ": " << end 
- start << "\n";
 
                if (gui != NULL && show_confirmation_)
                        gui::message_dialog(*gui,_("Saved"),_("The game has 
been saved")).show();
@@ -732,13 +738,23 @@
 }
 
 autosave_savegame::autosave_savegame(game_state &gamestate, const config& 
level_cfg,
-                                                        const game_display& 
gui, const std::vector<team>& teams,
+                                                        game_display& gui, 
const std::vector<team>& teams,
                                                         const unit_map& units, 
const gamestatus& gamestatus,
                                                         const gamemap& map, 
const bool compress_saves)
        : game_savegame(gamestate, level_cfg, gui, teams, units, gamestatus, 
map, compress_saves)
 {
        set_error_message(_("Could not auto save the game. Please save the game 
manually."));
        create_filename();
+}
+
+void autosave_savegame::autosave(const bool disable_autosave, const int 
autosave_max, const int infinite_autosaves)
+{
+       if(disable_autosave)
+               return;
+
+       save_game(&gui_);
+
+       savegame_manager::remove_old_auto_saves(autosave_max, 
infinite_autosaves);
 }
 
 void autosave_savegame::create_filename()
@@ -753,7 +769,7 @@
 }
 
 game_savegame::game_savegame(game_state &gamestate, const config& level_cfg,
-                                                        const game_display& 
gui, const std::vector<team>& teams,
+                                                        game_display& gui, 
const std::vector<team>& teams,
                                                         const unit_map& units, 
const gamestatus& gamestatus,
                                                         const gamemap& map, 
const bool compress_saves)
        : savegame(gamestate, compress_saves, _("Save Game")),

Modified: trunk/src/savegame.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=35103&r1=35102&r2=35103&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Tue Apr 21 23:15:59 2009
@@ -207,7 +207,7 @@
 {
 public:
        game_savegame(game_state& gamestate, const config& level_cfg,
-               const game_display& gui, const std::vector<team>& teams,
+               game_display& gui, const std::vector<team>& teams,
                const unit_map& units, const gamestatus& gamestatus,
                const gamemap& map, const bool compress_saves);
 
@@ -223,7 +223,7 @@
 
 protected:
        const config& level_cfg_;
-       const game_display& gui_;
+       game_display& gui_;
        const std::vector<team>& teams_;
        const unit_map& units_;
        const gamestatus& gamestatus_;
@@ -246,10 +246,11 @@
 {
 public:
        autosave_savegame(game_state &gamestate, const config& level_cfg,
-                                                        const game_display& 
gui, const std::vector<team>& teams,
+                                                        game_display& gui, 
const std::vector<team>& teams,
                                                         const unit_map& units, 
const gamestatus& gamestatus,
                                                         const gamemap& map, 
const bool compress_saves);
 
+       void autosave(const bool disable_autosave, const int autosave_max, 
const int infinite_autosaves);
 private:
        /** Create a filename for automatic saves */
        virtual void create_filename();


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

Reply via email to