Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize weather into the main game save. #35661

Merged
merged 6 commits into from
Nov 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Save weather data as part of the master game file
This ensures each character in the world has the same weather.

And save it as JSON data.
BevapDin committed Nov 22, 2019

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit 3c8d8376b62447ee94a0ebb2649b5fc4baf6dd42
7 changes: 1 addition & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
@@ -2668,8 +2668,6 @@ void game::load( const save_t &name )
u.deserialize_map_memory( jsin );
} );

read_from_file_optional( worldpath + name.base_path() + ".weather", std::bind( &game::load_weather,
this, _1 ) );
weather.nextweather = calendar::turn;

read_from_file_optional( worldpath + name.base_path() + ".log",
@@ -2878,9 +2876,6 @@ bool game::save_player_data()
JsonOut jsout( fout );
u.serialize_map_memory( jsout );
}, _( "player map memory" ) );
const bool saved_weather = write_to_file( playerfile + ".weather", [&]( std::ostream & fout ) {
save_weather( fout );
}, _( "weather state" ) );
const bool saved_log = write_to_file( playerfile + ".log", [&]( std::ostream & fout ) {
fout << memorial().dump();
}, _( "player memorial" ) );
@@ -2890,7 +2885,7 @@ bool game::save_player_data()
}, _( "quick shortcuts" ) );
#endif

return saved_data && saved_map_memory && saved_weather && saved_log
return saved_data && saved_map_memory && saved_log
#if defined(__ANDROID__)
&& saved_shortcuts
#endif
2 changes: 0 additions & 2 deletions src/game.h
Original file line number Diff line number Diff line change
@@ -709,7 +709,6 @@ class game
// Game-start procedures
void load( const save_t &name ); // Load a player-specific save file
void load_master(); // Load the master data file, with factions &c
void load_weather( std::istream &fin );
#if defined(__ANDROID__)
void load_shortcuts( std::istream &fin );
#endif
@@ -724,7 +723,6 @@ class game
bool save_artifacts();
// returns false if saving failed for whatever reason
bool save_maps();
void save_weather( std::ostream &fout );
#if defined(__ANDROID__)
void save_shortcuts( std::ostream &fout );
#endif
50 changes: 10 additions & 40 deletions src/savegame.cpp
Original file line number Diff line number Diff line change
@@ -263,46 +263,6 @@ void scent_map::deserialize( const std::string &data )
}
}

///// weather
void game::load_weather( std::istream &fin )
{
if( fin.peek() == '#' ) {
std::string vline;
getline( fin, vline );
std::string tmphash;
std::string tmpver;
int savedver = -1;
std::stringstream vliness( vline );
vliness >> tmphash >> tmpver >> savedver;
if( tmpver == "version" && savedver != -1 ) {
savegame_loading_version = savedver;
}
}

//Check for "lightning:" marker - if absent, ignore
if( fin.peek() == 'l' ) {
std::string line;
getline( fin, line );
weather.lightning_active = line == "lightning: 1";
} else {
weather.lightning_active = false;
}
if( fin.peek() == 's' ) {
std::string line;
std::string label;
getline( fin, line );
std::stringstream liness( line );
liness >> label >> seed;
}
}

void game::save_weather( std::ostream &fout )
{
fout << "# version " << savegame_version << std::endl;
fout << "lightning: " << ( weather.lightning_active ? "1" : "0" ) << std::endl;
fout << "seed: " << seed;
}

#if defined(__ANDROID__)
///// quick shortcuts
void game::load_shortcuts( std::istream &fin )
@@ -1620,6 +1580,10 @@ void game::unserialize_master( std::istream &fin )
mission::unserialize_all( jsin );
} else if( name == "factions" ) {
jsin.read( *faction_manager_ptr );
} else if( name == "weather" ) {
JsonObject w = jsin.get_object();
w.read( "lightning", weather.lightning_active );
w.read( "seed", seed );
} else {
// silently ignore anything else
jsin.skip_value();
@@ -1654,6 +1618,12 @@ void game::serialize_master( std::ostream &fout )

json.member( "factions", *faction_manager_ptr );

json.member( "weather" );
json.start_object();
json.member( "lightning", weather.lightning_active );
json.member( "seed", seed );
json.end_object();

json.end_object();
} catch( const JsonError &e ) {
debugmsg( "error saving to master.gsav: %s", e.c_str() );