added engine and graphics initialization functions for native BD engine
authorHolger Schemel <info@artsoft.org>
Sun, 11 Feb 2024 12:54:53 +0000 (13:54 +0100)
committerHolger Schemel <info@artsoft.org>
Sun, 18 Feb 2024 14:57:42 +0000 (15:57 +0100)
src/game_bd/export_bd.h
src/game_bd/import_bd.h
src/game_bd/main_bd.c
src/init.c
src/tools.c
src/tools.h

index c0e4d0a3798b2ce6d5994ca418e6e5c372958515..deb7d692d2786251517cfb4fdb643a731ce4a496 100644 (file)
@@ -81,11 +81,16 @@ extern struct LevelInfo_BD native_bd_level;
 extern struct GraphicInfo_BD graphic_info_bd_object[O_MAX_ALL][8];
 extern struct EngineSnapshotInfo_BD engine_snapshot_bd;
 
+void bd_open_all(void);
+void bd_close_all(void);
+
 int map_action_RND_to_BD(int);
 int map_action_BD_to_RND(int);
 
 boolean checkGameRunning_BD(void);
 
+void InitGfxBuffers_BD(void);
+
 void setLevelInfoToDefaults_BD_Ext(int, int);
 void setLevelInfoToDefaults_BD(void);
 boolean LoadNativeLevel_BD(char *, int, boolean);
index ef2fbd848507eaa11d16c25a4ff0c9677f861668..04260e132008db4cc0e4732586a12f9f925aad20 100644 (file)
@@ -22,6 +22,8 @@
 // functions and definitions exported from main program to game_bd
 // ============================================================================
 
+void InitGraphicInfo_BD(void);
+
 void PlayLevelSound_BD(int, int, int, int);
 void StopSound_BD(int, int);
 boolean isSoundPlaying_BD(int, int);
index bd3b038239c244f5a039de01cdc02a478bb147be..991523c5539e8d616a81508080a982c9543285a4 100644 (file)
@@ -17,6 +17,39 @@ struct LevelInfo_BD native_bd_level;
 struct EngineSnapshotInfo_BD engine_snapshot_bd;
 
 
+// ============================================================================
+// initialization functions
+// ============================================================================
+
+void InitGfxBuffers_BD(void)
+{
+  ReCreateBitmap(&gd_screen_bitmap, SXSIZE, SYSIZE);
+
+  set_cell_size(TILESIZE_VAR);
+  set_play_area(SXSIZE, SYSIZE);
+}
+
+void bd_open_all(void)
+{
+  InitGraphicInfo_BD();
+
+  gd_cave_init();
+  gd_cave_db_init();
+
+  gd_c64_import_init_tables();
+
+  gd_caveset_clear();
+
+  gd_init_keystate();
+
+  gd_sound_init();
+}
+
+void bd_close_all(void)
+{
+}
+
+
 // ============================================================================
 // level file functions
 // ============================================================================
index fd931a67cf5fbd5935eb42ba0414120acc61ad36..f2e78edebab08a46d38b37f73b18953fb0d0657c 100644 (file)
@@ -2446,6 +2446,8 @@ static void ReinitializeGraphics(void)
   InitImageTextures();                 // create textures for certain images
   print_timestamp_time("InitImageTextures");
 
+  InitGraphicInfo_BD();                        // graphic mapping for BD engine
+  print_timestamp_time("InitGraphicInfo_BD");
   InitGraphicInfo_EM();                        // graphic mapping for EM engine
   print_timestamp_time("InitGraphicInfo_EM");
 
@@ -5727,6 +5729,7 @@ void InitGfxBuffers(void)
   // required if door size definitions have changed
   InitGraphicCompatibilityInfo_Doors();
 
+  InitGfxBuffers_BD();
   InitGfxBuffers_EM();
   InitGfxBuffers_SP();
   InitGfxBuffers_MM();
@@ -6628,6 +6631,7 @@ void OpenAll(void)
 
   InitGfxBackground();
 
+  bd_open_all();
   em_open_all();
   sp_open_all();
   mm_open_all();
@@ -6746,6 +6750,7 @@ void CloseAllAndExit(int exit_value)
   FreeAllMusic();
   CloseAudio();                // called after freeing sounds (needed for SDL)
 
+  bd_close_all();
   em_close_all();
   sp_close_all();
 
index 622fa488166603440dd57e3a8afbbcc19a054a2b..cdb7b4cb70bc20bf5a75af60be8df3387c9f7890 100644 (file)
@@ -9688,6 +9688,7 @@ unsigned int InitRND(int seed)
     return InitEngineRandom_RND(seed);
 }
 
+static struct Mapping_BD_to_RND_object bd_object_mapping[O_MAX_ALL];
 static struct Mapping_EM_to_RND_object em_object_mapping[GAME_TILE_MAX];
 static struct Mapping_EM_to_RND_player em_player_mapping[MAX_PLAYERS][PLY_MAX];
 
@@ -10033,6 +10034,82 @@ void getGraphicSourcePlayerExt_EM(struct GraphicInfo_EM *g_em,
                      &g_em->src_x, &g_em->src_y, FALSE);
 }
 
