diff --git a/config/GALE01/symbols.txt b/config/GALE01/symbols.txt index c308947dc7..c7f69a85db 100644 --- a/config/GALE01/symbols.txt +++ b/config/GALE01/symbols.txt @@ -22617,11 +22617,12 @@ jumptable_803E099C = .data:0x803E099C; // type:object size:0x30 scope:local lbl_803E09CC = .data:0x803E09CC; // type:object size:0x1D data:string jumptable_803E09EC = .data:0x803E09EC; // type:object size:0x30 scope:local grMaterial_803E0A20 = .data:0x803E0A20; // type:object size:0xDC scope:global -lbl_803E0AFC = .data:0x803E0AFC; // type:object size:0x18 scope:local data:string -lbl_803E0B14 = .data:0x803E0B14; // type:object size:0xD scope:local data:string -lbl_803E0B21 = .data:0x803E0B24; // type:object size:0xE scope:local data:string -lbl_803E0B32 = .data:0x803E0B34; // type:object size:0x21 scope:local data:string -lbl_803E0B55 = .data:0x803E0B58; // type:object size:0x21 scope:local data:string +...data.0 = .data:0x803E0A20; // type:label scope:local +@356 = .data:0x803E0AFC; // type:object size:0x18 scope:local data:string +@467 = .data:0x803E0B14; // type:object size:0xD scope:local data:string +@468 = .data:0x803E0B24; // type:object size:0xE scope:local data:string +@469 = .data:0x803E0B34; // type:object size:0x21 scope:local data:string +@471 = .data:0x803E0B58; // type:object size:0x21 scope:local data:string @107 = .data:0x803E0B80; // type:object size:0x10 scope:local data:string @108 = .data:0x803E0B90; // type:object size:0x15 scope:local data:string @302 = .data:0x803E0BA8; // type:object size:0x12 scope:local data:string @@ -27123,8 +27124,8 @@ Ground_804D451C = .sdata:0x804D451C; // type:object size:0x8 scope:global grAnime_804D4550 = .sdata:0x804D4550; // type:object size:0x8 scope:global data:string grAnime_804D4558 = .sdata:0x804D4558; // type:object size:0x4 scope:global data:string grAnime_804D455C = .sdata:0x804D455C; // type:object size:0x2 scope:global data:string -grMaterial_804D4560 = .sdata:0x804D4560; // type:object size:0x8 scope:global data:string -grMaterial_804D4568 = .sdata:0x804D4568; // type:object size:0x2 scope:global data:string +@357 = .sdata:0x804D4560; // type:object size:0x8 scope:local data:string +@470 = .sdata:0x804D4568; // type:object size:0x2 scope:local data:string grMaterial_804D456C = .sdata:0x804D456C; // type:object size:0x4 scope:global @306 = .sdata:0x804D4570; // type:object size:0x8 scope:local data:string @307 = .sdata:0x804D4578; // type:object size:0x2 scope:local data:string @@ -32043,7 +32044,7 @@ gm_804DAC88 = .sdata2:0x804DAC88; // type:object size:0x4 scope:global align:4 d @1576 = .sdata2:0x804DAD70; // type:object size:0x4 scope:local align:4 data:float @1661 = .sdata2:0x804DAD74; // type:object size:0x4 scope:local align:4 data:float grAnime_804DAD78 = .sdata2:0x804DAD78; // type:object size:0x4 scope:global align:4 data:float -grMaterial_804DAD80 = .sdata2:0x804DAD80; // type:object size:0x8 scope:global align:8 data:double +@538 = .sdata2:0x804DAD80; // type:object size:0x8 scope:local align:8 data:double @251 = .sdata2:0x804DAD88; // type:object size:0x4 scope:local align:4 data:float @434 = .sdata2:0x804DAD8C; // type:object size:0x4 scope:local align:4 data:float @158 = .sdata2:0x804DAD90; // type:object size:0x4 scope:local align:4 data:float diff --git a/configure.py b/configure.py index 7214ceb7e8..ba3a1925e0 100755 --- a/configure.py +++ b/configure.py @@ -1227,7 +1227,7 @@ def MatchingFor(*versions): Object(Matching, "melee/gr/grdisplay.c"), Object(Matching, "melee/gr/grdatfiles.c"), Object(Linkable, "melee/gr/granime.c"), - Object(Linkable, "melee/gr/grmaterial.c"), + Object(Matching, "melee/gr/grmaterial.c"), Object(Matching, "melee/gr/grlib.c"), Object(Matching, "melee/gr/grdynamicattr.c"), Object(Matching, "melee/gr/grzakogenerator.c"), diff --git a/src/melee/ft/chara/ftCommon/ftCo_0A01.c b/src/melee/ft/chara/ftCommon/ftCo_0A01.c index 074423c4ae..3c09443677 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_0A01.c +++ b/src/melee/ft/chara/ftCommon/ftCo_0A01.c @@ -1959,18 +1959,24 @@ static inline bool ftCo_800A3908_inline0(Fighter* fp, return false; } -static inline s32 ftCo_800A3908_inline1(float x, float y) +static inline s32 ftCo_800A3908_inline2(Vec3* out_normal, u32* out_flags, + int* out_line, Vec3* out_pos, float y, + float x) +{ + return mpCheckFloor(x, 5.0f + y, x, y - 5.0f, 0.0f, out_pos, out_line, + out_flags, out_normal, -1, -1, -1, NULL, NULL); +} + +inline s32 ftCo_800A3908_inline1(float x, float y, Vec3* out_pos, + Vec3* out_normal, int* out_line, + u32* out_flags) { s32 result; - Vec3 floor_normal; - int line_id; - Vec3 floor_pos; - u32 flags; - line_id = -1; - result = mpCheckFloor(x, 5.0f + y, x, y - 5.0f, 0.0f, &floor_pos, &line_id, - &flags, &floor_normal, -1, -1, -1, NULL, NULL); - if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { + *out_line = -1; + result = + ftCo_800A3908_inline2(out_normal, out_flags, out_line, out_pos, y, x); + if (result != 0 && ftCo_800A1B38_noinline(*out_line) != 0) { return 0; } return result; @@ -2014,7 +2020,6 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) frames = -(-fp->co_attrs.terminal_velocity - fp->pos_delta.y) / grav; } info = &stage_info; - PAD_STACK(0x18); for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { @@ -2043,6 +2048,8 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) dx = fp->cur_pos.x - ex; if (dx > 0.0f) { f32 land_y; + + PAD_STACK(0x10); t = dx / fp->co_attrs.air_drift_max; if (frames <= 0) { land_y = fp->pos_delta.y * t + fp->cur_pos.y; @@ -2059,8 +2066,15 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) } if (arg1 != 0) { if (!(land_y + data->x558 < ey)) { + u32 flags0; + int line_id0; + Vec3 floor_normal0; + Vec3 floor_pos0; + px = ex - 5.0; - valid = ftCo_800A3908_inline1(px, ey); + valid = ftCo_800A3908_inline1(px, ey, &floor_pos0, + &floor_normal0, &line_id0, + &flags0); if (valid != 0 && !ftCo_800A3908_inline0(fp, data2, px, ey)) { @@ -2082,10 +2096,16 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) } } } else { - ddy = ey - fp->cur_pos.y; + u32 flags1; + int line_id1; + Vec3 floor_normal1; + Vec3 floor_pos1; + px = ex - 5.0; ddx = px - fp->cur_pos.x; - valid = ftCo_800A3908_inline1(px, ey); + ddy = ey - fp->cur_pos.y; + valid = ftCo_800A3908_inline1( + px, ey, &floor_pos1, &floor_normal1, &line_id1, &flags1); if (valid != 0 && !ftCo_800A3908_inline0(fp, data2, px, ey)) { ok = 1; } else { @@ -2109,6 +2129,7 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) } } } + PAD_STACK(8); return 0; } @@ -2126,18 +2147,17 @@ static inline bool ftCo_800A4038_inline0(Fighter* fp, return false; } -static inline s32 ftCo_800A4038_inline1(float x, float y) +static inline s32 ftCo_800A4038_inline1(float x, float y, Vec3* arg_floor_pos, + Vec3* arg_floor_normal, + int* arg_line_id, u32* arg_flags) { - Vec3 floor_normal; - Vec3 floor_pos; - int line_id; - u32 flags; s32 result; - line_id = -1; - result = mpCheckFloor(x, 5.0f + y, x, y - 5.0f, 0.0f, &floor_pos, &line_id, - &flags, &floor_normal, -1, -1, -1, NULL, NULL); - if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { + *arg_line_id = -1; + result = mpCheckFloor(x, 5.0f + y, x, y - 5.0f, 0.0f, arg_floor_pos, + arg_line_id, arg_flags, arg_floor_normal, -1, -1, -1, + NULL, NULL); + if (result != 0 && ftCo_800A1B38_noinline(*arg_line_id) != 0) { return 0; } return result; @@ -2148,6 +2168,14 @@ static inline float ftCo_800A4038_inline2(Fighter* fp) return -(-fp->co_attrs.terminal_velocity - fp->pos_delta.y); } +static inline s32 ftCo_800A4038_inline3(f32 y, f32 x, Vec3* arg_floor_pos, + Vec3* arg_floor_normal, + int* arg_line_id, u32* arg_flags) +{ + return ftCo_800A4038_inline1(x, y, arg_floor_pos, arg_floor_normal, + arg_line_id, arg_flags); +} + bool ftCo_800A4038(Fighter* fp, bool arg1) { f32 ez; @@ -2181,7 +2209,6 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) frames = ftCo_800A4038_inline2(fp) / grav; } info = &stage_info; - PAD_STACK(0x4); for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { @@ -2226,8 +2253,14 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } if (arg1 != 0) { if (!(land_y + data->x558 < ey)) { + u32 flags; + int line_id; + Vec3 floor_normal; + Vec3 floor_pos; + px = 5.0 + ex; - valid = ftCo_800A4038_inline1(px, ey); + valid = ftCo_800A4038_inline3( + ey, px, &floor_pos, &floor_normal, &line_id, &flags); if (valid != 0 && !ftCo_800A4038_inline0(fp, data2, px, ey)) { @@ -2249,10 +2282,16 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } } } else { - ddy = ey - fp->cur_pos.y; + u32 flags; + int line_id; + Vec3 floor_normal; + Vec3 floor_pos; + px = 5.0 + ex; ddx = px - fp->cur_pos.x; - valid = ftCo_800A4038_inline1(px, ey); + ddy = ey - fp->cur_pos.y; + valid = ftCo_800A4038_inline1(px, ey, &floor_pos, + &floor_normal, &line_id, &flags); if (valid != 0 && !ftCo_800A4038_inline0(fp, data2, px, ey)) { ok = 1; } else { @@ -3582,6 +3621,34 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) return 1; } +static inline s32 ftCo_800A75DC_CheckFloor(f32 x0, f32 above, f32 x1, + f32 below, Vec3* floor_pos, + int* line_id, u32* flags, + Vec3* floor_normal) +{ + int line; + s32 blocked; + s32 result; + + blocked = 0; + *line_id = -1; + result = + mpCheckFloor(x0, above, x1, below, 0.0f, floor_pos, line_id, flags, + floor_normal, -1, -1, -1, NULL, (Fighter_GObj*) blocked); + if (result != 0) { + line = *line_id; + if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || + grCorneria_801E2D90(line) || grVenom_80206D10(line)) + { + blocked = 1; + } + if (blocked != 0) { + result = 0; + } + } + return result; +} + void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) { struct Fighter_x1A88_t* data = &fp0->x1A88; @@ -3589,7 +3656,7 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) Vec3 floor_normal; int line_id; u32 flags; - u8 _[0x18]; + u8 _[0x14]; Vec3 sp18; f32 fx; f32 fy; @@ -3599,7 +3666,6 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) return; } if (fp1->ground_or_air == GA_Air) { - s32 blocked; s32 result; mp_UnkStruct0* island; fx = fp1->cur_pos.x; @@ -3608,24 +3674,11 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) f32 below; f32 above; fy = fp1->cur_pos.y; - blocked = 0; - line_id = -1; below = fy - 1000.0f; above = 10.0f + fy; - result = mpCheckFloor(fx2, above, fx, below, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, (Fighter_GObj*) blocked); - } - if (result != 0) { - int line = line_id; - if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || - grCorneria_801E2D90(line) || grVenom_80206D10(line)) - { - blocked = 1; - } - if (blocked != 0) { - result = 0; - } + result = + ftCo_800A75DC_CheckFloor(fx2, above, fx, below, &floor_pos, + &line_id, &flags, &floor_normal); } if (result != 0) { island = mpIsland_8005AB54(line_id); @@ -3698,31 +3751,6 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) } } -static inline s32 ftCo_800A7AAC_inline0(float x, float above, float below, - Vec3* floor_pos, int* line_id_ptr, - u32* flags, Vec3* floor_normal) -{ - int line_id; - s32 blocked = 0; - s32 result; - *line_id_ptr = -1; - result = - mpCheckFloor(x, above, x, below, 0.0f, floor_pos, line_id_ptr, flags, - floor_normal, -1, -1, -1, NULL, (Fighter_GObj*) blocked); - if (result != 0) { - line_id = *line_id_ptr; - if (grBigBlue_801EF844(line_id) || grInishie1_801FCAAC(line_id) || - grCorneria_801E2D90(line_id) || grVenom_80206D10(line_id)) - { - blocked = 1; - } - if (blocked != 0) { - result = 0; - } - } - return result; -} - void ftCo_800A7AAC(Fighter* fp) { Fighter* partner; @@ -3733,10 +3761,8 @@ void ftCo_800A7AAC(Fighter* fp) u32 flags; u8 _[0x18]; Vec3 partner_pos; - u8 _2[4]; f32 d; - - PAD_STACK(0xA); + PAD_STACK(4 * 4); partner = ftCo_800A589C(fp); if (partner == NULL) { @@ -3748,8 +3774,9 @@ void ftCo_800A7AAC(Fighter* fp) mp_UnkStruct0* island; f32 below = partner_pos.y - 1000.0f; f32 above = 10.0f + partner_pos.y; - result = ftCo_800A7AAC_inline0(partner_pos.x, above, below, &floor_pos, - &line_id, &flags, &floor_normal); + result = ftCo_800A75DC_CheckFloor(partner_pos.x, above, partner_pos.x, + below, &floor_pos, &line_id, &flags, + &floor_normal); if (result != 0) { island = mpIsland_8005AB54(line_id); if (ftCo_800A2718(island) == 0) { diff --git a/src/melee/ft/chara/ftCommon/ftCo_0D95.c b/src/melee/ft/chara/ftCommon/ftCo_0D95.c index 22e7cd5b71..8d1b031d9f 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_0D95.c +++ b/src/melee/ft/chara/ftCommon/ftCo_0D95.c @@ -14,10 +14,9 @@ bool fn_800D9558(Fighter_GObj* gobj) { Fighter* fp = GET_FIGHTER(gobj); - s32 i; ftSs_DatAttrs* attrs; Item_GObj* item; - Item* it; + s32 i; itSamusGrappleAttributes* grappleAttrs; HSD_GObj* segGobj; HSD_JObj* jobj; @@ -44,12 +43,13 @@ bool fn_800D9558(Fighter_GObj* gobj) fp->accessory3_cb = (void (*)(HSD_GObj*)) it_802BACC4; } else if (grav > (f32) attrs->x9C) { if (grav <= (f32) attrs->xA8) { - it = (Item*) fp->u.ss.x223C->user_data; + Item* it; + it = fp->u.ss.x223C->user_data; item = fp->u.ss.x223C; grappleAttrs = it->xC4_article_data->x4_specialAttributes; if (item != NULL) { for (i = 0; i < 6; i++) { - if (fp->mv.ca.specials.grav == (f32) (0x14 + i * 3)) { + if (fp->mv.ca.specials.grav == (f32) (i * 3 + 0x14)) { segGobj = it->xDD4_itemVar.samusgrapple.x0->gobj; jobj = (HSD_JObj*) segGobj->hsd_obj; HSD_JObjSetupMatrix(jobj); @@ -67,15 +67,15 @@ bool fn_800D9558(Fighter_GObj* gobj) } grav = fp->mv.ca.specials.grav; if (grav == (f32) attrs->xA0) { - HSD_JObj* j = fp->parts[51].joint; - HSD_JObjSetupMatrix(j); - jobj = j; - my = jobj->mtx[1][3]; + HSD_JObj* joint = fp->parts[51].joint; + + HSD_JObjSetupMatrix(joint); + my = joint->mtx[1][3]; if (mpCheckAllRemap(NULL, NULL, NULL, NULL, -1, -1, fp->coll_data.cur_pos.x, my, 2.0 * fp->facing_dir * fp->x34_scale.y + - jobj->mtx[0][3], + joint->mtx[0][3], my)) { it_802B7B84(fp->u.ss.x223C); diff --git a/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c b/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c index 27adcf30b1..5480857790 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c +++ b/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c @@ -516,9 +516,9 @@ void ftCo_ItemThrow_Anim(Fighter_GObj* gobj) } } -static inline float getItemThrowFsm(Fighter* fp) +inline float getItemThrowFsm(float fsm, Fighter* fp) { - return -fp->cmd_timer / fp->frame_speed_mul; + return fsm / fp->frame_speed_mul; } void ftCo_80095EFC(Fighter_GObj* gobj) @@ -542,13 +542,14 @@ void ftCo_80095EFC(Fighter_GObj* gobj) fp->cmd_vars[1] = 0; } { - float fsm = getItemThrowFsm(fp); + float fsm = -fp->cmd_timer; ftCo_ItemThrowAttrs* throw_speed_arr; float velocity_multiplier; float table_speed; float base_throw_speed; float throw_speed; interpolation = fp->mv.co.itemthrow4.x8.x; + fsm = getItemThrowFsm(fsm, fp); throw_speed_arr = (ftCo_ItemThrowAttrs*) Fighter_804D6550; velocity_multiplier = co_attrs->heavy_throw_velocity_multiplier; diff --git a/src/melee/ft/ftafterimage.c b/src/melee/ft/ftafterimage.c index f49cd63408..aaa1de0cec 100644 --- a/src/melee/ft/ftafterimage.c +++ b/src/melee/ft/ftafterimage.c @@ -26,45 +26,9 @@ typedef struct AfterimageVtx { #define AFTERIMAGE_ANGLE_STEP 0.0872664600610733f -void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) +static inline itSword_UnkBytes* ftCo_800C2600_get_params(Fighter* fp) { - Fighter* fp; itSword_UnkBytes* params; - f32 cumDist[3]; - AfterimageVtx vtx_buf[151]; - f32 d2; - s32 numSubdiv; - - PAD_STACK(0x10); - - if (arg1 != 2) { - return; - } - - { - void* fighter = gobj->user_data; - fp = fighter; - } - - if ((s8) (u8) fp->x2100 <= 1) { - return; - } - - GXSetColorUpdate(1); - GXSetAlphaUpdate(0); - GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP); - GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_AND, GX_GREATER, 0); - GXSetZMode(1, GX_LEQUAL, 0); - GXSetZCompLoc(0); - GXSetNumTexGens(0); - GXSetTevClampMode(0, 0); - GXSetNumTevStages(1); - GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); - GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GXSetNumChans(1); - GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_VTX, 0, GX_DF_NONE, - GX_AF_NONE); - GXSetCullMode(GX_CULL_NONE); if (fp->x2101_bits_8) { switch (itGetKind(fp->item_gobj)) { @@ -111,8 +75,52 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) break; } } + return params; +} + +void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) +{ + Fighter* fp; + itSword_UnkBytes* params; + f32 cumDist[3]; + AfterimageVtx vtx_buf[152]; + f32 d2; + f32* distPtr; + + if (arg1 != 2) { + return; + } + + { + void* fighter = gobj->user_data; + fp = fighter; + } + + if ((s8) (u8) fp->x2100 <= 1) { + return; + } + + GXSetColorUpdate(1); + GXSetAlphaUpdate(0); + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP); + GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_AND, GX_GREATER, 0); + GXSetZMode(1, GX_LEQUAL, 0); + GXSetZCompLoc(0); + GXSetNumTexGens(0); + GXSetTevClampMode(0, 0); + GXSetNumTevStages(1); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); + GXSetNumChans(1); + GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_VTX, 0, GX_DF_NONE, + GX_AF_NONE); + GXSetCullMode(GX_CULL_NONE); + + params = ftCo_800C2600_get_params(fp); { + s32 remaining; + struct Fighter_x20B0_t* curEntry; s32 nextIdx; f32 x20F8 = fp->x20F8; f32 x20FC = fp->x20FC; @@ -172,8 +180,6 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) } { - s32 remaining; - f32* distPtr; s32 numVerts; f32 scaleDiff; s32 curIdx2; @@ -208,8 +214,9 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) f32 outerScale, innerScale; s32 alpha; struct Fighter_x20B0_t* nextEntry; + s32 numSubdiv; - struct Fighter_x20B0_t* curEntry = &fp->x20B0[curIdx2]; + curEntry = &fp->x20B0[curIdx2]; outerScale = interpFactor * outerDiff + blendedOuter; innerScale = interpFactor * innerDiff + blendedInner; numVerts += 2; @@ -226,10 +233,7 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) vp->b = params->xC; vp->a = alpha; - { - f32 x = curEntry->xC.x * outerScale; - (vp + 1)->x = x + curEntry->x0.x; - } + (vp + 1)->x = curEntry->xC.x * outerScale + curEntry->x0.x; (vp + 1)->y = curEntry->xC.y * outerScale + curEntry->x0.y; (vp + 1)->z = curEntry->xC.z * outerScale + curEntry->x0.z; (vp + 1)->r = params->xE; @@ -263,9 +267,9 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) f32 frac; s32 j; f32 cumAngle = 0.0f; - f32 interpInner2, interpOuter2; f32 basePosX, basePosY, basePosZ; f32 stepPosX, stepPosY, stepPosZ; + f32 interpInner2, interpOuter2; s32 alphaStep; tempDir = curEntry->xC; diff --git a/src/melee/ft/ftcpuattack.c b/src/melee/ft/ftcpuattack.c index faeb4ac8b3..b81b7a44a6 100644 --- a/src/melee/ft/ftcpuattack.c +++ b/src/melee/ft/ftcpuattack.c @@ -141,6 +141,18 @@ static inline f32 get_scale(Fighter* fp) return fp->x34_scale.y; } +#ifdef MUST_MATCH +/// Preserve the caller operand area used by the inlined physics calculation. +static inline s32 ftCo_CpuAttackValue(s32 value, s32 arg1, s32 arg2, s32 arg3, + s32 arg4, s32 arg5, s32 arg6, s32 arg7, + s64 arg8, s64 arg9) +{ + return value; +} +#else +#define ftCo_CpuAttackValue(value, ...) (value) +#endif + static inline int ftCo_CpuSelectAttack(Fighter* fp, struct Fighter_x1A88_t* cpu, const ftCo_AttackEntry* entry) @@ -385,7 +397,6 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) f32 acc; f32 t; f32 fpPredY; - f32 relPredY; f32 v; f32 sq; f32 scale; @@ -407,9 +418,10 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) f32 relx; f32 lower; f32 upper; + f32 relPredY; f32 halfRange; - PAD_STACK(0x10); + PAD_STACK(8); cpu->x74.y = 0.0f; cpu->x74.x = 0.0f; @@ -525,10 +537,14 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) dirx *= halfRange; diry *= halfRange; scale = fp->x34_scale.y; - upper = list->x14 * scale + reach; - lower = list->x10 * scale; - upper *= halfRange; - lower *= halfRange; + { + f32 l = list->x10 * scale; + f32 u = list->x14 * scale + reach; + l *= halfRange; + u *= halfRange; + lower = l; + upper = u; + } if (upper > relPredY && lower < relPredY + x568 && dirx < relx + rangeF && diry > relx - rangeB) { @@ -575,13 +591,6 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) HSD_ASSERT(0x1C5, 0); } -ftCo_803C6594_t ftCo_803C639C = { 0 }; -ftCo_803C6594_t ftCo_803C61F8 = { 0 }; - -ftCo_803C6594_t* ftCo_803C6594[Gr_Kind_Count] = { - NULL, NULL, NULL, NULL, NULL, NULL, &ftCo_803C639C, &ftCo_803C61F8, -}; - int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) { Item* x50 = arg1; @@ -613,7 +622,6 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) f32 x50Vy; f32 x50Vx; f32 x50TermNeg; - f32 sq; f32 x50Grav; f32 sizeHalf; f32 yBound; @@ -640,7 +648,6 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) f32 relx; f32 diry; f32 scale; - f32 upper; f32 lower; found = false; if (list->x20 > cpu->level) { @@ -657,7 +664,7 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) list++; continue; } - t = list->x04; + t = ftCo_CpuAttackValue(list->x04, 0, 0, 0, 0, 0, 0, 0, 0, 0); relx = (x50Vx * t + x50X) - (fpVx * t + fpX); if (x50->ground_or_air == GA_Air) { if (fpGrav < 0.00001f && fpGrav > -0.00001f) { @@ -673,15 +680,14 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) if (v <= 0.0f) { fpPredY = fpVy * t + fpY; } else if (t < v) { - sq = sqrtf(t); - fpPredY = (f32) ((f64) fpY + ((f64) (fpVy * t) - - 0.5 * (f64) (fpGrav * sq))); + fpPredY = + (f32) ((f64) fpY + ((f64) (fpVy * t) - + 0.5 * (f64) (fpGrav * sqrtf(t)))); } else { - sq = sqrtf(v); fpPredY = - (f32) ((f64) fpY + - ((f64) (fpTermNeg * (t - v)) + - ((f64) (fpVy * t) - 0.5 * (f64) (fpGrav * sq)))); + (f32) ((f64) fpY + ((f64) (fpTermNeg * (t - v)) + + ((f64) (fpVy * t) - + 0.5 * (f64) (fpGrav * sqrtf(v))))); } } else { fpPredY = fpVy * t + fpY; @@ -700,31 +706,31 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) if (v <= 0.0f) { relPredY = (x50Vy * t + x50Y) - fpPredY; } else if (t < v) { - sq = sqrtf(t); relPredY = (f32) (((f64) (x50Vy * t + x50Y) - - 0.5 * (f64) (x50Grav * sq)) - + 0.5 * (f64) (x50Grav * sqrtf(t))) - (f64) fpPredY); } else { - sq = sqrtf(v); relPredY = (f32) (((f64) (x50TermNeg * (t - v)) + ((f64) (x50Vy * t + x50Y) - - 0.5 * (f64) (x50Grav * sq))) - + 0.5 * (f64) (x50Grav * sqrtf(v)))) - (f64) fpPredY); } } else { relPredY = (x50Vy * t + x50Y) - fpPredY; } if (fp->facing_dir > 0.0f) { - dirx = list->x08 * fp->x34_scale.y; - diry = list->x0C * fp->x34_scale.y; + dirx = list->x08; + scale = get_scale(fp); + dirx *= scale; + diry = list->x0C * scale; } else { - dirx = -list->x0C * fp->x34_scale.y; - diry = -list->x08 * fp->x34_scale.y; + dirx = -list->x0C * (scale = get_scale(fp)); + diry = -list->x08 * scale; } scale = get_scale(fp); - upper = list->x14 * scale; + v = list->x14 * scale; lower = list->x10 * scale; - if (upper > relPredY && lower < relPredY + yBound && + if (v > relPredY && lower < relPredY + yBound && dirx < relx + sizeHalf && diry > relx - sizeHalf) { if (cpu->xC8 != 0) { @@ -2954,3 +2960,244 @@ int ftCo_800BB9B4(Fighter* fp) return temp_r31->xF8_b12; } + +/// @todo Fix split +static ftCo_803C6594_t ftCo_803C61F8[] ATTRIBUTE_ALIGN(8) = { + { + { 37.0F, -143.5F, 0.0F }, + 5.5F, + -111.0F, + 0.0F, + 5.5F, + -111.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 5.5F, + -111.0F, + 0.0F, + 0.7853982F, + -0.7853982F, + 0, + 0.0F, + 0.0F, + &ftCo_803C61F8[1], + }, + { + { 30.0F, -16.0F, 0.0F }, + -3.5F, + 24.0F, + 0.0F, + -60.0F, + -86.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + -3.5F, + 24.0F, + 0.0F, + 0.7853982F, + -0.2617994F, + 0, + 0.0F, + 0.0F, + &ftCo_803C61F8[2], + }, + { + { -60.0F, -86.0F, 0.0F }, + -131.0F, + -26.8F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + 0.7853982F, + -0.7853982F, + 1, + -1000.0F, + -95.0F, + &ftCo_803C61F8[3], + }, + { + { -60.0F, -86.0F, 0.0F }, + -16.0F, + -46.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + 0.2617994F, + -0.7853982F, + 1, + -95.0F, + -25.0F, + &ftCo_803C61F8[4], + }, + { + { -60.0F, -86.0F, 0.0F }, + -60.0F, + -86.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + -60.0F, + -86.0F, + 0.0F, + 0.7853982F, + -0.7853982F, + 1, + -25.0F, + 1000.0F, + NULL, + }, + { + { -130.0F, 6.0F, 0.0F }, + -130.0F, + 6.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + -130.0F, + 6.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.7853982F, + -0.7853982F, + 1, + -120.0F, + 1000.0F, + &ftCo_803C61F8[6], + }, + { + { -130.0F, 6.0F, 0.0F }, + -100.0F, + 34.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + -100.0F, + 34.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.7853982F, + -0.7853982F, + 0, + 0.0F, + 0.0F, + &ftCo_803C61F8[7], + }, + { + { -10.0F, 6.0F, 0.0F }, + -10.0F, + 6.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + -10.0F, + 6.0F, + 0.0F, + 0.7853982F, + -0.7853982F, + 1, + -1000.0F, + -20.0F, + &ftCo_803C61F8[8], + }, + { + { -10.0F, 6.0F, 0.0F }, + -30.0F, + 34.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + -30.0F, + 34.0F, + 0.0F, + 0.7853982F, + -0.7853982F, + 0, + 0.0F, + 0.0F, + &ftCo_803C61F8[9], + }, + { + { -100.0F, 34.0F, 0.0F }, + 0.0F, + 0.0F, + -1.0F, + -10.0F, + 6.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + 0.7853982F, + -0.7853982F, + 1, + -50.0F, + 0.0F, + &ftCo_803C61F8[10], + }, + { + { -100.0F, 34.0F, 0.0F }, + 0.0F, + 0.0F, + -1.0F, + -130.0F, + 6.0F, + 0.0F, + 0.0F, + 0.0F, + -1.0F, + 0.0F, + 0.0F, + -1.0F, + 0.7853982F, + -0.7853982F, + 1, + -200.0F, + -80.0F, + NULL, + }, +}; + +ftCo_803C6594_t* ftCo_803C6594[Gr_Kind_Count] = { + NULL, NULL, NULL, NULL, NULL, NULL, &ftCo_803C61F8[5], &ftCo_803C61F8[0], +}; + +static ftCo_803C6594_t* ftCo_803C6594_tail[151] = { NULL }; diff --git a/src/melee/gm/gm_16A2.c b/src/melee/gm/gm_16A2.c index e38f17d34b..9ac76f5f29 100644 --- a/src/melee/gm/gm_16A2.c +++ b/src/melee/gm/gm_16A2.c @@ -357,7 +357,21 @@ s32 fn_80169A84(u8 arg0, s8* arg1, s8* arg2) src += 1; dst += 1; } - break; + return (s32) src; + } +} + +static inline struct lbl_8046B488_t* fn_80169C54_inline(void) +{ + return fn_8016AE60(); +} + +static inline void fn_80169C54_apply(s32 p, s32 count, s32* buf) +{ + s32 i; + + for (i = 0; i < count; i++) { + Player_80031DA8(p, buf[i]); } } @@ -371,12 +385,14 @@ void fn_80169C54(s8 arg0, s8 arg1) s32 count; s32 k; s32 j; + s32 p1; + s32 p0; s8* cp; s32 p; s32 ch; n = 0; - st = fn_8016AE60(); + st = fn_80169C54_inline(); pc = &st->x0; for (i = 0; i < 7; i++) { buf[i] = -1; @@ -410,31 +426,27 @@ void fn_80169C54(s8 arg0, s8 arg1) if (0x21 != ch && ch != 4) { p = Player_800325C8((CharacterKind) ch, 0); if ((p != -1) && (p != 4)) { - for (k = 0; k < n; k++) { - Player_80031DA8(p, buf[k]); - } + fn_80169C54_apply(p, n, buf); } p = Player_800325C8((CharacterKind) ch, 1); if ((p != -1) && (p != 4)) { - for (k = 0; k < n; k++) { - Player_80031DA8(p, buf[k]); - } + fn_80169C54_apply(p, n, buf); } } j++; cp++; } while (j < 3); if (arg0 != 4) { - p = Player_800325C8((CharacterKind) arg0, 0); - if ((p != -1) && (p != 4)) { + p0 = Player_800325C8((CharacterKind) arg0, 0); + if ((p0 != -1) && (p0 != 4)) { for (k = 0; k < n; k++) { - Player_80031DA8(p, buf[k]); + Player_80031DA8(p0, buf[k]); } } - p = Player_800325C8((CharacterKind) arg0, 1); - if ((p != -1) && (p != 4)) { + p1 = Player_800325C8((CharacterKind) arg0, 1); + if ((p1 != -1) && (p1 != 4)) { for (k = 0; k < n; k++) { - Player_80031DA8(p, buf[k]); + Player_80031DA8(p1, buf[k]); } } } diff --git a/src/melee/gm/gm_16F1.c b/src/melee/gm/gm_16F1.c index e6e6611382..35291b1236 100644 --- a/src/melee/gm/gm_16F1.c +++ b/src/melee/gm/gm_16F1.c @@ -35,54 +35,9 @@ struct lbl_803D6300_t { bool (*x4)(void); }; -struct lbl_803D6300_t lbl_803D6300[] = { - { 0x0016, 0xFFFF, fn_801735F0 }, - { 0x0017, 0x0001, fn_80173644 }, - { 0x0018, 0xFFFF, fn_80173510 }, - { 0x0019, 0xFFFF, NULL }, - { 0x001A, 0xFFFF, NULL }, - { 0x001B, 0xFFFF, fn_8017367C }, - { 0x001C, 0xFFFF, gm_80164ABC }, - { 0x001D, 0xFFFF, gm_80164600 }, - { 0x001E, 0x0040, fn_80162CCC }, - { 0x001F, 0x0040, gm_80162EC8 }, - { 0x0020, 0x0040, fn_801630C4 }, - { 0x0021, 0x0040, gm_80162D1C }, - { 0x0022, 0x0040, gm_80162F18 }, - { 0x0023, 0x0040, gm_80163114 }, - { 0x0024, 0x0010, fn_801722BC }, - { 0x0025, 0x0010, fn_801722F4 }, - { 0x0026, 0x0080, gmMainLib_8015D508 }, - { 0x0027, 0x0020, fn_80163D24 }, - { 0x0028, 0x0020, fn_80163D74 }, - { 0x0029, 0x0040, fn_8017232C }, - { 0x002A, 0x0040, fn_80172428 }, - { 0x002B, 0x0040, fn_80172380 }, - { 0x002C, 0x0040, fn_80172478 }, - { 0x002D, 0x0040, fn_801723D4 }, - { 0x002E, 0x0040, fn_801724C8 }, - { 0x002F, 0x0001, fn_801724D0 }, - { 0x0030, 0x0001, fn_80172504 }, - { 0x0031, 0x0001, fn_80172538 }, - { 0x0032, 0x0001, fn_8017256C }, - { 0x0033, 0x0001, fn_801725A8 }, - { 0x0034, 0x0001, fn_801725E4 }, - { 0x0035, 0x0001, fn_80172624 }, - { 0x0036, 0x0001, fn_80172664 }, - { 0x0037, 0xFFFF, fn_80172698 }, - { 0x0038, 0xFFFF, fn_801726CC }, - { 0x0039, 0xFFFF, fn_80172700 }, - { 0x003A, 0xFFFF, fn_80172734 }, - { 0x003B, 0xFFFF, fn_80172768 }, - { 0x003C, 0xFFFF, un_80304470 }, - { 0x003D, 0xFFFF, un_80304510 }, - { 0x0041, 0x0010, gmMainLib_8015CF94 }, - { 0x0042, 0x0000, NULL }, -}; - int fn_8016F180(int kind) { - struct lbl_803D5A4C_t* curr = lbl_803D5A4C; + struct lbl_803D5A4C_t* curr = lbl_803D5A4C.entries; while (curr->kind != kind) { if (curr->kind == 0x29A) { return 0; @@ -95,7 +50,7 @@ int fn_8016F180(int kind) Gm_DecType gmDecisionGetType(int kind) { struct lbl_803D5A4C_t* curr; - for (curr = lbl_803D5A4C; curr->kind != kind; curr++) { + for (curr = lbl_803D5A4C.entries; curr->kind != kind; curr++) { if (curr->kind == 0x29A) { return Gm_DecType_Flag; } @@ -105,12 +60,12 @@ Gm_DecType gmDecisionGetType(int kind) s32 fn_8016F1F0(int idx) { - return lbl_803D5A4C[idx].kind; + return lbl_803D5A4C.entries[idx].kind; } int gm_8016F208(int kind) { - struct lbl_803D5A4C_t* curr = lbl_803D5A4C; + struct lbl_803D5A4C_t* curr = lbl_803D5A4C.entries; while (curr->kind != kind) { if (curr->kind == 0x29A) { return 0; @@ -130,7 +85,7 @@ int fn_8016F280(int arg0) int gm_8016F2F8(int kind, u8 arg1) { - struct lbl_803D5A4C_t* curr = lbl_803D5A4C; + struct lbl_803D5A4C_t* curr = lbl_803D5A4C.entries; while (curr->kind != kind) { if (curr->kind == 0x29A) { return -1; @@ -160,7 +115,7 @@ void fn_8016F344(struct lbl_8046B6A0_24C_t* arg0) /// drops that zero-extension and regresses gm_8016F208/fn_8016F280. static inline u16 fn_8016F39C_GetSisTextId(int kind) { - struct lbl_803D5A4C_t* curr = lbl_803D5A4C; + struct lbl_803D5A4C_t* curr = lbl_803D5A4C.entries; while (curr->kind != kind) { if (curr->kind == 0x29A) { return 0; @@ -188,7 +143,7 @@ int fn_8016F39C(HSD_Text** arg0, void* arg1, u8 arg2, u16 arg3, u8 arg4, idx = arg3; while ((u32) idx < 0x101U) { matched = 0; - if (lbl_803D5A4C[idx].kind < 0xD7) { + if (lbl_803D5A4C.entries[idx].kind < 0xD7) { flags = fn_8016F180(idx); if (arg4 & flags) { if (pl_80039418(arg5, idx) != 0) { @@ -226,7 +181,7 @@ int fn_8016F548(void* arg0, u16 arg1, u8 mask, u8 player_id) } for (i = arg1; (u32) i < 0x101U; i++) { - if (lbl_803D5A4C[i].kind < 0xD7) { + if (lbl_803D5A4C.entries[i].kind < 0xD7) { if (mask & (u8) fn_8016F180(i)) { if (pl_80039418(player_id, i) != 0) { return i; @@ -242,7 +197,7 @@ int fn_8016F548(void* arg0, u16 arg1, u8 mask, u8 player_id) } for (i = 0x100; i >= 0; i--) { - if (lbl_803D5A4C[i].kind < 0xD7) { + if (lbl_803D5A4C.entries[i].kind < 0xD7) { if (mask & (u8) fn_8016F180(i)) { if (pl_80039418(player_id, i) != 0) { return i; @@ -275,7 +230,7 @@ int fn_8016F740(void* arg0, u16 arg1, u8 mask, u8 player_id) i = temp; for (; (u32) i < 0x101U; i++) { - if (lbl_803D5A4C[i].kind < 0xD7) { + if (lbl_803D5A4C.entries[i].kind < 0xD7) { flags = fn_8016F180(i); if (mask & flags) { if (pl_80039418(player_id, i) != 0) { @@ -308,7 +263,7 @@ int fn_8016F870(void* arg0, u16 arg1, u8 mask, u8 player_id) } for (i = arg1 - 1; i >= 0; i--) { - kind = lbl_803D5A4C[i].kind; + kind = lbl_803D5A4C.entries[i].kind; if (kind < 0xD7) { flags = fn_8016F180(i); @@ -341,7 +296,7 @@ int fn_8016F9A8(void* arg0, u16 arg1, u8 mask, u8 player_id) } for (i = arg1; (u32) i < 0x101; i++) { - if (lbl_803D5A4C[i].kind < 0xD7) { + if (lbl_803D5A4C.entries[i].kind < 0xD7) { flags = fn_8016F180(i); if (mask & flags) { if (pl_80039418(player_id, i) != 0) { @@ -365,7 +320,7 @@ int fn_8016F9A8(void* arg0, u16 arg1, u8 mask, u8 player_id) int fn_8016FAD4(struct lbl_8046B6A0_24C_t* rules, int kind, int flags, u8 player) { - struct lbl_803D5A4C_t* entry = lbl_803D5A4C; + struct lbl_803D5A4C_t* entry = lbl_803D5A4C.entries; struct lbl_8046B6A0_24C_58_t* x58 = rules->x58; u8 rankings[7] = { 0 }; s32 scores[6]; @@ -381,7 +336,8 @@ int fn_8016FAD4(struct lbl_8046B6A0_24C_t* rules, int kind, int flags, for (i = 0; i < 6; i++) { if (x58[i].x0 != 3) { u16 sd = x58[i].xA; - scores[i] = x58[i].x20 - (x58[i].x24 - sd) + (s8) rules->xC * sd; + scores[i] = + x58[i].x20 - (x58[i].x24 - sd) + *(s8*) &rules->xC * sd; } } @@ -405,12 +361,13 @@ int fn_8016FAD4(struct lbl_8046B6A0_24C_t* rules, int kind, int flags, return lbl_803D5648[entry->x2 - 2] * 2; } { - int j; - for (j = 0; j < 4; j++) { - if (x58[j].x0 == 3) { - break; + int active_count = 0; + for (i = 0; i < 4; i++) { + if (x58[i].x0 != 3) { + active_count++; } } + (void) active_count; } if (pr == rankings[6]) { return lbl_803D5648[entry->x2 - 2] / 2; @@ -448,7 +405,7 @@ int fn_8016FFD4(struct lbl_8046B6A0_24C_t* arg0, int arg1, u8 arg2) int count = 0; for (i = 0; (u32) i < 0x101U; i++) { - if (lbl_803D5A4C[i].kind < 0xD7) { + if (lbl_803D5A4C.entries[i].kind < 0xD7) { if ((arg1 & 0xFF) & (u8) fn_8016F180(i) && pl_80039418(arg2, i) != 0) { @@ -468,8 +425,8 @@ int fn_8016FFD4(struct lbl_8046B6A0_24C_t* arg0, int arg1, u8 arg2) int fn_80170110(void* arg0, int idx, int mask, u8 player_id) { - struct lbl_803D5A4C_t* curr = lbl_803D5A4C; - int kind = lbl_803D5A4C[idx].kind; + struct lbl_803D5A4C_t* curr = lbl_803D5A4C.entries; + int kind = lbl_803D5A4C.entries[idx].kind; u8 flags; flags = (fn_8016F180(kind)); @@ -539,11 +496,11 @@ static inline void gm_16F1_SortAscPass(u32* base, u32 n) int fn_801701C0(void* arg0, int arg1, int arg2) { struct lbl_8046B6A0_24C_t* rules = arg0; - struct lbl_803B7A60_t* zeroes = &lbl_803B7A60; + const struct lbl_803B7A60_t* zeroes = &lbl_803B7A60; u8* flags = rules->pad3F0; struct lbl_8046B6A0_24C_58_t* x58 = rules->x58; s32 player_net; - s32 scores[6]; + s32 scores[4]; u8 rankings[7] = { 0 }; if (lbl_804D65A0 != 0) { @@ -562,7 +519,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) if (x58[k].x0 != 3) { u16 xA = x58[k].xA; scores[k] = - (x58[k].x20 - (x58[k].x24 - xA)) + ((s8) rules->xC * xA); + (x58[k].x20 - (x58[k].x24 - xA)) + *(s8*) &rules->xC * xA; } } @@ -588,8 +545,6 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } } - PAD_STACK(8); - switch (arg2) { case 0xD7: if ((unsigned) fn_801701C0(arg0, arg1, 0xD9) != 0) { @@ -655,7 +610,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } case 0xDB: { - s32 vals[4]; + s32 vals[6]; int i, j; if (x58[arg1].x20 >= 3) { { @@ -1613,6 +1568,51 @@ bool fn_80172768(void) return false; } +struct lbl_803D6300_t lbl_803D6300[] ATTRIBUTE_ALIGN(8) = { + { 0x0016, 0xFFFF, fn_801735F0 }, + { 0x0017, 0x0001, fn_80173644 }, + { 0x0018, 0xFFFF, fn_80173510 }, + { 0x0019, 0xFFFF, NULL }, + { 0x001A, 0xFFFF, NULL }, + { 0x001B, 0xFFFF, fn_8017367C }, + { 0x001C, 0xFFFF, gm_80164ABC }, + { 0x001D, 0xFFFF, gm_80164600 }, + { 0x001E, 0x0040, fn_80162CCC }, + { 0x001F, 0x0040, gm_80162EC8 }, + { 0x0020, 0x0040, fn_801630C4 }, + { 0x0021, 0x0040, gm_80162D1C }, + { 0x0022, 0x0040, gm_80162F18 }, + { 0x0023, 0x0040, gm_80163114 }, + { 0x0024, 0x0010, fn_801722BC }, + { 0x0025, 0x0010, fn_801722F4 }, + { 0x0026, 0x0080, gmMainLib_8015D508 }, + { 0x0027, 0x0020, fn_80163D24 }, + { 0x0028, 0x0020, fn_80163D74 }, + { 0x0029, 0x0040, fn_8017232C }, + { 0x002A, 0x0040, fn_80172428 }, + { 0x002B, 0x0040, fn_80172380 }, + { 0x002C, 0x0040, fn_80172478 }, + { 0x002D, 0x0040, fn_801723D4 }, + { 0x002E, 0x0040, fn_801724C8 }, + { 0x002F, 0x0001, fn_801724D0 }, + { 0x0030, 0x0001, fn_80172504 }, + { 0x0031, 0x0001, fn_80172538 }, + { 0x0032, 0x0001, fn_8017256C }, + { 0x0033, 0x0001, fn_801725A8 }, + { 0x0034, 0x0001, fn_801725E4 }, + { 0x0035, 0x0001, fn_80172624 }, + { 0x0036, 0x0001, fn_80172664 }, + { 0x0037, 0xFFFF, fn_80172698 }, + { 0x0038, 0xFFFF, fn_801726CC }, + { 0x0039, 0xFFFF, fn_80172700 }, + { 0x003A, 0xFFFF, fn_80172734 }, + { 0x003B, 0xFFFF, fn_80172768 }, + { 0x003C, 0xFFFF, un_80304470 }, + { 0x003D, 0xFFFF, un_80304510 }, + { 0x0041, 0x0010, gmMainLib_8015CF94 }, + { 0x0042, 0x0000, NULL }, +}; + bool fn_8017279C(int arg0, u16 arg1) { struct lbl_803D6300_t* cur = lbl_803D6300; diff --git a/src/melee/gm/gm_16F1.static.h b/src/melee/gm/gm_16F1.static.h index 1f3729b1bd..72ce21c530 100644 --- a/src/melee/gm/gm_16F1.static.h +++ b/src/melee/gm/gm_16F1.static.h @@ -64,8 +64,11 @@ struct lbl_803D5A4C_t { /* +6 */ u8 x6; }; -/* 3D5A4C */ static struct lbl_803D5A4C_t - lbl_803D5A4C[0x80C / sizeof(struct lbl_803D5A4C_t)] = { +/* 3D5A4C */ static struct { + struct lbl_803D5A4C_t entries[0x80C / sizeof(struct lbl_803D5A4C_t)]; + u8 pad[4]; +} lbl_803D5A4C = { + { { 0, 0x011, 0xFF, 0, 2 }, { 1, 0x012, 0xFF, 0, 0 }, { 2, 0x013, 0x7F, 1, 0 }, @@ -323,7 +326,8 @@ struct lbl_803D5A4C_t { { 0xFE, 0x0B4, 0x87, 0, 0 }, { 0xFF, 0x0B5, 0x87, 0, 0 }, { 0x29A }, - }; + }, +}; /* 4D65A0 */ static u8 lbl_804D65A0; /* 4D65A8 */ static u8 lbl_804D65A8[6]; @@ -345,7 +349,7 @@ struct lbl_803B7A60_t { /* 0x60 */ u32 x60[4]; }; -static struct lbl_803B7A60_t lbl_803B7A60 = { +static const struct lbl_803B7A60_t lbl_803B7A60 = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, diff --git a/src/melee/gm/gm_1832.c b/src/melee/gm/gm_1832.c index b2a37329cf..d66f4801f1 100644 --- a/src/melee/gm/gm_1832.c +++ b/src/melee/gm/gm_1832.c @@ -601,6 +601,24 @@ void fn_801852FC(HSD_GObj* gobj) lbl_804735E8.xE1 = 1; } +/// @todo .sdata2 order hack +static inline void gm_1832_sdata2_order(int unused) +{ + (void) unused; + (void) 280.0f; + (void) 290.0f; + (void) 40.0f; + (void) -60.0f; + (void) 160.0f; + (void) U32_TO_F32; + (void) 0.0; + (void) 0.5; + (void) 3.0; + (void) 200.0f; + (void) 340.0f; + (void) 10000.0f; +} + void fn_80185408(int x, float arg8, float arg9, float argA, float argB) { u8 _[0x30]; @@ -640,6 +658,7 @@ void fn_80185408(int x, float arg8, float arg9, float argA, float argB) GXWGFifo.f32 = -4932.0F; GXSetColorUpdate(1); HSD_StateInvalidate(-1); + gm_1832_sdata2_order(0); } extern float MSL_TrigF_80400770[]; @@ -1226,12 +1245,23 @@ void gm_Scene_IntroEasy_OnEnter(void* arg0_) gm_80168F88(); } +static inline void gm_1832_sdata2_order_tail1(int unused) +{ + (void) unused; + (void) 7.0f; +} + +#ifdef MUST_MATCH +static const f32 gm_1832_sdata2_tail0[1] ATTRIBUTE_ALIGN(8) = { 0.0f }; +#endif + void fn_80186EFC(HSD_GObj* gobj) { HSD_JObj* jobj = GET_JOBJ(gobj); gm_804736B0_t* state = &lbl_804736B0; int* counter; PAD_STACK(8); + gm_1832_sdata2_order_tail1(0); HSD_JObjReqAnimAll(state->xC, 0.0f); HSD_JObjAnimAll(jobj); counter = &state->x4; @@ -1242,6 +1272,11 @@ void fn_80186EFC(HSD_GObj* gobj) } } +#ifdef MUST_MATCH +static const f32 gm_1832_sdata2_tail2[1] = { 3.0f }; +static const f32 gm_1832_sdata2_tail3[1] = { 5.0f }; +#endif + typedef struct gm_80186F6C_Entry { /* 0x00 */ f32 x0; /* 0x04 */ f32 x4; @@ -1282,6 +1317,11 @@ static gm_80186F6C_Entry lbl_803D9498[] = { { -1.1f, 2.5f, 0.0f, 0.4f, 0.4f, 0.4f }, }; +/// Duplicate literals owned by the original All-Star intro split. +static char gm_80186F6C_JObjFile[7] ATTRIBUTE_ALIGN(8) = "jobj.h"; +static char gm_80186F6C_JObjCondition[5] = "jobj"; +static char gm_Scene_IntroAllstar_ArchiveName[] = "IrAls"; + void fn_80186F6C(HSD_GObj* arg0) { Vec3 pos; @@ -1323,6 +1363,8 @@ void fn_80186F6C(HSD_GObj* arg0) static HSD_Archive* lbl_804D6610; #ifdef MUST_MATCH +static const f32 gm_1832_sdata2_tail5[1] = { 1.0f }; + #pragma push #pragma dont_inline on #endif @@ -1358,6 +1400,10 @@ void fn_80187494(HSD_GObj* gobj, int arg1) static SceneDesc* lbl_804D6614; +#ifdef MUST_MATCH +static const f32 gm_1832_sdata2_tail6[1] = { 10000.0f }; +#endif + void fn_801874FC(void) { HSD_JObj* sp8; @@ -1380,6 +1426,8 @@ void fn_801874FC(void) lb_80011E24(jobj, &lbl_804736B0.xC, 6, -1); } +/// #fn_801874FC + #ifdef MUST_MATCH #pragma push #pragma dont_inline on @@ -1481,6 +1529,17 @@ static struct gm_1832_804736C0_t { ASSERT_SIZE(struct gm_1832_804736C0_t, 0x40); typedef struct gm_1832_804736C0_t gm_1832_804736C0_t; +#ifdef MUST_MATCH +static const f32 gm_1832_sdata2_tail7[1] ATTRIBUTE_ALIGN(8) = { 0.0f }; +static const f64 gm_1832_sdata2_tail8[1] = { S32_TO_F32 }; +#endif + +static inline void gm_1832_sdata2_order_tail9(int unused) +{ + (void) unused; + (void) 0.0166666675f; +} + void fn_80187910(HSD_GObj* arg0) { Vec3 sp10; @@ -1515,6 +1574,7 @@ void fn_80187910(HSD_GObj* arg0) sp10.y *= scale; sp10.z *= scale; HSD_CObjSetEyePosition(cobj, &sp10); + gm_1832_sdata2_order_tail9(0); } typedef struct { @@ -1648,7 +1708,7 @@ void fn_80187CF4(HSD_GObj* gobj) HSD_JObjAnimAll(gobj->hsd_obj); } -static char lbl_804D4138[] = "IrNml"; +static char gm_Scene_IntroAllstar_SceneDataName[] = "ScItrAllstar_scene_data"; static char* lbl_803D9750[] = { "mc01", @@ -1738,11 +1798,10 @@ static inline void gm_80187F48_SetupCamera(HSD_GObj* gobj, static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) { gm_1832_804736C0_t* data; + char** table = lbl_803D9750; HSD_CObj* cobj; - u8 stage_index; HSD_GObj* gobj; - char** table = lbl_803D9750; - gm_1832_StageState* state; + u8 stage_index; data = &lbl_804736C0; data->x38 = arg0->x0; @@ -1770,7 +1829,7 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) data->x36.active = 0; stage_index = arg0->stage_index; - lbl_804D6620 = lbArchive_80016DBC(lbl_804D4138, &data->x0, &table[48], + lbl_804D6620 = lbArchive_80016DBC("IrNml", &data->x0, &table[48], &data->x4, table[stage_index], NULL); lbAudioAx_80026F2C((s32) table[stage_index + 12]); @@ -1802,13 +1861,12 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) GObj_SetupGXLink(light_gobj, HSD_GObj_LObjCallback, 0xA, 0); } - state = &data->x36; { HSD_JObj* model_jobj; HSD_GObj* model_gobj; model_gobj = GObj_Create(0xE, 0xF, 0); model_jobj = - HSD_JObjLoadJoint((*data->x0)[11 - state->stage_index]->joint); + HSD_JObjLoadJoint((*data->x0)[11 - data->x36.stage_index]->joint); lb_80011C18(model_jobj, 0x08000000); HSD_GObjObject_80390A70(model_gobj, HSD_GObj_JObjKind, model_jobj); GObj_SetupGXLink(model_gobj, fn_80187C9C, 0xB, 0xB); diff --git a/src/melee/gm/gm_1884.c b/src/melee/gm/gm_1884.c index d5f72a3a12..2c9ff556a1 100644 --- a/src/melee/gm/gm_1884.c +++ b/src/melee/gm/gm_1884.c @@ -40,9 +40,34 @@ #include #include +/// @todo .sdata2 order hack +static inline void gm_1884_sdata2_order(void) +{ + (void) U32_TO_F32; + (void) 10.0f; + (void) 1.0f; + (void) S32_TO_F32; + (void) 50.0f; + (void) 12.0f; + (void) 9.79882812f; + (void) 150.0f; + (void) 0.100000001f; + (void) 167.0f; + (void) 16.0f; + (void) 0.699999988f; + (void) 0.600000024f; + (void) 0.0f; + (void) 100.0f; +} + typedef struct { - HSD_GObjEvent v[6]; -} ClassicProcArray; + f32 values[6]; +} TrainingSpeedArray; + +typedef struct { + TrainingSpeedArray speeds; + u8 pad[8]; +} TrainingSpeedStack; typedef struct { u8 b7 : 1, b6 : 1, b5 : 1, b4 : 1, b3 : 1, b2 : 1, b1 : 1, b0 : 1; @@ -57,7 +82,7 @@ typedef struct TrainingItemEntry { } TrainingItemEntry; ASSERT_SIZE(TrainingItemEntry, 4); -TrainingItemEntry lbl_803D9828[] = { +static TrainingItemEntry gmTraining_ItemTable[] = { { It_Kind_Foods, 21 }, { It_Kind_Tomato, 11 }, { It_Kind_Heart, 10 }, { It_Kind_L_Gun, 18 }, { It_Kind_F_Flower, 35 }, { It_Kind_S_Scope, 25 }, @@ -76,13 +101,13 @@ TrainingItemEntry lbl_803D9828[] = { { It_Kind_None, 23 }, }; -f32 const lbl_803B7C68[] = { - 2.0f, 1.5f, 1.0f, 0.666f, 0.5f, 0.25f, +TrainingSpeedArray const lbl_803B7C68 = { + { 2.0f, 1.5f, 1.0f, 0.666f, 0.5f, 0.25f }, }; static inline TrainingItemEntry* TrainingItemTable_Get(void) { - return (TrainingItemEntry*) lbl_803D9828; + return (TrainingItemEntry*) gmTraining_ItemTable; } /// Classic mode stage data table entry (size 0x10) @@ -96,14 +121,13 @@ typedef struct ClassicStageEntry { } ClassicStageEntry; ASSERT_SIZE(ClassicStageEntry, 0x10); -ClassicStageEntry lbl_803D9910[65] = { 0 }; - /* 473700 */ static TrainingModeState lbl_80473700; /* 473814 */ struct TrainingMenuData gm_80473814; /* 473A18 */ UnkAllstarData gm_80473A18; int gm_80188454(int idx) { + gm_1884_sdata2_order(); return lbl_80473700.char_data[idx]; } @@ -431,6 +455,11 @@ void fn_80188EE8(HSD_GObj* gobj) sub->anim_frames[22]++; sub->anim_frames[1] = sub->anim_frames[22]; } +#ifdef MUST_MATCH + /// @remark Matching tactic: keep counter live through the update block + /// so MWCC allocates the range-check value to r4. + (void) sub->anim_frames[counter]; +#endif } HSD_JObjReqAnimAll(sub->jobjs[22], (f32) (u32) sub->anim_frames[22]); @@ -507,31 +536,38 @@ static inline s32* gm_801891F4_GetMenuValues(CssSubStruct* sub) return sub->menu_values; } +static inline void gm_801891F4_SetCpuType(int cpu_type) +{ + int i; + int count; + + count = lbl_80473700.count; + lbl_80473700.css.x03 = (u8) cpu_type; + for (i = 0; i < 4; i++) { + if (i != 0 && count != 0) { + Player_SetPlayerAndEntityCpuType(i, cpu_type); + count--; + if (count == 0) { + break; + } + } + } +} + void fn_801891F4(void) { CssSubStruct* sub; u64 buttons; + TrainingSpeedStack speed_stack; + Vec3 pos; buttons = gm_801A36C0((u8) lbl_80473700.mode); sub = &lbl_80473700.css; if (gm_801A45E8(2) != 0) { - int count; - int i; - if (sub->x01 == 0) { fn_801651FC(0, 0); - count = lbl_80473700.count; - lbl_80473700.css.x03 = 0; - for (i = 0; i < 4; i++) { - if (i != 0 && count != 0) { - Player_SetPlayerAndEntityCpuType(i, 0); - count--; - if (count == 0) { - break; - } - } - } + gm_801891F4_SetCpuType(0); sub->anim_frames[22] = 0; } sub->x01 = 1; @@ -598,14 +634,12 @@ void fn_801891F4(void) } } if (buttons & PAD_BUTTON_A) { - HSD_JObj* jobj; - HSD_GObj* player_entity; - Vec3 pos; s16 item; + HSD_JObj* jobj; lbAudioAx_80024030(8); - item = *(s16*) &((s32*) lbl_803D9828)[sub->menu_values[1]]; - player_entity = Player_GetEntity(0); - jobj = player_entity->hsd_obj; + item = gmTraining_ItemTable[lbl_80473700.css.menu_values[1]] + .item_id; + jobj = Player_GetEntity(0)->hsd_obj; HSD_JObjGetTranslation2(jobj, &pos); pos.y += 10.0f; it_8026D258(&pos, (ItemKind) item); @@ -616,7 +650,7 @@ void fn_801891F4(void) if (buttons & PAD_ANY_LEFT) { sfxMove(); if ((u32) sub->menu_values[sub->x00] != 0) { - gm_801891F4_GetMenuValues(sub)[sub->x00]--; + sub->menu_values[sub->x00]--; return; } sub->menu_values[sub->x00] = 2; @@ -656,7 +690,7 @@ void fn_801891F4(void) if (buttons & PAD_ANY_LEFT) { sfxMove(); if ((u32) sub->menu_values[sub->x00] != 0) { - sub->menu_values[sub->x00]--; + gm_801891F4_GetMenuValues(sub)[sub->x00]--; if ((u32) sub->menu_values[sub->x00] == 0) { gm_801A36E0(0, 0x19); return; @@ -754,19 +788,15 @@ void fn_801891F4(void) } } else { if (sub->x01 == 1) { - int count; - int i; - int cpu_type; - f32 speeds[] = { - 2, 1.5, 1, 0.666, 0.5, 0.25, - }; + PAD_STACK(20); - PAD_STACK(32); + speed_stack.speeds = lbl_803B7C68; sfxBack(); sub->anim_frames[22] = 0x14; { - f32 selected_speed = speeds[sub->menu_values[0]]; + f32 selected_speed = + speed_stack.speeds.values[sub->menu_values[0]]; lb_80019880( __cvt_dbl_usll((f64) (0.016666668f / selected_speed * (f32) gm_801891F4_GetTickRate()))); @@ -774,19 +804,7 @@ void fn_801891F4(void) fn_80188550(sub->menu_values[2] + 1); - cpu_type = sub->menu_values[3]; - (void) cpu_type; - count = lbl_80473700.count; - lbl_80473700.css.x03 = (u8) cpu_type; - for (i = 0; i < 4; i++) { - if (i != 0 && count != 0) { - Player_SetPlayerAndEntityCpuType(i, cpu_type); - count--; - if (count == 0) { - break; - } - } - } + gm_801891F4_SetCpuType(sub->menu_values[3]); { int count; @@ -913,7 +931,7 @@ HSD_Text* fn_8018A000(void) HSD_Text* text; PAD_STACK(0x10); - data = M2C_BITWISE(u8*, lbl_803D9828); + data = M2C_BITWISE(u8*, gmTraining_ItemTable); state = &lbl_80473700; memzero(state->result_cache, sizeof(state->result_cache)); lbl_804D6628 = @@ -942,47 +960,131 @@ HSD_Text* fn_8018A000(void) return text; } +char gmTraining_SceneModelsName[] = "ScGamTraining_scene_models"; +char gmTraining_UsdName[] = "SdTrain.usd"; +char gmTraining_SisDataName[] = "SIS_TrainingData"; +char gmTraining_DatName[] = "SdTrain.dat"; + +ClassicStageEntry gmTraining_ClassicStages[65] = { + { 4, 0, 50, 170, { 0, 1, 0x17, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 70, 140, { 1, 1, 0x17, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 80, 120, { 3, 1, 0x17, 0, 0, 0, 0, 0, 0, 0 } }, + { 2, 0, 90, 100, { 5, 1, 0x17, 0, 0, 0, 0, 0, 0, 0 } }, + { 1, 0, 100, 95, { 7, 1, 0x17, 0, 0, 0, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 1, 2, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 70, 140, { 3, 2, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 80, 115, { 4, 2, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 2, 0, 90, 100, { 6, 2, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 1, 0, 100, 95, { 8, 2, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 2, 3, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 70, 140, { 4, 3, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 80, 110, { 5, 3, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 2, 0, 90, 100, { 7, 3, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 1, 0, 100, 95, { 9, 3, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 3, 1, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 70, 140, { 5, 1, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 80, 120, { 6, 1, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 2, 0, 90, 105, { 8, 1, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 1, 0, 100, 95, { 9, 1, 4, 0, 0, 0, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 0, 2, 0x17, 0, 2, 0x17, 0, 0, 0, 0 } }, + { 3, 0, 67, 140, { 2, 2, 0x17, 2, 2, 0x17, 0, 0, 0, 0 } }, + { 3, 0, 78, 120, { 3, 2, 0x17, 3, 2, 0x17, 0, 0, 0, 0 } }, + { 2, 0, 90, 105, { 5, 2, 4, 4, 2, 4, 0, 0, 0, 0 } }, + { 1, 0, 100, 100, { 6, 2, 4, 6, 2, 4, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 1, 3, 0x17, 1, 3, 0x17, 0, 0, 0, 0 } }, + { 3, 0, 67, 140, { 3, 3, 4, 3, 3, 0x17, 0, 0, 0, 0 } }, + { 3, 0, 78, 120, { 4, 3, 4, 3, 3, 4, 0, 0, 0, 0 } }, + { 2, 0, 90, 105, { 5, 3, 4, 5, 3, 4, 0, 0, 0, 0 } }, + { 1, 0, 100, 100, { 7, 3, 4, 7, 3, 4, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 2, 1, 0x17, 1, 1, 0x17, 0, 0, 0, 0 } }, + { 3, 0, 70, 140, { 3, 1, 4, 3, 1, 4, 0, 0, 0, 0 } }, + { 3, 0, 78, 120, { 4, 1, 4, 4, 1, 4, 0, 0, 0, 0 } }, + { 2, 0, 90, 105, { 6, 1, 4, 5, 1, 4, 0, 0, 0, 0 } }, + { 1, 0, 102, 100, { 8, 1, 4, 7, 1, 4, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 2, 2, 4, 2, 2, 4, 0, 0, 0, 0 } }, + { 3, 0, 70, 130, { 3, 2, 4, 3, 2, 4, 0, 0, 0, 0 } }, + { 3, 0, 80, 110, { 5, 2, 4, 4, 2, 4, 0, 0, 0, 0 } }, + { 2, 0, 90, 105, { 7, 2, 4, 5, 2, 4, 0, 0, 0, 0 } }, + { 1, 0, 105, 100, { 9, 2, 4, 8, 2, 4, 0, 0, 0, 0 } }, + { 4, 0, 50, 170, { 0, 3, 0x17, 0, 3, 0x17, 0, 3, 0x17, 0 } }, + { 3, 0, 67, 130, { 2, 3, 0x17, 2, 3, 0x17, 1, 3, 0x17, 0 } }, + { 3, 0, 78, 110, { 3, 3, 0x17, 3, 3, 0x17, 3, 3, 0x17, 0 } }, + { 2, 0, 89, 100, { 4, 3, 4, 4, 3, 0x17, 4, 3, 0x17, 0 } }, + { 1, 0, 100, 100, { 6, 3, 4, 6, 3, 4, 6, 3, 0x17, 0 } }, + { 4, 0, 50, 170, { 1, 1, 0x17, 1, 1, 0x17, 1, 1, 0x17, 0 } }, + { 3, 0, 69, 125, { 2, 1, 0x17, 2, 1, 0x17, 2, 1, 0x17, 0 } }, + { 3, 0, 75, 110, { 4, 1, 0x11, 4, 1, 0x17, 3, 1, 0x17, 0 } }, + { 2, 0, 89, 100, { 5, 1, 4, 4, 1, 0x11, 4, 1, 0x17, 0 } }, + { 1, 0, 100, 100, { 7, 1, 4, 7, 1, 4, 7, 1, 0x11, 0 } }, + { 4, 0, 50, 170, { 1, 2, 0x17, 1, 2, 0x17, 1, 2, 0x17, 0 } }, + { 3, 0, 70, 125, { 3, 2, 0x11, 3, 2, 0x17, 3, 2, 0x17, 0 } }, + { 3, 0, 79, 112, { 4, 2, 4, 4, 2, 0x11, 4, 2, 0x17, 0 } }, + { 2, 0, 90, 100, { 5, 2, 4, 5, 2, 4, 4, 2, 0x11, 0 } }, + { 1, 0, 100, 100, { 8, 2, 4, 8, 2, 4, 7, 2, 4, 0 } }, + { 4, 0, 50, 170, { 2, 3, 0x17, 2, 3, 0x17, 1, 3, 0x17, 0 } }, + { 3, 0, 70, 125, { 4, 3, 0x11, 4, 3, 4, 3, 3, 0x17, 0 } }, + { 3, 0, 80, 110, { 5, 3, 4, 4, 3, 0x11, 4, 3, 0x17, 0 } }, + { 2, 0, 92, 100, { 6, 3, 4, 5, 3, 4, 5, 3, 0x11, 0 } }, + { 1, 0, 105, 96, { 9, 3, 4, 8, 3, 4, 8, 3, 0x11, 0 } }, + { 4, 0, 20, 360, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 30, 320, { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { 3, 0, 40, 300, { 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { 2, 0, 48, 240, { 5, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { 1, 0, 55, 200, { 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, +}; + +#ifdef MUST_MATCH +static const f64 gm_1884_sdata2_order_u32[1] = { U32_TO_F32 }; +#endif + u8 gm_8018A160(u8 difficulty, u8 stage_slot) { - return lbl_803D9910[stage_slot + (difficulty * 5)].stage_kind; + return gmTraining_ClassicStages[stage_slot + (difficulty * 5)].stage_kind; } f32 gm_8018A188(u8 difficulty, u8 stage_slot) { - return (f32) lbl_803D9910[stage_slot + (difficulty * 5)].scale0_pct / + return (f32) gmTraining_ClassicStages[stage_slot + (difficulty * 5)] + .scale0_pct / 100.0F; } f32 gm_8018A1D8(u8 difficulty, u8 stage_slot) { - return (f32) lbl_803D9910[stage_slot + (difficulty * 5)].scale1_pct / + return (f32) gmTraining_ClassicStages[stage_slot + (difficulty * 5)] + .scale1_pct / 100.0F; } u8 gm_8018A228(u8 difficulty, u8 stage_slot, u8 idx) { - return lbl_803D9910[stage_slot + (difficulty * 5)].pad_6[idx * 3]; + return gmTraining_ClassicStages[stage_slot + (difficulty * 5)] + .pad_6[idx * 3]; } u8 gm_8018A25C(u8 difficulty, u8 stage_slot, u8 arg2) { - return lbl_803D9910[stage_slot + difficulty * 5].pad_6[arg2 * 3 + 1]; + return gmTraining_ClassicStages[stage_slot + difficulty * 5] + .pad_6[arg2 * 3 + 1]; } u8 gm_8018A290(u8 difficulty, u8 stage_slot, u8 idx) { - return lbl_803D9910[stage_slot + (difficulty * 5)].pad_6[2 + idx * 3]; + return gmTraining_ClassicStages[stage_slot + (difficulty * 5)] + .pad_6[2 + idx * 3]; } f32 gm_8018A2C4(u8 difficulty, u8 stage_slot) { - return (f32) lbl_803D9910[stage_slot + (difficulty * 5)].scale0_pct / + return (f32) gmTraining_ClassicStages[stage_slot + (difficulty * 5)] + .scale0_pct / 100.0F; } f32 gm_8018A314(u8 difficulty, u8 stage_slot) { - return (f32) lbl_803D9910[stage_slot + (difficulty * 5)].scale1_pct / + return (f32) gmTraining_ClassicStages[stage_slot + (difficulty * 5)] + .scale1_pct / 100.0F; } diff --git a/src/melee/gm/gm_19EF.c b/src/melee/gm/gm_19EF.c index 431151e104..2862c929ba 100644 --- a/src/melee/gm/gm_19EF.c +++ b/src/melee/gm/gm_19EF.c @@ -63,23 +63,33 @@ static u32 lbl_804D66F8; static struct { u8 x0; u8 pad_01[0x3]; - s32 x4; - int x8; - s32 xC; - u32 x10; - u8 x14; - u8 x15; - u8 x16; - u8 pad_17; - int x18; - u16 x1C; - u16 x1E; - u8 x20; - u8 pad_21; - u16 x22; - HSD_Text* x24; - HSD_GObj* x28; - HSD_JObj* x2C[10]; + union { + struct { + s32 x4; + int x8; + s32 xC; + u32 x10; + u8 x14; + u8 x15; + u8 x16; + u8 pad_17; + int x18; + u16 x1C; + u16 x1E; + u8 x20; + u8 pad_21; + u16 x22; + HSD_Text* x24; + union { + struct { + HSD_GObj* gobj; + HSD_JObj* jobjs[10]; + } typed; + HSD_JObj* jobj_slots[11]; + } x28; + }; + HSD_JObj* jobj_slots[20]; + }; HSD_JObj* x54; HSD_JObj* x58; HSD_JObj* x5C; @@ -99,7 +109,7 @@ static void fn_8019EFC4(HSD_PadStatus* pad) HSD_JObj* child_next; HSD_JObj* jobj; - jobj = lbl_80479A98.x28->hsd_obj; + jobj = lbl_80479A98.x28.typed.gobj->hsd_obj; if (lbl_80479A98.x60 != 0) { if (jobj == NULL) { jobj = NULL; @@ -364,6 +374,86 @@ static inline s32 fn_8019F9C4_GetCharIdx(CharacterKind arg0) } } +static inline void fn_8019F9C4_LoadSymbols(u32 arg0) +{ + u8 game_mode = gm_GetCurrentGameMode(); + char* model_name = gm_80160564(arg0, game_mode); + char* scene_name = gm_801604DC(arg0, game_mode); + + lbArchive_LoadSymbols(scene_name, &lbl_804D66AC, model_name, 0); + lbArchive_LoadSymbols("GmGoAnim.dat", &lbl_804D66A4, + "ScGamRegGover_scene_data", 0); + lbArchive_LoadSymbols("GmRgStnd.dat", &lbl_804D66A8, "standScene", 0); +} + +static inline void fn_8019F9C4_inline1(HSD_JObj* next, HSD_JObj** child) +{ + if (next == NULL) { + *child = NULL; + } else { + *child = next->child; + } + lbl_80479A98.x54 = *child; + + if (lbl_80479A98.x54 == NULL) { + *child = NULL; + } else { + *child = lbl_80479A98.x54->next; + } + lbl_80479A98.x58 = *child; + + if (lbl_80479A98.x58 == NULL) { + *child = NULL; + } else { + *child = lbl_80479A98.x58->next; + } +} + +static inline void fn_8019F9C4_inline2(HSD_JObj* next_jobj, HSD_JObj* model) +{ + HSD_JObj* node; + + if (next_jobj == NULL) { + node = NULL; + } else { + node = next_jobj->child; + } + lb_8000C290(model, node); +} + +static inline void fn_8019F9C4_inline3(HSD_JObj* model, HSD_GObj* object, + CharacterKind arg0) +{ + HSD_JObj* child; + s32 char_idx; + f32 f; + f32 scale; + + lbl_804D66B8 = model; + HSD_GObjObject_80390A70(object, HSD_GObj_JObjKind, model); + GObj_SetupGXLink(object, HSD_GObj_JObjCallback, 0xB, 0); + char_idx = fn_8019F9C4_GetCharIdx(arg0); + + if (model == NULL) { + child = NULL; + } else { + child = model->child; + } + + HSD_JObjSetTranslateX(child, Toy_803060BC(char_idx, 0)); + HSD_JObjSetTranslateY(child, Toy_803060BC(char_idx, 1)); + HSD_JObjSetTranslateZ(child, Toy_803060BC(char_idx, 2)); + HSD_JObjSetRotationY(child, 0.017453292f * Toy_803060BC(char_idx, 5)); + f = Toy_803060BC(char_idx, 4); + scale = Toy_803060BC(char_idx, 3) / f; + HSD_JObjSetScaleX(child, scale); + HSD_JObjSetScaleY(child, scale); + HSD_JObjSetScaleZ(child, scale); + HSD_JObjSetScaleX(model, 2.0f); + HSD_JObjSetScaleY(model, 2.0f); + HSD_JObjSetScaleZ(model, 2.0f); +} + void fn_8019F9C4(u32 arg0) { HSD_CObj* cobj; @@ -376,9 +466,6 @@ void fn_8019F9C4(u32 arg0) HSD_JObj** ptr; s32 char_idx; s32 i; - f32 f; - f32 scale; - PAD_STACK(16); char_idx = fn_8019F9C4_GetCharIdx(arg0); arg0 = (char_idx == -1) ? 8 : arg0; @@ -389,15 +476,14 @@ void fn_8019F9C4(u32 arg0) "ScGamRegGover_scene_data", 0); Toy_803124BC(); Toy_803102D0(); - { - u8 game_mode = gm_GetCurrentGameMode(); - char* model_name = gm_80160564(arg0, game_mode); - char* scene_name = gm_801604DC(arg0, game_mode); - lbArchive_LoadSymbols(scene_name, &lbl_804D66AC, model_name, 0); - lbArchive_LoadSymbols("GmGoAnim.dat", &lbl_804D66A4, - "ScGamRegGover_scene_data", 0); - lbArchive_LoadSymbols("GmRgStnd.dat", &lbl_804D66A8, "standScene", 0); - } + fn_8019F9C4_LoadSymbols(arg0); +#ifdef MUST_MATCH + // Preserve the retail literal order across the later inlined JObj helpers. + (void) 0.1f; + (void) "SdIntro.dat"; + (void) "SIS_IntroData"; + (void) " "; +#endif cobj = HSD_CObjLoadDesc(lbl_804D669C->cameras->desc); cam_gobj = GObj_Create(0x13, 0x14, 0); HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_CameraKind, cobj); @@ -442,21 +528,17 @@ void fn_8019F9C4(u32 arg0) HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); gm_8016895C(jobj, lbl_804D66A0->models[0], 0); - lbl_80479A98.x28 = gobj; + lbl_80479A98.x28.typed.gobj = gobj; if (jobj == NULL) { child = NULL; } else { child = jobj->child; } - if (child == NULL) { - node = NULL; - } else { - node = child->child; - } + node = child == NULL ? NULL : child->child; - for (i = 0; i < 10; i++) { - lbl_80479A98.x2C[i] = node; + for (i = 10; i < 20; i++) { + lbl_80479A98.jobj_slots[i] = node; if (node->next != NULL) { node = node->next; } @@ -475,25 +557,7 @@ void fn_8019F9C4(u32 arg0) next = child->next; } - if (next == NULL) { - child = NULL; - } else { - child = next->child; - } - lbl_80479A98.x54 = child; - - if (lbl_80479A98.x54 == NULL) { - child = NULL; - } else { - child = lbl_80479A98.x54->next; - } - lbl_80479A98.x58 = child; - - if (lbl_80479A98.x58 == NULL) { - child = NULL; - } else { - child = lbl_80479A98.x58->next; - } + fn_8019F9C4_inline1(next, &child); lbl_80479A98.x5C = child; { @@ -567,39 +631,18 @@ void fn_8019F9C4(u32 arg0) } else { next = child->child; } - if (next == NULL) { - node = NULL; - } else { - node = next->child; + fn_8019F9C4_inline2(next, jobj); + { + HSD_GObj* character_gobj = +#ifdef MUST_MATCH + // Preserve the retail return-value copy. + character_gobj = +#endif + GObj_Create(0xE, 0xF, 0); + gobj = character_gobj; } - lb_8000C290(jobj, node); - - gobj = GObj_Create(0xE, 0xF, 0); jobj = HSD_JObjLoadJoint(lbl_804D66AC); - lbl_804D66B8 = jobj; - HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); - - char_idx = fn_8019F9C4_GetCharIdx(arg0); - - if (jobj == NULL) { - child = NULL; - } else { - child = jobj->child; - } - - HSD_JObjSetTranslateX(child, Toy_803060BC(char_idx, 0)); - HSD_JObjSetTranslateY(child, Toy_803060BC(char_idx, 1)); - HSD_JObjSetTranslateZ(child, Toy_803060BC(char_idx, 2)); - HSD_JObjSetRotationY(child, 0.017453292f * Toy_803060BC(char_idx, 5)); - f = Toy_803060BC(char_idx, 4); - scale = Toy_803060BC(char_idx, 3) / f; - HSD_JObjSetScaleX(child, scale); - HSD_JObjSetScaleY(child, scale); - HSD_JObjSetScaleZ(child, scale); - HSD_JObjSetScaleX(jobj, 2.0f); - HSD_JObjSetScaleY(jobj, 2.0f); - HSD_JObjSetScaleZ(jobj, 2.0f); + fn_8019F9C4_inline3(jobj, gobj, arg0); lb_8000C1C0(jobj, lbl_804D66E8); lb_8000C290(jobj, lbl_804D66E8); @@ -607,8 +650,11 @@ void fn_8019F9C4(u32 arg0) HSD_SisLib_803A611C(0, cam_gobj, 9, 0x12, 0, 0xB, 0, 0x13); HSD_SisLib_803A62A0(0, "SdIntro.dat", "SIS_IntroData"); lbl_80479A98.x24 = HSD_SisLib_803A6754(0, 0); - lbl_80479A98.x24->font_size.x = 0.1f; - lbl_80479A98.x24->font_size.y = 0.1f; + { + HSD_Text* text = lbl_80479A98.x24; + text->font_size.x = 0.1f; + text->font_size.y = 0.1f; + } lbl_80479A98.x24->default_alignment = 2; HSD_SisLib_803A6B98(lbl_80479A98.x24, 240.0f, 176.0f, " "); if (lbl_80479A98.x20 == 0) { diff --git a/src/melee/gm/gmallstar.c b/src/melee/gm/gmallstar.c index d60d8cdfb0..9ae0ead689 100644 --- a/src/melee/gm/gmallstar.c +++ b/src/melee/gm/gmallstar.c @@ -380,6 +380,19 @@ static AllstarRoundInfo gm_803DEC4C[13] = { gm_80490940_t gm_80490940[5]; +static inline void gm_801B5324_inline(s8* char_ids, gm_803DEBE8_t* opp_data, + s32 round) +{ + s32 i; + + for (i = 0; i < 3; i++) { + char_ids[i] = 0x21; + } + for (i = 0; i < (s32) gm_803DEC4C[round].count; i++) { + char_ids[i] = opp_data[i].x3; + } +} + void gm_801B5324(UnkAllstarData* arg0, u8 arg1) { s8 chars[3]; @@ -389,34 +402,27 @@ void gm_801B5324(UnkAllstarData* arg0, u8 arg1) gm_803DEBE8_t* opp_data; struct GameCache* gc; s32 slot_idx; - s32 count_processed; s32 i; u64 audio; - PAD_STACK(16); + PAD_STACK(4); is_last_round = 0; - chars_ptr = chars; - - opp_data = &gm_803DEBE8[gm_803DEC4C[arg1].start]; - chars_ptr[0] = 0x21; - chars_ptr[1] = 0x21; - chars_ptr[2] = 0x21; - - for (count_processed = 0; count_processed < (s32) gm_803DEC4C[arg1].count; - count_processed++) { - chars[count_processed] = opp_data[count_processed].x3; + u32 start = gm_803DEC4C[arg1].start; + opp_data = &gm_803DEBE8[start]; } + gm_801B5324_inline(chars, opp_data, arg1); + for (i = 0; i < 3; i++) { colors[i] = arg0->x54(arg1, arg0->x0.cpu_level, (u8) i); } - gmRegSetupEnemyColorTable(arg0->x0.ckind, arg0->x0.color, chars_ptr, - colors); + gmRegSetupEnemyColorTable(arg0->x0.ckind, arg0->x0.color, chars, colors); - if ((s32) arg1 == 0xC) { + chars_ptr = chars; + if (arg1 == 0xC) { chars_ptr[0] = 3; colors[0] = 0; is_last_round = 1; @@ -453,9 +459,9 @@ void gm_801B5324(UnkAllstarData* arg0, u8 arg1) audio = lbAudioAx_80026E84((CharacterKind) arg0->x0.ckind); { - for (i = 0; i < 3; i++) { - CharacterKind ckind = chars[i]; - audio |= lbAudioAx_80026E84(ckind); + s32 j; + for (j = 0; j < 3; j++) { + audio |= lbAudioAx_80026E84(chars[j]); } } @@ -582,16 +588,12 @@ void fn_801B5AA8(int arg0) lbBgFlash_8002063C(0x78); } -static inline void gm_801B5ACC_inline0(StartMeleeData* data, - GameModeState* arg0, u16* round) +static inline u16 gm_801B5ACC_inline0(StartMeleeData* match_data, + GameModeState* arg0) { - data->players[0].xD_b2 = 1; - data->rules.x7 = 9; - - { - u16 current_round = gm_8017BE84(arg0->id); - *round = current_round; - } + match_data->players[0].xD_b2 = 1; + match_data->rules.x7 = 9; + return gm_8017BE84(arg0->id); } static inline void gm_801B5ACC_inline1(AllstarRoundInfo* ri) @@ -609,11 +611,10 @@ static inline void gm_801B5ACC_inline1(AllstarRoundInfo* ri) void gm_801B5ACC(GameModeState* arg0) { s8 chars[3]; - StartMeleeData* data; + u8 color; u8* base; - UnkAllstarData* allstar; u16 round; - u8 color; + StartMeleeData* data; s32 i; s32 next_count; @@ -623,8 +624,7 @@ void gm_801B5ACC(GameModeState* arg0) chars[2] = 0x21; base = (u8*) gm_Mode_AllStar_States; data = gm_GetGameModeStateEnterData(arg0); - allstar = &gm_80473A18; - allstar->x0.x8 |= 0x80; + gm_80473A18.x0.x8 |= 0x80; round = gm_8017BE84(arg0->id); { @@ -633,56 +633,53 @@ void gm_801B5ACC(GameModeState* arg0) color = ((u8*) gm_80490940)[((u32) opp - (u32) (base + 0x2B8)) >> 2]; } - gm_8017CE34(data, (UnkAdventureData*) allstar, chars, 0, 0, 0, 0, 0x55, 0, - (s32) color); + gm_8017CE34(data, (UnkAdventureData*) &gm_80473A18, chars, 0, 0, 0, 0, + 0x55, 0, (s32) color); data->rules.x0_6 = 0; data->rules.timer_counts_up = 1; data->rules.x1_0 = 1; - data->rules.time_limit = (s32) allstar->x9C / 60; - data->rules.x14 = (s32) allstar->x9C % 60; + data->rules.time_limit = (s32) gm_80473A18.x9C / 60; + data->rules.x14 = (s32) gm_80473A18.x9C % 60; data->rules.xD = 0x78; - data->players[0].x10 = allstar->x74; - gm_801B5ACC_inline0(data, arg0, &round); + data->players[0].x10 = gm_80473A18.x74; + round = gm_801B5ACC_inline0(data, arg0); { + UnkAllstarData* allstar = &gm_80473A18; AllstarRoundInfo* ri = &gm_803DEC4C[round]; - u8* slot_base = allstar->x76; + s32 next_start; + for (i = 0; i < (s32) ri->count; i++) { u8* slot_ptr; s32 slot; do { slot = HSD_Randi(0x1A); - slot_ptr = &slot_base[slot]; + slot_ptr = &allstar->x76[slot]; } while ((s32) *slot_ptr != 0x21); *slot_ptr = gm_803DEBE8[i + ri->start].x3; } - } - { - AllstarRoundInfo* ri2 = &gm_803DEC4C[round]; - s32 next_start; - - next_count = (s32) ri2[1].count; - next_start = (s32) ri2[1].start; + next_count = (s32) ri[1].count; + next_start = (s32) ri[1].start; for (i = 0; i < next_count; i++) { allstar->_94[2 + i] = gm_803DEBE8[next_start + i].x3; } - } - allstar->_94[1] = (u8) next_count; - allstar->_94[0] = (u8) (round + 1); - data->players[0].xC_b1 = 0; - data->rules.x1_2 = 1; - data->rules.x1_3 = 1; - data->rules.x4_4 = 0; - gm_LoadRumbleEnabled(data); - gm_8016A92C(&data->rules); + allstar->_94[1] = (u8) next_count; + allstar->_94[0] = (u8) (round + 1); + data->players[0].xC_b1 = 0; + data->rules.x1_2 = 1; + data->rules.x1_3 = 1; + data->rules.x4_4 = 0; + gm_LoadRumbleEnabled(data); + gm_8016A92C(&data->rules); - gm_801B5ACC_inline1(&gm_803DEC4C[round]); + gm_801B5ACC_inline1(&gm_803DEC4C[round]); - gm_801B5324(allstar, round + 1); - data->rules.x50 = (void (*)(u8))(Event) fn_801B5AA8; + gm_801B5324(allstar, round + 1); + data->rules.x50 = (void (*)(u8))(Event) fn_801B5AA8; + } } void gm_801B5E7C(GameModeState* arg0) @@ -721,6 +718,8 @@ void gm_801B5F50(GameModeState* arg0) lbDvd_SetupVsPreloadCache(); } +/// #gm_801B5F50 + void gm_801B5FB4(GameModeState* arg0) { CSSData* temp_r31 = gm_GetGameModeStateExitData(arg0); diff --git a/src/melee/gm/gmclassic.c b/src/melee/gm/gmclassic.c index 243f463066..7273be6b45 100644 --- a/src/melee/gm/gmclassic.c +++ b/src/melee/gm/gmclassic.c @@ -33,6 +33,11 @@ typedef struct gmClassicMatchupData { } gmClassicMatchupData; ASSERT_SIZE(gmClassicMatchupData, 8); +typedef struct gmClassicOrderIndex { + u8 idx; +} gmClassicOrderIndex; +ASSERT_SIZE(gmClassicOrderIndex, 1); + typedef struct gmClassicIntroData { /* 0x00 */ s32 x00; /* 0x04 */ s32 x04; @@ -51,15 +56,23 @@ typedef struct gmClassicIntroData { } gmClassicIntroData; ASSERT_SIZE(gmClassicIntroData, 0x20); -typedef struct gmClassic_80490880Data { - /* 0x00 */ gmClassicIntroData x00; - /* 0x20 */ u8 x20[0x0C]; - /* 0x2C */ u8 x2C[0x28]; - /* 0x54 */ u8 x54[0x20]; - /* 0x74 */ u8 x74[0x0C]; - /* 0x80 */ u8 x80[0x10]; -} gmClassic_80490880Data; -ASSERT_SIZE(gmClassic_80490880Data, 0x90); +typedef union gmClassic_804908A0Data { + /* 0x00 */ u8 bytes[0x70]; + struct { + /* 0x00 */ u8 x00[0x0C]; + /* 0x0C */ u8 x0C[0x28]; + /* 0x34 */ u8 x34[0x20]; + /* 0x54 */ u8 x54[0x0C]; + /* 0x60 */ u8 x60[0x10]; + } order; +} gmClassic_804908A0Data; +ASSERT_SIZE(gmClassic_804908A0Data, 0x70); + +typedef struct gmClassicRuntimeData { + /* 0x00 */ gmClassicIntroData intro; + /* 0x20 */ gmClassic_804908A0Data state; +} gmClassicRuntimeData; +ASSERT_SIZE(gmClassicRuntimeData, 0x90); typedef struct gmClassic_803DDEC8Data { /* 0x000 */ gm_803DDEC8Struct x00[12]; @@ -80,7 +93,7 @@ typedef struct gmClassicSceneData { } gmClassicSceneData; ASSERT_SIZE(gmClassicSceneData, 0x560); -static gmClassic_80490880Data gmClassic_80490880; +gmClassicIntroData gmClassicIntroDataBuffer; GameModeState gm_Mode_Classic_States[] = { { @@ -91,7 +104,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -115,7 +128,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -139,7 +152,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -163,7 +176,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -187,7 +200,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -211,7 +224,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -235,7 +248,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -259,7 +272,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -283,7 +296,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -307,7 +320,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -331,7 +344,7 @@ GameModeState gm_Mode_Classic_States[] = { NULL, { GS_INTRO_EASY, - &gmClassic_80490880, + &gmClassicIntroDataBuffer, &gmClassic_804D68D0, }, }, @@ -475,7 +488,9 @@ static gmClassic_803DDEC8Data gmClassic_803DDEC8 = { }; static inline void gmClassic_InitMatchupOrder(const gmClassicMatchup* matchups, - u8* order) + gmClassicOrderIndex* order, + gmClassicOrderIndex* runtime, + s32 order_offset) { s32 count; s32 i; @@ -484,15 +499,16 @@ static inline void gmClassic_InitMatchupOrder(const gmClassicMatchup* matchups, } for (i = 0; i < count; i++) { - order[i] = i; + order[i].idx = i; } for (i = 0; i < count; i++) { - u8* swap = &order[HSD_Randi(count)]; - u8* cur = &order[i]; - u8 tmp = *cur; - *cur = *swap; - *swap = tmp; + s32 swap_idx = HSD_Randi(count); + gmClassicOrderIndex* swap = &runtime[swap_idx]; + gmClassicOrderIndex* cur = &order[i]; + u8 tmp = cur->idx; + cur->idx = swap[order_offset].idx; + swap[order_offset].idx = tmp; } } @@ -586,15 +602,16 @@ static gmClassicMatchupData gm_804D4328 = { { 0x053, { 0x21, 0x21, 0x21 }, 0 }, static gm_803DDEC8Struct* gmClassic_801B2D54(gm_803DDEC8Struct* arg0) { - gmClassic_80490880Data* o = &gmClassic_80490880; + gmClassicRuntimeData* o = + (gmClassicRuntimeData*) &gmClassicIntroDataBuffer; gm_803DDEC8Struct* ptr; gmClassicSceneData* scene_data = (gmClassicSceneData*) gm_Mode_Classic_States; for (ptr = arg0; ptr->x0 != 0xD; ptr++) { if (ptr->x1 & 8) { - gmClassicMatchup* result = - gmClassic_801B2BA4(scene_data->matchups.x2B0, o->x80, arg0); + gmClassicMatchup* result = gmClassic_801B2BA4( + scene_data->matchups.x2B0, o->state.order.x60, arg0); if (result != NULL) { ptr->xC = result; } else { @@ -607,8 +624,8 @@ static gm_803DDEC8Struct* gmClassic_801B2D54(gm_803DDEC8Struct* arg0) for (ptr = arg0; ptr->x0 != 0xD; ptr++) { u8 flags = ptr->x1; if ((flags & 2) && !(flags & 0x20)) { - gmClassicMatchup* result = - gmClassic_801B2BA4(scene_data->matchups.x26C, o->x74, arg0); + gmClassicMatchup* result = gmClassic_801B2BA4( + scene_data->matchups.x26C, o->state.order.x54, arg0); if (result != NULL) { ptr->xC = result; } else { @@ -621,8 +638,8 @@ static gm_803DDEC8Struct* gmClassic_801B2D54(gm_803DDEC8Struct* arg0) for (ptr = arg0; ptr->x0 != 0xD; ptr++) { u8 flags = ptr->x1; if ((flags & 0x10) && !(flags & 0x20)) { - gmClassicMatchup* result = - gmClassic_801B2BA4(scene_data->matchups.x1B8, o->x54, arg0); + gmClassicMatchup* result = gmClassic_801B2BA4( + scene_data->matchups.x1B8, o->state.order.x34, arg0); if (result != NULL) { ptr->xC = result; } else { @@ -635,8 +652,8 @@ static gm_803DDEC8Struct* gmClassic_801B2D54(gm_803DDEC8Struct* arg0) for (ptr = arg0; ptr->x0 != 0xD; ptr++) { u8 flags = ptr->x1; if (flags == 0 || flags == 4) { - gmClassicMatchup* result = - gmClassic_801B2BA4(scene_data->matchups.x0CC, o->x2C, arg0); + gmClassicMatchup* result = gmClassic_801B2BA4( + scene_data->matchups.x0CC, o->state.order.x0C, arg0); if (result != NULL) { ptr->xC = result; } else { @@ -677,29 +694,34 @@ void gm_Mode_Classic_OnLoad(void) UnkAllstarData* data; gmClassicSceneData* scene_data = (gmClassicSceneData*) gm_Mode_Classic_States; - gmClassic_80490880Data* o = &gmClassic_80490880; + gmClassicRuntimeData* o = + (gmClassicRuntimeData*) &gmClassicIntroDataBuffer; gm_803DDEC8Struct* entry; - PAD_STACK(56); + PAD_STACK(40); for (entry = scene_data->matchups.x00; entry->x0 != 0x0D; entry++) { entry->xC = NULL; } gmClassic_InitMatchupOrder(scene_data->matchups.x2B0, - gmClassic_80490880.x80); + (gmClassicOrderIndex*) &gm_804908A0[0x60], + (gmClassicOrderIndex*) o, 0x80); gmClassic_InitMatchupOrder(scene_data->matchups.x26C, - gmClassic_80490880.x74); + (gmClassicOrderIndex*) &gm_804908A0[0x54], + (gmClassicOrderIndex*) o, 0x74); gmClassic_InitMatchupOrder(scene_data->matchups.x1B8, - gmClassic_80490880.x54); + (gmClassicOrderIndex*) &gm_804908A0[0x34], + (gmClassicOrderIndex*) o, 0x54); gmClassic_InitMatchupOrder(scene_data->matchups.x0CC, - gmClassic_80490880.x2C); + (gmClassicOrderIndex*) &gm_804908A0[0x0C], + (gmClassicOrderIndex*) o, 0x2C); data = gm_GetAllStarData(); gmMainLib_8015CDC8(); gm_8017C984(data); { - u8* p = o->x20; + u8* p = o->state.order.x00; int i; for (i = 12; i > 0; i--) { *p++ = 0; diff --git a/src/melee/gm/gmmain_lib.c b/src/melee/gm/gmmain_lib.c index 3cbcf791d3..dfbb823caa 100644 --- a/src/melee/gm/gmmain_lib.c +++ b/src/melee/gm/gmmain_lib.c @@ -4,6 +4,8 @@ #include +#include "gm/forward.h" + #include #include #include @@ -238,8 +240,8 @@ struct gmm_x0_528_t* gmMainLib_8015CDE0(void) void gmMainLib_8015CDEC(void) { ssize_t i; - for (i = 0; i < GM_MAX_PLAYERS; ++i) { - s8* ptr = gmMainLib_8015CE44(i, 120); + for (i = 0; i < Gm_Player_NumMax; i++) { + s8* ptr = gmMainLib_8015CE44(i, GM_NAMETAG_NONE); if (ptr != 0) { *ptr = 5; } @@ -248,7 +250,7 @@ void gmMainLib_8015CDEC(void) s8* gmMainLib_8015CE44(s32 arg0, s32 arg1) { - if (arg1 == 120) { + if (arg1 == GM_NAMETAG_NONE) { if (arg0 < (signed) ARRAY_SIZE(gmMainLib_804D3EE0->unk_530.unk_588)) { return &gmMainLib_804D3EE0->unk_530.unk_588[arg0]; } @@ -745,13 +747,24 @@ static inline void gmMainLib_AdjustNameTags(VsModeData* load_vmd, for (i = 0; i < 6; i++) { ptr = &store_vmd->start.players[i].nametag; if (load_vmd->start.players[i].nametag == tag) { - *ptr = 0x78; - } else if (*ptr > tag && *ptr != 0x78) { + *ptr = GM_NAMETAG_NONE; + } else if (*ptr > tag && *ptr != GM_NAMETAG_NONE) { *ptr -= 1; } } } +inline void gmMainLib_AdjustNameTag(u8* tag_ptr, u8 tag) +{ + u8 value = *tag_ptr; + + if (value == tag) { + *tag_ptr = GM_NAMETAG_NONE; + } else if (value > tag && value != GM_NAMETAG_NONE) { + *tag_ptr = value - 1; + } +} + s32 gmMainLib_8015DBF4(s32 arg0) { extern VsModeData gm_80497618; @@ -780,7 +793,6 @@ s32 gmMainLib_8015DBF4(s32 arg0) }* base; GameRules* gr; u8 val; - u8* ptr; #define ADJ_NAMETAG_78(field) \ do { \ @@ -794,14 +806,8 @@ s32 gmMainLib_8015DBF4(s32 arg0) config = gmMainLib_8015CDC8(); config_all = (struct gmMainLib_8015DBF4_config*) config; - ptr = &config->x4; - val = *ptr; base = (struct gmMainLib_8015DBF4_base*) &config_all->unk_530.unk_588[0]; - if (val == (u8) arg0) { - *ptr = 0x78; - } else if (val > (u8) arg0 && val != 0x78) { - *ptr = val - 1; - } + gmMainLib_AdjustNameTag(&config->x4, (u8) arg0); ADJ_NAMETAG_78(gmMainLib_804D3EE0->unk_522.x4); ADJ_NAMETAG_78(gmMainLib_804D3EE0->unk_528.x4); ADJ_NAMETAG_78(config_all->unk_530.x4); @@ -869,29 +875,38 @@ s32 gmMainLib_8015DBF4(s32 arg0) return arg0; } -static inline void gmMainLib_SetHandicaps(s8* base) +static inline void +SetPlayerHandicaps(struct PlayerInitData* p0, struct PlayerInitData* p1, + struct PlayerInitData* p2, struct PlayerInitData* p3, + struct PlayerInitData* p4, struct PlayerInitData* p5) { - s32 i; - s32 j; - - for (i = 0; i < 6; i++) { - for (j = 0; j < 6; j++) { - base[0x78 + i * 0x140 + j * 0x24] = 9; - } - } + p5->handicap = p4->handicap = p3->handicap = p2->handicap = p1->handicap = + p0->handicap = 9; } void gmMainLib_8015EA80(void) { - s8* volatile base_temp = gmMainLib_804D3EE0->unk_530.unk_588; - s8* base = base_temp; - s8* base2 = base + 7 * 0x140; + struct gmMainLib_8015EA80_modes { + u8 pad[8]; + VsModeData modes[13]; + }* data = + (struct gmMainLib_8015EA80_modes*) gmMainLib_804D3EE0->unk_530.unk_588; + struct PlayerInitData* players; + s32 i; PAD_STACK(0x90); gmMainLib_8015CDEC(); - gmMainLib_SetHandicaps(base); - gmMainLib_SetHandicaps(base2); + for (i = 0; i < 6; i++) { + players = data->modes[i].start.players; + SetPlayerHandicaps(&players[0], &players[1], &players[2], &players[3], + &players[4], &players[5]); + } + for (i = 7; i < 13; i++) { + players = data->modes[i].start.players; + SetPlayerHandicaps(&players[0], &players[1], &players[2], &players[3], + &players[4], &players[5]); + } } int gmMainLib_8015ECB0(void) diff --git a/src/melee/gm/gmregclear.c b/src/melee/gm/gmregclear.c index 2ecb722037..3a0e2bb15b 100644 --- a/src/melee/gm/gmregclear.c +++ b/src/melee/gm/gmregclear.c @@ -196,6 +196,12 @@ static void order_data(void) (void) "Error : gobj don\'t get (gmRegClearAddModel)\n"; (void) "gmregclear.c"; (void) "Error : jobj don\'t get (gmRegClearAddModel)\n"; + (void) "SdClr.usd"; + (void) "SIS_ClearData"; + (void) "SdClr.dat"; + (void) "IfHrNoCn"; + (void) "ScInfCnt_scene_models"; + (void) "IfHrReco"; } #endif @@ -694,7 +700,7 @@ static inline s32 gm_8017CE34_CountEnemies(const s8* arg0) s32 i; for (i = 0; i < 3; i++) { - if ((s32) arg0[i] != CHKIND_NONE) { + if ((s32) arg0[i] != 0x21) { count++; } } @@ -704,30 +710,28 @@ static inline s32 gm_8017CE34_CountEnemies(const s8* arg0) static inline void gm_8017CE34_SetupColors(UnkAdventureData* arg1, s32 count, s8* arg2, u8* colors) { - u8* out_color = colors; s32 color_idx; - s8* kind_iter = arg2; + u8* out_color = colors; + u8 num_colors; + u8 result; for (color_idx = 0; color_idx < 3; color_idx++) { - *out_color = gm_8017CD94(arg1, (u8) *kind_iter, count, color_idx); + num_colors = gm_80169238((u8) arg2[color_idx]); + if (arg1->x54 != NULL) { + result = arg1->x54(count, arg1->x0.cpu_level, color_idx); + if (num_colors != 0) { + result %= num_colors; + } else { + result = 0; + } + } else { + result = 0; + } + *out_color = result; out_color++; - kind_iter++; } } -static inline u8 gm_8017CE34_ResolvePlayerCKind(UnkAdventureData* arg1, - u8 player_ckind) -{ - if (((s32) player_ckind == CKIND_ZELDA) && (arg1->x0.xC.x12 != 0)) { - player_ckind = CKIND_SEAK; - } else if (((arg1->x0.x8 & 0x80) != 0) && (arg1->x0.x9 == 1) && - ((s8) player_ckind == CKIND_POPONANA)) - { - player_ckind = CHKIND_POPO; - } - return player_ckind; -} - static inline u8 gm_8017CE34_GetCpuLevel(UnkAdventureData* arg1) { return arg1->x0.cpu_level; @@ -745,7 +749,7 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, f32 attack_ratio; u8 player_stocks; u8 player_ckind; - u8 flags; + s32 flags; s8* enemy_kind; f32 defense_ratio; u8 enemy_ckind; @@ -753,6 +757,8 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, s32 enemy_idx; u8* color_iter; + PAD_STACK(4); + boss_count = 0; enemy_level = 0; enemy_cpu_type = 0; @@ -832,8 +838,15 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, player_stocks = arg1->x0.stocks; } - player_ckind = (u8) arg1->x0.ckind; - player_ckind = gm_8017CE34_ResolvePlayerCKind(arg1, player_ckind); + if ((arg1->x0.ckind == CKIND_ZELDA) && (arg1->x0.xC.x12 != 0)) { + player_ckind = CKIND_SEAK; + } else if (((arg1->x0.x8 & 0x80) != 0) && (arg1->x0.x9 == 1) && + (arg1->x0.ckind == CKIND_POPONANA)) + { + player_ckind = CHKIND_POPO; + } else { + player_ckind = (u8) arg1->x0.ckind; + } gm_801B0620(arg0->players, player_ckind, arg1->x0.color, player_stocks, arg1->x0.slot); @@ -865,6 +878,7 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, { s32 temp_r3_4 = arg1->x0.x8 & 8; if ((temp_r3_4 != 0) && (arg1->x0.xC.x11 == 0)) { + s32 base_enemy_count; s32 event_enemy_count; s32 special_stage; s32 special_enemy_mode; @@ -872,8 +886,9 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, u8 first_enemy; u32 stage_flags; - event_enemy_count = gm_8017CE34_CountEnemies(arg2); + base_enemy_count = gm_8017CE34_CountEnemies(arg2); arg1->x0.xC.xC = 3; + event_enemy_count = base_enemy_count; special_stage = 0; special_enemy_mode = 0; sp8 = 0; @@ -1265,6 +1280,9 @@ s32 gm_8017DB88(void* arg0, u8 arg1, s32 arg2, s32 arg3, u8* arg4, u8 arg5, } #ifdef MUST_MATCH #pragma dont_inline off + +/// @todo .sdata2 order hack +static const u32 gmregclear_sdata2_order_pad0[1] = { 0 }; #endif s32 fn_8017DD7C(PlayerInitData* arg0, Unk1PData_x24* arg1, u8 arg2) @@ -1494,6 +1512,9 @@ u8 gm_8017E48C(GameModeState* scene) struct gm_803DE650_t* gm_8017E4C4(u8 arg0) { struct gm_803DE650_t* ptr; +#ifdef MUST_MATCH + (void) 100.0F; +#endif for (ptr = gm_803DE650; ptr->x0 != 0xFF; ptr++) { if (ptr->x0 == arg0) { return ptr; @@ -1502,6 +1523,10 @@ struct gm_803DE650_t* gm_8017E4C4(u8 arg0) return NULL; } +#ifdef MUST_MATCH +static const u32 gmregclear_sdata2_order_pad1[1] = { 0 }; +#endif + /// Get adventure stage kind for given difficulty and stage slot. /// The (u8) cast on difficulty is required - these functions are called /// via function pointers typed as f32(*)(int, u8) in UnkAdventureData. @@ -1560,6 +1585,11 @@ u8 gm_8017E76C(u8 difficulty, u8 stage_slot, u8 arg2) return lbl_803D7AC0[stage_slot + difficulty * 5].pad_6[0x10 + (arg2 * 3)]; } +#ifdef MUST_MATCH +static const f32 gmregclear_sdata2_order_hundred[1] = { 100.0F }; +static const f64 gmregclear_sdata2_order_u32_0[1] = { U32_TO_F32 }; +#endif + void gm_8017E7A0(u8 matchResult) { if (matchResult == OUTCOME_TIMEOUT) { @@ -1944,14 +1974,33 @@ s32 fn_8017F1B8(void) } mask = (u8) fn_8017F008(); +#ifdef MUST_MATCH + (void) 0.560000002F; + (void) 0.600000024F; + (void) 281.0F; + (void) 32.0F; +#endif return fn_8016FFD4(gm_8016B774(), mask, 0); } +#ifdef MUST_MATCH +static const f32 gmregclear_sdata2_order_zero_two[2] = { 0.0F, 2.0F }; +#endif + int fn_8017F294(void) { +#ifdef MUST_MATCH + (void) -12.0F; + (void) 9.0F; + (void) 134.400009F; +#endif return lbl_80472D28.x104; } +#ifdef MUST_MATCH +static const f64 gmregclear_sdata2_order_s32_0[1] = { S32_TO_F32 }; +#endif + s32 fn_8017F2A4(HSD_Text** arg0, f32 farg0, f32 farg1) { HSD_Text* text; @@ -2387,49 +2436,63 @@ void fn_8017FE54(HSD_GObj* gobj) } } +#ifdef MUST_MATCH +static const f32 gmregclear_sdata2_order_one[1] = { 1.0F }; +static const f64 gmregclear_sdata2_order_u32_1[1] = { U32_TO_F32 }; +static const f32 gmregclear_sdata2_order_half[1] = { 0.5F }; +#endif + void fn_8017FF1C(HSD_GObj* gobj) { HSD_JObj* jobj; - struct lbl_80472D28_t* state = &lbl_80472D28; + /// @todo Consolidate these split-derived views of the same state object. + union { + struct lbl_80472D28_t* state; + fn_8017FA1C_arg* arg; + } data; s32 result; s32 i; u8 mask; HSD_JObj* sp28; + data.state = (data.state = &lbl_80472D28); jobj = gobj->hsd_obj; - HSD_JObjAnimAll(gobj->hsd_obj); + HSD_JObjAnimAll(jobj); - if (state->x118 == 0) { - fn_8017F608(state); + if (data.arg->x118 == 0) { + fn_8017F608(data.arg); } - result = fn_8017FA1C(state); - fn_8017FBA4(state); + { + fn_8017FA1C_arg* arg = data.arg; + result = fn_8017FA1C(arg); + } + fn_8017FBA4(data.arg); - if (state->x117 != 0 && state->x110 > 0x29U) { - state->xC0 = fn_8017F47C(&state->x84, (s32) state->xC0); + if (data.state->x117 != 0 && data.state->x110 > 0x29U) { + data.state->xC0 = fn_8017F47C(&data.state->x84, (s32) data.state->xC0); mask = fn_8017F008(); - if (fn_8016F9A8(gm_8016B774(), state->xC0, mask, 0) > 7) { - state->x11F = 0; + if (fn_8016F9A8(gm_8016B774(), data.state->xC0, mask, 0) > 7) { + data.state->x11F = 0; } else { - state->x11F = 1; + data.state->x11F = 1; } mask = fn_8017F008(); - if (fn_8016F870(gm_8016B774(), state->xC0, mask, 0) < 0) { - state->x11E = 1; + if (fn_8016F870(gm_8016B774(), data.state->xC0, mask, 0) < 0) { + data.state->x11E = 1; } else { - state->x11E = 0; + data.state->x11E = 0; } - if (state->x110 % 30 == 0 && state->xC8 == 0) { + if (data.state->x110 % 30 == 0 && data.state->xC8 == 0) { mask = fn_8017F008(); - if (fn_8016F9A8(gm_8016B774(), state->xC0, mask, 0) > 7) { - state->xC0 = (u16) (state->xC0 + 1); + if (fn_8016F9A8(gm_8016B774(), data.state->xC0, mask, 0) > 7) { + data.state->xC0 = (u16) (data.state->xC0 + 1); } else { - state->xC8 = 1; - state->xC4 = state->x110; + data.state->xC8 = 1; + data.state->xC4 = data.state->x110; } } @@ -2440,14 +2503,16 @@ void fn_8017FF1C(HSD_GObj* gobj) ((repeat | buttons) & 0)) { mask = fn_8017F008(); - if (fn_8016F740(gm_8016B774(), state->xC0, mask, 0) > 0) { + if (fn_8016F740(gm_8016B774(), data.state->xC0, mask, 0) > 0) { mask = fn_8017F008(); - if (fn_8016F9A8(gm_8016B774(), state->xC0, mask, 0) > 7) { + if (fn_8016F9A8(gm_8016B774(), data.state->xC0, mask, 0) > + 7) + { mask = fn_8017F008(); - state->xC0 = - fn_8016F740(gm_8016B774(), state->xC0, mask, 0); - state->xC8 = 1; - state->xC4 = state->x110; + data.state->xC0 = fn_8016F740( + gm_8016B774(), data.state->xC0, mask, 0); + data.state->xC8 = 1; + data.state->xC4 = data.state->x110; } } } else { @@ -2456,28 +2521,31 @@ void fn_8017FF1C(HSD_GObj* gobj) if (((repeat | buttons) & (PAD_BUTTON_UP | PAD_STICK_UP)) | ((repeat | buttons) & 0)) { - mask = fn_8017F008(); - if (fn_8016F870(gm_8016B774(), state->xC0, mask, 0) >= 0) { - mask = fn_8017F008(); - state->xC0 = - fn_8016F870(gm_8016B774(), state->xC0, mask, 0); - state->xC8 = 1; - state->xC4 = state->x110; + if (fn_8016F870(gm_8016B774(), data.state->xC0, + (u8) fn_8017F008(), 0) >= 0) + { + data.state->xC0 = + fn_8016F870(gm_8016B774(), data.state->xC0, + (u8) fn_8017F008(), 0); + data.state->xC8 = 1; + data.state->xC4 = data.state->x110; } } } } } - if (state->x11A != 0 && state->x110 > 0x14U && state->x11D < state->x11C && - (s32) (0.5f * (f32) (state->x110 - 0x14)) > (s32) state->x11D) + if (data.state->x11A != 0 && data.state->x110 > 0x14U && + data.state->x11D < data.state->x11C && + (s32) (0.5f * (f32) (data.state->x110 - 0x14)) > + (s32) data.state->x11D) { - lb_80011E24(jobj, &sp28, state->x11D + 7, -1); + lb_80011E24(jobj, &sp28, data.state->x11D + 7, -1); HSD_JObjClearFlagsAll(sp28, JOBJ_HIDDEN); - state->x11D = (u8) (state->x11D + 1); + data.state->x11D = (u8) (data.state->x11D + 1); } - if (state->x115 == 0 && result != 0) { + if (data.state->x115 == 0 && result != 0) { fn_80168F2C(0); } @@ -2486,46 +2554,46 @@ void fn_8017FF1C(HSD_GObj* gobj) (HSD_PadMasterStatus[(u8) Player_GetPlayerId(i)].trigger & HSD_PAD_A)) { - state->xFC = state->x104; - state->x115 = 1; + data.state->xFC = data.state->x104; + data.state->x115 = 1; break; } } - if (state->x110 > 0x3EU) { + if (data.state->x110 > 0x3EU) { for (i = 0; i < 6; i++) { if (Player_GetPlayerSlotType(i) == Gm_PKind_Human && (HSD_PadMasterStatus[(u8) Player_GetPlayerId(i)].trigger & 0x1000)) { - state->xFC = state->x104; - state->x116 = 1; + data.state->xFC = data.state->x104; + data.state->x116 = 1; sfxForward(); break; } } } - if (state->x11E != 0) { - HSD_JObjSetFlagsAll(state->x20, JOBJ_HIDDEN); + if (data.state->x11E != 0) { + HSD_JObjSetFlagsAll(data.state->x20, JOBJ_HIDDEN); } else { - HSD_JObjClearFlagsAll(state->x20, JOBJ_HIDDEN); + HSD_JObjClearFlagsAll(data.state->x20, JOBJ_HIDDEN); } - if (state->x11F != 0) { - HSD_JObjSetFlagsAll(state->x24, JOBJ_HIDDEN); + if (data.state->x11F != 0) { + HSD_JObjSetFlagsAll(data.state->x24, JOBJ_HIDDEN); } else { - HSD_JObjClearFlagsAll(state->x24, JOBJ_HIDDEN); + HSD_JObjClearFlagsAll(data.state->x24, JOBJ_HIDDEN); } - if (state->x10C < 1.0f) { - state->x10C += 0.05f; + if (data.state->x10C < 1.0f) { + data.state->x10C += 0.05f; } else { - state->x10C = 1.0f; + data.state->x10C = 1.0f; } - if (state->x110 + 0x10000 != 0xFFFF) { - state->x110 = state->x110 + 1; + if (data.state->x110 + 0x10000 != 0xFFFF) { + data.state->x110 = data.state->x110 + 1; } PAD_STACK(0x1C); } @@ -2606,6 +2674,27 @@ static inline void* fn_80180630_LoadLightList(struct lbl_80472D28_t* state) return lb_80011AC4(state->x5C); } +static inline void* fn_80180630_LoadCameraDesc(struct lbl_80472D28_t* state) +{ + return HSD_CObjLoadDesc(state->x60); +} + +static inline DynamicModelDesc* +fn_80180630_GetModelDesc(struct lbl_80472D28_t* state) +{ + return &state->x4C; +} + +static inline void fn_80180630_SetupSisLib(HSD_GObj* cam_gobj) +{ + HSD_SisLib_803A611C(0, cam_gobj, 9U, 0xDU, 0U, 0xEU, 0U, 0x13U); + if (lbLang_IsSavedLanguageUS() != 0) { + HSD_SisLib_803A62A0(0, "SdClr.usd", "SIS_ClearData"); + } else { + HSD_SisLib_803A62A0(0, "SdClr.dat", "SIS_ClearData"); + } +} + static inline void fn_80180630_CreateLightAndCamera(struct lbl_80472D28_t* state, HSD_GObj** cam_gobj) @@ -2620,29 +2709,37 @@ fn_80180630_CreateLightAndCamera(struct lbl_80472D28_t* state, *cam_gobj = fn_80180630_CreateCameraGObj(); } +inline u8 fn_80180630_GetX118(const struct lbl_80472D28_t* state) +{ + return state->x118; +} + void fn_80180630(int arg0, int arg1, int arg2, bool arg3, lbl_8046B6A0_24C_t* arg4) { - struct lbl_80472D28_t* state = &lbl_80472D28; s32 sp64; s32 sp60; - s32 sp5C; - s32 sp58; - void* sp38; + int special_score_value; + int coin_count; + u16 coins; HSD_Archive* archive; HSD_GObj* cam_gobj; lbl_8046B6A0_t* temp; s32 total; s32 var_r4; + union { + struct lbl_80472D28_t* state; + fn_8017FA1C_arg* model; + } data; s32 special_score; s32 var_r3; - u16 coins; + struct lbl_80472D28_t* state; u8 mask; u8 var_r0; - PAD_STACK(0x38); special_score = 0; coins = arg4->x58[0].xE; + state = (data.state = &lbl_80472D28); memzero(state, sizeof(*state)); state->xD4 = -1; state->xD8 = 0; @@ -2658,8 +2755,9 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->x114 = (u8) arg3; switch (arg2) { - case 1: - Ground_801C1DE4(&sp60, &sp64); + case 1: { + s32* first = &sp60; + Ground_801C1DE4(first, &sp64); state->x11A = 1; state->x11C = (u8) (sp64 - sp60); state->x108 = 0xC8; @@ -2667,13 +2765,15 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->x11B = 1; } break; + } case 3: temp = gm_16AE_GetUnkData_0(); state->x118 = 1; if (temp->match_result == OUTCOME_UNK_1P_BONUS_STAGE_END) { - grPushOn_80219204(Ground_801C1DD4(), (int*) &sp5C, (int*) &sp58); - special_score = sp5C; - coins = (u16) sp58; + grPushOn_80219204(Ground_801C1DD4(), &special_score_value, + &coin_count); + special_score = special_score_value; + coins = (u16) coin_count; state->x108 = 0x1F4; } break; @@ -2715,9 +2815,7 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->xFC = arg0 + arg1; state->xCC = arg1; - total = state->xF0; - total += state->xCC; - total = arg0 + total; + total = arg0 + state->xCC + state->xF0; var_r4 = total; if (total > 999999999) { var_r4 = 999999999; @@ -2727,29 +2825,29 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->x104 = var_r4; lbl_804D65C0 = (var_r4 - (arg0 + arg1)) / 10; - archive = - lbArchive_80016DBC("GmRegClr", &sp38, "ScGamRegClear_scene_data", 0); - state->x48 = archive; - if (sp38 == NULL) { - OSReport("Error : Cannot open archive file (File Name : %s).", - "GmRegClr"); + PAD_STACK(0x18); + { + void* scene_data; + + archive = lbArchive_80016DBC("GmRegClr", &scene_data, + "ScGamRegClear_scene_data", 0); + state->x48 = archive; + if (scene_data == NULL) { + OSReport("Error : Cannot open archive file (File Name : %s).", + "GmRegClr"); + } + fn_80168A6C(scene_data, fn_80180630_GetModelDesc(state), 0); } - fn_80168A6C(sp38, &state->x4C, 0); fn_80180630_CreateLightAndCamera(state, &cam_gobj); HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_CameraKind, - HSD_CObjLoadDesc(state->x60)); + fn_80180630_LoadCameraDesc(state)); GObj_SetupGXLinkMax(cam_gobj, HSD_GObj_803910D8, 8U); cam_gobj->gxlink_prios = 0x4C00; - HSD_SisLib_803A611C(0, cam_gobj, 9U, 0xDU, 0U, 0xEU, 0U, 0x13U); - if (lbLang_IsSavedLanguageUS() != 0) { - HSD_SisLib_803A62A0(0, "SdClr.usd", "SIS_ClearData"); - } else { - HSD_SisLib_803A62A0(0, "SdClr.dat", "SIS_ClearData"); - } + fn_80180630_SetupSisLib(cam_gobj); - fn_801803FC(state); + fn_801803FC(data.model); fn_80168F7C(); if (HSD_Randi(2) != 0) { @@ -2760,14 +2858,14 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, lbAudioAx_80023F28(var_r3); Camera_8002F7AC(0); - lb_800121FC(&state->x30, 640, 480, GX_TF_RGB5A3, 0); + lb_800121FC(&state->x30, 0x280, 0x1E0, GX_TF_RGB5A3, 0); state->x2C = lb_800138EC(&state->x30, NULL, 2U, 0x32, 0.0f, 0.0f, 1.0f, 1.0f); lb_800138D8(state->x2C, 1); lb_800138CC(state->x2C, fn_8017FE54); if (gm_GetRules()->x1_1 && coins != 0) { - if (state->x118 == 0) { + if (fn_80180630_GetX118(state) == 0U) { un_802FF128(0x5A, 0x1AE, (s32) coins, 5); } else { un_802FF128(0x86, 0xC8, (s32) coins, 5); @@ -2776,8 +2874,15 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, arg4->x58[0].xE = coins; fn_8017F2A4(&state->x84, 264.0f, 211.0f); + PAD_STACK(0x18); } +#ifdef MUST_MATCH +static const u32 gmregclear_sdata2_order_pad2[1] = { 0 }; +static const f32 gmregclear_sdata2_order_tenth_zero[2] = { 0.100000001F, + 0.0F }; +#endif + int fn_80180AC0(void) { if (lbl_80472D28.x116 == 1) { @@ -2986,6 +3091,10 @@ void fn_80180C60(HSD_GObj* gobj) } } +#ifdef MUST_MATCH +static const f64 gmregclear_sdata2_order_s32_1[1] = { S32_TO_F32 }; +#endif + s32 lbl_804D65D8; void fn_80181598(void) @@ -4161,6 +4270,10 @@ void fn_80182F40(HSD_GObj* unused) } } +#ifdef MUST_MATCH +static const f64 gmregclear_sdata2_order_s32_2[1] = { S32_TO_F32 }; +#endif + void gm_80183218(void) { lbl_804D65E8 = 0; diff --git a/src/melee/gm/gmregtyfall.c b/src/melee/gm/gmregtyfall.c index 38b79316eb..8a95b70dd2 100644 --- a/src/melee/gm/gmregtyfall.c +++ b/src/melee/gm/gmregtyfall.c @@ -419,53 +419,89 @@ static inline void initImages(void) } } -static inline void setupTrophy(HSD_JObj* trophy_root) +static inline void gm_801A7070_SetupMain(u8 priority) { - s32 trophy; HSD_JObj* jobj; - f32 translate_x; - f32 translate_y; - f32 translate_z; - f32 rotation_y; - f32 inverse_scale; - f32 trophy_scale; - f32 root_scale; + HSD_GObj* gobj; + HSD_JObj* player_jobj; + f32 scale; - trophy = gm_801A659C(gm_801BEFB0()); - jobj = HSD_JObjGetChild(trophy_root); - translate_x = -Toy_803060BC(trophy, 0); - HSD_JObjSetTranslateXWithMtxDirty(jobj, translate_x); - translate_y = -Toy_803060BC(trophy, 1); - HSD_JObjSetTranslateYWithMtxDirty(jobj, translate_y); - translate_z = -Toy_803060BC(trophy, 2); - HSD_JObjSetTranslateZWithMtxDirty(jobj, translate_z); - - rotation_y = -(0.017453292f * Toy_803060BC(trophy, 5)); - HSD_JObjSetRotationYWithMtxDirty(jobj, rotation_y); - inverse_scale = 1.0f / Toy_803060BC(trophy, 3); - trophy_scale = Toy_803060BC(trophy, 4); - trophy_scale = trophy_scale * inverse_scale; - HSD_JObjSetScaleXWithMtxDirty(jobj, trophy_scale); - HSD_JObjSetScaleYWithMtxDirty(jobj, trophy_scale); - HSD_JObjSetScaleZWithMtxDirty(jobj, trophy_scale); - root_scale = gm_803DB2EC[gm_801BEFB0()]; - HSD_JObjSetScaleX(trophy_root, root_scale); - HSD_JObjSetScaleY(trophy_root, root_scale); - HSD_JObjSetScaleZ(trophy_root, root_scale); + gobj = GObj_Create(0xE, 0xF, priority); + gm_804D6768 = gobj; + jobj = HSD_JObjLoadJoint(gm_804D6798); + HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); + GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); + scale = gm_803DB2EC[gm_801BEFB0()]; + HSD_JObjSetScaleX(jobj, scale); + HSD_JObjSetScaleY(jobj, scale); + HSD_JObjSetScaleZ(jobj, scale); + + HSD_GObj_SetupProc(gobj, fn_801A6664, 0x17); + player_jobj = Player_80036EA0(0); + lb_8000C1C0(HSD_JObjGetChild(HSD_JObjGetChild( + HSD_JObjGetChild(HSD_JObjGetChild(jobj)))), + player_jobj); + lb_8000C290(HSD_JObjGetChild(HSD_JObjGetChild( + HSD_JObjGetChild(HSD_JObjGetChild(jobj)))), + player_jobj); } -void gm_Scene_ToyFall_OnEnter(void* unused) +static inline f32 getTrophyTranslateZ(s32 trophy) { - HSD_JObj* player_jobj; + return Toy_803060BC(trophy, 2); +} + +static inline void gm_801A7070_SetupTrophy(u8 priority) +{ + s32 trophy; + HSD_GObj* gobj; HSD_JObj* jobj; - HSD_JObj* main_jobj; - HSD_JObj* trophy_root; + HSD_JObj* child; + HSD_JObj* target; + f32 val; + f32 scale; - f32 main_scale; + gobj = GObj_Create(0xE, 0xF, priority); + gm_804D6778 = gobj; + jobj = HSD_JObjLoadJoint(gm_804D67AC->models[0]->joint); + HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); + GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); + trophy = gm_801A659C(gm_801BEFB0()); + child = jobj == NULL ? NULL : jobj->child; + val = -Toy_803060BC(trophy, 0); + HSD_JObjSetTranslateXWithMtxDirty(child, val); + val = -Toy_803060BC(trophy, 1); + HSD_JObjSetTranslateYWithMtxDirty(child, val); + val = -getTrophyTranslateZ(trophy); + HSD_JObjSetTranslateZWithMtxDirty(child, val); + + val = -(0.017453292f * Toy_803060BC(trophy, 5)); + HSD_JObjSetRotationYWithMtxDirty(child, val); + scale = 1.0f / Toy_803060BC(trophy, 3); + val = Toy_803060BC(trophy, 4); + scale = val * scale; + HSD_JObjSetScaleXWithMtxDirty(child, scale); + HSD_JObjSetScaleYWithMtxDirty(child, scale); + HSD_JObjSetScaleZWithMtxDirty(child, scale); + val = gm_803DB2EC[gm_801BEFB0()]; + HSD_JObjSetScaleX(jobj, val); + HSD_JObjSetScaleY(jobj, val); + HSD_JObjSetScaleZ(jobj, val); + + HSD_GObj_SetupProc(gobj, fn_801A6844, 0x17); + target = gm_804D6768->hsd_obj; + target = HSD_JObjGetNext(HSD_JObjGetChild(HSD_JObjGetChild( + HSD_JObjGetChild(HSD_JObjGetChild(HSD_JObjGetChild(target)))))); + lb_8000C1C0(gobj->hsd_obj, target); + lb_8000C290(gobj->hsd_obj, target); +} + +void gm_Scene_ToyFall_OnEnter(void* unused) +{ HSD_GObj* gobj; HSD_LObj* lobj; - PAD_STACK(68); + PAD_STACK(44); gm_804D6740 = 0x1E; gm_804D6750 = 0x320; @@ -532,39 +568,9 @@ void gm_Scene_ToyFall_OnEnter(void* unused) gm_801A68D8(); gm_GetCurrentSceneEnterData(); - // create jobj - gm_804D6768 = gobj = GObj_Create(0xE, 0xF, 0); - main_jobj = HSD_JObjLoadJoint(gm_804D6798); - HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, main_jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); - main_scale = gm_803DB2EC[gm_801BEFB0()]; - HSD_JObjSetScaleX(main_jobj, main_scale); - HSD_JObjSetScaleY(main_jobj, main_scale); - HSD_JObjSetScaleZ(main_jobj, main_scale); - - HSD_GObj_SetupProc(gobj, fn_801A6664, 0x17); - player_jobj = Player_80036EA0(0); - lb_8000C1C0(HSD_JObjGetChild(HSD_JObjGetChild( - HSD_JObjGetChild(HSD_JObjGetChild(main_jobj)))), - player_jobj); - lb_8000C290(HSD_JObjGetChild(HSD_JObjGetChild( - HSD_JObjGetChild(HSD_JObjGetChild(main_jobj)))), - player_jobj); + gm_801A7070_SetupMain(0); gm_GetCurrentSceneEnterData(); - gobj = GObj_Create(0xE, 0xF, 0); - gm_804D6778 = gobj; - trophy_root = HSD_JObjLoadJoint(gm_804D67AC->models[0]->joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, trophy_root); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); - - setupTrophy(trophy_root); - - HSD_GObj_SetupProc(gobj, fn_801A6844, 0x17); - jobj = gm_804D6768->hsd_obj; - jobj = HSD_JObjGetNext(HSD_JObjGetChild(HSD_JObjGetChild( - HSD_JObjGetChild(HSD_JObjGetChild(HSD_JObjGetChild(jobj)))))); - lb_8000C1C0(gobj->hsd_obj, jobj); - lb_8000C290(gobj->hsd_obj, jobj); + gm_801A7070_SetupTrophy(0); lbAudioAx_800237A8(0x7EF40, 0x7FU, 0x40U); } diff --git a/src/melee/gm/gmresult.c b/src/melee/gm/gmresult.c index 108b377e7d..9735221b3c 100644 --- a/src/melee/gm/gmresult.c +++ b/src/melee/gm/gmresult.c @@ -1147,10 +1147,11 @@ void fn_80175DC8(HSD_GObj* gobj) HSD_Text* title_text; s32 j; - PAD_STACK(24); + PAD_STACK(20); data = &lbl_8046DBE8; me = data->x94; + data_iter = data; { DynamicModelDesc* model = data->pnlsce->models[0]; jobj = HSD_JObjLoadJoint(model->joint); @@ -1170,8 +1171,8 @@ void fn_80175DC8(HSD_GObj* gobj) lb_80011E24(jobj, &sp100, 0x69, -1); data->x28 = sp100; - i = 0; - jobj_iter = &data->x34[i]; + jobj_iter = (HSD_JObj**) (data_iter == data ? data_iter : data) + (i = 0); + jobj_iter += offsetof(ResultsData, x34) / sizeof(*jobj_iter); for (; i < 6; i++, jobj_iter++) { lb_80011E24(jobj, jobj_iter, i + 0x62, -1); } diff --git a/src/melee/gm/gmresultplayer.c b/src/melee/gm/gmresultplayer.c index 2ae9b79a07..efbc7c702c 100644 --- a/src/melee/gm/gmresultplayer.c +++ b/src/melee/gm/gmresultplayer.c @@ -41,23 +41,382 @@ #include #include #include +#include extern ResultsData lbl_8046DBE8; typedef struct { - /* 0x00 */ u8 pad_00[0x20]; + /* 0x00 */ f32 x0[8]; /* 0x20 */ f32 x20[4]; } CharScaleEntry; -CharScaleEntry lbl_803D6A18[] = { 0 }; -f32 lbl_803D7058[0x890 / sizeof(f32)] = { 0 }; +/* 3D6A08 */ u32 gmResultPlayerColors[4] = { + 0x013C59FF, + 0x064E01FF, + 0x54010BFF, + 0x408080FF, +}; + +/* 3D6A18 */ CharScaleEntry gmResultCharacterScaleData[] = { + { + { 0.2F, 0.0F, 2.8F, 0.0F, 10.0F, 13.5F, 24.0F, 7.0F }, + { 3.6F, 4.0F, 3.8F, 1.5F }, + }, + { + { -3.0F, 0.0F, -0.8F, 0.0F, 12.0F, 11.0F, 12.0F, 1.0F }, + { 2.3F, 2.0F, 2.5F, 1.0F }, + }, + { + { 3.5F, -3.0F, 1.0F, 0.0F, 17.0F, 16.0F, 18.0F, 5.0F }, + { 3.5F, 3.3F, 3.5F, 1.5F }, + }, + { + { 2.5F, -7.0F, -2.0F, -0.5F, 3.5F, -4.5F, -7.0F, 3.0F }, + { 1.8F, 0.9F, 0.9F, 1.3F }, + }, + { + { 0.0F, -1.0F, 0.0F, 0.0F, 0.0F, 7.0F, -4.0F, 1.5F }, + { 2.0F, 3.2F, 1.5F, 1.2F }, + }, + { + { 0.0F, -8.0F, 5.0F, 0.0F, 20.0F, 10.0F, 13.0F, 1.0F }, + { 3.2F, 3.6F, 2.8F, 1.1F }, + }, + { + { -1.0F, -4.5F, 3.0F, 1.0F, 22.0F, 22.0F, 23.0F, 6.0F }, + { 3.6F, 3.7F, 3.7F, 1.5F }, + }, + { + { 11.0F, 2.0F, 0.0F, 0.0F, -3.0F, 11.0F, 13.5F, 5.0F }, + { 3.0F, 2.5F, 3.0F, 1.5F }, + }, + { + { 0.0F, -3.0F, 0.0F, 0.1F, 12.5F, 10.0F, 15.0F, 4.0F }, + { 3.0F, 3.0F, 4.0F, 1.4F }, + }, + { + { -2.0F, 0.0F, 3.0F, 0.0F, 20.0F, 23.0F, 23.0F, 7.0F }, + { 3.5F, 4.0F, 3.8F, 1.6F }, + }, + { + { -1.0F, 4.0F, -1.0F, -0.6F, 12.0F, 13.5F, 23.0F, 3.5F }, + { 2.8F, 3.0F, 3.0F, 1.3F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 7.0F, 4.0F, 6.0F, 4.0F }, + { 3.0F, 2.0F, 2.5F, 1.4F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 18.0F, 18.0F, 20.0F, 7.0F }, + { 3.5F, 3.5F, 4.0F, 1.6F }, + }, + { + { 0.0F, 2.0F, -8.0F, 0.0F, 0.0F, 9.0F, -4.0F, 1.5F }, + { 1.5F, 3.2F, 2.2F, 1.2F }, + }, + { + { -8.0F, -9.0F, -5.0F, -2.0F, 10.0F, 6.5F, 0.8F, 2.0F }, + { 2.35F, 3.0F, 2.0F, 1.3F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, -2.0F, 0.0F, -7.0F, 0.0F }, + { 1.6F, 2.8F, 1.0F, 1.1F }, + }, + { + { 0.0F, 1.0F, -2.0F, 0.0F, 18.0F, 12.5F, 25.0F, 6.5F }, + { 3.2F, 3.8F, 4.2F, 1.5F }, + }, + { + { 3.0F, -1.0F, 2.5F, 0.1F, 13.0F, 9.5F, 13.0F, 2.8F }, + { 2.6F, 2.2F, 2.3F, 1.2F }, + }, + { + { -1.0F, 1.0F, 0.0F, 0.2F, 23.5F, 22.0F, 23.0F, 8.0F }, + { 4.0F, 4.0F, 4.0F, 1.6F }, + }, + { + { 1.0F, 0.0F, 1.0F, 0.0F, 20.0F, 25.0F, 16.0F, 7.0F }, + { 3.5F, 4.0F, 4.0F, 1.5F }, + }, + { + { -11.0F, -9.0F, -3.0F, 0.5F, 9.0F, 7.0F, 24.0F, 5.0F }, + { 3.0F, 3.5F, 3.8F, 1.5F }, + }, + { + { 1.0F, -5.5F, -0.5F, 1.0F, 18.0F, 19.0F, 20.0F, 6.5F }, + { 3.3F, 4.0F, 3.8F, 1.5F }, + }, + { + { 0.0F, 0.5F, 0.0F, 0.2F, 10.0F, 13.0F, 14.0F, 5.0F }, + { 3.0F, 3.0F, 3.6F, 1.5F }, + }, + { + { -15.0F, 3.5F, -0.3F, 0.0F, 15.0F, 23.0F, 22.0F, 5.5F }, + { 4.0F, 3.5F, 4.0F, 1.5F }, + }, + { + { 0.0F, 2.0F, 0.0F, 0.0F, -3.0F, 1.0F, 1.0F, 0.5F }, + { 1.3F, 2.5F, 2.0F, 1.3F }, + }, + { + { 0.5F, 0.0F, 0.0F, 0.0F, 19.0F, 27.0F, 25.0F, 7.5F }, + { 4.1F, 4.0F, 4.0F, 1.5F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + }, +}; + +/* 3D7018 */ u32 gmResultX22F4Init[0x20 / sizeof(u32)] = { + 0x00180000, 0x00000000, 0x00150015, 0x00000000, + 0x00120012, 0x00120000, 0x000E000E, 0x000E000E, +}; + +/* 3D7038 */ u32 gmResultScoreTableInit[0x20 / sizeof(u32)] = { + 0x00000000, 0x00000000, 0xFFF2000E, 0x00000000, + 0xFFEE0000, 0x00120000, 0xFFEAFFF9, 0x00070016, +}; + +typedef struct { + /* 0x000 */ f32 scale[32]; + /* 0x080 */ f32 slot_off[32][3][4]; + /* 0x680 */ u8 x680[27][0x10]; + /* 0x830 */ u8 pad_830[0x60]; +} ResultsCharacterData; + +/* 3D7058 */ ResultsCharacterData gmResultCharacterData = { + { + 0.85F, 0.8F, 1.0F, 1.0F, 1.0F, 0.7F, 0.9F, 1.0F, 1.0F, 0.88F, 0.8F, + 1.0F, 0.9F, 1.0F, 0.9F, 1.0F, 0.9F, 0.9F, 0.9F, 0.9F, 1.0F, 1.0F, + 1.0F, 1.0F, 1.0F, 0.79F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, + }, + { + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -3.5F, -4.0F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -3.0F, -2.3F, -1.5F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -3.3F, -3.5F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.0F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.4F, -1.5F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.4F, -1.2F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, -0.3F, -0.6F }, + { 0.0F, -2.7F, -3.1F, -3.5F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.9F, -3.2F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, -0.2F, -0.4F }, + { 0.0F, -2.7F, -3.1F, -3.5F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.3F, -2.9F, -3.5F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.0F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.4F, 0.9F }, + { 0.0F, -3.3F, -2.9F, -2.0F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.0F, -1.0F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.9F, -3.3F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.1F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -3.5F, -3.9F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -3.3F, -3.9F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.5F, -2.6F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, -0.1F, -0.3F, -0.6F }, + { 0.0F, -2.7F, -2.9F, -3.2F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.9F, -3.1F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, -0.2F, -0.4F, -0.5F }, + { 0.0F, -2.7F, -3.0F, -3.3F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.0F, -0.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -3.3F, -3.9F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + { + { 0.0F, 0.0F, 0.0F, 0.0F }, + { 0.0F, -2.7F, -2.7F, -2.7F }, + { 0.0F, 0.0F, 0.0F, 0.0F }, + }, + }, + { + { 0x17 }, { 0x29 }, { 0x27 }, { 0x2C }, { 0x05 }, { 0x17 }, { 0x28 }, + { 0x24 }, { 0x18 }, { 0x57 }, { 0x13 }, { 0x13 }, { 0x17 }, { 0x17 }, + { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, + { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, { 0x17 }, + }, + { 0 }, +}; + +/* 3D78E8 */ HSD_WObjDesc gmResultCameraEyeDesc = { NULL, + { 0.0F, 0.0F, 62.0F }, + NULL }; +/* 3D78FC */ HSD_WObjDesc gmResultCameraInterestDesc = { NULL, + { 0.0F, 0.0F, 0.0F }, + NULL }; + +/* 3D7910 */ HSD_CameraDescPerspective gmResultCameraDesc = { + NULL, + 0, + PROJ_PERSPECTIVE, + { 0, 640, 0, 480 }, + { 0, 640, 0, 480 }, + &gmResultCameraEyeDesc, + &gmResultCameraInterestDesc, + 0.0F, + NULL, + 1.0F, + 5000.0F, + 19.999998F, + 1.216667F, +}; + +/* 3D7948 */ char gmResultMissingGObjMessage[] = + "Error : model gobj dont't find at gmResultSetViewPos\n"; +/* 3D7980 */ char gmResultSourceFileName[] = "gmresultplayer.c"; +/* 3D7994 */ char gmResultMissingJObjMessage[] = + "Error : model jobj dont't find at gmResultSetViewPos\n"; typedef struct { GObj_RenderFunc funcs[4]; } ResultsRenderFuncs; typedef struct { - /* 0x00 */ u8 pad_00[0x24]; + /* 0x00 */ f32 x00[9]; /* 0x24 */ Vec3 x24; /* 0x30 */ Vec3 x30; /* 0x3C */ ResultsRenderFuncs x3C; @@ -74,11 +433,29 @@ typedef struct { /* 0x90 */ f32 x90; /* 0x94 */ f32 x94; /* 0x98 */ f32 x98; - /* 0x98 */ f32 x9C; + /* 0x9C */ f32 x9C; } ResultsPlayerConfig; -ResultsPlayerConfig const lbl_803B7B68 = { 0 }; -HSD_CObjDesc lbl_803D7910 = { 0 }; +ResultsPlayerConfig const lbl_803B7B68 = { + { 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, -100.0F }, + { 0.0F, 100.0F, 62.0F }, + { 0.0F, 100.0F, 0.0F }, + { { fn_80179DCC, fn_80179E34, fn_80179E9C, fn_80179F04 } }, + { 0.0F, 100.0F, 62.0F }, + { 0.0F, 100.0F, 0.0F }, + { { fn_80179D3C, fn_80179D60, fn_80179D84, fn_80179DA8 } }, + 0.0F, + 0.0F, + -100.0F, + 0.0F, + 0.0F, + -100.0F, + 0.75F, + 0.48F, + 0.4F, + 0.307F, + 0.0F, +}; typedef struct { /* 0x00 */ f32 x_off[4]; // indexed by variant (clamped to 3) @@ -94,8 +471,6 @@ typedef struct { /* 0xF08 */ HSD_CObjDesc cobj_desc; } CameraKindData; -CameraKindData lbl_803D6A08 = { 0 }; - typedef union { s16 h[4]; u32 w[2]; @@ -147,11 +522,33 @@ static HSD_GObj* lbl_8046E38C[4]; static HSD_JObj* lbl_8046E39C[4]; static lbl_8046E3AC_t lbl_8046E3AC; +/// @todo .sdata2 order hack void gm_80177724(struct ResultsMatchInfo* arg0) { +#ifdef MUST_MATCH + (void) 0.0; + (void) S32_TO_F32; + (void) 10.0f; + (void) 40.0f; + (void) 0.0f; + (void) 1.0f; + (void) 0.2f; + (void) 0.3f; + (void) 0.05f; + (void) 50.0f; + (void) 1.0; + (void) 29.0f; + (void) 30.0f; + (void) 120.0f; + (void) U32_TO_F32; +#endif memzero(arg0, sizeof(*arg0)); } +#ifdef MUST_MATCH +static const f32 sdata2_order_zero_one[2] = { 0.0f, 1.0f }; +#endif + static inline void inline0(HSD_JObj* jobj, float f) { HSD_ForeachAnim(jobj, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjSetRate, @@ -170,6 +567,9 @@ void fn_80177748(void) ResultsData* data = &lbl_8046DBE8; +#ifdef MUST_MATCH + (void) 100.0f; +#endif temp_r3 = fn_80174274(); for (i = 0; i < 4; i++) { @@ -201,6 +601,11 @@ void fn_80177748(void) } } +#ifdef MUST_MATCH +static const f32 sdata2_order_ten[1] = { 10.0f }; +static const f64 sdata2_order_s32[1] = { S32_TO_F32 }; +#endif + void fn_80177920(HSD_GObj* gobj) { MatchEnd* end; @@ -211,6 +616,9 @@ void fn_80177920(HSD_GObj* gobj) PAD_STACK(8); +#ifdef MUST_MATCH + (void) -300.0f; +#endif end = fn_80174274(); human_controller_count = 0; @@ -1133,15 +1541,53 @@ static inline HSD_JObj** get_result_jobjs(ResultsDisplayLayout* disp) return disp->jobjs; } +static inline u8* get_player_flags(ResultsDisplayLayout* disp) +{ + return disp->state.player_flags; +} + +static inline void fn_80179990_set_erase_color(MatchEnd* match_end, int slot) +{ + GXColor color; + + color = gm_80160968( + gm_80160854((u8) slot, match_end->player_standings[slot].team, + (u8) (match_end->is_teams == 1), + match_end->player_standings[slot].slot_type)); + HSD_SetEraseColor(color.r, color.g, color.b, color.a); +} + +static inline HSD_ImageDesc* +fn_80179990_get_player_img1(int slot, ResultsDisplayLayout* disp) +{ + HSD_ImageDesc* image_desc = disp->player_img1; + return &image_desc[slot]; +} + +static inline HSD_ImageDesc* +fn_80179990_copy_player_image(ResultsDisplayLayout* disp, int slot, int lookup) +{ + HSD_ImageDesc* image_desc = disp->player_img2; + HSD_ImageDesc* desc = &image_desc[slot]; + + HSD_ImageDescCopyFromEFB( + desc, + disp->state.scissor_x[lookup] + + (0x140 - ((s32) ((u16*) disp->state.dim_w1)[lookup] / 4) * 2), + disp->state.scissor_y[lookup] + + (0xF4 - ((s32) ((u16*) disp->state.dim_h1)[lookup] / 2) * 2), + 0, 0); + return desc; +} + void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) { ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; MatchEnd* match_end = &disp->state.match_end; - int lookup; HSD_ImageDesc* desc; HSD_CObj* cobj; HSD_JObj* child_jobj; - PAD_STACK(8); + int lookup; fn_801795D4(); fn_801796F0(arg2); @@ -1155,42 +1601,27 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) match_end->team_standings[match_end->player_standings[arg2].team] .is_big_loser; } + if (lookup != 0) { - child_jobj = HSD_JObjGetChild((HSD_JObj*) disp->gobjs[arg2]->hsd_obj); + HSD_JObj* root = (HSD_JObj*) disp->gobjs[arg2]->hsd_obj; + child_jobj = root == NULL ? NULL : root->child; } if (HSD_CObjSetCurrent(cobj)) { if (lookup != 0) { - GXColor color; - - color = gm_80160968( - gm_80160854((u8) arg2, match_end->player_standings[arg2].team, - (u8) (match_end->is_teams == 1), - match_end->player_standings[arg2].slot_type)); - HSD_SetEraseColor(color.r, color.g, color.b, color.a); + fn_80179990_set_erase_color(match_end, arg2); HSD_CObjEraseScreen(cobj, 1, 0, 0); Camera_800313E0(arg0, 0); { - HSD_ImageDesc* image_desc = disp->player_img2; - desc = &image_desc[arg2]; - - HSD_ImageDescCopyFromEFB( - desc, - disp->state.scissor_x[lookup] + - (0x140 - - ((s32) ((u16*) disp->state.dim_w1)[lookup] / 4) * 2), - disp->state.scissor_y[lookup] + - (0xF4 - - ((s32) ((u16*) disp->state.dim_h1)[lookup] / 2) * 2), - 0, 0); + desc = fn_80179990_copy_player_image(disp, arg2, lookup); if (!disp->state.x0_4) { + s32 x_offset = + ((s32) ((u16*) disp->state.dim_w1)[lookup] / 4) * 2; HSD_ImageDescCopyFromEFB( - &disp->player_img1[arg2], - 0x140 - - ((s32) ((u16*) disp->state.dim_w1)[lookup] / 4) * - 2, + fn_80179990_get_player_img1(arg2, disp), + 0x140 - x_offset, 0xF4 - ((s32) ((u16*) disp->state.dim_h1)[lookup] / 2) * 2, @@ -1215,22 +1646,15 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) } else { HSD_GObj* entity = Player_GetEntity(arg2); if (ftLib_800876B4(entity) == 0) { - u8* player_flags = disp->state.player_flags; - if (player_flags[arg2] == 0 && disp->state.x0_6) { - GXColor color; - - color = gm_80160968(gm_80160854( - (u8) arg2, match_end->player_standings[arg2].team, - (u8) (match_end->is_teams == 1), - match_end->player_standings[arg2].slot_type)); - HSD_SetEraseColor(color.r, color.g, color.b, color.a); + u8* player_flags = &get_player_flags(disp)[arg2]; + if (*player_flags == 0 && disp->state.x0_6) { + fn_80179990_set_erase_color(match_end, arg2); HSD_CObjEraseScreen(cobj, 1, 0, 0); Camera_800313E0(arg0, 0); { HSD_ImageDesc* image_desc = disp->player_img2; desc = &image_desc[arg2]; - HSD_ImageDescCopyFromEFB( desc, disp->state.scissor_x[lookup] + @@ -1250,7 +1674,7 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) 0x7C, 1, 0); HSD_CObjEndCurrent(); - player_flags[arg2] = 1; + *player_flags = 1; { HSD_JObj* jobj2 = get_result_jobjs(disp)[arg2]; jobj2->u.dobj->next->mobj->tobj->imagedesc = desc; @@ -1376,7 +1800,7 @@ void fn_8017A078(s32 arg0) callbacks = config->x3C; gobj = GObj_Create(0x13, 0x14, 0); - cobj = HSD_CObjLoadDesc(&lbl_803D7910); + cobj = HSD_CObjLoadDesc((HSD_CObjDesc*) &gmResultCameraDesc); HSD_GObjObject_80390A70(gobj, HSD_GObj_CameraKind, cobj); eye.y = (eye.y * (f32) (arg0 + 1)) + (0.7f * Player_800360D8(arg0)); @@ -1412,7 +1836,7 @@ HSD_GObj* fn_8017A318(s32 arg0) { static Scissor const scissor_init = { 270, 370, 124, 276 }; u32* config = (u32*) &lbl_803B7B68; - CameraKindData* data = &lbl_803D6A08; + CameraKindData* data = (CameraKindData*) gmResultPlayerColors; ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; MatchEnd* match_end = &disp->state.match_end; s32 _pad[2]; @@ -1581,7 +2005,8 @@ Fighter_GObj* fn_8017A67C(CharacterKind kind, int arg1, int arg2) pos2 = *(Vec3*) &config->x80; pos2.y = 100.0f * (f32) (arg2 + 1); Player_80032A04(arg2, &pos2); - Player_SetScale(arg2, 1.8f * lbl_803D7058[kind]); + Player_SetScale(arg2, + 1.8f * gmResultCharacterData.scale[kind]); Player_80036F34(arg2, variant); } else { int var_idx; @@ -1592,7 +2017,7 @@ Fighter_GObj* fn_8017A67C(CharacterKind kind, int arg1, int arg2) } else { var_idx = 3; } - scale = lbl_803D6A18[kind].x20[var_idx]; + scale = gmResultCharacterScaleData[kind].x20[var_idx]; Player_80036F34(arg2, variant); Player_SetScale( arg2, @@ -1636,9 +2061,6 @@ void fn_8017A9B4(int slot) (u16*) disp->state.dim_h2 + lookup); } -u32 lbl_803D7018[0x20 / sizeof(u32)] = { 0 }; -u32 lbl_803D7038[0x20 / sizeof(u32)] = { 0 }; - static s32 lbl_804D3FD0 = 0x00500050; static s32 lbl_804D3FD4 = 0x00460034; static s32 lbl_804D3FD8 = 0x006E0072; @@ -1658,33 +2080,61 @@ fn_8017AA78_get_team_standings(ResultsDisplayLayout* disp) return disp->state.match_end.team_standings; } -static inline int inline2(int unused) +static inline void fn_8017AA78_init_state(GXTexFmt image_format) { ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; Player_InitAllPlayers(); disp->shared_img.image_ptr = NULL; - lb_800121FC(&disp->shared_img, 0x64, 0x98, GX_TF_RGB5A3, 0); + lb_800121FC(&disp->shared_img, 0x64, 0x98, image_format, 0); disp->state.match_end = *fn_80174274(); - return unused; } -static inline u32* inline3(lbl_8046E3AC_t* state) +static inline u32* fn_8017AA78_get_dim_h1(lbl_8046E3AC_t* state) { return state->dim_h1; } -static inline int inline4(ResultsDisplayLayout* disp) +static inline u32* fn_8017AA78_get_dim_h2(lbl_8046E3AC_t* result_layout_state) +{ + return result_layout_state->dim_h2; +} + +static inline int fn_8017AA78_get_result(ResultsDisplayLayout* disp) { return disp->state.match_end.result; } +typedef union { + lbl_8046E3AC_t* state; + u8* bytes; +} ResultsStatePointer; + +static inline void fn_8017AA78_set_x0_0(u8 x0_0_value) +{ + ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; + + disp->state.x0_0 = x0_0_value; +} + +static inline void fn_8017AA78_inline4(PackedS16x4** x22f4, + lbl_8046E3AC_t** result_state, + PackedS16x4** score_table) +{ + ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; + + *x22f4 = (PackedS16x4*) gmResultX22F4Init; + *result_state = &disp->state; + *score_table = (PackedS16x4*) gmResultScoreTableInit; +} + void fn_8017AA78(const u8* arg0) { ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; PackedS16x4* p5; PackedS16x4* p7; lbl_8046E3AC_t* state; + ResultsStatePointer player_state; memzero(disp->pad_000, sizeof(disp->pad_000)); lbBgFlash_800208EC(6); @@ -1699,14 +2149,16 @@ void fn_8017AA78(const u8* arg0) efLib_Init(); efAsync_LoadSync(0); ftDemo_ObjAllocInit(); - inline2(0); + fn_8017AA78_init_state(GX_TF_RGB5A3); - disp->state.x0_0 = 1; + fn_8017AA78_set_x0_0(1); disp->state.x0_4 = 0; disp->state.x0_6 = 0; - p5 = (PackedS16x4*) lbl_803D7038; - state = &disp->state; - p7 = (PackedS16x4*) lbl_803D7018; + fn_8017AA78_inline4(&p7, &state, &p5); +#ifdef MUST_MATCH + p5 = (PackedS16x4*) gmResultScoreTableInit; +#endif + player_state.state = state; { s32 a; @@ -1718,7 +2170,7 @@ void fn_8017AA78(const u8* arg0) state->dim_w1[0] = a; state->dim_w1[1] = b; { - u32* dim_h1 = inline3(state); + u32* dim_h1 = fn_8017AA78_get_dim_h1(state); a = lbl_804D3FD8; (void) a; b = lbl_804D3FDC; @@ -1727,13 +2179,20 @@ void fn_8017AA78(const u8* arg0) dim_h1[1] = b; } a = lbl_804D3FE0; + (void) a; b = lbl_804D3FE4; + (void) b; state->dim_w2[0] = a; state->dim_w2[1] = b; - a = lbl_804D3FE8; - b = lbl_804D3FEC; - state->dim_h2[0] = a; - state->dim_h2[1] = b; + { + u32* dim_h2 = fn_8017AA78_get_dim_h2(state); + a = lbl_804D3FE8; + (void) a; + b = lbl_804D3FEC; + (void) b; + dim_h2[0] = a; + dim_h2[1] = b; + } a = lbl_804D3FF0; b = lbl_804D3FF4; ((u32*) state->scissor_y)[0] = a; @@ -1746,10 +2205,10 @@ void fn_8017AA78(const u8* arg0) { int i; - for (i = 0; i < 4; i++) { - state->player_flags[i] = 0; - state->costume_override[i] = arg0[i]; - if ((u8) inline4(disp) == OUTCOME_NO_CONTEST) { + for (i = 0; i < 4; player_state.bytes++, i++) { + player_state.bytes[1] = 0; + player_state.bytes[0x24] = arg0[i]; + if ((u8) fn_8017AA78_get_result(disp) == OUTCOME_NO_CONTEST) { struct MatchTeamData* team_standings; state->match_end.player_standings[i].is_big_loser = 1; team_standings = fn_8017AA78_get_team_standings(disp); diff --git a/src/melee/gm/gmstaffroll.c b/src/melee/gm/gmstaffroll.c index 714e73f3e5..3d2a8d59af 100644 --- a/src/melee/gm/gmstaffroll.c +++ b/src/melee/gm/gmstaffroll.c @@ -688,10 +688,6 @@ typedef struct StaffRollPoints { }, }; -/* 3DD23C */ static char gm_803DD23C[] = { - 0x25, 0x64, 0x20, 0x82, 0x67, 0x82, 0x68, 0x82, 0x73, 0, -}; - /* 4DAAEC */ volatile const s32 gm_804DAAEC = 0xFFB40000; void fn_801AB200(HSD_GObj* gobj) @@ -700,13 +696,14 @@ void fn_801AB200(HSD_GObj* gobj) HSD_JObj* cursor_jobj; HSD_JObj* jobj_pair[2]; HSD_JObj* temp_jobj; - u8 operand_pad[4]; + HSD_GObj* leaf; Vec3 xform_result; f32 proj[8]; s32 tally_color; - s32 tally_color2; - HSD_JObj* ptcl_jobj; - HSD_JObj* ptcl_jobj2; + GXColor tally_color2; + GXColor tally_color_copy; + f32 fov_scale; + f32 offset1, offset2; HSD_JObj* ptcl_jobj3; s32 selected; s32 button; @@ -731,13 +728,13 @@ void fn_801AB200(HSD_GObj* gobj) s32 line_num; HSD_Generator* gen; HSD_psAppSRT* appsrt; - HSD_JObj* child_jobj; - f32 fov_scale; + HSD_JObj* ptcl_jobj; f32 half_size; f32 highlight_val; - f32 offset1, offset2; + HSD_JObj* ptcl_jobj2; + HSD_Text* text; HSD_Text* tally_text; - PAD_STACK(80); + PAD_STACK(72); lb_80011E24(root, &cursor_jobj, 7, -1); @@ -868,9 +865,10 @@ void fn_801AB200(HSD_GObj* gobj) gm_803DD1C8.particles[entry_idx], -1); if (entry_idx == 0) { + s32 hover_color = *(s32*) &gm_804D42CC; p = (StaffRollPtclNode*) ptcl_jobj2->u.ptcl; - tally_color = *(s32*) &gm_804D42CC; + tally_color = hover_color; p = p->x4.ptr; p = p->x4.ptr; p = p->x4.ptr; @@ -930,18 +928,15 @@ void fn_801AB200(HSD_GObj* gobj) if (selected != -1 && (button == HSD_PAD_B || (gm_804D6818 == 0 && button == HSD_PAD_A))) { + int text_idx; + lb_80011E24(root, &temp_jobj, 8, -1); HSD_JObjReqAnimAll(temp_jobj, 0.0f); lbAudioAx_800237A8(0x7A12A, 0x7F, 0x40); entry_data = &gm_803DBFD8[selected]; - check_failed = 0; - if (entry_data->check != NULL && - entry_data->check(entry_data->check_arg) == 0) - { - check_failed = 1; - } - + check_failed = entry_data->check != NULL && + entry_data->check(entry_data->check_arg) == 0; base_page = selected * 0xF; jp_page = base_page + 7; jp_page1 = jp_page; @@ -950,18 +945,18 @@ void fn_801AB200(HSD_GObj* gobj) page_6 = base_page + 6; page_8 = base_page + 8; text_arr = gm_80480D58; - for (j = 0; j < 6; j++) { - if (text_arr[j] != NULL) { - HSD_SisLib_803A5CC4(text_arr[j]); + for (text_idx = 0; text_idx < 6; text_idx++) { + if (text_arr[text_idx] != NULL) { + HSD_SisLib_803A5CC4(text_arr[text_idx]); } gm_804D6810 = entry_data->x0; - if (j == 0) { + if (text_idx == 0) { x_pos = gm_803DBFD8_extra.x_positions[gm_804D6810]; gm_80480D58[0] = HSD_SisLib_803A5ACC( 0, 0, 1.45f + x_pos, 0.86f, 0.0f, 0.0f, 100.0f); - } else if (j == 1) { + } else if (text_idx == 1) { if (selected == 0xAC) { offset1 = 0.2f; } else { @@ -978,31 +973,32 @@ void fn_801AB200(HSD_GObj* gobj) 0.0f, 100.0f); } else { x_pos = gm_803DBFD8_extra.x_positions[gm_804D6810]; - text_arr[j] = HSD_SisLib_803A5ACC( - 0, 0, 1.45f + x_pos, (0.19f * (f32) j) + 0.67f, 0.0f, - 0.0f, 100.0f); + text_arr[text_idx] = HSD_SisLib_803A5ACC( + 0, 0, 1.45f + x_pos, (0.19f * (f32) text_idx) + 0.67f, + 0.0f, 0.0f, 100.0f); } - text_arr[j]->default_kerning = 1; - text_arr[j]->font_size.x = 0.00376f; - text_arr[j]->font_size.y = 0.0045f; + text_arr[text_idx]->default_kerning = 1; + text = text_arr[text_idx]; + text->font_size.x = 0.00376f; + text->font_size.y = 0.0045f; - if (j == 0) { + if (text_idx == 0) { if (check_failed == 0 || entry_data->has_check == 0) { - text_arr[j]->text_color.r = 0xC3; - text_arr[j]->text_color.g = 0xC3; - text_arr[j]->text_color.b = 0xC3; + text_arr[text_idx]->text_color.r = 0xC3; + text_arr[text_idx]->text_color.g = 0xC3; + text_arr[text_idx]->text_color.b = 0xC3; if (lbLang_IsSavedLanguageJP() != 0) { HSD_SisLib_803A6368(gm_80480D58[0], page_5); } else { HSD_SisLib_803A6368(gm_80480D58[0], page_6); } } - } else if (j == 1) { + } else if (text_idx == 1) { if (check_failed == 0 || entry_data->has_check == 0) { - text_arr[j]->text_color.r = 0xE8; - text_arr[j]->text_color.g = 0x37; - text_arr[j]->text_color.b = 0xE0; + text_arr[text_idx]->text_color.r = 0xE8; + text_arr[text_idx]->text_color.g = 0x37; + text_arr[text_idx]->text_color.b = 0xE0; if (lbLang_IsSavedLanguageJP() != 0) { HSD_SisLib_803A6368(gm_80480D58[1], jp_page1); } else { @@ -1010,27 +1006,27 @@ void fn_801AB200(HSD_GObj* gobj) } } } else { - text_arr[j]->text_color.r = 0xFF; - text_arr[j]->text_color.g = 0xB4; - text_arr[j]->text_color.b = 0; - if (selected == 0x4B && j == 2) { + text_arr[text_idx]->text_color.r = 0xFF; + text_arr[text_idx]->text_color.g = 0xB4; + text_arr[text_idx]->text_color.b = 0; + if (selected == 0x4B && text_idx == 2) { line_num = gm_IsCKindUnlocked(CKIND_DRMARIO) * 2; HSD_SisLib_803A6368( - text_arr[j], 0xBEC + - gm_IsCKindUnlocked(CKIND_LUIGI) + - line_num); - } else if (j == 2 && check_failed == 1) { + text_arr[text_idx], + 0xBEC + gm_IsCKindUnlocked(CKIND_LUIGI) + + line_num); + } else if (text_idx == 2 && check_failed == 1) { if (lbLang_IsSavedLanguageJP() != 0) { - HSD_SisLib_803A6368(text_arr[j], + HSD_SisLib_803A6368(text_arr[text_idx], entry_data->alt_page + 2); } else { - HSD_SisLib_803A6368(text_arr[j], + HSD_SisLib_803A6368(text_arr[text_idx], entry_data->alt_page + 3); } } else if (lbLang_IsSavedLanguageJP() != 0) { - HSD_SisLib_803A6368(text_arr[j], jp_page); + HSD_SisLib_803A6368(text_arr[text_idx], jp_page); } else { - HSD_SisLib_803A6368(text_arr[j], en_page); + HSD_SisLib_803A6368(text_arr[text_idx], en_page); } } jp_page++; @@ -1039,8 +1035,7 @@ void fn_801AB200(HSD_GObj* gobj) if (button == HSD_PAD_A && gm_804D6820 == 0) { gen = hsd_8039F05C(0, 0, 0x27); - appsrt = gen->appsrt; - if (appsrt == NULL) { + if ((appsrt = gen->appsrt) == NULL) { appsrt = psAddGeneratorAppSRT_begin(gen, 1); } @@ -1120,7 +1115,7 @@ void fn_801AB200(HSD_GObj* gobj) if (gm_804D6814 >= 0x1285 && gm_804D680C == NULL) { tally_count = 0; - tally_color2 = gm_804DAAEC; + tally_color2 = *(GXColor*) &gm_804DAAEC; for (j = 0; j < 6; j++) { HSD_SisLib_803A5CC4(gm_80480D58[j]); gm_80480D58[j] = NULL; @@ -1141,15 +1136,12 @@ void fn_801AB200(HSD_GObj* gobj) } line_num = HSD_SisLib_803A6B98(gm_804D680C, 0.0f, 0.0f, - gm_803DD23C, tally_count); - HSD_SisLib_803A74F0(gm_804D680C, line_num, - (GXColor*) &tally_color2); - - child_jobj = jobj_pair[0]->child; - HSD_JObjSetTranslateY(child_jobj, -0.4f); + "%d HIT", tally_count); + tally_color_copy = tally_color2; + HSD_SisLib_803A74F0(gm_804D680C, line_num, &tally_color_copy); - child_jobj = jobj_pair[1]->child; - HSD_JObjSetTranslateY(child_jobj, -0.4f); + HSD_JObjSetTranslateY(jobj_pair[0]->child, -0.4f); + HSD_JObjSetTranslateY(jobj_pair[1]->child, -0.4f); gm_804D681C = 1; } diff --git a/src/melee/gm/gmtou_1.c b/src/melee/gm/gmtou_1.c index 657c972423..1a23d7178d 100644 --- a/src/melee/gm/gmtou_1.c +++ b/src/melee/gm/gmtou_1.c @@ -50,6 +50,13 @@ static void sdata2_order(void) { (void) -19.5f; (void) 13.0f; + (void) 6.5f; + (void) 19.5f; + (void) 2.0f; + (void) S32_TO_F32; + (void) U32_TO_F32; + (void) 0.0f; + (void) 1.0f; } #endif @@ -530,7 +537,10 @@ typedef union TmPlayerAnimFrameTable { } TmPlayerAnimFrameTable; ASSERT_SIZE(TmPlayerAnimFrameTable, sizeof(s32) * 9); -TmPlayerAnimFrameTable const lbl_803B7CE0 = { 0 }; +TmPlayerAnimFrameTable const lbl_803B7CE0 = { + { 0x0000001E, 0x00000032, 0x003B0000, 0x003C0046, 0x0001005A, 0x00640000, + 0x006E0082, 0x00000096, 0x00A00000 } +}; void fn_80196FFC(HSD_GObj* gobj) { @@ -1594,10 +1604,25 @@ static inline BracketEntry* fn_8019A158_GetBracketEntry(s32 bracket_idx) return &lbl_80473AB8[bracket_idx]; } +typedef struct MatchEndStanding { + u8 pad[0x5D]; + u8 is_big_loser; + u8 is_small_loser; + u8 pad5F[0xA8 - 0x5F]; +} MatchEndStanding; +ASSERT_SIZE(MatchEndStanding, 0xA8); + +typedef struct Lbl804799D8Text { + u8 pad[0x4E]; + char x4E[20]; +} Lbl804799D8Text; + /// @todo All instructions match; only the callee-saved register assignment /// is permuted against the target. void fn_8019A158(void) { + Lbl804799D8Text* base_ptr; + MatchEnd** x48_ptr; TmData* td1; TmData* td2; BracketEntry* bracket; @@ -1616,9 +1641,11 @@ void fn_8019A158(void) s32 local1, local2; PAD_STACK(4); + base_ptr = (Lbl804799D8Text*) &lbl_804799D8; td1 = gm_GetTournamentData(); - lbl_804799D8.x48 = &gm_80477738; - lbl_804799D8.x0 = mode = 0; + ((struct Lbl804799D8_t*) base_ptr)->x48 = &gm_80477738; + x48_ptr = &((struct Lbl804799D8_t*) base_ptr)->x48; + ((struct Lbl804799D8_t*) base_ptr)->x0 = mode = 0; td2 = gm_GetTournamentData(); @@ -1629,7 +1656,7 @@ void fn_8019A158(void) mode = 2; } - me = lbl_804799D8.x48; + me = *x48_ptr; (void) me; result = fn_8018F508(&local2); if (result == 1) { @@ -1651,7 +1678,7 @@ void fn_8019A158(void) bracket_idx = fn_8018F74C(); for (k = 0; k < 20; k++) { - lbl_804799D8.x4E[k] = 0; + ((struct Lbl804799D8_t*) base_ptr)->x4E[k] = 0; } if (mode == 1) { @@ -1672,32 +1699,28 @@ void fn_8019A158(void) if (cursor[0x4E] == 3) { cursor[0x4C] = 3; } else { + MatchEndStanding* standing; u8 v; - /// @todo byte-offset walker: player_standings[i] is biased - /// +0x58 from the MatchEnd base the original walks from. - u8* p = (u8*) lbl_804799D8.x48 + i * 0xA8; - v = p[0x5E]; - p[0x5D] = v; + + standing = &((MatchEndStanding*) *x48_ptr)[i]; + v = standing->is_small_loser; + standing->is_big_loser = v; cursor[0x4C] = v; - if (lbl_804799D8.x48->player_standings[i].is_small_loser == 0) - { + if ((*x48_ptr)->player_standings[i].is_small_loser == 0) { sel = i; } } cursor += 0x2C; } } else { - bracket = fn_8019A158_GetBracketEntry(bracket_idx); counter = 0; - cursor = (u8*) bracket; for (i = 0; i < 4; i++) { - if (cursor[0x4E] == 3) { - cursor[0x4C] = 4; + if (lbl_80473AB8[bracket_idx].slots[i].x4E == 3) { + lbl_80473AB8[bracket_idx].slots[i].x4C = 4; } else { - cursor[0x4C] = counter; + lbl_80473AB8[bracket_idx].slots[i].x4C = counter; counter++; } - cursor += 0x2C; } switch (counter) { @@ -1723,34 +1746,35 @@ void fn_8019A158(void) { u8 v = lbl_80473AB8[bracket_idx].slots[0].x4C; - lbl_804799D8.x48->player_standings[0].is_big_loser = v; - lbl_804799D8.x48->player_standings[0].is_small_loser = v; + (*x48_ptr)->player_standings[0].is_big_loser = v; + (*x48_ptr)->player_standings[0].is_small_loser = v; v = lbl_80473AB8[bracket_idx].slots[1].x4C; - lbl_804799D8.x48->player_standings[1].is_big_loser = v; - lbl_804799D8.x48->player_standings[1].is_small_loser = v; + (*x48_ptr)->player_standings[1].is_big_loser = v; + (*x48_ptr)->player_standings[1].is_small_loser = v; v = lbl_80473AB8[bracket_idx].slots[2].x4C; - lbl_804799D8.x48->player_standings[2].is_big_loser = v; - lbl_804799D8.x48->player_standings[2].is_small_loser = v; + (*x48_ptr)->player_standings[2].is_big_loser = v; + (*x48_ptr)->player_standings[2].is_small_loser = v; v = lbl_80473AB8[bracket_idx].slots[3].x4C; - lbl_804799D8.x48->player_standings[3].is_big_loser = v; - lbl_804799D8.x48->player_standings[3].is_small_loser = v; + (*x48_ptr)->player_standings[3].is_big_loser = v; + (*x48_ptr)->player_standings[3].is_small_loser = v; } - cursor = (u8*) bracket; for (i = 0; i < 4; i++) { - if (cursor[0x4C] == 0) { + if (lbl_80473AB8[bracket_idx].slots[i].x4C == 0) { sel = i; } - cursor += 0x2C; } } { - lbl_804799D8.x4C = sel; - lbl_804799D8.x4D = lbl_80473AB8[bracket_idx].slots[sel].x4E; + ((struct Lbl804799D8_t*) base_ptr)->x4C = sel; + ((struct Lbl804799D8_t*) base_ptr)->x4D = + lbl_80473AB8[bracket_idx].slots[sel].x4E; - if (lbl_804799D8.x4D == 0 && lbl_80473AB8[bracket_idx].x18 != 0) { - u8 s = lbl_804799D8.x4C; + if (((struct Lbl804799D8_t*) base_ptr)->x4D == 0 && + lbl_80473AB8[bracket_idx].x18 != 0) + { + u8 s = ((struct Lbl804799D8_t*) base_ptr)->x4C; u16 val = td1->x4B8[s].x6; if (val <= 0x78) { gm_80167858(s, (s32) val, 0x1F, 0x78); @@ -1762,7 +1786,7 @@ void fn_8019A158(void) cursor = (u8*) &lbl_80473AB8[bracket_idx] + sel * 0x2C; { u8 model_idx = cursor[0x50]; - fn_8018F00C((char*) lbl_804799D8.x4E, td1->x37[model_idx].x9); + fn_8018F00C(base_ptr->x4E, td1->x37[model_idx].x9); } } } diff --git a/src/melee/gm/gmtou_2.c b/src/melee/gm/gmtou_2.c index ff43c5dec1..3b1368fc2a 100644 --- a/src/melee/gm/gmtou_2.c +++ b/src/melee/gm/gmtou_2.c @@ -687,6 +687,7 @@ void fn_8019D1BC(void) jobj = GET_JOBJ(gobj); fn_8018FDC4(jobj, (5.999997f * (f32) tmd->x37[i].xF) - 21.5f, 17.0f, 0.01f); + (void) &tmd->x534[i]; if (tmd->x37[i].x5 != 0) { fn_8019044C(jobj, 201.0f); @@ -1000,6 +1001,14 @@ void gm_8019ECAC_OnEnter_inline(void) void gm_8019E634(void) { + union { + u8 (*u8_fn)(MatchEnd*, ssize_t); + s32 (*s32_fn)(MatchEnd*, ssize_t); + } get_result; + union { + u32 word; + u8 bytes[4]; + } hbuf; struct Indices { s32 values[4]; } indices; @@ -1015,7 +1024,8 @@ void gm_8019E634(void) /* Get match results per player */ for (i = 0; i < (s32) tmd->x30; i++) { - results[i] = fn_80166CBC(&gm_80477738, i); + get_result.u8_fn = fn_80166CBC; + results[i] = get_result.s32_fn(&gm_80477738, i); } /* Bubble sort results, keeping indices in parallel */ @@ -1034,11 +1044,6 @@ void gm_8019E634(void) /* Handicap adjustment */ if (gmMainLib_GetGameRules()->handicap == 1) { - union { - u32 word; - u8 bytes[4]; - } hbuf; - hbuf.word = *(volatile u32 const*) &lbl_804DA948; /* Read handicap from x37 entries */ diff --git a/src/melee/gm/gmtoulib.c b/src/melee/gm/gmtoulib.c index de100cf0d3..8c249fa98b 100644 --- a/src/melee/gm/gmtoulib.c +++ b/src/melee/gm/gmtoulib.c @@ -95,6 +95,11 @@ typedef struct BracketSrcPtr { BracketSrcEntry* ptr; } BracketSrcPtr; +typedef union lbl_803D9D20_u { + struct lbl_803D9D20_t fields; + u8 bytes[sizeof(struct lbl_803D9D20_t)]; +} lbl_803D9D20_u; + static inline void gmTournament_SetBracketByes(BracketEntry* entries, s32 entrant_count) { @@ -139,7 +144,7 @@ void fn_8018A514(int count, float val) } } - n = lbl_803D9D20.x20[count]; + n = ((lbl_803D9D20_u*) &lbl_803D9D20)->bytes[i = count + 0x20]; entries = lbl_80473AB8; for (i = 0; i < n; i++) { @@ -206,39 +211,45 @@ void fn_8018A970(int arg0) void fn_8018AA74(HSD_JObj* jobj, s32 entry_idx, s32 slot_idx) { + u8* px3; + s32 x14; + s32 val1; + s32* p48; s32* p34; s32* p3C; - s32* p44; - s32* p38; - s32* p40; - s32* p48; BracketEntry* entry; + s32* p44; s32* pX18; - s32* pX10; + s32* p38; s32 xC; - s32 x14; + s32* p40; s32 x10; s32 x18; s32 val; - s32 val1; + s32* pX10; s32 val2; s32 tmp; u8 x2; + u8 x3; u8 tm_x2E; TmData* tm = gm_GetTournamentData(); + BracketData* bracket = (BracketData*) lbl_80473AB8; - p34 = &lbl_80473AB8[entry_idx].slots[slot_idx].x34; - p3C = &lbl_80473AB8[entry_idx].slots[slot_idx].x3C; - p44 = &lbl_80473AB8[entry_idx].slots[slot_idx].x44; - p38 = &lbl_80473AB8[entry_idx].slots[slot_idx].x38; - p40 = &lbl_80473AB8[entry_idx].slots[slot_idx].x40; - p48 = &lbl_80473AB8[entry_idx].slots[slot_idx].x48; + p34 = &bracket->entries[entry_idx].slots[slot_idx].x34; + p3C = &bracket->entries[entry_idx].slots[slot_idx].x3C; + p44 = &bracket->entries[entry_idx].slots[slot_idx].x44; + p38 = &bracket->entries[entry_idx].slots[slot_idx].x38; + p40 = &bracket->entries[entry_idx].slots[slot_idx].x40; + { + s32* slot_x48 = &bracket->entries[entry_idx].slots[slot_idx].x48; + p48 = slot_x48; + } entry = &lbl_80473AB8[entry_idx]; if (entry->x1 != 0) { - u8* px3 = &entry->x3; - u8 x3 = *px3; + px3 = &entry->x3; + x3 = *px3; (void) px3; if (x3 == 0 && entry->x4 != 0) { switch (entry->x4) { @@ -246,6 +257,7 @@ void fn_8018AA74(HSD_JObj* jobj, s32 entry_idx, s32 slot_idx) xC = entry->xC; pX18 = &entry->x18; pX10 = &entry->x10; + (void) pX18; *p3C = xC; *p44 = xC; *p34 = xC; @@ -404,7 +416,7 @@ void fn_8018AA74(HSD_JObj* jobj, s32 entry_idx, s32 slot_idx) *p34 = val1; { x18 = lbl_80473AB8[entry_idx].x18; - x2 = lbl_80473AB8[entry_idx].x2; + x2 = bracket->entries[entry_idx].x2; x10 = lbl_80473AB8[entry_idx].x10; val2 = x10 + x18 - x18 * x2; *p40 = val2; @@ -490,6 +502,12 @@ static inline BracketEntry* fn_8018B090_inline2(BracketEntry* bracket_entries, return &bracket_entries[bracket_entry_index]; } +static inline void fn_8018B090_inline3(BracketEntry* entry) +{ + fn_80190520((f32) (entry->xC + (entry->x14 / 2)), + -(f32) (entry->x10 + (entry->x18 / 2)), -150.0f); +} + void fn_8018B090(HSD_GObj* arg0) { BracketEntry* entries = lbl_80473AB8; @@ -701,8 +719,7 @@ void fn_8018B090(HSD_GObj* arg0) case 32: { s32 h = entries[idx].x18; if (h != 0) { - fn_80190520((f32) (entries[idx].xC + (entries[idx].x14 / 2)), - -(f32) (entries[idx].x10 + (h / 2)), -150.0f); + fn_8018B090_inline3(&entries[idx]); for (i = 0; i < 4; i++) { if (entries[idx].slots[i].x4C == 0) { entries[idx].slots[i].x3C = @@ -758,8 +775,8 @@ void fn_8018B090(HSD_GObj* arg0) } } if (var_r24 == 4) { - s32 slot_idx = lbl_804D6634; - entries[idx].slots[slot_idx].x3C = + s32 slot_idx; + entries[idx].slots[slot_idx = lbl_804D6634].x3C = lbl_803D9E1C[tm->entrants][0]; entries[idx].slots[slot_idx].x40 = lbl_803D9E1C[tm->entrants][1]; diff --git a/src/melee/gm/gmtoygallery.c b/src/melee/gm/gmtoygallery.c index c7d25055e2..29dfd1cab8 100644 --- a/src/melee/gm/gmtoygallery.c +++ b/src/melee/gm/gmtoygallery.c @@ -7,6 +7,8 @@ /* 1BEC80 */ static void onExit(GameModeState*); /* 4D6908 */ static UNK_T exit_data[2]; +/* 4D6910 */ static UNK_T toy_lottery_exit_data[2]; +/* 4D6918 */ UNK_T toy_collection_exit_data[2]; GameModeState gm_Mode_ToyGallery_States[] = { { diff --git a/src/melee/gr/granime.c b/src/melee/gr/granime.c index 0ab7da6bfd..41138b830d 100644 --- a/src/melee/gr/granime.c +++ b/src/melee/gr/granime.c @@ -344,7 +344,24 @@ static inline void grAnime_801C6A54_inner(HSD_JObj* jobj, HSD_MatAnimJoint* matanimjoint, HSD_ShapeAnimJoint* shapeanimjoint) { - grAnime_801C6A54(jobj, animjoint, matanimjoint, shapeanimjoint); + if (jobj == NULL) { + return; + } + if (animjoint != NULL) { + if (animjoint->aobjdesc != NULL) { + if (jobj->aobj != NULL) { + HSD_AObjRemove(jobj->aobj); + } + jobj->aobj = HSD_AObjLoadDesc(animjoint->aobjdesc); + grAnime_801C69FC_for_jobj(grAnime_GetAObj(jobj)); + } + grAnime_801C6960(jobj->robj, animjoint->robj_anim); + } + if (union_type_dobj(jobj)) { + grAnime_801C683C( + jobj->u.dobj, matanimjoint != NULL ? matanimjoint->matanim : NULL, + shapeanimjoint != NULL ? shapeanimjoint->shapeanimdobj : NULL); + } } static inline void @@ -352,7 +369,7 @@ grAnime_801C6A54_noinline(HSD_JObj* jobj, HSD_AnimJoint* animjoint, HSD_MatAnimJoint* matanimjoint, HSD_ShapeAnimJoint* shapeanimjoint) { - grAnime_801C6A54_inner(jobj, animjoint, matanimjoint, shapeanimjoint); + grAnime_801C6A54(jobj, animjoint, matanimjoint, shapeanimjoint); } void grAnime_801C6C0C(HSD_JObj* jobj, HSD_AnimJoint* animjoint, @@ -372,7 +389,7 @@ void grAnime_801C6C0C(HSD_JObj* jobj, HSD_AnimJoint* animjoint, HSD_ShapeAnimJoint* next_sj; if (jobj != NULL) { - grAnime_801C6A54(jobj, animjoint, matanimjoint, shapeanimjoint); + grAnime_801C6A54_inner(jobj, animjoint, matanimjoint, shapeanimjoint); if (!(jobj->flags & 0x1000)) { jp = jobj->child; if (animjoint != NULL) { @@ -920,13 +937,13 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, HSD_MatAnimJoint** mjp; HSD_ShapeAnimJoint** sjp; u32 req_flags = 0; + u32 request_flags; HSD_AnimJoint* aj; HSD_AnimJoint* caj; HSD_ShapeAnimJoint* csj; HSD_JObj* child; HSD_MatAnimJoint* mj; HSD_MatAnimJoint* cmj; - HSD_ShapeAnimJoint* sj; u8* eflags; s32 flag; @@ -954,17 +971,19 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, mj = NULL; } if ((arg3 & 4) && (sjp = archive->unk4->unk8[map_id].unkC, sjp != NULL) && - ((sj = sjp[arg4]) != NULL)) + ((HSD_ShapeAnimJoint*) (arg3 = (s32) sjp[arg4]) != NULL)) { - sj = &sj[arg2]; + arg3 += arg2 * sizeof(HSD_ShapeAnimJoint); anim_flags |= 0x100; req_flags |= 8; } else { - sj = NULL; + arg3 = 0; } + request_flags = req_flags; if (arg5 != 0) { if (jobj != NULL) { - grAnime_801C6A54_noinline(jobj, aj, mj, sj); + grAnime_801C6A54_noinline(jobj, aj, mj, + (HSD_ShapeAnimJoint*) arg3); if (!(jobj->flags & 0x1000)) { child = jobj->child; if (aj != NULL) { @@ -985,9 +1004,9 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, } else { cmj = NULL; } - if (sj != NULL) { - if (sj != NULL) { - csj = sj->child; + if ((HSD_ShapeAnimJoint*) arg3 != NULL) { + if ((HSD_ShapeAnimJoint*) arg3 != NULL) { + csj = ((HSD_ShapeAnimJoint*) arg3)->child; } else { csj = NULL; } @@ -1027,7 +1046,7 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, } } } - HSD_JObjReqAnimAllByFlags(jobj, req_flags, farg0); + HSD_JObjReqAnimAllByFlags(jobj, request_flags, farg0); } else { if (jobj != NULL) { if (aj != NULL) { @@ -1049,10 +1068,12 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, if ((jobj->flags & 0x4020) ? false : true) { grAnime_801C683C_noinline( jobj->u.dobj, mj != NULL ? mj->matanim : NULL, - sj != NULL ? sj->shapeanimdobj : NULL); + (HSD_ShapeAnimJoint*) arg3 != NULL + ? ((HSD_ShapeAnimJoint*) arg3)->shapeanimdobj + : NULL); } } - HSD_JObjReqAnimByFlags(jobj, req_flags, farg0); + HSD_JObjReqAnimByFlags(jobj, request_flags, farg0); } grAnime_801C752C(jobj, arg5, anim_flags, HSD_AObjSetRate, 1, farg1); archive = grDatFiles_801C6330(map_id); diff --git a/src/melee/gr/grbigblue.c b/src/melee/gr/grbigblue.c index 8916bd1b8c..c5578496bb 100644 --- a/src/melee/gr/grbigblue.c +++ b/src/melee/gr/grbigblue.c @@ -10,6 +10,10 @@ #include +#ifdef MUST_MATCH +#include +#endif + #include "baselib/debug.h" #include "cm/camera.h" #include "gm/gm_1A45.h" @@ -109,11 +113,6 @@ typedef struct grBb_ItemKindList { ItemKind kinds[5]; } grBb_ItemKindList; -const grBb_LineIds grBb_803B8134 = { { - 33, 35, 38, 39, 40, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, -} }; - static grBb_YakumonoParam* yakumono_param; typedef struct grBb_Data803E2D78 { @@ -210,6 +209,11 @@ static const Vec3 grBb_803B8114 = { 56.0F, 40.0F, 24.0F }; It_Kind_Kusudama, } }; +const grBb_LineIds grBb_803B8134 = { { + 33, 35, 38, 39, 40, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, +} }; + void grBigBlue_801E57BC(bool arg) {} void grBigBlue_801E57C0(void) @@ -654,29 +658,33 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) s32 i; Vec3 pos; Ground* gp = GET_GROUND(gobj); - i = 0; - do { + for (i = 0; i < 3; i++) { + Vec3 fwd, neg_pos; + Point3d normal; + Vec3 euler; s8 idx = gp->u.bigblue.data[i].index; - u8 state = gp->u.bigblue.data[i].x1; HSD_JObj* jobj = gp->u.bigblue.xD4[idx]; - switch ((s8) state) { + switch ((s8) gp->u.bigblue.data[i].x1) { case 0: { if ((int) grBigBlue_801E89DC(0) != 0) { s32 range = yakumono_param->x8C; s32 rand_val; + Vec3* pos_ptr; if (range != 0) { - rand_val = HSD_Randi(range); + s32 random_value = HSD_Randi(range); + rand_val = random_value; } else { rand_val = 0; } gp->u.bigblue.data[i].x4 = yakumono_param->x88 + rand_val; HSD_JObjGetTranslation(jobj, &pos); + pos_ptr = &pos; - gp->u.bigblue.data[i].x38 = pos; + gp->u.bigblue.data[i].x38 = *pos_ptr; gp->u.bigblue.data[i].x44.z = 0.0f; gp->u.bigblue.data[i].x44.y = 0.0f; gp->u.bigblue.data[i].x44.x = 0.0f; @@ -692,10 +700,10 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->u.bigblue.data[i].x1 = 0; break; } + /* fallthrough */ case 2: { Ground* base = gp; if (gp->u.bigblue.data[i].x4 <= 0) { - Vec3 neg_pos; f32 right_y, left_y; s32 found; s32 retries; @@ -721,7 +729,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) } height_range_i = (s32) height_range; height_range_arg = (s32) height_range; - if (height_range_i != 0) { + if (height_range_i) { height_rand = HSD_Randi(height_range_arg); } else { height_rand = 0; @@ -777,13 +785,9 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) if (found == 0) { Vec3 speeds2; speeds2 = grBb_803B8114; - { - Vec3* pos_ptr = &pos; - found = grBigBlue_801EAB50( - pos_ptr, 0, - 2.0f * (speeds2.x * Ground_801C0498()), - 25.0f); - } + found = grBigBlue_801EAB50( + &pos, 0, + 2.0f * (speeds2.x * Ground_801C0498()), 25.0f); } if (found == 0) { f32 bound = grBigBlue_801E8D04(); @@ -837,25 +841,26 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) } base->u.arwing.xC4 += 1; if ((int) grBigBlue_801E89DC(2) == 0) { + grBb_YakumonoParam* params = yakumono_param; u32 cnt = base->u.arwing.xC4; - if ((s32) cnt >= yakumono_param->x11C) { - s32 max = yakumono_param->x120; + if ((s32) cnt >= params->x11C) { + s32 max = params->x120; if ((s32) cnt <= max && ((s32) cnt == max || HSD_Randi(2) != 0)) { - grBigBlue_801E8978(2, (void*) 1, jobj); + grBigBlue_801E8978(2, (HSD_JObj*) 1, jobj); } } } if ((int) grBigBlue_801E89DC(1) == 0) { + grBb_YakumonoParam* params = yakumono_param; u32 cnt2 = base->u.arwing.xC4; - if (yakumono_param->xDC <= (s32) cnt2 && + if ((s32) cnt2 >= params->xDC && (s32) gp->u.bigblue.data[i].x2 == 1 && - ((s32) cnt2 >= yakumono_param->xE0 || - HSD_Randi(2) != 0)) + ((s32) cnt2 >= params->xE0 || HSD_Randi(2) != 0)) { grBigBlue_801E8978(0, NULL, NULL); - grBigBlue_801E8978(1, (void*) 1, jobj); + grBigBlue_801E8978(1, (HSD_JObj*) 1, jobj); base->u.arwing.xC4 = 0; } } @@ -863,24 +868,24 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) } else { Ground* bone_ptr = base; Ground* other = base; - s32 active_count = 0; s32 j; + s32 active_count = 0; for (j = 0; j < 3; j++) { if (jobj != bone_ptr->u.bigblue.xD4[j]) { u8 other_state = other->u.bigblue.data[j].x1; if ((s8) other_state == 3) { - if ((gp->u.bigblue.data[j].x2 == 1 && - gp->u.bigblue.data[j].x38.x < + if ((other->u.bigblue.data[j].x2 == 1 && + other->u.bigblue.data[j].x38.x < Stage_GetCamBoundsRightOffset()) || - (gp->u.bigblue.data[j].x2 == -1 && - gp->u.bigblue.data[j].x38.x > + (other->u.bigblue.data[j].x2 == -1 && + other->u.bigblue.data[j].x38.x > Stage_GetCamBoundsLeftOffset())) { active_count++; } } else if ((s8) other_state == 1 && - gp->u.bigblue.data[j].x4 == 0) + other->u.bigblue.data[j].x4 == 0) { active_count++; } @@ -893,14 +898,11 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->u.bigblue.data[i].x4 -= 1; } } - break; - } + } break; case 3: { f32 surface_y; - Point3d normal; - Vec3 euler; - Vec3 fwd, back; + Vec3 back; f32 speed_val; HSD_JObjGetTranslation(jobj, &pos); @@ -1042,8 +1044,8 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->u.bigblue.data[i].x4 = yakumono_param->xB4; gp->u.bigblue.data[i].x34 = 2; } else { - f32 prev_y = gp->u.bigblue.data[i].x28; f32 prev_x = gp->u.bigblue.data[i].x24; + f32 prev_y = gp->u.bigblue.data[i].x28; if (prev_y > prev_x) { gp->u.bigblue.data[i].x18.z = @@ -1225,8 +1227,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) break; } } - i++; - } while (i < 3); + } Ground_801C2FE0(gobj); } @@ -1578,6 +1579,25 @@ bool grBigBlue_801E93D0(Ground_GObj* arg) return false; } +static inline s32 grBigBlue_CountCars(void) +{ + s32 i; + HSD_JObj* cars_avail = NULL; + Ground* manager = GET_GROUND(Ground_GetMapGObj(32)); + s32 count = 0; + + for (i = 0; i < 3; i++) { + if ((s8) manager->u.bigblue.data[i].x1 != 0) { + count++; + if (cars_avail != NULL) { + cars_avail = manager->u.bigblue + .xD4[(s8) manager->u.bigblue.data[i].index]; + } + } + } + return count; +} + void grBigBlue_801E93D8(Ground_GObj* gobj) { Vec3 pos; @@ -1585,8 +1605,9 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) Vec3 back; Vec3 normal; Vec3 euler; - Ground* gp = gobj->user_data; + u8 pad[4]; Vec3 check_pos; + Ground* gp = gobj->user_data; u8* bp = (u8*) gp; HSD_JObj* jobj = GET_JOBJ(gobj); PAD_STACK(56); @@ -1623,21 +1644,7 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) if (((grBb_GroundStateFlag*) Ground_GetMapGObj(32)->user_data) ->xCC != 0) { - s32 i; - HSD_JObj* cars_avail = NULL; - Ground* manager = GET_GROUND(Ground_GetMapGObj(32)); - s32 count = 0; - - for (i = 0; i < 3; i++) { - if ((s8) manager->u.bigblue.data[i].x1 != 0) { - count++; - if (cars_avail != NULL) { - cars_avail = - manager->u.bigblue.xD4 - [(s8) manager->u.bigblue.data[i].index]; - } - } - } + s32 count = grBigBlue_CountCars(); if (count <= 1) { f32 height; @@ -1781,22 +1788,28 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) target_z = euler.z; *(f32*) (bp + 0xCC) = target_z; if (HSD_JObjGetRotationZ(jobj) < *(f32*) (bp + 0xCC)) { + f32 target; f32 delta = 0.017453292f * (yakumono_param->xD4 * (*(f32*) (bp + 0xCC) - HSD_JObjGetRotationZ(jobj))); HSD_JObjAddRotationZ(jobj, delta); - if (HSD_JObjGetRotationZ(jobj) >= *(f32*) (bp + 0xCC)) { - HSD_JObjSetRotationZ(jobj, *(f32*) (bp + 0xCC)); + if (HSD_JObjGetRotationZ(jobj) >= + (target = *(f32*) (bp + 0xCC))) + { + HSD_JObjSetRotationZ(jobj, target); } } else { + f32 target; f32 delta = 0.017453292f * (yakumono_param->xD4 * (*(f32*) (bp + 0xCC) - HSD_JObjGetRotationZ(jobj))); HSD_JObjAddRotationZ(jobj, delta); - if (HSD_JObjGetRotationZ(jobj) <= *(f32*) (bp + 0xCC)) { - HSD_JObjSetRotationZ(jobj, *(f32*) (bp + 0xCC)); + if (HSD_JObjGetRotationZ(jobj) <= + (target = *(f32*) (bp + 0xCC))) + { + HSD_JObjSetRotationZ(jobj, target); } } @@ -1839,7 +1852,10 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) } pos.y += vy; - HSD_JObjAddTranslationX(jobj, *(f32*) (bp + 0xD8)); + { + f32 translate_x = *(f32*) (bp + 0xD8); + HSD_JObjAddTranslationX(jobj, translate_x); + } { f32 translate_y = pos.y; HSD_JObjSetTranslateY(jobj, translate_y); diff --git a/src/melee/gr/grbigblueroute.c b/src/melee/gr/grbigblueroute.c index 06cf237800..f1322ebf65 100644 --- a/src/melee/gr/grbigblueroute.c +++ b/src/melee/gr/grbigblueroute.c @@ -564,11 +564,14 @@ s32 grBigBlueRoute_8020C530(Ground_GObj* arg0) HSD_ASSERT(0X2E5, 0); } -/// @todo The initial Ground load is coalesced directly into r31 instead of -/// passing through r6. #define GRBB_ROUTE_ENTRY_AT(car_info, offset) \ ((RouteEntry*) &((union grBigBlueRoute_RouteStorage*) (car_info)) \ ->bytes[offset]) +static inline s32 grBigBlueRoute_Randi(s32 range) +{ + return HSD_Randi(range); +} + static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, Ground_GObj* gobj) { @@ -590,19 +593,26 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, if (max_val > min_val) { s32 range = max_val - min_val; - new_timer = min_val + ((range != 0) ? HSD_Randi(range) : 0); + new_timer = + min_val + ((range != 0) ? grBigBlueRoute_Randi(range) : 0); } else if (max_val < min_val) { s32 range = min_val - max_val; - new_timer = max_val + ((range != 0) ? HSD_Randi(range) : 0); + new_timer = + max_val + ((range != 0) ? grBigBlueRoute_Randi(range) : 0); } else { new_timer = max_val; } gp->u.car.x10A = (s16) new_timer; } +#ifdef MUST_MATCH + /// @remark Matching tactic: this keeps @c gobj live through route setup + /// for MWCC register allocation. + if (gobj != NULL) { + } +#endif if (route_idx != -1) { - s32 route = route_idx; - s32 offset = route * sizeof(RouteEntry); + s32 offset = route_idx * sizeof(RouteEntry); RouteEntry* re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset)->flags.b0 = 1; @@ -653,7 +663,7 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, if (jobj != NULL) { s32 i = 0; - while (i < route && jobj != NULL) { + while (i < route_idx && jobj != NULL) { i++; if (jobj == NULL) { jobj = NULL; @@ -677,8 +687,8 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->x28 = (void*) item; if (item != NULL) { - RouteEntry* route_entries = gp->u.car.car_info; - re = GRBB_ROUTE_ENTRY_AT(route_entries, offset); + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, + offset); grMaterial_801C8E28((HSD_GObj*) re->x28); } } @@ -695,7 +705,6 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, void grBigBlueRoute_8020C85C(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); - Ground* spawn_gp = gobj->user_data; if (!((f32) gp->u.car.x108 < 1.0f + yakumono_param->x40)) { return; @@ -705,7 +714,7 @@ void grBigBlueRoute_8020C85C(Ground_GObj* gobj) return; } - grBigBlueRoute_SpawnRoute(gp->u.car.x108, spawn_gp, gobj); + grBigBlueRoute_SpawnRoute(gp->u.car.x108, gp, gobj); } static const Vec3 grBb_Route_803B83E0 = { 0.0f, 1.0f, 0.0f }; diff --git a/src/melee/gr/grinishie1.c b/src/melee/gr/grinishie1.c index bb50645b6b..8fa59c47db 100644 --- a/src/melee/gr/grinishie1.c +++ b/src/melee/gr/grinishie1.c @@ -653,6 +653,7 @@ grInishie1_801FB3F0_update_blocks(HSD_GObj* gobj, grInishie1_801FB3F0_Vars* vars, Vec3* pos) { u32 i; + HSD_DObj* dobj; for (i = 0; i < 0x13; ++i) { switch (vars->blocks[i].x2) { @@ -693,7 +694,11 @@ grInishie1_801FB3F0_update_blocks(HSD_GObj* gobj, } else { lb_8000B1CC(vars->blocks[i].jobj, NULL, pos); if (!grLib_801C9EE8(pos, 15.0f)) { - DOBJ_CLEAR_LOOP(vars->blocks[i].jobj); + dobj = HSD_JObjGetDObj(vars->blocks[i].jobj); + while (dobj != NULL) { + HSD_DObjClearFlags(dobj, 1U); + dobj = (dobj != NULL) ? dobj->next : NULL; + } HSD_JObjClearFlagsAll(vars->blocks[i].jobj, JOBJ_HIDDEN); grMaterial_801C8E08(vars->blocks[i].item_gobj); vars->blocks[i].x2 = 1; @@ -723,12 +728,24 @@ grInishie1_801FB3F0_update_blocks(HSD_GObj* gobj, HSD_JObjSetFlagsAll(target, JOBJ_HIDDEN); } - DOBJ_CLEAR_LOOP(vars->blocks[i].jobj); + dobj = HSD_JObjGetDObj(vars->blocks[i].jobj); + while (dobj != NULL) { + HSD_DObjClearFlags(dobj, 1U); + dobj = (dobj != NULL) ? dobj->next : NULL; + } } else { if (vars->blocks[i].x22 & 1) { - DOBJ_CLEAR_LOOP(vars->blocks[i].jobj); + dobj = HSD_JObjGetDObj(vars->blocks[i].jobj); + while (dobj != NULL) { + HSD_DObjClearFlags(dobj, 1U); + dobj = (dobj != NULL) ? dobj->next : NULL; + } } else { - DOBJ_LOOP(vars->blocks[i].jobj); + dobj = HSD_JObjGetDObj(vars->blocks[i].jobj); + while (dobj != NULL) { + HSD_DObjSetFlags(dobj, 1U); + dobj = (dobj != NULL) ? dobj->next : NULL; + } } } diff --git a/src/melee/gr/grkongo.c b/src/melee/gr/grkongo.c index 7f678a9063..e429bc386a 100644 --- a/src/melee/gr/grkongo.c +++ b/src/melee/gr/grkongo.c @@ -813,39 +813,19 @@ void grKongo_801D69B0(HSD_GObj* gobj) mpJointSetB10(4); } -static inline void rad_compare(f32 a, f32 b, f32* ret) -{ - f32 c = MTXDegToRad(b); - if (a > c) { - *ret = c; - } else { - c = -c; - if (a < c) { - *ret = c; - } - } -} - static inline void rad_compare_b(f32 a, f32 b, f32* ret) { - f32 c = MTXDegToRad(b); - if (a > c) { - c = -c; - } else if (a < -c) { - } else { - c = 0.0F; - } - *ret = (f32) (0.99 * (f64) (c + *ret)); -} + f32 limit = MTXDegToRad(b); + f32 value; -static inline void rad_compare_c(f32 a, f32 b, f32 d, f32* ret) -{ - f32 c = MTXDegToRad(b); - if (a > c) { - *ret += d * (a - c); - } else if (a < -c) { - *ret += d * (a + c); + if (a > limit) { + value = -limit; + } else if (a < -limit) { + value = limit; + } else { + value = 0.0f; } + *ret = (f32) (0.99 * (f64) (value + *ret)); } typedef struct unk_struct_x14 { @@ -856,143 +836,111 @@ typedef struct unk_struct_x14 { f32 unk10; } unk_struct_x14; -static inline void grKongo_801D6AFC_apply(const f32* deltas, - _struct_grKg_803E188C_0x18* entries) -{ - int i; - - for (i = 0; i < 0xF; i++) { - f32 delta = deltas[i]; - if (delta != 0.0) { - entries[i].unkC += delta; - } - } -} - void grKongo_801D6AFC(void) { f32 sp44[15]; - _struct_grKg_803E188C_0x18* entries; - f32* var_r5; - f32* deltas; f32 sp8[15]; + f32* values = sp44; { - s32 var_ctr_1 = 3; - f32* p = sp44; - do { - p[0] = 0.0f; - p[1] = 0.0f; - p[2] = 0.0f; - p[3] = 0.0f; - p[4] = 0.0f; - p += 5; - var_ctr_1 -= 1; - } while (var_ctr_1 != 0); + f32* p = values; + s32 i; + + for (i = 15; i > 0; i--) { + *p++ = 0.0f; + } } - var_r5 = sp44; - entries = grKg_803E188C; + { - s32 var_ctr_2 = 5; - _struct_grKg_803E188C_0x18* var_r3_2 = grKg_803E188C; - do { - int i; - for (i = 0; i < 3; i++) { - rad_compare_b(var_r3_2->unkC - var_r3_2->unk8, - yakumono_param->unk94, &var_r3_2->unk10); - var_r3_2++; - } - var_ctr_2 -= 1; - } while (var_ctr_2 != 0); + s32 i; + + for (i = 0; i < 15; i++) { + rad_compare_b(grKg_803E188C[i].unkC - grKg_803E188C[i].unk8, + yakumono_param->unk94, &grKg_803E188C[i].unk10); + } } + { - s32 var_ctr_3 = 3; - _struct_grKg_803E188C_0x18* var_r3_3 = grKg_803E188C; - f32 temp_f0; - do { - var_r3_3->unk10 += var_r5[0]; - var_r3_3[1].unk10 += var_r5[1]; - var_r3_3[2].unk10 += var_r5[2]; - var_r3_3[3].unk10 += var_r5[3]; - temp_f0 = var_r5[4]; - var_r5 += 5; - var_r3_3[4].unk10 += temp_f0; - var_r3_3 += 5; - var_ctr_3 -= 1; - } while (var_ctr_3 != 0); + _struct_grKg_803E188C_0x18* entry = grKg_803E188C; + s32 i; + + for (i = 15; i > 0; i--) { + entry->unk10 += *values; + values++; + entry++; + } } + { - s32 var_ctr_4 = 3; - _struct_grKg_803E188C_0x18* var_r3_4 = grKg_803E188C; - do { - int i; - for (i = 0; i < 5; i++) { - rad_compare(var_r3_4->unk10, yakumono_param->unk98, - &var_r3_4->unk10); - var_r3_4++; - } - var_ctr_4 -= 1; - } while (var_ctr_4 != 0); + s32 i; + + for (i = 0; i < 15; i++) { + Ground_ClampSymmetric(grKg_803E188C[i].unk10, + MTXDegToRad(yakumono_param->unk98), + &grKg_803E188C[i].unk10); + } } - deltas = sp8; + { - s32 var_ctr_5 = 3; - _struct_grKg_803E188C_0x18* var_r3_5 = grKg_803E188C; - do { - int i; - for (i = 0; i < 5; i++) { - var_r3_5->unkC += var_r3_5->unk10; - rad_compare(var_r3_5->unkC, yakumono_param->unk90, - &var_r3_5->unkC); - var_r3_5++; - } - var_ctr_5 -= 1; - } while (var_ctr_5 != 0); + s32 i; + + for (i = 0; i < 15; i++) { + grKg_803E188C[i].unkC += grKg_803E188C[i].unk10; + Ground_ClampSymmetric(grKg_803E188C[i].unkC, + MTXDegToRad(yakumono_param->unk90), + &grKg_803E188C[i].unkC); + } } + { - s32 var_ctr_6 = 3; - f32* delta_init = deltas; - do { - delta_init[0] = 0.0f; - delta_init[1] = 0.0f; - delta_init[2] = 0.0f; - delta_init[3] = 0.0f; - delta_init[4] = 0.0f; - delta_init += 5; - var_ctr_6 -= 1; - } while (var_ctr_6 != 0); + f32* p = sp8; + s32 i; + + for (i = 15; i > 0; i--) { + *p++ = 0.0f; + } } + { - s32 var_ctr_7 = 0xF; - _struct_grKg_803E188C_0x18* entry = grKg_803E188C; - f32* delta_ptr = deltas; - s32 i = 0; - do { - if (entry->unk2 == 0) { - if ((i != 0) && (entry[-1].unk2 == 0)) { - { - volatile f32 stiffness = yakumono_param->unkA0; - rad_compare_c(entry[-1].unkC - entry->unkC, - yakumono_param->unk9C, stiffness, - delta_ptr); + s32 i; + + for (i = 0; i < 15; i++) { + if (grKg_803E188C[i].unk2 == 0) { + if (i != 0 && grKg_803E188C[i - 1].unk2 == 0) { + f32 input = + grKg_803E188C[i - 1].unkC - grKg_803E188C[i].unkC; + f32 limit = MTXDegToRad(yakumono_param->unk9C); + + if (input > limit) { + sp8[i] += yakumono_param->unkA0 * (input - limit); + } else if (input < -limit) { + sp8[i] += yakumono_param->unkA0 * (input + limit); } } - if (((u32) i != 0xEU) && (entry[1].unk2 == 0)) { - { - volatile f32 stiffness = yakumono_param->unkA0; - rad_compare_c(entry[1].unkC - entry->unkC, - yakumono_param->unk9C, stiffness, - delta_ptr); + if ((u32) i != 14 && grKg_803E188C[i + 1].unk2 == 0) { + f32 input = + grKg_803E188C[i + 1].unkC - grKg_803E188C[i].unkC; + f32 limit = MTXDegToRad(yakumono_param->unk9C); + + if (input > limit) { + sp8[i] += yakumono_param->unkA0 * (input - limit); + } else if (input < -limit) { + sp8[i] += yakumono_param->unkA0 * (input + limit); } } } - entry += 1; - delta_ptr += 1; - i += 1; - var_ctr_7 -= 1; - } while (var_ctr_7 != 0); + } + } + + { + s32 i; + + for (i = 0; i < 15; i++) { + if (sp8[i] != 0.0) { + grKg_803E188C[i].unkC += sp8[i]; + } + } } - grKongo_801D6AFC_apply(deltas, entries); } #if 0 @@ -1040,8 +988,27 @@ extern ? grKg_804D6984; static ? grKg_803B7FB0; /* unable to generate initializer: unknown type; const */ #endif +static inline f32 grKongo_calc_angle(s32 index) +{ + f32 angle = (f32) (0.7853981633974483 * + (0.5 * (f64) (((grKg_803E188C[index].unk14 - + grKg_803E188C[index - 1].unk14) / + 6.0f) + + ((grKg_803E188C[index + 1].unk14 - + grKg_803E188C[index].unk14) / + 6.0f)))); + + if (angle > MTXDegToRad(yakumono_param->unkAC)) { + angle = MTXDegToRad(yakumono_param->unkAC); + } else if (angle < -MTXDegToRad(yakumono_param->unkAC)) { + angle = -MTXDegToRad(yakumono_param->unkAC); + } + return angle; +} + void grKongo_801D7134(HSD_GObj* gobj, s32 arg1) { + u32 i; s32 line_id; Ground* gp; _struct_grKg_803E188C_0x18* table; @@ -1051,31 +1018,21 @@ void grKongo_801D7134(HSD_GObj* gobj, s32 arg1) f32 old_angle; f32 temp; f32 displacement; - u32 i; - PAD_STACK(0x18); + PAD_STACK(0x10); gp = gobj->user_data; grKongo_801D6AFC(); - for (i = 0U; i < 15U; i++) { - grKg_803E188C[i].unk14 = (f32) (37.8 * tanf(-grKg_803E188C[i].unkC)); + for (arg1 = 0; (u32) arg1 < 15U; arg1++) { + grKg_803E188C[arg1].unk14 = + (f32) (37.8 * tanf(-grKg_803E188C[arg1].unkC)); } displacement = grKg_803E188C[2].unkC * (MTXDegToRad(yakumono_param->unkA8) / MTXDegToRad(yakumono_param->unk90) - 1.0f); - angle = (f32) (0.7853981633974483 * - (0.5 * - (f64) (((grKg_803E188C[2].unk14 - grKg_803E188C[1].unk14) / - 6.0f) + - ((grKg_803E188C[3].unk14 - grKg_803E188C[2].unk14) / - 6.0f)))); - if (angle > MTXDegToRad(yakumono_param->unkAC)) { - angle = MTXDegToRad(yakumono_param->unkAC); - } else if (angle < -MTXDegToRad(yakumono_param->unkAC)) { - angle = -MTXDegToRad(yakumono_param->unkAC); - } + angle = grKongo_calc_angle(2); HSD_JObjSetRotationX(grKg_804D6984.unk0, displacement); old_angle = HSD_JObjGetRotationZ(grKg_804D6984.unk0); HSD_JObjSetRotationZ(grKg_804D6984.unk0, angle); @@ -1087,18 +1044,7 @@ void grKongo_801D7134(HSD_GObj* gobj, s32 arg1) grKg_803E188C[12].unkC * ((MTXDegToRad(yakumono_param->unkA8) / MTXDegToRad(yakumono_param->unk90)) - 1.0f); - angle = - (f32) (0.7853981633974483 * - (0.5 * - (f64) (((grKg_803E188C[12].unk14 - grKg_803E188C[11].unk14) / - 6.0f) + - ((grKg_803E188C[13].unk14 - grKg_803E188C[12].unk14) / - 6.0f)))); - if (angle > MTXDegToRad(yakumono_param->unkAC)) { - angle = MTXDegToRad(yakumono_param->unkAC); - } else if (angle < -MTXDegToRad(yakumono_param->unkAC)) { - angle = -MTXDegToRad(yakumono_param->unkAC); - } + angle = grKongo_calc_angle(12); HSD_JObjSetRotationX(grKg_804D6984.unk4, displacement); old_angle = HSD_JObjGetRotationZ(grKg_804D6984.unk4); HSD_JObjSetRotationZ(grKg_804D6984.unk4, angle); @@ -1106,19 +1052,23 @@ void grKongo_801D7134(HSD_GObj* gobj, s32 arg1) gp->u.kongo.xD8 = -(angle - old_angle); } - entry = (_struct_grKg_803E188C_0x18*) ((u8*) grKg_803E16E0 + 0x1AC); - for (i = 0; i < 15; i++) { - HSD_JObjSetRotationX(entry->unk4, entry->unkC); - entry++; + table = grKg_803E188C; + entry = table; + { + u32 index; + + for (index = 0; index < 15; index++) { + HSD_JObjSetRotationX(entry->unk4, entry->unkC); + entry++; + } } mpLib_80057424(4); - entry = (_struct_grKg_803E188C_0x18*) ((u8*) grKg_803E16E0 + 0x1AC); i = 0; line_id = 0x28; do { s32 id; - temp = entry->unk14; + temp = table->unk14; id = line_id; mpLib_80056758(id, 0.0f, temp, 0.0f, temp); if ((s32) i == 0) { @@ -1128,7 +1078,7 @@ void grKongo_801D7134(HSD_GObj* gobj, s32 arg1) } i++; line_id += 2; - entry++; + table++; } while (i < 15); } diff --git a/src/melee/gr/grmaterial.c b/src/melee/gr/grmaterial.c index 283b10835f..df32fcd0ae 100644 --- a/src/melee/gr/grmaterial.c +++ b/src/melee/gr/grmaterial.c @@ -288,70 +288,87 @@ void grMaterial_801C8E74(void) grMaterial_803E0A20.make_texp = hsdMObj.make_texp; } -static inline void grMaterial_SetupOverlayTev(Ground* gp, HSD_MObj* mobj) +static inline void grMaterial_SetTExpReg(HSD_TECnst* cnst) { - u8 pad3[0x1C]; - HSD_TECnst sp_cnst; - u8 pad2[0x54]; - HSD_TevDesc sp_tevdesc; - GXColor sp114; - s32 reg1_lt4_for_kcsel; - s32 temp2; + HSD_TExpSetReg((HSD_TExp*) cnst); +} + +static inline s32 grMaterial_GetFreeColorReg(HSD_TECnst* cnst, HSD_MObj* mobj, + s32 start) +{ + return lbGetFreeColorRegister(start, mobj, (HSD_TExp*) cnst); +} + +static inline GXTevKColorSel grMaterial_GetKColorSel(s32 reg) +{ + return lb_8000CCA4(reg); +} + +static inline void fn_801C8EF8_inline(Ground* gp, HSD_MObj* mobj) +{ + u8 cnst_pad[0x14]; + HSD_TECnst cnst; + u8 tevdesc_pad[0x54]; + HSD_TevDesc tevdesc; + GXColor color; s32 reg2; s32 reg1_lt4; s32 alpha_reg; s32 temp; s32 reg1; - (void) pad2; - (void) pad3; + (void) cnst_pad; + (void) tevdesc_pad; + if (grMaterial_GetOverlay(gp)->x7C_color_enable || gp->x10_flags.b6) { - sp_cnst = grMaterial_803E0A20.texp_tmpl; - sp_tevdesc = grMaterial_803E0A20.tevdesc_tmpl; - sp_tevdesc.stage = HSD_StateAssignTev(); + cnst = grMaterial_803E0A20.texp_tmpl; + tevdesc = grMaterial_803E0A20.tevdesc_tmpl; + tevdesc.stage = HSD_StateAssignTev(); if (grMaterial_GetOverlay(gp)->x7C_color_enable) { + s32 reg1_lt4_for_kcsel; + reg1 = lbGetFreeColorRegister(0, mobj, NULL); if (reg1 == -1) { OSReport("can't find free color register!\n"); HSD_ASSERT(0x7A, 0); } - sp_cnst.comp = reg1_lt4 = 1; - sp_cnst.ctype = temp = 0; - sp_cnst.reg = (u8) reg1; - sp_cnst.val = &gp->x6C; - HSD_TExpSetReg((HSD_TExp*) &sp_cnst); + cnst.comp = reg1_lt4 = 1; + cnst.ctype = temp = 0; + cnst.reg = (u8) reg1; + cnst.val = &gp->x6C; + grMaterial_SetTExpReg(&cnst); if (reg1 < 4) { !reg1; } else { - reg1_lt4 = 0; + reg1_lt4 = temp; } if (reg1_lt4 != 0) { temp = 4; } else { temp = 0; } - reg2 = lbGetFreeColorRegister(temp, mobj, (HSD_TExp*) &sp_cnst); + reg2 = grMaterial_GetFreeColorReg(&cnst, mobj, temp); if (reg2 == -1) { OSReport("can't find free color register!\n"); HSD_ASSERT(0x88, 0); } - sp_cnst.comp = reg1_lt4_for_kcsel = 1; - sp_cnst.ctype = temp2 = 0; - sp_cnst.reg = (u8) reg2; - sp114.r = gp->x6C.a; - sp114.g = gp->x6C.a; - sp114.b = gp->x6C.a; - sp_cnst.val = &sp114; - HSD_TExpSetReg((HSD_TExp*) &sp_cnst); - sp_tevdesc.u.tevconf.clr_b = lb_8000CC8C(reg1); - sp_tevdesc.u.tevconf.clr_c = lb_8000CC8C(reg2); + cnst.comp = temp = 1; + cnst.ctype = reg1_lt4_for_kcsel = 0; + cnst.reg = (u8) reg2; + color.r = gp->x6C.a; + color.g = gp->x6C.a; + color.b = gp->x6C.a; + cnst.val = &color; + grMaterial_SetTExpReg(&cnst); + tevdesc.u.tevconf.clr_b = lb_8000CC8C(reg1); + tevdesc.u.tevconf.clr_c = lb_8000CC8C(reg2); if (reg1 < 4) { !reg1; } else { - reg1_lt4_for_kcsel = 0; + temp = reg1_lt4_for_kcsel; } - if (reg1_lt4_for_kcsel != 0) { - sp_tevdesc.u.tevconf.kcsel = lb_8000CCA4(reg1); + if (temp != 0) { + tevdesc.u.tevconf.kcsel = grMaterial_GetKColorSel(reg1); } else { if (reg2 < 4) { temp = 1; @@ -359,7 +376,7 @@ static inline void grMaterial_SetupOverlayTev(Ground* gp, HSD_MObj* mobj) temp = 0; } if (temp != 0) { - sp_tevdesc.u.tevconf.kcsel = lb_8000CCA4(reg2); + tevdesc.u.tevconf.kcsel = lb_8000CCA4(reg2); } } } @@ -369,16 +386,16 @@ static inline void grMaterial_SetupOverlayTev(Ground* gp, HSD_MObj* mobj) OSReport("can't find free alpha register!\n"); HSD_ASSERT(0xA7, 0); } - sp_cnst.comp = 5; - sp_cnst.ctype = 3; - sp_cnst.reg = (u8) alpha_reg; - sp_cnst.val = &gp->xC0; - HSD_TExpSetReg((HSD_TExp*) &sp_cnst); - sp_tevdesc.u.tevconf.alpha_b = GX_CA_APREV; - sp_tevdesc.u.tevconf.alpha_c = lb_8000CD90(alpha_reg); - sp_tevdesc.u.tevconf.alpha_d = GX_CA_ZERO; + cnst.comp = 5; + cnst.ctype = 3; + cnst.reg = (u8) alpha_reg; + cnst.val = &gp->xC0; + grMaterial_SetTExpReg(&cnst); + tevdesc.u.tevconf.alpha_b = GX_CA_APREV; + tevdesc.u.tevconf.alpha_c = lb_8000CD90(alpha_reg); + tevdesc.u.tevconf.alpha_d = GX_CA_ZERO; } - HSD_SetupTevStage(&sp_tevdesc); + HSD_SetupTevStage(&tevdesc); } } @@ -418,8 +435,7 @@ static void fn_801C8EF8(HSD_MObj* mobj, u32 rendermode) HSD_TObjSetupVolatileTev(tobj, mobj_rendermode); gp = HSD_GObj_804D7814->user_data; - (void) gp; - grMaterial_SetupOverlayTev(gp, mobj); + fn_801C8EF8_inline(gp, mobj); HSD_SetupRenderModeWithCustomPE(mobj_rendermode, mobj->pe); if (cur_tobj != NULL) { *cur_tobj = NULL; diff --git a/src/melee/gr/grmutecity.c b/src/melee/gr/grmutecity.c index 409f0ba802..ea9810d13a 100644 --- a/src/melee/gr/grmutecity.c +++ b/src/melee/gr/grmutecity.c @@ -1455,11 +1455,6 @@ UNK_T grMc_803E3C6C[] = { grMuteCity_801F19C4, grMuteCity_801F19DC, grMuteCity_801F19F4, }; -static inline HSD_JObj* grMc_GetRightSplineJoint(Ground* gp) -{ - return gp->u.mutecity.xE0; -} - static inline f32 grMc_GetTrackMidpoint(Ground* gp) { return 0.5f * (gp->u.mutecity.xD4 + gp->u.mutecity.xD8); @@ -1505,7 +1500,6 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) Ground* gp; HSD_JObj* car_jobj; HSD_JObj* jobj; - HSD_JObj* child_jobj; s32 car_idx; s32 sound_count; f32 spline_t; @@ -1618,7 +1612,7 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) spA8 = sp44; block_28_done: lb_8000B1CC(gp->u.mutecity.xE0, &spA8, &spA8); - lb_8000B1CC(grMc_GetRightSplineJoint(gp), NULL, &spD8); + lb_8000B1CC(gp->u.mutecity.xE0, NULL, &spD8); lbVector_Sub(&spA8, &spD8); lbVector_Normalize(&spA8); @@ -1709,12 +1703,9 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) if (age > yakumono_param->x30) { if (!grMc_8049F4B8[car_idx].x22_flags.b0) { grLib_801C98A0(jobj); - grMc_8049F4B8[car_idx].x28 = (s32) (child_jobj = NULL); + grMc_8049F4B8[car_idx].x28 = 0; grLib_801C96F8(0xE3, 0, &car_pos); - if (jobj != NULL) { - child_jobj = jobj->child; - } - HSD_JObjUnref(child_jobj); + HSD_JObjUnref(HSD_JObjGetChild(jobj)); { HSD_JObj* new_jobj = Ground_801C13D0(5, 0); if (new_jobj != NULL) { diff --git a/src/melee/gr/grzebes.c b/src/melee/gr/grzebes.c index ad24f6ad9b..ca078f8865 100644 --- a/src/melee/gr/grzebes.c +++ b/src/melee/gr/grzebes.c @@ -950,8 +950,9 @@ void grZebes_801D99E0(HSD_GObj* gobj) f32 accel; f32 vel; f32 t; + f32 target_level; f32 delta; - f32 abs_delta; + f64 abs_delta; f32 threshold; gp->u.zebes5.xC6 = (s16) (gp->u.zebes5.xC6 + 1); @@ -967,12 +968,15 @@ void grZebes_801D99E0(HSD_GObj* gobj) } threshold = (f32) ((f64) (vel * t) - (0.5 * (f64) accel * (f64) (t * t))); - delta = gp->u.zebes5.xD4; - delta -= gp->u.zebes5.xD8; + target_level = gp->u.zebes5.xD4; + delta = target_level - gp->u.zebes5.xD8; - abs_delta = ABS(delta); + abs_delta = delta; + target_level = 0.0f; - if (abs_delta < threshold || ABS(delta) < accel) { + if ((delta < 0 ? -abs_delta : abs_delta) < threshold || + (abs_delta < target_level ? -abs_delta : abs_delta) < accel) + { gp->u.zebes5.xC8 = 4; } else { gp->u.zebes5.xD0 += accel; @@ -1730,22 +1734,26 @@ static inline f32 grZebes_801DB3CC_half_radius(grZe_YakumonoParam* yp) return yp->x74 * 0.5f; } -static inline f32 grZebes_801DB3CC_update_y(grZe_BubbleEntry** base, f32 old_y) -{ - return old_y + (*base)->x14; -} - static inline void grZebes_801DB3CC_update(grZe_BubbleEntry** base) { int k; - f32 left_anchor_x = grZe_8049F158[0].x; - f32 left_anchor_y = grZe_8049F158[0].y; - f32 left_bound_x = grZe_8049F140[0].x; - f32 left_bound_y = grZe_8049F140[0].y; - f32 right_anchor_y = grZe_8049F158[1].y; - f32 right_anchor_x = grZe_8049F158[1].x; - f32 right_bound_y = grZe_8049F140[1].y; - f32 right_bound_x = grZe_8049F140[1].x; + f32 right_bound_x; + f32 right_bound_y; + f32 left_bound_x; + f32 left_bound_y; + f32 right_anchor_y; + f32 right_anchor_x; + f32 left_anchor_y; + f32 left_anchor_x; + + left_anchor_x = grZe_8049F158[0].x; + left_anchor_y = grZe_8049F158[0].y; + right_anchor_x = grZe_8049F158[1].x; + right_anchor_y = grZe_8049F158[1].y; + left_bound_y = grZe_8049F140[0].y; + left_bound_x = grZe_8049F140[0].x; + right_bound_y = grZe_8049F140[1].y; + right_bound_x = grZe_8049F140[1].x; (void) 0.0; for (k = 0; k < 20; (*base)++, k++) { @@ -1761,10 +1769,11 @@ static inline void grZebes_801DB3CC_update(grZe_BubbleEntry** base) (*base)->x08_x = right_anchor_x; (*base)->x0C_y = right_anchor_y; } else { - f32 old_y = (*base)->x0C_y; + f32 current_y = (*base)->x0C_y; + f32 old_y = current_y; f32 current_x = (*base)->x08_x; f32 old_x = current_x; - f32 new_y = grZebes_801DB3CC_update_y(base, old_y); + f32 new_y = old_y + (*base)->x14; f32 new_x = old_x + (*base)->x10; if (new_y < left_bound_y && new_x < left_bound_x) { if (old_y >= left_bound_y) { @@ -1901,9 +1910,9 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) } { - grZe_BubbleEntry* ea = base; int a; - for (a = 0; a < 19; a++, ea++) { + for (a = 0; a < 19; a++) { + grZe_BubbleEntry* ea = &base[a]; if (ea->x00_active != 0) { int b = a + 1; grZe_BubbleEntry* eb = &grZe_8049F170[b]; @@ -1915,57 +1924,60 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) { grZe_YakumonoParam* yp = yakumono_param; f32 effective_dist = dist; + f32 col_rad = grZebes_801DB3CC_half_radius(yp); f32 avg_size = ea->x18_size + eb->x18_size; - f32 col_rad = - grZebes_801DB3CC_half_radius(yp) * avg_size; - f32 near_rad = yp->x70 * 0.5f * avg_size; - f32 far_rad = yp->x6C * 0.5f * avg_size; - if (dist < 0.001) { - dy = 0.001; - dx = 0.0f; - effective_dist = 0.001; - } - if (effective_dist < col_rad) { - f32 strength = - (f32) (((f64) (col_rad / effective_dist) - - 1.0) * - 0.5); - strength = (f32) ((f64) strength * 0.9); - if (a >= 7) { - f32 vx = -dx * strength; - f32 vy = -dy * strength; - f32 clamp_vy = vy; - if (vy < 0.0f) { - clamp_vy = 0.0f; - } - ea->x10 += vx; - ea->x14 += clamp_vy; - } - if (b >= 7) { - f32 vx2 = - grZebes_801DB3CC_scale(strength, dx); - f32 vy2 = dy * strength; - if (vy2 < 0.0f) { - vy2 = 0.0f; - } - eb->x10 += vx2; - eb->x14 += vy2; - } - } else if (!(effective_dist < near_rad) && - effective_dist < far_rad) + col_rad *= avg_size; { - f32 attract = yp->x78 / effective_dist; - if (a >= 7) { - f32 vx = dx * attract; - f32 vy = dy * attract; - ea->x10 += vx; - ea->x14 += vy; + f32 near_rad = yp->x70 * 0.5f * avg_size; + f32 far_rad = yp->x6C * 0.5f * avg_size; + if (dist < 0.001) { + dy = 0.001; + dx = 0.0f; + effective_dist = 0.001; } - if (b >= 7) { - f32 vx2 = -dx * attract; - f32 vy2 = -dy * attract; - eb->x10 += vx2; - eb->x14 += vy2; + if (effective_dist < col_rad) { + f32 strength = + (f32) (((f64) (col_rad / + effective_dist) - + 1.0) * + 0.5); + strength = (f32) ((f64) strength * 0.9); + if (a >= 7) { + f32 vx = -dx * strength; + f32 vy = -dy * strength; + f32 clamp_vy = vy; + if (vy < 0.0f) { + clamp_vy = 0.0f; + } + ea->x10 += vx; + ea->x14 += clamp_vy; + } + if (b >= 7) { + f32 vx2 = grZebes_801DB3CC_scale( + strength, dx); + f32 vy2 = dy * strength; + if (vy2 < 0.0f) { + vy2 = 0.0f; + } + eb->x10 += vx2; + eb->x14 += vy2; + } + } else if (!(effective_dist < near_rad) && + effective_dist < far_rad) + { + f32 attract = yp->x78 / effective_dist; + if (a >= 7) { + f32 vx = dx * attract; + f32 vy = dy * attract; + ea->x10 += vx; + ea->x14 += vy; + } + if (b >= 7) { + f32 vx2 = -dx * attract; + f32 vy2 = -dy * attract; + eb->x10 += vx2; + eb->x14 += vy2; + } } } } @@ -2042,6 +2054,11 @@ bool grZebes_801DBB60(Item_GObj* yaku) f32 ei_x; f32 ei_size; f32 ei_y; + f32 ej_y; + f32 ej_x; + f32 dx; + f32 dy; + f32 dist_sq; grZe_BubbleEntry* ej = &grZe_8049F170[j]; ei_y = ei->x0C_y; @@ -2049,22 +2066,20 @@ bool grZebes_801DBB60(Item_GObj* yaku) ei_size = ei->x18_size; for (; j < 20; ej++, j++) { if (ej->x00_active == 1 && j != 0 && j != 6) { - f32 ej_x = ej->x08_x; - f32 ej_y = ej->x0C_y; - f32 dx = grZebes_Subtract(ei_x, ej_x); - f32 dy = ei_y - ej_y; - f32 dist_sq; + ej_y = ej->x0C_y; + ej_x = ej->x08_x; + dx = grZebes_Subtract(ei_x, ej_x); + dy = ei_y - ej_y; dx *= dx; dy *= dy; - dist_sq = dx + dy; + dist_sq = dy + dx; if (max_dist_sq < dist_sq) { - f32 ej_size = ej->x18_size; max_dist_sq = dist_sq; x1 = ei_x; y1 = ei_y; x2 = ej_x; y2 = ej_y; - if (ei_size > ej_size) { + if (ei_size > ej->x18_size) { last_idx = i; } else { last_idx = j; @@ -2105,17 +2120,17 @@ bool grZebes_801DBB60(Item_GObj* yaku) if (t < 0.0f) { bx = dpy * dpy + dpx * dpx; } else if (t > 1.0f) { - f32 ex = bx - x2; - f32 ey = grZebes_Subtract(by, y2); - f32 ex_sq = ex * ex; - f32 ey_sq = ey * ey; - bx = ex_sq + ey_sq; + dpx = bx - x2; + dpy = grZebes_Subtract(by, y2); + dpx *= dpx; + dpy *= dpy; + bx = dpx + dpy; } else { - f32 cx = (dx * t + x1) - bx; - f32 cy = (dy * t + y1) - by; - f32 cx_sq = cx * cx; - f32 cy_sq = cy * cy; - bx = cx_sq + cy_sq; + dpx = (dx * t + x1) - bx; + dpy = (dy * t + y1) - by; + dpx *= dpx; + dpy *= dpy; + bx = dpx + dpy; } bx = sqrtf(bx); diff --git a/src/melee/if/ifstatus.c b/src/melee/if/ifstatus.c index 611a33d17f..ead732e793 100644 --- a/src/melee/if/ifstatus.c +++ b/src/melee/if/ifstatus.c @@ -205,6 +205,84 @@ void ifStatus_802F4B84(IfDamageState* state, s32 is_stamina) PAD_STACK(8); } +inline void ifStatus_SetDamageDigit(HSD_JObj* digit_jobj, + HSD_MatAnimJoint** anim_base, u8 digit) +{ + HSD_TObjAddAnimAll(digit_jobj->u.dobj->mobj->tobj, + (HSD_TexAnim*) ((HSD_AnimJoint*) anim_base[0]) + ->child->child->aobjdesc->fobjdesc); + HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); + HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); +} + +inline void ifStatus_InitDamageDigits(IfDamageState* state, + HSD_MatAnimJoint** anim_base) +{ + HSD_JObj* digit_jobj; + u8 digit; + + digit_jobj = state->jobjs[Ones]; + digit = state->damage_percent % 10; + ifStatus_SetDamageDigit(digit_jobj, anim_base, digit); + + digit_jobj = state->jobjs[Tens]; + digit = (state->damage_percent % 100) / 10; + ifStatus_SetDamageDigit(digit_jobj, anim_base, digit); + + digit_jobj = state->jobjs[Hundreds]; + digit = (state->damage_percent % 1000) / 100; + ifStatus_SetDamageDigit(digit_jobj, anim_base, digit); +} + +inline void ifStatus_ApplyDamageColor(IfDamageState* state, GXColor* color) +{ + HSD_MObj* mobj; + + mobj = state->jobjs[Hundreds]->u.dobj->mobj; + mobj->mat->diffuse.r = color->r; + mobj->mat->diffuse.g = color->g; + mobj->mat->diffuse.b = color->b; + + mobj = state->jobjs[Tens]->u.dobj->mobj; + mobj->mat->diffuse.r = color->r; + mobj->mat->diffuse.g = color->g; + mobj->mat->diffuse.b = color->b; + + mobj = state->jobjs[Ones]->u.dobj->mobj; + mobj->mat->diffuse.r = color->r; + mobj->mat->diffuse.g = color->g; + mobj->mat->diffuse.b = color->b; + + mobj = state->jobjs[Percent]->u.dobj->mobj; + mobj->mat->diffuse.r = color->r; + mobj->mat->diffuse.g = color->g; + mobj->mat->diffuse.b = color->b; +} + +inline void ifStatus_StoreDamageTranslations(IfDamageState* state, + HSD_JObj* jobj) +{ + HSD_JObj* digit_jobj; + s32 i; + + if (lb_8000B09C(jobj)) { + for (i = 0; i < 4; i++) { + digit_jobj = state->jobjs[i]; + ASSERT_NOT_NULL(digit_jobj, 993); + state->translation_x[i] = digit_jobj->translate.x; + + digit_jobj = state->jobjs[i]; + ASSERT_NOT_NULL(digit_jobj, 1006); + state->translation_y[i] = digit_jobj->translate.y; + } + } +} + +inline f32 ifStatus_GetStoredTranslationX(IfDamageState* state, s32 index) +{ + return state->translation_x[index]; +} + void ifStatus_802F4EDC(HSD_GObj* gobj) { HudIndex* hud; @@ -214,7 +292,6 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) s32 is_stamina; GXColor color; HSD_TObj* tobj; - HSD_MObj* mobj; HSD_MatAnimJoint** anim_base; s32 i; u8 digit; @@ -227,7 +304,7 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) f32 factor; IfDamageState* ptr; - PAD_STACK(64); + PAD_STACK(0x10); hud = ifStatus_GetHUDInfo(); { @@ -283,30 +360,7 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) } mn_8022F3D8(jobj, 1, 0x400); - - digit_jobj = state->jobjs[Ones]; - digit = state->damage_percent % 10; - HSD_TObjAddAnimAll(digit_jobj->u.dobj->mobj->tobj, - (HSD_TexAnim*) ((HSD_AnimJoint*) anim_base[0]) - ->child->child->aobjdesc->fobjdesc); - HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); - HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); - - digit_jobj = state->jobjs[Tens]; - digit = (state->damage_percent % 100) / 10; - HSD_TObjAddAnimAll(digit_jobj->u.dobj->mobj->tobj, - (HSD_TexAnim*) ((HSD_AnimJoint*) anim_base[0]) - ->child->child->aobjdesc->fobjdesc); - HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); - HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); - - digit_jobj = state->jobjs[Hundreds]; - digit = (state->damage_percent % 1000) / 100; - HSD_TObjAddAnimAll(digit_jobj->u.dobj->mobj->tobj, - (HSD_TexAnim*) ((HSD_AnimJoint*) anim_base[0]) - ->child->child->aobjdesc->fobjdesc); - HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); - HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); + ifStatus_InitDamageDigits(state, anim_base); } HSD_JObjAnimAll(jobj); @@ -360,8 +414,7 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) GXColor stamina_color; /* Stamina mode: 0-100% range */ - clamped_damage = state->damage_percent; - if (clamped_damage > 100) { + if ((clamped_damage = state->damage_percent) > 100) { clamped_damage = 100; } else if (clamped_damage < 0) { clamped_damage = 0; @@ -370,6 +423,7 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) stamina_color.r = (s8) (factor * (f32) (ifStatus_804D57AC[0] - ifStatus_804D57A8[0]) + (f32) ifStatus_804D57A8[0]); + PAD_STACK(4); stamina_color.g = (s8) (factor * (f32) (ifStatus_804D57AC[1] - ifStatus_804D57A8[1]) + (f32) ifStatus_804D57A8[1]); @@ -392,6 +446,7 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) normal_color.r = (s8) (factor * (f32) (ifStatus_804D57AC[0] - ifStatus_804D57A8[0]) + (f32) ifStatus_804D57A8[0]); + PAD_STACK(0x28); normal_color.g = (s8) (factor * (f32) (ifStatus_804D57AC[1] - ifStatus_804D57A8[1]) + (f32) ifStatus_804D57A8[1]); @@ -402,44 +457,11 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) color = normal_color; } - /* Apply color to all digit materials */ - mobj = state->jobjs[Hundreds]->u.dobj->mobj; - mobj->mat->diffuse.r = color.r; - mobj->mat->diffuse.g = color.g; - mobj->mat->diffuse.b = color.b; - - mobj = state->jobjs[Tens]->u.dobj->mobj; - mobj->mat->diffuse.r = color.r; - mobj->mat->diffuse.g = color.g; - mobj->mat->diffuse.b = color.b; - - mobj = state->jobjs[Ones]->u.dobj->mobj; - mobj->mat->diffuse.r = color.r; - mobj->mat->diffuse.g = color.g; - mobj->mat->diffuse.b = color.b; - - mobj = state->jobjs[Percent]->u.dobj->mobj; - mobj->mat->diffuse.r = color.r; - mobj->mat->diffuse.g = color.g; - mobj->mat->diffuse.b = color.b; + ifStatus_ApplyDamageColor(state, &color); } /* Update JObj positions when animating */ - if (lb_8000B09C(jobj)) { - for (i = 0; i < 4; i++) { - digit_jobj = state->jobjs[i]; - if (digit_jobj == NULL) { - __assert("jobj.h", 993, "jobj"); - } - state->translation_x[i] = digit_jobj->translate.x; - - digit_jobj = state->jobjs[i]; - if (digit_jobj == NULL) { - __assert("jobj.h", 1006, "jobj"); - } - state->translation_y[i] = digit_jobj->translate.y; - } - } + ifStatus_StoreDamageTranslations(state, jobj); /* Calculate digit spacing offsets based on which digit is "1" */ ones_offset = (state->damage_percent % 10 == 1) ? 0.5069F : 0.0F; @@ -468,9 +490,9 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) /* Position hundreds digit */ hundreds_offset = ((state->damage_percent % 1000) / 100 == 1) ? 0.5069F : 0.0F; + digit_offset += tens_offset + hundreds_offset; digit_jobj = state->jobjs[Hundreds]; - pos = state->translation_x[Hundreds] + - (hundreds_offset + tens_offset + digit_offset); + pos = ifStatus_GetStoredTranslationX(state, Hundreds) + digit_offset; if (digit_jobj == NULL) { __assert("jobj.h", 932, "jobj"); } @@ -616,20 +638,30 @@ void ifStatus_802F5E50(HSD_GObj* gobj, s32 arg1) } } +static inline HSD_JObj* ifStatus_GetDamageJObj(HSD_JObj* arg0, s32 i) +{ + HSD_GObj* node = (HSD_GObj*) arg0; + return (HSD_JObj*) ifStatus_802F6194(node, i); +} + +static inline HSD_JObj* ifStatus_LoadDamageJObj(HudIndex* hud) +{ + return HSD_JObjLoadJoint(hud->unk258); +} + HSD_GObj* ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) { HSD_GObj* gobj; HSD_MatAnimJoint** anim_base; HSD_JObj* jobj; Vec3* vec; - s32 i; HSD_TObj* tobj; - HSD_GObj* node; + s32 i; HudIndex* hud = ifStatus_GetHUDInfo(); if (state->HUD_parent_entity == NULL) { gobj = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint(hud->unk258); + jobj = ifStatus_LoadDamageJObj(hud); HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); GObj_SetupGXLink(gobj, (void (*)(HSD_GObj*, int)) ifStatus_802F5DE0, 0xB, 0); @@ -649,9 +681,8 @@ HSD_GObj* ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) HSD_JObjAnimAll(jobj); vec = ifAll_GetPlayerHUDPosition((u8) player_idx); HSD_JObjSetTranslate(jobj, vec); - node = (HSD_GObj*) jobj; for (i = 0; i < 4; i++) { - state->jobjs[i] = (HSD_JObj*) ifStatus_802F6194(node, i); + state->jobjs[i] = ifStatus_GetDamageJObj(jobj, i); state->translation_x[i] = HSD_JObjGetTranslationX(state->jobjs[i]); state->translation_y[i] = HSD_JObjGetTranslationY(state->jobjs[i]); } @@ -671,7 +702,7 @@ HSD_GObj* ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) ifStatus_802F5B48(state->HUD_parent_entity); state->old_damage = !state->damage_percent; ifStatus_802F4EDC(state->HUD_parent_entity); - PAD_STACK(0x18); + PAD_STACK(0x10); return state->HUD_parent_entity; } @@ -731,17 +762,14 @@ HSD_GObj* ifStatus_802F61FC(IfDamageState* state, s32 player_idx) Vec3* vec; HSD_MObj* mobj; HudIndex* hud = ifStatus_GetHUDInfo(); - u8 slot; GXColor color; - u8 hud_color; - u8 team; u8 idx = player_idx; - PAD_STACK(0x10); + + PAD_STACK(16); ifStatus_GetPlayerCharacter(player_idx, &chara); if (state->next == NULL) { HSD_GObj* gobj; - ifAll_GetArchive(); ifStatus_CreateMarkGObj(&gobj); if (gobj == NULL) { @@ -773,11 +801,9 @@ HSD_GObj* ifStatus_802F61FC(IfDamageState* state, s32 player_idx) vec = ifAll_GetPlayerHUDPosition(idx); HSD_JObjSetTranslate(jobj, vec); HSD_JObjAddTranslationX(jobj, 0.25f); - slot = Player_GetPlayerSlotType(idx); - hud_color = gm_8016B168(); - team = Player_GetTeam(idx); - color = gm_80160968( - gm_80160854(Player_GetPlayerId(idx), team, hud_color, slot)); + color = + gm_80160968(gm_80160854(Player_GetPlayerId(idx), Player_GetTeam(idx), + gm_8016B168(), Player_GetPlayerSlotType(idx))); mobj = HSD_JObjGetChild(jobj)->u.dobj->mobj; mobj->mat->diffuse.r = color.r; mobj->mat->diffuse.g = color.g; diff --git a/src/melee/if/ifstock.c b/src/melee/if/ifstock.c index a5351c8cb2..769d8b8aaf 100644 --- a/src/melee/if/ifstock.c +++ b/src/melee/if/ifstock.c @@ -48,7 +48,6 @@ struct IfStockData { struct IfStockDataOffset { unsigned char x0[0x204]; - struct IfStockData data; }; int ifStock_802F7EFC(int arg0, int arg1) @@ -57,15 +56,17 @@ int ifStock_802F7EFC(int arg0, int arg1) struct ifStock_804A1378* stock; struct IfStockData* arg1_data; struct IfStockData* arg0_data; + struct IfStockDataOffset* arg0_base; + struct IfStockDataOffset* arg1_base; int slot; int i, j; stock = &ifStock_804A1378; - arg0_data = (struct IfStockData*) stock; - arg0_data += arg0; - arg1_data = (struct IfStockData*) stock; - arg1_data += arg1; - arg0_data = &((struct IfStockDataOffset*) arg0_data)->data; - arg1_data = &((struct IfStockDataOffset*) arg1_data)->data; + arg0_base = + (struct IfStockDataOffset*) ((struct IfStockData*) stock + arg0); + arg1_base = + (struct IfStockDataOffset*) ((struct IfStockData*) stock + arg1); + arg0_data = (struct IfStockData*) ++arg0_base; + arg1_data = (struct IfStockData*) ++arg1_base; if (Player_GetStocks(arg1) == 0) { return 1; } @@ -132,14 +133,55 @@ ifStock_802F8298_get_data(struct ifStock_804A1378* stock) return stock->x204; } -static inline void ifStock_802F8298_init(HSD_GObj* gobj, - struct IfStockUserData** user_data, - HSD_JObj** jobj, - struct ifStock_804A1378** stock) +static inline struct IfStockUserData* +ifStock_802F8298_init(HSD_GObj* gobj, HSD_JObj** jobj, + struct ifStock_804A1378** stock) { - *user_data = GET_IFSTOCK(gobj); *jobj = gobj->hsd_obj; *stock = &ifStock_804A1378; + return GET_IFSTOCK(gobj); +} + +static inline int ifStock_802F8298_get_flag(struct IfStockUserData* user_data, + struct ifStock_804A1378* stock) +{ + return stock->x204[user_data->player].x0[2]; +} + +static inline int +ifStock_802F8298_get_player(struct IfStockUserData* user_data) +{ + return user_data->player; +} + +static inline HSD_JObj* +ifStock_802F8298_get_x3C(struct IfStockUserData* user_data, + struct ifStock_804A1378* stock) +{ + return stock->player[user_data->player].x3C; +} + +static inline HSD_JObj* +ifStock_802F8298_get_x40(struct IfStockUserData* user_data, + struct ifStock_804A1378* stock) +{ + return stock->player[user_data->player].x40; +} + +static inline void ifStock_802F8298_init_stocks( + HSD_GObj* gobj, struct ifStock_804A1378** stock, HSD_JObj** jobj, + struct IfStockUserData** user_data, HSD_JObj** jobj_anim) +{ + *user_data = ifStock_802F8298_init(gobj, jobj, stock); + *jobj_anim = *jobj; + (*stock)->player[(*user_data)->player].stocks = + Player_GetStocks((*user_data)->player); + if ((*stock)->player[(*user_data)->player].stocks > 99) { + (*stock)->player[(*user_data)->player].stocks = 99; + } + if ((*stock)->player[(*user_data)->player].stocks < 0) { + (*stock)->player[(*user_data)->player].stocks = 1; + } } void ifStock_802F8298(HSD_GObj* gobj) @@ -148,29 +190,23 @@ void ifStock_802F8298(HSD_GObj* gobj) HSD_JObj* jobj; struct ifStock_804A1378* stock; HSD_JObj* jobj_anim; - Vec3 vecA, vecB, vecC, vecD; - HSD_JObj* jobj2; int i; - ifStock_802F8298_init(gobj, &user_data, &jobj, &stock); - jobj_anim = jobj; - stock->player[user_data->player].stocks = - Player_GetStocks(user_data->player); - if (stock->player[user_data->player].stocks > 99) { - stock->player[user_data->player].stocks = 99; - } - if (stock->player[user_data->player].stocks < 0) { - stock->player[user_data->player].stocks = 1; - } + HSD_JObj* jobj2; + Vec3 vecA, vecB, vecC, vecD; + ifStock_802F8298_init_stocks(gobj, &stock, &jobj, &user_data, &jobj_anim); if (stock->player[user_data->player].stocks <= 5) { HSD_JObjSetFlagsAll(stock->player[user_data->player].x3C, JOBJ_HIDDEN); for (i = 0; i < 5; i++) { jobj2 = stock->player[user_data->player].x4[i + 1]; if (i < stock->player[user_data->player].stocks) { HSD_JObjClearFlagsAll(jobj2, JOBJ_HIDDEN); - if (stock->x204[user_data->player].x0[2] != 0) { - stock->x204[user_data->player].x0[i + 5] = 0; - } else { - stock->x204[user_data->player].x0[i + 5] = 10; + { + unsigned char* data = stock->x204[user_data->player].x0; + if (ifStock_802F8298_get_flag(user_data, stock) != 0) { + data[i + 5] = 0; + } else { + data[i + 5] = 10; + } } } else { if (stock->x204[user_data->player].x0[2] == 0) { @@ -187,18 +223,22 @@ void ifStock_802F8298(HSD_GObj* gobj) vecB.z += vecA.z; efSync_Spawn(0x474, gobj, &vecB); } - if (stock->x204[user_data->player].x0[i + 5] < 10) { - stock->x204[user_data->player].x0[i + 5] += 1; + if (ifStock_802F8298_get_data(stock)[user_data->player] + .x0[i + 5] < 10) + { + ifStock_802F8298_get_data(stock)[user_data->player] + .x0[i + 5] += 1; } } HSD_JObjReqAnimAll(jobj2, stock->x204[user_data->player].x0[i + 5]); - HSD_TObjReqAnimAll(jobj2->u.dobj->mobj->tobj, - gm_80168BF8(user_data->player)); + HSD_TObjReqAnimAll( + jobj2->u.dobj->mobj->tobj, + gm_80168BF8(ifStock_802F8298_get_player(user_data))); HSD_AObjSetRate(jobj2->u.dobj->mobj->tobj->aobj, 0.0f); } } else { - HSD_JObjClearFlagsAll(stock->player[user_data->player].x3C, + HSD_JObjClearFlagsAll(ifStock_802F8298_get_x3C(user_data, stock), JOBJ_HIDDEN); if (stock->player[user_data->player].stocks >= 10) { HSD_JObjReqAnimAll(stock->player[user_data->player].x44, @@ -208,7 +248,7 @@ void ifStock_802F8298(HSD_GObj* gobj) } else { HSD_JObjReqAnimAll(stock->player[user_data->player].x44, stock->player[user_data->player].stocks); - HSD_JObjSetFlagsAll(stock->player[user_data->player].x40, + HSD_JObjSetFlagsAll(ifStock_802F8298_get_x40(user_data, stock), JOBJ_HIDDEN); } for (i = 0; i < 5; i++) { @@ -302,78 +342,73 @@ void ifStock_802F8298(HSD_GObj* gobj) HSD_JObjAnimAll(jobj_anim); } -static inline void ifStock_802F89F8_inline(struct IfStockUserData* user_data, - int count, int coins) +static inline struct IfStockUserData* ifStock_802F89F8_get_data(HSD_GObj* gobj) +{ + struct IfStockUserData* user_data = GET_IFSTOCK(gobj); + + return user_data; +} + +static inline int ifStock_802F89F8_count(int coins) { int i; - int j; - int temp; - int digit; - for (i = 0; i < 5; i++) { - if (i < count) { - int divisor; - divisor = 1; - for (j = 0; j < i; j++) { - divisor *= 10; - } - HSD_JObjClearFlagsAll( - ifStock_804A1378.player[user_data->player].x4[13 - i], - JOBJ_HIDDEN); - temp = count - i - 1; - if (temp == 0) { - digit = coins % 10; - } else { - divisor = 1; - for (j = 0; j < temp; j++) { - divisor *= 10; - } - digit = (coins / divisor) % 10; - } - HSD_JObjReqAnimAll( - ifStock_804A1378.player[user_data->player].x4[13 - i], digit); - } else { - HSD_JObjSetFlagsAll( - ifStock_804A1378.player[user_data->player].x4[13 - i], - JOBJ_HIDDEN); - if (count == 0 && i == 0) { - HSD_JObjReqAnimAll( - ifStock_804A1378.player[user_data->player].x38, 0.0f); - HSD_JObjClearFlagsAll( - ifStock_804A1378.player[user_data->player].x38, - JOBJ_HIDDEN); - } + + for (i = 0; i < 32; i++) { + if (coins == 0) { + return i; + } + coins /= 10; + } + return 0; +} + +static inline int ifStock_802F89F8_divisor(int position) +{ + int i; + int divisor = 1; + + if (position != 0) { + for (i = 0; i < position; i++) { + divisor *= 10; } } + return divisor; +} + +static inline int ifStock_802F89F8_digit(int coins, int position) +{ + int i; + int divisor = 1; + + if (position - 1 == 0) { + coins %= 10; + return coins; + } + for (i = 0; i < position - 1; i++) { + divisor *= 10; + } + return (coins / divisor) % 10; } void ifStock_802F89F8(HSD_GObj* gobj) { - struct IfStockUserData* user_data = GET_IFSTOCK(gobj); - HSD_JObj* jobj = gobj->hsd_obj; + struct IfStockUserData* user_data = ifStock_802F89F8_get_data(gobj); + int i; int player = user_data->player; HSD_JObj* jobj2 = ifStock_804A1378.player[player].x4[1]; + HSD_JObj* jobj = gobj->hsd_obj; int coins; - int i; - int coins2; int count; + int digit; + int divisor; Player_GetCoins(player); - PAD_STACK(32); - coins = Player_GetCoins(user_data->player); - ifStock_804A1378.player[user_data->player].coins = coins; + PAD_STACK(16); + coins = ifStock_804A1378.player[user_data->player].coins = + Player_GetCoins(user_data->player); if ((u32) coins > 99999U) { coins = 99999; } - coins2 = coins; - for (i = 0; i < 32; i++) { - if (coins2 != 0) { - coins2 /= 10; - } else { - goto count_done; - } - } - i = 0; -count_done: - count = i; + count = ifStock_802F89F8_count(coins); if (count > 5) { count = 5; } @@ -381,7 +416,28 @@ void ifStock_802F89F8(HSD_GObj* gobj) HSD_TObjReqAnimAll(jobj2->u.dobj->mobj->tobj, gm_80168BF8(user_data->player)); HSD_AObjSetRate(jobj2->u.dobj->mobj->tobj->aobj, 0.0f); - ifStock_802F89F8_inline(user_data, count, coins); + for (i = 0; i < 5; i++) { + if (i < count) { + divisor = ifStock_802F89F8_divisor(i); + HSD_JObjClearFlagsAll( + ifStock_804A1378.player[user_data->player].x4[13 - i], + JOBJ_HIDDEN); + digit = ifStock_802F89F8_digit(coins, count - i); + HSD_JObjReqAnimAll( + ifStock_804A1378.player[user_data->player].x4[13 - i], digit); + } else { + HSD_JObjSetFlagsAll( + ifStock_804A1378.player[user_data->player].x4[13 - i], + JOBJ_HIDDEN); + if (count == 0 && i == 0) { + HSD_JObjReqAnimAll( + ifStock_804A1378.player[user_data->player].x38, 0.0f); + HSD_JObjClearFlagsAll( + ifStock_804A1378.player[user_data->player].x38, + JOBJ_HIDDEN); + } + } + } HSD_JObjAnimAll(jobj); } @@ -566,41 +622,46 @@ HSD_GObj* ifStock_802F96D0(int a, int b, float x, float y) return gobj; } +static inline HSD_JObj* ifStock_802F98E8_get_x3C(unsigned char player) +{ + return ifStock_804A1378.player[player].x3C; +} + void ifStock_802F98E8(unsigned char player, int b) { struct ifStock_804A1378* stock = &ifStock_804A1378; - HSD_GObj* gobj; + unsigned char* data; HSD_JObj* jobj; - struct ifStock_804A1378_x204* user_data; - struct ifStock_804A1378_per_player* r26; + unsigned char* user_data; int i; - unsigned char* data; + HSD_GObj* gobj; lbl_8046B6A0_t* ae44; - PAD_STACK(16); if (stock->x0 != NULL) { - user_data = &stock->x204[player]; - user_data->x0[0] = player; - user_data->x0[1] = b; - user_data->x0[2] = 1; - r26 = &stock->player[player]; - if (r26->x0 != NULL) { - HSD_GObjPLink_80390228(r26->x0); + user_data = ((struct IfStockData*) stock)[player].x0; + *(user_data += sizeof(struct IfStockDataOffset)) = player; + stock->x204[player].x0[1] = b; + stock->x204[player].x0[2] = 1; + if (stock->player[player].x0 != NULL) { + HSD_GObjPLink_80390228(stock->player[player].x0); } gobj = GObj_Create(14, 15, 0); gobj->user_data = user_data; if (gobj != NULL) { jobj = HSD_JObjLoadJoint((*stock->x0)->joint); if (jobj != NULL) { + DynamicModelDesc* model_desc; + HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); GObj_SetupGXLink(gobj, fn_802F94E0, 11, 0); - gm_8016895C(jobj, *stock->x0, 0); + model_desc = *stock->x0; + gm_8016895C(jobj, model_desc, 0); HSD_JObjReqAnimAll(jobj, 0.0f); HSD_GObj_SetupProc(gobj, fn_802F9410, 17); HSD_JObjSetTranslate(jobj, ifAll_GetPlayerHUDPosition(player)); lb_80011E24(jobj, ifStock_804A1378.player[player].x4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1); - r26->x0 = gobj; + stock->player[player].x0 = gobj; ifStock_804A1378.player[player].coins = Player_GetCoins(player); ifStock_804A1378.player[player].stocks = @@ -608,39 +669,46 @@ void ifStock_802F98E8(unsigned char player, int b) if (ifStock_804A1378.player[player].stocks < 0) { ifStock_804A1378.player[player].stocks = 1; } - data = user_data->x0; + data = user_data; switch ((unsigned char) b) { case 0: HSD_JObjSetFlagsAll(ifStock_804A1378.player[player].x24, JOBJ_HIDDEN); - if (ifStock_804A1378.player[player].stocks <= 5) { - HSD_JObjSetFlagsAll( - ifStock_804A1378.player[player].x3C, JOBJ_HIDDEN); - for (i = 0; i < 7; i++, data++) { - jobj = ifStock_804A1378.player[player].x4[i + 1]; - if (i < ifStock_804A1378.player[player].stocks || - i >= 5) - { - data[5] = 0; - if (i >= 5) { + { + struct ifStock_804A1378_per_player* players = + stock->player; + if (players[player].stocks <= 5) { + HSD_JObjSetFlagsAll( + ifStock_804A1378.player[player].x3C, + JOBJ_HIDDEN); + for (i = 0; i < 7; i++, data++) { + jobj = + ifStock_804A1378.player[player].x4[i + 1]; + if (i < ifStock_804A1378.player[player] + .stocks || + i >= 5) + { + data[5] = 0; + if (i >= 5) { + HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); + } + } else { + data[5] = 10; HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); } - } else { - data[5] = 10; - HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); + HSD_JObjReqAnimAll(jobj, data[5]); + HSD_TObjReqAnimAll(jobj->u.dobj->mobj->tobj, + gm_80168BF8(player)); + HSD_AObjSetRate(jobj->u.dobj->mobj->tobj->aobj, + 0.0f); } - HSD_JObjReqAnimAll(jobj, data[5]); - HSD_TObjReqAnimAll(jobj->u.dobj->mobj->tobj, - gm_80168BF8(player)); - HSD_AObjSetRate(jobj->u.dobj->mobj->tobj->aobj, - 0.0f); } } break; case 1: HSD_JObjSetFlagsAll(ifStock_804A1378.player[player].x24, JOBJ_HIDDEN); - HSD_JObjSetFlagsAll(ifStock_804A1378.player[player].x3C, + HSD_JObjSetFlagsAll(ifStock_802F98E8_get_x3C(player), JOBJ_HIDDEN); for (i = 0; i < 7; i++, data++) { jobj = ifStock_804A1378.player[player].x4[i + 1]; @@ -700,10 +768,12 @@ void ifStock_802F98E8(unsigned char player, int b) ae44 = gm_16AE_GetUnkData_1(); if (ae44->FighterMatchInfo[player].x4_b1) { GXColor c = { 0x08, 0x08, 0x08, 0x80 }; - ifStock_802FB4EC(player, &c); + GXColor* color = &c; + ifStock_802FB4EC(player, color); } else if (ae44->FighterMatchInfo[player].x4_b0) { GXColor c = { 0x3C, 0x3C, 0x46, 0x80 }; - ifStock_802FB4EC(player, &c); + GXColor* color = &c; + ifStock_802FB4EC(player, color); } fn_802F9410(gobj); // inlined } else { @@ -711,6 +781,7 @@ void ifStock_802F98E8(unsigned char player, int b) } } } + PAD_STACK(16); } static inline HSD_GObj* ifStock_802F9F48_inline(int arg) @@ -897,6 +968,55 @@ void fn_802FA8C0(HSD_GObj* arg) } } +static inline void ifStock_802FAEC4_call_802FA5BC(int arg) +{ + ifStock_802FA5BC(arg); +} + +static inline void ifStock_802FAEC4_clear_acc(int count) +{ + int i; + + for (i = 0; i < count; i++) { + ifStock_804A1ACC.x10C[i] = NULL; + } +} + +static inline void ifStock_802FAEC4_clear_1774(int count) +{ + int i; + + for (i = 0; i < count; i++) { + ifStock_804A1774.x10C[i + 1] = NULL; + } +} + +static inline void ifStock_802FAEC4_init_1A8C(HSD_GObj** p) +{ + struct ifStock_804A1378* stock = &ifStock_804A1378; + HSD_GObj* gobj; + HSD_JObj* jobj; + int i; + + for (i = 0; i < 16; i++, p++) { + *p = NULL; + if (gm_8016B1A8()) { + *p = ifStock_802FA118(i); + } + } + if (gm_IsMultimanSmashMode()) { + gobj = GObj_Create(14, 15, 0); + jobj = HSD_JObjLoadJoint(stock->x4->joint); + HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); + GObj_SetupGXLink(gobj, fn_802F9598, 11, 0); + gm_8016895C(jobj, stock->x4, 0); + HSD_JObjReqAnimAll(jobj, 10.0f); + HSD_JObjAnimAll(jobj); + stock->gobj = gobj; + lb_80011E24(jobj, &stock->jobj, 0, 1, 2, 3, 4, 5, -1); + } +} + void fn_802FAC34(HSD_GObj* arg) { int i; @@ -946,69 +1066,48 @@ void fn_802FAC34(HSD_GObj* arg) } } -#ifdef MUST_MATCH -#pragma push -#pragma dont_inline on -#endif void ifStock_802FAEC4(void) { - HSD_GObj* gobj; struct ifStock_804A1378* stock = &ifStock_804A1378; - DynamicModelDesc** sp18; - int i[1]; - int j[1]; - int k[1]; + union { + void* raw; + DynamicModelDesc** typed; + } scene_models; memzero(stock, sizeof(*stock) - sizeof(stock->x204)); memzero(&ifStock_804A1ACC, sizeof(ifStock_804A1ACC)); memzero(&ifStock_804A1A8C, sizeof(ifStock_804A1A8C)); memzero(&ifStock_804A1774, sizeof(ifStock_804A1774)); - lbArchive_LoadSections(*ifAll_GetArchive(), (void**) &sp18, "Stc_scemdls", - 0); - stock->x0 = sp18; - stock->x4 = sp18[1]; - ifStock_804A1ACC.x108 = 0; - ifStock_804A1ACC.x0 = 0; - gobj = GObj_Create(14, 15, 0); - HSD_GObj_SetupProc(gobj, fn_802FAC34, 17); - ifStock_804A1ACC.x108 = (int) gobj; - for (i[0] = 0; i[0] < 130; i[0]++) { - ifStock_804A1ACC.x10C[i[0]] = NULL; + lbArchive_LoadSections(*ifAll_GetArchive(), &scene_models.raw, + "Stc_scemdls", 0); + { + HSD_GObj** proc = (HSD_GObj**) &ifStock_804A1ACC.x108; + HSD_GObj* gobj; + + stock->x0 = scene_models.typed; + stock->x4 = scene_models.typed[1]; + *proc = NULL; + ifStock_804A1ACC.x0 = 0; + gobj = GObj_Create(14, 15, 0); + HSD_GObj_SetupProc(gobj, fn_802FAC34, 17); + *proc = gobj; + ifStock_802FAEC4_clear_acc(130); } if (gm_80169394() == 0) { - ifStock_804A1774.x10C[0] = NULL; + HSD_GObj** proc = &ifStock_804A1774.x10C[0]; + HSD_GObj* gobj; + + *proc = NULL; ifStock_804A1774.x0 = 0; gobj = GObj_Create(14, 15, 0); HSD_GObj_SetupProc(gobj, fn_802FA6C4, 17); - ifStock_804A1774.x10C[0] = gobj; - for (j[0] = 0; j[0] < 130; j[0]++) { - ifStock_804A1774.x10C[j[0] + 1] = NULL; - } + *proc = gobj; + ifStock_802FAEC4_clear_1774(130); } else if (gm_8016A1F8()) { ifStock_804A1774.x108 = -1; - ifStock_802FA5BC(1); // not inlined - } - for (k[0] = 0; k[0] < 16; k[0]++) { - ifStock_804A1A8C[k[0]] = NULL; - if (gm_8016B1A8()) { - ifStock_804A1A8C[k[0]] = ifStock_802FA118(k[0]); - } - } - if (gm_IsMultimanSmashMode()) { - // ifStock_802FA5BC(0); // inlined - HSD_GObj* gobj2 = GObj_Create(14, 15, 0); - HSD_JObj* jobj = HSD_JObjLoadJoint(stock->x4->joint); - HSD_GObjObject_80390A70(gobj2, HSD_GObj_JObjKind, jobj); - GObj_SetupGXLink(gobj2, fn_802F9598, 11, 0); - gm_8016895C(jobj, stock->x4, 0); - HSD_JObjReqAnimAll(jobj, 10.0f); - HSD_JObjAnimAll(jobj); - stock->gobj = gobj2; - lb_80011E24(jobj, &stock->jobj, 0, 1, 2, 3, 4, 5, -1); + ifStock_802FAEC4_call_802FA5BC(1); } + ifStock_802FAEC4_init_1A8C(ifStock_804A1A8C); } -#ifdef MUST_MATCH -#pragma pop -#endif void ifStock_802FB390(void) { diff --git a/src/melee/lb/lbcollision.c b/src/melee/lb/lbcollision.c index 4c5afbef78..9d4d6750b2 100644 --- a/src/melee/lb/lbcollision.c +++ b/src/melee/lb/lbcollision.c @@ -51,23 +51,6 @@ static GXColor lbColl_804D36E8 = { 0xFF, 0xFF, 0xFF, 0x80 }; static GXColor lbColl_804D36EC = { 0x80, 0x80, 0x80, 0x80 }; static GXColor lbColl_804D36F0 = { 0xFF, 0xFF, 0x00, 0x80 }; -/// .sdata2 -float const lbColl_804D79F0 = 1e-5; -float const lbColl_804D79F4 = -1e-5; -float const lbColl_804D79F8 = 0; -f64 const lbColl_804D7A00 = 1; -float const lbColl_804D7A08 = 1; -f64 const lbColl_804D7A10 = 0; -f64 const lbColl_804D7A18 = 0.5; -f64 const lbColl_804D7A20 = 3.0; -float const lbColl_804D7A28 = 2; -float const lbColl_804D7A2C = 4; -float const lbColl_804D7A30 = M_PI; -float const lbColl_804D7A34 = 20; -float const lbColl_804D7A38 = 3; -float const lbColl_804D7A3C = 0.5; -float const lbColl_804D7A40 = 5; - /// .data int lbColl_803B9880[] = { 0x00083D60, 0x00083D60, 0x00083D60, 0x0000005B, 0x0000005A, 0x00000059, @@ -91,13 +74,161 @@ struct unk { &lbColl_804D36B8, &lbColl_804D36BC, &lbColl_804D36C0, }; -u8 lbColl_803B9940[0x1A0] = { 0 }; -u8 lbColl_803B9AE0[0x1A0] = { 0 }; -u8 lbColl_803B9C80[0x120] = { 0 }; -u8 lbl_803B9DA0[0x80] = { 0 }; -u8 lbl_803B9E20[0xA0] = { 0 }; -u8 lbColl_803B9EC0[0x60] = { 0 }; -u8 lbColl_803B9F20[0xA0] = { 0 }; +u8 lbColl_SpherePositions[0x1A0] = { + 0x29, 0xCF, 0x2D, 0x41, 0x11, 0x51, 0x20, 0x00, 0x2D, 0x41, 0x1F, 0xFF, + 0x29, 0xCF, 0xE7, 0x83, 0x29, 0xCF, 0x00, 0x00, 0xC4, 0xE0, 0x18, 0x7D, + 0x11, 0x51, 0x3B, 0x20, 0x11, 0x51, 0x11, 0x51, 0xD2, 0xBF, 0x29, 0xCF, + 0x00, 0x00, 0xD2, 0xBF, 0x2D, 0x41, 0x16, 0xA0, 0x18, 0x7D, 0x36, 0xA0, + 0x00, 0x00, 0x18, 0x7D, 0x3B, 0x20, 0x09, 0x5F, 0xC4, 0xE0, 0x16, 0xA0, + 0x00, 0x00, 0x3B, 0x20, 0x18, 0x7D, 0x09, 0x5F, 0x3B, 0x20, 0x16, 0xA0, + 0x11, 0x51, 0x2D, 0x41, 0x29, 0xCF, 0x00, 0x00, 0x2D, 0x41, 0x2D, 0x41, + 0x29, 0xCF, 0x18, 0x7D, 0x29, 0xCF, 0x36, 0xA0, 0x18, 0x7D, 0x16, 0xA0, + 0x2D, 0x41, 0x00, 0x00, 0x2D, 0x41, 0x3B, 0x20, 0x00, 0x00, 0x18, 0x7D, + 0x36, 0xA0, 0xE7, 0x83, 0x16, 0xA0, 0x16, 0xA0, 0x3B, 0x20, 0x09, 0x5F, + 0x20, 0x00, 0xD2, 0xBF, 0x1F, 0xFF, 0x29, 0xCF, 0xD2, 0xBF, 0x11, 0x51, + 0x16, 0xA0, 0xC4, 0xE0, 0x09, 0x5F, 0x11, 0x51, 0xC4, 0xE0, 0x11, 0x51, + 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x18, 0x7D, 0x00, 0x00, 0x3B, 0x20, + 0x16, 0xA0, 0xE7, 0x83, 0x36, 0xA0, 0x00, 0x00, 0xE7, 0x83, 0x3B, 0x20, + 0x00, 0x00, 0x3B, 0x20, 0xE7, 0x83, 0x00, 0x00, 0x2D, 0x41, 0xD2, 0xBF, + 0x00, 0x00, 0x18, 0x7D, 0xC4, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, + 0x00, 0x00, 0xE7, 0x83, 0xC4, 0xE0, 0x00, 0x00, 0xD2, 0xBF, 0xD2, 0xBF, + 0x00, 0x00, 0xC4, 0xE0, 0xE7, 0x83, 0x09, 0x5F, 0x3B, 0x20, 0xE9, 0x60, + 0x11, 0x51, 0x2D, 0x41, 0xD6, 0x31, 0x16, 0xA0, 0x18, 0x7D, 0xC9, 0x60, + 0x18, 0x7D, 0x00, 0x00, 0xC4, 0xE0, 0x16, 0xA0, 0xE7, 0x83, 0xC9, 0x60, + 0x11, 0x51, 0xD2, 0xBF, 0xD6, 0x31, 0x09, 0x5F, 0xC4, 0xE0, 0xE9, 0x60, + 0x11, 0x51, 0x3B, 0x20, 0xEE, 0xAF, 0x1F, 0xFF, 0x2D, 0x41, 0xE0, 0x00, + 0x29, 0xCF, 0x18, 0x7D, 0xD6, 0x31, 0x2D, 0x41, 0x00, 0x00, 0xD2, 0xBF, + 0x29, 0xCF, 0xE7, 0x83, 0xD6, 0x31, 0x1F, 0xFF, 0xD2, 0xBF, 0xE0, 0x00, + 0x11, 0x51, 0xC4, 0xE0, 0xEE, 0xAF, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x18, 0x7D, 0x3B, 0x20, 0x00, 0x00, 0x16, 0xA0, 0x3B, 0x20, 0xF6, 0xA1, + 0x2D, 0x41, 0x2D, 0x41, 0x00, 0x00, 0x29, 0xCF, 0x2D, 0x41, 0xEE, 0xAF, + 0x3B, 0x20, 0x18, 0x7D, 0x00, 0x00, 0x36, 0xA0, 0x18, 0x7D, 0xE9, 0x60, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, 0x20, 0x00, 0x00, 0xE7, 0x83, + 0x3B, 0x20, 0xE7, 0x83, 0x00, 0x00, 0x36, 0xA0, 0xE7, 0x83, 0xE9, 0x60, + 0x2D, 0x41, 0xD2, 0xBF, 0x00, 0x00, 0x29, 0xCF, 0xD2, 0xBF, 0xEE, 0xAF, + 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x18, 0x7D, 0xC4, 0xE0, 0x00, 0x00, + 0x16, 0xA0, 0xC4, 0xE0, 0xF6, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +u8 lbColl_SphereNormals[0x1A0] = { + 0x29, 0xC7, 0x2D, 0x49, 0x11, 0x4E, 0x1F, 0xF9, 0x2D, 0x49, 0x1F, 0xF9, + 0x29, 0xCD, 0xE7, 0x7B, 0x29, 0xCD, 0x00, 0x00, 0xC4, 0xDC, 0x18, 0x75, + 0x11, 0x4B, 0x3B, 0x24, 0x11, 0x4B, 0x11, 0x4E, 0xD2, 0xB7, 0x29, 0xC7, + 0x00, 0x00, 0xD2, 0xB7, 0x2D, 0x38, 0x16, 0x9F, 0x18, 0x85, 0x36, 0x9D, + 0x00, 0x00, 0x18, 0x85, 0x3B, 0x1D, 0x09, 0x5C, 0xC4, 0xDC, 0x16, 0x99, + 0x00, 0x00, 0x3B, 0x24, 0x18, 0x75, 0x09, 0x5C, 0x3B, 0x24, 0x16, 0x99, + 0x11, 0x4E, 0x2D, 0x49, 0x29, 0xC7, 0x00, 0x00, 0x2D, 0x49, 0x2D, 0x38, + 0x29, 0xCD, 0x18, 0x85, 0x29, 0xCD, 0x36, 0x9D, 0x18, 0x85, 0x16, 0x9F, + 0x2D, 0x41, 0x00, 0x00, 0x2D, 0x41, 0x3B, 0x20, 0x00, 0x00, 0x18, 0x7D, + 0x36, 0x9D, 0xE7, 0x7B, 0x16, 0x9F, 0x16, 0x99, 0x3B, 0x24, 0x09, 0x5C, + 0x1F, 0xF9, 0xD2, 0xB7, 0x1F, 0xF9, 0x29, 0xC7, 0xD2, 0xB7, 0x11, 0x4E, + 0x16, 0x99, 0xC4, 0xDC, 0x09, 0x5C, 0x11, 0x4B, 0xC4, 0xDC, 0x11, 0x4B, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x18, 0x7D, 0x00, 0x00, 0x3B, 0x20, + 0x16, 0x9F, 0xE7, 0x7B, 0x36, 0x9D, 0x00, 0x00, 0xE7, 0x7B, 0x3B, 0x1D, + 0x00, 0x00, 0x3B, 0x24, 0xE7, 0x8B, 0x00, 0x00, 0x2D, 0x49, 0xD2, 0xC8, + 0x00, 0x00, 0x18, 0x85, 0xC4, 0xE3, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, + 0x00, 0x00, 0xE7, 0x7B, 0xC4, 0xE3, 0x00, 0x00, 0xD2, 0xB7, 0xD2, 0xC8, + 0x00, 0x00, 0xC4, 0xDC, 0xE7, 0x8B, 0x09, 0x5C, 0x3B, 0x24, 0xE9, 0x67, + 0x11, 0x4E, 0x2D, 0x49, 0xD6, 0x39, 0x16, 0x9F, 0x18, 0x85, 0xC9, 0x63, + 0x18, 0x7D, 0x00, 0x00, 0xC4, 0xE0, 0x16, 0x9F, 0xE7, 0x7B, 0xC9, 0x63, + 0x11, 0x4E, 0xD2, 0xB7, 0xD6, 0x39, 0x09, 0x5C, 0xC4, 0xDC, 0xE9, 0x67, + 0x11, 0x4B, 0x3B, 0x24, 0xEE, 0xB5, 0x1F, 0xF9, 0x2D, 0x49, 0xE0, 0x07, + 0x29, 0xCD, 0x18, 0x85, 0xD6, 0x33, 0x2D, 0x41, 0x00, 0x00, 0xD2, 0xBF, + 0x29, 0xCD, 0xE7, 0x7B, 0xD6, 0x33, 0x1F, 0xF9, 0xD2, 0xB7, 0xE0, 0x07, + 0x11, 0x4B, 0xC4, 0xDC, 0xEE, 0xB5, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x18, 0x75, 0x3B, 0x24, 0x00, 0x00, 0x16, 0x99, 0x3B, 0x24, 0xF6, 0xA4, + 0x2D, 0x38, 0x2D, 0x49, 0x00, 0x00, 0x29, 0xC7, 0x2D, 0x49, 0xEE, 0xB2, + 0x3B, 0x1D, 0x18, 0x85, 0x00, 0x00, 0x36, 0x9D, 0x18, 0x85, 0xE9, 0x61, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, 0x20, 0x00, 0x00, 0xE7, 0x83, + 0x3B, 0x1D, 0xE7, 0x7B, 0x00, 0x00, 0x36, 0x9D, 0xE7, 0x7B, 0xE9, 0x61, + 0x2D, 0x38, 0xD2, 0xB7, 0x00, 0x00, 0x29, 0xC7, 0xD2, 0xB7, 0xEE, 0xB2, + 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x18, 0x75, 0xC4, 0xDC, 0x00, 0x00, + 0x16, 0x99, 0xC4, 0xDC, 0xF6, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +u8 lbColl_SphereDisplayList[0x120] = { + 0x98, 0x00, 0x75, 0x0B, 0x0B, 0x04, 0x04, 0x0C, 0x0C, 0x01, 0x01, 0x07, + 0x07, 0x0E, 0x0E, 0x19, 0x19, 0x10, 0x10, 0x1A, 0x1A, 0x02, 0x02, 0x05, + 0x05, 0x14, 0x14, 0x09, 0x09, 0x14, 0x14, 0x17, 0x17, 0x15, 0x15, 0x17, + 0x17, 0x16, 0x16, 0x17, 0x17, 0x3E, 0x3E, 0x09, 0x09, 0x03, 0x03, 0x05, + 0x05, 0x06, 0x06, 0x1A, 0x1A, 0x1B, 0x1B, 0x19, 0x19, 0x18, 0x18, 0x07, + 0x07, 0x08, 0x08, 0x0C, 0x0C, 0x0D, 0x0D, 0x0B, 0x0B, 0x0A, 0x0A, 0x0B, + 0x0B, 0x31, 0x31, 0x04, 0x04, 0x31, 0x31, 0x13, 0x13, 0x32, 0x32, 0x00, + 0x00, 0x34, 0x34, 0x0F, 0x0F, 0x36, 0x36, 0x11, 0x11, 0x38, 0x38, 0x12, + 0x12, 0x3A, 0x3A, 0x15, 0x15, 0x3C, 0x3C, 0x16, 0x16, 0x3F, 0x3F, 0x3E, + 0x3E, 0x3F, 0x3F, 0x40, 0x40, 0x3F, 0x3F, 0x3D, 0x3D, 0x3C, 0x3C, 0x3B, + 0x3B, 0x3A, 0x3A, 0x39, 0x39, 0x38, 0x38, 0x37, 0x37, 0x36, 0x36, 0x35, + 0x35, 0x34, 0x34, 0x33, 0x33, 0x32, 0x32, 0x33, 0x33, 0x31, 0x31, 0x33, + 0x33, 0x2A, 0x2A, 0x35, 0x35, 0x2B, 0x2B, 0x37, 0x37, 0x2C, 0x2C, 0x39, + 0x39, 0x2D, 0x2D, 0x3B, 0x3B, 0x2E, 0x2E, 0x3D, 0x3D, 0x2F, 0x2F, 0x40, + 0x40, 0x30, 0x30, 0x3E, 0x3E, 0x30, 0x30, 0x29, 0x29, 0x30, 0x30, 0x28, + 0x28, 0x2F, 0x2F, 0x27, 0x27, 0x2E, 0x2E, 0x26, 0x26, 0x2D, 0x2D, 0x25, + 0x25, 0x2C, 0x2C, 0x24, 0x24, 0x2B, 0x2B, 0x23, 0x23, 0x2A, 0x2A, 0x23, + 0x23, 0x31, 0x31, 0x23, 0x23, 0x1C, 0x1C, 0x24, 0x24, 0x1D, 0x1D, 0x25, + 0x25, 0x1E, 0x1E, 0x26, 0x26, 0x1F, 0x1F, 0x27, 0x27, 0x20, 0x20, 0x28, + 0x28, 0x21, 0x21, 0x29, 0x29, 0x22, 0x22, 0x3E, 0x3E, 0x98, 0x00, 0x0C, + 0x15, 0x15, 0x14, 0x14, 0x12, 0x12, 0x02, 0x02, 0x11, 0x11, 0x10, 0x10, + 0x0F, 0x0F, 0x0E, 0x0E, 0x00, 0x00, 0x01, 0x01, 0x13, 0x13, 0x04, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +u8 lbColl_CylinderPositions[0x80] = { + 0xE0, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xE0, 0x01, 0xE7, 0x83, 0x3B, 0x20, + 0xE0, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, + 0x20, 0x00, 0x00, 0x00, 0xC0, 0x01, 0xE0, 0x01, 0xC4, 0xE0, 0xE7, 0x83, + 0xE0, 0x01, 0xE7, 0x83, 0xC4, 0xE0, 0xE0, 0x01, 0xD2, 0xBF, 0xD2, 0xBF, + 0xE0, 0x00, 0x18, 0x7D, 0xC4, 0xE0, 0x00, 0x00, 0x18, 0x7D, 0xC4, 0xE0, + 0x1F, 0xFF, 0x18, 0x7D, 0xC4, 0xE0, 0x1F, 0xFF, 0x18, 0x7D, 0x3B, 0x20, + 0xE0, 0x00, 0x18, 0x7D, 0x3B, 0x20, 0xE0, 0x00, 0x2D, 0x41, 0x2D, 0x41, + 0x00, 0x00, 0x18, 0x7D, 0x3B, 0x20, 0xE0, 0x01, 0xC0, 0x01, 0x00, 0x00, + 0x00, 0x00, 0xE7, 0x83, 0xC4, 0xE0, 0x00, 0x00, 0xD2, 0xBF, 0xD2, 0xBF, + 0x20, 0x00, 0xD2, 0xBF, 0xD2, 0xBF, 0x20, 0x00, 0xE7, 0x83, 0xC4, 0xE0, + 0xE0, 0x00, 0x2D, 0x41, 0xD2, 0xBF, 0x00, 0x00, +}; +u8 lbColl_UnknownData[0xA0] = { + 0x2D, 0x41, 0xD2, 0xBF, 0x1F, 0xFF, 0x2D, 0x41, 0xD2, 0xBF, 0x00, 0x00, + 0xC4, 0xE0, 0xE7, 0x83, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x20, 0x00, + 0xC0, 0x01, 0x00, 0x00, 0x20, 0x00, 0xC4, 0xE0, 0xE7, 0x83, 0x00, 0x00, + 0x2D, 0x41, 0x2D, 0x41, 0x1F, 0xFF, 0x3B, 0x20, 0x18, 0x7D, 0x1F, 0xFF, + 0x2D, 0x41, 0x2D, 0x41, 0x00, 0x00, 0xE7, 0x83, 0x3B, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x3F, 0xFF, 0x20, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x20, 0x00, + 0xE7, 0x83, 0x3B, 0x20, 0x20, 0x00, 0xD2, 0xBF, 0x2D, 0x41, 0x20, 0x00, + 0xC4, 0xE0, 0x18, 0x7D, 0xE0, 0x00, 0x3B, 0x20, 0xE7, 0x83, 0x00, 0x00, + 0x3B, 0x20, 0xE7, 0x83, 0x1F, 0xFF, 0x3B, 0x20, 0xE7, 0x83, 0x1F, 0xFF, + 0x40, 0x00, 0x00, 0x00, 0xE0, 0x01, 0xC4, 0xE0, 0x18, 0x7D, 0xE0, 0x01, + 0xD2, 0xBF, 0x2D, 0x41, 0x00, 0x00, 0xD2, 0xBF, 0x2D, 0x41, 0x00, 0x00, + 0xC4, 0xE0, 0x18, 0x7D, 0xE0, 0x00, 0x3B, 0x20, 0x18, 0x7D, 0xE0, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3B, 0x20, 0x18, 0x7D, +}; +u8 lbColl_CylinderNormals[0x60] = { + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x18, 0xFF, 0xC5, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x3B, 0x00, 0x00, 0xFF, 0xD3, 0xFF, 0xD3, + 0x00, 0x00, 0xFF, 0xE8, 0xFF, 0xC5, 0x00, 0x00, 0x00, 0x2D, 0xFF, 0xD3, + 0x00, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xC5, 0xFF, 0xE8, + 0x00, 0x00, 0x00, 0x2D, 0x00, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x00, 0xFF, 0xE8, 0x00, 0x3B, 0x00, 0x00, 0x00, 0x3B, 0xFF, 0xE8, + 0x00, 0x00, 0xFF, 0xD3, 0x00, 0x2D, 0x00, 0x00, 0xFF, 0xC5, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x18, +}; +u8 lbColl_CylinderDisplayList[0xA0] = { + 0x98, 0x00, 0x45, 0x2C, 0x0F, 0x2D, 0x0E, 0x2F, 0x0F, 0x2D, 0x0E, 0x2E, + 0x0E, 0x24, 0x0B, 0x25, 0x0B, 0x14, 0x05, 0x15, 0x05, 0x08, 0x01, 0x09, + 0x01, 0x02, 0x00, 0x03, 0x00, 0x06, 0x04, 0x10, 0x04, 0x07, 0x03, 0x11, + 0x03, 0x05, 0x07, 0x17, 0x07, 0x0F, 0x06, 0x18, 0x06, 0x28, 0x0D, 0x2B, + 0x0D, 0x29, 0x0C, 0x2A, 0x0C, 0x01, 0x0A, 0x1E, 0x0A, 0x00, 0x09, 0x1F, + 0x09, 0x0C, 0x02, 0x0E, 0x02, 0x0D, 0x08, 0x1B, 0x08, 0x2C, 0x0F, 0x1B, + 0x08, 0x2F, 0x0F, 0x1D, 0x08, 0x2F, 0x0F, 0x1C, 0x0F, 0x2E, 0x0E, 0x27, + 0x0E, 0x25, 0x0B, 0x26, 0x0B, 0x15, 0x05, 0x16, 0x05, 0x09, 0x01, 0x0A, + 0x01, 0x03, 0x00, 0x04, 0x00, 0x10, 0x04, 0x13, 0x04, 0x11, 0x03, 0x12, + 0x03, 0x17, 0x07, 0x1A, 0x07, 0x18, 0x06, 0x19, 0x06, 0x2B, 0x0D, 0x23, + 0x0D, 0x2A, 0x0C, 0x22, 0x0C, 0x1E, 0x0A, 0x21, 0x0A, 0x1F, 0x09, 0x20, + 0x09, 0x0E, 0x02, 0x0B, 0x02, 0x1B, 0x08, 0x1D, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; /// .text @@ -256,10 +387,10 @@ float lbColl_80005EBC(const Vec3* arg0, const Vec3* arg1, const Vec3* arg2, d1_dot_d2 = d1.x * d2.x + d1.y * d2.y + d1.z * d2.z; scale = -d1_dot_d2 / d1_dot_d1; - if (scale > lbColl_804D7A00) { - scale = lbColl_804D7A08; - } else if (scale < lbColl_804D7A10) { - scale = lbColl_804D79F8; + if (scale > 1.0) { + scale = 1.0F; + } else if (scale < 0.0) { + scale = 0.0F; } x = d1.x * scale + sp50.x - arg2->x; @@ -295,10 +426,10 @@ float lbColl_80005FC0(Vec3* arg0, Vec3* arg1, Vec3* arg2, float* arg3) d1_dot_d2 = d1.x * d2.x + d1.y * d2.y; scale = -d1_dot_d2 / d1_dot_d1; - if (scale > lbColl_804D7A00) { - scale = lbColl_804D7A08; - } else if (scale < lbColl_804D7A10) { - scale = lbColl_804D79F8; + if (scale > 1.0) { + scale = 1.0F; + } else if (scale < 0.0) { + scale = 0.0F; } x = d1.x * scale + sp50.x - arg2->x; @@ -310,8 +441,8 @@ float lbColl_80005FC0(Vec3* arg0, Vec3* arg1, Vec3* arg2, float* arg3) static inline bool end(Vec3* a, Vec3* b, float unk_sum) { - float y = a->y - b->y; float x = a->x - b->x; + float y = a->y - b->y; float z = a->z - b->z; if (unk_sum * unk_sum < z * z + (x * x + y * y)) { @@ -329,342 +460,349 @@ bool lbColl_80006094(Vec3* arg0, Vec3* arg1, Vec3* arg2, Vec3* arg3, Vec3 arg5_offset; float arg1_y; float unk_sum = arg6 + arg7; - Vec3 vec4 = *arg0; - (void) vec4; - arg4_offset = vec4; + + PAD_STACK(60); { + float candidate0_arg5_scl; + float candidate1_arg4_scl; + Vec3 vec4 = *arg0; + Vec3 a2; + Vec3 d1; + Vec3 c3; + Vec3 mid; + Vec3 b0; + Vec3 d2; + Vec3 c2; Vec3 arg2_copy; + + (void) vec4; + arg4_offset = vec4; arg2_copy = *arg2; (void) arg2_copy; arg5_offset = arg2_copy; - } - - { - float arg1_x = arg1->x; - if (arg4_offset.x > arg1_x) { - { - float x = arg4_offset.x + unk_sum; - if (x < arg5_offset.x && x < arg3->x) { - return false; - } - } - - { - float x = arg1_x - unk_sum; - if (x > arg5_offset.x && x > arg3->x) { - return false; - } - } - - } else { - { - float x = arg4_offset.x - unk_sum; - if (x > arg5_offset.x && x > arg3->x) { - return false; - } - } - - { - float x = arg1_x + unk_sum; - if (x < arg5_offset.x && x < arg3->x) { - return false; - } - } - } { - if (arg4_offset.y > (arg1_y = arg1->y)) { + float arg1_x = arg1->x; + if (arg4_offset.x > arg1_x) { { - float upper_bound = arg4_offset.y + unk_sum; - - if (upper_bound < arg5_offset.y && - upper_bound < arg3->y) - { + float x = arg4_offset.x + unk_sum; + if (x < arg5_offset.x && x < arg3->x) { return false; } } { - float lower_bound = arg1_y - unk_sum; - - if (lower_bound > arg5_offset.y && - lower_bound > arg3->y) - { + float x = arg1_x - unk_sum; + if (x > arg5_offset.x && x > arg3->x) { return false; } } } else { { - float y = arg4_offset.y - unk_sum; - if (y > arg5_offset.y && y > arg3->y) { + float x = arg4_offset.x - unk_sum; + if (x > arg5_offset.x && x > arg3->x) { return false; } } { - float y = arg1_y + unk_sum; - if (y < arg5_offset.y && y < arg3->y) { + float x = arg1_x + unk_sum; + if (x < arg5_offset.x && x < arg3->x) { return false; } } } - } - { - float arg1_z; - if (arg4_offset.z > (arg1_z = arg1->z)) { - { - float upper_bound = arg4_offset.z + unk_sum; - if ((upper_bound < arg5_offset.z) && - (upper_bound < arg3->z)) + + { + if (arg4_offset.y > (arg1_y = arg1->y)) { { - return false; + float upper_bound = arg4_offset.y + unk_sum; + + if (upper_bound < arg5_offset.y && + upper_bound < arg3->y) + { + return false; + } } - } - { - float lower_bound = arg1_z - unk_sum; - if ((lower_bound > arg5_offset.z) && - (lower_bound > arg3->z)) + { - return false; + float lower_bound = arg1_y - unk_sum; + + if (lower_bound > arg5_offset.y && + lower_bound > arg3->y) + { + return false; + } } - } - } else { - { - float lower_bound = arg4_offset.z - unk_sum; - if ((lower_bound > arg5_offset.z) && - (lower_bound > arg3->z)) + + } else { { - return false; + float y = arg4_offset.y - unk_sum; + if (y > arg5_offset.y && y > arg3->y) { + return false; + } } - } - { - float upper_bound = arg1_z + unk_sum; - if ((upper_bound < arg5_offset.z) && - (upper_bound < arg3->z)) + { - return false; + float y = arg1_y + unk_sum; + if (y < arg5_offset.y && y < arg3->y) { + return false; + } } } } { - float arg4_scl; - float d1_x; - float d1_y; - float d1_z; - float d2_x; - float d2_y; - float d2_z; - float arg3_z; - float offset_delta_y; - float offset_delta_z; - float offset_delta_x; - float d1_len_sq; - float d2_len_sq; - float d1_dot_d2; - float d2_dot_offset_delta; - float d1_dot_offset_delta; - float denom; - - d1_y = arg1->y - arg4_offset.y; - d1_z = arg1->z - arg4_offset.z; - d2_y = arg3->y - arg5_offset.y; - offset_delta_y = arg4_offset.y - arg5_offset.y; - d1_x = arg1_x - arg4_offset.x; - d2_x = arg3->x - arg5_offset.x; - { - f32 z = arg3->z; - arg3_z = z; + float arg1_z; + if (arg4_offset.z > (arg1_z = arg1->z)) { + { + float upper_bound = arg4_offset.z + unk_sum; + if ((upper_bound < arg5_offset.z) && + (upper_bound < arg3->z)) + { + return false; + } + } + { + float lower_bound = arg1_z - unk_sum; + if ((lower_bound > arg5_offset.z) && + (lower_bound > arg3->z)) + { + return false; + } + } + } else { + { + float lower_bound = arg4_offset.z - unk_sum; + if ((lower_bound > arg5_offset.z) && + (lower_bound > arg3->z)) + { + return false; + } + } + { + float upper_bound = arg1_z + unk_sum; + if ((upper_bound < arg5_offset.z) && + (upper_bound < arg3->z)) + { + return false; + } + } } - d2_z = arg3_z - arg5_offset.z; - offset_delta_x = arg4_offset.x - arg5_offset.x; - d1_len_sq = - (d1_z * d1_z) + ((d1_x * d1_x) + (d1_y * d1_y)); - d2_len_sq = - (d2_z * d2_z) + ((d2_x * d2_x) + (d2_y * d2_y)); - d1_dot_d2 = - (d1_z * d2_z) + ((d1_x * d2_x) + (d1_y * d2_y)); - offset_delta_z = arg4_offset.z - arg5_offset.z; - d2_dot_offset_delta = - (d2_z * offset_delta_z) + - ((d2_x * offset_delta_x) + (d2_y * offset_delta_y)); - d1_dot_offset_delta = - (d1_z * offset_delta_z) + - ((d1_x * offset_delta_x) + (d1_y * offset_delta_y)); - denom = (d1_len_sq * d2_len_sq) - (d1_dot_d2 * d1_dot_d2); - { - float arg5_scl; - if (approximatelyZero(d2_len_sq)) { - if (approximatelyZero(d1_len_sq)) { - arg4_scl = 0.0f; - arg5_scl = 0.0f; - } else { - arg5_scl = 0.0f; - { - float scale = - -d1_dot_offset_delta / d1_len_sq; - arg4_scl = scale; - - if (scale > lbColl_804D7A00) { - arg4_scl = lbColl_804D7A08; - } else if (arg4_scl < lbColl_804D7A10) { - arg4_scl = lbColl_804D79F8; - } - } - } - } else { - if (approximatelyZero(denom)) { - float mid_y = - (lbColl_804D7A18 * d2_y + arg5_offset.y); - float mid_x = - (lbColl_804D7A18 * d2_x + arg5_offset.x); - float arg4_mid_y = arg4_offset.y - mid_y; - float arg1_mid_y = arg1->y - mid_y; - float mid_z = - lbColl_804D7A18 * d2_z + arg5_offset.z; - float arg4_mid_x = arg4_offset.x - mid_x; - float arg1_mid_x = arg1_x - mid_x; - float arg4_offset_z = arg4_offset.z - mid_z; - float arg1_mid_z = arg1->z - mid_z; - - // lhs and rhs each the same inline - if ((arg4_offset_z * arg4_offset_z + - ((arg4_mid_x * arg4_mid_x) + - (arg4_mid_y * arg4_mid_y))) < - ((arg1_mid_z * arg1_mid_z) + - ((arg1_mid_x * arg1_mid_x) + - (arg1_mid_y * arg1_mid_y)))) - { - float scale; - Vec3 a2; - Vec3 d1; - Vec3 c3; + float arg4_scl; + float d1_x; + float d1_y; + float d1_z; + float d2_x; + float d2_y; + float d2_z; + float arg3_z; + float offset_delta_y; + float offset_delta_z; + float offset_delta_x; + float d1_len_sq; + float d2_len_sq; + float d1_dot_d2; + float d2_dot_offset_delta; + float d1_dot_offset_delta; + float denom; + + d1_y = arg1->y - arg4_offset.y; + d1_z = arg1->z - arg4_offset.z; + d2_y = arg3->y - arg5_offset.y; + offset_delta_y = arg4_offset.y - arg5_offset.y; + d1_x = arg1_x - arg4_offset.x; + d2_x = arg3->x - arg5_offset.x; + { + f32 z = arg3->z; + arg3_z = z; + } + d2_z = arg3_z - arg5_offset.z; + offset_delta_x = arg4_offset.x - arg5_offset.x; + d1_len_sq = + (d1_z * d1_z) + ((d1_x * d1_x) + (d1_y * d1_y)); + d2_len_sq = + (d2_z * d2_z) + ((d2_x * d2_x) + (d2_y * d2_y)); + d1_dot_d2 = + (d1_z * d2_z) + ((d1_x * d2_x) + (d1_y * d2_y)); + offset_delta_z = arg4_offset.z - arg5_offset.z; + d2_dot_offset_delta = (d2_z * offset_delta_z) + + ((d2_x * offset_delta_x) + + (d2_y * offset_delta_y)); + d1_dot_offset_delta = (d1_z * offset_delta_z) + + ((d1_x * offset_delta_x) + + (d1_y * offset_delta_y)); + denom = + (d1_len_sq * d2_len_sq) - (d1_dot_d2 * d1_dot_d2); - c3 = arg5_offset; + { + float arg5_scl; + if (approximatelyZero(d2_len_sq)) { + if (approximatelyZero(d1_len_sq)) { arg4_scl = 0.0f; - d1.x = arg3->x - arg2->x; - d1.y = arg3->y - arg2->y; - d1.z = arg3_z - arg2->z; - { - float dot; - - a2 = vec4; - dot = (d1.z * (c3.z - a2.z)) + - ((d1.x * (c3.x - a2.x)) + - (d1.y * (c3.y - a2.y))); - scale = - -dot / - ((d1.z * d1.z) + - ((d1.x * d1.x) + (d1.y * d1.y))); - } - if (scale > lbColl_804D7A00) { - scale = lbColl_804D7A08; - } else if (scale < lbColl_804D7A10) { - scale = lbColl_804D79F8; - } - arg5_scl = scale; + arg5_scl = 0.0f; } else { - Vec3 b0; - Vec3 d1; - Vec3 c2; - - c2 = arg5_offset; - arg4_scl = 1.0f; - d1.x = arg3->x - arg2->x; - d1.y = arg3->y - arg2->y; - d1.z = arg3_z - arg2->z; + arg5_scl = 0.0f; { - float dot; - float scale; + arg4_scl = + -d1_dot_offset_delta / d1_len_sq; - b0 = *arg1; - dot = (d1.z * (c2.z - b0.z)) + - ((d1.x * (c2.x - b0.x)) + - (d1.y * (c2.y - b0.y))); - scale = - -dot / - ((d1.z * d1.z) + - ((d1.x * d1.x) + (d1.y * d1.y))); - - if (scale > lbColl_804D7A00) { - scale = lbColl_804D7A08; - } else if (scale < lbColl_804D7A10) { - scale = lbColl_804D79F8; + if (arg4_scl > 1.0) { + arg4_scl = 1.0F; + } else if (arg4_scl < 0.0) { + arg4_scl = 0.0F; } - - arg5_scl = scale; } } } else { - float unclamped_arg4_scl = - ((d1_dot_d2 * d2_dot_offset_delta) - - (d2_len_sq * d1_dot_offset_delta)) / - denom; - arg5_scl = - ((d1_len_sq * d2_dot_offset_delta) - - (d1_dot_d2 * d1_dot_offset_delta)) / - denom; - arg4_scl = unclamped_arg4_scl; - if (unclamped_arg4_scl > lbColl_804D7A00 || - arg4_scl < lbColl_804D7A10 || - arg5_scl > lbColl_804D7A00 || - arg5_scl < lbColl_804D7A10) - { - float candidate0_dist_sq; - float candidate0_scale; - float candidate1_dist_sq; - float spA4; - - if (arg4_scl < lbColl_804D7A10) { - candidate0_scale = lbColl_804D79F8; - candidate0_dist_sq = lbColl_80005EBC( - arg2, arg3, arg0, &spA4); + if (approximatelyZero(denom)) { + float arg4_mid_y; + float arg4_mid_x; + float arg4_offset_z; + float arg1_mid_z; + float arg1_mid_x; + float arg1_mid_y; + + mid.y = 0.5 * d2_y + arg5_offset.y; + mid.x = 0.5 * d2_x + arg5_offset.x; + arg4_mid_y = arg4_offset.y - mid.y; + arg1_mid_y = arg1->y - mid.y; + mid.z = 0.5 * d2_z + arg5_offset.z; + arg4_mid_x = arg4_offset.x - mid.x; + arg1_mid_x = arg1_x - mid.x; + arg4_offset_z = arg4_offset.z - mid.z; + arg1_mid_z = arg1->z - mid.z; + + // lhs and rhs each the same inline + if ((arg4_offset_z * arg4_offset_z + + ((arg4_mid_x * arg4_mid_x) + + (arg4_mid_y * arg4_mid_y))) < + ((arg1_mid_z * arg1_mid_z) + + ((arg1_mid_x * arg1_mid_x) + + (arg1_mid_y * arg1_mid_y)))) + { + float scale; + + c3 = arg5_offset; + arg4_scl = 0.0f; + d1.x = arg3->x - arg2->x; + d1.y = arg3->y - arg2->y; + d1.z = arg3_z - arg2->z; + { + float dot; + + a2 = vec4; + dot = (d1.z * (c3.z - a2.z)) + + ((d1.x * (c3.x - a2.x)) + + (d1.y * (c3.y - a2.y))); + scale = -dot / ((d1.z * d1.z) + + ((d1.x * d1.x) + + (d1.y * d1.y))); + } + if (scale > 1.0) { + scale = 1.0F; + } else if (scale < 0.0) { + scale = 0.0F; + } + arg5_scl = scale; } else { - candidate0_scale = lbColl_804D7A08; - candidate0_dist_sq = lbColl_80005EBC( - arg2, arg3, arg1, &spA4); - } + c2 = arg5_offset; + arg4_scl = 1.0f; + d2.x = arg3->x - arg2->x; + d2.y = arg3->y - arg2->y; + d2.z = arg3_z - arg2->z; + { + float dot; + float scale; + b0 = *arg1; + dot = (d2.z * (c2.z - b0.z)) + + ((d2.x * (c2.x - b0.x)) + + (d2.y * (c2.y - b0.y))); + scale = -dot / ((d2.z * d2.z) + + ((d2.x * d2.x) + + (d2.y * d2.y))); + + if (scale > 1.0) { + scale = 1.0F; + } else if (scale < 0.0) { + scale = 0.0F; + } + + arg5_scl = scale; + } + } + } else { + arg4_scl = + ((d1_dot_d2 * d2_dot_offset_delta) - + (d2_len_sq * d1_dot_offset_delta)) / + denom; + arg5_scl = + ((d1_len_sq * d2_dot_offset_delta) - + (d1_dot_d2 * d1_dot_offset_delta)) / + denom; + if (arg4_scl > 1.0 || arg4_scl < 0.0 || + arg5_scl > 1.0 || arg5_scl < 0.0) { - float spA0; - if (arg5_scl < lbColl_804D7A10) { - arg5_scl = lbColl_804D79F8; - candidate1_dist_sq = - lbColl_80005EBC(arg0, arg1, - arg2, &spA0); + float candidate0_dist_sq; + float candidate0_scale; + float candidate1_dist_sq; + + if (arg4_scl < 0.0) { + candidate0_scale = 0.0F; + candidate0_dist_sq = + lbColl_80005EBC( + arg2, arg3, arg0, + &candidate0_arg5_scl); } else { - float result; - arg5_scl = lbColl_804D7A08; - result = lbColl_80005EBC( - arg0, arg1, arg3, &spA0); - candidate1_dist_sq = result; + candidate0_scale = 1.0F; + candidate0_dist_sq = + lbColl_80005EBC( + arg2, arg3, arg1, + &candidate0_arg5_scl); } - if (candidate0_dist_sq < - candidate1_dist_sq) { - arg4_scl = candidate0_scale; - arg5_scl = spA4; - } else { - arg4_scl = spA0; + if (arg5_scl < 0.0) { + arg5_scl = 0.0F; + candidate1_dist_sq = + lbColl_80005EBC( + arg0, arg1, arg2, + &candidate1_arg4_scl); + } else { + float result; + arg5_scl = 1.0F; + result = lbColl_80005EBC( + arg0, arg1, arg3, + &candidate1_arg4_scl); + candidate1_dist_sq = result; + } + + if (candidate0_dist_sq < + candidate1_dist_sq) + { + arg4_scl = candidate0_scale; + arg5_scl = candidate0_arg5_scl; + } else { + arg4_scl = candidate1_arg4_scl; + } } } } } - } - arg4->x = d1_x * arg4_scl + arg4_offset.x; - arg4->y = d1_y * arg4_scl + arg4_offset.y; - arg4->z = d1_z * arg4_scl + arg4_offset.z; + arg4->x = d1_x * arg4_scl + arg4_offset.x; + arg4->y = d1_y * arg4_scl + arg4_offset.y; + arg4->z = d1_z * arg4_scl + arg4_offset.z; - arg5->x = d2_x * arg5_scl + arg5_offset.x; - arg5->y = d2_y * arg5_scl + arg5_offset.y; - arg5->z = d2_z * arg5_scl + arg5_offset.z; + arg5->x = d2_x * arg5_scl + arg5_offset.x; + arg5->y = d2_y * arg5_scl + arg5_offset.y; + arg5->z = d2_z * arg5_scl + arg5_offset.z; + } } + return end(arg4, arg5, unk_sum); } - PAD_STACK(72); - return end(arg4, arg5, unk_sum); } } } @@ -683,29 +821,38 @@ static inline float lbColl_GetY(Vec3* v) bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, float p, float q, float r) { + Vec3 a1; + Vec3 c1; + float diff_ba_y; float diff_dc_x; - float diff_ac_x; float diff_dc_y; + float diff_ba_x; + float diff_ac_x; float d_y; - float diff_ba_y; float sqdist2_dc; float d_x; - Vec3 a1; - float diff_ba_x; float sqdist2_ba; - Vec3 c1; float dot2_diff_dc_ac; float dot2_diff_ba_ac; float determinant; + float c1_y; float sum_pq = p + q; - Vec3 a0; + Vec3 a0 = *a; - PAD_STACK(48); + PAD_STACK(36); - a0 = *a; (void) a0; a1 = a0; { + float out0; + float out1; + Vec3 a2; + Vec3 d1; + Vec3 c3; + Vec3 mid; + Vec3 b0; + Vec3 d2; + Vec3 c2; Vec3 c0; c0 = *c; @@ -748,8 +895,7 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, { float a1_y = a1.y; - float loaded_b_y = b->y; - float b_y = loaded_b_y; + float b_y = b->y; if (a1_y > b_y) { { float y; @@ -784,10 +930,11 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, { float dot2_diff_ba_dc; float diff_ac_y; + c1_y = c1.y; diff_ba_y = b_y - a1_y; d_y = lbColl_GetY(d); - diff_ac_y = a1_y - c1.y; - diff_dc_y = d_y - c1.y; + diff_ac_y = a1_y - c1_y; + diff_dc_y = d_y - c1_y; diff_ba_x = b_x - a1.x; { float loaded_d_x = d->x; @@ -810,8 +957,11 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, dot2_diff_dc_ac = diff_dc_x * diff_ac_x + diff_dc_y * diff_ac_y; - dot2_diff_ba_ac = - diff_ba_x * diff_ac_x + diff_ba_y * diff_ac_y; + { + float y_product = diff_ba_y * diff_ac_y; + dot2_diff_ba_ac = + diff_ba_x * diff_ac_x + y_product; + } { float lengths_product = sqdist2_ba * sqdist2_dc; @@ -822,133 +972,121 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, { float scl_e; float scl_f; - float out1; if (approximatelyZero(sqdist2_dc)) { if (approximatelyZero(sqdist2_ba)) { scl_e = 0.0f; scl_f = 0.0f; } else { - float temp_f1_2; + float unclamped_scl_e; scl_f = 0.0f; - temp_f1_2 = -dot2_diff_ba_ac / sqdist2_ba; - scl_e = temp_f1_2; - if (temp_f1_2 > lbColl_804D7A00) { - scl_e = lbColl_804D7A08; - } else if (scl_e < lbColl_804D7A10) { - scl_e = lbColl_804D79F8; + unclamped_scl_e = + -dot2_diff_ba_ac / sqdist2_ba; + scl_e = unclamped_scl_e; + if (unclamped_scl_e > 1.0) { + scl_e = 1.0F; + } else if (scl_e < 0.0) { + scl_e = 0.0F; } } } else if (approximatelyZero(determinant)) { - float mid_y = - lbColl_804D7A18 * diff_dc_y + c1.y; - float mid_x = - lbColl_804D7A18 * diff_dc_x + c1.x; - float a_mid_y = a1_y - mid_y; - float b_mid_y = b_y - mid_y; + float a_mid_y; + float b_mid_y; + + mid.y = 0.5 * diff_dc_y + c1_y; + mid.x = 0.5 * diff_dc_x + c1.x; + a_mid_y = a1_y - mid.y; + b_mid_y = b_y - mid.y; { - float a_mid_x = a1.x - mid_x; - float b_mid_x = b_x - mid_x; + float a_mid_x = a1.x - mid.x; + float b_mid_x = b_x - mid.x; if ((a_mid_x * a_mid_x + a_mid_y * a_mid_y) < (b_mid_x * b_mid_x + b_mid_y * b_mid_y)) { float scale; - Vec3 a2; - Vec3 delta; - Vec3 c3; c3 = c0; scl_e = 0.0f; - delta.x = d_x - c->x; - delta.y = d_y - c->y; - delta.z = d->z - c->z; + d1.x = d_x - c->x; + d1.y = d_y - c->y; + d1.z = d->z - c->z; { float dot; a2 = a0; - dot = delta.z * (c3.z - a2.z) + - ((delta.x * (c3.x - a2.x)) + - (delta.y * (c3.y - a2.y))); - scale = - -dot / ((delta.z * delta.z) + - ((delta.x * delta.x) + - (delta.y * delta.y))); + dot = d1.z * (c3.z - a2.z) + + ((d1.x * (c3.x - a2.x)) + + (d1.y * (c3.y - a2.y))); + scale = -dot / ((d1.z * d1.z) + + ((d1.x * d1.x) + + (d1.y * d1.y))); } - if (scale > lbColl_804D7A00) { - scale = lbColl_804D7A08; - } else if (scale < lbColl_804D7A10) { - scale = lbColl_804D79F8; + if (scale > 1.0) { + scale = 1.0F; + } else if (scale < 0.0) { + scale = 0.0F; } scl_f = scale; } else { - Vec3 delta; - Vec3 c2; - c2 = c0; scl_e = 1.0f; - delta.x = d_x - c->x; - delta.y = d_y - c->y; - delta.z = d->z - c->z; + d2.x = d_x - c->x; + d2.y = d_y - c->y; + d2.z = d->z - c->z; { - Vec3 b0; float dot; float scale; b0 = *b; - dot = delta.z * (c2.z - b0.z) + - ((delta.x * (c2.x - b0.x)) + - (delta.y * (c2.y - b0.y))); - scale = - -dot / ((delta.z * delta.z) + - ((delta.x * delta.x) + - (delta.y * delta.y))); - if (scale > lbColl_804D7A00) { - scale = lbColl_804D7A08; - } else if (scale < lbColl_804D7A10) - { - scale = lbColl_804D79F8; + dot = d2.z * (c2.z - b0.z) + + ((d2.x * (c2.x - b0.x)) + + (d2.y * (c2.y - b0.y))); + scale = -dot / ((d2.z * d2.z) + + ((d2.x * d2.x) + + (d2.y * d2.y))); + if (scale > 1.0) { + scale = 1.0F; + } else if (scale < 0.0) { + scale = 0.0F; } scl_f = scale; } } } } else { - float temp_f1_3 = + float unclamped_scl_e = ((dot2_diff_ba_dc * dot2_diff_dc_ac) - (sqdist2_dc * dot2_diff_ba_ac)) / determinant; scl_f = ((sqdist2_ba * dot2_diff_dc_ac) - (dot2_diff_ba_dc * dot2_diff_ba_ac)) / determinant; - scl_e = temp_f1_3; - if ((temp_f1_3 > lbColl_804D7A00) || - (scl_e < lbColl_804D7A10) || - (scl_f > lbColl_804D7A00) || - (scl_f < lbColl_804D7A10)) + scl_e = unclamped_scl_e; + if ((unclamped_scl_e > 1.0) || (scl_e < 0.0) || + (scl_f > 1.0) || (scl_f < 0.0)) { - float out0; float result0; float temp_scl_e; { - if (scl_e < lbColl_804D7A10) { - temp_scl_e = lbColl_804D79F8; + if (scl_e < 0.0) { + temp_scl_e = 0.0F; result0 = lbColl_80005FC0(c, d, a, &out0); } else { - temp_scl_e = lbColl_804D7A08; + temp_scl_e = 1.0F; result0 = lbColl_80005FC0(c, d, b, &out0); } } { float result1; - if (scl_f < lbColl_804D7A10) { - scl_f = lbColl_804D79F8; + if (scl_f < 0.0) { + scl_f = 0.0F; result1 = lbColl_80005FC0(a, b, c, &out1); } else { - scl_f = lbColl_804D7A08; + scl_f = 1.0F; result1 = lbColl_80005FC0(a, b, d, &out1); } @@ -968,7 +1106,7 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, e->z = 0.0f; f->x = diff_dc_x * scl_f + c1.x; - f->y = diff_dc_y * scl_f + c1.y; + f->y = diff_dc_y * scl_f + c1_y; f->z = 0.0f; } } @@ -1014,9 +1152,9 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float broadphase_scale) { float hit_end_min_z; - float closest_delta_x; + float start_delta_y; + float start_delta_x; float hit_start_mid_x; - float local_delta_x; float hurt_mid_z; Vec3 hit_start_copy; Vec3 hurt_start_copy; @@ -1035,16 +1173,16 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float allowed_distance; float hurt_closest_x; float hurt_closest_y; - float hurt_end_x; + float hit_end_y; float hit_start_mid_y; float hit_param_candidate; float closest_delta_y; float closest_dist_sq; float local_delta_y; - float start_delta_x; - float start_delta_y; + float closest_delta_x; + float hurt_param_from_hit_start; Mtx inv_hurt_mtx; - float hurt_delta_x; + float candidate_hit_param; float hit_start_max_x; float hit_end_min_x; float hit_start_min_x; @@ -1062,21 +1200,21 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float hurt_len_sq; float hit_end_max_z; float candidate_hurt_param; - float candidate_hit_param; + float hurt_delta_z; float hit_end_x; float hit_len_sq; float hit_end_mid_x; - float hit_end_y; + float segment_dot; float hit_start_max_z; float hit_start_min_z; float hurt_closest_z; float hit_end_z; - float segment_dot; + float hurt_end_x; float hurt_end_y; float hit_param; float local_dist; float hurt_param; - float hurt_param_from_hit_start; + float local_delta_x; float hurt_param_from_hit_end; float closest_dist; float hurt_end_z; @@ -1090,9 +1228,9 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, s32 is_hit_segment_degenerate; s32 is_parallel; s32 is_zero_distance; - float hurt_delta_z; + float hurt_delta_x; float hurt_delta_y; - PAD_STACK(52); + PAD_STACK(40); // Fast reject when the expanded hit segment AABB misses both hurt // endpoints. @@ -1197,57 +1335,58 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, hurt_end_z = hurt_end->z; (void) hurt_end_z; start_delta_x = hit_start_copy.x - hurt_start_copy.x; - segment_dot = (hit_delta.x * hurt_delta_x) + segment_dot; hurt_delta_z = hurt_end_z - hurt_start_copy.z; + segment_dot = (hit_delta.x * hurt_delta_x) + segment_dot; /* Cache 1.0 constant in a callee-save to avoid reloading it across the * several `hit_param = 1.0` / `hurt_param = 1.0` branches below. The * variable name is a borrow from the unused-after-broadphase-rejection * slot. */ - hit_start_min_z = lbColl_804D7A08; + hit_start_min_z = 1.0F; hurt_len_sq = (hurt_delta_x * hurt_delta_x) + hurt_len_sq; segment_dot = (hit_delta.z * hurt_delta_z) + segment_dot; hurt_len_sq = (hurt_delta_z * hurt_delta_z) + hurt_len_sq; - hit_start_mid_z = hit_delta.z * hit_delta.z; + { + float hit_delta_z_sq = hit_delta.z * hit_delta.z; + hit_start_mid_z = hit_delta_z_sq; + } start_delta_z = hit_start_copy.z - hurt_start_copy.z; - hit_len_sq = hit_start_mid_z + (hit_start_mid_x + hit_start_mid_y); + hit_len_sq = hit_start_mid_z + (hit_start_mid_y + hit_start_mid_x); hit_start_dot = hit_delta.y * start_delta_y; { float hit_start_dot_x = hit_delta.x * start_delta_x; hit_start_dot = hit_start_dot_x + hit_start_dot; } hurt_start_dot = - (hurt_delta_y * start_delta_y) + (hurt_delta_x * start_delta_x); - hit_start_dot = (hit_delta.z * start_delta_z) + hit_start_dot; + (hurt_delta_x * start_delta_x) + (hurt_delta_y * start_delta_y); hurt_start_dot = (hurt_delta_z * start_delta_z) + hurt_start_dot; - closest_denom = (hit_len_sq * hurt_len_sq) - (segment_dot * segment_dot); - if ((hurt_len_sq < lbColl_804D79F0) && (hurt_len_sq > lbColl_804D79F4)) { + hit_start_dot = (hit_delta.z * start_delta_z) + hit_start_dot; + closest_denom = (hurt_len_sq * hit_len_sq) - (segment_dot * segment_dot); + if ((hurt_len_sq < 1e-5F) && (hurt_len_sq > -1e-5F)) { is_hurt_segment_degenerate = 1; } else { is_hurt_segment_degenerate = 0; } if (is_hurt_segment_degenerate != 0) { - if ((hit_len_sq < lbColl_804D79F0) && (hit_len_sq > lbColl_804D79F4)) { + if ((hit_len_sq < 1e-5F) && (hit_len_sq > -1e-5F)) { is_hit_segment_degenerate = 1; } else { is_hit_segment_degenerate = 0; } if (is_hit_segment_degenerate != 0) { - hit_param = lbColl_804D79F8; + hit_param = 0.0F; hurt_param = hit_param; } else { - hurt_param = lbColl_804D79F8; + hurt_param = 0.0F; projected_hit_param = -hit_start_dot / hit_len_sq; hit_param = projected_hit_param; - if (projected_hit_param > lbColl_804D7A00) { + if (projected_hit_param > 1.0) { hit_param = hit_start_min_z; - } else if (hit_param < lbColl_804D7A10) { + } else if (hit_param < 0.0) { hit_param = hurt_param; } } } else { - if ((closest_denom < lbColl_804D79F0) && - (closest_denom > lbColl_804D79F4)) - { + if ((closest_denom < 1e-5F) && (closest_denom > -1e-5F)) { is_parallel = 1; } else { is_parallel = 0; @@ -1255,13 +1394,13 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, if (is_parallel != 0) { // For parallel axes, project the hit endpoint nearer the hurt // midpoint. - hurt_mid_y = (float) ((lbColl_804D7A18 * (f64) hurt_delta_y) + - (f64) hurt_start_copy.y); - hurt_mid_x = (float) ((lbColl_804D7A18 * (f64) hurt_delta_x) + - (f64) hurt_start_copy.x); + hurt_mid_y = + (float) ((0.5 * (f64) hurt_delta_y) + (f64) hurt_start_copy.y); + hurt_mid_x = + (float) ((0.5 * (f64) hurt_delta_x) + (f64) hurt_start_copy.x); hit_start_mid_y = hit_start_copy.y - hurt_mid_y; - hurt_mid_z = (float) ((lbColl_804D7A18 * (f64) hurt_delta_z) + - (f64) hurt_start_copy.z); + hurt_mid_z = + (float) ((0.5 * (f64) hurt_delta_z) + (f64) hurt_start_copy.z); hit_end_mid_y = hit_end->y - hurt_mid_y; hit_start_mid_x = hit_start_copy.x - hurt_mid_x; hit_end_mid_x = hit_end->x - hurt_mid_x; @@ -1277,9 +1416,8 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, Vec3 a2; Vec3 d1; Vec3 c3; - u8 gap_pad[4]; c3 = *hurt_start; - hit_param = lbColl_804D79F8; + hit_param = 0.0F; d1.x = hurt_end_x - hurt_start->x; d1.y = hurt_end_y - hurt_start->y; d1.z = hurt_end_z - hurt_start->z; @@ -1289,14 +1427,13 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, a2 = *hit_start; dot = (d1.z * (c3.z - a2.z)) + ((d1.x * (c3.x - a2.x)) + (d1.y * (c3.y - a2.y))); - hit_end_mid_x = d1.x * d1.x; hurt_param_from_hit_start = -dot / - ((d1.z * d1.z) + (hit_end_mid_x + (d1.y * d1.y))); + ((d1.z * d1.z) + ((d1.x * d1.x) + (d1.y * d1.y))); } - if (hurt_param_from_hit_start > lbColl_804D7A00) { + if (hurt_param_from_hit_start > 1.0) { hurt_param_from_hit_start = hit_start_min_z; - } else if (hurt_param_from_hit_start < lbColl_804D7A10) { + } else if (hurt_param_from_hit_start < 0.0) { hurt_param_from_hit_start = hit_param; } hurt_param = hurt_param_from_hit_start; @@ -1318,10 +1455,10 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, -dot / ((d1.z * d1.z) + ((d1.x * d1.x) + (d1.y * d1.y))); } - if (hurt_param_from_hit_end > lbColl_804D7A00) { + if (hurt_param_from_hit_end > 1.0) { hurt_param_from_hit_end = hit_param; - } else if (hurt_param_from_hit_end < lbColl_804D7A10) { - hurt_param_from_hit_end = lbColl_804D79F8; + } else if (hurt_param_from_hit_end < 0.0) { + hurt_param_from_hit_end = 0.0F; } hurt_param = hurt_param_from_hit_end; } @@ -1330,13 +1467,11 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, (hit_param_candidate = ((segment_dot * hurt_start_dot) - (hurt_len_sq * hit_start_dot)) / closest_denom); - hurt_param = ((hit_len_sq * hurt_start_dot) - + hurt_param = ((hurt_start_dot * hit_len_sq) - (segment_dot * hit_start_dot)) / closest_denom; - if ((hit_param_candidate > lbColl_804D7A00) || - (hit_param < lbColl_804D7A10) || - (hurt_param > lbColl_804D7A00) || - (hurt_param < lbColl_804D7A10)) + if ((hit_param_candidate > 1.0) || (hit_param < 0.0) || + (hurt_param > 1.0) || (hurt_param < 0.0)) { float hit_endpoint_dist_sq; float hit_endpoint_param; @@ -1345,8 +1480,8 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, // If the unconstrained solution leaves either segment, compare // the nearest endpoint projection from each axis. - if (hit_param < lbColl_804D7A10) { - hit_endpoint_param = lbColl_804D79F8; + if (hit_param < 0.0) { + hit_endpoint_param = 0.0F; hit_endpoint_dist_sq = lbColl_80005EBC(hurt_start, hurt_end, hit_start, &candidate_hurt_param); @@ -1355,8 +1490,8 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, hit_endpoint_dist_sq = lbColl_80005EBC( hurt_start, hurt_end, hit_end, &candidate_hurt_param); } - if (hurt_param < lbColl_804D7A10) { - hurt_endpoint_param = lbColl_804D79F8; + if (hurt_param < 0.0) { + hurt_endpoint_param = 0.0F; hurt_endpoint_dist_sq = lbColl_80005EBC( hit_start, hit_end, hurt_start, &candidate_hit_param); } else { @@ -1386,29 +1521,29 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, closest_dist_sq = (closest_delta_z * closest_delta_z) + ((closest_delta_y * closest_delta_y) + (closest_delta_x * closest_delta_x)); - if (closest_dist_sq > lbColl_804D79F8) { + if (closest_dist_sq > 0.0F) { volatile float sp38; closest_rsqrt_estimate = __frsqrte(closest_dist_sq); closest_rsqrt_step1 = - lbColl_804D7A18 * closest_rsqrt_estimate * + 0.5 * closest_rsqrt_estimate * -(((f64) closest_dist_sq * (closest_rsqrt_estimate * closest_rsqrt_estimate)) - - lbColl_804D7A20); - closest_rsqrt_step2 = lbColl_804D7A18 * closest_rsqrt_step1 * + 3.0); + closest_rsqrt_step2 = 0.5 * closest_rsqrt_step1 * -(((f64) closest_dist_sq * (closest_rsqrt_step1 * closest_rsqrt_step1)) - - lbColl_804D7A20); + 3.0); sp38 = (float) ((f64) closest_dist_sq * - (lbColl_804D7A18 * closest_rsqrt_step2 * + (0.5 * closest_rsqrt_step2 * -(((f64) closest_dist_sq * (closest_rsqrt_step2 * closest_rsqrt_step2)) - - lbColl_804D7A20))); + 3.0))); closest_dist = sp38; } else { closest_dist = closest_dist_sq; } - if ((closest_dist < lbColl_804D79F0) && (closest_dist > lbColl_804D79F4)) { + if ((closest_dist < 1e-5F) && (closest_dist > -1e-5F)) { is_zero_distance = 1; } else { is_zero_distance = 0; @@ -1429,23 +1564,27 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, local_dist_sq = (local_delta_z * local_delta_z) + ((local_delta_x * local_delta_x) + (local_delta_y * local_delta_y)); - if (local_dist_sq > lbColl_804D79F8) { + if (local_dist_sq > 0.0F) { volatile float sp34; local_rsqrt_estimate = __frsqrte(local_dist_sq); - local_rsqrt_step1 = lbColl_804D7A18 * local_rsqrt_estimate * - -(((f64) local_dist_sq * - (local_rsqrt_estimate * local_rsqrt_estimate)) - - lbColl_804D7A20); + { + f64 local_rsqrt_first_step = + 0.5 * local_rsqrt_estimate * + -(((f64) local_dist_sq * + (local_rsqrt_estimate * local_rsqrt_estimate)) - + 3.0); + local_rsqrt_step1 = local_rsqrt_first_step; + } local_rsqrt_step2 = - lbColl_804D7A18 * local_rsqrt_step1 * + 0.5 * local_rsqrt_step1 * -(((f64) local_dist_sq * (local_rsqrt_step1 * local_rsqrt_step1)) - - lbColl_804D7A20); + 3.0); sp34 = (float) ((f64) local_dist_sq * - (lbColl_804D7A18 * local_rsqrt_step2 * + (0.5 * local_rsqrt_step2 * -(((f64) local_dist_sq * (local_rsqrt_step2 * local_rsqrt_step2)) - - lbColl_804D7A20))); + 3.0))); local_dist = sp34; } else { local_dist = local_dist_sq; @@ -1606,8 +1745,8 @@ bool lbColl_80007BCC(HitCapsule* arg0, HitResult* shield_hit, void* arg2, { Vec3 sp74; Vec3 sp68; - MtxPtr var_r9; - float var_f1; + MtxPtr hurt_mtx; + float hit_radius; Mtx sp38; if (!shield_hit->skip_update_pos) { @@ -1619,35 +1758,35 @@ bool lbColl_80007BCC(HitCapsule* arg0, HitResult* shield_hit, void* arg2, } if (arg3 != 0) { arg0->hurt_coll_pos = shield_hit->pos; - arg0->coll_distance = lbColl_804D79F8; + arg0->coll_distance = 0.0F; return 1; } if (arg2 != NULL) { PSMTXConcat(arg2, HSD_JObjGetMtxPtr(shield_hit->bone), sp38); } if (arg2 != NULL) { - var_r9 = sp38; + hurt_mtx = sp38; } else { - var_r9 = HSD_JObjGetMtxPtr(shield_hit->bone); + hurt_mtx = HSD_JObjGetMtxPtr(shield_hit->bone); } if (arg0->x43_b1) { - var_f1 = arg0->scale; + hit_radius = arg0->scale; } else { - var_f1 = arg0->scale * arg4; - } - - return lbColl_80006E58(&arg0->x58, // hit_start - &arg0->x4C, // hit_end - &shield_hit->pos, // hurt_start - &shield_hit->pos, // hurt_end - &sp74, // hit_closest - &sp68, // hurt_closest - var_r9, // hurt_mtx - &arg0->hurt_coll_pos, // out_contact_pos - &arg0->coll_distance, // out_overlap - var_f1, // hit_radius - shield_hit->size, // hurt_radius - lbColl_804D7A34 * arg5 // broadphase_scale + hit_radius = arg0->scale * arg4; + } + + return lbColl_80006E58(&arg0->x58, // hit_start + &arg0->x4C, // hit_end + &shield_hit->pos, // hurt_start + &shield_hit->pos, // hurt_end + &sp74, // hit_closest + &sp68, // hurt_closest + hurt_mtx, // hurt_mtx + &arg0->hurt_coll_pos, // out_contact_pos + &arg0->coll_distance, // out_overlap + hit_radius, // hit_radius + shield_hit->size, // hurt_radius + 20.0F * arg5 // broadphase_scale ); } @@ -1680,8 +1819,8 @@ bool lbColl_80007ECC(HitCapsule* arg0, HurtCapsule* arg1, Mtx arg2, Vec3 sp70; Vec3 sp64; Mtx sp34; - float var_f1; - MtxPtr var_r9; + float hit_radius; + MtxPtr hurt_mtx; if (arg1->state == HurtCapsule_Enabled) { if (!arg1->skip_update_pos) { @@ -1697,19 +1836,19 @@ bool lbColl_80007ECC(HitCapsule* arg0, HurtCapsule* arg1, Mtx arg2, PSMTXConcat(arg2, HSD_JObjGetMtxPtr(arg1->bone), sp34); } if (arg2 != NULL) { - var_r9 = sp34; + hurt_mtx = sp34; } else { - var_r9 = HSD_JObjGetMtxPtr(arg1->bone); + hurt_mtx = HSD_JObjGetMtxPtr(arg1->bone); } if (arg0->x43_b1) { - var_f1 = arg0->scale; + hit_radius = arg0->scale; } else { - var_f1 = arg0->scale * hit_scl_y; + hit_radius = arg0->scale * hit_scl_y; } - return lbColl_80006E58( - &arg0->x58, &arg0->x4C, &arg1->a_pos, &arg1->b_pos, &sp70, &sp64, - var_r9, &arg0->hurt_coll_pos, &arg0->coll_distance, var_f1, - arg1->scale, lbColl_804D7A38 * hurt_scl_y); + return lbColl_80006E58(&arg0->x58, &arg0->x4C, &arg1->a_pos, + &arg1->b_pos, &sp70, &sp64, hurt_mtx, + &arg0->hurt_coll_pos, &arg0->coll_distance, + hit_radius, arg1->scale, 3.0F * hurt_scl_y); } return 0; } @@ -1721,7 +1860,7 @@ bool lbColl_8000805C(HitCapsule* arg0, HurtCapsule* arg1, Mtx arg2, s32 arg3, Vec3 sp68; Mtx sp38; MtxPtr var_r9; - float var_f1; + float hit_radius; if (arg1->state != HurtCapsule_Intangible) { if (!arg1->skip_update_pos) { @@ -1749,15 +1888,15 @@ bool lbColl_8000805C(HitCapsule* arg0, HurtCapsule* arg1, Mtx arg2, s32 arg3, var_r9 = HSD_JObjGetMtxPtr(arg1->bone); } if (arg0->x43_b1) { - var_f1 = arg0->scale; + hit_radius = arg0->scale; } else { - var_f1 = arg0->scale * arg4; + hit_radius = arg0->scale * arg4; } return lbColl_80006E58(&arg0->x58, &arg0->x4C, &arg1->a_pos, &arg1->b_pos, &sp74, &sp68, var_r9, &arg0->hurt_coll_pos, &arg0->coll_distance, - var_f1, arg1->scale, lbColl_804D7A38 * arg5); + hit_radius, arg1->scale, 3.0F * arg5); } return 0; } @@ -1956,8 +2095,6 @@ bool lbColl_80008820(HitCapsule* capsule, int type, void* victim) return true; } -GXColor const lbColl_804D7A50 = { 0 }; - void lbColl_800089B8(HitCapsule* hit, UNK_T arg1) { size_t i; @@ -2011,6 +2148,8 @@ void lbColl_80008D30(HitCapsule* arg0, lbColl_80008D30_arg1* arg1) arg0->unk_count = arg1->damage; } +GXColor const lbColl_804D7A50 = { 0 }; + void lbColl_80008DA4(GXColor* arg0, GXColor* arg1) { GXColor sp10; @@ -2157,8 +2296,8 @@ void lbColl_80008FC8(Vec3 arg0, Vec3 arg1, GXColor* arg2, GXColor* arg3, PSMTXConcat(sp44, sp74, sp74); GXSetCullMode(GX_CULL_BACK); GXClearVtxDesc(); - GXSetArray(GX_VA_POS, lbColl_803B9940, 6); - GXSetArray(GX_VA_NRM, lbColl_803B9AE0, 6); + GXSetArray(GX_VA_POS, lbColl_SpherePositions, 6); + GXSetArray(GX_VA_NRM, lbColl_SphereNormals, 6); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_TEX_ST, GX_RGBA4, 0xE); GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); @@ -2168,10 +2307,10 @@ void lbColl_80008FC8(Vec3 arg0, Vec3 arg1, GXColor* arg2, GXColor* arg3, HSD_MtxInverse(spD4, spD4); PSMTXTranspose(spD4, spD4); GXLoadNrmMtxImm(spD4, 0); - GXCallDisplayList(lbColl_803B9C80, 0x120); + GXCallDisplayList(lbColl_SphereDisplayList, 0x120); GXClearVtxDesc(); - GXSetArray(GX_VA_POS, lbColl_803B9940, 6); - GXSetArray(GX_VA_NRM, lbColl_803B9AE0, 6); + GXSetArray(GX_VA_POS, lbColl_SpherePositions, 6); + GXSetArray(GX_VA_NRM, lbColl_SphereNormals, 6); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_TEX_ST, GX_RGBA4, 0xE); GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); @@ -2181,11 +2320,11 @@ void lbColl_80008FC8(Vec3 arg0, Vec3 arg1, GXColor* arg2, GXColor* arg3, HSD_MtxInverse(spA4, spA4); PSMTXTranspose(spA4, spA4); GXLoadNrmMtxImm(spA4, 0); - GXCallDisplayList(lbColl_803B9C80, 0x120); + GXCallDisplayList(lbColl_SphereDisplayList, 0x120); if (!isSmall(var_f31)) { GXClearVtxDesc(); - GXSetArray(GX_VA_POS, lbl_803B9DA0, 6); - GXSetArray(GX_VA_NRM, lbColl_803B9EC0, 6); + GXSetArray(GX_VA_POS, lbColl_CylinderPositions, 6); + GXSetArray(GX_VA_NRM, lbColl_CylinderNormals, 6); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_TEX_ST, GX_RGBA4, 0xE); GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); @@ -2195,7 +2334,7 @@ void lbColl_80008FC8(Vec3 arg0, Vec3 arg1, GXColor* arg2, GXColor* arg3, HSD_MtxInverse(sp74, sp74); PSMTXTranspose(sp74, sp74); GXLoadNrmMtxImm(sp74, 0); - GXCallDisplayList(lbColl_803B9F20, 0xA0); + GXCallDisplayList(lbColl_CylinderDisplayList, 0xA0); } HSD_StateInvalidate(-1); HSD_StateInitTev(); @@ -2286,8 +2425,8 @@ void lbColl_800096B4(MtxPtr arg0, Vec3 arg1, Vec3 arg2, GXColor* arg3, PSMTXConcat(arg0, sp78, sp78); GXSetCullMode(GX_CULL_BACK); GXClearVtxDesc(); - GXSetArray(GX_VA_POS, lbColl_803B9940, 6); - GXSetArray(GX_VA_NRM, lbColl_803B9AE0, 6); + GXSetArray(GX_VA_POS, lbColl_SpherePositions, 6); + GXSetArray(GX_VA_NRM, lbColl_SphereNormals, 6); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_TEX_ST, GX_RGBA4, 0xE); GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); @@ -2297,10 +2436,10 @@ void lbColl_800096B4(MtxPtr arg0, Vec3 arg1, Vec3 arg2, GXColor* arg3, HSD_MtxInverse(spD8, spD8); PSMTXTranspose(spD8, spD8); GXLoadNrmMtxImm(spD8, 0); - GXCallDisplayList(lbColl_803B9C80, 0x120); + GXCallDisplayList(lbColl_SphereDisplayList, 0x120); GXClearVtxDesc(); - GXSetArray(GX_VA_POS, lbColl_803B9940, 6); - GXSetArray(GX_VA_NRM, lbColl_803B9AE0, 6); + GXSetArray(GX_VA_POS, lbColl_SpherePositions, 6); + GXSetArray(GX_VA_NRM, lbColl_SphereNormals, 6); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_TEX_ST, GX_RGBA4, 0xE); GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); @@ -2310,11 +2449,11 @@ void lbColl_800096B4(MtxPtr arg0, Vec3 arg1, Vec3 arg2, GXColor* arg3, HSD_MtxInverse(spA8, spA8); PSMTXTranspose(spA8, spA8); GXLoadNrmMtxImm(spA8, 0); - GXCallDisplayList(lbColl_803B9C80, 0x120); + GXCallDisplayList(lbColl_SphereDisplayList, 0x120); if (!isSmall(var_f31)) { GXClearVtxDesc(); - GXSetArray(GX_VA_POS, lbl_803B9DA0, 6); - GXSetArray(GX_VA_NRM, lbColl_803B9EC0, 6); + GXSetArray(GX_VA_POS, lbColl_CylinderPositions, 6); + GXSetArray(GX_VA_NRM, lbColl_CylinderNormals, 6); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_TEX_ST, GX_RGBA4, 0xE); GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); @@ -2324,7 +2463,7 @@ void lbColl_800096B4(MtxPtr arg0, Vec3 arg1, Vec3 arg2, GXColor* arg3, HSD_MtxInverse(sp78, sp78); PSMTXTranspose(sp78, sp78); GXLoadNrmMtxImm(sp78, 0); - GXCallDisplayList(lbColl_803B9F20, 0xA0); + GXCallDisplayList(lbColl_CylinderDisplayList, 0xA0); } HSD_StateInvalidate(-1); HSD_StateInitTev(); diff --git a/src/melee/lb/lbsnap.c b/src/melee/lb/lbsnap.c index 7a7387deda..153dde19cd 100644 --- a/src/melee/lb/lbsnap.c +++ b/src/melee/lb/lbsnap.c @@ -179,9 +179,8 @@ int lbSnap_8001D7B0(int chan, int index, int jndex) static inline u16 RGB565_TO_RGB5A3(u16 pixel) { u16 result = (pixel >> 1) & (RGB5A3_MASK_R | RGB5A3_MASK_G); - result = result | (pixel & RGB5A3_MASK_B); - result = result | RGB5A3_MASK_A; - return result; + result |= pixel & RGB5A3_MASK_B; + return result | RGB5A3_MASK_A; } static inline int lbSnap_GetTiledRemainder(int value) @@ -191,8 +190,9 @@ static inline int lbSnap_GetTiledRemainder(int value) static inline int lbSnap_GetTiledRGBOffset(int x, int y, int tile_stride) { - int tile_base = (x / 4) * tile_stride; - return ((tile_base + (y / 4)) << 5) + (lbSnap_GetTiledRemainder(x) * 8) + + int tile_x = x / 4; + int tile_base = tile_x * tile_stride; + return (((y / 4) + tile_base) << 5) + (lbSnap_GetTiledRemainder(x) * 8) + (lbSnap_GetTiledRemainder(y) * 2); } @@ -218,13 +218,14 @@ void lbSnap_8001DA5C(const u8* arg0) int ctr; for (dst_x = 0; dst_x < 32; dst_x++) { + int src_x_base = dst_x * 204 / 32; u8* dst_col = dst + ((dst_x % 4) * 8); int tile_column = lbSnap_GetTiledColumn(dst_x); int dst_y = 0; int src_y_accum = 0; u16 pixel; for (ctr = 0; ctr < 32; ctr++) { - int src_x = (dst_x * 204 / 32) + 138; + int src_x = src_x_base + 138; pixel = *(u16*) &arg0[lbSnap_GetTiledRGBOffset( src_x, src_y_accum / 64 + 96, 160)]; *(u16*) &dst_col[lbSnap_GetTiledYOff(tile_column, dst_y + 16)] = diff --git a/src/melee/mn/mndiagram.c b/src/melee/mn/mndiagram.c index 309965f9cc..1b2b6e5fd6 100644 --- a/src/melee/mn/mndiagram.c +++ b/src/melee/mn/mndiagram.c @@ -977,17 +977,18 @@ static inline s32 mnDiagram_FindPrevFighter(u8* sorted, static inline u8 mnDiagram_FindNextFighter(u8* sorted, SelectableCharacterKind cur) { - u8* p = sorted + cur; - SelectableCharacterKind found = cur; -loop: - found++; - p++; - if (found >= SELKIND_COUNT) { - return cur; - } - if (mn_IsFighterUnlocked(*p) == 0) { - goto loop; - } + u8* p; + SelectableCharacterKind found; + + found = cur; + p = sorted + cur; + do { + found++; + p++; + if (found >= SELKIND_COUNT) { + return cur; + } + } while (mn_IsFighterUnlocked(*p) == 0); return found; } @@ -1174,12 +1175,13 @@ static inline Diagram* mnDiagram_GetCurrentDiagramData(void) void mnDiagram_InputProc(HSD_GObj* gobj) { + u8* ptr2; u8* ptr; HSD_GObjProc* proc; u8 row_result; s32 i; - u8* ptr2; u8* ptr3; + u16* selection; s16 new_var; u8* sorted = mnDiagram_804A0750.sorted_fighters; Diagram* data = mnDiagram_GetCurrentDiagramData(); @@ -1228,8 +1230,10 @@ void mnDiagram_InputProc(HSD_GObj* gobj) mnDiagram_CreatePopup(col_result, row_result, 1); return; } - i = (u8) data->fighter_cursor_pos; - col = mn_804A04F0.hovered_selection; + selection = (u16*) &mn_804A04F0; + cursor_pos = data->fighter_cursor_pos; + col = (u8) * ++selection; + i = (u8) cursor_pos; ptr = sorted + i; goto fc_test; fc_outer: @@ -1256,7 +1260,7 @@ void mnDiagram_InputProc(HSD_GObj* gobj) } } - row2 = mn_804A04F0.hovered_selection >> 8; + row2 = *selection >> 8; i = data->fighter_cursor_pos >> 8; ptr = sorted + i; goto fr_test; @@ -2653,29 +2657,30 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) { int selkind; s32 count; - u8* pr; void** joint_data; int remr; HSD_JObj* jobj; Diagram* data = GET_DIAGRAM(arg0); int fighter_id; - u8* p2; + u8* sorted; u8 stack_obj[8]; HSD_JObj* sp_jobj; u8 stack_obj2[4]; HSD_JObj* jobj2; + HSD_JObj* row_jobj; HSD_JObj* sp_jobj2; u8 stack_obj3[12]; int idx; int remaining; + u8* p2; u8* p; - u8* sorted; mnDiagram_Assets* assets = (mnDiagram_Assets*) &mnDiagram_804A0750; u8* pr2; f32 x_spacing; f32 y_spacing; int fighter_kind; int i; + HSD_JObj* ref_jobj; (void) &stack_obj; (void) &stack_obj2; @@ -2719,8 +2724,9 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) HSD_JObjReqAnimAll(sp_jobj, (f32) (fighter_id & 0xFF)); HSD_JObjAnimAll(sp_jobj); jobj2 = jobj; - x_spacing = HSD_JObjGetTranslationX(data->jobjs[8]) - - HSD_JObjGetTranslationX(jobj = data->jobjs[7]); + x_spacing = + HSD_JObjGetTranslationX(data->jobjs[8]) - + HSD_JObjGetTranslationX(jobj = ref_jobj = data->jobjs[7]); HSD_JObjSetTranslateX(jobj2, x_spacing * i); HSD_JObjAddChild(data->jobjs[7], jobj2); } @@ -2732,6 +2738,7 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) sorted = mnDiagram_804A0750.sorted_fighters; count = mnDiagram_CountUnlockedFightersForHeaders(); if (count > i) { + u8* pr; remr = i; idx = arg1; pr = sorted + idx; @@ -2755,19 +2762,19 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) remr--; } row_found: - jobj = HSD_JObjLoadJoint(joint_data[0]); - HSD_JObjAddAnimAll(jobj, joint_data[1], joint_data[2], + row_jobj = HSD_JObjLoadJoint(joint_data[0]); + HSD_JObjAddAnimAll(row_jobj, joint_data[1], joint_data[2], joint_data[3]); - HSD_JObjReqAnimAll(jobj, 0.0f); - HSD_JObjAnimAll(jobj); - lb_80011E24(jobj, &sp_jobj2, 2, -1); + HSD_JObjReqAnimAll(row_jobj, 0.0f); + HSD_JObjAnimAll(row_jobj); + lb_80011E24(row_jobj, &sp_jobj2, 2, -1); fighter_kind = selkind & 0xFF; HSD_JObjReqAnimAll(sp_jobj2, (f32) fighter_kind); HSD_JObjAnimAll(sp_jobj2); y_spacing = HSD_JObjGetTranslationY(data->jobjs[10]) - HSD_JObjGetTranslationY(jobj2 = data->jobjs[9]); - HSD_JObjSetTranslateY(jobj, y_spacing * i); - HSD_JObjAddChild(data->jobjs[9], jobj); + HSD_JObjSetTranslateY(row_jobj, y_spacing * i); + HSD_JObjAddChild(data->jobjs[9], row_jobj); } } } diff --git a/src/melee/mn/mndiagram2.c b/src/melee/mn/mndiagram2.c index 90225529f8..ab2581541c 100644 --- a/src/melee/mn/mndiagram2.c +++ b/src/melee/mn/mndiagram2.c @@ -629,30 +629,41 @@ int mnDiagram2_GetStatValue(int is_name_mode, u8 stat_type, u8 entity_idx) void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, u8 row_idx, u8 entity_idx) { - Vec3 sp20; - Diagram2* data; + int mode; + u32 row; + f32 px; + f32 py; + f32 pz; + HSD_Text* text2; HSD_JObj* jobj; + int unit_glyph_id; + Diagram2* data; MnDiagram2RowLayout* base; HSD_Text* text; - HSD_Text* text2; f32 f31; - int mode = is_name_mode; + u8 str[8]; f32 f30; + Vec3 position; + u8 entity = entity_idx; + mode = is_name_mode; data = gobj->user_data; base = &mnDiagram2_803EEAD0; f31 = HSD_JObjGetTranslationY(data->row0_ref); f30 = HSD_JObjGetTranslationY(data->row1_ref) - f31; - lb_8000B1CC(data->row0_ref, &base->label_pos, &sp20); + lb_8000B1CC(data->row0_ref, &base->label_pos, &position); { - u32 r22 = row_idx; - f32 ny = -sp20.y; - f32 row_y_offset = -f30 * (f32) r22; - text = HSD_SisLib_803A5ACC(0, 1, sp20.x, ny + row_y_offset, sp20.z, - 320.0f, 240.0f); + f32 ny; + f32 row_y_offset; + + row = row_idx; + ny = -position.y; + row_y_offset = -f30 * (f32) row; + text = HSD_SisLib_803A5ACC(0, 1, position.x, ny + row_y_offset, + position.z, 320.0f, 240.0f); { data->row_labels[row_idx] = text; @@ -661,42 +672,37 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, HSD_SisLib_803A6368(text, base->label_ids[stat_type]); { - int r21 = base->unit_glyph_ids[stat_type]; - if (r21 != 0xFFFF) { - int var_r3; - lb_8000B1CC(data->row0_ref, &base->label_pos, &sp20); - text2 = HSD_SisLib_803A5ACC(0, 1, 12.0f + sp20.x, - -sp20.y + row_y_offset, - sp20.z, 1.0f, 1.0f); + unit_glyph_id = base->unit_glyph_ids[stat_type]; + if (unit_glyph_id != 0xFFFF) { + lb_8000B1CC(data->row0_ref, &base->label_pos, + &position); + text2 = HSD_SisLib_803A5ACC(0, 1, 12.0f + position.x, + -position.y + row_y_offset, + position.z, 1.0f, 1.0f); data->row_icons[row_idx] = text2; text2->default_alignment = 1; text2->text_color = mnDiagram2_804D4FBC; - var_r3 = mnDiagram2_IsDistanceStat(stat_type); - - if (var_r3 != 0 && + if (mnDiagram2_IsDistanceStat(stat_type) && mnDiagram_IsDistanceOverflow( - mnDiagram2_GetStatValue(mode, stat_type, - entity_idx))) + mnDiagram2_GetStatValue(is_name_mode, + stat_type, entity))) { HSD_SisLib_803A6368(text2, 0x7F); } else { - HSD_SisLib_803A6368(text2, r21); + HSD_SisLib_803A6368(text2, unit_glyph_id); } } } { - int var_r0 = mnDiagram2_IsIconOnlyStat(stat_type); - - if (var_r0 != 0 && - (u32) mnDiagram2_GetStatValue( - mode, stat_type, entity_idx) < SELKIND_COUNT) + if (mnDiagram2_IsIconOnlyStat(stat_type) && + (u32) mnDiagram2_GetStatValue(mode, stat_type, + entity) < SELKIND_COUNT) { - HSD_JObj* jobj = mnDiagram_CreateFighterIcon( - mnDiagram2_GetStatValue(mode, stat_type, - entity_idx), + jobj = mnDiagram_CreateFighterIcon( + mnDiagram2_GetStatValue(mode, stat_type, entity), 0); HSD_JObjSetTranslateX(jobj, base->icon_pos.x); HSD_JObjSetTranslateY(jobj, (f30 * (f32) row_idx) + @@ -709,24 +715,26 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, } { - u8 str[8]; HSD_Text* text3 = HSD_SisLib_803A6754(0, 1); data->row_values[row_idx] = text3; text3->font_size.x = 0.03f; text3->font_size.y = 0.035f; - lb_8000B1CC(data->icon_parent, &base->value_pos, &sp20); + lb_8000B1CC(data->icon_parent, &base->value_pos, + &position); { - f32 py = -sp20.y + row_y_offset; - text3->pos_x = sp20.x; + px = position.x; + py = -position.y + row_y_offset; + pz = position.z; + text3->pos_x = px; text3->pos_y = py; - text3->pos_z = sp20.z; + text3->pos_z = pz; } text3->text_color = mnDiagram2_804D4FBC; text3->default_alignment = 2; if (mnDiagram2_IsTimeStat(stat_type)) { - int val = mnDiagram2_GetStatValue(mode, stat_type, - entity_idx); + int val = + mnDiagram2_GetStatValue(mode, stat_type, entity); { u32 unsigned_val = (u32) val; if (unsigned_val > 0x927BF) { @@ -735,39 +743,31 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, } mnDiagram_FormatTime((char*) str, val); } else { - int var_r0_3 = mnDiagram2_IsDistanceStat(stat_type); - - if (var_r0_3 != 0) { + if (mnDiagram2_IsDistanceStat(stat_type)) { u32 val = mnDiagram2_GetStatValue(mode, stat_type, - entity_idx); + entity); val = mnDiagram_ConvertDistanceForDisplay(val); if (val > 0x98967F) { val = 0x98967F; } mnDiagram_IntToStr((char*) str, val); } else { - int var_r0_4 = - mnDiagram2_IsPercentageStat(stat_type); - - if (var_r0_4 != 0) { + if (mnDiagram2_IsPercentageStat(stat_type)) { int val = mnDiagram2_GetStatValue( - mode, stat_type, entity_idx); + mode, stat_type, entity); if ((u32) val > 0xF423F) { val = 0xF423F; } mnDiagram_FormatDecimalNumber((char*) str, val, 2); } else { - int var_r0_5 = - mnDiagram2_IsIconOnlyStat(stat_type); - - if (var_r0_5 != 0) { + if (mnDiagram2_IsIconOnlyStat(stat_type)) { str[0] = mnDiagram2_804D4FD0[0]; str[1] = mnDiagram2_804D4FD0[1]; str[2] = mnDiagram2_804D4FD0[2]; } else { int val = mnDiagram2_GetStatValue( - mode, stat_type, entity_idx); + mode, stat_type, entity); if ((u32) val > 0x98967F) { val = 0x98967F; } diff --git a/src/melee/mn/mndiagram3.c b/src/melee/mn/mndiagram3.c index 3f9ddd4805..3eb4a7f16a 100644 --- a/src/melee/mn/mndiagram3.c +++ b/src/melee/mn/mndiagram3.c @@ -72,8 +72,7 @@ HSD_GObj* mnDiagram3_804D6C20; void mnDiagram3_PopulateRankings(HSD_GObj* gobj) { u16* unit_glyph_ids; - Vec3 sp6C; - u32 max_distance; + u32 max_time; u8 sp58[0x10]; u8 sp48[0x10]; u8 fighter_rank[0x10]; @@ -95,14 +94,18 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) f32 icon_x_offset; float new_var; u8 stat_type; + u8 aggregate_rank; int i; HSD_Text* title_text; HSD_Text* value_text; HSD_JObj* icon; s32 entity; - u32 max_time; + Vec3 position; u32 max_percentage; + // Keep the stack frame aligned with the original local workspace. + PAD_STACK(8); + data = gobj->user_data; table = (mnDiagram3_DataTable*) &mnDiagram3_803EEC10; @@ -129,15 +132,16 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) } { - f32 row0_y = HSD_JObjGetTranslationY(row0); - f32 row1_y = HSD_JObjGetTranslationY(data->jobjs[7]); + divider = HSD_JObjGetTranslationY(row0); + row_spacing = HSD_JObjGetTranslationY(data->jobjs[7]); { + u32 max_distance; + unit_glyph_ids = table->stats.unit_glyph_ids; icon_x_offset = mnDiagram3_804DC010; - row_spacing = row1_y; (void) row_spacing; - row_spacing = row_spacing - row0_y; + row_spacing = row_spacing - divider; max_distance = 0x5F5E0FF; max_percentage = 0x98967F; divider = mnDiagram3_804DC008; @@ -146,21 +150,19 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) for (i = 0; i < 5; i++) { { - int is_name_mode = data->is_name_mode; - - if (is_name_mode != 0) { + if (data->is_name_mode != 0) { if (!mnDiagram2_IsIconOnlyStat(stat_type)) { if (i == 0) { lb_8000B1CC(data->jobjs[6], - &table->positions.xC, &sp6C); + &table->positions.xC, &position); title_text = HSD_SisLib_803A6754(0, 1); data->title_text = title_text; title_text->font_size.x = divider; title_text->font_size.y = divider; { - f32 y = sp6C.y; - f32 z = sp6C.z; - title_text->pos_x = sp6C.x; + f32 y = position.y; + f32 z = position.z; + title_text->pos_x = position.x; title_text->pos_y = (new_var = -y); title_text->pos_z = z; } @@ -189,15 +191,16 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) } if (i == 0) { - lb_8000B1CC(data->jobjs[6], &table->positions.x18, &sp6C); + lb_8000B1CC(data->jobjs[6], &table->positions.x18, + &position); value_text = HSD_SisLib_803A6754(0, 1); data->value_text = value_text; value_text->font_size.x = divider; value_text->font_size.y = divider; { - f32 y = sp6C.y; - f32 z = sp6C.z; - value_text->pos_x = sp6C.x; + f32 y = position.y; + f32 z = position.z; + value_text->pos_x = position.x; value_text->pos_y = (new_var = -y); value_text->pos_z = z; } @@ -205,25 +208,25 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) value_text->text_color = mn_804D4B64; } - if (mnDiagram2_IsIconOnlyStat(stat_type)) { + if (mnDiagram2_IsIconOnlyStat(stat_type) && + (aggregate_rank = (u8) i, + mnDiagram2_GetAggregatedFighterRank(sp48, stat_type, + aggregate_rank), + sp48[0] != 0x19)) + { { - u8 ii = (u8) i; - mnDiagram2_GetAggregatedFighterRank(sp48, stat_type, - ii); - } - if (sp48[0] == 0x19) { - continue; + u8 rank = (u16) i; + mnDiagram2_GetAggregatedFighterRank(fighter_rank, + stat_type, rank); } - mnDiagram2_GetAggregatedFighterRank(fighter_rank, - stat_type, (u8) i); icon = mnDiagram_CreateFighterIcon(fighter_rank[0], 0); HSD_JObjSetTranslateY(icon, row_spacing * (f32) i); HSD_JObjAddChild(data->jobjs[6], icon); { - u8 ii = (u8) i; + u8 rank = (u8) i; mnDiagram2_GetAggregatedFighterRank(sp28.bytes, - stat_type, ii); + stat_type, rank); } { int val = sp28.fields.xC; @@ -283,13 +286,14 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) continue; } - lb_8000B1CC(data->jobjs[6], &table->positions.x18, &sp6C); + lb_8000B1CC(data->jobjs[6], &table->positions.x18, + &position); { HSD_Text* icon_text; - f32 negated_y = -sp6C.y; + f32 negated_y = -position.y; icon_text = HSD_SisLib_803A5ACC( - 0, 1, icon_x_offset + sp6C.x, - neg_spacing * (f32) i + negated_y, sp6C.z, + 0, 1, icon_x_offset + position.x, + neg_spacing * (f32) i + negated_y, position.z, mnDiagram3_804DC014, mnDiagram3_804DC014); data->row_icons[i] = icon_text; icon_text->default_alignment = 1; @@ -473,41 +477,35 @@ void mnDiagram3_Create(int arg0) HSD_GObj_SetupProc(gobj, mnDiagram3_Think, 0); } -static inline HSD_JObj* mnDiagram3_GetSecondRow(Diagram3* data) -{ - return data->jobjs[9]; -} - -static inline void mnDiagram3_CreateRowLabels(HSD_GObj* labels_gobj) +static inline void mnDiagram3_SetupRows(HSD_JObj* jobj, Diagram3* popup_data, + int count) { - HSD_JObj* row0; + f32 spacing; f32 row_spacing; - f32 neg_spacing; int i; Vec3 pos; Diagram3* data; int scroll; u8 stat_idx; - data = labels_gobj->user_data; - row0 = data->jobjs[8]; + HSD_JObjSetTranslateZWithMtxDirty( + jobj, HSD_JObjGetTranslationZ(popup_data->jobjs[8])); + + data = mnDiagram3_804D6C20->user_data; scroll = data->scroll_offset; - row_spacing = HSD_JObjGetTranslationY(mnDiagram3_GetSecondRow(data)) - - HSD_JObjGetTranslationY(row0); - neg_spacing = row_spacing; + spacing = HSD_JObjGetTranslationY(data->jobjs[9]) - + HSD_JObjGetTranslationY(data->jobjs[8]); lb_8000B1CC(data->jobjs[8], &mnDiagram3_803EEC28.x0, &pos); - neg_spacing = -neg_spacing; row_spacing = 6.5f; - stat_idx = (u8) scroll; i = 0; do { f32 fi = (f32) i; HSD_Text* text = HSD_SisLib_803A5ACC(0, 1, pos.x - row_spacing, - neg_spacing * fi + -pos.y, pos.z, + -spacing * fi + -pos.y, pos.z, row_spacing, 240.0f); data->row_labels[i] = text; @@ -523,20 +521,26 @@ static inline void mnDiagram3_CreateRowLabels(HSD_GObj* labels_gobj) } limit = (u8) limit; - val = stat_idx + type_idx; + /// @remark Matching tactic: the self-assign keeps type_idx live + /// for MWCC register allocation. +#ifdef MUST_MATCH + val = (stat_idx = (u8) scroll) + (type_idx = type_idx); +#else + val = (stat_idx = (u8) scroll) + type_idx; +#endif if (val >= limit) { - val = val - limit; + limit = val - limit; } else { - val = (u8) val; + limit = (u8) val; } { - u16* entry = &mnDiagram3_803EEC4C.label_ids[(u8) val]; + u16* entry = &mnDiagram3_803EEC4C.label_ids[(u8) limit]; HSD_SisLib_803A6368(text, *entry); } } i++; - } while (i < 10); + } while (i < count); } static inline f32 mnDiagram3_GetPopupSpacing(HSD_JObj* popup_row, @@ -552,13 +556,29 @@ static inline f32 mnDiagram3_GetPopupY(HSD_JObj* popup_row, f32 row_spacing) HSD_JObjGetTranslationY(popup_row); } +static inline HSD_JObj* mnDiagram3_CreatePopup(Diagram3* data, + mnDiagram_ArchiveData* archive) +{ + HSD_GObj* popup; + HSD_JObj* popup_jobj; + + popup = GObj_Create(6, 7, 0x80); + data->popup_gobj = popup; + popup_jobj = mnDiagram3_LoadJoint(archive); + HSD_GObjObject_80390A70(popup, HSD_GObj_JObjKind, popup_jobj); + GObj_SetupGXLink(popup, HSD_GObj_JObjCallback, 4, 0x80); + HSD_JObjAddAnimAll(popup_jobj, archive->x4, archive->x8, archive->xC); + HSD_JObjReqAnimAll(popup_jobj, mnDiagram3_804DC00C); + HSD_JObjAnimAll(popup_jobj); + return popup_jobj; +} + void mnDiagram3_Init(void* arg0) { void* new_var; Diagram3* data; HSD_GObj* gobj; mnDiagram_ArchiveData* archive; - HSD_JObj* row0; f32 row_spacing; { @@ -577,34 +597,22 @@ void mnDiagram3_Init(void* arg0) { HSD_JObj* popup_jobj; - HSD_GObj* popup; data = gobj->user_data; - popup = GObj_Create(6, 7, 0x80); - data->popup_gobj = popup; - popup_jobj = mnDiagram3_LoadJoint(archive); - HSD_GObjObject_80390A70(popup, HSD_GObj_JObjKind, popup_jobj); - GObj_SetupGXLink(popup, HSD_GObj_JObjCallback, 4, 0x80); - HSD_JObjAddAnimAll(popup_jobj, archive->x4, archive->x8, archive->xC); - HSD_JObjReqAnimAll(popup_jobj, mnDiagram3_804DC00C); - HSD_JObjAnimAll(popup_jobj); + popup_jobj = mnDiagram3_CreatePopup(data, archive); new_var = gobj->user_data; data = new_var; - row0 = data->jobjs[8]; - row_spacing = mnDiagram3_GetPopupSpacing(row0, data); - - row0 = data->jobjs[8]; - HSD_JObjSetTranslateXWithMtxDirty(popup_jobj, - HSD_JObjGetTranslationX(row0)); - row0 = data->jobjs[8]; - row_spacing = mnDiagram3_GetPopupY(row0, row_spacing); + row_spacing = mnDiagram3_GetPopupSpacing(data->jobjs[8], data); + + HSD_JObjSetTranslateXWithMtxDirty( + popup_jobj, HSD_JObjGetTranslationX(data->jobjs[8])); + + row_spacing = mnDiagram3_GetPopupY(data->jobjs[8], row_spacing); HSD_JObjSetTranslateYWithMtxDirty(popup_jobj, row_spacing); - row0 = data->jobjs[8]; - HSD_JObjSetTranslateZWithMtxDirty(popup_jobj, - HSD_JObjGetTranslationZ(row0)); + + mnDiagram3_SetupRows(popup_jobj, data, 10); } - mnDiagram3_CreateRowLabels(mnDiagram3_804D6C20); mnDiagram3_PopulateRankings(mnDiagram3_804D6C20); @@ -636,18 +644,54 @@ static inline void mnDiagram3_ClearRowLabels(Diagram3* data) } while (++i < 10); } +static inline void mnDiagram3_RebuildRowLabels(Diagram3* data, char* base, + Vec3* pos, int count) +{ + f32 spacing; + int i; + int base_idx; + int v; + HSD_Text* text; + u8 base_idx_u8; + u8 i_u8; + u8 limit; + + base_idx = data->scroll_offset; + spacing = HSD_JObjGetTranslationY(data->jobjs[9]) - + HSD_JObjGetTranslationY(data->jobjs[8]); + lb_8000B1CC(data->jobjs[8], (Vec3*) (base + 0x18), pos); + base_idx_u8 = base_idx; + i = 0; + do { + text = HSD_SisLib_803A5ACC(0, 1, pos->x - 6.5f, + -spacing * (f32) i + -pos->y, pos->z, 6.5f, + 240.0f); + data->row_labels[i] = text; + i_u8 = i; + limit = (data->is_name_mode != 0) ? 0x18 : 0x15; + v = base_idx_u8 + i_u8; + if (v >= limit) { + v -= limit; + } else { + v = (u8) v; + } + HSD_SisLib_803A6368(text, ((u16*) (base + 0x3C))[(u8) v]); + i++; + } while (i < count); +} + +static inline void mnDiagram3_RefreshRankings(HSD_GObj* diagram_gobj) +{ + mnDiagram2_ClearDetailView(diagram_gobj); + mnDiagram3_PopulateRankings(diagram_gobj); +} + void mnDiagram3_HandleInput(HSD_GObj* gobj) { char* base = (char*) &mnDiagram3_803EEC10; Diagram3* data = mnDiagram3_804D6C20->user_data; u32 input = Menu_GetAllInputs(); - Vec3 spDC; - Vec3 spC0; - Vec3 spA4; - int i; - u8 limit; - int v; - PAD_STACK(64); + PAD_STACK(32); if (input & MenuInput_Back) { sfxBack(); @@ -678,6 +722,9 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) return; } if (input & (MenuInput_XButton | MenuInput_YButton)) { + Vec3 mode_label_pos; + PAD_STACK(12); + if (GetNameCount() == 0) { lbAudioAx_80024030(3); return; @@ -691,44 +738,9 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) } data = mnDiagram3_804D6C20->user_data; mnDiagram3_ClearRowLabels(data); - { - int base_idx; - u8 base_idx_u8; - u8 i_u8; - f32 spacing; - data = mnDiagram3_804D6C20->user_data; - base_idx = data->scroll_offset; - base_idx_u8 = base_idx; - spacing = HSD_JObjGetTranslationY(data->jobjs[9]) - - HSD_JObjGetTranslationY(data->jobjs[8]); - lb_8000B1CC(data->jobjs[8], (Vec3*) (base + 0x18), &spDC); - for (i = 0; i < 0xA; i++) { - HSD_Text* t = HSD_SisLib_803A5ACC(0, 1, spDC.x - 6.5f, - -spacing * (f32) i + -spDC.y, - spDC.z, 6.5f, 240.0f); - data->row_labels[i] = t; - i_u8 = i; - limit = (data->is_name_mode != 0) ? 0x18 : 0x15; - { - int tmp = base_idx_u8 + i_u8; - v = tmp; - } - if (v >= limit) { - v = v - limit; - } else { - v = (u8) v; - } - { - u8 idx = v; - HSD_SisLib_803A6368(t, ((u16*) (base + 0x3C))[idx]); - } - } - } - { - HSD_GObj* diagram_gobj = mnDiagram3_804D6C20; - mnDiagram2_ClearDetailView(diagram_gobj); - mnDiagram3_PopulateRankings(diagram_gobj); - } + data = mnDiagram3_804D6C20->user_data; + mnDiagram3_RebuildRowLabels(data, base, &mode_label_pos, 10); + mnDiagram3_RefreshRankings(mnDiagram3_804D6C20); return; } if (input & 1) { @@ -739,9 +751,9 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) f32 spacing; sfxMove(); data->cursor_row = data->cursor_row - 1; - cur = mnDiagram3_804D6C20->user_data; popup = data->popup_gobj->hsd_obj; n = data->cursor_row; + cur = mnDiagram3_804D6C20->user_data; spacing = mnDiagram3_GetRowSpacing(cur); HSD_JObjSetTranslateX(popup, HSD_JObjGetTranslationX(cur->jobjs[8])); @@ -750,54 +762,20 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) HSD_JObjGetTranslationY(cur->jobjs[8])); HSD_JObjSetTranslateZ(popup, HSD_JObjGetTranslationZ(cur->jobjs[8])); - { - HSD_GObj* diagram_gobj = mnDiagram3_804D6C20; - mnDiagram2_ClearDetailView(diagram_gobj); - mnDiagram3_PopulateRankings(diagram_gobj); - } + mnDiagram3_RefreshRankings(mnDiagram3_804D6C20); return; } if (data->scroll_offset != 0) { - int base_idx; - u8 base_idx_u8; - u8 i_u8; - f32 spacing; + Vec3 up_label_pos; + PAD_STACK(8); + sfxMove(); data->scroll_offset = data->scroll_offset - 1; data = mnDiagram3_804D6C20->user_data; mnDiagram3_ClearRowLabels(data); data = mnDiagram3_804D6C20->user_data; - base_idx = data->scroll_offset; - base_idx_u8 = base_idx; - spacing = HSD_JObjGetTranslationY(data->jobjs[9]) - - HSD_JObjGetTranslationY(data->jobjs[8]); - lb_8000B1CC(data->jobjs[8], (Vec3*) (base + 0x18), &spC0); - for (i = 0; i < 0xA; i++) { - HSD_Text* t = HSD_SisLib_803A5ACC(0, 1, spC0.x - 6.5f, - -spacing * (f32) i + -spC0.y, - spC0.z, 6.5f, 240.0f); - data->row_labels[i] = t; - i_u8 = i; - limit = (data->is_name_mode != 0) ? 0x18 : 0x15; - { - int tmp = base_idx_u8 + i_u8; - v = tmp; - } - if (v >= limit) { - v = v - limit; - } else { - v = (u8) v; - } - { - u8 idx = v; - HSD_SisLib_803A6368(t, ((u16*) (base + 0x3C))[idx]); - } - } - { - HSD_GObj* diagram_gobj = mnDiagram3_804D6C20; - mnDiagram2_ClearDetailView(diagram_gobj); - mnDiagram3_PopulateRankings(diagram_gobj); - } + mnDiagram3_RebuildRowLabels(data, base, &up_label_pos, 10); + mnDiagram3_RefreshRankings(mnDiagram3_804D6C20); } } else if (input & 2) { u32 down_limit; @@ -808,9 +786,9 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) f32 spacing; sfxMove(); data->cursor_row = data->cursor_row + 1; - cur = mnDiagram3_804D6C20->user_data; popup = data->popup_gobj->hsd_obj; n = data->cursor_row; + cur = mnDiagram3_804D6C20->user_data; spacing = mnDiagram3_GetRowSpacing(cur); HSD_JObjSetTranslateX(popup, HSD_JObjGetTranslationX(cur->jobjs[8])); @@ -819,55 +797,21 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) HSD_JObjGetTranslationY(cur->jobjs[8])); HSD_JObjSetTranslateZ(popup, HSD_JObjGetTranslationZ(cur->jobjs[8])); - { - HSD_GObj* diagram_gobj = mnDiagram3_804D6C20; - mnDiagram2_ClearDetailView(diagram_gobj); - mnDiagram3_PopulateRankings(diagram_gobj); - } + mnDiagram3_RefreshRankings(mnDiagram3_804D6C20); return; } down_limit = (data->is_name_mode != 0) ? 0x18 : 0x15; if ((u32) (data->scroll_offset + 0xA) < down_limit) { - int base_idx; - u8 base_idx_u8; - u8 i_u8; - f32 spacing; + Vec3 down_label_pos; + PAD_STACK(24); + sfxMove(); data->scroll_offset = data->scroll_offset + 1; data = mnDiagram3_804D6C20->user_data; mnDiagram3_ClearRowLabels(data); data = mnDiagram3_804D6C20->user_data; - base_idx = data->scroll_offset; - base_idx_u8 = base_idx; - spacing = HSD_JObjGetTranslationY(data->jobjs[9]) - - HSD_JObjGetTranslationY(data->jobjs[8]); - lb_8000B1CC(data->jobjs[8], (Vec3*) (base + 0x18), &spA4); - for (i = 0; i < 0xA; i++) { - HSD_Text* t = HSD_SisLib_803A5ACC(0, 1, spA4.x - 6.5f, - -spacing * (f32) i + -spA4.y, - spA4.z, 6.5f, 240.0f); - data->row_labels[i] = t; - i_u8 = i; - limit = (data->is_name_mode != 0) ? 0x18 : 0x15; - { - int tmp = base_idx_u8 + i_u8; - v = tmp; - } - if (v >= limit) { - v = v - limit; - } else { - v = (u8) v; - } - { - u8 idx = v; - HSD_SisLib_803A6368(t, ((u16*) (base + 0x3C))[idx]); - } - } - { - HSD_GObj* diagram_gobj = mnDiagram3_804D6C20; - mnDiagram2_ClearDetailView(diagram_gobj); - mnDiagram3_PopulateRankings(diagram_gobj); - } + mnDiagram3_RebuildRowLabels(data, base, &down_label_pos, 10); + mnDiagram3_RefreshRankings(mnDiagram3_804D6C20); } } } diff --git a/src/melee/mn/mnevent.c b/src/melee/mn/mnevent.c index 45d8d41f32..8cc151de32 100644 --- a/src/melee/mn/mnevent.c +++ b/src/melee/mn/mnevent.c @@ -474,128 +474,169 @@ void mnEvent_8024E524(s32 event_idx) mnEvent_ShowSelected(user_data, &jobj_09); } -static inline u8 mnEvent_GetPage(const MnEventData* data) +static inline void mnEvent_SetPageCursorY(MnEventData* cursor_data, + HSD_JObj** jobj_0A, + HSD_JObj** jobj_0C, + HSD_JObj** jobj_0B) { - return data->page; + u8 page; + HSD_JObj* tree; + f32 y_a; + f32 y_b; + + page = cursor_data->page; + tree = mnEvent_804D6C60->hsd_obj; + lb_80011E24(tree, jobj_0A, 0xA, -1); + lb_80011E24(tree, jobj_0C, 0xC, -1); + y_a = HSD_JObjGetTranslationY(*jobj_0A); + y_b = HSD_JObjGetTranslationY(*jobj_0C); + lb_80011E24(tree, jobj_0B, 0xB, -1); + HSD_JObjSetTranslateY(*jobj_0B, (f32) page * (y_b - y_a)); } void fn_8024D864(HSD_GObj* gobj) { u8 page; - f32 y_a; MnEventData* data; - HSD_JObj* jobj_09; + /// @remark These unreferenced declarations preserve MWCC allocation for + /// the inlined page-cursor helper and are excluded from non-matching + /// builds. +#ifdef MUST_MATCH HSD_JObj* tree; - HSD_JObj* jobj_0B; +#endif + HSD_JObj* up_jobj_0B; u64 inputs; - HSD_JObj* jobj_0C; - HSD_JObj* jobj_0A; + /// @remark Volatile is required for code matching but rejected by + /// clang-tidy. +#ifdef MUST_MATCH + HSD_JObj* volatile up_jobj_0C; + HSD_JObj* volatile up_jobj_0A; +#else + HSD_JObj* up_jobj_0C; + HSD_JObj* up_jobj_0A; +#endif +#ifdef MUST_MATCH f32 y_b; - PAD_STACK(0x70); - - if (mn_804D6BC8.cooldown != 0) { - mn_804D6BC8.cooldown -= 1; - mn_804D6BC8.x2 = 0; - mn_804D6BC8.x4 = 0; - return; - } - - inputs = mn_804A04F0.buttons = mn_80229624(4); - - if (inputs & MenuInput_Back) { - sfxBack(); - mn_804A04F0.entering_menu = 0; - mn_80229894(1, 1, 3); - return; - } - - if (mnEvent_804D6C64 != 0) { - mnEvent_804D6C64 -= 1; - return; - } +#endif - if (mnEvent_804D6C60 == NULL) { - mnEvent_8024E524(mnEvent_804D6C65); - } + { + HSD_JObj* down_jobj_0B; + HSD_JObj* down_jobj_0C; + /// @remark Volatile is required for code matching but rejected by + /// clang-tidy. +#ifdef MUST_MATCH + HSD_JObj* volatile down_jobj_0A; +#else + HSD_JObj* down_jobj_0A; +#endif + + if (mn_804D6BC8.cooldown != 0) { + mn_804D6BC8.cooldown -= 1; + mn_804D6BC8.x2 = 0; + mn_804D6BC8.x4 = 0; + return; + } - data = mnEvent_804D6C60->user_data; - if (inputs & MenuInput_Confirm) { - sfxForward(); - gm_801BEB74(data->first_event + data->page); - gm_801677E8(mn_802295AC()); - mn_80229860(GM_EVENT); - return; - } + inputs = mn_804A04F0.buttons = mn_80229624(4); - if (inputs & MenuInput_XButton) { - s32 max_events = mnEvent_8024CE74(); - if (data->first_event + 9 < max_events || - data->first_event != max_events) - { - sfxMove(); - if (data->first_event + 9 < max_events) { - data->first_event += 9; - } else { - data->first_event = max_events; - } - mnEvent_RefreshRows(data->first_event); - mnEvent_ShowSelected(data, &jobj_09); - } - } else if (inputs & MenuInput_YButton) { - if (data->first_event - 9 >= 0 || data->first_event != 0) { - sfxMove(); - if (data->first_event - 9 >= 0) { - data->first_event -= 9; - } else { - data->first_event = 0; - } - mnEvent_RefreshRows(data->first_event); - mnEvent_ShowSelected(data, &jobj_09); + if (inputs & MenuInput_Back) { + sfxBack(); + mn_804A04F0.entering_menu = 0; + mn_80229894(1, 1, 3); + return; } - } else if (inputs & MenuInput_Up) { - page = data->page; - if (page != 0) { - sfxMove(); - data->page -= 1; - tree = mnEvent_804D6C60->hsd_obj; - page = mnEvent_GetPage(data); - lb_80011E24(tree, &jobj_0A, 0xA, -1); - lb_80011E24(tree, &jobj_0C, 0xC, -1); - y_a = HSD_JObjGetTranslationY(jobj_0A); - y_b = HSD_JObjGetTranslationY(jobj_0C); - lb_80011E24(tree, &jobj_0B, 0xB, -1); - mnEvent_SetPageY(jobj_0B, page, y_a, y_b); - mnEvent_ShowSelected(data, &jobj_09); + + if (mnEvent_804D6C64 != 0) { + mnEvent_804D6C64 -= 1; return; } - if (data->first_event != 0) { - sfxMove(); - data->first_event -= 1; - mnEvent_RefreshRows(data->first_event); - mnEvent_ShowSelected(data, &jobj_09); + + if (mnEvent_804D6C60 == NULL) { + mnEvent_8024E524(mnEvent_804D6C65); } - } else if (inputs & MenuInput_Down) { - page = data->page; - if (page < 8) { - sfxMove(); - data->page += 1; - tree = mnEvent_804D6C60->hsd_obj; - page = mnEvent_GetPage(data); - lb_80011E24(tree, &jobj_0A, 0xA, -1); - lb_80011E24(tree, &jobj_0C, 0xC, -1); - y_a = HSD_JObjGetTranslationY(jobj_0A); - y_b = HSD_JObjGetTranslationY(jobj_0C); - lb_80011E24(tree, &jobj_0B, 0xB, -1); - mnEvent_SetPageY(jobj_0B, page, y_a, y_b); - mnEvent_ShowSelected(data, &jobj_09); + + data = mnEvent_804D6C60->user_data; + if (inputs & MenuInput_Confirm) { + sfxForward(); + gm_801BEB74(data->first_event + data->page); + gm_801677E8(mn_802295AC()); + mn_80229860(GM_EVENT); return; } - if (data->first_event < mnEvent_8024CE74()) { - sfxMove(); - data->first_event += 1; - mnEvent_RefreshRows(data->first_event); - mnEvent_ShowSelected(data, &jobj_09); + + if (inputs & MenuInput_XButton) { + HSD_JObj* jobj_09; + s32 max_events = mnEvent_8024CE74(); + if (data->first_event + 9 < max_events || + data->first_event != max_events) + { + sfxMove(); + if (data->first_event + 9 < max_events) { + data->first_event += 9; + } else { + data->first_event = max_events; + } + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); + } + } else if (inputs & MenuInput_YButton) { + HSD_JObj* jobj_09; + + if (data->first_event - 9 >= 0 || data->first_event != 0) { + sfxMove(); + if (data->first_event - 9 >= 0) { + data->first_event -= 9; + } else { + data->first_event = 0; + } + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); + } + PAD_STACK(4); + } else if (inputs & MenuInput_Up) { + page = data->page; + if (page != 0) { + HSD_JObj* jobj_09; + + sfxMove(); + data->page -= 1; + mnEvent_SetPageCursorY(data, &up_jobj_0A, &up_jobj_0C, + &up_jobj_0B); + mnEvent_ShowSelected(data, &jobj_09); + return; + } + if (data->first_event != 0) { + HSD_JObj* jobj_09; + + sfxMove(); + data->first_event -= 1; + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); + } + PAD_STACK(4); + } else if (inputs & MenuInput_Down) { + page = data->page; + if (page < 8) { + HSD_JObj* jobj_09; + + sfxMove(); + data->page += 1; + mnEvent_SetPageCursorY(data, &down_jobj_0A, &down_jobj_0C, + &down_jobj_0B); + mnEvent_ShowSelected(data, &jobj_09); + return; + } + if (data->first_event < mnEvent_8024CE74()) { + HSD_JObj* jobj_09; + + sfxMove(); + data->first_event += 1; + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); + } } + + PAD_STACK(0x34); } } diff --git a/src/melee/mn/mnitemsw.c b/src/melee/mn/mnitemsw.c index b7aa852c9a..cf14103138 100644 --- a/src/melee/mn/mnitemsw.c +++ b/src/melee/mn/mnitemsw.c @@ -450,7 +450,7 @@ static inline u8 mnItemSw_UpdateConfirmed(MnItemSwData* user_data, void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) { HSD_JObj* sp44; - u8 cursor; + u32 cursor; HSD_JObj* cjobj; MnItemSwData* data = gobj->user_data; struct MnItemSwTable* tbl = mnItemSw_GetTable(); @@ -461,20 +461,19 @@ void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) if (arg1_ != 0) { f32 y_spacing; f32 anim_val; + u8 old_cursor = data->cursor; - cursor = data->cursor; - - if (cursor == 0x1F || cursor == 0x20) { + if (old_cursor == 0x1F || old_cursor == 0x20) { arg1_ = mnItemSw_ReqFreqAnim(data->jobjs[3], tbl, data->x21, arg1_); } else { - HSD_JObj* jobj = mnItemSw_8023405C(data, cursor); + HSD_JObj* jobj = mnItemSw_8023405C(data, old_cursor); lb_80011E24(jobj, &sp44, 8, -1); HSD_JObjSetFlagsAll(sp44, JOBJ_HIDDEN); anim_val = mn_8022F298(sp44); lb_80011E24(jobj, &sp44, 3, -1); - HSD_JObjReqAnimAll( - sp44, (f32) mnItemSw_80233A98((s32) tbl->item_order[cursor])); + HSD_JObjReqAnimAll(sp44, (f32) mnItemSw_80233A98( + (s32) tbl->item_order[old_cursor])); HSD_JObjAnimAll(sp44); HSD_JObjReqAnimAll(sp44, tbl->x30[0]); mn_8022F3D8(sp44, 1, TOBJ_MASK); @@ -522,7 +521,7 @@ void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) (void) x; HSD_JObjSetTranslateX(cjobj, x); HSD_JObjSetTranslateY( - cjobj, y_spacing * (f32) (cursor - 0x10) + + cjobj, y_spacing * (f32) (s32) (cursor - 0x10) + HSD_JObjGetTranslationY(data->jobjs[4])); } } diff --git a/src/melee/mn/mnmainrule.c b/src/melee/mn/mnmainrule.c index 208651e658..8debb23559 100644 --- a/src/melee/mn/mnmainrule.c +++ b/src/melee/mn/mnmainrule.c @@ -66,9 +66,35 @@ struct mn_8022FEC8_jobj_ref_t { }; typedef union { - s32 packed; + u32 packed; u8 idx[4]; -} JObjIndices; +} JObjIndices4; + +typedef union { + u16 packed; + u8 idx[2]; +} JObjIndices2; + +typedef union { + u8 packed; + u8 idx[1]; +} JObjIndices1; + +typedef union { + struct { + JObjIndices4 hi; + JObjIndices1 lo; + } parts; + u8 idx[5]; +} JObjIndices5; + +typedef union { + struct { + JObjIndices4 hi; + JObjIndices2 lo; + } parts; + u8 idx[6]; +} JObjIndices6; union mn_802307F8_value_view { struct mn_802307F8_t fields; @@ -156,10 +182,6 @@ u8 mn_StockCountLimits[2] = { 1, 0x63 }; /// SIS text id for the rule value label when Mode is Stock Match. u8 mn_StockCountTextId = 0x2B; -extern u16 const mn_804DBDF8; -extern u32 const mn_804DBE10; -extern u16 const mn_804DBE14; - f32 mn_804D6BD8; HSD_GObj* mn_804D6BD0; @@ -186,6 +208,9 @@ void fn_8022F538(HSD_GObj* arg0) PAD_STACK(0x20); + /// @remark Keeps the unsigned conversion constant first in .sdata2. + (void) U32_TO_F32; + data = HSD_GObjGetUserData(mn_804D6BD0); buttons = mn_80229624(4); mn_804A04F0.buttons = buttons; @@ -398,6 +423,8 @@ void fn_8022F538(HSD_GObj* arg0) } } +JObjIndices2 const mn_804DBDF8 = { 0x0203 }; + void mn_8022FB88(u8 arg0, void* arg1) { struct mn_8022FB88_arg1_t* data = arg1; @@ -456,12 +483,16 @@ void mn_8022FB88(u8 arg0, void* arg1) HSD_JObjAnimAll(temp_r29_3); } +JObjIndices2 const mn_804DBE04 = { 0x0708 }; +JObjIndices4 const mn_804DBE08 = { 0x02030405 }; +JObjIndices1 const mn_804DBE0C = { 0x06 }; + void mn_8022FD18(u8 arg0) { UNUSED u8 pad[8]; struct mn_8022FB88_arg1_t* data = mn_804D6BD0->user_data; - u8 stock_digits[2] = { 7, 8 }; - u8 time_indices[5] = { 2, 3, 4, 5, 6 }; + JObjIndices2 stock_digits; + JObjIndices5 time_indices; HSD_JObj** jobjs; HSD_JObj* jobj; HSD_JObj* jobj2; @@ -474,16 +505,19 @@ void mn_8022FD18(u8 arg0) u8 val; data2 = data; + stock_digits = mn_804DBE04; + time_indices.parts.hi = mn_804DBE08; + time_indices.parts.lo = mn_804DBE0C; if (arg0 != 0) { i = 0; - ptr0 = stock_digits; + ptr0 = stock_digits.idx; do { HSD_JObjSetFlagsAll(data->x58[*ptr0], JOBJ_HIDDEN); i += 1; ptr0 += 1; } while (i < 2); i = 0; - ptr1 = time_indices; + ptr1 = time_indices.idx; do { HSD_JObjClearFlagsAll(data->x58[*ptr1], JOBJ_HIDDEN); i += 1; @@ -493,14 +527,14 @@ void mn_8022FD18(u8 arg0) return; } i = 0; - ptr2 = stock_digits; + ptr2 = stock_digits.idx; do { HSD_JObjClearFlagsAll(data->x58[*ptr2], JOBJ_HIDDEN); i += 1; ptr2 += 1; } while (i < 2); i = 0; - ptr3 = time_indices; + ptr3 = time_indices.idx; do { HSD_JObjSetFlagsAll(data->x58[*ptr3], JOBJ_HIDDEN); i += 1; @@ -638,53 +672,31 @@ void mn_80230198(HSD_GObj* gobj, HSD_JObj* jobj, u8 mode) extern MenuKindData mn_803EB6B0[]; -void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) +static inline void mn_80230274_InitOptionRoots(HSD_JObj** option_roots, + const u8* base, + struct mn_802307F8_t* data, + u8 count, s32* i) { - HSD_JObj* option_roots[8]; HSD_JObj** option_root; - HSD_JObj* roots[17]; - u8 pad_[4]; - u16 indices[17]; - u8 pad_2[4]; - AnimLoopSettings* settings; - HSD_JObj* jobj; - s32 i; - struct mn_802307F8_t* user_data; - s32 j; u8 j8; - u8 focus; - u8 count; - u8 selected; - u8* base; - s32 tail_i; - struct mn_802307F8_t* data; - - PAD_STACK(0x20); - - user_data = arg0->user_data; - count = mn_803EB6B0[13].selection_count; - base = mn_803EC600; - data = user_data; - for (i = 0; 0x11 > i; i++) { - indices[i] = i; - } + s32 j; + s32 visible; option_root = option_roots; - for (i = 0; i < count; option_root++, i++) { + for (*i = 0; *i < count; option_root++, (*i)++) { s32 valid; - if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) i == 4) { + if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) *i == 4) { valid = 0; } else { valid = 1; } if (valid) { - s32 visible; HSD_JObj* v; struct mn_8022FEC8_jobj_ref_t* p; - visible = valid - 1; + visible = 0; j = visible; - for (; j < (s32) (u8) i; j++) { + for (; j < (s32) (u8) *i; j++) { s32 valid2; j8 = j; if (gm_GetCurrentGameMode() == GM_TOURNAMENT && j8 == 4) { @@ -706,6 +718,37 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) *option_root = v; } } +} + +void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) +{ + HSD_JObj* option_roots[8]; + HSD_JObj* roots[17]; + u8 pad_[4]; + u16 indices[17]; + u8 pad_2[4]; + AnimLoopSettings* settings; + HSD_JObj* jobj; + s32 i; + struct mn_802307F8_t* user_data; + u8 focus; + u8 count; + u8 selected; + u8* base; + s32 tail_i; + struct mn_802307F8_t* data; + + PAD_STACK(0x20); + + user_data = arg0->user_data; + count = mn_803EB6B0[13].selection_count; + base = mn_803EC600; + data = user_data; + for (i = 0; 0x11 > i; i++) { + indices[i] = i; + } + + mn_80230274_InitOptionRoots(option_roots, base, data, count, &i); if (arg1 != 0) { u8 hovered; @@ -812,6 +855,9 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) } } +JObjIndices4 const mn_804DBE10 = { 0x02030506 }; +JObjIndices2 const mn_804DBE14 = { 0x0708 }; + void mn_802307F8(struct mn_802307F8_t* arg0, s32 arg1, s32 arg2) { HSD_Text* text; @@ -1060,10 +1106,6 @@ HSD_GObj* mn_80230E38(int arg0) u8 operand_pad[12]; u16 jobj_map[17]; HSD_JObj* jobj_parts[17]; - union { - u16 packed; - u8 idx[2]; - } damage_indices; HSD_GObj* gobj; struct mn_802307F8_t* user_data; u8 num_options; @@ -1078,9 +1120,9 @@ HSD_GObj* mn_80230E38(int arg0) HSD_JObj* value_jobj; StaticModelDesc* desc; HSD_JObj* root_jobj; - StaticModelDesc** desc_ptr; u16* sub_count_ptr; - PAD_STACK(12); + + PAD_STACK(4); selected = (u8) mn_804A04F0.hovered_selection; num_options = mn_803EB6B0[13].selection_count; @@ -1129,9 +1171,8 @@ HSD_GObj* mn_80230E38(int arg0) HSD_JObjAnim(anim_jobj); } - desc_ptr = (StaticModelDesc**) (mn_803EC600 + 0x1EC); sub_count_ptr = (u16*) (mn_803EC600 + 0x208); - for (i = 0; i < (s32) num_options; desc_ptr++, i++) { + for (i = 0; i < (s32) num_options; i++) { vis_before = mn_80230E38_CountVisible((u8) i); option_jobj = user_data->xC[((u16*) mn_803EC600)[(u8) vis_before]]; @@ -1185,7 +1226,7 @@ HSD_GObj* mn_80230E38(int arg0) HSD_JObjAddChild(option_jobj, cursor_jobj); if (i != 5 && i != 6) { - desc = *desc_ptr; + desc = ((StaticModelDesc**) (mn_803EC600 + 0x1EC))[i]; value_jobj = HSD_JObjLoadJoint(desc->joint); HSD_JObjAddAnimAll(value_jobj, desc->animjoint, desc->matanim_joint, desc->shapeanim_joint); @@ -1198,19 +1239,11 @@ HSD_GObj* mn_80230E38(int arg0) switch (i) { case 1: { - union { - struct { - u32 bytes4; - u16 bytes2; - } packed; - u8 idx[6]; - } time_indices; + JObjIndices6 time_indices; u8* index_ptr; - PAD_STACK(0x18); - - time_indices.packed.bytes4 = mn_804DBE10; - time_indices.packed.bytes2 = mn_804DBE14; + time_indices.parts.hi = mn_804DBE10; + time_indices.parts.lo = mn_804DBE14; index_ptr = time_indices.idx; for (j = 0; j < 6; j++, index_ptr++) { HSD_JObj* text = @@ -1227,11 +1260,14 @@ HSD_GObj* mn_80230E38(int arg0) break; } case 3: { + JObjIndices2 damage_indices; u8* index_ptr; u8 value = user_data->x5; HSD_JObj* digit_jobj; - damage_indices.packed = mn_804DBDF8; + PAD_STACK(0x24); + + damage_indices = mn_804DBDF8; index_ptr = damage_indices.idx; for (j = 0; j < 2; j++, index_ptr++) { HSD_JObj* text = @@ -1520,7 +1556,3 @@ bool mn_80231F80(u8 arg0) } return true; } - -u32 const mn_804DBE10 = 0x02030506; -u16 const mn_804DBE14 = 0x0708; -u16 const mn_804DBDF8 = 0x203; diff --git a/src/melee/mn/mnname.c b/src/melee/mn/mnname.c index 2661f96a99..8881ff1136 100644 --- a/src/melee/mn/mnname.c +++ b/src/melee/mn/mnname.c @@ -130,6 +130,11 @@ static inline s8 readNameTerminator(const volatile char* terminator) return *terminator; } +static inline bool signedCharactersEqual(s8 lhs, u8 rhs) +{ + return lhs == (s8) rhs; +} + static inline bool checkStringRest(const char* ptr, s8 terminator) { char c = " "[0]; // SJIS full-width space @@ -142,16 +147,27 @@ static inline bool checkStringRest(const char* ptr, s8 terminator) return true; } +static inline u8 unsignedCharacter(s32 character) +{ + return (u8) character; +} + s32 CompareNameStrings(char* str1, char* str2) { + union { + char* signed_characters; + u8* unsigned_characters; + } string1; + u8* unsigned_str1; s8 terminator = (s8) *mnName_StringTerminator; - char* p1 = str1; - char* p2 = str2; s32 i = 0; + + string1.signed_characters = str1; + unsigned_str1 = string1.unsigned_characters; while (true) { s8 ch1 = (s8) str1[i]; - if (terminator == ch1) { + if (signedCharactersEqual(terminator, (u8) ch1)) { if (checkStringRest(&str2[i & 0xFFFFFFFFFFFFFFFF], readNameTerminator(mnName_StringTerminator))) { @@ -163,23 +179,23 @@ s32 CompareNameStrings(char* str1, char* str2) { s8 ch2 = (s8) str2[i]; - if (*mnName_StringTerminator == ch2) { + if (signedCharactersEqual(*mnName_StringTerminator, + unsignedCharacter(ch2))) + { if (checkStringRest(&str1[i], terminator)) { return 0; } return 1; } - if ((u8) *p1 > (u8) ch2) { + if (unsigned_str1[i] > unsignedCharacter(ch2)) { return 1; } - if ((u8) *p1 < (u8) ch2) { + if (unsigned_str1[i] < unsignedCharacter(ch2)) { return 2; } } i++; - p2++; - p1++; } } @@ -1146,11 +1162,11 @@ static inline f32 mnName_80239A24_GetTextColumnWidth(HSD_GObj* gobj, void mnName_80239A24(HSD_GObj* gobj) { f32 text_row_height; - Vec3 text_position; + s32 row; HSD_JObj* jobj; HSD_JObj* ref_jobj; HSD_JObj* ref_jobj2; - s32 row; + Vec3 text_position; HSD_JObj* text_jobj0; HSD_JObj* text_jobj1; HSD_Text* text; @@ -1161,7 +1177,6 @@ void mnName_80239A24(HSD_GObj* gobj) s32 j; s32 i; MnNameArchive* archive = &mnName_804A06C0; - MenuFlow* flow = &mn_804A04F0; MnName_GObj* data = (MnName_GObj*) gobj; HSD_JObj* ref_jobj3; s32 count; @@ -1170,12 +1185,12 @@ void mnName_80239A24(HSD_GObj* gobj) u8 name_idx; PAD_STACK(8); - i = 0; - do { + for (i = 0; i < 0x18; i++) { jobj = HSD_JObjLoadJoint(archive->joint); HSD_JObjAddAnimAll(jobj, archive->anim_joint, archive->matanim_joint, archive->shapeanim_joint); - HSD_JObjReqAnimAll(jobj, (f32) ((u8) i == flow->hovered_selection)); + HSD_JObjReqAnimAll(jobj, + (f32) ((u8) i == mn_804A04F0.hovered_selection)); HSD_JObjAnimAll(jobj); col_width = HSD_JObjGetTranslationX( (HSD_JObj*) data->gobj.user_data_remove_func); @@ -1192,8 +1207,7 @@ void mnName_80239A24(HSD_GObj* gobj) HSD_JObjAddChild((HSD_JObj*) data->gobj.user_data_remove_func, child); } - i++; - } while (i < 0x18); + } text = HSD_SisLib_803A6754(0, 0); data->text = text; @@ -1216,8 +1230,7 @@ void mnName_80239A24(HSD_GObj* gobj) text_row_height = HSD_JObjGetTranslationY(text_jobj0); text_row_height = -(HSD_JObjGetTranslationY(text_jobj1) - text_row_height); - j = 0; - do { + for (j = 0; j < 0x18; j++) { MnName_GObj* global_data = (MnName_GObj*) mnName_804D6BF8->user_data; row = global_data->gobj.gx_link + ((u8) j / 6); count = GetNameCount_noinline(); @@ -1281,8 +1294,7 @@ void mnName_80239A24(HSD_GObj* gobj) HSD_SisLib_803A6B98(text, 0.0f, 0.0f, mnName_StringTerminator); } } - j++; - } while (j < 0x18); + } } void mnName_80239EBC(HSD_JObj* jobj, f32 y) diff --git a/src/melee/mn/mnnamenew.c b/src/melee/mn/mnnamenew.c index 22d3a0c907..c3c12afc3b 100644 --- a/src/melee/mn/mnnamenew.c +++ b/src/melee/mn/mnnamenew.c @@ -362,9 +362,10 @@ s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) Vec3 sp50; GXColor sp4C; GXColor sp48; - GXColor sp44; + GXColor color; MnNameNewDataLayout* layout; - HSD_JObj* key_jobj; + s32 j; + HSD_Text* text; HSD_JObj* ref1; HSD_JObj* ref2; char** str_table; @@ -378,7 +379,7 @@ s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) f32 font_x; f32 col_x; s32 i; - s32 j; + HSD_JObj* key_jobj; GXColor* color_ptr; FORCE_PAD_STACK(16); @@ -405,97 +406,93 @@ s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) if (arg0->key_text != NULL) { HSD_SisLib_803A5CC4(arg0->key_text); } - { - HSD_Text* text; + text = HSD_SisLib_803A6754(0, (s32) mn_804D6BB5); + arg0->key_text = text; - text = HSD_SisLib_803A6754(0, (s32) mn_804D6BB5); - arg0->key_text = text; - - key_jobj = arg0->jobjs[16]; + key_jobj = arg0->jobjs[16]; + if (key_jobj == NULL) { + key_jobj = NULL; + } else { + key_jobj = key_jobj->child; + } + for (i = 0; i < 50; i++) { + if (i == 0x2D) { + break; + } if (key_jobj == NULL) { key_jobj = NULL; } else { - key_jobj = key_jobj->child; - } - for (i = 0; i < 50; i++) { - if (i == 0x2D) { - break; - } - if (key_jobj == NULL) { - key_jobj = NULL; - } else { - key_jobj = key_jobj->next; - } + key_jobj = key_jobj->next; } + } + + lb_8000B1CC(key_jobj, &layout->x8CC, &sp50); + pos_x = sp50.x; + pos_y = -sp50.y; + pos_z = sp50.z; + text->pos_x = pos_x; + text->pos_y = pos_y; + text->pos_z = pos_z; + text->font_size.x = 0.03f; + text->font_size.y = 0.04f; + text->text_color = mnNameNew_804D4F6C; - lb_8000B1CC(key_jobj, &layout->x8CC, &sp50); - pos_x = sp50.x; - pos_y = -sp50.y; - pos_z = sp50.z; - text->pos_x = pos_x; - text->pos_y = pos_y; - text->pos_z = pos_z; - text->font_size.x = 0.03f; - text->font_size.y = 0.04f; - text->text_color = mnNameNew_804D4F6C; - - ref1 = arg0->jobjs[16]; + ref1 = arg0->jobjs[16]; + if (ref1 == NULL) { + ref1 = NULL; + } else { + ref1 = ref1->child; + } + for (i = 0; i < 50; i++) { + if (i == 0x28) { + break; + } if (ref1 == NULL) { ref1 = NULL; } else { - ref1 = ref1->child; - } - for (i = 0; i < 50; i++) { - if (i == 0x28) { - break; - } - if (ref1 == NULL) { - ref1 = NULL; - } else { - ref1 = ref1->next; - } + ref1 = ref1->next; } + } - base_x = HSD_JObjGetTranslationX(key_jobj); - x_range = HSD_JObjGetTranslationX(ref1) - base_x; + base_x = HSD_JObjGetTranslationX(key_jobj); + x_range = HSD_JObjGetTranslationX(ref1) - base_x; - ref2 = arg0->jobjs[16]; + ref2 = arg0->jobjs[16]; + if (ref2 == NULL) { + ref2 = NULL; + } else { + ref2 = ref2->child; + } + for (i = 0; i < 50; i++) { + if (i == 0x2E) { + break; + } if (ref2 == NULL) { ref2 = NULL; } else { - ref2 = ref2->child; - } - for (i = 0; i < 50; i++) { - if (i == 0x2E) { - break; - } - if (ref2 == NULL) { - ref2 = NULL; - } else { - ref2 = ref2->next; - } + ref2 = ref2->next; } + } - base_y = HSD_JObjGetTranslationY(key_jobj); - y_range = -(HSD_JObjGetTranslationY(ref2) - base_y); - - j = 0; - for (; j < 0x32; j++) { - font_x = text->font_size.x; - col_x = (f32) (9 - (j / 5)) * x_range; - HSD_SisLib_803A6B98(text, col_x / font_x, - ((f32) (j % 5) * y_range) / text->font_size.y, - str_table[j], font_x, col_x); - if (j == (s32) mn_804A04F0.hovered_selection) { - color_ptr = &sp48; - } else { - color_ptr = &sp4C; - } - mnNameNew_SetKeyColor(text, j, color_ptr, &sp44); - } + base_y = HSD_JObjGetTranslationY(key_jobj); + y_range = -(HSD_JObjGetTranslationY(ref2) - base_y); - return (s32) text; + j = 0; + for (; j < 0x32; j++) { + font_x = text->font_size.x; + col_x = (f32) (9 - (j / 5)) * x_range; + HSD_SisLib_803A6B98(text, col_x / font_x, + ((f32) (j % 5) * y_range) / text->font_size.y, + str_table[j]); + if (j == (s32) mn_804A04F0.hovered_selection) { + color_ptr = &sp48; + } else { + color_ptr = &sp4C; + } + mnNameNew_SetKeyColor(text, j, color_ptr, &color); } + + return (s32) text; } s32 mnNameNew_8023BAA8(NameNewEntry* arg0, s32 arg1, u8 arg2) @@ -585,14 +582,16 @@ static inline s32 PickAutoNameInline(HSD_GObj* arg0) s32 count; s32 pick; s32 dup; + s32 i; + u8 tmp; + s32 name_idx; + s8 ch; u8** name_ptr; char* text; + char* text_start; s32 char_idx; - u8 ch; s8 null_ch; - u8 tmp; - s32 name_idx; - s32 i; + s8 list_null_ch; data = arg0->user_data; cur_text = mnNameNew_CurrentNameText; @@ -600,10 +599,10 @@ static inline s32 PickAutoNameInline(HSD_GObj* arg0) do { dup = 0; do { - null_ch = (s8) *mnNameNew_NullCharacter; + list_null_ch = (s8) *mnNameNew_NullCharacter; count = 0; names = AutoNamesList; - while (null_ch != (s8) * *names) { + while (list_null_ch != (s8) * *names) { names++; count++; } @@ -626,7 +625,7 @@ static inline s32 PickAutoNameInline(HSD_GObj* arg0) name_idx = 0; char_idx = name_idx; cur_text[0] = *mnNameNew_NullCharacter; - text = cur_text; + text = text_start = cur_text; cur_text[3] = *mnNameNew_NullCharacter; cur_text[6] = *mnNameNew_NullCharacter; cur_text[9] = *mnNameNew_NullCharacter; @@ -643,14 +642,19 @@ static inline s32 PickAutoNameInline(HSD_GObj* arg0) text += 3; } - cur_text[name_idx * 3] = null_ch; + text_start[name_idx * 3] = null_ch; - tmp = data->auto_history[0]; - data->auto_history[0] = (u8) pick; - for (i = 1; i < 5; i++) { - u8 next = data->auto_history[i]; - data->auto_history[i] = tmp; - tmp = next; + { + u8* history = data->auto_history; + + tmp = history[0]; + history[0] = (u8) pick; + for (i = 1; i < 5; i++) { + u8* entry = &history[i]; + u8 next = *entry; + *entry = tmp; + tmp = next; + } } return (s32) null_ch; @@ -882,22 +886,18 @@ void mnNameNew_GlyphVariantInput(void) #endif void mnNameNew_MainInput(HSD_GObj* arg0) { - u8 sp24[16]; - s32 occupied_slots; + char name_buffer[16]; NameNewEntry* data; MnNameNewDataLayout* layout; u32 buttons; char* name_text; - s32 key_off; - u8* key_char; + char* key_char; s8 null_char; + s32 n; char* src; - u8* dest; + char* dest; s32 len; u8 cursor; - s32 n; - - PAD_STACK(12); name_text = mnNameNew_CurrentNameText; { @@ -912,14 +912,13 @@ void mnNameNew_MainInput(HSD_GObj* arg0) } buttons = (mn_804A04F0.buttons = mn_80229624((u32) mnNameNew_PortInUse)); - occupied_slots = 0; + n = 0; if (buttons & 0x200) { u16 sel = mn_804A04F0.hovered_selection; if (sel < 0x32U) { if (data->mode != 2 && sel < 0x32U) { - key_off = (((u8) sel) << 4) & 0xFF0; - key_char = *(u8**) ((u8*) layout->lower_glyphs + key_off); + key_char = layout->lower_glyphs[(u8) sel][0]; if (" "[0] == (s8) key_char[0] && (s8) " "[1] == (s8) key_char[1]) { @@ -933,9 +932,10 @@ void mnNameNew_MainInput(HSD_GObj* arg0) n = 0; { u16 sel2 = mn_804A04F0.hovered_selection; - u8** ptrs = (u8**) ((u8*) layout->lower_glyphs + - ((((u8) sel2) << 4) & 0xFF0)); - null_char = (s8) *mnNameNew_NullCharacter; + GlyphRow* glyphs = layout->lower_glyphs; + char** ptrs = glyphs[(u8) sel2]; + null_char = + (s8) * ((GlyphChar*) mnNameNew_NullCharacter); while ((s8) *ptrs[0] != null_char) { ptrs++; n++; @@ -953,7 +953,8 @@ void mnNameNew_MainInput(HSD_GObj* arg0) cursor = data->cursor_pos; name_text[cursor * 3] = " "[0]; name_text[cursor * 3 + 1] = " "[1]; - name_text[cursor * 3 + 2] = *mnNameNew_NullCharacter; + name_text[cursor * 3 + 2] = + *((GlyphChar*) mnNameNew_NullCharacter); lbAudioAx_80024030(1); if (data->cursor_pos < 3) { data->cursor_pos = (u8) (data->cursor_pos + 1); @@ -1019,18 +1020,22 @@ void mnNameNew_MainInput(HSD_GObj* arg0) (void) cursor; { char* slot = &name_text[cursor * 3]; - if ((s8) *mnNameNew_NullCharacter != (s8) slot[0]) { - occupied_slots = 1; + if ((s8) * ((GlyphChar*) mnNameNew_NullCharacter) == + (s8) slot[0]) + { + n = 0; + } else { + n = 1; } - if (occupied_slots != 0) { - slot[0] = *mnNameNew_NullCharacter; + if (n != 0) { + slot[0] = *((GlyphChar*) mnNameNew_NullCharacter); mnNameNew_8023CE4C(); return; } } if (cursor != 0) { name_text[(u8) (cursor - 1) * 3] = - *mnNameNew_NullCharacter; + *((GlyphChar*) mnNameNew_NullCharacter); data->cursor_pos = (u8) (data->cursor_pos - 1); mnNameNew_8023CE4C(); return; @@ -1041,89 +1046,91 @@ void mnNameNew_MainInput(HSD_GObj* arg0) case 0x37: lbAudioAx_80024030(1); PickAutoName(mnNameNew_804D6C08); - null_char = (s8) *mnNameNew_NullCharacter; + null_char = (s8) * ((GlyphChar*) mnNameNew_NullCharacter); { char* p = name_text; if (null_char != (s8) *p) { - occupied_slots = 1; - p += 3; - if (null_char != (s8) *p) { - occupied_slots = 2; - p += 3; - if (null_char != (s8) *p) { - occupied_slots = 3; - p += 3; - if (null_char != (s8) *p) { - occupied_slots = 4; + n = 1; + if (null_char != (s8) * (p += 3)) { + n = 2; + if (null_char != (s8) * (p += 3)) { + n = 3; + if (null_char != (s8) * (p += 3)) { + n = 4; } } } } } - if (occupied_slots == 4) { + if (n == 4) { data->cursor_pos = 3; } else { - data->cursor_pos = (u8) occupied_slots; + data->cursor_pos = (u8) n; } mnNameNew_8023CE4C(); return; case 0x38: case 0x39: - dest = sp24; + dest = name_buffer; len = 0; { char* src_iter; - u8* dest_iter; + char* dest_iter; - src = name_text; - src_iter = src; + src_iter = (src = name_text); dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; + for (; (s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter; dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src += 3; - src_iter = src; + src_iter = (src += 3); dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; + for (; (s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter; dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src += 3; - src_iter = src; + src_iter = (src += 3); dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; + for (; (s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter; dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src += 3; - src_iter = src; + src_iter = (src += 3); dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; - dest_iter++, dest++, len++, src_iter++) + while ((s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter) { *dest_iter = *src_iter; + dest_iter++; + dest++; + len++; + src_iter++; } } - sp24[len] = (u8) *mnNameNew_NullCharacter; + name_buffer[len] = *mnNameNew_NullCharacter; - if ((s8) name_text[0] == (s8) *mnNameNew_NullCharacter) { + if ((s8) name_text[0] == + (s8) * ((GlyphChar*) mnNameNew_NullCharacter)) + { n = 1; } else { n = 0; } if (n == 0 && NameContainsOnlySpaces() == 0 && - IsNameUnique((char*) sp24) == 0 && - IsNameNotAllowed((char*) sp24) == 0) + IsNameUnique(name_buffer) == 0 && + IsNameNotAllowed(name_buffer) == 0) { n = 1; } else { @@ -1144,148 +1151,152 @@ void mnNameNew_MainInput(HSD_GObj* arg0) return; } } - } else { - if (buttons & 0x100) { - if (mn_804A04F0.hovered_selection == 0x38 || - mn_804A04F0.hovered_selection == 0x39) - { - dest = sp24; - len = 0; + } else if (buttons & 0x100) { + if (mn_804A04F0.hovered_selection == 0x38 || + mn_804A04F0.hovered_selection == 0x39) + { + dest = name_buffer; + len = 0; + { + char* src_iter; + char* dest_iter; + + src_iter = (src = name_text); + dest_iter = dest; + for (; (s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter; + dest_iter++, dest++, len++, src_iter++) { - char* src_iter; - u8* dest_iter; - - src = name_text; - src_iter = src; - dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; - dest_iter++, dest++, len++, src_iter++) - { - *dest_iter = *src_iter; - } - - src += 3; - src_iter = src; - dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; - dest_iter++, dest++, len++, src_iter++) - { - *dest_iter = *src_iter; - } - - src += 3; - src_iter = src; - dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; - dest_iter++, dest++, len++, src_iter++) - { - *dest_iter = *src_iter; - } - - src += 3; - src_iter = src; - dest_iter = dest; - for (; (s8) *mnNameNew_NullCharacter != (s8) *src_iter; - dest_iter++, dest++, len++, src_iter++) - { - *dest_iter = *src_iter; - } + *dest_iter = *src_iter; } - sp24[len] = (u8) *mnNameNew_NullCharacter; - - if ((s8) name_text[0] == (s8) *mnNameNew_NullCharacter) { - n = 1; - } else { - n = 0; + src_iter = (src += 3); + dest_iter = dest; + for (; (s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter; + dest_iter++, dest++, len++, src_iter++) + { + *dest_iter = *src_iter; } - if (n == 0 && NameContainsOnlySpaces() == 0 && - IsNameUnique((char*) sp24) == 0 && - IsNameNotAllowed((char*) sp24) == 0) + + src_iter = (src += 3); + dest_iter = dest; + for (; (s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter; + dest_iter++, dest++, len++, src_iter++) { - n = 1; - } else { - n = 0; + *dest_iter = *src_iter; } - if (n != 0) { - lbAudioAx_80024030(1); - CreateNameAtIndex((s32) data->name_index); - WriteCharactersForNameAtIndex(data->name_index, - (s32) mn_802295AC()); - mnNameNew_8023B224(1U); - return; + + src_iter = (src += 3); + dest_iter = dest; + while ((s8) * ((GlyphChar*) mnNameNew_NullCharacter) != + (s8) *src_iter) + { + *dest_iter = *src_iter; + dest_iter++; + dest++; + len++; + src_iter++; } - lbAudioAx_80024030(3); - return; } - mn_804A04F0.hovered_selection = 0x39; - return; - } - if (buttons & 0xC0) { - lbAudioAx_80024030(1); - if (buttons & 0x40) { - if (data->mode != 0) { - data->mode = (u8) (data->mode - 1); - } else { - data->mode = 2; - } + + name_buffer[len] = *mnNameNew_NullCharacter; + + if ((s8) name_text[0] == + (s8) * ((GlyphChar*) mnNameNew_NullCharacter)) + { + n = 1; } else { - if (data->mode < 2) { - data->mode = (u8) (data->mode + 1); - } else { - data->mode = 0; - } - } - mnNameNew_KeySetup(data, data->mode); - mnNameNew_8023B0F8(mnNameNew_804D6C08, - (u8) mn_804A04F0.hovered_selection); - mnNameNew_8023B314(data, (s32) mn_804A04F0.hovered_selection); - return; - } - if (buttons & 0x20) { - lbAudioAx_80024030(0); - null_char = (s8) *mnNameNew_NullCharacter; - if (null_char == (s8) name_text[0]) { - occupied_slots = 1; - } - if (occupied_slots != 0) { - mnNameNew_8023B224(0U); - return; + n = 0; } + if (n == 0 && NameContainsOnlySpaces() == 0 && + IsNameUnique(name_buffer) == 0 && + IsNameNotAllowed(name_buffer) == 0) { - u8 cursor_pos = data->cursor_pos; - cursor = cursor_pos; - } - if (null_char != (s8) name_text[cursor * 3]) { n = 1; } else { n = 0; } if (n != 0) { - name_text[cursor * 3] = *mnNameNew_NullCharacter; - mnNameNew_8023CE4C(); - return; - } - if (cursor != 0) { - name_text[(u8) (cursor - 1) * 3] = *mnNameNew_NullCharacter; - data->cursor_pos = (u8) (data->cursor_pos - 1); - mnNameNew_8023CE4C(); + lbAudioAx_80024030(1); + CreateNameAtIndex((s32) data->name_index); + WriteCharactersForNameAtIndex(data->name_index, + (s32) mn_802295AC()); + mnNameNew_8023B224(1U); return; } lbAudioAx_80024030(3); return; } + mn_804A04F0.hovered_selection = 0x39; + return; + } else if (buttons & 0xC0) { + lbAudioAx_80024030(1); + if (buttons & 0x40) { + u8 mode = data->mode; + + if (mode != 0) { + data->mode = (u8) (data->mode - 1); + } else { + data->mode = 2; + } + } else { + if (data->mode < 2) { + data->mode = (u8) (data->mode + 1); + } else { + data->mode = 0; + } + } + mnNameNew_KeySetup(data, data->mode); + mnNameNew_8023B0F8(mnNameNew_804D6C08, + (u8) mn_804A04F0.hovered_selection); + mnNameNew_8023B314(data, (s32) mn_804A04F0.hovered_selection); + return; + } else if (buttons & 0x20) { + lbAudioAx_80024030(0); + if ((s8) name_text[0] == (s8) * ((GlyphChar*) mnNameNew_NullCharacter)) + { + n = 1; + } + if (n != 0) { + mnNameNew_8023B224(0U); + return; + } { - s32 buttons_arg = (s32) buttons; - u8 new_sel = mnNameNew_8023BAA8( - data, buttons_arg, (u8) mn_804A04F0.hovered_selection); - if ((s32) new_sel != (s32) mn_804A04F0.hovered_selection) { - lbAudioAx_80024030(2); - mn_804A04F0.hovered_selection = (u16) new_sel; - if (new_sel < 0x32) { - data->last_key_sel = new_sel; - } + u8 cursor_pos = data->cursor_pos; + cursor = cursor_pos; + } + if ((s8) * ((GlyphChar*) mnNameNew_NullCharacter) == + (s8) name_text[cursor * 3]) + { + n = 0; + } else { + n = 1; + } + if (n != 0) { + name_text[cursor * 3] = *((GlyphChar*) mnNameNew_NullCharacter); + mnNameNew_8023CE4C(); + return; + } + if (cursor != 0) { + name_text[(u8) (cursor - 1) * 3] = + *((GlyphChar*) mnNameNew_NullCharacter); + data->cursor_pos = (u8) (data->cursor_pos - 1); + mnNameNew_8023CE4C(); + return; + } + lbAudioAx_80024030(3); + return; + } else { + u8 new_sel = mnNameNew_8023BAA8(data, (s32) buttons, + (u8) mn_804A04F0.hovered_selection); + if ((s32) new_sel != (s32) mn_804A04F0.hovered_selection) { + lbAudioAx_80024030(2); + mn_804A04F0.hovered_selection = (u16) new_sel; + if (new_sel < 0x32) { + data->last_key_sel = new_sel; } } } @@ -1420,8 +1431,6 @@ void fn_8023D0F8(void* arg0) s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u16 arg1, u8 arg2, s32 arg3) { - GXColor* glyph_color_ptr; - char* str; f32 pos_z; f32 y_range; s32 i; @@ -1464,8 +1473,9 @@ s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u16 arg1, u8 arg2, s32 arg3) AddCharacterToName_getGlyphs(layout->upper_glyphs, (u8) arg3); table_lower = AddCharacterToName_getGlyphs(layout->lower_glyphs, (u8) arg3); - (void) table_lower; - for (i = 0; i < (s32) (u8) arg1; i++) { + arg1 = (u8) arg1; + for (i = 0; i < (s32) arg1; i++) { + char* str; if ((u8) (arg3 - 0x30) <= 1U) { if ((i % 2) != 0) { str = table_upper[i / 2]; @@ -1488,9 +1498,7 @@ s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u16 arg1, u8 arg2, s32 arg3) } else { color_ptr = &mnNameNew_804D4F74; } - glyph_color = *color_ptr; - glyph_color_ptr = &glyph_color; - HSD_SisLib_803A74F0(text, i, glyph_color_ptr); + mnNameNew_SetKeyColor(text, i, color_ptr, &glyph_color); } arg0->text = text; return (s32) text; @@ -2065,7 +2073,7 @@ void* mnNameNew_804A0710[4]; void* mnNameNew_804A0700[4]; void* mnNameNew_804A06F0[4]; -static u8 mnNameNew_804D4F98[8] = { 0 }; +static u8 mnNameNew_804D4F98[8] ATTRIBUTE_ALIGN(8) = { 0 }; char* mnNameNew_803EE720[] = { (char*) mnNameNew_804D4F98 }; char* mnNameNew_803EE724[] = { (char*) mnNameNew_804D4F98 }; diff --git a/src/melee/mn/mnruleplus.c b/src/melee/mn/mnruleplus.c index 8df2c66e6b..97b4abee78 100644 --- a/src/melee/mn/mnruleplus.c +++ b/src/melee/mn/mnruleplus.c @@ -355,36 +355,9 @@ void mn_802324E4(u8 time_limit, MenuRulesPlusData* data) mnRulePlus_AnimZeros(jobjs); } -static inline void mn_80232660_inline(HSD_JObj* jobj) -{ - AnimLoopSettings* settings; - AnimLoopSettings* p294; - AnimLoopSettings* p270; - f32 frame; - s32 i; - - frame = mn_8022F298(jobj); - - p294 = mn_803ED294; - p270 = mn_803ED270; - - for (i = 0; i < 3; i++) { - settings = p294; - if (p294->start_frame <= frame && frame <= p294->end_frame) { - break; - } - settings = p270; - if (p270->start_frame <= frame && frame <= p270->end_frame) { - break; - } - p294++; - p270++; - } - mn_8022ED6C(jobj, settings); -} - void mn_80232660(HSD_GObj* gobj, HSD_JObj* jobj, u8 option) { + f32 frame; PAD_STACK(8); switch (option) { @@ -392,7 +365,26 @@ void mn_80232660(HSD_GObj* gobj, HSD_JObj* jobj, u8 option) case 2: case 3: case 4: - mn_80232660_inline(jobj); + frame = mn_8022F298(jobj); + { + AnimLoopSettings* settings; + s32 i; + for (i = 0; i < 3; i++) { + settings = &mn_803ED294[i]; + if (settings->start_frame <= frame && + frame <= settings->end_frame) + { + break; + } + settings = &mn_803ED270[i]; + if (settings->start_frame <= frame && + frame <= settings->end_frame) + { + break; + } + } + mn_8022ED6C(jobj, settings); + } case 0: return; case 5: @@ -400,41 +392,29 @@ void mn_80232660(HSD_GObj* gobj, HSD_JObj* jobj, u8 option) } } -#ifdef MUST_MATCH -#pragma dont_inline on -#endif -void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) +static inline void mn_802327A4_InitOptionRoots(HSD_JObj** option_roots, + mn_803ED1D0_t* rule_data, + MenuRulesPlusData* data, + u8 num_options, s32* i) { - UNUSED u8 pad[8]; - HSD_JObj* option_roots[6]; - HSD_JObj* jobj_parts[17]; - u16 jobj_map[17]; - mn_803ED1D0_t* rule_data = &mn_803ED1D0; - u8 num_options = mn_803EB6B0[15].selection_count; - MenuRulesPlusData* data = gobj->user_data; HSD_JObj** option_root; - s32 i; + u8 j8; + s32 j; s32 visible; - u16 selected; - PAD_STACK(4); - - for (i = 0; 17 > i; i++) { - jobj_map[i] = (u16) i; - } option_root = option_roots; - for (i = 0; i < (s32) num_options; option_root++, i++) { + for (*i = 0; *i < (s32) num_options; option_root++, (*i)++) { s32 valid; - if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) i == 1) { + if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) *i == 1) { valid = 0; - } else if ((u8) i == 3) { + } else if ((u8) *i == 3) { if (gmMainLib_8015EE0C() != 0) { valid = 1; } else { valid = 0; } - } else if ((u8) i == 5) { + } else if ((u8) *i == 5) { if (gmMainLib_8015EE44() != 0) { valid = 1; } else { @@ -444,44 +424,108 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) valid = 1; } if (valid) { - s32 j; + HSD_JObj* child; + HSD_JObj* root; - visible = valid - 1; + visible = 0; j = visible; - for (; j < (s32) (u8) i; j++) { - u8 j8 = j; + for (; j < (s32) (u8) *i; j++) { + j8 = j; if (mn_80231F80(j8) != 0) { visible++; } } - { - HSD_JObj* child; - HSD_JObj* root = data->xC[rule_data->x0[(u8) visible]]; - if (root == NULL) { - child = NULL; + root = data->xC[rule_data->x0[(u8) visible]]; + if (root == NULL) { + child = NULL; + } else { + child = root->child; + } + *option_root = child; + } + } +} + +static inline void mn_802327A4_UpdateOption(MenuRulesPlusData* data, + HSD_GObj* gobj, u32 arg2, u32 arg1, + u16* selected) +{ + if ((s32) arg2 != 0) { + u16 hovered; + MenuRulesPlusData* data2 = gobj->user_data; + hovered = mn_804A04F0.hovered_selection; + { + u8 hovered_u8 = hovered; + u8 confirmed = mn_804A04F0.confirmed_selection; + HSD_JObj* tree = data->x34[hovered][0]; + switch ((s32) hovered_u8) { + case 0: + mn_802324E4(confirmed, data2); + break; + case 1: + case 2: + case 3: + case 4: + if (mn_804A04F0.buttons & 4) { + HSD_JObjReqAnimAll( + tree, + mn_80232458(hovered_u8, confirmed, 0)->start_frame); } else { - child = root->child; + HSD_JObjReqAnimAll( + tree, + mn_80232458(hovered_u8, confirmed, 1)->start_frame); } - *option_root = child; + HSD_JObjAnimAll(tree); + break; + case 5: + default: + break; } } } + if ((s32) arg1 != 0) { + *selected = mn_804A04F0.hovered_selection; + } else { + *selected = (u16) data->hovered_selection; + } +} + +void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) +{ + UNUSED u8 pad[4]; + HSD_JObj* option_roots[6]; + HSD_JObj* jobj_parts[17]; + u16 jobj_map[17]; + mn_803ED1D0_t* rule_data = &mn_803ED1D0; + u8 num_options = mn_803EB6B0[15].selection_count; + MenuRulesPlusData* data = gobj->user_data; + HSD_JObj* part; + s32 i; + s32 visible; + u16 selected; + PAD_STACK(8); + + for (i = 0; 17 > i; i++) { + jobj_map[i] = (u16) i; + } + + mn_802327A4_InitOptionRoots(option_roots, rule_data, data, num_options, + &i); + if ((s32) arg1 != 0) { u8 new_sel; selected = data->hovered_selection; lb_8001204C(option_roots[selected], jobj_parts, jobj_map, 17); HSD_JObjSetFlagsAll(jobj_parts[16], JOBJ_HIDDEN); HSD_JObjSetFlagsAll(jobj_parts[13], JOBJ_HIDDEN); - { - HSD_JObj* part = jobj_parts[2]; - if (selected == 5) { - HSD_JObjReqAnimAll(part, rule_data->x7C[0].start_frame); - } else { - HSD_JObjReqAnimAll(part, rule_data->x64[0].start_frame); - } - HSD_JObjAnimAll(part); + part = jobj_parts[2]; + if (selected == 5) { + HSD_JObjReqAnimAll(part, rule_data->x7C[0].start_frame); + } else { + HSD_JObjReqAnimAll(part, rule_data->x64[0].start_frame); } + HSD_JObjAnimAll(part); { HSD_JObj* part = jobj_parts[7]; HSD_JObjReqAnim(part, rule_data->text_start_frames[selected * 2]); @@ -523,45 +567,7 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) } } - if ((s32) arg2 != 0) { - u16 hovered; - MenuRulesPlusData* data2 = gobj->user_data; - hovered = mn_804A04F0.hovered_selection; - { - u8 hovered_u8 = hovered; - u8 confirmed = mn_804A04F0.confirmed_selection; - HSD_JObj* tree = data->x34[hovered][0]; - switch ((s32) hovered_u8) { - case 0: - mn_802324E4(confirmed, data2); - break; - case 1: - case 2: - case 3: - case 4: - if (mn_804A04F0.buttons & 4) { - HSD_JObjReqAnimAll( - tree, - mn_80232458(hovered_u8, confirmed, 0)->start_frame); - } else { - HSD_JObjReqAnimAll( - tree, - mn_80232458(hovered_u8, confirmed, 1)->start_frame); - } - HSD_JObjAnimAll(tree); - break; - case 5: - default: - break; - } - } - } - - if ((s32) arg1 != 0) { - selected = mn_804A04F0.hovered_selection; - } else { - selected = (u16) data->hovered_selection; - } + mn_802327A4_UpdateOption(data, gobj, arg2, arg1, &selected); for (i = 0; i < (s32) num_options; i++) { if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) i == 1) { @@ -603,9 +609,6 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) } } } -#ifdef MUST_MATCH -#pragma dont_inline off -#endif void mn_80232D4C(HSD_GObj* gobj, u32 arg1, u32 arg2) { @@ -781,11 +784,23 @@ void fn_80232F44(HSD_GObj* gobj) } } +static inline s32 mnRulePlus_CountVisible(u8 limit) +{ + s32 i; + s32 count = 0; + + for (i = 0; i < (s32) limit; i++) { + if (mn_80231F80((u8) i) != 0) { + count++; + } + } + return count; +} + HSD_GObj* mn_80233218(MenuState state) { - u8 operand_pad[8]; - HSD_JObj* jobj_parts[17]; - u16 jobj_map[17]; + u16* volatile sub_count_ptr; + GameRules* rules; HSD_GObj* gobj; MenuRulesPlusData* user_data; u8 num_options; @@ -802,9 +817,9 @@ HSD_GObj* mn_80233218(MenuState state) StaticModelDesc* desc; HSD_JObj* root_jobj; f32* frame_ptr; - u16* volatile sub_count_ptr; - GameRules* rules; - PAD_STACK(8); + HSD_JObj* jobj_parts[17]; + u16 jobj_map[17]; + PAD_STACK(4); selected = (u8) mn_804A04F0.hovered_selection; num_options = mn_803EB6B0[15].selection_count; @@ -869,20 +884,10 @@ HSD_GObj* mn_80233218(MenuState state) sub_count_ptr = mn_803ED1D0.x10; for (i = 0; i < (s32) num_options; i++) { - vis_before = 0; - for (j = vis_before; j < (s32) (u8) i; j++) { - if (mn_80231F80((u8) j) != 0) { - vis_before++; - } - } + vis_before = mnRulePlus_CountVisible((u8) i); - vis_total = 0; option_jobj = user_data->xC[mn_803ED1D0.x0[(u8) vis_before]]; - for (j = vis_total; j < 6; j++) { - if (mn_80231F80((u8) j) != 0) { - vis_total++; - } - } + vis_total = mnRulePlus_CountVisible(6); HSD_JObjReqAnim(option_jobj, (f32) vis_total); HSD_JObjAnim(option_jobj); @@ -937,10 +942,11 @@ HSD_GObj* mn_80233218(MenuState state) } if (i == 5) { - als = &mn_803ED1D0.x7C[i == selected]; - (void) als; + als = &mn_803ED1D0.x4C + (i == selected); + als += 4; } else { - als = &mn_803ED1D0.x64[i == selected]; + als = &mn_803ED1D0.x4C + (i == selected); + als += 2; } HSD_JObjReqAnimAll(jobj_parts[2], als->start_frame); HSD_JObjAnimAll(jobj_parts[2]); diff --git a/src/melee/mn/mnsnap.c b/src/melee/mn/mnsnap.c index 5b84915974..56e3efba90 100644 --- a/src/melee/mn/mnsnap.c +++ b/src/melee/mn/mnsnap.c @@ -747,6 +747,16 @@ static inline void mnSnap_ShowSubmenu(mnSnap_State* snap) HSD_JObjSetFlagsAll(snap->move_jobj, JOBJ_HIDDEN); } +static inline void mnSnap_HideSubmenu(mnSnap_State* snap) +{ + s32 i; + + for (i = 0; i < 5; i++) { + HSD_JObjSetFlagsAll(snap->option_jobjs[i], JOBJ_HIDDEN); + } + HSD_JObjClearFlagsAll(snap->move_jobj, JOBJ_HIDDEN); +} + /// Resets to slot selection state after a card error or empty card. void mnSnap_80254298(void) { @@ -864,6 +874,65 @@ static inline void mnSnap_InitDialogText(void) } } +static inline s32 mnSnap_GetCursorIdx(void) +{ + return mnSnap_804A0A10.cursor_idx; +} + +static inline HSD_JObj* mnSnap_GetMoveJObj(void) +{ + return mnSnap_804A0A10.move_jobj; +} + +static inline s32 mnSnap_GetActivePhotoCount(void) +{ + return mnSnap_804A0A10.photo_count[mnSnap_804A0A10.active_slot]; +} + +static inline void* mnSnap_GetCurrentThumbImage(mnSnap_State* snap) +{ + return mnSnap_thumb_imgs[snap->cursor_idx % 4]; +} + +static inline void mnSnap_AnimateCardSlots(const s32* active_slot) +{ + s32 i; + s32 byte_off; + f32 t; + + i = 0; + byte_off = 4; + do { + if (mnSnap_804A0A10.card_status[i] != 0) { + if (*active_slot == i) { + t = 1.0F; + } else { + t = 0.0F; + } + HSD_JObjReqAnimAll( + *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + byte_off) + + 0x98)), + t); + } else { + HSD_JObjReqAnimAll( + *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + byte_off) + + 0x98)), + 2.0F); + } + HSD_JObjAnimAll( + *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + byte_off) + 0x98))); + i++; + byte_off += 8; + } while (i < 2); +} + +static inline void mnSnap_UpdateSlotStatus(s32 slot) +{ + if (lbSnap_8001D338(slot) != 0) { + mnSnap_80253E90(slot); + } +} + /// Main per-frame update for the Snap menu. Handles all state transitions /// including slot selection, photo browsing, copy/move/delete operations, /// and dialog confirmations via a large switch on snap->state. @@ -871,12 +940,12 @@ void fn_802545C4(void) { u64 buttons; s32 state; - s32 byte_off; + f32 t; s32 byte_off2; s32 i; s32 result; s32 slot; - f32 t; + s32 byte_off; HSD_JObj* jobj; HSD_JObj* jobj2; Vec3* translate; @@ -975,20 +1044,25 @@ void fn_802545C4(void) mnSnap_80253E90(1); } } else { + s32* active_slot = &mnSnap_804A0A10.active_slot; +#ifdef MUST_MATCH + active_slot = active_slot; +#endif + mnSnap_804A0A10.state = 2; mnSnap_804A0A10.timer = 0xB; - mnSnap_804A0A10.active_slot = 0; + *active_slot = 0; HSD_JObjReqAnim(mnSnap_804A0A10.slot_a_jobj, 0.0F); HSD_JObjAnim(mnSnap_804A0A10.slot_a_jobj); HSD_JObjReqAnim(mnSnap_804A0A10.slot_b_jobj, 0.0F); HSD_JObjAnim(mnSnap_804A0A10.slot_b_jobj); mnSnap_804A0A10.pending_loads = 0; if (mnSnap_804A0A10.card_status[0] != 0) { - mnSnap_804A0A10.active_slot = 0; + *active_slot = 0; } else if (mnSnap_804A0A10.card_status[1] != 0) { - mnSnap_804A0A10.active_slot = 1; + *active_slot = 1; } else { - mnSnap_804A0A10.active_slot = -1; + *active_slot = -1; mnSnap_804A0A10.dlg_timer = 9; mnSnap_804A0A10.dlg_active = 1; mnSnap_8025409C(0); @@ -1009,33 +1083,7 @@ void fn_802545C4(void) mnSnap_804A0A10.dlg_text->pos_x = jobj->translate.x - 6.0F; lbAudioAx_80024030(3); } - i = 0; - byte_off = 4; - do { - if (mnSnap_804A0A10.card_status[i] != 0) { - if (mnSnap_804A0A10.active_slot == i) { - t = 1.0F; - } else { - t = 0.0F; - } - HSD_JObjReqAnimAll( - *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + - byte_off) + - 0x98)), - t); - } else { - HSD_JObjReqAnimAll( - *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + - byte_off) + - 0x98)), - 2.0F); - } - HSD_JObjAnimAll( - *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + byte_off) + - 0x98))); - i++; - byte_off += 8; - } while (i < 2); + mnSnap_AnimateCardSlots(active_slot); } break; @@ -1297,10 +1345,7 @@ void fn_802545C4(void) break; case 3: - slot = mnSnap_804A0A10.active_slot; - if (lbSnap_8001D338(slot) != 0) { - mnSnap_80253E90(slot); - } + mnSnap_UpdateSlotStatus(mnSnap_804A0A10.active_slot); if (mnSnap_804A0A10.dlg_result != 0) { sfxBack(); } @@ -1518,7 +1563,7 @@ void fn_802545C4(void) HSD_JObjClearFlagsAll(mnSnap_804A0A10.fullview_jobj, JOBJ_HIDDEN); jobj = mnSnap_804A0A10.fullview_jobj; - thumb_img = mnSnap_thumb_imgs[mnSnap_804A0A10.cursor_idx % 4]; + thumb_img = mnSnap_GetCurrentThumbImage(&mnSnap_804A0A10); HSD_ASSERT(181, jobj); HSD_ASSERT(182, jobj->u.dobj); HSD_ASSERT(183, jobj->u.dobj->mobj); @@ -1532,20 +1577,15 @@ void fn_802545C4(void) mnSnap_804A0A10.state = 0xB; HSD_JObjAnimAll(mnSnap_804A0A10.submenu_jobj); mnSnap_804A0A10.timer = 4; - for (i = 0; i < 5; i++) { - HSD_JObjSetFlagsAll(mnSnap_804A0A10.option_jobjs[i], - JOBJ_HIDDEN); - } - - HSD_JObjClearFlagsAll(mnSnap_804A0A10.move_jobj, JOBJ_HIDDEN); + mnSnap_HideSubmenu(&mnSnap_804A0A10); mnSnap_804A0A10.move_idx = mnSnap_804A0A10.cursor_idx; if ((mnSnap_804A0A10.move_idx / 4) == mnSnap_804A0A10.cur_page) { - jobj = mnSnap_804A0A10.move_jobj; - translate = &mnSnap_804A0A10 - .thumb_jobjs[mnSnap_804A0A10.move_idx % 4] - ->translate; - HSD_JObjSetTranslateWithMtxDirty(jobj, translate); + HSD_JObjSetTranslateWithMtxDirty( + mnSnap_804A0A10.move_jobj, + &mnSnap_804A0A10 + .thumb_jobjs[mnSnap_804A0A10.move_idx % 4] + ->translate); HSD_JObjClearFlagsAll(mnSnap_804A0A10.move_jobj, JOBJ_HIDDEN); } else { @@ -1651,7 +1691,7 @@ void fn_802545C4(void) { s32 mi = mnSnap_804A0A10.move_idx; result = lbSnap_8001D7B0(mnSnap_804A0A10.active_slot, - mnSnap_804A0A10.cursor_idx, mi); + mnSnap_GetCursorIdx(), mi); } if (result != 8) { do { @@ -1667,9 +1707,8 @@ void fn_802545C4(void) next_state = 6; sfxBack(); } else if (buttons & 0xCF) { - result = mnSnap_80253BE0( - buttons, &mnSnap_804A0A10.move_idx, - mnSnap_804A0A10.photo_count[mnSnap_804A0A10.active_slot]); + result = mnSnap_80253BE0(buttons, &mnSnap_804A0A10.move_idx, + mnSnap_GetActivePhotoCount()); if (result == 2) { mnSnap_80253640(mnSnap_804A0A10.move_idx / 4); mnSnap_80253964(); @@ -1698,8 +1737,7 @@ void fn_802545C4(void) HSD_JObjClearFlagsAll(mnSnap_804A0A10.move_jobj, JOBJ_HIDDEN); } else { - HSD_JObjSetFlagsAll(mnSnap_804A0A10.move_jobj, - JOBJ_HIDDEN); + HSD_JObjSetFlagsAll(mnSnap_GetMoveJObj(), JOBJ_HIDDEN); } } else if (result == 1) { if ((mnSnap_804A0A10.move_idx / 4) == mnSnap_804A0A10.cur_page) @@ -1721,12 +1759,7 @@ void fn_802545C4(void) mnSnap_804A0A10.state = next_state; HSD_JObjReqAnimAll(mnSnap_804A0A10.submenu_jobj, 0.0F); HSD_JObjAnimAll(mnSnap_804A0A10.submenu_jobj); - for (i = 0; i < 5; i++) { - HSD_JObjClearFlagsAll(mnSnap_804A0A10.option_jobjs[i], - JOBJ_HIDDEN); - } - - HSD_JObjSetFlagsAll(mnSnap_804A0A10.move_jobj, JOBJ_HIDDEN); + mnSnap_ShowSubmenu(&mnSnap_804A0A10); mnSnap_80253AE4(1); if ((mnSnap_804A0A10.cursor_idx / 4) != mnSnap_804A0A10.cur_page) { mnSnap_80253640(mnSnap_804A0A10.cursor_idx / 4); @@ -1911,10 +1944,7 @@ void fn_802545C4(void) mnSnap_804A0A10.dlg_text = NULL; } } else { - s32 other_slot = mnSnap_804A0A10.active_slot ^ 1; - if (lbSnap_8001D338(other_slot) != 0) { - mnSnap_80253E90(other_slot); - } + mnSnap_UpdateSlotStatus(mnSnap_804A0A10.active_slot ^ 1); if (mnSnap_804A0A10.card_status[mnSnap_804A0A10.active_slot ^ 1] != 0) { @@ -1940,10 +1970,7 @@ void fn_802545C4(void) mnSnap_804A0A10.dlg_text = NULL; } } else { - s32 other_slot = mnSnap_804A0A10.active_slot ^ 1; - if (lbSnap_8001D338(other_slot) != 0) { - mnSnap_80253E90(other_slot); - } + mnSnap_UpdateSlotStatus(mnSnap_804A0A10.active_slot ^ 1); if (mnSnap_804A0A10.card_status[mnSnap_804A0A10.active_slot ^ 1] == 0) { @@ -2178,12 +2205,7 @@ void fn_802545C4(void) case 21: if (mnSnap_804A0A10.dlg_result == 1) { s16 card_status; - { - s32 other_slot = mnSnap_804A0A10.active_slot ^ 1; - if (lbSnap_8001D338(other_slot) != 0) { - mnSnap_80253E90(other_slot); - } - } + mnSnap_UpdateSlotStatus(mnSnap_804A0A10.active_slot ^ 1); card_status = mnSnap_804A0A10.card_status[mnSnap_804A0A10.active_slot ^ 1]; if (card_status == 0) { @@ -2283,12 +2305,7 @@ void fn_802545C4(void) } } else { s16 card_status; - { - s32 other_slot = mnSnap_804A0A10.active_slot ^ 1; - if (lbSnap_8001D338(other_slot) != 0) { - mnSnap_80253E90(other_slot); - } - } + mnSnap_UpdateSlotStatus(mnSnap_804A0A10.active_slot ^ 1); card_status = mnSnap_804A0A10.card_status[mnSnap_804A0A10.active_slot ^ 1]; if (card_status != 0) { @@ -2375,12 +2392,7 @@ void fn_802545C4(void) } } else { s16 card_status; - { - s32 other_slot = mnSnap_804A0A10.active_slot ^ 1; - if (lbSnap_8001D338(other_slot) != 0) { - mnSnap_80253E90(other_slot); - } - } + mnSnap_UpdateSlotStatus(mnSnap_804A0A10.active_slot ^ 1); card_status = mnSnap_804A0A10.card_status[mnSnap_804A0A10.active_slot ^ 1]; if (card_status == 0) { @@ -2469,6 +2481,36 @@ void fn_80257D7C(void) mnSnap_804A0A10.frame_count += 1; } +static inline void mnSnap_LoadPageIndicator(void** page_joint, + mnSnap_State* snap, + HSD_JObj** parent, HSD_JObj** jobj) +{ + *jobj = HSD_JObjLoadJoint((HSD_Joint*) *page_joint); + snap->fullview_jobj = *jobj; + HSD_JObjAddChild(*parent, *jobj); +} + +static inline s16* mnSnap_GetCardStatus(mnSnap_State* snap) +{ + return snap->card_status; +} + +static inline s32* mnSnap_GetPhotoCounts(mnSnap_State* snap) +{ + return snap->photo_count; +} + +static inline void mnSnap_InitPageText(HSD_Text** text) +{ + mnSnap_State* snap = &mnSnap_804A0A10; + + snap->page_text = HSD_SisLib_803A6754(0, 0); + *text = snap->page_text; + (*text)->pos_x = -1.8F; + (*text)->pos_y = 9.2F; + (*text)->pos_z = 17.0F; +} + /// Entry point: initializes the Snap menu scene. Loads assets, creates GObjs, /// sets up thumbnail grid positions, SIS text labels, and dialog widgets. void mnSnap_80257F24(void) @@ -2486,28 +2528,34 @@ void mnSnap_80257F24(void) HSD_GObjProc* proc; HSD_Text* text; void** main_joint; - void** main_animjoint; - void** main_matanim; void** main_shapeanim; - void** csr_joint; - void** csr_animjoint; - void** csr_matanim; + void** warn_animjoint; + void** main_matanim; void** csr_shapeanim; + void** csr_matanim; + void** csr_animjoint; + void** csr_joint; + void** photo_joint; + void** sub_shapeanim; + void** sub_matanim; + void** sub_animjoint; + void** page_joint; void** arrows_joint; void** arrows_animjoint; - void** arrows_matanim; + Vec3 end_pos; void** arrows_shapeanim; void** warn_joint; - void** warn_animjoint; - void** warn_matanim; - void** warn_shapeanim; Vec3 start_pos; - Vec3 end_pos; + void** main_animjoint; + void** warn_shapeanim; + void** warn_matanim; + void** arrows_matanim; f32 dx; f32 dy; f32 dz; s32 i; - PAD_STACK(20); + + PAD_STACK(4); mn_804D6BC8.cooldown = 5; mn_804A04F0.prev_menu = mn_804A04F0.cur_menu; @@ -2525,7 +2573,7 @@ void mnSnap_80257F24(void) photo_count[1] = zero; } snap->card_status[0] = zero; - snap->card_status[1] = zero; + mnSnap_GetCardStatus(snap)[1] = zero; main_joint = &snap->main_joint; main_animjoint = &snap->main_animjoint; @@ -2535,6 +2583,11 @@ void mnSnap_80257F24(void) csr_animjoint = &snap->csr_animjoint; csr_matanim = &snap->csr_matanim; csr_shapeanim = &snap->csr_shapeanim; + photo_joint = &snap->photo_joint; + sub_animjoint = &snap->sub_animjoint; + sub_matanim = &snap->sub_matanim; + sub_shapeanim = &snap->sub_shapeanim; + page_joint = &snap->page_joint; arrows_joint = &snap->arrows_joint; arrows_animjoint = &snap->arrows_animjoint; arrows_matanim = &snap->arrows_matanim; @@ -2549,23 +2602,21 @@ void mnSnap_80257F24(void) "MenMainConSn_Top_animjoint", main_matanim, "MenMainConSn_Top_matanim_joint", main_shapeanim, "MenMainConSn_Top_shapeanim_joint", csr_joint, - "MenMainSubCsrSn_Top_joint", csr_animjoint, - "MenMainSubCsrSn_Top_animjoint", csr_matanim, - "MenMainSubCsrSn_Top_matanim_joint", csr_shapeanim, - "MenMainSubCsrSn_Top_shapeanim_joint", (&snap->photo_joint), - "MenMainPhotoSn_Top_joint", (&snap->sub_animjoint), - "MenMainSubSn_Top_animjoint", (&snap->sub_matanim), - "MenMainSubSn_Top_matanim_joint", (&snap->sub_shapeanim), - "MenMainSubSn_Top_shapeanim_joint", (&snap->page_joint), - "MenMainSubSn_Top_joint", (&snap->load_joint), - "MenMainLoadSn_Top_joint", arrows_joint, "MenMainSubSn_Top_joint", - arrows_animjoint, "MenMainSubSn_Top_animjoint", arrows_matanim, - "MenMainSubSn_Top_matanim_joint", arrows_shapeanim, - "MenMainSubSn_Top_shapeanim_joint", warn_joint, + "MenMainSubSn_Top_joint", csr_animjoint, "MenMainSubSn_Top_animjoint", + csr_matanim, "MenMainSubSn_Top_matanim_joint", csr_shapeanim, + "MenMainSubSn_Top_shapeanim_joint", photo_joint, + "MenMainSubCsrSn_Top_joint", sub_animjoint, + "MenMainSubCsrSn_Top_animjoint", sub_matanim, + "MenMainSubCsrSn_Top_matanim_joint", sub_shapeanim, + "MenMainSubCsrSn_Top_shapeanim_joint", page_joint, + "MenMainPhotoSn_Top_joint", arrows_joint, "MenMainLoadSn_Top_joint", + arrows_animjoint, "MenMainLoadSn_Top_animjoint", arrows_matanim, + "MenMainLoadSn_Top_matanim_joint", arrows_shapeanim, + "MenMainLoadSn_Top_shapeanim_joint", warn_joint, "MenMainWarCmn_Top_joint", warn_animjoint, "MenMainWarCmn_Top_animjoint", warn_matanim, "MenMainWarCmn_Top_matanim_joint", warn_shapeanim, - "MenMainWarCmn_Top_shapeanim_joint", 0); + "MenMainWarCmn_Top_shapeanim_joint\0\0\0\0\0\0", 0); /* Main GObj */ gobj = GObj_Create(6, 7, 0x80); @@ -2582,9 +2633,9 @@ void mnSnap_80257F24(void) slot_jobj_ptr = &snap->slot_a_jobj; snap->blank_img = - *(void**) (snap->slot_a_jobj)->u.dobj->mobj->tobj->imagedesc; + snap->slot_a_jobj->u.dobj->mobj->tobj->imagedesc->image_ptr; - if (snap->photo_count[snap->active_slot] <= 4) { + if (mnSnap_GetPhotoCounts(snap)[snap->active_slot] <= 4) { HSD_JObjSetFlagsAll(snap->arrow_jobj, JOBJ_HIDDEN); } else { HSD_JObjClearFlagsAll(snap->arrow_jobj, JOBJ_HIDDEN); @@ -2639,10 +2690,10 @@ void mnSnap_80257F24(void) /* Create 5 thumbnail position JObjs by interpolating */ for (i = 0; i < 5; i++) { - jobj2 = HSD_JObjLoadJoint((HSD_Joint*) snap->photo_joint); - HSD_JObjAddAnimAll(jobj2, (HSD_AnimJoint*) snap->sub_animjoint, - (HSD_MatAnimJoint*) snap->sub_matanim, - (HSD_ShapeAnimJoint*) snap->sub_shapeanim); + jobj2 = HSD_JObjLoadJoint((HSD_Joint*) *photo_joint); + HSD_JObjAddAnimAll(jobj2, (HSD_AnimJoint*) *sub_animjoint, + (HSD_MatAnimJoint*) *sub_matanim, + (HSD_ShapeAnimJoint*) *sub_shapeanim); end_pos.x = dx * (f32) i + start_pos.x; end_pos.y = dy * (f32) i + start_pos.y; end_pos.z = dz * (f32) i + start_pos.z; @@ -2652,9 +2703,7 @@ void mnSnap_80257F24(void) } /* Load page indicator */ - jobj2 = HSD_JObjLoadJoint((HSD_Joint*) snap->page_joint); - snap->fullview_jobj = jobj2; - HSD_JObjAddChild(*thumb_root_ptr, jobj2); + mnSnap_LoadPageIndicator(page_joint, snap, thumb_root_ptr, &jobj2); HSD_JObjSetFlagsAll(jobj2, JOBJ_HIDDEN); /* Create 4 SIS text objects for thumbnail labels */ @@ -2717,11 +2766,7 @@ void mnSnap_80257F24(void) text->default_alignment = 1; /* Create page text objects */ - snap->page_text = HSD_SisLib_803A6754(0, 0); - text = snap->page_text; - text->pos_x = -1.8F; - text->pos_y = 9.2F; - text->pos_z = 17.0F; + mnSnap_InitPageText(&text); text->font_size.x = 0.04F; text->font_size.y = 0.04F; text->default_alignment = 1; diff --git a/src/melee/mn/mnsound.c b/src/melee/mn/mnsound.c index 6ace2b976f..c9245e1faf 100644 --- a/src/melee/mn/mnsound.c +++ b/src/melee/mn/mnsound.c @@ -76,10 +76,10 @@ static inline void mnSound_InitChannelAnim(HSD_JObj* jobj, s32 channel, static void mnSound_ChannelAnim(HSD_JObj* jobj, s32 channel) { - HSD_JObj* jobj_anim_2; + f32 right_frame, left_frame; HSD_JObj* jobj_anim_1; + HSD_JObj* jobj_anim_2; HSD_JObj* jobj_anim_0; - f32 right_frame, left_frame; lb_80011E24(jobj, &jobj_anim_0, 8, -1); lb_80011E24(jobj, &jobj_anim_1, 10, -1); lb_80011E24(jobj, &jobj_anim_2, 9, -1); @@ -113,6 +113,7 @@ static inline void mnSound_InitVolumeAnim(HSD_JObj* jobj, s32 sound_music_mix, (((f32) ((s8) sound_music_mix + 100) / 200.0f) * (pos_1->x - pos_0->x)) + pos_0->x); + gm_801602C0((u8) sound_music_mix); } static inline void mnSound_UpdateCenterText(void) @@ -191,7 +192,7 @@ void mnSound_802492CC(HSD_GObj* gobj) sfxMove(); menu->unk3 += 5; mix = menu->unk3; - mnSound_VolumeAnim(GET_JOBJ(mnSound_804D6C30), mix, 18); + mnSound_VolumeAnim(GET_JOBJ(mnSound_804D6C30), mix, 6); gm_801602C0(mix); gmMainLib_8015ED80(GET_MENU(mnSound_804D6C30)->unk3); } @@ -288,14 +289,13 @@ void mnSound_80249C08(int unused) { StaticModelDesc* model = &mnSound_804A08A8; AnimLoopSettings* anims = mnSound_803EEED8; - HSD_GObj* gobj = GObj_Create(HSD_GOBJ_CLASS_ITEM, 7U, 0x80U); - HSD_JObj* jobj; - Menu* user_data; - UNUSED HSD_GObjProc* proc; HSD_JObj* sound_selection_jobj; HSD_JObj* channel_selection_jobj; HSD_JObj* volume_cursor_jobj; - PAD_STACK(4); + HSD_JObj* jobj; + Menu* user_data; + UNUSED HSD_GObjProc* proc; + HSD_GObj* gobj = GObj_Create(HSD_GOBJ_CLASS_ITEM, 7U, 0x80U); mnSound_804D6C30 = gobj; jobj = HSD_JObjLoadJoint(model->joint); HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); @@ -303,10 +303,7 @@ void mnSound_80249C08(int unused) HSD_JObjAddAnimAll(jobj, model->animjoint, model->matanim_joint, model->shapeanim_joint); HSD_JObjReqAnimAll(jobj, 0.0F); - { - Menu* alloc = HSD_MemAlloc(sizeof(Menu)); - user_data = alloc; - } + user_data = HSD_MemAlloc(sizeof(Menu)); HSD_ASSERTREPORT(0x22CU, user_data, "Can't get user_data.\n"); gmMainLib_GetGameRules(); user_data->cursor = 0x14; @@ -316,16 +313,10 @@ void mnSound_80249C08(int unused) { Menu* menu = GET_MENU(mnSound_804D6C30); - s32 text_id; if (menu->text != NULL) { HSD_SisLib_803A5CC4(menu->text); } - if (menu->unk2 == 0) { - text_id = 0xBB; - } else { - text_id = 0xBC; - } - Menu_InitCenterText(menu, text_id); + Menu_InitCenterText(menu, menu->unk2 == 0 ? 0xBB : 0xBC); } { @@ -356,7 +347,6 @@ void mnSound_80249C08(int unused) } { - gm_801602C0(user_data->unk3); lb_80011E24(jobj, &sound_selection_jobj, 0xE, -1); { AnimLoopSettings* anim = &anims[user_data->unk2]; diff --git a/src/melee/mn/mnstagesw.c b/src/melee/mn/mnstagesw.c index 624fe4e3e2..d395a6f04e 100644 --- a/src/melee/mn/mnstagesw.c +++ b/src/melee/mn/mnstagesw.c @@ -506,10 +506,38 @@ static void mnStageSw_80236548(HSD_GObj* gobj, u8 arg1, u8 arg2) mn_8022ED6C(hover_anim_jobj, mnStageSw_803ED488); } -#ifdef MUST_MATCH -#pragma push -#pragma inline_depth(0) -#endif +static inline void mnStageSw_FinishEnter(HSD_GObj* menu_gobj, + MnStageSwData* data, HSD_JObj** child) +{ + HSD_JObj* jobj; + s32 i; + + data->x1F = i = 0; + mnStageSw_802359C8(data); + menu_gobj = menu_gobj->user_data; + HSD_JObjClearFlagsAll(((MnStageSwData*) menu_gobj)->x2C, JOBJ_HIDDEN); + HSD_JObjClearFlagsAll(((MnStageSwData*) menu_gobj)->x34, JOBJ_HIDDEN); + for (; i < NUM_STAGES; i++) { + jobj = mnStageSw_802364A0((MnStageSwData*) menu_gobj, i); + if (i != ((MnStageSwData*) menu_gobj)->x1) { + lb_80011E24(jobj, child, 3, -1); + HSD_JObjSetFlagsAll(*child, JOBJ_HIDDEN); + } + } + mnStageSw_80236178((MnStageSwData*) menu_gobj, + ((MnStageSwData*) menu_gobj)->x1); + mnStageSw_804D6BF4 = 0; +} + +static inline void mnStageSw_FreeTexts(MnStageSwData* data) +{ + s32 i; + + for (i = 0; i < NUM_STAGES; i++) { + HSD_SisLib_803A5CC4(data->x40[i]); + } +} + static void fn_80236998(HSD_GObj* gobj) { HSD_JObj* jobj; @@ -517,7 +545,6 @@ static void fn_80236998(HSD_GObj* gobj) MnStageSwData* data = current_data; AnimLoopSettings* anims; s32 changed_menu; - s32 i; s32 changed_hovered; u64 pad3; HSD_JObj* child; @@ -583,30 +610,11 @@ static void fn_80236998(HSD_GObj* gobj) switch ((s32) data->x1F) { case 1: case 3: - data->x1F = changed_menu = 0; - mnStageSw_802359C8(data); - gobj = gobj->user_data; - HSD_JObjClearFlagsAll(((MnStageSwData*) gobj)->x2C, - JOBJ_HIDDEN); - HSD_JObjClearFlagsAll(((MnStageSwData*) gobj)->x34, - JOBJ_HIDDEN); - for (; changed_menu < NUM_STAGES; changed_menu++) { - jobj = mnStageSw_802364A0((MnStageSwData*) gobj, - changed_menu); - if (changed_menu != ((MnStageSwData*) gobj)->x1) { - lb_80011E24(jobj, &child, 3, -1); - HSD_JObjSetFlagsAll(child, JOBJ_HIDDEN); - } - } - mnStageSw_80236178((MnStageSwData*) gobj, - ((MnStageSwData*) gobj)->x1); - mnStageSw_804D6BF4 = 0; + mnStageSw_FinishEnter(gobj, data, &child); return; case 2: case 4: - for (i = 0; i < NUM_STAGES; i++) { - HSD_SisLib_803A5CC4(data->x40[i]); - } + mnStageSw_FreeTexts(data); HSD_GObjPLink_80390228(gobj); return; } @@ -638,9 +646,6 @@ static void fn_80236998(HSD_GObj* gobj) mn_804A04F0.confirmed_selection; } } -#ifdef MUST_MATCH -#pragma pop -#endif static inline void mnStageSw_SetCursorPosition(MnStageSwData* user_data) { diff --git a/src/melee/mn/mnvibration.c b/src/melee/mn/mnvibration.c index d58cccadb6..a8b76685fd 100644 --- a/src/melee/mn/mnvibration.c +++ b/src/melee/mn/mnvibration.c @@ -85,7 +85,11 @@ static inline f32 mnVibration_JObjGetTranslationZ(HSD_JObj* jobj) static inline void mnVibration_JObjSetTranslateX(HSD_JObj* jobj, f32 x) { - HSD_JObj* temp = jobj; + HSD_JObj* temp = +#ifdef MUST_MATCH + temp = +#endif + jobj; (jobj ? ((void) 0) : __assert(mnVibration_804D4FF4, 0x3A4, mnVibration_804D4FFC)); jobj->translate.x = x; @@ -94,20 +98,24 @@ static inline void mnVibration_JObjSetTranslateX(HSD_JObj* jobj, f32 x) } } -static inline void mnVibration_JObjSetTranslateY(HSD_JObj* jobj, f32 y) +static inline void mnVibration_JObjSetTranslateY(HSD_JObj* jobj, f32 y, + HSD_JObj* dirty_jobj) { - HSD_JObj* temp = jobj; (jobj ? ((void) 0) : __assert(mnVibration_804D4FF4, 0x3B3, mnVibration_804D4FFC)); jobj->translate.y = y; if (!(jobj->flags & JOBJ_MTX_INDEP_SRT)) { - (HSD_JObjSetMtxDirty)(temp); + (HSD_JObjSetMtxDirty)(dirty_jobj); } } static inline void mnVibration_JObjSetTranslateZ(HSD_JObj* jobj, f32 z) { - HSD_JObj* temp = jobj; + HSD_JObj* temp = +#ifdef MUST_MATCH + temp = +#endif + jobj; (jobj ? ((void) 0) : __assert(mnVibration_804D4FF4, 0x3C2, mnVibration_804D4FFC)); jobj->translate.z = z; @@ -197,6 +205,35 @@ static inline u8 mnVibration_GetNameRumble(s32 name_idx) return GetPersistentNameData(name_idx)->rumble_enabled; } +static inline u8 mnVibration_GetCursorRow(MnVibrationData* data) +{ + return data->x0[1]; +} + +static inline s32 mnVibration_GetPreviousCursorRow(s32 cursor_row) +{ + return cursor_row - 1; +} + +static inline s32 mnVibration_GetNextCursorRow(s32 cursor_row) +{ + return cursor_row + 1; +} + +static inline u8 mnVibration_GetPortRumble(s32 port) +{ + return GetRumbleSettingOfPort(port); +} + +static inline void mnVibration_FreeNameTexts(MnVibrationData* data) +{ + s32 i; + + for (i = 0; i < 8; i++) { + HSD_SisLib_803A5CC4(data->texts[i]); + } +} + #ifdef MUST_MATCH #pragma push #pragma dont_inline on @@ -227,6 +264,23 @@ HSD_JObj* mnVibration_GetNameRowJObj(s32 count) #pragma pop #endif +static inline f32 mnVibration_GetCursorYSpacing(f32 base_y, HSD_JObj* jobj) +{ + return HSD_JObjGetTranslationY(jobj) - base_y; +} + +static inline void mnVibration_AnimatePortPanel(MnVibrationData* data, + s32 port) +{ + HSD_JObj* jobj; + u8 state; + + state = data->x0[port + 2]; + jobj = data->jobjs[mnVibration_PortPanelJointIds[(u8) port]]; + HSD_JObjReqAnimAll(jobj, (f32) state); + HSD_JObjAnimAll(jobj); +} + static inline void mnVibration_AnimateNameRow(u8 row, u8 state) { HSD_JObj* jobj; @@ -244,7 +298,6 @@ void mnVibration_HandleInput(HSD_GObj* gobj) s32 i; u64 inputs; u64 inputs_repeat; - HSD_JObj* panel_jobj; u8 cursor_row; u8 scroll_offset; s32 name_count; @@ -253,7 +306,10 @@ void mnVibration_HandleInput(HSD_GObj* gobj) u8 rumble_setting; HSD_JObj* loaded_joint; HSD_JObj* jobj; - u8 sp[112]; + HSD_JObj* panel_jobj2; + HSD_JObj* panel_jobj3; + + PAD_STACK(96); if (mn_804D6BC8.cooldown != 0) { Menu_DecrementAnimTimer(); @@ -271,13 +327,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) mn_80229894(4, 0, 3); // Clean up text objects - reload data pointer exit_data = mnVibration_804D6C28->user_data; - { - s32 text_idx; - for (text_idx = 0; text_idx < 8; text_idx++) { - HSD_SisLib_803A5CC4(exit_data->texts[text_idx]); - } - i = text_idx; - } + mnVibration_FreeNameTexts(exit_data); if (exit_data->title_text != NULL) { HSD_SisLib_803A5CC4(exit_data->title_text); } @@ -301,9 +351,8 @@ void mnVibration_HandleInput(HSD_GObj* gobj) HSD_JObj* temp_jobj; sfxForward(); if (GetRumbleSettingOfPort(i) != 0) { - HSD_JObj* panel_jobj2; gmMainLib_SetRumbleEnabled(i, 0); - rumble_setting = GetRumbleSettingOfPort(i); + rumble_setting = mnVibration_GetPortRumble(i); temp_jobj = ((MnVibrationData*) mnVibration_804D6C28->user_data) ->jobjs[23]; @@ -326,9 +375,8 @@ void mnVibration_HandleInput(HSD_GObj* gobj) HSD_PadRumbleOffN(i); return; } else { - HSD_JObj* panel_jobj2; gmMainLib_SetRumbleEnabled(i, 1); - rumble_setting = GetRumbleSettingOfPort(i); + rumble_setting = mnVibration_GetPortRumble(i); temp_jobj = ((MnVibrationData*) mnVibration_804D6C28->user_data) ->jobjs[23]; @@ -344,9 +392,9 @@ void mnVibration_HandleInput(HSD_GObj* gobj) jobj = jobj->next; } } - lb_80011E24(jobj, &panel_jobj2, 2, -1); - HSD_JObjReqAnimAll(panel_jobj2, (f32) rumble_setting); - HSD_JObjAnimAll(panel_jobj2); + lb_80011E24(jobj, &panel_jobj3, 2, -1); + HSD_JObjReqAnimAll(panel_jobj3, (f32) rumble_setting); + HSD_JObjAnimAll(panel_jobj3); HSD_PadRumbleAdd(i, 0, 14, 0, &mnVibration_804D4FF0); return; } @@ -355,8 +403,11 @@ void mnVibration_HandleInput(HSD_GObj* gobj) } // Handle name list navigation if names exist - if (GetNameCount() == 0) { - return; + { + s32 names_empty = GetNameCount() == 0; + if (names_empty) { + return; + } } // Check for up/down navigation @@ -365,25 +416,15 @@ void mnVibration_HandleInput(HSD_GObj* gobj) for (j = 0; j < 4; j++) { inputs = gm_GetButtonsTriggered(j); if ((inputs & PAD_ANY_LEFT) && data->x0[j + 2] == 1) { - u8 state; sfxMove(); data->x0[j + 2] = 0; - state = data->x0[j + 2]; - panel_jobj = - data->jobjs[mnVibration_PortPanelJointIds[(u8) j]]; - HSD_JObjReqAnimAll(panel_jobj, (f32) state); - HSD_JObjAnimAll(panel_jobj); + mnVibration_AnimatePortPanel(data, j); } else { inputs = gm_GetButtonsTriggered(j); if ((inputs & PAD_ANY_RIGHT) && data->x0[j + 2] == 0) { - u8 state; sfxMove(); data->x0[j + 2] = 1; - state = data->x0[j + 2]; - panel_jobj = - data->jobjs[mnVibration_PortPanelJointIds[(u8) j]]; - HSD_JObjReqAnimAll(panel_jobj, (f32) state); - HSD_JObjAnimAll(panel_jobj); + mnVibration_AnimatePortPanel(data, j); } } } @@ -402,7 +443,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) // Handle A button to toggle rumble setting for selected name if (inputs_repeat & (1LL << 32)) { sfxForward(); - cursor_row = data->x0[1]; + cursor_row = mnVibration_GetCursorRow(data); name_idx = mnVibration_GetNameSlot(data, cursor_row); rumble_setting = mnVibration_GetNameRumble(name_idx); if (rumble_setting == 1) { @@ -411,15 +452,16 @@ void mnVibration_HandleInput(HSD_GObj* gobj) GetPersistentNameData(name_idx)->rumble_enabled = true; } rumble_setting = mnVibration_GetNameRumble(name_idx); - mnVibration_AnimateNameRow(data->x0[1], rumble_setting); + cursor_row = data->x0[1]; + mnVibration_AnimateNameRow(cursor_row, rumble_setting); return; } // Handle up navigation if (inputs_repeat & (0x10LL << 32)) { - cursor_row = data->x0[1]; + cursor_row = mnVibration_GetCursorRow(data); if (cursor_row != 0) { - s32 name_row = cursor_row - 1; + s32 name_row = mnVibration_GetPreviousCursorRow(cursor_row); name_idx = mnVibration_GetNameSlot(data, name_row); if (name_idx != 0xFF) { MnVibrationData* data2; @@ -427,29 +469,25 @@ void mnVibration_HandleInput(HSD_GObj* gobj) HSD_JObj* jobj18; f32 base_y; f32 spacing; - f32 temp_x; - f32 temp_y; - f32 temp_z; sfxMove(); data->x0[1]--; data2 = mnVibration_804D6C28->user_data; (void) data2; cursor_jobj = data->cursor_gobj->hsd_obj; jobj17 = data2->jobjs[17]; - cursor_row = data->x0[1]; + cursor_row = mnVibration_GetCursorRow(data); base_y = HSD_JObjGetTranslationY(jobj17); jobj18 = data2->jobjs[18]; - spacing = HSD_JObjGetTranslationY(jobj18) - base_y; - jobj17 = data2->jobjs[17]; - temp_x = HSD_JObjGetTranslationX(jobj17); - HSD_JObjSetTranslateX(cursor_jobj, temp_x); + spacing = mnVibration_GetCursorYSpacing(base_y, jobj18); jobj17 = data2->jobjs[17]; - temp_y = (spacing * (f32) cursor_row) + - HSD_JObjGetTranslationY(jobj17); - HSD_JObjSetTranslateY(cursor_jobj, temp_y); - jobj17 = data2->jobjs[17]; - temp_z = HSD_JObjGetTranslationZ(jobj17); - HSD_JObjSetTranslateZ(cursor_jobj, temp_z); + HSD_JObjSetTranslateX(cursor_jobj, + HSD_JObjGetTranslationX(jobj17)); + HSD_JObjSetTranslateY( + cursor_jobj, + (spacing * (f32) cursor_row) + + HSD_JObjGetTranslationY(data2->jobjs[17])); + HSD_JObjSetTranslateZ( + cursor_jobj, HSD_JObjGetTranslationZ(data2->jobjs[17])); } } else if (GetNameCount() > 8 && data->scroll_offset != 0) { sfxMove(); @@ -461,9 +499,9 @@ void mnVibration_HandleInput(HSD_GObj* gobj) // Handle down navigation else if (inputs_repeat & (0x20LL << 32)) { - cursor_row = data->x0[1]; + cursor_row = mnVibration_GetCursorRow(data); if (cursor_row < 7) { - u8 name_row = cursor_row + 1; + s32 name_row = mnVibration_GetNextCursorRow(cursor_row); name_idx = mnVibration_GetNameSlot(data, name_row); if (name_idx != 0xFF) { MnVibrationData* data2; @@ -471,28 +509,24 @@ void mnVibration_HandleInput(HSD_GObj* gobj) HSD_JObj* jobj18; f32 base_y; f32 spacing; - f32 temp_x; - f32 temp_y; - f32 temp_z; sfxMove(); data->x0[1]++; data2 = mnVibration_804D6C28->user_data; cursor_jobj = data->cursor_gobj->hsd_obj; jobj17 = data2->jobjs[17]; - cursor_row = data->x0[1]; + cursor_row = mnVibration_GetCursorRow(data); base_y = HSD_JObjGetTranslationY(jobj17); jobj18 = data2->jobjs[18]; spacing = HSD_JObjGetTranslationY(jobj18) - base_y; jobj17 = data2->jobjs[17]; - temp_x = HSD_JObjGetTranslationX(jobj17); - HSD_JObjSetTranslateX(cursor_jobj, temp_x); - jobj17 = data2->jobjs[17]; - temp_y = (spacing * (f32) cursor_row) + - HSD_JObjGetTranslationY(jobj17); - HSD_JObjSetTranslateY(cursor_jobj, temp_y); - jobj17 = data2->jobjs[17]; - temp_z = HSD_JObjGetTranslationZ(jobj17); - HSD_JObjSetTranslateZ(cursor_jobj, temp_z); + HSD_JObjSetTranslateX(cursor_jobj, + HSD_JObjGetTranslationX(jobj17)); + HSD_JObjSetTranslateY( + cursor_jobj, + (spacing * (f32) cursor_row) + + HSD_JObjGetTranslationY(data2->jobjs[17])); + HSD_JObjSetTranslateZ( + cursor_jobj, HSD_JObjGetTranslationZ(data2->jobjs[17])); } } else if (GetNameCount() > 8) { if (mnVibration_GetNameSlot(data, 8) != 0xFF) { @@ -691,44 +725,47 @@ void mnVibration_OnAnimComplete(HSD_GObj* gobj) } } +static inline s32 mnVibration_GetPortModeIndex(s32 port) +{ + return port + 2; +} + static inline HSD_JObj* mnVibration_GetPortChildAt(HSD_GObj* gobj, s32 n) { HSD_JObj* child; - HSD_JObj* temp_jobj; s32 i; - temp_jobj = ((MnVibrationData*) gobj->user_data)->jobjs[23]; - if (temp_jobj == NULL) { - child = NULL; - } else { - child = temp_jobj->child; - } + child = HSD_JObjGetChild(((MnVibrationData*) gobj->user_data)->jobjs[23]); for (i = 0; i < n; i++) { - if (child == NULL) { - child = NULL; - } else { - child = child->next; - } + child = HSD_JObjGetNext(child); } return child; } -void mnVibration_Think(HSD_GObj* gobj) +static inline MnVibrationData* mnVibration_GetUserData(HSD_GObj* gobj) +{ + return gobj->user_data; +} + +static inline u8 mnVibration_GetPadIndex(s32 port) +{ + return port; +} + +static inline void mnVibration_ThinkInline(HSD_GObj* gobj, + HSD_JObj** port_anim_jobj) { - HSD_JObj* sp44; - HSD_JObj* toggle_jobj; + HSD_JObj* panel_jobj; HSD_JObj* port_child; s32 port; - s32 port_idx; - u8 pad_err; u8 pad_idx; - u8 state; + u8 pad_err; + s32 port_idx; + u8 anim_state; HSD_JObj* active_child; - MnVibrationData* data; HSD_JObj* disconnected_child; - u8 sp[52]; + MnVibrationData* data = mnVibration_GetUserData(gobj); - data = gobj->user_data; if ((u8) mn_804A04F0.cur_menu != 0x13) { HSD_GObjProc* proc; HSD_GObjProc_8038FE24(HSD_GObj_804D7838); @@ -738,36 +775,20 @@ void mnVibration_Think(HSD_GObj* gobj) } port = 0; do { - void* temp_jobj; - temp_jobj = ((MnVibrationData*) gobj->user_data)->jobjs[23]; - if (temp_jobj == NULL) { - port_child = NULL; - } else { - port_child = ((HSD_JObj*) temp_jobj)->child; - } - { - s32 i; - for (i = 0; i < port; i++) { - if (port_child == NULL) { - port_child = NULL; - } else { - port_child = port_child->next; - } - } - } - lb_80011E24(port_child, &sp44, 1, -1); + port_child = mnVibration_GetPortChildAt(gobj, port); + lb_80011E24(port_child, port_anim_jobj, 1, -1); if (GetRumbleSettingOfPort(port) != 0) { - mn_8022EC18(sp44, &mnVibration_803EECF8, MOBJ_MASK); + mn_8022EC18(*port_anim_jobj, &mnVibration_803EECF8, MOBJ_MASK); } else { - HSD_JObjReqAnimAll(sp44, 0.0f); - mn_8022F3D8(sp44, 0xFF, MOBJ_MASK); - HSD_JObjAnimAll(sp44); + HSD_JObjReqAnimAll(*port_anim_jobj, 0.0f); + mn_8022F3D8(*port_anim_jobj, 0xFF, MOBJ_MASK); + HSD_JObjAnimAll(*port_anim_jobj); } port += 1; } while (port < 4); port_idx = 0; do { - pad_idx = port_idx; + pad_idx = mnVibration_GetPadIndex(port_idx); pad_err = HSD_PadCopyStatus[pad_idx].err; if ((((s8) pad_err != 0) && (data->x6[port_idx] != 0)) || (((s8) pad_err == 0) && (data->x6[port_idx] == 0))) @@ -799,15 +820,23 @@ void mnVibration_Think(HSD_GObj* gobj) mnVibration_UpdatePortPanel(disconnected_child, port_idx, 0); data->x6[port_idx] = 0; } else { - HSD_JObjClearFlagsAll( - data->jobjs[mnVibration_PortPanelJointIds[port_idx]], - JOBJ_HIDDEN); - data->x0[port_idx + 2] = 0; - toggle_jobj = - ((MnVibrationData*) mnVibration_804D6C28->user_data) - ->jobjs[mnVibration_PortPanelJointIds[pad_idx]]; - state = data->x0[port_idx + 2]; - HSD_JObjReqAnimAll(toggle_jobj, state); + HSD_JObj* toggle_jobj; + + panel_jobj = + data->jobjs[mnVibration_PortPanelJointIds[port_idx]]; + HSD_JObjClearFlagsAll(panel_jobj, JOBJ_HIDDEN); + data->x0[mnVibration_GetPortModeIndex(port_idx)] = 0; + { + HSD_JObj* selected_panel = + ((MnVibrationData*) mnVibration_804D6C28->user_data) + ->jobjs[mnVibration_PortPanelJointIds[pad_idx]]; + toggle_jobj = selected_panel; + } + { + u8 port_mode = data->x0[port_idx + 2]; + anim_state = port_mode; + } + HSD_JObjReqAnimAll(toggle_jobj, anim_state); HSD_JObjAnimAll(toggle_jobj); active_child = mnVibration_GetPortChildAt(gobj, port_idx); mnVibration_UpdatePortPanel(active_child, port_idx, 1); @@ -818,9 +847,12 @@ void mnVibration_Think(HSD_GObj* gobj) } while (port_idx < 4); } -static inline f32 mnVibration_GetCursorYSpacing(f32 base_y, HSD_JObj* jobj) +void mnVibration_Think(HSD_GObj* gobj) { - return mnVibration_JObjGetTranslationY(jobj) - base_y; + { + HSD_JObj* port_anim_jobj; + mnVibration_ThinkInline(gobj, &port_anim_jobj); + } } void mnVibration_IntroProc(HSD_GObj* arg0) @@ -830,7 +862,8 @@ void mnVibration_IntroProc(HSD_GObj* arg0) MnVibrationJointAssets* assets; MnVibrationData* data2; HSD_GObj* cursor_gobj; - HSD_JObj* loaded_joint; + HSD_JObj* dirty_jobj; + MnVibrationData* data3; HSD_JObj* cursor_jobj; HSD_JObj* jobj; HSD_JObj* jobj2; @@ -838,6 +871,7 @@ void mnVibration_IntroProc(HSD_GObj* arg0) HSD_JObj* jobj4; HSD_JObj* jobj17; HSD_JObj* jobj18; + HSD_JObj* loaded_joint; f32 base_y; f32 spacing; f32 temp_x; @@ -947,25 +981,49 @@ void mnVibration_IntroProc(HSD_GObj* arg0) loaded_joint); GObj_SetupGXLink(cursor_gobj, HSD_GObj_JObjCallback, 4U, 0x80U); HSD_GObj_SetupProc(cursor_gobj, mnVibration_CursorThink, 0U); - data2 = arg0->user_data; + data3 = arg0->user_data; cursor_jobj = cursor_gobj->hsd_obj; - jobj17 = data2->jobjs[17]; + jobj17 = data3->jobjs[17]; cursor_row = data2->x0[1]; (void) jobj17; (void) cursor_row; base_y = mnVibration_JObjGetTranslationY(jobj17); - jobj18 = data2->jobjs[18]; + jobj18 = data3->jobjs[18]; spacing = mnVibration_GetCursorYSpacing(base_y, jobj18); - jobj17 = data2->jobjs[17]; - temp_x = mnVibration_JObjGetTranslationX(jobj17); - mnVibration_JObjSetTranslateX(cursor_jobj, temp_x); - jobj17 = data2->jobjs[17]; - mnVibration_JObjSetTranslateY( - cursor_jobj, (spacing * (f32) cursor_row) + - mnVibration_JObjGetTranslationY(jobj17)); - jobj17 = data2->jobjs[17]; - temp_z = mnVibration_JObjGetTranslationZ(jobj17); - mnVibration_JObjSetTranslateZ(cursor_jobj, temp_z); + (void) spacing; + { + HSD_JObj* position_jobj = +#ifdef MUST_MATCH + position_jobj = +#endif + data3->jobjs[17]; + temp_x = mnVibration_JObjGetTranslationX(position_jobj); + (void) temp_x; + mnVibration_JObjSetTranslateX(cursor_jobj, temp_x); + } + { + HSD_JObj* position_jobj = +#ifdef MUST_MATCH + position_jobj = +#endif + data3->jobjs[17]; + base_y = spacing; + base_y = (base_y * (f32) cursor_row) + + mnVibration_JObjGetTranslationY(position_jobj); + (void) base_y; + dirty_jobj = cursor_jobj; + mnVibration_JObjSetTranslateY(cursor_jobj, base_y, dirty_jobj); + } + { + HSD_JObj* position_jobj = +#ifdef MUST_MATCH + position_jobj = +#endif + data3->jobjs[17]; + temp_z = mnVibration_JObjGetTranslationZ(position_jobj); + (void) temp_z; + mnVibration_JObjSetTranslateZ(cursor_jobj, temp_z); + } } } diff --git a/src/melee/ty/toy.c b/src/melee/ty/toy.c index fbc7380647..e8c65ac86b 100644 --- a/src/melee/ty/toy.c +++ b/src/melee/ty/toy.c @@ -56,6 +56,16 @@ int Toy_GetTrophyTotal(void) } } +static inline s32 _Toy_GetTrophyTotal(Toy26B8* toy) +{ + if (gm_IsCurrently1PMode() != 0 || + gm_GetCurrentGameMode() == GM_TOY_LOTTERY) + { + return toy->trophy_count; + } + return *gmMainLib_GetTrophyCount(); +} + static inline u16* idk(void) { if (gm_IsCurrently1PMode() || gm_GetCurrentGameMode() == GM_TOY_LOTTERY) { @@ -2805,12 +2815,13 @@ void _Toy_80309404(HSD_GObj* gobj) struct { void* next; void* next_wrap; + u8 pad[4]; void* prev; void* prev_wrap; u8 trailing_pad[0x78]; } archive_symbols; - PAD_STACK(164); + PAD_STACK(160); cobj = gobj->hsd_obj; base = (Toy26B8*) &_Toy_804A26B8; @@ -3281,9 +3292,9 @@ void _Toy_80309404(HSD_GObj* gobj) char* md; s16 tid; - entry = display->first_entry->prev; tid = Toy_sbss_804D6EDC[display->selectedIdx - 1]; + entry = display->first_entry->prev; md = Toy_8030813C(tid); if ((oa = entry->archive) != NULL) { lbArchive_80016EFC(oa); @@ -3337,16 +3348,9 @@ void _Toy_80309404(HSD_GObj* gobj) total = *gmMainLib_GetTrophyCount(); } if (total > 3) { - s32 cnt; - - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) + if ((s32) (display->selectedIdx + 1) >= + _Toy_GetTrophyTotal(base)) { - cnt = base->trophy_count; - } else { - cnt = *gmMainLib_GetTrophyCount(); - } - if ((s32) (display->selectedIdx + 1) >= cnt) { s32 cnt2; ToyListEntry* entry; HSD_Archive* oa; @@ -3362,9 +3366,9 @@ void _Toy_80309404(HSD_GObj* gobj) } else { cnt2 = *gmMainLib_GetTrophyCount(); } - entry = display->last_entry->next; lk = display->selectedIdx - cnt2; tid = Toy_sbss_804D6EDC[lk + 1]; + entry = display->last_entry->next; md = Toy_8030813C(tid); if ((oa = entry->archive) != NULL) { lbArchive_80016EFC(oa); @@ -3383,9 +3387,9 @@ void _Toy_80309404(HSD_GObj* gobj) char* md; s16 tid; - entry = display->last_entry->next; tid = Toy_sbss_804D6EDC[display->selectedIdx + 1]; + entry = display->last_entry->next; md = Toy_8030813C(tid); if ((oa = entry->archive) != NULL) { lbArchive_80016EFC(oa); @@ -3534,7 +3538,7 @@ void _Toy_8030B530(HSD_GObj* arg0) u32 button; f32 angle; - PAD_STACK(72); + PAD_STACK(68); { ToyUnkJObjData* data = anim->gobj->hsd_obj; @@ -3925,7 +3929,7 @@ void _Toy_8030B530(HSD_GObj* arg0) u8 trailing_pad[40]; } archive_symbols; - PAD_STACK(192); + PAD_STACK(188); moved_x = 0.3f * adj_sx; moved_y = 0.3f * adj_sy; @@ -3975,7 +3979,6 @@ void _Toy_8030B530(HSD_GObj* arg0) } if (total > 3) { if ((display->selectedIdx - 1) < 0) { - s32 cnt; s32 lk; ToyListEntry* entry; HSD_Archive* oa; @@ -3983,11 +3986,10 @@ void _Toy_8030B530(HSD_GObj* arg0) if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - cnt = base->trophy_count; + lk = base->trophy_count; } else { - cnt = *gmMainLib_GetTrophyCount(); + lk = *gmMainLib_GetTrophyCount(); } - lk = cnt; lk += display->selectedIdx; entry = display->first_entry; entry = entry->prev; @@ -4012,8 +4014,8 @@ void _Toy_8030B530(HSD_GObj* arg0) HSD_Archive* oa; char* md; s16 tid; - entry = display->first_entry->prev; tid = Toy_sbss_804D6EDC[display->selectedIdx - 1]; + entry = display->first_entry->prev; md = Toy_8030813C(tid); if ((oa = entry->archive) != NULL) { lbArchive_80016EFC(oa); @@ -4061,13 +4063,7 @@ void _Toy_8030B530(HSD_GObj* arg0) } if (total > 3) { s32 cnt; - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) - { - cnt = base->trophy_count; - } else { - cnt = *gmMainLib_GetTrophyCount(); - } + cnt = _Toy_GetTrophyTotal(base); if ((s32) (display->selectedIdx + 1) >= cnt) { s32 cnt2; ToyListEntry* entry; @@ -4102,8 +4098,8 @@ void _Toy_8030B530(HSD_GObj* arg0) HSD_Archive* oa; char* md; s16 tid; - entry = display->last_entry->next; tid = Toy_sbss_804D6EDC[display->selectedIdx + 1]; + entry = display->last_entry->next; md = Toy_8030813C(tid); if ((oa = entry->archive) != NULL) { lbArchive_80016EFC(oa); @@ -4579,9 +4575,9 @@ void _Toy_8030E110(HSD_GObj* arg0) char* model_data; s16 trophy_id; - list_entry = display->first_entry->prev; trophy_id = Toy_sbss_804D6EDC [display->selectedIdx - 1]; + list_entry = display->first_entry->prev; model_data = Toy_8030813C(trophy_id); if ((old_archive = list_entry->archive) != NULL) @@ -4645,24 +4641,15 @@ void _Toy_8030E110(HSD_GObj* arg0) total = *gmMainLib_GetTrophyCount(); } if (total > 3) { - s32 count; - - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == - GM_TOY_LOTTERY)) - { - count = base->trophy_count; - } else { - count = *gmMainLib_GetTrophyCount(); - } - if ((s32) (display->selectedIdx + 1) >= count) + if ((s32) (display->selectedIdx + 1) >= + _Toy_GetTrophyTotal(base)) { - s32 list_idx; + s32 count2; ToyListEntry* list_entry; HSD_Archive* old_archive; char* model_data; s16 trophy_id; - s32 count2; + s32 list_idx; if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == @@ -4672,12 +4659,10 @@ void _Toy_8030E110(HSD_GObj* arg0) } else { count2 = *gmMainLib_GetTrophyCount(); } - list_entry = display->last_entry; - count2 = display->selectedIdx - count2; - list_idx = count2; - list_entry = list_entry->next; + list_idx = display->selectedIdx - count2; trophy_id = Toy_sbss_804D6EDC[list_idx + 1]; + list_entry = display->last_entry->next; model_data = Toy_8030813C(trophy_id); if ((old_archive = list_entry->archive) != NULL) @@ -4700,9 +4685,9 @@ void _Toy_8030E110(HSD_GObj* arg0) char* model_data; s16 trophy_id; - list_entry = display->last_entry->next; trophy_id = Toy_sbss_804D6EDC [display->selectedIdx + 1]; + list_entry = display->last_entry->next; model_data = Toy_8030813C(trophy_id); if ((old_archive = list_entry->archive) != NULL) @@ -4977,16 +4962,6 @@ void _Toy_8030FA50(void) } } -static inline s32 _Toy_GetTrophyTotal(Toy26B8* toy) -{ - if (gm_IsCurrently1PMode() != 0 || - gm_GetCurrentGameMode() == GM_TOY_LOTTERY) - { - return toy->trophy_count; - } - return *gmMainLib_GetTrophyCount(); -} - static inline void _Toy_8030FE48_init_sort_key(s16** ptr) { Toy26B8* toy = (Toy26B8*) &_Toy_804A26B8; @@ -4996,6 +4971,44 @@ static inline void _Toy_8030FE48_init_sort_key(s16** ptr) *ptr = &_Toy_sbss_804D6E64->key[sort_mode]; } +inline void _Toy_8030FE48_setup_entry(ToyListEntry* entry, s16 trophy_idx) +{ + char* result = Toy_8030813C(trophy_idx); + + if (entry->archive != NULL) { + lbArchive_80016EFC(entry->archive); + entry->archive = NULL; + } + entry->archive_name = result + 4; + entry->symbol_name = result + 0x24; + entry->trophy_id = trophy_idx; +} + +inline void _Toy_8030FE48_link_entries(ToyDisplayList* data, s32 entry_count) +{ + s32 i; + ToyListEntry* last_entry; + ToyListEntry* entry; + s32 last; + + last = entry_count - 1; + entry = data->entries; + last_entry = &data->entries[last]; + for (i = 0; i < entry_count; i++) { + if (i == 0) { + entry->prev = last_entry; + } else { + entry->prev = &data->entries[i - 1]; + } + if (i == last) { + entry->next = data->entries; + } else { + entry->next = &data->entries[i + 1]; + } + entry++; + } +} + void _Toy_8030FE48(ToyDisplayList* data, s32 arg1) { Toy26B8* toy = (Toy26B8*) &_Toy_804A26B8; @@ -5004,8 +5017,6 @@ void _Toy_8030FE48(ToyDisplayList* data, s32 arg1) void* sym2; s32 count; s32 entry_count; - char* result; - s16 trophyIdx; void* sym; void* zero; s16* ptr; @@ -5035,25 +5046,7 @@ void _Toy_8030FE48(ToyDisplayList* data, s32 arg1) } if (arg1 == 0) { - s32 last = entry_count - 1; - ToyListEntry* entry = data->entries; - s32 i; - ToyListEntry* last_entry; - - last_entry = &data->entries[last]; - for (i = 0; i < entry_count; i++) { - if (i == 0) { - entry->prev = last_entry; - } else { - entry->prev = &data->entries[i - 1]; - } - if (i == last) { - entry->next = data->entries; - } else { - entry->next = &data->entries[i + 1]; - } - entry++; - } + _Toy_8030FE48_link_entries(data, entry_count); } zero = NULL; @@ -5068,31 +5061,15 @@ void _Toy_8030FE48(ToyDisplayList* data, s32 arg1) start = 0; offset = start; entry = data->entries; - for (; start < data->visible_count; start += 1, offset += 2, entry++) { + for (; start < data->visible_count; offset += 2, entry++, start += 1) { if (start == data->selectedIdx) { - trophyIdx = Toy_sbss_804D6EDC[offset / 2]; - result = Toy_8030813C(trophyIdx); - if (entry->archive != NULL) { - lbArchive_80016EFC(entry->archive); - entry->archive = NULL; - } - - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophyIdx; + _Toy_8030FE48_setup_entry(entry, + Toy_sbss_804D6EDC[offset / 2]); entry->archive = lbArchive_LoadSymbols( entry->archive_name, &sym, entry->symbol_name, 0); } else { - trophyIdx = Toy_sbss_804D6EDC[offset / 2]; - result = Toy_8030813C(trophyIdx); - if (entry->archive != NULL) { - lbArchive_80016EFC(entry->archive); - entry->archive = NULL; - } - - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophyIdx; + _Toy_8030FE48_setup_entry(entry, + Toy_sbss_804D6EDC[offset / 2]); } } @@ -5146,29 +5123,11 @@ void _Toy_8030FE48(ToyDisplayList* data, s32 arg1) } if (startIdx == data->selectedIdx) { - trophyIdx = Toy_sbss_804D6EDC[startIdx]; - result = Toy_8030813C(trophyIdx); - if (cur->archive != NULL) { - lbArchive_80016EFC(cur->archive); - cur->archive = NULL; - } - - cur->archive_name = result + 4; - cur->symbol_name = result + 0x24; - cur->trophy_id = trophyIdx; + _Toy_8030FE48_setup_entry(cur, Toy_sbss_804D6EDC[startIdx]); cur->archive = lbArchive_LoadSymbols(cur->archive_name, &sym2, cur->symbol_name, 0); } else { - trophyIdx = Toy_sbss_804D6EDC[startIdx]; - result = Toy_8030813C(trophyIdx); - if (cur->archive != NULL) { - lbArchive_80016EFC(cur->archive); - cur->archive = NULL; - } - - cur->archive_name = result + 4; - cur->symbol_name = result + 0x24; - cur->trophy_id = trophyIdx; + _Toy_8030FE48_setup_entry(cur, Toy_sbss_804D6EDC[startIdx]); } cur = cur->next; diff --git a/src/melee/ty/tydisplay.c b/src/melee/ty/tydisplay.c index 23f0f1f79e..a72ea8e339 100644 --- a/src/melee/ty/tydisplay.c +++ b/src/melee/ty/tydisplay.c @@ -509,11 +509,118 @@ static inline void _tyDisplay_80319540_sort(TyDspConfig* cfg, TyDspGrid* grid) } } +inline void _tyDisplay_80319994_sort(TyDspConfig* cfg, TyDspGrid* grid) +{ + s32 pivot; + s32 n2; + _tyDisplay_80318B1C(cfg->x08); + + if (cfg->x08 > 1) { + n2 = (cfg->x08 / 3) * 2; + if (n2 > 0) { + struct { + u8 pad0[4]; + TySortElem tmp2; + u8 pad1[4]; + TySortElem tmp1, tmp0; + } temps; + s32 mid = n2 / 2; + TyDspGrid* cur; + s32 n; + + if (mid != 0) { + temps.tmp0 = grid->sort[0]; + grid->sort[0] = grid->sort[mid]; + grid->sort[mid] = temps.tmp0; + } + + pivot = 0; + cur = (TyDspGrid*) ((size_t) grid + sizeof(TySortElem)); + for (n = 1; n2 >= n; + cur = (TyDspGrid*) ((size_t) cur + sizeof(TySortElem)), n++) + { + if (*(s32*) &cur->sort[0].val > *(s32*) &grid->sort[0].val) { + pivot += 1; + if (pivot != n) { + TySortElem* s = tyDisplay_GetGridSortElem( + pivot * sizeof(TySortElem), grid); + temps.tmp1 = *s; + *s = cur->sort[0]; + cur->sort[0] = temps.tmp1; + } + } + } + + if (pivot != 0) { + temps.tmp2 = grid->sort[0]; + grid->sort[0] = grid->sort[pivot]; + grid->sort[pivot] = temps.tmp2; + } + + _tyDisplay_80318714(grid->sort, 0, pivot - 1); + _tyDisplay_80318714(grid->sort, pivot + 1, n2); + } + } +} + +inline void _tyDisplay_80318CB4_sort(TyDspConfig* cfg, TyDspGrid* grid) +{ + s32 n2; + _tyDisplay_80318B1C(cfg->x08); + + if (cfg->x08 > 1) { + n2 = (cfg->x08 / 3) * 2; + if (0 < n2) { + struct { + TySortElem tmp2; + u8 pad1[4]; + TySortElem tmp1, tmp0; + } temps; + s32 mid = n2 / 2; + TyDspGrid* cur; + s32 pivot, n; + + if (mid != 0) { + temps.tmp0 = grid->sort[0]; + grid->sort[0] = grid->sort[mid]; + grid->sort[mid] = temps.tmp0; + } + + pivot = 0; + cur = (TyDspGrid*) ((size_t) grid + sizeof(TySortElem)); + for (n = 1; n2 >= n; + cur = (TyDspGrid*) ((size_t) cur + sizeof(TySortElem)), n++) + { + if (*(s32*) &cur->sort[0].val > *(s32*) &grid->sort[0].val) { + pivot += 1; + if (pivot != n) { + TySortElem* s = tyDisplay_GetGridSortElem( + pivot * sizeof(TySortElem), grid); + temps.tmp1 = *s; + *s = cur->sort[0]; + cur->sort[0] = temps.tmp1; + } + } + } + + if (pivot != 0) { + temps.tmp2 = grid->sort[0]; + grid->sort[0] = grid->sort[pivot]; + grid->sort[pivot] = temps.tmp2; + } + + _tyDisplay_80318714(grid->sort, 0, pivot - 1); + _tyDisplay_80318714(grid->sort, pivot + 1, n2); + } + } +} + static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count) { if (count > 1) { s32 n2; s32 pivot; + TyDspGrid* base = grid; n2 = count - 1; if (n2 > 0) { struct { @@ -523,6 +630,58 @@ static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count) } temps; s32 mid = n2 / 2; TyDspPos* p; + TyDspGrid* cur; + s32 n; + + if (mid != 0) { + temps.tmp0 = base->pos[0]; + base->pos[0] = base->pos[mid]; + base->pos[mid] = temps.tmp0; + } + + pivot = 0; + cur = (TyDspGrid*) ((size_t) base + sizeof(TyDspPos)); + for (n = 1; n2 >= n; + cur = (TyDspGrid*) ((size_t) cur + sizeof(TyDspPos)), n++) + { + if (cur->pos[0].z < base->pos[0].z) { + pivot += 1; + if (pivot != n) { + p = (TyDspPos*) ((size_t) base + + pivot * sizeof(TyDspPos) + 0x97C); + temps.tmp1 = *p; + *p = cur->pos[0]; + cur->pos[0] = temps.tmp1; + } + } + } + + if (pivot != 0) { + temps.tmp2 = base->pos[0]; + base->pos[0] = base->pos[pivot]; + base->pos[pivot] = temps.tmp2; + } + + _tyDisplay_8031830C((TySortElem*) base->pos, 0, pivot - 1); + _tyDisplay_8031830C((TySortElem*) base->pos, pivot + 1, n2); + } + } +} + +inline void _tyDisplay_80318CB4_sort_pos(TyDspGrid* grid, s32 count) +{ + if (count > 1) { + s32 pivot; + s32 n2 = count - 1; + if (n2 > 0) { + struct { + TyDspPos tmp2; + u8 pad1[4]; + TyDspPos tmp1, tmp0; + } temps; + s32 mid = n2 / 2; + TyDspPos* p; + TyDspGrid* cur; s32 n; if (mid != 0) { @@ -532,15 +691,18 @@ static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count) } pivot = 0; - for (n = 1; n2 >= n; n++) { - if (grid->pos[n].z < grid->pos[0].z) { + cur = (TyDspGrid*) ((size_t) grid + sizeof(TyDspPos)); + for (n = 1; n2 >= n; + cur = (TyDspGrid*) ((size_t) cur + sizeof(TyDspPos)), n++) + { + if (cur->pos[0].z < grid->pos[0].z) { pivot += 1; if (pivot != n) { p = (TyDspPos*) ((size_t) grid + pivot * sizeof(TyDspPos) + 0x97C); temps.tmp1 = *p; - *p = grid->pos[n]; - grid->pos[n] = temps.tmp1; + *p = cur->pos[0]; + cur->pos[0] = temps.tmp1; } } } @@ -557,6 +719,11 @@ static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count) } } +static inline f32 _tyDisplay_80318CB4_calc_dist_sq(f32 dz, f32 dx) +{ + return dx * dx + dz * dz; +} + static inline void _tyDisplay_80318CB4_place_toys(TyDspGrid* grid, TyDspConfig* cfg) { @@ -586,8 +753,8 @@ void _tyDisplay_80318CB4(s32 arg0) s32 ring_count; s32 ring_max; s32 prev_ring_size; - f32 radius; f32 angle; + f32 radius; f32 base_step; f32 dist_limit; s32 count; @@ -653,9 +820,8 @@ void _tyDisplay_80318CB4(s32 arg0) } for (k = i - 1; k >= start; k--) { f32 dx = grid->pos[i].x - grid->pos[k].x; - f32 dist = sqrtf( - dx * dx + (grid->pos[i].z - grid->pos[k].z) * - (grid->pos[i].z - grid->pos[k].z)); + f32 dist = sqrtf(_tyDisplay_80318CB4_calc_dist_sq( + grid->pos[i].z - grid->pos[k].z, dx)); if (dist > 2.1474836e9f || dist < -2.1474836e9f) { OSReport("*** tyDisplay Atari Irregul!\n"); HSD_ASSERT(0xC6, 0); @@ -713,9 +879,9 @@ void _tyDisplay_80318CB4(s32 arg0) } count = cfg->x08; - _tyDisplay_80319994_sort_pos(grid, count); + _tyDisplay_80318CB4_sort_pos(grid, count); - _tyDisplay_80319540_sort(cfg, grid); + _tyDisplay_80318CB4_sort(cfg, grid); _tyDisplay_80318CB4_place_toys(grid, cfg); } @@ -825,14 +991,10 @@ void _tyDisplay_80319994(s32 arg0) { TyDspConfig* cfg = _tyDisplay_804D6F18; TyDspGrid* grid = _tyDisplay_804D6F14; + TyDspGrid* cur; f32 xoff = 0.0f; s32 pivot; s32 count; - TyDspGrid* cur; - s32 ring; - s32 i; - s32 col; - s32 row; PAD_STACK(0x20); { pivot = arg0; @@ -843,8 +1005,12 @@ void _tyDisplay_80319994(s32 arg0) grid->x0C_max_x = 3.5f; { - cur = grid; + s32 ring; + s32 i; + s32 col; + s32 row; + cur = grid; row = 0; col = 0; ring = 1; @@ -900,21 +1066,24 @@ void _tyDisplay_80319994(s32 arg0) } } - _tyDisplay_80319540_sort(cfg, grid); + _tyDisplay_80319994_sort(cfg, grid); } { - for (cur = (TyDspGrid*) ((size_t) grid + (i = 0) * sizeof(TySortElem)); - i < cfg->x08; - cur = (TyDspGrid*) ((size_t) cur + sizeof(TySortElem)), i++) + for (cur = (TyDspGrid*) ((size_t) grid + + (count = 0) * sizeof(TySortElem)); + count < cfg->x08; + cur = (TyDspGrid*) ((size_t) cur + sizeof(TySortElem)), count++) { HSD_GObj* gobj; cfg->x78 = _tyDisplay_8031BC54(cur->sort[0].key); gobj = cfg->x78; if (gobj != NULL) { - _tyDisplay_804D6F10[i] = (HSD_JObj*) gobj->hsd_obj; - HSD_JObjSetTranslateX(_tyDisplay_804D6F10[i], cur->pos[0].x); - HSD_JObjSetTranslateZ(_tyDisplay_804D6F10[i], cur->pos[0].z); + _tyDisplay_804D6F10[count] = (HSD_JObj*) gobj->hsd_obj; + HSD_JObjSetTranslateX(_tyDisplay_804D6F10[count], + cur->pos[0].x); + HSD_JObjSetTranslateZ(_tyDisplay_804D6F10[count], + cur->pos[0].z); } } } diff --git a/src/sysdolphin/baselib/debugconsole_main.c b/src/sysdolphin/baselib/debugconsole_main.c index 0731bee554..0abed809eb 100644 --- a/src/sysdolphin/baselib/debugconsole_main.c +++ b/src/sysdolphin/baselib/debugconsole_main.c @@ -1127,6 +1127,7 @@ void hsd_80394F48(void* data) struct lbl_8040AB00_t* hi_color; s32 x_base; s32* pxC8; + s32 entry_idx; s32 i; s32 b6; @@ -1181,7 +1182,7 @@ void hsd_80394F48(void* data) hi_color = hsd_80394F48_get_highlight_color(base_color); cur_row -= 1; - for (i = 0; dp->entries[i] != 0; i++) { + for (entry_idx = 0; dp->entries[entry_idx] != 0; entry_idx++) { *px4 = x_base; *px8 = (*px40 - 0x28) - (cur_row-- + 1) * 14; @@ -1194,16 +1195,16 @@ void hsd_80394F48(void* data) (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } - if (i == dp->index) { + if (entry_idx == dp->index) { *px50 = hi_color; } else { hsd_80394F48_set_base_color(px50); } *px4 += 11; - hsd_80394434(dp->entries[i]); + hsd_80394434(dp->entries[entry_idx]); - *px4 += hsd_80394F48_entry_length(i, dp) * 11; + *px4 += hsd_80394F48_entry_length(entry_idx, dp) * 11; hsd_80394F48_set_base_color(px50); b6 = sp->x0_b6; diff --git a/src/sysdolphin/baselib/generator.c b/src/sysdolphin/baselib/generator.c index 6c48a94985..cefa7add3a 100644 --- a/src/sysdolphin/baselib/generator.c +++ b/src/sysdolphin/baselib/generator.c @@ -361,19 +361,21 @@ HSD_Generator* hsd_8039D9C8(void) // switch case logic, Newton-Raphson sqrt inlining, trig matrix layout f32 hsd_8039DAD4(HSD_Generator* gen) { - f32 radius; - Vec3 vel_out; Vec3 vel_copy; + f32 vel_mag_sq; Vec3 emit_pos; - Vec3 cross1; Vec3 tmpvec; + Vec3 vel_out; Mtx rot_mtx; Mtx jobj_mtx; Vec3 look_dir; Vec3 cam_up; + Vec3 cross1; + Vec3 vel_norm; Mtx trig_mtx; f64 eps; - f32 vel_mag_sq; + f32 abs_projected; + f32 tmp; f32 angle1; f32 sin_az; f32 cos_az; @@ -382,11 +384,10 @@ f32 hsd_8039DAD4(HSD_Generator* gen) f32 cur_angle; f32 cone_angle; f32 elevation; - f32 tmp; + f32 radius; f32 angle3; - PAD_STACK(8); - angle1 = angle3 = 0.0F; + angle3 = angle1 = 0.0F; if (gen->count < 1.0F) { return gen->count; } @@ -399,16 +400,8 @@ f32 hsd_8039DAD4(HSD_Generator* gen) vel_copy.z = gen->vel.z; /* Compute velocity magnitude */ - vel_mag_sq = vel_copy.z * vel_copy.z; - vel_mag_sq += vel_copy.x * vel_copy.x + vel_copy.y * vel_copy.y; - if (vel_mag_sq > 0.0F) { - f64 e = __frsqrte(vel_mag_sq); - e = 0.5 * e * -(vel_mag_sq * (e * e) - 3.0); - e = 0.5 * e * -(vel_mag_sq * (e * e) - 3.0); - e = 0.5 * e * -(vel_mag_sq * (e * e) - 3.0); - tmp = (f32) (vel_mag_sq * e); - vel_mag_sq = tmp; - } + vel_mag_sq = sqrtf(vel_copy.z * vel_copy.z + + (vel_copy.x * vel_copy.x + vel_copy.y * vel_copy.y)); /* Initialize rotation matrix */ PSMTXIdentity(rot_mtx); @@ -418,36 +411,36 @@ f32 hsd_8039DAD4(HSD_Generator* gen) if ((gen->type & 0x100) && gen->jobj != NULL && (gen->type & 0x400) && !(gen->kind & 0x30000)) { - PSMTXCopy((void*) ((u8*) gen->jobj + 0x44), jobj_mtx); + PSMTXCopy(gen->jobj->mtx, jobj_mtx); /* Extract and normalize each column of the 3x3 rotation */ - tmpvec.x = jobj_mtx[0][0]; - tmpvec.y = jobj_mtx[1][0]; - tmpvec.z = jobj_mtx[2][0]; - PSVECNormalize(&tmpvec, &tmpvec); - rot_mtx[0][0] = tmpvec.x; - rot_mtx[1][0] = tmpvec.y; - rot_mtx[2][0] = tmpvec.z; - - tmpvec.x = jobj_mtx[0][1]; - tmpvec.y = jobj_mtx[1][1]; - tmpvec.z = jobj_mtx[2][1]; - PSVECNormalize(&tmpvec, &tmpvec); - rot_mtx[0][1] = tmpvec.x; - rot_mtx[1][1] = tmpvec.y; - rot_mtx[2][1] = tmpvec.z; - - tmpvec.x = jobj_mtx[0][2]; - tmpvec.y = jobj_mtx[1][2]; - tmpvec.z = jobj_mtx[2][2]; - PSVECNormalize(&tmpvec, &tmpvec); - rot_mtx[0][2] = tmpvec.x; - rot_mtx[1][2] = tmpvec.y; - rot_mtx[2][2] = tmpvec.z; + vel_out.x = jobj_mtx[0][0]; + vel_out.y = jobj_mtx[1][0]; + vel_out.z = jobj_mtx[2][0]; + PSVECNormalize(&vel_out, &vel_out); + rot_mtx[0][0] = vel_out.x; + rot_mtx[1][0] = vel_out.y; + rot_mtx[2][0] = vel_out.z; + + vel_out.x = jobj_mtx[0][1]; + vel_out.y = jobj_mtx[1][1]; + vel_out.z = jobj_mtx[2][1]; + PSVECNormalize(&vel_out, &vel_out); + rot_mtx[0][1] = vel_out.x; + rot_mtx[1][1] = vel_out.y; + rot_mtx[2][1] = vel_out.z; + + vel_out.x = jobj_mtx[0][2]; + vel_out.y = jobj_mtx[1][2]; + vel_out.z = jobj_mtx[2][2]; + PSVECNormalize(&vel_out, &vel_out); + rot_mtx[0][2] = vel_out.x; + rot_mtx[1][2] = vel_out.y; + rot_mtx[2][2] = vel_out.z; - rot_mtx[0][3] = 0.0F; - rot_mtx[1][3] = 0.0F; rot_mtx[2][3] = 0.0F; + rot_mtx[1][3] = 0.0F; + rot_mtx[0][3] = 0.0F; } /* Billboard orientation: kind & 0x10000 */ @@ -474,8 +467,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) } /* Velocity-based rotation */ - if ((gen->type & 0xF) != 1 && vel_mag_sq > 0.0F) { - Vec3 vel_norm; + if ((gen->type & 0xF) != 1 && vel_mag_sq > 1.1920929e-7F) { vel_norm.x = gen->vel.x; vel_norm.y = gen->vel.y; vel_norm.z = gen->vel.z; @@ -496,11 +488,10 @@ f32 hsd_8039DAD4(HSD_Generator* gen) sin_az = cosf(sin_az); { - f32 projected_z = vel_norm.z * sin_az; - projected_z += vel_norm.y * cos_az; - tmp = projected_z; - *(s32*) &tmp &= 0x7FFFFFFF; - if (tmp < 1.1754944e-38F) { + f32 projected_z = vel_norm.y * cos_az + vel_norm.z * sin_az; + abs_projected = projected_z; + *(s32*) &abs_projected &= 0x7FFFFFFF; + if (abs_projected < 1.1754944e-38F) { if (vel_norm.x >= 0.0F) { elevation = 1.5707964F; } else { @@ -546,8 +537,9 @@ f32 hsd_8039DAD4(HSD_Generator* gen) angle1 = atan2f(rot_mtx[1][2], rot_mtx[2][2]); } { - f32 comb = rot_mtx[2][2] * cosf(angle1); - comb += rot_mtx[1][2] * sinf(angle1); + f32 first = rot_mtx[2][2] * cosf(angle1); + f32 comb_value = first + rot_mtx[1][2] * sinf(angle1); + f32 comb = comb_value; tmp = comb; *(s32*) &tmp &= 0x7FFFFFFF; if (tmp < 1.1754944e-38F) { @@ -605,7 +597,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) /* Compute radius */ if (gen->radius < 0.0F) { sin_az = -gen->radius; - radius = 0.0F; + radius = 1.0F; } else { radius = HSD_Randf(); if ((gen->type & 0xF) == 3 || (gen->type & 0xF) == 4) { @@ -618,7 +610,6 @@ f32 hsd_8039DAD4(HSD_Generator* gen) switch (gen->type & 0xF) { case 6: if (gen->angle < 0.0F) { - emit_pos.z = sin_az; cur_angle += angle_step; tmp = sin_az; *(s32*) &tmp &= 0x7FFFFFFF; @@ -630,7 +621,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) } } else { f64 cone_angle_d = - M_PI - atan2f(gen->aux.cone.height, sin_az) - + M_PI_2 - atan2f(gen->aux.cone.height, sin_az) - gen->angle; cone_angle = (f32) cone_angle_d; } @@ -645,7 +636,6 @@ f32 hsd_8039DAD4(HSD_Generator* gen) cone_angle = radius * gen->angle; cur_angle = range * rnd + cur_angle; } - emit_pos.z = sin_az; tmp = sin_az; *(s32*) &tmp &= 0x7FFFFFFF; if (tmp < 1.1754944e-38F) { @@ -657,22 +647,25 @@ f32 hsd_8039DAD4(HSD_Generator* gen) } else { f64 cone_angle_d = gen->angle + - (M_PI - atan2f(gen->aux.cone.height, sin_az)); + (M_PI_2 - atan2f(gen->aux.cone.height, sin_az)); cone_angle = (f32) cone_angle_d; } } break; case 7: if (gen->angle < 0.0F) { - cone_angle = (f32) (M_PI - gen->angle); + cone_angle = (f32) (M_PI_2 - gen->angle); cur_angle += angle_step; } else { - cur_angle = gen->aux.disc.minAngle; + { + f32 min_angle = gen->aux.disc.minAngle; + cur_angle = min_angle; + } { f32 rnd = HSD_Randf(); f32 range = gen->aux.disc.maxAngle - cur_angle; cur_angle = range * rnd + cur_angle; - cone_angle = (f32) (M_PI + gen->angle); + cone_angle = (f32) (M_PI_2 + gen->angle); } } break; @@ -767,7 +760,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) case 2: /* tornado */ { if (gen->radius < 0.0F) { - sin_az = 0.0F; + sin_az = 1.0F; } else { sin_az = HSD_Randf(); } @@ -787,7 +780,6 @@ f32 hsd_8039DAD4(HSD_Generator* gen) case 5: /* rect */ { - Vec3 vel_temp; emit_pos.x = HSD_Randf(); emit_pos.y = HSD_Randf(); emit_pos.z = HSD_Randf(); @@ -854,7 +846,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) if (rnd < t1) { emit_pos.z = emit_pos.z > 0.5F ? 1.0F : 0.0F; } else { - f32 t2 = 1.0F - c2 * r0 * a2; + f32 t2 = 1.0F - c2 * a2 * r0; if (rnd > t2) { emit_pos.y = emit_pos.y > 0.5F ? 1.0F : 0.0F; } else { @@ -873,17 +865,17 @@ f32 hsd_8039DAD4(HSD_Generator* gen) emit_pos.z -= 0.5F; /* Multiply by rect's 3x3 matrix */ - vel_temp.x = gen->aux.rect.yx * emit_pos.y + - gen->aux.rect.xx * emit_pos.x + - gen->aux.rect.zx * emit_pos.z; - vel_temp.y = gen->aux.rect.yy * emit_pos.y + - gen->aux.rect.xy * emit_pos.x + - gen->aux.rect.zy * emit_pos.z; - vel_temp.z = gen->aux.rect.yz * emit_pos.y + - gen->aux.rect.xz * emit_pos.x + - gen->aux.rect.zz * emit_pos.z; - - PSMTXMultVec(rot_mtx, &vel_temp, &emit_pos); + tmpvec.x = gen->aux.rect.xx * emit_pos.x + + gen->aux.rect.yx * emit_pos.y + + gen->aux.rect.zx * emit_pos.z; + tmpvec.y = gen->aux.rect.xy * emit_pos.x + + gen->aux.rect.yy * emit_pos.y + + gen->aux.rect.zy * emit_pos.z; + tmpvec.z = gen->aux.rect.xz * emit_pos.x + + gen->aux.rect.yz * emit_pos.y + + gen->aux.rect.zz * emit_pos.z; + + PSMTXMultVec(rot_mtx, &tmpvec, &emit_pos); emit_pos.x += gen->pos.x; emit_pos.y += gen->pos.y; emit_pos.z += gen->pos.z; @@ -917,7 +909,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) f32 r0 = gen->aux.cone.height; if (r0 == 0.0F || __fabs(r0 - M_PI) < eps) { f32 rnd = sqrtf(HSD_Randf()); - radius = (f32) (M_PI * rnd); + radius = (f32) (M_PI_2 * rnd); { f32 rnd2 = HSD_Randf(); if (rnd2 < 0.5F) { @@ -950,7 +942,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) vel_out.x = cos_az * cos_r; sin_el = sinf(cone_angle); sin_r = sinf(radius); - vel_out.y = sin_el * sin_r; + vel_out.y = sin_r * sin_el; vel_out.z = cosf(radius); } @@ -1073,13 +1065,7 @@ HSD_Generator* hsd_8039EFAC(s32 linkNo, s32 bank, s32 gfx_id, HSD_JObj* jobj) // frame differences remain HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) { - HSD_PSCmdList*** cmdListArr; - HSD_PSTexGroup* tg; HSD_Generator* gen; - s32 ofs; - f32 mag; - f32 f0, f1, f3; - u32 shape; if (bank >= 0x41) { return NULL; @@ -1091,44 +1077,40 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) return NULL; } - cmdListArr = (HSD_PSCmdList***) &ptclref_804D0E5C[bank]; - ofs = idx * 4; - if ((*cmdListArr)[idx] == NULL) { + if (((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx] == NULL) { return NULL; } gen = hsd_8039D9C8(); if (gen != NULL) { - gen->type = (*cmdListArr)[idx]->type; + gen->type = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->type; gen->bank = bank; gen->linkNo = linkNo; - gen->kind = (*cmdListArr)[idx]->kind; - gen->texGroup = (*cmdListArr)[idx]->texGroup; - gen->life = (*cmdListArr)[idx]->life; - gen->genLife = (*cmdListArr)[idx]->genLife; + gen->kind = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->kind; + gen->texGroup = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->texGroup; + gen->life = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->life; + gen->genLife = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->genLife; gen->pos.z = 0.0F; gen->pos.y = 0.0F; gen->pos.x = 0.0F; - gen->vel.x = (*cmdListArr)[idx]->vx; - gen->vel.y = (*cmdListArr)[idx]->vy; - gen->vel.z = (*cmdListArr)[idx]->vz; - gen->grav = (*cmdListArr)[idx]->grav; - gen->fric = (*cmdListArr)[idx]->fric; - gen->size = (*cmdListArr)[idx]->size; - gen->cmdList = (*cmdListArr)[idx]->cmdList; - gen->radius = (*cmdListArr)[idx]->radius; - gen->angle = (*cmdListArr)[idx]->angle; - gen->random = (*cmdListArr)[idx]->random; + gen->vel.x = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->vx; + gen->vel.y = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->vy; + gen->vel.z = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->vz; + gen->grav = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->grav; + gen->fric = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->fric; + gen->size = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->size; + gen->cmdList = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->cmdList; + gen->radius = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->radius; + gen->angle = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->angle; + gen->random = ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->random; if (gen->kind & 0x100) { - f1 = gen->random; - if (f1 < 0.0F) { - f3 = 1.0F; - if ((1.0F + f1) > 1.1920929e-7F) { - } else { - f3 = 0.0F; - } - gen->count = f3; + if (gen->random < 0.0F) { + gen->count = + (1.0F + gen->random > 1.1920929e-7F) ? 1.0F : 0.0F; } else { gen->count = 0.9999999F; } @@ -1138,95 +1120,97 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) gen->count = HSD_Randf(); } - tg = ((HSD_PSTexGroup***) ((uintptr_t) cmdListArr - bank * 4 - - 0x30C))[bank][gen->texGroup]; - if (tg != NULL && tg->palflag != 0) { - gen->kind |= 0x10; + { + HSD_PSTexGroup* tg = psTexGroupArray[bank][gen->texGroup]; + if (tg != NULL && tg->palflag != 0) { + gen->kind |= 0x10; + } } gen->jobj = NULL; gen->numChild = 0; - shape = gen->type & 0xF; - switch (shape) { + switch (gen->type & 0xF) { case 0: case 3: case 4: { - HSD_PSCmdList* c = (*cmdListArr)[idx]; + HSD_PSCmdList* c = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]; f32 p1 = c->param1; if (p1 == 0.0F && c->param2 == 0.0F) { gen->aux.disc.minAngle = 0.0F; gen->aux.disc.maxAngle = 6.2831855F; } else { gen->aux.disc.minAngle = p1; - gen->aux.disc.maxAngle = (*cmdListArr)[idx]->param2; + gen->aux.disc.maxAngle = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param2; } break; } case 1: - gen->aux.line.x2 = (*cmdListArr)[idx]->param1; - gen->aux.line.y2 = (*cmdListArr)[idx]->param2; - gen->aux.line.z2 = (*cmdListArr)[idx]->param3; + gen->aux.line.x2 = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param1; + gen->aux.line.y2 = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param2; + gen->aux.line.z2 = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param3; break; case 6: case 7: { - HSD_PSCmdList* c = (*cmdListArr)[idx]; + HSD_PSCmdList* c = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]; f32 p1 = c->param1; if (p1 == 0.0F && c->param2 == 0.0F) { gen->aux.cone.minAngle = 0.0F; gen->aux.cone.maxAngle = 6.2831855F; } else { gen->aux.cone.minAngle = p1; - gen->aux.cone.maxAngle = (*cmdListArr)[idx]->param2; + gen->aux.cone.maxAngle = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param2; } - gen->aux.cone.height = (*cmdListArr)[idx]->param3; + gen->aux.cone.height = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param3; break; } case 5: { - f0 = (*cmdListArr)[idx]->param1; - gen->aux.rect.x = f0; - gen->aux.rect.xx = f0; - f0 = (*cmdListArr)[idx]->param2; - gen->aux.rect.y = f0; - gen->aux.rect.zx = f0; - f0 = (*cmdListArr)[idx]->param3; - gen->aux.rect.z = f0; - gen->aux.rect.zy = f0; - gen->aux.rect.zz = 0.0F; + gen->aux.rect.xx = gen->aux.rect.x = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param1; + gen->aux.rect.yy = gen->aux.rect.y = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param2; + gen->aux.rect.zz = gen->aux.rect.z = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param3; + gen->aux.rect.zy = 0.0F; + gen->aux.rect.zx = 0.0F; gen->aux.rect.yz = 0.0F; - gen->aux.rect.yy = 0.0F; - gen->aux.rect.xy = 0.0F; - gen->aux.rect.xz = 0.0F; gen->aux.rect.yx = 0.0F; + gen->aux.rect.xz = 0.0F; + gen->aux.rect.xy = 0.0F; gen->aux.rect.flag = 0; - if ((*cmdListArr)[idx]->param1 < 0.0F) { + if (((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param1 < + 0.0F) + { gen->aux.rect.flag |= 1; } - if ((*cmdListArr)[idx]->param2 < 0.0F) { + if (((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param2 < + 0.0F) + { gen->aux.rect.flag |= 2; } - if ((*cmdListArr)[idx]->param3 < 0.0F) { + if (((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param3 < + 0.0F) + { gen->aux.rect.flag |= 4; } break; } case 8: { - f32 vx = gen->vel.x; - f32 vy = gen->vel.y; - f32 vz = gen->vel.z; - f32 vx_sq = vx * vx; - f32 vy_sq = vy * vy; - f32 vz_sq = vz * vz; - mag = vx_sq + vy_sq; - mag += vz_sq; - gen->aux.sphere.speed = sqrtf(mag); - - f0 = gen->vel.x; - f1 = gen->vel.z; - vx_sq = f0 * f0; - vz_sq = f1 * f1; - mag = vx_sq + vz_sq; - mag = sqrtf(mag); + f32 mag; + + gen->aux.sphere.speed = + sqrtf(gen->vel.z * gen->vel.z + + (gen->vel.x * gen->vel.x + gen->vel.y * gen->vel.y)); + + mag = sqrtf(gen->vel.x * gen->vel.x + gen->vel.z * gen->vel.z); if (mag < 1.1754944e-38F) { if (gen->vel.y >= 0.0F) { @@ -1247,13 +1231,14 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) } else { gen->aux.sphere.lonMid = atan2f(gen->vel.z, gen->vel.x); } - gen->aux.sphere.latRange = (*cmdListArr)[idx]->param1; - f1 = gen->aux.sphere.latRange; - if (f1 < 0.0F) { - gen->aux.sphere.latRange = -f1; + gen->aux.sphere.latRange = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param1; + if (gen->aux.sphere.latRange < 0.0F) { + gen->aux.sphere.latRange = -gen->aux.sphere.latRange; gen->aux.sphere.speed = -gen->aux.sphere.speed; } - gen->aux.sphere.lonRange = (*cmdListArr)[idx]->param2; + gen->aux.sphere.lonRange = + ((HSD_PSCmdList***) ptclref_804D0E5C)[bank][idx]->param2; break; } default: diff --git a/src/sysdolphin/baselib/hsd_3915.c b/src/sysdolphin/baselib/hsd_3915.c index bdd7506790..a9d4c6b884 100644 --- a/src/sysdolphin/baselib/hsd_3915.c +++ b/src/sysdolphin/baselib/hsd_3915.c @@ -407,7 +407,6 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) step_x = dx / count; GXWGFifo.f32 = x1; - i = 0; GXWGFifo.f32 = y1; r = color->r; GXWGFifo.u8 = r; @@ -434,7 +433,7 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) GXWGFifo.u8 = b; GXWGFifo.u8 = a; - while ((f32) i <= count) { + for (i = 0; (f32) i <= count; i++) { GXBegin(0xA8, 0, 2); GXWGFifo.f32 = x1; GXWGFifo.f32 = y1; @@ -457,9 +456,8 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) b = color->b; g = color->g; r = color->r; - x1 += step_x; + x1 = step_x + x1; y1 += step_y; - i++; GXWGFifo.u8 = r; GXWGFifo.u8 = g; GXWGFifo.u8 = b; @@ -467,9 +465,27 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) } } +/// @todo .sdata2 order helpers; split-owned one-element arrays preserve the +/// duplicate pool entries at their target boundaries. +static const GXColor hsd_3915_default_color = { 0xFF, 0xFF, 0xFF, 0xFF }; + +#ifdef MUST_MATCH +static inline void hsd_3915_sdata2_order0(void) +{ + (void) 1.0F; + (void) 10.0F; + (void) -10.0F; + (void) 5.0F; + (void) 620.0F; +} +#endif + void hsd_80392194(u8* dst, s32 flags, s32 unused1, s32 unused2, const u8* src) { u8 b; +#ifdef MUST_MATCH + hsd_3915_sdata2_order0(); +#endif dst[0] = src[0]; if (flags & 1) { b = src[2]; @@ -479,6 +495,15 @@ void hsd_80392194(u8* dst, s32 flags, s32 unused1, s32 unused2, const u8* src) dst[1] = b; } +#ifdef MUST_MATCH +static const f64 hsd_3915_sdata2_half[1] = { 0.5 }; + +static inline void hsd_3915_sdata2_order1(void) +{ + (void) 2.0F; +} +#endif + typedef void (*GlyphFn)(u8* dst, s32 flags, s32 unused1, s32 unused2, const u8* src); @@ -494,7 +519,7 @@ GlyphEntry lbl_80408898[4] = { { 0xB3808000, hsd_80392194 }, }; -DebugFontGlyph HSD_DebugFontAtlas[] ATTRIBUTE_ALIGN(32) = { +DebugFontGlyph HSD_DebugFontAtlas[] = { #include }; @@ -516,6 +541,9 @@ void hsd_803921B8(void* bitmap, s32 x, s32 y, s32 dst, s32 w, s32 h, u8* bmp; GlyphEntry* entry; +#ifdef MUST_MATCH + hsd_3915_sdata2_order1(); +#endif bmp = bitmap; off_y = 0; off_x = 0; @@ -560,6 +588,15 @@ void hsd_803921B8(void* bitmap, s32 x, s32 y, s32 dst, s32 w, s32 h, } } +#ifdef MUST_MATCH +static const f32 hsd_3915_sdata2_zero0[1] = { 0.0F }; + +static inline void hsd_3915_sdata2_order2(void) +{ + (void) 600.0F; +} +#endif + void hsd_803922FC(void* bitmap, s32 x, s32 y, s32 parity, s32 dst, s32 w, s32 h, s32 stride, void* tbl) { @@ -578,6 +615,9 @@ void hsd_803922FC(void* bitmap, s32 x, s32 y, s32 parity, s32 dst, s32 w, u8* bmp; GlyphEntry* entry; +#ifdef MUST_MATCH + hsd_3915_sdata2_order2(); +#endif bmp = bitmap; off_y = 0; off_x = 0; @@ -628,11 +668,29 @@ void hsd_803922FC(void* bitmap, s32 x, s32 y, s32 parity, s32 dst, s32 w, } } +#ifdef MUST_MATCH +static const f64 hsd_3915_sdata2_s32_0[1] = { S32_TO_F32 }; +static const f32 hsd_3915_sdata2_zero1[1] = { 0.0F }; + +static inline void hsd_3915_sdata2_order3(void) +{ + (void) 0.9999F; + (void) -1.0F; +} +#endif + void hsd_80392474(void) { +#ifdef MUST_MATCH + hsd_3915_sdata2_order3(); +#endif hsd_804D7850 = NULL; } +#ifdef MUST_MATCH +static const f64 hsd_3915_sdata2_s32_1[1] = { S32_TO_F32 }; +#endif + struct EventPriority { Event event; int priority; @@ -684,7 +742,6 @@ void hsd_80392528(Event event) #endif static u32 lbl_804D6084; -static const u32 lbl_804DE8E0 = 0xFFFFFFFF; typedef struct { s32 count; @@ -771,7 +828,7 @@ void hsd_8039254C(void) first = 1; line = 1.0F; event_node = hsd_804D7850; - default_col = *(GXColor*) &lbl_804DE8E0; + default_col = hsd_3915_default_color; while (event_node != NULL) { DispItem* item; diff --git a/src/sysdolphin/baselib/hsd_3A94.c b/src/sysdolphin/baselib/hsd_3A94.c index 816d1f96a1..3f11b98e3a 100644 --- a/src/sysdolphin/baselib/hsd_3A94.c +++ b/src/sysdolphin/baselib/hsd_3A94.c @@ -1730,32 +1730,32 @@ static inline s32 fn_803AC6B8_blocks_before(struct CardState* file_desc, return (s32) total; } -static inline u32 fn_803AC7DC_block_count(struct CardState* file_desc, +static inline s32 fn_803AC7DC_block_count(struct CardState* file_state, s32 file_idx) { - if (file_desc->x4C[file_idx] <= 0) { - return 0; - } + s32 blocks; - if (file_idx == 0) { + if (file_state->x4C[file_idx] <= 0) { + blocks = 0; + } else if (file_idx == 0) { u32 usable; - u32 sector_size = file_desc->x8; + u32 sector_size = file_state->x8; s32 remaining; - remaining = file_desc->x4C[0]; + remaining = file_state->x4C[0]; remaining = remaining - (s32) ((usable = sector_size - 0x20) - - (file_desc->x24 + 48) % sector_size); + (file_state->x24 + 48) % sector_size); if (remaining <= 0) { - return 1; + blocks = 1; + } else { + blocks = (u32) (remaining + sector_size - 0x21) / usable + 1; } - return (u32) (remaining + sector_size - 0x21) / usable + 1; - } - - { - u32 sector_size = file_desc->x8; - return (u32) (file_desc->x4C[file_idx] + sector_size - 0x21) / - (sector_size - 0x20); + } else { + u32 sector_size = file_state->x8; + blocks = (u32) (file_state->x4C[file_idx] + sector_size - 0x21) / + (sector_size - 0x20); } + return blocks; } s32 fn_803AC7DC(CardState* state) @@ -1765,7 +1765,7 @@ s32 fn_803AC7DC(CardState* state) s32 i; if (state->x4C[0] > 0) { - total = (s32) fn_803AC7DC_block_count(state, 0) - 1; + total = fn_803AC7DC_block_count(state, 0) - 1; } for (i = 1; i < 9; i++) { @@ -1781,8 +1781,8 @@ s32 fn_803AC7DC(CardState* state) break; case 1: total += fn_803AC7DC_block_count(state, i); - if (extra < (s32) fn_803AC7DC_block_count(state, i)) { - extra = (s32) fn_803AC7DC_block_count(state, i); + if (extra < fn_803AC7DC_block_count(state, i)) { + extra = fn_803AC7DC_block_count(state, i); } break; case 2: @@ -4062,13 +4062,14 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) s32 file_size; s32 total_blocks; s32 current_seq; + s32 seq; s32 secondary_count; s32 free_count; s32 i; s32 remaining; s32 result; u8* data; - PAD_STACK(16); + PAD_STACK(4); needs_rewrite = 0; if (arg3 == 0) { @@ -4091,47 +4092,16 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) s32 size = state->x4C[arg1]; file_size = size; } - if (file_size <= 0) { - file_blocks = 0; - } else if (arg1 == 0) { - s32 hdr = state->x24; - u32 sector_size = state->x8; - s32 sz0; - s32 rem; - hdr += 0x30; - sz0 = state->x4C[0]; - rem = (s32) ((u32) hdr % sector_size); - rem = (s32) (sector_size - 0x20) - rem; - rem = sz0 - rem; - if (rem <= 0) { - file_blocks = 1; - } else { - file_blocks = - (u32) (rem + sector_size - 0x21) / (sector_size - 0x20) + 1; - } - } else { - u32 sector_size = state->x8; - file_blocks = - (u32) (file_size + sector_size - 0x21) / (sector_size - 0x20); - } - + file_blocks = calculateFileBlockCount(state, arg1); total_blocks = fn_803AC7DC(state); if (arg3 != 0) { hsd_804D7998 = hsd_804D7984; } else { - s32 ofs = state->x20; - s32 fd = state->x4; - s32 retries; - s32 r; - for (retries = 0; retries < 10; retries++) { - r = CARDFastOpen(fd, ofs, &state->file_info); - if (r != -1) { - break; - } - } - if (r < 0) { - return r; + s32 open_result = + fn_803AF3F0_open(state->x4, state->x20, &state->file_info); + if (open_result < 0) { + return open_result; } } @@ -4151,9 +4121,10 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } { + i = 1; secondary_count = 0; free_count = 0; - for (i = 1; i <= total_blocks; i++) { + for (; i <= total_blocks; i++) { s32 file_idx = state->x170[i]; if (file_idx >= 0) { @@ -4162,7 +4133,7 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) block_map[1][secondary_count] = i; secondary_count++; } else if (logical >= 0 && logical < file_blocks) { - s32 seq = state->x270[i]; + seq = state->x270[i]; if (fn_803ACB74(current_seq, seq) < 0) { current_seq = seq; } @@ -4228,17 +4199,19 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (remaining > chunk) { if (arg3 != 0) { + s32 block = block_map[0][i]; s32 cmd_result = fn_803B0120_queue_verify( - state, block_map[0][i], blocks_before + i, current_seq, - data, chunk); + state, block, blocks_before + i, current_seq, data, + chunk); if (cmd_result < 0) { fn_803B0120_rewind(entries); return cmd_result; } } else { - result = + s32 verify_result = fn_803ACC0C(state, block_map[0][i], blocks_before + i, current_seq, data, chunk); + result = verify_result; if (result < 0) { fn_803B0120_close(state); return result; @@ -4311,14 +4284,15 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return cmd_result; } } else { - s32 block = block_map[1][secondary_count]; - result = fn_803ACFC0(state, block, 0xFFFF, 0, NULL, 0, arg1); - state->x170[block_map[1][secondary_count]] = -0x7FFF; - state->x270[block_map[1][secondary_count]] = 0; + s32* secondary = block_map[1]; + s32* block = &secondary[secondary_count]; + result = fn_803ACFC0(state, *block, 0xFFFF, 0, NULL, 0, arg1); + state->x170[*block] = -0x7FFF; + state->x270[*block] = 0; if (result < 0) { fn_803B0120_close(state); - return result; } + return result; } } @@ -4339,16 +4313,18 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (remaining > chunk) { if (arg3 != 0) { - s32 cmd_result = - fn_803B0120_queue_write(state, block_map[0][i], logical, - current_seq, data, chunk, arg1); + s32 block = block_map[0][i]; + s32 cmd_result = fn_803B0120_queue_write( + state, block, logical, current_seq, data, chunk, arg1); if (cmd_result < 0) { fn_803B0120_rewind(entries); return cmd_result; } } else { - result = fn_803ACFC0(state, block_map[0][i], blocks_before + i, - current_seq, data, chunk, arg1); + s32 write_result = + fn_803ACFC0(state, block_map[0][i], blocks_before + i, + current_seq, data, chunk, arg1); + result = write_result; if (result < 0) { state->x170[block_map[0][i]] = -0x7FFF; state->x270[block_map[0][i]] = 0; @@ -4362,9 +4338,9 @@ s32 fn_803B0120(CardState* state, s32 arg1, s32 arg2, s32 arg3, s32 arg4) data += chunk; } else { if (arg3 != 0) { + s32 block = block_map[0][i]; s32 cmd_result = fn_803B0120_queue_write( - state, block_map[0][i], logical, current_seq, data, - remaining, arg1); + state, block, logical, current_seq, data, remaining, arg1); if (cmd_result < 0) { fn_803B0120_rewind(entries); return cmd_result; @@ -4749,7 +4725,7 @@ s32 fn_803B1338(CardState* state, s32 arg1) s32 logical; s32 max_redun; s32 file_blocks; - s32 file_id; + s32 index; s32 phys; u8* fdata; PAD_STACK(32); @@ -4880,24 +4856,24 @@ s32 fn_803B1338(CardState* state, s32 arg1) } } - for (file_id = 1; file_id < 9; file_id++) { + for (index = 1; index < 9; index++) { s32 j; s32 offset; - file_blocks = fn_803AC634(state, file_id); + file_blocks = fn_803AC7DC_block_count(state, index); offset = 0; if (file_blocks > 0) { for (j = 0; j < file_blocks; j++) { if (arg1 != 0) { - fdata = state->x70[file_id].ptr; + fdata = state->x70[index].ptr; if (fdata == NULL) { result = fn_803B1338_queue_write( - state, logical, phys, NULL, 0, file_id, cmd8, + state, logical, phys, NULL, 0, index, cmd8, cmd9); } else { - u8* wdata = fn_803B1338_data_at(fdata, offset); s32 chunk = fn_803B1338_data_size(state); + u8* wdata = fn_803B1338_data_at(fdata, offset); result = fn_803B1338_queue_write( - state, logical, phys, wdata, chunk, file_id, + state, logical, phys, wdata, chunk, index, cmd10, cmd11); offset = state->x8 + offset; offset -= 0x20; @@ -4906,14 +4882,14 @@ s32 fn_803B1338(CardState* state, s32 arg1) return result; } } else { - fdata = state->x70[file_id].ptr; + fdata = state->x70[index].ptr; if (fdata == NULL) { result = fn_803ACFC0(state, logical, phys, 0, NULL, - 0, file_id); + 0, index); } else { result = fn_803ACFC0(state, logical, phys, 0, fdata + offset, - state->x8 - 0x20, file_id); + state->x8 - 0x20, index); offset = state->x8 + offset; offset -= 0x20; } @@ -4928,7 +4904,7 @@ s32 fn_803B1338(CardState* state, s32 arg1) logical++; phys++; } - switch (state->x28[file_id]) { + switch (state->x28[index]) { case 0: break; case 1: @@ -4951,15 +4927,14 @@ s32 fn_803B1338(CardState* state, s32 arg1) s32 i; for (i = 0; i < max_redun; i++) { if (arg1 != 0) { - result = - fn_803B1338_queue_write(state, logical, 0xFFFF, NULL, - 0, file_id, cmd12, cmd13); + result = fn_803B1338_queue_write( + state, logical, 0xFFFF, NULL, 0, index, cmd12, cmd13); if (result < 0) { return result; } } else { - result = fn_803ACFC0(state, logical, 0xFFFF, 0, NULL, 0, - file_id); + result = + fn_803ACFC0(state, logical, 0xFFFF, 0, NULL, 0, index); state->x170[logical] = -0x7FFF; state->x270[logical] = 0; if (result < 0) { @@ -4971,69 +4946,74 @@ s32 fn_803B1338(CardState* state, s32 arg1) } } - phys = 1; - if ((s32) fn_803AC634(state, 0) != 0) { - file_blocks = fn_803AC634(state, 0); - phys = file_blocks; - } - for (file_id = 1; file_id < 9; file_id++) { - s32 k; - s32 offset; - file_blocks = fn_803AC634(state, file_id); - offset = 0; - if (file_blocks > 0) { - switch (state->x28[file_id]) { - case 0: - for (k = 0; k < file_blocks; k++) { - if (arg1 != 0) { - fdata = state->x70[file_id].ptr; - if (fdata == NULL) { - result = fn_803B1338_queue_write( - state, logical, phys, NULL, 0, file_id, - cmd14, cmd15); - } else { - s32 chunk; - u8* wdata; - wdata = fn_803B1338_data_at(fdata, offset); - chunk = fn_803B1338_data_size(state); - result = fn_803B1338_queue_write( - state, logical, phys, wdata, chunk, - file_id, cmd16, cmd17); - offset = state->x8 + offset; - offset -= 0x20; - } - if (result < 0) { - return result; - } - } else { - fdata = state->x70[file_id].ptr; - if (fdata == NULL) { - result = fn_803ACFC0(state, logical, phys, 0, - NULL, 0, file_id); + { + s32 block_idx; + s32 file_id; + + index = 1; + if ((s32) fn_803AC634(state, 0) != 0) { + index = fn_803AC634(state, 0); + } + for (file_id = 1; file_id < 9; file_id++) { + s32 offset; + file_blocks = fn_803AC634(state, file_id); + offset = 0; + if (file_blocks > 0) { + switch (state->x28[file_id]) { + case 0: + for (block_idx = 0; block_idx < file_blocks; + block_idx++) + { + if (arg1 != 0) { + fdata = state->x70[file_id].ptr; + if (fdata == NULL) { + result = fn_803B1338_queue_write( + state, logical, index, NULL, 0, + file_id, cmd14, cmd15); + } else { + s32 chunk = fn_803B1338_data_size(state); + u8* wdata = + fn_803B1338_data_at(fdata, offset); + result = fn_803B1338_queue_write( + state, logical, index, wdata, chunk, + file_id, cmd16, cmd17); + offset = state->x8 + offset; + offset -= 0x20; + } + if (result < 0) { + return result; + } } else { - result = fn_803ACFC0( - state, logical, phys, 0, fdata + offset, - state->x8 - 0x20, file_id); - offset = state->x8 + offset; - offset -= 0x20; - } - if (result < 0) { - state->x170[logical] = -0x7FFF; + fdata = state->x70[file_id].ptr; + if (fdata == NULL) { + result = fn_803ACFC0(state, logical, index, + 0, NULL, 0, file_id); + } else { + result = + fn_803ACFC0(state, logical, index, 0, + fdata + offset, + state->x8 - 0x20, file_id); + offset = state->x8 + offset; + offset -= 0x20; + } + if (result < 0) { + state->x170[logical] = -0x7FFF; + state->x270[logical] = 0; + return result; + } + state->x170[logical] = index; state->x270[logical] = 0; - return result; } - state->x170[logical] = phys; - state->x270[logical] = 0; + logical++; + index++; } - logical++; - phys++; + break; + case 1: + case 2: + case 3: + index += file_blocks; + break; } - break; - case 1: - case 2: - case 3: - phys += file_blocks; - break; } } } diff --git a/src/sysdolphin/baselib/hsd_3B34.c b/src/sysdolphin/baselib/hsd_3B34.c index f991b31c58..2b0e56906e 100644 --- a/src/sysdolphin/baselib/hsd_3B34.c +++ b/src/sysdolphin/baselib/hsd_3B34.c @@ -22,10 +22,13 @@ typedef union JpegWork { } data; } JpegWork; -typedef struct JpegLumaPair { - s32 block0[0x40]; - s32 block1[0x40]; -} JpegLumaPair; +typedef struct JpegBlock { + s32 data[0x40]; +} JpegBlock; + +typedef struct JpegByteBuffer { + u8 data[1]; +} JpegByteBuffer; typedef struct JpegComment { char data[0x15]; @@ -195,64 +198,50 @@ extern u16 lbl_8043169C[0xC]; extern u8 lbl_804316B4[0xC]; static s32 lbl_804D6398 = 3; -static inline s32 hsd_803B3408_inline(s32 index) -{ - return (index & 1) * 0x20; -} - static inline s32 hsd_803B3408_offset(s32 tile_stride, s32 y, s32 x) { return ((x / 4) * 0x10) + ((y / 4) * tile_stride); } -static inline void hsd_803B3408_set_stride(s32* tile_stride, s32 width) -{ - *tile_stride = ((width + 0xF) / 16) << 6; -} - void hsd_803B3408(u8* image, s32 x, s32 y, s32 width, s32 height) { - s32 luma_block_offset; - s32 chroma_block_offset; - s32 second_pixel_offset; - s32 chroma_pixel_count; - s32 luma_offset; + JpegBlock* luma_block; + s32 tile_row_offset; s32 chroma_row_base; - s32 second_pixel_index; s32 luma_row_base; - s32 pixel_index; + s32 luma_offset; s32 luma_row; + s32 luma_block_offset; s32 tile_stride; s32 luma_y; - s32 pair_count; + s32 block_count; s32 luma_x; s32 tile_y; s32 tile_x; u16 pixel; - JpegLumaPair* luma_pair; - s32 tile_row_offset; + s32 pixel_index; u16* pixel_ptr; tile_row_offset = 0; - hsd_803B3408_set_stride(&tile_stride, width); + tile_stride = ((width + 0xF) / 16) << 6; chroma_row_base = 0; luma_row_base = 0; for (tile_y = 0; tile_y < 2; tile_y++) { + s32 chroma_block_offset; u16* src; + chroma_block_offset = chroma_row_base; - src = (u16*) image + - (hsd_803B3408_offset(tile_stride, y, x) + tile_row_offset); - luma_block_offset = 0; - for (tile_x = 0; tile_x < 2; tile_x++) { + { + s32 image_offset = hsd_803B3408_offset(tile_stride, y, x); + src = (u16*) image + (image_offset + tile_row_offset); + } + for (tile_x = 0, luma_block_offset = 0; tile_x < 2; tile_x++) { s32 chroma_y; for (chroma_y = 0; chroma_y < 4; chroma_y++) { s32 chroma_x; - chroma_x = 0; - for (chroma_pixel_count = 4; chroma_pixel_count != 0; - chroma_pixel_count--) - { + for (chroma_x = 0; chroma_x < 4; chroma_x++) { f32 green; s32 chroma_x_offset; s32 red_chroma; @@ -282,7 +271,6 @@ void hsd_803B3408(u8* image, s32 x, s32 y, s32 width, s32 height) (((chroma_y & 1) * 4) + ((chroma_y & 2) * 0x10)))) * 4)); - chroma_x += 1; chroma_work->data.x518[0] = (s32) ((0.5f * (f32) blue_chroma) + ((-0.1687f * (f32) red_chroma) - @@ -295,35 +283,26 @@ void hsd_803B3408(u8* image, s32 x, s32 y, s32 width, s32 height) (0.0813f * (f32) ((pixel_again * 8) & 0xF8))); } } + luma_y = 0; luma_row = luma_row_base; - for (luma_y = 0; luma_y < 4; luma_y++) { - luma_offset = luma_row * 8; + for (; luma_y < 4; luma_y++) { + luma_offset = luma_row; + luma_offset <<= 3; for (luma_x = 0; luma_x < 4; luma_x++) { pixel_index = 0; - luma_pair = - (JpegLumaPair*) (HSD_804D2648_BUF + - ((luma_block_offset + luma_offset) * - 4) + - 0x118); - for (pair_count = 2; pair_count != 0; pair_count--) { + luma_block = + (JpegBlock*) (HSD_804D2648_BUF + + ((luma_block_offset + luma_offset) * 4) + + 0x118); + for (block_count = 4; block_count != 0; block_count--) { s32 row_offset = (pixel_index & 2) * tile_stride; - pixel = src[((pixel_index & 1) * 0x20) + row_offset]; - second_pixel_index = pixel_index + 1; - second_pixel_offset = - hsd_803B3408_inline(second_pixel_index) + - ((second_pixel_index & 2) * tile_stride); - pixel_index = second_pixel_index + 1; - luma_pair->block0[0] = - (s32) ((s32) ((0.114f * - (f32) ((pixel * 8) & 0xF8)) + - ((0.299f * - (f32) ((pixel >> 8U) & 0xF8)) + - (0.587f * - (f32) ((pixel >> 3U) & 0xFC)))) - - 0x80); - pixel = src[second_pixel_offset]; - luma_pair->block1[0] = + { + s32 column_offset = (pixel_index & 1) * 0x20; + pixel = src[column_offset + row_offset]; + } + pixel_index += 1; + luma_block->data[0] = (s32) ((s32) ((0.114f * (f32) ((pixel * 8) & 0xF8)) + ((0.299f * @@ -331,7 +310,7 @@ void hsd_803B3408(u8* image, s32 x, s32 y, s32 width, s32 height) (0.587f * (f32) ((pixel >> 3U) & 0xFC)))) - 0x80); - luma_pair += 1; + luma_block += 1; } src += 1; luma_offset += 1; @@ -350,39 +329,37 @@ void hsd_803B3408(u8* image, s32 x, s32 y, s32 width, s32 height) static void fn_803B376C(u8* arg0) { f32 scratch_f4; - f32 scratch_f11_2; f32 scratch_f8_2; + f32 scratch_f8; f32 scratch_f11_4; - f32 scratch_f11_5; - f32 scratch_f11_6; - f32 scratch_f27; f32 scratch_f6; - f32 scratch_f8; - f32 scratch_f27_6; - f32 scratch_f30_4; + f32 scratch_f4_2; + f32 scratch_f11; + f32 scratch_f30; f32 scratch_f28; - f32 scratch_f11_3; f32 scratch_f28_3; - f32 scratch_f28_4; - f32 scratch_f28_5; f32 scratch_f28_6; + f32 scratch_f28_4; + f32 scratch_f30_3; f32 scratch_f28_7; - f32 scratch_f4_2; + f32 scratch_f8_4; + f32 scratch_f11_6; + f32 scratch_f30_2; f32 scratch_f29_2; + f32 scratch_f8_3; + f32 scratch_f30_4; + f32 scratch_f28_5; f32 scratch_f29_3; - f32 scratch_f11; - f32 scratch_f30_2; - f32 scratch_f30_3; - f32 scratch_f8_4; - f32 scratch_f30; - f32 scratch_f27_2; f32 scratch_f6_2; + f32 scratch_f27; + f32 scratch_f11_3; + f32 scratch_f27_2; f32 scratch_f27_3; - f32 scratch_f28_2; - f32 scratch_f8_3; f32 scratch_f27_5; + f32 scratch_f28_2; f32 scratch_f27_4; f32 scratch_f29; + f32 scratch_f27_6; f32 scratch_f26; s32 scratch_r7_2; s32 scratch_r9_2; @@ -394,13 +371,12 @@ static void fn_803B376C(u8* arg0) s32 scratch_r29_2; s32 work_ctr; s32 work_ctr_2; - s32 work_ctr_3; - s32* work_r3; s32* work_r4; s32* work_r4_2; work_r4 = (s32*) arg0; for (work_ctr = 8; work_ctr != 0; work_ctr--) { + f32 scratch_f11_2; s32 scratch_r7; f32 scratch_f26_2; s32 scratch_r9; @@ -436,8 +412,8 @@ static void fn_803B376C(u8* arg0) (0.382683 * (f64) scratch_f26)); work_r4[2] = (s32) ((0.382683 * (f64) scratch_f27_2) + (0.92388 * (f64) scratch_f26)); - scratch_f11_3 = (f32) (0.707107 * (f64) (scratch_f8 + scratch_f11_2)); scratch_f8_2 = (f32) (0.707107 * (f64) (scratch_f8 - scratch_f11_2)); + scratch_f11_3 = (f32) (0.707107 * (f64) (scratch_f8 + scratch_f11_2)); scratch_f30_2 = scratch_f11_3 + scratch_f28_2; scratch_f26_2 = -scratch_f27_3 + scratch_f8_2; scratch_f28_3 = -scratch_f11_3 + scratch_f28_2; @@ -454,6 +430,7 @@ static void fn_803B376C(u8* arg0) } work_r4_2 = (s32*) arg0; for (work_ctr_2 = 8; work_ctr_2 != 0; work_ctr_2--) { + f32 scratch_f11_5; scratch_r31_2 = work_r4_2[0]; scratch_r30_2 = work_r4_2[56]; scratch_r29_2 = work_r4_2[8]; @@ -480,18 +457,15 @@ static void fn_803B376C(u8* arg0) (0.382683 * (f64) scratch_f27_5)); work_r4_2[16] = (s32) ((0.382683 * (f64) scratch_f28_5) + (0.92388 * (f64) scratch_f27_5)); + scratch_f8_4 = (f32) (0.707107 * (f64) (scratch_f8_3 - scratch_f11_5)); scratch_f11_6 = (f32) (0.707107 * (f64) (scratch_f8_3 + scratch_f11_5)); - scratch_f8_4 = (f32) (0.707107 * (f64) (scratch_f8_3 - scratch_f11_5)); - scratch_f30_4 = scratch_f29_2 + scratch_f11_6; + scratch_f30_4 = scratch_f11_6 + scratch_f29_2; scratch_f27_6 = -scratch_f28_6 + scratch_f8_4; scratch_f29_3 = -scratch_f11_6 + scratch_f29_2; scratch_f28_7 = scratch_f28_6 + scratch_f8_4; - { - f64 scratch_f30_5 = 0.19509 * (f64) scratch_f30_4; - work_r4_2[56] = - (s32) ((0.980785 * (f64) scratch_f27_6) + scratch_f30_5); - } + work_r4_2[56] = (s32) ((0.980785 * (f64) scratch_f27_6) + + (0.19509 * (f64) scratch_f30_4)); work_r4_2[40] = (s32) ((0.83147 * (f64) scratch_f28_7) + (0.55557 * (f64) scratch_f29_3)); work_r4_2[24] = (s32) ((-0.55557 * (f64) scratch_f28_7) + @@ -500,33 +474,26 @@ static void fn_803B376C(u8* arg0) (0.980785 * (f64) scratch_f30_4)); work_r4_2 += 1; } - work_r3 = (s32*) arg0; - work_ctr_3 = 4; - do { - work_r3[0] = work_r3[0] >> 2; - work_r3[1] = work_r3[1] >> 2; - work_r3[2] = work_r3[2] >> 2; - work_r3[3] = work_r3[3] >> 2; - work_r3[4] = work_r3[4] >> 2; - work_r3[5] = work_r3[5] >> 2; - work_r3[6] = work_r3[6] >> 2; - work_r3[7] = work_r3[7] >> 2; - work_r3[8] = work_r3[8] >> 2; - work_r3[9] = work_r3[9] >> 2; - work_r3[10] = work_r3[10] >> 2; - work_r3[11] = work_r3[11] >> 2; - work_r3[12] = work_r3[12] >> 2; - work_r3[13] = work_r3[13] >> 2; - work_r3[14] = work_r3[14] >> 2; - work_r3[15] = work_r3[15] >> 2; - work_ctr_3 -= 1; - work_r3 += 16; - } while (work_ctr_3 != 0); + for (work_ctr = 0; 0x40 > work_ctr; work_ctr++) { + ((s32*) arg0)[work_ctr] >>= 2; + } +} + +static inline s32 hsd_803B3CD8_bit_length(s32 value) +{ + s32 bit; + + for (bit = 0x1F; bit >= 0; bit--) { + if (value & (1 << bit)) { + return bit + 1; + } + } + return 0; } -static inline s32 hsd_803B3CD8_dec(s32 value) +static inline s32 hsd_803B3CD8_abs(s32 sign, s32 value) { - return value - 1; + return (sign ^ value) - sign; } void hsd_803B3CD8(s32 arg0) @@ -538,23 +505,11 @@ void hsd_803B3CD8(s32 arg0) s32 work_r28_2; s32 work_r28; u16* work_r6; - s32 scratch_r0; + s32 work_r28_4; s32 work_r28_6; s32 scratch_r3; - s32 scratch_r4; s32 scratch_r4_12; - s32 scratch_r4_17; - s32 scratch_r4_18; - s32 scratch_r4_19; - s32 scratch_r4_20; - s32 scratch_r4_21; - s32 scratch_r4_22; - s32 scratch_r4_23; - s32 scratch_r4_2; s32 work_r22; - s32 scratch_r4_5; - s32 scratch_r4_6; - s32 scratch_r4_7; s32 scratch_r5; s32 scratch_r5_2; s32 scratch_r5_3; @@ -564,23 +519,18 @@ void hsd_803B3CD8(s32 arg0) s32 scratch_r5_7; s32 scratch_r5_8; u8* work_r25_2; - s32 work_ctr; s32 work_ctr_2; - s32 work_ctr_3; - s32 scratch_r4_4; s32 work_r24; s32 work_r25; s32 work_r23; u8* work_r26; s32 work_r28_3; - s32 work_r28_4; + s32 scratch_r0; u8 byte_out; s32 scratch_r0_2; s32 work_r29; s32 work_r29_2; s32 work_r29_3; - s32 work_r4; - s32 work_r4_2; s32 work_r5; u16 scratch_r28; u16 scratch_r29; @@ -613,53 +563,8 @@ void hsd_803B3CD8(s32 arg0) work_r25 = work->data.coef[0] - work->data.prev_dc[arg0]; scratch_r0 = work_r25 >> 0x1F; work_r24 = 0; - scratch_r5 = (scratch_r0 ^ work_r25) - scratch_r0; - work_r4 = 0x1F; - for (work_ctr = 4; work_ctr != 0; work_ctr--) { - s32 scratch_r4_3; - if (scratch_r5 & (1 << work_r4)) { - work_r31 = work_r4 + 1; - goto loop_13; - } - scratch_r4 = work_r4 - 1; - if (scratch_r5 & (1 << scratch_r4)) { - work_r31 = scratch_r4 + 1; - goto loop_13; - } - scratch_r4_2 = scratch_r4 - 1; - if (scratch_r5 & (1 << scratch_r4_2)) { - work_r31 = scratch_r4_2 + 1; - goto loop_13; - } - scratch_r4_3 = scratch_r4_2 - 1; - if (scratch_r5 & (1 << scratch_r4_3)) { - work_r31 = scratch_r4_3 + 1; - goto loop_13; - } - scratch_r4_4 = scratch_r4_3 - 1; - if (scratch_r5 & (1 << scratch_r4_4)) { - work_r31 = scratch_r4_4 + 1; - goto loop_13; - } - scratch_r4_5 = scratch_r4_4 - 1; - if (scratch_r5 & (1 << scratch_r4_5)) { - work_r31 = scratch_r4_5 + 1; - goto loop_13; - } - scratch_r4_6 = scratch_r4_5 - 1; - if (scratch_r5 & (1 << scratch_r4_6)) { - work_r31 = scratch_r4_6 + 1; - goto loop_13; - } - scratch_r4_7 = scratch_r4_6 - 1; - if (scratch_r5 & (1 << scratch_r4_7)) { - work_r31 = scratch_r4_7 + 1; - goto loop_13; - } - work_r4 = scratch_r4_7 - 1; - } - work_r31 = 0; -loop_13: + scratch_r5 = hsd_803B3CD8_abs(scratch_r0, work_r25); + work_r31 = hsd_803B3CD8_bit_length(scratch_r5); work->data.prev_dc[arg0] = work->data.coef[0]; scratch_r28 = work_r6[work_r31]; work_r29 = work_r7[work_r31] - 1; @@ -777,7 +682,7 @@ void hsd_803B3CD8(s32 arg0) } work_r28_2 = 0; loop_65: - scratch_r31 = *(work_r27 + (work_r28_2 * 2)); + scratch_r31 = work_r27[work_r28_2]; work_r29_2 = *(work_r26 + work_r28_2) - 1; for (; work_r29_2 >= 0; work_r29_2--) { hsd_804D79B0 <<= 1; @@ -838,52 +743,8 @@ void hsd_803B3CD8(s32 arg0) } scratch_r3 = work_r22 >> 0x1F; scratch_r5_9 = (scratch_r3 ^ work_r22) - scratch_r3; - work_r4_2 = 0x1F; - for (work_ctr_3 = 4; work_ctr_3 != 0; work_ctr_3--) { - if (scratch_r5_9 & (1 << work_r4_2)) { - work_r28_4 = work_r4_2 + 1; - goto loop_112; - } - scratch_r4_17 = work_r4_2 - 1; - if (scratch_r5_9 & (1 << scratch_r4_17)) { - work_r28_4 = scratch_r4_17 + 1; - goto loop_112; - } - scratch_r4_18 = scratch_r4_17 - 1; - if (scratch_r5_9 & (1 << scratch_r4_18)) { - work_r28_4 = scratch_r4_18 + 1; - goto loop_112; - } - scratch_r4_19 = hsd_803B3CD8_dec(scratch_r4_18); - if (scratch_r5_9 & (1 << scratch_r4_19)) { - work_r28_4 = scratch_r4_19 + 1; - goto loop_112; - } - scratch_r4_20 = scratch_r4_19 - 1; - if (scratch_r5_9 & (1 << scratch_r4_20)) { - work_r28_4 = scratch_r4_20 + 1; - goto loop_112; - } - scratch_r4_21 = scratch_r4_20 - 1; - if (scratch_r5_9 & (1 << scratch_r4_21)) { - work_r28_4 = scratch_r4_21 + 1; - goto loop_112; - } - scratch_r4_22 = scratch_r4_21 - 1; - if (scratch_r5_9 & (1 << scratch_r4_22)) { - work_r28_4 = scratch_r4_22 + 1; - goto loop_112; - } - scratch_r4_23 = scratch_r4_22 - 1; - if (scratch_r5_9 & (1 << scratch_r4_23)) { - work_r28_4 = scratch_r4_23 + 1; - goto loop_112; - } - work_r4_2 = scratch_r4_23 - 1; - } - work_r28_4 = 0; - loop_112: - scratch_r31_2 = *(work_r27 + (work_r28_4 * 2)); + work_r28_4 = hsd_803B3CD8_bit_length(scratch_r5_9); + scratch_r31_2 = work_r27[work_r28_4]; work_r29_3 = *(work_r26 + work_r28_4) - 1; for (; work_r29_3 >= 0; work_r29_3--) { hsd_804D79B0 <<= 1; @@ -987,7 +848,7 @@ void hsd_803B3CD8(s32 arg0) } static const s32 lbl_804DEB88[1] = { 0x4A464946 }; -static const u8 lbl_804DEB8C[4] = { 0 }; +static const u8 jpeg_jfif_terminator[1] = { 0 }; void hsd_803B46D4(void) { @@ -1014,7 +875,7 @@ void hsd_803B46D4(void) scratch_r4 = hsd_804D79A0; sp8.word = lbl_804DEB88[0]; - sp8.byte[0] = lbl_804DEB8C[0]; + sp8.byte[0] = jpeg_jfif_terminator[0]; state.jmp_buf = &hsd_804D2648; if (scratch_r4 < &hsd_804D79A4[hsd_804D79A8]) { hsd_804D79A0 = scratch_r4 + 1; @@ -1405,54 +1266,44 @@ void hsd_803B4D64(u32 arg0, u32 arg1) hsd_803B4D64_inline(arg0, arg1, &hsd_804D2648); } -#ifdef MUST_MATCH -#pragma dont_inline on -#endif -s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) +static inline s32 +hsd_803B51C8_inline(s32 image, s32 image_height, s32 image_width, + const char* output, s32 output_capacity, + const JpegMetadata* metadata, JpegComment* comment, + JpegHuffDc* huff_dc_luma, JpegHuffDc* huff_dc_chroma, + JpegHuffAc* huff_ac_luma, JpegHuffAc* huff_ac_chroma) { - JpegComment comment; - JpegHuffDc huff_dc_luma; - JpegHuffDc huff_dc_chroma; - JpegHuffAc huff_ac_luma; + s32 work_r24; + s32 work_r25; s32* work_r26_2; s32 scratch_r6_4; s32 scratch_r6_5; s32 scratch_r7_2; s32 scratch_r7_4; s32 quant_scale; - s32 work_r25; - s32 work_r24; - const JpegMetadata* const metadata = &lbl_803B9670; - s32 work_r3; - s32 work_r3_2; - u32 scratch_r23; + u16 scratch_r0; u8 scratch_r6_3; u8 scratch_r7_3; - JpegHuffAc huff_ac_chroma; struct { u8* base; JpegWork* work; u8* quant_table; } state; - s32* work_r4_3; - s32* work_r4_4; - u16 scratch_r0; + u32 scratch_r23; u32 comment_size; - s32 height; s32 width; + s32 height; u8* src; - PAD_STACK(0x1C); - state.base = HSD_804D2648_BUF; state.work = (JpegWork*) state.base; - src = (u8*) arg0; - width = arg1; - height = arg2; - hsd_804D79A8 = arg4; + src = ((JpegByteBuffer*) image)->data; + width = image_width; + height = image_height; + hsd_804D79A8 = output_capacity; hsd_804D79AC = 0; - hsd_804D79A0 = (u8*) arg3; - hsd_804D79A4 = (u8*) arg3; + hsd_804D79A0 = ((JpegByteBuffer*) output)->data; + hsd_804D79A4 = ((JpegByteBuffer*) output)->data; state.quant_table = lbl_80430C40; state.work->data.prev_dc[0] = state.work->data.prev_dc[1] = state.work->data.prev_dc[2] = 0; @@ -1470,44 +1321,44 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) longjmp((__jmp_buf*) state.base, 1); } hsd_803B46D4(); - comment = metadata->data.comment; - scratch_r23 = strlen(comment.data) + 1; + *comment = metadata->data.comment; + scratch_r23 = strlen(comment->data) + 1; hsd_803B3344(0xFFU); hsd_803B3344(0xFEU); comment_size = scratch_r23 + 2; scratch_r0 = comment_size; hsd_803B3344((u8) (comment_size >> 8U)); hsd_803B3344((u8) scratch_r0); - hsd_803B3398(comment.data, scratch_r23); + hsd_803B3398(comment->data, scratch_r23); hsd_803B4A2C(); - huff_dc_luma = metadata->data.huff_dc_luma; + *huff_dc_luma = metadata->data.huff_dc_luma; hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0x1FU); hsd_803B3344(0U); - hsd_803B3398(huff_dc_luma.data, 0x1CU); - huff_dc_chroma = metadata->data.huff_dc_chroma; + hsd_803B3398(huff_dc_luma->data, 0x1CU); + *huff_dc_chroma = metadata->data.huff_dc_chroma; hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0x1FU); hsd_803B3344(1U); - hsd_803B3398(huff_dc_chroma.data, 0x1CU); - huff_ac_luma = metadata->data.huff_ac_luma; + hsd_803B3398(huff_dc_chroma->data, 0x1CU); + *huff_ac_luma = metadata->data.huff_ac_luma; hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0xB5U); hsd_803B3344(0x10U); - hsd_803B3398(huff_ac_luma.data, 0xB2U); - huff_ac_chroma = metadata->data.huff_ac_chroma; + hsd_803B3398(huff_ac_luma->data, 0xB2U); + *huff_ac_chroma = metadata->data.huff_ac_chroma; hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0xB5U); hsd_803B3344(0x11U); - hsd_803B3398(huff_ac_chroma.data, 0xB2U); + hsd_803B3398(huff_ac_chroma->data, 0xB2U); { void (*const write_frame_header)(u32, u32) = hsd_803B4D64; write_frame_header(width, height); @@ -1586,20 +1437,20 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) for (work_r25 = 0; work_r25 < width; work_r25 += 0x10) { s32 work_r26; u8* work_r23; - s32 work_r3_3; - s32* work_r5_4; hsd_803B3408(src, work_r25, work_r24, width, height); work_r23 = state.base + ((work_r26 = 0) << 8); work_r23 += 0x118; while (work_r26 < 4) { + u8* scratch_r6; s32* work_r5_3; + s32* work_r4_3; + s32 work_r3; fn_803B376C(work_r23); quant_scale = lbl_804D6398; work_r4_3 = (s32*) work_r23; work_r5_3 = (s32*) (state.base + 0x718); for (work_r3 = 0; work_r3 < 0x40; work_r3 += 8) { u8 scratch_r7; - u8* scratch_r6; scratch_r6 = state.quant_table + work_r3; scratch_r7 = scratch_r6[0]; work_r5_3[0] = @@ -1627,13 +1478,16 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) work_r26++; } { + u8* scratch_r6_2; + s32* work_r5_4; + s32* work_r4_4; + s32 work_r3_2; u8* chroma_quant_table = state.quant_table + 0x40; fn_803B376C(state.base + 0x518); work_r5_4 = work_r26_2 = (s32*) (state.base + 0x718); quant_scale = lbl_804D6398; work_r4_4 = (s32*) (state.base + 0x518); for (work_r3_2 = 0; work_r3_2 < 0x40; work_r3_2 += 8) { - u8* scratch_r6_2; scratch_r6_2 = chroma_quant_table + work_r3_2; scratch_r7_3 = scratch_r6_2[0]; work_r5_4[0] = @@ -1660,12 +1514,13 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) } { u8* chroma_quant_table = state.quant_table + 0x40; + u8* scratch_r5; s32* work_r4_5; + s32 work_r3_3; fn_803B376C(state.base + 0x618); quant_scale = lbl_804D6398; work_r4_5 = (s32*) (state.base + 0x618); for (work_r3_3 = 0; work_r3_3 < 0x40; work_r3_3 += 8) { - u8* scratch_r5; scratch_r5 = chroma_quant_table + work_r3_3; scratch_r6_3 = scratch_r5[0]; work_r26_2[0] = @@ -1724,9 +1579,21 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) return hsd_804D79A0 - hsd_804D79A4; } -#ifdef MUST_MATCH -#pragma dont_inline off -#endif +s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) +{ + JpegComment comment; + JpegHuffDc huff_dc_luma; + JpegHuffDc huff_dc_chroma; + JpegHuffAc huff_ac_luma; + JpegHuffAc huff_ac_chroma; + + PAD_STACK(0x18); + + return hsd_803B51C8_inline(arg0, arg2, arg1, arg3, arg4, &lbl_803B9670, + &comment, &huff_dc_luma, &huff_dc_chroma, + &huff_ac_luma, &huff_ac_chroma); +} + void hsd_803B5C2C(s32 arg0) { lbl_804D6398 = arg0; diff --git a/src/sysdolphin/baselib/hsd_3B5C.c b/src/sysdolphin/baselib/hsd_3B5C.c index 55e174d904..8287d3407c 100644 --- a/src/sysdolphin/baselib/hsd_3B5C.c +++ b/src/sysdolphin/baselib/hsd_3B5C.c @@ -25,6 +25,10 @@ typedef struct JpegState { JpegWorkData work; } JpegState; +typedef struct JpegLumaRow { + s32 values[16]; +} JpegLumaRow; + typedef struct JpegQuantTables { u8 luma[0x40]; u8 chroma[0x40]; @@ -336,24 +340,23 @@ void hsd_803B5EA0(s32 arg0) #pragma dont_inline off #endif -static void fn_803B61B4(u8* arg0) +void fn_803B61B4(s32* arg0) { f32 scratch_f9; - f32 scratch_f10; - f32 scratch_f11; - s32 scratch_r5_5; - f32 scratch_f22; - f32 scratch_f13_3; f32 scratch_f12; f32 scratch_f13; - f32 scratch_f31; + s32 scratch_r5_5; + f32 scratch_f24; + f32 scratch_f13_3; + f32 scratch_f10; + f32 scratch_f11; + f32 scratch_f24_2; f32 scratch_f25; f32 scratch_f25_2; - f32 scratch_f23; - f32 scratch_f12_2; - f32 scratch_f24; f32 scratch_f23_2; - f32 scratch_f24_2; + f32 scratch_f12_2; + f32 scratch_f23; + s32 scratch_r6_2; f32 scratch_f22_2; f32 scratch_f10_2; s32 scratch_r0; @@ -369,9 +372,10 @@ static void fn_803B61B4(u8* arg0) s32 scratch_r5_3; s32 scratch_r5_4; f32 scratch_f13_2; + f32 temp; + f32 scratch_f22; + f32 scratch_f31; s32 scratch_r5_6; - s32 scratch_r6; - s32 scratch_r6_2; s32 work_ctr; s32 work_ctr_2; s32 work_ctr_3; @@ -379,10 +383,10 @@ static void fn_803B61B4(u8* arg0) s32* work_r4; s32* work_r4_2; - PAD_STACK(8); - - work_r4 = (s32*) arg0; + work_r4 = arg0; for (work_ctr = 8; work_ctr != 0; work_ctr--) { + s32 scratch_r6; + scratch_r5 = work_r4[1]; scratch_r0 = work_r4[3]; scratch_r6 = work_r4[7]; @@ -410,22 +414,23 @@ static void fn_803B61B4(u8* arg0) (0.92388 * (f64) scratch_r0_2)); scratch_f9 = (f32) (0.707107 * (f64) (-scratch_f12 + scratch_f13)); scratch_f23_2 = scratch_f10 + scratch_f12_2; - scratch_f22_2 = (f32) (0.707107 * (f64) (scratch_f12 + scratch_f13)); + scratch_f13_3 = -scratch_f22 + scratch_f31; + temp = (f32) (0.707107 * (f64) (scratch_f12 + scratch_f13)); + scratch_f22 = temp; scratch_f24_2 = scratch_f11 + scratch_f25; scratch_f25_2 = scratch_f11 - scratch_f25; work_r4[0] = (s32) (scratch_f23_2 + scratch_f13_2); work_r4[1] = (s32) (scratch_f24_2 + scratch_f9); - scratch_f13_3 = -scratch_f22 + scratch_f31; scratch_f10_2 = scratch_f10 - scratch_f12_2; - work_r4[2] = (s32) (scratch_f22_2 + scratch_f25_2); + work_r4[2] = (s32) (scratch_f25_2 + scratch_f22); work_r4[3] = (s32) (scratch_f10_2 + scratch_f13_3); work_r4[4] = (s32) (scratch_f10_2 - scratch_f13_3); - work_r4[5] = (s32) (scratch_f25_2 - scratch_f22_2); + work_r4[5] = (s32) (scratch_f25_2 - scratch_f22); work_r4[6] = (s32) (scratch_f24_2 - scratch_f9); work_r4[7] = (s32) (scratch_f23_2 - scratch_f13_2); work_r4 += 8; } - work_r4_2 = (s32*) arg0; + work_r4_2 = arg0; for (work_ctr_2 = 8; work_ctr_2 != 0; work_ctr_2--) { scratch_r5_4 = work_r4_2[8]; scratch_r0_3 = work_r4_2[24]; @@ -452,7 +457,10 @@ static void fn_803B61B4(u8* arg0) (0.382683 * (f64) scratch_r0_4)); scratch_f12_2 = (f32) ((0.382683 * (f64) scratch_r5_6) + (0.92388 * (f64) scratch_r0_4)); - scratch_f9 = (f32) (0.707107 * (f64) (-scratch_f12 + scratch_f13)); + { + f32 temp = (f32) (0.707107 * (f64) (-scratch_f12 + scratch_f13)); + scratch_f9 = temp; + } scratch_f23_2 = scratch_f10 + scratch_f12_2; scratch_f13_3 = -scratch_f22 + scratch_f31; scratch_f22_2 = (f32) (0.707107 * (f64) (scratch_f12 + scratch_f13)); @@ -470,28 +478,10 @@ static void fn_803B61B4(u8* arg0) work_r4_2[56] = (s32) (scratch_f23_2 - scratch_f13_2); work_r4_2 += 1; } - work_r3 = (s32*) arg0; - work_ctr_3 = 4; - do { - work_r3[0] = work_r3[0] >> 2; - work_r3[1] = work_r3[1] >> 2; - work_r3[2] = work_r3[2] >> 2; - work_r3[3] = work_r3[3] >> 2; - work_r3[4] = work_r3[4] >> 2; - work_r3[5] = work_r3[5] >> 2; - work_r3[6] = work_r3[6] >> 2; - work_r3[7] = work_r3[7] >> 2; - work_r3[8] = work_r3[8] >> 2; - work_r3[9] = work_r3[9] >> 2; - work_r3[10] = work_r3[10] >> 2; - work_r3[11] = work_r3[11] >> 2; - work_r3[12] = work_r3[12] >> 2; - work_r3[13] = work_r3[13] >> 2; - work_r3[14] = work_r3[14] >> 2; - work_r3[15] = work_r3[15] >> 2; - work_r3 += 16; - work_ctr_3 -= 1; - } while (work_ctr_3 != 0); + work_r3 = arg0; + for (work_ctr_3 = 0; 0x40 > work_ctr_3; work_ctr_3++) { + work_r3[work_ctr_3] >>= 2; + } } static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, @@ -508,73 +498,74 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 work_ctr_2; s32 work_r10; s32 work_r12; - s32 work_r21; - s32 work_r22; - s32 work_r24; - s32 work_r25; - u32 work_r31; - s32 work_r4; s32 work_r5; s32 work_r6; + s32 work_r21; s32 work_r7; - u16* work_r9_2; + u32 work_r31; + s32 work_r22; u8* work_r8; u8* work_r9; - PAD_STACK(0x30); - base = hsd_804D2E70; - work_r9 = &base[0x118]; + PAD_STACK(0x28); + work_r9 = &hsd_804D2E70[0x118]; for (work_r10 = 0; work_r10 < 4; work_r10++) { work_r8 = work_r9; for (work_ctr = 4; work_ctr != 0; work_ctr--) { - M2C_FIELD(work_r8, s32*, 0) = - (s32) (M2C_FIELD(work_r8, s32*, 0) + 0x80); - M2C_FIELD(work_r8, s32*, 4) = - (s32) (M2C_FIELD(work_r8, s32*, 4) + 0x80); - M2C_FIELD(work_r8, s32*, 8) = - (s32) (M2C_FIELD(work_r8, s32*, 8) + 0x80); - M2C_FIELD(work_r8, s32*, 0xC) = - (s32) (M2C_FIELD(work_r8, s32*, 0xC) + 0x80); - M2C_FIELD(work_r8, s32*, 0x10) = - (s32) (M2C_FIELD(work_r8, s32*, 0x10) + 0x80); - M2C_FIELD(work_r8, s32*, 0x14) = - (s32) (M2C_FIELD(work_r8, s32*, 0x14) + 0x80); - M2C_FIELD(work_r8, s32*, 0x18) = - (s32) (M2C_FIELD(work_r8, s32*, 0x18) + 0x80); - M2C_FIELD(work_r8, s32*, 0x1C) = - (s32) (M2C_FIELD(work_r8, s32*, 0x1C) + 0x80); - M2C_FIELD(work_r8, s32*, 0x20) = - (s32) (M2C_FIELD(work_r8, s32*, 0x20) + 0x80); - M2C_FIELD(work_r8, s32*, 0x24) = - (s32) (M2C_FIELD(work_r8, s32*, 0x24) + 0x80); - M2C_FIELD(work_r8, s32*, 0x28) = - (s32) (M2C_FIELD(work_r8, s32*, 0x28) + 0x80); - M2C_FIELD(work_r8, s32*, 0x2C) = - (s32) (M2C_FIELD(work_r8, s32*, 0x2C) + 0x80); - M2C_FIELD(work_r8, s32*, 0x30) = - (s32) (M2C_FIELD(work_r8, s32*, 0x30) + 0x80); - M2C_FIELD(work_r8, s32*, 0x34) = - (s32) (M2C_FIELD(work_r8, s32*, 0x34) + 0x80); - M2C_FIELD(work_r8, s32*, 0x38) = - (s32) (M2C_FIELD(work_r8, s32*, 0x38) + 0x80); - M2C_FIELD(work_r8, s32*, 0x3C) = - (s32) (M2C_FIELD(work_r8, s32*, 0x3C) + 0x80); + temp_v = ((JpegLumaRow*) work_r8)->values[0]; + ((JpegLumaRow*) work_r8)->values[0] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[1]; + ((JpegLumaRow*) work_r8)->values[1] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[2]; + ((JpegLumaRow*) work_r8)->values[2] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[3]; + ((JpegLumaRow*) work_r8)->values[3] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[4]; + ((JpegLumaRow*) work_r8)->values[4] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[5]; + ((JpegLumaRow*) work_r8)->values[5] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[6]; + ((JpegLumaRow*) work_r8)->values[6] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[7]; + ((JpegLumaRow*) work_r8)->values[7] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[8]; + ((JpegLumaRow*) work_r8)->values[8] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[9]; + ((JpegLumaRow*) work_r8)->values[9] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[10]; + ((JpegLumaRow*) work_r8)->values[10] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[11]; + ((JpegLumaRow*) work_r8)->values[11] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[12]; + ((JpegLumaRow*) work_r8)->values[12] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[13]; + ((JpegLumaRow*) work_r8)->values[13] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[14]; + ((JpegLumaRow*) work_r8)->values[14] = temp_v + 0x80; + temp_v = ((JpegLumaRow*) work_r8)->values[15]; + ((JpegLumaRow*) work_r8)->values[15] = temp_v + 0x80; work_r8 += 0x40; } work_r9 += 0x100; } + base = hsd_804D2E70; scratch_r6 = (s32) (arg3 + 0xF) / 16; sc16 = scratch_r6 << 4; work_r21 = work_r22 = 0; for (work_r6 = 0; work_r6 < 2; work_r6++) { + u16* work_r9_2; + s32 work_r25; + s32 work_r24; + work_r25 = work_r22; work_r9_2 = (u16*) arg0 + (((arg1 / 4) * 0x10) + ((scratch_r6 << 6) * ((arg2 / 4) + work_r6))); - work_r24 = 0; - for (work_r7 = 0; work_r7 < 2; work_r7++) { - work_r12 = work_r21 * 8; - for (work_r4 = 0; work_r4 < 4; work_r4++) { + for (work_r7 = 0, work_r24 = 0; work_r7 < 2; work_r7++) { + s32 work_r4; + + for (work_r4 = 0, work_r12 = work_r21 * 8; work_r4 < 4; work_r4++) + { work_r31 = (work_r24 + work_r12) * 4; for (work_r5 = 0; work_r5 < 4; work_r5++) { s32 work_r8_2; @@ -594,17 +585,21 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, u8* scratch_r16; scratch_r19 = *work_r27; - scratch_r16 = - base + (((work_r5 >> 1) + - (work_r25 + ((work_r4 & 2) * 4)) + - (((work_r8_2 % 2) * 4) + - ((work_r8_2 / 2) << 5))) * - 4); - scratch_r20 = M2C_FIELD(scratch_r16, s32*, 0x618); - scratch_r18 = M2C_FIELD(scratch_r16, s32*, 0x518); + { + s32 chroma_x; + + chroma_x = (work_r8_2 % 2) * 4; + scratch_r16 = + base + (((work_r5 >> 1) + + (work_r25 + ((work_r4 & 2) * 4)) + + (chroma_x + ((work_r8_2 / 2) << 5))) * + 4); + } + scratch_r20 = ((JpegState*) scratch_r16)->work.cr[0]; + scratch_r18 = ((JpegState*) scratch_r16)->work.cb[0]; store_off = ((work_r8_2 & 1) << 5) + (sc16 * ((work_r8_2 & 2) << 2)); - scratch_f0 = (f32) ((1.402f * (f64) scratch_r20) + + scratch_f0 = (f32) ((1.402 * (f64) scratch_r20) + (f64) scratch_r19); if (scratch_f0 < 0.0f) { temp_v = 0; @@ -628,7 +623,7 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, scratch_f0_3 = (f32) ((f64) ((1.7718f * (f32) scratch_r18) + (f32) scratch_r19) - - (0.0012f * (f64) scratch_r20)); + (0.0012 * (f64) scratch_r20)); if (scratch_f0_3 < 0.0f) { temp_v = 0; } else if (255.0f < scratch_f0_3) { @@ -656,19 +651,15 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, } } -s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) +static inline s32 hsd_803B6BE4_inline(char* arg0, s32 arg1, void* arg2) { s32 scratch_r6_4; s32 scratch_r7; s32 scratch_r7_3; - s32 work_r26; s32 work_r25; - s32 work_r3; + s32 work_r26; + u8* work_r4_2; s32 work_r3_2; - s32 scratch_r0_3; - s32 work_r3_3; - s32 work_r3_4; - s32 work_r3_5; u8 scratch_r0; u8 scratch_r0_7; u8 scratch_r6_3; @@ -689,19 +680,9 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) u8* scratch_r5_7; u8* scratch_r5_8; u8* scratch_r5_9; + s32 work_r23; s32* work_r24; s32* work_r24_2; - s32 work_r23; - u8* work_r4; - u8* work_r4_2; - s32* work_r4_3; - s32* work_r4_4; - s32* work_r4_5; - s32* work_r5; - s32* work_r5_2; - u8* qptr; - u8 qbyte; - u8* quant_chroma; struct { u8* base; JpegState* work; @@ -710,7 +691,6 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) s32 height; } state; - PAD_STACK(0x30); state.base = hsd_804D2E70; state.work = (JpegState*) state.base; hsd_804D79C0 = arg1; @@ -726,8 +706,11 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; loop_3: if (*(u16*) hsd_804D79B8 == 0xFFDB) { - work_r4 = lbl_80431638; + u8* work_r4; + s32 work_r3; + hsd_804D79B8 += 5; + work_r4 = lbl_80431638; for (work_r3 = 0; work_r3 < 0x40; work_r3 += 8) { scratch_r5 = hsd_804D79B8; hsd_804D79B8 = scratch_r5 + 1; @@ -766,58 +749,55 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; loop_11: if (*(u16*) hsd_804D79B8 == 0xFFDB) { - work_r4_2 = lbl_80431638; + u8 qbyte; + u8* qptr; + s32 scratch_r0_3; + hsd_804D79B8 += 5; + work_r4_2 = lbl_80431638; for (work_r3_2 = 0; work_r3_2 < 0x40; work_r3_2 += 8) { scratch_r5_9 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_9 + 1; scratch_r0_3 = work_r4_2[0]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_9; - qptr[0x40] = qbyte; + qptr[0x40] = qbyte = *scratch_r5_9; scratch_r5_10 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_10 + 1; scratch_r0_3 = work_r4_2[1]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_10; - qptr[0x40] = qbyte; + qptr[0x40] = qbyte = *scratch_r5_10; scratch_r5_11 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_11 + 1; scratch_r0_3 = work_r4_2[2]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_11; - qptr[0x40] = qbyte; + qptr[0x40] = qbyte = *scratch_r5_11; scratch_r5_12 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_12 + 1; scratch_r0_3 = work_r4_2[3]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_12; - qptr[0x40] = qbyte; + qptr[0x40] = qbyte = *scratch_r5_12; scratch_r5_13 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_13 + 1; scratch_r0_3 = work_r4_2[4]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_13; - qptr[0x40] = qbyte; + qptr[0x40] = qbyte = *scratch_r5_13; scratch_r5_14 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_14 + 1; scratch_r0_3 = work_r4_2[5]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_14; + qbyte = scratch_r0 = *scratch_r5_14; qptr[0x40] = qbyte; scratch_r5_15 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_15 + 1; scratch_r0_3 = work_r4_2[6]; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_15; - qptr[0x40] = qbyte; + qptr[0x40] = qbyte = *scratch_r5_15; scratch_r5_16 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_16 + 1; scratch_r0_3 = work_r4_2[7]; - work_r4_2 += 8; qptr = state.quant_table->luma + scratch_r0_3; - qbyte = *scratch_r5_16; - qptr[0x40] = qbyte; + work_r4_2 += 8; + qptr[0x40] = qbyte = *scratch_r5_16; } } else { if (++hsd_804D79B8 >= scratch_r5) { @@ -857,114 +837,97 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) for (work_r26 = 0; work_r26 < state.width; work_r26 += 0x10) { work_r24 = state.work->work.luma; for (work_r23 = 0; work_r23 < 4; work_r23++) { + u8* scratch_r6; + s32* work_r5; + s32* work_r4_3; + s32 work_r3_3; + hsd_803B5EA0(0); work_r5 = work_r24; work_r4_3 = state.work->work.coeff; for (work_r3_3 = 0; work_r3_3 < 0x40; work_r3_3 += 8) { - u8* scratch_r6 = state.quant_table->luma + work_r3_3; - scratch_r0_7 = M2C_FIELD(scratch_r6, u8*, 0); - M2C_FIELD(work_r5, s32*, 0) = - (s32) (M2C_FIELD(work_r4_3, s32*, 0) * scratch_r0_7); - M2C_FIELD(work_r5, s32*, 4) = - (s32) (M2C_FIELD(work_r4_3, s32*, 4) * - M2C_FIELD(scratch_r6, u8*, 1)); - M2C_FIELD(work_r5, s32*, 8) = - (s32) (M2C_FIELD(work_r4_3, s32*, 8) * - M2C_FIELD(scratch_r6, u8*, 2)); - M2C_FIELD(work_r5, s32*, 0xC) = - (s32) (M2C_FIELD(work_r4_3, s32*, 0xC) * - M2C_FIELD(scratch_r6, u8*, 3)); - M2C_FIELD(work_r5, s32*, 0x10) = - (s32) (M2C_FIELD(work_r4_3, s32*, 0x10) * - M2C_FIELD(scratch_r6, u8*, 4)); - M2C_FIELD(work_r5, s32*, 0x14) = - (s32) (M2C_FIELD(work_r4_3, s32*, 0x14) * - M2C_FIELD(scratch_r6, u8*, 5)); - M2C_FIELD(work_r5, s32*, 0x18) = - (s32) (M2C_FIELD(work_r4_3, s32*, 0x18) * - M2C_FIELD(scratch_r6, u8*, 6)); - scratch_r7 = M2C_FIELD(work_r4_3, s32*, 0x1C); + scratch_r6 = state.quant_table->luma + work_r3_3; + scratch_r0_7 = scratch_r6[0]; + work_r5[0] = (s32) (work_r4_3[0] * scratch_r0_7); + work_r5[1] = (s32) (work_r4_3[1] * scratch_r6[1]); + work_r5[2] = (s32) (work_r4_3[2] * scratch_r6[2]); + work_r5[3] = (s32) (work_r4_3[3] * scratch_r6[3]); + work_r5[4] = (s32) (work_r4_3[4] * scratch_r6[4]); + work_r5[5] = (s32) (work_r4_3[5] * scratch_r6[5]); + work_r5[6] = (s32) (work_r4_3[6] * scratch_r6[6]); + scratch_r7 = work_r4_3[7]; work_r4_3 += 8; - M2C_FIELD(work_r5, s32*, 0x1C) = - (s32) (scratch_r7 * M2C_FIELD(scratch_r6, u8*, 7)); + work_r5[7] = (s32) (scratch_r7 * scratch_r6[7]); work_r5 += 8; } - fn_803B61B4((u8*) work_r24); + fn_803B61B4(work_r24); work_r24 += 0x40; } hsd_803B5EA0(1); - work_r4_4 = work_r24_2 = state.work->work.coeff; - quant_chroma = state.quant_table->chroma; - work_r5_2 = state.work->work.cb; - for (work_r3_4 = 0; work_r3_4 < 0x40; work_r3_4 += 8) { - u8* scratch_r6_2 = quant_chroma + work_r3_4; - scratch_r7_2 = M2C_FIELD(scratch_r6_2, u8*, 0); - M2C_FIELD(work_r5_2, s32*, 0) = - (s32) (M2C_FIELD(work_r4_4, s32*, 0) * scratch_r7_2); - M2C_FIELD(work_r5_2, s32*, 4) = - (s32) (M2C_FIELD(work_r4_4, s32*, 4) * - M2C_FIELD(scratch_r6_2, u8*, 1)); - M2C_FIELD(work_r5_2, s32*, 8) = - (s32) (M2C_FIELD(work_r4_4, s32*, 8) * - M2C_FIELD(scratch_r6_2, u8*, 2)); - M2C_FIELD(work_r5_2, s32*, 0xC) = - (s32) (M2C_FIELD(work_r4_4, s32*, 0xC) * - M2C_FIELD(scratch_r6_2, u8*, 3)); - M2C_FIELD(work_r5_2, s32*, 0x10) = - (s32) (M2C_FIELD(work_r4_4, s32*, 0x10) * - M2C_FIELD(scratch_r6_2, u8*, 4)); - M2C_FIELD(work_r5_2, s32*, 0x14) = - (s32) (M2C_FIELD(work_r4_4, s32*, 0x14) * - M2C_FIELD(scratch_r6_2, u8*, 5)); - M2C_FIELD(work_r5_2, s32*, 0x18) = - (s32) (M2C_FIELD(work_r4_4, s32*, 0x18) * - M2C_FIELD(scratch_r6_2, u8*, 6)); - scratch_r7_3 = M2C_FIELD(work_r4_4, s32*, 0x1C); - work_r4_4 += 8; - M2C_FIELD(work_r5_2, s32*, 0x1C) = - (s32) (scratch_r7_3 * M2C_FIELD(scratch_r6_2, u8*, 7)); - work_r5_2 += 8; + { + u8* scratch_r6_2; + s32* work_r5_2; + s32* work_r4_4; + s32 work_r3_4; + u8* quant_chroma = state.quant_table->chroma; + + work_r4_4 = work_r24_2 = state.work->work.coeff; + work_r5_2 = state.work->work.cb; + for (work_r3_4 = 0; work_r3_4 < 0x40; work_r3_4 += 8) { + scratch_r6_2 = quant_chroma + work_r3_4; + scratch_r7_2 = scratch_r6_2[0]; + work_r5_2[0] = (s32) (work_r4_4[0] * scratch_r7_2); + work_r5_2[1] = (s32) (work_r4_4[1] * scratch_r6_2[1]); + work_r5_2[2] = (s32) (work_r4_4[2] * scratch_r6_2[2]); + work_r5_2[3] = (s32) (work_r4_4[3] * scratch_r6_2[3]); + work_r5_2[4] = (s32) (work_r4_4[4] * scratch_r6_2[4]); + work_r5_2[5] = (s32) (work_r4_4[5] * scratch_r6_2[5]); + work_r5_2[6] = (s32) (work_r4_4[6] * scratch_r6_2[6]); + scratch_r7_3 = work_r4_4[7]; + work_r4_4 += 8; + work_r5_2[7] = (s32) (scratch_r7_3 * scratch_r6_2[7]); + work_r5_2 += 8; + } + fn_803B61B4(state.work->work.cb); } - fn_803B61B4((u8*) state.work->work.cb); hsd_803B5EA0(2); - quant_chroma = state.quant_table->chroma; - work_r4_5 = state.work->work.cr; - for (work_r3_5 = 0; work_r3_5 < 0x40; work_r3_5 += 8) { - u8* scratch_r5_17 = quant_chroma + work_r3_5; - scratch_r6_3 = M2C_FIELD(scratch_r5_17, u8*, 0); - M2C_FIELD(work_r4_5, s32*, 0) = - (s32) (M2C_FIELD(work_r24_2, s32*, 0) * scratch_r6_3); - M2C_FIELD(work_r4_5, s32*, 4) = - (s32) (M2C_FIELD(work_r24_2, s32*, 4) * - M2C_FIELD(scratch_r5_17, u8*, 1)); - M2C_FIELD(work_r4_5, s32*, 8) = - (s32) (M2C_FIELD(work_r24_2, s32*, 8) * - M2C_FIELD(scratch_r5_17, u8*, 2)); - M2C_FIELD(work_r4_5, s32*, 0xC) = - (s32) (M2C_FIELD(work_r24_2, s32*, 0xC) * - M2C_FIELD(scratch_r5_17, u8*, 3)); - M2C_FIELD(work_r4_5, s32*, 0x10) = - (s32) (M2C_FIELD(work_r24_2, s32*, 0x10) * - M2C_FIELD(scratch_r5_17, u8*, 4)); - M2C_FIELD(work_r4_5, s32*, 0x14) = - (s32) (M2C_FIELD(work_r24_2, s32*, 0x14) * - M2C_FIELD(scratch_r5_17, u8*, 5)); - M2C_FIELD(work_r4_5, s32*, 0x18) = - (s32) (M2C_FIELD(work_r24_2, s32*, 0x18) * - M2C_FIELD(scratch_r5_17, u8*, 6)); - scratch_r6_4 = M2C_FIELD(work_r24_2, s32*, 0x1C); - work_r24_2 += 8; - M2C_FIELD(work_r4_5, s32*, 0x1C) = - (s32) (scratch_r6_4 * M2C_FIELD(scratch_r5_17, u8*, 7)); - work_r4_5 += 8; + { + u8* quant_chroma = state.quant_table->chroma; + u8* scratch_r5_17; + s32* work_r4_5; + s32 work_r3_5; + + work_r4_5 = state.work->work.cr; + for (work_r3_5 = 0; work_r3_5 < 0x40; work_r3_5 += 8) { + scratch_r5_17 = quant_chroma + work_r3_5; + scratch_r6_3 = scratch_r5_17[0]; + work_r4_5[0] = (s32) (work_r24_2[0] * scratch_r6_3); + work_r4_5[1] = (s32) (work_r24_2[1] * scratch_r5_17[1]); + work_r4_5[2] = (s32) (work_r24_2[2] * scratch_r5_17[2]); + work_r4_5[3] = (s32) (work_r24_2[3] * scratch_r5_17[3]); + work_r4_5[4] = (s32) (work_r24_2[4] * scratch_r5_17[4]); + work_r4_5[5] = (s32) (work_r24_2[5] * scratch_r5_17[5]); + work_r4_5[6] = (s32) (work_r24_2[6] * scratch_r5_17[6]); + scratch_r6_4 = work_r24_2[7]; + work_r24_2 += 8; + work_r4_5[7] = (s32) (scratch_r6_4 * scratch_r5_17[7]); + work_r4_5 += 8; + } + fn_803B61B4(state.work->work.cr); } - fn_803B61B4((u8*) state.work->work.cr); fn_803B6820(arg2, work_r26, work_r25, state.width, state.height); } } return state.width * state.height * 2; } +s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) +{ + PAD_STACK(0x30); + + return hsd_803B6BE4_inline(arg0, arg1, arg2); +} + u8 lbl_80431638[0x40] = { 0, 1, 8, 0x10, 9, 2, 3, 0xA, 0x11, 0x18, 0x20, 0x19, 0x12, 0xB, 4, 5, 0xC, 0x13, 0x1A, 0x21, 0x28, 0x30, diff --git a/src/sysdolphin/baselib/psdisp.c b/src/sysdolphin/baselib/psdisp.c index f79b4255db..1e1390a28d 100644 --- a/src/sysdolphin/baselib/psdisp.c +++ b/src/sysdolphin/baselib/psdisp.c @@ -1103,8 +1103,8 @@ static inline void psDispSub(HSD_Particle* pp, u8* texform) prev_x_sum = pvmtx[0][0] * prev_x + prev_xy; prev_yx = prev_x * pvmtx[1][0] + prev_y_terms; cur_yx = pvmtx[1][0] * pp->pos.x + cur_y_term; - x = w0inv * (pvmtx[0][3] + (pvmtx[0][2] * pp->pos.z + - (pvmtx[0][0] * pp->pos.x + cur_y))) - + x = w0inv * (pvmtx[0][3] + ((pp->pos.x * pvmtx[0][0] + cur_y) + + pvmtx[0][2] * pp->pos.z)) - w1inv * (pvmtx[0][3] + (pvmtx[0][2] * prev_z + prev_x_sum)); y = w0inv * (pvmtx[1][3] + (pvmtx[1][2] * pp->pos.z + cur_yx)) - w1inv * (pvmtx[1][3] + (pvmtx[1][2] * prev_z + prev_yx)); @@ -1288,13 +1288,13 @@ static inline void psDispSubAPPSRTPoint(HSD_Particle* pp) f32 dz = pp->pos.z - pp->vel.z; prev_pos.x = pp->appsrt->x70 + (pp->appsrt->x6C * dz + - (pp->appsrt->ssx * dx + pp->appsrt->ssy * dy)); + (pp->appsrt->ssy * dy + pp->appsrt->ssx * dx)); prev_pos.y = pp->appsrt->x80 + (pp->appsrt->x7C * dz + (pp->appsrt->x78 * dy + pp->appsrt->x74 * dx)); prev_pos.z = pp->appsrt->x90 + (pp->appsrt->x8C * dz + - (pp->appsrt->x84 * dx + pp->appsrt->x88 * dy)); + (pp->appsrt->x88 * dy + pp->appsrt->x84 * dx)); } ax = pp->size > 42.5 ? 255.0f : 6.0f * pp->size; @@ -1468,7 +1468,7 @@ static inline void psDispSubAppSRT(HSD_Particle* pp, u8* texform) (draw_mtx[1][0] * dx + draw_mtx[1][1] * dy)); prev_pos.z = draw_mtx[2][3] + (draw_mtx[2][2] * dz + - (draw_mtx[2][0] * dx + draw_mtx[2][1] * dy)); + (draw_mtx[2][0] * dx + dy * draw_mtx[2][1])); } psScaleAppSRTAxes(pp, draw_mtx); } @@ -1860,8 +1860,8 @@ static inline void psUpdateBillboardAxes(const Mtx inv_view) f32 right; f32 up; - right = inv_view[0][0]; up = inv_view[0][1]; + right = inv_view[0][0]; HSD_PSDisp_804D7914 = right + up; HSD_PSDisp_804D7918 = right - up; right = inv_view[1][0]; @@ -1908,10 +1908,10 @@ static inline void psUpdateProjectionCache(f32 perspective) y_offset = prj[4]; y0 = y_offset * w0; y1 = y_offset * w1; - y2 = y_offset * w2; + y2 = w2 * y_offset; y3 = y_offset * w3; - pvmtx[1][0] = y_scale * vmtx[1][0] + y0; - pvmtx[1][1] = y_scale * vmtx[1][1] + y1; + pvmtx[1][0] = vmtx[1][0] * y_scale + y0; + pvmtx[1][1] = vmtx[1][1] * y_scale + y1; pvmtx[1][2] = y_scale * vmtx[1][2] + y2; pvmtx[1][3] = y_scale * vmtx[1][3] + y3; } else {