diff --git a/singe/frameFile.c b/singe/frameFile.c index 39443b625..21bbde95b 100644 --- a/singe/frameFile.c +++ b/singe/frameFile.c @@ -101,7 +101,7 @@ int32_t frameFileInit(void) { } -int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { +int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer, bool showCalculated) { int32_t result = 0; int32_t count = 0; int64_t frame = 0; @@ -203,7 +203,7 @@ int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Re result = _nextId++; // Show debug output? - if (_confShowCalculated) { + if (showCalculated) { // 00000000011111111112222222222333333333344444444445555555555666666666677777777778 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 utilSay("Existing Framefile:\n"); diff --git a/singe/frameFile.h b/singe/frameFile.h index a1cb8846b..4cdd69594 100644 --- a/singe/frameFile.h +++ b/singe/frameFile.h @@ -31,7 +31,7 @@ int64_t frameFileGetFrame(int32_t frameFileHandle, int32_t videoHandle); int32_t frameFileInit(void); -int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); +int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer, bool showCalculated); int32_t frameFileSeek(int32_t frameFileHandle, int64_t seekFrame, int32_t *videoHandle, int64_t *actualFrame); int32_t frameFileQuit(void); int32_t frameFileUnload(int32_t frameFileHandle); diff --git a/singe/main.c b/singe/main.c index 907a0bb4e..757a78e78 100644 --- a/singe/main.c +++ b/singe/main.c @@ -252,25 +252,25 @@ int main(int argc, char *argv[]) { // Show Calculated Frame File Values case 'c': - _confShowCalculated = true; + _conf.showCalculated = true; break; // Data Dir case 'd': - if (_confDataDir) free(_confDataDir); - _confDataDir = strdup(arg); + if (_conf.dataDir) free(_conf.dataDir); + _conf.dataDir = strdup(arg); argCount++; break; // Effects Volume case 'e': - _confVolumeNonVldp = atoi(arg); + _conf.volumeNonVldp = atoi(arg); argCount++; break; // Full Screen case 'f': - _confFullScreen = true; + _conf.fullScreen = true; break; // Sinden Light Gun @@ -287,29 +287,29 @@ int main(int argc, char *argv[]) { // No Logos case 'k': - _confNoLogos = true; + _conf.noLogos = true; break; // Video Volume case 'l': - _confVolumeVldp = atoi(arg); + _conf.volumeVldp = atoi(arg); argCount++; break; // No Mouse case 'm': - _confNoMouse = true; + _conf.noMouse = true; break; // Overscan Zoom case 'o': - _confScaleFactor = atoi(arg); + _conf.scaleFactor = atoi(arg); argCount++; break; // No Sound case 's': - _confNoSound = true; + _conf.noSound = true; break; // Trace @@ -319,36 +319,36 @@ int main(int argc, char *argv[]) { // Ugly Stretched Video case 'u': - _confStretchVideo = true; + _conf.stretchVideo = true; break; // Video File case 'v': - if (_confVideoFile) free(_confVideoFile); - _confVideoFile = strdup(arg); + if (_conf.videoFile) free(_conf.videoFile); + _conf.videoFile = strdup(arg); argCount++; break; // Full Screen Windowed case 'w': - _confFullScreenWindow = true; + _conf.fullScreenWindow = true; break; // X Resolution case 'x': - _confXResolution = atoi(arg); + _conf.xResolution = atoi(arg); argCount++; break; // Y Resolution case 'y': - _confYResolution = atoi(arg); + _conf.yResolution = atoi(arg); argCount++; break; // No console output or splash screens case 'z': - _confNoConsole = true; + _conf.noConsole = true; break; default: @@ -358,123 +358,123 @@ int main(int argc, char *argv[]) { } // For that dumb OS - if (!_confNoConsole) utilRedirectConsole(); + if (!_conf.noConsole) utilRedirectConsole(); // Did we get a filename or path to open? if ((argc - argCount) != 1) showUsage(exeName, "No script file specified."); - _confScriptFile = strdup(argv[argCount]); - utilFixPathSeparators(&_confScriptFile, false); + _conf.scriptFile = strdup(argv[argCount]); + utilFixPathSeparators(&_conf.scriptFile, false); // Exists? - if (!utilFileExists(_confScriptFile)) { + if (!utilFileExists(_conf.scriptFile)) { // Missing. Is a path? - if (utilPathExists(_confScriptFile)) { + if (utilPathExists(_conf.scriptFile)) { // See if the script exists in the path. - temp = utilCreateString("%s%c%s.singe", _confScriptFile, utilGetPathSeparator(), utilGetLastPathComponent(_confScriptFile)); + temp = utilCreateString("%s%c%s.singe", _conf.scriptFile, utilGetPathSeparator(), utilGetLastPathComponent(_conf.scriptFile)); if (utilFileExists(temp)) { // Found script named for path inside path. - free(_confScriptFile); - _confScriptFile = temp; + free(_conf.scriptFile); + _conf.scriptFile = temp; temp = NULL; } else { // Not in the path either. - free(_confScriptFile); - _confScriptFile = NULL; + free(_conf.scriptFile); + _conf.scriptFile = NULL; } } else { // Not a path either. - free(_confScriptFile); - _confScriptFile = NULL; + free(_conf.scriptFile); + _conf.scriptFile = NULL; } } - if (!_confScriptFile) showUsage(exeName, "Unable to locate script."); + if (!_conf.scriptFile) showUsage(exeName, "Unable to locate script."); // Do we need to generate a video name? - if (_confVideoFile) { - utilFixPathSeparators(&_confVideoFile, false); - if (!utilFileExists(_confVideoFile)) { - free(_confVideoFile); - _confVideoFile = NULL; + if (_conf.videoFile) { + utilFixPathSeparators(&_conf.videoFile, false); + if (!utilFileExists(_conf.videoFile)) { + free(_conf.videoFile); + _conf.videoFile = NULL; } } else { - x = (int32_t)(strlen(_confScriptFile) - strlen(utilGetFileExtension(_confScriptFile))) - 1; + x = (int32_t)(strlen(_conf.scriptFile) - strlen(utilGetFileExtension(_conf.scriptFile))) - 1; if (x < 0) { x = 0; } - temp = strdup(_confScriptFile); + temp = strdup(_conf.scriptFile); temp[x] = 0; // Check all known extensions - lower case only, Windows users! x = 0; while (ffmpegExtensions[x]) { - _confVideoFile = utilCreateString("%s.%s", temp, ffmpegExtensions[x]); - if (utilFileExists(_confVideoFile)) { + _conf.videoFile = utilCreateString("%s.%s", temp, ffmpegExtensions[x]); + if (utilFileExists(_conf.videoFile)) { break; } - free(_confVideoFile); - _confVideoFile = NULL; + free(_conf.videoFile); + _conf.videoFile = NULL; x++; } free(temp); // If we still don't have one, try a framefile - if (!_confVideoFile) { - _confVideoFile = utilCreateString("%s.txt", temp); - if (!utilFileExists(_confVideoFile)) { - free(_confVideoFile); - _confVideoFile = NULL; + if (!_conf.videoFile) { + _conf.videoFile = utilCreateString("%s.txt", temp); + if (!utilFileExists(_conf.videoFile)) { + free(_conf.videoFile); + _conf.videoFile = NULL; } } } - if (!_confVideoFile) showUsage(exeName, "Unable to locate video."); + if (!_conf.videoFile) showUsage(exeName, "Unable to locate video."); // Is it a framefile? - if (strncmp(utilGetFileExtension(_confVideoFile), "txt", 3) == 0) { - _confIsFrameFile = true; + if (strncmp(utilGetFileExtension(_conf.videoFile), "txt", 3) == 0) { + _conf.isFrameFile = true; } // Do we need to generate a data directory name? - if (_confDataDir) { - utilFixPathSeparators(&_confDataDir, false); + if (_conf.dataDir) { + utilFixPathSeparators(&_conf.dataDir, false); // Try to create data directory to ensure it exists. - utilMkDirP(_confDataDir, 0777); + utilMkDirP(_conf.dataDir, 0777); // Does it exist? - if (!utilPathExists(_confDataDir)) { - free(_confDataDir); - _confDataDir = NULL; + if (!utilPathExists(_conf.dataDir)) { + free(_conf.dataDir); + _conf.dataDir = NULL; } } else { // Put it in the game folder. - x = (int32_t)(strlen(_confScriptFile) - strlen(utilGetLastPathComponent(_confScriptFile))) - 1; + x = (int32_t)(strlen(_conf.scriptFile) - strlen(utilGetLastPathComponent(_conf.scriptFile))) - 1; if (x < 0) { x = 0; } - temp = strdup(_confScriptFile); + temp = strdup(_conf.scriptFile); temp[x] = 0; - _confDataDir = strdup(temp); + _conf.dataDir = strdup(temp); free(temp); temp = NULL; } - if (!_confDataDir) showUsage(exeName, "Unable to locate data directory."); - utilFixPathSeparators(&_confDataDir, true); + if (!_conf.dataDir) showUsage(exeName, "Unable to locate data directory."); + utilFixPathSeparators(&_conf.dataDir, true); // Do they want tracing? if (tracing) { - temp = utilCreateString("%strace.txt", _confDataDir); + temp = utilCreateString("%strace.txt", _conf.dataDir); utilTraceStart(temp); free(temp); temp = NULL; } // Do the full screen options make sense? - if (_confFullScreen && _confFullScreenWindow) showUsage(exeName, "Full Screen or Full Screen Windowed. Pick one."); + if (_conf.fullScreen && _conf.fullScreenWindow) showUsage(exeName, "Full Screen or Full Screen Windowed. Pick one."); // Sane volume values? - if ((_confVolumeVldp < 0) || (_confVolumeVldp > 100)) showUsage(exeName, "Laserdisc volume must be between 0 and 100 percent."); - if ((_confVolumeNonVldp < 0) || (_confVolumeNonVldp > 100)) showUsage(exeName, "Effects volume must be between 0 and 100 percent."); + if ((_conf.volumeVldp < 0) || (_conf.volumeVldp > 100)) showUsage(exeName, "Laserdisc volume must be between 0 and 100 percent."); + if ((_conf.volumeNonVldp < 0) || (_conf.volumeNonVldp > 100)) showUsage(exeName, "Effects volume must be between 0 and 100 percent."); // Sane scale factor? - if ((_confScaleFactor < 50) || (_confScaleFactor > 100)) showUsage(exeName, "Display scale must be between 50 and 100 percent."); + if ((_conf.scaleFactor < 50) || (_conf.scaleFactor > 100)) showUsage(exeName, "Display scale must be between 50 and 100 percent."); // Sinden light gun? if (sindenString) { - if (_confScaleFactor != 100) showUsage(exeName, "Cannot use --sindengun and --scalefactor together."); + if (_conf.scaleFactor != 100) showUsage(exeName, "Cannot use --sindengun and --scalefactor together."); // Was it wrapped in quotes? if ((sindenString[0] == '"') || (sindenString[0] == '\'')) { sindenString[0] = ' '; @@ -487,12 +487,12 @@ int main(int argc, char *argv[]) { // RW GW BW WW RB GB BB WB - Custom color "white" border and width then custom color "black" border and width temp = strtok(sindenString, " "); while (temp != NULL) { - _confSindenArgv[_confSindenArgc++] = atoi(temp); + _conf.sindenArgv[_conf.sindenArgc++] = atoi(temp); temp = strtok(NULL, " "); - if ((temp != NULL) && (_confSindenArgc > SINDEN_OPTION_COUNT)) showUsage(exeName, "Too many arguments to --sindengun."); + if ((temp != NULL) && (_conf.sindenArgc > SINDEN_OPTION_COUNT)) showUsage(exeName, "Too many arguments to --sindengun."); } // Did we get a sane number of arguments? - if ((_confSindenArgc != SINDEN_WHITE) && (_confSindenArgc != SINDEN_WHITE_BLACK) && (_confSindenArgc != SINDEN_CUSTOM_WHITE) && (_confSindenArgc != SINDEN_CUSTOM_WHITE_BLACK) && (_confSindenArgc != SINDEN_CUSTOM_WHITE_CUSTOM_BLACK)) showUsage(exeName, "Bad argument count to --sindengun."); + if ((_conf.sindenArgc != SINDEN_WHITE) && (_conf.sindenArgc != SINDEN_WHITE_BLACK) && (_conf.sindenArgc != SINDEN_CUSTOM_WHITE) && (_conf.sindenArgc != SINDEN_CUSTOM_WHITE_BLACK) && (_conf.sindenArgc != SINDEN_CUSTOM_WHITE_CUSTOM_BLACK)) showUsage(exeName, "Bad argument count to --sindengun."); free(sindenString); } @@ -501,7 +501,7 @@ int main(int argc, char *argv[]) { if (SDL_GetCurrentDisplayMode(0, &mode) < 0) utilDie("%s", SDL_GetError()); // Determine resolution if not specified - if ((_confXResolution <= 0) || (_confYResolution <= 0)) { + if ((_conf.xResolution <= 0) || (_conf.yResolution <= 0)) { // Did they specify an aspect ratio? if (aspectString) { aspectNum = atoi(aspectString); @@ -538,12 +538,12 @@ int main(int argc, char *argv[]) { if (bestRatioIndex < 0) showUsage(exeName, "Unknown aspect ratio."); x = 0; // Were both resolutions not specified? - if ((_confXResolution <= 0) && (_confYResolution <= 0)) { + if ((_conf.xResolution <= 0) && (_conf.yResolution <= 0)) { // Are we full screen? - if (_confFullScreen || _confFullScreenWindow) { + if (_conf.fullScreen || _conf.fullScreenWindow) { // Use desktop resolution - _confXResolution = mode.w; - _confYResolution = mode.h; + _conf.xResolution = mode.w; + _conf.yResolution = mode.h; } else { // Find largest window that will fit on the screen but not fill it while (modes[x].ratio.aspectNum != 0) { @@ -554,8 +554,8 @@ int main(int argc, char *argv[]) { } x++; } - _confXResolution = modes[bestResIndex].resolution.width; - _confYResolution = modes[bestResIndex].resolution.height; + _conf.xResolution = modes[bestResIndex].resolution.width; + _conf.yResolution = modes[bestResIndex].resolution.height; } } else { // Find unprovided width/height using provided value @@ -563,18 +563,18 @@ int main(int argc, char *argv[]) { // Is this the aspect ratio we're using? if ((modes[bestRatioIndex].ratio.aspectNum == modes[x].ratio.aspectNum) && (modes[bestRatioIndex].ratio.aspectDom == modes[x].ratio.aspectDom)) { // Do we have the width or height? - if (_confXResolution > 0) { + if (_conf.xResolution > 0) { // We have the width. Is this the matching entry? - if (modes[x].resolution.width == _confXResolution) { + if (modes[x].resolution.width == _conf.xResolution) { bestResIndex = x; - _confYResolution = modes[x].resolution.height; + _conf.yResolution = modes[x].resolution.height; break; } } else { // We have the height. Is this the matching entry? - if (modes[x].resolution.height == _confYResolution) { + if (modes[x].resolution.height == _conf.yResolution) { bestResIndex = x; - _confXResolution = modes[x].resolution.width; + _conf.xResolution = modes[x].resolution.width; break; } } @@ -584,9 +584,9 @@ int main(int argc, char *argv[]) { } } // Did we end up with a valid resolution? - if (_confXResolution <= 0) showUsage(exeName, "Unable to determine X resolution. (Is the Y value sane?)"); - if (_confYResolution <= 0) showUsage(exeName, "Unable to determine Y resolution. (Is the X value sane?)"); - if ((_confXResolution > mode.w) || (_confYResolution > mode.h)) showUsage(exeName, "Specified resolution is larger than the display."); + if (_conf.xResolution <= 0) showUsage(exeName, "Unable to determine X resolution. (Is the Y value sane?)"); + if (_conf.yResolution <= 0) showUsage(exeName, "Unable to determine Y resolution. (Is the X value sane?)"); + if ((_conf.xResolution > mode.w) || (_conf.yResolution > mode.h)) showUsage(exeName, "Specified resolution is larger than the display."); // Init SDL_mixer ***FIX*** flags = /* MIX_INIT_FLAC | */ MIX_INIT_MOD | /* MIX_INIT_MP3 | */ MIX_INIT_OGG | MIX_INIT_MID | MIX_INIT_OPUS; @@ -602,7 +602,7 @@ int main(int argc, char *argv[]) { if (TTF_Init() < 0) utilDie("%s", TTF_GetError()); // Create Resizable Window - window = SDL_CreateWindow("SINGE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _confXResolution, _confYResolution, SDL_WINDOW_RESIZABLE); + window = SDL_CreateWindow("SINGE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _conf.xResolution, _conf.yResolution, SDL_WINDOW_RESIZABLE); if (window == NULL) utilDie("%s", SDL_GetError()); // Window Icon @@ -613,8 +613,8 @@ int main(int argc, char *argv[]) { icon = NULL; // Do we want full screen of some kind? - if (_confFullScreen || _confFullScreenWindow) { - flags = _confFullScreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP; + if (_conf.fullScreen || _conf.fullScreenWindow) { + flags = _conf.fullScreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP; SDL_SetWindowFullscreen(window, (Uint32)flags); } @@ -652,14 +652,14 @@ int main(int argc, char *argv[]) { IMG_Quit(); Mix_Quit(); SDL_Quit(); - if (_confDataDir) free(_confDataDir); - if (_confVideoFile) free(_confVideoFile); - if (_confScriptFile) free(_confScriptFile); + if (_conf.dataDir) free(_conf.dataDir); + if (_conf.videoFile) free(_conf.videoFile); + if (_conf.scriptFile) free(_conf.scriptFile); utilTraceEnd(); ap_free(&parser); #ifdef _WIN32 - if (!_confNoConsole) getchar(); + if (!_conf.noConsole) getchar(); #endif return 0; diff --git a/singe/singe.c b/singe/singe.c index 59d196a91..efce77479 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -118,11 +118,17 @@ enum { LDP_SEARCHING, LDP_STOPPED, LDP_PLAYING, - LDP_PAUSE + LDP_PAUSED }; enum { - // Index into _controlMappings array + FONT_QUALITY_SOLID = 1, + FONT_QUALITY_SHADED, + FONT_QUALITY_BLENDED +}; + +enum { + // Index into _global.controlMappings array INPUT_UP = 0, INPUT_LEFT, INPUT_DOWN, @@ -153,94 +159,55 @@ enum { // Command line options -char *_confVideoFile = NULL; -char *_confScriptFile = NULL; -char *_confDataDir = NULL; -bool _confIsFrameFile = false; -bool _confStretchVideo = false; -bool _confNoMouse = false; -bool _confNoSound = false; -bool _confFullScreen = false; -bool _confFullScreenWindow = false; -bool _confShowCalculated = false; -bool _confNoConsole = false; -bool _confNoLogos = false; -int32_t _confVolumeVldp = 100; -int32_t _confVolumeNonVldp = 100; -int32_t _confScaleFactor = 100; -int32_t _confXResolution = -1; -int32_t _confYResolution = -1; -int32_t _confSindenArgc = 0; -int32_t _confSindenArgv[SINDEN_OPTION_COUNT]; +ConfigT _conf; + + +typedef struct GlobalS { + MouseT mice[MAX_MICE]; + lua_State *luaContext; + SDL_Color colorForeground; + SDL_Color colorBackground; + SDL_Surface *overlay; + SDL_Window *window; + SDL_Renderer *renderer; + SDL_Texture *videoTexture; + SDL_Surface *consoleFontSurface; + SDL_GameController **controllers; + int32_t controllerCount; + int32_t controllerDeadZone; + int32_t consoleFontWidth; + int32_t consoleFontHeight; + int32_t nextSpriteId; + int32_t nextSoundId; + int32_t nextFontId; + int32_t effectsVolume; + int32_t keyboardMode; + int32_t frameFileHandle; + int32_t videoHandle; + int32_t fontQuality; + int32_t mouseMode; + int32_t mouseCount; + int32_t axisCache[AXIS_COUNT]; + double overlayScaleX; // Difference between overlay and video + double overlayScaleY; // Difference between overlay and video + bool pauseState; // by RDG2010 + bool pauseEnabled; // by RDG2010 + bool refreshDisplay; + bool running; + bool discStopped; + bool mouseEnabled; + bool mouseGrabbed; + bool requestScreenShot; + SpriteT *spriteList; + SoundT *soundList; + FontT *fontList; + FontT *fontCurrent; + MappingT controlMappings[INPUT_COUNT]; +} GlobalT; // Other globals -static MouseT _mice[MAX_MICE]; -static lua_State *_luaContext = NULL; -static SDL_Color _colorForeground = { 255, 255, 255, 255 }; -static SDL_Color _colorBackground = { 0, 0, 0, 0 }; -static SDL_Surface *_overlay = NULL; -static SDL_Window *_window = NULL; -static SDL_Renderer *_renderer = NULL; -static SDL_Texture *_videoTexture = NULL; -static SDL_Surface *_consoleFontSurface = NULL; -static SDL_GameController **_controllers = NULL; -static int32_t _controllerCount = 0; -static int32_t _controllerDeadZone = 0; -static int32_t _consoleFontWidth = 0; -static int32_t _consoleFontHeight = 0; -static int32_t _nextSpriteId = 0; -static int32_t _nextSoundId = 0; -static int32_t _nextFontId = 0; -static int32_t _effectsVolume = AUDIO_MAX_VOLUME; -static int32_t _keyboardMode = KEYBD_NORMAL; -static int32_t _frameFileHandle = -1; -static int32_t _videoHandle = -1; -static int32_t _fontQuality = 1; -static int32_t _mouseMode = MOUSE_SINGLE; -static int32_t _mouseCount = 0; -static int32_t _axisCache[AXIS_COUNT]; -static double _overlayScaleX = 1; // Difference between overlay and video -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; -static bool _mouseGrabbed = false; -static bool _requestScreenShot = false; -static SpriteT *_spriteList = NULL; -static SoundT *_soundList = NULL; -static FontT *_fontList = NULL; -static FontT *_fontCurrent = NULL; - -static MappingT _controlMappings[] = { - { "INPUT_UP", 0, 0, NULL }, - { "INPUT_LEFT", 1, 0, NULL }, - { "INPUT_DOWN", 2, 0, NULL }, - { "INPUT_RIGHT", 3, 0, NULL }, - { "INPUT_1P_START", 4, 0, NULL }, - { "INPUT_2P_START", 5, 0, NULL }, - { "INPUT_ACTION_1", 6, 0, NULL }, - { "INPUT_ACTION_2", 7, 0, NULL }, - { "INPUT_ACTION_3", 8, 0, NULL }, - { "INPUT_1P_COIN", 9, 0, NULL }, - { "INPUT_2P_COIN", 10, 0, NULL }, - { "INPUT_SKILL_EASY", 11, 0, NULL }, - { "INPUT_SKILL_MEDIUM", 12, 0, NULL }, - { "INPUT_SKILL_HARD", 13, 0, NULL }, - { "INPUT_SERVICE", 14, 0, NULL }, - { "INPUT_TEST_MODE", 15, 0, NULL }, - { "INPUT_RESET_CPU", 16, 0, NULL }, - { "INPUT_SCREENSHOT", 17, 0, NULL }, - { "INPUT_QUIT", 18, 0, NULL }, - { "INPUT_PAUSE", 19, 0, NULL }, - { "INPUT_CONSOLE", 20, 0, NULL }, - { "INPUT_ACTION_4", 21, 0, NULL }, - { "INPUT_TILT", 22, 0, NULL }, - { "INPUT_GRAB", 23, 0, NULL } -}; +GlobalT _global; int32_t apiColorBackground(lua_State *L); @@ -333,16 +300,16 @@ int32_t apiColorBackground(lua_State *L) { if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 2)) { if (lua_isnumber(L, 3)) { - d = lua_tonumber(L, 1); _colorBackground.r = (byte)d; - d = lua_tonumber(L, 2); _colorBackground.g = (byte)d; - d = lua_tonumber(L, 3); _colorBackground.b = (byte)d; + d = lua_tonumber(L, 1); _global.colorBackground.r = (byte)d; + d = lua_tonumber(L, 2); _global.colorBackground.g = (byte)d; + d = lua_tonumber(L, 3); _global.colorBackground.b = (byte)d; if (n == 3) { - _colorBackground.a = (byte)255; + _global.colorBackground.a = (byte)255; } else { if (lua_isnumber(L, 4)) { - d = lua_tonumber(L, 4); _colorBackground.a = (byte)d; + d = lua_tonumber(L, 4); _global.colorBackground.a = (byte)d; } else { - _colorBackground.a = (byte)255; + _global.colorBackground.a = (byte)255; } } result = true; @@ -352,7 +319,7 @@ int32_t apiColorBackground(lua_State *L) { } if (result) { - luaTrace(L, "colorBackground", "%d %d %d %d", _colorBackground.r, _colorBackground.g, _colorBackground.b, _colorBackground.a); + luaTrace(L, "colorBackground", "%d %d %d %d", _global.colorBackground.r, _global.colorBackground.g, _global.colorBackground.b, _global.colorBackground.a); } else { luaTrace(L, "colorBackground", "Failed!"); } @@ -370,16 +337,16 @@ int32_t apiColorForeground(lua_State *L) { if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 2)) { if (lua_isnumber(L, 3)) { - d = lua_tonumber(L, 1); _colorForeground.r = (byte)d; - d = lua_tonumber(L, 2); _colorForeground.g = (byte)d; - d = lua_tonumber(L, 3); _colorForeground.b = (byte)d; + d = lua_tonumber(L, 1); _global.colorForeground.r = (byte)d; + d = lua_tonumber(L, 2); _global.colorForeground.g = (byte)d; + d = lua_tonumber(L, 3); _global.colorForeground.b = (byte)d; if (n == 3) { - _colorForeground.a = (byte)255; + _global.colorForeground.a = (byte)255; } else { if (lua_isnumber(L, 4)) { - d = lua_tonumber(L, 4); _colorForeground.a = (byte)d; + d = lua_tonumber(L, 4); _global.colorForeground.a = (byte)d; } else { - _colorForeground.a = (byte)255; + _global.colorForeground.a = (byte)255; } } result = true; @@ -389,7 +356,7 @@ int32_t apiColorForeground(lua_State *L) { } if (result) { - luaTrace(L, "colorForeground", "%d %d %d %d", _colorForeground.r, _colorForeground.g, _colorForeground.b, _colorForeground.a); + luaTrace(L, "colorForeground", "%d %d %d %d", _global.colorForeground.r, _global.colorForeground.g, _global.colorForeground.b, _global.colorForeground.a); } else { luaTrace(L, "colorForeground", "Failed!"); } @@ -413,7 +380,7 @@ int32_t apiControllerGetAxis(lua_State *L) { d = lua_tonumber(L, 2); a = (int32_t)d; if ((c < 0) || (c >= MAX_CONTROLLERS)) luaDie(L, "controllerGetAxis", "Invalid controller index: %d", c); if ((a < 0) || (a >= CONTROLLER_AXIS_COUNT)) luaDie(L, "controllerGetAxis", "Invalid controller axis: %d", a); - v = _axisCache[c * CONTROLLER_AXIS_COUNT + a]; + v = _global.axisCache[c * CONTROLLER_AXIS_COUNT + a]; result = true; } } @@ -433,7 +400,7 @@ int32_t apiControllerGetAxis(lua_State *L) { int32_t apiDaphneGetHeight(lua_State *L) { int32_t y; - SDL_GetWindowSize(_window, NULL, &y); + SDL_GetWindowSize(_global.window, NULL, &y); luaTrace(L, "daphneGetHeight", "%d", y); lua_pushinteger(L, y); return 1; @@ -442,7 +409,7 @@ int32_t apiDaphneGetHeight(lua_State *L) { int32_t apiDaphneGetWidth(lua_State *L) { int32_t x; - SDL_GetWindowSize(_window, &x, NULL); + SDL_GetWindowSize(_global.window, &x, NULL); luaTrace(L, "daphneGetWidth", "%d", x); lua_pushinteger(L, x); return 1; @@ -452,7 +419,7 @@ int32_t apiDaphneGetWidth(lua_State *L) { int32_t apiDaphneScreenshot(lua_State *L) { luaTrace(L, "daphneScreenshot", "Screenshot requested."); - _requestScreenShot = true; + _global.requestScreenShot = true; return 0; } @@ -484,13 +451,13 @@ int32_t apiDiscAudio(lua_State *L) { if (n == 2) { if (lua_isnumber(L, 1)) { if (lua_isboolean(L, 2)) { - if (_videoHandle >= 0) { + if (_global.videoHandle >= 0) { d = lua_tonumber(L, 1); channel = (int32_t)d; d = lua_toboolean(L, 2); onOff = (bool)d; - videoGetVolume(_videoHandle, &left, &right); - if (channel == 1) left = (onOff ? _confVolumeVldp : 0); - if (channel == 2) right = (onOff ? _confVolumeVldp : 0); - videoSetVolume(_videoHandle, left, right); + videoGetVolume(_global.videoHandle, &left, &right); + if (channel == 1) left = (onOff ? _conf.volumeVldp : 0); + if (channel == 2) right = (onOff ? _conf.volumeVldp : 0); + videoSetVolume(_global.videoHandle, left, right); result = true; } } @@ -518,11 +485,11 @@ int32_t apiDiscChangeSpeed(lua_State *L) { int32_t apiDiscGetFrame(lua_State *L) { int64_t frame = 0; - if (!_discStopped) { - if (_confIsFrameFile) { - frame = frameFileGetFrame(_frameFileHandle, _videoHandle); + if (!_global.discStopped) { + if (_conf.isFrameFile) { + frame = frameFileGetFrame(_global.frameFileHandle, _global.videoHandle); } else { - if (_videoHandle >= 0) frame = videoGetFrame(_videoHandle); + if (_global.videoHandle >= 0) frame = videoGetFrame(_global.videoHandle); } } @@ -535,8 +502,8 @@ int32_t apiDiscGetFrame(lua_State *L) { int32_t apiDiscPause(lua_State *L) { (void)L; - if (!_discStopped) { - if (_videoHandle >= 0) videoPause(_videoHandle); + if (!_global.discStopped) { + if (_global.videoHandle >= 0) videoPause(_global.videoHandle); luaTrace(L, "discPause", ""); } else { luaTrace(L, "discPause", "Failed! Disc is stopped."); @@ -553,8 +520,8 @@ int32_t apiDiscPauseAtFrame(lua_State *L) { int32_t apiDiscPlay(lua_State *L) { (void)L; - if (_videoHandle >= 0) videoPlay(_videoHandle); - _discStopped = false; + if (_global.videoHandle >= 0) videoPlay(_global.videoHandle); + _global.discStopped = false; luaTrace(L, "discPlay", ""); return 0; } @@ -572,13 +539,13 @@ int32_t apiDiscSearch(lua_State *L) { if (n == 1) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); frame = (int64_t)d; - if (_confIsFrameFile) { - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + if (_conf.isFrameFile) { + frameFileSeek(_global.frameFileHandle, frame, &_global.videoHandle, &aFrame); } else { - if (_videoHandle >= 0) videoSeek(_videoHandle, frame); + if (_global.videoHandle >= 0) videoSeek(_global.videoHandle, frame); } - if (_videoHandle >= 0) videoPause(_videoHandle); - _discStopped = false; + if (_global.videoHandle >= 0) videoPause(_global.videoHandle); + _global.discStopped = false; result = true; } } @@ -618,15 +585,15 @@ int32_t apiDiscSkipBackward(lua_State *L) { // If disc is not stopped, seek backwards to given frame. Do not change play/pause state. - if (!_discStopped) { + if (!_global.discStopped) { if (n == 1) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); - if (_videoHandle >= 0) frame = videoGetFrame(_videoHandle) - (int64_t)d; - if (_confIsFrameFile) { - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + if (_global.videoHandle >= 0) frame = videoGetFrame(_global.videoHandle) - (int64_t)d; + if (_conf.isFrameFile) { + frameFileSeek(_global.frameFileHandle, frame, &_global.videoHandle, &aFrame); } else { - if (_videoHandle >= 0) videoSeek(_videoHandle, frame); + if (_global.videoHandle >= 0) videoSeek(_global.videoHandle, frame); } result = true; } @@ -663,14 +630,14 @@ int32_t apiDiscSkipForward(lua_State *L) { // If disc is not stopped, seek ahead to given frame. Do not change play/pause state. - if (!_discStopped) { + if (!_global.discStopped) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); if (_videoHandle >= 0) frame = videoGetFrame(_videoHandle) + (int64_t)d; - if (_confIsFrameFile) { - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + d = lua_tonumber(L, 1); if (_global.videoHandle >= 0) frame = videoGetFrame(_global.videoHandle) + (int64_t)d; + if (_conf.isFrameFile) { + frameFileSeek(_global.frameFileHandle, frame, &_global.videoHandle, &aFrame); } else { - if (_videoHandle >= 0) videoSeek(_videoHandle, frame); + if (_global.videoHandle >= 0) videoSeek(_global.videoHandle, frame); } result = true; } @@ -702,13 +669,13 @@ int32_t apiDiscSkipToFrame(lua_State *L) { if (n == 1) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); frame = (int64_t)d; - if (_confIsFrameFile) { - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + if (_conf.isFrameFile) { + frameFileSeek(_global.frameFileHandle, frame, &_global.videoHandle, &aFrame); } else { - if (_videoHandle >= 0) videoSeek(_videoHandle, frame); + if (_global.videoHandle >= 0) videoSeek(_global.videoHandle, frame); } - if (_videoHandle >= 0) videoPlay(_videoHandle); - _discStopped = false; + if (_global.videoHandle >= 0) videoPlay(_global.videoHandle); + _global.discStopped = false; result = true; } } @@ -731,15 +698,15 @@ int32_t apiDiscStepBackward(lua_State *L) { // No matter disc state, go back a frame. If playing, pause. - if (_videoHandle >= 0) { - if (_confIsFrameFile) { - frame = frameFileGetFrame(_frameFileHandle, _videoHandle) - 1; - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + if (_global.videoHandle >= 0) { + if (_conf.isFrameFile) { + frame = frameFileGetFrame(_global.frameFileHandle, _global.videoHandle) - 1; + frameFileSeek(_global.frameFileHandle, frame, &_global.videoHandle, &aFrame); } else { - frame = videoGetFrame(_videoHandle) - 1; - videoSeek(_videoHandle, frame); + frame = videoGetFrame(_global.videoHandle) - 1; + videoSeek(_global.videoHandle, frame); } - videoPause(_videoHandle); + videoPause(_global.videoHandle); } luaTrace(L, "discStepBackward", "%ld", frame); @@ -755,15 +722,15 @@ int32_t apiDiscStepForward(lua_State *L) { // No matter disc state, go forward a frame. If playing, pause. - if (_videoHandle >= 0) { - if (_confIsFrameFile) { - frame = frameFileGetFrame(_frameFileHandle, _videoHandle) + 1; - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + if (_global.videoHandle >= 0) { + if (_conf.isFrameFile) { + frame = frameFileGetFrame(_global.frameFileHandle, _global.videoHandle) + 1; + frameFileSeek(_global.frameFileHandle, frame, &_global.videoHandle, &aFrame); } else { - frame = videoGetFrame(_videoHandle) + 1; - videoSeek(_videoHandle, frame); + frame = videoGetFrame(_global.videoHandle) + 1; + videoSeek(_global.videoHandle, frame); } - videoPause(_videoHandle); + videoPause(_global.videoHandle); } luaTrace(L, "discStepForward", "%ld", frame); @@ -773,10 +740,10 @@ int32_t apiDiscStepForward(lua_State *L) { int32_t apiDiscStop(lua_State *L) { (void)L; - if (!_discStopped) { - if (_videoHandle >= 0) videoPause(_videoHandle); - _discStopped = true; - _refreshDisplay = true; + if (!_global.discStopped) { + if (_global.videoHandle >= 0) videoPause(_global.videoHandle); + _global.discStopped = true; + _global.refreshDisplay = true; luaTrace(L, "discStop", ""); } else { luaTrace(L, "discStop", "Failed! Disc is stopped."); @@ -804,10 +771,10 @@ int32_t apiFontLoad(lua_State *L) { font->font = TTF_OpenFont(name, points); if (!font->font) luaDie(L, "fontLoad", "%s", TTF_GetError()); // Make it the current font and mark it as loaded. - font->id = _nextFontId; - result = _nextFontId++; - _fontCurrent = font; - HASH_ADD_INT(_fontList, id, font); + font->id = _global.nextFontId; + result = _global.nextFontId++; + _global.fontCurrent = font; + HASH_ADD_INT(_global.fontList, id, font); } } } @@ -834,22 +801,22 @@ int32_t apiFontPrint(lua_State *L) { if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 2)) { if (lua_isstring(L, 3)) { - if (_fontCurrent) { + if (_global.fontCurrent) { d = lua_tonumber(L, 1); dest.x = (int32_t)d; d = lua_tonumber(L, 2); dest.y = (int32_t)d; textSurface = NULL; message = lua_tostring(L, 3); - switch (_fontQuality) { - case 1: - textSurface = TTF_RenderText_Solid(_fontCurrent->font, message, _colorForeground); + switch (_global.fontQuality) { + case FONT_QUALITY_SOLID: + textSurface = TTF_RenderText_Solid(_global.fontCurrent->font, message, _global.colorForeground); break; - case 2: - textSurface = TTF_RenderText_Shaded(_fontCurrent->font, message, _colorForeground, _colorBackground); + case FONT_QUALITY_SHADED: + textSurface = TTF_RenderText_Shaded(_global.fontCurrent->font, message, _global.colorForeground, _global.colorBackground); break; - case 3: - textSurface = TTF_RenderText_Blended(_fontCurrent->font, message, _colorForeground); + case FONT_QUALITY_BLENDED: + textSurface = TTF_RenderText_Blended(_global.fontCurrent->font, message, _global.colorForeground); break; } if (!textSurface) { @@ -858,7 +825,7 @@ int32_t apiFontPrint(lua_State *L) { SDL_SetColorKey(textSurface, true, 0); dest.w = textSurface->w; dest.h = textSurface->h; - SDL_BlitSurface(textSurface, NULL, _overlay, &dest); + SDL_BlitSurface(textSurface, NULL, _global.overlay, &dest); SDL_FreeSurface(textSurface); } } @@ -884,13 +851,13 @@ int32_t apiFontQuality(lua_State *L) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); _fontQuality = (int32_t)d; + d = lua_tonumber(L, 1); _global.fontQuality = (int32_t)d; result = true; } } if (result) { - luaTrace(L, "fontQuality", "%d", _fontQuality); + luaTrace(L, "fontQuality", "%d", _global.fontQuality); } else { luaTrace(L, "fontQuality", "Failed!"); } @@ -910,15 +877,15 @@ int32_t apiFontSelect(lua_State *L) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); id = (int32_t)d; - HASH_FIND_INT(_fontList, &id, font); + HASH_FIND_INT(_global.fontList, &id, font); if (!font) luaDie(L, "fontSelect", "No font at index %d in apiSpriteGetWidth.", id); - _fontCurrent = font; + _global.fontCurrent = font; result = true; } } if (result) { - luaTrace(L, "fontSelect", "%d", _fontCurrent->id); + luaTrace(L, "fontSelect", "%d", _global.fontCurrent->id); } else { luaTrace(L, "fontSelect", "Failed!"); } @@ -935,22 +902,22 @@ int32_t apiFontToSprite(lua_State *L) { if (n == 1) { if (lua_isstring(L, 1)) { - if (_fontCurrent) { + if (_global.fontCurrent) { // Create spirte sprite = (SpriteT *)calloc(1, sizeof(SpriteT)); if (!sprite) luaDie(L, "fontToSprite", "Unable to allocate new text sprite."); message = lua_tostring(L, 1); - switch (_fontQuality) { + switch (_global.fontQuality) { case 1: - sprite->surface = TTF_RenderText_Solid(_fontCurrent->font, message, _colorForeground); + sprite->surface = TTF_RenderText_Solid(_global.fontCurrent->font, message, _global.colorForeground); break; case 2: - sprite->surface = TTF_RenderText_Shaded(_fontCurrent->font, message, _colorForeground, _colorBackground); + sprite->surface = TTF_RenderText_Shaded(_global.fontCurrent->font, message, _global.colorForeground, _global.colorBackground); break; case 3: - sprite->surface = TTF_RenderText_Blended(_fontCurrent->font, message, _colorForeground); + sprite->surface = TTF_RenderText_Blended(_global.fontCurrent->font, message, _global.colorForeground); break; } @@ -958,9 +925,9 @@ int32_t apiFontToSprite(lua_State *L) { luaDie(L, "fontToSprite", "Font surface is null!"); } else { SDL_SetColorKey(sprite->surface, true, 0); - sprite->id = _nextSpriteId; - result = _nextSpriteId++; - HASH_ADD_INT(_spriteList, id, sprite); + sprite->id = _global.nextSpriteId; + result = _global.nextSpriteId++; + HASH_ADD_INT(_global.spriteList, id, sprite); } } } @@ -979,22 +946,22 @@ int32_t apiFontToSprite(lua_State *L) { int32_t apiOverlayClear(lua_State *L) { (void)L; - SDL_FillRect(_overlay, NULL, SDL_MapRGBA(_overlay->format, _colorBackground.r, _colorBackground.g, _colorBackground.b, _colorBackground.a)); + SDL_FillRect(_global.overlay, NULL, SDL_MapRGBA(_global.overlay->format, _global.colorBackground.r, _global.colorBackground.g, _global.colorBackground.b, _global.colorBackground.a)); luaTrace(L, "overlayClear", ""); return 0; } int32_t apiOverlayGetHeight(lua_State *L) { - luaTrace(L, "overlayGetHeight", "%d", _overlay->h); - lua_pushinteger(L, _overlay->h); + luaTrace(L, "overlayGetHeight", "%d", _global.overlay->h); + lua_pushinteger(L, _global.overlay->h); return 1; } int32_t apiOverlayGetWidth(lua_State *L) { - luaTrace(L, "overlayGetWidth", "%d", _overlay->w); - lua_pushinteger(L, _overlay->w); + luaTrace(L, "overlayGetWidth", "%d", _global.overlay->w); + lua_pushinteger(L, _global.overlay->w); return 1; } @@ -1012,22 +979,22 @@ int32_t apiOverlayPrint(lua_State *L) { if (lua_isnumber(L, 2)) { if (lua_isstring(L, 3)) { src.y = 0; - src.w = _consoleFontWidth; - src.h = _consoleFontHeight; - dst.x = lua_tonumber(L, 1) * _consoleFontWidth; - dst.y = lua_tonumber(L, 2) * _consoleFontHeight; - dst.w = _consoleFontWidth; - dst.h = _consoleFontHeight; + src.w = _global.consoleFontWidth; + src.h = _global.consoleFontHeight; + dst.x = lua_tonumber(L, 1) * _global.consoleFontWidth; + dst.y = lua_tonumber(L, 2) * _global.consoleFontHeight; + dst.w = _global.consoleFontWidth; + dst.h = _global.consoleFontHeight; s = (char *)lua_tostring(L, 3); - if (strlen(s) < (uint32_t)((_overlay->w - dst.x) / _consoleFontWidth)) { + if (strlen(s) < (uint32_t)((_global.overlay->w - dst.x) / _global.consoleFontWidth)) { length = strlen(s); } else { - length = (_overlay->w - dst.x) / _consoleFontWidth; + length = (_global.overlay->w - dst.x) / _global.consoleFontWidth; } for (i=0; ichunk = Mix_LoadWAV(name); if (!sound->chunk) luaDie(L, "soundLoad", "%s", Mix_GetError()); - sound->id = _nextSoundId; - result = _nextSoundId++; - HASH_ADD_INT(_soundList, id, sound); + sound->id = _global.nextSoundId; + result = _global.nextSoundId++; + HASH_ADD_INT(_global.soundList, id, sound); } } @@ -1079,12 +1046,12 @@ int32_t apiSoundPlay(lua_State *L) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); id = (int32_t)d; // Get our sound structure - HASH_FIND_INT(_soundList, &id, sound); + HASH_FIND_INT(_global.soundList, &id, sound); if (!sound) luaDie(L, "soundPlay", "No sound at index %d in apiSoundPlay.", id); // Play it (can gracefully fail if we run out of channels) result = Mix_PlayChannel(-1, sound->chunk, 0); if (result >= 0) { - Mix_Volume(result, _effectsVolume * 2); + Mix_Volume(result, _global.effectsVolume * 2); } } } @@ -1267,8 +1234,8 @@ int32_t apiSoundSetVolume(lua_State *L) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); thisValue = (int32_t)d; if (thisValue >= 0 && thisValue <= AUDIO_MAX_VOLUME) { - _effectsVolume = thisValue; - Mix_Volume(-1, _effectsVolume * 2); + _global.effectsVolume = thisValue; + Mix_Volume(-1, _global.effectsVolume * 2); } else { luaDie(L, "soundSetVolume", "Invalid sound volume value."); } @@ -1276,7 +1243,7 @@ int32_t apiSoundSetVolume(lua_State *L) { } if (result) { - luaTrace(L, "soundSetVolume", "%d", _effectsVolume); + luaTrace(L, "soundSetVolume", "%d", _global.effectsVolume); } else { luaTrace(L, "soundSetVolume", "Failed!"); } @@ -1296,9 +1263,9 @@ int32_t apiSoundGetVolume(lua_State *L) { // // --rdg - luaTrace(L, "soundGetVolume", "%d", _effectsVolume); + luaTrace(L, "soundGetVolume", "%d", _global.effectsVolume); - lua_pushinteger(L, _effectsVolume); + lua_pushinteger(L, _global.effectsVolume); return 1; } @@ -1333,11 +1300,11 @@ int32_t apiSpriteDraw(lua_State *L) { d = lua_tonumber(L, 1); dest.x = (int32_t)d; d = lua_tonumber(L, 2); dest.y = (int32_t)d; d = lua_tonumber(L, 3); id = (int32_t)d; - HASH_FIND_INT(_spriteList, &id, sprite); + HASH_FIND_INT(_global.spriteList, &id, sprite); if (!sprite) luaDie(L, "spriteDraw", "No sprite at index %d in apiSpriteGetWidth.", id); dest.w = sprite->surface->w; dest.h = sprite->surface->h; - SDL_BlitSurface(sprite->surface, NULL, _overlay, &dest); + SDL_BlitSurface(sprite->surface, NULL, _global.overlay, &dest); } } } @@ -1364,7 +1331,7 @@ int32_t apiSpriteGetHeight(lua_State *L) { if (lua_isstring(L, 1)) { d = lua_tonumber(L, 1); id = (int32_t)d; // Get our sprite structure - HASH_FIND_INT(_spriteList, &id, sprite); + HASH_FIND_INT(_global.spriteList, &id, sprite); if (!sprite) luaDie(L, "spriteGetHeight", "No sprite at index %d in apiSpriteGetWidth.", id); result = sprite->surface->h; } @@ -1396,7 +1363,7 @@ int32_t apiSpriteGetWidth(lua_State *L) { if (lua_isstring(L, 1)) { d = lua_tonumber(L, 1); id = (int32_t)d; // Get our sprite structure - HASH_FIND_INT(_spriteList, &id, sprite); + HASH_FIND_INT(_global.spriteList, &id, sprite); if (!sprite) luaDie(L, "spriteGetWidth", "No sprite at index %d in apiSpriteGetWidth.", id); result = sprite->surface->w; } @@ -1427,9 +1394,9 @@ int32_t apiSpriteLoad(lua_State *L) { sprite->surface = IMG_Load(name); if (!sprite->surface) luaDie(L, "spriteLoad", "%s", IMG_GetError()); SDL_SetColorKey(sprite->surface, true, 0); - sprite->id = _nextSpriteId; - result = _nextSpriteId++; - HASH_ADD_INT(_spriteList, id, sprite); + sprite->id = _global.nextSpriteId; + result = _global.nextSpriteId++; + HASH_ADD_INT(_global.spriteList, id, sprite); } } @@ -1446,7 +1413,7 @@ int32_t apiSpriteLoad(lua_State *L) { int32_t apiVldpGetHeight(lua_State *L) { int32_t height = 0; - if (_videoHandle >= 0) height = videoGetHeight(_videoHandle); + if (_global.videoHandle >= 0) height = videoGetHeight(_global.videoHandle); luaTrace(L, "vldpGetHeight", "%d", height); lua_pushinteger(L, height); return 1; @@ -1465,11 +1432,11 @@ int32_t apiVldpGetPixel(lua_State *L) { if (lua_isnumber(L, 2)) { rect.h = 1; rect.w = 1; - d = lua_tonumber(L, 1); rect.x = (int32_t)(d / _overlayScaleX); - d = lua_tonumber(L, 2); rect.y = (int32_t)(d / _overlayScaleY); - if (SDL_SetRenderTarget(_renderer, _videoTexture) < 0) luaDie(L, "vldpGetPixel", "%s", SDL_GetError()); - if (SDL_RenderReadPixels(_renderer, &rect, SDL_PIXELFORMAT_BGRA32, pixel, SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_BGRA32) * videoGetWidth(_videoHandle)) < 0) luaDie(L, "vldpGetPixel", "%s", SDL_GetError()); - if (SDL_SetRenderTarget(_renderer, NULL) < 0) luaDie(L, "vldpGetPixel", "%s", SDL_GetError()); + d = lua_tonumber(L, 1); rect.x = (int32_t)(d / _global.overlayScaleX); + d = lua_tonumber(L, 2); rect.y = (int32_t)(d / _global.overlayScaleY); + if (SDL_SetRenderTarget(_global.renderer, _global.videoTexture) < 0) luaDie(L, "vldpGetPixel", "%s", SDL_GetError()); + if (SDL_RenderReadPixels(_global.renderer, &rect, SDL_PIXELFORMAT_BGRA32, pixel, SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_BGRA32) * videoGetWidth(_global.videoHandle)) < 0) luaDie(L, "vldpGetPixel", "%s", SDL_GetError()); + if (SDL_SetRenderTarget(_global.renderer, NULL) < 0) luaDie(L, "vldpGetPixel", "%s", SDL_GetError()); result = true; } } @@ -1493,7 +1460,7 @@ int32_t apiVldpGetPixel(lua_State *L) { int32_t apiVldpGetWidth(lua_State *L) { int32_t width = 0; - if (_videoHandle >= 0) width = videoGetWidth(_videoHandle); + if (_global.videoHandle >= 0) width = videoGetWidth(_global.videoHandle); luaTrace(L, "vldpGetHeight", "%d", width); lua_pushinteger(L, width); return 1; @@ -1515,8 +1482,8 @@ int32_t apiVldpVerbose(lua_State *L) { int32_t apiKeyboardGetMode(lua_State *L) { - luaTrace(L, "keyboardGetMode", "%d", _keyboardMode); - lua_pushinteger(L, _keyboardMode); + luaTrace(L, "keyboardGetMode", "%d", _global.keyboardMode); + lua_pushinteger(L, _global.keyboardMode); return 1; } @@ -1539,13 +1506,13 @@ int32_t apiKeyboardSetMode(lua_State *L) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); _keyboardMode = (int32_t)d; + d = lua_tonumber(L, 1); _global.keyboardMode = (int32_t)d; result = true; } } if (result) { - luaTrace(L, "keyboardSetMode", "%d", _keyboardMode); + luaTrace(L, "keyboardSetMode", "%d", _global.keyboardMode); } else { luaTrace(L, "keyboardSetMode", "Failed!"); } @@ -1557,8 +1524,8 @@ int32_t apiKeyboardSetMode(lua_State *L) { int32_t apiMouseEnable(lua_State *L) { // Enables mouse monitoring (void)L; - luaTrace(L, "mouseEnable", "%d", _confNoMouse); - _mouseEnabled = (bool)!_confNoMouse; + luaTrace(L, "mouseEnable", "%d", _conf.noMouse); + _global.mouseEnabled = (bool)!_conf.noMouse; return 0; } @@ -1567,7 +1534,7 @@ int32_t apiMouseDisable(lua_State *L) { // Disables mouse monitoring (void)L; luaTrace(L, "mouseDisable", ""); - _mouseEnabled = false; + _global.mouseEnabled = false; return 0; } @@ -1596,15 +1563,15 @@ int32_t apiMouseSetMode(lua_State *L) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); _mouseMode = (int32_t)d; + d = lua_tonumber(L, 1); _global.mouseMode = (int32_t)d; result = true; } } - //utilSay("MouseMode now %d", _mouseMode); + //utilSay("MouseMode now %d", _global.mouseMode); if (result) { - luaTrace(L, "mouseSetMode", "%d", _mouseMode); + luaTrace(L, "mouseSetMode", "%d", _global.mouseMode); } else { luaTrace(L, "mouseSetMode", "Failed!"); } @@ -1626,8 +1593,8 @@ int32_t apiMouseGetPosition(lua_State *L) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); m = (int32_t)d; if ((m < 0) || (m >= MAX_MICE)) luaDie(L, "apiMouseGetPosition", "Invalid mouse index: %d", m); - x = _axisCache[MAX_CONTROLLERS * CONTROLLER_AXIS_COUNT + m * MOUSE_AXIS_COUNT]; - y = _axisCache[MAX_CONTROLLERS * CONTROLLER_AXIS_COUNT + m * MOUSE_AXIS_COUNT + 1]; + x = _global.axisCache[MAX_CONTROLLERS * CONTROLLER_AXIS_COUNT + m * MOUSE_AXIS_COUNT]; + y = _global.axisCache[MAX_CONTROLLERS * CONTROLLER_AXIS_COUNT + m * MOUSE_AXIS_COUNT + 1]; result = true; } } @@ -1647,8 +1614,8 @@ int32_t apiMouseGetPosition(lua_State *L) { int32_t apiMouseHowMany(lua_State *L) { - luaTrace(L, "mouseHowMany", "%d", _mouseCount); - lua_pushinteger(L, _mouseCount); + luaTrace(L, "mouseHowMany", "%d", _global.mouseCount); + lua_pushinteger(L, _global.mouseCount); return 1; } @@ -1665,33 +1632,33 @@ int32_t apiDiscGetState(lua_State *L) { * LDP_SEARCHING = 1 * LDP_STOPPED = 2 * LDP_PLAYING = 3 - * LDP_PAUSE = 4 + * LDP_PAUSED = 4 * */ // Our player isn't as sophisticated as the one in Daphne - if (_videoHandle >= 0) isPlaying = videoIsPlaying(_videoHandle); - luaTrace(L, "discGetState", "%s", _discStopped ? "Stopped" : (isPlaying ? "Playing" : "Paused")); - lua_pushinteger(L, _discStopped ? LDP_STOPPED : (isPlaying ? LDP_PLAYING : LDP_PAUSE)); + if (_global.videoHandle >= 0) isPlaying = videoIsPlaying(_global.videoHandle); + luaTrace(L, "discGetState", "%s", _global.discStopped ? "Stopped" : (isPlaying ? "Playing" : "Paused")); + lua_pushinteger(L, _global.discStopped ? LDP_STOPPED : (isPlaying ? LDP_PLAYING : LDP_PAUSED)); return 1; } int32_t apiSingeGetPauseFlag(lua_State *L) { /* - * This function returns g_pause_state's value to the lua script. + * This function returns _global.pauseState's value to the lua script. * * Sometimes game logic pauses the game (which implies pausing video playback). * When implementing a pause state it is possible for the player * to resume playblack at moments where the game is not intended to. - * Boolean g_pause state is an internal variable that keeps track - * of this. It's set to true whenever sep_pre_pause is called. + * Boolean g_global.pause state is an internal variable that keeps track + * of this. It's set to true whenever sep_pre_global.pause is called. * It's set to false whenever sep_pre_play or sep_skip_to_frame is called. * * A lua programmer can use this to prevent resuming playback accidentally. */ - luaTrace(L, "singeGetPauseFlag", "%d", _pauseState); - lua_pushboolean(L, _pauseState); + luaTrace(L, "singeGetPauseFlag", "%d", _global.pauseState); + lua_pushboolean(L, _global.pauseState); return 1; } @@ -1702,13 +1669,13 @@ int32_t apiSingeSetPauseFlag(lua_State *L) { if (n == 1) { if (lua_isboolean(L, 1)) { - _pauseState = (bool)lua_toboolean(L, 1); + _global.pauseState = (bool)lua_toboolean(L, 1); result = true; } } if (result) { - luaTrace(L, "singeSetPauseFlag", "%d", _pauseState); + luaTrace(L, "singeSetPauseFlag", "%d", _global.pauseState); } else { luaTrace(L, "singeSetPauseFlag", "Failed!"); } @@ -1720,7 +1687,7 @@ int32_t apiSingeSetPauseFlag(lua_State *L) { int32_t apiSingeEnablePauseKey(lua_State *L) { (void)L; luaTrace(L, "singeEnablePauseKey", ""); - _pauseEnabled = true; + _global.pauseEnabled = true; return 0; } @@ -1728,7 +1695,7 @@ int32_t apiSingeEnablePauseKey(lua_State *L) { int32_t apiSingeDisablePauseKey(lua_State *L) { (void)L; luaTrace(L, "singeDisablePauseKey", ""); - _pauseEnabled = false; + _global.pauseEnabled = false; return 0; } @@ -1736,7 +1703,7 @@ int32_t apiSingeDisablePauseKey(lua_State *L) { int32_t apiSingeQuit(lua_State *L) { (void)L; luaTrace(L, "singeQuit", ""); - _running = false; + _global.running = false; return 0; } @@ -1766,7 +1733,7 @@ int32_t apiSingeSetGameName(lua_State *L) { if (n == 1) { if (lua_isstring(L, 1)) { sprintf(thisName,"%.40s", lua_tostring(L, 1)); // Need a better way to do this...? - SDL_SetWindowTitle(_window, thisName); + SDL_SetWindowTitle(_global.window, thisName); result = true; } } @@ -1789,8 +1756,8 @@ int32_t apiSingeGetScriptPath(lua_State *L) { // sGameDirectory = singeGetScriptPath() // - luaTrace(L, "singeSetScriptPath", "%s", _confScriptFile); - lua_pushstring(L, _confScriptFile); + luaTrace(L, "singeSetScriptPath", "%s", _conf.scriptFile); + lua_pushstring(L, _conf.scriptFile); return 1; } @@ -1802,15 +1769,15 @@ void callLua(const char *func, const char *sig, ...) { int32_t nres; int32_t popCount; double d; - const int32_t top = lua_gettop(_luaContext); + const int32_t top = lua_gettop(_global.luaContext); va_start(vl, sig); // Get Function - lua_getglobal(_luaContext, func); - if (!lua_isfunction(_luaContext, -1)) { + lua_getglobal(_global.luaContext, func); + if (!lua_isfunction(_global.luaContext, -1)) { // Function does not exist. Bail. - lua_settop(_luaContext, top); + lua_settop(_global.luaContext, top); return; } @@ -1822,15 +1789,15 @@ void callLua(const char *func, const char *sig, ...) { switch (*sig++) { case 'd': // Double - lua_pushnumber(_luaContext, va_arg(vl, double)); + lua_pushnumber(_global.luaContext, va_arg(vl, double)); break; case 'i': // Int - lua_pushinteger(_luaContext, va_arg(vl, int)); // Not sure I want to change this to int32_t + lua_pushinteger(_global.luaContext, va_arg(vl, int)); // Not sure I want to change this to int32_t break; case 's': // String - lua_pushstring(_luaContext, va_arg(vl, char *)); + lua_pushstring(_global.luaContext, va_arg(vl, char *)); break; case '>': @@ -1842,14 +1809,14 @@ void callLua(const char *func, const char *sig, ...) { } if (!done) { narg++; - luaL_checkstack(_luaContext, 1, "Too many arguments"); + luaL_checkstack(_global.luaContext, 1, "Too many arguments"); } } // Do the call popCount = nres = (int32_t)strlen(sig); // Number of expected results - if (lua_pcall(_luaContext, narg, nres, 0) != 0) { - utilDie("Error executing function '%s': %s", func, lua_tostring(_luaContext, -1)); + if (lua_pcall(_global.luaContext, narg, nres, 0) != 0) { + utilDie("Error executing function '%s': %s", func, lua_tostring(_global.luaContext, -1)); } // Retrieve results @@ -1858,24 +1825,24 @@ void callLua(const char *func, const char *sig, ...) { switch (*sig++) { case 'd': // Double - if (!lua_isnumber(_luaContext, nres)) { + if (!lua_isnumber(_global.luaContext, nres)) { utilDie("Wrong result type"); } - *va_arg(vl, double *) = lua_tonumber(_luaContext, nres); + *va_arg(vl, double *) = lua_tonumber(_global.luaContext, nres); break; case 'i': // Int - if (!lua_isnumber(_luaContext, nres)) { + if (!lua_isnumber(_global.luaContext, nres)) { utilDie("Wrong result type"); } - d = lua_tonumber(_luaContext, nres); *va_arg(vl, int *) = (int32_t)d; // Not sure I want to change this to int32_t + d = lua_tonumber(_global.luaContext, nres); *va_arg(vl, int *) = (int32_t)d; // Not sure I want to change this to int32_t break; case 's': // String - if (!lua_isstring(_luaContext, nres)) { + if (!lua_isstring(_global.luaContext, nres)) { utilDie("Wrong result type"); } - *va_arg(vl, const char **) = lua_tostring(_luaContext, nres); + *va_arg(vl, const char **) = lua_tostring(_global.luaContext, nres); break; default: @@ -1886,7 +1853,7 @@ void callLua(const char *func, const char *sig, ...) { va_end(vl); if (popCount > 0) { - lua_pop(_luaContext, popCount); + lua_pop(_global.luaContext, popCount); } } @@ -1922,8 +1889,8 @@ void doIndexDisplay(int32_t percent) { if (percent == -1) { // Setup - SDL_RenderGetLogicalSize(_renderer, &oldW, &oldH); - SDL_RenderSetLogicalSize(_renderer, screenW, screenH); + SDL_RenderGetLogicalSize(_global.renderer, &oldW, &oldH); + SDL_RenderSetLogicalSize(_global.renderer, screenW, screenH); surfGlass = IMG_LoadPNG_RW(SDL_RWFromMem(magnifyingGlass_png, magnifyingGlass_png_len)); if (!surfGlass) utilDie("%s", IMG_GetError()); @@ -1932,11 +1899,11 @@ void doIndexDisplay(int32_t percent) { surfIndex = IMG_LoadPNG_RW(SDL_RWFromMem(indexing_png, indexing_png_len)); if (!surfIndex) utilDie("%s", IMG_GetError()); - texDisc = SDL_CreateTextureFromSurface(_renderer, surfDisc); + texDisc = SDL_CreateTextureFromSurface(_global.renderer, surfDisc); if (!texDisc) utilDie("%s", SDL_GetError()); - texGlass = SDL_CreateTextureFromSurface(_renderer, surfGlass); + texGlass = SDL_CreateTextureFromSurface(_global.renderer, surfGlass); if (!texGlass) utilDie("%s", SDL_GetError()); - texIndex = SDL_CreateTextureFromSurface(_renderer, surfIndex); + texIndex = SDL_CreateTextureFromSurface(_global.renderer, surfIndex); if (!texIndex) utilDie("%s", SDL_GetError()); radius = surfDisc->w * 0.3; @@ -1961,18 +1928,18 @@ void doIndexDisplay(int32_t percent) { surfGlass = NULL; surfIndex = NULL; - SDL_RenderSetLogicalSize(_renderer, oldW, oldH); + SDL_RenderSetLogicalSize(_global.renderer, oldW, oldH); - SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 255); - SDL_RenderClear(_renderer); - SDL_RenderPresent(_renderer); + SDL_SetRenderDrawColor(_global.renderer, 0, 0, 0, 255); + SDL_RenderClear(_global.renderer); + SDL_RenderPresent(_global.renderer); return; } // Display animation - SDL_RenderSetLogicalSize(_renderer, screenW, screenH); - SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 255); - SDL_RenderClear(_renderer); + SDL_RenderSetLogicalSize(_global.renderer, screenW, screenH); + SDL_SetRenderDrawColor(_global.renderer, 0, 0, 0, 255); + SDL_RenderClear(_global.renderer); // Draw "Indexing" text vShift = surfIndex->h - 5; @@ -1980,21 +1947,21 @@ void doIndexDisplay(int32_t percent) { target.y = screenH - vShift; target.w = surfIndex->w; target.h = surfIndex->h; - SDL_RenderCopy(_renderer, texIndex, NULL, &target); + SDL_RenderCopy(_global.renderer, texIndex, NULL, &target); // Draw laserdisc target.x = (screenW * 0.5) - (surfDisc->w * 0.5); target.y = (screenH * 0.5) - (surfDisc->h * 0.5) - vShift; target.w = surfDisc->w; target.h = surfDisc->h; - SDL_RenderCopy(_renderer, texDisc, NULL, &target); + SDL_RenderCopy(_global.renderer, texDisc, NULL, &target); // Draw magnifying glass target.x = (surfDisc->w * 0.15) + (screenW * 0.5) - (surfGlass->w * 0.5) + cos(angle * M_PI / 180) * radius; target.y = (surfDisc->h * 0.1) + (screenH * 0.5) - vShift - (surfGlass->h * 0.5) + sin(angle * M_PI / 180) * radius; target.w = surfGlass->w; target.h = surfGlass->h; - SDL_RenderCopy(_renderer, texGlass, NULL, &target); + SDL_RenderCopy(_global.renderer, texGlass, NULL, &target); // Update animation if (SDL_GetTicks() > nextUpdate) { @@ -2004,7 +1971,7 @@ void doIndexDisplay(int32_t percent) { nextUpdate = SDL_GetTicks() + updateTicks; } - SDL_RenderPresent(_renderer); + SDL_RenderPresent(_global.renderer); } @@ -2017,26 +1984,26 @@ void doLogos(void) { SDL_Texture *texKangaroo = NULL; SDL_Texture *texSinge = NULL; - SDL_RenderGetLogicalSize(_renderer, &w, &h); + SDL_RenderGetLogicalSize(_global.renderer, &w, &h); surfKangaroo = IMG_LoadPNG_RW(SDL_RWFromMem(kangarooPunchLogo_png, kangarooPunchLogo_png_len)); if (!surfKangaroo) utilDie("%s", IMG_GetError()); surfSinge = IMG_LoadPNG_RW(SDL_RWFromMem(singeLogo_png, singeLogo_png_len)); if (!surfSinge) utilDie("%s", IMG_GetError()); - texKangaroo = SDL_CreateTextureFromSurface(_renderer, surfKangaroo); + texKangaroo = SDL_CreateTextureFromSurface(_global.renderer, surfKangaroo); if (!texKangaroo) utilDie("%s", SDL_GetError()); - texSinge = SDL_CreateTextureFromSurface(_renderer, surfSinge); + texSinge = SDL_CreateTextureFromSurface(_global.renderer, surfSinge); if (!texSinge) utilDie("%s", SDL_GetError()); // Fade in to white with Kangaroo logo - SDL_RenderSetLogicalSize(_renderer, surfKangaroo->w, surfKangaroo->h); + SDL_RenderSetLogicalSize(_global.renderer, surfKangaroo->w, surfKangaroo->h); for (i=0; i<256; i++) { - SDL_SetRenderDrawColor(_renderer, i, i, i, 255); - SDL_RenderClear(_renderer); + SDL_SetRenderDrawColor(_global.renderer, i, i, i, 255); + SDL_RenderClear(_global.renderer); SDL_SetTextureAlphaMod(texKangaroo, i); - SDL_RenderCopy(_renderer, texKangaroo, NULL, NULL); - SDL_RenderPresent(_renderer); + SDL_RenderCopy(_global.renderer, texKangaroo, NULL, NULL); + SDL_RenderPresent(_global.renderer); SDL_Delay(3); } @@ -2044,25 +2011,25 @@ void doLogos(void) { // Cross fade to Singe logo for (i=0; i<256; i++) { - SDL_RenderClear(_renderer); + SDL_RenderClear(_global.renderer); SDL_SetTextureAlphaMod(texKangaroo, 255 - i); - SDL_RenderCopy(_renderer, texKangaroo, NULL, NULL); + SDL_RenderCopy(_global.renderer, texKangaroo, NULL, NULL); SDL_SetTextureAlphaMod(texSinge, i); - SDL_RenderCopy(_renderer, texSinge, NULL, NULL); - SDL_RenderPresent(_renderer); + SDL_RenderCopy(_global.renderer, texSinge, NULL, NULL); + SDL_RenderPresent(_global.renderer); SDL_Delay(3); } SDL_Delay(750); // Fade to black - SDL_RenderSetLogicalSize(_renderer, surfSinge->w, surfSinge->h); + SDL_RenderSetLogicalSize(_global.renderer, surfSinge->w, surfSinge->h); for (i=255; i>=0; i--) { - SDL_SetRenderDrawColor(_renderer, i, i, i, 255); - SDL_RenderClear(_renderer); + SDL_SetRenderDrawColor(_global.renderer, i, i, i, 255); + SDL_RenderClear(_global.renderer); SDL_SetTextureAlphaMod(texSinge, i); - SDL_RenderCopy(_renderer, texSinge, NULL, NULL); - SDL_RenderPresent(_renderer); + SDL_RenderCopy(_global.renderer, texSinge, NULL, NULL); + SDL_RenderPresent(_global.renderer); SDL_Delay(3); } @@ -2072,7 +2039,7 @@ void doLogos(void) { SDL_FreeSurface(surfSinge); SDL_FreeSurface(surfKangaroo); - SDL_RenderSetLogicalSize(_renderer, w, h); + SDL_RenderSetLogicalSize(_global.renderer, w, h); } @@ -2156,7 +2123,7 @@ void luaTrace(lua_State *L, char *method, char *fmt, ...) { char *string1 = NULL; char *string2 = NULL; - if (utilTraceFile) { + if (utilTraceGetFile()) { lua_getstack(L, 1, &ar); lua_getinfo(L, "nSl", &ar); string1 = utilCreateString("%d:%s: ", ar.currentline, method); @@ -2179,36 +2146,36 @@ void processKey(bool down, int32_t keysym, int32_t scancode) { //utilSay("U:%d SY:%d SC:%d", down, keysym, scancode); - if (_keyboardMode == KEYBD_NORMAL) { + if (_global.keyboardMode == KEYBD_NORMAL) { // Mappable keys for (move=0; move 0) { - for (index=0; index<_controlMappings[move].inputCount; index++) { - //utilSay("Checking %s %d = %d", _controlMappings[move].name, _controlMappings[move].input[index], scancode); - if (_controlMappings[move].input[index] == scancode) { - //utilSay("Sending move %d - %s %d - %s", move, _controlMappings[move].name, _controlMappings[move].input[index], down ? "down" : "up"); + if (_global.controlMappings[move].inputCount > 0) { + for (index=0; index<_global.controlMappings[move].inputCount; index++) { + //utilSay("Checking %s %d = %d", _global.controlMappings[move].name, _global.controlMappings[move].input[index], scancode); + if (_global.controlMappings[move].input[index] == 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) && (_pauseEnabled)) { + if ((move == INPUT_PAUSE) && (_global.pauseEnabled)) { //***TODO*** g_game->toggle_game_pause(); } if (move == INPUT_GRAB) { - if (_mouseGrabbed) { + if (_global.mouseGrabbed) { // Ungrab mouse - _mouseGrabbed = false; - SDL_SetWindowGrab(_window, SDL_FALSE); + _global.mouseGrabbed = false; + SDL_SetWindowGrab(_global.window, SDL_FALSE); SDL_ShowCursor(SDL_ENABLE); } else { // Grab mouse - _mouseGrabbed = true; - SDL_SetWindowGrab(_window, SDL_TRUE); + _global.mouseGrabbed = true; + SDL_SetWindowGrab(_global.window, SDL_TRUE); SDL_ShowCursor(SDL_DISABLE); } } if (move == INPUT_QUIT) { - _running = false; + _global.running = false; } if (move == INPUT_SCREENSHOT) { - _requestScreenShot = true; + _global.requestScreenShot = true; } } callLua(down ? "onInputPressed" : "onInputReleased", "i", move); @@ -2251,185 +2218,232 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { ManyMouseEvent mouseEvent; MouseT *mouse = NULL; + // Set up globals + memset(&_global, 0, sizeof(GlobalT)); + _global.colorForeground.r = 255; + _global.colorForeground.g = 255; + _global.colorForeground.b = 255; + _global.colorForeground.a = 255; + _global.effectsVolume = AUDIO_MAX_VOLUME; + _global.keyboardMode = KEYBD_NORMAL; + _global.frameFileHandle = -1; + _global.videoHandle = -1; + _global.fontQuality = FONT_QUALITY_SOLID; + _global.mouseMode = MOUSE_SINGLE; + _global.overlayScaleX = 1; + _global.overlayScaleY = 1; + _global.pauseEnabled = true; + _global.running = true; + _global.discStopped = true; + _global.mouseEnabled = true; + + _global.controlMappings[INPUT_UP].name = "INPUT_UP"; + _global.controlMappings[INPUT_LEFT].name = "INPUT_LEFT"; + _global.controlMappings[INPUT_DOWN].name = "INPUT_DOWN"; + _global.controlMappings[INPUT_RIGHT].name = "INPUT_RIGHT"; + _global.controlMappings[INPUT_1P_START].name = "INPUT_1P_START"; + _global.controlMappings[INPUT_2P_START].name = "INPUT_2P_START"; + _global.controlMappings[INPUT_ACTION_1].name = "INPUT_ACTION_1"; + _global.controlMappings[INPUT_ACTION_2].name = "INPUT_ACTION_2"; + _global.controlMappings[INPUT_ACTION_3].name = "INPUT_ACTION_3"; + _global.controlMappings[INPUT_1P_COIN].name = "INPUT_1P_COIN"; + _global.controlMappings[INPUT_2P_COIN].name = "INPUT_2P_COIN"; + _global.controlMappings[INPUT_SKILL_EASY].name = "INPUT_SKILL_EASY"; + _global.controlMappings[INPUT_SKILL_MEDIUM].name = "INPUT_SKILL_MEDIUM"; + _global.controlMappings[INPUT_SKILL_HARD].name = "INPUT_SKILL_HARD"; + _global.controlMappings[INPUT_SERVICE].name = "INPUT_SERVICE"; + _global.controlMappings[INPUT_TEST_MODE].name = "INPUT_TEST_MODE"; + _global.controlMappings[INPUT_RESET_CPU].name = "INPUT_RESET_CPU"; + _global.controlMappings[INPUT_SCREENSHOT].name = "INPUT_SCREENSHOT"; + _global.controlMappings[INPUT_QUIT].name = "INPUT_QUIT"; + _global.controlMappings[INPUT_PAUSE].name = "INPUT_PAUSE"; + _global.controlMappings[INPUT_CONSOLE].name = "INPUT_CONSOLE"; + _global.controlMappings[INPUT_ACTION_4].name = "INPUT_ACTION_4"; + _global.controlMappings[INPUT_TILT].name = "INPUT_TILT"; + _global.controlMappings[INPUT_GRAB].name = "INPUT_GRAB"; + for (x=0; x 0) { - _controlMappings[x].inputCount = y; - _controlMappings[x].input = (int32_t *)malloc(sizeof(int32_t) * y); - if (!_controlMappings[x].input) utilDie("Unable to allocate memory for control mappings."); + _global.controlMappings[x].inputCount = y; + _global.controlMappings[x].input = (int32_t *)malloc(sizeof(int32_t) * y); + if (!_global.controlMappings[x].input) utilDie("Unable to allocate memory for control mappings."); } } else { - utilSay("Configuration option %s missing!", _controlMappings[x].name); + utilSay("Configuration option %s missing!", _global.controlMappings[x].name); } - lua_pop(_luaContext, 1); + lua_pop(_global.luaContext, 1); // Then load them for real. - lua_getglobal(_luaContext, _controlMappings[x].name); - if (lua_istable(_luaContext, -1)) { + lua_getglobal(_global.luaContext, _global.controlMappings[x].name); + if (lua_istable(_global.luaContext, -1)) { y = 0; - lua_pushnil(_luaContext); - while (lua_next(_luaContext, -2)) { - if (lua_istable(_luaContext, -1)) { - lua_pushnil(_luaContext); - while (lua_next(_luaContext, -2)) { - if (lua_type(_luaContext, -2) == LUA_TSTRING) { - if (utilStricmp((char *)lua_tostring(_luaContext, -2), "value") == 0) { - _controlMappings[x].input[y++] = (int32_t)lua_tonumber(_luaContext, -1); + lua_pushnil(_global.luaContext); + while (lua_next(_global.luaContext, -2)) { + if (lua_istable(_global.luaContext, -1)) { + lua_pushnil(_global.luaContext); + while (lua_next(_global.luaContext, -2)) { + if (lua_type(_global.luaContext, -2) == LUA_TSTRING) { + if (utilStricmp((char *)lua_tostring(_global.luaContext, -2), "value") == 0) { + _global.controlMappings[x].input[y++] = (int32_t)lua_tonumber(_global.luaContext, -1); } } - lua_pop(_luaContext, 1); + lua_pop(_global.luaContext, 1); } } - lua_pop(_luaContext, 1); + lua_pop(_global.luaContext, 1); } } - lua_pop(_luaContext, 1); + lua_pop(_global.luaContext, 1); } - lua_close(_luaContext); + lua_close(_global.luaContext); // Show splash screens - if (!_confNoLogos) { + if (!_conf.noLogos) { doLogos(); } // Start Lua for game - _luaContext = luaL_newstate(); - luaL_openlibs(_luaContext); - lua_atpanic(_luaContext, luaError); + _global.luaContext = luaL_newstate(); + luaL_openlibs(_global.luaContext); + lua_atpanic(_global.luaContext, luaError); // Lua API for Singe - lua_register(_luaContext, "colorBackground", apiColorBackground); - lua_register(_luaContext, "colorForeground", apiColorForeground); + lua_register(_global.luaContext, "colorBackground", apiColorBackground); + lua_register(_global.luaContext, "colorForeground", apiColorForeground); - lua_register(_luaContext, "controllerGetAxis", apiControllerGetAxis); + lua_register(_global.luaContext, "controllerGetAxis", apiControllerGetAxis); - lua_register(_luaContext, "daphneGetHeight", apiDaphneGetHeight); - lua_register(_luaContext, "daphneGetWidth", apiDaphneGetWidth); - lua_register(_luaContext, "daphneScreenshot", apiDaphneScreenshot); + lua_register(_global.luaContext, "daphneGetHeight", apiDaphneGetHeight); + lua_register(_global.luaContext, "daphneGetWidth", apiDaphneGetWidth); + lua_register(_global.luaContext, "daphneScreenshot", apiDaphneScreenshot); - lua_register(_luaContext, "debugPrint", apiDebugPrint); + lua_register(_global.luaContext, "debugPrint", apiDebugPrint); - lua_register(_luaContext, "discAudio", apiDiscAudio); - lua_register(_luaContext, "discChangeSpeed", apiDiscChangeSpeed); - lua_register(_luaContext, "discGetFrame", apiDiscGetFrame); - lua_register(_luaContext, "discGetState", apiDiscGetState); - lua_register(_luaContext, "discPause", apiDiscPause); - lua_register(_luaContext, "discPauseAtFrame", apiDiscPauseAtFrame); - lua_register(_luaContext, "discPlay", apiDiscPlay); - lua_register(_luaContext, "discSearch", apiDiscSearch); - lua_register(_luaContext, "discSearchBlanking", apiDiscSearchBlanking); - lua_register(_luaContext, "discSetFPS", apiDiscSetFps); - lua_register(_luaContext, "discSkipBackward", apiDiscSkipBackward); - lua_register(_luaContext, "discSkipBlanking", apiDiscSkipBlanking); - lua_register(_luaContext, "discSkipForward", apiDiscSkipForward); - lua_register(_luaContext, "discSkipToFrame", apiDiscSkipToFrame); - lua_register(_luaContext, "discStepBackward", apiDiscStepBackward); - lua_register(_luaContext, "discStepForward", apiDiscStepForward); - lua_register(_luaContext, "discStop", apiDiscStop); + lua_register(_global.luaContext, "discAudio", apiDiscAudio); + lua_register(_global.luaContext, "discChangeSpeed", apiDiscChangeSpeed); + lua_register(_global.luaContext, "discGetFrame", apiDiscGetFrame); + lua_register(_global.luaContext, "discGetState", apiDiscGetState); + lua_register(_global.luaContext, "discPause", apiDiscPause); + lua_register(_global.luaContext, "discPauseAtFrame", apiDiscPauseAtFrame); + lua_register(_global.luaContext, "discPlay", apiDiscPlay); + lua_register(_global.luaContext, "discSearch", apiDiscSearch); + lua_register(_global.luaContext, "discSearchBlanking", apiDiscSearchBlanking); + lua_register(_global.luaContext, "discSetFPS", apiDiscSetFps); + lua_register(_global.luaContext, "discSkipBackward", apiDiscSkipBackward); + lua_register(_global.luaContext, "discSkipBlanking", apiDiscSkipBlanking); + lua_register(_global.luaContext, "discSkipForward", apiDiscSkipForward); + lua_register(_global.luaContext, "discSkipToFrame", apiDiscSkipToFrame); + lua_register(_global.luaContext, "discStepBackward", apiDiscStepBackward); + lua_register(_global.luaContext, "discStepForward", apiDiscStepForward); + lua_register(_global.luaContext, "discStop", apiDiscStop); - lua_register(_luaContext, "fontLoad", apiFontLoad); - lua_register(_luaContext, "fontPrint", apiFontPrint); - lua_register(_luaContext, "fontQuality", apiFontQuality); - lua_register(_luaContext, "fontSelect", apiFontSelect); - lua_register(_luaContext, "fontToSprite", apiFontToSprite); + lua_register(_global.luaContext, "fontLoad", apiFontLoad); + lua_register(_global.luaContext, "fontPrint", apiFontPrint); + lua_register(_global.luaContext, "fontQuality", apiFontQuality); + lua_register(_global.luaContext, "fontSelect", apiFontSelect); + lua_register(_global.luaContext, "fontToSprite", apiFontToSprite); - lua_register(_luaContext, "keyboardGetMode", apiKeyboardGetMode); - lua_register(_luaContext, "keyboardSetMode", apiKeyboardSetMode); + lua_register(_global.luaContext, "keyboardGetMode", apiKeyboardGetMode); + lua_register(_global.luaContext, "keyboardSetMode", apiKeyboardSetMode); - lua_register(_luaContext, "mouseEnable", apiMouseEnable); - lua_register(_luaContext, "mouseDisable", apiMouseDisable); - lua_register(_luaContext, "mouseGetPosition", apiMouseGetPosition); - lua_register(_luaContext, "mouseHowMany", apiMouseHowMany); - lua_register(_luaContext, "mouseSetMode", apiMouseSetMode); + lua_register(_global.luaContext, "mouseEnable", apiMouseEnable); + lua_register(_global.luaContext, "mouseDisable", apiMouseDisable); + lua_register(_global.luaContext, "mouseGetPosition", apiMouseGetPosition); + lua_register(_global.luaContext, "mouseHowMany", apiMouseHowMany); + lua_register(_global.luaContext, "mouseSetMode", apiMouseSetMode); - lua_register(_luaContext, "overlayClear", apiOverlayClear); - lua_register(_luaContext, "overlayGetHeight", apiOverlayGetHeight); - lua_register(_luaContext, "overlayGetWidth", apiOverlayGetWidth); - lua_register(_luaContext, "overlayPrint", apiOverlayPrint); + lua_register(_global.luaContext, "overlayClear", apiOverlayClear); + lua_register(_global.luaContext, "overlayGetHeight", apiOverlayGetHeight); + lua_register(_global.luaContext, "overlayGetWidth", apiOverlayGetWidth); + lua_register(_global.luaContext, "overlayPrint", apiOverlayPrint); - lua_register(_luaContext, "singeGetPauseFlag", apiSingeGetPauseFlag); - lua_register(_luaContext, "singeSetPauseFlag", apiSingeSetPauseFlag); - lua_register(_luaContext, "singeEnablePauseKey", apiSingeEnablePauseKey); - lua_register(_luaContext, "singeDisablePauseKey", apiSingeDisablePauseKey); - lua_register(_luaContext, "singeQuit", apiSingeQuit); - lua_register(_luaContext, "singeVersion", apiSingeVersion); - lua_register(_luaContext, "singeSetGameName", apiSingeSetGameName); - lua_register(_luaContext, "singeGetScriptPath", apiSingeGetScriptPath); + lua_register(_global.luaContext, "singeGetPauseFlag", apiSingeGetPauseFlag); + lua_register(_global.luaContext, "singeSetPauseFlag", apiSingeSetPauseFlag); + lua_register(_global.luaContext, "singeEnablePauseKey", apiSingeEnablePauseKey); + lua_register(_global.luaContext, "singeDisablePauseKey", apiSingeDisablePauseKey); + lua_register(_global.luaContext, "singeQuit", apiSingeQuit); + lua_register(_global.luaContext, "singeVersion", apiSingeVersion); + lua_register(_global.luaContext, "singeSetGameName", apiSingeSetGameName); + lua_register(_global.luaContext, "singeGetScriptPath", apiSingeGetScriptPath); - lua_register(_luaContext, "soundLoad", apiSoundLoad); - lua_register(_luaContext, "soundPlay", apiSoundPlay); - lua_register(_luaContext, "soundPause", apiSoundPause); - lua_register(_luaContext, "soundResume", apiSoundResume); - lua_register(_luaContext, "soundIsPlaying", apiSoundIsPlaying); - lua_register(_luaContext, "soundStop", apiSoundStop); - lua_register(_luaContext, "soundSetVolume", apiSoundSetVolume); - lua_register(_luaContext, "soundGetVolume", apiSoundGetVolume); - lua_register(_luaContext, "soundFullStop", apiSoundFullStop); + lua_register(_global.luaContext, "soundLoad", apiSoundLoad); + lua_register(_global.luaContext, "soundPlay", apiSoundPlay); + lua_register(_global.luaContext, "soundPause", apiSoundPause); + lua_register(_global.luaContext, "soundResume", apiSoundResume); + lua_register(_global.luaContext, "soundIsPlaying", apiSoundIsPlaying); + lua_register(_global.luaContext, "soundStop", apiSoundStop); + lua_register(_global.luaContext, "soundSetVolume", apiSoundSetVolume); + lua_register(_global.luaContext, "soundGetVolume", apiSoundGetVolume); + lua_register(_global.luaContext, "soundFullStop", apiSoundFullStop); - lua_register(_luaContext, "spriteDraw", apiSpriteDraw); - lua_register(_luaContext, "spriteGetHeight", apiSpriteGetHeight); - lua_register(_luaContext, "spriteGetWidth", apiSpriteGetWidth); - lua_register(_luaContext, "spriteLoad", apiSpriteLoad); + lua_register(_global.luaContext, "spriteDraw", apiSpriteDraw); + lua_register(_global.luaContext, "spriteGetHeight", apiSpriteGetHeight); + lua_register(_global.luaContext, "spriteGetWidth", apiSpriteGetWidth); + lua_register(_global.luaContext, "spriteLoad", apiSpriteLoad); - lua_register(_luaContext, "vldpGetHeight", apiVldpGetHeight); - lua_register(_luaContext, "vldpGetPixel", apiVldpGetPixel); - lua_register(_luaContext, "vldpGetWidth", apiVldpGetWidth); - lua_register(_luaContext, "vldpSetVerbose", apiVldpVerbose); + lua_register(_global.luaContext, "vldpGetHeight", apiVldpGetHeight); + lua_register(_global.luaContext, "vldpGetPixel", apiVldpGetPixel); + lua_register(_global.luaContext, "vldpGetWidth", apiVldpGetWidth); + lua_register(_global.luaContext, "vldpSetVerbose", apiVldpVerbose); // Open main video file doIndexDisplay(-1); videoSetIndexCallback(doIndexDisplay); - if (_confIsFrameFile) { - _frameFileHandle = frameFileLoad(_confVideoFile, _confDataDir, (bool)_confStretchVideo, _renderer); - if (_frameFileHandle < 0) utilDie("Unable to load framefile: %s", _confVideoFile); - frameFileSeek(_frameFileHandle, 0, &_videoHandle, &thisFrame); // Fills in _videoHandle + if (_conf.isFrameFile) { + _global.frameFileHandle = frameFileLoad(_conf.videoFile, _conf.dataDir, (bool)_conf.stretchVideo, _global.renderer, _conf.showCalculated); + if (_global.frameFileHandle < 0) utilDie("Unable to load framefile: %s", _conf.videoFile); + frameFileSeek(_global.frameFileHandle, 0, &_global.videoHandle, &thisFrame); // Fills in _global.videoHandle } else { - _videoHandle = videoLoad(_confVideoFile, _confDataDir, (bool)_confStretchVideo, _renderer); + _global.videoHandle = videoLoad(_conf.videoFile, _conf.dataDir, (bool)_conf.stretchVideo, _global.renderer); } - if (_videoHandle < 0) utilDie("Unable to load video file: %s", _confVideoFile); - videoSetVolume(_videoHandle, _confVolumeVldp, _confVolumeVldp); + if (_global.videoHandle < 0) utilDie("Unable to load video file: %s", _conf.videoFile); + videoSetVolume(_global.videoHandle, _conf.volumeVldp, _conf.volumeVldp); videoSetIndexCallback(NULL); doIndexDisplay(-2); @@ -2439,21 +2453,21 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { // Default render location is the entire window windowTarget.x = 0; windowTarget.y = 0; - windowTarget.w = videoGetWidth(_videoHandle); - windowTarget.h = videoGetHeight(_videoHandle); + windowTarget.w = videoGetWidth(_global.videoHandle); + windowTarget.h = videoGetHeight(_global.videoHandle); sindenWhite.x = -1; sindenBlack.x = -1; // Overscan compensation - if (_confScaleFactor < 100) { - windowTarget.w = videoGetWidth(_videoHandle) * _confScaleFactor / 100; - windowTarget.h = videoGetHeight(_videoHandle) * _confScaleFactor / 100; - windowTarget.x = (videoGetWidth(_videoHandle) - windowTarget.w) / 2; - windowTarget.y = (videoGetHeight(_videoHandle) - windowTarget.h) / 2; + if (_conf.scaleFactor < 100) { + windowTarget.w = videoGetWidth(_global.videoHandle) * _conf.scaleFactor / 100; + windowTarget.h = videoGetHeight(_global.videoHandle) * _conf.scaleFactor / 100; + windowTarget.x = (videoGetWidth(_global.videoHandle) - windowTarget.w) / 2; + windowTarget.y = (videoGetHeight(_global.videoHandle) - windowTarget.h) / 2; } // Sinden Light Gun Border Setup - if (_confSindenArgc > 0) { + if (_conf.sindenArgc > 0) { //***TODO*** ADD MOUSE SCALING TO COMPENSATE FOR BORDER sindenWhiteColor.r = 255; sindenWhiteColor.g = 255; @@ -2464,52 +2478,52 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { sindenBlackColor.b = 0; sindenBlackColor.a = 255; // Ok, this thing can have a mess of different arguments: - switch(_confSindenArgc) { + switch(_conf.sindenArgc) { // WW - Just the width of the white border case SINDEN_WHITE: - sindenWhite.x = _confSindenArgv[0]; + sindenWhite.x = _conf.sindenArgv[0]; break; // WW WB - Width of white border and then black border case SINDEN_WHITE_BLACK: - sindenWhite.x = _confSindenArgv[0]; - sindenBlack.x = _confSindenArgv[1]; + sindenWhite.x = _conf.sindenArgv[0]; + sindenBlack.x = _conf.sindenArgv[1]; break; // RW GW BW WW - Custom color "white" border and width case SINDEN_CUSTOM_WHITE: - sindenWhiteColor.r = _confSindenArgv[0]; - sindenWhiteColor.g = _confSindenArgv[1]; - sindenWhiteColor.b = _confSindenArgv[2]; - sindenWhite.x = _confSindenArgv[3]; + sindenWhiteColor.r = _conf.sindenArgv[0]; + sindenWhiteColor.g = _conf.sindenArgv[1]; + sindenWhiteColor.b = _conf.sindenArgv[2]; + sindenWhite.x = _conf.sindenArgv[3]; break; // RW GW BW WW WB - Custom color "white" border and width then width of black border case SINDEN_CUSTOM_WHITE_BLACK: - sindenWhiteColor.r = _confSindenArgv[0]; - sindenWhiteColor.g = _confSindenArgv[1]; - sindenWhiteColor.b = _confSindenArgv[2]; - sindenWhite.x = _confSindenArgv[3]; - sindenBlack.x = _confSindenArgv[4]; + sindenWhiteColor.r = _conf.sindenArgv[0]; + sindenWhiteColor.g = _conf.sindenArgv[1]; + sindenWhiteColor.b = _conf.sindenArgv[2]; + sindenWhite.x = _conf.sindenArgv[3]; + sindenBlack.x = _conf.sindenArgv[4]; break; // RW GW BW WW RB GB BB WB - Custom color "white" border and width then custom color "black" border and width case SINDEN_CUSTOM_WHITE_CUSTOM_BLACK: - sindenWhiteColor.r = _confSindenArgv[0]; - sindenWhiteColor.g = _confSindenArgv[1]; - sindenWhiteColor.b = _confSindenArgv[2]; - sindenWhite.x = _confSindenArgv[3]; - sindenBlackColor.r = _confSindenArgv[4]; - sindenBlackColor.g = _confSindenArgv[5]; - sindenBlackColor.b = _confSindenArgv[6]; - sindenBlack.x = _confSindenArgv[7]; + sindenWhiteColor.r = _conf.sindenArgv[0]; + sindenWhiteColor.g = _conf.sindenArgv[1]; + sindenWhiteColor.b = _conf.sindenArgv[2]; + sindenWhite.x = _conf.sindenArgv[3]; + sindenBlackColor.r = _conf.sindenArgv[4]; + sindenBlackColor.g = _conf.sindenArgv[5]; + sindenBlackColor.b = _conf.sindenArgv[6]; + sindenBlack.x = _conf.sindenArgv[7]; break; } if (sindenWhite.x >= 0) { sindenWhite.y = sindenWhite.x; - sindenWhite.w = videoGetWidth(_videoHandle) - (sindenWhite.x * 2); - sindenWhite.h = videoGetHeight(_videoHandle) - (sindenWhite.y * 2); + sindenWhite.w = videoGetWidth(_global.videoHandle) - (sindenWhite.x * 2); + sindenWhite.h = videoGetHeight(_global.videoHandle) - (sindenWhite.y * 2); } if (sindenBlack.x >= 0) { sindenBlack.y = sindenBlack.x; - sindenBlack.w = videoGetWidth(_videoHandle) - (sindenBlack.x * 2); - sindenBlack.h = videoGetHeight(_videoHandle) - (sindenBlack.y * 2); + sindenBlack.w = videoGetWidth(_global.videoHandle) - (sindenBlack.x * 2); + sindenBlack.h = videoGetHeight(_global.videoHandle) - (sindenBlack.y * 2); sindenWhite.x += sindenBlack.x; sindenWhite.y += sindenBlack.y; sindenWhite.w -= (sindenBlack.x * 2); @@ -2519,74 +2533,74 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { } // Create overlay surface - _overlayScaleX = 0.5; - _overlayScaleY = 0.5; - x = (int32_t)(videoGetWidth(_videoHandle) * _overlayScaleX); - y = (int32_t)(videoGetHeight(_videoHandle) * _overlayScaleY); - _overlay = SDL_CreateRGBSurfaceWithFormat(0, x, y, 32, SDL_PIXELFORMAT_BGRA32); - if (_overlay == NULL) utilDie("%s", SDL_GetError()); - SDL_SetColorKey(_overlay, true, 0); + _global.overlayScaleX = 0.5; + _global.overlayScaleY = 0.5; + x = (int32_t)(videoGetWidth(_global.videoHandle) * _global.overlayScaleX); + y = (int32_t)(videoGetHeight(_global.videoHandle) * _global.overlayScaleY); + _global.overlay = SDL_CreateRGBSurfaceWithFormat(0, x, y, 32, SDL_PIXELFORMAT_BGRA32); + if (_global.overlay == NULL) utilDie("%s", SDL_GetError()); + SDL_SetColorKey(_global.overlay, true, 0); // Mouse setup - _mouseCount = ManyMouse_Init(); + _global.mouseCount = ManyMouse_Init(); //utilSay("***DEBUG*** Mouse Driver: %s", ManyMouse_DriverName()); - //utilSay("***DEBUG*** Mice Found: %d", _mouseCount); - if (_mouseCount < 1) utilDie("No mice detected."); - if (_mouseCount > MAX_MICE) { - _mouseCount = MAX_MICE; + //utilSay("***DEBUG*** Mice Found: %d", _global.mouseCount); + if (_global.mouseCount < 1) utilDie("No mice detected."); + if (_global.mouseCount > MAX_MICE) { + _global.mouseCount = MAX_MICE; } - memset(_mice, 0, sizeof(_mice)); - _mouseEnabled = (bool)!_confNoMouse; - for (x=0; x<_mouseCount; x++) { - strncpy(_mice[x].name, ManyMouse_DeviceName((unsigned)x), sizeof(_mice[x].name)); - _mice[x].name[sizeof(_mice[x].name) - 1] = 0; - _mice[x].x = (int32_t)(videoGetWidth(_videoHandle) * _overlayScaleX); - _mice[x].y = (int32_t)(videoGetHeight(_videoHandle) * _overlayScaleY); - //utilSay("***DEBUG*** Mouse %d: %s", x, _mice[x].name); + memset(_global.mice, 0, sizeof(_global.mice)); + _global.mouseEnabled = (bool)!_conf.noMouse; + for (x=0; x<_global.mouseCount; x++) { + strncpy(_global.mice[x].name, ManyMouse_DeviceName((unsigned)x), sizeof(_global.mice[x].name)); + _global.mice[x].name[sizeof(_global.mice[x].name) - 1] = 0; + _global.mice[x].x = (int32_t)(videoGetWidth(_global.videoHandle) * _global.overlayScaleX); + _global.mice[x].y = (int32_t)(videoGetHeight(_global.videoHandle) * _global.overlayScaleY); + //utilSay("***DEBUG*** Mouse %d: %s", x, _global.mice[x].name); } // Grab mouse - _mouseGrabbed = true; - SDL_SetWindowGrab(_window, SDL_TRUE); + _global.mouseGrabbed = true; + SDL_SetWindowGrab(_global.window, SDL_TRUE); SDL_ShowCursor(SDL_DISABLE); // Clear axis cache for (x=0; xw / 256; - _consoleFontHeight = _consoleFontSurface->h; - SDL_SetColorKey(_consoleFontSurface, true, _consoleFontSurface->format->Rmask | _consoleFontSurface->format->Bmask); + _global.consoleFontSurface = IMG_LoadPNG_RW(SDL_RWFromMem(font_png, font_png_len)); + if (_global.consoleFontSurface == NULL) utilDie("%s", SDL_GetError()); + _global.consoleFontWidth = _global.consoleFontSurface->w / 256; + _global.consoleFontHeight = _global.consoleFontSurface->h; + SDL_SetColorKey(_global.consoleFontSurface, true, _global.consoleFontSurface->format->Rmask | _global.consoleFontSurface->format->Bmask); // Start video - videoPlay(_videoHandle); - _discStopped = false; + videoPlay(_global.videoHandle); + _global.discStopped = false; // Start script - if (luaL_dofile(_luaContext, _confScriptFile) != 0) utilDie("Error compiling script: %s", lua_tostring(_luaContext, -1)); + if (luaL_dofile(_global.luaContext, _conf.scriptFile) != 0) utilDie("Error compiling script: %s", lua_tostring(_global.luaContext, -1)); // Game Loop - while (_running) { + while (_global.running) { // SDL Event Loop while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_CONTROLLERAXISMOTION: // Is this in a range we care about? - if (abs(event.caxis.value) > _controllerDeadZone) { + if (abs(event.caxis.value) > _global.controllerDeadZone) { // Determine which "scancode" to process - see Framework.singe // Controller codes begin at 500 and increment in 100 x = event.caxis.which * 100 + 500; @@ -2602,7 +2616,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { processKey(false, 0, x); } // Remember this change - _axisCache[event.caxis.which * 2 + event.caxis.axis] = event.caxis.value; + _global.axisCache[event.caxis.which * 2 + event.caxis.axis] = event.caxis.value; // Fire analog event callLua("onControllerMoved", "iii", event.caxis.axis, event.caxis.value, event.caxis.which); break; @@ -2630,14 +2644,14 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { break; case SDL_MOUSEMOTION: - if ((_mouseEnabled) && (_mouseMode == MOUSE_SINGLE)) { - x = (int32_t)(event.motion.x * _overlayScaleX); - y = (int32_t)(event.motion.y * _overlayScaleY); - xr = (int32_t)(event.motion.xrel * _overlayScaleX); - yr = (int32_t)(event.motion.yrel * _overlayScaleY); + if ((_global.mouseEnabled) && (_global.mouseMode == MOUSE_SINGLE)) { + x = (int32_t)(event.motion.x * _global.overlayScaleX); + y = (int32_t)(event.motion.y * _global.overlayScaleY); + xr = (int32_t)(event.motion.xrel * _global.overlayScaleX); + yr = (int32_t)(event.motion.yrel * _global.overlayScaleY); // Remember this change - _axisCache[MAX_CONTROLLERS * 2] = x; - _axisCache[MAX_CONTROLLERS * 2 + 1] = y; + _global.axisCache[MAX_CONTROLLERS * 2] = x; + _global.axisCache[MAX_CONTROLLERS * 2 + 1] = y; // Fire event callLua("onMouseMoved", "iiiii", x, y, xr, yr, 0); } @@ -2645,7 +2659,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - if ((_mouseEnabled) && (_mouseMode == MOUSE_SINGLE)) { + if ((_global.mouseEnabled) && (_global.mouseMode == MOUSE_SINGLE)) { // Mouse events start at "scancode" 1000 x = 1000; // SDL maps buttons L,M,R,X1,X2 starting at 1 @@ -2669,7 +2683,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { break; case SDL_MOUSEWHEEL: - if ((_mouseEnabled) && (_mouseMode == MOUSE_SINGLE)) { + if ((_global.mouseEnabled) && (_global.mouseMode == MOUSE_SINGLE)) { // Mouse events start at "scancode" 1000 x = 1000; // Scroll events start at 1005 and are mapped UP then DOWN @@ -2681,7 +2695,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { break; case SDL_QUIT: - _running = 0; + _global.running = 0; break; } @@ -2689,11 +2703,11 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { while (ManyMouse_PollEvent(&mouseEvent)) { // Just run out the event queue if we're not using ManyMouse - if ((!_mouseEnabled) || (_mouseMode == MOUSE_SINGLE)) continue; + if ((!_global.mouseEnabled) || (_global.mouseMode == MOUSE_SINGLE)) continue; // Has this one been unplugged? - if (mouseEvent.device >= (unsigned)_mouseCount) continue; - mouse = &_mice[mouseEvent.device]; + if (mouseEvent.device >= (unsigned)_global.mouseCount) continue; + mouse = &_global.mice[mouseEvent.device]; switch (mouseEvent.type) { case MANYMOUSE_EVENT_RELMOTION: @@ -2707,19 +2721,19 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { break; } // Clamp to video size - x = videoGetWidth(_videoHandle); - y = videoGetHeight(_videoHandle); + x = videoGetWidth(_global.videoHandle); + y = videoGetHeight(_global.videoHandle); if (mouse->relx < 0) mouse->relx = 0; if (mouse->relx >= x) mouse->relx = x - 1; if (mouse->rely < 0) mouse->rely = 0; if (mouse->rely >= y) mouse->rely = y - 1; - x = (int32_t)(mouse->x * _overlayScaleX); - y = (int32_t)(mouse->y * _overlayScaleY); - xr = (int32_t)(mouse->relx * _overlayScaleX); - yr = (int32_t)(mouse->relx * _overlayScaleY); + x = (int32_t)(mouse->x * _global.overlayScaleX); + y = (int32_t)(mouse->y * _global.overlayScaleY); + xr = (int32_t)(mouse->relx * _global.overlayScaleX); + yr = (int32_t)(mouse->relx * _global.overlayScaleY); // Remember this change - _axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2] = x; - _axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2 + 1] = y; + _global.axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2] = x; + _global.axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2 + 1] = y; // Fire event callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device); break; @@ -2734,14 +2748,14 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { mouse->y += mouseEvent.value; break; } - x = (int32_t)(mouse->x * _overlayScaleX); - y = (int32_t)(mouse->y * _overlayScaleY); - xr = (int32_t)(mouse->relx * _overlayScaleX); - yr = (int32_t)(mouse->relx * _overlayScaleY); + x = (int32_t)(mouse->x * _global.overlayScaleX); + y = (int32_t)(mouse->y * _global.overlayScaleY); + xr = (int32_t)(mouse->relx * _global.overlayScaleX); + yr = (int32_t)(mouse->relx * _global.overlayScaleY); //utilSay("Mouse %d: Absolute %d, %d", mouseEvent.device, x, y); // Remember this change - _axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2] = x; - _axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2 + 1] = y; + _global.axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2] = x; + _global.axisCache[MAX_CONTROLLERS * 2 + mouseEvent.device * 2 + 1] = y; // Fire event callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device); break; @@ -2789,67 +2803,67 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { } // Update video - thisFrame = videoUpdate(_videoHandle, &_videoTexture); - if (_confIsFrameFile) { - frameFileUpdate(_frameFileHandle, &_videoHandle); + thisFrame = videoUpdate(_global.videoHandle, &_global.videoTexture); + if (_conf.isFrameFile) { + frameFileUpdate(_global.frameFileHandle, &_global.videoHandle); } // Did we get a new video frame? if ((thisFrame != lastFrame) && (thisFrame >= 0)) { lastFrame = thisFrame; frameClock = 0; - _refreshDisplay = true; + _global.refreshDisplay = true; } // Call game code if (SDL_GetTicks() > frameClock) { callLua("onOverlayUpdate", ">i", &intReturn); if (intReturn == 1) { - _refreshDisplay = true; + _global.refreshDisplay = true; } frameClock = SDL_GetTicks() + 15; // Don't eat all the CPU. } // Update display - if (_refreshDisplay || _discStopped) { + if (_global.refreshDisplay || _global.discStopped) { // Sinden Gun Border if (sindenWhite.x >= 0) { if (sindenBlack.x >= 0) { // Black and White - SDL_SetRenderDrawColor(_renderer, sindenBlackColor.r, sindenBlackColor.g, sindenBlackColor.b, sindenBlackColor.a); - SDL_RenderClear(_renderer); - SDL_SetRenderDrawColor(_renderer, sindenWhiteColor.r, sindenWhiteColor.g, sindenWhiteColor.b, sindenWhiteColor.a); - SDL_RenderFillRect(_renderer, &sindenBlack); + SDL_SetRenderDrawColor(_global.renderer, sindenBlackColor.r, sindenBlackColor.g, sindenBlackColor.b, sindenBlackColor.a); + SDL_RenderClear(_global.renderer); + SDL_SetRenderDrawColor(_global.renderer, sindenWhiteColor.r, sindenWhiteColor.g, sindenWhiteColor.b, sindenWhiteColor.a); + SDL_RenderFillRect(_global.renderer, &sindenBlack); } else { // Only white - SDL_SetRenderDrawColor(_renderer, sindenWhiteColor.r, sindenWhiteColor.g, sindenWhiteColor.b, sindenWhiteColor.a); - SDL_RenderClear(_renderer); + SDL_SetRenderDrawColor(_global.renderer, sindenWhiteColor.r, sindenWhiteColor.g, sindenWhiteColor.b, sindenWhiteColor.a); + SDL_RenderClear(_global.renderer); } - SDL_RenderFillRect(_renderer, &windowTarget); + SDL_RenderFillRect(_global.renderer, &windowTarget); } // Laserdisc Video - if (_discStopped) { + if (_global.discStopped) { // Stopped discs display blue like the good old days - SDL_SetRenderTarget(_renderer, _videoTexture); - SDL_SetRenderDrawColor(_renderer, 0, 0, 255, 255); - SDL_RenderClear(_renderer); - SDL_SetRenderTarget(_renderer, NULL); + SDL_SetRenderTarget(_global.renderer, _global.videoTexture); + SDL_SetRenderDrawColor(_global.renderer, 0, 0, 255, 255); + SDL_RenderClear(_global.renderer); + SDL_SetRenderTarget(_global.renderer, NULL); } - SDL_RenderCopy(_renderer, _videoTexture, NULL, &windowTarget); + SDL_RenderCopy(_global.renderer, _global.videoTexture, NULL, &windowTarget); // Overlay - overlayTexture = SDL_CreateTextureFromSurface(_renderer, _overlay); + overlayTexture = SDL_CreateTextureFromSurface(_global.renderer, _global.overlay); if (!overlayTexture) utilDie("%s", SDL_GetError()); - if (!_confStretchVideo) { - SDL_RenderSetLogicalSize(renderer, videoGetWidth(_videoHandle), videoGetHeight(_videoHandle)); + if (!_conf.stretchVideo) { + SDL_RenderSetLogicalSize(renderer, videoGetWidth(_global.videoHandle), videoGetHeight(_global.videoHandle)); } - SDL_RenderCopy(_renderer, overlayTexture, NULL, &windowTarget); + SDL_RenderCopy(_global.renderer, overlayTexture, NULL, &windowTarget); SDL_DestroyTexture(overlayTexture); overlayTexture = NULL; // Show it - SDL_RenderPresent(_renderer); - _refreshDisplay = false; + SDL_RenderPresent(_global.renderer); + _global.refreshDisplay = false; // Save it? - if (_requestScreenShot) { - _requestScreenShot = false; + if (_global.requestScreenShot) { + _global.requestScreenShot = false; takeScreenshot(); } } @@ -2865,47 +2879,47 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { Mix_ChannelFinished(NULL); // Stop Lua - lua_close(_luaContext); + lua_close(_global.luaContext); // Free overlay & overlay font - SDL_FreeSurface(_overlay); - SDL_FreeSurface(_consoleFontSurface); + SDL_FreeSurface(_global.overlay); + SDL_FreeSurface(_global.consoleFontSurface); // Unload fonts - HASH_ITER(hh, _fontList, font, fontTemp) { + HASH_ITER(hh, _global.fontList, font, fontTemp) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" - HASH_DEL(_fontList, font); + HASH_DEL(_global.fontList, font); #pragma GCC diagnostic pop TTF_CloseFont(font->font); free(font); } // Unload sounds - HASH_ITER(hh, _soundList, sound, soundTemp) { + HASH_ITER(hh, _global.soundList, sound, soundTemp) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" - HASH_DEL(_soundList, sound); + HASH_DEL(_global.soundList, sound); #pragma GCC diagnostic pop Mix_FreeChunk(sound->chunk); free(sound); } // Unload sprites - HASH_ITER(hh, _spriteList, sprite, spriteTemp) { + HASH_ITER(hh, _global.spriteList, sprite, spriteTemp) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" - HASH_DEL(_spriteList, sprite); + HASH_DEL(_global.spriteList, sprite); #pragma GCC diagnostic pop SDL_FreeSurface(sprite->surface); free(sprite); } // Unload video - if (_confIsFrameFile) { - frameFileUnload(_frameFileHandle); + if (_conf.isFrameFile) { + frameFileUnload(_global.frameFileHandle); } else { - videoUnload(_videoHandle); + videoUnload(_global.videoHandle); } // Stop controllers @@ -2923,14 +2937,14 @@ void startControllers(void) { stopControllers(); // Clamp to the first four controllers found for now - _controllerCount = SDL_NumJoysticks(); - if (_controllerCount > 4) _controllerCount = 4; + _global.controllerCount = SDL_NumJoysticks(); + if (_global.controllerCount > 4) _global.controllerCount = 4; - _controllers = (SDL_GameController **)malloc(sizeof(SDL_GameController *) * (size_t)_controllerCount); - for (x=0; x<_controllerCount; x++) { - _controllers[x] = NULL; + _global.controllers = (SDL_GameController **)malloc(sizeof(SDL_GameController *) * (size_t)_global.controllerCount); + for (x=0; x<_global.controllerCount; x++) { + _global.controllers[x] = NULL; if (SDL_IsGameController(x)) { - _controllers[x] = SDL_GameControllerOpen(x); + _global.controllers[x] = SDL_GameControllerOpen(x); /* if (_controllers[x]) { utilSay("Found #%d - %s\n", x, SDL_GameControllerName(_controllers[x])); @@ -2950,16 +2964,16 @@ void startControllers(void) { void stopControllers(void) { int32_t x; - if (_controllerCount > 0) { - for (x=0; x<_controllerCount; x++) { - if (_controllers[x] != NULL) { - SDL_GameControllerClose(_controllers[x]); - _controllers[x] = NULL; + if (_global.controllerCount > 0) { + for (x=0; x<_global.controllerCount; x++) { + if (_global.controllers[x] != NULL) { + SDL_GameControllerClose(_global.controllers[x]); + _global.controllers[x] = NULL; } } - free(_controllers); - _controllers = NULL; - _controllerCount = 0; + free(_global.controllers); + _global.controllers = NULL; + _global.controllerCount = 0; } } @@ -2973,16 +2987,16 @@ void takeScreenshot(void) { SDL_Rect viewport; while (x <= 999) { - snprintf(filename, 1024, "%ssinge%03d.png", _confDataDir, x); + snprintf(filename, 1024, "%ssinge%03d.png", _conf.dataDir, x); if (!utilFileExists(filename)) break; x++; } if (x > 999) utilDie("Seriously? You have 1000 screenshots in this folder? Remove some."); - SDL_RenderGetViewport(_renderer, &viewport); + SDL_RenderGetViewport(_global.renderer, &viewport); surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 32, 0, 0, 0, 0); if (!surface) utilDie("%s", SDL_GetError()); - if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) != 0) utilDie("%s", SDL_GetError()); + if (SDL_RenderReadPixels(_global.renderer, NULL, surface->format->format, surface->pixels, surface->pitch) != 0) utilDie("%s", SDL_GetError()); //***FIX*** This crashes with a SEGFAULT sometimes. Not sure why. if (IMG_SavePNG(surface, filename) < 0) utilDie("%s", IMG_GetError()); SDL_FreeSurface(surface); diff --git a/singe/singe.h b/singe/singe.h index 9c3430ebd..923690bd1 100644 --- a/singe/singe.h +++ b/singe/singe.h @@ -31,7 +31,7 @@ // Don't forget to update singe.rc! #define SINGE_VERSION 2.00 -#define VERSION_STRING "v2.00b11" +#define VERSION_STRING "v2.00b12" #define COPYRIGHT_END_YEAR "2020" @@ -45,26 +45,31 @@ enum { }; +typedef struct ConfigS { + char *videoFile; + char *scriptFile; + char *dataDir; + bool isFrameFile; + bool stretchVideo; + bool noMouse; + bool noSound; + bool fullScreen; + bool fullScreenWindow; + bool showCalculated; + bool noConsole; + bool noLogos; + int32_t volumeVldp; + int32_t volumeNonVldp; + int32_t scaleFactor; + int32_t xResolution; + int32_t yResolution; + int32_t sindenArgc; + int32_t sindenArgv[SINDEN_OPTION_COUNT]; +} ConfigT; + + // Command line options -extern char *_confVideoFile; -extern char *_confScriptFile; -extern char *_confDataDir; -extern bool _confIsFrameFile; -extern bool _confStretchVideo; -extern bool _confNoMouse; -extern bool _confNoSound; -extern bool _confFullScreen; -extern bool _confFullScreenWindow; -extern bool _confShowCalculated; -extern bool _confNoConsole; -extern bool _confNoLogos; -extern int32_t _confVolumeVldp; -extern int32_t _confVolumeNonVldp; -extern int32_t _confScaleFactor; -extern int32_t _confXResolution; -extern int32_t _confYResolution; -extern int32_t _confSindenArgc; -extern int32_t _confSindenArgv[SINDEN_OPTION_COUNT]; +extern ConfigT _conf; void singe(SDL_Window *window, SDL_Renderer *renderer); diff --git a/singe/singe.rc b/singe/singe.rc index 135f20fc5..28f119075 100644 --- a/singe/singe.rc +++ b/singe/singe.rc @@ -1,7 +1,7 @@ 101 ICON "/tmp/icon.ico" 1 VERSIONINFO -FILEVERSION 2,0,0,11 -PRODUCTVERSION 2,0,0,11 +FILEVERSION 2,0,0,12 +PRODUCTVERSION 2,0,0,12 BEGIN BLOCK "StringFileInfo" BEGIN @@ -9,12 +9,12 @@ BEGIN BEGIN VALUE "CompanyName", "Kangaroo Punch Studios" VALUE "FileDescription", "Somewhat Interactive Nostalgic Game Engine" - VALUE "FileVersion", "2.00b11" + VALUE "FileVersion", "2.00b12" VALUE "InternalName", "Singe" VALUE "LegalCopyright", "Copyright 2006-2020 Scott C. Duensing" VALUE "OriginalFilename", "singe.exe" VALUE "ProductName", "Singe" - VALUE "ProductVersion", "2.00b11" + VALUE "ProductVersion", "2.00b12" END END BLOCK "VarFileInfo" diff --git a/singe/util.c b/singe/util.c index abd7201a2..d419fbab1 100644 --- a/singe/util.c +++ b/singe/util.c @@ -42,10 +42,8 @@ static const int CONSOLE_LINES = 1000; #include "util.h" -extern bool _confNoConsole; - - -FILE *utilTraceFile = NULL; +static bool _consoleEnabled = true; +static FILE *_utilTraceFile = NULL; char *utilCreateString(char *format, ...) { @@ -82,7 +80,7 @@ __attribute__((__format__(__printf__, 1, 0))) __attribute__((noreturn)) void utilDie(char *fmt, ...) { va_list args; - if (!_confNoConsole) { + if (_consoleEnabled) { va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); @@ -96,6 +94,11 @@ void utilDie(char *fmt, ...) { } +void utilEnableConsole(bool enable) { + _consoleEnabled = enable; +} + + bool utilFileExists(char *filename) { FILE *file; if ((file = fopen(filename, "r+"))) { @@ -372,7 +375,7 @@ void utilRedirectConsole(void) { __attribute__((__format__(__printf__, 1, 0))) void utilSay(char *fmt, ...) { va_list args; - if (!_confNoConsole) { + if (_consoleEnabled) { va_start(args, fmt); vfprintf(stdout, fmt, args); va_end(args); @@ -404,7 +407,7 @@ char *utilStrndup( const char *s1, size_t n) { void utilTrace(char *fmt, ...) { va_list args; - if (utilTraceFile) { + if (_utilTraceFile) { va_start(args, fmt); utilTraceVArgs(fmt, args); va_end(args); @@ -413,21 +416,26 @@ void utilTrace(char *fmt, ...) { void utilTraceEnd(void) { - if (utilTraceFile) fclose(utilTraceFile); + if (_utilTraceFile) fclose(_utilTraceFile); +} + + +FILE *utilTraceGetFile(void) { + return _utilTraceFile; } void utilTraceStart(char *filename) { - utilTraceFile = fopen(filename, "wt"); - if (!utilTraceFile) utilDie("Unable to create trace file: %s", filename); + _utilTraceFile = fopen(filename, "wt"); + if (!_utilTraceFile) utilDie("Unable to create trace file: %s", filename); } __attribute__((__format__(__printf__, 1, 0))) void utilTraceVArgs(char *fmt, va_list args) { - if (utilTraceFile) { - vfprintf(utilTraceFile, fmt, args); - fprintf(utilTraceFile, "\n"); - fflush(utilTraceFile); + if (_utilTraceFile) { + vfprintf(_utilTraceFile, fmt, args); + fprintf(_utilTraceFile, "\n"); + fflush(_utilTraceFile); } } diff --git a/singe/util.h b/singe/util.h index b6e8f5cec..15fb7662f 100644 --- a/singe/util.h +++ b/singe/util.h @@ -35,12 +35,10 @@ #define UTIL_PATH_MAX 1024 -extern FILE *utilTraceFile; - - char *utilCreateString(char *format, ...); char *utilCreateStringVArgs(char *format, va_list args); void utilDie(char *fmt, ...); +void utilEnableConsole(bool enable); bool utilFileExists(char *filename); void utilFixPathSeparators(char **path, bool slash); char *utilGetFileExtension(char *filename); @@ -56,6 +54,7 @@ int utilStricmp(char *a, char *b); char *utilStrndup( const char *s1, size_t n); void utilTrace(char *fmt, ...); void utilTraceEnd(void); +FILE *utilTraceGetFile(void); void utilTraceStart(char *filename); void utilTraceVArgs(char *fmt, va_list args);