From 5299208291dc3032954b8b2242be2be9c7b6c7c0 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 15 Jun 2022 11:41:47 -0700 Subject: [PATCH] Macros for `Entranceinfo.field` (#1270) * Macros for `Entranceinfo.field` * `ENTRANCE_INFO_FIELD_` -> `ENTRANCE_INFO_` * Remove mentioning the transition types being "default" * comment on macros what they are for * Shorten "transition" -> "trans" for `EntranceInfo.field` usage --- include/tables/entrance_table.h | 8 ++++---- include/z64.h | 14 ++++++++++++++ src/code/z_play.c | 8 ++++---- src/code/z_scene_table.c | 11 +++++++---- src/overlays/actors/ovl_player_actor/z_player.c | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/include/tables/entrance_table.h b/include/tables/entrance_table.h index c1b37674ab..09c1c8835b 100644 --- a/include/tables/entrance_table.h +++ b/include/tables/entrance_table.h @@ -7,12 +7,12 @@ * - Argument 3: Spawn number for this entrance * - Argument 4: Toggle if bgm should continue during the transition using this entrance (true or false) * - Argument 5: Toggle if a title card should display when using this entrance (true or false) - * - Argument 6: Transition type when entering using this entrance - * - Argument 7: Transition type when exiting using this entrance - * + * - Argument 6: Transition type when entering using this entrance (second half of a scene transition) + * - Argument 7: Transition type when exiting using this entrance (first half of a scene transition) + * * WARNING: Due to how the entrance system is implemented, entries within the same group of scene setups are NOT shiftable. * Groups of scene setups are indicated by line breaks. - * + * * Only the first entrance within a group of setups is expected to be referenced in code. * The entrance system will apply the offset on its own to access the correct entrance for a given setup. */ diff --git a/include/z64.h b/include/z64.h index b7aa80a95b..505859a202 100644 --- a/include/z64.h +++ b/include/z64.h @@ -1344,6 +1344,20 @@ typedef struct { /* 0x24 */ s16 unk_24; } struct_80034A14_arg1; // size = 0x28 +// Macros for `EntranceInfo.field` +#define ENTRANCE_INFO_CONTINUE_BGM_FLAG (1 << 15) +#define ENTRANCE_INFO_DISPLAY_TITLE_CARD_FLAG (1 << 14) +#define ENTRANCE_INFO_END_TRANS_TYPE_MASK 0x3F80 +#define ENTRANCE_INFO_END_TRANS_TYPE_SHIFT 7 +#define ENTRANCE_INFO_END_TRANS_TYPE(field) \ + (((field) >> ENTRANCE_INFO_END_TRANS_TYPE_SHIFT) \ + & (ENTRANCE_INFO_END_TRANS_TYPE_MASK >> ENTRANCE_INFO_END_TRANS_TYPE_SHIFT)) +#define ENTRANCE_INFO_START_TRANS_TYPE_MASK 0x7F +#define ENTRANCE_INFO_START_TRANS_TYPE_SHIFT 0 +#define ENTRANCE_INFO_START_TRANS_TYPE(field) \ + (((field) >> ENTRANCE_INFO_START_TRANS_TYPE_SHIFT) \ + & (ENTRANCE_INFO_START_TRANS_TYPE_MASK >> ENTRANCE_INFO_START_TRANS_TYPE_SHIFT)) + typedef struct { /* 0x00 */ s8 scene; /* 0x01 */ s8 spawn; diff --git a/src/code/z_play.c b/src/code/z_play.c index dd8c424660..ca13477ea7 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -349,9 +349,8 @@ void Play_Init(GameState* thisx) { if (gSaveContext.gameMode != 1) { if (gSaveContext.nextTransitionType == TRANS_NEXT_TYPE_DEFAULT) { - // fade in - this->transitionType = - (gEntranceTable[((void)0, gSaveContext.entranceIndex) + tempSetupIndex].field >> 7) & 0x7F; + this->transitionType = ENTRANCE_INFO_END_TRANS_TYPE( + gEntranceTable[((void)0, gSaveContext.entranceIndex) + tempSetupIndex].field); } else { this->transitionType = gSaveContext.nextTransitionType; gSaveContext.nextTransitionType = TRANS_NEXT_TYPE_DEFAULT; @@ -490,7 +489,8 @@ void Play_Update(PlayState* this) { } // fade out bgm if "continue bgm" flag is not set - if (!(gEntranceTable[this->nextEntranceIndex + sceneSetupIndex].field & 0x8000)) { + if (!(gEntranceTable[this->nextEntranceIndex + sceneSetupIndex].field & + ENTRANCE_INFO_CONTINUE_BGM_FLAG)) { // "Sound initalized. 111" osSyncPrintf("\n\n\nサウンドイニシャル来ました。111"); if ((this->transitionType < TRANS_TYPE_MAX) && !Environment_IsForcedSequenceDisabled()) { diff --git a/src/code/z_scene_table.c b/src/code/z_scene_table.c index 1477c6d5ff..91fc9d360c 100644 --- a/src/code/z_scene_table.c +++ b/src/code/z_scene_table.c @@ -24,9 +24,12 @@ #include "overlays/actors/ovl_Bg_Dodoago/z_bg_dodoago.h" // Entrance Table definition -#define DEFINE_ENTRANCE(_0, scene, spawn, continueBgm, displayTitleCard, fadeIn, fadeOut) \ - { scene, spawn, \ - ((continueBgm & 1) << 15) | ((displayTitleCard & 1) << 14) | ((fadeIn & 0x7F) << 7) | (fadeOut & 0x7F) }, +#define DEFINE_ENTRANCE(_0, scene, spawn, continueBgm, displayTitleCard, endTransType, startTransType) \ + { scene, spawn, \ + (((continueBgm) ? ENTRANCE_INFO_CONTINUE_BGM_FLAG : 0) | \ + ((displayTitleCard) ? ENTRANCE_INFO_DISPLAY_TITLE_CARD_FLAG : 0) | \ + (((endTransType) << ENTRANCE_INFO_END_TRANS_TYPE_SHIFT) & ENTRANCE_INFO_END_TRANS_TYPE_MASK) | \ + (((startTransType) << ENTRANCE_INFO_START_TRANS_TYPE_SHIFT) & ENTRANCE_INFO_START_TRANS_TYPE_MASK)) }, EntranceInfo gEntranceTable[] = { #include "tables/entrance_table.h" @@ -90,7 +93,7 @@ void Scene_SetTransitionForNextEntrance(PlayState* play) { } } - play->transitionType = gEntranceTable[entranceIndex].field & 0x7F; // Fade out + play->transitionType = ENTRANCE_INFO_START_TRANS_TYPE(gEntranceTable[entranceIndex].field); } void Scene_DrawConfigDefault(PlayState* play) { diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index df8f665818..e5976072fd 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -9343,7 +9343,7 @@ void Player_Init(Actor* thisx, PlayState* play2) { if ((titleFileSize != 0) && gSaveContext.showTitleCard) { if ((gSaveContext.sceneSetupIndex < 4) && (gEntranceTable[((void)0, gSaveContext.entranceIndex) + ((void)0, gSaveContext.sceneSetupIndex)].field & - 0x4000) && + ENTRANCE_INFO_DISPLAY_TITLE_CARD_FLAG) && ((play->sceneNum != SCENE_DDAN) || GET_EVENTCHKINF(EVENTCHKINF_B0)) && ((play->sceneNum != SCENE_NIGHT_SHOP) || GET_EVENTCHKINF(EVENTCHKINF_25))) { TitleCard_InitPlaceName(play, &play->actorCtx.titleCtx, this->giObjectSegment, 160, 120, 144, 24, 20);