X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=d21363cad99665ff029ee48bb9c94ec2739c59af;hb=b6847742a0713d8ed21bb6104476db54f8c1a4b9;hp=9061a3cf89cd225a5a57bbe6f76aab422ec0f47e;hpb=ae9c6c4794c6a8f9704850427de3ebbe933400da;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 9061a3cf..d21363ca 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -337,13 +337,26 @@ unsigned int init_random_number(int nr, long seed) { if (seed == NEW_RANDOMIZE) { -#if defined(TARGET_SDL) - seed = (long)SDL_GetTicks(); -#else + /* default random seed */ + seed = (long)time(NULL); // seconds since the epoch + +#if !defined(PLATFORM_WIN32) + /* add some more randomness */ struct timeval current_time; gettimeofday(¤t_time, NULL); - seed = (long)current_time.tv_usec; + + seed += (long)current_time.tv_usec; // microseconds since the epoch +#endif + +#if defined(TARGET_SDL) + /* add some more randomness */ + seed += (long)SDL_GetTicks(); // milliseconds since SDL init +#endif + +#if 1 + /* add some more randomness */ + seed += GetSimpleRandom(1000000); #endif } @@ -624,12 +637,33 @@ boolean strSuffix(char *s, char *suffix) strncmp(&s[strlen(s) - strlen(suffix)], suffix, strlen(suffix)) == 0); } +boolean strPrefixLower(char *s, char *prefix) +{ + char *s_lower = getStringToLower(s); + boolean match = strPrefix(s_lower, prefix); + + free(s_lower); + + return match; +} + +boolean strSuffixLower(char *s, char *suffix) +{ + char *s_lower = getStringToLower(s); + boolean match = strSuffix(s_lower, suffix); + + free(s_lower); + + return match; +} + /* ------------------------------------------------------------------------- */ /* command line option handling functions */ /* ------------------------------------------------------------------------- */ -void GetOptions(char *argv[], void (*print_usage_function)(void)) +void GetOptions(char *argv[], void (*print_usage_function)(void), + unsigned long (*get_cmd_switch_function)(char *)) { char *ro_base_path = RO_BASE_PATH; char *rw_base_path = RW_BASE_PATH; @@ -652,6 +686,7 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) options.display_name = NULL; options.server_host = NULL; options.server_port = 0; + options.ro_base_directory = ro_base_path; options.rw_base_directory = rw_base_path; options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY); @@ -660,10 +695,14 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY); options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY); options.execute_command = NULL; + options.serveronly = FALSE; options.network = FALSE; options.verbose = FALSE; options.debug = FALSE; + options.debug_x11_sync = FALSE; + + options.cmd_switches = 0; #if !defined(PLATFORM_UNIX) if (*options_left == NULL) /* no options given -- enable verbose mode */ @@ -687,7 +726,7 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) if (strEqual(option, "--")) /* stop scanning arguments */ break; - if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */ + if (strPrefix(option, "--")) /* treat '--' like '-' */ option++; option_arg = strchr(option, '='); @@ -789,6 +828,25 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) { options.debug = TRUE; } + else if (strncmp(option, "-debug-x11-sync", option_len) == 0) + { + options.debug_x11_sync = TRUE; + } + else if (strPrefix(option, "-D")) + { + char *switch_string = &option[2]; + unsigned long switch_value; + + if (*switch_string == '\0') + Error(ERR_EXIT_HELP, "empty switch ignored"); + + switch_value = get_cmd_switch_function(switch_string); + + if (switch_value == 0) + Error(ERR_EXIT_HELP, "unknown switch '%s'", switch_string); + + options.cmd_switches |= switch_value; + } else if (strncmp(option, "-execute", option_len) == 0) { if (option_arg == NULL) @@ -1391,7 +1449,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) Key key = KSYM_UNDEFINED; char *name_ptr = *x11name; - if (strncmp(name_ptr, "XK_", 3) == 0 && strlen(name_ptr) == 4) + if (strPrefix(name_ptr, "XK_") && strlen(name_ptr) == 4) { char c = name_ptr[3]; @@ -1402,14 +1460,14 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) else if (c >= '0' && c <= '9') key = KSYM_0 + (Key)(c - '0'); } - else if (strncmp(name_ptr, "XK_KP_", 6) == 0 && strlen(name_ptr) == 7) + else if (strPrefix(name_ptr, "XK_KP_") && strlen(name_ptr) == 7) { char c = name_ptr[6]; if (c >= '0' && c <= '9') key = KSYM_KP_0 + (Key)(c - '0'); } - else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6) + else if (strPrefix(name_ptr, "XK_F") && strlen(name_ptr) <= 6) { char c1 = name_ptr[4]; char c2 = name_ptr[5]; @@ -1422,7 +1480,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) if (d >= 1 && d <= KSYM_NUM_FKEYS) key = KSYM_F1 + (Key)(d - 1); } - else if (strncmp(name_ptr, "XK_", 3) == 0) + else if (strPrefix(name_ptr, "XK_")) { i = 0; @@ -1436,7 +1494,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) } while (translate_key[++i].x11name); } - else if (strncmp(name_ptr, "0x", 2) == 0) + else if (strPrefix(name_ptr, "0x")) { unsigned long value = 0; @@ -1595,6 +1653,24 @@ boolean get_boolean_from_string(char *s) return result; } +int get_switch3_from_string(char *s) +{ + char *s_lower = getStringToLower(s); + int result = FALSE; + + if (strEqual(s_lower, "true") || + strEqual(s_lower, "yes") || + strEqual(s_lower, "on") || + get_integer_from_string(s) == 1) + result = TRUE; + else if (strEqual(s_lower, "auto")) + result = AUTO; + + free(s_lower); + + return result; +} + /* ------------------------------------------------------------------------- */ /* functions for generic lists */ @@ -2211,7 +2287,7 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, if (filename == NULL) return; -#if 1 +#if 0 printf("LoadArtworkConfigFromFilename '%s' ...\n", filename); #endif @@ -2671,9 +2747,11 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) /* first look for special artwork configured in level series config */ filename_base = getCustomArtworkLevelConfigFilename(artwork_info->type); +#if 0 printf("::: filename_base == '%s' [%s, %s]\n", filename_base, leveldir_current->graphics_set, leveldir_current->graphics_path); +#endif if (fileExists(filename_base)) LoadArtworkConfigFromFilename(artwork_info, filename_base);