+#define BD_GFX_RANGE(a, n, i)          ((i) >= (a) && (i) < (a) + (n))
+#define BD_GFX_FRAME(b, i)             (((i) - (b)) * 8)
+
+void InitGraphicInfo_BD(void)
+{
+  int i, j;
+
+  // always start with reliable default values
+  for (i = 0; i < O_MAX_ALL; i++)
+  {
+    bd_object_mapping[i].element_rnd = EL_UNKNOWN;
+    bd_object_mapping[i].action = ACTION_DEFAULT;
+    bd_object_mapping[i].direction = MV_NONE;
+  }
+
+  for (i = 0; bd_object_mapping_list[i].element_bd != -1; i++)
+  {
+    int e = bd_object_mapping_list[i].element_bd;
+
+    bd_object_mapping[e].element_rnd = bd_object_mapping_list[i].element_rnd;
+
+    if (bd_object_mapping_list[i].action != -1)
+      bd_object_mapping[e].action = bd_object_mapping_list[i].action;
+
+    if (bd_object_mapping_list[i].direction != -1)
+      bd_object_mapping[e].direction =
+       MV_DIR_FROM_BIT(bd_object_mapping_list[i].direction);
+  }
+
+  for (i = 0; i < O_MAX_ALL; i++)
+  {
+    int element = bd_object_mapping[i].element_rnd;
+    int action = bd_object_mapping[i].action;
+    int direction = bd_object_mapping[i].direction;
+
+    for (j = 0; j < 8; j++)
+    {
+      int effective_element = element;
+      int effective_action = action;
+      int graphic = (el_act_dir2img(effective_element, effective_action,
+                                   direction));
+      struct GraphicInfo *g = &graphic_info[graphic];
+      struct GraphicInfo_BD *g_bd = &graphic_info_bd_object[i][j];
+      Bitmap *src_bitmap;
+      int src_x, src_y;
+      int sync_frame = (BD_GFX_RANGE(O_PRE_PL_1, 3, i)        ? BD_GFX_FRAME(O_PRE_PL_1, i) :
+                       BD_GFX_RANGE(O_PRE_DIA_1, 5, i)       ? BD_GFX_FRAME(O_PRE_DIA_1, i) :
+                       BD_GFX_RANGE(O_PRE_STONE_1, 4, i)     ? BD_GFX_FRAME(O_PRE_STONE_1, i) :
+                       BD_GFX_RANGE(O_PRE_STEEL_1, 4, i)     ? BD_GFX_FRAME(O_PRE_STEEL_1, i) :
+                       BD_GFX_RANGE(O_BOMB_TICK_1, 7, i)     ? BD_GFX_FRAME(O_BOMB_TICK_1, i) :
+                       BD_GFX_RANGE(O_BOMB_EXPL_1, 4, i)     ? BD_GFX_FRAME(O_BOMB_EXPL_1, i) :
+                       BD_GFX_RANGE(O_NUT_EXPL_1, 4, i)      ? BD_GFX_FRAME(O_NUT_EXPL_1, i) :
+                       BD_GFX_RANGE(O_GHOST_EXPL_1, 4, i)    ? BD_GFX_FRAME(O_GHOST_EXPL_1, i) :
+                       BD_GFX_RANGE(O_EXPLODE_1, 5, i)       ? BD_GFX_FRAME(O_EXPLODE_1, i) :
+                       BD_GFX_RANGE(O_PRE_CLOCK_1, 4, i)     ? BD_GFX_FRAME(O_PRE_CLOCK_1, i) :
+                       BD_GFX_RANGE(O_NITRO_EXPL_1, 4, i)    ? BD_GFX_FRAME(O_NITRO_EXPL_1, i) :
+                       BD_GFX_RANGE(O_AMOEBA_2_EXPL_1, 4, i) ? BD_GFX_FRAME(O_AMOEBA_2_EXPL_1, i):
+                       i == O_INBOX_OPEN || i == O_OUTBOX_OPEN ? j :
+                       j * 2);
+      int frame = getAnimationFrame(g->anim_frames,
+                                   g->anim_delay,
+                                   g->anim_mode,
+                                   g->anim_start_frame,
+                                   sync_frame);
+
+      getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE);
+
+      g_bd->bitmap = src_bitmap;
+      g_bd->src_x  = src_x;
+      g_bd->src_y  = src_y;
+      g_bd->width  = TILEX;
+      g_bd->height = TILEY;
+    }
+  }
+}
+
 void InitGraphicInfo_EM(void)
 {
   int i, j, p;
@@ -10940,6 +11017,7 @@ void ChangeViewportPropertiesIfNeeded(void)
   boolean init_gfx_buffers = FALSE;
   boolean init_video_buffer = FALSE;
   boolean init_gadgets_and_anims = FALSE;
+  boolean init_bd_graphics = FALSE;
   boolean init_em_graphics = FALSE;
 
   if (new_win_xsize != WIN_XSIZE ||
@@ -11038,7 +11116,8 @@ void ChangeViewportPropertiesIfNeeded(void)
       // changing tile size invalidates scroll values of engine snapshots
       FreeEngineSnapshotSingle();
 
-      // changing tile size requires update of graphic mapping for EM engine
+      // changing tile size requires update of graphic mapping for BD/EM engine
+      init_bd_graphics = TRUE;
       init_em_graphics = TRUE;
     }
 
@@ -11105,6 +11184,11 @@ void ChangeViewportPropertiesIfNeeded(void)
     InitGlobalAnimations();
   }
 
+  if (init_bd_graphics)
+  {
+    InitGraphicInfo_BD();
+  }
+
   if (init_em_graphics)
   {
     InitGraphicInfo_EM();
index de6fbad359ace3b4922f668f62ad59c905c6cd70..e2bb9f09cf16815403fffdb6ac8a699d75ff4f7a 100644 (file)
@@ -277,6 +277,8 @@ int getBeltSwitchElementFromBeltNrAndBeltDirNr(int, int);
 int getBeltSwitchElementFromBeltNrAndBeltDir(int, int);
 
 unsigned int InitRND(int);
+
+void InitGraphicInfo_BD(void);
 void InitGraphicInfo_EM(void);
 
 void PlayMenuSoundExt(int);