Author: jhinrichs
Date: Sun Apr 12 21:43:55 2009
New Revision: 34820
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34820&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and
loading.
Cleaning up multiplayer code in savegame.cpp.
Modified:
trunk/src/multiplayer_connect.cpp
trunk/src/savegame.cpp
trunk/src/savegame.hpp
Modified: trunk/src/multiplayer_connect.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_connect.cpp?rev=34820&r1=34819&r2=34820&view=diff
==============================================================================
--- trunk/src/multiplayer_connect.cpp (original)
+++ trunk/src/multiplayer_connect.cpp Sun Apr 12 21:43:55 2009
@@ -1516,8 +1516,8 @@
{
if(params_.saved_game) {
try{
- multiplayer_loadgame load(disp(), game_config(),
state_);
- load.load_game();
+ loadgame load(disp(), game_config(), state_);
+ load.load_multiplayer_game();
}
catch (load_game_cancelled_exception){
set_result(CREATE);
Modified: trunk/src/savegame.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=34820&r1=34819&r2=34820&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Sun Apr 12 21:43:55 2009
@@ -102,24 +102,29 @@
if(game_config::wesnoth_version.minor_version() % 2 != 0 ||
game_config::wesnoth_version.major_version() !=
parsed_savegame_version.major_version() ||
game_config::wesnoth_version.minor_version() !=
parsed_savegame_version.minor_version()) {
- // do not load if too old, if either the savegame or
the current game
- // has the version 'test' allow loading
-
if(!game_config::is_compatible_savegame_version(gamestate_.version)) {
- /* GCC-3.3 needs a temp var otherwise
compilation fails */
- gui::message_dialog dlg(gui_, "", _("This save
is from a version too old to be loaded."));
- dlg.show();
- throw load_game_cancelled_exception();
- }
-
- const int res = gui::dialog(gui_,"",
- _("This save is
from a different version of the game. Do you want to try to load it?"),
-
gui::YES_NO).show();
- if(res == 1) {
- throw load_game_cancelled_exception();
- }
- }
- }
-
+ check_version_compatibility();
+ }
+ }
+
+}
+
+void loadgame::check_version_compatibility()
+{
+ // do not load if too old, if either the savegame or the current game
+ // has the version 'test' allow loading
+ if(!game_config::is_compatible_savegame_version(gamestate_.version)) {
+ /* GCC-3.3 needs a temp var otherwise compilation fails */
+ gui::message_dialog dlg(gui_, "", _("This save is from a
version too old to be loaded."));
+ dlg.show();
+ throw load_game_cancelled_exception();
+ }
+
+ const int res = gui::dialog(gui_,"",
+ _("This save is from a
different version of the game. Do you want to try to load it?"),
+ gui::YES_NO).show();
+ if(res == 1) {
+ throw load_game_cancelled_exception();
+ }
}
void loadgame::set_gamestate()
@@ -137,53 +142,34 @@
gamestate_.rng().seed_random(seed, calls);
}
-multiplayer_loadgame::multiplayer_loadgame(display& gui, const config&
game_config, game_state& gamestate)
- : loadgame(gui, game_config, gamestate)
-{}
-
-void multiplayer_loadgame::load_game()
+void loadgame::load_multiplayer_game()
{
show_dialog(false, NULL);
- if (this->filename().empty())
+ if (filename_.empty())
throw load_game_cancelled_exception();
std::string error_log;
{
cursor::setter cur(cursor::WAIT);
- ::load_game(this->filename(), gamestate(), &error_log);
+ ::load_game(filename_, gamestate_, &error_log);
}
if(!error_log.empty()) {
- gui::show_error_message(gui(),
+ gui::show_error_message(gui_,
_("The file you have tried to load is corrupt:
'") +
error_log);
throw load_game_cancelled_exception();
}
- if(gamestate().campaign_type != "multiplayer") {
+ if(gamestate_.campaign_type != "multiplayer") {
/* GCC-3.3 needs a temp var otherwise compilation fails */
- gui::message_dialog dlg(gui(), "", _("This is not a multiplayer
save"));
+ gui::message_dialog dlg(gui_, "", _("This is not a multiplayer
save"));
dlg.show();
throw load_game_cancelled_exception();
}
- if(gamestate().version != game_config::version) {
- // Do not load if too old, but if either the savegame or
- // the current game has the version 'test' allow loading.
-
if(!game_config::is_compatible_savegame_version(gamestate().version)) {
- /* GCC-3.3 needs a temp var otherwise compilation fails
*/
- gui::message_dialog dlg2(gui(), "", _("This save is
from a version too old to be loaded."));
- dlg2.show();
- throw load_game_cancelled_exception();
- }
-
- const int res = gui::dialog(gui(), "",
- _("This save is from a different version of the
game. Do you want to try to load it?"),
- gui::YES_NO).show();
- if(res == 1)
- throw load_game_cancelled_exception();
- }
+ check_version_compatibility();
}
savegame::savegame(game_state& gamestate, const std::string title)
Modified: trunk/src/savegame.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=34820&r1=34819&r2=34820&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Sun Apr 12 21:43:55 2009
@@ -32,21 +32,19 @@
loadgame(display& gui, const config& game_config, game_state&
gamestate);
virtual ~loadgame() {}
- virtual void load_game();
+ void load_game();
void load_game(std::string& filename, bool show_replay, bool
cancel_orders);
+ void load_multiplayer_game();
void set_gamestate();
bool show_replay() const { return show_replay_; }
bool cancel_orders() const { return cancel_orders_; }
const std::string filename() const { return filename_; }
-protected:
+private:
void show_dialog(bool show_replay, bool cancel_orders);
+ void check_version_compatibility();
- game_state& gamestate() const { return gamestate_; }
- display& gui() const { return gui_; }
-
-private:
const config& game_config_;
display& gui_;
@@ -55,14 +53,6 @@
config load_config_;
bool show_replay_;
bool cancel_orders_;
-};
-
-class multiplayer_loadgame : public loadgame
-{
-public:
- multiplayer_loadgame(display& gui, const config& game_config,
game_state& gamestate);
-
- virtual void load_game();
};
/** The base class for all savegame stuff */
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits