mirror of https://github.com/stella-emu/stella.git
added individual size to each save state (fixes #727)
This commit is contained in:
parent
8e118b055d
commit
7d63a0dfb8
|
@ -37,7 +37,6 @@ RewindManager::RewindManager(OSystem& system, StateManager& statemgr)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void RewindManager::setup()
|
void RewindManager::setup()
|
||||||
{
|
{
|
||||||
myStateSize = 0;
|
|
||||||
myLastTimeMachineAdd = false;
|
myLastTimeMachineAdd = false;
|
||||||
|
|
||||||
const string& prefix = myOSystem.settings().getBool("dev.settings") ? "dev." : "plr.";
|
const string& prefix = myOSystem.settings().getBool("dev.settings") ? "dev." : "plr.";
|
||||||
|
@ -138,7 +137,6 @@ bool RewindManager::addState(const string& message, bool timeMachine)
|
||||||
s.rewind(); // rewind Serializer internal buffers
|
s.rewind(); // rewind Serializer internal buffers
|
||||||
if(myStateManager.saveState(s) && myOSystem.console().tia().saveDisplay(s))
|
if(myStateManager.saveState(s) && myOSystem.console().tia().saveDisplay(s))
|
||||||
{
|
{
|
||||||
myStateSize = std::max(myStateSize, uInt32(s.size()));
|
|
||||||
state.message = message;
|
state.message = message;
|
||||||
state.cycles = myOSystem.console().tia().cycles();
|
state.cycles = myOSystem.console().tia().cycles();
|
||||||
myLastTimeMachineAdd = timeMachine;
|
myLastTimeMachineAdd = timeMachine;
|
||||||
|
@ -256,18 +254,22 @@ string RewindManager::saveAllStates()
|
||||||
buf.str("");
|
buf.str("");
|
||||||
out.putString(STATE_HEADER);
|
out.putString(STATE_HEADER);
|
||||||
out.putShort(numStates);
|
out.putShort(numStates);
|
||||||
out.putInt(myStateSize);
|
|
||||||
|
|
||||||
unique_ptr<uInt8[]> buffer = make_unique<uInt8[]>(myStateSize);
|
|
||||||
for (uInt32 i = 0; i < numStates; ++i)
|
for (uInt32 i = 0; i < numStates; ++i)
|
||||||
{
|
{
|
||||||
RewindState& state = myStateList.current();
|
RewindState& state = myStateList.current();
|
||||||
Serializer& s = state.data;
|
Serializer& s = state.data;
|
||||||
|
uInt32 stateSize = uInt32(s.size());
|
||||||
|
unique_ptr<uInt8[]> buffer = make_unique<uInt8[]>(stateSize);
|
||||||
|
|
||||||
|
out.putInt(stateSize);
|
||||||
|
|
||||||
// Rewind Serializer internal buffers
|
// Rewind Serializer internal buffers
|
||||||
s.rewind();
|
s.rewind();
|
||||||
|
|
||||||
// Save state
|
// Save state
|
||||||
s.getByteArray(buffer.get(), myStateSize);
|
s.getByteArray(buffer.get(), stateSize);
|
||||||
out.putByteArray(buffer.get(), myStateSize);
|
out.putByteArray(buffer.get(), stateSize);
|
||||||
out.putString(state.message);
|
out.putString(state.message);
|
||||||
out.putLong(state.cycles);
|
out.putLong(state.cycles);
|
||||||
|
|
||||||
|
@ -310,25 +312,27 @@ string RewindManager::loadAllStates()
|
||||||
if (in.getString() != STATE_HEADER)
|
if (in.getString() != STATE_HEADER)
|
||||||
return "Incompatible all states file";
|
return "Incompatible all states file";
|
||||||
numStates = in.getShort();
|
numStates = in.getShort();
|
||||||
myStateSize = in.getInt();
|
|
||||||
|
|
||||||
unique_ptr<uInt8[]> buffer = make_unique<uInt8[]>(myStateSize);
|
|
||||||
for (uInt32 i = 0; i < numStates; ++i)
|
for (uInt32 i = 0; i < numStates; ++i)
|
||||||
{
|
{
|
||||||
if (myStateList.full())
|
if (myStateList.full())
|
||||||
compressStates();
|
compressStates();
|
||||||
|
|
||||||
|
uInt32 stateSize = in.getInt();
|
||||||
|
unique_ptr<uInt8[]> buffer = make_unique<uInt8[]>(stateSize);
|
||||||
|
|
||||||
// Add new state at the end of the list (queue adds at end)
|
// Add new state at the end of the list (queue adds at end)
|
||||||
// This updates the 'current' iterator inside the list
|
// This updates the 'current' iterator inside the list
|
||||||
myStateList.addLast();
|
myStateList.addLast();
|
||||||
RewindState& state = myStateList.current();
|
RewindState& state = myStateList.current();
|
||||||
Serializer& s = state.data;
|
Serializer& s = state.data;
|
||||||
|
|
||||||
// Rewind Serializer internal buffers
|
// Rewind Serializer internal buffers
|
||||||
s.rewind();
|
s.rewind();
|
||||||
|
|
||||||
// Fill new state with saved values
|
// Fill new state with saved values
|
||||||
in.getByteArray(buffer.get(), myStateSize);
|
in.getByteArray(buffer.get(), stateSize);
|
||||||
s.putByteArray(buffer.get(), myStateSize);
|
s.putByteArray(buffer.get(), stateSize);
|
||||||
state.message = in.getString();
|
state.message = in.getString();
|
||||||
state.cycles = in.getLong();
|
state.cycles = in.getLong();
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,6 @@ class RewindManager
|
||||||
bool atLast() const { return myStateList.atLast(); }
|
bool atLast() const { return myStateList.atLast(); }
|
||||||
void resize(uInt32 size) { myStateList.resize(size); }
|
void resize(uInt32 size) { myStateList.resize(size); }
|
||||||
void clear() {
|
void clear() {
|
||||||
myStateSize = 0;
|
|
||||||
myStateList.clear();
|
myStateList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +175,6 @@ class RewindManager
|
||||||
uInt64 myHorizon{0};
|
uInt64 myHorizon{0};
|
||||||
double myFactor{0.0};
|
double myFactor{0.0};
|
||||||
bool myLastTimeMachineAdd{false};
|
bool myLastTimeMachineAdd{false};
|
||||||
uInt32 myStateSize{0};
|
|
||||||
|
|
||||||
struct RewindState {
|
struct RewindState {
|
||||||
Serializer data; // actual save state
|
Serializer data; // actual save state
|
||||||
|
|
|
@ -91,6 +91,8 @@ void Serializer::rewind()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
size_t Serializer::size() const
|
size_t Serializer::size() const
|
||||||
{
|
{
|
||||||
|
myStream->seekp(0, std::ios::end);
|
||||||
|
|
||||||
return myStream->tellp();
|
return myStream->tellp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue