X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Finit.c;h=114b177fb1578c19f30248069d85bf6a23acb350;hp=44b0a5cbb10da6c37d001c37d0818bad679d1abe;hb=5e195517fdcbad3043eff72d91399f6a5e604d8b;hpb=7bcc6aa833d64b21f78793dd00ed4c1356b98d05 diff --git a/src/init.c b/src/init.c index 44b0a5cb..114b177f 100644 --- a/src/init.c +++ b/src/init.c @@ -333,6 +333,8 @@ static int getFontBitmapID(int font_nr) special = game_status; else if (game_status == GAME_MODE_PSEUDO_TYPENAME) special = GFX_SPECIAL_ARG_MAIN; + else if (game_status == GAME_MODE_PSEUDO_TYPENAMES) + special = GFX_SPECIAL_ARG_NAMES; if (special != -1) return font_info[font_nr].special_bitmap_id[special]; @@ -1695,6 +1697,7 @@ static void InitGraphicInfo(void) IMG_BACKGROUND_TITLE_INITIAL, IMG_BACKGROUND_TITLE, IMG_BACKGROUND_MAIN, + IMG_BACKGROUND_NAMES, IMG_BACKGROUND_LEVELS, IMG_BACKGROUND_LEVELNR, IMG_BACKGROUND_SCORES, @@ -4661,7 +4664,7 @@ void InitElementPropertiesEngine(int engine_version) i == EL_BLACK_ORB)); // ---------- COULD_MOVE_INTO_ACID ---------------------------------------- - SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, (ELEM_IS_PLAYER(i) || + SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, (IS_PLAYER_ELEMENT(i) || CAN_MOVE(i) || IS_CUSTOM_ELEMENT(i))); @@ -4900,7 +4903,10 @@ static void InitGlobal(void) global.autoplay_leveldir = NULL; global.patchtapes_leveldir = NULL; global.convert_leveldir = NULL; - global.create_images_dir = NULL; + global.dumplevel_leveldir = NULL; + global.dumptape_leveldir = NULL; + global.create_sketch_images_dir = NULL; + global.create_collect_images_dir = NULL; global.frames_per_second = 0; global.show_frames_per_second = FALSE; @@ -4909,6 +4915,8 @@ static void InitGlobal(void) global.anim_status = global.anim_status_next = GAME_MODE_LOADING; global.use_envelope_request = FALSE; + + global.user_names = NULL; } static void Execute_Command(char *command) @@ -5010,39 +5018,70 @@ static void Execute_Command(char *command) { char *filename = &command[11]; - if (!fileExists(filename)) + if (fileExists(filename)) + { + LoadLevelFromFilename(&level, filename); + DumpLevel(&level); + + exit(0); + } + + char *leveldir = getStringCopy(filename); // read command parameters + char *level_nr = strchr(leveldir, ' '); + + if (level_nr == NULL) Fail("cannot open file '%s'", filename); - LoadLevelFromFilename(&level, filename); - DumpLevel(&level); + *level_nr++ = '\0'; - exit(0); + global.dumplevel_leveldir = leveldir; + global.dumplevel_level_nr = atoi(level_nr); + + program.headless = TRUE; } else if (strPrefix(command, "dump tape ")) { char *filename = &command[10]; - if (!fileExists(filename)) + if (fileExists(filename)) + { + LoadTapeFromFilename(filename); + DumpTape(&tape); + + exit(0); + } + + char *leveldir = getStringCopy(filename); // read command parameters + char *level_nr = strchr(leveldir, ' '); + + if (level_nr == NULL) Fail("cannot open file '%s'", filename); - LoadTapeFromFilename(filename); - DumpTape(&tape); + *level_nr++ = '\0'; - exit(0); + global.dumptape_leveldir = leveldir; + global.dumptape_level_nr = atoi(level_nr); + + program.headless = TRUE; } else if (strPrefix(command, "autoplay ") || strPrefix(command, "autoffwd ") || strPrefix(command, "autowarp ") || strPrefix(command, "autotest ") || + strPrefix(command, "autosave ") || + strPrefix(command, "autoupload ") || strPrefix(command, "autofix ")) { - char *str_ptr = getStringCopy(&command[8]); // read command parameters + char *arg_ptr = strchr(command, ' '); + char *str_ptr = getStringCopy(arg_ptr); // read command parameters global.autoplay_mode = (strPrefix(command, "autoplay") ? AUTOPLAY_MODE_PLAY : strPrefix(command, "autoffwd") ? AUTOPLAY_MODE_FFWD : strPrefix(command, "autowarp") ? AUTOPLAY_MODE_WARP : strPrefix(command, "autotest") ? AUTOPLAY_MODE_TEST : + strPrefix(command, "autosave") ? AUTOPLAY_MODE_SAVE : + strPrefix(command, "autoupload") ? AUTOPLAY_MODE_UPLOAD : strPrefix(command, "autofix") ? AUTOPLAY_MODE_FIX : AUTOPLAY_MODE_NONE); @@ -5156,13 +5195,21 @@ static void Execute_Command(char *command) program.headless = TRUE; } - else if (strPrefix(command, "create images ")) + else if (strPrefix(command, "create sketch images ")) + { + global.create_sketch_images_dir = getStringCopy(&command[21]); + + if (access(global.create_sketch_images_dir, W_OK) != 0) + Fail("image target directory '%s' not found or not writable", + global.create_sketch_images_dir); + } + else if (strPrefix(command, "create collect image ")) { - global.create_images_dir = getStringCopy(&command[14]); + global.create_collect_images_dir = getStringCopy(&command[21]); - if (access(global.create_images_dir, W_OK) != 0) + if (access(global.create_collect_images_dir, W_OK) != 0) Fail("image target directory '%s' not found or not writable", - global.create_images_dir); + global.create_collect_images_dir); } else if (strPrefix(command, "create CE image ")) { @@ -5181,8 +5228,10 @@ static void Execute_Command(char *command) static void InitSetup(void) { + LoadUserNames(); // global user names + LoadUserSetup(); // global user number + LoadSetup(); // global setup info - LoadSetup_AutoSetup(); // global auto setup info // set some options from setup file @@ -5197,7 +5246,9 @@ static void InitGameInfo(void) { game.restart_level = FALSE; game.restart_game_message = NULL; + game.request_active = FALSE; + game.request_active_or_moving = FALSE; } static void InitPlayerInfo(void) @@ -5478,7 +5529,7 @@ static void InitGfx(void) DrawProgramInfo(); - DrawInitText("Loading graphics", 120, FC_GREEN); + DrawInitTextHead("Loading graphics"); // initialize settings for busy animation with default values int parameter[NUM_GFX_ARGS]; @@ -5901,7 +5952,8 @@ static void InitOverrideArtwork(void) static char *getNewArtworkIdentifier(int type) { - static char *leveldir_current_identifier[3] = { NULL, NULL, NULL }; + static char *last_leveldir_identifier[3] = { NULL, NULL, NULL }; + static char *last_artwork_identifier[3] = { NULL, NULL, NULL }; static boolean last_override_level_artwork[3] = { FALSE, FALSE, FALSE }; static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE }; static boolean initialized[3] = { FALSE, FALSE, FALSE }; @@ -5936,16 +5988,15 @@ static char *getNewArtworkIdentifier(int type) else artwork_current_identifier = setup_artwork_set; - /* 2nd step: check if it is really needed to reload artwork set ------------------------------------------------------------ */ // ---------- reload if level set and also artwork set has changed ---------- - if (leveldir_current_identifier[type] != leveldir_identifier && + if (last_leveldir_identifier[type] != leveldir_identifier && (last_has_level_artwork_set[type] || has_level_artwork_set)) artwork_new_identifier = artwork_current_identifier; - leveldir_current_identifier[type] = leveldir_identifier; + last_leveldir_identifier[type] = leveldir_identifier; last_has_level_artwork_set[type] = has_level_artwork_set; // ---------- reload if "override artwork" setting has changed -------------- @@ -5955,11 +6006,13 @@ static char *getNewArtworkIdentifier(int type) last_override_level_artwork[type] = setup_override_artwork; // ---------- reload if current artwork identifier has changed -------------- - if (!strEqual(ARTWORK_CURRENT_IDENTIFIER(artwork, type), - artwork_current_identifier)) + if (!strEqual(last_artwork_identifier[type], artwork_current_identifier)) artwork_new_identifier = artwork_current_identifier; - *(ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type))= artwork_current_identifier; + // (we cannot compare string pointers here, so copy string content itself) + setString(&last_artwork_identifier[type], artwork_current_identifier); + + *(ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)) = artwork_current_identifier; // ---------- do not reload directly after starting ------------------------- if (!initialized[type]) @@ -5983,8 +6036,8 @@ void ReloadCustomArtwork(int force_reload) InitOverrideArtwork(); - force_reload_gfx |= AdjustGraphicsForEMC(); - force_reload_snd |= AdjustSoundsForEMC(); + AdjustGraphicsForEMC(); + AdjustSoundsForEMC(); gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS); snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS); @@ -6142,14 +6195,16 @@ void OpenAll(void) InitGlobal(); // initialize some global variables + InitRND(NEW_RANDOMIZE); + InitSimpleRandom(NEW_RANDOMIZE); + InitBetterRandom(NEW_RANDOMIZE); + print_timestamp_time("[init global stuff]"); InitSetup(); print_timestamp_time("[init setup/config stuff (1)]"); - InitScoresInfo(); - if (options.execute_command) Execute_Command(options.execute_command); @@ -6179,9 +6234,6 @@ void OpenAll(void) InitMixer(); print_timestamp_time("[init setup/config stuff (6)]"); - InitRND(NEW_RANDOMIZE); - InitSimpleRandom(NEW_RANDOMIZE); - InitJoysticks(); print_timestamp_time("[init setup/config stuff]"); @@ -6246,11 +6298,26 @@ void OpenAll(void) ConvertLevels(); return; } - else if (global.create_images_dir) + else if (global.dumplevel_leveldir) + { + DumpLevels(); + return; + } + else if (global.dumptape_leveldir) + { + DumpTapes(); + return; + } + else if (global.create_sketch_images_dir) { CreateLevelSketchImages(); return; } + else if (global.create_collect_images_dir) + { + CreateCollectElementImages(); + return; + } InitNetworkServer(); @@ -6264,6 +6331,9 @@ void OpenAll(void) print_timestamp_done("OpenAll"); + if (setup.ask_for_remaining_tapes) + setup.ask_for_uploading_tapes = TRUE; + DrawMainMenu(); #if 0 @@ -6285,8 +6355,44 @@ void OpenAll(void) #endif } +static boolean WaitForApiThreads(void) +{ + unsigned int thread_delay = 0; + unsigned int thread_delay_value = 10000; + + if (program.api_thread_count == 0) + return TRUE; + + // deactivate global animations (not accessible in game state "loading") + setup.toons = FALSE; + + // set game state to "loading" to be able to show busy animation + SetGameStatus(GAME_MODE_LOADING); + + ResetDelayCounter(&thread_delay); + + // wait for threads to finish (and fail on timeout) + while (program.api_thread_count > 0) + { + if (DelayReached(&thread_delay, thread_delay_value)) + { + Error("failed waiting for threads - TIMEOUT"); + + return FALSE; + } + + UPDATE_BUSY_STATE(); + + Delay(20); + } + + return TRUE; +} + void CloseAllAndExit(int exit_value) { + WaitForApiThreads(); + StopSounds(); FreeAllSounds(); FreeAllMusic();