Savegame reorganization Step 1: a simpler interface to saving and loading.

Providing a new file savegame.cpp for dealing with savegames. This is
only a first throw, much of the savegame functionality will have to be
transferred to this file in subsequent steps.

Disclaimer: This is a pain to do without breaking anything. I'll do my
best to test everything before i commit. However, expect some stuff to
slip through now and then.
This commit is contained in:
Jörg Hinrichs 2009-03-31 20:33:55 +00:00
parent e3c96c20c9
commit 4182bafab4
10 changed files with 477 additions and 463 deletions

View file

@ -45,6 +45,8 @@ Version 1.7.0-svn:
now (bug #13170)
* Added a "preload" WML event type.
* Added support for Lua scripts in WML event actions ([lua] tag)
* Savegames
* Providing a new simpler interface for dealing with savegames
* Miscellaneous and bugfixes:
* Fixed compilation with -D_GLIBCXX_PARALLEL
* Fixed handling of floating-point WML constants on localized Windows

View file

@ -301,6 +301,7 @@ SET(wesnoth-main_SRC
portrait.cpp
replay.cpp
replay_controller.cpp
savegame.cpp
scripting/lua.cpp
sha1.cpp
settings.cpp

View file

@ -138,6 +138,7 @@ wesnoth_source = \
portrait.cpp \
replay.cpp \
replay_controller.cpp \
savegame.cpp \
scripting/lua.cpp \
sha1.cpp \
settings.cpp \

View file

@ -1,406 +1,407 @@
# vi: syntax=python:et:ts=4
import commands, os
from subprocess import Popen, PIPE
from glob import glob
Import("*")
env.Append(CPPDEFINES = "$EXTRA_DEFINE")
test_env.Append(CPPDEFINES = "$EXTRA_DEFINE")
#color_range.cpp should be removed, but game_config depends on it.
#game_config has very few things that are needed elsewhere, it should be
#removed. Requires moving path and version at least to other files.
libwesnoth_core_sources = Split("""
color_range.cpp
config.cpp
gettext.cpp
# vi: syntax=python:et:ts=4
import commands, os
from subprocess import Popen, PIPE
from glob import glob
Import("*")
env.Append(CPPDEFINES = "$EXTRA_DEFINE")
test_env.Append(CPPDEFINES = "$EXTRA_DEFINE")
#color_range.cpp should be removed, but game_config depends on it.
#game_config has very few things that are needed elsewhere, it should be
#removed. Requires moving path and version at least to other files.
libwesnoth_core_sources = Split("""
color_range.cpp
config.cpp
gettext.cpp
hash.cpp
log.cpp
map.cpp
map_location.cpp
md5.cpp
network.cpp
thread.cpp
tstring.cpp
util.cpp
version.cpp
serialization/binary_or_text.cpp
serialization/binary_wml.cpp
serialization/parser.cpp
serialization/preprocessor.cpp
serialization/string_utils.cpp
serialization/tokenizer.cpp
""")
if env["pool_alloc"]:
libwesnoth_core_sources.extend(Split("""
malloc.c
poolalloc.c
"""))
libwesnoth_core_sources.extend(env.Object("network_worker.cpp", EXTRA_DEFINE = env['raw_sockets'] and "NETWORK_USE_RAW_SOCKETS" or None))
game_config_env = env.Clone()
filesystem_env = env.Clone()
if env["PLATFORM"] != "win32":
game_config_env.Append(CPPDEFINES = "WESNOTH_PATH='\"$datadir\"'")
if env['localedirname']:
filesystem_env.Append(CPPDEFINES = "LOCALEDIR='\"$localedirname\"'")
if not os.path.isabs(env['localedirname']):
filesystem_env.Append(CPPDEFINES = "HAS_RELATIVE_LOCALEDIR")
if env['prefsdir']:
filesystem_env.Append(CPPDEFINES = "PREFERENCES_DIR='\"$prefsdir\"'")
libwesnoth_core_sources.extend([
game_config_env.Object("game_config.cpp"),
filesystem_env.Object("filesystem.cpp")
])
libwesnoth_core = env.Library("wesnoth_core", libwesnoth_core_sources)
libwesnoth_sources = Split("""
astarnode.cpp
astarsearch.cpp
builder.cpp
cavegen.cpp
clipboard.cpp
construct_dialog.cpp
cursor.cpp
display.cpp
events.cpp
filechooser.cpp
generic_event.cpp
hotkeys.cpp
image.cpp
image_function.cpp
key.cpp
language.cpp
loadscreen.cpp
map_create.cpp
map_label.cpp
mapgen.cpp
mapgen_dialog.cpp
marked-up_text.cpp
minimap.cpp
pathutils.cpp
preferences.cpp
preferences_display.cpp
race.cpp
random.cpp
reports.cpp
show_dialog.cpp
sound.cpp
soundsource.cpp
sound_music_track.cpp
terrain.cpp
terrain_translation.cpp
text.cpp
time_of_day.cpp
tooltips.cpp
video.cpp
theme.cpp
widgets/button.cpp
widgets/file_menu.cpp
widgets/label.cpp
widgets/menu.cpp
widgets/menu_style.cpp
widgets/progressbar.cpp
widgets/scrollarea.cpp
widgets/scrollbar.cpp
widgets/slider.cpp
widgets/textbox.cpp
widgets/widget.cpp
wml_exception.cpp
""")
libwesnoth_sources.extend([
env.Object("font.cpp", EXTRA_DEFINE = env['fribidi'] and "HAVE_FRIBIDI" or None),
])
libwesnoth = env.Library("wesnoth", libwesnoth_sources)
libwesnothd_sources = Split("""
loadscreen_empty.cpp
tools/dummy_video.cpp
""")
libwesnothd = env.Library("wesnothd", libwesnothd_sources)
libcampaignd_sources = Split("""
addon_checks.cpp
""")
libcampaignd = env.Library("campaignd", libcampaignd_sources)
libwesnoth_sdl_sources = Split("""
sdl_utils.cpp
""")
libwesnoth_sdl = env.Library("wesnoth_sdl", libwesnoth_sdl_sources)
libcutter_sources = Split("""
tools/exploder_utils.cpp
tools/exploder_cutter.cpp
""")
libcutter = env.Library("cutter", libcutter_sources)
# Used by both 'wesnoth' and 'test' targets
wesnoth_sources = Split("""
about.cpp
actions.cpp
addon_checks.cpp
addon_management.cpp
ai_dfool.cpp
ai_attack.cpp
log.cpp
map.cpp
map_location.cpp
md5.cpp
network.cpp
thread.cpp
tstring.cpp
util.cpp
version.cpp
serialization/binary_or_text.cpp
serialization/binary_wml.cpp
serialization/parser.cpp
serialization/preprocessor.cpp
serialization/string_utils.cpp
serialization/tokenizer.cpp
""")
if env["pool_alloc"]:
libwesnoth_core_sources.extend(Split("""
malloc.c
poolalloc.c
"""))
libwesnoth_core_sources.extend(env.Object("network_worker.cpp", EXTRA_DEFINE = env['raw_sockets'] and "NETWORK_USE_RAW_SOCKETS" or None))
game_config_env = env.Clone()
filesystem_env = env.Clone()
if env["PLATFORM"] != "win32":
game_config_env.Append(CPPDEFINES = "WESNOTH_PATH='\"$datadir\"'")
if env['localedirname']:
filesystem_env.Append(CPPDEFINES = "LOCALEDIR='\"$localedirname\"'")
if not os.path.isabs(env['localedirname']):
filesystem_env.Append(CPPDEFINES = "HAS_RELATIVE_LOCALEDIR")
if env['prefsdir']:
filesystem_env.Append(CPPDEFINES = "PREFERENCES_DIR='\"$prefsdir\"'")
libwesnoth_core_sources.extend([
game_config_env.Object("game_config.cpp"),
filesystem_env.Object("filesystem.cpp")
])
libwesnoth_core = env.Library("wesnoth_core", libwesnoth_core_sources)
libwesnoth_sources = Split("""
astarnode.cpp
astarsearch.cpp
builder.cpp
cavegen.cpp
clipboard.cpp
construct_dialog.cpp
cursor.cpp
display.cpp
events.cpp
filechooser.cpp
generic_event.cpp
hotkeys.cpp
image.cpp
image_function.cpp
key.cpp
language.cpp
loadscreen.cpp
map_create.cpp
map_label.cpp
mapgen.cpp
mapgen_dialog.cpp
marked-up_text.cpp
minimap.cpp
pathutils.cpp
preferences.cpp
preferences_display.cpp
race.cpp
random.cpp
reports.cpp
show_dialog.cpp
sound.cpp
soundsource.cpp
sound_music_track.cpp
terrain.cpp
terrain_translation.cpp
text.cpp
time_of_day.cpp
tooltips.cpp
video.cpp
theme.cpp
widgets/button.cpp
widgets/file_menu.cpp
widgets/label.cpp
widgets/menu.cpp
widgets/menu_style.cpp
widgets/progressbar.cpp
widgets/scrollarea.cpp
widgets/scrollbar.cpp
widgets/slider.cpp
widgets/textbox.cpp
widgets/widget.cpp
wml_exception.cpp
""")
libwesnoth_sources.extend([
env.Object("font.cpp", EXTRA_DEFINE = env['fribidi'] and "HAVE_FRIBIDI" or None),
])
libwesnoth = env.Library("wesnoth", libwesnoth_sources)
libwesnothd_sources = Split("""
loadscreen_empty.cpp
tools/dummy_video.cpp
""")
libwesnothd = env.Library("wesnothd", libwesnothd_sources)
libcampaignd_sources = Split("""
addon_checks.cpp
""")
libcampaignd = env.Library("campaignd", libcampaignd_sources)
libwesnoth_sdl_sources = Split("""
sdl_utils.cpp
""")
libwesnoth_sdl = env.Library("wesnoth_sdl", libwesnoth_sdl_sources)
libcutter_sources = Split("""
tools/exploder_utils.cpp
tools/exploder_cutter.cpp
""")
libcutter = env.Library("cutter", libcutter_sources)
# Used by both 'wesnoth' and 'test' targets
wesnoth_sources = Split("""
about.cpp
actions.cpp
addon_checks.cpp
addon_management.cpp
ai_dfool.cpp
ai_attack.cpp
ai_configuration.cpp
ai_manager.cpp
ai_move.cpp
ai_village.cpp
animated_game.cpp
attack_prediction.cpp
attack_prediction_display.cpp
callable_objects.cpp
config_adapter.cpp
controller_base.cpp
dialogs.cpp
floating_textbox.cpp
formula.cpp
formula_ai.cpp
formula_function.cpp
formula_tokenizer.cpp
formula_string_utils.cpp
game_display.cpp
game_events.cpp
game_preferences.cpp
gamestatus.cpp
generate_report.cpp
halo.cpp
help.cpp
intro.cpp
leader_list.cpp
menu_events.cpp
mouse_events.cpp
mouse_handler_base.cpp
multiplayer.cpp
multiplayer_ui.cpp
multiplayer_wait.cpp
multiplayer_create.cpp
multiplayer_lobby.cpp
pathfind.cpp
playcampaign.cpp
play_controller.cpp
playmp_controller.cpp
playsingle_controller.cpp
playturn.cpp
portrait.cpp
replay.cpp
replay_controller.cpp
scripting/lua.cpp
sha1.cpp
settings.cpp
statistics.cpp
statistics_dialog.cpp
ai_move.cpp
ai_village.cpp
animated_game.cpp
attack_prediction.cpp
attack_prediction_display.cpp
callable_objects.cpp
config_adapter.cpp
controller_base.cpp
dialogs.cpp
floating_textbox.cpp
formula.cpp
formula_ai.cpp
formula_function.cpp
formula_tokenizer.cpp
formula_string_utils.cpp
game_display.cpp
game_events.cpp
game_preferences.cpp
gamestatus.cpp
generate_report.cpp
halo.cpp
help.cpp
intro.cpp
leader_list.cpp
menu_events.cpp
mouse_events.cpp
mouse_handler_base.cpp
multiplayer.cpp
multiplayer_ui.cpp
multiplayer_wait.cpp
multiplayer_create.cpp
multiplayer_lobby.cpp
pathfind.cpp
playcampaign.cpp
play_controller.cpp
playmp_controller.cpp
playsingle_controller.cpp
playturn.cpp
portrait.cpp
replay.cpp
replay_controller.cpp
savegame.cpp
scripting/lua.cpp
sha1.cpp
settings.cpp
statistics.cpp
statistics_dialog.cpp
storyscreen/interface.cpp
storyscreen/controller.cpp
storyscreen/page.cpp
team.cpp
terrain_filter.cpp
time_of_day.cpp
titlescreen.cpp
unit.cpp
unit_abilities.cpp
unit_animation.cpp
unit_display.cpp
unit_frame.cpp
unit_id.cpp
unit_map.cpp
unit_types.cpp
upload_log.cpp
variable.cpp
variant.cpp
widgets/combo.cpp
widgets/combo_drag.cpp
widgets/drop_target.cpp
widgets/scrollpane.cpp
gui/dialogs/addon_connect.cpp
gui/dialogs/addon_list.cpp
gui/dialogs/campaign_selection.cpp
gui/dialogs/dialog.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/message.cpp
gui/dialogs/mp_connect.cpp
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_method_selection.cpp
gui/dialogs/mp_cmd_wrapper.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/wml_message.cpp
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp
gui/widgets/container.cpp
gui/widgets/event_handler.cpp
gui/widgets/generator.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp
gui/widgets/horizontal_scrollbar.cpp
gui/widgets/image.cpp
gui/widgets/label.cpp
gui/widgets/listbox.cpp
gui/widgets/menubar.cpp
gui/widgets/minimap.cpp
gui/widgets/panel.cpp
gui/widgets/password_box.cpp
gui/widgets/settings.cpp
gui/widgets/scroll_label.cpp
gui/widgets/scrollbar_container.cpp
gui/widgets/scrollbar.cpp
gui/widgets/slider.cpp
gui/widgets/spacer.cpp
gui/widgets/text.cpp
gui/widgets/text_box.cpp
gui/widgets/toggle_button.cpp
gui/widgets/toggle_panel.cpp
gui/widgets/tooltip.cpp
gui/widgets/vertical_scrollbar.cpp
gui/widgets/widget.cpp
gui/widgets/window.cpp
gui/widgets/window_builder.cpp
""")
wesnoth_sources.extend(env.Object("game_preferences_display.cpp", EXTRA_DEFINE = env["PLATFORM"] != "win32" and "WESNOTH_PREFIX='\"$prefix\"'" or None))
wesnoth_sources.extend(env.Object(Split("""
ai.cpp
config_cache.cpp
multiplayer_connect.cpp
""")))
wesnoth_editor2_sources = Split("""
gui/dialogs/editor_generate_map.cpp
gui/dialogs/editor_new_map.cpp
gui/dialogs/editor_resize_map.cpp
gui/dialogs/editor_settings.cpp
editor2/action.cpp
editor2/brush.cpp
editor2/editor_main.cpp
editor2/editor_controller.cpp
editor2/editor_display.cpp
editor2/editor_layout.cpp
editor2/editor_map.cpp
editor2/editor_palettes.cpp
editor2/map_context.cpp
editor2/map_fragment.cpp
editor2/mouse_action.cpp
""")
if env["editor"]:
wesnoth_sources += wesnoth_editor2_sources
libwesnoth_extras = env.Library("wesnoth_extras", wesnoth_sources)
#
# Target declarations
#
def WesnothProgram(env, target, source, can_build, **kw):
if can_build:
if env["build"] == "base":
bin = env.Program(target, source, **kw)
else:
bin = env.Program("#/" + target + build_suffix, source, **kw)
else:
bin = None
env.Alias(target, bin)
exec target + " = bin"
Export(target)
env.AddMethod(WesnothProgram)
test_env.AddMethod(WesnothProgram)
game_cpp = env.Object("game.cpp", EXTRA_DEFINE = not env["pool_alloc"] and "DISABLE_POOL_ALLOC" or None);
env.WesnothProgram("wesnoth", [game_cpp] + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth, libcampaignd, env["wesnoth_res"]], have_client_prereqs)
campaignd_sources = Split("""
server/input_stream.cpp
""")
if env["PLATFORM"] == "win32": env["fifodir"] = ""
campaignd_sources.extend(env.Object("campaign_server/campaign_server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
env.WesnothProgram("campaignd", campaignd_sources + [libwesnoth_core, libwesnothd, libcampaignd], have_server_prereqs)
# I don't know Scons so I just add jwsmtp here...
wesnothd_sources = Split("""
server/ban.cpp
server/forum_user_handler.cpp
server/game.cpp
server/input_stream.cpp
server/metrics.cpp
server/player.cpp
server/proxy.cpp
server/sample_user_handler.cpp
server/simple_wml.cpp
server/user_handler.cpp
server/mail.cpp
time.cpp
server/jwsmtp/mailer.cpp
server/jwsmtp/compat.cpp
server/jwsmtp/base64.cpp
""")
wesnothd_sources.extend(env.Object("server/server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
env.WesnothProgram("wesnothd", wesnothd_sources + [libwesnoth_core, libwesnothd], have_server_prereqs)
cutter_sources = Split("""
tools/cutter.cpp
""")
env.WesnothProgram("cutter", cutter_sources + [libcutter, libwesnoth_core, libwesnoth_sdl, libwesnothd, libwesnoth], have_client_prereqs,
LIBS = env["LIBS"] + ["png"])
exploder_sources = Split("""
tools/exploder.cpp
tools/exploder_composer.cpp
""")
env.WesnothProgram("exploder", exploder_sources + [libcutter, libwesnoth_core, libwesnoth_sdl, libwesnothd, libwesnoth], have_client_prereqs,
LIBS = env["LIBS"] + ["png"])
test_utils_sources = Split("""
tests/utils/game_config_manager.cpp
tests/utils/fake_event_source.cpp
tests/utils/fake_display.cpp
""")
libtest_utils = env.Library("test_utils", test_utils_sources)
test_sources = Split("""
tests/main.cpp
tests/test_formula_ai.cpp
tests/test_network_worker.cpp
tests/test_policy.cpp
tests/test_team.cpp
tests/test_util.cpp
tests/test_serialization.cpp
tests/test_version.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_save_dialog.cpp
tests/utils/play_scenario.cpp
""")
test_sources.extend(test_env.Object("tests/test_config_cache.cpp"))
test = test_env.WesnothProgram("test", test_sources + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth,libtest_utils], have_test_prereqs)
if env["svnrev"] != "" and env["svnrev"] != "exported":
revision_define = "#define REVISION \"%s\"\n" % env["svnrev"]
env.Command("#/src/revision.hpp", Value(env["svnrev"]), Action(
lambda target, source, env: open(str(target[0]), "w").write(revision_define),
"Generating revision.hpp..."
))
game_config_env.Append(CPPDEFINES = 'HAVE_REVISION')
sources = []
if "TAGS" in COMMAND_LINE_TARGETS:
sources = [ Glob(os.path.join(dir, pattern)) for dir in ["", "*", "*/*"] for pattern in ["*.cpp", "*.hpp"] ]
Export("sources")
# Local variables:
# mode: python
# end:
team.cpp
terrain_filter.cpp
time_of_day.cpp
titlescreen.cpp
unit.cpp
unit_abilities.cpp
unit_animation.cpp
unit_display.cpp
unit_frame.cpp
unit_id.cpp
unit_map.cpp
unit_types.cpp
upload_log.cpp
variable.cpp
variant.cpp
widgets/combo.cpp
widgets/combo_drag.cpp
widgets/drop_target.cpp
widgets/scrollpane.cpp
gui/dialogs/addon_connect.cpp
gui/dialogs/addon_list.cpp
gui/dialogs/campaign_selection.cpp
gui/dialogs/dialog.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/message.cpp
gui/dialogs/mp_connect.cpp
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_method_selection.cpp
gui/dialogs/mp_cmd_wrapper.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/wml_message.cpp
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp
gui/widgets/container.cpp
gui/widgets/event_handler.cpp
gui/widgets/generator.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp
gui/widgets/horizontal_scrollbar.cpp
gui/widgets/image.cpp
gui/widgets/label.cpp
gui/widgets/listbox.cpp
gui/widgets/menubar.cpp
gui/widgets/minimap.cpp
gui/widgets/panel.cpp
gui/widgets/password_box.cpp
gui/widgets/settings.cpp
gui/widgets/scroll_label.cpp
gui/widgets/scrollbar_container.cpp
gui/widgets/scrollbar.cpp
gui/widgets/slider.cpp
gui/widgets/spacer.cpp
gui/widgets/text.cpp
gui/widgets/text_box.cpp
gui/widgets/toggle_button.cpp
gui/widgets/toggle_panel.cpp
gui/widgets/tooltip.cpp
gui/widgets/vertical_scrollbar.cpp
gui/widgets/widget.cpp
gui/widgets/window.cpp
gui/widgets/window_builder.cpp
""")
wesnoth_sources.extend(env.Object("game_preferences_display.cpp", EXTRA_DEFINE = env["PLATFORM"] != "win32" and "WESNOTH_PREFIX='\"$prefix\"'" or None))
wesnoth_sources.extend(env.Object(Split("""
ai.cpp
config_cache.cpp
multiplayer_connect.cpp
""")))
wesnoth_editor2_sources = Split("""
gui/dialogs/editor_generate_map.cpp
gui/dialogs/editor_new_map.cpp
gui/dialogs/editor_resize_map.cpp
gui/dialogs/editor_settings.cpp
editor2/action.cpp
editor2/brush.cpp
editor2/editor_main.cpp
editor2/editor_controller.cpp
editor2/editor_display.cpp
editor2/editor_layout.cpp
editor2/editor_map.cpp
editor2/editor_palettes.cpp
editor2/map_context.cpp
editor2/map_fragment.cpp
editor2/mouse_action.cpp
""")
if env["editor"]:
wesnoth_sources += wesnoth_editor2_sources
libwesnoth_extras = env.Library("wesnoth_extras", wesnoth_sources)
#
# Target declarations
#
def WesnothProgram(env, target, source, can_build, **kw):
if can_build:
if env["build"] == "base":
bin = env.Program(target, source, **kw)
else:
bin = env.Program("#/" + target + build_suffix, source, **kw)
else:
bin = None
env.Alias(target, bin)
exec target + " = bin"
Export(target)
env.AddMethod(WesnothProgram)
test_env.AddMethod(WesnothProgram)
game_cpp = env.Object("game.cpp", EXTRA_DEFINE = not env["pool_alloc"] and "DISABLE_POOL_ALLOC" or None);
env.WesnothProgram("wesnoth", [game_cpp] + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth, libcampaignd, env["wesnoth_res"]], have_client_prereqs)
campaignd_sources = Split("""
server/input_stream.cpp
""")
if env["PLATFORM"] == "win32": env["fifodir"] = ""
campaignd_sources.extend(env.Object("campaign_server/campaign_server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
env.WesnothProgram("campaignd", campaignd_sources + [libwesnoth_core, libwesnothd, libcampaignd], have_server_prereqs)
# I don't know Scons so I just add jwsmtp here...
wesnothd_sources = Split("""
server/ban.cpp
server/forum_user_handler.cpp
server/game.cpp
server/input_stream.cpp
server/metrics.cpp
server/player.cpp
server/proxy.cpp
server/sample_user_handler.cpp
server/simple_wml.cpp
server/user_handler.cpp
server/mail.cpp
time.cpp
server/jwsmtp/mailer.cpp
server/jwsmtp/compat.cpp
server/jwsmtp/base64.cpp
""")
wesnothd_sources.extend(env.Object("server/server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
env.WesnothProgram("wesnothd", wesnothd_sources + [libwesnoth_core, libwesnothd], have_server_prereqs)
cutter_sources = Split("""
tools/cutter.cpp
""")
env.WesnothProgram("cutter", cutter_sources + [libcutter, libwesnoth_core, libwesnoth_sdl, libwesnothd, libwesnoth], have_client_prereqs,
LIBS = env["LIBS"] + ["png"])
exploder_sources = Split("""
tools/exploder.cpp
tools/exploder_composer.cpp
""")
env.WesnothProgram("exploder", exploder_sources + [libcutter, libwesnoth_core, libwesnoth_sdl, libwesnothd, libwesnoth], have_client_prereqs,
LIBS = env["LIBS"] + ["png"])
test_utils_sources = Split("""
tests/utils/game_config_manager.cpp
tests/utils/fake_event_source.cpp
tests/utils/fake_display.cpp
""")
libtest_utils = env.Library("test_utils", test_utils_sources)
test_sources = Split("""
tests/main.cpp
tests/test_formula_ai.cpp
tests/test_network_worker.cpp
tests/test_policy.cpp
tests/test_team.cpp
tests/test_util.cpp
tests/test_serialization.cpp
tests/test_version.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_save_dialog.cpp
tests/utils/play_scenario.cpp
""")
test_sources.extend(test_env.Object("tests/test_config_cache.cpp"))
test = test_env.WesnothProgram("test", test_sources + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth,libtest_utils], have_test_prereqs)
if env["svnrev"] != "" and env["svnrev"] != "exported":
revision_define = "#define REVISION \"%s\"\n" % env["svnrev"]
env.Command("#/src/revision.hpp", Value(env["svnrev"]), Action(
lambda target, source, env: open(str(target[0]), "w").write(revision_define),
"Generating revision.hpp..."
))
game_config_env.Append(CPPDEFINES = 'HAVE_REVISION')
sources = []
if "TAGS" in COMMAND_LINE_TARGETS:
sources = [ Glob(os.path.join(dir, pattern)) for dir in ["", "*", "*/*"] for pattern in ["*.cpp", "*.hpp"] ]
Export("sources")
# Local variables:
# mode: python
# end:

View file

@ -489,6 +489,12 @@ static void write_player(const player_info& player, config& cfg)
void write_players(game_state& gamestate, config& cfg)
{
// If there is already a player config available it means we are loading
// from a savegame. Don't do anything then, the information is already there
config::child_itors player_cfg = cfg.child_range("player");
if (player_cfg.first != player_cfg.second)
return;
for(std::map<std::string, player_info>::const_iterator i=gamestate.players.begin();
i!=gamestate.players.end(); ++i)
{
@ -695,7 +701,7 @@ void game_state::write_snapshot(config& cfg) const
}
}
void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE mode)
void write_game(config_writer &out, const config& snapshot, const game_state& gamestate, WRITE_GAME_MODE mode)
{
log_scope("write_game");
@ -747,7 +753,7 @@ void write_game(config_writer &out, const game_state& gamestate, WRITE_GAME_MODE
out.write_child("replay", gamestate.replay_data);
}
out.write_child("snapshot",gamestate.snapshot);
out.write_child("snapshot",snapshot);
out.write_child("replay_start",gamestate.starting_pos);
out.open_child("statistics");
statistics::write_stats(out);
@ -932,7 +938,7 @@ void save_game(const game_state& gamestate)
std::stringstream ss;
{
config_writer out(ss, preferences::compress_saves());
write_game(out, gamestate);
write_game(out, gamestate.snapshot, gamestate);
finish_save_game(out, gamestate, gamestate.label);
}
(*os) << ss.str();

View file

@ -320,7 +320,7 @@ 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 game_state& gamestate, WRITE_GAME_MODE mode=WRITE_FULL_GAME);
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);

View file

@ -39,6 +39,7 @@
#include "mouse_events.hpp"
#include "preferences_display.hpp"
#include "replay.hpp"
#include "savegame.hpp"
#include "sound.hpp"
#include "statistics_dialog.hpp"
#include "unit_display.hpp"
@ -608,10 +609,16 @@ private:
if(res == 0) {
config snapshot;
if (!replay)
if (!replay){
write_game_snapshot(snapshot);
}
gamestate_.replay_data = recorder.get_replay_data();
try {
recorder.save_game(label, snapshot, gamestate_.starting_pos);
if (replay)
::save_replay(label, gamestate_);
else
::save_game(label, snapshot, gamestate_);
if(dialog_type != gui::NULL_DIALOG) {
gui::message_dialog(*gui_,_("Saved"),_("The game has been saved")).show();
}
@ -737,7 +744,7 @@ private:
savename = label + "-" + _("Auto-Save") + lexical_cast<std::string>(turn);
write_game_snapshot(snapshot);
try {
recorder.save_game(savename, snapshot, starting_pos);
::save_game(savename, snapshot, gamestate_);
} catch(game::save_game_failed&) {
gui::message_dialog(*gui_,"",_("Could not auto save the game. Please save the game manually.")).show();
//do not bother retrying, since the user can just save the game

View file

@ -29,6 +29,7 @@
#include "map_exception.hpp"
#include "dialogs.hpp"
#include "gettext.hpp"
#include "savegame.hpp"
#include "sound.hpp"
#include "wml_exception.hpp"
#include "formula_string_utils.hpp"
@ -364,6 +365,10 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
switch (io_type){
case IO_NONE:
//Add the player section to the starting position so we can get the correct recall list
//when loading the replay later on
write_players(gamestate, gamestate.starting_pos);
res = playsingle_scenario(game_config,scenario,disp,gamestate,story,log, skip_replay, end_level);
break;
case IO_SERVER:
@ -409,17 +414,9 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
std::string label = gamestate.label + _(" replay");
if (dialogs::get_save_name(disp, "", _("Name: "), &label,
gui::OK_CANCEL, _("Save Replay"), false, false) == 0) {
gamestate.replay_data = recorder.get_replay_data();
try {
config snapshot;
//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) {
recorder.set_save_info(gamestate, player_list);
}
recorder.save_game(label, snapshot, gamestate.starting_pos);
::save_replay(gamestate);
} catch(game::save_game_failed&) {
gui::show_error_message(disp, _("The replay could not be saved"));
}
@ -539,9 +536,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// Sends scenario data
config cfg;
cfg.add_child("store_next_scenario", *scenario);
//Add the player section to the starting position so we can get the correct recall list
//when loading the replay later on
write_players(gamestate, gamestate.starting_pos);
// Adds player information, and other state
// information, to the configuration object
assert(cfg.child("store_next_scenario") != NULL);

View file

@ -169,12 +169,12 @@ void replay::set_save_info(const game_state& save)
saveInfo_ = save;
}
void replay::set_save_info(const game_state &save, const config::const_child_itors &players)
{
saveInfo_ = save;
saveInfo_.players.clear();
saveInfo_.load_recall_list(players);
}
//void replay::set_save_info(const game_state &save, const config::const_child_itors &players)
//{
// saveInfo_ = save;
// saveInfo_.players.clear();
// saveInfo_.load_recall_list(players);
//}
void replay::set_save_info_completion(const std::string &st)
// This function is a kluge to get around the fact that replay objects carry
@ -194,40 +194,40 @@ bool replay::is_skipping() const
return skip_;
}
void replay::save_game(const std::string& label, const config& snapshot,
const config& starting_pos, bool include_replay)
{
log_scope("replay::save_game");
saveInfo_.snapshot = snapshot;
saveInfo_.starting_pos = starting_pos;
if(include_replay) {
saveInfo_.replay_data = cfg_;
} else {
saveInfo_.replay_data = config();
}
saveInfo_.label = label;
std::string filename = label;
if(preferences::compress_saves()) {
filename += ".gz";
}
std::stringstream ss;
{
config_writer out(ss, preferences::compress_saves());
::write_game(out, saveInfo_);
finish_save_game(out, saveInfo_, saveInfo_.label);
}
scoped_ostream os(open_save_game(filename));
(*os) << ss.str();
saveInfo_.replay_data = config();
saveInfo_.snapshot = config();
if (!os->good()) {
throw game::save_game_failed(_("Could not write to file"));
}
}
//void replay::save_game(const std::string& label, const config& snapshot,
// const config& starting_pos, bool include_replay)
//{
// log_scope("replay::save_game");
// saveInfo_.snapshot = snapshot;
// saveInfo_.starting_pos = starting_pos;
//
// if(include_replay) {
// saveInfo_.replay_data = cfg_;
// } else {
// saveInfo_.replay_data = config();
// }
//
// saveInfo_.label = label;
//
// std::string filename = label;
// if(preferences::compress_saves()) {
// filename += ".gz";
// }
//
// std::stringstream ss;
// {
// config_writer out(ss, preferences::compress_saves());
// ::write_game(out, saveInfo_);
// finish_save_game(out, saveInfo_, saveInfo_.label);
// }
// scoped_ostream os(open_save_game(filename));
// (*os) << ss.str();
// saveInfo_.replay_data = config();
// saveInfo_.snapshot = config();
// if (!os->good()) {
// throw game::save_game_failed(_("Could not write to file"));
// }
//}
void replay::add_unit_checksum(const map_location& loc,config* const cfg)
{

View file

@ -43,14 +43,14 @@ public:
explicit replay(const config& cfg);
void set_save_info(const game_state& save);
void set_save_info(const game_state &save, const config::const_child_itors &players);
//void set_save_info(const game_state &save, const config::const_child_itors &players);
void set_save_info_completion(const std::string &st);
void set_skip(bool skip);
bool is_skipping() const;
void save_game(const std::string& label, const config& snapshot,
const config& starting_pos, bool include_replay = true);
//void save_game(const std::string& label, const config& snapshot,
// const config& starting_pos, bool include_replay = true);
void add_start();
void add_recruit(int unit_index, const map_location& loc);
@ -91,6 +91,7 @@ public:
enum DATA_TYPE { ALL_DATA, NON_UNDO_DATA };
config get_data_range(int cmd_start, int cmd_end, DATA_TYPE data_type=ALL_DATA);
config get_last_turn(int num_turns=1);
const config& get_replay_data() const { return cfg_; }
void undo();