diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 703777a936..2015cc6c8a 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -202,6 +202,10 @@ hotkey.text.move.right = "Ctrl+RightArrow" ; Move cursor to start of word to hotkey.profile.toggle = "F11" ; Enable/disable real-time profiler hotkey.profile.save = "Shift+F11" ; Save current profiler data to logs/profile.txt +; > QUICKSAVE +hotkey.quicksave = "Shift+F5" +hotkey.quickload = "Shift+F8" + ; EXPERIMENTAL: joystick/gamepad settings joystick.enable = false joystick.deadzone = 8192 diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml index c8481b6648..50c15476d8 100644 --- a/binaries/data/mods/public/gui/session/session.xml +++ b/binaries/data/mods/public/gui/session/session.xml @@ -60,6 +60,14 @@ togglePause(); + + + Engine.QuickSave(); + + + Engine.QuickLoad(); + + performCommand(g_Selection.toList()[0], "delete"); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 0054246f6c..2cb1abf29c 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -456,6 +456,16 @@ void RewindTimeWarp(void* UNUSED(cbdata)) g_Game->GetTurnManager()->RewindTimeWarp(); } +void QuickSave(void* UNUSED(cbdata)) +{ + g_Game->GetTurnManager()->QuickSave(); +} + +void QuickLoad(void* UNUSED(cbdata)) +{ + g_Game->GetTurnManager()->QuickLoad(); +} + } // namespace void GuiScriptingInit(ScriptInterface& scriptInterface) @@ -520,4 +530,6 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("DumpSimState"); scriptInterface.RegisterFunction("EnableTimeWarpRecording"); scriptInterface.RegisterFunction("RewindTimeWarp"); + scriptInterface.RegisterFunction("QuickSave"); + scriptInterface.RegisterFunction("QuickLoad"); } diff --git a/source/network/NetTurnManager.cpp b/source/network/NetTurnManager.cpp index 5f54047480..a346c93d5d 100644 --- a/source/network/NetTurnManager.cpp +++ b/source/network/NetTurnManager.cpp @@ -25,6 +25,7 @@ #include "gui/GUIManager.h" #include "maths/MathUtil.h" +#include "ps/CLogger.h" #include "ps/Profile.h" #include "ps/Pyrogenesis.h" #include "ps/Replay.h" @@ -270,6 +271,46 @@ void CNetTurnManager::RewindTimeWarp() m_QueuedCommands.resize(queuedCommandsSize); } +void CNetTurnManager::QuickSave() +{ + std::stringstream stream; + bool ok = m_Simulation2.SerializeState(stream); + if (!ok) + { + LOGERROR(L"Failed to quicksave game"); + return; + } + LOGMESSAGERENDER(L"Quicksaved game"); + + m_QuickSaveState = stream.str(); + +} + +void CNetTurnManager::QuickLoad() +{ + if (m_QuickSaveState.empty()) + { + LOGERROR(L"Cannot quickload game - no game was quicksaved"); + return; + } + + std::stringstream stream(m_QuickSaveState); + bool ok = m_Simulation2.DeserializeState(stream); + if (!ok) + { + LOGERROR(L"Failed to quickload game"); + return; + } + LOGMESSAGERENDER(L"Quickloaded game"); + + // See RewindTimeWarp + m_CurrentTurn = 0; + m_ReadyTurn = 1; + m_DeltaTime = 0; + size_t queuedCommandsSize = m_QueuedCommands.size(); + m_QueuedCommands.clear(); + m_QueuedCommands.resize(queuedCommandsSize); +} CNetClientTurnManager::CNetClientTurnManager(CSimulation2& simulation, CNetClient& client, int clientId, IReplayLogger& replay) : diff --git a/source/network/NetTurnManager.h b/source/network/NetTurnManager.h index c97de0f97d..babafbbec0 100644 --- a/source/network/NetTurnManager.h +++ b/source/network/NetTurnManager.h @@ -119,6 +119,9 @@ public: */ void RewindTimeWarp(); + void QuickSave(); + void QuickLoad(); + protected: /** * Store a command to be executed at a given turn. @@ -168,6 +171,7 @@ protected: private: size_t m_TimeWarpNumTurns; // 0 if disabled std::list m_TimeWarpStates; + std::string m_QuickSaveState; // TODO: should implement a proper disk-based quicksave system }; /**