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.: diff --git a/Snipes.cpp b/Snipes.cpp index 0cc201b..f71b89c 100644 --- a/Snipes.cpp +++ b/Snipes.cpp @@ -13,6 +13,22 @@ #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 + +//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; @@ -1733,7 +1749,7 @@ void EraseObjectFromMaze() } } -//template TYPE &IncWrap(TYPE &n, +//template TYPE &IncWrap(TYPE &n, void UpdateSnipePortals() { @@ -2271,9 +2287,13 @@ extern "C" int __cdecl SDL_main(int argc, char* argv[]) struct tm *rectime_gmt; rectime_gmt = gmtime(&rectime); - char replayFilename[1024]; - sprintf(replayFilename, - "%04d-%02d-%02d %02d.%02d.%02d.SnipesGame", + // Create the replay folder if it doesn't exist + CREATE_DIRECTORY(REPLAY_FOLDER); + + char replayFilename[1024]; + 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); diff --git a/config-sample.h b/config-sample.h index 1651540..d5a392d 100644 --- a/config-sample.h +++ b/config-sample.h @@ -18,6 +18,14 @@ // 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 where there are SnipesGameFiles littered everywhere. +// For Linux: (note, you can't use the ~/SnipesGameFiles naming format) +#define REPLAY_FOLDER "/home/username/SnipesGameFiles" +// +// For Windows: +// #define PLAYBACKFOLDER "C:\SnipesGameFiles" + // Windows options #define WINDOWS_PRECISE_TIMER