From b03a96f3b6e267f46cd3fcd1020017d32d7a77fb Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 6 Jan 2020 18:04:17 -0600 Subject: [PATCH] Fixed framefile reading bug, sound stopping when out of channels, added Windows icon and resources. --- .gitignore | 1 + singe/buildRelease.sh | 8 +++++++- singe/frameFile.c | 2 +- singe/icon.png | 3 +++ singe/main.c | 10 +++++++++- singe/preBuild.sh | 3 +++ singe/singe.c | 6 ++++-- singe/singe.h | 3 ++- singe/singe.pro | 4 +++- singe/singe.rc | 24 ++++++++++++++++++++++++ singe/util.c | 2 +- 11 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 singe/icon.png create mode 100644 singe/singe.rc diff --git a/.gitignore b/.gitignore index 9be321e7e..8411a0c93 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ games/ build/ singe/source.inc.sh singe/font.h +singe/icon.h diff --git a/singe/buildRelease.sh b/singe/buildRelease.sh index 7666509a1..9b1305c6c 100755 --- a/singe/buildRelease.sh +++ b/singe/buildRelease.sh @@ -56,7 +56,7 @@ function doBuild() { TARGET="${SOURCE_DIR}/../build/${OSNAME}/${OSARCH}/${TARGET}${EXT}" echo "Linking ${TARGET}..." - ${CROSS}-g++ -o "${TARGET}" ${OFILES} "-L${SOURCE_DIR}/../thirdparty-build/${OSNAME}/${OSARCH}/installed/lib" ${EXTRA_LD_FLAGS} + ${CROSS}-g++ -o "${TARGET}" ${OFILES} ${EXTRA_OFILES} "-L${SOURCE_DIR}/../thirdparty-build/${OSNAME}/${OSARCH}/installed/lib" ${EXTRA_LD_FLAGS} echo "Compressing ${TARGET}..." #${CROSS}-strip "${TARGET}" @@ -68,10 +68,16 @@ function doBuild() { CROSS="x86_64-linux-gnu" EXTRA_CFLAGS="" +EXTRA_OFILES="" EXTRA_LD_FLAGS="-l:everything.a -lpthread -lXv -lX11 -lXext -lm -ldl -lrt" doBuild Singe-Linux-x86_64 linux 64 CROSS="x86_64-w64-mingw32" EXTRA_CFLAGS="" +EXTRA_OFILES="/tmp/singe.res" EXTRA_LD_FLAGS="-mwindows -static -lmingw32 -l:everything.a -lm -lbcrypt -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid -Dmain=SDL_main" +icotool -c -o /tmp/icon.ico icon.png +x86_64-w64-mingw32-windres singe.rc -O coff -o /tmp/singe.res doBuild Singe-Windows-x86_64 mingw 64 .exe +rm /tmp/icon.ico +rm /tmp/singe.res diff --git a/singe/frameFile.c b/singe/frameFile.c index 88db5318b..f4f475adc 100644 --- a/singe/frameFile.c +++ b/singe/frameFile.c @@ -124,7 +124,7 @@ int frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Render utilFixPathSeparators(&path); // If it's not an absolute path, pre-pend the path to the framefile - if (path[0] != utilGetPathSeparator()) { + if ((path[0] != utilGetPathSeparator()) && (path[1] != ':')) { temp = path; count = strlen(filename) - strlen(utilGetLastPathComponent(filename)); path = malloc(sizeof(char) * (count + strlen(temp) + 1)); diff --git a/singe/icon.png b/singe/icon.png new file mode 100644 index 000000000..568aec5b3 --- /dev/null +++ b/singe/icon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13034fd263b97f9e51c77a00cd5791606005a97e32998307f6de966d34bc41eb +size 3392 diff --git a/singe/main.c b/singe/main.c index 52f8225c6..8d0dc96cb 100644 --- a/singe/main.c +++ b/singe/main.c @@ -36,6 +36,7 @@ #include "videoPlayer.h" #include "singe.h" #include "extensions.h" +#include "icon.h" typedef struct RatioS { @@ -119,6 +120,7 @@ int main(int argc, char *argv[]) { float bestRatio = 9999; SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; + SDL_Surface *icon = NULL; SDL_DisplayMode mode; static struct option options[] = { { "nomouse", no_argument, NULL, 'm' }, @@ -478,7 +480,12 @@ int main(int argc, char *argv[]) { window = SDL_CreateWindow("SINGE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _confXResolution, _confYResolution, SDL_WINDOW_RESIZABLE); if (window == NULL) utilDie("%s", SDL_GetError()); - //***TODO*** Window Icon + // Window Icon + icon = IMG_LoadPNG_RW(SDL_RWFromMem(icon_png, icon_png_len)); + if (icon == NULL) utilDie("%s", SDL_GetError()); + SDL_SetWindowIcon(window, icon); + SDL_FreeSurface(icon); + icon = NULL; // Do we want full screen of some kind? if (_confFullScreen || _confFullScreenWindow) { @@ -497,6 +504,7 @@ int main(int argc, char *argv[]) { // Create audio mixer device err = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 44100 /* freq */ * 16 /* bits */ * 2 /* channels */ * 2 /* seconds */); if (err != 0) utilDie("%s", Mix_GetError()); + Mix_AllocateChannels(16); // Start our video playback system if (frameFileInit()) utilDie("Unable to initialize framefile handler."); diff --git a/singe/preBuild.sh b/singe/preBuild.sh index 34481ec1f..80bc36f8a 100755 --- a/singe/preBuild.sh +++ b/singe/preBuild.sh @@ -405,3 +405,6 @@ fi # === Overlay Font === createEmbeddedBinary font.png font.h FONT_H + +# === Window Icon === +createEmbeddedBinary icon.png icon.h ICON_H diff --git a/singe/singe.c b/singe/singe.c index fd13d901c..954585b3b 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -1054,9 +1054,11 @@ int apiSoundPlay(lua_State *L) { // Get our sound structure HASH_FIND_INT(_soundList, &id, sound); if (!sound) luaDie(L, "soundPlay", "No sound at index %d in apiSoundPlay.", id); - // Play it + // Play it (can gracefully fail if we run out of channels) result = Mix_PlayChannel(-1, sound->chunk, 0); - Mix_Volume(result, _effectsVolume * 2); + if (result >= 0) { + Mix_Volume(result, _effectsVolume * 2); + } } } diff --git a/singe/singe.h b/singe/singe.h index 066b52704..14a0dfd61 100644 --- a/singe/singe.h +++ b/singe/singe.h @@ -29,8 +29,9 @@ #include "common.h" +// Don't forget to update singe.rc! #define SINGE_VERSION 2.00 -#define VERSION_STRING "v2.00b4" +#define VERSION_STRING "v2.00b5" #define COPYRIGHT_END_YEAR "2020" diff --git a/singe/singe.pro b/singe/singe.pro index e3ad7c12b..61b4ffdae 100644 --- a/singe/singe.pro +++ b/singe/singe.pro @@ -113,7 +113,9 @@ LIBS += \ OTHER_FILES += \ preBuild.sh \ postLink.sh \ - buildRelease.sh + buildRelease.sh \ + singe.rc + #linux:QMAKE_POST_LINK += bash $$PWD/postLink.sh "$$PWD" "$$DESTDIR" "$$TARGET" diff --git a/singe/singe.rc b/singe/singe.rc new file mode 100644 index 000000000..87f38ee7d --- /dev/null +++ b/singe/singe.rc @@ -0,0 +1,24 @@ +101 ICON "/tmp/icon.ico" +1 VERSIONINFO +FILEVERSION 2,0,0,0 +PRODUCTVERSION 2,0,0,0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "CompanyName", "Kangaroo Punch Studios" + VALUE "FileDescription", "Somewhat Interactive Nostalgic Game Emulator" + VALUE "FileVersion", "2.0b5" + VALUE "InternalName", "Singe" + VALUE "LegalCopyright", "Copyright 2006-2020 Scott C. Duensing" + VALUE "OriginalFilename", "singe.exe" + VALUE "ProductName", "Singe" + VALUE "ProductVersion", "2.0b5" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/singe/util.c b/singe/util.c index 5ce966c4a..aa5ba61e0 100644 --- a/singe/util.c +++ b/singe/util.c @@ -232,7 +232,7 @@ char *utilReadLine(char *haystack, size_t length, char **offset) { bytes = tail - temp + 1; result = malloc(sizeof(char) * bytes); memcpy(result, temp, bytes - 1); - result[bytes] = 0; + result[bytes - 1] = 0; temp = tail; *offset = temp; }