From: Holger Schemel Date: Sun, 11 Feb 2024 12:54:53 +0000 (+0100) Subject: added engine and graphics initialization functions for native BD engine X-Git-Tag: 4.4.0.0-test-1~389 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=45483d224aed58ac2cf856b0fcdd2d4707084047;p=rocksndiamonds.git added engine and graphics initialization functions for native BD engine --- diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index c0e4d0a3..deb7d692 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -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); diff --git a/src/game_bd/import_bd.h b/src/game_bd/import_bd.h index ef2fbd84..04260e13 100644 --- a/src/game_bd/import_bd.h +++ b/src/game_bd/import_bd.h @@ -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); diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index bd3b0382..991523c5 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -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 // ============================================================================ diff --git a/src/init.c b/src/init.c index fd931a67..f2e78ede 100644 --- a/src/init.c +++ b/src/init.c @@ -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(); diff --git a/src/tools.c b/src/tools.c index 622fa488..cdb7b4cb 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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(); diff --git a/src/tools.h b/src/tools.h index de6fbad3..e2bb9f09 100644 --- a/src/tools.h +++ b/src/tools.h @@ -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);