GBA Thread: Rewind API enhancements
Jeffrey Pfau jeffrey@endrift.com
Mon, 05 Jan 2015 23:11:56 -0800
7 files changed,
49 insertions(+),
9 deletions(-)
M
src/gba/gba-config.c
→
src/gba/gba-config.c
@@ -205,6 +205,9 @@ }
if (_lookupIntValue(config, "skipBios", &fakeBool)) { opts->skipBios = fakeBool; } + if (_lookupIntValue(config, "rewindEnable", &fakeBool)) { + opts->rewindEnable = fakeBool; + } _lookupIntValue(config, "fullscreen", &opts->fullscreen); _lookupIntValue(config, "width", &opts->width);@@ -216,6 +219,7 @@ ConfigurationSetValue(&config->defaultsTable, 0, "bios", opts->bios);
ConfigurationSetIntValue(&config->defaultsTable, 0, "skipBios", opts->skipBios); ConfigurationSetIntValue(&config->defaultsTable, 0, "logLevel", opts->logLevel); ConfigurationSetIntValue(&config->defaultsTable, 0, "frameskip", opts->frameskip); + ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindEnable", opts->rewindEnable); ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindBufferCapacity", opts->rewindBufferCapacity); ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindBufferInterval", opts->rewindBufferInterval); ConfigurationSetFloatValue(&config->defaultsTable, 0, "fpsTarget", opts->fpsTarget);
M
src/gba/gba-config.h
→
src/gba/gba-config.h
@@ -21,6 +21,7 @@ char* bios;
bool skipBios; int logLevel; int frameskip; + bool rewindEnable; int rewindBufferCapacity; int rewindBufferInterval; float fpsTarget;
M
src/gba/gba-serialize.c
→
src/gba/gba-serialize.c
@@ -249,6 +249,28 @@ thread->rewindBufferSize = thread->rewindBufferSize == thread->rewindBufferCapacity ? thread->rewindBufferCapacity : thread->rewindBufferSize + 1;
thread->rewindBufferWriteOffset = (offset + 1) % thread->rewindBufferCapacity; } +void GBARewindSettingsChanged(struct GBAThread* threadContext, int newCapacity, int newInterval) { + if (newCapacity == threadContext->rewindBufferCapacity && newInterval == threadContext->rewindBufferInterval) { + return; + } + threadContext->rewindBufferInterval = newInterval; + threadContext->rewindBufferNext = threadContext->rewindBufferInterval; + threadContext->rewindBufferSize = 0; + if (threadContext->rewindBuffer) { + int i; + for (i = 0; i < threadContext->rewindBufferCapacity; ++i) { + GBADeallocateState(threadContext->rewindBuffer[i]); + } + free(threadContext->rewindBuffer); + } + threadContext->rewindBufferCapacity = newCapacity; + if (threadContext->rewindBufferCapacity > 0) { + threadContext->rewindBuffer = calloc(threadContext->rewindBufferCapacity, sizeof(struct GBASerializedState*)); + } else { + threadContext->rewindBuffer = 0; + } +} + void GBARewind(struct GBAThread* thread, int nStates) { if (nStates > thread->rewindBufferSize || nStates < 0) { nStates = thread->rewindBufferSize;@@ -268,3 +290,7 @@ thread->rewindBufferSize -= nStates - 1;
thread->rewindBufferWriteOffset = (offset + 1) % thread->rewindBufferCapacity; GBADeserialize(thread->gba, state); } + +void GBARewindAll(struct GBAThread* thread) { + GBARewind(thread, thread->rewindBufferSize); +}
M
src/gba/gba-serialize.h
→
src/gba/gba-serialize.h
@@ -298,6 +298,8 @@ void GBADeallocateState(struct GBASerializedState* state);
struct GBAThread; void GBARecordFrame(struct GBAThread* thread); +void GBARewindSettingsChanged(struct GBAThread* thread, int newCapacity, int newInterval); void GBARewind(struct GBAThread* thread, int nStates); +void GBARewindAll(struct GBAThread* thread); #endif
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -240,8 +240,12 @@ void GBAMapOptionsToContext(const struct GBAOptions* opts, struct GBAThread* threadContext) {
threadContext->bios = VFileOpen(opts->bios, O_RDONLY); threadContext->frameskip = opts->frameskip; threadContext->logLevel = opts->logLevel; - threadContext->rewindBufferCapacity = opts->rewindBufferCapacity; - threadContext->rewindBufferInterval = opts->rewindBufferInterval; + if (opts->rewindEnable) { + threadContext->rewindBufferCapacity = opts->rewindBufferCapacity; + threadContext->rewindBufferInterval = opts->rewindBufferInterval; + } else { + threadContext->rewindBufferCapacity = 0; + } threadContext->skipBios = opts->skipBios; threadContext->sync.audioWait = opts->audioSync; threadContext->sync.videoFrameWait = opts->videoSync;@@ -276,13 +280,12 @@ threadContext->state = THREAD_INITIALIZED;
threadContext->sync.videoFrameOn = true; threadContext->sync.videoFrameSkip = 0; - threadContext->rewindBufferNext = threadContext->rewindBufferInterval; - threadContext->rewindBufferSize = 0; - if (threadContext->rewindBufferCapacity) { - threadContext->rewindBuffer = calloc(threadContext->rewindBufferCapacity, sizeof(void*)); - } else { - threadContext->rewindBuffer = 0; - } + threadContext->rewindBuffer = 0; + int newCapacity = threadContext->rewindBufferCapacity; + int newInterval = threadContext->rewindBufferInterval; + threadContext->rewindBufferCapacity = 0; + threadContext->rewindBufferInterval = 0; + GBARewindSettingsChanged(threadContext, newCapacity, newInterval); if (!threadContext->fpsTarget) { threadContext->fpsTarget = _defaultFPSTarget;
M
src/platform/qt/ConfigController.cpp
→
src/platform/qt/ConfigController.cpp
@@ -96,6 +96,9 @@ m_opts.videoSync = GameController::VIDEO_SYNC;
m_opts.fpsTarget = 60; m_opts.audioBuffers = 2048; m_opts.logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL; + m_opts.rewindEnable = false; + m_opts.rewindBufferInterval = 0; + m_opts.rewindBufferCapacity = 0; GBAConfigLoadDefaults(&m_config, &m_opts); GBAConfigLoad(&m_config); GBAConfigMap(&m_config, &m_opts);
M
src/platform/sdl/main.c
→
src/platform/sdl/main.c
@@ -45,6 +45,7 @@
struct GBAOptions opts = { .width = VIDEO_HORIZONTAL_PIXELS, .height = VIDEO_VERTICAL_PIXELS, + .rewindEnable = true, .audioBuffers = 512, .videoSync = false, .audioSync = true,