Author: jhinrichs
Date: Wed Apr 8 18:44:34 2009
New Revision: 34636
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34636&view=rev
Log:
Savegame reorganization Step 1: Providing a simpler interface to saving and
loading.
Move write_game to savegame.cpp.
Modified:
trunk/src/gamestatus.cpp
trunk/src/gamestatus.hpp
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=34636&r1=34635&r2=34636&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Wed Apr 8 18:44:34 2009
@@ -654,58 +654,6 @@
::write_player(i->second, new_cfg);
new_cfg["save_id"]=i->first;
cfg.add_child("player", new_cfg);
- }
-}
-
-void write_game(config_writer &out, const config& snapshot, const game_state&
gamestate, WRITE_GAME_MODE mode)
-{
- log_scope("write_game");
-
- out.write_key_val("label", gamestate.label);
- out.write_key_val("history", gamestate.history);
- out.write_key_val("abbrev", gamestate.abbrev);
- out.write_key_val("version", game_config::version);
- out.write_key_val("scenario", gamestate.scenario);
- out.write_key_val("next_scenario", gamestate.next_scenario);
- out.write_key_val("completion", gamestate.completion);
- out.write_key_val("campaign", gamestate.campaign);
- out.write_key_val("campaign_type", gamestate.campaign_type);
- out.write_key_val("difficulty", gamestate.difficulty);
- out.write_key_val("campaign_define", gamestate.campaign_define);
- out.write_key_val("campaign_extra_defines",
utils::join(gamestate.campaign_xtra_defines));
- out.write_key_val("random_seed",
lexical_cast<std::string>(gamestate.rng().get_random_seed()));
- out.write_key_val("random_calls",
lexical_cast<std::string>(gamestate.rng().get_random_calls()));
- out.write_key_val("next_underlying_unit_id",
lexical_cast<std::string>(n_unit::id_manager::instance().get_save_id()));
- out.write_key_val("end_text", gamestate.end_text);
- out.write_key_val("end_text_duration", str_cast<unsigned
int>(gamestate.end_text_duration));
- out.write_child("variables", gamestate.get_variables());
-
- for(std::map<std::string, wml_menu_item *>::const_iterator
j=gamestate.wml_menu_items.begin();
- j!=gamestate.wml_menu_items.end(); ++j) {
- out.open_child("menu_item");
- out.write_key_val("id", j->first);
- out.write_key_val("image", j->second->image);
- out.write_key_val("description", j->second->description);
- out.write_key_val("needs_select", (j->second->needs_select) ?
"yes" : "no");
- if(!j->second->show_if.empty())
- out.write_child("show_if", j->second->show_if);
- if(!j->second->filter_location.empty())
- out.write_child("filter_location",
j->second->filter_location);
- if(!j->second->command.empty())
- out.write_child("command", j->second->command);
- out.close_child("menu_item");
- }
-
- if(mode == WRITE_FULL_GAME) {
- if (!gamestate.replay_data.child("replay")) {
- out.write_child("replay", gamestate.replay_data);
- }
-
- out.write_child("snapshot",snapshot);
- out.write_child("replay_start",gamestate.starting_pos);
- out.open_child("statistics");
- statistics::write_stats(out);
- out.close_child("statistics");
}
}
Modified: trunk/src/gamestatus.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=34636&r1=34635&r2=34636&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Wed Apr 8 18:44:34 2009
@@ -315,12 +315,9 @@
/** Get a list of available saves. */
std::vector<save_info> get_saves_list(const std::string* dir = NULL, const
std::string* filter = NULL);
-enum WRITE_GAME_MODE { WRITE_SNAPSHOT_ONLY, WRITE_FULL_GAME };
-
void read_save_file(const std::string& name, config& cfg, std::string*
error_log);
void write_players(game_state& gamestate, config& cfg);
-void write_game(config_writer &out, const config& snapshot, const game_state&
gamestate, WRITE_GAME_MODE mode=WRITE_FULL_GAME);
/** Returns true iff there is already a savegame with that name. */
bool save_game_exists(const std::string & name);
Modified: trunk/src/savegame.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.cpp?rev=34636&r1=34635&r2=34636&view=diff
==============================================================================
--- trunk/src/savegame.cpp (original)
+++ trunk/src/savegame.cpp Wed Apr 8 18:44:34 2009
@@ -27,6 +27,7 @@
#include "replay.hpp"
#include "serialization/binary_or_text.hpp"
#include "sound.hpp"
+#include "statistics.hpp"
#define LOG_SAVE LOG_STREAM(info, engine)
@@ -101,7 +102,7 @@
std::stringstream ss;
{
config_writer out(ss, preferences::compress_saves());
- ::write_game(out, snapshot_, gamestate_);
+ write_game(out);
finish_save_game(out);
}
scoped_ostream os(open_save_game(filename_));
@@ -112,7 +113,57 @@
}
}
-void savegame::finish_save_game(config_writer &out)
+void savegame::write_game(config_writer &out) const
+{
+ log_scope("write_game");
+
+ out.write_key_val("label", gamestate_.label);
+ out.write_key_val("history", gamestate_.history);
+ out.write_key_val("abbrev", gamestate_.abbrev);
+ out.write_key_val("version", game_config::version);
+ out.write_key_val("scenario", gamestate_.scenario);
+ out.write_key_val("next_scenario", gamestate_.next_scenario);
+ out.write_key_val("completion", gamestate_.completion);
+ out.write_key_val("campaign", gamestate_.campaign);
+ out.write_key_val("campaign_type", gamestate_.campaign_type);
+ out.write_key_val("difficulty", gamestate_.difficulty);
+ out.write_key_val("campaign_define", gamestate_.campaign_define);
+ out.write_key_val("campaign_extra_defines",
utils::join(gamestate_.campaign_xtra_defines));
+ out.write_key_val("random_seed",
lexical_cast<std::string>(gamestate_.rng().get_random_seed()));
+ out.write_key_val("random_calls",
lexical_cast<std::string>(gamestate_.rng().get_random_calls()));
+ out.write_key_val("next_underlying_unit_id",
lexical_cast<std::string>(n_unit::id_manager::instance().get_save_id()));
+ out.write_key_val("end_text", gamestate_.end_text);
+ out.write_key_val("end_text_duration", str_cast<unsigned
int>(gamestate_.end_text_duration));
+ out.write_child("variables", gamestate_.get_variables());
+
+ for(std::map<std::string, wml_menu_item *>::const_iterator
j=gamestate_.wml_menu_items.begin();
+ j!=gamestate_.wml_menu_items.end(); ++j) {
+ out.open_child("menu_item");
+ out.write_key_val("id", j->first);
+ out.write_key_val("image", j->second->image);
+ out.write_key_val("description", j->second->description);
+ out.write_key_val("needs_select", (j->second->needs_select) ?
"yes" : "no");
+ if(!j->second->show_if.empty())
+ out.write_child("show_if", j->second->show_if);
+ if(!j->second->filter_location.empty())
+ out.write_child("filter_location",
j->second->filter_location);
+ if(!j->second->command.empty())
+ out.write_child("command", j->second->command);
+ out.close_child("menu_item");
+ }
+
+ if (!gamestate_.replay_data.child("replay")) {
+ out.write_child("replay", gamestate_.replay_data);
+ }
+
+ out.write_child("snapshot",snapshot_);
+ out.write_child("replay_start",gamestate_.starting_pos);
+ out.open_child("statistics");
+ statistics::write_stats(out);
+ out.close_child("statistics");
+}
+
+void savegame::finish_save_game(const config_writer &out)
{
std::string name = gamestate_.label;
std::replace(name.begin(),name.end(),' ','_');
Modified: trunk/src/savegame.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/savegame.hpp?rev=34636&r1=34635&r2=34636&view=diff
==============================================================================
--- trunk/src/savegame.hpp (original)
+++ trunk/src/savegame.hpp Wed Apr 8 18:44:34 2009
@@ -19,6 +19,7 @@
#include "global.hpp"
#include "show_dialog.hpp"
#include "gamestatus.hpp"
+#include "unit_id.hpp"
#include <string>
@@ -73,7 +74,8 @@
data manipulation has to happen before calling this method */
void save_game_internal(const std::string& filename);
- void finish_save_game(config_writer &out);
+ void write_game(config_writer &out) const;
+ void finish_save_game(const config_writer &out);
void extract_summary_data_from_save(config& out);
game_state& gamestate_;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits