Author: cazfi Date: Wed Jan 6 21:14:44 2016 New Revision: 31395 URL: http://svn.gna.org/viewcvs/freeciv?rev=31395&view=rev Log: Added main savegame.c and have the main savegame loading and saving entry points there.
See patch #6776 Added: trunk/server/savegame.c Modified: trunk/server/Makefile.am trunk/server/savegame.h trunk/server/savegame2.c trunk/server/savegame2.h trunk/server/savegame3.c trunk/server/savegame3.h Modified: trunk/server/Makefile.am URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/Makefile.am?rev=31395&r1=31394&r2=31395&view=diff ============================================================================== --- trunk/server/Makefile.am (original) +++ trunk/server/Makefile.am Wed Jan 6 21:14:44 2016 @@ -96,6 +96,7 @@ sanitycheck.h \ savecompat.c \ savecompat.h \ + savegame.c \ savegame.h \ savegame2.c \ savegame2.h \ Added: trunk/server/savegame.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=31395&view=auto ============================================================================== --- trunk/server/savegame.c (added) +++ trunk/server/savegame.c Wed Jan 6 21:14:44 2016 @@ -0,0 +1,81 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <fc_config.h> +#endif + +/* utility */ +#include "log.h" +#include "registry.h" + +/* common */ +#include "capability.h" + +/* server */ +#include "legacysave.h" +#include "savegame2.h" +#include "savegame3.h" + +#include "savegame.h" + +/**************************************************************************** + Main entry point for loading a game. +****************************************************************************/ +void savegame_load(struct section_file *sfile) +{ + const char *savefile_options; + + fc_assert_ret(sfile != NULL); + +#ifdef DEBUG_TIMERS + struct timer *loadtimer = timer_new(TIMER_CPU, TIMER_DEBUG); + timer_start(loadtimer); +#endif + + savefile_options = secfile_lookup_str(sfile, "savefile.options"); + + if (!savefile_options) { + log_error("Missing savefile options. Can not load the savegame."); + return; + } + + if (has_capabilities("+version3", savefile_options)) { + /* load new format (freeciv 3.0.x and newer) */ + log_verbose("loading savefile in 3.0+ format ..."); + savegame3_load(sfile); + } else if (has_capabilities("+version2", savefile_options)) { + /* load old format (freeciv 2.3 - 2.6) */ + log_verbose("loading savefile in 2.3 - 2.6 format ..."); + savegame2_load(sfile); + } else { + log_verbose("loading savefile in legacy format ..."); + secfile_allow_digital_boolean(sfile, TRUE); + legacy_game_load(sfile); + } + +#ifdef DEBUG_TIMERS + timer_stop(loadtimer); + log_debug("Loading secfile in %.3f seconds.", timer_read_seconds(loadtimer)); + timer_destroy(loadtimer); +#endif /* DEBUG_TIMERS */ +} + +/**************************************************************************** + Main entry point for saving a game. +****************************************************************************/ +void savegame_save(struct section_file *sfile, const char *save_reason, + bool scenario) +{ + savegame3_save(sfile, save_reason, scenario); +} Modified: trunk/server/savegame.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.h?rev=31395&r1=31394&r2=31395&view=diff ============================================================================== --- trunk/server/savegame.h (original) +++ trunk/server/savegame.h Wed Jan 6 21:14:44 2016 @@ -13,10 +13,13 @@ #ifndef FC__SAVEGAME_H #define FC__SAVEGAME_H +/* utility */ +#include "support.h" + struct section_file; -void savegame_load(struct section_file *file); -void savegame_save(struct section_file *file, const char *save_reason, +void savegame_load(struct section_file *sfile); +void savegame_save(struct section_file *sfile, const char *save_reason, bool scenario); #endif /* FC__SAVEGAME_H */ Modified: trunk/server/savegame2.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=31395&r1=31394&r2=31395&view=diff ============================================================================== --- trunk/server/savegame2.c (original) +++ trunk/server/savegame2.c Wed Jan 6 21:14:44 2016 @@ -22,10 +22,7 @@ Structure of this file: - - The main function is savegame2_load(). The savegame version is tested and - the requested savegame version is loaded. - - - The real work is done by savegame2_load_real(). + - The real work is done by savegame2_load(). This function call all submodules (settings, players, etc.) - The remaining part of this file is split into several sections: @@ -46,7 +43,7 @@ Loading a savegame: - The status of the process is saved within the static variable - 'sg_success'. This variable is set to TRUE within savegame2_load_real(). + 'sg_success'. This variable is set to TRUE within savegame2_load(). If you encounter an error use sg_failure_*() to set it to FALSE and return an error message. Furthermore, sg_check_* should be used at the start of each (submodule) function to return if previous functions failed. @@ -107,7 +104,6 @@ #include "citytools.h" #include "cityturn.h" #include "diplhand.h" -#include "legacysave.h" #include "maphand.h" #include "meta.h" #include "notify.h" @@ -284,7 +280,6 @@ static const char num_chars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+"; -static void savegame2_load_real(struct section_file *file); static struct loaddata *loaddata_new(struct section_file *file); static void loaddata_destroy(struct loaddata *loading); @@ -379,36 +374,6 @@ static void sg_load_sanitycheck(struct loaddata *loading); -/**************************************************************************** - Main entry point for loading a game. - Called only in ./server/stdinhand.c:load_command(). - The entire ruleset is always sent afterwards-> -****************************************************************************/ -void savegame2_load(struct section_file *file) -{ - const char *savefile_options; - - fc_assert_ret(file != NULL); - - savefile_options = secfile_lookup_str(file, "savefile.options"); - - if (!savefile_options) { - log_error("Missing savefile options. Can not load the savegame."); - return; - } - - if (!has_capabilities("+version2", savefile_options)) { - /* load old format (freeciv 2.2.x) */ - log_verbose("loading savefile in old format ..."); - secfile_allow_digital_boolean(file, TRUE); - legacy_game_load(file); - } else { - /* load new format (freeciv 2.2.99 and newer) */ - log_verbose("loading savefile in format 2..."); - savegame2_load_real(file); - } -} - /* ======================================================================= * Basic load / save functions. * ======================================================================= */ @@ -416,7 +381,7 @@ /**************************************************************************** Really loading the savegame. ****************************************************************************/ -static void savegame2_load_real(struct section_file *file) +void savegame2_load(struct section_file *file) { struct loaddata *loading; bool was_send_city_suppressed, was_send_tile_suppressed; Modified: trunk/server/savegame2.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.h?rev=31395&r1=31394&r2=31395&view=diff ============================================================================== --- trunk/server/savegame2.h (original) +++ trunk/server/savegame2.h Wed Jan 6 21:14:44 2016 @@ -15,6 +15,6 @@ struct section_file; -void savegame2_load(struct section_file *file); +void savegame2_load(struct section_file *sfile); #endif /* FC__SAVEGAME2_H */ Modified: trunk/server/savegame3.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=31395&r1=31394&r2=31395&view=diff ============================================================================== --- trunk/server/savegame3.c (original) +++ trunk/server/savegame3.c Wed Jan 6 21:14:44 2016 @@ -22,11 +22,9 @@ Structure of this file: - - The main functions are savegame_load() and savegame_save(). Within - former function the savegame version is tested and the requested savegame version is - loaded. - - - The real work is done by savegame3_load_real() and savegame3_save_real(). + - The main function for saving is savegame3_save(). + + - The real work is done by savegame3_load() and savegame3_save_real(). This function call all submodules (settings, players, etc.) - The remaining part of this file is split into several sections: @@ -51,7 +49,7 @@ Loading a savegame: - The status of the process is saved within the static variable - 'sg_success'. This variable is set to TRUE within savegame3_load_real(). + 'sg_success'. This variable is set to TRUE within savegame3_load(). If you encounter an error use sg_failure_*() to set it to FALSE and return an error message. Furthermore, sg_check_* should be used at the start of each (submodule) function to return if previous functions failed. @@ -120,7 +118,6 @@ #include "ruleset.h" #include "sanitycheck.h" #include "savecompat.h" -#include "savegame2.h" #include "score.h" #include "settings.h" #include "spacerace.h" @@ -277,7 +274,6 @@ static const char num_chars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+"; -static void savegame3_load_real(struct section_file *file); static void savegame3_save_real(struct section_file *file, const char *save_reason, bool scenario); @@ -416,53 +412,12 @@ /**************************************************************************** - Main entry point for loading a game. - Called only in ./server/stdinhand.c:load_command(). - The entire ruleset is always sent afterwards-> -****************************************************************************/ -void savegame_load(struct section_file *file) -{ - const char *savefile_options; - - fc_assert_ret(file != NULL); - -#ifdef DEBUG_TIMERS - struct timer *loadtimer = timer_new(TIMER_CPU, TIMER_DEBUG); - timer_start(loadtimer); -#endif - - savefile_options = secfile_lookup_str(file, "savefile.options"); - - if (!savefile_options) { - log_error("Missing savefile options. Can not load the savegame."); - return; - } - - if (!has_capabilities("+version3", savefile_options)) { - /* load old format (freeciv 2.6.x or older) */ - log_verbose("loading savefile in old format ..."); - savegame2_load(file); - } else { - /* load new format (freeciv 3.0.x and newer) */ - log_verbose("loading savefile in new format ..."); - savegame3_load_real(file); - } - -#ifdef DEBUG_TIMERS - timer_stop(loadtimer); - log_debug("Loading secfile in %.3f seconds.", timer_read_seconds(loadtimer)); - timer_destroy(loadtimer); -#endif /* DEBUG_TIMERS */ -} - -/**************************************************************************** - Main entry point for saving a game. - Called only in ./server/srv_main.c:save_game(). -****************************************************************************/ -void savegame_save(struct section_file *file, const char *save_reason, - bool scenario) -{ - fc_assert_ret(file != NULL); + Main entry point for saving a game in savegame3 format. +****************************************************************************/ +void savegame3_save(struct section_file *sfile, const char *save_reason, + bool scenario) +{ + fc_assert_ret(sfile != NULL); #ifdef DEBUG_TIMERS struct timer *savetimer = timer_new(TIMER_CPU, TIMER_DEBUG); @@ -470,7 +425,7 @@ #endif log_verbose("saving game in new format ..."); - savegame3_save_real(file, save_reason, scenario); + savegame3_save_real(sfile, save_reason, scenario); #ifdef DEBUG_TIMERS timer_stop(savetimer); @@ -486,7 +441,7 @@ /**************************************************************************** Really loading the savegame. ****************************************************************************/ -static void savegame3_load_real(struct section_file *file) +void savegame3_load(struct section_file *file) { struct loaddata *loading; bool was_send_city_suppressed, was_send_tile_suppressed; Modified: trunk/server/savegame3.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.h?rev=31395&r1=31394&r2=31395&view=diff ============================================================================== --- trunk/server/savegame3.h (original) +++ trunk/server/savegame3.h Wed Jan 6 21:14:44 2016 @@ -13,10 +13,8 @@ #ifndef FC__SAVEGAME3_H #define FC__SAVEGAME3_H -/* Server */ -#include "savegame.h" - -/* Currently savegame3.c implements the main savegame functionality, - * not fallback functionality like older savegame modules. */ +void savegame3_load(struct section_file *sfile); +void savegame3_save(struct section_file *sfile, const char *save_reason, + bool scenario); #endif /* FC__SAVEGAME3_H */ _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits