removed reloading artwork set for changed level set if not required (again)
[rocksndiamonds.git] / src / init.c
index 3f8c253b14c014b904424b6ba23351ddbcb03482..121fab26e27e7665126921834d036fa22dd83260 100644 (file)
@@ -2236,6 +2236,13 @@ static void InitMusicInfo(void)
   }
 }
 
+
+static void InitGameInfoFromArtworkInfo(void)
+{
+  // special case: store initial value of custom artwork setting
+  game.use_masked_elements_initial = game.use_masked_elements;
+}
+
 static void ReinitializeGraphics(void)
 {
   print_timestamp_init("ReinitializeGraphics");
@@ -2279,6 +2286,8 @@ static void ReinitializeGraphics(void)
   InitDoors();
   print_timestamp_time("InitDoors");
 
+  InitGameInfoFromArtworkInfo();
+
   print_timestamp_done("ReinitializeGraphics");
 }
 
@@ -3000,6 +3009,22 @@ void InitElementPropertiesStatic(void)
   static int ep_walkable_over[] =
   {
     EL_EMPTY_SPACE,
+    EL_EMPTY_SPACE_1,
+    EL_EMPTY_SPACE_2,
+    EL_EMPTY_SPACE_3,
+    EL_EMPTY_SPACE_4,
+    EL_EMPTY_SPACE_5,
+    EL_EMPTY_SPACE_6,
+    EL_EMPTY_SPACE_7,
+    EL_EMPTY_SPACE_8,
+    EL_EMPTY_SPACE_9,
+    EL_EMPTY_SPACE_10,
+    EL_EMPTY_SPACE_11,
+    EL_EMPTY_SPACE_12,
+    EL_EMPTY_SPACE_13,
+    EL_EMPTY_SPACE_14,
+    EL_EMPTY_SPACE_15,
+    EL_EMPTY_SPACE_16,
     EL_SP_EMPTY_SPACE,
     EL_SOKOBAN_FIELD_EMPTY,
     EL_EXIT_OPEN,
@@ -3297,6 +3322,29 @@ void InitElementPropertiesStatic(void)
     -1
   };
 
+  static int ep_empty_space[] =
+  {
+    EL_EMPTY_SPACE,
+    EL_EMPTY_SPACE_1,
+    EL_EMPTY_SPACE_2,
+    EL_EMPTY_SPACE_3,
+    EL_EMPTY_SPACE_4,
+    EL_EMPTY_SPACE_5,
+    EL_EMPTY_SPACE_6,
+    EL_EMPTY_SPACE_7,
+    EL_EMPTY_SPACE_8,
+    EL_EMPTY_SPACE_9,
+    EL_EMPTY_SPACE_10,
+    EL_EMPTY_SPACE_11,
+    EL_EMPTY_SPACE_12,
+    EL_EMPTY_SPACE_13,
+    EL_EMPTY_SPACE_14,
+    EL_EMPTY_SPACE_15,
+    EL_EMPTY_SPACE_16,
+
+    -1
+  };
+
   static int ep_player[] =
   {
     EL_PLAYER_1,
@@ -4099,6 +4147,22 @@ void InitElementPropertiesStatic(void)
   static int ep_inactive[] =
   {
     EL_EMPTY,
+    EL_EMPTY_SPACE_1,
+    EL_EMPTY_SPACE_2,
+    EL_EMPTY_SPACE_3,
+    EL_EMPTY_SPACE_4,
+    EL_EMPTY_SPACE_5,
+    EL_EMPTY_SPACE_6,
+    EL_EMPTY_SPACE_7,
+    EL_EMPTY_SPACE_8,
+    EL_EMPTY_SPACE_9,
+    EL_EMPTY_SPACE_10,
+    EL_EMPTY_SPACE_11,
+    EL_EMPTY_SPACE_12,
+    EL_EMPTY_SPACE_13,
+    EL_EMPTY_SPACE_14,
+    EL_EMPTY_SPACE_15,
+    EL_EMPTY_SPACE_16,
     EL_SAND,
     EL_WALL,
     EL_BD_WALL,
@@ -4348,6 +4412,7 @@ void InitElementPropertiesStatic(void)
     EL_INTERNAL_CASCADE_STEEL_CHARS_ACTIVE,
     EL_INTERNAL_CASCADE_CE_ACTIVE,
     EL_INTERNAL_CASCADE_GE_ACTIVE,
+    EL_INTERNAL_CASCADE_ES_ACTIVE,
     EL_INTERNAL_CASCADE_REF_ACTIVE,
     EL_INTERNAL_CASCADE_USER_ACTIVE,
     EL_INTERNAL_CASCADE_DYNAMIC_ACTIVE,
@@ -4371,6 +4436,7 @@ void InitElementPropertiesStatic(void)
     EL_INTERNAL_CASCADE_STEEL_CHARS,
     EL_INTERNAL_CASCADE_CE,
     EL_INTERNAL_CASCADE_GE,
+    EL_INTERNAL_CASCADE_ES,
     EL_INTERNAL_CASCADE_REF,
     EL_INTERNAL_CASCADE_USER,
     EL_INTERNAL_CASCADE_DYNAMIC,
@@ -4428,6 +4494,7 @@ void InitElementPropertiesStatic(void)
     { ep_can_explode,                  EP_CAN_EXPLODE                  },
     { ep_gravity_reachable,            EP_GRAVITY_REACHABLE            },
 
+    { ep_empty_space,                  EP_EMPTY_SPACE                  },
     { ep_player,                       EP_PLAYER                       },
     { ep_can_pass_magic_wall,          EP_CAN_PASS_MAGIC_WALL          },
     { ep_can_pass_dc_magic_wall,       EP_CAN_PASS_DC_MAGIC_WALL       },
@@ -4689,7 +4756,7 @@ void InitElementPropertiesEngine(int engine_version)
     // ---------- CAN_BE_CLONED_BY_ANDROID ------------------------------------
     for (j = 0; j < level.num_android_clone_elements; j++)
       SET_PROPERTY(i, EP_CAN_BE_CLONED_BY_ANDROID,
-                  (i != EL_EMPTY &&
+                  (!IS_EMPTY(i) &&
                    IS_EQUAL_OR_IN_GROUP(i, level.android_clone_element[j])));
 
     // ---------- CAN_CHANGE --------------------------------------------------
@@ -5232,7 +5299,6 @@ static void InitSetup(void)
   LoadUserSetup();                             // global user number
 
   LoadSetup();                                 // global setup info
-  LoadSetup_AutoSetup();                       // global auto setup info
 
   // set some options from setup file
 
@@ -5250,6 +5316,8 @@ static void InitGameInfo(void)
 
   game.request_active = FALSE;
   game.request_active_or_moving = FALSE;
+
+  game.use_masked_elements_initial = FALSE;
 }
 
 static void InitPlayerInfo(void)
@@ -5521,6 +5589,8 @@ static void InitGfx(void)
   InitGfxCustomArtworkInfo();
   InitGfxOtherSettings();
 
+  InitGfxTileSizeInfo(TILESIZE, TILESIZE);
+
   bitmap_font_initial = LoadCustomImage(filename_font_initial);
 
   for (j = 0; j < NUM_INITIAL_FONTS; j++)
@@ -5530,7 +5600,9 @@ static void InitGfx(void)
 
   DrawProgramInfo();
 
-  DrawInitText("Loading graphics", 120, FC_GREEN);
+  DrawInitTextHead("Loading graphics");
+
+  InitMenuDesignSettings_Static();
 
   // initialize settings for busy animation with default values
   int parameter[NUM_GFX_ARGS];
@@ -5573,6 +5645,9 @@ static void InitGfx(void)
        }
       }
 
