From 93481c1f66280696fc1ee6ee7cc03e33686d8987 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Fri, 6 Dec 2019 20:18:47 -0600 Subject: [PATCH] Compiles and starts to run scripts. --- .gitignore | 1 + singe/singe.c | 48 ++++++++++++++++++++++++++++++++++++------------ singe/singe.pro | 2 ++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index ab0345b4e..3b4246f94 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ singe/thirdparty/SDL2_image/external/tiff-4.1.0/autom4te.cache/ thirdparty-build/ singe/extensions.h videotest/*.singe +games/ diff --git a/singe/singe.c b/singe/singe.c index ffba97b7f..84252c620 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -178,6 +178,7 @@ static double _overlayScaleX = 1; // Difference between overlay static double _overlayScaleY = 1; // Difference between overlay and video static bool _pauseState = false; // by RDG2010 static bool _pauseEnabled = true; // by RDG2010 +static bool _refreshDisplay = false; static bool _running = true; static bool _discStopped = true; static bool _mouseEnabled = true; @@ -294,6 +295,7 @@ int apiSingeVersion(lua_State *L); int apiSingeSetGameName(lua_State *L); int apiSingeGetScriptPath(lua_State *L); void callLua(const char *func, const char *sig, ...); +void channelFinished(int channel); int luaError(lua_State *L); void processKey(bool down, int keysym); @@ -487,6 +489,7 @@ int apiDiscPlay(lua_State *L) { (void)L; videoPlay(_videoHandle); _discStopped = false; + return 0; } @@ -584,6 +587,8 @@ int apiDiscStop(lua_State *L) { (void)L; videoPause(_videoHandle); _discStopped = true; + _refreshDisplay = true; + return 0; } @@ -755,6 +760,7 @@ int apiOverlayClear(lua_State *L) { (void)L; SDL_SetRenderDrawColor(_renderer, _colorBackground.r, _colorBackground.g, _colorBackground.b, _colorBackground.a); SDL_RenderClear(_renderer); + return 0; } @@ -824,10 +830,10 @@ int apiSoundLoad(lua_State *L) { int apiSoundPlay(lua_State *L) { - int n = lua_gettop(L); - int result = -1; - int id = -1; - SoundT *sound = NULL; + int n = lua_gettop(L); + int result = -1; + int id = -1; + SoundT *sound = NULL; if (n == 1) { if (lua_isinteger(L, 1)) { @@ -835,6 +841,7 @@ int apiSoundPlay(lua_State *L) { // Get our sound structure HASH_FIND_INT(_soundList, &id, sound); if (!sound) utilDie("No sound at index %d in apiSoundPlay.", id); + // Play it result = Mix_PlayChannel(-1, sound->chunk, 0); Mix_Volume(result, _effectsVolume * 2); } @@ -1339,6 +1346,7 @@ int apiSingeDisablePauseKey(lua_State *L) { int apiSingeQuit(lua_State *L) { (void)L; _running = false; + return 0; } @@ -1481,6 +1489,11 @@ void callLua(const char *func, const char *sig, ...) { } +void channelFinished(int channel) { + callLua("onSoundCompleted", "i", channel); +} + + int luaError(lua_State *L) { lua_Debug ar; int level = 0; @@ -1574,7 +1587,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { int thisFrame = -1; int lastFrame = -1; int intReturn = 0; - bool refresh = false; SDL_Texture *videoTexture = NULL; SpriteT *sprite = NULL; SpriteT *spriteTemp = NULL; @@ -1602,7 +1614,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { _luaContext = luaL_newstate(); luaL_openlibs(_luaContext); lua_atpanic(_luaContext, luaError); - if (luaL_dofile(_luaContext, _confScriptFile) != 0) utilDie("Error compiling script: %s", lua_tostring(_luaContext, -1)); // Lua API for Singe lua_register(_luaContext, "colorBackground", apiColorBackground); @@ -1699,6 +1710,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { _mice[x].y = videoGetHeight(_videoHandle) / 2; } SDL_SetWindowGrab(_window, SDL_TRUE); + SDL_ShowCursor(SDL_DISABLE); // Create overlay texture _overlay = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_TARGET, videoGetWidth(_videoHandle), videoGetHeight(_videoHandle)); @@ -1712,11 +1724,16 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { _effectsVolume = (int)((float)AUDIO_MAX_VOLUME * (float)_confVolumeNonVldp * (float)0.01); Mix_Volume(-1, _effectsVolume * 2); - // Start video + // Let us know when sounds end + Mix_ChannelFinished(channelFinished); + + // Start video paused videoPlay(_videoHandle); + videoPause(_videoHandle); _discStopped = false; - //***TODO*** Sound completed callback + // Start script + if (luaL_dofile(_luaContext, _confScriptFile) != 0) utilDie("Error compiling script: %s", lua_tostring(_luaContext, -1)); // Game Loop while (_running) { @@ -1829,28 +1846,34 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { SDL_SetRenderTarget(_renderer, _overlay); callLua("onOverlayUpdate", ">i", &intReturn); if (intReturn == 1) { - refresh = true; + _refreshDisplay = true; } // Update video thisFrame = videoUpdate(_videoHandle, &videoTexture); if ((thisFrame != lastFrame) && (thisFrame>= 0)) { lastFrame = thisFrame; - refresh = true; + _refreshDisplay = true; } // Update display - if (refresh) { + if (_refreshDisplay) { + //***TODO*** Handle overlay and blank disk frames SDL_SetRenderTarget(_renderer, NULL); SDL_RenderCopy(_renderer, videoTexture, NULL, NULL); + //SDL_RenderCopy(_renderer, _overlay, NULL, NULL); SDL_RenderPresent(_renderer); - refresh = false; + _refreshDisplay = false; } } // End game callLua("onShutdown", ""); + // Stop all sounds + Mix_HaltChannel(-1); + Mix_ChannelFinished(NULL); + // Stop Lua lua_close(_luaContext); @@ -1891,5 +1914,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { videoUnload(_videoHandle); // Stop mice + SDL_ShowCursor(SDL_ENABLE); ManyMouse_Quit(); } diff --git a/singe/singe.pro b/singe/singe.pro index ad54d28e5..ca42ad291 100644 --- a/singe/singe.pro +++ b/singe/singe.pro @@ -17,6 +17,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # +TARGET = singeEmu + # We're just a boring old C app TEMPLATE = app CONFIG += console