diff --git a/include/functions.h b/include/functions.h index 2c4a770b60..c092919de1 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1540,8 +1540,8 @@ s32 func_800E9250(GlobalContext* ctxt, Actor* actor, Vec3s* param_3, Vec3s* para u8 func_800E9360(void); // func_800E9360 void static_context_init(void); // func_800E93E0 void func_800E9470(void); // func_800E9470 -void func_800E9488(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE2 param_5, UNK_TYPE2 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE1 param_10, UNK_TYPE1 param_11, UNK_TYPE1 param_12, UNK_TYPE1 param_13, UNK_TYPE2 param_14, UNK_TYPE4 param_15); // func_800E9488 -void func_800E9564(void); // func_800E9564 +void DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX, f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type, GraphicsContext* gfxCtx); // func_800E9488 +void DebugDisplay_DrawObjects(GlobalContext* globalCtx); // func_800E9564 void func_800E95F4(void); // func_800E95F4 void func_800E97D8(void); // func_800E97D8 void func_800E992C(void); // func_800E992C @@ -2737,7 +2737,7 @@ void func_8013D768(void); // func_8013D768 void func_8013D83C(void); // func_8013D83C void func_8013D8DC(void); // func_8013D8DC void func_8013D924(void); // func_8013D924 -void func_8013D960(void); // func_8013D960 +Actor* func_ActorCategoryIterateById(GlobalContext* globalCtx, struct Actor* actorListStart, s32 actorCategory, s32 actorId); // func_8013D960 void func_8013D9C8(void); // func_8013D9C8 void func_8013DB90(void); // func_8013DB90 void func_8013DC40(void); // func_8013DC40 diff --git a/include/functions_overlay.h b/include/functions_overlay.h index beef9aa1e3..e52b3382c2 100644 --- a/include/functions_overlay.h +++ b/include/functions_overlay.h @@ -9102,12 +9102,6 @@ void func_80B19718(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_ void EnSnowman_Draw(void); // func_80B198B0 void func_80B19948(void); // func_80B19948 void func_80B19998(void); // func_80B19998 -void func_80B19F60(void); // func_80B19F60 -void func_80B1A008(void); // func_80B1A008 -void TGSw_Init(void); // func_80B1A15C -void TGSw_Destroy(void); // func_80B1A17C -void TGSw_Update(void); // func_80B1A18C -void TGSw_Draw(void); // func_80B1A1B0 void EnPoSisters_Init(void); // func_80B1A3B0 void EnPoSisters_Destroy(void); // func_80B1A600 void func_80B1A648(void); // func_80B1A648 diff --git a/include/macros.h b/include/macros.h index 04a955acd8..42ad4f7e49 100644 --- a/include/macros.h +++ b/include/macros.h @@ -40,12 +40,13 @@ extern GraphicsContext* oGfxCtx; #define GRAPH_ALLOC(gfxCtx, size) \ ((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - (size))) -#define SQ(x) ((x)*(x)) -#define ABS(x) ((x) >= 0 ? (x) : -(x)) -#define ULTRA_ABS(x) ((x) > 0) ? (x) : -(x) -#define DECR(x) ((x) == 0 ? 0 : ((x) -= 1)) +#define SQ(x) ((x)*(x)) +#define ABS(x) ((x) >= 0 ? (x) : -(x)) +#define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) +#define DECR(x) ((x) == 0 ? 0 : ((x) -= 1)) + #define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) -#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) -#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) +#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) +#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) #endif // _MACROS_H_ diff --git a/include/variables_overlay.h b/include/variables_overlay.h index 9f650bc3c7..8fa2f13114 100644 --- a/include/variables_overlay.h +++ b/include/variables_overlay.h @@ -10509,10 +10509,6 @@ extern OverlayRelocationSection enSnowmanOverlayInfo; // D_80B19BA0 extern u32 enSnowmanOverlayRelocations[233]; // D_80B19BB4 extern u32 enSnowmanOverlayInfoOffset; // D_80B19F5C extern ActorInit TG_Sw_InitVars; // TG_Sw_InitVars -extern UNK_TYPE4 D_80B1A340; // D_80B1A340 -extern UNK_TYPE4 D_80B1A344; // D_80B1A344 -extern UNK_TYPE4 D_80B1A348; // D_80B1A348 -extern UNK_TYPE4 D_80B1A34C; // D_80B1A34C extern OverlayRelocationSection tGSwOverlayInfo; // D_80B1A350 extern u32 tGSwOverlayRelocations[16]; // D_80B1A364 extern u32 tGSwOverlayInfoOffset; // D_80B1A3AC diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index 19cc9eb1f7..82fa57559d 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -6108,8 +6108,9 @@ SECTIONS ovl_TG_Sw : AT(RomLocation) { build/src/overlays/actors/ovl_TG_Sw/z_tg_sw.o(.text) - build/asm/ovl_TG_Sw_data.o(.data) - build/asm/ovl_TG_Sw_rodata.o(.rodata) + build/src/overlays/actors/ovl_TG_Sw/z_tg_sw.o(.data) + build/src/overlays/actors/ovl_TG_Sw/z_tg_sw.o(.rodata) + build/src/overlays/actors/ovl_TG_Sw/z_tg_sw_overlay.o(.ovl) } SegmentEnd = .; SegmentSize = SegmentEnd - SegmentStart; diff --git a/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c b/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c index 90580a6a49..b10fd088cb 100644 --- a/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c +++ b/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c @@ -4,12 +4,14 @@ #define THIS ((TGSw*)thisx) +// Prototypes void TGSw_Init(Actor* thisx, GlobalContext* globalCtx); void TGSw_Destroy(Actor* thisx, GlobalContext* globalCtx); void TGSw_Update(Actor* thisx, GlobalContext* globalCtx); void TGSw_Draw(Actor* thisx, GlobalContext* globalCtx); -/* +static void TGSw_ActionExecuteOneShot(struct TGSw* this, GlobalContext* globalCtx); + const ActorInit TG_Sw_InitVars = { ACTOR_TG_SW, ACTORTYPE_PROP, @@ -21,16 +23,102 @@ const ActorInit TG_Sw_InitVars = { (ActorFunc)TGSw_Update, (ActorFunc)TGSw_Draw }; -*/ -GLOBAL_ASM("asm/non_matchings/ovl_TG_Sw_0x80B19F60/func_80B19F60.asm") +static void TGSw_ActionDecider(struct TGSw* this, GlobalContext* globalCtx) { + f32 scaledAbsoluteRotZ; + f32 scaledAbsoluteRotY; + u8 unk1F4; -GLOBAL_ASM("asm/non_matchings/ovl_TG_Sw_0x80B19F60/func_80B1A008.asm") + // Maybe actorCtx Debug Flag? + if (!!globalCtx->actorCtx.unk1F5) { + scaledAbsoluteRotY = ABS_ALT(this->actor.currPosRot.rot.y) * 4.0f; + scaledAbsoluteRotZ = ABS_ALT(this->actor.currPosRot.rot.z) * 4.0f; -GLOBAL_ASM("asm/non_matchings/ovl_TG_Sw_0x80B19F60/TGSw_Init.asm") + if (!(scaledAbsoluteRotZ < this->actor.xzDistanceFromLink) && + !(scaledAbsoluteRotY < this->actor.yDistanceFromLink)) { + unk1F4 = globalCtx->actorCtx.unk1F4; + if (unk1F4 == 2 || !unk1F4) { + this->actionFunc = &TGSw_ActionExecuteOneShot; + } + } + } +} -GLOBAL_ASM("asm/non_matchings/ovl_TG_Sw_0x80B19F60/TGSw_Destroy.asm") +static void TGSw_ActionExecuteOneShot(struct TGSw* this, GlobalContext* globalCtx) { + void* actorIterator; + struct Actor* actorEntry; -GLOBAL_ASM("asm/non_matchings/ovl_TG_Sw_0x80B19F60/TGSw_Update.asm") + actorIterator = NULL; + do { + actorEntry = func_ActorCategoryIterateById(globalCtx, (struct Actor*)actorIterator, ACTORTYPE_ENEMY, ACTOR_EN_SW); + if (actorIterator = (void*)!actorEntry) { + break; + } -GLOBAL_ASM("asm/non_matchings/ovl_TG_Sw_0x80B19F60/TGSw_Draw.asm") + if ((((this->actor.params & 0xFC) >> 2) & 0xFF) == (((actorEntry->params & 0xFC) >> 2) & 0xFF)) { + // Prevents register swap + if (1) {} + actorEntry->parent = (struct Actor*)this; + actorEntry->speedXZ = ABS_ALT(this->actor.currPosRot.rot.x); + break; + } + } while (actorIterator = actorEntry->next); + + actorIterator = NULL; + do { + actorEntry = func_ActorCategoryIterateById(globalCtx, actorIterator, ACTORTYPE_NPC, ACTOR_EN_SW); + if (actorIterator = (void*)!actorEntry) { + break; + } + + if ((((this->actor.params & 0xFC) >> 2) & 0xFF) == (((actorEntry->params & 0xFC) >> 2) & 0xFF)) { + actorEntry->parent = (struct Actor*)this; + actorEntry->speedXZ = ABS_ALT(this->actor.currPosRot.rot.x); + break; + } + } while (actorIterator = actorEntry->next); + + Actor_MarkForDeath((Actor*)this); +} + +void TGSw_Init(Actor* thisx, GlobalContext* globalCtx) { + TGSw* this = THIS; + this->actor.cutscene = this->actor.currPosRot.rot.z; + this->actionFunc = &TGSw_ActionDecider; +} + +void TGSw_Destroy(Actor* thisx, GlobalContext* globalCtx) { + ; +} + +void TGSw_Update(Actor* thisx, GlobalContext* globalCtx) { + TGSw* this = THIS; + this->actionFunc(this, globalCtx); +} + +void TGSw_Draw(Actor* thisx, GlobalContext* globalCtx) { + s32 pad0; + s32 absoluteRotZ; + s32 absoluteRotY; + f32 factoredRotZ; + TGSw* this = THIS; + + if (!!sREG(0)) { + absoluteRotZ = ABS_ALT(this->actor.currPosRot.rot.z); + factoredRotZ = absoluteRotZ * 0.2f; + // if needs to use the factored Rot as a var, "true" doesnt work + if (factoredRotZ) + { + ; + } + absoluteRotY = ABS_ALT(this->actor.currPosRot.rot.y); + + DebugDisplay_AddObject(this->actor.currPosRot.pos.x, this->actor.currPosRot.pos.y, this->actor.currPosRot.pos.z, + 0, this->actor.shape.rot.y, 0, 0.1f, 0.1f, factoredRotZ, 0xA0, 0xA0, 0xA0, 0xFF, 6, + globalCtx->state.gfxCtx); + DebugDisplay_AddObject(this->actor.currPosRot.pos.x, this->actor.currPosRot.pos.y, this->actor.currPosRot.pos.z, + 0, 0, 0, 0.1f, absoluteRotY * 0.2f, 0.1f, 0xA0, 0xA0, 0xA0, 0xFF, 6, + globalCtx->state.gfxCtx); + this->actor.shape.rot.y = (s16)(this->actor.shape.rot.y + 0x1000); + } +} diff --git a/src/overlays/actors/ovl_TG_Sw/z_tg_sw.h b/src/overlays/actors/ovl_TG_Sw/z_tg_sw.h index 5eea5a3b74..10cc975a42 100644 --- a/src/overlays/actors/ovl_TG_Sw/z_tg_sw.h +++ b/src/overlays/actors/ovl_TG_Sw/z_tg_sw.h @@ -4,10 +4,11 @@ #include struct TGSw; +typedef void (*TGSwActionFunc)(struct TGSw*, GlobalContext*); typedef struct TGSw { /* 0x000 */ Actor actor; - /* 0x144 */ char unk_144[0x4]; + /* 0x144 */ TGSwActionFunc actionFunc; } TGSw; // size = 0x148 extern const ActorInit TG_Sw_InitVars; diff --git a/tables/files_with_nonmatching.txt b/tables/files_with_nonmatching.txt index a2dc744258..967685dbd9 100644 --- a/tables/files_with_nonmatching.txt +++ b/tables/files_with_nonmatching.txt @@ -389,7 +389,6 @@ ovl_Obj_Dhouse_0x80B12980 ovl_Obj_Hakaisi_0x80B14180 ovl_Bg_Hakugin_Switch_0x80B15790 ovl_En_Snowman_0x80B16B00 -ovl_TG_Sw_0x80B19F60 ovl_En_Po_Sisters_0x80B1A3B0 ovl_En_Pp_0x80B1DEB0 ovl_En_Hakurock_0x80B21B00 diff --git a/tables/functions.txt b/tables/functions.txt index f53cb32164..0732415aa7 100644 --- a/tables/functions.txt +++ b/tables/functions.txt @@ -1530,8 +1530,8 @@ 0x800E9360:("func_800E9360",), 0x800E93E0:("static_context_init",), 0x800E9470:("func_800E9470",), - 0x800E9488:("func_800E9488",), - 0x800E9564:("func_800E9564",), + 0x800E9488:("DebugDisplay_AddObject",), + 0x800E9564:("DebugDisplay_DrawObjects",), 0x800E95F4:("func_800E95F4",), 0x800E97D8:("func_800E97D8",), 0x800E992C:("func_800E992C",), @@ -2698,7 +2698,7 @@ 0x8013D83C:("func_8013D83C",), 0x8013D8DC:("func_8013D8DC",), 0x8013D924:("func_8013D924",), - 0x8013D960:("func_8013D960",), + 0x8013D960:("func_ActorCategoryIterateById",), 0x8013D9C8:("func_8013D9C8",), 0x8013DB90:("func_8013DB90",), 0x8013DC40:("func_8013DC40",), @@ -13098,8 +13098,8 @@ 0x80B198B0:("EnSnowman_Draw",), 0x80B19948:("func_80B19948",), 0x80B19998:("func_80B19998",), - 0x80B19F60:("func_80B19F60",), - 0x80B1A008:("func_80B1A008",), + 0x80B19F60:("TGSw_ActionDecider",), + 0x80B1A008:("TGSw_ActionExecuteOneShot",), 0x80B1A15C:("TGSw_Init",), 0x80B1A17C:("TGSw_Destroy",), 0x80B1A18C:("TGSw_Update",), diff --git a/tables/variables.txt b/tables/variables.txt index e942929821..f4ed94d4cd 100644 --- a/tables/variables.txt +++ b/tables/variables.txt @@ -15423,10 +15423,6 @@ 0x80B19BB4:("enSnowmanOverlayRelocations","u32","[233]",0x3a4), 0x80B19F5C:("enSnowmanOverlayInfoOffset","u32","",0x4), 0x80B1A320:("TG_Sw_InitVars","UNK_TYPE1","",0x1), - 0x80B1A340:("D_80B1A340","UNK_TYPE4","",0x4), - 0x80B1A344:("D_80B1A344","UNK_TYPE4","",0x4), - 0x80B1A348:("D_80B1A348","UNK_TYPE4","",0x4), - 0x80B1A34C:("D_80B1A34C","UNK_TYPE4","",0x4), 0x80B1A350:("tGSwOverlayInfo","OverlayRelocationSection","",0x14), 0x80B1A364:("tGSwOverlayRelocations","u32","[16]",0x40), 0x80B1A3AC:("tGSwOverlayInfoOffset","u32","",0x4),