Core: Move rewind state coalescing into mCoreRewindRestore

This commit is contained in:
Vicki Pfau 2024-02-08 17:15:18 -08:00
parent c917a71ef8
commit 49d9b70e6f
4 changed files with 29 additions and 29 deletions

View File

@ -40,7 +40,7 @@ void mCoreRewindContextDeinit(struct mCoreRewindContext*);
struct mCore; struct mCore;
void mCoreRewindAppend(struct mCoreRewindContext*, struct mCore*); void mCoreRewindAppend(struct mCoreRewindContext*, struct mCore*);
bool mCoreRewindRestore(struct mCoreRewindContext*, struct mCore*); bool mCoreRewindRestore(struct mCoreRewindContext*, struct mCore*, unsigned count);
CXX_GUARD_END CXX_GUARD_END

View File

@ -115,7 +115,7 @@ void _rewindDiff(struct mCoreRewindContext* context) {
context->currentState->unmap(context->currentState, next, size); context->currentState->unmap(context->currentState, next, size);
} }
bool mCoreRewindRestore(struct mCoreRewindContext* context, struct mCore* core) { bool mCoreRewindRestore(struct mCoreRewindContext* context, struct mCore* core, unsigned count) {
#ifndef DISABLE_THREADING #ifndef DISABLE_THREADING
if (context->onThread) { if (context->onThread) {
MutexLock(&context->mutex); MutexLock(&context->mutex);
@ -129,15 +129,14 @@ bool mCoreRewindRestore(struct mCoreRewindContext* context, struct mCore* core)
#endif #endif
return false; return false;
} }
--context->size;
mCoreLoadStateNamed(core, context->previousState, SAVESTATE_SAVEDATA | SAVESTATE_RTC); for (; count && context->size; --count, --context->size) {
if (context->current == 0) { if (context->current == 0) {
context->current = mCoreRewindPatchesSize(&context->patchMemory); context->current = mCoreRewindPatchesSize(&context->patchMemory);
} }
--context->current; --context->current;
if (context->size) { if (context->size > 1) {
struct PatchFast* patch = mCoreRewindPatchesGetPointer(&context->patchMemory, context->current); struct PatchFast* patch = mCoreRewindPatchesGetPointer(&context->patchMemory, context->current);
size_t size2 = context->previousState->size(context->previousState); size_t size2 = context->previousState->size(context->previousState);
size_t size = context->currentState->size(context->currentState); size_t size = context->currentState->size(context->currentState);
@ -153,6 +152,11 @@ bool mCoreRewindRestore(struct mCoreRewindContext* context, struct mCore* core)
struct VFile* nextState = context->previousState; struct VFile* nextState = context->previousState;
context->previousState = context->currentState; context->previousState = context->currentState;
context->currentState = nextState; context->currentState = nextState;
}
mCoreLoadStateNamed(core, context->currentState, SAVESTATE_SAVEDATA | SAVESTATE_RTC);
#ifndef DISABLE_THREADING #ifndef DISABLE_THREADING
if (context->onThread) { if (context->onThread) {
MutexUnlock(&context->mutex); MutexUnlock(&context->mutex);

View File

@ -153,7 +153,7 @@ void _frameStarted(void* context) {
return; return;
} }
if (thread->core->opts.rewindEnable && thread->core->opts.rewindBufferCapacity > 0) { if (thread->core->opts.rewindEnable && thread->core->opts.rewindBufferCapacity > 0) {
if (!thread->impl->rewinding || !mCoreRewindRestore(&thread->impl->rewind, thread->core)) { if (!thread->impl->rewinding || !mCoreRewindRestore(&thread->impl->rewind, thread->core, 1)) {
if (thread->impl->rewind.rewindFrameCounter == 0) { if (thread->impl->rewind.rewindFrameCounter == 0) {
mCoreRewindAppend(&thread->impl->rewind, thread->core); mCoreRewindAppend(&thread->impl->rewind, thread->core);
thread->impl->rewind.rewindFrameCounter = thread->core->opts.rewindBufferInterval; thread->impl->rewind.rewindFrameCounter = thread->core->opts.rewindBufferInterval;

View File

@ -556,11 +556,7 @@ void CoreController::rewind(int states) {
if (!states) { if (!states) {
states = INT_MAX; states = INT_MAX;
} }
for (int i = 0; i < states; ++i) { mCoreRewindRestore(&m_threadContext.impl->rewind, m_threadContext.core, states);
if (!mCoreRewindRestore(&m_threadContext.impl->rewind, m_threadContext.core)) {
break;
}
}
interrupter.resume(); interrupter.resume();
emit frameAvailable(); emit frameAvailable();
emit rewound(); emit rewound();