From 436e25207aa5961e0a89d47104fdfed710739ecb Mon Sep 17 00:00:00 2001 From: "Christopher M. Hobbs" Date: Thu, 8 Aug 2019 21:19:11 -0500 Subject: [PATCH] Add preliminary command line options to main.cpp - Add -h, --help and --version - Address most of Issue #219. --- Source/diablo.cpp | 9 +++---- SourceX/main.cpp | 51 ++++++++++++++++++++++++++++++++++++-- SourceX/miniwin/dsound.cpp | 2 +- SourceX/miniwin/misc.cpp | 3 ++- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index d8e2c9c89..1f02abc3f 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -251,6 +251,7 @@ void free_game() void diablo_init(const char *lpCmdLine) { + diablo_parse_flags(lpCmdLine); init_create_window(); SFileEnableDirectAccess(TRUE); @@ -269,7 +270,6 @@ void diablo_init(const char *lpCmdLine) InitHash(); diablo_init_screen(); - diablo_parse_flags(lpCmdLine); snd_init(NULL); atexit(sound_cleanup); @@ -279,10 +279,8 @@ void diablo_init(const char *lpCmdLine) void diablo_splash() { -#ifdef _DEBUG if (!showintrodebug) return; -#endif play_movie("gendata\\logo.smk", TRUE); #ifndef SPAWN @@ -331,7 +329,6 @@ void diablo_parse_flags(const char *args) */ break; case 'd': - showintrodebug = 0; debug_mode_key_d = 1; break; #endif @@ -390,9 +387,11 @@ void diablo_parse_flags(const char *args) } DebugMonsters[debugmonsttypes++] = i; break; +#endif case 'n': showintrodebug = 0; break; +#ifdef _DEBUG case 'q': while (isspace(*args)) { args++; @@ -437,10 +436,10 @@ void diablo_parse_flags(const char *args) case 'w': debug_mode_key_w = 1; break; +#endif case 'x': fullscreen = FALSE; break; -#endif } } } diff --git a/SourceX/main.cpp b/SourceX/main.cpp index a4f798d89..727b9ae59 100644 --- a/SourceX/main.cpp +++ b/SourceX/main.cpp @@ -3,6 +3,7 @@ #ifdef __SWITCH__ #include "platform/switch/network.h" #endif +#include #include "devilution.h" @@ -22,16 +23,62 @@ static std::string build_cmdline(int argc, char **argv) } str += argv[i]; } + return str; } -int main(int argc, char **argv) +static bool HasArgumst(const char *arg, int argc, char **argv) { - auto cmdline = build_cmdline(argc, argv); + for (int i = 1; i < argc; i++) { + if (strcasecmp(arg, argv[i]) == 0) { + return true; + } + } + + return false; +} +static void ShowCLIinfo(int argc, char **argv) +{ + if (HasArgumst("-h", argc, argv) || HasArgumst("--help", argc, argv)) { + printf("Options:\n"); + printf(" %-20s %-30s\n", "-h, --help", "Print this message and exit"); + printf(" %-20s %-30s\n", "--version", "Print the version and exit"); + printf(" %-20s %-30s\n", "-n", "Skip startup videos"); + printf(" %-20s %-30s\n", "-f", "Display frames per second"); + printf(" %-20s %-30s\n", "-x", "Run in windows mode"); +#ifdef _DEBUG + printf("\nDebug options:\n"); + printf(" %-20s %-30s\n", "-d", "Increaased item drops"); + printf(" %-20s %-30s\n", "-w", "Enable cheats"); + printf(" %-20s %-30s\n", "-$", "Enable god mode"); + printf(" %-20s %-30s\n", "-^", "Enable god mode and debug tools"); + //printf(" %-20s %-30s\n", "-b", "Enable item drop log"); + printf(" %-20s %-30s\n", "-v", "Highlight visibility"); + printf(" %-20s %-30s\n", "-i", "Ignore network timeout"); + //printf(" %-20s %-30s\n", "-j <##>", "Init trigger at level"); + printf(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type"); + printf(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed"); + printf(" %-20s %-30s\n", "-q <#>", "Force a certain quest"); + printf(" %-20s %-30s\n", "-r <##########>", "Set map seed"); + printf(" %-20s %-30s\n", "-t <##>", "Set current quest level"); +#endif + printf("\nReport bugs at https://github.com/diasurgical/devilutionX/\n"); + exit(0); + } + if (HasArgumst("--version", argc, argv)) { + printf("%s v%s\n", PROJECT_NAME, PROJECT_VERSION); + exit(0); + } +} + +int main(int argc, char **argv) +{ + ShowCLIinfo(argc, argv); #ifdef __SWITCH__ switch_enable_network(); #endif + auto cmdline = build_cmdline(argc, argv); return dvl::DiabloMain(cmdline.c_str()); } diff --git a/SourceX/miniwin/dsound.cpp b/SourceX/miniwin/dsound.cpp index 13e9684e2..db6baba37 100644 --- a/SourceX/miniwin/dsound.cpp +++ b/SourceX/miniwin/dsound.cpp @@ -27,7 +27,7 @@ void DirectSoundBuffer::Play(int lVolume, int lPan) { int channel = Mix_PlayChannel(-1, chunk, 0); if (channel == -1) { - SDL_Log("Too few channels, skipping sound\n"); + SDL_Log("Too few channels, skipping sound"); return; } diff --git a/SourceX/miniwin/misc.cpp b/SourceX/miniwin/misc.cpp index 066583807..5cb590f2a 100644 --- a/SourceX/miniwin/misc.cpp +++ b/SourceX/miniwin/misc.cpp @@ -125,7 +125,8 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight) int upscale = 1; DvlIntSetting("upscale", &upscale); - DvlIntSetting("fullscreen", (int *)&fullscreen); + if (fullscreen) + DvlIntSetting("fullscreen", (int *)&fullscreen); int grabInput = 1; DvlIntSetting("grab input", &grabInput);