From 639291665b5c919d64a1cfdfbfc034f66999e683 Mon Sep 17 00:00:00 2001 From: Cormac McGaughey Date: Tue, 20 Jan 2026 15:17:40 -0800 Subject: [PATCH 1/5] Update to record playback files to a single folder --- GNUmakefile | 3 ++- Snipes.cpp | 21 ++++++++++++++++++--- config-sample.h | 3 +++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 1bc7b5f..c5b2047 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,5 +1,6 @@ SOURCES=$(addsuffix .cpp, Snipes $(addprefix sdl/, console keyboard sound timer)) -CFLAGS=-std=c++11 $(shell sdl2-config --cflags) +# CFLAGS=-std=c++11 $(shell sdl2-config --cflags) +CFLAGS=-std=c++23 $(shell sdl2-config --cflags) CFLAGS+=$(if $(MAINT),-Werror -Wall -Wextra,) CFLAGS2=-O3 -fstack-protector #CFLAGS2=-Og -g -fsanitize=address -fsanitize=undefined diff --git a/Snipes.cpp b/Snipes.cpp index 0cc201b..06b4421 100644 --- a/Snipes.cpp +++ b/Snipes.cpp @@ -13,6 +13,17 @@ #include "keyboard.h" #include "platform.h" + +// Platform-specific directory creation +#if defined(_WIN32) || defined(_WIN64) + #include + #define CREATE_DIRECTORY(path) _mkdir(path) +#else + #include + #include + #define CREATE_DIRECTORY(path) mkdir(path, 0755) +#endif + bool got_ctrl_break = false; bool forfeit_match = false; bool instant_quit = false; @@ -1733,7 +1744,7 @@ void EraseObjectFromMaze() } } -//template TYPE &IncWrap(TYPE &n, +//template TYPE &IncWrap(TYPE &n, void UpdateSnipePortals() { @@ -2271,9 +2282,13 @@ extern "C" int __cdecl SDL_main(int argc, char* argv[]) struct tm *rectime_gmt; rectime_gmt = gmtime(&rectime); - char replayFilename[1024]; + // Create the replay folder if it doesn't exist + CREATE_DIRECTORY(REPLAY_FOLDER); + + char replayFilename[1024]; sprintf(replayFilename, - "%04d-%02d-%02d %02d.%02d.%02d.SnipesGame", + "%s/%04d-%02d-%02d %02d.%02d.%02d.SnipesGame", + REPLAY_FOLDER, 1900+rectime_gmt->tm_year, rectime_gmt->tm_mon+1, rectime_gmt->tm_mday, rectime_gmt->tm_hour, rectime_gmt->tm_min, rectime_gmt->tm_sec); diff --git a/config-sample.h b/config-sample.h index 1651540..8388bf4 100644 --- a/config-sample.h +++ b/config-sample.h @@ -18,6 +18,9 @@ // For playback: Wait for a keypress at start, and behave like a live game at end. Meant for screen recording of a played back replay. //#define PLAYBACK_FOR_SCREEN_RECORDING +// Store Recording files to a single folder. This should ensure playback that the game doesn't develop a __MACOSX problem. +#define PLAYBACKFOLDER "~/SnipesGameFiles" + // Windows options #define WINDOWS_PRECISE_TIMER From 7cddb63c6484d6600408ac8438d8970aeef9a255 Mon Sep 17 00:00:00 2001 From: Cormac McGaughey Date: Thu, 22 Jan 2026 21:15:24 -0800 Subject: [PATCH 2/5] Added .h comments for documentation --- GNUmakefile | 3 +-- Snipes.cpp | 11 +++++++++-- config-sample.h | 9 +++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index c5b2047..1bc7b5f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,5 @@ SOURCES=$(addsuffix .cpp, Snipes $(addprefix sdl/, console keyboard sound timer)) -# CFLAGS=-std=c++11 $(shell sdl2-config --cflags) -CFLAGS=-std=c++23 $(shell sdl2-config --cflags) +CFLAGS=-std=c++11 $(shell sdl2-config --cflags) CFLAGS+=$(if $(MAINT),-Werror -Wall -Wextra,) CFLAGS2=-O3 -fstack-protector #CFLAGS2=-Og -g -fsanitize=address -fsanitize=undefined diff --git a/Snipes.cpp b/Snipes.cpp index 06b4421..6d770f6 100644 --- a/Snipes.cpp +++ b/Snipes.cpp @@ -2281,16 +2281,23 @@ extern "C" int __cdecl SDL_main(int argc, char* argv[]) time_t rectime = time(NULL); struct tm *rectime_gmt; rectime_gmt = gmtime(&rectime); - +#ifdef REPLAY_FOLDER // Create the replay folder if it doesn't exist CREATE_DIRECTORY(REPLAY_FOLDER); char replayFilename[1024]; - sprintf(replayFilename, + snprintf(replayFilename, sizeof(replayFilename), "%s/%04d-%02d-%02d %02d.%02d.%02d.SnipesGame", REPLAY_FOLDER, 1900+rectime_gmt->tm_year, rectime_gmt->tm_mon+1, rectime_gmt->tm_mday, rectime_gmt->tm_hour, rectime_gmt->tm_min, rectime_gmt->tm_sec); +#else + char replayFilename[1024]; + snprintf(replayFilename, sizeof(replayFilename), + "%04d-%02d-%02d %02d.%02d.%02d.SnipesGame", + 1900+rectime_gmt->tm_year, rectime_gmt->tm_mon+1, rectime_gmt->tm_mday, + rectime_gmt->tm_hour, rectime_gmt->tm_min, rectime_gmt->tm_sec); +#endif #ifdef CHEAT replayFile = fopen(replayFilename, "w+b"); diff --git a/config-sample.h b/config-sample.h index 8388bf4..b7c82a7 100644 --- a/config-sample.h +++ b/config-sample.h @@ -18,8 +18,13 @@ // For playback: Wait for a keypress at start, and behave like a live game at end. Meant for screen recording of a played back replay. //#define PLAYBACK_FOR_SCREEN_RECORDING -// Store Recording files to a single folder. This should ensure playback that the game doesn't develop a __MACOSX problem. -#define PLAYBACKFOLDER "~/SnipesGameFiles" +// Store Recording files to a single folder. +// This should ensure playback that the game doesn't develop a __MACOSX problem where there are SnipesGameFiles littered everywhere. +// For Linux: (note, you can't use the ~/SnipesGameFiles naming format) +#define PLAYBACKFOLDER "/home/username/SnipesGameFiles" +// +// For Windows: +// #define PLAYBACKFOLDER "C:\SnipesGameFiles" // Windows options #define WINDOWS_PRECISE_TIMER From 7bf814321957da65b349ed0e34d0c25378562539 Mon Sep 17 00:00:00 2001 From: Cormac McGaughey Date: Thu, 22 Jan 2026 21:28:20 -0800 Subject: [PATCH 3/5] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e6d85d..e587191 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Snipes -This is a modern port of the classic 1982 text-mode game Snipes. The code has been reverse-engineered from the original DOS executable, and has 100% identical game logic. +This is a modern port of the classic 1982 text-mode game Snipes. The code has been reverse-engineered from the original DOS executable, and has 100% identical game logic. For more information, see the [vogons.org forum thread](https://www.vogons.org/viewtopic.php?f=7&t=49073). @@ -28,6 +28,7 @@ For Arch Linux, you can use the [snipes-git](https://aur.archlinux.org/packages/ ### Replay recording This version automatically records replay files of played games. By default, replay files are saved to the current directory, and have a `.SnipesGame` file extension. +If you uncomment the `#define REPLAY_FOLDER` line in config.h and enter a valid path, the `.SnipesGame` replays will be saved to that directory rather than the current directory. To play back a replay file, pass it as the first argument to the game program, e.g.: From 2d8ac3ef59356764b65a3a012c85b45d234fd1e9 Mon Sep 17 00:00:00 2001 From: Cormac McGaughey Date: Fri, 23 Jan 2026 20:19:03 -0800 Subject: [PATCH 4/5] Update to correct config-sample.h file example --- config-sample.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-sample.h b/config-sample.h index b7c82a7..d5a392d 100644 --- a/config-sample.h +++ b/config-sample.h @@ -21,7 +21,7 @@ // Store Recording files to a single folder. // This should ensure playback that the game doesn't develop a __MACOSX problem where there are SnipesGameFiles littered everywhere. // For Linux: (note, you can't use the ~/SnipesGameFiles naming format) -#define PLAYBACKFOLDER "/home/username/SnipesGameFiles" +#define REPLAY_FOLDER "/home/username/SnipesGameFiles" // // For Windows: // #define PLAYBACKFOLDER "C:\SnipesGameFiles" From af731897444f8d8b59251859eb4a12e6b74f9f87 Mon Sep 17 00:00:00 2001 From: Cormac McGaughey Date: Fri, 23 Jan 2026 20:34:53 -0800 Subject: [PATCH 5/5] Update to simplify the replay folder use logic. --- Snipes.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Snipes.cpp b/Snipes.cpp index 6d770f6..f71b89c 100644 --- a/Snipes.cpp +++ b/Snipes.cpp @@ -24,6 +24,11 @@ #define CREATE_DIRECTORY(path) mkdir(path, 0755) #endif +//IF REPLAY_FOLDER is not defined, it should use the current folder. +#ifndef REPLAY_FOLDER + #define REPLAY_FOLDER "." +#endif + bool got_ctrl_break = false; bool forfeit_match = false; bool instant_quit = false; @@ -2281,7 +2286,7 @@ extern "C" int __cdecl SDL_main(int argc, char* argv[]) time_t rectime = time(NULL); struct tm *rectime_gmt; rectime_gmt = gmtime(&rectime); -#ifdef REPLAY_FOLDER + // Create the replay folder if it doesn't exist CREATE_DIRECTORY(REPLAY_FOLDER); @@ -2291,13 +2296,6 @@ extern "C" int __cdecl SDL_main(int argc, char* argv[]) REPLAY_FOLDER, 1900+rectime_gmt->tm_year, rectime_gmt->tm_mon+1, rectime_gmt->tm_mday, rectime_gmt->tm_hour, rectime_gmt->tm_min, rectime_gmt->tm_sec); -#else - char replayFilename[1024]; - snprintf(replayFilename, sizeof(replayFilename), - "%04d-%02d-%02d %02d.%02d.%02d.SnipesGame", - 1900+rectime_gmt->tm_year, rectime_gmt->tm_mon+1, rectime_gmt->tm_mday, - rectime_gmt->tm_hour, rectime_gmt->tm_min, rectime_gmt->tm_sec); -#endif #ifdef CHEAT replayFile = fopen(replayFilename, "w+b");