Browse Source

Add preliminary command line options to main.cpp

- Add -h, --help and --version
- Address most of Issue #219.
pull/523/head
Christopher M. Hobbs 7 years ago committed by Anders Jenbo
parent
commit
436e25207a
  1. 9
      Source/diablo.cpp
  2. 51
      SourceX/main.cpp
  3. 2
      SourceX/miniwin/dsound.cpp
  4. 3
      SourceX/miniwin/misc.cpp

9
Source/diablo.cpp

@ -251,6 +251,7 @@ void free_game()
void diablo_init(const char *lpCmdLine) void diablo_init(const char *lpCmdLine)
{ {
diablo_parse_flags(lpCmdLine);
init_create_window(); init_create_window();
SFileEnableDirectAccess(TRUE); SFileEnableDirectAccess(TRUE);
@ -269,7 +270,6 @@ void diablo_init(const char *lpCmdLine)
InitHash(); InitHash();
diablo_init_screen(); diablo_init_screen();
diablo_parse_flags(lpCmdLine);
snd_init(NULL); snd_init(NULL);
atexit(sound_cleanup); atexit(sound_cleanup);
@ -279,10 +279,8 @@ void diablo_init(const char *lpCmdLine)
void diablo_splash() void diablo_splash()
{ {
#ifdef _DEBUG
if (!showintrodebug) if (!showintrodebug)
return; return;
#endif
play_movie("gendata\\logo.smk", TRUE); play_movie("gendata\\logo.smk", TRUE);
#ifndef SPAWN #ifndef SPAWN
@ -331,7 +329,6 @@ void diablo_parse_flags(const char *args)
*/ */
break; break;
case 'd': case 'd':
showintrodebug = 0;
debug_mode_key_d = 1; debug_mode_key_d = 1;
break; break;
#endif #endif
@ -390,9 +387,11 @@ void diablo_parse_flags(const char *args)
} }
DebugMonsters[debugmonsttypes++] = i; DebugMonsters[debugmonsttypes++] = i;
break; break;
#endif
case 'n': case 'n':
showintrodebug = 0; showintrodebug = 0;
break; break;
#ifdef _DEBUG
case 'q': case 'q':
while (isspace(*args)) { while (isspace(*args)) {
args++; args++;
@ -437,10 +436,10 @@ void diablo_parse_flags(const char *args)
case 'w': case 'w':
debug_mode_key_w = 1; debug_mode_key_w = 1;
break; break;
#endif
case 'x': case 'x':
fullscreen = FALSE; fullscreen = FALSE;
break; break;
#endif
} }
} }
} }

51
SourceX/main.cpp

@ -3,6 +3,7 @@
#ifdef __SWITCH__ #ifdef __SWITCH__
#include "platform/switch/network.h" #include "platform/switch/network.h"
#endif #endif
#include <config.h>
#include "devilution.h" #include "devilution.h"
@ -22,16 +23,62 @@ static std::string build_cmdline(int argc, char **argv)
} }
str += argv[i]; str += argv[i];
} }
return str; 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__ #ifdef __SWITCH__
switch_enable_network(); switch_enable_network();
#endif #endif
auto cmdline = build_cmdline(argc, argv);
return dvl::DiabloMain(cmdline.c_str()); return dvl::DiabloMain(cmdline.c_str());
} }

2
SourceX/miniwin/dsound.cpp

@ -27,7 +27,7 @@ void DirectSoundBuffer::Play(int lVolume, int lPan)
{ {
int channel = Mix_PlayChannel(-1, chunk, 0); int channel = Mix_PlayChannel(-1, chunk, 0);
if (channel == -1) { if (channel == -1) {
SDL_Log("Too few channels, skipping sound\n"); SDL_Log("Too few channels, skipping sound");
return; return;
} }

3
SourceX/miniwin/misc.cpp

@ -125,7 +125,8 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
int upscale = 1; int upscale = 1;
DvlIntSetting("upscale", &upscale); DvlIntSetting("upscale", &upscale);
DvlIntSetting("fullscreen", (int *)&fullscreen); if (fullscreen)
DvlIntSetting("fullscreen", (int *)&fullscreen);
int grabInput = 1; int grabInput = 1;
DvlIntSetting("grab input", &grabInput); DvlIntSetting("grab input", &grabInput);

Loading…
Cancel
Save