Author: jhinrichs
Date: Tue Apr 7 22:49:05 2009
New Revision: 34622
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34622&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and
loading.
Adding comments for savegame.hpp.
Modified:
trunk/src/savegame.cpp
trunk/src/savegame.hpp
Modified: trunk/src/savegame.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=34622&r1=34621&r2=34622&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Tue Apr 7 22:49:05 2009
@@ -81,8 +81,6 @@
assert(SDL_SemValue(sem_) == 0);
SDL_SemPost(sem_);
}
-
-// Prototypes
void savegame::save_game_interactive(display& gui, const std::string& message,
gui::DIALOG_TYPE dialog_type, const bool has_exit_button,
@@ -303,110 +301,3 @@
gui_.labels().write(snapshot());
}
-//// Interactive replay save
-//void save_replay(std::string filename, game_state& gamestate)
-//{
-// // Create an empty snapshot
-// config snapshot;
-//
-// // FIXME
-// // Doesn't make too much sense at the moment but will, once
-// // including the savegame dialog here is done
-// //save_game(filename, snapshot, gamestate);
-//}
-//
-//// Automatic replay save at the end of the scenario
-//void save_replay(game_state& gamestate)
-//{
-// // FIXME:
-// // We create a copy here in order to avoid having to change the original
-// // gamestate. Once we made sure the player information is within
-// // [replay_start] only, this whole stuff is no longer needed.
-// game_state saveInfo = gamestate;
-//
-// // If the starting position contains player information, use this for
-// // the replay savegame (this originally comes from the gamestate
constructor,
-// // where the player stuff is added to the starting position to be used
here.
-// config::child_itors player_list =
gamestate.starting_pos.child_range("player");
-// if (player_list.first != player_list.second) {
-// saveInfo.players.clear();
-// saveInfo.load_recall_list(player_list);
-// }
-//
-// // Create an empty snapshot
-// config snapshot;
-//
-// std::string filename = gamestate.label + _(" replay");
-// //save_game(filename, snapshot, saveInfo);
-//
-// // clear replay data and snapshot for the next scenario
-// gamestate.replay_data = config();
-// gamestate.snapshot = config();
-//}
-
-///** Autosave */
-//std::string save_autosave(unsigned turn, const config& snapshot, game_state&
gamestate)
-//{
-// std::string filename;
-// if (gamestate.label.empty())
-// filename = _("Auto-Save");
-// else
-// filename = gamestate.label + "-" + _("Auto-Save") +
lexical_cast<std::string>(turn);
-//
-// //save_game(filename, snapshot, gamestate);
-//
-// return filename;
-//}
-
-//void save_game(std::string& filename, const config& snapshot, game_state&
gamestate)
-//{
-// LOG_SAVE << "savegame::save_game";
-//
-// if(preferences::compress_saves()) {
-// filename += ".gz";
-// }
-//
-// std::stringstream ss;
-// {
-// config_writer out(ss, preferences::compress_saves());
-// ::write_game(out, snapshot, gamestate);
-// finish_save_game(out, gamestate, gamestate.label);
-// }
-// scoped_ostream os(open_save_game(filename));
-// (*os) << ss.str();
-//
-// if (!os->good()) {
-// throw game::save_game_failed(_("Could not write to file"));
-// }
-//}
-//
-//std::string create_filename(const std::string& filename_base, const unsigned
turn)
-//{
-// std::stringstream stream;
-//
-// const std::string ellipsed_name =
font::make_text_ellipsis(filename_base,
-// font::SIZE_NORMAL, 200);
-// stream << ellipsed_name << " " << _("Turn") << " " << turn;
-// std::string filename = stream.str();
-//
-// filename.erase(std::remove_if(filename.begin(), filename.end(),
-// dialogs::is_illegal_file_char), filename.end());
-//
-// return filename;
-//}
-//
-//std::string create_replay_filename(const std::string& filename_base)
-//{
-// std::stringstream stream;
-//
-// const std::string ellipsed_name =
font::make_text_ellipsis(filename_base,
-// font::SIZE_NORMAL, 200);
-// stream << ellipsed_name << " " << _("replay");
-// std::string filename = stream.str();
-//
-// filename.erase(std::remove_if(filename.begin(), filename.end(),
-// dialogs::is_illegal_file_char), filename.end());
-//
-// return filename;
-//}
-
Modified: trunk/src/savegame.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=34622&r1=34621&r2=34622&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Tue Apr 7 22:49:05 2009
@@ -50,15 +50,25 @@
static SDL_sem* sem_;
};
+/** The base class for all savegame stuff */
class savegame
{
public:
+ /** The only constructor of savegame. The title parameter is only
necessary if you
+ intend to do interactive saves. */
savegame(game_state& gamestate, const std::string title = "Save");
virtual ~savegame() {}
+ /** Save a game without any further user interaction. Atm, this is only
used by the
+ console_handler save actions */
void save_game(const std::string& filename);
+ /** Save a game without any further user interaction. This is used by
autosaves and
+ automatically generated replay saves. If you want notifying
messages or error messages
+ to appear, you have to provide the gui parameter. */
void save_game(display* gui = NULL);
+ /** Save a game interactively through the savegame dialog. Used for
manual midgame and replay
+ saves. */
void save_game_interactive(display& gui, const std::string& message,
gui::DIALOG_TYPE dialog_type, const bool has_exit_button =
false,
const bool ask_for_filename = true);
@@ -66,27 +76,46 @@
const std::string filename() const { return filename_; }
protected:
+ /** Sets the filename and removes invalid characters. Don't set the
filename directly but
+ use this method instead. */
void set_filename(std::string filename);
+ /** Customize the standard error message */
void set_error_message(std::string error_message) { error_message_ =
error_message; }
game_state& gamestate() { return gamestate_; }
config& snapshot() { return snapshot_; }
+ /** If there needs to be some data fiddling before saving the game,
this is the place to go. */
virtual void before_save();
private:
+ /** Build the filename according to the specific savegame's needs.
Subclasses will have to
+ override this to take effect. */
virtual void create_filename() {}
+ /** For normal game saves. Builds a snapshot config object out of the
relevant information. */
virtual void write_game_snapshot(const display& /*gui*/) {}
+ /** The actual method for saving the game to disk. All interactive
filename choosing and
+ data manipulation has to happen before calling this method */
void save_game_internal(const std::string& filename);
game_state& gamestate_;
+ /** Gamestate information at the time of saving. Note that this object
is needed here, since
+ even if it is empty the code relies on it to be there. */
config snapshot_;
+ /** Filename of the savegame file on disk */
std::string filename_;
+ /** Title of the savegame dialog */
const std::string title_;
+ /** Error message to be displayed if the savefile could not be
generated. */
std::string error_message_;
+ /** Determines if the save is done interactively or not. This controls
if a filename is
+ generated automatically (interactive = false) and if a message
is displayed that the
+ game was successfully saved (interactive = true). */
bool interactive_;
};
+/** Class for "normal" midgame saves. The additional members are needed for
creating the snapshot
+ information. */
class game_savegame : public savegame
{
public:
@@ -97,6 +126,7 @@
private:
virtual void create_filename();
+ /** Builds the snapshot config. */
virtual void before_save();
void write_game_snapshot();
@@ -109,6 +139,7 @@
const gamemap& map_;
};
+/** Class for replay saves (either manually or automatically). */
class replay_savegame : public savegame
{
public:
@@ -118,6 +149,7 @@
virtual void create_filename();
};
+/** Class for autosaves. */
class autosave_savegame : public game_savegame
{
public:
@@ -130,25 +162,15 @@
virtual void create_filename();
};
+/** Class for start-of-scenario saves */
class scenariostart_savegame : public savegame
{
public:
scenariostart_savegame(game_state& gamestate);
private:
+ /** Adds the player information to the starting position (=
[replay_start]). */
virtual void before_save();
};
-///** Autosave */
-//std::string save_autosave(unsigned turn, const config& snapshot, game_state&
gamestate);
-//
-///** Replay save created by player interaction */
-//void save_replay(std::string filename, game_state& gamestate);
-//
-///** Replay save, created automatically at the end of a scenario */
-//void save_replay(game_state& gamestate);
-//
-//std::string create_filename(const std::string& filename_base, const unsigned
turn);
-//std::string create_replay_filename(const std::string& filename_base);
-
#endif
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits