Core: Restore sleep callback
Vicki Pfau vi@endrift.com
Sun, 09 Apr 2017 19:13:13 -0700
7 files changed,
24 insertions(+),
16 deletions(-)
M
include/mgba/core/interface.h
→
include/mgba/core/interface.h
@@ -38,6 +38,7 @@ void* context;
void (*videoFrameStarted)(void* context); void (*videoFrameEnded)(void* context); void (*coreCrashed)(void* context); + void (*sleep)(void* context); }; DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);@@ -51,10 +52,6 @@ };
struct mKeyCallback { uint16_t (*readKeys)(struct mKeyCallback*); -}; - -struct mStopCallback { - void (*stop)(struct mStopCallback*); }; struct mRotationSource {
M
include/mgba/core/thread.h
→
include/mgba/core/thread.h
@@ -62,6 +62,7 @@ ThreadCallback startCallback;
ThreadCallback resetCallback; ThreadCallback cleanCallback; ThreadCallback frameCallback; + ThreadCallback sleepCallback; void* userData; void (*run)(struct mCoreThread*);
M
include/mgba/internal/gba/gba.h
→
include/mgba/internal/gba/gba.h
@@ -99,7 +99,6 @@ struct VFile* biosVf;
struct mAVStream* stream; struct mKeyCallback* keyCallback; - struct mStopCallback* stopCallback; struct mCoreCallbacksList coreCallbacks; enum GBAIdleLoopOptimization idleOptimization;
M
src/core/thread.c
→
src/core/thread.c
@@ -120,6 +120,16 @@ }
_changeState(thread, THREAD_CRASHED, true); } +void _sleep(void* context) { + struct mCoreThread* thread = context; + if (!thread) { + return; + } + if (thread->sleepCallback) { + thread->sleepCallback(thread); + } +} + static THREAD_ENTRY _mCoreThreadRun(void* context) { struct mCoreThread* threadContext = context; #ifdef USE_PTHREADS@@ -143,6 +153,7 @@ struct mCoreCallbacks callbacks = {
.videoFrameStarted = _frameStarted, .videoFrameEnded = _frameEnded, .coreCrashed = _crashed, + .sleep = _sleep, .context = threadContext }; core->addCoreCallbacks(core, &callbacks);
M
src/gba/gba.c
→
src/gba/gba.c
@@ -89,8 +89,6 @@ gba->biosVf = 0;
gba->stream = NULL; gba->keyCallback = NULL; - gba->stopCallback = NULL; - gba->stopCallback = NULL; mCoreCallbacksListInit(&gba->coreCallbacks, 0); gba->biosChecksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);@@ -450,11 +448,14 @@ gba->cpu->halted = 1;
} void GBAStop(struct GBA* gba) { - if (!gba->stopCallback) { - return; + size_t c; + for (c = 0; c < mCoreCallbacksListSize(&gba->coreCallbacks); ++c) { + struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&gba->coreCallbacks, c); + if (callbacks->sleep) { + callbacks->sleep(callbacks->context); + } } gba->cpu->nextEvent = gba->cpu->cycles; - gba->stopCallback->stop(gba->stopCallback); } void GBADebug(struct GBA* gba, uint16_t flags) {
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -217,18 +217,16 @@ QMetaObject::invokeMethod(controller, "gamePaused", Q_ARG(mCoreThread*, context));
} }; - // TODO: Put back - /*m_threadContext.stopCallback = [](mCoreThread* context) { + m_threadContext.sleepCallback = [](mCoreThread* context) { if (!context) { - return false; + return; } GameController* controller = static_cast<GameController*>(context->userData); if (!mCoreSaveState(context->core, 0, controller->m_saveStateFlags)) { - return false; + return; } QMetaObject::invokeMethod(controller, "closeGame"); - return true; - };*/ + }; m_threadContext.logger.d.log = [](mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) { mThreadLogger* logContext = reinterpret_cast<mThreadLogger*>(logger);