+      // read values from custom graphics config file
+      InitMenuDesignSettings_FromHash(setup_file_hash, FALSE);
+
       freeSetupFileHash(setup_file_hash);
     }
   }
@@ -5620,8 +5695,6 @@ static void InitGfx(void)
   init.busy.width  = anim_initial.width;
   init.busy.height = anim_initial.height;
 
-  InitMenuDesignSettings_Static();
-
   InitGfxDrawBusyAnimFunction(DrawInitAnim);
   InitGfxDrawGlobalAnimFunction(DrawGlobalAnimations);
   InitGfxDrawGlobalBorderFunction(DrawMaskedBorderToTarget);
@@ -5956,7 +6029,7 @@ static char *getNewArtworkIdentifier(int type)
   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 last_has_custom_artwork_set[3] = { FALSE, FALSE, FALSE };
   static boolean initialized[3] = { FALSE, FALSE, FALSE };
   TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
   boolean setup_override_artwork = GFX_OVERRIDE_ARTWORK(type);
@@ -5965,6 +6038,9 @@ static char *getNewArtworkIdentifier(int type)
   // !!! setLevelArtworkDir() should be moved to an earlier stage !!!
   char *leveldir_artwork_set = setLevelArtworkDir(artwork_first_node);
   boolean has_level_artwork_set = (leveldir_artwork_set != NULL);
+  TreeInfo *custom_artwork_set =
+    getTreeInfoFromIdentifier(artwork_first_node, leveldir_identifier);
+  boolean has_custom_artwork_set = (custom_artwork_set != NULL);
   char *artwork_current_identifier;
   char *artwork_new_identifier = NULL; // default: nothing has changed
 
@@ -5982,9 +6058,9 @@ static char *getNewArtworkIdentifier(int type)
 
   if (setup_override_artwork)
     artwork_current_identifier = setup_artwork_set;
-  else if (leveldir_artwork_set != NULL)
+  else if (has_level_artwork_set)
     artwork_current_identifier = leveldir_artwork_set;
-  else if (getTreeInfoFromIdentifier(artwork_first_node, leveldir_identifier))
+  else if (has_custom_artwork_set)
     artwork_current_identifier = leveldir_identifier;
   else
     artwork_current_identifier = setup_artwork_set;
@@ -5994,11 +6070,11 @@ static char *getNewArtworkIdentifier(int type)
 
   // ---------- reload if level set and also artwork set has changed ----------
   if (last_leveldir_identifier[type] != leveldir_identifier &&
-      (last_has_level_artwork_set[type] || has_level_artwork_set))
+      (last_has_custom_artwork_set[type] || has_custom_artwork_set))
     artwork_new_identifier = artwork_current_identifier;
 
   last_leveldir_identifier[type] = leveldir_identifier;
-  last_has_level_artwork_set[type] = has_level_artwork_set;
+  last_has_custom_artwork_set[type] = has_custom_artwork_set;
 
   // ---------- reload if "override artwork" setting has changed --------------
   if (last_override_level_artwork[type] != setup_override_artwork)
@@ -6198,6 +6274,7 @@ void OpenAll(void)
 
   InitRND(NEW_RANDOMIZE);
   InitSimpleRandom(NEW_RANDOMIZE);
+  InitBetterRandom(NEW_RANDOMIZE);
 
   print_timestamp_time("[init global stuff]");
 
@@ -6331,6 +6408,9 @@ void OpenAll(void)
 
   print_timestamp_done("OpenAll");
 
+  if (setup.ask_for_remaining_tapes)
+    setup.ask_for_uploading_tapes = TRUE;
+
   DrawMainMenu();
 
 #if 0
@@ -6352,8 +6432,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();