added extra save state when starting time machine navigation

(some TODOs left, see EventHandler and TimeMachineDialog)
This commit is contained in:
thrust26 2018-01-28 10:15:39 +01:00
parent 2c90aaa7c7
commit d2177ea610
8 changed files with 84 additions and 34 deletions

View File

@ -138,7 +138,7 @@ bool RewindManager::addState(const string& message, bool timeMachine)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 RewindManager::rewindState(uInt32 numStates)
uInt32 RewindManager::rewindStates(uInt32 numStates)
{
uInt64 startCycles = myOSystem.console().tia().cycles();
uInt32 i;
@ -177,7 +177,7 @@ uInt32 RewindManager::rewindState(uInt32 numStates)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 RewindManager::unwindState(uInt32 numStates)
uInt32 RewindManager::unwindStates(uInt32 numStates)
{
uInt64 startCycles = myOSystem.console().tia().cycles();
uInt32 i;
@ -210,6 +210,16 @@ uInt32 RewindManager::unwindState(uInt32 numStates)
return i;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 RewindManager::windStates(uInt32 numStates, bool unwind)
{
if(unwind)
return unwindStates(numStates);
else
return rewindStates(numStates);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RewindManager::compressStates()
{

View File

@ -106,22 +106,32 @@ class RewindManager
bool addState(const string& message, bool timeMachine = false);
/**
Rewind one level of the state list, and display the message associated
Rewind numStates levels of the state list, and display the message associated
with that state.
@param numStates Number of states to rewind
@return Number of states to rewinded
*/
uInt32 rewindState(uInt32 numStates = 1);
uInt32 rewindStates(uInt32 numStates = 1);
/**
Unwind one level of the state list, and display the message associated
Unwind numStates levels of the state list, and display the message associated
with that state.
@param numStates Number of states to unwind
@return Number of states to unwinded
*/
uInt32 unwindState(uInt32 numStates = 1);
uInt32 unwindStates(uInt32 numStates = 1);
/**
Rewind/unwind numStates levels of the state list, and display the message associated
with that state.
@param numStates Number of states to wind
@param unwind unwind or rewind
@return Number of states to winded
*/
uInt32 windStates(uInt32 numStates, bool unwind);
bool atFirst() const { return myStateList.atFirst(); }
bool atLast() const { return myStateList.atLast(); }

View File

@ -142,17 +142,31 @@ void StateManager::toggleTimeMachine()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StateManager::rewindState(uInt32 numStates)
bool StateManager::addState(const string& message, bool timeMachine)
{
RewindManager& r = myOSystem.state().rewindManager();
return r.rewindState(numStates);
return r.addState(message, timeMachine);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StateManager::unwindState(uInt32 numStates)
bool StateManager::rewindStates(uInt32 numStates)
{
RewindManager& r = myOSystem.state().rewindManager();
return r.unwindState(numStates);
return r.rewindStates(numStates);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StateManager::unwindStates(uInt32 numStates)
{
RewindManager& r = myOSystem.state().rewindManager();
return r.unwindStates(numStates);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool StateManager::windStates(uInt32 numStates, bool unwind)
{
RewindManager& r = myOSystem.state().rewindManager();
return r.windStates(numStates, unwind);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -72,14 +72,24 @@ class StateManager
void setRewindMode(Mode mode) { myActiveMode = mode; }
/**
Rewinds one state; this uses the RewindManager for its functionality.
Adds one state ; this uses the RewindManager for its functionality.
*/
bool rewindState(uInt32 numStates = 1);
bool addState(const string& message, bool timeMachine = false);
/**
Unwinds one state; this uses the RewindManager for its functionality.
Rewinds states; this uses the RewindManager for its functionality.
*/
bool unwindState(uInt32 numStates = 1);
bool rewindStates(uInt32 numStates = 1);
/**
Unwinds states; this uses the RewindManager for its functionality.
*/
bool unwindStates(uInt32 numStates = 1);
/**
Rewinds/unwinds states; this uses the RewindManager for its functionality.
*/
bool windStates(uInt32 numStates, bool unwind);
/**
Updates the state of the system based on the currently active mode.

View File

@ -538,7 +538,7 @@ uInt16 Debugger::windStates(uInt16 numStates, bool unwind, string& message)
unlockBankswitchState();
uInt64 startCycles = myOSystem.console().tia().cycles();
uInt16 winds = unwind ? r.unwindState(numStates) : r.rewindState(numStates);
uInt16 winds = r.windStates(numStates, unwind);
message = r.getUnitString(myOSystem.console().tia().cycles() - startCycles);
lockBankswitchState();

View File

@ -300,27 +300,19 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state)
switch(key)
{
case KBDK_LEFT: // Alt-left(-shift) rewinds 1(10) states
myOSystem.frameBuffer().setPauseDelay();
setEventState(EventHandlerState::PAUSE);
myOSystem.state().rewindState((StellaModTest::isShift(mod) && state) ? 10 : 1);
enterTimeMachineMenuMode((StellaModTest::isShift(mod) && state) ? 10 : 1, false);
break;
case KBDK_RIGHT: // Alt-right(-shift) unwinds 1(10) states
myOSystem.frameBuffer().setPauseDelay();
setEventState(EventHandlerState::PAUSE);
myOSystem.state().unwindState((StellaModTest::isShift(mod) && state) ? 10 : 1);
enterTimeMachineMenuMode((StellaModTest::isShift(mod) && state) ? 10 : 1, true);
break;
case KBDK_DOWN: // Alt-down rewinds to start of list
myOSystem.frameBuffer().setPauseDelay();
setEventState(EventHandlerState::PAUSE);
myOSystem.state().rewindState(1000);
enterTimeMachineMenuMode(1000, false);
break;
case KBDK_UP: // Alt-up rewinds to end of list
myOSystem.frameBuffer().setPauseDelay();
setEventState(EventHandlerState::PAUSE);
myOSystem.state().unwindState(1000);
enterTimeMachineMenuMode(1000, true);
break;
default:
@ -1223,14 +1215,14 @@ bool EventHandler::eventStateChange(Event::Type type)
break;
case Event::OptionsMenuMode:
if(myState == EventHandlerState::EMULATION)
if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE)
enterMenuMode(EventHandlerState::OPTIONSMENU);
else
handled = false;
break;
case Event::CmdMenuMode:
if(myState == EventHandlerState::EMULATION)
if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE)
enterMenuMode(EventHandlerState::CMDMENU);
else if(myState == EventHandlerState::CMDMENU)
leaveMenuMode();
@ -1239,7 +1231,7 @@ bool EventHandler::eventStateChange(Event::Type type)
break;
case Event::TimeMachineMode:
if(myState == EventHandlerState::EMULATION)
if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE)
enterMenuMode(EventHandlerState::TIMEMACHINE);
else if(myState == EventHandlerState::TIMEMACHINE)
leaveMenuMode();
@ -1248,8 +1240,7 @@ bool EventHandler::eventStateChange(Event::Type type)
break;
case Event::DebuggerMode:
if(myState == EventHandlerState::EMULATION
|| myState == EventHandlerState::PAUSE
if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE
|| myState == EventHandlerState::TIMEMACHINE)
enterDebugMode();
else if(myState == EventHandlerState::DEBUGGER)
@ -2141,6 +2132,19 @@ void EventHandler::leaveDebugMode()
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::enterTimeMachineMenuMode(uInt32 numWinds, bool unwind)
{
// TODO: maybe remove this state if we leave the menu at the last state
myOSystem.state().addState("enter Time Machine menu", false); // force new state
myOSystem.state().windStates(numWinds, unwind);
// TODO: probably this check is not necessary
if(myState != EventHandlerState::TIMEMACHINE)
// TODO: display last wind message in time machine dialog
enterMenuMode(EventHandlerState::TIMEMACHINE);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setEventState(EventHandlerState state)
{

View File

@ -137,6 +137,7 @@ class EventHandler
void leaveMenuMode();
bool enterDebugMode();
void leaveDebugMode();
void enterTimeMachineMenuMode(uInt32 numWinds, bool unwind);
void takeSnapshot(uInt32 number = 0);
/**

View File

@ -383,10 +383,11 @@ void TimeMachineDialog::handleWinds(Int32 numWinds)
if(numWinds)
{
uInt64 startCycles = instance().console().tia().cycles();
if(numWinds < 0) r.rewindState(-numWinds);
else if(numWinds > 0) r.unwindState(numWinds);
if(numWinds < 0) r.rewindStates(-numWinds);
else if(numWinds > 0) r.unwindStates(numWinds);
string message = r.getUnitString(instance().console().tia().cycles() - startCycles);
// TODO: add message text from addState()
myMessageWidget->setLabel((numWinds < 0 ? "(-" : "(+") + message + ")");
}
// Update time