diff --git a/singe/common.h b/singe/common.h index 2a650218a..254e3ec1e 100644 --- a/singe/common.h +++ b/singe/common.h @@ -24,6 +24,9 @@ #define COMMON_H +#include + + #define byte unsigned char #define bool unsigned char diff --git a/singe/frameFile.c b/singe/frameFile.c index f4f475adc..2dba54466 100644 --- a/singe/frameFile.c +++ b/singe/frameFile.c @@ -27,17 +27,20 @@ #include "frameFile.h" +extern bool _confShowCalculated; + + typedef struct FrameLineS { - int videoHandle; - int lastFramePlayed; - long frame; - char *filename; + int32_t videoHandle; + int64_t lastFramePlayed; + int64_t frame; + char *filename; } FrameLineT; typedef struct FrameFileS { - int id; - int count; + int32_t id; + int32_t count; char *videoPath; FrameLineT *files; UT_hash_handle hh; @@ -45,15 +48,15 @@ typedef struct FrameFileS { static FrameFileT *_frameFileHash = NULL; -static int _nextId = 0; +static int32_t _nextId = 0; -void _transferProperties(int oldHandle, int newHandle); +void _transferProperties(int32_t oldHandle, int32_t newHandle); -void _transferProperties(int oldHandle, int newHandle) { - int l = 0; - int r = 0; +void _transferProperties(int32_t oldHandle, int32_t newHandle) { + int32_t l = 0; + int32_t r = 0; if ((oldHandle < 0) || (newHandle < 0)) { // Invalid handle somewhere @@ -72,13 +75,13 @@ void _transferProperties(int oldHandle, int newHandle) { } -long frameFileGetFrame(int frameFileIndex, int videoHandle) { - int i = 0; +int64_t frameFileGetFrame(int32_t frameFileHandle, int32_t videoHandle) { + int32_t i = 0; FrameFileT *f = NULL; // Get our framefile structure - HASH_FIND_INT(_frameFileHash, &frameFileIndex, f); - if (!f) utilDie("No framefile at index %d in frameFileSeek.", frameFileIndex); + HASH_FIND_INT(_frameFileHash, &frameFileHandle, f); + if (!f) utilDie("No framefile at index %d in frameFileSeek.", frameFileHandle); // Search through loaded video segments for (i=0; icount; i++) { @@ -93,15 +96,15 @@ long frameFileGetFrame(int frameFileIndex, int videoHandle) { } -int frameFileInit(void) { +int32_t frameFileInit(void) { return 0; // Nothing to do } -int frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { - int result = 0; - int count = 0; - long frame = 0; +int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { + int32_t result = 0; + int32_t count = 0; + int64_t frame = 0; size_t bytes = 0; char *audio = NULL; char *data = NULL; @@ -190,23 +193,35 @@ int frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Render result = _nextId++; + // Show debug output? + if (_confShowCalculated) { + // 00000000011111111112222222222333333333344444444445555555555666666666677777777778 + // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 + utilSay(" Start Length End File"); + utilSay("-------- -------- -------- -------------------------------------------------"); + for (count=0; countcount; count++) { + frame = videoGetFrameCount(frameFile->files[count].videoHandle); + utilSay("%8ld %8ld %8ld %s", frameFile->files[count].frame, frame, frameFile->files[count].frame + frame, frameFile->files[count].filename); + } + } + return result; } -int frameFileSeek(int frameFileIndex, long seekFrame, int *videoHandle, int *actualFrame) { - int i = 0; +int32_t frameFileSeek(int32_t frameFileHandle, int64_t seekFrame, int32_t *videoHandle, int64_t *actualFrame) { + int32_t i = 0; FrameFileT *f = NULL; // Get our framefile structure - HASH_FIND_INT(_frameFileHash, &frameFileIndex, f); - if (!f) utilDie("No framefile at index %d in frameFileSeek.", frameFileIndex); + HASH_FIND_INT(_frameFileHash, &frameFileHandle, f); + if (!f) utilDie("No framefile at index %d in frameFileSeek.", frameFileHandle); // Search through loaded video segments for (i=0; icount; i++) { if ((seekFrame >= f->files[i].frame) && (seekFrame <= (f->files[i].frame + videoGetFrameCount(f->files[i].videoHandle)))) { // Frame is in this video - *actualFrame = (int)(seekFrame - f->files[i].frame); + *actualFrame = seekFrame - f->files[i].frame; f->files[i].lastFramePlayed = *actualFrame; videoSeek(f->files[i].videoHandle, *actualFrame); // Is this a different video from the previous one? @@ -226,7 +241,7 @@ int frameFileSeek(int frameFileIndex, long seekFrame, int *videoHandle, int *act } -int frameFileQuit(void) { +int32_t frameFileQuit(void) { FrameFileT *f = NULL; FrameFileT *t = NULL; @@ -239,13 +254,13 @@ int frameFileQuit(void) { } -int frameFileUnload(int frameFileIndex) { - int i = 0; +int32_t frameFileUnload(int32_t frameFileHandle) { + int32_t i = 0; FrameFileT *f = NULL; // Get our framefile structure - HASH_FIND_INT(_frameFileHash, &frameFileIndex, f); - if (!f) utilDie("No framefile at index %d in frameFileUnload.", frameFileIndex); + HASH_FIND_INT(_frameFileHash, &frameFileHandle, f); + if (!f) utilDie("No framefile at index %d in frameFileUnload.", frameFileHandle); // Unload videos for (i=0; icount; i++) { @@ -265,14 +280,14 @@ int frameFileUnload(int frameFileIndex) { } -int frameFileUpdate(int frameFileIndex, int *videoHandle) { - int i = 0; - int frame = 0; +int32_t frameFileUpdate(int32_t frameFileHandle, int32_t *videoHandle) { + int32_t i = 0; + int64_t frame = 0; FrameFileT *f = NULL; // Get our framefile structure - HASH_FIND_INT(_frameFileHash, &frameFileIndex, f); - if (!f) utilDie("No framefile at index %d in frameFileUpdate.", frameFileIndex); + HASH_FIND_INT(_frameFileHash, &frameFileHandle, f); + if (!f) utilDie("No framefile at index %d in frameFileUpdate.", frameFileHandle); // Did the current video loop? If so, move to next video. for (i=0; icount; i++) { diff --git a/singe/frameFile.h b/singe/frameFile.h index 34c616b12..a1cb8846b 100644 --- a/singe/frameFile.h +++ b/singe/frameFile.h @@ -29,13 +29,13 @@ #include "common.h" -long frameFileGetFrame(int frameFileIndex, int videoHandle); -int frameFileInit(void); -int frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); -int frameFileSeek(int frameFileIndex, long seekFrame, int *videoHandle, int *actualFrame); -int frameFileQuit(void); -int frameFileUnload(int frameFileIndex); -int frameFileUpdate(int frameFileIndex, int *videoHandle); +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 frameFileSeek(int32_t frameFileHandle, int64_t seekFrame, int32_t *videoHandle, int64_t *actualFrame); +int32_t frameFileQuit(void); +int32_t frameFileUnload(int32_t frameFileHandle); +int32_t frameFileUpdate(int32_t frameFileHandle, int32_t *videoHandle); #endif // FRAMEFILE_H diff --git a/singe/main.c b/singe/main.c index 8e08d8257..03a6352b0 100644 --- a/singe/main.c +++ b/singe/main.c @@ -20,7 +20,7 @@ */ -// -v singe/ActionMax/frame_SonicFury.txt singe/ActionMax/SonicFury.singe +// -c -v singe/ActionMax/frame_SonicFury.txt singe/ActionMax/SonicFury.singe // -v singe/ActionMax/BlueThunder.mp4 singe/test.singe @@ -44,13 +44,13 @@ typedef struct RatioS { - int aspectNum; - int aspectDom; + int32_t aspectNum; + int32_t aspectDom; } RatioT; typedef struct ResolutionS { - int width; - int height; + int32_t width; + int32_t height; } ResolutionT; typedef struct ModeS { @@ -64,7 +64,7 @@ void showUsage(char *name, char *message); __attribute__((noreturn)) void showUsage(char *name, char *message) { - int result = 0; + int32_t result = 0; // 00000000011111111112222222222333333333344444444445555555555666666666677777777778 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 @@ -90,6 +90,7 @@ void showUsage(char *name, char *message) { utilSay(" -x, --xresolution=VALUE specify horizontal resolution"); utilSay(" -y, --yresolution=VALUE specify vertical resolution"); utilSay(" -t, --trace trace script execution to screen and file"); + utilSay(" -c, --showcalculated show calculated framefile values for debugging"); utilSay(" -h, --help this display"); utilSay(""); if (message) { @@ -106,18 +107,19 @@ void showUsage(char *name, char *message) { int main(int argc, char *argv[]) { - int x = 0; - int err = 0; - int flags = 0; - int optionIndex = 0; - int bestResIndex = -1; - int bestRatioIndex = -1; - int aspectNum = -1; - int aspectDom = -1; + int32_t x = 0; + int32_t err = 0; + int32_t flags = 0; + int32_t optionIndex = 0; + int32_t bestResIndex = -1; + int32_t bestRatioIndex = -1; + int32_t aspectNum = -1; + int32_t aspectDom = -1; char *temp = NULL; char *aspectString = NULL; float thisRatio = 0; float bestRatio = 9999; + bool tracing = false; SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; SDL_Surface *icon = NULL; @@ -140,6 +142,7 @@ int main(int argc, char *argv[]) { { "yresolution", optional_argument, NULL, 'y' }, { "help", no_argument, NULL, 'h' }, { "trace", no_argument, NULL, 't' }, + { "showcalculated", no_argument, NULL, 'c' }, { NULL, 0, NULL, 0 } }; static ModeT modes[] = { @@ -178,7 +181,7 @@ int main(int argc, char *argv[]) { while (true) { optionIndex = 0; opterr = 0; - x = getopt_long(argc, argv, "mnsfwha:d:v:l:e:z:x:y:", options, &optionIndex); + x = getopt_long(argc, argv, "cmnsfwha:d:v:l:e:z:x:y:", options, &optionIndex); // Out of options? if (x == -1) break; @@ -265,7 +268,12 @@ int main(int argc, char *argv[]) { // Trace case 't': - utilTraceStart("trace.txt"); + tracing = true; + break; + + // Show Calculated Frame File Values + case 'c': + _confShowCalculated = true; break; case '?': @@ -312,7 +320,7 @@ int main(int argc, char *argv[]) { _confVideoFile = NULL; } } else { - x = (int)(strlen(_confScriptFile) - strlen(utilGetFileExtension(_confScriptFile))) - 1; + x = (int32_t)(strlen(_confScriptFile) - strlen(utilGetFileExtension(_confScriptFile))) - 1; if (x < 0) { x = 0; } @@ -353,14 +361,29 @@ int main(int argc, char *argv[]) { } } else { // Put it in the game folder. - x = (int)(strlen(_confScriptFile) - strlen(utilGetLastPathComponent(_confScriptFile))) - 1; + x = (int32_t)(strlen(_confScriptFile) - strlen(utilGetLastPathComponent(_confScriptFile))) - 1; if (x < 0) { x = 0; } - _confDataDir = strdup(_confScriptFile); - _confDataDir[x] = 0; + // All this temp nonsense here... + // I had just jammed a zero into _confDataDir at 'x' but then if utilFixPathSeparators + // calls realloc() it pooches things up. Weird. + temp = strdup(_confScriptFile); + temp[x] = 0; + _confDataDir = strdup(temp); + free(temp); + temp = NULL; } if (!_confDataDir) showUsage(argv[0], "Unable to locate data directory."); + utilFixPathSeparators(&_confDataDir); + + // Do they want tracing? + if (tracing) { + temp = utilCreateString("%strace.txt", _confDataDir); + utilTraceStart(temp); + free(temp); + temp = NULL; + } // Do the full screen options make sense? if (_confFullScreen && _confFullScreenWindow) showUsage(argv[0], "Full Screen or Full Screen Windowed. Pick one."); diff --git a/singe/singe.c b/singe/singe.c index d52e61164..e52e10841 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -50,24 +50,24 @@ typedef struct MouseS { - int x; - int y; - int relx; - int rely; - char name[64]; - bool connected; + int32_t x; + int32_t y; + int32_t relx; + int32_t rely; + char name[64]; + bool connected; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpadded" - Uint32 buttons; + Uint32 buttons; #pragma GCC diagnostic pop - Uint32 scrolluptick; - Uint32 scrolldowntick; - Uint32 scrolllefttick; - Uint32 scrollrighttick; + Uint32 scrolluptick; + Uint32 scrolldowntick; + Uint32 scrolllefttick; + Uint32 scrollrighttick; } MouseT; typedef struct SpriteS { - int id; + int32_t id; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpadded" SDL_Surface *surface; @@ -76,7 +76,7 @@ typedef struct SpriteS { } SpriteT; typedef struct SoundS { - int id; + int32_t id; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpadded" Mix_Chunk *chunk; @@ -85,7 +85,7 @@ typedef struct SoundS { } SoundT; typedef struct FontS { - int id; + int32_t id; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpadded" TTF_Font *font; @@ -143,21 +143,22 @@ enum { // Command line options -char *_confVideoFile = NULL; -char *_confScriptFile = NULL; -char *_confDataDir = NULL; -bool _confIsFrameFile = false; -bool _confStretchVideo = false; -bool _confNoMouse = false; -bool _confNoStats = false; -bool _confNoSound = false; -bool _confFullScreen = false; -bool _confFullScreenWindow = false; -int _confVolumeVldp = 100; -int _confVolumeNonVldp = 100; -int _confScaleFactor = 100; -int _confXResolution = -1; -int _confYResolution = -1; +char *_confVideoFile = NULL; +char *_confScriptFile = NULL; +char *_confDataDir = NULL; +bool _confIsFrameFile = false; +bool _confStretchVideo = false; +bool _confNoMouse = false; +bool _confNoStats = false; +bool _confNoSound = false; +bool _confFullScreen = false; +bool _confFullScreenWindow = false; +bool _confShowCalculated = false; +int32_t _confVolumeVldp = 100; +int32_t _confVolumeNonVldp = 100; +int32_t _confScaleFactor = 100; +int32_t _confXResolution = -1; +int32_t _confYResolution = -1; // Other globals @@ -170,18 +171,18 @@ static SDL_Window *_window = NULL; static SDL_Renderer *_renderer = NULL; static SDL_Texture *_videoTexture = NULL; static SDL_Surface *_consoleFontSurface = NULL; -static int _consoleFontWidth = 0; -static int _consoleFontHeight = 0; -static int _nextSpriteId = 0; -static int _nextSoundId = 0; -static int _nextFontId = 0; -static int _effectsVolume = AUDIO_MAX_VOLUME; -static int _keyboardMode = KEYBD_NORMAL; -static int _frameFileHandle = -1; -static int _videoHandle = -1; -static int _fontQuality = 1; -static int _mouseMode = MOUSE_SINGLE; -static int _mouseCount = 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 double _overlayScaleX = 1; // Difference between overlay and video static double _overlayScaleY = 1; // Difference between overlay and video static bool _pauseState = false; // by RDG2010 @@ -240,81 +241,81 @@ static int _fullKeybdDefs[] = { }; -int apiColorBackground(lua_State *L); -int apiColorForeground(lua_State *L); -int apiDaphneGetHeight(lua_State *L); -int apiDaphneGetWidth(lua_State *L); -int apiDaphneScreenshot(lua_State *L); -int apiDebugPrint(lua_State *L); -int apiDiscAudio(lua_State *L); -int apiDiscChangeSpeed(lua_State *L); -int apiDiscGetFrame(lua_State *L); -int apiDiscPause(lua_State *L); -int apiDiscPauseAtFrame(lua_State *L); -int apiDiscPlay(lua_State *L); -int apiDiscSearch(lua_State *L); -int apiDiscSearchBlanking(lua_State *L); -int apiDiscSetFps(lua_State *L); -int apiDiscSkipBackward(lua_State *L); -int apiDiscSkipBlanking(lua_State *L); -int apiDiscSkipForward(lua_State *L); -int apiDiscSkipToFrame(lua_State *L); -int apiDiscStepBackward(lua_State *L); -int apiDiscStepForward(lua_State *L); -int apiDiscStop(lua_State *L); -int apiFontLoad(lua_State *L); -int apiFontPrint(lua_State *L); -int apiFontQuality(lua_State *L); -int apiFontSelect(lua_State *L); -int apiFontToSprite(lua_State *L); -int apiOverlayClear(lua_State *L); -int apiOverlayGetHeight(lua_State *L); -int apiOverlayGetWidth(lua_State *L); -int apiOverlayPrint(lua_State *L); -int apiSoundLoad(lua_State *L); -int apiSoundPlay(lua_State *L); -int apiSoundPause(lua_State *L); -int apiSoundResume(lua_State *L); -int apiSoundIsPlaying(lua_State *L); -int apiSoundStop(lua_State *L); -int apiSoundSetVolume(lua_State *L); -int apiSoundGetVolume(lua_State *L); -int apiSoundFullStop(lua_State *L); -int apiSpriteDraw(lua_State *L); -int apiSpriteGetHeight(lua_State *L); -int apiSpriteGetWidth(lua_State *L); -int apiSpriteLoad(lua_State *L); -int apiVldpGetHeight(lua_State *L); -int apiVldpGetPixel(lua_State *L); -int apiVldpGetWidth(lua_State *L); -int apiVldpVerbose(lua_State *L); -int apiKeyboardGetMode(lua_State *L); -int apiKeyboardSetMode(lua_State *L); -int apiMouseEnable(lua_State *L); -int apiMouseDisable(lua_State *L); -int apiMouseSetMode(lua_State *L); -int apiMouseHowMany(lua_State *L); -int apiDiscGetState(lua_State *L); -int apiSingeGetPauseFlag(lua_State *L); -int apiSingeSetPauseFlag(lua_State *L); -int apiSingeEnablePauseKey(lua_State *L); -int apiSingeDisablePauseKey(lua_State *L); -int apiSingeQuit(lua_State *L); -int apiSingeVersion(lua_State *L); -int apiSingeSetGameName(lua_State *L); -int apiSingeGetScriptPath(lua_State *L); -void callLua(const char *func, const char *sig, ...); -void channelFinished(int channel); -void luaDie(lua_State *L, char *method, char *fmt, ...); -int luaError(lua_State *L); -void luaTrace(lua_State *L, char *method, char *fmt, ...); -void processKey(bool down, int keysym); +int32_t apiColorBackground(lua_State *L); +int32_t apiColorForeground(lua_State *L); +int32_t apiDaphneGetHeight(lua_State *L); +int32_t apiDaphneGetWidth(lua_State *L); +int32_t apiDaphneScreenshot(lua_State *L); +int32_t apiDebugPrint32_t(lua_State *L); +int32_t apiDiscAudio(lua_State *L); +int32_t apiDiscChangeSpeed(lua_State *L); +int32_t apiDiscGetFrame(lua_State *L); +int32_t apiDiscPause(lua_State *L); +int32_t apiDiscPauseAtFrame(lua_State *L); +int32_t apiDiscPlay(lua_State *L); +int32_t apiDiscSearch(lua_State *L); +int32_t apiDiscSearchBlanking(lua_State *L); +int32_t apiDiscSetFps(lua_State *L); +int32_t apiDiscSkipBackward(lua_State *L); +int32_t apiDiscSkipBlanking(lua_State *L); +int32_t apiDiscSkipForward(lua_State *L); +int32_t apiDiscSkipToFrame(lua_State *L); +int32_t apiDiscStepBackward(lua_State *L); +int32_t apiDiscStepForward(lua_State *L); +int32_t apiDiscStop(lua_State *L); +int32_t apiFontLoad(lua_State *L); +int32_t apiFontPrint32_t(lua_State *L); +int32_t apiFontQuality(lua_State *L); +int32_t apiFontSelect(lua_State *L); +int32_t apiFontToSprite(lua_State *L); +int32_t apiOverlayClear(lua_State *L); +int32_t apiOverlayGetHeight(lua_State *L); +int32_t apiOverlayGetWidth(lua_State *L); +int32_t apiOverlayPrint32_t(lua_State *L); +int32_t apiSoundLoad(lua_State *L); +int32_t apiSoundPlay(lua_State *L); +int32_t apiSoundPause(lua_State *L); +int32_t apiSoundResume(lua_State *L); +int32_t apiSoundIsPlaying(lua_State *L); +int32_t apiSoundStop(lua_State *L); +int32_t apiSoundSetVolume(lua_State *L); +int32_t apiSoundGetVolume(lua_State *L); +int32_t apiSoundFullStop(lua_State *L); +int32_t apiSpriteDraw(lua_State *L); +int32_t apiSpriteGetHeight(lua_State *L); +int32_t apiSpriteGetWidth(lua_State *L); +int32_t apiSpriteLoad(lua_State *L); +int32_t apiVldpGetHeight(lua_State *L); +int32_t apiVldpGetPixel(lua_State *L); +int32_t apiVldpGetWidth(lua_State *L); +int32_t apiVldpVerbose(lua_State *L); +int32_t apiKeyboardGetMode(lua_State *L); +int32_t apiKeyboardSetMode(lua_State *L); +int32_t apiMouseEnable(lua_State *L); +int32_t apiMouseDisable(lua_State *L); +int32_t apiMouseSetMode(lua_State *L); +int32_t apiMouseHowMany(lua_State *L); +int32_t apiDiscGetState(lua_State *L); +int32_t apiSingeGetPauseFlag(lua_State *L); +int32_t apiSingeSetPauseFlag(lua_State *L); +int32_t apiSingeEnablePauseKey(lua_State *L); +int32_t apiSingeDisablePauseKey(lua_State *L); +int32_t apiSingeQuit(lua_State *L); +int32_t apiSingeVersion(lua_State *L); +int32_t apiSingeSetGameName(lua_State *L); +int32_t apiSingeGetScriptPath(lua_State *L); +void callLua(const char *func, const char *sig, ...); +void channelFinished(int channel); +void luaDie(lua_State *L, char *method, char *fmt, ...); +int32_t luaError(lua_State *L); +void luaTrace(lua_State *L, char *method, char *fmt, ...); +void processKey(bool down, int keysym); -int apiColorBackground(lua_State *L) { - int n = lua_gettop(L); - double d = 0; - bool result = false; +int32_t apiColorBackground(lua_State *L) { + int32_t n = lua_gettop(L); + double d = 0; + bool result = false; if ((n == 3) || (n == 4)) { if (lua_isnumber(L, 1)) { @@ -348,10 +349,10 @@ int apiColorBackground(lua_State *L) { } -int apiColorForeground(lua_State *L) { - int n = lua_gettop(L); - bool result = false; - double d = 0; +int32_t apiColorForeground(lua_State *L) { + int32_t n = lua_gettop(L); + bool result = false; + double d = 0; if ((n == 3) || (n == 4)) { if (lua_isnumber(L, 1)) { @@ -385,8 +386,8 @@ int apiColorForeground(lua_State *L) { } -int apiDaphneGetHeight(lua_State *L) { - int y; +int32_t apiDaphneGetHeight(lua_State *L) { + int32_t y; SDL_GetWindowSize(_window, NULL, &y); luaTrace(L, "daphneGetHeight", "%d", y); lua_pushinteger(L, y); @@ -394,8 +395,8 @@ int apiDaphneGetHeight(lua_State *L) { } -int apiDaphneGetWidth(lua_State *L) { - int x; +int32_t apiDaphneGetWidth(lua_State *L) { + int32_t x; SDL_GetWindowSize(_window, &x, NULL); luaTrace(L, "daphneGetWidth", "%d", x); lua_pushinteger(L, x); @@ -403,9 +404,9 @@ int apiDaphneGetWidth(lua_State *L) { } -int apiDaphneScreenshot(lua_State *L) { - int x = 0; - int y = 0; +int32_t apiDaphneScreenshot(lua_State *L) { + int32_t x = 0; + int32_t y = 0; Uint32 format = 0; char filename[128]; void *pixels = NULL; @@ -438,8 +439,8 @@ int apiDaphneScreenshot(lua_State *L) { } -int apiDebugPrint(lua_State *L) { - int n = lua_gettop(L); +int32_t apiDebugPrint(lua_State *L) { + int32_t n = lua_gettop(L); if (n == 1) { if (lua_isstring(L, 1)) { @@ -452,25 +453,27 @@ int apiDebugPrint(lua_State *L) { } -int apiDiscAudio(lua_State *L) { - int n = lua_gettop(L); - int channel = 0; - int left = 0; - int right = 0; - bool onOff = false; - bool result = false; - double d = 0; +int32_t apiDiscAudio(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t channel = 0; + int32_t left = 0; + int32_t right = 0; + bool onOff = false; + bool result = false; + double d = 0; if (n == 2) { if (lua_isnumber(L, 1)) { if (lua_isboolean(L, 2)) { - d = lua_tonumber(L, 1); channel = (int)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); - result = true; + if (_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); + result = true; + } } } } @@ -485,7 +488,7 @@ int apiDiscAudio(lua_State *L) { } -int apiDiscChangeSpeed(lua_State *L) { +int32_t apiDiscChangeSpeed(lua_State *L) { (void)L; //***REMOVED*** luaTrace(L, "discChangeSpeed", "Unimplemented"); @@ -493,28 +496,28 @@ int apiDiscChangeSpeed(lua_State *L) { } -int apiDiscGetFrame(lua_State *L) { - int frame = 0; +int32_t apiDiscGetFrame(lua_State *L) { + int64_t frame = 0; if (!_discStopped) { if (_confIsFrameFile) { frame = frameFileGetFrame(_frameFileHandle, _videoHandle); } else { - frame = videoGetFrame(_videoHandle); + if (_videoHandle >= 0) frame = videoGetFrame(_videoHandle); } } - luaTrace(L, "discGetFrame", "%d", frame); + luaTrace(L, "discGetFrame", "%ld", frame); lua_pushinteger(L, frame); return 1; } -int apiDiscPause(lua_State *L) { +int32_t apiDiscPause(lua_State *L) { (void)L; if (!_discStopped) { - videoPause(_videoHandle); + if (_videoHandle >= 0) videoPause(_videoHandle); luaTrace(L, "discPause", ""); } else { luaTrace(L, "discPause", "Failed! Disc is stopped."); @@ -523,25 +526,25 @@ int apiDiscPause(lua_State *L) { } -int apiDiscPauseAtFrame(lua_State *L) { +int32_t apiDiscPauseAtFrame(lua_State *L) { // More RDG oddness. This appears to be identical to discSearch. return apiDiscSearch(L); } -int apiDiscPlay(lua_State *L) { +int32_t apiDiscPlay(lua_State *L) { (void)L; - videoPlay(_videoHandle); + if (_videoHandle >= 0) videoPlay(_videoHandle); _discStopped = false; luaTrace(L, "discPlay", ""); return 0; } -int apiDiscSearch(lua_State *L) { - int n = lua_gettop(L); - int frame = 0; - int aFrame = 0; +int32_t apiDiscSearch(lua_State *L) { + int32_t n = lua_gettop(L); + int64_t frame = 0; + int64_t aFrame = 0; bool result = false; double d = 0; @@ -549,20 +552,20 @@ int apiDiscSearch(lua_State *L) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); frame = (int)d; + d = lua_tonumber(L, 1); frame = (int64_t)d; if (_confIsFrameFile) { frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); } else { - videoSeek(_videoHandle, frame); + if (_videoHandle >= 0) videoSeek(_videoHandle, frame); } - videoPause(_videoHandle); + if (_videoHandle >= 0) videoPause(_videoHandle); _discStopped = false; result = true; } } if (result) { - luaTrace(L, "discSearch", "%d", frame); + luaTrace(L, "discSearch", "%ld", frame); } else { luaTrace(L, "discSearch", "Failed!"); } @@ -571,7 +574,7 @@ int apiDiscSearch(lua_State *L) { } -int apiDiscSearchBlanking(lua_State *L) { +int32_t apiDiscSearchBlanking(lua_State *L) { (void)L; //***REMOVED*** luaTrace(L, "discSearchBlanking", "Unimplemented"); @@ -579,7 +582,7 @@ int apiDiscSearchBlanking(lua_State *L) { } -int apiDiscSetFps(lua_State *L) { +int32_t apiDiscSetFps(lua_State *L) { (void)L; //***REMOVED*** luaTrace(L, "discSetFPS", "Unimplemented"); @@ -587,23 +590,24 @@ int apiDiscSetFps(lua_State *L) { } -int apiDiscSkipBackward(lua_State *L) { - int n = lua_gettop(L); - int frame = 0; - int aFrame = 0; - bool result = false; - double d = 0; +int32_t apiDiscSkipBackward(lua_State *L) { + int32_t n = lua_gettop(L); + int64_t frame = 0; + int64_t aFrame = 0; + bool result = false; + double d = 0; // If disc is not stopped, seek backwards to given frame. Do not change play/pause state. if (!_discStopped) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); frame = videoGetFrame(_videoHandle) - (int)d; + d = lua_tonumber(L, 1); + if (_videoHandle >= 0) frame = videoGetFrame(_videoHandle) - (int64_t)d; if (_confIsFrameFile) { frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); } else { - videoSeek(_videoHandle, frame); + if (_videoHandle >= 0) videoSeek(_videoHandle, frame); } result = true; } @@ -614,7 +618,7 @@ int apiDiscSkipBackward(lua_State *L) { } if (result) { - luaTrace(L, "discSkipBackward", "%d", frame); + luaTrace(L, "discSkipBackward", "%ld", frame); } else { luaTrace(L, "discSkipBackward", "Failed!"); } @@ -623,7 +627,7 @@ int apiDiscSkipBackward(lua_State *L) { } -int apiDiscSkipBlanking(lua_State *L) { +int32_t apiDiscSkipBlanking(lua_State *L) { (void)L; //***REMOVED*** luaTrace(L, "discSkipBlanking", "Unimplemented"); @@ -631,23 +635,23 @@ int apiDiscSkipBlanking(lua_State *L) { } -int apiDiscSkipForward(lua_State *L) { - int n = lua_gettop(L); - int frame = 0; - int aFrame = 0; - bool result = false; - double d = 0; +int32_t apiDiscSkipForward(lua_State *L) { + int32_t n = lua_gettop(L); + int64_t frame = 0; + int64_t aFrame = 0; + bool result = false; + double d = 0; // If disc is not stopped, seek ahead to given frame. Do not change play/pause state. if (!_discStopped) { if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); frame = videoGetFrame(_videoHandle) + (int)d; + d = lua_tonumber(L, 1); if (_videoHandle >= 0) frame = videoGetFrame(_videoHandle) + (int64_t)d; if (_confIsFrameFile) { frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); } else { - videoSeek(_videoHandle, frame); + if (_videoHandle >= 0) videoSeek(_videoHandle, frame); } result = true; } @@ -658,7 +662,7 @@ int apiDiscSkipForward(lua_State *L) { } if (result) { - luaTrace(L, "discSkipForward", "%d", frame); + luaTrace(L, "discSkipForward", "%ld", frame); } else { luaTrace(L, "discSkipForward", "Failed!"); } @@ -667,31 +671,31 @@ int apiDiscSkipForward(lua_State *L) { } -int apiDiscSkipToFrame(lua_State *L) { - int n = lua_gettop(L); - int frame = 0; - int aFrame = 0; - bool result = false; - double d = 0; +int32_t apiDiscSkipToFrame(lua_State *L) { + int32_t n = lua_gettop(L); + int64_t frame = 0; + int64_t aFrame = 0; + bool result = false; + double d = 0; // No matter disc state, seek to given frame and play. if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); frame = (int)d; + d = lua_tonumber(L, 1); frame = (int64_t)d; if (_confIsFrameFile) { frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); } else { - videoSeek(_videoHandle, frame); + if (_videoHandle >= 0) videoSeek(_videoHandle, frame); } - videoPlay(_videoHandle); + if (_videoHandle >= 0) videoPlay(_videoHandle); _discStopped = false; result = true; } } if (result) { - luaTrace(L, "discSkipToFrame", "%d", frame); + luaTrace(L, "discSkipToFrame", "%ld", frame); } else { luaTrace(L, "discSkipToFrame", "Failed!"); } @@ -700,52 +704,58 @@ int apiDiscSkipToFrame(lua_State *L) { } -int apiDiscStepBackward(lua_State *L) { - int frame = 0; - int aFrame = 0; +int32_t apiDiscStepBackward(lua_State *L) { + int64_t frame = 0; + int64_t aFrame = 0; (void)L; // No matter disc state, go back a frame. If playing, pause. - frame = videoGetFrame(_videoHandle) - 1; - if (_confIsFrameFile) { - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); - } else { - videoSeek(_videoHandle, frame); + if (_videoHandle >= 0) { + if (_confIsFrameFile) { + frame = frameFileGetFrame(_frameFileHandle, _videoHandle) - 1; + frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + } else { + frame = videoGetFrame(_videoHandle) - 1; + videoSeek(_videoHandle, frame); + } + videoPause(_videoHandle); } - videoPause(_videoHandle); - luaTrace(L, "discStepBackward", "%d", frame); + luaTrace(L, "discStepBackward", "%ld", frame); return 0; } -int apiDiscStepForward(lua_State *L) { - int frame = 0; - int aFrame = 0; +int32_t apiDiscStepForward(lua_State *L) { + int64_t frame = 0; + int64_t aFrame = 0; (void)L; // No matter disc state, go forward a frame. If playing, pause. - frame = videoGetFrame(_videoHandle) + 1; - if (_confIsFrameFile) { - frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); - } else { - videoSeek(_videoHandle, frame); + if (_videoHandle >= 0) { + if (_confIsFrameFile) { + frame = frameFileGetFrame(_frameFileHandle, _videoHandle) + 1; + frameFileSeek(_frameFileHandle, frame, &_videoHandle, &aFrame); + } else { + frame = videoGetFrame(_videoHandle) + 1; + videoSeek(_videoHandle, frame); + } + videoPause(_videoHandle); } - videoPause(_videoHandle); - luaTrace(L, "discStepForward", "%d", frame); + luaTrace(L, "discStepForward", "%ld", frame); return 0; } -int apiDiscStop(lua_State *L) { +int32_t apiDiscStop(lua_State *L) { (void)L; if (!_discStopped) { - videoPause(_videoHandle); + if (_videoHandle >= 0) videoPause(_videoHandle); _discStopped = true; _refreshDisplay = true; luaTrace(L, "discStop", ""); @@ -756,10 +766,10 @@ int apiDiscStop(lua_State *L) { } -int apiFontLoad(lua_State *L) { - int n = lua_gettop(L); - int result = -1; - int points = 0; +int32_t apiFontLoad(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; + int32_t points = 0; const char *name = NULL; double d = 0; FontT *font = NULL; @@ -768,7 +778,7 @@ int apiFontLoad(lua_State *L) { if (lua_isstring(L, 1)) { if (lua_isnumber(L, 2)) { name = lua_tostring(L, 1); - d = lua_tonumber(L, 2); points = (int)d; + d = lua_tonumber(L, 2); points = (int32_t)d; font = (FontT *)calloc(1, sizeof(FontT)); if (!font) luaDie(L, "fontLoad", "Unable to allocate new font."); // Load this font. @@ -794,8 +804,8 @@ int apiFontLoad(lua_State *L) { } -int apiFontPrint(lua_State *L) { - int n = lua_gettop(L); +int32_t apiFontPrint(lua_State *L) { + int32_t n = lua_gettop(L); const char *message = NULL; double d = 0; SDL_Surface *textSurface = NULL; @@ -806,8 +816,8 @@ int apiFontPrint(lua_State *L) { if (lua_isnumber(L, 2)) { if (lua_isstring(L, 3)) { if (_fontCurrent) { - d = lua_tonumber(L, 1); dest.x = (int)d; - d = lua_tonumber(L, 2); dest.y = (int)d; + 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) { @@ -826,8 +836,6 @@ int apiFontPrint(lua_State *L) { if (!textSurface) { luaDie(L, "fontPrint", "Font surface is null!"); } else { - SDL_SetSurfaceBlendMode(textSurface, SDL_BLENDMODE_BLEND); - // Transparent index is 0 SDL_SetColorKey(textSurface, true, 0); dest.w = textSurface->w; dest.h = textSurface->h; @@ -850,14 +858,14 @@ int apiFontPrint(lua_State *L) { } -int apiFontQuality(lua_State *L) { - int n = lua_gettop(L); - bool result = false; - double d = 0; +int32_t apiFontQuality(lua_State *L) { + int32_t n = lua_gettop(L); + bool result = false; + double d = 0; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); _fontQuality = (int)d; + d = lua_tonumber(L, 1); _fontQuality = (int32_t)d; result = true; } } @@ -872,17 +880,17 @@ int apiFontQuality(lua_State *L) { } -int apiFontSelect(lua_State *L) { - int n = lua_gettop(L); - int id = -1; - double d = 0; - bool result = false; - FontT *font = NULL; +int32_t apiFontSelect(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t id = -1; + double d = 0; + bool result = false; + FontT *font = NULL; if (n == 1) { if (lua_isnumber(L, 1)) { d = lua_tonumber(L, 1); - id = (int)d; + id = (int32_t)d; HASH_FIND_INT(_fontList, &id, font); if (!font) luaDie(L, "fontSelect", "No font at index %d in apiSpriteGetWidth.", id); _fontCurrent = font; @@ -900,9 +908,9 @@ int apiFontSelect(lua_State *L) { } -int apiFontToSprite(lua_State *L) { - int n = lua_gettop(L); - int result = -1; +int32_t apiFontToSprite(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; const char *message = NULL; SpriteT *sprite = NULL; @@ -950,7 +958,7 @@ int apiFontToSprite(lua_State *L) { } -int apiOverlayClear(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)); luaTrace(L, "overlayClear", ""); @@ -958,25 +966,25 @@ int apiOverlayClear(lua_State *L) { } -int apiOverlayGetHeight(lua_State *L) { - luaTrace(L, "overlayGetWidth", "%d", _overlay->h); +int32_t apiOverlayGetHeight(lua_State *L) { + luaTrace(L, "overlayGetHeight", "%d", _overlay->h); lua_pushinteger(L, _overlay->h); return 1; } -int apiOverlayGetWidth(lua_State *L) { +int32_t apiOverlayGetWidth(lua_State *L) { luaTrace(L, "overlayGetWidth", "%d", _overlay->w); lua_pushinteger(L, _overlay->w); return 1; } -int apiOverlayPrint(lua_State *L) { - int n = lua_gettop(L); - int i = 0; +int32_t apiOverlayPrint(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t i = 0; char *s = NULL; - int length = 0; + int32_t length = 0; SDL_Rect src; SDL_Rect dst; @@ -992,7 +1000,7 @@ int apiOverlayPrint(lua_State *L) { dst.w = _consoleFontWidth; dst.h = _consoleFontHeight; s = (char *)lua_tostring(L, 3); - if (strlen(s) < (unsigned int)((_overlay->w - dst.x) / _consoleFontWidth)) { + if (strlen(s) < (uint32_t)((_overlay->w - dst.x) / _consoleFontWidth)) { length = strlen(s); } else { length = (_overlay->w - dst.x) / _consoleFontWidth; @@ -1011,9 +1019,9 @@ int apiOverlayPrint(lua_State *L) { } -int apiSoundLoad(lua_State *L) { - int n = lua_gettop(L); - int result = -1; +int32_t apiSoundLoad(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; const char *name = NULL; SoundT *sound = NULL; @@ -1041,16 +1049,16 @@ int apiSoundLoad(lua_State *L) { } -int apiSoundPlay(lua_State *L) { - int n = lua_gettop(L); - int result = -1; - int id = -1; +int32_t apiSoundPlay(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; + int32_t id = -1; double d = 0; SoundT *sound = NULL; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); id = (int)d; + d = lua_tonumber(L, 1); id = (int32_t)d; // Get our sound structure HASH_FIND_INT(_soundList, &id, sound); if (!sound) luaDie(L, "soundPlay", "No sound at index %d in apiSoundPlay.", id); @@ -1073,7 +1081,7 @@ int apiSoundPlay(lua_State *L) { } -int apiSoundPause(lua_State *L) { +int32_t apiSoundPause(lua_State *L) { // Instructs Daphne to pause a given sample from playing. // User must feed the sound handle on the lua side. // e.g. lua code, @@ -1085,14 +1093,14 @@ int apiSoundPause(lua_State *L) { // // --rdg - int n = lua_gettop(L); - int channel = -1; + int32_t n = lua_gettop(L); + int32_t channel = -1; double d = 0; bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); channel = (int)d; + d = lua_tonumber(L, 1); channel = (int32_t)d; Mix_Pause(channel); result = true; } @@ -1109,7 +1117,7 @@ int apiSoundPause(lua_State *L) { } -int apiSoundResume(lua_State *L) { +int32_t apiSoundResume(lua_State *L) { // Instructs Daphne to unpause a sound that was previously paused. // User must feed the sound handle on the lua side. // e.g. lua code, @@ -1122,14 +1130,14 @@ int apiSoundResume(lua_State *L) { // // --rdg - int n = lua_gettop(L); - int channel = -1; + int32_t n = lua_gettop(L); + int32_t channel = -1; double d = 0; bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); channel = (int)d; + d = lua_tonumber(L, 1); channel = (int32_t)d; Mix_Resume(channel); result = true; } @@ -1146,7 +1154,7 @@ int apiSoundResume(lua_State *L) { } -int apiSoundIsPlaying(lua_State *L) { +int32_t apiSoundIsPlaying(lua_State *L) { // Checks to see if a certain sound has finished playing. // User must feed the sound handle on the lua side. // e.g. lua code, @@ -1158,14 +1166,14 @@ int apiSoundIsPlaying(lua_State *L) { // // --rdg - int n = lua_gettop(L); - int channel = -1; + int32_t n = lua_gettop(L); + int32_t channel = -1; double d = 0; bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); channel = (int)d; + d = lua_tonumber(L, 1); channel = (int32_t)d; result = (bool)Mix_Playing(channel); } } @@ -1181,7 +1189,7 @@ int apiSoundIsPlaying(lua_State *L) { } -int apiSoundStop(lua_State *L) { +int32_t apiSoundStop(lua_State *L) { // Instructs Daphne to end a sound early. // User must feed the sound handle on the lua side. // e.g. lua code, @@ -1196,14 +1204,14 @@ int apiSoundStop(lua_State *L) { // // --rdg - int n = lua_gettop(L); - int channel = -1; + int32_t n = lua_gettop(L); + int32_t channel = -1; double d = 0; bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); channel = (int)d; + d = lua_tonumber(L, 1); channel = (int32_t)d; Mix_HaltChannel(channel); result = true; } @@ -1220,7 +1228,7 @@ int apiSoundStop(lua_State *L) { } -int apiSoundSetVolume(lua_State *L) { +int32_t apiSoundSetVolume(lua_State *L) { // Allows manipulation of sample volume. // Valid values range from 0 to 63 // e.g. lua code, @@ -1231,14 +1239,14 @@ int apiSoundSetVolume(lua_State *L) { // // --rdg - int n = lua_gettop(L); - int thisValue = 0; - double d = 0; - bool result = false; + int32_t n = lua_gettop(L); + int32_t thisValue = 0; + double d = 0; + bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); thisValue = (int)d; + d = lua_tonumber(L, 1); thisValue = (int32_t)d; if (thisValue >= 0 && thisValue <= AUDIO_MAX_VOLUME) { _effectsVolume = thisValue; Mix_Volume(-1, _effectsVolume * 2); @@ -1259,7 +1267,7 @@ int apiSoundSetVolume(lua_State *L) { } -int apiSoundGetVolume(lua_State *L) { +int32_t apiSoundGetVolume(lua_State *L) { // Returns the current sample volume value. // e.g. lua code, // @@ -1276,7 +1284,7 @@ int apiSoundGetVolume(lua_State *L) { } -int apiSoundFullStop(lua_State *L) { +int32_t apiSoundFullStop(lua_State *L) { // Clears the audio queue of any samples actively playing. // No parameters needed. Function returns nothing. // e.g. lua code, @@ -1292,9 +1300,9 @@ int apiSoundFullStop(lua_State *L) { } -int apiSpriteDraw(lua_State *L) { - int n = lua_gettop(L); - int id = -1; +int32_t apiSpriteDraw(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t id = -1; double d = 0; SpriteT *sprite = NULL; SDL_Rect dest; @@ -1303,9 +1311,9 @@ int apiSpriteDraw(lua_State *L) { if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 2)) { if (lua_isnumber(L, 3)) { - d = lua_tonumber(L, 1); dest.x = (int)d; - d = lua_tonumber(L, 2); dest.y = (int)d; - d = lua_tonumber(L, 3); id = (int)d; + 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); if (!sprite) luaDie(L, "spriteDraw", "No sprite at index %d in apiSpriteGetWidth.", id); dest.w = sprite->surface->w; @@ -1326,16 +1334,16 @@ int apiSpriteDraw(lua_State *L) { } -int apiSpriteGetHeight(lua_State *L) { - int n = lua_gettop(L); - int result = -1; - int id = -1; +int32_t apiSpriteGetHeight(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; + int32_t id = -1; double d; SpriteT *sprite = NULL; if (n == 1) { if (lua_isstring(L, 1)) { - d = lua_tonumber(L, 1); id = (int)d; + d = lua_tonumber(L, 1); id = (int32_t)d; // Get our sprite structure HASH_FIND_INT(_spriteList, &id, sprite); if (!sprite) luaDie(L, "spriteGetHeight", "No sprite at index %d in apiSpriteGetWidth.", id); @@ -1354,10 +1362,10 @@ int apiSpriteGetHeight(lua_State *L) { } -int apiSpriteGetWidth(lua_State *L) { - int n = lua_gettop(L); - int result = -1; - int id = -1; +int32_t apiSpriteGetWidth(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; + int32_t id = -1; double d; SpriteT *sprite = NULL; @@ -1367,7 +1375,7 @@ int apiSpriteGetWidth(lua_State *L) { if (n == 1) { if (lua_isstring(L, 1)) { - d = lua_tonumber(L, 1); id = (int)d; + d = lua_tonumber(L, 1); id = (int32_t)d; // Get our sprite structure HASH_FIND_INT(_spriteList, &id, sprite); if (!sprite) luaDie(L, "spriteGetWidth", "No sprite at index %d in apiSpriteGetWidth.", id); @@ -1386,9 +1394,9 @@ int apiSpriteGetWidth(lua_State *L) { } -int apiSpriteLoad(lua_State *L) { - int n = lua_gettop(L); - int result = -1; +int32_t apiSpriteLoad(lua_State *L) { + int32_t n = lua_gettop(L); + int32_t result = -1; const char *name = NULL; SpriteT *sprite = NULL; @@ -1417,16 +1425,17 @@ int apiSpriteLoad(lua_State *L) { } -int apiVldpGetHeight(lua_State *L) { - int height = videoGetHeight(_videoHandle); +int32_t apiVldpGetHeight(lua_State *L) { + int32_t height = 0; + if (_videoHandle >= 0) height = videoGetHeight(_videoHandle); luaTrace(L, "vldpGetHeight", "%d", height); lua_pushinteger(L, height); return 1; } -int apiVldpGetPixel(lua_State *L) { - int n = lua_gettop(L); +int32_t apiVldpGetPixel(lua_State *L) { + int32_t n = lua_gettop(L); double d = 0; bool result = false; byte pixel[SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_BGRA32)]; @@ -1437,8 +1446,8 @@ int apiVldpGetPixel(lua_State *L) { if (lua_isnumber(L, 2)) { rect.h = 1; rect.w = 1; - d = lua_tonumber(L, 1); rect.x = (int)(d / _overlayScaleX); - d = lua_tonumber(L, 2); rect.y = (int)(d / _overlayScaleY); + 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()); @@ -1449,9 +1458,9 @@ int apiVldpGetPixel(lua_State *L) { if (result) { luaTrace(L, "vldpGetPixel", "%d %d %d %d %d", rect.x, rect.y, pixel[2], pixel[1], pixel[0]); - lua_pushinteger(L, (int)pixel[2]); // R - lua_pushinteger(L, (int)pixel[1]); // G - lua_pushinteger(L, (int)pixel[0]); // B + lua_pushinteger(L, (int32_t)pixel[2]); // R + lua_pushinteger(L, (int32_t)pixel[1]); // G + lua_pushinteger(L, (int32_t)pixel[0]); // B } else { luaTrace(L, "vldpGetPixel", "Failed!"); lua_pushinteger(L, -1); @@ -1463,15 +1472,16 @@ int apiVldpGetPixel(lua_State *L) { } -int apiVldpGetWidth(lua_State *L) { - int width = videoGetWidth(_videoHandle); +int32_t apiVldpGetWidth(lua_State *L) { + int32_t width = 0; + if (_videoHandle >= 0) width = videoGetWidth(_videoHandle); luaTrace(L, "vldpGetHeight", "%d", width); lua_pushinteger(L, width); return 1; } -int apiVldpVerbose(lua_State *L) { +int32_t apiVldpVerbose(lua_State *L) { /* * Enables/Disables writing of VLDP playback activity to daphne_log.txt * Enabled by default. @@ -1485,16 +1495,14 @@ int apiVldpVerbose(lua_State *L) { } -int apiKeyboardGetMode(lua_State *L) { +int32_t apiKeyboardGetMode(lua_State *L) { luaTrace(L, "keyboardGetMode", "%d", _keyboardMode); lua_pushinteger(L, _keyboardMode); return 1; } -int apiKeyboardSetMode(lua_State *L) { - - bool result = false; +int32_t apiKeyboardSetMode(lua_State *L) { /* * Singe can scan keyboard input in two ways: @@ -1506,12 +1514,13 @@ int apiKeyboardSetMode(lua_State *L) { * */ - int n = lua_gettop(L); - double d = 0; + int32_t n = lua_gettop(L); + double d = 0; + bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); _keyboardMode = (int)d; + d = lua_tonumber(L, 1); _keyboardMode = (int32_t)d; result = true; } } @@ -1526,7 +1535,7 @@ int apiKeyboardSetMode(lua_State *L) { } -int apiMouseEnable(lua_State *L) { +int32_t apiMouseEnable(lua_State *L) { // Enables mouse monitoring (void)L; luaTrace(L, "mouseEnable", "%d", _confNoMouse); @@ -1535,7 +1544,7 @@ int apiMouseEnable(lua_State *L) { } -int apiMouseDisable(lua_State *L) { +int32_t apiMouseDisable(lua_State *L) { // Disables mouse monitoring (void)L; luaTrace(L, "mouseDisable", ""); @@ -1544,7 +1553,7 @@ int apiMouseDisable(lua_State *L) { } -int apiMouseSetMode(lua_State *L) { +int32_t apiMouseSetMode(lua_State *L) { // Sets the scanning mode for mouse input. // Can be one of two values: // @@ -1562,13 +1571,13 @@ int apiMouseSetMode(lua_State *L) { // // --rdg - int n = lua_gettop(L); - double d = 0; - bool result = false; + int32_t n = lua_gettop(L); + double d = 0; + bool result = false; if (n == 1) { if (lua_isnumber(L, 1)) { - d = lua_tonumber(L, 1); _mouseMode = (int)d; + d = lua_tonumber(L, 1); _mouseMode = (int32_t)d; result = true; } } @@ -1584,15 +1593,15 @@ int apiMouseSetMode(lua_State *L) { } -int apiMouseHowMany(lua_State *L) { +int32_t apiMouseHowMany(lua_State *L) { luaTrace(L, "mouseHowMany", "%d", _mouseCount); lua_pushinteger(L, _mouseCount); return 1; } -int apiDiscGetState(lua_State *L) { - int isPlaying = -1; +int32_t apiDiscGetState(lua_State *L) { + int32_t isPlaying = -1; /* * Returns the status of the vldp @@ -1608,14 +1617,14 @@ int apiDiscGetState(lua_State *L) { */ // Our player isn't as sophisticated as the one in Daphne - isPlaying = videoIsPlaying(_videoHandle); + 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)); return 1; } -int apiSingeGetPauseFlag(lua_State *L) { +int32_t apiSingeGetPauseFlag(lua_State *L) { /* * This function returns g_pause_state's value to the lua script. * @@ -1634,9 +1643,9 @@ int apiSingeGetPauseFlag(lua_State *L) { } -int apiSingeSetPauseFlag(lua_State *L) { - int n = lua_gettop(L); - bool result = false; +int32_t apiSingeSetPauseFlag(lua_State *L) { + int32_t n = lua_gettop(L); + bool result = false; if (n == 1) { if (lua_isboolean(L, 1)) { @@ -1655,7 +1664,7 @@ int apiSingeSetPauseFlag(lua_State *L) { } -int apiSingeEnablePauseKey(lua_State *L) { +int32_t apiSingeEnablePauseKey(lua_State *L) { (void)L; luaTrace(L, "singeEnablePauseKey", ""); _pauseEnabled = true; @@ -1663,7 +1672,7 @@ int apiSingeEnablePauseKey(lua_State *L) { } -int apiSingeDisablePauseKey(lua_State *L) { +int32_t apiSingeDisablePauseKey(lua_State *L) { (void)L; luaTrace(L, "singeDisablePauseKey", ""); _pauseEnabled = false; @@ -1671,7 +1680,7 @@ int apiSingeDisablePauseKey(lua_State *L) { } -int apiSingeQuit(lua_State *L) { +int32_t apiSingeQuit(lua_State *L) { (void)L; luaTrace(L, "singeQuit", ""); _running = false; @@ -1679,14 +1688,14 @@ int apiSingeQuit(lua_State *L) { } -int apiSingeVersion(lua_State *L) { +int32_t apiSingeVersion(lua_State *L) { luaTrace(L, "singeVersion", "%f", SINGE_VERSION); lua_pushnumber(L, SINGE_VERSION); return 1; } -int apiSingeSetGameName(lua_State *L) { +int32_t apiSingeSetGameName(lua_State *L) { // Adds the name of the singe game to the window's title bar. // Valid value is a string no longer than 25 characters. // e.g. lua code, @@ -1697,13 +1706,13 @@ int apiSingeSetGameName(lua_State *L) { // // --rdg - int n = lua_gettop(L); - bool result = false; - char thisName[MAX_TITLE_LENGTH]; + int32_t n = lua_gettop(L); + bool result = false; + char thisName[MAX_TITLE_LENGTH]; if (n == 1) { if (lua_isstring(L, 1)) { - sprintf(thisName,"%.40s", lua_tostring(L, 1)); // Need a better way to do this... + sprintf(thisName,"%.40s", lua_tostring(L, 1)); // Need a better way to do this...? SDL_SetWindowTitle(_window, thisName); result = true; } @@ -1720,7 +1729,7 @@ int apiSingeSetGameName(lua_State *L) { } -int apiSingeGetScriptPath(lua_State *L) { +int32_t apiSingeGetScriptPath(lua_State *L) { // Returns the path to the singe script. // e.g. lua code, // @@ -1734,13 +1743,13 @@ int apiSingeGetScriptPath(lua_State *L) { void callLua(const char *func, const char *sig, ...) { - va_list vl; - bool done = false; - int narg; - int nres; - int popCount; - double d; - const int top = lua_gettop(_luaContext); + va_list vl; + bool done = false; + int32_t narg; + int32_t nres; + int32_t popCount; + double d; + const int32_t top = lua_gettop(_luaContext); va_start(vl, sig); @@ -1764,7 +1773,7 @@ void callLua(const char *func, const char *sig, ...) { break; case 'i': // Int - lua_pushinteger(_luaContext, va_arg(vl, int)); + lua_pushinteger(_luaContext, va_arg(vl, int)); // Not sure I want to change this to int32_t break; case 's': // String @@ -1785,7 +1794,7 @@ void callLua(const char *func, const char *sig, ...) { } // Do the call - popCount = nres = (int)strlen(sig); // Number of expected results + 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)); } @@ -1806,7 +1815,7 @@ void callLua(const char *func, const char *sig, ...) { if (!lua_isnumber(_luaContext, nres)) { utilDie("Wrong result type"); } - d = lua_tonumber(_luaContext, nres); *va_arg(vl, int *) = (int)d; + d = lua_tonumber(_luaContext, nres); *va_arg(vl, int *) = (int32_t)d; // Not sure I want to change this to int32_t break; case 's': // String @@ -1854,9 +1863,9 @@ void luaDie(lua_State *L, char *method, char *fmt, ...) { } -int luaError(lua_State *L) { +int32_t luaError(lua_State *L) { lua_Debug ar; - int level = 0; + int32_t level = 0; utilSay("Singe has panicked! Very bad!"); utilSay("Error: %s", lua_tostring(L, -1)); @@ -1896,8 +1905,8 @@ void luaTrace(lua_State *L, char *method, char *fmt, ...) { } -void processKey(bool down, int keysym) { - int move; +void processKey(bool down, int32_t keysym) { + int32_t move; if (_keyboardMode == KEYBD_NORMAL) { // Daphne keys @@ -1963,13 +1972,13 @@ void processKey(bool down, int keysym) { void singe(SDL_Window *window, SDL_Renderer *renderer) { - int x = 0; - int y = 0; - int xr = 0; - int yr = 0; - int thisFrame = -1; - int lastFrame = -1; - int intReturn = 0; + int32_t x = 0; + int32_t y = 0; + int32_t xr = 0; + int32_t yr = 0; + int32_t intReturn = 0; + int64_t thisFrame = -1; + int64_t lastFrame = -1; SDL_Texture *overlayTexture = NULL; SpriteT *sprite = NULL; SpriteT *spriteTemp = NULL; @@ -1980,7 +1989,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { SDL_Event event; ManyMouseEvent mouseEvent; MouseT *mouse = NULL; - int mouseButtonMap[] = { + int32_t mouseButtonMap[] = { SWITCH_BUTTON1, // Left SWITCH_BUTTON3, // Middle SWITCH_BUTTON2, // Right @@ -2090,8 +2099,8 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { // Create overlay surface _overlayScaleX = 0.5; _overlayScaleY = 0.5; - x = (int)(videoGetWidth(_videoHandle) * _overlayScaleX); - y = (int)(videoGetHeight(_videoHandle) * _overlayScaleY); + 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); @@ -2107,14 +2116,14 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { 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 = (int)(videoGetWidth(_videoHandle) * _overlayScaleX); - _mice[x].y = (int)(videoGetHeight(_videoHandle) * _overlayScaleY); + _mice[x].x = (int32_t)(videoGetWidth(_videoHandle) * _overlayScaleX); + _mice[x].y = (int32_t)(videoGetHeight(_videoHandle) * _overlayScaleY); } SDL_SetWindowGrab(_window, SDL_TRUE); SDL_ShowCursor(SDL_DISABLE); // Set volume - _effectsVolume = (int)((float)AUDIO_MAX_VOLUME * (float)_confVolumeNonVldp * (float)0.01); + _effectsVolume = (int32_t)((float)AUDIO_MAX_VOLUME * (float)_confVolumeNonVldp * (float)0.01); Mix_Volume(-1, _effectsVolume * 2); // Let us know when sounds end @@ -2151,10 +2160,10 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { case SDL_MOUSEMOTION: if ((_mouseEnabled) && (_mouseMode == MOUSE_SINGLE)) { - x = (int)(event.motion.x * _overlayScaleX); - y = (int)(event.motion.y * _overlayScaleY); - xr = (int)(event.motion.xrel * _overlayScaleX); - yr = (int)(event.motion.yrel * _overlayScaleY); + 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); callLua("onMouseMoved", "iiiii", x, y, xr, yr, NOMOUSE); } break; @@ -2210,10 +2219,10 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { if (mouse->relx >= x) mouse->relx = x - 1; if (mouse->rely < 0) mouse->rely = 0; if (mouse->rely >= y) mouse->rely = y - 1; - x = (int)(mouse->x * _overlayScaleX); - y = (int)(mouse->y * _overlayScaleY); - xr = (int)(mouse->relx * _overlayScaleX); - yr = (int)(mouse->relx * _overlayScaleY); + x = (int32_t)(mouse->x * _overlayScaleX); + y = (int32_t)(mouse->y * _overlayScaleY); + xr = (int32_t)(mouse->relx * _overlayScaleX); + yr = (int32_t)(mouse->relx * _overlayScaleY); callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device); break; @@ -2227,10 +2236,10 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { mouse->y += mouseEvent.value; break; } - x = (int)(mouse->x * _overlayScaleX); - y = (int)(mouse->y * _overlayScaleY); - xr = (int)(mouse->relx * _overlayScaleX); - yr = (int)(mouse->relx * _overlayScaleY); + x = (int32_t)(mouse->x * _overlayScaleX); + y = (int32_t)(mouse->y * _overlayScaleY); + xr = (int32_t)(mouse->relx * _overlayScaleX); + yr = (int32_t)(mouse->relx * _overlayScaleY); utilSay("Mouse %d: Absolute %d, %d", mouseEvent.device, x, y); callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device); break; @@ -2296,11 +2305,12 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { if (_refreshDisplay || _discStopped) { if (_discStopped) { // Stopped discs display blue like the good old days + SDL_SetRenderTarget(renderer, _videoTexture); SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); SDL_RenderClear(renderer); - } else { - SDL_RenderCopy(_renderer, _videoTexture, NULL, NULL); + SDL_SetRenderTarget(renderer, NULL); } + SDL_RenderCopy(_renderer, _videoTexture, NULL, NULL); overlayTexture = SDL_CreateTextureFromSurface(_renderer, _overlay); if (!overlayTexture) utilDie("%s", SDL_GetError()); if (!_confStretchVideo) { diff --git a/singe/singe.h b/singe/singe.h index 14a0dfd61..4a138838b 100644 --- a/singe/singe.h +++ b/singe/singe.h @@ -31,26 +31,27 @@ // Don't forget to update singe.rc! #define SINGE_VERSION 2.00 -#define VERSION_STRING "v2.00b5" +#define VERSION_STRING "v2.00b6" #define COPYRIGHT_END_YEAR "2020" // Command line options -extern char *_confVideoFile; -extern char *_confScriptFile; -extern char *_confDataDir; -extern bool _confIsFrameFile; -extern bool _confStretchVideo; -extern bool _confNoMouse; -extern bool _confNoStats; -extern bool _confNoSound; -extern bool _confFullScreen; -extern bool _confFullScreenWindow; -extern int _confVolumeVldp; -extern int _confVolumeNonVldp; -extern int _confScaleFactor; -extern int _confXResolution; -extern int _confYResolution; +extern char *_confVideoFile; +extern char *_confScriptFile; +extern char *_confDataDir; +extern bool _confIsFrameFile; +extern bool _confStretchVideo; +extern bool _confNoMouse; +extern bool _confNoStats; +extern bool _confNoSound; +extern bool _confFullScreen; +extern bool _confFullScreenWindow; +extern bool _confShowCalculated; +extern int32_t _confVolumeVldp; +extern int32_t _confVolumeNonVldp; +extern int32_t _confScaleFactor; +extern int32_t _confXResolution; +extern int32_t _confYResolution; void singe(SDL_Window *window, SDL_Renderer *renderer); diff --git a/singe/singe.rc b/singe/singe.rc index 87f38ee7d..93d17e83a 100644 --- a/singe/singe.rc +++ b/singe/singe.rc @@ -1,7 +1,7 @@ 101 ICON "/tmp/icon.ico" 1 VERSIONINFO -FILEVERSION 2,0,0,0 -PRODUCTVERSION 2,0,0,0 +FILEVERSION 2,0,0,6 +PRODUCTVERSION 2,0,0,6 BEGIN BLOCK "StringFileInfo" BEGIN @@ -9,12 +9,12 @@ BEGIN BEGIN VALUE "CompanyName", "Kangaroo Punch Studios" VALUE "FileDescription", "Somewhat Interactive Nostalgic Game Emulator" - VALUE "FileVersion", "2.0b5" + VALUE "FileVersion", "2.00b6" VALUE "InternalName", "Singe" VALUE "LegalCopyright", "Copyright 2006-2020 Scott C. Duensing" VALUE "OriginalFilename", "singe.exe" VALUE "ProductName", "Singe" - VALUE "ProductVersion", "2.0b5" + VALUE "ProductVersion", "2.00b6" END END BLOCK "VarFileInfo" diff --git a/singe/util.c b/singe/util.c index aa5ba61e0..a69491e24 100644 --- a/singe/util.c +++ b/singe/util.c @@ -55,7 +55,7 @@ char *utilCreateString(char *format, ...) { __attribute__((__format__(__printf__, 1, 0))) char *utilCreateStringVArgs(char *format, va_list args) { va_list argsCopy; - int size = 0; + int32_t size = 0; char *buffer = NULL; va_copy(argsCopy, args); @@ -98,8 +98,8 @@ bool utilFileExists(char *filename) { void utilFixPathSeparators(char **path) { - int i = 0; - char *temp = *path; + int32_t i = 0; + char *temp = *path; // Flip path separators to whatever our OS wants while (temp[i] != 0) { @@ -113,19 +113,19 @@ void utilFixPathSeparators(char **path) { if (temp[strlen(temp) - 1] != utilGetPathSeparator()) { // No - append one. temp = realloc(temp, sizeof(char) * (strlen(temp) + 1)); - temp[strlen(temp) - 1] = utilGetPathSeparator(); - temp[strlen(temp)] = 0; + temp[strlen(temp)] = utilGetPathSeparator(); + temp[strlen(temp) + 1] = 0; *path = temp; } } char *utilGetFileExtension(char *filename) { - char *start = filename + strlen(filename); - int x; + char *start = filename + strlen(filename); + int32_t x; // Scan through name and find the last '.' - for (x=0; x<(int)strlen(filename); x++) { + for (x=0; x<(int32_t)strlen(filename); x++) { if (filename[x] == '.') { start = &filename[x + 1]; } @@ -140,11 +140,11 @@ char *utilGetFileExtension(char *filename) { char *utilGetLastPathComponent(char *pathname) { - char *start = pathname; - int x; + char *start = pathname; + int32_t x; // Scan through name and find the last path separator - for (x=0; x<(int)strlen(pathname); x++) { + for (x=0; x<(int32_t)strlen(pathname); x++) { if (pathname[x] == utilGetPathSeparator()) { start = &pathname[x + 1]; } @@ -245,7 +245,7 @@ char *utilReadLine(char *haystack, size_t length, char **offset) { void utilRedirectConsole(void) { #ifdef _WIN32 // http://dslweb.nwnexus.com/~ast/dload/guicon.htm - int hConHandle; + int hConHandle; // Not changing this int. intptr_t lStdHandle; CONSOLE_SCREEN_BUFFER_INFO coninfo; FILE *fp; diff --git a/singe/videoPlayer.c b/singe/videoPlayer.c index e2fef1c34..88d6ffb0e 100644 --- a/singe/videoPlayer.c +++ b/singe/videoPlayer.c @@ -37,21 +37,21 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpadded" typedef struct VideoPlayerS { - int id; + int32_t id; bool playing; bool resetTime; byte *audioBuffer; byte audioSampleBytes; byte *audioSilenceRaw; char errMsg[1024]; - int volumeLeft; - int volumeRight; - int audioTrack; - int videoTrack; - int frame; - int audioSampleSize; - int mixSampleSize; - int audioSilenceChannel; + int32_t volumeLeft; + int32_t volumeRight; + int32_t audioTrack; + int32_t videoTrack; + int32_t audioSampleSize; + int32_t mixSampleSize; + int32_t audioSilenceChannel; + int64_t frame; int64_t audioBufferSize; int64_t frameDeltaTime; int64_t lastFrameTime; @@ -78,25 +78,25 @@ typedef struct VideoPlayerS { FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool hasAudio, VideoPlayerT *v); -void _dequeueVideoAudio(int channel, void *stream, int len, void *udata); -int FFMS_CC _indexCallBack(int64_t Current, int64_t Total, void *ICPrivate); -int _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); +void _dequeueVideoAudio(int channel, void *stream, int len, void *udata); // Callback. Not changing ints. +int FFMS_CC _indexCallBack(int64_t Current, int64_t Total, void *ICPrivate); // Callback. Not changing int. +int32_t _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); static VideoPlayerT *_videoPlayerHash = NULL; -static int _nextId = 0; -static int _mixRate = -1; +static int32_t _nextId = 0; +static int32_t _mixRate = -1; static Uint8 _mixChannels = 0; static SDL_AudioFormat _mixFormat = 0; -void _dequeueVideoAudio(int channel, void *stream, int bytes, void *udata) { +void _dequeueVideoAudio(int channel, void *stream, int bytes, void *udata) { // Callback. Not changing ints. VideoPlayerT *v = (VideoPlayerT *)udata; - int bytesToCopy = bytes; - int available = SDL_AudioStreamAvailable(v->audioStream); - int remainder = 0; - int bytesRead = 0; - int i = 0; + int32_t bytesToCopy = bytes; + int32_t available = SDL_AudioStreamAvailable(v->audioStream); + int32_t remainder = 0; + int32_t bytesRead = 0; + int32_t i = 0; Sint16 *data = stream; (void)channel; @@ -117,7 +117,7 @@ void _dequeueVideoAudio(int channel, void *stream, int bytes, void *udata) { // We do our own volume per channel here in the mixer if (_mixChannels < 2) { // Mono output, average volume levels together - Mix_Volume(channel, (int)((float)MIX_MAX_VOLUME * ((float)v->volumeLeft * (float)v->volumeRight / (float)2) * (float)0.01)); + Mix_Volume(channel, (int32_t)((float)MIX_MAX_VOLUME * ((float)v->volumeLeft * (float)v->volumeRight / (float)2) * (float)0.01)); } else { // Stereo output. Assumes MIX_DEFAULT_FORMAT for now. Mix_Volume(channel, MIX_MAX_VOLUME); @@ -129,16 +129,16 @@ void _dequeueVideoAudio(int channel, void *stream, int bytes, void *udata) { } -int FFMS_CC _indexCallBack(int64_t current, int64_t total, void *ICPrivate) { - static int lastPercent = 0; - int thisPercent = 0; +int FFMS_CC _indexCallBack(int64_t current, int64_t total, void *ICPrivate) { // Callback. Not changing int. + static int32_t lastPercent = 0; + int32_t thisPercent = 0; (void)ICPrivate; // Contains current VideoPlayerT if ((current == 0) && (total == 0)) { lastPercent = 0; // Reset } else { - thisPercent = (int)((double)current / (double)total * 100.0); + thisPercent = (int32_t)((double)current / (double)total * 100.0); if (thisPercent != lastPercent) { lastPercent = thisPercent; utilSay("Indexing: %d%%", thisPercent); @@ -149,6 +149,7 @@ int FFMS_CC _indexCallBack(int64_t current, int64_t total, void *ICPrivate) { return 0; } + FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool hasAudio, VideoPlayerT *v) { char indexName[1024]; FFMS_Index *index = NULL; @@ -161,11 +162,6 @@ FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool ha if (FFMS_IndexBelongsToFile(index, filename, &v->errInfo)) { FFMS_DestroyIndex(index); index = NULL; - /* - utilSay("Cached index is invalid."); - } else { - utilSay("Loaded cached index."); - */ } } if (!index) { @@ -185,9 +181,9 @@ FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool ha } -int _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { - int pixelFormats[2]; - int result = -1; +int32_t _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { + int32_t pixelFormats[2]; + int32_t result = -1; FFMS_Index *vIndex = NULL; FFMS_Index *aIndex = NULL; VideoPlayerT *v = NULL; @@ -333,9 +329,9 @@ int _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bool s } -int videoInit(void) { +int32_t videoInit(void) { - int channels = _mixChannels; + int32_t channels = _mixChannels; // Start FFMS FFMS_Init(0, 0); @@ -351,68 +347,68 @@ int videoInit(void) { } -int videoIsPlaying(int playerIndex) { +int32_t videoIsPlaying(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoIsPlaying.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoIsPlaying.", playerHandle); return v->playing; } -int videoGetFrame(int playerIndex) { +int64_t videoGetFrame(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoGetFrame.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoGetFrame.", playerHandle); return v->frame; } -int videoGetFrameCount(int playerIndex) { +int64_t videoGetFrameCount(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoGetFrameCount.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoGetFrameCount.", playerHandle); return v->videoProps->NumFrames; } -int videoGetHeight(int playerIndex) { +int32_t videoGetHeight(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoGetHeight.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoGetHeight.", playerHandle); return v->propFrame->EncodedHeight; } -int videoGetWidth(int playerIndex) { +int32_t videoGetWidth(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoGetWidth.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoGetWidth.", playerHandle); return v->propFrame->EncodedWidth; } -int videoGetVolume(int playerIndex, int *leftPercent, int *rightPercent) { +int32_t videoGetVolume(int32_t playerHandle, int32_t *leftPercent, int32_t *rightPercent) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoGetVolume.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoGetVolume.", playerHandle); if (leftPercent != NULL) *leftPercent = v->volumeLeft; if (rightPercent != NULL) *rightPercent = v->volumeRight; @@ -421,22 +417,22 @@ int videoGetVolume(int playerIndex, int *leftPercent, int *rightPercent) { } -int videoLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { +int32_t videoLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { return _loadVideoAndAudio(filename, NULL, indexPath, stretchVideo, renderer); } -int videoLoadWithAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { +int32_t videoLoadWithAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) { return _loadVideoAndAudio(vFilename, aFilename, indexPath, stretchVideo, renderer); } -int videoPause(int playerIndex) { +int32_t videoPause(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoPause.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoPause.", playerHandle); v->playing = false; v->resetTime = true; @@ -445,12 +441,12 @@ int videoPause(int playerIndex) { } -int videoPlay(int playerIndex) { +int32_t videoPlay(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoPlay.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoPlay.", playerHandle); v->playing = true; v->resetTime = true; @@ -459,7 +455,7 @@ int videoPlay(int playerIndex) { } -int videoQuit(void) { +int32_t videoQuit(void) { VideoPlayerT *v = NULL; VideoPlayerT *t = NULL; @@ -475,12 +471,12 @@ int videoQuit(void) { } -int videoSeek(int playerIndex, int seekFrame) { +int32_t videoSeek(int32_t playerHandle, int64_t seekFrame) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoSeek.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoSeek.", playerHandle); while (seekFrame >= v->videoProps->NumFrames) { seekFrame -= v->videoProps->NumFrames; @@ -496,12 +492,12 @@ int videoSeek(int playerIndex, int seekFrame) { } -int videoSetVolume(int playerIndex, int leftPercent, int rightPercent) { +int32_t videoSetVolume(int32_t playerHandle, int32_t leftPercent, int32_t rightPercent) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoSetVolume.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoSetVolume.", playerHandle); v->volumeLeft = leftPercent; v->volumeRight = rightPercent; @@ -510,12 +506,12 @@ int videoSetVolume(int playerIndex, int leftPercent, int rightPercent) { } -int videoUnload(int playerIndex) { +int32_t videoUnload(int32_t playerHandle) { VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoStop.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoStop.", playerHandle); Mix_HaltChannel(v->audioSilenceChannel); Mix_UnregisterEffect(v->audioSilenceChannel, _dequeueVideoAudio); @@ -539,14 +535,14 @@ int videoUnload(int playerIndex) { } -int videoUpdate(int playerIndex, SDL_Texture **texture) { - int result = -1; +int32_t videoUpdate(int32_t playerHandle, SDL_Texture **texture) { + int32_t result = -1; int64_t count = 0; VideoPlayerT *v = NULL; // Get our player structure - HASH_FIND_INT(_videoPlayerHash, &playerIndex, v); - if (!v) utilDie("No video player at index %d in videoUpdate.", playerIndex); + HASH_FIND_INT(_videoPlayerHash, &playerHandle, v); + if (!v) utilDie("No video player at index %d in videoUpdate.", playerHandle); // Handle video frames (and time) if ((SDL_GetTicks() - v->lastTickTime >= v->frameDeltaTime) || v->resetTime) { @@ -596,7 +592,7 @@ int videoUpdate(int playerIndex, SDL_Texture **texture) { // Get audio from video stream if (FFMS_GetAudio(v->audioSource, v->audioBuffer, v->audioPosition, count, &v->errInfo)) utilDie("%s", v->errInfo.Buffer); // Feed it to the mixer stream - if (SDL_AudioStreamPut(v->audioStream, v->audioBuffer, (int)(count * v->audioSampleSize)) < 0) utilDie("%s", SDL_GetError()); + if (SDL_AudioStreamPut(v->audioStream, v->audioBuffer, (int32_t)(count * v->audioSampleSize)) < 0) utilDie("%s", SDL_GetError()); v->audioPosition += count; } } diff --git a/singe/videoPlayer.h b/singe/videoPlayer.h index 0b2cace74..fb3e5b58f 100644 --- a/singe/videoPlayer.h +++ b/singe/videoPlayer.h @@ -29,22 +29,22 @@ #include "common.h" -int videoInit(void); -int videoIsPlaying(int playerIndex); -int videoGetFrame(int playerIndex); -int videoGetFrameCount(int playerIndex); -int videoGetHeight(int playerIndex); -int videoGetWidth(int playerIndex); -int videoGetVolume(int playerIndex, int *leftPercent, int *rightPercent); -int videoLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); -int videoLoadWithAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); -int videoPause(int playerIndex); -int videoPlay(int playerIndex); -int videoQuit(void); -int videoSeek(int playerIndex, int seekFrame); -int videoSetVolume(int playerIndex, int leftPercent, int rightPercent); -int videoUnload(int playerIndex); -int videoUpdate(int playerIndex, SDL_Texture **texture); +int32_t videoInit(void); +int32_t videoIsPlaying(int32_t playerHandle); +int64_t videoGetFrame(int32_t playerHandle); +int64_t videoGetFrameCount(int32_t playerHandle); +int32_t videoGetHeight(int32_t playerHandle); +int32_t videoGetWidth(int32_t playerHandle); +int32_t videoGetVolume(int32_t playerHandle, int32_t *leftPercent, int32_t *rightPercent); +int32_t videoLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); +int32_t videoLoadWithAudio(char *vFilename, char *aFilename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer); +int32_t videoPause(int32_t playerHandle); +int32_t videoPlay(int32_t playerHandle); +int32_t videoQuit(void); +int32_t videoSeek(int32_t playerHandle, int64_t seekFrame); +int32_t videoSetVolume(int32_t playerHandle, int32_t leftPercent, int32_t rightPercent); +int32_t videoUnload(int32_t playerHandle); +int32_t videoUpdate(int32_t playerHandle, SDL_Texture **texture); #endif // VIDEOPLAYER_H