From eed1293624882d364ef0b9e4e8f05b538fced0ea Mon Sep 17 00:00:00 2001 From: Arceveti Date: Sat, 10 Dec 2022 18:38:32 -0500 Subject: [PATCH] Replace gEnteredPaintingObject with a MarioState field --- include/types.h | 1 + src/game/behaviors/clock_arm.inc.c | 10 ++++++---- src/game/level_update.c | 8 ++++---- src/game/mario.c | 2 ++ src/game/object_list_processor.c | 1 - src/game/paintings.c | 32 +++++++++++++----------------- src/game/paintings.h | 3 --- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/include/types.h b/include/types.h index cd9dcd57c..4397aac83 100644 --- a/include/types.h +++ b/include/types.h @@ -473,6 +473,7 @@ struct MarioState { /*0xC0*/ f32 quicksandDepth; /*0xC4*/ f32 windGravity; // -- HackerSM64 MarioState fields begin -- + struct Object *paintingObj; #ifdef BREATH_METER s16 breath; u8 breathCounter; diff --git a/src/game/behaviors/clock_arm.inc.c b/src/game/behaviors/clock_arm.inc.c index 2f7597545..f0986c27b 100644 --- a/src/game/behaviors/clock_arm.inc.c +++ b/src/game/behaviors/clock_arm.inc.c @@ -4,21 +4,23 @@ * Main loop of the hour and minute hands of the Tick Tock Clock painting. */ void bhv_rotating_clock_arm_loop(void) { - u16 rollAngle = o->oFaceAngleRoll; + struct Object *paintingObj = gMarioState->paintingObj; if (o->oAction == TTC_PAINTING_CLOCK_ARM_WAIT) { // Make sure Mario not in a painting & 3 frames pass before allowing him to // change the Tick Tock Clock speed setting. // Probably a safety check for when you leave the level through the painting // to make sure the setting isn't accidentally locked in as you fly out. - if (gEnteredPaintingObject == NULL && o->oTimer > 3) { + if (paintingObj == NULL && o->oTimer > 3) { o->oAction++; // TTC_PAINTING_CLOCK_ARM_ACT_MOVING } } else if (o->oAction == TTC_PAINTING_CLOCK_ARM_ACT_MOVING) { // If Mario is entering the Tick Tock Clock painting... - if (gEnteredPaintingObject != NULL && GET_BPARAM1(gEnteredPaintingObject->oBehParams) == PAINTING_ID_CASTLE_TTC) { + if (paintingObj != NULL && GET_BPARAM1(paintingObj->oBehParams) == PAINTING_ID_CASTLE_TTC) { // And this is the minute hand... if (cur_obj_has_behavior(bhvClockMinuteHand)) { + u16 rollAngle = o->oFaceAngleRoll; + // Set Tick Tick Clock's speed based on the angle of the hand. // The angle actually counting down from 0xFFFF to 0 so // 11 o'clock is a small value and 1 o'clock is a large value. @@ -40,7 +42,7 @@ void bhv_rotating_clock_arm_loop(void) { o->oAction++; // TTC_PAINTING_CLOCK_ARM_ACT_STOPPED } } else if (o->oAction == TTC_PAINTING_CLOCK_ARM_ACT_STOPPED) { - if (gEnteredPaintingObject == NULL) { + if (paintingObj == NULL) { o->oAction = TTC_PAINTING_CLOCK_ARM_ACT_MOVING; } } diff --git a/src/game/level_update.c b/src/game/level_update.c index dcfeefee9..f95a737fc 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -637,10 +637,10 @@ s8 gPaintingEjectSoundPlayed = FALSE; * Check is Mario has entered a painting, and if so, initiate a warp. */ void initiate_painting_warp(void) { - struct ObjectWarpNode *warpNode = NULL; + struct Object *paintingObj = gMarioState->paintingObj; - if (gEnteredPaintingObject != NULL) { - warpNode = area_get_warp_node(GET_BPARAM2(gEnteredPaintingObject->oBehParams)); + if (paintingObj != NULL) { + struct ObjectWarpNode *warpNode = area_get_warp_node(GET_BPARAM2(paintingObj->oBehParams)); if (warpNode != NULL) { if (gMarioState->action & ACT_FLAG_INTANGIBLE) { @@ -673,7 +673,7 @@ void initiate_painting_warp(void) { queue_rumble_data(80, 70); queue_rumble_decay(1); #endif - cutscene_object(CUTSCENE_ENTER_PAINTING, gEnteredPaintingObject); + cutscene_object(CUTSCENE_ENTER_PAINTING, paintingObj); } } } else { diff --git a/src/game/mario.c b/src/game/mario.c index ebf3bb268..bd6a824dd 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -1824,6 +1824,8 @@ void init_mario(void) { gMarioState->riddenObj = NULL; gMarioState->usedObj = NULL; + gMarioState->paintingObj = NULL; + gMarioState->waterLevel = find_water_level(gMarioSpawnInfo->startPos[0], gMarioSpawnInfo->startPos[2]); gMarioState->area = gCurrentArea; diff --git a/src/game/object_list_processor.c b/src/game/object_list_processor.c index 5e7718838..97382e902 100644 --- a/src/game/object_list_processor.c +++ b/src/game/object_list_processor.c @@ -526,7 +526,6 @@ void spawn_objects_from_info(UNUSED s32 unused, struct SpawnInfo *spawnInfo) { void clear_objects(void) { s32 i; - gEnteredPaintingObject = NULL; gTHIWaterDrained = 0; gTimeStopState = 0; gMarioObject = NULL; diff --git a/src/game/paintings.c b/src/game/paintings.c index 290811fa1..fb10e5ae4 100644 --- a/src/game/paintings.c +++ b/src/game/paintings.c @@ -78,11 +78,6 @@ const struct Painting *sPaintings[] = { /* PAINTING_ID_TTM_SLIDE */ &ttm_slide_painting, }; -/** - * The id of the painting Mario has entered. - */ -struct Object *gEnteredPaintingObject = NULL; - /** * When a painting is rippling, this mesh is generated each frame using the Painting's parameters. * @@ -807,7 +802,7 @@ void bhv_painting_init(void) { /** * Check for Mario entering the painting. */ -void painting_update_mario_pos(struct Object *obj) { +void painting_update_mario_pos_and_flags(struct Object *obj) { if (!gMarioObject) { return; } @@ -846,6 +841,9 @@ void painting_update_mario_pos(struct Object *obj) { rippleFlags |= RIPPLE_FLAG_ENTER; } } + + obj->oPaintingLocalMarioPosX = marioLocalPos[0]; + obj->oPaintingLocalMarioPosY = marioLocalPos[1]; s16 lastFlags = obj->oPaintingCurrFlags; @@ -855,9 +853,15 @@ void painting_update_mario_pos(struct Object *obj) { // changedFlags is true if currFlags is true and lastFlags is false // (Mario just entered the floor on this frame). obj->oPaintingChangedFlags = ((lastFlags ^ obj->oPaintingCurrFlags) & obj->oPaintingCurrFlags); - - obj->oPaintingLocalMarioPosX = marioLocalPos[0]; - obj->oPaintingLocalMarioPosY = marioLocalPos[1]; + + // Detect whether Mario is entering this painting, and set paintingObj accordingly + if (obj->oPaintingCurrFlags & RIPPLE_FLAG_ENTER) { + // Mario has entered the painting. + gMarioState->paintingObj = obj; + } else if (gMarioState->paintingObj == obj) { + // Reset gMarioState->paintingObj if it's this painting and this painting is not entered. + gMarioState->paintingObj = NULL; + } } /** @@ -1022,7 +1026,7 @@ void bhv_painting_loop(void) { const struct Painting *painting = obj->oPaintingData; // Update the painting info. - painting_update_mario_pos(obj); + painting_update_mario_pos_and_flags(obj); // Update the ripple, may automatically reset the painting's state. painting_update_ripple_state(obj); @@ -1049,12 +1053,4 @@ void bhv_painting_loop(void) { painting_state(obj, PAINTING_RIPPLE, TRUE, TRUE ); // Idle } } - - if (obj->oPaintingCurrFlags & RIPPLE_FLAG_ENTER) { - // Mario has entered the painting. - gEnteredPaintingObject = obj; - } else if (gEnteredPaintingObject == obj) { - // Reset gEnteredPaintingObject if it's this painting and this painting is not entered. - gEnteredPaintingObject = NULL; - } } diff --git a/src/game/paintings.h b/src/game/paintings.h index ff8a87bc1..9c227180a 100644 --- a/src/game/paintings.h +++ b/src/game/paintings.h @@ -149,9 +149,6 @@ struct PaintingMeshVertex { }; /*0x0C*/ -extern struct Object *gEnteredPaintingObject; - - Gfx *geo_painting_draw(s32 callContext, struct GraphNode *node, UNUSED void *context); void bhv_painting_init(void);