X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=b344ba6f2a9e65365ea36b4fe7c14359b13c9aeb;hb=7891415ca10eb882506eaaa3bca720ec75723a0e;hp=6fe6949b45e3adc687938977ee4248b491449d5e;hpb=bcb3453f710b95ec98b188b95574bea9ab336e96;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 6fe6949b..b344ba6f 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -14,9 +14,6 @@ #include #include #include -/* -#include -*/ #include #include #include @@ -115,7 +112,7 @@ static void sleep_milliseconds(unsigned long milliseconds_delay) boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE); #if defined(PLATFORM_MSDOS) - /* don't use select() to perform waiting operations under DOS/Windows + /* don't use select() to perform waiting operations under DOS environment; always use a busy loop for waiting instead */ do_busy_waiting = TRUE; #endif @@ -159,12 +156,13 @@ boolean FrameReached(unsigned long *frame_counter_var, { unsigned long actual_frame_counter = FrameCounter; - if (actual_frame_counter < *frame_counter_var+frame_delay && + if (actual_frame_counter < *frame_counter_var + frame_delay && actual_frame_counter >= *frame_counter_var) - return(FALSE); + return FALSE; *frame_counter_var = actual_frame_counter; - return(TRUE); + + return TRUE; } boolean DelayReached(unsigned long *counter_var, @@ -174,10 +172,11 @@ boolean DelayReached(unsigned long *counter_var, if (actual_counter < *counter_var + delay && actual_counter >= *counter_var) - return(FALSE); + return FALSE; *counter_var = actual_counter; - return(TRUE); + + return TRUE; } void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay) @@ -435,6 +434,7 @@ void GetOptions(char *argv[]) options.network = FALSE; options.verbose = FALSE; options.debug = FALSE; + options.debug_command = NULL; while (*options_left) { @@ -472,19 +472,23 @@ void GetOptions(char *argv[]) Error(ERR_EXIT_HELP, "unrecognized option '%s'", option); else if (strncmp(option, "-help", option_len) == 0) { - printf("Usage: %s [options] [server.name [port]]\n" + printf("Usage: %s [options] [ []]\n" "Options:\n" " -d, --display [:] X server display\n" " -b, --basepath alternative base directory\n" " -l, --level alternative level directory\n" " -g, --graphics alternative graphics directory\n" - " -s, --sounds alternative graphics directory\n" - " -m, --music alternative graphics directory\n" + " -s, --sounds alternative sounds directory\n" + " -m, --music alternative music directory\n" " -n, --network network multiplayer game\n" " --serveronly only start network server\n" " -v, --verbose verbose mode\n" " --debug display debugging information\n", program.command_basename); + + if (options.debug) + printf(" --debug-command execute special command\n"); + exit(0); } else if (strncmp(option, "-display", option_len) == 0) @@ -563,6 +567,15 @@ void GetOptions(char *argv[]) { options.debug = TRUE; } + else if (strncmp(option, "-debug-command", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + + options.debug_command = option_arg; + if (option_arg == next_option) + options_left++; + } else if (*option == '-') { Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str); @@ -806,7 +819,7 @@ void putFileChunk(FILE *file, char *chunk_name, int chunk_size, void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes) { - while (bytes--) + while (bytes-- && !feof(file)) fgetc(file); } @@ -1172,27 +1185,38 @@ boolean FileIsGraphic(char *filename) return FALSE; } -boolean FileIsSound(char *filename) +boolean FileIsSound(char *basename) { - if (strlen(filename) > 4 && - strcmp(&filename[strlen(filename) - 4], ".wav") == 0) + if (strlen(basename) > 4 && + strcmp(&basename[strlen(basename) - 4], ".wav") == 0) return TRUE; return FALSE; } -boolean FileIsMusic(char *filename) +boolean FileIsMusic(char *basename) { - if (strlen(filename) > 4 && - (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 || - strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 || - strncmp(filename, "mod.", 4) == 0 || - strncmp(filename, "MOD.", 4) == 0)) + if (strlen(basename) > 4 && + (strcmp(&basename[strlen(basename) - 4], ".mod") == 0 || + strcmp(&basename[strlen(basename) - 4], ".MOD") == 0 || + strncmp(basename, "mod.", 4) == 0 || + strncmp(basename, "MOD.", 4) == 0)) return TRUE; return FALSE; } +boolean FileIsArtworkType(char *basename, int type) +{ + if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) || + (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) || + (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename))) + return TRUE; + + return FALSE; +} + + /* ========================================================================= */ /* functions only needed for non-Unix (non-command-line) systems */ /* ========================================================================= */