Experimental quicksave/quickload feature

This was SVN commit r10427.
This commit is contained in:
Ykkrosh 2011-10-24 14:55:45 +00:00
parent 29e4f633f1
commit a3c03815c0
5 changed files with 69 additions and 0 deletions

View File

@ -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

View File

@ -60,6 +60,14 @@
<action on="Press">togglePause();</action>
</object>
<!-- Quicksave/load -->
<object hotkey="quicksave">
<action on="Press">Engine.QuickSave();</action>
</object>
<object hotkey="quickload">
<action on="Press">Engine.QuickLoad();</action>
</object>
<!-- Delete button Hotkey (For some reason it won't work when the console is visible -->
<object hotkey="session.kill">
<action on="Press">performCommand(g_Selection.toList()[0], "delete");</action>

View File

@ -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<void, &DumpSimState>("DumpSimState");
scriptInterface.RegisterFunction<void, unsigned int, &EnableTimeWarpRecording>("EnableTimeWarpRecording");
scriptInterface.RegisterFunction<void, &RewindTimeWarp>("RewindTimeWarp");
scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave");
scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad");
}

View File

@ -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) :

View File

@ -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<std::string> m_TimeWarpStates;
std::string m_QuickSaveState; // TODO: should implement a proper disk-based quicksave system
};
/**