From 885b1cea4aced7e4d905d4b63ebbaf4d0f4e18a6 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 1 Apr 2020 19:36:40 -0500 Subject: [PATCH] Pausing implemented. --- singe/singe.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/singe/singe.c b/singe/singe.c index 967633ce1..9303ff637 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -101,6 +101,7 @@ typedef struct VideoS { int32_t id; int32_t handle; int64_t lastFrame; + bool wasPlayingBeforePause; SDL_Texture *texture; SDL_Surface *surface; UT_hash_handle hh; @@ -206,6 +207,7 @@ typedef struct GlobalS { bool mouseEnabled; bool mouseGrabbed; bool requestScreenShot; + bool wasPlayingBeforePause; VideoT *videoList; SpriteT *spriteList; SoundT *soundList; @@ -337,6 +339,7 @@ void putPixel(int32_t x, int32_t y); void startControllers(void); void stopControllers(void); void takeScreenshot(void); +void updatePauseState(void); #ifdef DEBUG_TOOLS void luaStackDump(lua_State *L); @@ -2635,6 +2638,7 @@ int32_t apiSingeSetPauseFlag(lua_State *L) { if (n == 1) { if (lua_isboolean(L, 1)) { _global.pauseState = (bool)lua_toboolean(L, 1); + updatePauseState(); result = true; } } @@ -3217,7 +3221,8 @@ void processKey(bool down, int32_t keysym, int32_t scancode) { //utilSay("Sending move %d - %s %d - %s", move, _global.controlMappings[move].name, _global.controlMappings[move].input[index], down ? "down" : "up"); if (!down) { if ((move == INPUT_PAUSE) && (_global.pauseEnabled)) { - //***TODO*** g_game->toggle_game_pause(); + _global.pauseState = _global.pauseState ? false : true; + updatePauseState(); } if (move == INPUT_GRAB) { if (_global.mouseGrabbed) { @@ -4148,3 +4153,43 @@ void takeScreenshot(void) { SDL_FreeSurface(surface); free(pixels); } + + +void updatePauseState(void) { + VideoT *video = NULL; + VideoT *videoTemp = NULL; + + if (_global.pauseState) { + // Pause laserdisc + if (!_global.discStopped) { + if (videoIsPlaying(_global.videoHandle)) { + _global.wasPlayingBeforePause = true; + videoPause(_global.videoHandle); + } + } + // Pause videos + HASH_ITER(hh, _global.videoList, video, videoTemp) { + if (videoIsPlaying(video->handle)) { + video->wasPlayingBeforePause = true; + videoPause(video->handle); + } + } + // Pause sounds + Mix_Pause(-1); + } else { + // Resume laserdisc + if ((!_global.discStopped) && (_global.wasPlayingBeforePause)) { + _global.wasPlayingBeforePause = false; + videoPlay(_global.videoHandle); + } + // Resume videos + HASH_ITER(hh, _global.videoList, video, videoTemp) { + if (video->wasPlayingBeforePause) { + video->wasPlayingBeforePause = false; + videoPlay(video->handle); + } + } + // Resume laserdisc + Mix_Resume(-1); + } +}