Simplify parent assignment still further,
...and compute the inverse relationship in the initializatoopn of the load_game dialog (it's not used yet).
This commit is contained in:
parent
e9e1a13506
commit
8c07aedc6a
2 changed files with 9 additions and 10 deletions
|
@ -568,8 +568,11 @@ std::string load_game_dialog(display& disp, const config& game_config, bool* sho
|
|||
|
||||
std::vector<config*> summaries;
|
||||
std::vector<save_info>::const_iterator i;
|
||||
//FIXME: parent_to_child is not used yet
|
||||
std::map<std::string,std::string> parent_to_child;
|
||||
for(i = games.begin(); i != games.end(); ++i) {
|
||||
config& cfg = save_index::save_summary(i->name);
|
||||
parent_to_child[cfg["parent"]] = i->name;
|
||||
summaries.push_back(&cfg);
|
||||
}
|
||||
|
||||
|
|
|
@ -602,7 +602,7 @@ void savegame::before_save()
|
|||
|
||||
bool savegame::save_game(CVideo* video, const std::string& filename)
|
||||
{
|
||||
static std::string parent, grandparent;
|
||||
static std::string parent, grandparent;
|
||||
|
||||
try {
|
||||
Uint32 start, end;
|
||||
|
@ -611,30 +611,25 @@ bool savegame::save_game(CVideo* video, const std::string& filename)
|
|||
if (filename_ == "")
|
||||
filename_ = filename;
|
||||
|
||||
bool overwriting = (filename_ == parent);
|
||||
|
||||
before_save();
|
||||
|
||||
// The magic moment that does save threading; after
|
||||
// each save, the filename of the save file becomes
|
||||
// the parent for the next. *Unless* the parent file
|
||||
// has the same name as the savefile, in which case we
|
||||
// restore the grandparent name. When user loads a
|
||||
// savegame, we load its correct parent link along with it.
|
||||
LOG_SAVE << "While saving '" << filename_ << "', parent is '" << gamestate_.parent << "' and grandparent is '" << grandparent << "'\n";
|
||||
|
||||
if (overwriting) {
|
||||
// use the grandparent name. When user loads a savegame,
|
||||
// we load its correct parent link along with it.
|
||||
if (filename_ == parent) {
|
||||
gamestate_.parent = grandparent;
|
||||
} else {
|
||||
gamestate_.parent = parent;
|
||||
}
|
||||
LOG_SAVE << "Setting file parent to " << gamestate_.parent << "\n";
|
||||
LOG_SAVE << "Setting parent of '" << filename_<< "' to " << gamestate_.parent << "\n";
|
||||
|
||||
write_game_to_disk(filename_);
|
||||
|
||||
grandparent = parent;
|
||||
parent = filename_;
|
||||
LOG_SAVE << "Setting parent to '" << parent << "' and grandparent to '" << grandparent << "'\n";
|
||||
|
||||
end = SDL_GetTicks();
|
||||
LOG_SAVE << "Milliseconds to save " << filename_ << ": " << end - start << "\n";
|
||||
|
@ -771,6 +766,7 @@ void savegame::extract_summary_data_from_save(config& out)
|
|||
out["snapshot"] = has_snapshot ? "yes" : "no";
|
||||
|
||||
out["label"] = gamestate_.label;
|
||||
out["parent"] = gamestate_.parent;
|
||||
out["campaign"] = gamestate_.campaign;
|
||||
out["campaign_type"] = gamestate_.campaign_type;
|
||||
out["scenario"] = gamestate_.scenario;
|
||||
|
|
Loading…
Add table
Reference in a new issue