X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=c34cddd322cf7a1294ee33c074e73f736327e2c9;hp=4498e7f49522a8ea9bfcd9485d87ab1cd584771c;hb=30f5fd7b8f2235820dcbe638a18319d802317530;hpb=1907a314668338eb542080062ca81d95451ca9db diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 4498e7f4..c34cddd3 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -357,25 +357,7 @@ unsigned int Counter() /* get milliseconds since last call of InitCounter() */ static void sleep_milliseconds(unsigned int milliseconds_delay) { - boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE); - - if (do_busy_waiting) - { - /* we want to wait only a few ms -- if we assume that we have a - kernel timer resolution of 10 ms, we would wait far too long; - therefore it's better to do a short interval of busy waiting - to get our sleeping time more accurate */ - - unsigned int base_counter = Counter(), actual_counter = Counter(); - - while (actual_counter < base_counter + milliseconds_delay && - actual_counter >= base_counter) - actual_counter = Counter(); - } - else - { - SDL_Delay(milliseconds_delay); - } + SDL_Delay(milliseconds_delay); } void Delay(unsigned int delay) /* Sleep specified number of milliseconds */ @@ -383,32 +365,42 @@ void Delay(unsigned int delay) /* Sleep specified number of milliseconds */ sleep_milliseconds(delay); } -boolean FrameReached(unsigned int *frame_counter_var, - unsigned int frame_delay) +boolean DelayReachedExt(unsigned int *counter_var, unsigned int delay, + unsigned int actual_counter) { - unsigned int actual_frame_counter = FrameCounter; - - if (actual_frame_counter >= *frame_counter_var && - actual_frame_counter < *frame_counter_var + frame_delay) + if (actual_counter >= *counter_var && + actual_counter < *counter_var + delay) return FALSE; - *frame_counter_var = actual_frame_counter; + *counter_var = actual_counter; return TRUE; } -boolean DelayReached(unsigned int *counter_var, - unsigned int delay) +boolean FrameReached(unsigned int *frame_counter_var, unsigned int frame_delay) { - unsigned int actual_counter = Counter(); + return DelayReachedExt(frame_counter_var, frame_delay, FrameCounter); +} - if (actual_counter >= *counter_var && - actual_counter < *counter_var + delay) - return FALSE; +boolean DelayReached(unsigned int *counter_var, unsigned int delay) +{ + return DelayReachedExt(counter_var, delay, Counter()); +} - *counter_var = actual_counter; +void ResetDelayCounterExt(unsigned int *counter_var, + unsigned int actual_counter) +{ + DelayReachedExt(counter_var, 0, actual_counter); +} - return TRUE; +void ResetFrameCounter(unsigned int *frame_counter_var) +{ + FrameReached(frame_counter_var, 0); +} + +void ResetDelayCounter(unsigned int *counter_var) +{ + DelayReached(counter_var, 0); } int WaitUntilDelayReached(unsigned int *counter_var, unsigned int delay) @@ -784,46 +776,27 @@ char *getPath3(char *path1, char *path2, char *path3) return getStringCat3WithSeparator(path1, path2, path3, STRING_PATH_SEPARATOR); } -char *getImg2(char *path1, char *path2) +static char *getPngOrPcxIfNotExists(char *filename) { - char *filename = getPath2(path1, path2); + // switch from PNG to PCX file and vice versa, if file does not exist + // (backwards compatibility with PCX files used in previous versions) - if (!fileExists(filename) && strSuffix(path2, ".png")) - { - // backward compatibility: if PNG file not found, check for PCX file - char *path2pcx = getStringCopy(path2); - - strcpy(&path2pcx[strlen(path2pcx) - 3], "pcx"); - - free(filename); - - filename = getPath2(path1, path2pcx); - - free(path2pcx); - } + if (!fileExists(filename) && strSuffix(filename, ".png")) + strcpy(&filename[strlen(filename) - 3], "pcx"); + else if (!fileExists(filename) && strSuffix(filename, ".pcx")) + strcpy(&filename[strlen(filename) - 3], "png"); return filename; } -char *getImg3(char *path1, char *path2, char *path3) +char *getImg2(char *path1, char *path2) { - char *filename = getPath3(path1, path2, path3); - - if (!fileExists(filename) && strSuffix(path3, ".png")) - { - // backward compatibility: if PNG file not found, check for PCX file - char *path3pcx = getStringCopy(path3); - - strcpy(&path3pcx[strlen(path3pcx) - 3], "pcx"); - - free(filename); - - filename = getPath3(path1, path2, path3pcx); - - free(path3pcx); - } + return getPngOrPcxIfNotExists(getPath2(path1, path2)); +} - return filename; +char *getImg3(char *path1, char *path2, char *path3) +{ + return getPngOrPcxIfNotExists(getPath3(path1, path2, path3)); } char *getStringCopy(const char *s) @@ -2604,6 +2577,43 @@ char *get_mapped_token(char *token) return NULL; } +char *get_special_base_token(struct ArtworkListInfo *artwork_info, char *token) +{ + /* !!! make this dynamically configurable (init.c:InitArtworkConfig) !!! */ + static struct ConfigTypeInfo prefix_list[] = + { + { "global.anim_1" }, + { "global.anim_2" }, + { "global.anim_3" }, + { "global.anim_4" }, + { "global.anim_5" }, + { "global.anim_6" }, + { "global.anim_7" }, + { "global.anim_8" }, + + { NULL } + }; + struct ConfigTypeInfo *suffix_list = artwork_info->suffix_list; + boolean prefix_found = FALSE; + int len_suffix = 0; + int i; + + /* search for prefix to check if base token has to be created */ + for (i = 0; prefix_list[i].token != NULL; i++) + if (strPrefix(token, prefix_list[i].token)) + prefix_found = TRUE; + + if (!prefix_found) + return NULL; + + /* search for suffix (parameter) to determine base token length */ + for (i = 0; suffix_list[i].token != NULL; i++) + if (strSuffix(token, suffix_list[i].token)) + len_suffix = strlen(suffix_list[i].token); + + return getStringCopyN(token, strlen(token) - len_suffix); +} + /* This function checks if a string of the format "string1, string2, ..." exactly contains a string . */ @@ -2706,7 +2716,8 @@ int get_parameter_value(char *value_raw, char *suffix, int type) } else if (strEqual(suffix, ".class")) { - result = get_hash_from_key(value); + result = (strEqual(value, ARG_UNDEFINED) ? ARG_UNDEFINED_VALUE : + get_hash_from_key(value)); } else if (strEqual(suffix, ".style")) { @@ -3025,6 +3036,7 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, SetupFileHash *setup_file_hash, *valid_file_hash; SetupFileHash *extra_file_hash, *empty_file_hash; char *known_token_value = KNOWN_TOKEN_VALUE; + char *base_token_value = UNDEFINED_FILENAME; int i, j, k, l; if (filename == NULL) @@ -3069,6 +3081,23 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, } END_HASH_ITERATION(valid_file_hash, itr) + /* add special base tokens (using prefix match and replace) */ + BEGIN_HASH_ITERATION(valid_file_hash, itr) + { + char *token = HASH_ITERATION_TOKEN(itr); + char *base_token = get_special_base_token(artwork_info, token); + + if (base_token != NULL) + { + /* add base token only if it does not already exist */ + if (getHashEntry(valid_file_hash, base_token) == NULL) + setHashEntry(valid_file_hash, base_token, base_token_value); + + free(base_token); + } + } + END_HASH_ITERATION(valid_file_hash, itr) + /* read parameters for all known config file tokens */ for (i = 0; i < num_file_list_entries; i++) read_token_parameters(valid_file_hash, suffix_list, &file_list[i]);