X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=d21815b29b48db5dc91e27de15558b5f50984880;hb=f965a2a6e56dd5c1e91b306dfd52b38b1dd49537;hp=d21363cad99665ff029ee48bb9c94ec2739c59af;hpb=b6847742a0713d8ed21bb6104476db54f8c1a4b9;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index d21363ca..d21815b2 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -181,6 +182,46 @@ END_OF_FUNCTION(increment_counter); /* maximal allowed length of a command line option */ #define MAX_OPTION_LEN 256 +#if 1 + +#ifdef TARGET_SDL +static unsigned long getCurrentMS() +{ + return SDL_GetTicks(); +} + +#else /* !TARGET_SDL */ + +#if defined(PLATFORM_UNIX) +static unsigned long getCurrentMS() +{ + struct timeval current_time; + + gettimeofday(¤t_time, NULL); + + return current_time.tv_sec * 1000 + current_time.tv_usec / 1000; +} +#endif /* PLATFORM_UNIX */ +#endif /* !TARGET_SDL */ + +static unsigned long mainCounter(int mode) +{ + static unsigned long base_ms = 0; + unsigned long current_ms; + + /* get current system milliseconds */ + current_ms = getCurrentMS(); + + /* reset base timestamp in case of counter reset or wrap-around */ + if (mode == INIT_COUNTER || current_ms < base_ms) + base_ms = current_ms; + + /* return milliseconds since last counter reset */ + return current_ms - base_ms; +} + +#else + #ifdef TARGET_SDL static unsigned long mainCounter(int mode) { @@ -222,6 +263,8 @@ static unsigned long mainCounter(int mode) #endif /* PLATFORM_UNIX */ #endif /* !TARGET_SDL */ +#endif + void InitCounter() /* set counter back to zero */ { #if !defined(PLATFORM_MSDOS) @@ -468,6 +511,16 @@ char *getRealName() return real_name; } +time_t getFileTimestampEpochSeconds(char *filename) +{ + struct stat file_status; + + if (stat(filename, &file_status) != 0) /* cannot stat file */ + return 0; + + return file_status.st_mtime; +} + /* ------------------------------------------------------------------------- */ /* path manipulation functions */ @@ -662,8 +715,7 @@ boolean strSuffixLower(char *s, char *suffix) /* command line option handling functions */ /* ------------------------------------------------------------------------- */ -void GetOptions(char *argv[], void (*print_usage_function)(void), - unsigned long (*get_cmd_switch_function)(char *)) +void GetOptions(char *argv[], void (*print_usage_function)(void)) { char *ro_base_path = RO_BASE_PATH; char *rw_base_path = RW_BASE_PATH; @@ -694,7 +746,9 @@ void GetOptions(char *argv[], void (*print_usage_function)(void), options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY); options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY); options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY); + options.execute_command = NULL; + options.special_flags = NULL; options.serveronly = FALSE; options.network = FALSE; @@ -702,8 +756,6 @@ void GetOptions(char *argv[], void (*print_usage_function)(void), 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 */ options.verbose = TRUE; @@ -834,18 +886,22 @@ void GetOptions(char *argv[], void (*print_usage_function)(void), } else if (strPrefix(option, "-D")) { - char *switch_string = &option[2]; - unsigned long switch_value; +#if 1 + options.special_flags = getStringCopy(&option[2]); +#else + char *flags_string = &option[2]; + unsigned long flags_value; - if (*switch_string == '\0') - Error(ERR_EXIT_HELP, "empty switch ignored"); + if (*flags_string == '\0') + Error(ERR_EXIT_HELP, "empty flag ignored"); - switch_value = get_cmd_switch_function(switch_string); + flags_value = get_special_flags_function(flags_string); - if (switch_value == 0) - Error(ERR_EXIT_HELP, "unknown switch '%s'", switch_string); + if (flags_value == 0) + Error(ERR_EXIT_HELP, "unknown flag '%s'", flags_string); - options.cmd_switches |= switch_value; + options.special_flags |= flags_value; +#endif } else if (strncmp(option, "-execute", option_len) == 0) { @@ -1955,6 +2011,20 @@ int get_parameter_value(char *value_raw, char *suffix, int type) if (string_has_parameter(value, "static_panel")) result |= ANIM_STATIC_PANEL; } + else if (strEqual(suffix, ".class")) + { + result = get_hash_from_key(value); + } + else if (strEqual(suffix, ".style")) + { + result = STYLE_DEFAULT; + + if (string_has_parameter(value, "accurate_borders")) + result |= STYLE_ACCURATE_BORDERS; + + if (string_has_parameter(value, "inner_corners")) + result |= STYLE_INNER_CORNERS; + } else if (strEqual(suffix, ".fade_mode")) { result = (string_has_parameter(value, "none") ? FADE_MODE_NONE :