From fe607e66820516b904a86d81b478ad64038dc9c2 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 23 Mar 2020 18:20:45 -0500 Subject: [PATCH] Overlay now using blending instead of color key for transparency. Data folder automatically generates subdirectory names for individual games. Beta 12 released. --- singe/Menu.singe | 1 - singe/buildRelease.sh | 4 +-- singe/games.dat | 4 --- singe/main.c | 23 ++++++++--------- singe/singe.c | 59 ++++++++++++++++++++++++------------------- singe/singe.h | 3 ++- singe/singe.rc | 8 +++--- singe/util.c | 21 +++++++++++++-- singe/util.h | 1 + 9 files changed, 71 insertions(+), 53 deletions(-) diff --git a/singe/Menu.singe b/singe/Menu.singe index 860618e57..72d6b6072 100644 --- a/singe/Menu.singe +++ b/singe/Menu.singe @@ -49,7 +49,6 @@ for dir in lfs.dir(".") do end end table.sort(FOUND_GAMES, compareTitles) -scriptExecute(FOUND_GAMES[1]) font = fontLoad("ActionMax/font_LED_Real.ttf", 32); diff --git a/singe/buildRelease.sh b/singe/buildRelease.sh index a7802dba7..68fdc6e6c 100755 --- a/singe/buildRelease.sh +++ b/singe/buildRelease.sh @@ -64,8 +64,8 @@ function doBuild() { ${CROSS}-${CPPCOMPILER} -o "${TARGET}" ${OFILES} ${EXTRA_OFILES} "-L${SOURCE_DIR}/../thirdparty-build/${OSNAME}/${OSARCH}/installed/lib" ${EXTRA_LD_FLAGS} echo "Compressing ${TARGET}..." - #${CROSS}-strip "${TARGET}" - #upx -9 "${TARGET}" + ${CROSS}-strip "${TARGET}" + upx -9 "${TARGET}" popd } diff --git a/singe/games.dat b/singe/games.dat index 7c03319fa..9dda14efb 100644 --- a/singe/games.dat +++ b/singe/games.dat @@ -3,7 +3,6 @@ GAMES = { TITLE = ".38 Ambush Alley", SCRIPT = "ActionMax/38AmbushAlley.singe", VIDEO = "ActionMax/frame_38AmbushAlley.txt", - DATA = "ActionMax", STRETCH = false, NO_MOUSE = false, RESOLUTION_X = 720, @@ -25,7 +24,6 @@ GAMES = { TITLE = "Blue Thunder", SCRIPT = "ActionMax/BlueThunder.singe", VIDEO = "ActionMax/frame_BlueThunder.txt", - DATA = "ActionMax", STRETCH = false, NO_MOUSE = false, RESOLUTION_X = 720, @@ -69,7 +67,6 @@ GAMES = { TITLE = "Rescue of Pops Ghostly, The", SCRIPT = "ActionMax/PopsGhostly.singe", VIDEO = "ActionMax/frame_PopsGhostly.txt", - DATA = "ActionMax", STRETCH = false, NO_MOUSE = false, RESOLUTION_X = 720, @@ -91,7 +88,6 @@ GAMES = { TITLE = "Sonic Fury", SCRIPT = "ActionMax/SonicFury.singe", VIDEO = "ActionMax/frame_SonicFury.txt", - DATA = "ActionMax", STRETCH = false, NO_MOUSE = false, RESOLUTION_X = 720, diff --git a/singe/main.c b/singe/main.c index fa5d85069..c50b9367c 100644 --- a/singe/main.c +++ b/singe/main.c @@ -355,9 +355,12 @@ ConfigT *createConf(char *exeName, int argc, char *argv[]) { conf->isFrameFile = true; } - // Do we need to generate a data directory name? + // They provided a data directory. Append the game name. if (conf->dataDir) { - utilFixPathSeparators(&conf->dataDir, false); + conf->dataDirBase = strdup(conf->dataDir); + utilFixPathSeparators(&conf->dataDirBase, true); + free(conf->dataDir); + conf->dataDir = utilCreateString("%s%s", conf->dataDirBase, utilGetUpToLastPathComponent(conf->scriptFile)); // Try to create data directory to ensure it exists. utilMkDirP(conf->dataDir, 0777); // Does it exist? @@ -366,16 +369,9 @@ ConfigT *createConf(char *exeName, int argc, char *argv[]) { conf->dataDir = NULL; } } else { - // Put it in the game folder. - x = (int32_t)(strlen(conf->scriptFile) - strlen(utilGetLastPathComponent(conf->scriptFile))) - 1; - if (x < 0) { - x = 0; - } - temp = strdup(conf->scriptFile); - temp[x] = 0; - conf->dataDir = strdup(temp); - free(temp); - temp = NULL; + // No data directory specified. Use the game folder. + conf->dataDirBase = utilCreateString(".%c", utilGetPathSeparator()); + conf->dataDir = strdup(utilGetUpToLastPathComponent(conf->scriptFile)); } if (!conf->dataDir) showUsage(exeName, "Unable to locate data directory."); utilFixPathSeparators(&conf->dataDir, true); @@ -697,6 +693,7 @@ void showUsage(char *name, char *message) { temp = utilCreateString("Singe%cFramework.singe", utilGetPathSeparator()); created |= extractFile(temp, Framework_singe, Framework_singe_len); free(temp); + /* // Singe/Menu.singe temp = utilCreateString("Singe%cMenu.singe", utilGetPathSeparator()); created |= extractFile(temp, Menu_singe, Menu_singe_len); @@ -705,6 +702,7 @@ void showUsage(char *name, char *message) { temp = utilCreateString("Singe%cmenuBackground.mkv", utilGetPathSeparator()); created |= extractFile(temp, menuBackground_mkv, menuBackground_mkv_len); free(temp); + */ // Singe/controls.cfg.example temp = utilCreateString("Singe%ccontrols.cfg.example", utilGetPathSeparator()); created |= extractFile(temp, controls_cfg, controls_cfg_len); @@ -742,7 +740,6 @@ int main(int argc, char *argv[]) { launcher(exeName, conf); destroyConf(&conf); LL_DELETE(_scriptQueue, q); - free(q); } return 0; diff --git a/singe/singe.c b/singe/singe.c index beadd9a89..328475c9d 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -1399,7 +1399,7 @@ int32_t apiOverlaySetResolution(lua_State *L) { // Create the new one. _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); + SDL_SetSurfaceBlendMode(_global.overlay, SDL_BLENDMODE_BLEND); // Update some variables. _global.overlayScaleX = x / videoGetWidth(_global.videoHandle); _global.overlayScaleY = y / videoGetHeight(_global.videoHandle); @@ -1912,14 +1912,12 @@ int32_t apiVideoDraw(lua_State *L) { if (video->surface) SDL_FreeSurface(video->surface); SDL_QueryTexture(video->texture, NULL, NULL, &w, &h); video->surface = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 255); - SDL_SetColorKey(video->surface, SDL_FALSE, 0); if (!video->surface) utilDie("%s", SDL_GetError()); if (SDL_SetRenderTarget(_global.renderer, video->texture) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); if (SDL_RenderReadPixels(_global.renderer, NULL, video->surface->format->format, video->surface->pixels, video->surface->pitch) != 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); if (SDL_SetRenderTarget(_global.renderer, NULL) < 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); } // Render frame into overlay - SDL_SetColorKey(_global.overlay, SDL_FALSE, 0); if (SDL_BlitScaled(video->surface, NULL, _global.overlay, &dest) != 0) luaDie(L, "videoDraw", "%s", SDL_GetError()); result = true; } @@ -2125,25 +2123,18 @@ int32_t apiVideoLoad(lua_State *L) { int32_t n = lua_gettop(L); int32_t result = -1; const char *name = NULL; - const char *data = NULL; + char *data = NULL; VideoT *video = NULL; - if ((n == 1) || (n == 2)) { + if (n == 1) { if (lua_isstring(L, 1)) { name = lua_tostring(L, 1); - if (n == 2) { - if (lua_isstring(L, 2)) { - data = lua_tostring(L, 2); - } else { - luaDie(L, "videoLoad", "Optional second parameter must be a string."); - } - } else { - data = _global.conf.dataDir; - } + // Create data directory based on video path. + data = utilCreateString("%s%s", _global.conf.dataDirBase, utilGetUpToLastPathComponent((char *)name)); video = (VideoT *)calloc(1, sizeof(VideoT)); if (!video) luaDie(L, "videoLoad", "Unable to allocate new video."); // Load this video. - video->handle = videoLoad((char *)name, (char *)data, false, _global.renderer); + video->handle = videoLoad((char *)name, data, false, _global.renderer); if (video->handle < 0) luaDie(L, "videoLoad", "Failed to load video: %s", name); video->id = _global.nextVideoId; video->lastFrame = -1; @@ -2158,6 +2149,8 @@ int32_t apiVideoLoad(lua_State *L) { luaTrace(L, "fontVideo", "Failed!"); } + free(data); + lua_pushnumber(L, result); return 1;} @@ -2729,9 +2722,9 @@ int32_t apiSingeGetScriptPath(lua_State *L) { ConfigT *buildConfFromTable(lua_State *L) { + char *sindenString = NULL; const char *confKey = NULL; const char *valueString = NULL; - char *sindenString = NULL; bool valueBoolean = false; int64_t valueNumber = 0; ConfigT *c = NULL; @@ -2739,9 +2732,10 @@ ConfigT *buildConfFromTable(lua_State *L) { // Start with current config. c = (ConfigT *)calloc(1, sizeof(ConfigT)); memcpy(c, &_global.conf, sizeof(ConfigT)); - if (_global.conf.scriptFile) c->scriptFile = strdup(_global.conf.scriptFile); - if (_global.conf.videoFile) c->videoFile = strdup(_global.conf.videoFile); - if (_global.conf.dataDir) c->dataDir = strdup(_global.conf.dataDir); + if (_global.conf.scriptFile) c->scriptFile = strdup(_global.conf.scriptFile); + if (_global.conf.videoFile) c->videoFile = strdup(_global.conf.videoFile); + if (_global.conf.dataDirBase) c->dataDirBase = strdup(_global.conf.dataDirBase); + if (_global.conf.dataDir) c->dataDir = strdup(_global.conf.dataDir); // Update with data in the table on the top of the Lua stack. lua_pushnil(L); @@ -2780,12 +2774,15 @@ ConfigT *buildConfFromTable(lua_State *L) { if (strcmp(confKey, "SCRIPT") == 0) { if (c->scriptFile) free (c->scriptFile); c->scriptFile = strdup(valueString); + utilFixPathSeparators(&c->scriptFile, false); } else if (strcmp(confKey, "VIDEO") == 0) { if (c->videoFile) free(c->videoFile); c->videoFile = strdup(valueString); - } else if (strcmp(confKey, "DATA") == 0) { - if (c->dataDir) free(c->dataDir); - c->dataDir = strdup(valueString); + utilFixPathSeparators(&c->videoFile, false); + // Is it a framefile? + if (strncmp(utilGetFileExtension(c->videoFile), "txt", 3) == 0) { + c->isFrameFile = true; + } } else if (strcmp(confKey, "STRETCH") == 0) { c->stretchVideo = valueBoolean; } else if (strcmp(confKey, "NO_MOUSE") == 0) { @@ -2805,6 +2802,16 @@ ConfigT *buildConfFromTable(lua_State *L) { lua_pop(L, 1); } + // Create new data dir location based on script location. + if (c->dataDir) free(c->dataDir); + c->dataDir = utilCreateString("%s%s", c->dataDirBase, utilGetUpToLastPathComponent(c->scriptFile)); + // Try to create data directory to ensure it exists. + utilMkDirP(c->dataDir, 0777); + // Does it exist? + if (!utilPathExists(c->dataDir)) { + utilDie("Unable to create data directory: %s", c->dataDir); + } + return c; } @@ -3653,7 +3660,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { 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, SDL_FALSE, 0); + SDL_SetSurfaceBlendMode(_global.overlay, SDL_BLENDMODE_BLEND); // Mouse setup _global.mouseCount = ManyMouse_Init(); @@ -3674,9 +3681,9 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, ConfigT *conf) { } // Grab mouse -// _global.mouseGrabbed = true; -// SDL_SetWindowGrab(_global.window, SDL_TRUE); -// SDL_ShowCursor(SDL_DISABLE); + _global.mouseGrabbed = true; + SDL_SetWindowGrab(_global.window, SDL_TRUE); + SDL_ShowCursor(SDL_DISABLE); // Clear axis cache for (x=0; x