Only unpause from state operations when we paused manually

This commit is contained in:
Jeffrey Pfau 2014-01-26 23:17:17 -08:00
parent c3a5fb497a
commit ef66e4a8c7
3 changed files with 28 additions and 7 deletions

View File

@ -256,6 +256,14 @@ void GBAThreadUnpause(struct GBAThread* threadContext) {
MutexUnlock(&threadContext->sync.videoFrameMutex);
}
int GBAThreadIsPaused(struct GBAThread* threadContext) {
int isPaused;
MutexLock(&threadContext->stateMutex);
isPaused = threadContext->state == THREAD_PAUSED;
MutexUnlock(&threadContext->stateMutex);
return isPaused;
}
void GBAThreadTogglePause(struct GBAThread* threadContext) {
int frameOn = 1;
MutexLock(&threadContext->stateMutex);
@ -278,7 +286,6 @@ void GBAThreadTogglePause(struct GBAThread* threadContext) {
MutexUnlock(&threadContext->sync.videoFrameMutex);
}
#ifdef USE_PTHREADS
struct GBAThread* GBAThreadGetContext(void) {
pthread_once(&_contextOnce, _createTLS);

View File

@ -66,6 +66,7 @@ void GBAThreadJoin(struct GBAThread* threadContext);
void GBAThreadPause(struct GBAThread* threadContext);
void GBAThreadUnpause(struct GBAThread* threadContext);
int GBAThreadIsPaused(struct GBAThread* threadContext);
void GBAThreadTogglePause(struct GBAThread* threadContext);
struct GBAThread* GBAThreadGetContext(void);

View File

@ -27,6 +27,7 @@ static void _pauseAfterFrame(struct GBAThread* context) {
static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_KeyboardEvent* event) {
enum GBAKey key = 0;
int isPaused = GBAThreadIsPaused(context);
switch (event->keysym.sym) {
case SDLK_z:
key = GBA_KEY_A;
@ -69,9 +70,13 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke
context->sync.audioWait = event->type != SDL_KEYDOWN;
return;
case SDLK_LEFTBRACKET:
if (!isPaused) {
GBAThreadPause(context);
}
GBARewind(context, 10);
if (!isPaused) {
GBAThreadUnpause(context);
}
default:
if (event->type == SDL_KEYDOWN) {
if (event->keysym.mod & KMOD_CTRL) {
@ -100,9 +105,13 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke
case SDLK_F8:
case SDLK_F9:
case SDLK_F10:
if (!isPaused) {
GBAThreadPause(context);
}
GBASaveState(context->gba, event->keysym.sym - SDLK_F1);
if (!isPaused) {
GBAThreadUnpause(context);
}
break;
default:
break;
@ -119,9 +128,13 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke
case SDLK_F8:
case SDLK_F9:
case SDLK_F10:
if (!isPaused) {
GBAThreadPause(context);
}
GBALoadState(context->gba, event->keysym.sym - SDLK_F1);
if (!isPaused) {
GBAThreadUnpause(context);
}
break;
default:
break;