mirror of https://github.com/stella-emu/stella.git
frame timed interval checks aligned to actual scanlines/frame
code cleanup
This commit is contained in:
parent
3f00d2fb86
commit
418b0f07ae
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include "RewindManager.hxx"
|
#include "RewindManager.hxx"
|
||||||
|
|
||||||
//static int count = 1;
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
RewindManager::RewindManager(OSystem& system, StateManager& statemgr)
|
RewindManager::RewindManager(OSystem& system, StateManager& statemgr)
|
||||||
: myOSystem(system),
|
: myOSystem(system),
|
||||||
|
@ -99,7 +98,17 @@ bool RewindManager::addState(const string& message, bool continuous)
|
||||||
{
|
{
|
||||||
// check if the current state has the right interval from the last state
|
// check if the current state has the right interval from the last state
|
||||||
RewindState& lastState = myStateList.current();
|
RewindState& lastState = myStateList.current();
|
||||||
if(myOSystem.console().tia().cycles() - lastState.cycles < myInterval)
|
uInt32 interval = myInterval;
|
||||||
|
|
||||||
|
// adjust frame timed intervals to actual scanlines (vs 262)
|
||||||
|
if(interval >= 76 * 262 && interval <= 76 * 262 * 30)
|
||||||
|
{
|
||||||
|
const uInt32 scanlines = std::max(myOSystem.console().tia().scanlinesLastFrame(), 240u);
|
||||||
|
|
||||||
|
interval = interval * scanlines / 262;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(myOSystem.console().tia().cycles() - lastState.cycles < interval)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +130,6 @@ bool RewindManager::addState(const string& message, bool continuous)
|
||||||
{
|
{
|
||||||
state.message = message;
|
state.message = message;
|
||||||
state.cycles = myOSystem.console().tia().cycles();
|
state.cycles = myOSystem.console().tia().cycles();
|
||||||
//state.count = count++;
|
|
||||||
//cerr << "add " << state.count << endl;
|
|
||||||
myLastContinuousAdd = continuous;
|
myLastContinuousAdd = continuous;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -144,11 +151,13 @@ uInt32 RewindManager::rewindState(uInt32 numStates)
|
||||||
// Set internal current iterator to previous state (back in time),
|
// Set internal current iterator to previous state (back in time),
|
||||||
// since we will now processed this state
|
// since we will now processed this state
|
||||||
myStateList.moveToPrevious();
|
myStateList.moveToPrevious();
|
||||||
myLastContinuousAdd = false;
|
else
|
||||||
|
// except fif the last state was added automatically,
|
||||||
|
// because that already happened one interval before
|
||||||
|
myLastContinuousAdd = false;
|
||||||
|
|
||||||
RewindState& state = myStateList.current();
|
RewindState& state = myStateList.current();
|
||||||
Serializer& s = state.data;
|
Serializer& s = state.data;
|
||||||
//cerr << "rewind " << state.count << endl;
|
|
||||||
s.rewind(); // rewind Serializer internal buffers
|
s.rewind(); // rewind Serializer internal buffers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -190,7 +199,6 @@ uInt32 RewindManager::unwindState(uInt32 numStates)
|
||||||
|
|
||||||
RewindState& state = myStateList.current();
|
RewindState& state = myStateList.current();
|
||||||
Serializer& s = state.data;
|
Serializer& s = state.data;
|
||||||
//cerr << "unwind " << state.count << endl;
|
|
||||||
s.rewind(); // rewind Serializer internal buffers
|
s.rewind(); // rewind Serializer internal buffers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -47,7 +47,8 @@ class RewindManager
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr int NUM_INTERVALS = 7;
|
static constexpr int NUM_INTERVALS = 7;
|
||||||
const uInt32 INTERVAL_CYCLES[NUM_INTERVALS] = {
|
// cycle values for the intervals
|
||||||
|
static constexpr uInt32 INTERVAL_CYCLES[NUM_INTERVALS] = {
|
||||||
76 * 262,
|
76 * 262,
|
||||||
76 * 262 * 3,
|
76 * 262 * 3,
|
||||||
76 * 262 * 10,
|
76 * 262 * 10,
|
||||||
|
@ -56,11 +57,7 @@ class RewindManager
|
||||||
76 * 262 * 60 * 3,
|
76 * 262 * 60 * 3,
|
||||||
76 * 262 * 60 * 10
|
76 * 262 * 60 * 10
|
||||||
};
|
};
|
||||||
/*static const int NUM_INTERVALS = 6;
|
// settings values for the intervals
|
||||||
const string INTERVALS[NUM_INTERVALS] = { "1 scanline", "50 scanlines", "1 frame", "10 frames",
|
|
||||||
"1 second", "10 seconds" };
|
|
||||||
const uInt32 INTERVAL_CYCLES[NUM_INTERVALS] = { 76, 76 * 50, 76 * 262, 76 * 262 * 10,
|
|
||||||
76 * 262 * 60, 76 * 262 * 60 * 10 };*/
|
|
||||||
const string INT_SETTINGS[NUM_INTERVALS] = {
|
const string INT_SETTINGS[NUM_INTERVALS] = {
|
||||||
"1f",
|
"1f",
|
||||||
"3f",
|
"3f",
|
||||||
|
@ -72,7 +69,8 @@ class RewindManager
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr int NUM_HORIZONS = 8;
|
static constexpr int NUM_HORIZONS = 8;
|
||||||
const uInt64 HORIZON_CYCLES[NUM_HORIZONS] = {
|
// cycle values for the horzions
|
||||||
|
static constexpr uInt64 HORIZON_CYCLES[NUM_HORIZONS] = {
|
||||||
76 * 262 * 60 * 3,
|
76 * 262 * 60 * 3,
|
||||||
76 * 262 * 60 * 10,
|
76 * 262 * 60 * 10,
|
||||||
76 * 262 * 60 * 30,
|
76 * 262 * 60 * 30,
|
||||||
|
@ -82,11 +80,7 @@ class RewindManager
|
||||||
uInt64(76) * 262 * 60 * 60 * 30,
|
uInt64(76) * 262 * 60 * 60 * 30,
|
||||||
uInt64(76) * 262 * 60 * 60 * 60
|
uInt64(76) * 262 * 60 * 60 * 60
|
||||||
};
|
};
|
||||||
/*static const int NUM_HORIZONS = 7;
|
// settings values for the horzions
|
||||||
const string HORIZONS[NUM_HORIZONS] = { "~1 frame", "~10 frames", "~1 second", "~10 seconds",
|
|
||||||
"~1 minute", "~10 minutes", "~60 minutes" };
|
|
||||||
const uInt64 HORIZON_CYCLES[NUM_HORIZONS] = { 76 * 262, 76 * 262 * 10, 76 * 262 * 60, 76 * 262 * 60 * 10,
|
|
||||||
76 * 262 * 60 * 60, 76 * 262 * 60 * 60 * 10, uInt64(76) * 262 * 60 * 60 * 60 };*/
|
|
||||||
const string HOR_SETTINGS[NUM_HORIZONS] = {
|
const string HOR_SETTINGS[NUM_HORIZONS] = {
|
||||||
"3s",
|
"3s",
|
||||||
"10s",
|
"10s",
|
||||||
|
@ -140,9 +134,6 @@ class RewindManager
|
||||||
string getUnitString(Int64 cycles);
|
string getUnitString(Int64 cycles);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Maximum number of states to save
|
|
||||||
static constexpr uInt32 INITIAL_SIZE = 100;
|
|
||||||
|
|
||||||
OSystem& myOSystem;
|
OSystem& myOSystem;
|
||||||
StateManager& myStateManager;
|
StateManager& myStateManager;
|
||||||
|
|
||||||
|
@ -154,10 +145,9 @@ class RewindManager
|
||||||
bool myLastContinuousAdd;
|
bool myLastContinuousAdd;
|
||||||
|
|
||||||
struct RewindState {
|
struct RewindState {
|
||||||
Serializer data;
|
Serializer data; // actual save state
|
||||||
string message;
|
string message; // describes save state origin
|
||||||
uInt64 cycles;
|
uInt64 cycles; // cycles since emulation started
|
||||||
//int count; // TODO - remove this
|
|
||||||
|
|
||||||
// We do nothing on object instantiation or copy
|
// We do nothing on object instantiation or copy
|
||||||
// The goal of LinkedObjectPool is to not do any allocations at all
|
// The goal of LinkedObjectPool is to not do any allocations at all
|
||||||
|
@ -166,13 +156,13 @@ class RewindManager
|
||||||
|
|
||||||
// Output object info; used for debugging only
|
// Output object info; used for debugging only
|
||||||
friend ostream& operator<<(ostream& os, const RewindState& s) {
|
friend ostream& operator<<(ostream& os, const RewindState& s) {
|
||||||
return os << "msg: " << s.message << " cycle: " << s.cycles; // << " count: " << s.count;
|
return os << "msg: " << s.message << " cycle: " << s.cycles;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The linked-list to store states (internally it takes care of reducing
|
// The linked-list to store states (internally it takes care of reducing
|
||||||
// frequent (de)-allocations)
|
// frequent (de)-allocations)
|
||||||
Common::LinkedObjectPool<RewindState, INITIAL_SIZE> myStateList;
|
Common::LinkedObjectPool<RewindState> myStateList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Remove a save state from the list
|
Remove a save state from the list
|
||||||
|
|
Loading…
Reference in New Issue