diff --git a/src/melee/ft/chara/ftCommon/ftCo_0A01.c b/src/melee/ft/chara/ftCommon/ftCo_0A01.c index a0019ac3bc..30e5022934 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_0A01.c +++ b/src/melee/ft/chara/ftCommon/ftCo_0A01.c @@ -1047,7 +1047,7 @@ void ftCo_800A1F3C_noinline2(Fighter* fp, float arg1, float arg2, float arg3) void ftCo_800A1F3C(Fighter* fp, float arg1, float arg2, float arg3) { struct Fighter_x1A88_t* data = &fp->x1A88; - if (fp->x1A88.x60 == 0) { + if (data->x60 == 0) { data->x54.x = arg1; data->x54.y = arg2; data->x38 = arg3; @@ -1945,39 +1945,62 @@ static inline bool ftCo_IsAlly_dontinline(Fighter* fp0, Fighter* fp1) return ftCo_IsAlly(fp0, fp1); } -static inline float ftCo_800A3908_inline0(Fighter* fp, s32 t) +static inline bool ftCo_800A3908_inline0(Fighter* fp, + struct Fighter_x1A88_t* data, float x, + float y) { - return fp->co_attrs.gravity * sqrtf((f32) t); + if (x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || + x > Stage_GetBlastZoneRightOffset() - data->half_width || + y < data->half_height + Stage_GetBlastZoneBottomOffset() || + y > Stage_GetBlastZoneTopOffset() - data->half_height) + { + return true; + } + return false; +} + +static inline s32 ftCo_800A3908_inline1(float x, float y) +{ + 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) { + return 0; + } + return result; +} + +static inline float ftCo_GetTerminalVelocity(Fighter* fp) +{ + return fp->co_attrs.terminal_velocity; } bool ftCo_800A3908(Fighter* fp, bool arg1) { - struct Fighter_x1A88_t* data2; + f32 ez; struct Fighter_x1A88_t* data = &fp->x1A88; - s32 t; - u32 flags; - int line_id; - Vec3 island_pos; - Vec3 floor_normal; - Vec3 alt_floor_pos; - Vec3 alt_floor_normal; f32 dist; - Vec3 floor_pos; + Vec3 island_pos; + f32 ex; f32 ey; - f32 ez; + s32 valid; f32 grav; f32 dx; f32 px; + mp_UnkStruct0* island; f32 ddx; f32 ddy; - mp_UnkStruct0* island; + s32 t; s32 frames; - s32 result; - s32 valid; + struct Fighter_x1A88_t* data2 = &fp->x1A88; + StageInfo* info; s32 ok; - s32 oob; - - PAD_STACK(0x20); grav = fp->co_attrs.gravity; if (grav < 0.00001f && grav > -0.00001f) { @@ -1990,17 +2013,18 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) } else { frames = -(-fp->co_attrs.terminal_velocity - fp->pos_delta.y) / grav; } - data2 = &fp->x1A88; + info = &stage_info; + PAD_STACK(0x18); for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { - f32 ex; island_pos = island->x14; ex = island_pos.x; - ey = island_pos.y; - (void) ey; + { + f32 y = island_pos.y; + ey = y; + } ez = island_pos.z; - (void) ez; if (ex < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || ex > Stage_GetBlastZoneRightOffset() - data2->half_width || ey < data2->half_height + Stage_GetBlastZoneBottomOffset() || @@ -2023,66 +2047,35 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) if (frames <= 0) { land_y = fp->pos_delta.y * t + fp->cur_pos.y; } else if (t < frames) { - land_y = fp->cur_pos.y + (fp->pos_delta.y * t - - 0.5 * ftCo_800A3908_inline0(fp, t)); + land_y = fp->cur_pos.y + + (fp->pos_delta.y * t - + 0.5 * (fp->co_attrs.gravity * sqrtf((f32) t))); } else { land_y = fp->cur_pos.y + ((fp->pos_delta.y * frames - 0.5 * (fp->co_attrs.gravity * sqrtf((f32) frames))) - - (f32) (t - frames) * fp->co_attrs.terminal_velocity); + (f32) (t - frames) * ftCo_GetTerminalVelocity(fp)); } if (arg1 != 0) { if (!(land_y + data->x558 < ey)) { - valid = 0; px = ex - 5.0; + valid = ftCo_800A3908_inline1(px, ey); + if (valid != 0 && + !ftCo_800A3908_inline0(fp, data2, px, ey)) { - s32 floor_result; - - line_id = -1; - floor_result = mpCheckFloor( - px, 5.0f + ey, px, ey - 5.0f, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, NULL, - NULL); - result = floor_result; - if (result != 0 && - ftCo_800A1B38_noinline(line_id) != 0) - { - } else { - valid = result; - } - } - if (valid != 0) { - if (px < fp->x1A88.half_width + - Stage_GetBlastZoneLeftOffset() || - px > Stage_GetBlastZoneRightOffset() - - data2->half_width || - ey < data2->half_height + - Stage_GetBlastZoneBottomOffset() || - ey > Stage_GetBlastZoneTopOffset() - - data2->half_height) - { - oob = 1; - } else { - oob = 0; - } - if (oob == 0) { - ok = 1; - } else { - ok = 0; - } + ok = 1; } else { ok = 0; } if (ok != 0) { + struct Fighter_x1A88_t* data3 = &fp->x1A88; if (fp->x1A88.x60 == 0) { - data2->x54.x = px; - data2->x54.y = ey; - data2->x38 = 5.0f; - { - s32 kind = stage_info.grkind; - ftCo_800A1CC4(fp, ftCo_803C6594[kind]); - } + data3->x54.x = px; + data3->x54.y = ey; + data3->x38 = 5.0f; + ftCo_800A1CC4(fp, + ftCo_803C6594[stage_info.grkind]); } ftCo_800A49B4(fp); return 1; @@ -2091,38 +2084,10 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) } else { ddy = ey - fp->cur_pos.y; px = ex - 5.0; - valid = 0; ddx = px - fp->cur_pos.x; - { - line_id = -1; - result = mpCheckFloor(px, 5.0f + ey, px, ey - 5.0f, 0.0f, - &alt_floor_pos, &line_id, &flags, - &alt_floor_normal, -1, -1, -1, NULL, - NULL); - if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { - } else { - valid = result; - } - } - if (valid != 0) { - if (px < fp->x1A88.half_width + - Stage_GetBlastZoneLeftOffset() || - px > Stage_GetBlastZoneRightOffset() - - data2->half_width || - ey < data2->half_height + - Stage_GetBlastZoneBottomOffset() || - ey > - Stage_GetBlastZoneTopOffset() - data2->half_height) - { - oob = 1; - } else { - oob = 0; - } - if (oob == 0) { - ok = 1; - } else { - ok = 0; - } + valid = ftCo_800A3908_inline1(px, ey); + if (valid != 0 && !ftCo_800A3908_inline0(fp, data2, px, ey)) { + ok = 1; } else { ok = 0; } @@ -2134,7 +2099,7 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) data2->x54.y = ey; data2->x38 = 5.0f; { - s32 kind = stage_info.grkind; + GrKind kind = info->grkind; ftCo_800A1CC4(fp, ftCo_803C6594[kind]); } } @@ -2147,14 +2112,35 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) return 0; } -static inline float ftCo_GetTerminalVelocity(Fighter* fp) +static inline bool ftCo_800A4038_inline0(Fighter* fp, + struct Fighter_x1A88_t* data, float x, + float y) { - return fp->co_attrs.terminal_velocity; + if (x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || + x > Stage_GetBlastZoneRightOffset() - data->half_width || + y < data->half_height + Stage_GetBlastZoneBottomOffset() || + y > Stage_GetBlastZoneTopOffset() - data->half_height) + { + return true; + } + return false; } -static inline bool ftCo_800A4038_inline1(int line_id) +static inline s32 ftCo_800A4038_inline1(float x, float y) { - return ftCo_800A1B38_noinline(line_id) != 0; + 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) { + return 0; + } + return result; } static inline float ftCo_800A4038_inline2(Fighter* fp) @@ -2165,26 +2151,23 @@ static inline float ftCo_800A4038_inline2(Fighter* fp) bool ftCo_800A4038(Fighter* fp, bool arg1) { f32 ez; - struct Fighter_x1A88_t* data2; - s32 t; + struct Fighter_x1A88_t* data = &fp->x1A88; + mp_UnkStruct0* island; Vec3 island_pos; f32 ex; f32 ey; - struct Fighter_x1A88_t* data = &fp->x1A88; + s32 valid; f32 grav; f32 dx; f32 px; f32 dist; f32 ddx; f32 ddy; - mp_UnkStruct0* island; + s32 t; s32 frames; - s32 result; - s32 valid; + struct Fighter_x1A88_t* data2 = &fp->x1A88; + StageInfo* info; s32 ok; - s32 oob; - - PAD_STACK(0x8); grav = fp->co_attrs.gravity; if (grav < 0.00001f && grav > -0.00001f) { @@ -2197,7 +2180,8 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } else { frames = ftCo_800A4038_inline2(fp) / grav; } - data2 = &fp->x1A88; + info = &stage_info; + PAD_STACK(0x4); for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { @@ -2242,47 +2226,12 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } if (arg1 != 0) { if (!(land_y + data->x558 < ey)) { - valid = 0; px = 5.0 + ex; + valid = ftCo_800A4038_inline1(px, ey); + if (valid != 0 && + !ftCo_800A4038_inline0(fp, data2, px, ey)) { - Vec3 floor_pos; - Vec3 floor_normal; - int line_id; - u32 flags; - s32 floor_result; - - line_id = -1; - floor_result = mpCheckFloor( - px, 5.0f + ey, px, ey - 5.0f, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, NULL, - NULL); - result = floor_result; - if (result != 0 && - ftCo_800A1B38_noinline(line_id) != 0) - { - } else { - valid = result; - } - } - if (valid != 0) { - if (px < fp->x1A88.half_width + - Stage_GetBlastZoneLeftOffset() || - px > Stage_GetBlastZoneRightOffset() - - data2->half_width || - ey < data2->half_height + - Stage_GetBlastZoneBottomOffset() || - ey > Stage_GetBlastZoneTopOffset() - - data2->half_height) - { - oob = 1; - } else { - oob = 0; - } - if (oob == 0) { - ok = 1; - } else { - ok = 0; - } + ok = 1; } else { ok = 0; } @@ -2302,43 +2251,10 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } else { ddy = ey - fp->cur_pos.y; px = 5.0 + ex; - valid = 0; ddx = px - fp->cur_pos.x; - { - Vec3 alt_floor_pos; - Vec3 alt_floor_normal; - int line_id; - u32 flags; - - line_id = -1; - result = mpCheckFloor(px, 5.0f + ey, px, ey - 5.0f, 0.0f, - &alt_floor_pos, &line_id, &flags, - &alt_floor_normal, -1, -1, -1, NULL, - NULL); - if (result != 0 && ftCo_800A4038_inline1(line_id)) { - } else { - valid = result; - } - } - if (valid != 0) { - if (px < fp->x1A88.half_width + - Stage_GetBlastZoneLeftOffset() || - px > Stage_GetBlastZoneRightOffset() - - data2->half_width || - ey < data2->half_height + - Stage_GetBlastZoneBottomOffset() || - ey > - Stage_GetBlastZoneTopOffset() - data2->half_height) - { - oob = 1; - } else { - oob = 0; - } - if (oob == 0) { - ok = 1; - } else { - ok = 0; - } + valid = ftCo_800A4038_inline1(px, ey); + if (valid != 0 && !ftCo_800A4038_inline0(fp, data2, px, ey)) { + ok = 1; } else { ok = 0; } @@ -2350,7 +2266,7 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) data2->x54.y = ey; data2->x38 = 5.0f; { - GrKind kind = stage_info.grkind; + GrKind kind = info->grkind; ftCo_800A1CC4(fp, ftCo_803C6594[kind]); } } @@ -3253,12 +3169,13 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) { mp_UnkStruct0* island; f32 best; + f32 px; + f32 ay; f32 ax; Vec3 b; Vec3 a; Vec3 floor_pos; Vec3 floor_normal; - f32 px; f32 dy; f32 dist; s32 result; @@ -3270,18 +3187,14 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) if (ftCo_800A2718(island) == 0) { int line_id; u32 flags; - f32 ay; + f32 by; a = island->x8; ax = a.x; ay = a.y; px = ax + 5.0; - line_id = -1; - result = mpCheckFloor(px, ay + 5.0, px, ay - 5.0, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, NULL); - if (result != 0 && ftCo_IsIgnoredFloor(line_id)) { - result = 0; - } + result = ftCo_800A0FB0(&floor_pos, &line_id, &flags, &floor_normal, + -1, -1, -1, ax + 5.0, ay + 5.0, ax + 5.0, + ay - 5.0, 0.0f); if (result != 0) { if (!ftCo_800A6700_inline0(fp, px, ay)) { px = px - arg1->x; @@ -3297,24 +3210,20 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) } b = island->x14; ax = b.x; - ay = b.y; + by = b.y; px = ax - 5.0; - line_id = -1; - result = mpCheckFloor(px, ay + 5.0, px, ay - 5.0, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, NULL); - if (result != 0 && ftCo_800A1B38(line_id)) { - result = 0; - } + result = + ftCo_800A0FB0(&floor_pos, &line_id, &flags, &floor_normal, -1, + -1, -1, px, by + 5.0, px, by - 5.0, 0.0f); if (result != 0) { - if (!ftCo_800A6700_inline0(fp, px, ay)) { + if (!ftCo_800A6700_inline0(fp, px, by)) { px = px - arg1->x; - dy = ay - arg1->y; + dy = by - arg1->y; dist = px * px + dy * dy; if (dist > best) { best = dist; arg2->x = ax - 5.0; - arg2->y = ay; + arg2->y = by; arg2->z = b.z; } } @@ -3685,14 +3594,13 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) f32 fx; f32 fy; f32 d; - f32 cx; if (fp1 == NULL) { return; } if (fp1->ground_or_air == GA_Air) { - s32 result; s32 blocked; + s32 result; mp_UnkStruct0* island; fx = fp1->cur_pos.x; { @@ -3722,86 +3630,39 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) if (result != 0) { island = mpIsland_8005AB54(line_id); if (ftCo_800A2718(island) == 0) { - int* x60 = &fp0->x1A88.x60; - struct Fighter_x1A88_t* data2 = &fp0->x1A88; - f32 x38 = data->x56C + fp1->x1A88.x564; - f32 x = floor_pos.x; - f32 y = floor_pos.y; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp0, floor_pos.x, floor_pos.y, + data->x56C + fp1->x1A88.x564); if (island != NULL) { d = island->x14.x - data->x54.x; if (d < 0.0f) { d = -d; } if (d < 5.0) { - struct Fighter_x1A88_t* data2 = &fp0->x1A88; - f32 x38_edge = data->x56C + fp1->x1A88.x564; - f32 x = island->x14.x - 5.0; - f32 y = island->x14.y; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38_edge; - ftCo_800A1CC4(fp0, - ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp0, island->x14.x - 5.0, island->x14.y, + data->x56C + fp1->x1A88.x564); } else { - d = island->x8.x - data->x54.x; - if (d < 0.0f) { - d = -d; - } + d = ABS(island->x8.x - data->x54.x); if (d < 5.0) { - struct Fighter_x1A88_t* data2 = &fp0->x1A88; - f32 x38_edge = data->x56C + fp1->x1A88.x564; - f32 x = 5.0 + island->x8.x; - f32 y = island->x8.y; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38_edge; - ftCo_800A1CC4( - fp0, ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp0, 5.0 + island->x8.x, + island->x8.y, + data->x56C + fp1->x1A88.x564); } } } } } else { ftCo_800A4768(fp1, &sp18); - { - struct Fighter_x1A88_t* data2 = &fp0->x1A88; - f32 x38 = data->x56C + fp1->x1A88.x564; - f32 x = sp18.x; - f32 y = sp18.y; - if (fp0->x1A88.x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.grkind]); - } - } + ftCo_800A1F3C(fp0, sp18.x, sp18.y, data->x56C + fp1->x1A88.x564); } } else if (ftCo_800A2718(mpIsland_8005AB54(fp1->coll_data.floor.index)) == 0) { - int* x60 = &fp0->x1A88.x60; mp_UnkStruct0* island; mp_UnkStruct0* fp0_island; s32 same_island; - f32 x38 = data->x56C + fp1->x1A88.x564; - f32 x = fp1->cur_pos.x; - f32 y = fp1->cur_pos.y; - if (*x60 == 0) { - data->x54.x = x; - data->x54.y = y; - data->x38 = x38; - ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.grkind]); - } + + ftCo_800A1F3C(fp0, fp1->cur_pos.x, fp1->cur_pos.y, + data->x56C + fp1->x1A88.x564); if (fp0->ground_or_air == GA_Air) { same_island = 0; } else if (fp1->ground_or_air == GA_Air) { @@ -3822,32 +3683,15 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) (island = mpIsland_8005AB54(fp1->coll_data.floor.index)) != NULL && data->x54.y - fp0->cur_pos.y > 0.0) { - cx = fp0->cur_pos.x; - if (0.0f < data->x54.x - cx) { - if (cx < island->x8.x) { - struct Fighter_x1A88_t* data2 = &fp0->x1A88; - f32 x = 5.0 + island->x8.x; - f32 y = island->x8.y; - f32 x38 = data->x56C + fp1->x1A88.x564; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.grkind]); - } + if (data->x54.x - fp0->cur_pos.x > 0.0) { + if (fp0->cur_pos.x < island->x8.x) { + ftCo_800A1F3C(fp0, 5.0 + island->x8.x, island->x8.y, + data->x56C + fp1->x1A88.x564); } } else { - if (cx > island->x14.x) { - struct Fighter_x1A88_t* data2 = &fp0->x1A88; - f32 x = island->x14.x - 5.0; - f32 y = island->x14.y; - f32 x38 = data->x56C + fp1->x1A88.x564; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.grkind]); - } + if (fp0->cur_pos.x > island->x14.x) { + ftCo_800A1F3C(fp0, island->x14.x - 5.0, island->x14.y, + data->x56C + fp1->x1A88.x564); } } } @@ -3856,7 +3700,6 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) void ftCo_800A7AAC(Fighter* fp) { - s32 result; Fighter* partner; struct Fighter_x1A88_t* data = &fp->x1A88; Vec3 floor_pos; @@ -3866,9 +3709,9 @@ void ftCo_800A7AAC(Fighter* fp) u8 _[0x18]; Vec3 partner_pos; f32 d; - f32 cx; PAD_STACK(0xA); + PAD_STACK(8); partner = ftCo_800A589C(fp); if (partner == NULL) { @@ -3877,6 +3720,7 @@ void ftCo_800A7AAC(Fighter* fp) partner_pos = partner->cur_pos; if (partner->ground_or_air == GA_Air) { s32 blocked; + s32 result; mp_UnkStruct0* island; f32 below = partner_pos.y - 1000.0f; f32 above = 10.0f + partner_pos.y; @@ -3899,51 +3743,21 @@ void ftCo_800A7AAC(Fighter* fp) if (result != 0) { island = mpIsland_8005AB54(line_id); if (ftCo_800A2718(island) == 0) { - int* x60 = &fp->x1A88.x60; - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x38 = data->x56C + partner->x1A88.x564; - f32 x = floor_pos.x; - f32 y = floor_pos.y; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp, floor_pos.x, floor_pos.y, + data->x56C + partner->x1A88.x564); if (island != NULL) { d = island->x14.x - data->x54.x; if (d < 0.0f) { d = -d; } if (d < 5.0) { - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x38_edge = data->x56C + partner->x1A88.x564; - f32 x = island->x14.x - 5.0; - f32 y = island->x14.y; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38_edge; - ftCo_800A1CC4(fp, - ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp, island->x14.x - 5.0, island->x14.y, + data->x56C + partner->x1A88.x564); } else { - d = island->x8.x - data->x54.x; - if (d < 0.0f) { - d = -d; - } + d = ABS(island->x8.x - data->x54.x); if (d < 5.0) { - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x38_edge = data->x56C + partner->x1A88.x564; - f32 x = 5.0 + island->x8.x; - f32 y = island->x8.y; - if (*x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38_edge; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp, 5.0 + island->x8.x, island->x8.y, + data->x56C + partner->x1A88.x564); } } } @@ -3953,6 +3767,8 @@ void ftCo_800A7AAC(Fighter* fp) mpIsland_8005AB54(partner->coll_data.floor.index)) == 0) { s32 blocked; + int line; + s32 result; mp_UnkStruct0* fp_island; mp_UnkStruct0* island; s32 same_island; @@ -3965,7 +3781,7 @@ void ftCo_800A7AAC(Fighter* fp) &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, NULL, (Fighter_GObj*) blocked); if (result != 0) { - int line = line_id; + line = line_id; if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || grCorneria_801E2D90(line) || grVenom_80206D10(line)) { @@ -3976,27 +3792,11 @@ void ftCo_800A7AAC(Fighter* fp) } } if (result == 0) { - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x38 = data->x56C + partner->x1A88.x564; - f32 x = partner->cur_pos.x; - f32 y = partner->cur_pos.y; - if (fp->x1A88.x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp, partner->cur_pos.x, partner->cur_pos.y, + data->x56C + partner->x1A88.x564); } else { - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x38 = data->x56C + partner->x1A88.x564; - f32 x = partner_pos.x; - f32 y = partner_pos.y; - if (fp->x1A88.x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.grkind]); - } + ftCo_800A1F3C(fp, partner_pos.x, partner_pos.y, + data->x56C + partner->x1A88.x564); } if (fp->ground_or_air == GA_Air) { same_island = 0; @@ -4026,39 +3826,18 @@ void ftCo_800A7AAC(Fighter* fp) sub = 0; break; } - if (sub == 0) { + switch (sub) { + case 0: island = mpIsland_8005AB54(partner->coll_data.floor.index); if (island != NULL && data->x54.y - fp->cur_pos.y > 0.0) { - cx = fp->cur_pos.x; - if (data->x54.x - cx > 0.0) { - if (cx < island->x8.x) { - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x = 5.0 + island->x8.x; - f32 y = island->x8.y; - f32 x38 = data->x56C + partner->x1A88.x564; - if (fp->x1A88.x60 == 0) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.grkind]); - } - } - } else { - if (cx > island->x14.x) { - struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x = island->x14.x - 5.0; - f32 y = island->x14.y; - f32 x38 = data->x56C + partner->x1A88.x564; - int update = fp->x1A88.x60 == 0; - if (update) { - data2->x54.x = x; - data2->x54.y = y; - data2->x38 = x38; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.grkind]); - } + if (data->x54.x - fp->cur_pos.x > 0.0) { + if (fp->cur_pos.x < island->x8.x) { + ftCo_800A1F3C(fp, 5.0 + island->x8.x, island->x8.y, + data->x56C + partner->x1A88.x564); } + } else if (fp->cur_pos.x > island->x14.x) { + ftCo_800A1F3C(fp, island->x14.x - 5.0, island->x14.y, + data->x56C + partner->x1A88.x564); } } } @@ -6242,13 +6021,13 @@ static bool ftCo_800ADE48(Fighter* fp) { s32 switch_cmd; struct Fighter_x1A88_t* data; - struct Fighter_x1A88_t* data2; + Item* ip; u32 flags; int line_id; Vec3 floor_normal; Vec3 floor_pos; Item_GObj* item_gobj; - Item* ip; + struct Fighter_x1A88_t* data2; ItemKind kind; s32 found; s32 result; @@ -6256,37 +6035,40 @@ static bool ftCo_800ADE48(Fighter* fp) s32 motion_id; s32 cur_cmd; f64 five; - f32 px; - f32 py; + f32 x; + f32 x2; + f32 y; + f32 below; + f32 above; f32 dy; - PAD_STACK(0x14); + PAD_STACK(8); data = &fp->x1A88; found = 0; - px = data->x54.x; - py = data->x54.y; + x = data->x54.x; + x2 = x; + y = data->x54.y; five = 5.0; + below = y - five; + above = five + y; line_id = -1; - result = mpCheckFloor(px, py + five, px, py - five, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, NULL, - (Fighter_GObj*) found); - if (result != 0) { - if (ftCo_800A1B38_noinline(line_id) != 0) { + do { + result = mpCheckFloor(x2, above, x, below, 0.0f, &floor_pos, &line_id, + &flags, &floor_normal, -1, -1, -1, NULL, + (Fighter_GObj*) found); + if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { + (void) result; } else { found = result; } - } else { - found = result; - } - do { if (found != 0) { struct Fighter_x1A88_t* data2 = &fp->x1A88; - py = data->x54.y; - px = data->x54.x; - if (px < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || - px > Stage_GetBlastZoneRightOffset() - data2->half_width || - py < data2->half_height + Stage_GetBlastZoneBottomOffset() || - py > Stage_GetBlastZoneTopOffset() - data2->half_height) + y = data->x54.y; + x = data->x54.x; + if (x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || + x > Stage_GetBlastZoneRightOffset() - data2->half_width || + y < data2->half_height + Stage_GetBlastZoneBottomOffset() || + y > Stage_GetBlastZoneTopOffset() - data2->half_height) { in_bounds = 1; } else { @@ -6298,18 +6080,16 @@ static bool ftCo_800ADE48(Fighter* fp) } data->xFA_b2 = false; if (fp->ground_or_air == GA_Air) { - px = fp->cur_pos.x; - py = fp->cur_pos.y; + x = fp->cur_pos.x; + x2 = x; + y = fp->cur_pos.y; line_id = -1; found = 0; - result = mpCheckFloor(px, py, px, ftCo_800ADE48_inline0(py), 0.0f, + result = mpCheckFloor(x2, y, x, ftCo_800ADE48_inline0(y), 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, NULL, (Fighter_GObj*) found); - if (result != 0) { - if (ftCo_800A1B38_noinline(line_id) != 0) { - } else { - found = result; - } + if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { + (void) result; } else { found = result; } @@ -6361,7 +6141,7 @@ static bool ftCo_800ADE48(Fighter* fp) data->x94 = 0; } if (data->x18 != 0x12) { - data2 = &fp->x1A88; + data2 = ftCo_800ADE48_inline1(fp); if (fp->kind == FTKIND_GKOOPS) { switch_cmd = 0; } else if (data2->xC == 0xF || data2->xC == 0) { @@ -6387,13 +6167,7 @@ static bool ftCo_800ADE48(Fighter* fp) cur_cmd = data->x18; if (cur_cmd != 0x11) { motion_id = fp->motion_id; - if (motion_id == ftCo_MS_BarrelWait) { - switch_cmd = 1; - } else if (motion_id == ftCo_MS_Barrel) { - switch_cmd = 2; - } else { - switch_cmd = 0; - } + switch_cmd = inlineH0(fp); if (switch_cmd != 0) { ftCo_800B4A78(fp); data->x18 = 0x11; @@ -6572,22 +6346,25 @@ static bool ftCo_800ADE48(Fighter* fp) found = 1; } else { kind = ip->kind; - if (kind == It_Kind_M_Ball) { + switch (kind) { + case It_Kind_Capsule: + case It_Kind_Box: + case It_Kind_Taru: + case It_Kind_Egg: + case It_Kind_Kusudama: + case It_Kind_TaruCann: + case It_Kind_BombHei: + case It_Kind_M_Ball: + case It_Kind_EvYoshiEgg: found = 1; - } else if (kind < It_Kind_M_Ball) { - if (kind < It_Kind_Dosei) { - if (kind < 0) { - found = ftCo_ItemCheck(ip); - } else { - found = 1; - } + break; + default: + if (ftCo_ItemCheck(ip)) { + found = 1; } else { - found = ftCo_ItemCheck(ip); + found = 0; } - } else if (kind != It_Kind_EvYoshiEgg) { - found = ftCo_ItemCheck(ip); - } else { - found = 1; + break; } } } @@ -6603,9 +6380,10 @@ static bool ftCo_800ADE48(Fighter* fp) data->x18 = data->x20; return true; } - return false; + } else { + return true; } - return true; + return false; } static inline void ftCo_CpuUpdateCommonItemTarget(Fighter* fp) diff --git a/src/melee/ft/chara/ftCommon/ftCo_0D95.c b/src/melee/ft/chara/ftCommon/ftCo_0D95.c index 74c7a75351..22e7cd5b71 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_0D95.c +++ b/src/melee/ft/chara/ftCommon/ftCo_0D95.c @@ -4,9 +4,10 @@ #include "ft/fighter.h" #include "ft/ft_0892.h" #include "ft/inlines.h" -#include "it/inlines.h" #include "it/items/itsamusgrapple.h" +#include "it/types.h" #include "lb/lb_00B0.h" +#include "mp/mplib.h" #include @@ -104,7 +105,6 @@ bool fn_800D9930(Fighter_GObj* gobj) Fighter* fp = GET_FIGHTER(gobj); ftSs_DatAttrs* attrs; Item_GObj* item; - s32 frame; s32 i; itSamusGrappleAttributes* grappleAttrs; HSD_GObj* segGobj; @@ -114,7 +114,7 @@ bool fn_800D9930(Fighter_GObj* gobj) Vec3 vel; f32 grav; f32 r; - PAD_STACK(4); + PAD_STACK(12); if (fp->kind == FTKIND_SAMUS) { attrs = fp->dat_attrs; @@ -133,12 +133,12 @@ bool fn_800D9930(Fighter_GObj* gobj) } else if (grav > (f32) attrs->xAC) { if (grav <= (f32) attrs->xB8) { Item* it; - it = GET_ITEM(fp->u.ss.x223C); + 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, frame = 0x14; i < 4; i++, frame += 3) { - if (fp->mv.ca.specials.grav == (f32) frame) { + for (i = 0; i < 4; i++) { + 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); diff --git a/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c b/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c index 4919ded75a..27adcf30b1 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c +++ b/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c @@ -516,15 +516,19 @@ void ftCo_ItemThrow_Anim(Fighter_GObj* gobj) } } +static inline float getItemThrowFsm(Fighter* fp) +{ + return -fp->cmd_timer / fp->frame_speed_mul; +} + void ftCo_80095EFC(Fighter_GObj* gobj) { Fighter* fp = GET_FIGHTER(gobj); + float interpolation; Vec3 vec0; Vec3 vec1; Vec3 vec2; - PAD_STACK(0x4); - if (fp->item_gobj != NULL) { lb_8000B1CC(it_80272C90(fp->item_gobj), NULL, &vec0); if (ftCheckThrowB3(fp)) { @@ -538,24 +542,32 @@ void ftCo_80095EFC(Fighter_GObj* gobj) fp->cmd_vars[1] = 0; } { - ftCo_ItemThrowAttrs* throw_speed_arr = - (ftCo_ItemThrowAttrs*) Fighter_804D6550; - float cd_xB4 = co_attrs->heavy_throw_velocity_multiplier; - float base_throw_speed = - cd_xB4 * + float fsm = getItemThrowFsm(fp); + 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; + throw_speed_arr = (ftCo_ItemThrowAttrs*) Fighter_804D6550; + velocity_multiplier = + co_attrs->heavy_throw_velocity_multiplier; + table_speed = throw_speed_arr[fp->motion_id - ftCo_MS_LightThrowF] .x8; - float throw_speed_arg = throw_scale * base_throw_speed; - float throw_speed = throw_speed_arg; - float fsm = -fp->cmd_timer / fp->frame_speed_mul; - vec2.x = - fsm * (fp->mv.co.itemthrow4.x8.x - vec0.x) + vec0.x; - vec2.y = + base_throw_speed = velocity_multiplier * table_speed; + throw_scale *= base_throw_speed; + throw_speed = throw_scale; + interpolation = fsm * (interpolation - vec0.x) + vec0.x; + vec2.x = interpolation; + interpolation = fsm * (fp->mv.co.itemthrow4.x8.y - vec0.y) + vec0.y; + vec2.y = interpolation; vec2.z = 0; pl_8003E978(fp->player_id, fp->x221F_b4, fp->item_gobj, - vec2.y, base_throw_speed, cd_xB4, - throw_speed_arg, vec0.x, vec0.y, fsm); + interpolation, base_throw_speed, + velocity_multiplier, throw_speed, vec0.x, + vec0.y, fsm); { FtMoveId msid = fp->motion_id; if (msid == (FtMoveId) ftCo_MS_LightThrowDrop) { diff --git a/src/melee/ft/ftafterimage.c b/src/melee/ft/ftafterimage.c index 5341b3f2d5..f49cd63408 100644 --- a/src/melee/ft/ftafterimage.c +++ b/src/melee/ft/ftafterimage.c @@ -30,15 +30,12 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) { Fighter* fp; itSword_UnkBytes* params; - f32* distPtr; - u32 n4; f32 cumDist[3]; AfterimageVtx vtx_buf[151]; f32 d2; - s32 numVerts; - s32 remaining; s32 numSubdiv; - s32 nextIdx; + + PAD_STACK(0x10); if (arg1 != 2) { return; @@ -116,11 +113,15 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) } { + s32 nextIdx; f32 x20F8 = fp->x20F8; f32 x20FC = fp->x20FC; s32 ringIdx; f32 totalDist; f32* dp; + Vec3 prevPos, delta, crossProd, tempDir; + + PAD_STACK(0x14); { s32 idx = fp->x2101_bits_0to6; @@ -136,7 +137,6 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) dp = &cumDist[1]; { - Vec3 delta, prevPos; s32 i; s32 curIdx = ringIdx; @@ -161,11 +161,7 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) prevPos = delta; if (i != 0) { - if (curIdx != 0) { - nextIdx = curIdx - 1; - } else { - nextIdx = 2; - } + nextIdx = curIdx != 0 ? curIdx - 1 : 2; } curIdx = nextIdx; } @@ -176,34 +172,42 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) } { - Vec3 tempDir, crossProd; - f32 scaleDiff = x20FC - x20F8; + s32 remaining; + f32* distPtr; + s32 numVerts; + f32 scaleDiff; s32 curIdx2; - f32 blendedInner = params->x0 * scaleDiff + x20F8; - f32 blendedOuter = params->x4 * scaleDiff + x20F8; - f32 interpFactor = 1.0f; - f32 innerDiff = x20F8 - blendedInner; - f32 outerDiff = x20FC - blendedOuter; + s32 idx2; + f32 blendedOuter; + f32 blendedInner; + f32 interpFactor; + f32 innerDiff; + f32 outerDiff; AfterimageVtx* vp; + scaleDiff = x20FC - x20F8; + idx2 = fp->x2101_bits_0to6; + blendedInner = params->x0 * scaleDiff + x20F8; + vp = vtx_buf; + blendedOuter = params->x4 * scaleDiff + x20F8; numVerts = 0; - { - s32 idx2 = fp->x2101_bits_0to6; - if (idx2 != 0) { - curIdx2 = idx2 - 1; - } else { - curIdx2 = 2; - } + if (idx2 != 0) { + curIdx2 = idx2 - 1; + } else { + curIdx2 = 2; } + innerDiff = x20F8 - blendedInner; + interpFactor = 1.0f; remaining = (s8) (u8) fp->x2100 - 1; + outerDiff = x20FC - blendedOuter; distPtr = &cumDist[0]; - vp = &vtx_buf[0]; while (remaining >= 0) { f32 outerScale, innerScale; s32 alpha; + struct Fighter_x20B0_t* nextEntry; struct Fighter_x20B0_t* curEntry = &fp->x20B0[curIdx2]; outerScale = interpFactor * outerDiff + blendedOuter; @@ -222,7 +226,10 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) vp->b = params->xC; vp->a = alpha; - (vp + 1)->x = curEntry->xC.x * outerScale + curEntry->x0.x; + { + f32 x = curEntry->xC.x * outerScale; + (vp + 1)->x = x + 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; @@ -234,7 +241,6 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) if (remaining != 0) { s32 nextRingIdx; - struct Fighter_x20B0_t* nextEntry; if (curIdx2 != 0) { nextRingIdx = curIdx2 - 1; @@ -292,7 +298,7 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) (f32) alpha)); for (j = 0; j < numSubdiv; j++) { - cumAngle += angle * frac; + cumAngle += frac * angle; basePosX += stepPosX; basePosY += stepPosY; basePosZ += stepPosZ; @@ -346,38 +352,26 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) GXPosition3f32(vtx_buf[0].x, vtx_buf[0].y, vtx_buf[0].z); GXColor4u8(vtx_buf[0].r, vtx_buf[0].g, vtx_buf[0].b, vtx_buf[0].a); - GXPosition3f32(vtx_buf[2].x, vtx_buf[2].y, vtx_buf[2].z); - GXColor4u8(vtx_buf[2].r, vtx_buf[2].g, vtx_buf[2].b, vtx_buf[2].a); - - if (numVerts > 1) { - AfterimageVtx* p = &vtx_buf[1]; - u32 count = (u32) (numVerts - 1); - n4 = count >> 2; - if (n4 != 0) { - do { - GXPosition3f32(p[0].x, p[0].y, p[0].z); - GXColor4u8(p[0].r, p[0].g, p[0].b, p[0].a); - GXPosition3f32(p[1].x, p[1].y, p[1].z); - GXColor4u8(p[1].r, p[1].g, p[1].b, p[1].a); - GXPosition3f32(p[2].x, p[2].y, p[2].z); - GXColor4u8(p[2].r, p[2].g, p[2].b, p[2].a); - GXPosition3f32(p[3].x, p[3].y, p[3].z); - GXColor4u8(p[3].r, p[3].g, p[3].b, p[3].a); - p += 4; - n4--; - } while (n4 != 0); - count &= 3; - if (count != 0) { - goto remainder; + { + AfterimageVtx* vtx = &vtx_buf[2]; + + GXPosition3f32(vtx->x, vtx->y, vtx->z); + { + u8 r = vtx->r; + GXColor4u8(r, vtx->g, vtx->b, vtx->a); + } + } + + { + s32 i; + AfterimageVtx* vtx = &vtx_buf[1]; + + for (i = 1; i < numVerts; i++, vtx++) { + GXPosition3f32(vtx->x, vtx->y, vtx->z); + { + u8 r = vtx->r; + GXColor4u8(r, vtx->g, vtx->b, vtx->a); } - } else { - remainder: - do { - GXPosition3f32(p->x, p->y, p->z); - GXColor4u8(p->r, p->g, p->b, p->a); - p++; - count--; - } while (count != 0); } } } diff --git a/src/melee/ft/ftcpuattack.c b/src/melee/ft/ftcpuattack.c index 53ac6cb983..faeb4ac8b3 100644 --- a/src/melee/ft/ftcpuattack.c +++ b/src/melee/ft/ftcpuattack.c @@ -40,30 +40,6 @@ typedef struct ftCo_AttackEntry { /* +20 */ s32 x20; } ftCo_AttackEntry; -typedef struct ftCo_x50_attr { - /* +00 */ u8 pad00[0x10]; - /* +10 */ f32 x10; - /* +14 */ f32 x14; -} ftCo_x50_attr; - -typedef struct ftCo_x50_t { - /* +00 */ u8 pad00[0x40]; - /* +40 */ f32 x40; - /* +44 */ f32 x44; - /* +48 */ u8 pad48[0x4C - 0x48]; - /* +4C */ f32 x4C; - /* +50 */ f32 x50; - /* +54 */ u8 pad54[0xC0 - 0x54]; - /* +C0 */ s32 xC0; - /* +C4 */ u8 padC4[0xCC - 0xC4]; - /* +CC */ ftCo_x50_attr* xCC; - /* +D0 */ u8 padD0[0xC1C - 0xD0]; - /* +C1C */ f32 xC1C; - /* +C20 */ f32 xC20; - /* +C24 */ f32 xC24; - /* +C28 */ f32 xC28; -} ftCo_x50_t; - typedef struct ftCo_CollData { /* +00 */ u8 pad0[4]; /* +04 */ Vec3 p; @@ -141,7 +117,6 @@ static void sdata2_order(void) } #endif -/// @todo Fake helper forcing a fresh load of the scale field. #ifdef MUST_MATCH /// MSL sqrtf expansion writing through a caller-provided stack slot so each /// call site owns a distinct 4-byte temp (retail 0x28..0x34 below sp3C). @@ -161,6 +136,11 @@ static inline float sqrtf_store(float x, volatile float* y) #define sqrtf_store(x, y) sqrtf(x) #endif +static inline f32 get_scale(Fighter* fp) +{ + return fp->x34_scale.y; +} + static inline int ftCo_CpuSelectAttack(Fighter* fp, struct Fighter_x1A88_t* cpu, const ftCo_AttackEntry* entry) @@ -389,12 +369,14 @@ int ftCo_800B4AB0(Fighter* fp, Fighter* target, void* arg2) int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) { ftCo_AttackEntry sp40[32]; + float sqrt_tmp[4]; /* pins sqrtf volatile slots at 0x2C..0x38 */ ftCo_AttackEntry* list = arg2; ftCo_AttackEntry* sel; struct Fighter_x1A88_t* cpu = &fp->x1A88; s32 count; s32 i; s32 j; + s32 k; bool found; bool nearzero; f32 r; @@ -406,7 +388,7 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) f32 relPredY; f32 v; f32 sq; - f32 diry; + f32 scale; f32 fpX; f32 fpY; f32 fpVx; @@ -423,6 +405,8 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) f32 rangeB; f32 x568; f32 relx; + f32 lower; + f32 upper; f32 halfRange; PAD_STACK(0x10); @@ -432,7 +416,6 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) cpu->x6C.y = 0.0f; cpu->x6C.x = 0.0f; halfRange = (f32) (0.5 * cpu->x570 + 0.5); - (void) halfRange; if (list == NULL) { return 0; } @@ -458,8 +441,8 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) x568 = target->x1A88.x568; count = 0; while (list->cmd) { - f32 scale; f32 dirx; + f32 diry; found = false; if (list->x20 > cpu->level) { list++; @@ -491,11 +474,11 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) if (v <= 0.0f) { fpPredY = fpVy * t + fpY; } else if (t < v) { - sq = sqrtf(t); + sq = sqrtf_store(t, &sqrt_tmp[2]); fpPredY = (f32) ((f64) fpY + ((f64) (fpVy * t) - 0.5 * (f64) (fpGrav * sq))); } else { - sq = sqrtf(v); + sq = sqrtf_store(v, &sqrt_tmp[1]); fpPredY = (f32) ((f64) fpY + ((f64) (fpTermNeg * (t - v)) + @@ -515,15 +498,15 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) } else { v = -(tgtTermNeg - tgtVy) / tgtGrav; } - if (v <= 0.0) { + if (v <= 0.0f) { relPredY = (tgtVy * t + tgtY) - fpPredY; } else if (t < v) { - sq = sqrtf(t); + sq = sqrtf_store(t, &sqrt_tmp[0]); relPredY = (f32) (((f64) (tgtVy * t + tgtY) - 0.5 * (f64) (tgtGrav * sq)) - (f64) fpPredY); } else { - sq = sqrtf(v); + sq = sqrtf_store(v, sqrt_tmp - 1); relPredY = (f32) (((f64) (tgtTermNeg * (t - v)) + ((f64) (tgtVy * t + tgtY) - 0.5 * (f64) (tgtGrav * sq))) - @@ -536,15 +519,17 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) dirx = list->x08 * fp->x34_scale.y; diry = list->x0C * fp->x34_scale.y + reach; } else { - dirx = fp->x34_scale.y * -list->x0C - reach; - diry = fp->x34_scale.y * -list->x08; + dirx = -list->x0C * fp->x34_scale.y - reach; + diry = -list->x08 * fp->x34_scale.y; } dirx *= halfRange; diry *= halfRange; scale = fp->x34_scale.y; - (void) scale; - if ((scale * list->x14 + reach) * halfRange > relPredY && - list->x10 * scale * halfRange < relPredY + x568 && + upper = list->x14 * scale + reach; + lower = list->x10 * scale; + upper *= halfRange; + lower *= halfRange; + if (upper > relPredY && lower < relPredY + x568 && dirx < relx + rangeF && diry > relx - rangeB) { if (cpu->xC8 != 0) { @@ -579,11 +564,13 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) } inv = 1.0 / sum; acc = 0.0f; - for (i = 0, sel = sp40; i < count; i++, sel++) { + sel = sp40; + for (k = 0; k < count; k++) { acc += sel->weight; if (acc * inv >= r) { - return ftCo_CpuSelectAttack(fp, cpu, &sp40[i]); + return ftCo_CpuSelectAttack(fp, cpu, &sp40[k]); } + sel++; } HSD_ASSERT(0x1C5, 0); } @@ -597,16 +584,14 @@ ftCo_803C6594_t* ftCo_803C6594[Gr_Kind_Count] = { int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) { + Item* x50 = arg1; ftCo_AttackEntry sp34[32]; - ftCo_x50_t* x50 = arg1; - ftCo_x50_attr* attrs; ftCo_AttackEntry* list = arg2; - ftCo_AttackEntry* sel; struct Fighter_x1A88_t* cpu = &fp->x1A88; s32 count; s32 i; s32 j; - bool found; + f32 t; bool nearzero; f32 r; f32 sum; @@ -615,47 +600,45 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) f32 fpPredY; f32 relPredY; f32 v; - f32 sq; - f32 diry; - f32 acc; f32 fpX; - f32 fpY; + f32 dirx; + f32 acc; f32 fpVx; + f32 fpY; f32 fpVy; + bool found; f32 fpGrav; f32 x50X; f32 x50Y; f32 x50Vy; f32 x50Vx; f32 x50TermNeg; - f32 sizeHalf; + f32 sq; f32 x50Grav; + f32 sizeHalf; f32 yBound; - cpu = &fp->x1A88; if (list == NULL) { return 0; } - attrs = x50->xCC; count = 0; fpTermNeg = -fp->co_attrs.terminal_velocity; fpY = fp->cur_pos.y; - x50Vy = x50->x44; - x50TermNeg = -attrs->x14; - sizeHalf = (f32) (0.5 * (x50->xC24 + x50->xC28)); - yBound = x50->xC1C + x50->xC20; + x50Vy = x50->x40_vel.y; + x50TermNeg = -x50->xCC_item_attr->x14_fall_speed_max; + sizeHalf = (f32) (0.5 * (x50->xC1C.right + x50->xC1C.left)); fpX = fp->cur_pos.x; + yBound = x50->xC1C.top + x50->xC1C.bottom; fpVx = fp->pos_delta.x; fpVy = fp->pos_delta.y; fpGrav = fp->co_attrs.gravity; - x50X = x50->x4C; - x50Y = x50->x50; - x50Vx = x50->x40; - x50Grav = attrs->x10; + x50X = x50->pos.x; + x50Y = x50->pos.y; + x50Vx = x50->x40_vel.x; + x50Grav = x50->xCC_item_attr->x10_fall_speed; while (list->cmd) { - f32 t; f32 relx; - f32 dirx; + f32 diry; f32 scale; f32 upper; f32 lower; @@ -676,7 +659,7 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) } t = list->x04; relx = (x50Vx * t + x50X) - (fpVx * t + fpX); - if (x50->xC0 == 1) { + if (x50->ground_or_air == GA_Air) { if (fpGrav < 0.00001f && fpGrav > -0.00001f) { nearzero = true; } else { @@ -703,7 +686,7 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) } else { fpPredY = fpVy * t + fpY; } - if (x50->xC0 == 1) { + if (x50->ground_or_air == GA_Air) { if (x50Grav < 0.00001f && x50Grav > -0.00001f) { nearzero = true; } else { @@ -735,10 +718,10 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) dirx = list->x08 * fp->x34_scale.y; diry = list->x0C * fp->x34_scale.y; } else { - dirx = fp->x34_scale.y * -list->x0C; - diry = fp->x34_scale.y * -list->x08; + dirx = -list->x0C * fp->x34_scale.y; + diry = -list->x08 * fp->x34_scale.y; } - scale = fp->x34_scale.y; + scale = get_scale(fp); upper = list->x14 * scale; lower = list->x10 * scale; if (upper > relPredY && lower < relPredY + yBound && @@ -776,8 +759,8 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) } inv = 1.0 / sum; acc = 0.0f; - for (i = 0, sel = sp34; i < count; i++, sel++) { - acc += sel->weight; + for (i = 0; i < count; i++) { + acc += sp34[i].weight; if (acc * inv >= r) { return sp34[i].cmd; } diff --git a/src/melee/gm/gm_16A2.c b/src/melee/gm/gm_16A2.c index 5029cc70e6..e38f17d34b 100644 --- a/src/melee/gm/gm_16A2.c +++ b/src/melee/gm/gm_16A2.c @@ -333,18 +333,19 @@ s32 fn_80169A84(u8 arg0, s8* arg1, s8* arg2) } { + s8* q; s32 idx = 0; - s8* dst2 = arg1; - s8* src2 = arg2; - while (*src2 != -2) { - while (lbl_8046B488.x1C0[idx] == -1) { + p = arg1; + arg1 = arg2; + while (*arg1 != -2) { + while ((result = (q = &lbl_8046B488.x0 + idx)[0x1C0]) == -1) { idx = (idx + 1) % 27; } - result = Player_800325C8(lbl_8046B488.x1C0[idx], 0); - *dst2 = result; + result = Player_800325C8(result, 0); + *p = result; idx += 1; - src2 += 1; - dst2 += 1; + arg1 += 1; + p += 1; } } break; @@ -363,38 +364,30 @@ s32 fn_80169A84(u8 arg0, s8* arg1, s8* arg2) void fn_80169C54(s8 arg0, s8 arg1) { struct lbl_8046B488_t* st; - s32* bp; - s8* pc; - s8* cp; s32 buf[7]; + s8* pc; s32 n; s32 i; - s32 j; + s32 count; s32 k; + s32 j; + s8* cp; s32 p; s32 ch; - PAD_STACK(8); - n = 0; st = fn_8016AE60(); - pc = (s8*) st; - bp = buf; - buf[0] = -1; - buf[1] = -1; - buf[2] = -1; - buf[3] = -1; - buf[4] = -1; - buf[5] = -1; - buf[6] = -1; + pc = &st->x0; + for (i = 0; i < 7; i++) { + buf[i] = -1; + } for (i = 0; i < 3; i++) { if ((s32) *pc == 4) { if (st->xB == 0) { - s32 count; count = gm_80169238(4U); for (k = 0; k < count; k++) { - bp[k] = k; - n += 1; + buf[k] = k; + n++; } } else { n = 1; @@ -402,16 +395,16 @@ void fn_80169C54(s8 arg0, s8 arg1) } break; } - pc += 1; + pc++; } if (arg0 == 4) { buf[n] = arg1; - n += 1; + n++; } if (n > 0) { j = 0; - cp = (s8*) st; + cp = &st->x0; do { ch = *cp; if (0x21 != ch && ch != 4) { @@ -428,8 +421,8 @@ void fn_80169C54(s8 arg0, s8 arg1) } } } - j += 1; - cp += 1; + j++; + cp++; } while (j < 3); if (arg0 != 4) { p = Player_800325C8((CharacterKind) arg0, 0); @@ -448,19 +441,22 @@ void fn_80169C54(s8 arg0, s8 arg1) } } -static inline void fn_80169F50_inline(s32 arg1, struct lbl_8046B488_t* gp, - int temp_arg0) +static inline void fn_80169F50_inline(s8 costume, struct lbl_8046B488_t* gp, + int character) { s32 i; - if (temp_arg0 == 4 && gp->xE != 0) { - for (i = 0; gp->x20[i] != -2; i++) { + s32 costume_id; + if (character == 4 && gp->xE != 0) { + i = 0; + costume_id = costume; + for (; gp->x20[i] != -2; i++) { if (gp->x20[i] == -1) { continue; } if (gp->x124[i] == -1) { continue; } - Player_80031DA8(gp->x124[i], arg1); + Player_80031DA8(gp->x124[i], costume_id); } } } @@ -476,14 +472,11 @@ void fn_80169F50(s8 arg0, s8 arg1) temp_arg0 = arg0; flag = 0; - if (gp->x0 == 4) { - flag = 1; - } else { - p = &gp->x1; - if (gp->x1 == 4) { - flag = 1; - } else if (p[1] == 4) { + p = &gp->x0; + for (i = 0; i < 3; i++) { + if (p[i] == 4) { flag = 1; + break; } } @@ -598,11 +591,11 @@ s32 gm_8016A22C(s8 k0, s8 k1, s8 k2, u8 a3, u8 a4, int a5, int mode, int a7, int flag2, int flag1, f32 f1, f32 f2) { int i; - struct lbl_8046B488_t* gp; + struct lbl_8046B488_t* gp = &lbl_8046B488; struct gm_8016A22C_header* header; u8 x7_tmp; - memzero(&lbl_8046B488, 0x1C0); + memzero(gp, 0x1C0); lbl_8046B488.x0 = k0; lbl_8046B488.x1 = k1; @@ -641,7 +634,6 @@ s32 gm_8016A22C(s8 k0, s8 k1, s8 k2, u8 a3, u8 a4, int a5, int mode, int a7, lbl_8046B488.xC = a3; - gp = &lbl_8046B488; header = gm_8016A22C_header(gp); x7_tmp = header->bytes[7]; memzero(header->x20, x7_tmp); diff --git a/src/melee/gm/gm_16F1.c b/src/melee/gm/gm_16F1.c index a808f46485..21f10915d1 100644 --- a/src/melee/gm/gm_16F1.c +++ b/src/melee/gm/gm_16F1.c @@ -503,9 +503,10 @@ int fn_801701C0(void* arg0, int arg1, int arg2) 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]; u8 rankings[7] = { 0 }; + s32 player_net; + int i; if (lbl_804D65A0 != 0) { return 0; @@ -517,39 +518,30 @@ int fn_801701C0(void* arg0, int arg1, int arg2) if (rules->x5 == 3) { fn_80171B64((struct lbl_804D65A8_t*) rankings); } else { - int k; - - for (k = 0; k < 6; k++) { - if (x58[k].x0 != 3) { - u16 xA = x58[k].xA; - scores[k] = - (x58[k].x20 - (x58[k].x24 - xA)) + ((s8) rules->xC * xA); + for (i = 0; i < 6; i++) { + if (x58[i].x0 != 3) { + u16 xA = x58[i].xA; + scores[i] = + x58[i].x20 - (x58[i].x24 - xA) + *(s8*) &rules->xC * xA; } } - { - int idx; - for (idx = 0; idx < 6; idx++) { - if (x58[idx].x0 != 3) { - s32 my_score = scores[idx]; - int j; - - for (j = 0; j < 6; j++) { - if (x58[j].x0 != 3 && idx != j && my_score < scores[j]) - { - rankings[idx]++; - } - } - - if (rankings[6] < rankings[idx]) { - rankings[6] = rankings[idx]; + for (i = 0; i < 6; i++) { + if (x58[i].x0 != 3) { + int j; + for (j = 0; j < 6; j++) { + if (x58[j].x0 != 3 && i != j && scores[i] < scores[j]) { + rankings[i]++; } } + if (rankings[6] < rankings[i]) { + rankings[6] = rankings[i]; + } } } } - PAD_STACK(8); + PAD_STACK(4); switch (arg2) { case 0xD7: @@ -557,13 +549,12 @@ int fn_801701C0(void* arg0, int arg1, int arg2) return 0; } { - struct lbl_8046B6A0_24C_58_t* p = x58; + u8* rank = rankings; int i; - for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && rankings[i] == 0) { + for (i = 0; i < 4; i++, rank++) { + if (x58[i].x0 != 3 && i != arg1 && *rank == 0) { return 0; } - p++; } } if (rankings[arg1] == 0) { @@ -576,17 +567,17 @@ int fn_801701C0(void* arg0, int arg1, int arg2) return 0; } { - struct lbl_8046B6A0_24C_58_t* p = x58; + u8* rank = rankings; + u8 max_rank = rankings[6]; int i; - for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && rankings[i] == rankings[6]) { + for (i = 0; i < 4; i++, rank++) { + if (x58[i].x0 != 3 && i != arg1 && *rank == max_rank) { return 0; } - p++; } - } - if (rankings[arg1] == rankings[6]) { - return 1; + if (rankings[arg1] == max_rank) { + return 1; + } } return 0; @@ -621,6 +612,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xDB: { s32 vals[4]; s32* base; + s32* p; int i, j; if (x58[arg1].x20 >= 3) { base = vals; @@ -630,19 +622,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } copy_t; *(copy_t*) base = *(copy_t*) zeroes->x0; } - { - struct lbl_8046B6A0_24C_58_t* p = x58; - s32* vp = base; - for (i = 0; i < 4; i++) { - if (p->x0 != 3) { - *vp = p->x20; - } - p++; - vp++; + for (i = 0; i < 4; i++) { + if (x58[i].x0 != 3) { + base[i] = x58[i].x20; } } for (j = 3; j >= 1; j--) { - s32* p = base; + p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { s32 tmp = p[1]; @@ -662,13 +648,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xDC: { if ((unsigned) fn_801701C0(arg0, arg1, 0xDB) == 0) { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && p->x20 >= x58[arg1].x20) { + if (x58[i].x0 != 3 && i != arg1 && + x58[i].x20 >= x58[arg1].x20) + { return 0; } - p++; } } if (x58[arg1].x20 != 0) { @@ -681,6 +667,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xDD: { s32 vals[4]; s32* base; + s32* p; int i, j; if (x58[arg1].x40 >= 3) { base = vals; @@ -690,19 +677,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } copy_t; *(copy_t*) base = *(copy_t*) zeroes->x10; } - { - struct lbl_8046B6A0_24C_58_t* p = x58; - s32* vp = base; - for (i = 0; i < 4; i++) { - if (p->x0 != 3) { - *vp = p->x40; - } - p++; - vp++; + for (i = 0; i < 4; i++) { + if (x58[i].x0 != 3) { + base[i] = x58[i].x40; } } for (j = 3; j >= 1; j--) { - s32* p = base; + p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { s32 tmp = p[1]; @@ -722,13 +703,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xDE: { if ((unsigned) fn_801701C0(arg0, arg1, 0xDD) == 0) { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && p->x40 >= x58[arg1].x40) { + if (x58[i].x0 != 3 && i != arg1 && + x58[i].x40 >= x58[arg1].x40) + { return 0; } - p++; } } if (x58[arg1].x40 != 0) { @@ -741,6 +722,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xDF: { s32 vals[4]; s32* base; + s32* p; int i, j; player_net = x58[arg1].x24 - x58[arg1].xA; if ((u32) player_net >= 3) { @@ -751,19 +733,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } copy_t; *(copy_t*) base = *(copy_t*) zeroes->x20; } - { - struct lbl_8046B6A0_24C_58_t* p = x58; - s32* vp = base; - for (i = 0; i < 4; i++) { - if (p->x0 != 3) { - *vp = p->x24 - p->xA; - } - p++; - vp++; + for (i = 0; i < 4; i++) { + if (x58[i].x0 != 3) { + base[i] = x58[i].x24 - x58[i].xA; } } for (j = 3; j >= 1; j--) { - s32* p = base; + p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { s32 tmp = p[1]; @@ -785,16 +761,14 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xE0: { if ((unsigned) fn_801701C0(arg0, arg1, 0xDF) == 0) { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && - (u32) (p->x24 - p->xA) >= + if (x58[i].x0 != 3 && i != arg1 && + (u32) (x58[i].x24 - x58[i].xA) >= (u32) (x58[arg1].x24 - x58[arg1].xA)) { return 0; } - p++; } } if ((x58[arg1].x24 - x58[arg1].xA) != 0) { @@ -807,6 +781,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xE1: { s32 vals[4]; s32* base; + s32* p; int i, j; if (x58[arg1].xA >= 3) { base = vals; @@ -816,19 +791,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } copy_t; *(copy_t*) base = *(copy_t*) zeroes->x30; } - { - struct lbl_8046B6A0_24C_58_t* p = x58; - s32* vp = base; - for (i = 0; i < 4; i++) { - if (p->x0 != 3) { - *vp = p->xA; - } - p++; - vp++; + for (i = 0; i < 4; i++) { + if (x58[i].x0 != 3) { + base[i] = x58[i].xA; } } for (j = 3; j >= 1; j--) { - s32* p = base; + p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { s32 tmp = p[1]; @@ -848,13 +817,13 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xE2: { if ((unsigned) fn_801701C0(arg0, arg1, 0xE1) == 0) { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && p->xA >= x58[arg1].xA) { + if (x58[i].x0 != 3 && i != arg1 && + x58[i].xA >= x58[arg1].xA) + { return 0; } - p++; } } if (x58[arg1].xA != 0) { @@ -1004,6 +973,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xF9: { f32 vals[4]; f32* base = vals; + f32* p; int i, j; { typedef struct { @@ -1017,7 +987,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } } for (j = 3; j >= 1; j--) { - f32* p = base; + p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { f32 tmp = p[1]; @@ -1057,28 +1027,24 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xFC: { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && (p->x3 & 1)) { + if (x58[i].x0 != 3 && i != arg1 && (x58[i].x3 & 1)) { return 0; } - p++; } } if (rules->x5 == 3) { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && rankings[i] == 0) { + if (x58[i].x0 != 3 && i != arg1 && rankings[i] == 0) { return 0; } - p++; } } - if (!(((u8*) x58)[arg1 * sizeof(*x58) + 3] & 1) && - rankings[arg1] == 0 && x58[arg1].x20 == 0) + if (!(rules->x58[arg1].x3 & 1) && rankings[arg1] == 0 && + x58[arg1].x20 == 0) { return 1; } @@ -1091,24 +1057,20 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } if (mode == 0) { { - struct lbl_8046B6A0_24C_58_t* p = x58; int i; for (i = 0; i < 4; i++) { - if (p->x0 != 3 && i != arg1 && p->x5 == 0) { + if (x58[i].x0 != 3 && i != arg1 && x58[i].x5 == 0) { return 0; } - p++; } } - if (!(((u8*) x58)[arg1 * sizeof(*x58) + 3] & 1) && - x58[arg1].x5 == 0 && x58[arg1].x20 == 0) + if (!(rules->x58[arg1].x3 & 1) && x58[arg1].x5 == 0 && + x58[arg1].x20 == 0) { return 1; } } else { - if (!(((u8*) x58)[arg1 * sizeof(*x58) + 3] & 1) && - x58[arg1].x20 == 0) - { + if (!(rules->x58[arg1].x3 & 1) && x58[arg1].x20 == 0) { return 1; } } @@ -1126,6 +1088,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xFE: { u32 vals[4]; + u32* p; int i, j; unsigned int threshold; if (pl_800408B8(arg1) == 0) { @@ -1152,8 +1115,8 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } } for (j = 3; j >= 1; j--) { - u32* p = vals; - for (i = j; i > 0; i--) { + p = vals; + for (i = j; (u32) i > 0; i--) { if (p[0] > p[1]) { u32 tmp = p[1]; p[1] = p[0]; @@ -1174,6 +1137,7 @@ int fn_801701C0(void* arg0, int arg1, int arg2) case 0xFF: { u32 vals[4]; + u32* p; int i, j; unsigned int threshold; threshold = pl_80038914()->x140; @@ -1197,8 +1161,8 @@ int fn_801701C0(void* arg0, int arg1, int arg2) } } for (j = 3; j >= 1; j--) { - u32* p = vals; - for (i = j; i > 0; i--) { + p = vals; + for (i = j; (u32) i > 0; i--) { if (p[0] < p[1]) { u32 tmp = p[1]; p[1] = p[0]; diff --git a/src/melee/gm/gm_1832.c b/src/melee/gm/gm_1832.c index cba511cd01..665c1e5628 100644 --- a/src/melee/gm/gm_1832.c +++ b/src/melee/gm/gm_1832.c @@ -1029,17 +1029,84 @@ void fn_80186400(void) static char lbl_804D40B0[] = "IrRdMap"; -void fn_80186634(void* arg0) +typedef struct ClassicArchiveNameArray { + const char* v[4]; +} ClassicArchiveNameArray; + +typedef struct ClassicArchiveNameLocal { + ClassicArchiveNameArray names; + u32 pad; +} ClassicArchiveNameLocal; + +static inline void* gm_80186634_LoadLightList(void) +{ + return lb_80011AC4(lbl_804D65FC->lights); +} + +static inline void gm_80186634_SetupLight(void) { HSD_GObj* gobj; + + gobj = GObj_Create(0xB, 3, 0); + HSD_GObjObject_80390A70(gobj, HSD_GObj_LightKind, + gm_80186634_LoadLightList()); + GObj_SetupGXLink(gobj, HSD_GObj_LObjCallback, 0, 0); +} + +static inline void gm_80186634_SetupCamera(void) +{ HSD_GObj* gobj2; - HSD_JObj* jobj; - HSD_CObj* cobj1; - HSD_GObj* gobj3; + HSD_GObj* gobj; + HSD_CObj* cobj; HSD_CObj* cobj2; - HSD_GObj* gobj4; - const char* names[4]; - PAD_STACK(16); + + gobj = GObj_Create(0x13, 0x14, 0); + cobj = HSD_CObjLoadDesc(lbl_804D65FC->cameras[0].desc); + cobj2 = HSD_CObjLoadDesc(lbl_804D6600->cameras[0].desc); + HSD_GObjObject_80390A70(gobj, HSD_GObj_CameraKind, cobj); + GObj_SetupGXLinkMax(gobj, HSD_GObj_803910D8, 8); + gobj->gxlink_prios = 0x801; + gobj2 = GObj_Create(0x13, 0x15, 0); + HSD_GObjObject_80390A70(gobj2, HSD_GObj_CameraKind, cobj2); + if (lbl_8047368C.model_scale_kind == 4) { + GObj_SetupGXLinkMax(gobj2, (GObj_RenderFunc) (Event) fn_8018569C, 8); + } else { + GObj_SetupGXLinkMax(gobj2, (GObj_RenderFunc) (Event) fn_8018575C, 8); + } +} + +static inline void gm_80186634_SetupModel(void) +{ + HSD_GObj* gobj; + HSD_JObj* jobj; + + gobj = GObj_Create(0xE, 0xF, 0); + jobj = HSD_JObjLoadJoint(lbl_804D6600->models[0]->joint); + HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); + GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xC, 0); + HSD_GObj_SetupProc(gobj, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); + gm_8016895C(jobj, lbl_804D6600->models[0], 0); + HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); + HSD_JObjAnimAll(jobj); + lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); + lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); +} + +static inline void gm_80186634_SetupFog(void) +{ + HSD_GObj* gobj; + HSD_Fog* fog; + + gobj = GObj_Create(0xE, 0xF, 0); + fog = HSD_FogLoadDesc(lbl_804D65FC->fogs[0].desc); + HSD_GObjObject_80390A70(gobj, HSD_GObj_FogKind, fog); + GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0xB, 0); +} + +void fn_80186634(void* arg0) +{ + ClassicArchiveNameLocal local; + PAD_STACK(12); lbArchive_80016DBC("GmIntEz.dat", &lbl_804D6604, "gmIntroEasyTable", 0); Camera_80028B9C(0xC); @@ -1053,20 +1120,14 @@ void fn_80186634(void* arg0) efLib_Init(); efAsync_LoadSync(0); - names[0] = lbl_803B7C58[0]; - names[1] = lbl_803B7C58[1]; - names[3] = lbl_803B7C58[3]; - names[2] = lbl_803B7C58[2]; + local.names = *(const ClassicArchiveNameArray*) lbl_803B7C58; lbl_804D65F4 = - lbArchive_80016DBC(names[lbl_8047368C.game_type], &lbl_804D65FC, - "ScItrAllstar_scene_data", 0); + lbArchive_80016DBC(local.names.v[lbl_8047368C.game_type], + &lbl_804D65FC, "ScItrAllstar_scene_data", 0); lbl_804D65F8 = lbArchive_80016DBC(lbl_804D40B0, &lbl_804D6600, "ScItrAllstar_scene_data", 0); - gobj = GObj_Create(0xB, 3, 0); - HSD_GObjObject_80390A70(gobj, HSD_GObj_LightKind, - lb_80011AC4(lbl_804D65FC->lights)); - GObj_SetupGXLink(gobj, HSD_GObj_LObjCallback, 0, 0); + gm_80186634_SetupLight(); if (lbl_8047368C.model_scale_kind != 3) { lbl_8047368C.game_type = 0; @@ -1074,110 +1135,28 @@ void fn_80186634(void* arg0) switch (lbl_8047368C.model_scale_kind) { case 3: - gobj2 = GObj_Create(0x13, 0x14, 0); - cobj1 = HSD_CObjLoadDesc(lbl_804D65FC->cameras[0].desc); - cobj2 = HSD_CObjLoadDesc(lbl_804D6600->cameras[0].desc); - HSD_GObjObject_80390A70(gobj2, HSD_GObj_CameraKind, cobj1); - GObj_SetupGXLinkMax(gobj2, HSD_GObj_803910D8, 8); - gobj2->gxlink_prios = 0x801; - gobj3 = GObj_Create(0x13, 0x15, 0); - HSD_GObjObject_80390A70(gobj3, HSD_GObj_CameraKind, cobj2); - if (lbl_8047368C.model_scale_kind == 4) { - GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018569C, - 8); - } else { - GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018575C, - 8); - } + gm_80186634_SetupCamera(); fn_80186400(); - gobj4 = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint(lbl_804D6600->models[0]->joint); - HSD_GObjObject_80390A70(gobj4, HSD_GObj_JObjKind, jobj); - GObj_SetupGXLink(gobj4, HSD_GObj_JObjCallback, 0xC, 0); - HSD_GObj_SetupProc(gobj4, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); - gm_8016895C(jobj, lbl_804D6600->models[0], 0); - HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); - HSD_JObjAnimAll(jobj); - lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); - lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); - gobj = GObj_Create(0xE, 0xF, 0); - { - HSD_Fog* fog = HSD_FogLoadDesc(lbl_804D65FC->fogs[0].desc); - HSD_GObjObject_80390A70(gobj, HSD_GObj_FogKind, fog); - } - GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0xB, 0); + gm_80186634_SetupModel(); + gm_80186634_SetupFog(); fn_80186080(); break; case 0: case 1: case 2: - gobj2 = GObj_Create(0x13, 0x14, 0); - cobj1 = HSD_CObjLoadDesc(lbl_804D65FC->cameras[0].desc); - cobj2 = HSD_CObjLoadDesc(lbl_804D6600->cameras[0].desc); - HSD_GObjObject_80390A70(gobj2, HSD_GObj_CameraKind, cobj1); - GObj_SetupGXLinkMax(gobj2, HSD_GObj_803910D8, 8); - gobj2->gxlink_prios = 0x801; - gobj3 = GObj_Create(0x13, 0x15, 0); - HSD_GObjObject_80390A70(gobj3, HSD_GObj_CameraKind, cobj2); - if (lbl_8047368C.model_scale_kind == 4) { - GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018569C, - 8); - } else { - GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018575C, - 8); - } + gm_80186634_SetupCamera(); fn_80186400(); - gobj4 = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint(lbl_804D6600->models[0]->joint); - HSD_GObjObject_80390A70(gobj4, HSD_GObj_JObjKind, jobj); - GObj_SetupGXLink(gobj4, HSD_GObj_JObjCallback, 0xC, 0); - HSD_GObj_SetupProc(gobj4, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); - gm_8016895C(jobj, lbl_804D6600->models[0], 0); - HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); - HSD_JObjAnimAll(jobj); - lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); - lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); - gobj = GObj_Create(0xE, 0xF, 0); - { - HSD_Fog* fog = HSD_FogLoadDesc(lbl_804D65FC->fogs[0].desc); - HSD_GObjObject_80390A70(gobj, HSD_GObj_FogKind, fog); - } - GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0xB, 0); + gm_80186634_SetupModel(); + gm_80186634_SetupFog(); fn_801861B8(); fn_80185D64(); fn_80185F5C(fn_80185E34()); break; case 4: - gobj2 = GObj_Create(0x13, 0x14, 0); - cobj1 = HSD_CObjLoadDesc(lbl_804D65FC->cameras[0].desc); - cobj2 = HSD_CObjLoadDesc(lbl_804D6600->cameras[0].desc); - HSD_GObjObject_80390A70(gobj2, HSD_GObj_CameraKind, cobj1); - GObj_SetupGXLinkMax(gobj2, HSD_GObj_803910D8, 8); - gobj2->gxlink_prios = 0x801; - gobj3 = GObj_Create(0x13, 0x15, 0); - HSD_GObjObject_80390A70(gobj3, HSD_GObj_CameraKind, cobj2); - if (lbl_8047368C.model_scale_kind == 4) { - GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018569C, - 8); - } else { - GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018575C, - 8); - } + gm_80186634_SetupCamera(); fn_80186400(); - gobj4 = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint(lbl_804D6600->models[0]->joint); - HSD_GObjObject_80390A70(gobj4, HSD_GObj_JObjKind, jobj); - GObj_SetupGXLink(gobj4, HSD_GObj_JObjCallback, 0xC, 0); - HSD_GObj_SetupProc(gobj4, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); - gm_8016895C(jobj, lbl_804D6600->models[0], 0); - HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); - HSD_JObjAnimAll(jobj); - lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); - lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); - gobj = GObj_Create(0xE, 0xF, 0); - HSD_GObjObject_80390A70(gobj, HSD_GObj_FogKind, - HSD_FogLoadDesc(lbl_804D65FC->fogs[0].desc)); - GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0xB, 0); + gm_80186634_SetupModel(); + gm_80186634_SetupFog(); fn_801861B8(); fn_80185D64(); fn_80185A0C(); @@ -1742,14 +1721,31 @@ static inline StKind gm_GetStKind(gm_80187F48_EnterData* data) return data->stkind; } +static inline u64 gm_80187F48_GetAudioConfig(u8 stage_index, char** table) +{ + return lbAudioAx_80026E84(Player_GetPlayerCharacter(0)) | + ((u64*) &table[24])[stage_index]; +} + +static inline void gm_80187F48_SetupCamera(HSD_GObj* gobj, + gm_1832_804736C0_t* data, + HSD_CObj* cobj) +{ + HSD_GObj_SetupProc(gobj, fn_80187910, 0); + HSD_CObjAddAnim(cobj, *(HSD_CameraAnim**) data->x4[1]); + HSD_CObjReqAnim(cobj, 0.0f); +} + static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) { - gm_1832_804736C0_t* data = &lbl_804736C0; - char** table = lbl_803D9750; + gm_1832_804736C0_t* data; + HSD_CObj* cobj; u8 stage_index; HSD_GObj* gobj; - HSD_CObj* cobj; + char** table = lbl_803D9750; gm_1832_StageState* state; + + data = &lbl_804736C0; data->x38 = arg0->x0; lb_8000FCDC(); mpColl_80041C78(); @@ -1780,8 +1776,7 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) lbAudioAx_80026F2C((s32) table[stage_index + 12]); lbAudioAx_8002702C((s32) table[stage_index + 12], - lbAudioAx_80026E84(Player_GetPlayerCharacter(0)) | - ((u64*) &table[24])[stage_index]); + gm_80187F48_GetAudioConfig(stage_index, table)); lbAudioAx_80027168(); lbAudioAx_80027648(); @@ -1790,9 +1785,7 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) cobj = HSD_CObjLoadDesc((HSD_CObjDesc*) *data->x4); HSD_GObjObject_80390A70(gobj, HSD_GObj_CameraKind, cobj); GObj_SetupGXLinkMax(gobj, (GObj_RenderFunc) (Event) Camera_800304E0, 8); - HSD_GObj_SetupProc(gobj, fn_80187910, 0); - HSD_CObjAddAnim(cobj, *(HSD_CameraAnim**) data->x4[1]); - HSD_CObjReqAnim(cobj, 0.0f); + gm_80187F48_SetupCamera(gobj, data, cobj); { HSD_GObj* scene_gobj = GObj_Create(0x13, 0x14, 0); @@ -1814,7 +1807,6 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) { HSD_JObj* model_jobj; HSD_GObj* model_gobj; - DynamicModelDesc* model_desc; model_gobj = GObj_Create(0xE, 0xF, 0); model_jobj = HSD_JObjLoadJoint((*data->x0)[11 - state->stage_index]->joint); @@ -1822,15 +1814,7 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) HSD_GObjObject_80390A70(model_gobj, HSD_GObj_JObjKind, model_jobj); GObj_SetupGXLink(model_gobj, fn_80187C9C, 0xB, 0xB); - model_desc = (*data->x0)[11 - state->stage_index]; - if (model_desc->anims != NULL) { - int model_anim_idx = data->x37.anim_state; - if (model_desc->anims[model_anim_idx] != NULL) { - lb_8000C0E8(model_jobj, model_anim_idx, model_desc); - HSD_JObjReqAnimAll(model_jobj, 0.0f); - HSD_JObjAnimAll(model_jobj); - } - } + fn_80187AB4_LoadAnim(model_jobj, data); HSD_GObj_SetupProc(model_gobj, fn_80187AB4, 0); } @@ -1860,7 +1844,7 @@ static inline void gm_80187F48_OnEnter_inline(gm_80187F48_EnterData* arg0) void gm_Scene_IntroNormal_OnEnter(void* arg0) { - PAD_STACK(32); + PAD_STACK(16); gm_80187F48_OnEnter_inline(arg0); } diff --git a/src/melee/gm/gm_1884.c b/src/melee/gm/gm_1884.c index 5e304ec4f7..977fc93efe 100644 --- a/src/melee/gm/gm_1884.c +++ b/src/melee/gm/gm_1884.c @@ -503,17 +503,23 @@ static inline u32 gm_801891F4_GetTickRate(void) return OS_TIMER_CLOCK; } +static inline s32* gm_801891F4_GetMenuValues(CssSubStruct* sub) +{ + return sub->menu_values; +} + void fn_801891F4(void) { CssSubStruct* sub; u64 buttons; - int count; - int i; 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; @@ -594,11 +600,13 @@ void fn_801891F4(void) } if (buttons & PAD_BUTTON_A) { HSD_JObj* jobj; + HSD_GObj* player_entity; Vec3 pos; s16 item; lbAudioAx_80024030(8); item = *(s16*) &((s32*) lbl_803D9828)[sub->menu_values[1]]; - jobj = Player_GetEntity(0)->hsd_obj; + player_entity = Player_GetEntity(0); + jobj = player_entity->hsd_obj; HSD_JObjGetTranslation2(jobj, &pos); pos.y += 10.0f; it_8026D258(&pos, (ItemKind) item); @@ -609,7 +617,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]--; return; } sub->menu_values[sub->x00] = 2; @@ -747,8 +755,9 @@ void fn_801891F4(void) } } else { if (sub->x01 == 1) { + int count; + int i; int cpu_type; - int damage; f32 speeds[] = { 2, 1.5, 1, 0.666, 0.5, 0.25, }; @@ -757,16 +766,19 @@ void fn_801891F4(void) sfxBack(); sub->anim_frames[22] = 0x14; - lb_80019880(__cvt_dbl_usll( - (f64) (0.016666668f / speeds[sub->menu_values[0]] * - (f32) gm_801891F4_GetTickRate()))); + { + f32 selected_speed = speeds[sub->menu_values[0]]; + lb_80019880( + __cvt_dbl_usll((f64) (0.016666668f / selected_speed * + (f32) gm_801891F4_GetTickRate()))); + } fn_80188550(sub->menu_values[2] + 1); cpu_type = sub->menu_values[3]; (void) cpu_type; count = lbl_80473700.count; - sub->x03 = (u8) cpu_type; + lbl_80473700.css.x03 = (u8) cpu_type; for (i = 0; i < 4; i++) { if (i != 0 && count != 0) { Player_SetPlayerAndEntityCpuType(i, cpu_type); @@ -777,20 +789,30 @@ void fn_801891F4(void) } } - damage = sub->menu_values[4]; - count = lbl_80473700.count; - for (i = 0; i < 4; i++) { - if (i != 0 && count != 0) { - Player_SetHUDDamage(i, damage); - count--; - if (count == 0) { - break; + { + int count; + int i; + int damage; + + damage = sub->menu_values[4]; + count = lbl_80473700.count; + for (i = 0; i < 4; i++) { + if (i != 0 && count != 0) { + Player_SetHUDDamage(i, damage); + count--; + if (count == 0) { + break; + } } } } - for (i = 1; i < 4; i++) { - fn_8016B388(i, sub->menu_values[4]); + { + int i; + + for (i = 1; i < 4; i++) { + fn_8016B388(i, gm_801891F4_GetMenuValues(sub)[4]); + } } switch (sub->menu_values[6]) { diff --git a/src/melee/gm/gm_19EF.c b/src/melee/gm/gm_19EF.c index e5c6e1cf11..b71d870440 100644 --- a/src/melee/gm/gm_19EF.c +++ b/src/melee/gm/gm_19EF.c @@ -378,7 +378,7 @@ void fn_8019F9C4(u32 arg0) s32 i; f32 f; f32 scale; - PAD_STACK(8); + PAD_STACK(16); char_idx = fn_8019F9C4_GetCharIdx(arg0); arg0 = (char_idx == -1) ? 8 : arg0; @@ -505,11 +505,18 @@ void fn_8019F9C4(u32 arg0) HSD_JObjReqAnimAll(lbl_80479A98.x5C, (f32) lbl_80479A98.x6C); HSD_JObjReqAnimAll(lbl_80479A98.x58, (f32) lbl_80479A98.x68); HSD_JObjReqAnimAll(lbl_80479A98.x54, (f32) lbl_80479A98.x64); - for (i = 10; i > 0; i--) { - if (i > lbl_80479A98.x70) { - HSD_JObjSetFlags(lbl_80479A98.x2C[i - 1], JOBJ_HIDDEN); - } else { - HSD_JObjClearFlags(lbl_80479A98.x2C[i - 1], JOBJ_HIDDEN); + { + s32 j; + + ptr = &((HSD_JObj**) &lbl_80479A98)[j = 10]; + ptr += 10; + + for (; j > 0; j--, ptr--) { + if (j > lbl_80479A98.x70) { + HSD_JObjSetFlags(*ptr, JOBJ_HIDDEN); + } else { + HSD_JObjClearFlags(*ptr, JOBJ_HIDDEN); + } } } HSD_JObjAnimAll(jobj); diff --git a/src/melee/gm/gmallstar.c b/src/melee/gm/gmallstar.c index 9cb4531e03..e6ed521313 100644 --- a/src/melee/gm/gmallstar.c +++ b/src/melee/gm/gmallstar.c @@ -380,38 +380,32 @@ static AllstarRoundInfo gm_803DEC4C[13] = { gm_80490940_t gm_80490940[5]; -void gm_801B5324(UnkAllstarData* arg0, s32 arg1) +void gm_801B5324(UnkAllstarData* arg0, u8 arg1) { s8 chars[3]; u8 colors[3]; s8* chars_ptr; - u8* base; s32 is_last_round; gm_803DEBE8_t* opp_data; - s32 count_processed; - s32 count; struct GameCache* gc; s32 slot_idx; - u64 audio; + s32 count_processed; s32 i; - PAD_STACK(12); + u64 audio; + PAD_STACK(16); - base = (u8*) gm_Mode_AllStar_States; is_last_round = 0; chars_ptr = chars; - { - u32 start = ((AllstarRoundInfo*) (base + 0x31C))[arg1].start; - opp_data = (gm_803DEBE8_t*) (base + 0x2B8) + start; - } + opp_data = &gm_803DEBE8[gm_803DEC4C[arg1].start]; chars_ptr[0] = 0x21; chars_ptr[1] = 0x21; chars_ptr[2] = 0x21; - count = ((AllstarRoundInfo*) ((u8*) gm_Mode_AllStar_States + 0x31C))[arg1] - .count; - for (count_processed = 0; count_processed < count; count_processed++) { + for (count_processed = 0; count_processed < (s32) gm_803DEC4C[arg1].count; + count_processed++) + { chars[count_processed] = opp_data[count_processed].x3; } @@ -422,7 +416,7 @@ void gm_801B5324(UnkAllstarData* arg0, s32 arg1) gmRegSetupEnemyColorTable(arg0->x0.ckind, arg0->x0.color, chars_ptr, colors); - if (arg1 == 0xC) { + if ((s32) arg1 == 0xC) { chars_ptr[0] = 3; colors[0] = 0; is_last_round = 1; @@ -434,9 +428,10 @@ void gm_801B5324(UnkAllstarData* arg0, s32 arg1) gc = &lbDvd_GetPreloadCacheScene()->game_cache; lbDvd_80018C6C(); - slot_idx = 1; - gc->entries[0].char_id = (s32) arg0->x0.ckind; - gc->entries[0].color = arg0->x0.color; + slot_idx = 0; + gc->entries[slot_idx].char_id = (s32) arg0->x0.ckind; + gc->entries[slot_idx].color = arg0->x0.color; + slot_idx++; lbDvd_80018254(); lbDvd_80018C2C(0xC7); lbDvd_80017700(4); @@ -458,9 +453,9 @@ void gm_801B5324(UnkAllstarData* arg0, s32 arg1) audio = lbAudioAx_80026E84((CharacterKind) arg0->x0.ckind); { - s8* cp = chars_ptr; for (i = 0; i < 3; i++) { - audio |= lbAudioAx_80026E84(cp[i]); + CharacterKind ckind = chars[i]; + audio |= lbAudioAx_80026E84(ckind); } } @@ -470,6 +465,19 @@ void gm_801B5324(UnkAllstarData* arg0, s32 arg1) lbAudioAx_80027168(); } +static inline void gm_801B5624_inline(s8* char_ids, gm_803DEBE8_t* opp_data, + u16 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_801B5624(GameModeState* arg0) { s8 chars[3]; @@ -477,11 +485,9 @@ void gm_801B5624(GameModeState* arg0) u8* base; UnkAllstarData* allstar; gm_803DEBE8_t* opp_data; - s32 i; - s32 count; u16 round; u8 color; - PAD_STACK(16); + PAD_STACK(8); base = (u8*) gm_Mode_AllStar_States; data = gm_GetGameSceneLoadData(arg0); @@ -489,18 +495,11 @@ void gm_801B5624(GameModeState* arg0) round = gm_8017BE84(arg0->id); { - u32 start = ((AllstarRoundInfo*) (base + 0x31C))[round].start; - opp_data = (gm_803DEBE8_t*) (base + 0x2B8) + start; + u32 start = gm_803DEC4C[round].start; + opp_data = &gm_803DEBE8[start]; } - chars[0] = 0x21; - chars[1] = 0x21; - chars[2] = 0x21; - - count = ((AllstarRoundInfo*) (base + 0x31C))[round].count; - for (i = 0; i < count; i++) { - chars[i] = opp_data[i].x3; - } + gm_801B5624_inline(chars, opp_data, round); allstar->x0.xB = 4; allstar->x0.x8 = 0; @@ -583,9 +582,32 @@ void fn_801B5AA8(int arg0) lbBgFlash_8002063C(0x78); } +static inline void gm_801B5ACC_inline0(StartMeleeData* data, + GameModeState* arg0, u16* round) +{ + data->players[0].xD_b2 = 1; + data->rules.x7 = 9; + + { + u16 current_round = gm_8017BE84(arg0->id); + *round = current_round; + } +} + +static inline void gm_801B5ACC_inline1(AllstarRoundInfo* ri) +{ + s32 end_idx = (s32) ri[1].start; + gm_803DEBE8_t* opp = &gm_803DEBE8[end_idx]; + + while (end_idx < 0x19) { + gm_8016A998((s8) opp->x3, 0); + opp++; + end_idx++; + } +} + void gm_801B5ACC(GameModeState* arg0) { - u8 operand_pad[8]; s8 chars[3]; StartMeleeData* data; u8* base; @@ -621,19 +643,19 @@ void gm_801B5ACC(GameModeState* arg0) data->rules.x14 = (s32) allstar->x9C % 60; data->rules.xD = 0x78; data->players[0].x10 = allstar->x74; - data->players[0].xD_b2 = 1; - data->rules.x7 = 9; - - round = gm_8017BE84(arg0->id); + gm_801B5ACC_inline0(data, arg0, &round); { AllstarRoundInfo* ri = &gm_803DEC4C[round]; + u8* slot_base = allstar->x76; for (i = 0; i < (s32) ri->count; i++) { + u8* slot_ptr; s32 slot; do { slot = HSD_Randi(0x1A); - } while ((s32) allstar->x76[slot] != 0x21); - allstar->x76[slot] = gm_803DEBE8[ri->start + i].x3; + slot_ptr = &slot_base[slot]; + } while ((s32) *slot_ptr != 0x21); + *slot_ptr = gm_803DEBE8[i + ri->start].x3; } } @@ -657,15 +679,7 @@ void gm_801B5ACC(GameModeState* arg0) gm_8016F088(data); gm_8016A92C(&data->rules); - { - s32 end_idx = (s32) gm_803DEC4C[round + 1].start; - gm_803DEBE8_t* opp = &gm_803DEBE8[end_idx]; - while (end_idx < 0x19) { - gm_8016A998((s8) opp->x3, 0); - opp++; - end_idx++; - } - } + gm_801B5ACC_inline1(&gm_803DEC4C[round]); gm_801B5324(allstar, round + 1); data->rules.x50 = (void (*)(u8))(Event) fn_801B5AA8; diff --git a/src/melee/gm/gmallstar.h b/src/melee/gm/gmallstar.h index 27cbe5a073..0c90ab5252 100644 --- a/src/melee/gm/gmallstar.h +++ b/src/melee/gm/gmallstar.h @@ -3,7 +3,7 @@ #include -/* 1B5324 */ void gm_801B5324(UnkAllstarData*, s32); +/* 1B5324 */ void gm_801B5324(UnkAllstarData*, u8); /* 1B5624 */ void gm_801B5624(GameModeState*); /* 1B59AC */ void gm_801B59AC(GameModeState*); /* 1B5AA8 */ void fn_801B5AA8(int); diff --git a/src/melee/gm/gmclassic.c b/src/melee/gm/gmclassic.c index 2100f13468..7481b8c93c 100644 --- a/src/melee/gm/gmclassic.c +++ b/src/melee/gm/gmclassic.c @@ -480,7 +480,7 @@ static inline void gmClassic_InitMatchupOrder(const gmClassicMatchup* matchups, s32 count; s32 i; - for (count = 0; matchups[count].x00 != 0x148; count++) { + for (count = 0; matchups->x00 != 0x148; matchups++, count++) { } for (i = 0; i < count; i++) { @@ -488,38 +488,44 @@ static inline void gmClassic_InitMatchupOrder(const gmClassicMatchup* matchups, } for (i = 0; i < count; i++) { - s32 swap_idx = HSD_Randi(count); - u8 tmp = order[i]; - order[i] = order[swap_idx]; - order[swap_idx] = tmp; + u8* swap = &order[HSD_Randi(count)]; + u8* cur = &order[i]; + u8 tmp = *cur; + *cur = *swap; + *swap = tmp; } } -static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, u8* arg1, +static inline s32 gmClassic_GetMatchupCount(const gmClassicMatchup* matchups) +{ + s32 count; + + for (count = 0; matchups[count].x00 != 0x148; count++) { + } + return count; +} + +static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, + const u8* arg1, gm_803DDEC8Struct* arg2) { - gmClassicMatchup* result; - gmClassicMatchup* entry; - gm_803DDEC8Struct* temp; - u8* order; s32 outer; - s8 target_char; - int cur_char; s32 j; + gmClassicMatchup* entry; + gmClassicMatchup* result; + s32 target_char; s32 k; - s32 count; - s32 stage1; + s32 temp_idx; result = NULL; target_char = gmMainLib_8015CDC8()->c_kind; - order = arg1; outer = 0; goto check; loop: - entry = &arg0[*order]; + entry = &arg0[arg1[outer]]; for (j = 0; j < 3; j++) { - cur_char = entry->x02[j]; + int cur_char = entry->x02[j]; if (cur_char == CHKIND_NONE) { continue; @@ -534,18 +540,21 @@ static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, u8* arg1, goto next; } - for (temp = arg2; temp->x0 != 0xD; temp++) { + for (temp_idx = 0; arg2[temp_idx].x0 != 0xD; temp_idx++) { for (k = 0; k < 3; k++) { - if (temp->xC != NULL && cur_char == temp->xC->x02[k]) { + if (arg2[temp_idx].xC != NULL && + cur_char == arg2[temp_idx].xC->x02[k]) + { goto next; } } } - for (temp = arg2; temp->x0 != 0xD; temp++) { - if (temp->xC != NULL) { - stage1 = Stage_8022519C(entry->x00); - if (Stage_8022519C(temp->xC->x00) == stage1) { + for (temp_idx = 0; arg2[temp_idx].x0 != 0xD; temp_idx++) { + if (arg2[temp_idx].xC != NULL) { + if (Stage_8022519C(arg2[temp_idx].xC->x00) == + Stage_8022519C(entry->x00)) + { result = entry; goto next; } @@ -557,13 +566,8 @@ static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, u8* arg1, } next: outer++; - order++; check: - count = 0; - while (arg0[count].x00 != 0x148) { - count++; - } - if (outer < count) { + if (outer < gmClassic_GetMatchupCount(arg0)) { goto loop; } @@ -675,8 +679,7 @@ void gm_Mode_Classic_OnLoad(void) (gmClassicSceneData*) gm_Mode_Classic_States; gmClassic_80490880Data* o = &gmClassic_80490880; gm_803DDEC8Struct* entry; - s32 i; - PAD_STACK(32); + PAD_STACK(56); for (entry = scene_data->matchups.x00; entry->x0 != 0x0D; entry++) { entry->xC = NULL; @@ -695,10 +698,11 @@ void gm_Mode_Classic_OnLoad(void) gmMainLib_8015CDC8(); gm_8017C984(data); - for (i = 0; i < 2; i++) { - s32 j; - for (j = 0; j < 6; j++) { - o->x20[i * 6 + j] = 0; + { + u8* p = o->x20; + 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 4fc80653e3..7c0213c446 100644 --- a/src/melee/gm/gmmain_lib.c +++ b/src/melee/gm/gmmain_lib.c @@ -736,6 +736,22 @@ void gmMainLib_8015DB80(void) } } +static inline void gmMainLib_AdjustNameTags(VsModeData* load_vmd, + VsModeData* store_vmd, u8 tag) +{ + u8* ptr; + s32 i; + + for (i = 0; i < 6; i++) { + ptr = &store_vmd->data.players[i].xA; + if (load_vmd->data.players[i].xA == tag) { + *ptr = 0x78; + } else if (*ptr > tag && *ptr != 0x78) { + *ptr -= 1; + } + } +} + s32 gmMainLib_8015DBF4(s32 arg0) { extern VsModeData gm_80497618; @@ -763,7 +779,6 @@ s32 gmMainLib_8015DBF4(s32 arg0) VsModeData unk_1490; }* base; GameRules* gr; - s32 j; u8 val; u8* ptr; @@ -777,40 +792,11 @@ s32 gmMainLib_8015DBF4(s32 arg0) } \ } while (0) -#define ADJ_NAMETAG_PAIR(field, store_field) \ - do { \ - ptr = &(store_field); \ - if ((field) == (u8) arg0) { \ - *ptr = 0x78; \ - } else if (*ptr > (u8) arg0 && *ptr != 0x78) { \ - *ptr -= 1; \ - } \ - } while (0) - -#define ADJ_VMD(load_vmd_expr, store_vmd_expr) \ - do { \ - VsModeData* store_vmd = (store_vmd_expr); \ - for (j = 0; j < 6; j++) { \ - ADJ_NAMETAG_PAIR((load_vmd_expr)->data.players[j].xA, \ - store_vmd->data.players[j].xA); \ - } \ - } while (0) - -#define ADJ_VMD_SINGLE(vmd_expr) \ - do { \ - VsModeData* vmd = (vmd_expr); \ - for (j = 0; j < 6; j++) { \ - ADJ_NAMETAG_PAIR(vmd->data.players[j].xA, \ - vmd->data.players[j].xA); \ - } \ - } while (0) - - config = &gmMainLib_804D3EE0->unk_51C; + config = gmMainLib_8015CDC8(); config_all = (struct gmMainLib_8015DBF4_config*) config; ptr = &config->x4; val = *ptr; - base = (struct gmMainLib_8015DBF4_base*) &gmMainLib_804D3EE0->unk_530 - .unk_588[0]; + 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) { @@ -821,22 +807,36 @@ s32 gmMainLib_8015DBF4(s32 arg0) ADJ_NAMETAG_78(config_all->unk_530.x4); ADJ_NAMETAG_78(gmMainLib_804D3EE0->unk_530.unk_584.unk_586); - ADJ_VMD_SINGLE(&gm_80497618); - - ADJ_VMD(&base->unk_1490, (VsModeData*) ((s8*) base + 0xF08)); - ADJ_VMD(&base->unk_D10, (VsModeData*) ((s8*) base + 0x788)); - ADJ_VMD(&base->unk_590, (VsModeData*) ((s8*) base + 8)); - ADJ_VMD(&base->unk_6D0, (VsModeData*) ((s8*) base + 0x148)); - ADJ_VMD(&base->unk_810, (VsModeData*) ((s8*) base + 0x288)); - ADJ_VMD(&base->unk_950, (VsModeData*) ((s8*) base + 0x3C8)); - ADJ_VMD(&base->unk_A90, (VsModeData*) ((s8*) base + 0x508)); - ADJ_VMD(&base->unk_BD0, (VsModeData*) ((s8*) base + 0x648)); - ADJ_VMD(&base->unk_E50, (VsModeData*) ((s8*) base + 0x8C8)); - ADJ_VMD(&base->unk_F90, (VsModeData*) ((s8*) base + 0xA08)); - ADJ_VMD(&base->unk_10D0, (VsModeData*) ((s8*) base + 0xB48)); - ADJ_VMD(&base->unk_1210, (VsModeData*) ((s8*) base + 0xC88)); - ADJ_VMD(&base->unk_1350, (VsModeData*) ((s8*) base + 0xDC8)); - ADJ_VMD(&base->unk_1490, (VsModeData*) ((s8*) base + 0xF08)); + gmMainLib_AdjustNameTags(&gm_80497618, &gm_80497618, (u8) arg0); + + gmMainLib_AdjustNameTags(&base->unk_1490, + (VsModeData*) ((s8*) base + 0xF08), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_D10, + (VsModeData*) ((s8*) base + 0x788), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_590, (VsModeData*) ((s8*) base + 8), + (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_6D0, + (VsModeData*) ((s8*) base + 0x148), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_810, + (VsModeData*) ((s8*) base + 0x288), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_950, + (VsModeData*) ((s8*) base + 0x3C8), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_A90, + (VsModeData*) ((s8*) base + 0x508), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_BD0, + (VsModeData*) ((s8*) base + 0x648), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_E50, + (VsModeData*) ((s8*) base + 0x8C8), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_F90, + (VsModeData*) ((s8*) base + 0xA08), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_10D0, + (VsModeData*) ((s8*) base + 0xB48), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_1210, + (VsModeData*) ((s8*) base + 0xC88), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_1350, + (VsModeData*) ((s8*) base + 0xDC8), (u8) arg0); + gmMainLib_AdjustNameTags(&base->unk_1490, + (VsModeData*) ((s8*) base + 0xF08), (u8) arg0); { gr = &gmMainLib_804D3EE0->x1850; @@ -864,31 +864,34 @@ s32 gmMainLib_8015DBF4(s32 arg0) } } -#undef ADJ_VMD -#undef ADJ_VMD_SINGLE -#undef ADJ_NAMETAG_PAIR #undef ADJ_NAMETAG_78 return arg0; } -void gmMainLib_8015EA80(void) +static inline void gmMainLib_SetHandicaps(s8* base) { s32 i; s32 j; - s8* base = gmMainLib_804D3EE0->unk_530.unk_588; - gmMainLib_8015CDEC(); for (i = 0; i < 6; i++) { for (j = 0; j < 6; j++) { base[0x78 + i * 0x140 + j * 0x24] = 9; } } - for (i = 7; i < 13; i++) { - for (j = 0; j < 6; j++) { - base[0x78 + i * 0x140 + j * 0x24] = 9; - } - } +} + +void gmMainLib_8015EA80(void) +{ + s8* volatile base_temp = gmMainLib_804D3EE0->unk_530.unk_588; + s8* base = base_temp; + s8* base2 = base + 7 * 0x140; + + PAD_STACK(0x90); + + gmMainLib_8015CDEC(); + gmMainLib_SetHandicaps(base); + gmMainLib_SetHandicaps(base2); } int gmMainLib_8015ECB0(void) diff --git a/src/melee/gm/gmregclear.c b/src/melee/gm/gmregclear.c index adab9f1ac7..d7156267a7 100644 --- a/src/melee/gm/gmregclear.c +++ b/src/melee/gm/gmregclear.c @@ -688,55 +688,30 @@ u8 gm_8017CD94(UnkAdventureData* arg0, int arg1, int arg2, int arg3) return 0; } -static inline s32 gm_8017CE34_CountEnemies(s8* arg0) +static inline s32 gm_8017CE34_CountEnemies(const s8* arg0) { s32 count = 0; - s32 result; + s32 i; - if ((s32) (u8) arg0[0] != CHKIND_NONE) { - count = 1; - } - { - s8* p = &arg0[1]; - if ((s32) *p != CHKIND_NONE) { - count += 1; - } - if ((s32) p[1] != CHKIND_NONE) { - result = count + 1; - } else { - result = count; + for (i = 0; i < 3; i++) { + if ((s32) arg0[i] != CHKIND_NONE) { + count++; } } - return result; + return count; } static inline void gm_8017CE34_SetupColors(UnkAdventureData* arg1, s32 count, s8* arg2, u8* colors) { - { - u8* out_color = colors; - s8* kind_iter = arg2; - s32 color_idx; - for (color_idx = 0; color_idx < 3; color_idx++) { - u8 kind = (u8) *kind_iter; - u8 num_colors = gm_80169238(kind); - u8 color_id; - if (arg1->x54 != NULL) { - u8 requested_color; - requested_color = - arg1->x54((u8) count, arg1->x0.cpu_level, (u8) color_idx); - if (num_colors != 0) { - color_id = requested_color % num_colors; - } else { - color_id = 0; - } - } else { - color_id = 0; - } - *out_color = color_id; - out_color += 1; - kind_iter += 1; - } + u8* out_color = colors; + s32 color_idx; + s8* kind_iter = arg2; + + for (color_idx = 0; color_idx < 3; color_idx++) { + *out_color = gm_8017CD94(arg1, (u8) *kind_iter, count, color_idx); + out_color++; + kind_iter++; } } @@ -753,6 +728,11 @@ static inline u8 gm_8017CE34_ResolvePlayerCKind(UnkAdventureData* arg1, return player_ckind; } +static inline u8 gm_8017CE34_GetCpuLevel(UnkAdventureData* arg1) +{ + return arg1->x0.cpu_level; +} + void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, u8 arg3, u8 arg4, u8 arg5, s32 arg6, StKind arg7, s32 count, s32 arg9) @@ -771,7 +751,6 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, u8 enemy_ckind; s32 enemy_count; s32 enemy_idx; - u8 sp8; u8* color_iter; boss_count = 0; @@ -864,7 +843,8 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, { u8 team_color; if (arg1->x58 != NULL) { - team_color = arg1->x58((u8) count, arg1->x0.cpu_level, 0); + team_color = + arg1->x58((u8) count, gm_8017CE34_GetCpuLevel(arg1), 0); } else { team_color = 0; } @@ -888,6 +868,7 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, s32 event_enemy_count; s32 special_stage; s32 special_enemy_mode; + u8 sp8; u8 first_enemy; u32 stage_flags; @@ -915,10 +896,7 @@ void gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, } } - { - GrKind grkind = Stage_8022519C(arg7); - stage_flags = Ground_801C5AD0(grkind); - } + stage_flags = Ground_801C5AD0(Stage_8022519C(arg7)); gm_8016A22C((s8) (u8) arg2[0], arg2[1], arg2[2], colors[0], colors[1], (s32) colors[2], special_stage, @@ -3359,13 +3337,18 @@ void fn_80181C80(s32 arg0) } } -static inline s32 fn_80181E18_ComputeRemaining100(s32 count) +static inline s32 fn_80181E18_ComputeRemaining100(const s32* x4, s32 count) { - return 0x64 - (count + lbl_80472ED8.x4); + return 0x64 - (count + *x4); } void fn_80181E18(void) { + lbl_80472ED8_t* data = &lbl_80472ED8; + s32* x4; + s32* field; + RegClearSpawnEntry* entry; + RegClearSpawnEntry* entries; s32 entry_idx; s32 next; s32 temp; @@ -3373,8 +3356,9 @@ void fn_80181E18(void) s32 i; s32 mode = gm_GetCurrentGameMode(); - if (lbl_80472ED8.x8 <= 0x5A) { - lbl_80472ED8.x8 += 1; + field = &data->x8; + if (data->x8 <= 0x5A) { + *field += 1; } switch (mode) { @@ -3385,7 +3369,7 @@ void fn_80181E18(void) case 0x23: case 0x24: if (gm_8016AEEC() == 0 && gm_8016AEFC() == 0x3B) { - lbl_80473594.x0 = 1; + data->record[0].x0 = 1; gm_8016B33C(7); gm_8016B328(); } @@ -3399,15 +3383,16 @@ void fn_80181E18(void) break; } - for (entry_idx = 0; entry_idx < 101; entry_idx++) { - if (lbl_80472ED8.x54[entry_idx].x0 == -2) { + entry = data->x54; + for (entry_idx = 0; entry_idx < 101; entry++, entry_idx++) { + if (entry->x0 == -2) { continue; } - switch (lbl_80473594.x8) { + switch (data->record[0].x8) { case 0x21: case 0x22: - lbl_80473594.x4 = gm_8016AEDC(); + data->record[0].x4 = gm_8016AEDC(); break; } @@ -3415,7 +3400,10 @@ void fn_80181E18(void) if (temp < 0) { temp = 0; } - lbl_80473594.x2 = (s16) (temp + lbl_80472ED8.x4); + field = &data->x4; + x4 = field; + next = *x4; + data->record[0].x2 = (s16) (temp + next); switch (mode) { case 0x21: @@ -3423,25 +3411,25 @@ void fn_80181E18(void) if (temp < 0) { temp = 0; } - ifStock_802FA2D0(0xA - (temp + lbl_80472ED8.x4)); + ifStock_802FA2D0(0xA - (temp + *x4)); break; case 0x22: temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } - ifStock_802FA2D0(fn_80181E18_ComputeRemaining100(temp)); + ifStock_802FA2D0(fn_80181E18_ComputeRemaining100(x4, temp)); break; default: temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } - ifStock_802FA2D0(temp + lbl_80472ED8.x4); + ifStock_802FA2D0(temp + *x4); break; } - next = lbl_80472ED8.x54[entry_idx].x0; + next = data->x54[entry_idx].x0; if (next == -1) { fn_80181C80(entry_idx); @@ -3458,26 +3446,27 @@ void fn_80181E18(void) } } if (count == 0) { - lbl_80473594.x0 = 1; + data->record[0].x0 = 1; gm_8016B33C(7); gm_8016B328(); } } else { s32 k; + entries = data->x54; for (k = next; k < entry_idx; k++) { - lbl_80472ED8.x54[k].x0 = -1; - lbl_80472ED8.x4 += 1; + entries[k].x0 = -1; + *x4 += 1; } - fn_80181C80(lbl_80472ED8.x54[entry_idx].x0); + fn_80181C80(data->x54[entry_idx].x0); temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } - ifStock_802FA2D0(temp + lbl_80472ED8.x4); + ifStock_802FA2D0(temp + *x4); } break; } - PAD_STACK(16); + PAD_STACK(8); } void gm_80182174(void) @@ -3674,9 +3663,9 @@ void gm_80182554(int arg0, int arg1) s->x6BE = 0; } -static inline u16 gm_80182578_GetTime(void) +static inline u16 gm_80182578_GetTimeFromData(RegClearRecordOverlay* data) { - return lbl_80472ED8.record[0].x2; + return data->record.x2; } static inline int gm_80182578_GetRecordTime(RecordBlock* blocks, int idx, @@ -3721,16 +3710,52 @@ static inline u32 gm_80182578_GetRecordScore(RecordBlock* blocks, int idx, } } -s32 gm_80182578(void) +static inline int gm_80182578_GetIndexFromPointer(const int* idx_ptr) +{ + return *idx_ptr; +} + +inline void gm_80182578_SetTime(RecordBlock* blocks, int idx, int mode, + u16 value) +{ + switch (mode) { + case 33: + blocks[0].times[idx] = value; + break; + case 34: + blocks[1].times[idx] = value; + break; + case 35: + blocks[2].times[idx] = value; + break; + case 36: + blocks[3].times[idx] = value; + break; + case 37: + blocks[4].times[idx] = value; + break; + case 38: + blocks[5].times[idx] = value; + break; + } +} + +void gm_80182578(void) { - RecordBlock* blocks = lbl_803D8D08; + RegClearRecordOverlay* data = (RegClearRecordOverlay*) &lbl_80472ED8; + int* idx_ptr; + int* mode_ptr; + RecordBlock* blocks; int time_val; int idx; s32 mode; u32 score_val; - mode = lbl_80472ED8.record[0].x8; - idx = lbl_80472ED8.record[0].xC; + mode_ptr = &data->record.x8; + idx_ptr = &data->record.xC; + blocks = lbl_803D8D08; + mode = data->record.x8; + idx = gm_80182578_GetIndexFromPointer(idx_ptr); time_val = gm_80182578_GetRecordTime(blocks, idx, mode); score_val = gm_80182578_GetRecordScore(blocks, idx, mode); @@ -3743,29 +3768,29 @@ s32 gm_80182578(void) } else { mode = gmMainLib_8015D710(gm_CKindToSelKind((u8) idx)); } - if (lbl_80472ED8.record[0].x0 != 0) { - u32 score_store = (u32) lbl_80472ED8.record[0].x4; + if (data->record.x0 != 0) { + u32 score_store = (u32) data->record.x4; if (score_store < score_val) { - int i = lbl_80472ED8.record[0].xC; - int m = lbl_80472ED8.record[0].x8; + int i = gm_80182578_GetIndexFromPointer(idx_ptr); + int m = *mode_ptr; switch (m) { case 33: - blocks[0].icons[i] = lbl_80472ED8.record[0].x0; + blocks[0].icons[i] = data->record.x0; break; case 34: - blocks[1].icons[i] = lbl_80472ED8.record[0].x0; + blocks[1].icons[i] = data->record.x0; break; case 35: - blocks[2].icons[i] = lbl_80472ED8.record[0].x0; + blocks[2].icons[i] = data->record.x0; break; case 36: - blocks[3].icons[i] = lbl_80472ED8.record[0].x0; + blocks[3].icons[i] = data->record.x0; break; case 37: - blocks[4].icons[i] = lbl_80472ED8.record[0].x0; + blocks[4].icons[i] = data->record.x0; break; case 38: - blocks[5].icons[i] = lbl_80472ED8.record[0].x0; + blocks[5].icons[i] = data->record.x0; break; } switch (m) { @@ -3788,80 +3813,56 @@ s32 gm_80182578(void) blocks[5].scores[i] = score_store; break; } - { - u16 time_store = lbl_80472ED8.record[0].x2; - switch (m) { - case 33: - blocks[0].times[i] = time_store; - break; - case 34: - blocks[1].times[i] = time_store; - break; - case 35: - blocks[2].times[i] = time_store; - break; - case 36: - blocks[3].times[i] = time_store; - break; - case 37: - blocks[4].times[i] = time_store; - break; - case 38: - blocks[5].times[i] = time_store; - break; - } - } + gm_80182578_SetTime(blocks, i, m, data->record.x2); } - return mode; - } - if ((s32) lbl_80472ED8.record[0].x2 > (s32) time_val && mode == 0) { - int i = lbl_80472ED8.record[0].xC; - int m = lbl_80472ED8.record[0].x8; + } else if ((s32) data->record.x2 > (s32) time_val && mode == 0) { + int i = *idx_ptr; + int m = *mode_ptr; switch (m) { case 33: - blocks[0].times[i] = lbl_80472ED8.record[0].x2; + blocks[0].times[i] = data->record.x2; break; case 34: - blocks[1].times[i] = lbl_80472ED8.record[0].x2; + blocks[1].times[i] = data->record.x2; break; case 35: - blocks[2].times[i] = lbl_80472ED8.record[0].x2; + blocks[2].times[i] = data->record.x2; break; case 36: - blocks[3].times[i] = lbl_80472ED8.record[0].x2; + blocks[3].times[i] = data->record.x2; break; case 37: - blocks[4].times[i] = lbl_80472ED8.record[0].x2; + blocks[4].times[i] = data->record.x2; break; case 38: - blocks[5].times[i] = lbl_80472ED8.record[0].x2; + blocks[5].times[i] = data->record.x2; break; } } break; case 0x23: case 0x24: - if (lbl_80472ED8.record[0].x0 != 0) { - u16 time_store = gm_80182578_GetTime(); + if (data->record.x0 != 0) { + u16 time_store = gm_80182578_GetTimeFromData(data); if ((s32) time_store > (s32) time_val) { switch (mode) { case 33: - blocks[0].icons[idx] = lbl_80472ED8.record[0].x0; + blocks[0].icons[idx] = data->record.x0; break; case 34: - blocks[1].icons[idx] = lbl_80472ED8.record[0].x0; + blocks[1].icons[idx] = data->record.x0; break; case 35: - blocks[2].icons[idx] = lbl_80472ED8.record[0].x0; + blocks[2].icons[idx] = data->record.x0; break; case 36: - blocks[3].icons[idx] = lbl_80472ED8.record[0].x0; + blocks[3].icons[idx] = data->record.x0; break; case 37: - blocks[4].icons[idx] = lbl_80472ED8.record[0].x0; + blocks[4].icons[idx] = data->record.x0; break; case 38: - blocks[5].icons[idx] = lbl_80472ED8.record[0].x0; + blocks[5].icons[idx] = data->record.x0; break; } switch (mode) { @@ -3889,33 +3890,32 @@ s32 gm_80182578(void) break; case 0x25: case 0x26: - if ((s32) lbl_80472ED8.record[0].x2 > (s32) time_val) { + if ((s32) data->record.x2 > (s32) time_val) { switch (mode) { case 33: - blocks[0].times[idx] = lbl_80472ED8.record[0].x2; + blocks[0].times[idx] = data->record.x2; break; case 34: - blocks[1].times[idx] = lbl_80472ED8.record[0].x2; + blocks[1].times[idx] = data->record.x2; break; case 35: - blocks[2].times[idx] = lbl_80472ED8.record[0].x2; + blocks[2].times[idx] = data->record.x2; break; case 36: - blocks[3].times[idx] = lbl_80472ED8.record[0].x2; + blocks[3].times[idx] = data->record.x2; break; case 37: - blocks[4].times[idx] = lbl_80472ED8.record[0].x2; + blocks[4].times[idx] = data->record.x2; break; case 38: - blocks[5].times[idx] = lbl_80472ED8.record[0].x2; + blocks[5].times[idx] = data->record.x2; break; } } break; } - return mode; - PAD_STACK(0x40); + PAD_STACK(0x38); } static inline RecordBlock* fn_80182B5C_GetRecordBlocks(void) diff --git a/src/melee/gm/gmregclear.h b/src/melee/gm/gmregclear.h index b1d6e87aff..2ee3c16cb8 100644 --- a/src/melee/gm/gmregclear.h +++ b/src/melee/gm/gmregclear.h @@ -118,7 +118,7 @@ /* 182174 */ UNK_RET gm_80182174(UNK_PARAMS); /* 182510 */ bool gm_IsMultimanSmashMode(void); /* 182554 */ void gm_80182554(int, int); -/* 182578 */ s32 gm_80182578(void); +/* 182578 */ void gm_80182578(void); /* 182B5C */ UNK_RET fn_80182B5C(UNK_PARAMS); /* 182DF0 */ UnkMultimanData* gm_80182DF0(int c_kind, int); /* 182F40 */ void fn_80182F40(HSD_GObj*); diff --git a/src/melee/gm/gmregtyfall.c b/src/melee/gm/gmregtyfall.c index f7b437ed25..38b79316eb 100644 --- a/src/melee/gm/gmregtyfall.c +++ b/src/melee/gm/gmregtyfall.c @@ -409,16 +409,20 @@ void gm_801A6EE4(void) } } -void gm_Scene_ToyFall_OnEnter(void* unused) +static inline void initImages(void) { - s32 trophy; int i; - HSD_JObj* player_jobj; - HSD_JObj* trophy_jobj; - HSD_JObj* main_jobj; - HSD_JObj* trophy_root; - f32 main_scale; + for (i = 0; i < 2; i++) { + gm_804809D0[i].image_ptr = NULL; + lb_800121FC(&gm_804809D0[i], 0x1EA, 0x1E0, 5, 0); + } +} + +static inline void setupTrophy(HSD_JObj* trophy_root) +{ + s32 trophy; + HSD_JObj* jobj; f32 translate_x; f32 translate_y; f32 translate_z; @@ -427,10 +431,41 @@ void gm_Scene_ToyFall_OnEnter(void* unused) f32 trophy_scale; f32 root_scale; - HSD_JObj* constraint_target; + 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); +} + +void gm_Scene_ToyFall_OnEnter(void* unused) +{ + HSD_JObj* player_jobj; + HSD_JObj* jobj; + HSD_JObj* main_jobj; + HSD_JObj* trophy_root; + + f32 main_scale; + HSD_GObj* gobj; HSD_LObj* lobj; - PAD_STACK(108); + PAD_STACK(68); gm_804D6740 = 0x1E; gm_804D6750 = 0x320; @@ -461,22 +496,27 @@ void gm_Scene_ToyFall_OnEnter(void* unused) /// with sobjs gm_801A6C54(); gm_801A6DC0(); - gobj = GObj_Create(0x13, 0x14, 0); - HSD_SObjLib_803A55DC(gobj, 0x280, 0x1E0, 0xC); - HSD_GObjGXLink_8039084C(gobj); - GObj_SetupGXLinkMax(gobj, fn_801A6A48, 0xC); - gobj->gxlink_prios = 0x40000; - gobj = GObj_Create(0x13, 0x14, 0); - HSD_SObjLib_803A55DC(gobj, 0x280, 0x1E0, 9); - HSD_GObjGXLink_8039084C(gobj); - GObj_SetupGXLinkMax(gobj, HSD_SObjLib_803A54EC, 9); - gobj->gxlink_prios = 0x200; - - for (i = 0; i < 2; i++) { - gm_804809D0[i].image_ptr = NULL; - lb_800121FC(&gm_804809D0[i], 0x1EA, 0x1E0, 5, 0); + { + HSD_GObj* gobj; + + gobj = GObj_Create(0x13, 0x14, 0); + HSD_SObjLib_803A55DC(gobj, 0x280, 0x1E0, 0xC); + HSD_GObjGXLink_8039084C(gobj); + GObj_SetupGXLinkMax(gobj, fn_801A6A48, 0xC); + gobj->gxlink_prios = 0x40000; + } + { + HSD_GObj* gobj; + + gobj = GObj_Create(0x13, 0x14, 0); + HSD_SObjLib_803A55DC(gobj, 0x280, 0x1E0, 9); + HSD_GObjGXLink_8039084C(gobj); + GObj_SetupGXLinkMax(gobj, HSD_SObjLib_803A54EC, 9); + gobj->gxlink_prios = 0x200; } + initImages(); + gobj = GObj_Create(0xE, 0xD, 0); gm_804D677C = gobj; HSD_GObjObject_80390A70(gobj, HSD_SObjLib_804D7960, NULL); @@ -517,35 +557,14 @@ void gm_Scene_ToyFall_OnEnter(void* unused) HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, trophy_root); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); - trophy = gm_801A659C(gm_801BEFB0()); - trophy_jobj = HSD_JObjGetChild(trophy_root); - translate_x = -Toy_803060BC(trophy, 0); - HSD_JObjSetTranslateXWithMtxDirty(trophy_jobj, translate_x); - translate_y = -Toy_803060BC(trophy, 1); - HSD_JObjSetTranslateYWithMtxDirty(trophy_jobj, translate_y); - translate_z = -Toy_803060BC(trophy, 2); - HSD_JObjSetTranslateZWithMtxDirty(trophy_jobj, translate_z); - - rotation_y = -(0.017453292f * Toy_803060BC(trophy, 5)); - HSD_JObjSetRotationYWithMtxDirty(trophy_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(trophy_jobj, trophy_scale); - HSD_JObjSetScaleYWithMtxDirty(trophy_jobj, trophy_scale); - HSD_JObjSetScaleZWithMtxDirty(trophy_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); + setupTrophy(trophy_root); HSD_GObj_SetupProc(gobj, fn_801A6844, 0x17); - constraint_target = gm_804D6768->hsd_obj; - constraint_target = - HSD_JObjGetNext(HSD_JObjGetChild(HSD_JObjGetChild(HSD_JObjGetChild( - HSD_JObjGetChild(HSD_JObjGetChild(constraint_target)))))); - lb_8000C1C0(gobj->hsd_obj, constraint_target); - lb_8000C290(gobj->hsd_obj, constraint_target); + 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); lbAudioAx_800237A8(0x7EF40, 0x7FU, 0x40U); } diff --git a/src/melee/gm/gmresult.c b/src/melee/gm/gmresult.c index 22d20c1619..e885d77518 100644 --- a/src/melee/gm/gmresult.c +++ b/src/melee/gm/gmresult.c @@ -12,11 +12,44 @@ static void order_sdata(void) (void) "GmRst"; (void) "pnlsce"; (void) "flmsce"; + (void) "%s"; } #endif struct ResultsData lbl_8046DBE8; static u32 lbl_804D3F8C[2] = { 0x817C817C, 0x817C0000 }; + +#ifdef MUST_MATCH +static void gmresult_sdata2_order(void) +{ + (void) "%d"; + (void) "%s%d"; + (void) 0.0f; + (void) -30.0f; + (void) 0.0500000007f; + (void) 0.0546875f; + (void) 0.0590000004f; + (void) 10.0f; + (void) 1.75f; + (void) 11.0f; + (void) S32_TO_F32; + (void) 12.0f; + (void) 300.0f; + (void) 100.0f; + (void) 0.899999976f; + (void) 255.0f; + (void) U32_TO_F32; + (void) 1.13999999f; + (void) 1.12f; + (void) 30.0f; + (void) 0.109999999f; + (void) 0.0799999982f; + (void) 0.0900000036f; + (void) 5.5f; + (void) 1.0f; +} +#endif + u32 lbl_804D3FA0 = 0x817C0000; u32 lbl_804D3FA4 = 0x817B0000; union { @@ -152,21 +185,37 @@ bool fn_801743C4(s32 slot, StatsEntry* entry) return true; } +static inline s32 gmResultFindNth(const u8* values, s32 n) +{ + s32 i; + + for (i = 0; i < 256; i++) { + if (values[i] != 0 && --n == 0) { + break; + } + } + return i; +} + +static inline s32 gmResultFormatLabel(s32 slot, StatsEntry* entry, f32 zero, + f32 neg30, HSD_Text* text) +{ + return HSD_SisLib_803A6B98(text, zero, neg30, "%s", entry->get(slot)); +} + void fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, StatsList* list, s32 entry_idx) { s32 value_id; - StatsEntry* entry; - s32 label_id; s32 result; + s32 label_id; + StatsEntry* entry; s32 idx; s32 stat_value; /* Variables for inlined unrolled loop */ s32 loop_i; s32 loop_n; - s32 loop_outer; u8* loop_ptr; - u8 loop_val; /* Float constants preloaded into registers */ f32 const_zero = 0.0F; f32 const_neg30 = -30.0F; @@ -183,7 +232,8 @@ void fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, } else { /// Mode 2: special handling for pairs if ((entry_idx & 1) == 1 && entry_idx < list->count) { - struct UnkResultPlayerData* tmp = lbl_8046DBE8.x94->x44C; + struct lbl_8046B6A0_24C_44C_t* tmp = + (struct lbl_8046B6A0_24C_44C_t*) lbl_8046DBE8.x94->x44C; loop_n = entry_idx / 2; loop_i = 0; loop_n++; @@ -194,13 +244,14 @@ void fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, } } idx = fn_8016F1F0(loop_i); - HSD_SisLib_803A6368(text1, (u16) fn_8016F280(idx) + 60); + idx = (u16) fn_8016F280(idx) + 60; + HSD_SisLib_803A6368(text1, idx); } } if (list->mode == 2 || entry->check != NULL) { if (list->mode != 2) { - result = ((s32 (*)(s32))(Event) entry->check)(slot); + result = entry->check(slot); if (result < 0) { value_id = HSD_SisLib_803A6B98(text3, const_zero, const_neg30, "%s", &lbl_804D3F8C); @@ -209,19 +260,12 @@ void fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, "%d", result); } } else if ((entry_idx & 1) == 0) { - idx = (entry_idx / 2) - 1; - if (idx >= 0) { - u8* base = lbl_8046DBE8.x94->x44C[0].x0; - s32 player_offset = - (u8) slot * sizeof(struct UnkResultPlayerData); - loop_n = idx + 1; - loop_ptr = base + player_offset; - for (loop_i = 0; loop_i < 256; loop_ptr++, loop_i++) { - if (*loop_ptr != 0 && --loop_n == 0) { - break; - } - } - stat_value = *(s32*) &base[player_offset + loop_i * 4 + 0x104]; + s32 pair_idx = (entry_idx / 2) - 1; + if (0 <= pair_idx) { + struct lbl_8046B6A0_24C_44C_t* tmp = + (struct lbl_8046B6A0_24C_44C_t*) lbl_8046DBE8.x94->x44C; + s32 i = gmResultFindNth(tmp[(u8) slot].x0, pair_idx + 1); + stat_value = tmp[(u8) slot].x104[i]; if (stat_value < 0) { value_id = HSD_SisLib_803A6B98(text3, const_zero, const_neg30, "%s%d", @@ -237,16 +281,14 @@ void fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, } if (list->mode != 2) { if (entry->get != NULL) { - label_id = HSD_SisLib_803A6B98( - text2, const_zero, const_neg30, "%s", - ((u8 * (*) (s32))(Event) entry->get)(slot)); + label_id = gmResultFormatLabel(slot, entry, const_zero, + const_neg30, text2); } } } else if (list->mode != 2) { if (entry->get != NULL) { - label_id = HSD_SisLib_803A6B98( - text2, const_zero, const_neg30, "%s", - ((u8 * (*) (s32))(Event) entry->get)(slot)); + label_id = HSD_SisLib_803A6B98(text2, const_zero, const_neg30, + "%s", entry->get(slot)); } } @@ -658,85 +700,116 @@ GXColor fn_8017507C(s32 slot) void fn_80175240(s32 slot) { - GXColor sp2C; - GXColor sp30; - GXColor sp28; - GXColor sp24; - GXColor sp20; - GXColor sp1C; - GXColor sp18; - HSD_Text** temp_r31; + GXColor color; + GXColor first_color; + GXColor second_color; + GXColor third_color; + GXColor empty_first_color; + GXColor empty_second_color; + GXColor empty_third_color; + GXColor* color_ptr; HSD_Text* ko_count; MatchEnd* me; - f32 temp_f31; - f32 temp_f30; - s32 temp_r3; - s32 var_r3; - s32 var_r5; - PAD_STACK(16); + f32 pos_x; + f32 pos_y; + f32 pos_z; + f32 first_row_offset; + f32 second_row_offset; + s32 line_id; + s32 first_value; + s32 value; + PAD_STACK(8); me = lbl_8046DBE8.x94; if (me->x5 != 3) { /// maybe x4C is an array of Vec2's - temp_f31 = 1.14f * (lbl_8046DBE8.x4C[4].y - lbl_8046DBE8.x4C[0].y); - temp_f30 = 1.12f * (lbl_8046DBE8.x4C[5].y - lbl_8046DBE8.x4C[4].y); - sp30 = fn_8017507C(slot); - ko_count = lbl_8046DBE8.player_data[slot].ko_count = - HSD_SisLib_803A6754(0, 0); - ko_count->pos_x = lbl_8046DBE8.x4C[slot].x; - ko_count->pos_y = -lbl_8046DBE8.x4C[slot].y - 30.0f; - ko_count->pos_z = lbl_8046DBE8.x4C[slot].z; + first_row_offset = + 1.14f * (lbl_8046DBE8.x4C[4].y - lbl_8046DBE8.x4C[0].y); + second_row_offset = + 1.12f * (lbl_8046DBE8.x4C[5].y - lbl_8046DBE8.x4C[4].y); + color = fn_8017507C(slot); + lbl_8046DBE8.player_data[slot].ko_count = HSD_SisLib_803A6754(0, 0); + pos_z = lbl_8046DBE8.x4C[slot].z; + ko_count = lbl_8046DBE8.player_data[slot].ko_count; + pos_y = -lbl_8046DBE8.x4C[slot].y - 30.0f; + pos_x = lbl_8046DBE8.x4C[slot].x; + ko_count->pos_x = pos_x; + ko_count->pos_y = pos_y; + ko_count->pos_z = pos_z; lbl_8046DBE8.player_data[slot].ko_count->default_alignment = 1; - temp_r31 = &lbl_8046DBE8.player_data[slot].ko_count; lbl_8046DBE8.player_data[slot].ko_count->default_kerning = 1; if (me->player_standings[slot].slot_type != Gm_PKind_NA) { - var_r3 = fn_8017AE0C(slot); - if (var_r3 > 0x3E7) { - var_r3 = 0x3E7; + first_value = fn_8017AE0C(slot); + if (first_value > 0x3E7) { + first_value = 0x3E7; } - temp_r3 = HSD_SisLib_803A6B98(*temp_r31, 0.0f, 0.0f, "%d", var_r3); - HSD_SisLib_803A7548(*temp_r31, temp_r3, 0.11f, 0.08f); - sp2C = sp30; - HSD_SisLib_803A74F0(*temp_r31, temp_r3, &sp2C); - var_r5 = fn_8017B010(slot); - if (var_r5 > 0x3E7) { - var_r5 = 0x3E7; + line_id = + HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_count, + 0.0f, 0.0f, "%d", first_value); + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_count, + line_id, 0.11f, 0.08f); + first_color = color; + color_ptr = &first_color; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_count, + line_id, color_ptr); + value = fn_8017B010(slot); + if (value > 0x3E7) { + value = 0x3E7; } - temp_r3 = - HSD_SisLib_803A6B98(*temp_r31, 0.0f, -temp_f31, "%d", var_r5); - HSD_SisLib_803A7548(*temp_r31, temp_r3, 0.11f, 0.08f); - sp28 = sp30; - HSD_SisLib_803A74F0(*temp_r31, temp_r3, &sp28); - var_r5 = fn_8017B21C(slot); - if (var_r5 > 0x3E7) { - var_r5 = 0x3E7; + line_id = + HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_count, + 0.0f, -first_row_offset, "%d", value); + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_count, + line_id, 0.11f, 0.08f); + second_color = color; + color_ptr = &second_color; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_count, + line_id, color_ptr); + value = fn_8017B21C(slot); + if (value > 0x3E7) { + value = 0x3E7; } - temp_r3 = HSD_SisLib_803A6B98(*temp_r31, 0.0f, - -temp_f31 - temp_f30, "%d", var_r5); - HSD_SisLib_803A7548(*temp_r31, temp_r3, 0.11f, 0.08f); - sp24 = sp30; - HSD_SisLib_803A74F0(*temp_r31, temp_r3, &sp24); + line_id = HSD_SisLib_803A6B98( + lbl_8046DBE8.player_data[slot].ko_count, 0.0f, + -first_row_offset - second_row_offset, "%d", value); + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_count, + line_id, 0.11f, 0.08f); + third_color = color; + color_ptr = &third_color; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_count, + line_id, color_ptr); return; } - sp30.r = 0xA0; - sp30.g = 0xA0; - sp30.b = 0xA0; - temp_r3 = - HSD_SisLib_803A6B98(*temp_r31, 0.0f, 0.0f, "%s", &lbl_804D3FA0); - HSD_SisLib_803A7548(*temp_r31, temp_r3, 0.11f, 0.08f); - sp20 = sp30; - HSD_SisLib_803A74F0(*temp_r31, temp_r3, &sp20); - temp_r3 = HSD_SisLib_803A6B98(*temp_r31, 0.0f, -temp_f31, "%s", - &lbl_804D3FA0); - HSD_SisLib_803A7548(*temp_r31, temp_r3, 0.11f, 0.08f); - sp1C = sp30; - HSD_SisLib_803A74F0(*temp_r31, temp_r3, &sp1C); - temp_r3 = HSD_SisLib_803A6B98(*temp_r31, 0.0f, -temp_f31 - temp_f30, - "%s", &lbl_804D3FA0); - HSD_SisLib_803A7548(*temp_r31, temp_r3, 0.11f, 0.08f); - sp18 = sp30; - HSD_SisLib_803A74F0(*temp_r31, temp_r3, &sp18); + color.r = 0xA0; + color.g = 0xA0; + color.b = 0xA0; + line_id = HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_count, + 0.0f, 0.0f, "%s", &lbl_804D3FA0); + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_count, line_id, + 0.11f, 0.08f); + empty_first_color = color; + color_ptr = &empty_first_color; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_count, line_id, + color_ptr); + line_id = + HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_count, 0.0f, + -first_row_offset, "%s", &lbl_804D3FA0); + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_count, line_id, + 0.11f, 0.08f); + empty_second_color = color; + color_ptr = &empty_second_color; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_count, line_id, + color_ptr); + line_id = HSD_SisLib_803A6B98( + lbl_8046DBE8.player_data[slot].ko_count, 0.0f, + -first_row_offset - second_row_offset, "%s", &lbl_804D3FA0); + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_count, line_id, + 0.11f, 0.08f); + empty_third_color = color; + color_ptr = &empty_third_color; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_count, line_id, + color_ptr); } } diff --git a/src/melee/gm/gmresultplayer.c b/src/melee/gm/gmresultplayer.c index 31881f061b..831fefbf41 100644 --- a/src/melee/gm/gmresultplayer.c +++ b/src/melee/gm/gmresultplayer.c @@ -122,7 +122,7 @@ typedef struct { /* 0x22C4 */ u32 dim_h1[2]; /* 0x22CC */ u32 dim_h2[2]; /* 0x22D4 */ PackedS16x4 score_tbl[4]; - /* 0x22F4 */ u32 x22F4[4][2]; + /* 0x22F4 */ PackedS16x4 x22F4[4]; } lbl_8046E3AC_t; typedef struct ResultsDisplayData { @@ -1123,12 +1123,6 @@ void fn_80179854(void) extern s32 ftLib_800876B4(HSD_GObj*); -static inline HSD_ImageDesc* get_player_img2(int slot, - ResultsDisplayLayout* disp) -{ - return &disp->player_img2[slot]; -} - static inline int get_big_loser(int slot, MatchEnd* match_end) { return match_end->player_standings[slot].is_big_loser; @@ -1143,10 +1137,11 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) { ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; MatchEnd* match_end = &disp->state.match_end; - HSD_JObj* child_jobj; - HSD_CObj* cobj; int lookup; - PAD_STACK(16); + HSD_ImageDesc* desc; + HSD_CObj* cobj; + HSD_JObj* child_jobj; + PAD_STACK(8); fn_801795D4(); fn_801796F0(arg2); @@ -1160,11 +1155,8 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) match_end->team_standings[match_end->player_standings[arg2].team] .is_big_loser; } - cobj = (HSD_CObj*) arg0->hsd_obj; - if (lookup != 0) { - HSD_JObj* root = (HSD_JObj*) disp->gobjs[arg2]->hsd_obj; - child_jobj = root == NULL ? NULL : root->child; + child_jobj = HSD_JObjGetChild((HSD_JObj*) disp->gobjs[arg2]->hsd_obj); } if (HSD_CObjSetCurrent(cobj)) { @@ -1181,7 +1173,7 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) { HSD_ImageDesc* image_desc = disp->player_img2; - HSD_ImageDesc* desc = &image_desc[arg2]; + desc = &image_desc[arg2]; HSD_ImageDescCopyFromEFB( desc, @@ -1223,7 +1215,8 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) } else { HSD_GObj* entity = Player_GetEntity(arg2); if (ftLib_800876B4(entity) == 0) { - if (disp->state.player_flags[arg2] == 0 && disp->state.x0_6) { + u8* player_flags = disp->state.player_flags; + if (player_flags[arg2] == 0 && disp->state.x0_6) { GXColor color; color = gm_80160968(gm_80160854( @@ -1235,7 +1228,8 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) Camera_800313E0(arg0, 0); { - HSD_ImageDesc* desc = get_player_img2(arg2, disp); + HSD_ImageDesc* image_desc = disp->player_img2; + desc = &image_desc[arg2]; HSD_ImageDescCopyFromEFB( desc, @@ -1256,7 +1250,7 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) 0x7C, 1, 0); HSD_CObjEndCurrent(); - disp->state.player_flags[arg2] = 1; + player_flags[arg2] = 1; { HSD_JObj* jobj2 = get_result_jobjs(disp)[arg2]; jobj2->u.dobj->next->mobj->tobj->imagedesc = desc; @@ -1664,20 +1658,33 @@ fn_8017AA78_get_team_standings(ResultsDisplayLayout* disp) return disp->state.match_end.team_standings; } -static inline PackedS16x4* fn_8017AA78_get_score_entry(int i, - lbl_8046E3AC_t* state) +static inline int inline2(int unused) +{ + ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; + + Player_InitAllPlayers(); + disp->shared_img.image_ptr = NULL; + lb_800121FC(&disp->shared_img, 0x64, 0x98, GX_TF_RGB5A3, 0); + disp->state.match_end = *fn_80174274(); + return unused; +} + +static inline u32* inline3(lbl_8046E3AC_t* state) { - return &state->score_tbl[i]; + return state->dim_h1; +} + +static inline int inline4(ResultsDisplayLayout* disp) +{ + return disp->state.match_end.result; } void fn_8017AA78(const u8* arg0) { ResultsDisplayLayout* disp = (ResultsDisplayLayout*) &lbl_8046E1B0; - u32* p5; - u32* p7; + PackedS16x4* p5; + PackedS16x4* p7; lbl_8046E3AC_t* state; - MatchEnd* end; - struct MatchPlayerData* player_standings; memzero(disp->pad_000, sizeof(disp->pad_000)); lbBgFlash_800208EC(6); @@ -1692,34 +1699,33 @@ void fn_8017AA78(const u8* arg0) efLib_Init(); efAsync_LoadSync(0); ftDemo_ObjAllocInit(); - Player_InitAllPlayers(); - - disp->shared_img.image_ptr = NULL; - lb_800121FC(&disp->shared_img, 0x64, 0x98, GX_TF_RGB5A3, 0); - - disp->state.match_end = *fn_80174274(); + inline2(0); disp->state.x0_0 = 1; disp->state.x0_4 = 0; disp->state.x0_6 = 0; - p5 = lbl_803D7038; + p5 = (PackedS16x4*) lbl_803D7038; state = &disp->state; - end = &state->match_end; - player_standings = end->player_standings; - p7 = lbl_803D7018; + p7 = (PackedS16x4*) lbl_803D7018; { - lbl_8046E3AC_t* state = &disp->state; s32 a; s32 b; a = lbl_804D3FD0; + (void) a; b = lbl_804D3FD4; + (void) b; state->dim_w1[0] = a; state->dim_w1[1] = b; - a = lbl_804D3FD8; - b = lbl_804D3FDC; - state->dim_h1[0] = a; - state->dim_h1[1] = b; + { + u32* dim_h1 = inline3(state); + a = lbl_804D3FD8; + (void) a; + b = lbl_804D3FDC; + (void) b; + dim_h1[0] = a; + dim_h1[1] = b; + } a = lbl_804D3FE0; b = lbl_804D3FE4; state->dim_w2[0] = a; @@ -1740,20 +1746,19 @@ void fn_8017AA78(const u8* arg0) { int i; - struct MatchTeamData* team_standings; for (i = 0; i < 4; i++) { state->player_flags[i] = 0; state->costume_override[i] = arg0[i]; - if (disp->state.match_end.result == OUTCOME_NO_CONTEST) { - player_standings[i].is_big_loser = 1; + if ((u8) inline4(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); - team_standings[player_standings[i].team].is_big_loser = 1; + team_standings[state->match_end.player_standings[i].team] + .is_big_loser = 1; } state->x6[i] = 0; - fn_8017AA78_get_score_entry(i, state)->w[0] = p5[0 + i * 2]; - state->score_tbl[i].w[1] = p5[1 + i * 2]; - state->x22F4[i][0] = p7[i * 2]; - state->x22F4[i][1] = p7[1 + i * 2]; + state->score_tbl[i] = p5[i]; + state->x22F4[i] = p7[i]; } } } diff --git a/src/melee/gm/gmstaffroll.c b/src/melee/gm/gmstaffroll.c index 8df99a4aa8..0d7ea88270 100644 --- a/src/melee/gm/gmstaffroll.c +++ b/src/melee/gm/gmstaffroll.c @@ -516,7 +516,6 @@ void fn_801AAB18(HSD_GObj* gobj) void fn_801AAB74(HSD_GObj* gobj) { HSD_JObj* jobj = GET_JOBJ(gobj); - StaffEntryData* entry_data; int name_page_jp; int name_page_en; int title_page; @@ -538,7 +537,6 @@ void fn_801AAB74(HSD_GObj* gobj) entry_idx = staff_idx = 0; child = jobj->child; gm_804D6800 = 0; - entry_data = gm_803DBFD8; { int temp = entry_idx * 15; name_page_jp = temp + 3; @@ -551,8 +549,9 @@ void fn_801AAB74(HSD_GObj* gobj) if (!(HSD_JObjGetFlags(leaf) & 0x10) && staffInfo[staff_idx].win[0] == NULL && - (entry_data->has_check == 0 || - entry_data->check(entry_data->check_arg) != 0 || + (gm_803DBFD8[staff_idx].has_check == 0 || + gm_803DBFD8[staff_idx].check(gm_803DBFD8[staff_idx].check_arg) != + 0 || entry_idx == 0xC5) && (entry_idx != 0x5E || lbLang_IsSavedLanguageJP() != 0)) { @@ -574,15 +573,16 @@ void fn_801AAB74(HSD_GObj* gobj) text->font_size.y = 0.209f; } - if (entry_data->has_check != 0 && - entry_data->check(entry_data->check_arg) == 0) + if (gm_803DBFD8[staff_idx].has_check != 0 && + gm_803DBFD8[staff_idx].check( + gm_803DBFD8[staff_idx].check_arg) == 0) { if (lbLang_IsSavedLanguageJP() != 0) { HSD_SisLib_803A6368(staffInfo[staff_idx].win[0], - entry_data->alt_page); + gm_803DBFD8[staff_idx].alt_page); } else { HSD_SisLib_803A6368(staffInfo[staff_idx].win[0], - entry_data->alt_page + 1); + gm_803DBFD8[staff_idx].alt_page + 1); } } else if ((entry_idx != 0xB7 && entry_idx != 0xC1 && entry_idx != 0xC3 && @@ -607,8 +607,9 @@ void fn_801AAB74(HSD_GObj* gobj) text->font_size.y = 0.1f; } - if (entry_data->has_check == 0 || - entry_data->check(entry_data->check_arg) != 0) + if (gm_803DBFD8[staff_idx].has_check == 0 || + gm_803DBFD8[staff_idx].check( + gm_803DBFD8[staff_idx].check_arg) != 0) { HSD_SisLib_803A6368(staffInfo[staff_idx].win[1], title_page); } @@ -627,8 +628,9 @@ void fn_801AAB74(HSD_GObj* gobj) } if (!(HSD_JObjGetFlags(leaf) & 0x10) && - (entry_data->has_check == 0 || - entry_data->check(entry_data->check_arg) != 0 || + (gm_803DBFD8[staff_idx].has_check == 0 || + gm_803DBFD8[staff_idx].check(gm_803DBFD8[staff_idx].check_arg) != + 0 || entry_idx == 0xC5) && (entry_idx != 0x5E || lbLang_IsSavedLanguageJP() != 0)) { @@ -640,7 +642,6 @@ void fn_801AAB74(HSD_GObj* gobj) child = child->next; staff_idx++; - entry_data++; name_page_jp += 15; name_page_en += 15; title_page += 15; diff --git a/src/melee/gm/gmtou_1.c b/src/melee/gm/gmtou_1.c index b531c86a08..002736102e 100644 --- a/src/melee/gm/gmtou_1.c +++ b/src/melee/gm/gmtou_1.c @@ -1589,24 +1589,31 @@ void fn_80199AF0(void) } } +static inline BracketEntry* fn_8019A158_GetBracketEntry(s32 bracket_idx) +{ + return &lbl_80473AB8[bracket_idx]; +} + /// @todo All instructions match; only the callee-saved register assignment /// is permuted against the target. void fn_8019A158(void) { TmData* td1; TmData* td2; + BracketEntry* bracket; s32 mode; - s32 slot; s32 sel; s32 bracket_idx; s32 result; s32 counter; s32 i; int k; - UNUSED u8 unused[8]; - s32 local1, local2; MatchEnd* me; + struct { + s32 slot; + } state; u8* cursor; + s32 local1, local2; PAD_STACK(4); td1 = gm_GetTournamentData(); @@ -1623,22 +1630,23 @@ void fn_8019A158(void) } me = lbl_804799D8.x48; + (void) me; result = fn_8018F508(&local2); if (result == 1) { - slot = local2; + state.slot = local2; } else { for (i = 0; i < 4; i++) { if (me->player_standings[i].slot_type != 3 && me->player_standings[i].is_small_loser == 0) { - slot = i; + state.slot = i; goto found; } } - slot = -1; + state.slot = -1; found:; } - sel = slot; + sel = state.slot; bracket_idx = fn_8018F74C(); @@ -1647,18 +1655,18 @@ void fn_8019A158(void) } if (mode == 1) { - BracketEntry* bracket = &lbl_80473AB8[bracket_idx]; + bracket = fn_8019A158_GetBracketEntry(bracket_idx); cursor = (u8*) bracket; for (i = 0; i < 4; i++) { - if (i == slot) { - bracket->slots[slot].x4C = 0; + if (i == state.slot) { + bracket->slots[state.slot].x4C = 0; } else { cursor[0x4C] = 3; } cursor += 0x2C; } } else if (td1->x2D == 1) { - BracketEntry* bracket = &lbl_80473AB8[bracket_idx]; + bracket = fn_8019A158_GetBracketEntry(bracket_idx); cursor = (u8*) bracket; for (i = 0; i < 4; i++) { if (cursor[0x4E] == 3) { @@ -1679,7 +1687,7 @@ void fn_8019A158(void) cursor += 0x2C; } } else { - BracketEntry* bracket = &lbl_80473AB8[bracket_idx]; + bracket = fn_8019A158_GetBracketEntry(bracket_idx); counter = 0; cursor = (u8*) bracket; for (i = 0; i < 4; i++) { diff --git a/src/melee/gm/gmtou_2.c b/src/melee/gm/gmtou_2.c index f607bbd957..00e4282136 100644 --- a/src/melee/gm/gmtou_2.c +++ b/src/melee/gm/gmtou_2.c @@ -3,7 +3,6 @@ #include "gm_1601.h" #include "gm_1A3F.h" #include "gm_1A45.h" -#include "gm_unsplit.h" #include "gmmain_lib.h" #include "gmtoulib.h" #include "types.h" @@ -560,12 +559,15 @@ void fn_8019D1BC(void) for (i = 0; i < (s32) tmd->x30; i++) { { - HSD_GObj* first_gobj = - fn_8019035C(0, lbl_804D6694->models[12], 0, 0x1A, 2, 1, - fn_8019C048, (f32) i); - HSD_JObj* first_jobj = GET_JOBJ(first_gobj); - (void) first_jobj; - HSD_JObjSetTranslateY(GET_JOBJ(first_gobj), -2.5f); + HSD_GObj* first_gobj; + HSD_JObj* first_c; + HSD_JObj* first_jobj; + + first_gobj = fn_8019035C(0, lbl_804D6694->models[12], 0, 0x1A, 2, + 1, fn_8019C048, (f32) i); + first_jobj = GET_JOBJ(first_gobj); + first_c = first_gobj->hsd_obj; + HSD_JObjSetTranslateY(first_c, -2.5f); fn_8018FBD8(first_gobj, i); c = HSD_JObjGetChild(first_jobj); @@ -706,7 +708,7 @@ void fn_8019D1BC(void) tmd->x534[i]->default_alignment = 1; HSD_SisLib_803A6B98(tmd->x534[i], 10.0f * ((5.999997f * (f32) i) - 21.5f), -172.0f, - name_buf[i], tmd->x534[i]->default_alignment); + name_buf[i]); HSD_SisLib_803A7548(tmd->x534[i], 0, 0.35f, 0.6f); } } @@ -879,7 +881,7 @@ void gm_Scene_TouAlt_OnFrame(void) chr = fn_8018F6DC(0x19); } } while (gm_IsCKindUnlocked( - fn_8018F6FC((CSSIconHud) chr)) == 0); + (u8) fn_8018F6FC((CSSIconHud) chr)) == 0); tmd->x4B8[i].x1 = chr; j = get_match_player_index(i); @@ -906,7 +908,7 @@ void gm_Scene_TouAlt_OnFrame(void) chr = fn_8018F6DC(0); } } while (gm_IsCKindUnlocked( - fn_8018F6FC((CSSIconHud) chr)) == 0); + (u8) fn_8018F6FC((CSSIconHud) chr)) == 0); tmd->x4B8[i].x1 = chr; j = get_match_player_index(i); @@ -942,7 +944,7 @@ void gm_Scene_TouAlt_OnFrame(void) if (buttons & PAD_BUTTON_X) { /* Down: increment color */ if ((s32) tmd->x4B8[i].x3 < - (s32) (gm_80169238(fn_8018F6FC( + (s32) (gm_80169238((u8) fn_8018F6FC( (CSSIconHud) tmd->x4B8[i].x1)) - 1)) { @@ -998,44 +1000,34 @@ void gm_8019ECAC_OnEnter_inline(void) void gm_8019E634(void) { - s32 indices[4]; + struct Indices { + s32 values[4]; + } indices; s32 results[4]; TmData* tmd; s32 hmn_cpu; s32 i, j; - MatchEnd* match_end; - s32* results_base; tmd = gm_GetTournamentData(); hmn_cpu = tmd->hmn_cpu_count; - indices[0] = lbl_803B7D3C[0]; - indices[1] = lbl_803B7D3C[1]; - indices[2] = lbl_803B7D3C[2]; - indices[3] = lbl_803B7D3C[3]; + indices = *(struct Indices*) lbl_803B7D3C; /* Get match results per player */ - match_end = &gm_80477738; - results_base = results; - { - s32* result_ptr; - for (result_ptr = results_base, i = 0; i < (s32) tmd->x30; - result_ptr++, i++) - { - *result_ptr = fn_80166CBC(match_end, i); - } + for (i = 0; i < (s32) tmd->x30; i++) { + results[i] = fn_80166CBC(&gm_80477738, i); } /* Bubble sort results, keeping indices in parallel */ for (i = 0; i < (s32) (tmd->x30 - 1); i++) { for (j = 0; j < (s32) ((tmd->x30 - 1) - i); j++) { - if (results_base[j] > results_base[j + 1]) { - s32 tr = results_base[j]; - s32 ti = indices[j]; - results_base[j] = results_base[j + 1]; - indices[j] = indices[j + 1]; - results_base[j + 1] = tr; - indices[j + 1] = ti; + if (results[j] > results[j + 1]) { + s32 tr = results[j]; + s32 ti = indices.values[j]; + results[j] = results[j + 1]; + indices.values[j] = indices.values[j + 1]; + results[j + 1] = tr; + indices.values[j + 1] = ti; } } } @@ -1052,8 +1044,7 @@ void gm_8019E634(void) /* Read handicap from x37 entries */ for (i = 0; i < 4; i++) { if (i < (s32) tmd->x30) { - s32 id = results_base[i]; - j = get_match_player_index_xF(id); + j = get_match_player_index_xF(results[i]); hbuf.bytes[i] = tmd->x37[j].x2; } } @@ -1063,7 +1054,7 @@ void gm_8019E634(void) /* Write back adjusted handicap */ for (i = 0; i < 4; i++) { if (i < (s32) tmd->x30) { - s32 id = results_base[i]; + s32 id = results[i]; j = get_match_player_index_xF(id); tmd->x37[j].x2 = hbuf.bytes[i]; } @@ -1074,7 +1065,7 @@ void gm_8019E634(void) if ((s32) gm_804771C4.match_type == 1) { /* Team mode */ for (i = 0; i < hmn_cpu; i++) { - s32 id = indices[i]; + s32 id = indices.values[i]; j = get_match_player_index_xF(id); tmd->x37[j].xE = (tmd->x2E - 1) - i; @@ -1083,18 +1074,18 @@ void gm_8019E634(void) id = next_id; } j = get_match_player_index_xF(id); - tmd->x37[j].xE = indices[i]; + tmd->x37[j].xE = indices.values[i]; } } else { /* FFA mode */ for (i = 0; i < hmn_cpu; i++) { - s32 id = indices[(tmd->x30 - 1) - i]; + s32 id = indices.values[(tmd->x30 - 1) - i]; j = get_match_player_index_xF(id); tmd->x37[j].xE = (tmd->x2E - 1) - i; id = tmd->x30 + i; j = get_match_player_index_xF(id); - tmd->x37[j].xE = indices[(tmd->x30 - 1) - i]; + tmd->x37[j].xE = indices.values[(tmd->x30 - 1) - i]; } } diff --git a/src/melee/gm/gmtoulib.c b/src/melee/gm/gmtoulib.c index 45c81d9c21..8304f3eef5 100644 --- a/src/melee/gm/gmtoulib.c +++ b/src/melee/gm/gmtoulib.c @@ -119,13 +119,7 @@ void fn_8018A514(int count, float val) int i; s32 n; - if (count < 9) { - region = 0; - } else if (count >= 14) { - region = 2; - } else { - region = 1; - } + region = count < 9 ? 0 : count >= 14 ? 2 : 1; srcs = (BracketSrcPtr*) ((BracketData*) lbl_80473AB8)->srcs; src = srcs[region].ptr; @@ -144,7 +138,7 @@ void fn_8018A514(int count, float val) } } - n = lbl_803D9D20.x20[i]; + n = lbl_803D9D20.x20[count]; entries = lbl_80473AB8; for (i = 0; i < n; i++) { @@ -472,8 +466,32 @@ static inline f32 gmTournament_GetBracketSlideYReverse(BracketEntrySlot* slot) return -((f32) slot->x48 - 0.3f * (f32) lbl_804D6630); } +static inline HSD_JObj* fn_8018B090_inline0(BracketEntry* bracket_entries, + s32 bracket_slot_index, + s32 bracket_entry_index) +{ + return bracket_entries[bracket_entry_index] + .slots[bracket_slot_index] + .x2C->hsd_obj; +} + +static inline HSD_JObj* fn_8018B090_inline1(BracketEntry* bracket_entries, + s32 bracket_entry_index) +{ + return bracket_entries[bracket_entry_index] + .slots[lbl_804D6634] + .x2C->hsd_obj; +} + +static inline BracketEntry* fn_8018B090_inline2(BracketEntry* bracket_entries, + s32 bracket_entry_index) +{ + return &bracket_entries[bracket_entry_index]; +} + void fn_8018B090(HSD_GObj* arg0) { + BracketEntry* entries = lbl_80473AB8; TmData* tm = gm_GetTournamentData(); s32 var_r24 = 0; s32 idx = fn_8018F74C(); @@ -484,30 +502,30 @@ void fn_8018B090(HSD_GObj* arg0) lbl_804D6630 = 0; return; case 21: - if (lbl_80473AB8[idx].x18 != 0) { + if (entries[idx].x18 != 0) { for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x30 != 0) { + if (entries[idx].slots[i].x30 != 0) { HSD_JObj* jobj; HSD_JObj* jobj2; - jobj = lbl_80473AB8[idx].slots[i].x2C->hsd_obj; + jobj = fn_8018B090_inline0(entries, i, idx); jobj2 = jobj; - if (lbl_80473AB8[idx].x2 != 0) { + if (entries[idx].x2 != 0) { HSD_JObjSetTranslateY( jobj2, gmTournament_GetBracketSlideYReverse( - &lbl_80473AB8[idx].slots[i])); + &entries[idx].slots[i])); } else { - switch (lbl_80473AB8[idx].x4) { + switch (entries[idx].x4) { case 1: if (i == 0) { HSD_JObjSetTranslateY( jobj2, gmTournament_GetBracketSlideYForward( - &lbl_80473AB8[idx].slots[i])); + &entries[idx].slots[i])); } else { HSD_JObjSetTranslateY( jobj2, gmTournament_GetBracketSlideYReverse( - &lbl_80473AB8[idx].slots[i])); + &entries[idx].slots[i])); } break; case 2: @@ -516,18 +534,18 @@ void fn_8018B090(HSD_GObj* arg0) HSD_JObjSetTranslateY( jobj2, gmTournament_GetBracketSlideYForward( - &lbl_80473AB8[idx].slots[i])); + &entries[idx].slots[i])); } else { HSD_JObjSetTranslateY( jobj2, gmTournament_GetBracketSlideYReverse( - &lbl_80473AB8[idx].slots[i])); + &entries[idx].slots[i])); } break; default: HSD_JObjSetTranslateY( jobj2, gmTournament_GetBracketSlideYForward( - &lbl_80473AB8[idx].slots[i])); + &entries[idx].slots[i])); break; } } @@ -537,21 +555,18 @@ void fn_8018B090(HSD_GObj* arg0) lbl_804D6630 += 1; return; case 22: { - s32 h = lbl_80473AB8[idx].x18; - if (h != 0) { + BracketEntry* entry = &entries[idx]; + s32 h = entry->x18; + if (h) { f32 d; lbl_803D9DAC.current.x = 320.0f; lbl_803D9DAC.current.y = -240.0f; lbl_803D9DAC.current.z = 0.0f; - lbl_803D9DAC.target.x = - (f32) (lbl_80473AB8[idx].xC + (lbl_80473AB8[idx].x14 / 2)); - lbl_803D9DAC.target.y = -(f32) (lbl_80473AB8[idx].x10 + (h / 2)); + lbl_803D9DAC.target.x = (f32) (entry->xC + (entry->x14 / 2)); + lbl_803D9DAC.target.y = -(f32) (entry->x10 + (h / 2)); lbl_803D9DAC.target.z = -150.0f; - d = lbl_803D9DAC.target.x - lbl_803D9DAC.current.x; - d = 0.033333f * d; - if (d < 0.0f) { - d = -d; - } + d = ABS((lbl_803D9DAC.target.x - lbl_803D9DAC.current.x) * + 0.033333f); lbl_803D9DAC.step.x = 1.0f + d; d = 0.033333f * (lbl_803D9DAC.target.y - lbl_803D9DAC.current.y); if (d < 0.0f) { @@ -568,7 +583,7 @@ void fn_8018B090(HSD_GObj* arg0) lbl_804D6630 = 0; /* fallthrough */ case 23: - if (lbl_80473AB8[idx].x18 != 0) { + if (entries[idx].x18 != 0) { s32 amount = lbl_804D6630 / 6; lbl_804D6630 += 1; if (mn_8022F410(&lbl_803D9DAC.current.x, &lbl_803D9DAC.target.x, @@ -600,53 +615,53 @@ void fn_8018B090(HSD_GObj* arg0) } fn_80190520(lbl_803D9DAC.current.x, lbl_803D9DAC.current.y, lbl_803D9DAC.current.z); - if (lbl_80473AB8[idx].x4 != 1) { + if (entries[idx].x4 != 1) { for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x30 != 0) { - mn_8022F470((int*) &lbl_80473AB8[idx].slots[i].x48, - (int*) &lbl_80473AB8[idx].slots[i].x40, - amount); - HSD_JObjSetTranslateY( - lbl_80473AB8[idx].slots[i].x2C->hsd_obj, - -(f32) lbl_80473AB8[idx].slots[i].x48); + if (entries[idx].slots[i].x30 != 0) { + mn_8022F470((int*) &entries[idx].slots[i].x48, + (int*) &entries[idx].slots[i].x40, amount); + { + f32 y = -(f32) entries[idx].slots[i].x48; + HSD_JObjSetTranslateY( + entries[idx].slots[i].x2C->hsd_obj, y); + } } } return; } for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x30 != 0) { - lbl_80473AB8[idx].slots[i].x40 = - lbl_80473AB8[idx].slots[i].x48; + if (entries[idx].slots[i].x30 != 0) { + entries[idx].slots[i].x40 = entries[idx].slots[i].x48; } } } return; case 24: - if (lbl_80473AB8[idx].x18 != 0) { + if (entries[idx].x18 != 0) { struct lbl_803B7C80_t sp; s32* arr; sp = lbl_803B7C80; arr = sp.v; lbl_804D6630 += 1; for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x30 != 0) { - HSD_JObj* jobj = lbl_80473AB8[idx].slots[i].x2C->hsd_obj; - if (lbl_80473AB8[idx].x2 != 0) { + if (entries[idx].slots[i].x30 != 0) { + HSD_JObj* jobj = entries[idx].slots[i].x2C->hsd_obj; + if (entries[idx].x2 != 0) { HSD_JObjSetTranslateY( - jobj, -((f32) lbl_80473AB8[idx].slots[i].x40 - + jobj, -((f32) entries[idx].slots[i].x40 - (0.1f * (f32) arr[lbl_804D6630 % 10]))); } else { - switch (lbl_80473AB8[idx].x4) { + switch (entries[idx].x4) { case 1: if (i == 0) { HSD_JObjSetTranslateY( jobj, -((0.1f * (f32) arr[lbl_804D6630 % 10]) + - (f32) lbl_80473AB8[idx].slots[i].x40)); + (f32) entries[idx].slots[i].x40)); } else { HSD_JObjSetTranslateY( jobj, - -((f32) lbl_80473AB8[idx].slots[i].x40 - + -((f32) entries[idx].slots[i].x40 - (0.1f * (f32) arr[lbl_804D6630 % 10]))); } break; @@ -656,18 +671,18 @@ void fn_8018B090(HSD_GObj* arg0) HSD_JObjSetTranslateY( jobj, -((0.1f * (f32) arr[lbl_804D6630 % 10]) + - (f32) lbl_80473AB8[idx].slots[i].x40)); + (f32) entries[idx].slots[i].x40)); } else { HSD_JObjSetTranslateY( jobj, - -((f32) lbl_80473AB8[idx].slots[i].x40 - + -((f32) entries[idx].slots[i].x40 - (0.1f * (f32) arr[lbl_804D6630 % 10]))); } break; default: HSD_JObjSetTranslateY( jobj, -((0.1f * (f32) arr[lbl_804D6630 % 10]) + - (f32) lbl_80473AB8[idx].slots[i].x40)); + (f32) entries[idx].slots[i].x40)); break; } } @@ -677,27 +692,24 @@ void fn_8018B090(HSD_GObj* arg0) return; case 25: for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x30 != 0) { - lbl_80473AB8[idx].slots[i].x48 = - lbl_80473AB8[idx].slots[i].x40; + if (entries[idx].slots[i].x30 != 0) { + entries[idx].slots[i].x48 = entries[idx].slots[i].x40; } } return; case 32: { - s32 h = lbl_80473AB8[idx].x18; + s32 h = entries[idx].x18; if (h != 0) { - fn_80190520( - (f32) (lbl_80473AB8[idx].xC + (lbl_80473AB8[idx].x14 / 2)), - -(f32) (lbl_80473AB8[idx].x10 + (h / 2)), -150.0f); + fn_80190520((f32) (entries[idx].xC + (entries[idx].x14 / 2)), + -(f32) (entries[idx].x10 + (h / 2)), -150.0f); for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x4C == 0) { - lbl_80473AB8[idx].slots[i].x3C = - lbl_80473AB8[idx].xC + (lbl_80473AB8[idx].x14 / 2); + if (entries[idx].slots[i].x4C == 0) { + entries[idx].slots[i].x3C = + entries[idx].xC + (entries[idx].x14 / 2); } else { - s32 t = lbl_80473AB8[idx].slots[i].x40; - lbl_80473AB8[idx].slots[i].x40 = - lbl_80473AB8[idx].slots[i].x38; - lbl_80473AB8[idx].slots[i].x38 = t; + s32 t = entries[idx].slots[i].x40; + entries[idx].slots[i].x40 = entries[idx].slots[i].x38; + entries[idx].slots[i].x38 = t; } } } else { @@ -707,48 +719,48 @@ void fn_8018B090(HSD_GObj* arg0) tm->cur_option = 0x21; return; case 33: - if (lbl_80473AB8[idx].x18 != 0) { + if (entries[idx].x18 != 0) { for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x30 == 0) { + if (entries[idx].slots[i].x30 == 0) { var_r24 += 1; } else { - u8 t5 = lbl_80473AB8[idx].slots[i].x4C; + u8 t5 = entries[idx].slots[i].x4C; if (t5 == 0) { lbl_804D6634 = i; - if (lbl_80473AB8[idx].x4 != 1) { - mn_8022F470((int*) &lbl_80473AB8[idx].slots[i].x44, - (int*) &lbl_80473AB8[idx].slots[i].x3C, - 2); - if (lbl_80473AB8[idx].slots[i].x44 == - lbl_80473AB8[idx].slots[i].x3C) + if (entries[idx].x4 != 1) { + mn_8022F470((int*) &entries[idx].slots[i].x44, + (int*) &entries[idx].slots[i].x3C, 2); + if (entries[idx].slots[i].x44 == + entries[idx].slots[i].x3C) { var_r24 += 1; } HSD_JObjSetTranslateX( - lbl_80473AB8[idx].slots[i].x2C->hsd_obj, - (f32) lbl_80473AB8[idx].slots[i].x44); + entries[idx].slots[i].x2C->hsd_obj, + (f32) entries[idx].slots[i].x44); } else { var_r24 += 1; } } else { - mn_8022F470((int*) &lbl_80473AB8[idx].slots[i].x48, - (int*) &lbl_80473AB8[idx].slots[i].x40, + mn_8022F470((int*) &entries[idx].slots[i].x48, + (int*) &entries[idx].slots[i].x40, t5 + ((t5 + 1) / 2)); - if (lbl_80473AB8[idx].slots[i].x48 == - lbl_80473AB8[idx].slots[i].x40) + if (entries[idx].slots[i].x48 == + entries[idx].slots[i].x40) { var_r24 += 1; } HSD_JObjSetTranslateY( - lbl_80473AB8[idx].slots[i].x2C->hsd_obj, - -(f32) lbl_80473AB8[idx].slots[i].x48); + entries[idx].slots[i].x2C->hsd_obj, + -(f32) entries[idx].slots[i].x48); } } } if (var_r24 == 4) { - lbl_80473AB8[idx].slots[lbl_804D6634].x3C = + s32 slot_idx = lbl_804D6634; + entries[idx].slots[slot_idx].x3C = lbl_803D9E1C[tm->entrants][0]; - lbl_80473AB8[idx].slots[lbl_804D6634].x40 = + entries[idx].slots[slot_idx].x40 = lbl_803D9E1C[tm->entrants][1]; tm->cur_option = 0x22; } @@ -757,16 +769,15 @@ void fn_8018B090(HSD_GObj* arg0) } return; case 34: - if (lbl_80473AB8[idx].x18 != 0) { + if (entries[idx].x18 != 0) { if (tm->x33 == 5) { - mn_8022F470((int*) &lbl_80473AB8[idx].slots[lbl_804D6634].x44, - (int*) &lbl_80473AB8[idx].slots[lbl_804D6634].x3C, - 2); + mn_8022F470((int*) &entries[idx].slots[lbl_804D6634].x44, + (int*) &entries[idx].slots[lbl_804D6634].x3C, 2); HSD_JObjSetTranslateX( - lbl_80473AB8[idx].slots[lbl_804D6634].x2C->hsd_obj, - (f32) lbl_80473AB8[idx].slots[lbl_804D6634].x44); - if (lbl_80473AB8[idx].slots[lbl_804D6634].x44 == - lbl_80473AB8[idx].slots[lbl_804D6634].x3C) + fn_8018B090_inline1(entries, idx), + (f32) entries[idx].slots[lbl_804D6634].x44); + if (entries[idx].slots[lbl_804D6634].x44 == + entries[idx].slots[lbl_804D6634].x3C) { tm->cur_option = 0x23; } @@ -780,16 +791,15 @@ void fn_8018B090(HSD_GObj* arg0) } return; case 35: - if (lbl_80473AB8[idx].x18 != 0) { + if (entries[idx].x18 != 0) { if (tm->x33 == 5) { - mn_8022F470((int*) &lbl_80473AB8[idx].slots[lbl_804D6634].x48, - (int*) &lbl_80473AB8[idx].slots[lbl_804D6634].x40, - 2); + mn_8022F470((int*) &entries[idx].slots[lbl_804D6634].x48, + (int*) &entries[idx].slots[lbl_804D6634].x40, 2); HSD_JObjSetTranslateY( - lbl_80473AB8[idx].slots[lbl_804D6634].x2C->hsd_obj, - -(f32) lbl_80473AB8[idx].slots[lbl_804D6634].x48); - if (lbl_80473AB8[idx].slots[lbl_804D6634].x48 == - lbl_80473AB8[idx].slots[lbl_804D6634].x40) + fn_8018B090_inline1(entries, idx), + -(f32) entries[idx].slots[lbl_804D6634].x48); + if (entries[idx].slots[lbl_804D6634].x48 == + entries[idx].slots[lbl_804D6634].x40) { tm->x33 = 6; } @@ -803,12 +813,12 @@ void fn_8018B090(HSD_GObj* arg0) } return; case 36: { - s32 h = lbl_80473AB8[idx].x18; + s32 h = entries[idx].x18; if (h != 0) { f32 d; lbl_803D9DAC.current.x = - (f32) (lbl_80473AB8[idx].xC + (lbl_80473AB8[idx].x14 / 2)); - lbl_803D9DAC.current.y = -(f32) ((h / 2) + lbl_80473AB8[idx].x10); + (f32) (entries[idx].xC + (entries[idx].x14 / 2)); + lbl_803D9DAC.current.y = -(f32) ((h / 2) + entries[idx].x10); lbl_803D9DAC.current.z = -150.0f; lbl_803D9DAC.target.x = 320.0f; lbl_803D9DAC.target.y = -240.0f; @@ -833,7 +843,7 @@ void fn_8018B090(HSD_GObj* arg0) tm->cur_option = 0x25; return; case 37: - if (lbl_80473AB8[idx].x18 == 0) { + if (entries[idx].x18 == 0) { lbl_804D6630 = 0x78; } if (lbl_804D6630 < 0x78) { @@ -853,7 +863,7 @@ void fn_8018B090(HSD_GObj* arg0) tm->cur_option = 0x26; return; case 38: - if (lbl_80473AB8[idx].x18 == 0) { + if (entries[idx].x18 == 0) { lbl_804D6630 = 0x78; } if (lbl_804D6630 < 0x78) { @@ -866,35 +876,29 @@ void fn_8018B090(HSD_GObj* arg0) u8* next_entry; u8* next_slot; for (i = 0; i < 4; i++) { - if (lbl_80473AB8[idx].slots[i].x4C == 0) { + if (entries[idx].slots[i].x4C == 0) { break; } r = i + 1; } - src = &lbl_80473AB8[fn_8018F74C()]; + src = fn_8018B090_inline2(entries, fn_8018F74C()); src->x1 = 0; next_entry = &src->x5; next_slot = &src->x6; - lbl_80473AB8[*next_entry].slots[*next_slot].x30 = 1; - lbl_80473AB8[*next_entry].slots[*next_slot].x50 = - src->slots[r].x50; - lbl_80473AB8[*next_entry].slots[*next_slot].x51 = - src->slots[r].x51; - lbl_80473AB8[*next_entry].slots[*next_slot].x52 = - src->slots[r].x52; - lbl_80473AB8[*next_entry].slots[*next_slot].x4D = - src->slots[r].x4D; - lbl_80473AB8[*next_entry].slots[*next_slot].x4E = - src->slots[r].x4E; - lbl_80473AB8[*next_entry].slots[*next_slot].x4F = - src->slots[r].x4F; + entries[*next_entry].slots[*next_slot].x30 = 1; + entries[*next_entry].slots[*next_slot].x50 = src->slots[r].x50; + entries[*next_entry].slots[*next_slot].x51 = src->slots[r].x51; + entries[*next_entry].slots[*next_slot].x52 = src->slots[r].x52; + entries[*next_entry].slots[*next_slot].x4D = src->slots[r].x4D; + entries[*next_entry].slots[*next_slot].x4E = src->slots[r].x4E; + entries[*next_entry].slots[*next_slot].x4F = src->slots[r].x4F; src->slots[r].x30 = 0; src->slots[r].x4E = 3; tm->cur_option = 0x27; } break; } - PAD_STACK(0x30); + PAD_STACK(0x28); } /* 3D9EE8 */ static char lbl_803D9EE8[] = { @@ -924,7 +928,7 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, GXColor c0, c1, c2, c3, c4, c5, c6, c7, c8, c9; s32 half_h, third_h; s32 mid_y, bot_y, two_third_y; - s32 half, center, right, left; + s32 half, center, right; GXColor c10, c11, c12, c13, c14, c15, c16, c17, c18, c19; GXColor c20, c21, c22, c23, c24, c25, c26, c27, c28, c29; GXColor c30, c31, c32, c33; @@ -989,12 +993,10 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, } neg_thickness = -thickness; - left = arg1 + 0x2B; - mid_y = arg2 + half_h; c7 = c0; { GXColor* color = &c7; - DrawRectangle((f32) left, (f32) mid_y, + DrawRectangle((f32) (arg1 + 0x2B), (f32) (mid_y = arg2 + half_h), ((f32) arg3 + thickness) - 43.0f, neg_thickness, color); } @@ -1058,17 +1060,12 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, case 3: half = arg3 / 2; third_h = arg4 / 3; - center = arg1 + half; - mid_y = arg2 + third_h; c15 = c0; { GXColor* color = &c15; - { - f32 tmp_p34770 = (f32) center; - DrawRectangle(tmp_p34770, (f32) mid_y, thickness, - (f32) (third_h - 2), color); - } + DrawRectangle((f32) (arg1 + half), (f32) (arg2 + third_h), + thickness, (f32) (third_h - 2), color); } c16 = c0; @@ -1105,8 +1102,8 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, c20 = c0; { GXColor* color = &c20; - DrawRectangle((f32) arg1, (f32) mid_y, (f32) arg3 + thickness, - neg_thickness, color); + DrawRectangle((f32) arg1, (f32) (arg2 + third_h), + (f32) arg3 + thickness, neg_thickness, color); } c21 = c0; @@ -1134,8 +1131,9 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, c24 = data->x20; { GXColor* color = &c24; - DrawRectangle((f32) center, (f32) (arg2 + (arg4 / 2)), - thickness, (f32) ((arg4 / 6) - 1), color); + DrawRectangle((f32) (arg1 + half), + (f32) (arg2 + (arg4 / 2)), thickness, + (f32) ((arg4 / 6) - 1), color); } return; } @@ -1150,14 +1148,15 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, c26 = data->x20; { GXColor* color = &c26; - DrawRectangle((f32) center, (f32) two_third_y, (f32) half, - neg_thickness, color); + DrawRectangle((f32) (arg1 + half), (f32) two_third_y, + (f32) half, neg_thickness, color); } c27 = data->x20; { GXColor* color = &c27; - DrawRectangle((f32) center, (f32) (arg2 + (arg4 / 2)), - thickness, (f32) ((arg4 / 6) - 1), color); + DrawRectangle((f32) (arg1 + half), + (f32) (arg2 + (arg4 / 2)), thickness, + (f32) ((arg4 / 6) - 1), color); } return; } @@ -1171,14 +1170,14 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, c29 = data->x20; { GXColor* color = &c29; - DrawRectangle((f32) arg1, (f32) mid_y, (f32) half, - neg_thickness, color); + DrawRectangle((f32) arg1, (f32) (arg2 + third_h), + (f32) half, neg_thickness, color); } c30 = data->x20; { GXColor* color = &c30; - DrawRectangle((f32) center, (f32) mid_y, thickness, - (f32) ((arg4 / 6) - 1), color); + DrawRectangle((f32) (arg1 + half), (f32) (arg2 + third_h), + thickness, (f32) ((arg4 / 6) - 1), color); } return; } @@ -1191,14 +1190,14 @@ void fn_8018C8D4(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, c32 = data->x20; { GXColor* color = &c32; - DrawRectangle((f32) center, (f32) mid_y, (f32) half, - neg_thickness, color); + DrawRectangle((f32) (arg1 + half), (f32) (arg2 + third_h), + (f32) half, neg_thickness, color); } c33 = data->x20; { GXColor* color = &c33; - DrawRectangle((f32) center, (f32) mid_y, thickness, - (f32) ((arg4 / 6) - 1), color); + DrawRectangle((f32) (arg1 + half), (f32) (arg2 + third_h), + thickness, (f32) ((arg4 / 6) - 1), color); } } break; @@ -1374,7 +1373,7 @@ void fn_8018D50C(BracketEntry* data, s32 arg1, s32 arg2, s32 arg3, s32 arg4, static GXColor const col = { 0xFF, 0xFF, 0x00, 0xFF }; -void fn_8018DC18(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, +void fn_8018DC18(BracketEntry* data, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) { f32 thickness; @@ -1385,7 +1384,7 @@ void fn_8018DC18(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, GXColor c0, c1, c2, c3, c4, c5, c6, c7, c8, c9; c0 = col; - thickness = arg0->x1C; + thickness = data->x1C; c1 = c0; { GXColor* color = &c1; @@ -1415,29 +1414,41 @@ void fn_8018DC18(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, neg_thickness, color); } - if (arg0->x20.g == 0) { - if (arg0->slots[0].x4C == 0) { - GXColor* entry_color = &arg0->x20; - c5 = *entry_color; - DrawRectangle(arg1, arg2, thickness, arg4, &c5); - c6 = *entry_color; - DrawRectangle(arg1, arg5, half + thickness, neg_thickness, &c6); + if (data->x20.g == 0) { + if (data->slots[0].x4C == 0) { + c5 = data->x20; + { + GXColor* color = &c5; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, + color); + } + c6 = data->x20; + { + GXColor* color = &c6; + DrawRectangle((f32) arg1, (f32) arg5, (f32) half + thickness, + neg_thickness, color); + } return; } - if (arg0->slots[1].x4C == 0) { - c7 = arg0->x20; + if (data->slots[1].x4C == 0) { + c7 = data->x20; { GXColor* color = &c7; DrawRectangle(center, arg2, thickness, arg4, color); } return; } + c8 = data->x20; { - GXColor* entry_color = &arg0->x20; - c8 = *entry_color; - DrawRectangle(right, arg2, thickness, arg4, &c8); - c9 = *entry_color; - DrawRectangle(center, arg5, half + thickness, neg_thickness, &c9); + GXColor* color = &c8; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, + color); + } + c9 = data->x20; + { + GXColor* color = &c9; + DrawRectangle((f32) center, (f32) arg5, (f32) half + thickness, + neg_thickness, color); } } } @@ -1465,7 +1476,6 @@ void fn_8018DF68(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, f32 thickness; s32 right; s32 third; - s32 left_third; s32 right_third; s32 half; @@ -1484,12 +1494,12 @@ void fn_8018DF68(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, color); } - third = arg3 / 3; - left_third = arg1 + third; left_third_color = line_color; + third = arg3 / 3; { - f32 x = (f32) left_third; - DrawRectangle(x, (f32) arg2, thickness, (f32) arg4, &left_third_color); + f32 x = (f32) (arg1 + third); + GXColor* color = &left_third_color; + DrawRectangle(x, (f32) arg2, thickness, (f32) arg4, color); } right_third = right - third; @@ -1502,59 +1512,74 @@ void fn_8018DF68(BracketEntry* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, neg_thickness = -thickness; horizontal_color = line_color; - DrawRectangle((f32) arg1, (f32) arg5, (f32) arg3 + thickness, - neg_thickness, &horizontal_color); + { + GXColor* color = &horizontal_color; + DrawRectangle((f32) arg1, (f32) arg5, (f32) arg3 + thickness, + neg_thickness, color); + } if (arg0->x20.g == 0) { if (arg0->slots[0].x4C == 0) { - GXColor* entry_color = &arg0->x20; - slot0_vertical_color = *entry_color; - DrawRectangle(arg1, arg2, thickness, arg4, &slot0_vertical_color); - slot0_horizontal_color = *entry_color; - DrawRectangle(arg1, arg5, (arg3 / 2) + thickness, neg_thickness, - &slot0_horizontal_color); + slot0_vertical_color = arg0->x20; + { + GXColor* color = &slot0_vertical_color; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, + color); + } + slot0_horizontal_color = arg0->x20; + { + GXColor* color = &slot0_horizontal_color; + DrawRectangle((f32) arg1, (f32) arg5, + (f32) (arg3 / 2) + thickness, neg_thickness, + color); + } return; } if (arg0->slots[1].x4C == 0) { - GXColor* entry_color = &arg0->x20; - slot1_vertical_color = *entry_color; - DrawRectangle(left_third, arg2, thickness, arg4, - &slot1_vertical_color); - slot1_horizontal_color = *entry_color; + slot1_vertical_color = arg0->x20; + { + GXColor* color = &slot1_vertical_color; + DrawRectangle((f32) (arg1 + third), (f32) arg2, thickness, + (f32) arg4, color); + } + slot1_horizontal_color = arg0->x20; { GXColor* color = &slot1_horizontal_color; - DrawRectangle(left_third, arg5, - ((arg3 / 2) + thickness) - third, neg_thickness, - color); + DrawRectangle((f32) (arg1 + third), (f32) arg5, + ((f32) (arg3 / 2) + thickness) - third, + neg_thickness, color); } return; } if (arg0->slots[2].x4C == 0) { - GXColor* entry_color = &arg0->x20; - slot2_vertical_color = *entry_color; - DrawRectangle(right_third, arg2, thickness, arg4, - &slot2_vertical_color); + slot2_vertical_color = arg0->x20; + { + GXColor* color = &slot2_vertical_color; + DrawRectangle((f32) right_third, (f32) arg2, thickness, + (f32) arg4, color); + } half = arg3 / 2; - slot2_horizontal_color = *entry_color; + slot2_horizontal_color = arg0->x20; { - f32 y = arg5; - DrawRectangle((arg1 + half), y, (half + thickness) - third, - neg_thickness, &slot2_horizontal_color); + GXColor* color = &slot2_horizontal_color; + DrawRectangle((f32) (arg1 + half), (f32) arg5, + ((f32) half + thickness) - third, neg_thickness, + color); } return; } + slot3_vertical_color = arg0->x20; { - GXColor* entry_color = &arg0->x20; - slot3_vertical_color = *entry_color; - DrawRectangle(right, arg2, thickness, arg4, &slot3_vertical_color); - half = arg3 / 2; - slot3_horizontal_color = *entry_color; + GXColor* color = &slot3_vertical_color; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, + color); } + half = arg3 / 2; + slot3_horizontal_color = arg0->x20; { - f32 y = arg5; GXColor* color = &slot3_horizontal_color; - DrawRectangle((arg1 + half), y, half + thickness, neg_thickness, - color); + DrawRectangle((f32) (arg1 + half), (f32) arg5, + (f32) half + thickness, neg_thickness, color); } } } diff --git a/src/melee/gr/granime.c b/src/melee/gr/granime.c index d8d6793494..5adfd748bb 100644 --- a/src/melee/gr/granime.c +++ b/src/melee/gr/granime.c @@ -579,62 +579,42 @@ void grAnime_801C706C(HSD_TObj* tobj, s32 flags, void* func, u32 type, } } -static inline void grAnime_801C706C_inner(HSD_TObj* tobj, s32 flags, - void* func, u32 type, void* param) +static inline void grAnime_MObjForeachAnim(HSD_MObj* mobj, int flags, + void* func, u32 type, void* param) { - grAnime_801C706C(tobj, flags, func, type, param); -} - -static inline void grAnime_801C706C_noinline(HSD_TObj* tobj, s32 flags, - void* func, u32 type, void* param) -{ - grAnime_801C706C_inner(tobj, flags, func, type, param); + if (mobj == NULL) { + return; + } + if ((flags & CALL_ON_MOBJ) && mobj->aobj != NULL) { + grAnime_801C6F50(mobj->aobj, mobj, ARG_TYPE_MOBJ, func, type, param); + } + grAnime_801C706C(mobj->tobj, flags, func, type, param); } -void grAnime_801C70E0(HSD_DObj* dobj, int flags, void* function, u32 arg3, - void* arg4) +static inline void grAnime_PObjForeachAnim(HSD_PObj* pobj, int flags, + void* func, u32 type, void* param) { - HSD_MObj* mobj; - HSD_PObj* pobj; - - while (dobj != NULL) { - if (flags & CALL_ON_DOBJ && dobj->aobj != NULL) { - grAnime_801C6F50(dobj->aobj, dobj, ARG_TYPE_DOBJ, function, arg3, - arg4); - } - if (dobj->mobj != NULL) { - mobj = dobj->mobj; - if (flags & CALL_ON_MOBJ && mobj->aobj != NULL) { - HSD_MObj* mobj_tmp = dobj->mobj; - grAnime_801C6F50(mobj_tmp->aobj, mobj_tmp, ARG_TYPE_MOBJ, - function, arg3, arg4); - } - grAnime_801C706C(mobj->tobj, flags, function, arg3, arg4); - } - pobj = dobj->pobj; - if (flags & CALL_ON_POBJ && pobj != NULL && - pobj_type(pobj) == POBJ_SHAPEANIM && pobj->u.unk != NULL && - pobj->u.unk->aobj != NULL) - { - grAnime_801C6F50(pobj->u.unk->aobj, pobj, ARG_TYPE_POBJ, function, - arg3, arg4); - } - dobj = dobj->next; + if ((flags & CALL_ON_POBJ) && pobj != NULL && + pobj_type(pobj) == POBJ_SHAPEANIM && pobj->u.unk != NULL && + pobj->u.unk->aobj != NULL) + { + grAnime_801C6F50(pobj->u.unk->aobj, pobj, ARG_TYPE_POBJ, func, type, + param); } } -/* -void grAnime_801C706C(HSD_TObj* tobj, int flags, void (*function)(), void* -arg3, void* arg4) +void grAnime_801C70E0(HSD_DObj* dobj, int flags, void* func, u32 type, + void* param) { - while (tobj != NULL) { - if (flags & CALL_ON_TOBJ && tobj->aobj != NULL) { - grAnime_801C6F50(tobj->aobj, tobj, ARG_TYPE_TOBJ, function, arg3, -arg4); + for (; dobj != NULL; dobj = dobj->next) { + if ((flags & CALL_ON_DOBJ) && dobj->aobj != NULL) { + grAnime_801C6F50(dobj->aobj, dobj, ARG_TYPE_DOBJ, func, type, + param); } - tobj = tobj->next; + grAnime_MObjForeachAnim(dobj->mobj, flags, func, type, param); + grAnime_PObjForeachAnim(dobj->pobj, flags, func, type, param); } -}*/ +} static inline bool grAnime_801C6F50_wrapped(HSD_JObj* obj, int flags, void* func, u32 type, void* param) @@ -648,80 +628,53 @@ static inline bool grAnime_801C6F50_wrapped(HSD_JObj* obj, int flags, return ((obj->flags & 0x4020) ? false : true); } -static inline void grAnime_801C7228_for_each_child(HSD_JObj* obj, void* param, - u32 type, void* func, - int flags, int arg5) +static inline void grAnime_RObjForeachAnim(HSD_RObj* robj, int flags, + void* func, u32 type, void* param) { - HSD_RObj* robj; - HSD_JObj* child; - HSD_RObj* child_robj; - HSD_JObj* grandchild; - - for (robj = obj->robj; robj != NULL; robj = robj->next) { + for (; robj != NULL; robj = robj->next) { if ((flags & 0x200) && robj->aobj != NULL) { grAnime_801C6F50(robj->aobj, robj, 0xA, func, type, param); } } - if (arg5 && !(obj->flags & 0x1000)) { - for (child = obj->child; child != NULL; child = child->next) { - if (grAnime_801C6F50_wrapped(child, flags, func, type, param)) { - grAnime_801C70E0(child->u.dobj, flags, func, type, param); - } - for (child_robj = child->robj; child_robj != NULL; - child_robj = child_robj->next) - { - if (flags & 0x200) { - if (child_robj->aobj != NULL) { - grAnime_801C6F50(child_robj->aobj, child_robj, 0xA, - func, type, param); - } - } - } - if (arg5 && !(child->flags & 0x1000)) { - for (grandchild = child->child; grandchild != NULL; - grandchild = grandchild->next) - { - grAnime_801C7228(grandchild, flags, func, type, param, - arg5); - } - } - } - } } void grAnime_801C7228(HSD_JObj* obj, int flags, void* func, u32 type, void* param, int arg5) { - HSD_DObj* dobj; - HSD_MObj* mobj; - HSD_PObj* pobj; - if (grAnime_801C6F50_wrapped(obj, flags, func, type, param)) { - for (dobj = obj->u.dobj; dobj != NULL; dobj = dobj->next) { - if ((flags & 4) && dobj->aobj != NULL) { - grAnime_801C6F50(dobj->aobj, dobj, 3, func, type, param); - } - if ((mobj = dobj->mobj) != NULL) { - if ((flags & 0x80) && mobj->aobj != NULL) { - grAnime_801C6F50(mobj->aobj, mobj, 8, func, type, param); - } - grAnime_801C706C_noinline(mobj->tobj, flags, func, type, - param); - } - pobj = dobj->pobj; - if (((flags & 0x100) != 0) && (pobj != NULL) && - ((pobj->flags & 0x3000) == 0x1000)) - { - if (pobj->u.unk != NULL) { - if (pobj->u.unk->aobj != NULL) { - grAnime_801C6F50(pobj->u.unk->aobj, pobj, 9, func, - type, param); - } - } - } + grAnime_801C70E0(obj->u.dobj, flags, func, type, param); + } + grAnime_RObjForeachAnim(obj->robj, flags, func, type, param); + if (arg5 && !(obj->flags & 0x1000)) { + for (obj = obj->child; obj != NULL; obj = obj->next) { + grAnime_801C7228(obj, flags, func, type, param, arg5); } } - grAnime_801C7228_for_each_child(obj, param, type, func, flags, arg5); +} + +static inline void grAnime_801C70E0_inner(HSD_DObj* arg0, int arg1, void* arg2, + u32 arg3, void* arg4) +{ + grAnime_801C70E0(arg0, arg1, arg2, arg3, arg4); +} + +static inline void grAnime_801C70E0_noinline(HSD_DObj* arg0, int arg1, + void* arg2, u32 arg3, void* arg4) +{ + grAnime_801C70E0_inner(arg0, arg1, arg2, arg3, arg4); +} + +static inline void grAnime_801C7228_inner(HSD_JObj* arg0, int arg1, void* arg2, + u32 arg3, void* arg4, int arg5) +{ + grAnime_801C7228(arg0, arg1, arg2, arg3, arg4, arg5); +} + +static inline void grAnime_801C7228_noinline(HSD_JObj* arg0, int arg1, + void* arg2, u32 arg3, void* arg4, + int arg5) +{ + grAnime_801C7228_inner(arg0, arg1, arg2, arg3, arg4, arg5); } void grAnime_801C752C(HSD_JObj* obj, s32 arg1, s32 flags, void* func, u32 type, @@ -764,7 +717,7 @@ void grAnime_801C752C(HSD_JObj* obj, s32 arg1, s32 flags, void* func, u32 type, break; } if (grAnime_801C6F50_wrapped(obj_tmp, flags, func, type, &arg)) { - grAnime_801C70E0(obj->u.dobj, flags, func, type, &arg); + grAnime_801C70E0_noinline(obj->u.dobj, flags, func, type, &arg); } flags2 = flags & 0x200; for (robj = obj->robj; robj != 0L; robj = robj->next) { @@ -774,7 +727,7 @@ void grAnime_801C752C(HSD_JObj* obj, s32 arg1, s32 flags, void* func, u32 type, } if (arg1 != 0 && !(obj->flags & 0x1000)) { for (child = obj->child; child != NULL; child = child->next) { - grAnime_801C7228(child, flags, func, type, &arg, arg1); + grAnime_801C7228_noinline(child, flags, func, type, &arg, arg1); } } va_end(ap); @@ -956,12 +909,12 @@ void grAnime_801C7BA0(HSD_GObj* gobj, int arg1, u32 arg2, f32 arg8) void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, int arg5, f32 farg0, f32 farg1) { - u32 var_r30 = 0; + s32 anim_flags = 0; UnkArchiveStruct* archive; HSD_AnimJoint** ajp; HSD_MatAnimJoint** mjp; HSD_ShapeAnimJoint** sjp; - s32 anim_flags = 0; + u32 req_flags = 0; HSD_AnimJoint* aj; HSD_AnimJoint* caj; HSD_ShapeAnimJoint* csj; @@ -969,8 +922,6 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, HSD_MatAnimJoint* mj; HSD_MatAnimJoint* cmj; HSD_ShapeAnimJoint* sj; - HSD_MatAnim* manim; - HSD_ShapeAnimDObj* sdobj; u8* eflags; s32 flag; @@ -983,8 +934,8 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, ((aj = ajp[arg4]) != NULL)) { aj = &aj[arg2]; - var_r30 |= 0x81; anim_flags |= 0x220; + req_flags |= 0x81; } else { aj = NULL; } @@ -992,8 +943,8 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, ((mj = mjp[arg4]) != NULL)) { mj = &mj[arg2]; - var_r30 |= 0x416; anim_flags |= 0x7484; + req_flags |= 0x416; } else { mj = NULL; } @@ -1001,8 +952,8 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, ((sj = sjp[arg4]) != NULL)) { sj = &sj[arg2]; - var_r30 |= 8; anim_flags |= 0x100; + req_flags |= 8; } else { sj = NULL; } @@ -1071,13 +1022,13 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, } } } - HSD_JObjReqAnimAllByFlags(jobj, var_r30, farg0); + HSD_JObjReqAnimAllByFlags(jobj, req_flags, farg0); } else { if (jobj != NULL) { if (aj != NULL) { if (aj->aobjdesc != NULL) { if (jobj->aobj != NULL) { - HSD_AObjRemove(jobj->aobj); + HSD_AObjRemove(grAnime_GetAObj(jobj)); } { HSD_AObjDesc* aobjdesc = aj->aobjdesc; @@ -1091,25 +1042,17 @@ void grAnime_801C7C1C(HSD_JObj* jobj, s32 map_id, s32 arg2, s32 arg3, s32 arg4, } } if ((jobj->flags & 0x4020) ? false : true) { - if (sj != NULL) { - sdobj = sj->shapeanimdobj; - } else { - sdobj = NULL; - } - if (mj != NULL) { - manim = mj->matanim; - } else { - manim = NULL; - } - grAnime_801C683C_noinline(jobj->u.dobj, manim, sdobj); + grAnime_801C683C_noinline( + jobj->u.dobj, mj != NULL ? mj->matanim : NULL, + sj != NULL ? sj->shapeanimdobj : NULL); } } - HSD_JObjReqAnimByFlags(jobj, var_r30, farg0); + HSD_JObjReqAnimByFlags(jobj, req_flags, farg0); } grAnime_801C752C(jobj, arg5, anim_flags, HSD_AObjSetRate, 1, farg1); archive = grDatFiles_801C6330(map_id); HSD_ASSERT(0x148, archive); - eflags = (u8*) archive->unk4->unk8[map_id].x28; + eflags = archive->unk4->unk8[map_id].x28; if (eflags != NULL) { flag = eflags[arg4]; } else { diff --git a/src/melee/gr/grbigblue.c b/src/melee/gr/grbigblue.c index f3d7db18bd..892c8e6c91 100644 --- a/src/melee/gr/grbigblue.c +++ b/src/melee/gr/grbigblue.c @@ -665,7 +665,6 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) 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); @@ -675,9 +674,8 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) 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_ptr; + gp->u.bigblue.data[i].x38 = pos; 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; @@ -691,212 +689,211 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) case 1: if ((int) grBigBlue_801E89DC(0) == 0) { gp->u.bigblue.data[i].x1 = 0; - } else { - 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; - - memzero(&pos, sizeof(pos)); - memzero(&neg_pos, sizeof(neg_pos)); - pos.x = 10.0f + Stage_GetBlastZoneRightOffset(); - neg_pos.x = -(10.0f + Stage_GetBlastZoneRightOffset()); - - right_y = grBigBlue_801EC58C(&pos, NULL, 500.0f); - left_y = grBigBlue_801EC58C(&neg_pos, NULL, 500.0f); - - if (right_y != -F32_MAX || left_y != -F32_MAX) { - f32 height_range; - s32 height_range_i; - s32 height_range_arg; - s32 height_rand; - - gp->u.bigblue.data[i].x8 = yakumono_param->x90; - height_range = - yakumono_param->x94 - yakumono_param->x90; - if (height_range < 0.0f) { - height_range = -height_range; - } - height_range_i = (s32) height_range; - height_range_arg = (s32) height_range; - if (height_range_i != 0) { - height_rand = HSD_Randi(height_range_arg); - } else { - height_rand = 0; + break; + } + 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; + + memzero(&pos, sizeof(pos)); + memzero(&neg_pos, sizeof(neg_pos)); + pos.x = 10.0f + Stage_GetBlastZoneRightOffset(); + neg_pos.x = -(10.0f + Stage_GetBlastZoneRightOffset()); + + right_y = grBigBlue_801EC58C(&pos, NULL, 500.0f); + left_y = grBigBlue_801EC58C(&neg_pos, NULL, 500.0f); + + if (right_y != -F32_MAX || left_y != -F32_MAX) { + f32 height_range; + s32 height_range_i; + s32 height_range_arg; + s32 height_rand; + + gp->u.bigblue.data[i].x8 = yakumono_param->x90; + height_range = yakumono_param->x94 - yakumono_param->x90; + if (height_range < 0.0f) { + height_range = -height_range; + } + height_range_i = (s32) height_range; + height_range_arg = (s32) height_range; + if (height_range_i != 0) { + height_rand = HSD_Randi(height_range_arg); + } else { + height_rand = 0; + } + gp->u.bigblue.data[i].x8 += (f32) height_rand; + pos.y = right_y + gp->u.bigblue.data[i].x8; + neg_pos.y = left_y + gp->u.bigblue.data[i].x8; + + if (left_y == -F32_MAX) { + gp->u.bigblue.data[i].x2 = (u8) -1; + } else if (right_y == -F32_MAX) { + gp->u.bigblue.data[i].x2 = 1; + } else { + f32 diff = right_y - left_y; + if (diff < 0.0f) { + diff = -diff; } - gp->u.bigblue.data[i].x8 += (f32) height_rand; - pos.y = right_y + gp->u.bigblue.data[i].x8; - neg_pos.y = left_y + gp->u.bigblue.data[i].x8; - - if (left_y == -F32_MAX) { - gp->u.bigblue.data[i].x2 = (u8) -1; - } else if (right_y == -F32_MAX) { - gp->u.bigblue.data[i].x2 = 1; - } else { - f32 diff = right_y - left_y; - if (diff < 0.0f) { - diff = -diff; + if (diff < 80.0f) { + s32 dir; + if (HSD_Randi(2) != 0) { + dir = 1; + } else { + dir = -1; } - if (diff < 80.0f) { - s32 dir; - if (HSD_Randi(2) != 0) { - dir = 1; - } else { - dir = -1; - } - gp->u.bigblue.data[i].x2 = dir; + gp->u.bigblue.data[i].x2 = dir; + } else { + s32 dir2; + if (right_y < left_y) { + dir2 = -1; } else { - s32 dir2; - if (right_y < left_y) { - dir2 = -1; - } else { - dir2 = 1; - } - gp->u.bigblue.data[i].x2 = dir2; + dir2 = 1; } + gp->u.bigblue.data[i].x2 = dir2; } + } - if ((int) grBigBlue_801E89DC(1) != 0) { - gp->u.bigblue.data[i].x2 = 1; - pos.x = -(10.0f + Stage_GetBlastZoneRightOffset()); - } else if ((s32) gp->u.bigblue.data[i].x2 == 1) { - pos = neg_pos; - } + if ((int) grBigBlue_801E89DC(1) != 0) { + gp->u.bigblue.data[i].x2 = 1; + pos.x = -(10.0f + Stage_GetBlastZoneRightOffset()); + } else if ((s32) gp->u.bigblue.data[i].x2 == 1) { + pos = neg_pos; + } - retries = 0; - found = 0; - for (;;) { - Vec3 speeds; - - speeds = grBb_803B8114; - found = grBigBlue_801E8794( - jobj, &pos, 0, - 2.0f * (speeds.x * Ground_801C0498()), 25.0f); - 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); - } - } - if (found == 0) { - f32 bound = grBigBlue_801E8D04(); - if (pos.y <= bound) { - found = 1; - } - } - if (found == 1) { - retries += 1; - pos.y += 25.0f; - if (retries < 3) { - continue; - } + retries = 0; + found = 0; + for (;;) { + Vec3 speeds; + + speeds = grBb_803B8114; + found = grBigBlue_801E8794( + jobj, &pos, 0, + 2.0f * (speeds.x * Ground_801C0498()), 25.0f); + 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); } - break; } - if (found != 0) { - pos.y = 10.0f + Stage_GetCamBoundsTopOffset(); + if (found == 0) { + f32 bound = grBigBlue_801E8D04(); + if (pos.y <= bound) { + found = 1; + } } - if (pos.y == -F32_MAX) { - pos.y = 10.0f + Stage_GetCamBoundsTopOffset(); + if (found == 1) { + retries += 1; + pos.y += 25.0f; + if (retries < 3) { + continue; + } } + break; + } + if (found != 0) { + pos.y = 10.0f + Stage_GetCamBoundsTopOffset(); + } + if (pos.y == -F32_MAX) { + pos.y = 10.0f + Stage_GetCamBoundsTopOffset(); + } - HSD_JObjSetTranslate(jobj, &pos); - gp->u.bigblue.data[i].xC.z = pos.y; - - gp->u.bigblue.data[i].x38 = pos; - gp->u.bigblue.data[i].x44.x = - yakumono_param->x98 * - (f32) gp->u.bigblue.data[i].x2; - gp->u.bigblue.data[i].x44.z = 0.0f; - gp->u.bigblue.data[i].x44.y = 0.0f; - gp->u.bigblue.data[i].x18.z = 0.0f; - gp->u.bigblue.data[i].x18.y = 0.0f; - gp->u.bigblue.data[i].x18.x = 0.0f; - gp->u.bigblue.data[i].x34 = 0; - gp->u.bigblue.data[i].x2C = 0; - gp->u.bigblue.data[i].x1 = 3; - HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); - gp->u.bigblue.data[i].x50 = 0; - { - s32 chance = yakumono_param->xB8; - s32 spawn; - if (chance != 0) { - spawn = HSD_Randi(chance); - } else { - spawn = 0; - } - if (spawn == 0) { - grBigBlue_801E8A1C(i); - } + HSD_JObjSetTranslate(jobj, &pos); + gp->u.bigblue.data[i].xC.z = pos.y; + + gp->u.bigblue.data[i].x38 = pos; + gp->u.bigblue.data[i].x44.x = + yakumono_param->x98 * (f32) gp->u.bigblue.data[i].x2; + gp->u.bigblue.data[i].x44.z = 0.0f; + gp->u.bigblue.data[i].x44.y = 0.0f; + gp->u.bigblue.data[i].x18.z = 0.0f; + gp->u.bigblue.data[i].x18.y = 0.0f; + gp->u.bigblue.data[i].x18.x = 0.0f; + gp->u.bigblue.data[i].x34 = 0; + gp->u.bigblue.data[i].x2C = 0; + gp->u.bigblue.data[i].x1 = 3; + HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); + gp->u.bigblue.data[i].x50 = 0; + { + s32 chance = yakumono_param->xB8; + s32 spawn; + if (chance != 0) { + spawn = HSD_Randi(chance); + } else { + spawn = 0; } - base->u.arwing.xC4 += 1; - if ((int) grBigBlue_801E89DC(2) == 0) { - u32 cnt = base->u.arwing.xC4; - if ((s32) cnt >= yakumono_param->x11C) { - s32 max = yakumono_param->x120; - if ((s32) cnt <= max && - ((s32) cnt == max || HSD_Randi(2) != 0)) - { - grBigBlue_801E8978(2, (void*) 1, jobj); - } - } + if (spawn == 0) { + grBigBlue_801E8A1C(i); } - if ((int) grBigBlue_801E89DC(1) == 0) { - u32 cnt2 = base->u.arwing.xC4; - if ((s32) cnt2 >= yakumono_param->xDC && - (s32) gp->u.bigblue.data[i].x2 == 1 && - ((s32) cnt2 >= yakumono_param->xE0 || - HSD_Randi(2) != 0)) + } + base->u.arwing.xC4 += 1; + if ((int) grBigBlue_801E89DC(2) == 0) { + u32 cnt = base->u.arwing.xC4; + if ((s32) cnt >= yakumono_param->x11C) { + s32 max = yakumono_param->x120; + if ((s32) cnt <= max && + ((s32) cnt == max || HSD_Randi(2) != 0)) { - grBigBlue_801E8978(0, NULL, NULL); - grBigBlue_801E8978(1, (void*) 1, jobj); - base->u.arwing.xC4 = 0; + grBigBlue_801E8978(2, (void*) 1, jobj); } } } - } else { - Ground* bone_ptr = base; - Ground* other = base; - s32 active_count = 0; - s32 j; - - 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 < - Stage_GetCamBoundsRightOffset()) || - (gp->u.bigblue.data[j].x2 == -1 && - gp->u.bigblue.data[j].x38.x > - Stage_GetCamBoundsLeftOffset())) - { - active_count++; - } - } else if ((s8) other_state == 1 && - gp->u.bigblue.data[j].x4 == 0) + if ((int) grBigBlue_801E89DC(1) == 0) { + u32 cnt2 = base->u.arwing.xC4; + if (yakumono_param->xDC <= (s32) cnt2 && + (s32) gp->u.bigblue.data[i].x2 == 1 && + ((s32) cnt2 >= yakumono_param->xE0 || + HSD_Randi(2) != 0)) + { + grBigBlue_801E8978(0, NULL, NULL); + grBigBlue_801E8978(1, (void*) 1, jobj); + base->u.arwing.xC4 = 0; + } + } + } + } else { + Ground* bone_ptr = base; + Ground* other = base; + s32 active_count = 0; + s32 j; + + 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 < + Stage_GetCamBoundsRightOffset()) || + (gp->u.bigblue.data[j].x2 == -1 && + gp->u.bigblue.data[j].x38.x > + Stage_GetCamBoundsLeftOffset())) { active_count++; } + } else if ((s8) other_state == 1 && + gp->u.bigblue.data[j].x4 == 0) + { + active_count++; } } + } - if (active_count <= 1) { - gp->u.bigblue.data[i].x4 = 0; - } else { - gp->u.bigblue.data[i].x4 -= 1; - } + if (active_count <= 1) { + gp->u.bigblue.data[i].x4 = 0; + } else { + gp->u.bigblue.data[i].x4 -= 1; } - } break; } + break; + } case 3: { f32 surface_y; @@ -944,7 +941,9 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) s32 sub_state = gp->u.bigblue.data[i].x2C; if (sub_state == 0 || gp->u.bigblue.data[i].x34 == 3) { - if (gp->u.bigblue.data[i].x30 == 0 && sub_state != 0) { + s32 prev_sub_state = gp->u.bigblue.data[i].x30; + + if (prev_sub_state == 0 && sub_state != 0) { gp->u.bigblue.data[i].xC.y = pos.y; gp->u.bigblue.data[i].x4 = yakumono_param->xB0; gp->u.bigblue.data[i].x34 = 1; @@ -1045,7 +1044,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) f32 prev_y = gp->u.bigblue.data[i].x28; f32 prev_x = gp->u.bigblue.data[i].x24; - if (prev_x < prev_y) { + if (prev_y > prev_x) { gp->u.bigblue.data[i].x18.z = yakumono_param->xA0 * (prev_y - prev_x); if (gp->u.bigblue.data[i].x18.z >= @@ -1587,8 +1586,8 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) Vec3 back; Vec3 normal; Vec3 euler; - Vec3 check_pos; Ground* gp = gobj->user_data; + Vec3 check_pos; u8* bp = (u8*) gp; HSD_JObj* jobj = GET_JOBJ(gobj); PAD_STACK(56); @@ -1704,25 +1703,17 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) f32 range_scale; f32 range; f32 velocity; - s32 collided; + f32 next_velocity; velocity = 140.0f * Ground_801C0498(); range_scale = Ground_801C0498(); range = (60.0f * range_scale) + 30.0f; - collided = - grBigBlue_801E8794(jobj, &pos, 1, range, velocity); - if (collided == 0) { - f32 range_scale2; - f32 range2; - f32 next_velocity; - - next_velocity = 140.0f * Ground_801C0498(); - range_scale2 = Ground_801C0498(); - range2 = (60.0f * range_scale2) + 30.0f; - collided = - grBigBlue_801EAB50(&pos, 1, range2, next_velocity); - } - if (collided != 0) { + if (grBigBlue_801E8794(jobj, &pos, 1, range, velocity) != + 0 || + grBigBlue_801EAB50( + &pos, 1, (60.0f * Ground_801C0498()) + 30.0f, + next_velocity = 140.0f * Ground_801C0498()) != 0) + { *(f32*) (bp + 0xD8) = 0.0f; } else { *(f32*) (bp + 0xD8) = yakumono_param->xD0; @@ -1783,7 +1774,6 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) } { f32 target_z; - f32 target_y; f32 diff_y; f32 vy; f32 bound_y; @@ -1831,21 +1821,19 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) *(f32*) (bp + 0xD0) = bound_y + yakumono_param->xCC; } - target_y = *(f32*) (bp + 0xD0); - (void) target_y; - diff_y = pos.y - target_y; + diff_y = pos.y - *(f32*) (bp + 0xD0); if (diff_y < 0.0f) { diff_y = -diff_y; } if (diff_y < 0.5f) { vy = 0.0f; - } else if (pos.y < target_y) { - vy = (target_y - pos.y) / yakumono_param->xE4; + } else if (pos.y < *(f32*) (bp + 0xD0)) { + vy = (*(f32*) (bp + 0xD0) - pos.y) / yakumono_param->xE4; if (vy > yakumono_param->xE8) { vy = yakumono_param->xE8; } } else { - vy = (target_y - pos.y) / yakumono_param->xEC; + vy = (*(f32*) (bp + 0xD0) - pos.y) / yakumono_param->xEC; if (vy < -yakumono_param->xF0) { vy = -yakumono_param->xF0; } @@ -1853,7 +1841,10 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) pos.y += vy; HSD_JObjAddTranslationX(jobj, *(f32*) (bp + 0xD8)); - HSD_JObjSetTranslateY(jobj, pos.y); + { + f32 translate_y = pos.y; + HSD_JObjSetTranslateY(jobj, translate_y); + } } break; } @@ -3025,6 +3016,28 @@ f32 grBigBlue_801EC58C(Vec3* pos, Vec3* normal_out, f32 half_height) #pragma push #pragma fp_contract on #endif +static inline f32 grBigBlue_801EC6C0_inline(s32 index) +{ + grBb_YakumonoParam* params; + f32 scale; + f32 result; + + params = yakumono_param; + scale = Ground_801C0498(); + result = (f32) params->x1C * scale; + scale = result / (f32) (params->x18 + 1); + result = (f32) (index + 1) * scale; + + scale = Ground_801C0498(); + params = yakumono_param; + return result + 0.5F * -((f32) params->x1C * scale); +} + +static inline f32 grBigBlue_801EC6C0_inline2(s32 k) +{ + return grBigBlue_801EC6C0_inline(k); +} + void grBigBlue_801EC6C0(Ground_GObj* gobj) { typedef struct grBb_StateBits { @@ -3094,14 +3107,7 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) idx = 0; ((grBb_ByteBits*) (car + 0xD4))->b6 = idx; - params = yakumono_param; - scale = Ground_801C0498(); - lerp = (f32) (k + 1) * - ((f32) params->x1C * scale / (f32) (params->x18 + 1)); - - scale = Ground_801C0498(); - params = yakumono_param; - *(f32*) (car + 0xE0) = lerp + 0.5F * -((f32) params->x1C * scale); + *(f32*) (car + 0xE0) = grBigBlue_801EC6C0_inline2(k); scale = Ground_801C0498(); params = yakumono_param; @@ -3113,14 +3119,7 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) *(f32*) (car + 0xE8) = 0.0F; - params = yakumono_param; - scale = Ground_801C0498(); - lerp = (f32) (k + 1) * - ((f32) params->x1C * scale / (f32) (params->x18 + 1)); - - scale = Ground_801C0498(); - params = yakumono_param; - *(f32*) (car + 0xD8) = lerp + 0.5F * -((f32) params->x1C * scale); + *(f32*) (car + 0xD8) = grBigBlue_801EC6C0_inline(k); *(f32*) (car + 0xDC) = 0.0F; @@ -3184,6 +3183,49 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) #pragma pop #endif +static inline void grBigBlue_FindClosestCar(Ground* gp, s32* found_ten, + s32* closest_lane) +{ + f32 closest_dist = F32_MAX; + f32 dist; + s32 car_idx; + u8* car_p = (u8*) gp; + s32 ctr; + s32 j; + + *found_ten = 0; + *closest_lane = -1; + car_idx = 0; + + for (ctr = 0; ctr < 2; ctr++) { + for (j = 0; j < 2; j++) { + u32 state = (car_p[0xD4] >> 2) & 0x3F; + + if (state == 10) { + *found_ten = 1; + return; + } + if (state != 1 && state != 7 && state != 8) { + dist = *(f32*) (car_p + 0xE0); + if (dist < 0.0F) { + dist = -dist; + } + if (dist > 60.0F) { + if (closest_dist > dist) { + closest_dist = dist; + *closest_lane = car_idx; + } + } else { + *found_ten = 1; + return; + } + } + car_p += 0x40; + car_idx++; + } + } +} + void grBigBlue_801ECB50(Ground_GObj* gobj) { s32 i = 0; @@ -3277,67 +3319,10 @@ void grBigBlue_801ECB50(Ground_GObj* gobj) /* Find closest car */ { u8* bp = (u8*) gp; - f32 dist; - f32 closest_dist = 3.4028235e38f; - s32 ctr = 2; - u8* car_p = (u8*) gp; - s32 found_ten = 0; - s32 closest_lane = -1; - s32 car_idx = 0; - - car_loop: { - u32 st; + s32 found_ten; + s32 closest_lane; - st = (car_p[0xD4] >> 2) & 0x3F; - if (st == 10) { - found_ten = 1; - goto car_done; - } - if (st != 1 && st != 7 && st != 8) { - dist = *(f32*) (car_p + 0xE0); - if (dist < 0.0f) { - dist = -dist; - } - if (dist > 60.0f) { - if (closest_dist > dist) { - closest_dist = dist; - closest_lane = car_idx; - } - } else { - found_ten = 1; - goto car_done; - } - } - - st = (car_p[0x114] >> 2) & 0x3F; - car_idx++; - if (st == 10) { - found_ten = 1; - goto car_done; - } - if (st != 1 && st != 7 && st != 8) { - dist = *(f32*) (car_p + 0x120); - if (dist < 0.0f) { - dist = -dist; - } - if (dist > 60.0f) { - if (closest_dist > dist) { - closest_dist = dist; - closest_lane = car_idx; - } - } else { - found_ten = 1; - goto car_done; - } - } - ctr--; - car_p += 0x80; - car_idx++; - if (ctr != 0) { - goto car_loop; - } - } - car_done: + grBigBlue_FindClosestCar(gp, &found_ten, &closest_lane); if (found_ten == 0 && closest_lane != -1) { register s32 st_val; @@ -3852,16 +3837,16 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) #pragma pop #endif -/// @todo Currently 87.41% match - compiler CSEs gp+offset into one register -/// (4 NV regs) instead of keeping them separate (5 NV regs, stmw r27) +/// @todo The remaining mismatch swaps the gp and offset registers. s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) { - grBigBlue_CarPhysics* gp; u8* self; - s32 result; s32 offset; + grBigBlue_CarPhysics* gp; + s32 result; - offset = index << 6; + offset = index; + offset <<= 6; result = 0; gp = gobj->user_data; @@ -3878,12 +3863,14 @@ s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) case 7: { f32 blast = Stage_GetBlastZoneRightOffset(); f32 scale = Ground_801C0498(); + grBigBlue_CarPhysicsLane* lane; self = gp->raw; self += offset; - if (blast + yakumono_param->x68 * scale < gp->data.lanes[index].pos.x) - { - if (0.0F != gp->data.lanes[index].xEC) { + blast += yakumono_param->x68 * scale; + lane = &gp->data.lanes[index]; + if (lane->pos.x > blast) { + if (0.0F != lane->xEC) { result = 9; } else { result = 1; @@ -3894,12 +3881,14 @@ s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) case 8: { f32 blast = Stage_GetBlastZoneLeftOffset(); f32 scale = Ground_801C0498(); + grBigBlue_CarPhysicsLane* lane; self = gp->raw; self += offset; - if (blast - yakumono_param->x68 * scale > gp->data.lanes[index].pos.x) - { - if (0.0F != gp->data.lanes[index].xEC) { + blast -= yakumono_param->x68 * scale; + lane = &gp->data.lanes[index]; + if (lane->pos.x < blast) { + if (0.0F != lane->xEC) { result = 9; } else { result = 1; @@ -4026,7 +4015,9 @@ s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) } /* Final threshold check */ - if (*(f32*) (gp->raw + offset + 0xE4) < -2000.0F) { + self = gp->raw; + self += offset; + if (*(f32*) (self + 0xE4) < -2000.0F) { result = 1; } break; @@ -4036,9 +4027,22 @@ s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) return result; } +typedef union grBb_CarStatus { + struct { + u8 state : 6; + u8 pad_0 : 2; + u8 pad_1; + } state; + struct { + u16 pad_0 : 7; + u16 lane : 5; + u16 pad_1 : 4; + } lane; +} grBb_CarStatus; + typedef struct grBb_Car { - u8 state; - u8 pad_1[3]; + grBb_CarStatus status; + u8 pad_2[2]; f32 target; f32 xDC; Vec3 pos; @@ -4055,6 +4059,7 @@ typedef struct grBb_Car { } grBb_Car; typedef union grBb_CarGround { + Ground ground; struct { u8 pad_0[0xC8]; HSD_JObj** jobjs; @@ -4069,48 +4074,46 @@ typedef union grBb_CarGround { #pragma push #pragma fp_contract on #endif -s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) +static inline void grBigBlue_801EE398_inline(s32 arg2, s32 arg1, + grBb_CarGround* gp, s32* result, + Vec3* pos) { - s32 result = 0; - Ground* gp = gobj->user_data; - Vec3 pos; + s32 slot; PAD_STACK(4); switch (arg2) { case 1: { - grBb_Car* car = &((grBb_CarGround*) gp)->typed.cars[arg1]; + grBb_Car* car = &gp->typed.cars[arg1]; - HSD_JObjSetFlagsAll( - ((grBb_CarGround*) gp)->typed.jobjs[(*(u16*) car >> 4) & 0x1F], - JOBJ_HIDDEN); + HSD_JObjSetFlagsAll(gp->typed.jobjs[(*(u16*) car >> 4) & 0x1F], + JOBJ_HIDDEN); - if (gp->u.bigblue.car.lanes[arg1].pos.x > 0.0f) { - ((grBb_CarGround*) gp)->typed.ranks[(*(u16*) car >> 4) & 0x1F] = 0; + if (gp->typed.cars[arg1].pos.x > 0.0f) { + gp->typed.ranks[(*(u16*) car >> 4) & 0x1F] = 0; } else { - ((grBb_CarGround*) gp)->typed.ranks[(*(u16*) car >> 4) & 0x1F] = 2; + gp->typed.ranks[(*(u16*) car >> 4) & 0x1F] = 2; } { typedef struct grBb_StateBits { u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - result = 1; + *result = 1; ((grBb_StateBits*) car)->state = arg2; } break; } case 10: { - grBb_Car* car = &((grBb_CarGround*) gp)->typed.cars[arg1]; - car->threshold = 0x14; + gp->typed.cars[arg1].threshold = 0x14; { typedef struct grBb_StateBits { u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - result = 1; - ((grBb_StateBits*) car)->state = arg2; + *result = 1; + ((grBb_StateBits*) &gp->typed.cars[arg1])->state = arg2; } break; } @@ -4118,12 +4121,10 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) case 2: case 3: case 4: { - f32 hi_f = yakumono_param->x60; - f32 lo_f = yakumono_param->x5C; - s32 hi = (s32) hi_f; - s32 lo = (s32) lo_f; + s32 hi = (s32) yakumono_param->x60; + s32 lo = (s32) yakumono_param->x5C; - if ((s32) lo_f > (s32) hi_f) { + if (lo > hi) { s32 diff = lo - hi; s32 rand_val; if (diff != 0) { @@ -4143,15 +4144,14 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) lo += rand_val; } { - grBb_Car* car = &((grBb_CarGround*) gp)->typed.cars[arg1]; - car->threshold = lo; + gp->typed.cars[arg1].threshold = lo; { typedef struct grBb_StateBits { u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - result = 1; - ((grBb_StateBits*) car)->state = arg2; + *result = 1; + ((grBb_StateBits*) &gp->typed.cars[arg1])->state = arg2; } } break; @@ -4160,29 +4160,30 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) case 5: { f32 blast = Stage_GetBlastZoneRightOffset(); - pos.x = (yakumono_param->x68 * Ground_801C0498()) + blast; - pos.z = 0.0f; - pos.y = 0.0f; - pos.y = grBigBlue_801EC58C(&pos, NULL, 1000.0f); + pos->x = (yakumono_param->x68 * Ground_801C0498()) + blast; + pos->z = 0.0f; + pos->y = 0.0f; + pos->y = grBigBlue_801EC58C(pos, NULL, 1000.0f); - if (-3.4028235e38f != pos.y) { + if (-3.4028235e38f != pos->y) { s32 count; s32 j; - for (j = 0, count = 0; j < 30; j++) { - if (((u8*) gp->u.bigblue.xCC)[j] == 0) { + for (count = j = 0; j < 30; j++) { + if (gp->typed.ranks[j] == 0) { count++; } } if (count != 0) { s32 pick; - s32 slot = 0; s32 offset; u8* car; u8* car_d4; Vec3* car_e0; f32* car_ec; + + slot = 0; if (count != 0) { pick = HSD_Randi(count); } else { @@ -4190,7 +4191,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } for (; slot < 30; slot++) { - if (((u8*) gp->u.bigblue.xCC)[slot] == 0) { + if (gp->typed.ranks[slot] == 0) { if (--pick < 0) { break; } @@ -4198,7 +4199,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } offset = arg1 << 6; - car = (u8*) gp + offset; + car = gp->bytes + offset; { typedef struct grBb_SlotBits { @@ -4221,11 +4222,11 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) ((grBb_DirBits*) car_d4)->dir = 0; } - *(f32*) (car + 0xE0) = pos.x; + *(f32*) (car + 0xE0) = pos->x; *(f32*) (car + 0xE4) = - (yakumono_param->x2C * Ground_801C0498()) + pos.y; + (yakumono_param->x2C * Ground_801C0498()) + pos->y; *(f32*) (car + 0xE8) = 0.0f; - *(f32*) (car + 0xD8) = pos.x; + *(f32*) (car + 0xD8) = pos->x; *(f32*) (car + 0xDC) = 0.0f; *(f32*) (car + 0xF4) = 0.0f; @@ -4238,11 +4239,9 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(f32*) (car + 0x10C) = 0.0f; { - f32 hi_f = yakumono_param->x60; - f32 lo_f = yakumono_param->x5C; - s32 hi = (s32) hi_f; - s32 lo = (s32) lo_f; - if ((s32) lo_f > (s32) hi_f) { + s32 hi = (s32) yakumono_param->x60; + s32 lo = (s32) yakumono_param->x5C; + if (lo > hi) { s32 diff = lo - hi; s32 rand_val; if (diff != 0) { @@ -4261,28 +4260,25 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } lo += rand_val; } - *(s32*) (((grBb_CarGround*) gp)->bytes + offset + 0xF0) = - lo; + *(s32*) (gp->bytes + offset + 0xF0) = lo; } - car_ec = - (f32*) (((grBb_CarGround*) gp)->bytes + offset + 0xEC); - ((u8*) gp->u.bigblue.xCC)[slot] = 1; + car_ec = (f32*) (gp->bytes + offset + 0xEC); + gp->typed.ranks[slot] = 1; *car_ec = 0.0f; { Ground_801C5440( - gp, slot, + &gp->ground, slot, ((u32*) ((u8*) grBb_803E2938 + 0x6D8))[HSD_Randi(4)]); } - Ground_801C5630(gp, arg1, *car_ec); + Ground_801C5630(&gp->ground, arg1, *car_ec); { HSD_JObj* jobj; - HSD_JObjClearFlagsAll( - ((HSD_JObj**) gp->u.bigblue.xC8)[slot], JOBJ_HIDDEN); - jobj = ((HSD_JObj**) gp->u.bigblue.xC8)[slot]; + HSD_JObjClearFlagsAll(gp->typed.jobjs[slot], JOBJ_HIDDEN); + jobj = gp->typed.jobjs[slot]; HSD_JObjSetTranslate(jobj, car_e0); } @@ -4291,7 +4287,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - result = 1; + *result = 1; ((grBb_StateBits*) car_d4)->state = arg2; } } @@ -4302,30 +4298,31 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) case 6: { f32 blast = Stage_GetBlastZoneLeftOffset(); - pos.x = -((yakumono_param->x68 * Ground_801C0498()) - blast); - pos.z = 0.0f; - pos.y = 0.0f; - pos.y = grBigBlue_801EC58C(&pos, NULL, 1000.0f); + pos->x = -((yakumono_param->x68 * Ground_801C0498()) - blast); + pos->z = 0.0f; + pos->y = 0.0f; + pos->y = grBigBlue_801EC58C(pos, NULL, 1000.0f); - if (-3.4028235e38f != pos.y) { + if (-3.4028235e38f != pos->y) { s32 count; s32 j; for (j = 0, count = 0; j < 30; j++) { - if (((u8*) gp->u.bigblue.xCC)[j] == 0) { + if (gp->typed.ranks[j] == 0) { count++; } } if (count != 0) { s32 pick; - s32 slot = 0; s32 offset; u8* car; u8* car_d4; Vec3* car_e0; f32* car_ec; + slot = 0; + if (count != 0) { pick = HSD_Randi(count); } else { @@ -4333,7 +4330,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } for (; slot < 30; slot++) { - if (((u8*) gp->u.bigblue.xCC)[slot] == 0) { + if (gp->typed.ranks[slot] == 0) { if (--pick < 0) { break; } @@ -4341,7 +4338,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } offset = arg1 << 6; - car = (u8*) gp + offset; + car = gp->bytes + offset; { typedef struct grBb_SlotBits { @@ -4364,11 +4361,11 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) ((grBb_DirBits*) car_d4)->dir = 0; } - *(f32*) (car + 0xE0) = pos.x; + *(f32*) (car + 0xE0) = pos->x; *(f32*) (car + 0xE4) = - (yakumono_param->x2C * Ground_801C0498()) + pos.y; + (yakumono_param->x2C * Ground_801C0498()) + pos->y; *(f32*) (car + 0xE8) = 0.0f; - *(f32*) (car + 0xD8) = pos.x; + *(f32*) (car + 0xD8) = pos->x; *(f32*) (car + 0xDC) = 0.0f; *(f32*) (car + 0xF4) = 0.0f; @@ -4381,11 +4378,9 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(f32*) (car + 0x10C) = 0.0f; { - f32 hi_f = yakumono_param->x60; - f32 lo_f = yakumono_param->x5C; - s32 hi = (s32) hi_f; - s32 lo = (s32) lo_f; - if ((s32) lo_f > (s32) hi_f) { + s32 hi = (s32) yakumono_param->x60; + s32 lo = (s32) yakumono_param->x5C; + if (lo > hi) { s32 diff = lo - hi; s32 rand_val; if (diff != 0) { @@ -4404,28 +4399,25 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } lo += rand_val; } - *(s32*) (((grBb_CarGround*) gp)->bytes + offset + 0xF0) = - lo; + *(s32*) (gp->bytes + offset + 0xF0) = lo; } - car_ec = - (f32*) (((grBb_CarGround*) gp)->bytes + offset + 0xEC); - ((u8*) gp->u.bigblue.xCC)[slot] = 1; + car_ec = (f32*) (gp->bytes + offset + 0xEC); + gp->typed.ranks[slot] = 1; *car_ec = 0.0f; { Ground_801C5440( - gp, slot, + &gp->ground, slot, ((u32*) ((u8*) grBb_803E2938 + 0x6D8))[HSD_Randi(4)]); } - Ground_801C5630(gp, arg1, *car_ec); + Ground_801C5630(&gp->ground, arg1, *car_ec); { HSD_JObj* jobj; - HSD_JObjClearFlagsAll( - ((HSD_JObj**) gp->u.bigblue.xC8)[slot], JOBJ_HIDDEN); - jobj = ((HSD_JObj**) gp->u.bigblue.xC8)[slot]; + HSD_JObjClearFlagsAll(gp->typed.jobjs[slot], JOBJ_HIDDEN); + jobj = gp->typed.jobjs[slot]; HSD_JObjSetTranslate(jobj, car_e0); } @@ -4434,7 +4426,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - result = 1; + *result = 1; ((grBb_StateBits*) car_d4)->state = arg2; } } @@ -4444,15 +4436,14 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) case 7: case 8: { - grBb_Car* car = &((grBb_CarGround*) gp)->typed.cars[arg1]; - car->threshold = 0x3E8; + gp->typed.cars[arg1].threshold = 0x3E8; { typedef struct grBb_StateBits { u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - result = 1; - ((grBb_StateBits*) car)->state = arg2; + *result = 1; + ((grBb_StateBits*) &gp->typed.cars[arg1])->state = arg2; } break; } @@ -4462,11 +4453,19 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) u8 state : 6; u8 pad0 : 2; } grBb_StateBits; - ((grBb_StateBits*) &((grBb_CarGround*) gp)->typed.cars[arg1])->state = - arg2; + ((grBb_StateBits*) &gp->typed.cars[arg1])->state = arg2; break; } } +} + +s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) +{ + s32 result = 0; + grBb_CarGround* gp = gobj->user_data; + Vec3 pos; + + grBigBlue_801EE398_inline(arg2, arg1, gp, &result, &pos); return result; } diff --git a/src/melee/gr/grbigblueroute.c b/src/melee/gr/grbigblueroute.c index 18fb4ff1c0..06cf237800 100644 --- a/src/melee/gr/grbigblueroute.c +++ b/src/melee/gr/grbigblueroute.c @@ -47,6 +47,12 @@ struct grBigBlueRoute_8020DA9C_t { /* +8 */ int x8; }; +/* car_info stores 31 RouteEntry records in its 0x554-byte allocation. */ +union grBigBlueRoute_RouteStorage { + RouteEntry entries[31]; + u8 bytes[0x554]; +}; + /* 20DA9C */ static int grBigBlueRoute_8020DA9C(struct grBigBlueRoute_8020DA9C_t*); @@ -558,20 +564,21 @@ s32 grBigBlueRoute_8020C530(Ground_GObj* arg0) HSD_ASSERT(0X2E5, 0); } -/// @todo Register allocation and addressing-mode choices for RouteEntry -/// stores. +/// @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 void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, Ground_GObj* gobj) { - PAD_STACK(8); - if (route_idx == 0) { route_idx = 30; ((RouteEntry*) gp->u.car.car_info)[30].flags.b1 = 1; gp->u.car.x10A = yakumono_param->x4C; } else { - s32 max_val; s32 min_val; + s32 max_val; s32 new_timer; route_idx = grBigBlueRoute_8020C530(gobj); @@ -594,46 +601,47 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, } if (route_idx != -1) { - // probably an inline of some sort - RouteEntry* re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + s32 route = route_idx; + s32 offset = route * sizeof(RouteEntry); + RouteEntry* re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); - (&((RouteEntry*) gp->u.car.car_info)[route_idx])->flags.b0 = 1; - (&((RouteEntry*) gp->u.car.car_info)[route_idx])->flags.b6 = 0; - (&((RouteEntry*) gp->u.car.car_info)[route_idx])->flags.b2_5 = 1; + GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset)->flags.b0 = 1; + GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset)->flags.b6 = 0; + GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset)->flags.b2_5 = 1; - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->x4 = 1.0F; - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->x8 = yakumono_param->x20; - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->xC = 0.5F; { f32 rand = HSD_Randf(); - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->x10 = rand; } - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->x14 = 0.0F; - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); re->x18 = yakumono_param->x3C; - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); (void) re; re->x1C = 0.0F; { f32 rand = HSD_Randf(); - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + re = GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset); (void) re; re->x20 = 5.2359877f * rand - 2.6179938f; } - if (!((RouteEntry*) gp->u.car.car_info)[route_idx].flags.b1) { + if (!GRBB_ROUTE_ENTRY_AT(gp->u.car.car_info, offset)->flags.b1) { HSD_JObj* root = gobj->hsd_obj; if (root != NULL) { HSD_JObj* jobj; @@ -645,12 +653,12 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, if (jobj != NULL) { s32 i = 0; - while (i < route_idx && jobj != NULL) { + while (i < route && jobj != NULL) { i++; - if (jobj != NULL) { - jobj = jobj->next; - } else { + if (jobj == NULL) { jobj = NULL; + } else { + jobj = jobj->next; } } @@ -666,24 +674,28 @@ static inline void grBigBlueRoute_SpawnRoute(s32 route_idx, Ground* gp, 0, 1, gp, jobj, (void (*)(Item_GObj*, Ground*)) fn_8020DEAC, NULL, NULL); - re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; + 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); grMaterial_801C8E28((HSD_GObj*) re->x28); } } } } + (void) re; } } gp->u.car.x108++; } +#undef GRBB_ROUTE_ENTRY_AT void grBigBlueRoute_8020C85C(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); - PAD_STACK(8); + Ground* spawn_gp = gobj->user_data; if (!((f32) gp->u.car.x108 < 1.0f + yakumono_param->x40)) { return; @@ -693,7 +705,7 @@ void grBigBlueRoute_8020C85C(Ground_GObj* gobj) return; } - grBigBlueRoute_SpawnRoute(gp->u.car.x108, gp, gobj); + grBigBlueRoute_SpawnRoute(gp->u.car.x108, spawn_gp, gobj); } static const Vec3 grBb_Route_803B83E0 = { 0.0f, 1.0f, 0.0f }; diff --git a/src/melee/gr/grgreens.c b/src/melee/gr/grgreens.c index acef02c091..591c6fb55f 100644 --- a/src/melee/gr/grgreens.c +++ b/src/melee/gr/grgreens.c @@ -1083,27 +1083,24 @@ void fn_802159B4(Item_GObj* item_gobj, Ground* gp) return; } -static inline Item_GObj* getBlockItemGObj(Ground* gp, int i, int j) -{ - return gp->u.greens.x8_blocks[j][i].x10; -} - void grGreens_802159B8(Ground* gp, int i, int j, int value) { - HSD_GObj* gobj = getBlockItemGObj(gp, i, j); UNUSED u8 pad[8]; Vec vec; + Item_GObj* gobj; float f; PAD_STACK(0x10); - - if (gobj != NULL && !gp->u.greens.x8_blocks[j][i].x1_7) { + if ((gobj = gp->u.greens.x8_blocks[j][i].x10) && + !gp->u.greens.x8_blocks[j][i].x1_7) + { gp->u.greens.x8_blocks[j][i].x1_7 = 1; grMaterial_801C8E28(gobj); gp->u.greens.x8_blocks[j][i].x1C = value; if (gp->u.greens.x8_blocks[j][i].x1_1) { - HSD_JObjSetFlagsAll(gp->u.greens.x8_blocks[j][i].xC->hsd_obj, - JOBJ_HIDDEN); + HSD_JObj* jobj = gp->u.greens.x8_blocks[j][i].xC->hsd_obj; + + HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); grMaterial_801C8D98(gobj, 1); it_80275414(gobj); gp->u.greens.x8_blocks[j][i].x1_2 = 1; @@ -1278,9 +1275,9 @@ void grGreens_80215ED8(Ground_GObj* gobj, int col, int row) break; } pos.x = (gp->u.greens.x4 + next_row * 6)[col].x; - pos.y = (gp->u.greens.x4 + next_row * 6)[col].y - - (gp->u.greens.x4 + next_row * 6 - 6)[col].y + - gp->u.greens.x8_blocks[next_row - 1][col].x8; + scale = (gp->u.greens.x4 + next_row * 6)[col].y - + (gp->u.greens.x4 + next_row * 6 - 6)[col].y; + pos.y = scale + gp->u.greens.x8_blocks[next_row - 1][col].x8; pos.z = 0.0f; gp->u.greens.x8_blocks[next_row][col].x8 = pos.y; HSD_JObjSetTranslate( diff --git a/src/melee/gr/grinishie1.c b/src/melee/gr/grinishie1.c index a896e55541..bb50645b6b 100644 --- a/src/melee/gr/grinishie1.c +++ b/src/melee/gr/grinishie1.c @@ -633,6 +633,21 @@ typedef struct grInishie1_801FB3F0_Vars { grInishie1_801FB3F0_Block* blocks; } grInishie1_801FB3F0_Vars; +static inline void set_all_hatena(HSD_GObj* gobj, + grInishie1_801FB3F0_Vars* vars) +{ + u32 i = 0; + + vars->xC8 = 0; + vars->xC6 = 0; + + for (; i < 0x13; ++i) { + vars->blocks[i].x0 = 3; + grInishie1_801FBAA0(gobj, i); + vars->blocks[i].x20 = 0; + } +} + static inline void grInishie1_801FB3F0_update_blocks(HSD_GObj* gobj, grInishie1_801FB3F0_Vars* vars, Vec3* pos) @@ -730,7 +745,6 @@ grInishie1_801FB3F0_update_blocks(HSD_GObj* gobj, void grInishie1_801FB3F0(HSD_GObj* gobj) { grInishie1_801FB3F0_Vars* vars = gobj->user_data; - u32 i; Vec3 pos; PAD_STACK(48); @@ -743,16 +757,9 @@ void grInishie1_801FB3F0(HSD_GObj* gobj) (vars->xC8 == 1 && vars->xC6 > 0 && vars->xC6 < yakumono_param->unk14))) { - vars->xC8 = 0; - vars->xC6 = 0; - // this is likely the rare case mentioned on smashwiki // where every block will become a hatena block - for (i = 0; i < 0x13; ++i) { - vars->blocks[i].x0 = 3; - grInishie1_801FBAA0(gobj, i); - vars->blocks[i].x20 = 0; - } + set_all_hatena(gobj, vars); } else { HATENA_APPEAR_CHECKLOOP(vars->xC6, vars->xCA, 1, 0x2D0U); HATENA_APPEAR_CHECKLOOP(vars->xC8, vars->xCC, 2, 0x2EBU); diff --git a/src/melee/gr/grmutecity.c b/src/melee/gr/grmutecity.c index e15cd0f175..409f0ba802 100644 --- a/src/melee/gr/grmutecity.c +++ b/src/melee/gr/grmutecity.c @@ -1455,11 +1455,34 @@ 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); +} + +static inline f32 grMc_Sqrtf(f32 x, volatile f32* result) +{ + if (x > 0.0f) { + f64 guess = __frsqrte((f64) x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + *result = (f32) (x * guess); + return *result; + } + return x; +} + void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) { Vec3 car_pos; Vec3 spE8; - UNUSED u8 padE4[4]; + f32 track_mid; Vec3 spD8; Vec3 spCC; Vec3 spC0; @@ -1468,6 +1491,7 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) Vec3 sp9C; Vec3 sp90; Vec3 spawn_pos; + f32 distance; Vec3 sp74; Vec3 sp68; Vec3 sp5C; @@ -1476,23 +1500,24 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) Vec3 sp38; Vec3 sp2C; Vec3 sp20; - f32 sp1C; - s32 var_r26 = 0; - Ground* car_gp = arg0->user_data; - Ground* gp = arg1->user_data; - HSD_JObj* car_jobj = arg0->hsd_obj; + f32 sqrt_tmp[4]; + Ground* car_gp; + Ground* gp; + HSD_JObj* car_jobj; HSD_JObj* jobj; - HSD_JObj* var_r20; + HSD_JObj* child_jobj; s32 car_idx; - grMc_CarEntry* car; - f32 track_mid; - f32 var_f31; - f32 var_f21; + s32 sound_count; + f32 spline_t; + f32 wrapped_t; HSD_Spline* spline; + sound_count = 0; + car_gp = arg0->user_data; + gp = arg1->user_data; + car_jobj = arg0->hsd_obj; Ground_801C0498(); - PAD_STACK(12); - track_mid = 0.5f * (gp->u.mutecity.xD4 + gp->u.mutecity.xD8); + track_mid = grMc_GetTrackMidpoint(gp); Camera_GetTransformPosition(&spE8); jobj = car_jobj == NULL ? NULL : car_jobj->child; @@ -1505,34 +1530,33 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) } car_idx = 0; - car = grMc_8049F4B8; do { - car->x4 += car->x8; - car->x0 += car->x8; + grMc_8049F4B8[car_idx].x4 += grMc_8049F4B8[car_idx].x8; + grMc_8049F4B8[car_idx].x0 += grMc_8049F4B8[car_idx].x8; { - f32 p = car->x4; + f32 p = grMc_8049F4B8[car_idx].x4; if (p > 1.0f) { - car->x4 = p - 1.0f; + grMc_8049F4B8[car_idx].x4 = p - 1.0f; } } - var_f31 = car->x4; + spline_t = grMc_8049F4B8[car_idx].x4; spline = gp->u.mutecity.xE0->u.spline; - if (var_f31 > 0.93f) { - var_f21 = var_f31 - 0.93f; - } else if (var_f31 < 0.01f) { - var_f21 = 0.06999999f + var_f31; + if (spline_t > 0.93f) { + wrapped_t = spline_t - 0.93f; + } else if (spline_t < 0.01f) { + wrapped_t = 0.06999999f + spline_t; } else { - splGetSplinePoint(&spD8, spline, var_f31); + splGetSplinePoint(&spD8, spline, spline_t); goto block_13_done; } splGetSplinePoint(&sp68, spline, 0.93f); splGetSplinePoint(&sp74, spline, 0.01f); lbVector_Sub(&sp74, &sp68); { - f32 ratio = var_f21 / 0.07999999f; + f32 ratio = wrapped_t / 0.07999999f; sp74.x *= ratio; sp74.y *= ratio; sp74.z *= ratio; @@ -1543,19 +1567,19 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) lb_8000B1CC(gp->u.mutecity.xE0, &spD8, &spCC); spline = gp->u.mutecity.xDC->u.spline; - if (var_f31 > 0.93f) { - var_f21 = var_f31 - 0.93f; - } else if (var_f31 < 0.01f) { - var_f21 = 0.06999999f + var_f31; + if (spline_t > 0.93f) { + wrapped_t = spline_t - 0.93f; + } else if (spline_t < 0.01f) { + wrapped_t = 0.06999999f + spline_t; } else { - splGetSplinePoint(&spD8, spline, var_f31); + splGetSplinePoint(&spD8, spline, spline_t); goto block_19_done; } splGetSplinePoint(&sp50, spline, 0.93f); splGetSplinePoint(&sp5C, spline, 0.01f); lbVector_Sub(&sp5C, &sp50); { - f32 ratio = var_f21 / 0.07999999f; + f32 ratio = wrapped_t / 0.07999999f; sp5C.x *= ratio; sp5C.y *= ratio; sp5C.z *= ratio; @@ -1568,24 +1592,24 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) lbVector_Diff(&spC0, &spCC, &spB4); lbVector_Normalize(&spB4); - if (var_f31 > 0.827f && var_f31 < 0.914f) { - var_f31 = 0.0f; + if (spline_t > 0.827f && spline_t < 0.914f) { + spline_t = 0.0f; } spline = gp->u.mutecity.xE0->u.spline; - if (var_f31 > 0.93f) { - var_f21 = var_f31 - 0.93f; - } else if (var_f31 < 0.01f) { - var_f21 = 0.06999999f + var_f31; + if (spline_t > 0.93f) { + wrapped_t = spline_t - 0.93f; + } else if (spline_t < 0.01f) { + wrapped_t = 0.06999999f + spline_t; } else { - lbShadow_8000E9F0(&spA8, spline, var_f31); + lbShadow_8000E9F0(&spA8, spline, spline_t); goto block_28_done; } lbShadow_8000E9F0(&sp38, spline, 0.93f); lbShadow_8000E9F0(&sp44, spline, 0.01f); lbVector_Sub(&sp44, &sp38); { - f32 ratio = var_f21 / 0.07999999f; + f32 ratio = wrapped_t / 0.07999999f; sp44.x *= ratio; sp44.y *= ratio; sp44.z *= ratio; @@ -1594,24 +1618,24 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) spA8 = sp44; block_28_done: lb_8000B1CC(gp->u.mutecity.xE0, &spA8, &spA8); - lb_8000B1CC(gp->u.mutecity.xE0, NULL, &spD8); + lb_8000B1CC(grMc_GetRightSplineJoint(gp), NULL, &spD8); lbVector_Sub(&spA8, &spD8); lbVector_Normalize(&spA8); spline = gp->u.mutecity.xDC->u.spline; - if (var_f31 > 0.93f) { - var_f21 = var_f31 - 0.93f; - } else if (var_f31 < 0.01f) { - var_f21 = 0.06999999f + var_f31; + if (spline_t > 0.93f) { + wrapped_t = spline_t - 0.93f; + } else if (spline_t < 0.01f) { + wrapped_t = 0.06999999f + spline_t; } else { - lbShadow_8000E9F0(&sp9C, spline, var_f31); + lbShadow_8000E9F0(&sp9C, spline, spline_t); goto block_34_done; } lbShadow_8000E9F0(&sp20, spline, 0.93f); lbShadow_8000E9F0(&sp2C, spline, 0.01f); lbVector_Sub(&sp2C, &sp20); { - f32 ratio = var_f21 / 0.07999999f; + f32 ratio = wrapped_t / 0.07999999f; sp2C.x *= ratio; sp2C.y *= ratio; sp2C.z *= ratio; @@ -1631,10 +1655,13 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) PSVECCrossProduct(&spB4, &sp90, &spA8); lbVector_Normalize(&spA8); - car_pos.x = (3.0 * sp90.x) + (((spC0.x - spCC.x) * car->xC) + spCC.x); - car_pos.y = (3.0 * sp90.y) + (((spC0.y - spCC.y) * car->xC) + spCC.y); - car_pos.z = (3.0 * sp90.z) + (((spC0.z - spCC.z) * car->xC) + spCC.z); - *(Vec3*) &car->x14 = car_pos; + car_pos.x = (3.0 * sp90.x) + + (((spC0.x - spCC.x) * grMc_8049F4B8[car_idx].xC) + spCC.x); + car_pos.y = (3.0 * sp90.y) + + (((spC0.y - spCC.y) * grMc_8049F4B8[car_idx].xC) + spCC.y); + car_pos.z = (3.0 * sp90.z) + + (((spC0.z - spCC.z) * grMc_8049F4B8[car_idx].xC) + spCC.z); + *(Vec3*) &grMc_8049F4B8[car_idx].x14 = car_pos; HSD_JObjSetTranslate(jobj, &car_pos); @@ -1644,18 +1671,18 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) HSD_JObjSetRotationZ(jobj, spD8.z); { - u16 flags20 = car->x20; + u16 flags20 = grMc_8049F4B8[car_idx].x20; if ((flags20 & 8) && (flags20 & 2) && car_gp->u.mutecity.xC4 == 0) { grLib_801C96F8(0x11A, 0, &car_pos); - if (var_r26 < 1) { + if (sound_count < 1) { if (car_pos.z < 0.0f) { - var_f31 = (car_pos.z * car_pos.z) + - ((car_pos.x * car_pos.x) + - (car_pos.y * car_pos.y)); - sp1C = sqrtf(var_f31); - var_f31 = sp1C; - if (var_f31 < 300.0f) { + spline_t = (car_pos.z * car_pos.z) + + ((car_pos.x * car_pos.x) + + (car_pos.y * car_pos.y)); + distance = grMc_Sqrtf(spline_t, &sqrt_tmp[3]); + spline_t = distance; + if (spline_t < 300.0f) { switch (HSD_Randi(3)) { case 0: Ground_801C5440(car_gp, 0, 0x5CC69); @@ -1668,8 +1695,8 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) break; } Ground_801C5630(car_gp, 0, - 1.0f - (var_f31 / 300.0f)); - var_r26 += 1; + 1.0f - (spline_t / 300.0f)); + sound_count += 1; } } car_gp->u.mutecity.xC4 = 7; @@ -1678,17 +1705,16 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) } { - f32 age = car->x10; + f32 age = grMc_8049F4B8[car_idx].x10; if (age > yakumono_param->x30) { - if (!car->x22_flags.b0) { + if (!grMc_8049F4B8[car_idx].x22_flags.b0) { grLib_801C98A0(jobj); - var_r20 = NULL; - car->x28 = 0; + grMc_8049F4B8[car_idx].x28 = (s32) (child_jobj = NULL); grLib_801C96F8(0xE3, 0, &car_pos); if (jobj != NULL) { - var_r20 = jobj->child; + child_jobj = jobj->child; } - HSD_JObjUnref(var_r20); + HSD_JObjUnref(child_jobj); { HSD_JObj* new_jobj = Ground_801C13D0(5, 0); if (new_jobj != NULL) { @@ -1700,20 +1726,22 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) HSD_JObjSetTranslate(new_jobj, &spawn_pos); } } - if ((u32) car->x24 != 0) { - grMaterial_801C8CDC((HSD_GObj*) car->x24); - car->x24 = 0; + if ((u32) grMc_8049F4B8[car_idx].x24 != 0) { + grMaterial_801C8CDC( + (HSD_GObj*) grMc_8049F4B8[car_idx].x24); + grMc_8049F4B8[car_idx].x24 = 0; } - car->x22_flags.b0 = 1; + grMc_8049F4B8[car_idx].x22_flags.b0 = 1; } - } else if (age > yakumono_param->x2C && (u32) car->x28 == 0) { - grMuteCity_801F2AB0(0x116, jobj); - car->x28 = (s32) jobj; + } else if (age > yakumono_param->x2C && + (u32) grMc_8049F4B8[car_idx].x28 == 0) + { + grMc_8049F4B8[car_idx].x28 = grMuteCity_801F2AB0(0x116, jobj); } } - if (!car->x22_flags.b0) { - f32 rel_t = car->x4; + if (!grMc_8049F4B8[car_idx].x22_flags.b0) { + f32 rel_t = grMc_8049F4B8[car_idx].x4; f32 dist_t; if (track_mid < rel_t) { dist_t = (1.0f + track_mid) - rel_t; @@ -1727,7 +1755,7 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) -1350.0f < car_pos.z && car_pos.z < 50.0f) { Camera_80030E44(1, NULL); - if (!car->x22_flags.b1) { + if (!grMc_8049F4B8[car_idx].x22_flags.b1) { if (gp->u.mutecity.xD0_flags.b1) { switch (HSD_Randi(3)) { case 0: @@ -1753,11 +1781,11 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) break; } } - car->x22_flags.b1 = 1; + grMc_8049F4B8[car_idx].x22_flags.b1 = 1; } } else { - if (car->x22_flags.b1) { - car->x22_flags.b1 = 0; + if (grMc_8049F4B8[car_idx].x22_flags.b1) { + grMc_8049F4B8[car_idx].x22_flags.b1 = 0; } } } @@ -1766,7 +1794,9 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) -200.0f < car_pos.y && car_pos.y < 200.0f && -100.0f < car_pos.z && car_pos.z < 50.0f) { - if (!car->x22_flags.b0 && (u32) car->x24 == 0) { + if (!grMc_8049F4B8[car_idx].x22_flags.b0 && + (u32) grMc_8049F4B8[car_idx].x24 == 0) + { Item_GObj* item_gobj = grMaterial_801C8CFC( 0, 2, car_gp, jobj, grMuteCity_801F1A0C, ((grMc_SpeedFn*) grMc_803E3C6C)[car_idx], NULL); @@ -1774,30 +1804,29 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) grMaterial_801C8DE0(item_gobj, 0.0f, 0.0f, -12.0f, 0.0f, 0.0f, 2.0f, 15.0f); grMaterial_801C8E08(item_gobj); - car->x24 = (s32) item_gobj; + grMc_8049F4B8[car_idx].x24 = (s32) item_gobj; } } } else { - if ((u32) car->x24 != 0) { - grMaterial_801C8CDC((HSD_GObj*) car->x24); - car->x24 = 0; + if ((u32) grMc_8049F4B8[car_idx].x24 != 0) { + grMaterial_801C8CDC( + (HSD_GObj*) grMc_8049F4B8[car_idx].x24); + grMc_8049F4B8[car_idx].x24 = 0; } } } else { if (car_pos.z > spE8.z || car_pos.z > 5000.0f || car_pos.z < -1500.0f) { - if ((u32) car->x28 != 0) { + if ((u32) grMc_8049F4B8[car_idx].x28 != 0) { grLib_801C98A0(jobj); - car->x28 = 0; + grMc_8049F4B8[car_idx].x28 = 0; } - } else if ((u32) car->x28 == 0) { - grMuteCity_801F2AB0(0x119, jobj); - car->x28 = (s32) jobj; + } else if ((u32) grMc_8049F4B8[car_idx].x28 == 0) { + grMc_8049F4B8[car_idx].x28 = grMuteCity_801F2AB0(0x119, jobj); } } - car++; car_idx += 1; jobj = jobj == NULL ? NULL : jobj->next; } while (car_idx < 0x1E); @@ -1892,7 +1921,7 @@ void grMuteCity_801F290C(Ground_GObj* gobj) grMc_StackPad(*(grMc_StackPadArg*) gp->u.mutecity2.saved_colors); } -void grMuteCity_801F2AB0(s32 arg0, HSD_JObj* arg1) +s32 grMuteCity_801F2AB0(s32 arg0, HSD_JObj* arg1) { HSD_Generator* gen; HSD_psAppSRT* appsrt; diff --git a/src/melee/gr/grmutecity.h b/src/melee/gr/grmutecity.h index b8f11455bd..2f0cbeb68a 100644 --- a/src/melee/gr/grmutecity.h +++ b/src/melee/gr/grmutecity.h @@ -72,7 +72,7 @@ /* 1F1A34 */ void grMuteCity_801F1A34(HSD_GObj*, Ground_GObj*); /* 1F28A8 */ DynamicModelDesc* grMuteCity_801F28A8(void); /* 1F290C */ void grMuteCity_801F290C(Ground_GObj*); -/* 1F2AB0 */ void grMuteCity_801F2AB0(s32, HSD_JObj*); +/* 1F2AB0 */ s32 grMuteCity_801F2AB0(s32, HSD_JObj*); /* 1F2BBC */ DynamicsDesc* grMuteCity_801F2BBC(enum_t); /* 1F2C10 */ bool grMuteCity_801F2C10(Vec3*, int arg, HSD_JObj* jobj); /* 3E33DC */ extern StageData grMc_StageData; diff --git a/src/melee/gr/grzebes.c b/src/melee/gr/grzebes.c index 1b1163967b..f9c17c3f70 100644 --- a/src/melee/gr/grzebes.c +++ b/src/melee/gr/grzebes.c @@ -385,21 +385,21 @@ Vec3 grZe_803E1C80[8] = { void grZebes_801D881C(HSD_GObj* gobj) { - Vec3 sp80; - Vec3 sp74; - f32 col_x[6]; + f32 intercept; + Vec3 spot_pos; + Vec3 spot_interest; + Vec3 lower_point_pos; + f32 slope; f32 col_heights[6]; - Vec3 sp28; - Vec3 sp1C; - f32 sp18; - f32 sp14; - HSD_GObj* secondary_gobj; - s32 popped; + f32 col_x[6]; + Vec3 upper_point_pos; + f32* heights; Ground* gp = GET_GROUND(gobj); + HSD_GObj* secondary_gobj; s32 result; secondary_gobj = (HSD_GObj*) gp->u.zebes5.xF0; result = grZebes_801DA528(gobj, &gp->u.zebes5.xC8, 1, 2); - PAD_STACK(4); + PAD_STACK(0xC); if ((s32) gp->u.zebes5.xEC != result) { gp->u.zebes5.xEC = result; @@ -427,14 +427,14 @@ void grZebes_801D881C(HSD_GObj* gobj) } { - popped = grZebes_801DB3CC(gobj); + result = grZebes_801DB3CC(gobj); grZebes_801DC260(); grZebes_801DBB60((HSD_GObj*) gp->u.zebes5.x100); grZebes_801DC408(gobj); switch (gp->u.zebes5.xC4) { case 0: - if (popped != 0) { + if (result != 0) { gp->u.zebes5.xC4 = 1; grAnime_801C8098(gobj, 0xE, 1, 3, 0.0f, 1.0f); grAnime_801C7980(gobj, 0xE, 1U); @@ -482,10 +482,13 @@ void grZebes_801D881C(HSD_GObj* gobj) f32 scale_min = yakumono_param->x58; grZe_BubbleSpawnPos* pos = (grZe_BubbleSpawnPos*) grZe_8049F140; - grZebes_801DAE70(spawn_phase, 4, pos[spawn_phase].x14_x, - pos[spawn_phase].x18_y, - (yakumono_param->x5C - scale_min) * rand + - scale_min); + { + f32 scale_range = yakumono_param->x5C - scale_min; + grZebes_801DAE70(spawn_phase, 4, + pos[spawn_phase].x14_x, + pos[spawn_phase].x18_y, + scale_range * rand + scale_min); + } } if (spawn_phase <= mirror) { f32 rand2 = HSD_Randf(); @@ -510,26 +513,26 @@ void grZebes_801D881C(HSD_GObj* gobj) } } - sp80 = grZe_803B7FF0.spot_pos; - sp74 = grZe_803B7FF0.spot_interest; + spot_pos = grZe_803B7FF0.spot_pos; + spot_interest = grZe_803B7FF0.spot_interest; { HSD_JObj* jobj = Ground_801C3FA4(gobj, 0xE); if (jobj != NULL) { - lb_8000B1CC(jobj, &sp80, &grZe_8049F158[0]); - lb_8000B1CC(jobj, &sp74, &grZe_8049F140[0]); + lb_8000B1CC(jobj, &spot_pos, &grZe_8049F158[0]); + lb_8000B1CC(jobj, &spot_interest, &grZe_8049F140[0]); } } if (gp->u.zebes5.xC4 == 0) { int i; f32 colWidth; - f32 left_x; + grZe_BubbleState* state = (grZe_BubbleState*) grZe_8049F140; mpJointListAdd(0); mpLib_80057424(0); - colWidth = (grZe_8049F140[1].x - grZe_8049F140[0].x) / 5.0f; - left_x = grZe_8049F140[0].x; + colWidth = (state->positions[1].x - state->positions[0].x) / 5.0f; + heights = col_heights; col_heights[0] = -9999.0f; col_heights[1] = -9999.0f; @@ -541,15 +544,16 @@ void grZebes_801D881C(HSD_GObj* gobj) (void) 0.9; { - int j; - grZe_BubbleEntry* entry = grZe_8049F170; - for (j = 0; j < 20; j++, entry++) { + f32 left_x = state->positions[0].x; + grZe_BubbleEntry* entry = state->bubbles; + for (i = 0; i < 20; i++, entry++) { if (entry->x00_active == 1) { f32 dx = entry->x08_x - left_x; + f32 left_frac = (f32) ((f64) dx - 0.9) / colWidth; + f32 right_frac = (f32) (0.9 + (f64) dx); f32 top = (f32) (1.8 * (f64) entry->x18_size + (f64) entry->x0C_y); { - f32 left_frac = (f32) ((f64) dx - 0.9) / colWidth; s32 col_left = (s32) (0.5 + (f64) left_frac); if (5 < col_left) { col_left = 5; @@ -562,8 +566,8 @@ void grZebes_801D881C(HSD_GObj* gobj) } } { - f32 right_frac = (f32) (0.9 + (f64) dx) / colWidth; - s32 col_right = (s32) (0.5 + (f64) right_frac); + s32 col_right = + (s32) (0.5 + (f64) (right_frac / colWidth)); if (5 < col_right) { col_right = 5; } else if (col_right < 0) { @@ -578,46 +582,44 @@ void grZebes_801D881C(HSD_GObj* gobj) } } - sp28 = grZe_803B7FF0.upper_point_pos; - sp1C = grZe_803B7FF0.lower_point_pos; + upper_point_pos = grZe_803B7FF0.upper_point_pos; + lower_point_pos = grZe_803B7FF0.lower_point_pos; { HSD_JObj* sima_jobj; sima_jobj = Ground_801C3FA4(gobj, 0xE); HSD_ASSERT(0x293, sima_jobj); - lb_8000B1CC(sima_jobj, &sp28, &sp28); + lb_8000B1CC(sima_jobj, &upper_point_pos, &upper_point_pos); } - col_x[0] = sp28.x; - col_heights[0] = sp28.y; + col_x[0] = upper_point_pos.x; + col_heights[0] = upper_point_pos.y; { HSD_JObj* sima_jobj; sima_jobj = Ground_801C3FA4(secondary_gobj, 1); HSD_ASSERT(0x299, sima_jobj); - lb_8000B1CC(sima_jobj, &sp1C, &sp1C); + lb_8000B1CC(sima_jobj, &lower_point_pos, &lower_point_pos); } - col_x[5] = sp1C.x; - col_heights[5] = sp1C.y; + col_x[5] = lower_point_pos.x; + col_heights[5] = lower_point_pos.y; for (i = 0; i < 5; i++) { if (i != 0) { - f32 limit = col_heights[i + 1] - colWidth; - if (limit > col_heights[i]) { - col_heights[i] = limit; + if (heights[i] < heights[i + 1] - colWidth) { + heights[i] = heights[i + 1] - colWidth; } } if (i != 5) { - f32 limit = col_heights[i] - colWidth; - if (col_heights[i + 1] < limit) { - col_heights[i + 1] = limit; + if (heights[i + 1] < heights[i] - colWidth) { + heights[i + 1] = heights[i] - colWidth; } } } { int k; - for (k = 0; k <= 5; k++) { - mpVtxSetPos(k, col_x[k], col_heights[k]); + for (i = 0, k = 0; i <= 5; i++, k++) { + mpVtxSetPos(k, col_x[i], col_heights[i]); } } mpLib_80055E24(0); @@ -625,9 +627,9 @@ void grZebes_801D881C(HSD_GObj* gobj) mpLib_80057BC0(0); } - Ground_801C4368(&sp18, &sp14); + Ground_801C4368(&slope, &intercept); grZakoGenerator_801CA43C((grZakoGenerator_Config*) gp->u.zebes5.xFC, - Ground_801C3FA4(gobj, 0xE), sp18); + Ground_801C3FA4(gobj, 0xE), slope); Ground_801C2FE0((Ground_GObj*) gobj); lb_800115F4(); } @@ -1538,173 +1540,254 @@ void grZebes_801DAE70(s32 arg0, u8 arg1, f32 x, f32 y, f32 scale) } } +static inline Ground* grZebes_801DB088_GetGround(HSD_GObj* gobj) +{ + return GET_GROUND(gobj); +} + +static inline s16 grZebes_801DB088_GetTimer(s32 arg1) +{ + return grZe_8049F170[arg1].x02_timer; +} + s32 grZebes_801DB088(Ground* gp, s32 arg1) { - u8 _[0x38]; - grZe_BubbleEntry* entry = &grZe_8049F170[arg1]; s32 result = 0; - if (entry->x00_active != 0) { - HSD_GObj** gobjp = - &((grZe_BubbleState*) grZe_8049F140)->bubbles[arg1].x20_gobj; - HSD_GObj* gobj = *gobjp; + if (grZe_8049F170[arg1].x00_active != 0) { + HSD_GObj* gobj = grZe_8049F170[arg1].x20_gobj; if (gobj != NULL) { - Ground* bgp = GET_GROUND(gobj); + Ground* bgp = grZebes_801DB088_GetGround(gobj); if (bgp != NULL) { - Item_GObj* mat = bgp->u.zebes3.xC4; - - if (mat != NULL) { - if (entry->x00_active == 1) { - grMaterial_801C8E08(mat); + if (bgp->u.zebes3.xC4 != NULL) { + if (grZe_8049F170[arg1].x00_active == 1) { + grMaterial_801C8E08(bgp->u.zebes3.xC4); } else { - grMaterial_801C8E28(mat); + grMaterial_801C8E28(bgp->u.zebes3.xC4); } } { - f32* targetp = &((grZe_BubbleState*) grZe_8049F140) - ->bubbles[arg1] - .x1C; f32 speed = yakumono_param->x68; - f32* sizep = &((grZe_BubbleState*) grZe_8049F140) - ->bubbles[arg1] - .x18_size; - f32 target = *targetp; - f32 current = *sizep; + f32 target_value = grZe_8049F170[arg1].x1C; + f32 target = target_value; + f32 current = grZe_8049F170[arg1].x18_size; f32 diff = target - current; if (diff > speed) { - *sizep = current + speed; + grZe_8049F170[arg1].x18_size = current + speed; } else if (diff < -speed) { - *sizep = current - speed; + grZe_8049F170[arg1].x18_size = current - speed; } else { - *sizep = target; + grZe_8049F170[arg1].x18_size = target; } + if (grZe_8049F170[arg1].x04 != NULL && + grAnime_801C83D0(grZe_8049F170[arg1].x20_gobj, 0, 7) != + 0) { - HSD_JObj** jobjp = &((grZe_BubbleState*) grZe_8049F140) - ->bubbles[arg1] - .x04; - - if (*jobjp != NULL && - grAnime_801C83D0(*gobjp, 0, 7) != 0) - { - HSD_JObjRemoveAll(*jobjp); - *jobjp = NULL; - { - HSD_JObj* jobj = GET_JOBJ(*gobjp); - if (jobj != NULL) { - HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); - } - } + HSD_JObj* jobj = grZe_8049F170[arg1].x04; + HSD_JObjRemoveAll(jobj); + grZe_8049F170[arg1].x04 = NULL; + if (GET_JOBJ(grZe_8049F170[arg1].x20_gobj) != NULL) { + HSD_JObjClearFlagsAll( + GET_JOBJ(grZe_8049F170[arg1].x20_gobj), + JOBJ_HIDDEN); } + } - switch (entry->x00_active) { - case 3: { - s16 t = entry->x02_timer; - entry->x02_timer = (s16) (t - 1); - if (t < 0) { - Item_GObj* m = bgp->u.zebes3.xC4; - if (m != NULL) { - grMaterial_801C8CDC(m); - } - Ground_801C4A08(entry->x20_gobj); - { - Vec3 pos; - pos.x = entry->x08_x; - pos.y = entry->x0C_y; - pos.z = 4.0f; - grLib_801C96F8(0x7530, 0x1E, &pos); - } - Ground_801C5440(gp, 0, 0x61A86); - entry->x20_gobj = NULL; - entry->x04 = NULL; - entry->x00_active = 0; + switch (grZe_8049F170[arg1].x00_active) { + case 3: { + s16 t = grZebes_801DB088_GetTimer(arg1); + grZe_8049F170[arg1].x02_timer = (s16) (t - 1); + if (t < 0) { + if (bgp->u.zebes3.xC4 != NULL) { + grMaterial_801C8CDC(bgp->u.zebes3.xC4); } - break; - } - case 2: { - Item_GObj* m = bgp->u.zebes3.xC4; - if (m != NULL) { - grMaterial_801C8CDC(m); - } - Ground_801C4A08(entry->x20_gobj); + Ground_801C4A08(grZe_8049F170[arg1].x20_gobj); { Vec3 pos; - pos.x = entry->x08_x; - pos.y = entry->x0C_y; + pos.x = grZe_8049F170[arg1].x08_x; + pos.y = grZe_8049F170[arg1].x0C_y; pos.z = 4.0f; grLib_801C96F8(0x7530, 0x1E, &pos); } - entry->x20_gobj = NULL; - entry->x04 = NULL; - entry->x00_active = 0; - - if (arg1 < 7 && arg1 != 0 && arg1 != 6) { - f32 best_dist = 64.0f; - s32 best_idx = -1; - s32 j; - f32 ey = entry->x0C_y; - f32 ex = entry->x08_x; - - for (j = 7; j < 20; j++) { - if (grZe_8049F170[j].x00_active == 1) { - f32 dx = grZe_8049F170[j].x08_x - ex; - f32 dy = grZe_8049F170[j].x0C_y - ey; - f32 dx2 = dx * dx; - f32 dy2 = dy * dy; - f32 dist = dx2 + dy2; - if (dist < best_dist) { - best_idx = j; - best_dist = dist; - } + Ground_801C5440(gp, 0, 0x61A86); + grZe_8049F170[arg1].x20_gobj = NULL; + grZe_8049F170[arg1].x04 = NULL; + grZe_8049F170[arg1].x00_active = 0; + } + break; + } + case 2: { + if (bgp->u.zebes3.xC4 != NULL) { + grMaterial_801C8CDC(bgp->u.zebes3.xC4); + } + Ground_801C4A08(grZe_8049F170[arg1].x20_gobj); + { + Vec3 pos; + pos.x = grZe_8049F170[arg1].x08_x; + pos.y = grZe_8049F170[arg1].x0C_y; + pos.z = 4.0f; + grLib_801C96F8(0x7530, 0x1E, &pos); + } + grZe_8049F170[arg1].x20_gobj = NULL; + grZe_8049F170[arg1].x04 = NULL; + grZe_8049F170[arg1].x00_active = 0; + + if (arg1 < 7 && arg1 != 0 && arg1 != 6) { + grZe_BubbleEntry* entry = &grZe_8049F170[arg1]; + f32 ey; + f32 ex; + f32 best_dist; + s32 j; + s32 best_idx; + + best_dist = 64.0f; + ey = entry->x0C_y; + ex = entry->x08_x; + best_idx = -1; + for (j = 7; j < 20; j++) { + if (grZe_8049F170[j].x00_active == 1) { + f32 dx = grZe_8049F170[j].x08_x - ex; + f32 dy = grZe_8049F170[j].x0C_y - ey; + f32 dx2 = dx * dx; + f32 dy2 = dy * dy; + f32 dist = dx2 + dy2; + if (dist < best_dist) { + best_idx = j; + best_dist = dist; } } + } - if (best_idx != -1) { - grZe_BubbleEntry* src = - &grZe_8049F170[best_idx]; - entry->x00_active = src->x00_active; - *jobjp = src->x04; - *sizep = src->x18_size; - *targetp = src->x1C; - *gobjp = src->x20_gobj; - src->x00_active = 0; - src->x20_gobj = NULL; - } else { - for (j = 7; j < 20; j++) { - if (j != 0 && j != 6 && - grZe_8049F170[j].x00_active == 1) - { - grZe_8049F170[j].x00_active = 3; - grZe_8049F170[j].x02_timer = - (s16) (HSD_Randi(0x3C) + 0x0A); - } + if (best_idx != -1) { + grZe_8049F170[arg1].x00_active = + grZe_8049F170[best_idx].x00_active; + grZe_8049F170[arg1].x04 = + grZe_8049F170[best_idx].x04; + grZe_8049F170[arg1].x18_size = + grZe_8049F170[best_idx].x18_size; + grZe_8049F170[arg1].x1C = + grZe_8049F170[best_idx].x1C; + grZe_8049F170[arg1].x20_gobj = + grZe_8049F170[best_idx].x20_gobj; + grZe_8049F170[best_idx].x00_active = 0; + grZe_8049F170[best_idx].x20_gobj = NULL; + } else { + for (j = 7; j < 20; j++) { + if (j != 0 && j != 6 && + grZe_8049F170[j].x00_active == 1) + { + grZe_8049F170[j].x00_active = 3; + grZe_8049F170[j].x02_timer = + (s16) (HSD_Randi(0x3C) + 0x0A); } - result = 1; } + result = 1; } - break; - } } + break; + } } } } } } + PAD_STACK(8); return result; } -static inline f32 grZebes_801DB3CC_dist2(f32 dy, f32 dx) +static inline f32 grZebes_801DB3CC_scale(f32 scale, f32 value) +{ + return value * scale; +} + +static inline f32 grZebes_801DB3CC_dist(f32 dy, f32 dx) +{ + return sqrtf(dx * dx + dy * dy); +} + +static inline f32 grZebes_801DB3CC_half_radius(grZe_YakumonoParam* yp) { - return dx * dx + dy * dy; + return yp->x74 * 0.5f; } -static inline f32 grZebes_801DB3CC_normalize(f32 dist, f32 value) +static inline f32 grZebes_801DB3CC_update_y(grZe_BubbleEntry** base, f32 old_y) { - return value / dist; + 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; + + (void) 0.0; + for (k = 0; k < 20; (*base)++, k++) { + if ((*base)->x00_active != 0) { + if (k == 0) { + (*base)->x10 = 0.0f; + (*base)->x14 = 0.0f; + (*base)->x08_x = left_anchor_x; + (*base)->x0C_y = left_anchor_y; + } else if (k == 6) { + (*base)->x10 = 0.0f; + (*base)->x14 = 0.0f; + (*base)->x08_x = right_anchor_x; + (*base)->x0C_y = right_anchor_y; + } else { + f32 old_y = (*base)->x0C_y; + f32 current_x = (*base)->x08_x; + f32 old_x = current_x; + f32 new_y = grZebes_801DB3CC_update_y(base, old_y); + f32 new_x = old_x + (*base)->x10; + if (new_y < left_bound_y && new_x < left_bound_x) { + if (old_y >= left_bound_y) { + new_y = left_bound_y; + } else if (old_x >= left_bound_x) { + new_x = left_bound_x; + } + } + if (new_y < right_bound_y && new_x > right_bound_x) { + if (old_y >= right_bound_y) { + new_y = right_bound_y; + } else if (old_x <= right_bound_x) { + new_x = right_bound_x; + } + } + (*base)->x08_x = new_x; + (*base)->x0C_y = new_y; + { + f32 vx = (*base)->x10; + f32 max_v = yakumono_param->x88; + if (vx > max_v) { + (*base)->x10 = max_v; + } else if (vx < -max_v) { + (*base)->x10 = -max_v; + } + } + { + f32 vy = (*base)->x14; + f32 max_v = yakumono_param->x88; + if (vy > max_v) { + (*base)->x14 = max_v; + } else if (vy < -max_v) { + (*base)->x14 = -max_v; + } + } + } + } + } } s32 grZebes_801DB3CC(HSD_GObj* gobj) @@ -1712,15 +1795,10 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) grZe_BubbleEntry* base = grZe_8049F170; s32 popped = 0; int i; - grZe_BubbleEntry* ptr; - f32 dist; - f32 dx; - f32 dist2; - f32 dx2; - - ptr = base; - for (i = 0; i < 20; i++, ptr++) { - if (ptr->x00_active != 0 && grZebes_801DB088((Ground*) gobj, i) != 0) { + for (i = 0; i < 20; i++) { + if (base[i].x00_active != 0 && + grZebes_801DB088((Ground*) gobj, i) != 0) + { popped = 1; } } @@ -1748,44 +1826,37 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) if (idx != 0 && idx != 6) { f32 fx = zero; f32 fy = zero; - grZe_BubbleEntry* left = &base[idx - 1]; + s32 left_idx = idx - 1; right_idx = idx + 1; - if (left->x00_active != 0) { + if (grZe_8049F170[left_idx].x00_active != 0) { + grZe_BubbleEntry* left = &grZe_8049F170[left_idx]; + f32 dx = left->x08_x - cur->x08_x; f32 dy = left->x0C_y - cur->x0C_y; - dx = left->x08_x; - dx -= cur->x08_x; - dist = dx * dx + dy * dy; - if (dist > zero) { - dist = sqrtf(dist); - } + f32 dist = grZebes_801DB3CC_dist(dy, dx); { f32 col_r = yakumono_param->x74; if (dist > col_r) { f32 max_force = yakumono_param->x80; - f32 norm_x = - grZebes_801DB3CC_normalize(dist, dx); - f32 norm_y = - grZebes_801DB3CC_normalize(dist, dy); - f32 push = dist - col_r; + f32 push; + + dx /= dist; + push = dist - col_r; + dist = dy / dist; if (push > max_force) { push = max_force; } - fx = norm_x * push + zero; - fy = norm_y * push + zero; + fx += dx * push; + fy += dist * push; } } neighbor_count = 1; } { - grZe_BubbleEntry* right = &base[right_idx]; + grZe_BubbleEntry* right = &grZe_8049F170[right_idx]; if (right->x00_active != 0) { + f32 dx2 = right->x08_x - cur->x08_x; f32 dy2 = right->x0C_y - cur->x0C_y; - dx2 = right->x08_x; - dx2 -= cur->x08_x; - dist2 = dx2 * dx2 + dy2 * dy2; - if (dist2 > zero) { - dist2 = sqrtf(dist2); - } + f32 dist2 = sqrtf(dx2 * dx2 + dy2 * dy2); { f32 col_r2 = yakumono_param->x74; if (dist2 > col_r2) { @@ -1820,75 +1891,66 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) for (a = 0; a < 19; a++, ea++) { if (ea->x00_active != 0) { int b = a + 1; - grZe_BubbleEntry* eb = &base[b]; - int rem = 20 - b; - if (b < 20) { - for (; rem != 0; eb++, b++, rem--) { - if (eb->x00_active != 0) { - f32 dy = eb->x0C_y - ea->x0C_y; - f32 dx = eb->x08_x - ea->x08_x; - f32 dist_sq = grZebes_801DB3CC_dist2(dy, dx); - f32 dist = dist_sq; - if (dist_sq > 0.0f) { - dist = sqrtf(dist_sq); + grZe_BubbleEntry* eb = &grZe_8049F170[b]; + for (; b < 20; eb++, b++) { + if (eb->x00_active != 0) { + f32 dx = eb->x08_x - ea->x08_x; + f32 dy = eb->x0C_y - ea->x0C_y; + f32 dist = sqrtf(dx * dx + dy * dy); + { + grZe_YakumonoParam* yp = yakumono_param; + f32 effective_dist = dist; + 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; } - { - f32 effective_dist = dist; - f32 avg_size = ea->x18_size + eb->x18_size; - f32 col_rad = - yakumono_param->x74 * 0.5f * avg_size; - f32 near_rad = - yakumono_param->x70 * 0.5f * avg_size; - f32 far_rad = - yakumono_param->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) (f32) (((f64) (col_rad / - effective_dist) - - 1.0) * - 0.5) * - 0.9); - if (a >= 7) { - f32 vx = -dx * strength; - f32 vy = -dy * strength; - f32 clamp_vy = vy; - if (vy < 0.0) { - clamp_vy = 0.0f; - } - ea->x10 += vx; - ea->x14 += clamp_vy; - } - if (b >= 7) { - f32 vx2 = dx * strength; - 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 = - yakumono_param->x78 / effective_dist; - if (a >= 7) { - f32 vx = dx * attract; - f32 vy = dy * attract; - ea->x10 += vx; - ea->x14 += vy; + 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; } - if (b >= 7) { - f32 vx2 = -dx * attract; - f32 vy2 = -dy * attract; - eb->x10 += vx2; - eb->x14 += vy2; + 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; } } } @@ -1898,75 +1960,16 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) } } - { - int k; - f32 left_anchor_x = grZe_8049F158[0].x; - f32 left_anchor_y = grZe_8049F158[0].y; - f32 right_anchor_x = grZe_8049F158[1].x; - f32 right_anchor_y = grZe_8049F158[1].y; - f32 left_bound_y = grZe_8049F140[0].y; - f32 left_bound_x = grZe_8049F140[0].x; - f32 right_bound_y = grZe_8049F140[1].y; - f32 right_bound_x = grZe_8049F140[1].x; - for (k = 0; k < 20; base++, k++) { - if (base->x00_active != 0) { - if (k == 0) { - base->x10 = 0.0f; - base->x14 = 0.0f; - base->x08_x = left_anchor_x; - base->x0C_y = left_anchor_y; - } else if (k == 6) { - base->x10 = 0.0f; - base->x14 = 0.0f; - base->x08_x = right_anchor_x; - base->x0C_y = right_anchor_y; - } else { - f32 old_y = base->x0C_y; - f32 old_x = base->x08_x; - 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) { - new_y = left_bound_y; - } else if (old_x >= left_bound_x) { - new_x = left_bound_x; - } - } - if (new_y < right_bound_y && new_x > right_bound_x) { - if (old_y >= right_bound_y) { - new_y = right_bound_y; - } else if (old_x <= right_bound_x) { - new_x = right_bound_x; - } - } - base->x08_x = new_x; - base->x0C_y = new_y; - { - f32 vx = base->x10; - f32 max_v = yakumono_param->x88; - if (vx > max_v) { - base->x10 = max_v; - } else if (vx < -max_v) { - base->x10 = -max_v; - } - } - { - f32 vy = base->x14; - f32 max_v = yakumono_param->x88; - if (vy > max_v) { - base->x14 = max_v; - } else if (vy < -max_v) { - base->x14 = -max_v; - } - } - } - } - } - } + grZebes_801DB3CC_update(&base); return popped; } +static inline f32 grZebes_Subtract(f32 lhs, f32 rhs) +{ + return lhs - rhs; +} + bool grZebes_801DBB60(Item_GObj* yaku) { s32 last_idx; @@ -1974,7 +1977,6 @@ bool grZebes_801DBB60(Item_GObj* yaku) grZe_BubbleEntry* bubbles; s32 count = 0; f32 max_dist_sq = -1.0f; - grZe_BubbleEntry* ej; HSD_ASSERT(0x898, yaku); @@ -2002,7 +2004,7 @@ bool grZebes_801DBB60(Item_GObj* yaku) grZe_BubbleEntry* entry; f32 zero; grMaterial_801C8E08(yaku); - entry = &bubbles[last_idx]; + entry = &grZe_8049F170[last_idx]; zero = 0.0f; grMaterial_801C8DE0(yaku, entry->x08_x, entry->x0C_y, zero, entry->x08_x, entry->x0C_y, zero, @@ -2013,40 +2015,44 @@ bool grZebes_801DBB60(Item_GObj* yaku) grMaterial_801C8E08(yaku); { - s32 i = 0; - grZe_BubbleEntry* ei = bubbles; + grZe_BubbleEntry* ei; + s32 i; f32 x1, y1, x2, y2; + i = 0; + ei = bubbles; for (; i < 20; i++, ei++) { if (ei->x00_active == 1 && i != 0 && i != 6) { s32 j = i + 1; - f32 ei_y = ei->x0C_y; - f32 ei_x = ei->x08_x; - f32 ei_size = ei->x18_size; - s32 rem = 20 - j; - ej = &bubbles[j]; - if (j < 20) { - for (; rem != 0; ej++, j++, rem--) { - if (ej->x00_active == 1 && j != 0 && j != 6) { - f32 ej_x = ej->x08_x; - f32 ej_y = ej->x0C_y; - f32 dx = ei_x - ej_x; - f32 dy = ei_y - ej_y; - f32 dx_sq = dx * dx; - f32 dy_sq = dy * dy; - f32 dist_sq = dx_sq + dy_sq; - 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) { - last_idx = i; - } else { - last_idx = j; - } + f32 ei_x; + f32 ei_size; + f32 ei_y; + grZe_BubbleEntry* ej = &grZe_8049F170[j]; + + ei_y = ei->x0C_y; + ei_x = ei->x08_x; + 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; + dx *= dx; + dy *= dy; + dist_sq = dx + dy; + 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) { + last_idx = i; + } else { + last_idx = j; } } } @@ -2057,117 +2063,100 @@ bool grZebes_801DBB60(Item_GObj* yaku) if (max_dist_sq < 0.0f) { HSD_ASSERT(0x8D2, 0); } else if (max_dist_sq < 0.0001f) { - grZe_BubbleEntry* entry = &bubbles[last_idx]; + grZe_BubbleEntry* entry = &grZe_8049F170[last_idx]; grMaterial_801C8DE0(yaku, entry->x08_x, entry->x0C_y, 0.0f, entry->x08_x, entry->x0C_y, 0.0f, (f32) (2.0 * (f64) entry->x18_size)); return 1; } else { - f32 dy = y2 - y1; - f32 dx = x2 - x1; - f32 width = 1.0f; + f32 dx; + f32 dy; + f32 width; f32 inv_len_sq; int k = 0; - grZe_BubbleEntry* bp = bubbles; - + dy = y2 - y1; + dx = x2 - x1; + width = 1.0f; inv_len_sq = 1.0f / (dx * dx + dy * dy); - (void) inv_len_sq; - for (k = 0; k < 20; k++, bp++) { - if (bp->x00_active == 1 && k != 0 && k != 6) { - f32 by = bp->x0C_y; - f32 bx = bp->x08_x; + for (k = 0; k < 20; bubbles++, k++) { + if (bubbles->x00_active == 1 && k != 0 && k != 6) { + f32 by = bubbles->x0C_y; + f32 bx = bubbles->x08_x; f32 dpx = by - y1; f32 dpy = bx - x1; f32 t = inv_len_sq * (dx * dpy + dy * dpx); - f32 closest_dist; - if (t < 0.0) { - closest_dist = dpy * dpy + dpx * dpx; + if (t < 0.0f) { + bx = dpy * dpy + dpx * dpx; } else if (t > 1.0f) { f32 ex = bx - x2; - f32 ey = by - y2; - f32 ex2 = ex * ex; - f32 ey2 = ey * ey; - closest_dist = ex2 + ey2; + f32 ey = grZebes_Subtract(by, y2); + f32 ex_sq = ex * ex; + f32 ey_sq = ey * ey; + bx = ex_sq + ey_sq; } else { f32 cx = (dx * t + x1) - bx; f32 cy = (dy * t + y1) - by; - f32 cx2 = cx * cx; - f32 cy2 = cy * cy; - closest_dist = cx2 + cy2; + f32 cx_sq = cx * cx; + f32 cy_sq = cy * cy; + bx = cx_sq + cy_sq; } - closest_dist = sqrtf(closest_dist); + bx = sqrtf(bx); { - f32 check = (f32) (2.0 * (f64) bp->x18_size + - (f64) closest_dist); - if (check > width) { + if ((f32) (2.0 * (f64) bubbles->x18_size + (f64) bx) > + width) + { + f32 new_width; if (t < 0.5f) { - f32 dpx2 = bp->x08_x - x1; - f32 dpy2 = bp->x0C_y - y1; - f32 dist2 = grZebes_801DB3CC_dist2(dpy2, dpx2); - f32 new_width; - dist2 = sqrtf(dist2); - { - f32 sum = dist2 + width; - new_width = - (f32) (0.5 * - (2.0 * (f64) bp->x18_size + - (f64) sum)); - } - if (dist2 > 0.001) { - f32 ratio = (new_width - width) / dist2; - x1 += ratio * (bp->x08_x - x1); - y1 += ratio * (bp->x0C_y - y1); - } - { - f32 ddy = y1 - y2; - f32 ddx = x1 - x2; - f32 dist3 = ddx * ddx + ddy * ddy; - f32 expand; - dist3 = sqrtf(dist3); - expand = new_width - width; - width = new_width; - { - f32 ratio2 = expand / dist3; - x2 += ddx * ratio2; - y2 += ddy * ratio2; - } + f32 dpx2 = bubbles->x08_x - x1; + f32 dpy2 = bubbles->x0C_y - y1; + dpx2 *= dpx2; + dpy2 *= dpy2; + t = sqrtf(dpx2 + dpy2); + new_width = + (f32) (0.5 * + (2.0 * (f64) bubbles->x18_size + + (f64) (t + width))); + if (t > 0.001f) { + dpx2 = (new_width - width) / t; + x1 += dpx2 * (bubbles->x08_x - x1); + y1 += dpx2 * (bubbles->x0C_y - y1); } + dpy2 = y1 - y2; + dpx2 = x1 - x2; + t = (new_width - width) / + sqrtf(dpx2 * dpx2 + dpy2 * dpy2); + width = new_width; + x2 += dpx2 * t; + y2 += dpy2 * t; } else { - f32 dpx2 = bp->x08_x - x2; - f32 dpy2 = bp->x0C_y - y2; - f32 dist2 = grZebes_801DB3CC_dist2(dpy2, dpx2); - f32 new_width; - dist2 = sqrtf(dist2); + f32 dpx2 = bubbles->x08_x - x2; + f32 dpy2 = bubbles->x0C_y - y2; + dpx2 *= dpx2; + dpy2 *= dpy2; + t = sqrtf(dpx2 + dpy2); { - f32 sum = dist2 + width; - new_width = + f32 calculated_width = (f32) (0.5 * - (2.0 * (f64) bp->x18_size + - (f64) sum)); - } - if (dist2 > 0.001) { - f32 ratio = (new_width - width) / dist2; - x2 += ratio * (bp->x08_x - x2); - y2 += ratio * (bp->x0C_y - y2); + (2.0 * (f64) bubbles->x18_size + + (f64) (t + width))); + new_width = calculated_width; } - { - f32 ddy = y2 - y1; - f32 ddx = x2 - x1; - f32 dist3 = ddx * ddx + ddy * ddy; - f32 expand; - dist3 = sqrtf(dist3); - expand = new_width - width; - width = new_width; - { - f32 ratio2 = expand / dist3; - x1 += ddx * ratio2; - y1 += ddy * ratio2; - } + if (t > 0.001f) { + dpx2 = (new_width - width) / t; + x2 += dpx2 * (bubbles->x08_x - x2); + y2 += dpx2 * (bubbles->x0C_y - y2); } + dpy2 = y2 - y1; + dpx2 = x2 - x1; + t = (new_width - width) / + sqrtf(dpx2 * dpx2 + dpy2 * dpy2); + width = new_width; + x1 += dpx2 * t; + y1 += dpy2 * t; } dy = y2 - y1; dx = x2 - x1; diff --git a/src/melee/if/ifstatus.c b/src/melee/if/ifstatus.c index d54136988e..72adfc4004 100644 --- a/src/melee/if/ifstatus.c +++ b/src/melee/if/ifstatus.c @@ -212,14 +212,12 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) HSD_JObj* jobj; HSD_JObj* digit_jobj; s32 is_stamina; + GXColor color; HSD_TObj* tobj; HSD_MObj* mobj; HSD_MatAnimJoint** anim_base; s32 i; - s32 var_ctr; - u8 ones_digit; - u8 tens_digit; - u8 hundreds_digit; + u8 digit; f32 digit_offset; f32 ones_offset; f32 tens_offset; @@ -227,7 +225,6 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) f32 pos; s16 clamped_damage; f32 factor; - GXColor color; IfDamageState* ptr; PAD_STACK(64); @@ -288,67 +285,68 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) mn_8022F3D8(jobj, 1, 0x400); digit_jobj = state->jobjs[Ones]; - ones_digit = state->damage_percent % 10; + 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 * ones_digit); + 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]; - tens_digit = (state->damage_percent % 100) / 10; + 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 * tens_digit); + 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]; - hundreds_digit = (state->damage_percent % 1000) / 100; + 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 * hundreds_digit); + HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); } HSD_JObjAnimAll(jobj); - digit_jobj = state->jobjs[Ones]; - ones_digit = state->damage_percent % 10; - HSD_TObjAddAnimAll( - digit_jobj->u.dobj->mobj->tobj, - (HSD_TexAnim*) ifStatus_GetHUDInfo() - ->janim_selection_joints->child->child->aobjdesc->fobjdesc); - HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * ones_digit); - HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); - - digit_jobj = state->jobjs[Tens]; - tens_digit = (state->damage_percent % 100) / 10; - HSD_TObjAddAnimAll( - digit_jobj->u.dobj->mobj->tobj, - (HSD_TexAnim*) ifStatus_GetHUDInfo() - ->janim_selection_joints->child->child->aobjdesc->fobjdesc); - HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * tens_digit); - HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); - - if ((state->damage_percent % 1000) / 100 == 0 && - (state->damage_percent % 100) / 10 == 0) { - HSD_JObjSetFlagsAll(state->jobjs[Tens], JOBJ_HIDDEN); - } else { - HSD_JObjClearFlagsAll(state->jobjs[Tens], JOBJ_HIDDEN); - } + HSD_AnimJoint** anim_joints = &hud->janim_selection_joints; + HSD_JObj* post_digit_jobj; - digit_jobj = state->jobjs[Hundreds]; - hundreds_digit = (state->damage_percent % 1000) / 100; - HSD_TObjAddAnimAll( - digit_jobj->u.dobj->mobj->tobj, - (HSD_TexAnim*) ifStatus_GetHUDInfo() - ->janim_selection_joints->child->child->aobjdesc->fobjdesc); - HSD_TObjReqAnimAll(digit_jobj->u.dobj->mobj->tobj, 2.0F * hundreds_digit); - HSD_AObjSetRate(digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); + post_digit_jobj = state->jobjs[Ones]; + digit = state->damage_percent % 10; + HSD_TObjAddAnimAll( + post_digit_jobj->u.dobj->mobj->tobj, + (HSD_TexAnim*) anim_joints[0]->child->child->aobjdesc->fobjdesc); + HSD_TObjReqAnimAll(post_digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); + HSD_AObjSetRate(post_digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); + + post_digit_jobj = state->jobjs[Tens]; + digit = (state->damage_percent % 100) / 10; + HSD_TObjAddAnimAll( + post_digit_jobj->u.dobj->mobj->tobj, + (HSD_TexAnim*) anim_joints[0]->child->child->aobjdesc->fobjdesc); + HSD_TObjReqAnimAll(post_digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); + HSD_AObjSetRate(post_digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); + + if ((state->damage_percent % 1000) / 100 == 0 && + (state->damage_percent % 100) / 10 == 0) + { + HSD_JObjSetFlagsAll(state->jobjs[Tens], JOBJ_HIDDEN); + } else { + HSD_JObjClearFlagsAll(state->jobjs[Tens], JOBJ_HIDDEN); + } + + post_digit_jobj = state->jobjs[Hundreds]; + digit = (state->damage_percent % 1000) / 100; + HSD_TObjAddAnimAll( + post_digit_jobj->u.dobj->mobj->tobj, + (HSD_TexAnim*) anim_joints[0]->child->child->aobjdesc->fobjdesc); + HSD_TObjReqAnimAll(post_digit_jobj->u.dobj->mobj->tobj, 2.0F * digit); + HSD_AObjSetRate(post_digit_jobj->u.dobj->mobj->tobj->aobj, 0.0F); + } if ((state->damage_percent % 1000) / 100 == 0) { HSD_JObjSetFlagsAll(state->jobjs[Hundreds], JOBJ_HIDDEN); @@ -359,6 +357,8 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) /* Update colors when damage changes */ if (state->old_damage != state->damage_percent) { if (Player_GetMoreFlagsBit2((s8) state->player_slot)) { + GXColor stamina_color; + /* Stamina mode: 0-100% range */ clamped_damage = state->damage_percent; if (clamped_damage > 100) { @@ -367,17 +367,20 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) clamped_damage = 0; } factor = 1.0F - ((f32) clamped_damage / 100.0F); - color.r = (s8) (factor * (f32) (ifStatus_804D57AC[0] - - ifStatus_804D57A8[0]) + - (f32) ifStatus_804D57A8[0]); - color.g = (s8) (factor * (f32) (ifStatus_804D57AC[1] - - ifStatus_804D57A8[1]) + - (f32) ifStatus_804D57A8[1]); - color.b = (s8) (factor * (f32) (ifStatus_804D57AC[2] - - ifStatus_804D57A8[2]) + - (f32) ifStatus_804D57A8[2]); - color.a = 255; + stamina_color.r = (s8) (factor * (f32) (ifStatus_804D57AC[0] - + ifStatus_804D57A8[0]) + + (f32) ifStatus_804D57A8[0]); + stamina_color.g = (s8) (factor * (f32) (ifStatus_804D57AC[1] - + ifStatus_804D57A8[1]) + + (f32) ifStatus_804D57A8[1]); + stamina_color.b = (s8) (factor * (f32) (ifStatus_804D57AC[2] - + ifStatus_804D57A8[2]) + + (f32) ifStatus_804D57A8[2]); + stamina_color.a = 255; + color = stamina_color; } else { + GXColor normal_color; + /* Normal mode: 0-300% range */ clamped_damage = state->damage_percent; if (clamped_damage > 300) { @@ -386,16 +389,17 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) clamped_damage = 0; } factor = (f32) clamped_damage / 300.0F; - color.r = (s8) (factor * (f32) (ifStatus_804D57AC[0] - - ifStatus_804D57A8[0]) + - (f32) ifStatus_804D57A8[0]); - color.g = (s8) (factor * (f32) (ifStatus_804D57AC[1] - - ifStatus_804D57A8[1]) + - (f32) ifStatus_804D57A8[1]); - color.b = (s8) (factor * (f32) (ifStatus_804D57AC[2] - - ifStatus_804D57A8[2]) + - (f32) ifStatus_804D57A8[2]); - color.a = 255; + normal_color.r = (s8) (factor * (f32) (ifStatus_804D57AC[0] - + ifStatus_804D57A8[0]) + + (f32) ifStatus_804D57A8[0]); + normal_color.g = (s8) (factor * (f32) (ifStatus_804D57AC[1] - + ifStatus_804D57A8[1]) + + (f32) ifStatus_804D57A8[1]); + normal_color.b = (s8) (factor * (f32) (ifStatus_804D57AC[2] - + ifStatus_804D57A8[2]) + + (f32) ifStatus_804D57A8[2]); + normal_color.a = 255; + color = normal_color; } /* Apply color to all digit materials */ @@ -466,7 +470,7 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) ((state->damage_percent % 1000) / 100 == 1) ? 0.5069F : 0.0F; digit_jobj = state->jobjs[Hundreds]; pos = state->translation_x[Hundreds] + - (tens_offset + digit_offset + hundreds_offset); + (hundreds_offset + tens_offset + digit_offset); if (digit_jobj == NULL) { __assert("jobj.h", 932, "jobj"); } @@ -706,31 +710,38 @@ HSD_GObj* ifStatus_802F6194(HSD_GObj* node, s32 n) return gx_cur; } -static inline HSD_GObj* ifStatus_CreateMarkGObj(void) +inline void ifStatus_CreateMarkGObj(HSD_GObj** gobj) { - return GObj_Create(0xE, 0xF, 0); + *gobj = GObj_Create(0xE, 0xF, 0); +} + +static inline void ifStatus_GetPlayerCharacter(s32 arg0, CharacterKind* chara) +{ + u8 idx = arg0; + *chara = Player_GetPlayerCharacter(idx); } HSD_GObj* ifStatus_802F61FC(IfDamageState* state, s32 player_idx) { CharacterKind chara; - HSD_GObj* gobj; HSD_JObj* jobj; HSD_TObj* tobj; Vec3* vec; HSD_MObj* mobj; - GXColor color; + HudIndex* hud = ifStatus_GetHUDInfo(); u8 slot; - u8 team; + GXColor color; u8 hud_color; - HudIndex* hud = ifStatus_GetHUDInfo(); + u8 team; u8 idx = player_idx; PAD_STACK(0x10); - chara = Player_GetPlayerCharacter(idx); + ifStatus_GetPlayerCharacter(player_idx, &chara); if (state->next == NULL) { + HSD_GObj* gobj; + ifAll_GetArchive(); - gobj = ifStatus_CreateMarkGObj(); + ifStatus_CreateMarkGObj(&gobj); if (gobj == NULL) { HSD_ASSERTREPORT(0x30A, 0, "Error : gobj dont't get (ifAddMark)\n"); diff --git a/src/melee/if/ifstock.c b/src/melee/if/ifstock.c index a4ad5efe50..3f09c92165 100644 --- a/src/melee/if/ifstock.c +++ b/src/melee/if/ifstock.c @@ -41,18 +41,31 @@ struct IfStockStealAnim { Vec3 end; }; +struct IfStockData { + unsigned char x0[0xC]; + struct IfStockStealAnim anim[2]; +}; + +struct IfStockDataOffset { + unsigned char x0[0x204]; + struct IfStockData data; +}; + int ifStock_802F7EFC(int arg0, int arg1) { Vec3 pos; struct ifStock_804A1378* stock; - struct ifStock_804A1378_x204* arg0_data; - struct ifStock_804A1378_x204* arg1_data; - struct IfStockStealAnim* anim; + struct IfStockData* arg1_data; + struct IfStockData* arg0_data; int slot; int i, j; stock = &ifStock_804A1378; - arg0_data = &stock->x204[arg0]; - arg1_data = &stock->x204[arg1]; + 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; if (Player_GetStocks(arg1) == 0) { return 1; } @@ -70,62 +83,75 @@ int ifStock_802F7EFC(int arg0, int arg1) arg1_data->x0[slot + 5] = 1; arg0_data->x0[2] = 0; arg1_data->x0[slot - 2] = arg0; - if (stock->player[arg1].stocks <= 5 && stock->player[arg1].stocks > 0) { - arg1_data->x0[stock->player[arg1].stocks + 4] = 10; - } - i = 0; - if (stock->player[arg1].stocks <= 5 && stock->player[arg1].stocks > 0) { - i = 1; - } - if (i != 0) { - j = stock->player[arg1].stocks; - } else { - j = 1; + { + int stocks = stock->player[arg1].stocks; + if (stocks <= 5 && stocks > 0) { + arg1_data->x0[stocks + 4] = 10; + } + i = 0; + if (stocks <= 5 && stocks > 0) { + i = 1; + } + j = i != 0 ? stocks : 1; } HSD_JObjGetTranslation(stock->player[arg1].x4[0], &pos); HSD_JObjReqAnimAll(stock->player[arg1].x4[j], 0.0f); HSD_JObjAnimAll(stock->player[arg1].x4[j]); - anim = (struct IfStockStealAnim*) &arg1_data - ->x0[0xC + (slot - 5) * sizeof(struct IfStockStealAnim)]; - HSD_JObjGetTranslation(stock->player[arg1].x4[j], &anim->start); - anim->start.x += pos.x; - anim->start.y += pos.y; - anim->start.z += pos.z; - i = 0; - if (Player_GetStocks(arg0) < 5 && Player_GetStocks(arg0) > 0) { - i = 1; - } - if (i != 0) { - j = Player_GetStocks(arg0); - } else { - j = 0; + HSD_JObjGetTranslation(stock->player[arg1].x4[j], + &arg1_data->anim[slot - 5].start); + arg1_data->anim[slot - 5].start.x += pos.x; + arg1_data->anim[slot - 5].start.y += pos.y; + arg1_data->anim[slot - 5].start.z += pos.z; + i = Player_GetStocks(arg0) < 5 && Player_GetStocks(arg0) > 0; + j = i != 0 ? Player_GetStocks(arg0) : 0; + { + HSD_JObj* jobj = stock->player[arg0].x4[0]; + HSD_JObjGetTranslation(jobj, &pos); } - HSD_JObjGetTranslation(stock->player[arg0].x4[0], &pos); HSD_JObjReqAnimAll(stock->player[arg0].x4[j], 0.0f); HSD_JObjAnimAll(stock->player[arg0].x4[j]); - HSD_JObjGetTranslation(stock->player[arg0].x4[1], &anim->end); - anim->end.x += (2.4f * j) + pos.x; - anim->end.y = anim->start.y; - anim->end.z += pos.z; - anim->mid.x = 0.5f * (anim->end.x + anim->start.x); - anim->mid.z = 0.5f * (anim->end.z + anim->start.z); - anim->mid.y = 10.0f + anim->start.y; + HSD_JObjGetTranslation(stock->player[arg0].x4[1], + &arg1_data->anim[slot - 5].end); + arg1_data->anim[slot - 5].end.x += (2.4f * j) + pos.x; + arg1_data->anim[slot - 5].end.y = arg1_data->anim[slot - 5].start.y; + arg1_data->anim[slot - 5].end.z += pos.z; + arg1_data->anim[slot - 5].mid.x = + 0.5f * + (arg1_data->anim[slot - 5].end.x + arg1_data->anim[slot - 5].start.x); + arg1_data->anim[slot - 5].mid.z = + 0.5f * + (arg1_data->anim[slot - 5].end.z + arg1_data->anim[slot - 5].start.z); + arg1_data->anim[slot - 5].mid.y = + 10.0f + arg1_data->anim[slot - 5].start.y; return 0; } +static inline struct ifStock_804A1378_x204* +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) +{ + *user_data = GET_IFSTOCK(gobj); + *jobj = gobj->hsd_obj; + *stock = &ifStock_804A1378; +} + void ifStock_802F8298(HSD_GObj* gobj) { struct IfStockUserData* user_data; HSD_JObj* jobj; struct ifStock_804A1378* stock; HSD_JObj* jobj_anim; - int i; + Vec3 vecA, vecB, vecC, vecD; HSD_JObj* jobj2; - Vec3 vecA, vecB; - PAD_STACK(24); - user_data = GET_IFSTOCK(gobj); - jobj = gobj->hsd_obj; - stock = &ifStock_804A1378; + int i; + ifStock_802F8298_init(gobj, &user_data, &jobj, &stock); jobj_anim = jobj; stock->player[user_data->player].stocks = Player_GetStocks(user_data->player); @@ -150,9 +176,12 @@ void ifStock_802F8298(HSD_GObj* gobj) if (stock->x204[user_data->player].x0[2] == 0) { stock->x204[user_data->player].x0[i + 5] = 10; } - if (stock->x204[user_data->player].x0[i + 5] == 0) { + if (ifStock_802F8298_get_data(stock)[user_data->player] + .x0[i + 5] == 0) + { HSD_JObjGetTranslation(jobj, &vecA); - HSD_JObjGetTranslation(jobj2, &vecB); + HSD_JObjGetTranslation( + stock->player[user_data->player].x4[i + 1], &vecB); vecB.x += vecA.x; vecB.y += vecA.y; vecB.z += vecA.z; @@ -185,9 +214,11 @@ void ifStock_802F8298(HSD_GObj* gobj) for (i = 0; i < 5; i++) { jobj2 = stock->player[user_data->player].x4[i + 1]; if (i == 0) { - stock->x204[user_data->player].x0[i + 5] = 0; + ifStock_802F8298_get_data(stock)[user_data->player].x0[i + 5] = + 0; } else { - stock->x204[user_data->player].x0[i + 5] = 10; + ifStock_802F8298_get_data(stock)[user_data->player].x0[i + 5] = + 10; } HSD_JObjReqAnimAll(jobj2, stock->x204[user_data->player].x0[i + 5]); @@ -198,47 +229,70 @@ void ifStock_802F8298(HSD_GObj* gobj) } for (i = 5; i <= 6; i++) { jobj2 = stock->player[user_data->player].x4[i + 1]; - if (stock->x204[user_data->player].x0[i + 5] == 0) { + if (ifStock_802F8298_get_data(stock)[user_data->player].x0[i + 5] == 0) + { HSD_JObjSetFlagsAll(jobj2, JOBJ_HIDDEN); } else { HSD_JObjClearFlagsAll(jobj2, JOBJ_HIDDEN); if (stock->x204[user_data->player].x0[i + 5] <= 10) { - lbVector_8000DE38( - (float (*)[4]) & - stock->x204[user_data->player] - .x0[0xC + - (i - 5) * sizeof(struct IfStockStealAnim)], - &vecA, 0.1f * stock->x204[user_data->player].x0[i + 5]); + { + unsigned char* data = stock->x204[user_data->player].x0; + u32 anim_offset = + 0xC + (i - 5) * sizeof(struct IfStockStealAnim); + lbVector_8000DE38( + (float (*)[4]) & + stock->x204[user_data->player].x0[anim_offset], + &vecC, 0.1f * data[i + 5]); + } HSD_JObjGetTranslation(stock->player[user_data->player].x4[0], - &vecB); - vecA.x -= vecB.x; - vecA.y -= vecB.y; - vecA.z -= vecB.z; - HSD_JObjSetTranslate(jobj2, &vecA); + &vecD); + vecC.x -= vecD.x; + vecC.y -= vecD.y; + vecC.z -= vecD.z; + HSD_JObjSetTranslate(jobj2, &vecC); if (stock->x204[user_data->player].x0[i + 5] == 1) { - struct IfStockStealAnim* anim = - (struct IfStockStealAnim*) &stock - ->x204[user_data->player] - .x0[0xC + - (i - 5) * sizeof(struct IfStockStealAnim)]; - vecA.x = anim->start.x; - vecA.y = anim->start.y; - efSync_Spawn(0x475, gobj, &vecA); + vecC.x = + ((struct IfStockStealAnim*) &stock + ->x204[user_data->player] + .x0[0xC + i * sizeof(struct IfStockStealAnim) - + 5 * sizeof(struct IfStockStealAnim)]) + ->start.x; + vecC.y = + ((struct IfStockStealAnim*) &ifStock_802F8298_get_data( + stock)[user_data->player] + .x0[0xC + i * sizeof(struct IfStockStealAnim) - + 5 * sizeof(struct IfStockStealAnim)]) + ->start.y; + efSync_Spawn(0x475, gobj, &vecC); } else if (stock->x204[user_data->player].x0[i + 5] == 10) { - struct IfStockStealAnim* anim = - (struct IfStockStealAnim*) &stock - ->x204[user_data->player] - .x0[0xC + - (i - 5) * sizeof(struct IfStockStealAnim)]; - vecA.x = anim->end.x; - vecA.y = anim->end.y; - efSync_Spawn(0x476, gobj, &vecA); + { + struct ifStock_804A1378_x204* data = + ifStock_802F8298_get_data(stock); + vecC.x = + ((struct IfStockStealAnim*) &data[user_data + ->player] + .x0[0xC + + i * sizeof(struct IfStockStealAnim) - + 5 * sizeof(struct IfStockStealAnim)]) + ->end.x; + } + vecC.y = + ((struct IfStockStealAnim*) &ifStock_802F8298_get_data( + stock)[user_data->player] + .x0[0xC + i * sizeof(struct IfStockStealAnim) - + 5 * sizeof(struct IfStockStealAnim)]) + ->end.y; + efSync_Spawn(0x476, gobj, &vecC); } - stock->x204[user_data->player].x0[i + 5]++; + ifStock_802F8298_get_data(stock)[user_data->player] + .x0[i + 5]++; } else { - stock->x204[user_data->player].x0[i + 5] = 0; - stock->x204[stock->x204[user_data->player].x0[i - 2]].x0[2] = - 1; + int count_index = i + 5; + stock->x204[user_data->player].x0[count_index] = 0; + ifStock_802F8298_get_data( + stock)[ifStock_802F8298_get_data(stock)[user_data->player] + .x0[i - 2]] + .x0[2] = 1; } } HSD_TObjReqAnimAll(jobj2->u.dobj->mobj->tobj, diff --git a/src/melee/lb/lbcollision.c b/src/melee/lb/lbcollision.c index 3bbb62ee39..4c5afbef78 100644 --- a/src/melee/lb/lbcollision.c +++ b/src/melee/lb/lbcollision.c @@ -327,376 +327,346 @@ bool lbColl_80006094(Vec3* arg0, Vec3* arg1, Vec3* arg2, Vec3* arg3, { Vec3 arg4_offset; Vec3 arg5_offset; - float temp_f1; - float unk_sum; - float arg1_x; - float x; - float x2; - float x3; - float x_d; - float temp_f3; - float temp_f3_2; - float y; - float y3; - float temp_f2_5; - float temp_f4; - float temp_f4_2; - float temp_f4_3; - float temp_f4_4; - float arg4_scl; - float d1_x; - float arg3_y; - float d1_y; - float d1_z; - float offset_delta_y; - float arg3_x; - float d2_x; - float d2_y; - float arg3_z; - float d2_z; - float d2_len_sq; - /* d2_z_sq and d2_y_offset are no longer assigned: they are frame - * placeholders. Deleting either costs 445 points -- the target - * reserves their slots. */ - float d2_z_sq; - float d1_dot_d2; - float offset_delta_x; - float d1_len_sq; - float offset_delta_z; - float d2_y_offset; - float d2_dot_offset_delta; - float d1_dot_offset_delta; - float len_product; - float denom; - float arg5_scl; - float scale; - float mid_y; - float mid_x; - float arg4_mid_y; - float arg1_mid_y; - float mid_z; - float arg4_mid_x; - float arg1_mid_x; - float arg4_offset_z; - float arg1_mid_z; - float arg3_arg2_x; - float arg3_arg2_y; - float dot; - float arg3_arg2_z; - float scale_a; - float arg3_arg2_x_b; - float arg3_arg2_y_b; - float arg3_arg2_z_b; - float dot_b2; - float scale_b; - float d2_from_arg2_len_sq; - float temp_f1_3; - float var_f18; - float var_f19; - float var_f1; - u8 pad_stack[36]; - float spA4; - float spA0; - u8 pad_94[12]; - Vec3 a2; - u8 pad_7c[12]; - Vec3 c3; - u8 pad_64[12]; - Vec3 b0; - u8 pad_4c[12]; - Vec3 c2; - Vec3 arg2_copy; - Vec3 vec4; - unk_sum = arg6 + arg7; - vec4 = *arg0; + float arg1_y; + float unk_sum = arg6 + arg7; + Vec3 vec4 = *arg0; (void) vec4; arg4_offset = vec4; { + Vec3 arg2_copy; arg2_copy = *arg2; (void) arg2_copy; arg5_offset = arg2_copy; } { - arg1_x = arg1->x; + float arg1_x = arg1->x; if (arg4_offset.x > arg1_x) { { - x = arg4_offset.x + unk_sum; + float x = arg4_offset.x + unk_sum; if (x < arg5_offset.x && x < arg3->x) { return false; } } { - x2 = arg1_x - unk_sum; - if (x2 > arg5_offset.x && x2 > arg3->x) { + float x = arg1_x - unk_sum; + if (x > arg5_offset.x && x > arg3->x) { return false; } } - goto block_13; } else { { - x3 = arg4_offset.x - unk_sum; - if (x3 > arg5_offset.x && x3 > arg3->x) { + float x = arg4_offset.x - unk_sum; + if (x > arg5_offset.x && x > arg3->x) { return false; } } { - x_d = arg1_x + unk_sum; - if (x_d < arg5_offset.x && x_d < arg3->x) { + float x = arg1_x + unk_sum; + if (x < arg5_offset.x && x < arg3->x) { return false; } } } - block_13: { - temp_f1 = arg1->y; - if (arg4_offset.y > temp_f1) { - { - temp_f3 = arg4_offset.y + unk_sum; + { + if (arg4_offset.y > (arg1_y = arg1->y)) { + { + float upper_bound = arg4_offset.y + unk_sum; - if (temp_f3 < arg5_offset.y && temp_f3 < arg3->y) { - return false; + if (upper_bound < arg5_offset.y && + upper_bound < arg3->y) + { + return false; + } } - } - { - temp_f3_2 = temp_f1 - unk_sum; + { + float lower_bound = arg1_y - unk_sum; - if (temp_f3_2 > arg5_offset.y && temp_f3_2 > arg3->y) { - return false; + if (lower_bound > arg5_offset.y && + lower_bound > arg3->y) + { + return false; + } } - } - goto block_26; - } - - { - y = arg4_offset.y - unk_sum; - if (y > arg5_offset.y && y > arg3->y) { - return false; - } - } - - { - y3 = temp_f1 + unk_sum; - if (y3 < arg5_offset.y && y3 < arg3->y) { - return false; - } - } - } - block_26: { - if (arg4_offset.z > (temp_f2_5 = arg1->z)) { - { - temp_f4 = arg4_offset.z + unk_sum; - if ((temp_f4 < arg5_offset.z) && (temp_f4 < arg3->z)) { - return false; + } else { + { + float y = arg4_offset.y - unk_sum; + if (y > arg5_offset.y && y > arg3->y) { + return false; + } } - } - { - temp_f4_2 = temp_f2_5 - unk_sum; - if ((temp_f4_2 > arg5_offset.z) && (temp_f4_2 > arg3->z)) { - return false; + + { + float y = arg1_y + unk_sum; + if (y < arg5_offset.y && y < arg3->y) { + return false; + } } } - goto block_39; - } - { - temp_f4_3 = arg4_offset.z - unk_sum; - if ((temp_f4_3 > arg5_offset.z) && (temp_f4_3 > arg3->z)) { - return false; - } } { - temp_f4_4 = temp_f2_5 + unk_sum; - if ((temp_f4_4 < arg5_offset.z) && (temp_f4_4 < arg3->z)) { - return false; - } - } - block_39: { - d1_y = arg1->y - arg4_offset.y; - arg3_y = arg3->y; - d2_y = arg3_y - arg5_offset.y; - d1_z = arg1->z - arg4_offset.z; - offset_delta_y = arg4_offset.y - arg5_offset.y; - arg3_x = arg3->x; - d2_x = arg3_x - arg5_offset.x; - d1_x = arg1_x - arg4_offset.x; - arg3_z = arg3->z; - d2_z = arg3_z - arg5_offset.z; - d1_dot_d2 = d1_z * d2_z + (d1_x * d2_x + d1_y * d2_y); - d2_len_sq = (d2_z * d2_z) + ((d2_x * d2_x) + (d2_y * d2_y)); - offset_delta_x = arg4_offset.x - arg5_offset.x; - d1_len_sq = (d1_z * d1_z) + ((d1_x * d1_x) + (d1_y * d1_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); - len_product = d1_dot_d2 * d1_dot_d2; - denom = d1_len_sq * d2_len_sq - len_product; - - { - if (approximatelyZero(d2_len_sq)) { - if (approximatelyZero(d1_len_sq)) { - arg4_scl = 0.0f; - arg5_scl = 0.0f; - } else { - arg5_scl = 0.0f; + 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)) { - 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; - } + return false; + } + } + { + float lower_bound = arg1_z - unk_sum; + if ((lower_bound > arg5_offset.z) && + (lower_bound > arg3->z)) + { + return false; } } } else { - if (approximatelyZero(denom)) { - mid_y = (lbColl_804D7A18 * d2_y + arg5_offset.y); - mid_x = (lbColl_804D7A18 * d2_x + arg5_offset.x); - arg4_mid_y = arg4_offset.y - mid_y; - arg1_mid_y = arg1->y - mid_y; - mid_z = lbColl_804D7A18 * 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 lower_bound = arg4_offset.z - unk_sum; + if ((lower_bound > arg5_offset.z) && + (lower_bound > arg3->z)) { - c3 = arg5_offset; - arg3_arg2_x = arg3_x - arg2->x; - arg3_arg2_y = arg3_y - arg2->y; - { - arg3_arg2_z = arg3_z - arg2->z; - a2 = vec4; + return false; + } + } + { + float upper_bound = arg1_z + unk_sum; + if ((upper_bound < arg5_offset.z) && + (upper_bound < arg3->z)) + { + 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; + } + 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; - dot = (arg3_arg2_z * (c3.z - a2.z)) + - ((arg3_arg2_x * (c3.x - a2.x)) + - (arg3_arg2_y * (c3.y - a2.y))); - scale_a = - -dot / ((arg3_arg2_z * arg3_arg2_z) + - ((arg3_arg2_x * arg3_arg2_x) + - (arg3_arg2_y * arg3_arg2_y))); - if (scale_a > lbColl_804D7A00) { - scale_a = lbColl_804D7A08; - } else if (scale_a < lbColl_804D7A10) { - scale_a = lbColl_804D79F8; + 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; + } } - arg5_scl = scale_a; } } else { - c2 = arg5_offset; - { - arg4_scl = 1.0f; - arg3_arg2_x_b = arg3_x - arg2->x; + 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)))) { - arg3_arg2_y_b = arg3_y - arg2->y; - arg3_arg2_z_b = arg3_z - arg2->z; + float scale; + Vec3 a2; + Vec3 d1; + Vec3 c3; + + 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; { - b0 = *arg1; - { - dot_b2 = (arg3_arg2_z_b * - (c2.z - b0.z)) + - ((arg3_arg2_x_b * - (c2.x - b0.x)) + - (arg3_arg2_y_b * - (c2.y - b0.y))); - d2_from_arg2_len_sq = - (arg3_arg2_z_b * - arg3_arg2_z_b) + - ((arg3_arg2_x_b * - arg3_arg2_x_b) + - (arg3_arg2_y_b * - arg3_arg2_y_b)); - scale_b = - -dot_b2 / d2_from_arg2_len_sq; - - if (scale_b > lbColl_804D7A00) { - scale_b = lbColl_804D7A08; - } else if (scale_b < - lbColl_804D7A10) - { - scale_b = lbColl_804D79F8; - } + 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; + } 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; + { + float dot; + float scale; - arg5_scl = scale_b; + 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; } + + arg5_scl = scale; } } - } - } - } else { - temp_f1_3 = ((d1_dot_d2 * d2_dot_offset_delta) - + } 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 = temp_f1_3; - if (temp_f1_3 > lbColl_804D7A00 || - arg4_scl < lbColl_804D7A10 || - arg5_scl > lbColl_804D7A00 || - arg5_scl < lbColl_804D7A10) - { - if (arg4_scl < lbColl_804D7A10) { - var_f19 = lbColl_804D79F8; - var_f18 = - lbColl_80005EBC(arg2, arg3, arg0, &spA4); - } else { - var_f19 = lbColl_804D7A08; - var_f18 = - lbColl_80005EBC(arg2, arg3, arg1, &spA4); - } + 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); + } else { + candidate0_scale = lbColl_804D7A08; + candidate0_dist_sq = lbColl_80005EBC( + arg2, arg3, arg1, &spA4); + } - { - if (arg5_scl < lbColl_804D7A10) { - arg5_scl = lbColl_804D79F8; - var_f1 = lbColl_80005EBC(arg0, arg1, arg2, - &spA0); - } else { - arg5_scl = lbColl_804D7A08; - var_f1 = lbColl_80005EBC(arg0, arg1, arg3, - &spA0); - } + { + float spA0; + if (arg5_scl < lbColl_804D7A10) { + arg5_scl = lbColl_804D79F8; + candidate1_dist_sq = + lbColl_80005EBC(arg0, arg1, + arg2, &spA0); + } else { + float result; + arg5_scl = lbColl_804D7A08; + result = lbColl_80005EBC( + arg0, arg1, arg3, &spA0); + candidate1_dist_sq = result; + } - if (var_f18 < var_f1) { - arg4_scl = var_f19; - arg5_scl = spA4; - } else { - arg4_scl = spA0; + if (candidate0_dist_sq < + candidate1_dist_sq) + { + arg4_scl = candidate0_scale; + arg5_scl = spA4; + } else { + arg4_scl = spA0; + } + } } } } - } - } - 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; + } + } + PAD_STACK(72); + return end(arg4, arg5, unk_sum); } } - return end(arg4, arg5, unk_sum); - } - } } } @@ -718,105 +688,58 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, float diff_dc_y; float d_y; float diff_ba_y; - float diff_ba_x; + float sqdist2_dc; float d_x; Vec3 a1; - float sqdist2_dc; + float diff_ba_x; float sqdist2_ba; Vec3 c1; float dot2_diff_dc_ac; float dot2_diff_ba_ac; float determinant; float sum_pq = p + q; - u8 operand_pad[8]; - u8 pad_stack[32]; - float b_x; - float x; - float x2; - float x3; - float temp_f2_4; - float loaded_b_y; - float b_y; - float y; - float y2; - float y3; - float y4; - float dot2_diff_ba_dc; - float diff_ac_y; - float temp_f1_2; - float temp_f7_2; - float temp_f5_2; - float temp_f6_2; - float temp_f7_3; - float temp_scl_f; - float f4; - float temp_f5_3; - float diff_dc_x_b; - float temp_f8_2; - float diff_dc_z; - float dot; - float diff_dc_x1; - float diff_dc_y1; - float diff_dc_z1; - float dot_b; - float var_f2_2; - float temp_f1_3; - float result0; - float temp_scl_e; - float result1; - float diff_ef_y; - float diff_ef_x; - float scl_e; - float scl_f; - float out0; - float out1; - u8 pad_94[12]; - Vec3 a2; - u8 pad_7c[12]; - Vec3 c3; - u8 pad_64[12]; - Vec3 b0; - u8 pad_4c[12]; - Vec3 c2; - Vec3 c0; Vec3 a0; + PAD_STACK(48); + a0 = *a; (void) a0; a1 = a0; { + Vec3 c0; + c0 = *c; (void) c0; { c1 = c0; { - b_x = b->x; + float b_x = b->x; if (a1.x > b_x) { { - x = a1.x + sum_pq; + float x = a1.x + sum_pq; if (x < c1.x && x < d->x) { return false; } } { - x2 = b_x - sum_pq; - if ((x2 > c1.x) && (x2 > d->x)) { + float x = b_x - sum_pq; + if ((x > c1.x) && (x > d->x)) { return false; } } } else { { - x3 = a1.x - sum_pq; - if (x3 > c1.x && x3 > d->x) { + float x = a1.x - sum_pq; + if (x > c1.x && x > d->x) { return false; } } { - temp_f2_4 = b_x + sum_pq; + float temp_f2_4 = b_x + sum_pq; if (temp_f2_4 < c1.x && temp_f2_4 < d->x) { return false; } @@ -824,52 +747,62 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, } { - loaded_b_y = b->y; - b_y = loaded_b_y; - if (a1.y > b_y) { + float a1_y = a1.y; + float loaded_b_y = b->y; + float b_y = loaded_b_y; + if (a1_y > b_y) { { - y = a1.y; + float y; + y = a1_y; y += sum_pq; if (y < c1.y && y < d->y) { return false; } } { - y2 = b_y - sum_pq; - if (y2 > c1.y && y2 > d->y) { + float y = b_y - sum_pq; + if (c1.y < y && y > d->y) { return false; } } } else { { - y3 = a1.y - sum_pq; - if (y3 > c1.y && y3 > d->y) { + float y = a1_y - sum_pq; + if (y > c1.y && y > d->y) { return false; } } { - y4 = b_y + sum_pq; - if (y4 < c1.y && y4 < d->y) { + float y = b_y + sum_pq; + if (y < c1.y && y < d->y) { return false; } } } { - diff_ba_y = b_y - a1.y; + float dot2_diff_ba_dc; + float diff_ac_y; + diff_ba_y = b_y - a1_y; d_y = lbColl_GetY(d); - diff_ac_y = a1.y - c1.y; + diff_ac_y = a1_y - c1.y; diff_dc_y = d_y - c1.y; diff_ba_x = b_x - a1.x; - d_x = d->x; + { + float loaded_d_x = d->x; + d_x = loaded_d_x; + } diff_dc_x = d_x - c1.x; dot2_diff_ba_dc = lbColl_Dot2(diff_ba_x, diff_ba_y, diff_dc_x, diff_dc_y); - sqdist2_dc = - diff_dc_x * diff_dc_x + diff_dc_y * diff_dc_y; + { + float dist2_dc = + diff_dc_x * diff_dc_x + diff_dc_y * diff_dc_y; + sqdist2_dc = dist2_dc; + } sqdist2_ba = diff_ba_x * diff_ba_x + diff_ba_y * diff_ba_y; diff_ac_x = a1.x - c1.x; @@ -880,15 +813,22 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, dot2_diff_ba_ac = diff_ba_x * diff_ac_x + diff_ba_y * diff_ac_y; - determinant = sqdist2_ba * sqdist2_dc - - dot2_diff_ba_dc * dot2_diff_ba_dc; + { + float lengths_product = sqdist2_ba * sqdist2_dc; + determinant = lengths_product - + dot2_diff_ba_dc * dot2_diff_ba_dc; + } { + 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; scl_f = 0.0f; temp_f1_2 = -dot2_diff_ba_ac / sqdist2_ba; scl_e = temp_f1_2; @@ -899,95 +839,82 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, } } } else if (approximatelyZero(determinant)) { - temp_f7_2 = lbColl_804D7A18 * diff_dc_y + c1.y; - temp_f5_2 = lbColl_804D7A18 * diff_dc_x + c1.x; - temp_f6_2 = a1.y - temp_f7_2; - temp_f7_3 = b_y - temp_f7_2; + 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; { - f4 = a1.x - temp_f5_2; - temp_f5_3 = b_x - temp_f5_2; - if ((f4 * f4 + temp_f6_2 * temp_f6_2) < - (temp_f5_3 * temp_f5_3 + - temp_f7_3 * temp_f7_3)) + 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; - diff_dc_x_b = d_x - c->x; - temp_f8_2 = d_y - c->y; + scl_e = 0.0f; + delta.x = d_x - c->x; + delta.y = d_y - c->y; + delta.z = d->z - c->z; { - { - diff_dc_z = d->z - c->z; - a2 = a0; - scl_e = 0.0f; - dot = - diff_dc_z * (c3.z - a2.z) + - ((diff_dc_x_b * - (c3.x - a2.x)) + - (temp_f8_2 * - (c3.y - a2.y))); - temp_scl_f = - -dot / - ((diff_dc_z * diff_dc_z) + - ((diff_dc_x_b * - diff_dc_x_b) + - (temp_f8_2 * - temp_f8_2))); - } + 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))); } - if (temp_scl_f > lbColl_804D7A00) { - temp_scl_f = lbColl_804D7A08; - } else if (temp_scl_f < - lbColl_804D7A10) - { - temp_scl_f = lbColl_804D79F8; + if (scale > lbColl_804D7A00) { + scale = lbColl_804D7A08; + } else if (scale < lbColl_804D7A10) { + scale = lbColl_804D79F8; } - scl_f = temp_scl_f; + 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; { - scl_e = 1.0f; - diff_dc_x1 = d_x - c->x; + 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) { - diff_dc_y1 = d_y - c->y; - diff_dc_z1 = d->z - c->z; - { - b0 = *b; - { - dot_b = - diff_dc_z1 * - (c2.z - b0.z) + - ((diff_dc_x1 * - (c2.x - b0.x)) + - (diff_dc_y1 * - (c2.y - b0.y))); - var_f2_2 = - -dot_b / - ((diff_dc_z1 * - diff_dc_z1) + - ((diff_dc_x1 * - diff_dc_x1) + - (diff_dc_y1 * - diff_dc_y1))); - if (var_f2_2 > - lbColl_804D7A00) - { - var_f2_2 = - lbColl_804D7A08; - } else if ( - var_f2_2 < - lbColl_804D7A10) - { - var_f2_2 = - lbColl_804D79F8; - } - scl_f = var_f2_2; - } - } + scale = lbColl_804D79F8; } + scl_f = scale; } } } } else { - temp_f1_3 = + float temp_f1_3 = ((dot2_diff_ba_dc * dot2_diff_dc_ac) - (sqdist2_dc * dot2_diff_ba_ac)) / determinant; @@ -1000,6 +927,9 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, (scl_f > lbColl_804D7A00) || (scl_f < lbColl_804D7A10)) { + float out0; + float result0; + float temp_scl_e; { if (scl_e < lbColl_804D7A10) { temp_scl_e = lbColl_804D79F8; @@ -1012,6 +942,7 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, } } { + float result1; if (scl_f < lbColl_804D7A10) { scl_f = lbColl_804D79F8; result1 = lbColl_80005FC0(a, b, c, @@ -1033,7 +964,7 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, } e->x = diff_ba_x * scl_e + a1.x; - e->y = diff_ba_y * scl_e + a1.y; + e->y = diff_ba_y * scl_e + a1_y; e->z = 0.0f; f->x = diff_dc_x * scl_f + c1.x; @@ -1046,6 +977,8 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, } } { + float diff_ef_y; + float diff_ef_x; diff_ef_y = e->y - f->y; diff_ef_x = e->x; diff_ef_x -= f->x; @@ -1085,10 +1018,10 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float hit_start_mid_x; float local_delta_x; float hurt_mid_z; - u8 operand_pad[4]; Vec3 hit_start_copy; Vec3 hurt_start_copy; Vec3 hit_delta; + u8 operand_pad[4]; float start_delta_z; float hit_start_dot; float scaled_hurt_radius; @@ -1159,7 +1092,7 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, s32 is_zero_distance; float hurt_delta_z; float hurt_delta_y; - PAD_STACK(60); + PAD_STACK(52); // Fast reject when the expanded hit segment AABB misses both hurt // endpoints. @@ -1276,10 +1209,12 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, hurt_len_sq = (hurt_delta_z * hurt_delta_z) + hurt_len_sq; hit_start_mid_z = hit_delta.z * hit_delta.z; start_delta_z = hit_start_copy.z - hurt_start_copy.z; - hit_len_sq = hit_start_mid_x + hit_start_mid_y; - hit_len_sq = hit_start_mid_z + hit_len_sq; + hit_len_sq = hit_start_mid_z + (hit_start_mid_x + hit_start_mid_y); hit_start_dot = hit_delta.y * start_delta_y; - hit_start_dot = (hit_delta.x * start_delta_x) + hit_start_dot; + { + 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; diff --git a/src/melee/lb/lbsnap.c b/src/melee/lb/lbsnap.c index 878f234c03..7a7387deda 100644 --- a/src/melee/lb/lbsnap.c +++ b/src/melee/lb/lbsnap.c @@ -229,7 +229,10 @@ void lbSnap_8001DA5C(const u8* arg0) src_x, src_y_accum / 64 + 96, 160)]; *(u16*) &dst_col[lbSnap_GetTiledYOff(tile_column, dst_y + 16)] = RGB565_TO_RGB5A3(pixel); - src_y_accum += 448; + { + int next_src_y_accum = src_y_accum + 448; + src_y_accum = next_src_y_accum; + } pixel = *(u16*) &arg0[lbSnap_GetTiledRGBOffset( src_x, src_y_accum / 64 + 96, 160)]; diff --git a/src/melee/mn/mndiagram.c b/src/melee/mn/mndiagram.c index 7da094ad96..309965f9cc 100644 --- a/src/melee/mn/mndiagram.c +++ b/src/melee/mn/mndiagram.c @@ -415,6 +415,18 @@ static inline int mnDiagram_CountUnlockedFightersInline(void) return count; } +static inline int mnDiagram_CountUnlockedFightersForHeaders(void) +{ + int i; + int count = 0; + for (i = 0; i < SELKIND_COUNT; i++) { + if (mn_IsFighterUnlocked(i)) { + count++; + } + } + return count; +} + /// @brief Formats a number with optional decimal places. /// @param buf Output buffer for the string. /// @param val The value to format (treat last decimal_places digits as @@ -1041,7 +1053,6 @@ static inline u8 mnDiagram_GetVisibleNameCursorFrom(u8* sorted, int start, int rank) { u8* p; - u8* p2; int remaining; int idx; @@ -1050,6 +1061,7 @@ static inline u8 mnDiagram_GetVisibleNameCursorFrom(u8* sorted, int start, idx = start; p = p + 0x1C; while (remaining > 0) { + u8* p2; p2 = p; loop: idx++; @@ -1155,6 +1167,11 @@ static inline u8 mnDiagram_GetVisibleFighterCursorFrom2(u8* sorted, int start, /// The "visible entry" scans skip locked fighters / empty name slots, and are /// factored into the mnDiagram_GetVisible*From / /// mnDiagram_Get{Prev,Next}*Index helpers shared with mndiagram2. +static inline Diagram* mnDiagram_GetCurrentDiagramData(void) +{ + return mnDiagram_804D6C10->user_data; +} + void mnDiagram_InputProc(HSD_GObj* gobj) { u8* ptr; @@ -1165,7 +1182,7 @@ void mnDiagram_InputProc(HSD_GObj* gobj) u8* ptr3; s16 new_var; u8* sorted = mnDiagram_804A0750.sorted_fighters; - Diagram* data = mnDiagram_804D6C10->user_data; + Diagram* data = mnDiagram_GetCurrentDiagramData(); u32 input = mn_80229624(4); s32 count = 0; s32 col; @@ -1185,9 +1202,9 @@ void mnDiagram_InputProc(HSD_GObj* gobj) u8 row_result4; s32 found; s32 cur; + s32 cursor_pos; s32 count2; - u8 operand_pad[4]; - u8 sp[64]; + PAD_STACK(48); mn_804A04F0.buttons = input; count2 = 0; if (input & MenuInput_Confirm) { @@ -1205,8 +1222,9 @@ void mnDiagram_InputProc(HSD_GObj* gobj) sorted, (u8) data->name_cursor_pos, (u8) cur); row = mn_804A04F0.hovered_selection >> 8; (void) row; + cursor_pos = data->name_cursor_pos; row_result = mnDiagram_GetVisibleNameFrom( - sorted, data->name_cursor_pos >> 8, row); + sorted, cursor_pos >> 8, mn_804A04F0.hovered_selection >> 8); mnDiagram_CreatePopup(col_result, row_result, 1); return; } @@ -1273,7 +1291,7 @@ void mnDiagram_InputProc(HSD_GObj* gobj) sfxBack(); mn_804A04F0.entering_menu = count2; { - Diagram* d = mnDiagram_804D6C10->user_data; + Diagram* d = mnDiagram_GetCurrentDiagramData(); gmMainLib_GetGameRules()->xE = (u8) (d->fighter_cursor_pos >> 8); gmMainLib_GetGameRules()->xF = (u8) d->fighter_cursor_pos; gmMainLib_GetGameRules()->unk_x10 = (u8) (d->name_cursor_pos >> 8); @@ -1286,7 +1304,7 @@ void mnDiagram_InputProc(HSD_GObj* gobj) if (input & (MenuInput_LTrigger | MenuInput_RTrigger)) { sfxForward(); { - Diagram* d = mnDiagram_804D6C10->user_data; + Diagram* d = mnDiagram_GetCurrentDiagramData(); gmMainLib_GetGameRules()->xE = (u8) (d->fighter_cursor_pos >> 8); gmMainLib_GetGameRules()->xF = (u8) d->fighter_cursor_pos; gmMainLib_GetGameRules()->unk_x10 = (u8) (d->name_cursor_pos >> 8); @@ -2435,7 +2453,7 @@ void mnDiagram_DrawGridValues(void* arg0, s32 arg1, s32 arg2, u8 arg3) s32 entry_count; s32 name_kos; s32 fighter_falls; - u8 row_name; + s32 row_name; s32 col_name; s32 row_fighter; u8 col_fighter; @@ -2450,21 +2468,21 @@ void mnDiagram_DrawGridValues(void* arg0, s32 arg1, s32 arg2, u8 arg3) if (is_name_mode != 0) { entry_count = GetNameCount(); if (entry_count > bottom_col) { - name_falls = mnDiagram_SumNameFalls( - mnDiagram_GetVisibleNameCursorFrom( - sorted, col_start, bottom_col)); - mnDiagram_DrawCellValue(arg0, (u8) bottom_col, - (u8) row, name_falls); + mnDiagram_DrawCellValue( + arg0, (u8) bottom_col, (u8) row, + mnDiagram_SumNameFalls( + mnDiagram_GetVisibleNameFrom(sorted, col_start, + bottom_col))); } } else { bottom_unlocked_count = mnDiagram_CountUnlockedFightersInline(); if (bottom_unlocked_count > bottom_col) { - fighter_falls = mnDiagram_SumFighterFalls( - mnDiagram_GetVisibleFighterCursorFrom2( - sorted, col_start, bottom_col)); - mnDiagram_DrawCellValue(arg0, (u8) bottom_col, - (u8) row, fighter_falls); + mnDiagram_DrawCellValue( + arg0, (u8) bottom_col, (u8) row, + mnDiagram_SumFighterFalls( + mnDiagram_GetVisibleFighterCursorFrom2( + sorted, col_start, bottom_col))); } } bottom_col += 1; @@ -2478,7 +2496,7 @@ void mnDiagram_DrawGridValues(void* arg0, s32 arg1, s32 arg2, u8 arg3) if ((name_col == 7) || (entry_count = GetNameCount(), (entry_count > name_col))) { - row_name = mnDiagram_GetVisibleNameCursorFrom( + row_name = mnDiagram_GetVisibleNameFrom2( sorted, row_start, row); if (name_col == 7) { name_kos = mnDiagram_GetNameTotalKOs(row_name); @@ -2488,7 +2506,7 @@ void mnDiagram_DrawGridValues(void* arg0, s32 arg1, s32 arg2, u8 arg3) int ko_count; col_name = mnDiagram_GetVisibleNameCursorFrom( sorted, col_start, name_col); - ko_count = GetPersistentNameData(row_name) + ko_count = GetPersistentNameData((u8) row_name) ->vs_kos[col_name]; mnDiagram_DrawCellValue(arg0, (u8) name_col, (u8) row, ko_count); @@ -2633,29 +2651,30 @@ HSD_JObj* mnDiagram_CreateFighterIcon(int idx, int arg1) void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) { - int count; + int selkind; + s32 count; u8* pr; - u8* p2; + void** joint_data; int remr; HSD_JObj* jobj; Diagram* data = GET_DIAGRAM(arg0); - mnDiagram_Assets* assets = (mnDiagram_Assets*) &mnDiagram_804A0750; - void** joint_data; + int fighter_id; + u8* p2; u8 stack_obj[8]; HSD_JObj* sp_jobj; u8 stack_obj2[4]; + HSD_JObj* jobj2; HSD_JObj* sp_jobj2; - u8 stack_obj3[20]; - int k; + u8 stack_obj3[12]; int idx; int remaining; u8* p; u8* sorted; - int fighter_id; + mnDiagram_Assets* assets = (mnDiagram_Assets*) &mnDiagram_804A0750; u8* pr2; f32 x_spacing; f32 y_spacing; - int selkind; + int fighter_kind; int i; (void) &stack_obj; @@ -2663,14 +2682,10 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) (void) &stack_obj3; // Column headers (fighter icons) - joint_data = assets->FaceB; for (i = 0; i < 7; i++) { sorted = mnDiagram_804A0750.sorted_fighters; - for (count = k = 0; k < SELKIND_COUNT; k++) { - if (mn_IsFighterUnlocked(k) != 0) { - count++; - } - } + joint_data = assets->FaceB; + count = mnDiagram_CountUnlockedFightersForHeaders(); if (count > i) { remaining = i; idx = arg2; @@ -2685,8 +2700,8 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) idx++; p2++; p++; - if (idx >= SELKIND_COUNT) { - fighter_id = SELKIND_COUNT; + if (idx >= 0x19) { + fighter_id = 0x19; goto col_found; } if (mn_IsFighterUnlocked(*p2) == 0) { @@ -2703,10 +2718,11 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) lb_80011E24(jobj, &sp_jobj, 2, -1); HSD_JObjReqAnimAll(sp_jobj, (f32) (fighter_id & 0xFF)); HSD_JObjAnimAll(sp_jobj); + jobj2 = jobj; x_spacing = HSD_JObjGetTranslationX(data->jobjs[8]) - - HSD_JObjGetTranslationX(data->jobjs[7]); - HSD_JObjSetTranslateX(jobj, x_spacing * i); - HSD_JObjAddChild(data->jobjs[7], jobj); + HSD_JObjGetTranslationX(jobj = data->jobjs[7]); + HSD_JObjSetTranslateX(jobj2, x_spacing * i); + HSD_JObjAddChild(data->jobjs[7], jobj2); } } @@ -2714,12 +2730,7 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) joint_data = assets->FaceB; for (i = 0; i < 0xA; i++) { sorted = mnDiagram_804A0750.sorted_fighters; - count = 0; - for (k = 0; k < SELKIND_COUNT; k++) { - if (mn_IsFighterUnlocked(k) != 0) { - count++; - } - } + count = mnDiagram_CountUnlockedFightersForHeaders(); if (count > i) { remr = i; idx = arg1; @@ -2734,7 +2745,7 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) idx++; pr2++; pr++; - if (idx >= SELKIND_COUNT) { + if (idx >= 0x19) { selkind = SELKIND_COUNT; goto row_found; } @@ -2750,21 +2761,17 @@ void mnDiagram_DrawFighterHeaders(void* arg0, int arg1, int arg2) HSD_JObjReqAnimAll(jobj, 0.0f); HSD_JObjAnimAll(jobj); lb_80011E24(jobj, &sp_jobj2, 2, -1); - HSD_JObjReqAnimAll(sp_jobj2, (f32) (selkind & 0xFF)); + fighter_kind = selkind & 0xFF; + HSD_JObjReqAnimAll(sp_jobj2, (f32) fighter_kind); HSD_JObjAnimAll(sp_jobj2); y_spacing = HSD_JObjGetTranslationY(data->jobjs[10]) - - HSD_JObjGetTranslationY(data->jobjs[9]); + HSD_JObjGetTranslationY(jobj2 = data->jobjs[9]); HSD_JObjSetTranslateY(jobj, y_spacing * i); HSD_JObjAddChild(data->jobjs[9], jobj); } } } -static inline Diagram* mnDiagram_GetCurrentDiagramData(void) -{ - return mnDiagram_804D6C10->user_data; -} - void mnDiagram_CursorProc(HSD_GObj* gobj) { HSD_JObj* sp_jobj; diff --git a/src/melee/mn/mndiagram2.c b/src/melee/mn/mndiagram2.c index d74e6f0e50..90225529f8 100644 --- a/src/melee/mn/mndiagram2.c +++ b/src/melee/mn/mndiagram2.c @@ -294,14 +294,14 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) { Diagram2* data; int result; - Diagram2* data2; + HSD_GObj* d2; u8 x46; u8 x47; u8 x48; - u8 var_r6; - u8 var_r5; - int var_r28; - HSD_GObj* d2; + u8 entity_idx; + int selection; + Diagram2* data2; + GameRules* rules; PAD_STACK(40); { @@ -315,7 +315,8 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) mn_804A04F0.entering_menu = 0; data2 = (d2 = mnDiagram2_804D6C18)->user_data; x46 = data2->selected_fighter_idx; - gmMainLib_GetGameRules()->x12 = x46; + rules = gmMainLib_GetGameRules(); + rules->x12 = x46; x47 = data2->selected_name_idx; gmMainLib_GetGameRules()->x13 = x47; gmMainLib_GetGameRules()->xD = (x48 = data2->is_name_mode ^ 0); @@ -324,6 +325,7 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) return; } + selection = 0; if (result & 0xC0) { sfxForward(); data2 = mnDiagram2_804D6C18->user_data; @@ -342,7 +344,6 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) return; } - var_r28 = 0; if (result & 0xC00) { if (GetNameCount() == 0) { lbAudioAx_80024030(3); @@ -350,21 +351,21 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) } sfxForward(); if (data->is_name_mode == 0) { - var_r28 = 1; + selection = 1; } - data->is_name_mode = var_r28; + data->is_name_mode = selection; if (data->is_name_mode == 0 && (s32) (data->scroll_offset + 10) > 0x15) { data->scroll_offset = 0; } mnDiagram2_RefreshStatRows(); if (data->is_name_mode != 0) { - var_r5 = data->selected_name_idx; + entity_idx = data->selected_name_idx; } else { - var_r5 = data->selected_fighter_idx; + entity_idx = data->selected_fighter_idx; } mnDiagram2_UpdateHeader(mnDiagram2_804D6C18, data->is_name_mode, - var_r5); + entity_idx); x48 = data->is_name_mode; data2 = (d2 = mnDiagram2_804D6C18)->user_data; if (x48 != 0) { @@ -375,11 +376,11 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) HSD_JObjSetFlagsAll(data2->name_mode_header, JOBJ_HIDDEN); } if (x48 != 0) { - var_r5 = data2->selected_name_idx; + entity_idx = data2->selected_name_idx; } else { - var_r5 = data2->selected_fighter_idx; + entity_idx = data2->selected_fighter_idx; } - mnDiagram2_UpdateHeader(d2, x48, var_r5); + mnDiagram2_UpdateHeader(d2, x48, entity_idx); return; } @@ -398,22 +399,22 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) mnDiagram2_RefreshStatRows(); } } else if (result & 4) { - var_r28 = + selection = (u8) mnDiagram_GetPrevNameIndex_s(data->selected_name_idx); - if ((s32) data->selected_name_idx != var_r28) { + if ((s32) data->selected_name_idx != selection) { sfxMove(); - data->selected_name_idx = var_r28; + data->selected_name_idx = selection; mnDiagram2_RefreshStatRows(); mnDiagram2_UpdateHeader(mnDiagram2_804D6C18, data->is_name_mode, data->selected_name_idx); } } else if (result & 8) { - var_r28 = + selection = (u8) mnDiagram_GetNextNameIndex_s(data->selected_name_idx); - if ((s32) data->selected_name_idx != var_r28) { + if ((s32) data->selected_name_idx != selection) { sfxMove(); - data->selected_name_idx = var_r28; + data->selected_name_idx = selection; mnDiagram2_RefreshStatRows(); mnDiagram2_UpdateHeader(mnDiagram2_804D6C18, data->is_name_mode, @@ -435,22 +436,22 @@ void mnDiagram2_HandleInput(HSD_GObj* gobj) mnDiagram2_RefreshStatRows(); } } else if (result & 4) { - var_r28 = (u8) mnDiagram_GetPrevFighterIndex_s( + selection = (u8) mnDiagram_GetPrevFighterIndex_s( data->selected_fighter_idx); - if ((s32) data->selected_fighter_idx != var_r28) { + if ((s32) data->selected_fighter_idx != selection) { sfxMove(); - data->selected_fighter_idx = var_r28; + data->selected_fighter_idx = selection; mnDiagram2_RefreshStatRows(); mnDiagram2_UpdateHeader(mnDiagram2_804D6C18, data->is_name_mode, data->selected_fighter_idx); } } else if (result & 8) { - var_r28 = (u8) mnDiagram_GetNextFighterIndex_s( + selection = (u8) mnDiagram_GetNextFighterIndex_s( data->selected_fighter_idx); - if ((s32) data->selected_fighter_idx != var_r28) { + if ((s32) data->selected_fighter_idx != selection) { sfxMove(); - data->selected_fighter_idx = var_r28; + data->selected_fighter_idx = selection; mnDiagram2_RefreshStatRows(); mnDiagram2_UpdateHeader(mnDiagram2_804D6C18, data->is_name_mode, @@ -628,18 +629,17 @@ 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) { - u8 str[8]; Vec3 sp20; Diagram2* data; HSD_JObj* jobj; MnDiagram2RowLayout* base; HSD_Text* text; + HSD_Text* text2; f32 f31; - f32 f30; int mode = is_name_mode; - Diagram2* user_data = gobj->user_data; + f32 f30; - data = user_data; + data = gobj->user_data; base = &mnDiagram2_803EEAD0; f31 = HSD_JObjGetTranslationY(data->row0_ref); @@ -650,9 +650,9 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, { u32 r22 = row_idx; f32 ny = -sp20.y; - f32 temp_f31 = -f30 * (f32) r22; - text = HSD_SisLib_803A5ACC(0, 1, sp20.x, ny + temp_f31, sp20.z, 320.0f, - 240.0f); + 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); { data->row_labels[row_idx] = text; @@ -663,14 +663,11 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, { int r21 = base->unit_glyph_ids[stat_type]; if (r21 != 0xFFFF) { - HSD_Text* text2; int var_r3; lb_8000B1CC(data->row0_ref, &base->label_pos, &sp20); - { - f32 py2 = -sp20.y + temp_f31; - text2 = HSD_SisLib_803A5ACC( - 0, 1, 12.0f + sp20.x, py2, sp20.z, 1.0f, 1.0f); - } + text2 = HSD_SisLib_803A5ACC(0, 1, 12.0f + sp20.x, + -sp20.y + row_y_offset, + sp20.z, 1.0f, 1.0f); data->row_icons[row_idx] = text2; text2->default_alignment = 1; @@ -712,13 +709,14 @@ 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); { - f32 py = -sp20.y + temp_f31; + f32 py = -sp20.y + row_y_offset; text3->pos_x = sp20.x; text3->pos_y = py; text3->pos_z = sp20.z; @@ -729,8 +727,11 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, if (mnDiagram2_IsTimeStat(stat_type)) { int val = mnDiagram2_GetStatValue(mode, stat_type, entity_idx); - if ((u32) val > 0x927BF) { - val = 0x927BF; + { + u32 unsigned_val = (u32) val; + if (unsigned_val > 0x927BF) { + val = 0x927BF; + } } mnDiagram_FormatTime((char*) str, val); } else { @@ -766,7 +767,7 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, str[2] = mnDiagram2_804D4FD0[2]; } else { int val = mnDiagram2_GetStatValue( - is_name_mode, stat_type, entity_idx); + mode, stat_type, entity_idx); if ((u32) val > 0x98967F) { val = 0x98967F; } @@ -1002,18 +1003,19 @@ void mnDiagram2_Create(int arg0) { int entity_val; Diagram2* user_data; - mnDiagram_ArchiveData* archive = &mnDiagram_804A0834; + u8 entity_idx; HSD_GObj* gobj; Diagram2* new_var; int j; - u32 is_name; - u8 entity_idx; + int threshold; + mnDiagram_ArchiveData* archive = &mnDiagram_804A0834; int scroll; int i; - int threshold; + u32 is_name; HSD_JObj* jobj; int offset; Diagram2* user_data2; + HSD_JObj** cursor; gobj = GObj_Create(6, 7, 0x80); mnDiagram2_804D6C18 = gobj; @@ -1029,10 +1031,13 @@ void mnDiagram2_Create(int arg0) GObj_InitUserData(gobj, 0, (void (*)(void*)) mnDiagram2_FreeUserData, user_data); - for (i = 0; i < 15; i++) { - lb_80011E24(jobj, (HSD_JObj**) ((u8*) user_data + (i << 2) + 8), i, - -1); - } + i = (offset = 0); + cursor = (HSD_JObj**) user_data + i; + do { + lb_80011E24(jobj, cursor + 2, i, -1); + i++; + cursor++; + } while (i < 15); HSD_GObj_SetupProc(gobj, mnDiagram2_Think, 0); @@ -1066,7 +1071,10 @@ void mnDiagram2_Create(int arg0) j++; } while (j < 10); - is_name = user_data->is_name_mode; + { + u32 mode = user_data->is_name_mode; + is_name = mode; + } user_data2 = gobj->user_data; if (is_name) { HSD_JObjSetFlagsAll(user_data2->fighter_mode_header, JOBJ_HIDDEN); diff --git a/src/melee/mn/mndiagram3.c b/src/melee/mn/mndiagram3.c index 8c3f7136c6..3f9ddd4805 100644 --- a/src/melee/mn/mndiagram3.c +++ b/src/melee/mn/mndiagram3.c @@ -35,6 +35,13 @@ typedef struct mnDiagram3_StatTable { /* 0x30 */ u16 unit_glyph_ids[24]; ///< mnDiagram2 unit/icon column entries } mnDiagram3_StatTable; +typedef struct mnDiagram3_DataTable { + /* 0x00 */ AnimLoopSettings x0; + /* 0x0C */ AnimLoopSettings xC; + /* 0x18 */ mnDiagram3_PosTable positions; + /* 0x3C */ mnDiagram3_StatTable stats; +} mnDiagram3_DataTable; + /* 3EEC10 */ extern AnimLoopSettings mnDiagram3_803EEC10; /* 3EEC1C */ extern AnimLoopSettings mnDiagram3_803EEC1C; /* 3EEC28 */ extern mnDiagram3_PosTable mnDiagram3_803EEC28; @@ -64,11 +71,12 @@ HSD_GObj* mnDiagram3_804D6C20; void mnDiagram3_PopulateRankings(HSD_GObj* gobj) { + u16* unit_glyph_ids; Vec3 sp6C; u32 max_distance; u8 sp58[0x10]; u8 sp48[0x10]; - u8 sp38[0x10]; + u8 fighter_rank[0x10]; union { u8 bytes[0x10]; struct { @@ -79,7 +87,7 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) } fields; } sp28; Diagram3* data; - char* base; + mnDiagram3_DataTable* table; HSD_JObj* row0; f32 neg_spacing; f32 row_spacing; @@ -96,17 +104,20 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) u32 max_percentage; data = gobj->user_data; - base = (char*) &mnDiagram3_803EEC10; + table = (mnDiagram3_DataTable*) &mnDiagram3_803EEC10; { - u8 scroll = data->cursor_row; - u8 offset = data->scroll_offset; + u8 offset; + u8 scroll; u8 limit; + scroll = data->cursor_row; + offset = data->scroll_offset; limit = (data->is_name_mode != 0) ? 0x18 : 0x15; { - int val = scroll + offset; + int sum = offset + scroll; + int val = sum; if (val >= limit) { val = val - limit; } else { @@ -122,11 +133,7 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) f32 row1_y = HSD_JObjGetTranslationY(data->jobjs[7]); { - u16* stat_table; - char* stat_ptr; - stat_ptr = base; - stat_ptr += (int) stat_type << 1; - stat_table = (u16*) stat_ptr; + unit_glyph_ids = table->stats.unit_glyph_ids; icon_x_offset = mnDiagram3_804DC010; row_spacing = row1_y; (void) row_spacing; @@ -136,49 +143,53 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) divider = mnDiagram3_804DC008; max_time = 0x5B8D7F; neg_spacing = -row_spacing; - stat_ptr += 0x6C; - stat_table = (u16*) stat_ptr; for (i = 0; i < 5; i++) { - if (data->is_name_mode != 0) { - if (!mnDiagram2_IsIconOnlyStat(stat_type)) { - if (i == 0) { - lb_8000B1CC(data->jobjs[6], (Vec3*) (base + 0x24), - &sp6C); - 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; - title_text->pos_y = (new_var = -y); - title_text->pos_z = z; + { + int is_name_mode = data->is_name_mode; + + if (is_name_mode != 0) { + if (!mnDiagram2_IsIconOnlyStat(stat_type)) { + if (i == 0) { + lb_8000B1CC(data->jobjs[6], + &table->positions.xC, &sp6C); + 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; + title_text->pos_y = (new_var = -y); + title_text->pos_z = z; + } } - } - entity = mnDiagram2_GetRankedName(stat_type, (u8) i); - if (entity == 0x78) { - goto next; - } - { - char* name_str = GetNameText(entity); - f32 f1 = mnDiagram3_804DC00C; - f32 offset_y = neg_spacing * (f32) i / divider; - HSD_SisLib_803A6B98(title_text, f1, offset_y, - name_str); + entity = + mnDiagram2_GetRankedName(stat_type, (u8) i); + if (entity == 0x78) { + continue; + } + { + char* name_str = GetNameText(entity); + f32 f1 = mnDiagram3_804DC00C; + f32 offset_y = neg_spacing * (f32) i / divider; + HSD_SisLib_803A6B98(title_text, f1, offset_y, + name_str); + } } + } else { + entity = + mnDiagram2_GetRankedFighter(stat_type, (u8) i); + icon = mnDiagram_CreateFighterIcon(entity, 0); + HSD_JObjSetTranslateY(icon, row_spacing * (f32) i); + HSD_JObjAddChild(data->jobjs[6], icon); } - } else { - entity = mnDiagram2_GetRankedFighter(stat_type, (u8) i); - icon = mnDiagram_CreateFighterIcon(entity, 0); - HSD_JObjSetTranslateY(icon, row_spacing * (f32) i); - HSD_JObjAddChild(data->jobjs[6], icon); } if (i == 0) { - lb_8000B1CC(data->jobjs[6], (Vec3*) (base + 0x30), &sp6C); + lb_8000B1CC(data->jobjs[6], &table->positions.x18, &sp6C); value_text = HSD_SisLib_803A6754(0, 1); data->value_text = value_text; value_text->font_size.x = divider; @@ -195,14 +206,17 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) } if (mnDiagram2_IsIconOnlyStat(stat_type)) { - u8 rank = (u8) i; - - mnDiagram2_GetAggregatedFighterRank(sp48, stat_type, rank); + { + u8 ii = (u8) i; + mnDiagram2_GetAggregatedFighterRank(sp48, stat_type, + ii); + } if (sp48[0] == 0x19) { - goto next; + continue; } - mnDiagram2_GetAggregatedFighterRank(sp38, stat_type, rank); - icon = mnDiagram_CreateFighterIcon(sp38[0], 0); + 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); @@ -245,7 +259,7 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) } mnDiagram_FormatDecimalNumber((char*) sp58, val, 2); } else if (mnDiagram2_IsIconOnlyStat(stat_type)) { - goto next; + continue; } else { u32 val = mnDiagram2_GetStatValue(data->is_name_mode, stat_type, entity); @@ -264,13 +278,12 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) } { - u16 icon_id = *stat_table; - int r17 = icon_id; - if (r17 == 0xFFFF) { - goto next; + int icon_id = unit_glyph_ids[stat_type]; + if (icon_id == 0xFFFF) { + continue; } - lb_8000B1CC(data->jobjs[6], (Vec3*) (base + 0x30), &sp6C); + lb_8000B1CC(data->jobjs[6], &table->positions.x18, &sp6C); { HSD_Text* icon_text; f32 negated_y = -sp6C.y; @@ -289,15 +302,12 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) entity))) { HSD_SisLib_803A6368(icon_text, 0x7F); - goto next; + continue; } } - HSD_SisLib_803A6368(icon_text, r17); + HSD_SisLib_803A6368(icon_text, icon_id); } } - - next: - (void) 0; } } } @@ -428,6 +438,11 @@ void mnDiagram3_InitUserData(Diagram3* data, int arg1) data->row_icons[4] = NULL; } +static inline HSD_JObj* mnDiagram3_LoadJoint(mnDiagram_ArchiveData* archive) +{ + return HSD_JObjLoadJoint(archive->x0); +} + void mnDiagram3_Create(int arg0) { mnDiagram_ArchiveData* archive = &mnDiagram_804A0844; @@ -438,7 +453,7 @@ void mnDiagram3_Create(int arg0) gobj = GObj_Create(6, 7, 0x80); mnDiagram3_804D6C20 = gobj; - jobj = HSD_JObjLoadJoint(archive->x0); + jobj = mnDiagram3_LoadJoint(archive); HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 6, 0x80); HSD_JObjAddAnimAll(jobj, archive->x4, archive->x8, archive->xC); @@ -458,19 +473,93 @@ 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) +{ + HSD_JObj* row0; + 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]; + scroll = data->scroll_offset; + + row_spacing = HSD_JObjGetTranslationY(mnDiagram3_GetSecondRow(data)) - + HSD_JObjGetTranslationY(row0); + neg_spacing = row_spacing; + + 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, + row_spacing, 240.0f); + + data->row_labels[i] = text; + { + u8 type_idx = (u8) i; + int val; + int limit; + + if (data->is_name_mode != 0) { + limit = 0x18; + } else { + limit = 0x15; + } + limit = (u8) limit; + + val = stat_idx + type_idx; + if (val >= limit) { + val = val - limit; + } else { + val = (u8) val; + } + + { + u16* entry = &mnDiagram3_803EEC4C.label_ids[(u8) val]; + HSD_SisLib_803A6368(text, *entry); + } + } + i++; + } while (i < 10); +} + +static inline f32 mnDiagram3_GetPopupSpacing(HSD_JObj* popup_row, + Diagram3* data) +{ + return HSD_JObjGetTranslationY(data->jobjs[9]) - + HSD_JObjGetTranslationY(popup_row); +} + +static inline f32 mnDiagram3_GetPopupY(HSD_JObj* popup_row, f32 row_spacing) +{ + return row_spacing * mnDiagram3_804DC00C + + HSD_JObjGetTranslationY(popup_row); +} + void mnDiagram3_Init(void* arg0) { void* new_var; - int i; - u8 sp54[8]; - Vec3 sp48; - u8 sp40[8]; Diagram3* data; HSD_GObj* gobj; mnDiagram_ArchiveData* archive; HSD_JObj* row0; f32 row_spacing; - f32 neg_spacing; { MenuFlow* flow = &mn_804A04F0; @@ -493,7 +582,7 @@ void mnDiagram3_Init(void* arg0) data = gobj->user_data; popup = GObj_Create(6, 7, 0x80); data->popup_gobj = popup; - popup_jobj = HSD_JObjLoadJoint(archive->x0); + 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); @@ -503,79 +592,19 @@ void mnDiagram3_Init(void* arg0) new_var = gobj->user_data; data = new_var; row0 = data->jobjs[8]; - row_spacing = HSD_JObjGetTranslationY(data->jobjs[9]) - - HSD_JObjGetTranslationY(row0); + row_spacing = mnDiagram3_GetPopupSpacing(row0, data); row0 = data->jobjs[8]; HSD_JObjSetTranslateXWithMtxDirty(popup_jobj, HSD_JObjGetTranslationX(row0)); - row0 = data->jobjs[8]; - row_spacing = - row_spacing * mnDiagram3_804DC00C + HSD_JObjGetTranslationY(row0); + row_spacing = mnDiagram3_GetPopupY(row0, row_spacing); HSD_JObjSetTranslateYWithMtxDirty(popup_jobj, row_spacing); - row0 = data->jobjs[8]; HSD_JObjSetTranslateZWithMtxDirty(popup_jobj, HSD_JObjGetTranslationZ(row0)); } - - { - Diagram3* d; - int scroll; - u8 stat_idx; - - gobj = mnDiagram3_804D6C20; - d = gobj->user_data; - row0 = d->jobjs[8]; - scroll = d->scroll_offset; - - row_spacing = HSD_JObjGetTranslationY(d->jobjs[9]) - - HSD_JObjGetTranslationY(row0); - - neg_spacing = row_spacing; - - lb_8000B1CC(d->jobjs[8], &mnDiagram3_803EEC28.x0, &sp48); - - 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, sp48.x - row_spacing, - neg_spacing * fi + -sp48.y, - sp48.z, row_spacing, 240.0f); - - d->row_labels[i] = text; - { - u8 type_idx = (u8) i; - int val; - int limit; - - if (d->is_name_mode != 0) { - limit = 0x18; - } else { - limit = 0x15; - } - limit = (u8) limit; - - val = stat_idx + type_idx; - if (val >= limit) { - val = val - limit; - } else { - val = (u8) val; - } - - { - u16* entry = &mnDiagram3_803EEC4C.label_ids[(u8) val]; - HSD_SisLib_803A6368(text, *entry); - } - } - i++; - } while (i < 10); - } + mnDiagram3_CreateRowLabels(mnDiagram3_804D6C20); mnDiagram3_PopulateRankings(mnDiagram3_804D6C20); @@ -593,6 +622,20 @@ static inline f32 mnDiagram3_GetRowSpacing(Diagram3* data) HSD_JObjGetTranslationY(data->jobjs[8]); } +static inline void mnDiagram3_ClearRowLabels(Diagram3* data) +{ + int i = 0; + Diagram3* check_data = data; + Diagram3* text_data = data; + + do { + if (check_data->row_labels[i] != NULL) { + HSD_SisLib_803A5CC4(text_data->row_labels[i]); + check_data->row_labels[i] = NULL; + } + } while (++i < 10); +} + void mnDiagram3_HandleInput(HSD_GObj* gobj) { char* base = (char*) &mnDiagram3_803EEC10; @@ -604,28 +647,17 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) int i; u8 limit; int v; - PAD_STACK(72); + PAD_STACK(64); if (input & MenuInput_Back) { sfxBack(); - i = mn_804A04F0.entering_menu = 0; + mn_804A04F0.entering_menu = 0; gmMainLib_GetGameRules()->xD = ((Diagram3*) mnDiagram3_804D6C20->user_data)->is_name_mode; mnDiagram2_ClearDetailView(mnDiagram3_804D6C20); HSD_GObjPLink_80390228(data->popup_gobj); data = mnDiagram3_804D6C20->user_data; - { - HSD_Text** check_cur = data->row_labels; - HSD_Text** text_cur = &data->row_labels[i]; - do { - if (*check_cur != NULL) { - HSD_SisLib_803A5CC4(*text_cur); - *check_cur = NULL; - } - check_cur++; - text_cur++; - } while (++i < 0xA); - } + mnDiagram3_ClearRowLabels(data); mn_80229894(0x1C, 0, 3); return; } @@ -636,17 +668,7 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) mnDiagram2_ClearDetailView(mnDiagram3_804D6C20); HSD_GObjPLink_80390228(data->popup_gobj); data = mnDiagram3_804D6C20->user_data; - { - Diagram3* check_data = data; - Diagram3* text_data = data; - i = 0; - do { - if (check_data->row_labels[i] != NULL) { - HSD_SisLib_803A5CC4(text_data->row_labels[i]); - check_data->row_labels[i] = NULL; - } - } while (++i < 0xA); - } + mnDiagram3_ClearRowLabels(data); HSD_GObjPLink_80390228(gobj); if (input & MenuInput_LTrigger) { mnDiagram2_Init(); @@ -668,17 +690,7 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) data->scroll_offset = 0; } data = mnDiagram3_804D6C20->user_data; - { - Diagram3* check_data = data; - Diagram3* text_data = data; - i = 0; - do { - if (check_data->row_labels[i] != NULL) { - HSD_SisLib_803A5CC4(text_data->row_labels[i]); - check_data->row_labels[i] = NULL; - } - } while (++i < 0xA); - } + mnDiagram3_ClearRowLabels(data); { int base_idx; u8 base_idx_u8; @@ -730,8 +742,7 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) cur = mnDiagram3_804D6C20->user_data; popup = data->popup_gobj->hsd_obj; n = data->cursor_row; - spacing = HSD_JObjGetTranslationY(cur->jobjs[9]) - - HSD_JObjGetTranslationY(cur->jobjs[8]); + spacing = mnDiagram3_GetRowSpacing(cur); HSD_JObjSetTranslateX(popup, HSD_JObjGetTranslationX(cur->jobjs[8])); HSD_JObjSetTranslateY(popup, @@ -754,17 +765,7 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) sfxMove(); data->scroll_offset = data->scroll_offset - 1; data = mnDiagram3_804D6C20->user_data; - { - Diagram3* check_data = data; - Diagram3* text_data = data; - i = 0; - do { - if (check_data->row_labels[i] != NULL) { - HSD_SisLib_803A5CC4(text_data->row_labels[i]); - check_data->row_labels[i] = NULL; - } - } while (++i < 0xA); - } + mnDiagram3_ClearRowLabels(data); data = mnDiagram3_804D6C20->user_data; base_idx = data->scroll_offset; base_idx_u8 = base_idx; @@ -834,17 +835,7 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) sfxMove(); data->scroll_offset = data->scroll_offset + 1; data = mnDiagram3_804D6C20->user_data; - { - Diagram3* check_data = data; - Diagram3* text_data = data; - i = 0; - do { - if (check_data->row_labels[i] != NULL) { - HSD_SisLib_803A5CC4(text_data->row_labels[i]); - check_data->row_labels[i] = NULL; - } - } while (++i < 0xA); - } + mnDiagram3_ClearRowLabels(data); data = mnDiagram3_804D6C20->user_data; base_idx = data->scroll_offset; base_idx_u8 = base_idx; diff --git a/src/melee/mn/mnevent.c b/src/melee/mn/mnevent.c index b25707b19d..45d8d41f32 100644 --- a/src/melee/mn/mnevent.c +++ b/src/melee/mn/mnevent.c @@ -125,89 +125,119 @@ u8 mnEvent_804D6C65; static char mnEvent_804D5040[3] = "%d"; static char mnEvent_804D5044[4] = { 0x81, 0x7C, 0, 0 }; +static inline MnEventData* mnEvent_GetData(void) +{ + return mnEvent_804D6C60->user_data; +} + +static inline void mnEvent_CreateIconForSlot(s32 idx, HSD_GObj** slot, + HSD_JObj** jobj_0A, + HSD_JObj** jobj_0C, Vec3* pos) +{ + HSD_GObj* icon_gobj; + HSD_JObj* icon_jobj; + HSD_JObj* tree; + f32 spacing; + void** assets; + + (void) mnEvent_804A08F8; + assets = mnEvent_804A0908; + tree = mnEvent_804D6C60->hsd_obj; + lb_80011E24(tree, jobj_0A, 0xA, -1); + lb_80011E24(tree, jobj_0C, 0xC, -1); + spacing = HSD_JObjGetTranslationY(*jobj_0A); + spacing = HSD_JObjGetTranslationY(*jobj_0C) - spacing; + HSD_JObjGetTranslation(*jobj_0A, pos); + pos->y = pos->y + (f32) idx * spacing; + + icon_gobj = GObj_Create(6, 7, 0x80); + icon_jobj = HSD_JObjLoadJoint(assets[0]); + HSD_GObjObject_80390A70(icon_gobj, HSD_GObj_JObjKind, icon_jobj); + GObj_SetupGXLink(icon_gobj, HSD_GObj_JObjCallback, 4, 0x80); + mnEvent_8024D4E0(icon_jobj, pos); + *slot = icon_gobj; +} + void mnEvent_8024D15C(s32 idx, s32 event_id) { HSD_JObj* jobj_0A; HSD_JObj* jobj_0C; Vec3 pos; - Vec3 icon_pos; - HSD_JObj* jobj_0C_2; - f32 icon_spacing; - MnEventData* data; - HSD_Text** text_slot; - HSD_Text** icon_slot; - HSD_JObj* icon_jobj; - HSD_Text* text; - HSD_Text* icon_text; - f32 spacing; - HSD_JObj* jobj_0A_2; - s32 is_unlocked; - HSD_JObj* tree; - PAD_STACK(0x40); - tree = mnEvent_804D6C60->hsd_obj; - data = mnEvent_804D6C60->user_data; - lb_80011E24(tree, &jobj_0A, 0xA, -1); - lb_80011E24(tree, &jobj_0C, 0xC, -1); + PAD_STACK(8); + { + Vec3 icon_pos; + HSD_JObj* icon_jobj_0C; + HSD_JObj* icon_jobj_0A; + MnEventData* data; + HSD_Text** text_base; + HSD_Text** text_slot; + HSD_Text** icon_base; + HSD_Text** icon_slot; + HSD_Text* text; + HSD_Text* icon_text; + f32 spacing; + f32 text_x; + f32 text_y; + HSD_JObj* tree; + s32 sis_idx; + PAD_STACK(0x28); - spacing = HSD_JObjGetTranslationY(jobj_0A); - spacing = HSD_JObjGetTranslationY(jobj_0C) - spacing; - HSD_JObjGetTranslation(jobj_0A, &pos); + tree = mnEvent_804D6C60->hsd_obj; + data = mnEvent_GetData(); + lb_80011E24(tree, &jobj_0A, 0xA, -1); + lb_80011E24(tree, &jobj_0C, 0xC, -1); - pos.y = -(((f32) idx * spacing) + pos.y); + spacing = HSD_JObjGetTranslationY(jobj_0A); + spacing = HSD_JObjGetTranslationY(jobj_0C) - spacing; + HSD_JObjGetTranslation(jobj_0A, &pos); - if (data->gobjs[idx] != NULL) { - HSD_GObjPLink_80390228(data->gobjs[idx]); - data->gobjs[idx] = NULL; - } + pos.y = -(((f32) idx * spacing) + pos.y); - is_unlocked = gmMainLib_8015CEFC(event_id); - if (is_unlocked != 0) { - HSD_GObj* icon_gobj; - tree = mnEvent_804D6C60->hsd_obj; - lb_80011E24(tree, &jobj_0A_2, 0xA, -1); - lb_80011E24(tree, &jobj_0C_2, 0xC, -1); - icon_spacing = HSD_JObjGetTranslationY(jobj_0A_2); - icon_spacing = HSD_JObjGetTranslationY(jobj_0C_2) - icon_spacing; - HSD_JObjGetTranslation(jobj_0A_2, &icon_pos); - - icon_pos.y = icon_pos.y + (f32) idx * icon_spacing; - icon_gobj = GObj_Create(6, 7, 0x80); - icon_jobj = HSD_JObjLoadJoint((HSD_Joint*) mnEvent_804A0908[0]); - HSD_GObjObject_80390A70(icon_gobj, HSD_GObj_JObjKind, icon_jobj); - GObj_SetupGXLink(icon_gobj, HSD_GObj_JObjCallback, 4, 0x80); - mnEvent_8024D4E0(icon_jobj, &icon_pos); - data->gobjs[idx] = icon_gobj; - } - - text_slot = &data->texts[idx]; - (void) text_slot; - if (*text_slot != NULL) { - HSD_SisLib_803A5CC4(data->texts[idx]); - } - text = HSD_SisLib_803A6754(0, 1); - *text_slot = text; - text->font_size.x = 0.035f; - text->font_size.y = 0.035f; - text->pos_x = pos.x + mnEvent_803EF764.x; - text->pos_y = pos.y + mnEvent_803EF764.y; - text->pos_z = 17.0f; - text->default_kerning = 1; - *(s32*) &text->text_color = mnEvent_804D5028; - HSD_SisLib_803A6B98(text, 0.0f, 0.0f, mnEvent_803EF77C, event_id + 1); - - icon_slot = &data->icons[idx]; - if (*icon_slot != NULL) { - HSD_SisLib_803A5CC4(data->icons[idx]); - } - icon_text = HSD_SisLib_803A5ACC(0, 1, pos.x + mnEvent_803EF770.x, - pos.y + mnEvent_803EF770.y, 17.0f, - 364.68332f, 38.38772f); - *icon_slot = icon_text; - icon_text->font_size.x = 0.035f; - icon_text->font_size.y = 0.035f; - HSD_SisLib_803A6368(icon_text, - ((gm_801BEBA8((u8) event_id) * 2) & 0x1FE) + 0x154); + if (data->gobjs[idx] != NULL) { + HSD_GObj** gobjs = data->gobjs; + HSD_GObj* old_gobj = gobjs[idx]; + HSD_GObjPLink_80390228(old_gobj); + data->gobjs[idx] = NULL; + } + + if (gmMainLib_8015CEFC(event_id) != 0) { + mnEvent_CreateIconForSlot(idx, &data->gobjs[idx], &icon_jobj_0A, + &icon_jobj_0C, &icon_pos); + } + + text_base = data->texts; + text_slot = &text_base[idx]; + if (*text_slot != NULL) { + HSD_SisLib_803A5CC4(data->texts[idx]); + } + text = HSD_SisLib_803A6754(0, 1); + *text_slot = text; + text->font_size.x = 0.035f; + text->font_size.y = 0.035f; + text_x = pos.x + mnEvent_803EF764.x; + text_y = pos.y + mnEvent_803EF764.y; + text->pos_x = text_x; + text->pos_y = text_y; + text->pos_z = 17.0f; + text->default_kerning = 1; + *(s32*) &text->text_color = mnEvent_804D5028; + HSD_SisLib_803A6B98(text, 0.0f, 0.0f, mnEvent_803EF77C, event_id + 1); + + icon_base = data->icons; + icon_slot = &icon_base[idx]; + if (*icon_slot != NULL) { + HSD_SisLib_803A5CC4(data->icons[idx]); + } + icon_text = HSD_SisLib_803A5ACC(0, 1, pos.x + mnEvent_803EF770.x, + pos.y + mnEvent_803EF770.y, 17.0f, + 364.68332f, 38.38772f); + *icon_slot = icon_text; + icon_text->font_size.x = 0.035f; + icon_text->font_size.y = 0.035f; + sis_idx = ((gm_801BEBA8((u8) event_id) * 2) & 0x1FE) + 0x154; + HSD_SisLib_803A6368(icon_text, sis_idx); + } } void mnEvent_8024D4E0(HSD_JObj* jobj, Vec3* translate) @@ -444,23 +474,24 @@ void mnEvent_8024E524(s32 event_idx) mnEvent_ShowSelected(user_data, &jobj_09); } +static inline u8 mnEvent_GetPage(const MnEventData* data) +{ + return data->page; +} + void fn_8024D864(HSD_GObj* gobj) { - HSD_JObj* jobj_0C; - HSD_JObj* jobj_0A; - HSD_JObj* jobj_0B; - HSD_JObj* jobj_09; + u8 page; + f32 y_a; MnEventData* data; - HSD_GObj* event_gobj; + HSD_JObj* jobj_09; + HSD_JObj* tree; + HSD_JObj* jobj_0B; u64 inputs; - s32 i; - s32 first_event; - s32 selected_event; - s32 page; - u8 event; - f32 y_a; + HSD_JObj* jobj_0C; + HSD_JObj* jobj_0A; f32 y_b; - PAD_STACK(0x78); + PAD_STACK(0x70); if (mn_804D6BC8.cooldown != 0) { mn_804D6BC8.cooldown -= 1; @@ -507,21 +538,8 @@ void fn_8024D864(HSD_GObj* gobj) } else { data->first_event = max_events; } - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); - } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + 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) { @@ -531,106 +549,52 @@ void fn_8024D864(HSD_GObj* gobj) } else { data->first_event = 0; } - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); - } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, (f32) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); } } else if (inputs & MenuInput_Up) { page = data->page; if (page != 0) { sfxMove(); data->page -= 1; - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0A, 0xA, -1); - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0C, 0xC, -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(mnEvent_804D6C60->hsd_obj, &jobj_0B, 0xB, -1); - HSD_JObjSetTranslateY(jobj_0B, (f32) data->page * (y_b - y_a)); - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + lb_80011E24(tree, &jobj_0B, 0xB, -1); + mnEvent_SetPageY(jobj_0B, page, y_a, y_b); + mnEvent_ShowSelected(data, &jobj_09); return; } if (data->first_event != 0) { sfxMove(); data->first_event -= 1; - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); - } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); } } else if (inputs & MenuInput_Down) { page = data->page; if (page < 8) { sfxMove(); data->page += 1; - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0A, 0xA, -1); - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0C, 0xC, -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(mnEvent_804D6C60->hsd_obj, &jobj_0B, 0xB, -1); - HSD_JObjSetTranslateY(jobj_0B, (f32) data->page * (y_b - y_a)); - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + lb_80011E24(tree, &jobj_0B, 0xB, -1); + mnEvent_SetPageY(jobj_0B, page, y_a, y_b); + mnEvent_ShowSelected(data, &jobj_09); return; } if (data->first_event < mnEvent_8024CE74()) { sfxMove(); data->first_event += 1; - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); - } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + mnEvent_RefreshRows(data->first_event); + mnEvent_ShowSelected(data, &jobj_09); } } } diff --git a/src/melee/mn/mninfo.c b/src/melee/mn/mninfo.c index 66d6d426ed..ab11665c63 100644 --- a/src/melee/mn/mninfo.c +++ b/src/melee/mn/mninfo.c @@ -95,13 +95,25 @@ static inline bool mnInfo_80251AFC_inline(s32 i) return unlock_state == 0; } +static inline u32 mnInfo_80251AFC_inline_2(s32 j) +{ + return *gmMainLib_8015D804(mnInfo_804A0968[j]); +} + +static inline s32 mnInfo_80251AFC_inline_3(u8* ids, s32 i) +{ + return ids[i]; +} + void mnInfo_80251AFC(void) { s32 i; s32 j; - PAD_STACK(8); + /// @todo Keep #mnInfo_804A0958 before #mnInfo_804A0968 in `.bss`. + (void) &mnInfo_804A0958; + for (i = 0; 0x42 > i; i++) { mnInfo_804A0968[i] = i; } @@ -119,8 +131,8 @@ void mnInfo_80251AFC(void) for (j = i + 1; j < 0x42; j++) { if (mnInfo_80251A08(mnInfo_804A0968[j]) != 0 && (mnInfo_80251A08(mnInfo_804A0968[i]) == 0 || - *gmMainLib_8015D804(mnInfo_804A0968[i]) > - *gmMainLib_8015D804(mnInfo_804A0968[j]))) + *gmMainLib_8015D804(mnInfo_80251AFC_inline_3( + mnInfo_804A0968, i)) > mnInfo_80251AFC_inline_2(j))) { u8 tmp = mnInfo_804A0968[i]; @@ -152,6 +164,8 @@ static AnimLoopSettings mnInfo_803EFC08[0x12] = { { 2.8395941e29f, 1.7935375e25f, 7.2243537e28f }, }; +#define mnInfo_layout (*(MnInfoDataLayout*) mnInfo_803EFC08) + #ifdef MUST_MATCH #pragma push #pragma dont_inline on @@ -171,7 +185,7 @@ s32 mnInfo_80251D58(mnInfo_GObj* arg0, s32 arg1, u32 arg2, u32 arg3) MnInfoDataLayout* layout; data = arg0->user_data; - layout = (MnInfoDataLayout*) mnInfo_803EFC08; + layout = &mnInfo_layout; slot = (HSD_Text**) ((u8*) data + (arg1 * 4)); if (*(slot += 2) != NULL) { HSD_SisLib_803A5CC4(data->left_column[arg1]); @@ -249,18 +263,54 @@ static inline s32 mnInfo_CountUnlocked(void) return count; } -void fn_80251FE4(void) +inline void mnInfo_CreateEntries(u32 id) { - mnInfo_GObj* gobj; - MnInfoData* data; - u64 buttons; u8* trophy; - s32 count; s32 i; + mnInfo_GObj* gobj; + + gobj = mnInfo_804D6C78; + trophy = &mnInfo_804A0968[id]; + (void) trophy; + for (i = 0; i < 4; i++) { + if (mnInfo_80251A08(*trophy) != 0) { + id = *trophy; + + mnInfo_80251D58(gobj, i, id, *gmMainLib_8015D804(id)); + mnInfo_80251F04(gobj, i, id); + } + trophy++; + } +} + +static inline void mnInfo_FreeEntries(void) +{ s32 j; MnInfoData* data2; MnInfoData* data3; - PAD_STACK(0x20); + + j = 0; + data2 = mnInfo_804D6C78->user_data; + data3 = data2; + do { + if (data2->left_column[j] != NULL) { + HSD_SisLib_803A5CC4(data3->left_column[j]); + data2->left_column[j] = NULL; + } + if (data2->right_column[j] != NULL) { + HSD_SisLib_803A5CC4(data3->right_column[j]); + data2->right_column[j] = NULL; + } + j++; + } while (j < 4); +} + +void fn_80251FE4(void) +{ + MnInfoData* data; + u64 buttons; + s32 count; + PAD_STACK(0x18); data = mnInfo_804D6C78->user_data; if (mn_804D6BC8.cooldown != 0) { @@ -280,67 +330,32 @@ void fn_80251FE4(void) if (data->scroll_idx != 0) { data->scroll_idx -= 1; sfxMove(); - j = 0; - data2 = mnInfo_804D6C78->user_data; - data3 = data2; - do { - if (data2->left_column[j] != NULL) { - HSD_SisLib_803A5CC4(data3->left_column[j]); - data2->left_column[j] = NULL; - } - if (data2->right_column[j] != NULL) { - HSD_SisLib_803A5CC4(data3->right_column[j]); - data2->right_column[j] = NULL; - } - j++; - } while (j < 4); - gobj = mnInfo_804D6C78; - trophy = &mnInfo_804A0968[data->scroll_idx]; - for (i = 0; i < 4; i++) { - if (mnInfo_80251A08(*trophy) != 0) { - u8 id = *trophy; - - mnInfo_80251D58(gobj, i, id, *gmMainLib_8015D804(id)); - mnInfo_80251F04(gobj, i, id); + mnInfo_FreeEntries(); + { + u8* trophy; + s32 i; + mnInfo_GObj* gobj; + + gobj = mnInfo_804D6C78; + trophy = &mnInfo_804A0968[data->scroll_idx]; + for (i = 0; i < 4; i++) { + if (mnInfo_80251A08(*trophy) != 0) { + u8 id = *trophy; + + mnInfo_80251D58(gobj, i, id, *gmMainLib_8015D804(id)); + mnInfo_80251F04(gobj, i, id); + } + trophy++; } - trophy++; } } } else if (buttons & MenuInput_Down) { - count = 0; - for (j = 0; j < 0x42; j++) { - if (mnInfo_80251A08(j) != 0) { - count++; - } - } + count = mnInfo_CountUnlocked(); if ((data->scroll_idx + 4) < count) { sfxMove(); data->scroll_idx += 1; - j = 0; - data2 = mnInfo_804D6C78->user_data; - data3 = data2; - do { - if (data2->left_column[j] != NULL) { - HSD_SisLib_803A5CC4(data3->left_column[j]); - data2->left_column[j] = NULL; - } - if (data2->right_column[j] != NULL) { - HSD_SisLib_803A5CC4(data3->right_column[j]); - data2->right_column[j] = NULL; - } - j++; - } while (j < 4); - gobj = mnInfo_804D6C78; - trophy = &mnInfo_804A0968[data->scroll_idx]; - for (i = 0; i < 4; i++) { - if (mnInfo_80251A08(*trophy) != 0) { - u8 id = *trophy; - - mnInfo_80251D58(gobj, i, id, *gmMainLib_8015D804(id)); - mnInfo_80251F04(gobj, i, id); - } - trophy++; - } + mnInfo_FreeEntries(); + mnInfo_CreateEntries(data->scroll_idx); } } } @@ -373,7 +388,7 @@ void mnInfo_802522B8(HSD_GObj* gobj) } else { HSD_JObjSetFlagsAll(child, JOBJ_HIDDEN); } - mn_8022ED6C(jobj, (AnimLoopSettings*) mnInfo_803EFC08); + mn_8022ED6C(jobj, &mnInfo_layout.anim); } #ifdef MUST_MATCH #pragma pop @@ -431,7 +446,7 @@ static inline void fn_802523D8_inline(MnInfoData* data, HSD_GObj* gobj) HSD_JObjSetFlagsAll(child, JOBJ_HIDDEN); } - mn_8022ED6C(jobj, (AnimLoopSettings*) mnInfo_803EFC08); + mn_8022ED6C(jobj, &mnInfo_layout.anim); } } @@ -533,50 +548,61 @@ void mnInfo_80252720(MnInfoData* data) s32 mnInfo_80252758(void) { - MnInfoData* data; - MnInfoDataLayout* layout; MnInfoData* user_data; - HSD_GObj* menu_gobj; HSD_GObjProc* proc; - HSD_GObjProc* menu_proc; - HSD_Text* description; + HSD_GObj* gobj; + HSD_Archive* archive; + StaticModelDesc* model = &mnInfo_804A0958; + char* top_joint = mnInfo_layout.top_joint; + HSD_AnimJoint** animjoint = &model->animjoint; PAD_STACK(8); - layout = (MnInfoDataLayout*) mnInfo_803EFC08; + (void) "Can't get user_data.\n"; + (void) __FILE__; + (void) "user_data"; + mn_804D6BC8.cooldown = 5; mn_804A04F0.prev_menu = mn_804A04F0.cur_menu; mn_804A04F0.cur_menu = 0x1D; mn_804A04F0.hovered_selection = 0; + archive = mn_804D6BB8; lbArchive_LoadSections( - mn_804D6BB8, (void**) &mnInfo_804A0958.joint, layout->top_joint, - &mnInfo_804A0958.animjoint, layout->top_animjoint, - &mnInfo_804A0958.matanim_joint, layout->top_matanim_joint, - &mnInfo_804A0958.shapeanim_joint, layout->top_shapeanim_joint, 0); + archive, (void**) &model->joint, top_joint, animjoint, + mnInfo_layout.top_animjoint, &model->matanim_joint, + mnInfo_layout.top_matanim_joint, &model->shapeanim_joint, + mnInfo_layout.top_shapeanim_joint, 0); mnInfo_80251AFC(); - menu_gobj = GObj_Create(6, 7, 0x80); - mnInfo_804D6C78 = menu_gobj; + gobj = GObj_Create(6, 7, 0x80); + mnInfo_804D6C78 = gobj; - user_data = HSD_MemAlloc(sizeof(MnInfoData)); - HSD_ASSERTREPORT(0x267, user_data, "Can't get user_data.\n"); + user_data = HSD_MemAlloc(sizeof(*user_data)); + if (user_data == NULL) { + OSReport(mnInfo_layout.assert_report); + __assert(mnInfo_layout.assert_file, 0x267, mnInfo_layout.assert_expr); + } mnInfo_80252720(user_data); - GObj_InitUserData(menu_gobj, 0, HSD_Free, user_data); + GObj_InitUserData(gobj, 0, HSD_Free, user_data); - menu_proc = HSD_GObj_SetupProc(menu_gobj, (HSD_GObjEvent) fn_80252548, 0); - menu_proc->flags_3 = HSD_GObj_804D783C; + proc = HSD_GObj_SetupProc(gobj, (HSD_GObjEvent) fn_80252548, 0); + proc->flags_3 = HSD_GObj_804D783C; - data = menu_gobj->user_data; - if (data->description != NULL) { - HSD_SisLib_803A5CC4(data->description); + { + MnInfoData* data; + HSD_Text* text; + + if ((data = gobj->user_data)->description != NULL) { + HSD_SisLib_803A5CC4(data->description); + } + text = HSD_SisLib_803A5ACC(0, 1, -9.5f, 9.1f, 17.0f, 364.68332f, + 38.38772f); + data->description = text; + text->font_size.x = 0.0521f; + text->font_size.y = 0.0521f; + HSD_SisLib_803A6368(text, 0xA3); } - description = - HSD_SisLib_803A5ACC(0, 1, -9.5f, 9.1f, 17.0f, 364.68332f, 38.38772f); - data->description = description; - description->font_size.x = 0.0521f; - description->font_size.y = 0.0521f; - HSD_SisLib_803A6368(description, 0xA3); proc = HSD_GObj_SetupProc(GObj_Create(0, 1, 0x80), (HSD_GObjEvent) fn_80251FE4, 0); diff --git a/src/melee/mn/mnitemsw.c b/src/melee/mn/mnitemsw.c index c1abc7ae6b..b7aa852c9a 100644 --- a/src/melee/mn/mnitemsw.c +++ b/src/melee/mn/mnitemsw.c @@ -410,8 +410,9 @@ void mnItemSw_80234104(HSD_GObj* gobj) mnItemSw_SetCursorPosition(data); } -static inline void mnItemSw_ReqFreqAnim(HSD_JObj* jobj, - struct MnItemSwTable* tbl, u8 freq) +static inline u8 mnItemSw_ReqFreqAnim(HSD_JObj* jobj, + struct MnItemSwTable* tbl, u8 freq, + u8 changed) { if ((u8) mn_804A04F0.hovered_selection == 0x1F || (u8) mn_804A04F0.hovered_selection == 0x20) @@ -421,17 +422,39 @@ static inline void mnItemSw_ReqFreqAnim(HSD_JObj* jobj, HSD_JObjReqAnimAll(jobj, tbl->x30[6 + freq * 2]); } HSD_JObjAnimAll(jobj); + return changed; +} + +static inline u8 mnItemSw_UpdateConfirmed(MnItemSwData* user_data, + struct MnItemSwTable* tbl, + u8 changed) +{ + if (mn_804A04F0.hovered_selection == 0x1F || + mn_804A04F0.hovered_selection == 0x20) + { + changed = + mnItemSw_ReqFreqAnim(user_data->jobjs[3], tbl, + mn_804A04F0.confirmed_selection, changed); + } else { + HSD_JObj* confirmed_jobj; + u8 confirmed = mn_804A04F0.confirmed_selection; + HSD_JObj* jobj = + mnItemSw_8023405C(user_data, (u8) mn_804A04F0.hovered_selection); + lb_80011E24(jobj, &confirmed_jobj, 2, -1); + HSD_JObjReqAnimAll(confirmed_jobj, mnItemSw_804D4BA0[confirmed]); + HSD_JObjAnimAll(confirmed_jobj); + } + return changed; } void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) { HSD_JObj* sp44; - u8 arg1_ = arg1; - HSD_JObj* sp3C; u8 cursor; HSD_JObj* cjobj; MnItemSwData* data = gobj->user_data; struct MnItemSwTable* tbl = mnItemSw_GetTable(); + u8 arg1_ = arg1; f32 x; u8 arg2_ = arg2; @@ -442,7 +465,8 @@ void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) cursor = data->cursor; if (cursor == 0x1F || cursor == 0x20) { - mnItemSw_ReqFreqAnim(data->jobjs[3], tbl, data->x21); + arg1_ = + mnItemSw_ReqFreqAnim(data->jobjs[3], tbl, data->x21, arg1_); } else { HSD_JObj* jobj = mnItemSw_8023405C(data, cursor); lb_80011E24(jobj, &sp44, 8, -1); @@ -460,8 +484,8 @@ void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) cursor = (u8) mn_804A04F0.hovered_selection; if (cursor == 0x1F || cursor == 0x20) { - mnItemSw_ReqFreqAnim(data->jobjs[3], tbl, - mn_804A04F0.confirmed_selection); + arg1_ = mnItemSw_ReqFreqAnim( + data->jobjs[3], tbl, mn_804A04F0.confirmed_selection, arg1_); } else { HSD_JObj* jobj = mnItemSw_8023405C(data, cursor); lb_80011E24(jobj, &sp44, 8, -1); @@ -505,24 +529,12 @@ void mnItemSw_8023453C(HSD_GObj* gobj, u8 arg1, u8 arg2) } if (arg2_ != 0) { - if (mn_804A04F0.hovered_selection == 0x1F || - mn_804A04F0.hovered_selection == 0x20) - { - mnItemSw_ReqFreqAnim(data->jobjs[3], tbl, - mn_804A04F0.confirmed_selection); - } else { - u8 confirmed = mn_804A04F0.confirmed_selection; - HSD_JObj* jobj = - mnItemSw_8023405C(data, (u8) mn_804A04F0.hovered_selection); - lb_80011E24(jobj, &sp3C, 2, -1); - HSD_JObjReqAnimAll(sp3C, mnItemSw_804D4BA0[confirmed]); - HSD_JObjAnimAll(sp3C); - } + arg1_ = mnItemSw_UpdateConfirmed(data, tbl, arg1_); } { u16 sel; - if (arg1 != 0) { + if (arg1_ != 0) { sel = mn_804A04F0.hovered_selection; } else { sel = data->cursor; diff --git a/src/melee/mn/mnmainrule.c b/src/melee/mn/mnmainrule.c index 2c8cc6b60d..208651e658 100644 --- a/src/melee/mn/mnmainrule.c +++ b/src/melee/mn/mnmainrule.c @@ -157,6 +157,8 @@ u8 mn_StockCountLimits[2] = { 1, 0x63 }; 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; @@ -514,24 +516,46 @@ void mn_8022FD18(u8 arg0) HSD_JObjAnimAll(jobj2); } +static inline void mn_8022FEC8_AnimDigit(HSD_JObj* jobj, u8 digit) +{ + HSD_JObjReqAnimAll(jobj, (f32) digit); + HSD_JObjAnimAll(jobj); +} + +static inline void +mn_8022FEC8_AnimDamageDigits(u8 value, struct mn_8022FB88_arg1_t* data) +{ + mn_8022FEC8_AnimDigit(data->xA8 == NULL ? NULL : data->xA8->x10, + (u8) (value / 10)); + mn_8022FEC8_AnimDigit(data->xAC == NULL ? NULL : data->xAC->x10, + (u8) (value % 10)); +} + +static inline AnimLoopSettings* mn_8022FEC8_GetSettings(u8 rule_kind, + u8 rule_value) +{ + u8 default_value; + + if (rule_kind != 0 && rule_kind != 2 && rule_kind != 4) { + return NULL; + } + default_value = mn_803EC7DC[rule_kind][1]; + return &mn_803EC770[default_value - rule_value]; +} + void mn_8022FEC8(HSD_GObj* arg0, HSD_JObj* arg1, u8 arg2, u8 arg3) { + AnimLoopSettings* settings; struct mn_8022FB88_arg1_t* data; HSD_JObj** digit_jobjs; - struct mn_8022FEC8_jobj_ref_t* tens_ref; - struct mn_8022FEC8_jobj_ref_t* ones_ref; - u8* base; HSD_JObj* digit_jobj; HSD_JObj* digit_jobj2; - HSD_JObj* tens_jobj; - HSD_JObj* ones_jobj; int value; - f32* frame; + u8 default_value; PAD_STACK(0x18); data = HSD_GObjGetUserData(arg0); - base = mn_803EC600; switch ((s32) arg2) { case 1: if (((struct mn_8022FB88_arg1_t*) mn_804D6BD0->user_data)->x2 != 1) { @@ -541,63 +565,39 @@ void mn_8022FEC8(HSD_GObj* arg0, HSD_JObj* arg1, u8 arg2, u8 arg3) digit_jobjs = data->x58; value = arg3; digit_jobj = digit_jobjs[7]; - HSD_JObjReqAnimAll(digit_jobj, (f32) (u8) (value / 10)); - HSD_JObjAnimAll(digit_jobj); + mn_8022FEC8_AnimDigit(digit_jobj, (u8) (value / 10)); digit_jobj2 = digit_jobjs[8]; - HSD_JObjReqAnimAll(digit_jobj2, (f32) (u8) (value % 10)); - HSD_JObjAnimAll(digit_jobj2); + mn_8022FEC8_AnimDigit(digit_jobj2, (u8) (value % 10)); return; case 3: - tens_ref = data->xA8; - if (tens_ref == NULL) { - tens_jobj = NULL; - } else { - tens_jobj = tens_ref->x10; - } - HSD_JObjReqAnimAll(tens_jobj, (f32) (u8) (arg3 / 10)); - HSD_JObjAnimAll(tens_jobj); - ones_ref = data->xAC; - if (ones_ref == NULL) { - ones_jobj = NULL; - } else { - ones_jobj = ones_ref->x10; - } - HSD_JObjReqAnimAll(ones_jobj, (f32) (u8) (arg3 % 10)); - HSD_JObjAnimAll(ones_jobj); + mn_8022FEC8_AnimDamageDigits(arg3, data); return; case 0: case 2: case 4: - break; + if ((mn_804A04F0.buttons & 4) != 0) { + settings = mn_8022FEC8_GetSettings(arg2, arg3); + HSD_JObjReqAnimAll(arg1, settings->start_frame); + } else { + if (arg2 != 0 && arg2 != 2 && arg2 != 4) { + settings = NULL; + } else { + default_value = mn_803EC7DC[arg2][1]; + if (arg3 == 0) { + settings = &mn_803EC734[default_value]; + } else { + settings = &mn_803EC734[arg3 - 1]; + } + } + HSD_JObjReqAnimAll(arg1, settings->start_frame); + } + HSD_JObjAnimAll(arg1); + return; case 5: case 6: default: return; } - - if ((mn_804A04F0.buttons & 4) != 0) { - if (arg2 == 0 || arg2 == 2 || arg2 == 4) { - u8* frame_base = base + 0x170; - frame = (f32*) (frame_base + - (0xC * (base[0x1DD + (arg2 << 1)] - arg3))); - } - HSD_JObjReqAnimAll(arg1, *frame); - } else { - if (arg2 == 0 || arg2 == 2 || arg2 == 4) { - u8 idx = base[0x1DD + (arg2 << 1)]; - if (arg3 == 0) { - frame = (f32*) (base + 0x134 + (0xC * idx)); - (void) frame; - } else { - frame = (f32*) (base + 0x134 + (0xC * (arg3 - 1))); - } - } - { - f32 frame_value = *frame; - HSD_JObjReqAnimAll(arg1, frame_value); - } - } - HSD_JObjAnimAll(arg1); } void mn_80230198(HSD_GObj* gobj, HSD_JObj* jobj, u8 mode) @@ -641,6 +641,7 @@ extern MenuKindData mn_803EB6B0[]; void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) { HSD_JObj* option_roots[8]; + HSD_JObj** option_root; HSD_JObj* roots[17]; u8 pad_[4]; u16 indices[17]; @@ -648,12 +649,12 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) AnimLoopSettings* settings; HSD_JObj* jobj; s32 i; + struct mn_802307F8_t* user_data; s32 j; - void* user_data; - s32 visible; + u8 j8; + u8 focus; u8 count; u8 selected; - u8 hovered; u8* base; s32 tail_i; struct mn_802307F8_t* data; @@ -668,7 +669,8 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) indices[i] = i; } - for (i = 0; i < count; i++) { + option_root = option_roots; + for (i = 0; i < count; option_root++, i++) { s32 valid; if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) i == 4) { valid = 0; @@ -676,12 +678,15 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) valid = 1; } if (valid) { + s32 visible; HSD_JObj* v; struct mn_8022FEC8_jobj_ref_t* p; - for (j = (visible = 0); j < (u8) i; j++) { - u8 j8 = j; + visible = valid - 1; + j = visible; + for (; j < (s32) (u8) i; j++) { s32 valid2; + j8 = j; if (gm_GetCurrentGameMode() == GM_TOURNAMENT && j8 == 4) { valid2 = 0; } else { @@ -698,11 +703,13 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) } else { v = p->x10; } - option_roots[i] = v; + *option_root = v; } } if (arg1 != 0) { + u8 hovered; + selected = data->x1; lb_8001204C(option_roots[selected], roots, indices, 0x11); HSD_JObjSetFlagsAll(roots[16], JOBJ_HIDDEN); @@ -725,7 +732,7 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) HSD_JObjAnim(roots[7]); HSD_JObjSetFlagsAll(roots[8], JOBJ_HIDDEN); - hovered = mn_804A04F0.hovered_selection; + hovered = mn_8022F538_GetHoveredSelection(); lb_8001204C(option_roots[hovered], roots, indices, 0x11); jobj = roots[16]; HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); @@ -745,7 +752,7 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) if (hovered == 1 && ((struct mn_8022FB88_arg1_t*) mn_804D6BD0->user_data)->x2 == 1) { - HSD_JObjReqAnim(roots[7], lbl_804D4B8C); + HSD_JObjReqAnim(roots[7], (&mn_804D4B88)[1]); } else { f32* q = (f32*) (base + hovered * 8); HSD_JObjReqAnim(roots[7], *(f32*) ((u8*) q + 0x14)); @@ -767,7 +774,6 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) } for (i = 0; i < count; i++) { - u8 focus; s32 valid; if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) i == 4) { valid = 0; @@ -784,11 +790,11 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) mn_8022ED6C(roots[13], (AnimLoopSettings*) (base + 0x54)); } if ((u32) (i - 5) <= 1) { - u8* q = base + (i == focus) * 0xC; - settings = (AnimLoopSettings*) (q + 0x78); + settings = (AnimLoopSettings*) base + (i == focus); + settings += 10; } else { - u8* q = base + ((tail_i = i) == focus) * 0xC; - settings = (AnimLoopSettings*) (q + 0x60); + settings = (AnimLoopSettings*) base + (i == focus); + settings += 8; } mn_8022ED6C(roots[2], settings); mn_8022ED6C(roots[8], (AnimLoopSettings*) (base + 0x90)); @@ -1028,16 +1034,40 @@ s32 mn_80230D18(struct mn_802307F8_t* arg0, HSD_JObj* arg1, s8 arg2) return ret; } +static inline s32 mn_80230E38_CountVisible(u8 limit) +{ + u8 option_index; + s32 visible; + s32 i; + s32 count = 0; + + for (i = 0; i < (s32) limit; i++) { + option_index = i; + if (gm_GetCurrentGameMode() == GM_TOURNAMENT && option_index == 4) { + visible = 0; + } else { + visible = 1; + } + if (visible != 0) { + count++; + } + } + return count; +} + HSD_GObj* mn_80230E38(int arg0) { - UNUSED u8 pad94[12]; + 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; u8 selected; - u8 option_index; s32 i, j; s32 vis_before; s32 vis_total; @@ -1050,7 +1080,7 @@ HSD_GObj* mn_80230E38(int arg0) HSD_JObj* root_jobj; StaticModelDesc** desc_ptr; u16* sub_count_ptr; - PAD_STACK(52); + PAD_STACK(12); selected = (u8) mn_804A04F0.hovered_selection; num_options = mn_803EB6B0[13].selection_count; @@ -1080,9 +1110,7 @@ HSD_GObj* mn_80230E38(int arg0) { mn_804A04F0.confirmed_selection = user_data->x9; } else { - mn_804A04F0.confirmed_selection = - ((union mn_802307F8_value_view*) user_data) - ->indexed.values[user_data->x1]; + mn_804A04F0.confirmed_selection = *(&user_data->x2 + user_data->x1); } if ((u8) arg0 != 0) { @@ -1104,34 +1132,10 @@ HSD_GObj* mn_80230E38(int arg0) desc_ptr = (StaticModelDesc**) (mn_803EC600 + 0x1EC); sub_count_ptr = (u16*) (mn_803EC600 + 0x208); for (i = 0; i < (s32) num_options; desc_ptr++, i++) { - vis_before = 0; - for (j = vis_before; j < (s32) (u8) i; j++) { - option_index = j; - if (gm_GetCurrentGameMode() == GM_TOURNAMENT && option_index == 4) - { - visible = 0; - } else { - visible = 1; - } - if (visible != 0) { - vis_before++; - } - } + vis_before = mn_80230E38_CountVisible((u8) i); - vis_total = 0; option_jobj = user_data->xC[((u16*) mn_803EC600)[(u8) vis_before]]; - for (j = vis_total; j < 7; j++) { - option_index = j; - if (gm_GetCurrentGameMode() == GM_TOURNAMENT && option_index == 4) - { - visible = 0; - } else { - visible = 1; - } - if (visible != 0) { - vis_total++; - } - } + vis_total = mn_80230E38_CountVisible(7); HSD_JObjReqAnim(option_jobj, (f32) vis_total); HSD_JObjAnim(option_jobj); @@ -1194,15 +1198,28 @@ HSD_GObj* mn_80230E38(int arg0) switch (i) { case 1: { - u8 time_indices[6] = { 2, 3, 5, 6, 7, 8 }; - for (j = 0; j < 6; j++) { + union { + struct { + u32 bytes4; + u16 bytes2; + } packed; + u8 idx[6]; + } time_indices; + u8* index_ptr; + + PAD_STACK(0x18); + + time_indices.packed.bytes4 = mn_804DBE10; + time_indices.packed.bytes2 = mn_804DBE14; + index_ptr = time_indices.idx; + for (j = 0; j < 6; j++, index_ptr++) { HSD_JObj* text = HSD_JObjLoadJoint(MenMainNmRl_Top.joint); HSD_JObjAddAnimAll(text, MenMainNmRl_Top.animjoint, MenMainNmRl_Top.matanim_joint, MenMainNmRl_Top.shapeanim_joint); - HSD_JObjAddChild( - *(&user_data->x34[1].x0 + time_indices[j]), text); + HSD_JObjAddChild(*(&user_data->x34[1].x0 + *index_ptr), + text); } mn_8022FD18((u8) (((struct mn_8022FB88_arg1_t*) mn_804D6BD0->user_data) @@ -1210,23 +1227,20 @@ HSD_GObj* mn_80230E38(int arg0) break; } case 3: { - union { - u16 packed; - u8 idx[2]; - } damage_indices; + u8* index_ptr; u8 value = user_data->x5; HSD_JObj* digit_jobj; damage_indices.packed = mn_804DBDF8; - for (j = 0; j < 2; j++) { + index_ptr = damage_indices.idx; + for (j = 0; j < 2; j++, index_ptr++) { HSD_JObj* text = HSD_JObjLoadJoint(MenMainNmRl_Top.joint); HSD_JObjAddAnimAll(text, MenMainNmRl_Top.animjoint, MenMainNmRl_Top.matanim_joint, MenMainNmRl_Top.shapeanim_joint); - HSD_JObjAddChild( - *(&user_data->x34[3].x0 + damage_indices.idx[j]), - text); + HSD_JObjAddChild(*(&user_data->x34[3].x0 + *index_ptr), + text); } digit_jobj = (HSD_JObj*) mn_80231634( (struct mn_80231634_t*) *(&user_data->x34[3].x0 + 2)); @@ -1241,8 +1255,7 @@ HSD_GObj* mn_80230E38(int arg0) case 0: case 2: case 4: { - u8 value = ((union mn_802307F8_value_view*) user_data) - ->indexed.values[i]; + u8 value = *(&user_data->x2 + i); u8 default_value; AnimLoopSettings* value_als; @@ -1508,4 +1521,6 @@ 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 5a56a89ee7..f241ef294c 100644 --- a/src/melee/mn/mnname.c +++ b/src/melee/mn/mnname.c @@ -125,13 +125,16 @@ bool IsNameListFull(void) return true; } -static inline bool checkStringRest(const char* ptr) +static inline s8 readNameTerminator(const volatile char* terminator) { - char* term = mnName_StringTerminator; - char* cmp = " "; // SJIS full-width space - char c = cmp[0]; - while (*term != *ptr) { - if (c != *ptr || cmp[1] != ptr[1]) { + return *terminator; +} + +static inline bool checkStringRest(const char* ptr, s8 terminator) +{ + char c = " "[0]; // SJIS full-width space + while (terminator != *ptr) { + if (c != *ptr || " "[1] != ptr[1]) { return false; } ptr += 2; @@ -141,24 +144,27 @@ static inline bool checkStringRest(const char* ptr) s32 CompareNameStrings(char* str1, char* str2) { - char* p1; - char* p2; - s32 i; - for (i = 0, p2 = str2, p1 = str1;; i++, p1++, p2++) { - char* ch1 = &str1[i]; + s8 terminator = (s8) *mnName_StringTerminator; + char* p1 = str1; + char* p2 = str2; + s32 i = 0; + while (true) { + s8 ch1 = (s8) str1[i]; - if (*mnName_StringTerminator == *ch1) { - if (checkStringRest(&str2[i & 0xFFFFFFFFFFFFFFFF])) { + if (terminator == ch1) { + if (checkStringRest(&str2[i & 0xFFFFFFFFFFFFFFFF], + readNameTerminator(mnName_StringTerminator))) + { return 0; } return 2; } { - char ch2 = str2[i]; + s8 ch2 = (s8) str2[i]; if (*mnName_StringTerminator == ch2) { - if (checkStringRest(&str1[i])) { + if (checkStringRest(&str1[i], terminator)) { return 0; } return 1; @@ -171,6 +177,9 @@ s32 CompareNameStrings(char* str1, char* str2) return 2; } } + i++; + p2++; + p1++; } } @@ -1126,22 +1135,29 @@ void mnName_80239878(u8 arg0, HSD_GObj* gobj) } } +static inline f32 mnName_80239A24_GetTextColumnWidth(HSD_GObj* gobj, + HSD_JObj* text_jobj0) +{ + HSD_JObj* text_jobj6 = mnName_802388D4_noinline(gobj, 6U); + f32 width = HSD_JObjGetTranslationX(text_jobj0); + return HSD_JObjGetTranslationX(text_jobj6) - width; +} + void mnName_80239A24(HSD_GObj* gobj) { - GXColor text_color; + f32 text_row_height; Vec3 text_position; HSD_JObj* jobj; HSD_JObj* ref_jobj; HSD_JObj* ref_jobj2; s32 row; HSD_JObj* text_jobj0; - HSD_JObj* text_jobj6; HSD_JObj* text_jobj1; HSD_Text* text; f32 col_width; f32 row_height; f32 text_col_width; - f32 text_row_height; + GXColor text_color; s32 j; s32 i; MnNameArchive* archive = &mnName_804A06C0; @@ -1152,7 +1168,7 @@ void mnName_80239A24(HSD_GObj* gobj) s32 extra; s32 total_rows; u8 name_idx; - PAD_STACK(24); + PAD_STACK(8); i = 0; do { @@ -1183,16 +1199,19 @@ void mnName_80239A24(HSD_GObj* gobj) data->text = text; text_jobj0 = mnName_802388D4_noinline(gobj, 0U); lb_8000B1CC(text_jobj0, mnName_803ED618, &text_position); - text->pos_x = text_position.x; - text->pos_z = text_position.z; - text->pos_y = -text_position.y; + { + f32 pos_y = -text_position.y; + f32 pos_z = text_position.z; + f32 pos_x = text_position.x; + 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.03f; text->text_color = *(&mnName_804D4BE4); - text_jobj6 = mnName_802388D4_noinline(gobj, 6U); - text_col_width = HSD_JObjGetTranslationX(text_jobj0); - text_col_width = HSD_JObjGetTranslationX(text_jobj6) - text_col_width; + text_col_width = mnName_80239A24_GetTextColumnWidth(gobj, text_jobj0); text_jobj1 = mnName_802388D4_noinline(gobj, 1U); text_row_height = HSD_JObjGetTranslationY(text_jobj0); text_row_height = -(HSD_JObjGetTranslationY(text_jobj1) - text_row_height); diff --git a/src/melee/mn/mnnamenew.c b/src/melee/mn/mnnamenew.c index 2c18fa20e3..d2c894f110 100644 --- a/src/melee/mn/mnnamenew.c +++ b/src/melee/mn/mnnamenew.c @@ -349,6 +349,14 @@ u8 mnNameNew_804D4F7C[8] = { 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'H' }; GXColor const mnNameNew_804DBF44 = { 0xA6, 0x81, 0x3D, 0xFF }; GXColor const mnNameNew_804DBF48 = { 0x00, 0x00, 0x00, 0xFF }; +static inline void mnNameNew_SetKeyColor(HSD_Text* text, s32 index, + GXColor* color_ptr, GXColor* color) +{ + *color = *color_ptr; + color_ptr = color; + HSD_SisLib_803A74F0(text, index, color_ptr); +} + s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) { Vec3 sp50; @@ -357,7 +365,6 @@ s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) GXColor sp44; MnNameNewDataLayout* layout; HSD_JObj* key_jobj; - HSD_Text* text; HSD_JObj* ref1; HSD_JObj* ref2; char** str_table; @@ -398,95 +405,97 @@ s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) if (arg0->key_text != NULL) { HSD_SisLib_803A5CC4(arg0->key_text); } - text = HSD_SisLib_803A6754(0, (s32) mn_804D6BB5); - arg0->key_text = text; + { + HSD_Text* text; - 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; - } + text = HSD_SisLib_803A6754(0, (s32) mn_804D6BB5); + arg0->key_text = text; + + key_jobj = arg0->jobjs[16]; if (key_jobj == NULL) { key_jobj = NULL; } else { - key_jobj = key_jobj->next; + key_jobj = key_jobj->child; } - } - - 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]; - if (ref1 == NULL) { - ref1 = NULL; - } else { - ref1 = ref1->child; - } - for (i = 0; i < 50; i++) { - if (i == 0x28) { - break; + for (i = 0; i < 50; i++) { + if (i == 0x2D) { + break; + } + if (key_jobj == NULL) { + key_jobj = NULL; + } else { + 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; + + ref1 = arg0->jobjs[16]; if (ref1 == NULL) { ref1 = NULL; } else { - ref1 = ref1->next; + ref1 = ref1->child; + } + for (i = 0; i < 50; i++) { + if (i == 0x28) { + break; + } + if (ref1 == NULL) { + ref1 = NULL; + } else { + 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]; - if (ref2 == NULL) { - ref2 = NULL; - } else { - ref2 = ref2->child; - } - for (i = 0; i < 50; i++) { - if (i == 0x2E) { - break; - } + ref2 = arg0->jobjs[16]; if (ref2 == NULL) { ref2 = NULL; } else { - ref2 = ref2->next; + ref2 = ref2->child; + } + for (i = 0; i < 50; i++) { + if (i == 0x2E) { + break; + } + if (ref2 == NULL) { + ref2 = NULL; + } else { + 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; + 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); } - sp44 = *color_ptr; - color_ptr = &sp44; - HSD_SisLib_803A74F0(text, j, color_ptr); - } - return (s32) text; + return (s32) text; + } } s32 mnNameNew_8023BAA8(NameNewEntry* arg0, s32 arg1, u8 arg2) @@ -563,26 +572,30 @@ s32 mnNameNew_8023BAA8(NameNewEntry* arg0, s32 arg1, u8 arg2) return (s32) arg2; } -s32 PickAutoName(HSD_GObj* arg0) +inline u8 GetAutoNameCharacter(u8** names, s32 char_idx) +{ + return (*names)[char_idx]; +} + +static inline s32 PickAutoNameInline(HSD_GObj* arg0) { + char* cur_text; NameNewEntry* data; - u8* cur_text; u8** names; s32 count; s32 pick; s32 dup; - s32 char_idx; - u8* text; u8** name_ptr; + char* text; + s32 char_idx; u8 ch; - s32 name_idx; - u8 tmp; s8 null_ch; - - PAD_STACK(48); + u8 tmp; + s32 name_idx; + s32 i; data = arg0->user_data; - cur_text = (u8*) mnNameNew_CurrentNameText; + cur_text = mnNameNew_CurrentNameText; do { dup = 0; @@ -620,10 +633,10 @@ s32 PickAutoName(HSD_GObj* arg0) name_ptr = &AutoNamesList[pick]; while ((null_ch = (s8) *mnNameNew_NullCharacter) != - (s8) (ch = (*name_ptr)[char_idx])) + (s8) (ch = GetAutoNameCharacter(name_ptr, char_idx))) { text[0] = ch; - text[1] = (*name_ptr)[char_idx + 1]; + text[1] = GetAutoNameCharacter(name_ptr, char_idx + 1); text[2] = *mnNameNew_NullCharacter; char_idx += 2; name_idx++; @@ -634,17 +647,21 @@ s32 PickAutoName(HSD_GObj* arg0) tmp = data->auto_history[0]; data->auto_history[0] = (u8) pick; - ch = data->auto_history[1]; - data->auto_history[1] = tmp; - tmp = data->auto_history[2]; - data->auto_history[2] = ch; - ch = data->auto_history[3]; - data->auto_history[3] = tmp; - data->auto_history[4] = ch; + for (i = 1; i < 5; i++) { + u8 next = data->auto_history[i]; + data->auto_history[i] = tmp; + tmp = next; + } return (s32) null_ch; } +s32 PickAutoName(HSD_GObj* arg0) +{ + PAD_STACK(16); + return PickAutoNameInline(arg0); +} + #line 779 "mnnamenew.c" bool NameContainsOnlySpaces(void) { @@ -669,51 +686,27 @@ bool NameContainsOnlySpaces(void) static inline void CopyCurrentNameToNametag(struct NameTagData* nametag) { s32 idx; - u8* text; u8 ch; + u8* text; s8 null_ch; + s32 i; text = (u8*) mnNameNew_CurrentNameText; - null_ch = (s8) *mnNameNew_NullCharacter; idx = 0; - if (null_ch != (s8) *text) { + for (i = 0; i < 4; i++) { u8* ptr; + + null_ch = (s8) *mnNameNew_NullCharacter; + if (null_ch == (s8) *text) { + break; + } ptr = text; while ((null_ch = (s8) *mnNameNew_NullCharacter) != (s8) (ch = *ptr)) { nametag->namedata[idx] = (s8) ch; idx += 1; ptr += 1; } - if (null_ch != (s8) * (text += 3)) { - ptr = text; - while ((null_ch = (s8) *mnNameNew_NullCharacter) != - (s8) (ch = *ptr)) - { - nametag->namedata[idx] = (s8) ch; - idx += 1; - ptr += 1; - } - if (null_ch != (s8) * (text += 3)) { - ptr = text; - while ((null_ch = (s8) *mnNameNew_NullCharacter) != - (s8) (ch = *ptr)) - { - nametag->namedata[idx] = (s8) ch; - idx += 1; - ptr += 1; - } - if (null_ch != (s8) * (text += 3)) { - ptr = text; - while ((null_ch = (s8) *mnNameNew_NullCharacter) != - (s8) (ch = *ptr)) - { - nametag->namedata[idx] = (s8) ch; - idx += 1; - ptr += 1; - } - } - } - } + text += 3; } nametag->namedata[idx] = (s8) *mnNameNew_NullCharacter; } @@ -1677,7 +1670,11 @@ void fn_8023DAEC(HSD_GObj* arg0) #endif void fn_8023DBE8(HSD_GObj* arg0) { + MenuFlow* flow; + HSD_GObj* gobj; NameNewEntry* data; + u16* hovered; + u16 hovered_value; HSD_JObj* jobj; HSD_JObj* parent; HSD_GObjProc* proc; @@ -1691,14 +1688,16 @@ void fn_8023DBE8(HSD_GObj* arg0) PAD_STACK(28); - data = arg0->user_data; + flow = &mn_804A04F0; + gobj = arg0; + data = gobj->user_data; - if (mn_804A04F0.x10 != 1) { + if (flow->x10 != 1) { HSD_JObjSetFlagsAll(data->jobjs[16], JOBJ_HIDDEN); HSD_JObjSetFlagsAll(data->jobjs[12], JOBJ_HIDDEN); HSD_JObjSetFlagsAll(data->jobjs[13], JOBJ_HIDDEN); HSD_GObjProc_8038FE24(HSD_GObj_804D7838); - proc = HSD_GObj_SetupProc(arg0, fn_8023DAEC, 0U); + proc = HSD_GObj_SetupProc(gobj, fn_8023DAEC, 0U); proc->flags_3 = HSD_GObj_804D783C; return; } @@ -1706,7 +1705,7 @@ void fn_8023DBE8(HSD_GObj* arg0) mnNameNew_8023DA08(data); cursor = data->x1; - if ((s32) cursor != (s32) mn_804A04F0.hovered_selection) { + if ((s32) cursor != (s32) * (hovered = &flow->hovered_selection)) { if (cursor >= 0x32U && cursor < 0x3AU) { jobj = data->jobjs[mnNameNew_KeyMap.key_jobj_ids[cursor - 0x32]]; } else { @@ -1736,7 +1735,7 @@ void fn_8023DBE8(HSD_GObj* arg0) &normal_key_color); } - sel = (u8) mn_804A04F0.hovered_selection; + sel = (u8) *hovered; if (sel >= 0x32U && sel < 0x3AU) { jobj = data->jobjs[mnNameNew_KeyMap.key_jobj_ids[sel - 0x32]]; } else { @@ -1760,22 +1759,22 @@ void fn_8023DBE8(HSD_GObj* arg0) frame = 1.0f; HSD_JObjReqAnimAll(jobj, frame); HSD_JObjAnimAll(jobj); - if (mn_804A04F0.hovered_selection < 0x32U) { + hovered_value = *hovered; + if (hovered_value < 0x32U) { highlighted_key_color = mnNameNew_804D4F68; - HSD_SisLib_803A74F0(data->key_text, - (s32) mn_804A04F0.hovered_selection, + HSD_SisLib_803A74F0(data->key_text, (s32) hovered_value, &highlighted_key_color); } - mnNameNew_8023B314(data, (s32) mn_804A04F0.hovered_selection); - data->x1 = (u8) mn_804A04F0.hovered_selection; - mnNameNew_8023B0F8(arg0, data->x1); + mnNameNew_8023B314(data, (s32) *hovered); + data->x1 = (u8) *hovered; + mnNameNew_8023B0F8(gobj, data->x1); } if ((mnNameNew_804D4C10 + (f32) data->cursor_pos) != mn_8022F298(data->jobjs[13])) { cursor = data->cursor_pos; - jobj = ((NameNewEntry*) arg0->user_data)->jobjs[13]; + jobj = ((NameNewEntry*) gobj->user_data)->jobjs[13]; HSD_JObjReqAnimAll(jobj, mnNameNew_804D4C10 + (f32) cursor); HSD_JObjAnimAll(jobj); } diff --git a/src/melee/mn/mnruleplus.c b/src/melee/mn/mnruleplus.c index 0e419b8bd9..8df2c66e6b 100644 --- a/src/melee/mn/mnruleplus.c +++ b/src/melee/mn/mnruleplus.c @@ -412,62 +412,70 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) mn_803ED1D0_t* rule_data = &mn_803ED1D0; u8 num_options = mn_803EB6B0[15].selection_count; MenuRulesPlusData* data = gobj->user_data; - s32 i, vis_count, j; + HSD_JObj** option_root; + s32 i; s32 visible; u16 selected; - PAD_STACK(8); + PAD_STACK(4); for (i = 0; 17 > i; i++) { jobj_map[i] = (u16) i; } - for (i = 0; i < (s32) num_options; i++) { + option_root = option_roots; + for (i = 0; i < (s32) num_options; option_root++, i++) { + s32 valid; + if (gm_GetCurrentGameMode() == GM_TOURNAMENT && (u8) i == 1) { - visible = 0; + valid = 0; } else if ((u8) i == 3) { if (gmMainLib_8015EE0C() != 0) { - visible = 1; + valid = 1; } else { - visible = 0; + valid = 0; } } else if ((u8) i == 5) { if (gmMainLib_8015EE44() != 0) { - visible = 1; + valid = 1; } else { - visible = 0; + valid = 0; } } else { - visible = 1; + valid = 1; } - if (visible != 0) { - vis_count = 0; - j = 0; - while (j < (s32) (u8) i) { - if (mn_80231F80((u8) j) != 0) { - vis_count++; + if (valid) { + s32 j; + + visible = valid - 1; + j = visible; + for (; j < (s32) (u8) i; j++) { + u8 j8 = j; + if (mn_80231F80(j8) != 0) { + visible++; } - j++; } { - HSD_JObj* root = data->xC[rule_data->x0[(u8) vis_count]]; + HSD_JObj* child; + HSD_JObj* root = data->xC[rule_data->x0[(u8) visible]]; if (root == NULL) { - option_roots[i] = NULL; + child = NULL; } else { - option_roots[i] = root->child; + child = root->child; } + *option_root = child; } } } if ((s32) arg1 != 0) { - u8 old_sel = data->hovered_selection; u8 new_sel; - lb_8001204C(option_roots[old_sel], jobj_parts, jobj_map, 17); + 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 (old_sel == 5) { + if (selected == 5) { HSD_JObjReqAnimAll(part, rule_data->x7C[0].start_frame); } else { HSD_JObjReqAnimAll(part, rule_data->x64[0].start_frame); @@ -476,7 +484,7 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) } { HSD_JObj* part = jobj_parts[7]; - HSD_JObjReqAnim(part, rule_data->text_start_frames[old_sel * 2]); + HSD_JObjReqAnim(part, rule_data->text_start_frames[selected * 2]); HSD_JObjAnim(part); } HSD_JObjSetFlagsAll(jobj_parts[8], JOBJ_HIDDEN); @@ -490,11 +498,12 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) } if (new_sel != 5) { HSD_JObj* part = jobj_parts[13]; + HSD_JObj* part2; HSD_JObjClearFlagsAll(part, JOBJ_HIDDEN); HSD_JObjReqAnimAll(part, rule_data->x58.start_frame); - part = jobj_parts[2]; - HSD_JObjReqAnimAll(part, rule_data->x64[1].start_frame); - HSD_JObjAnimAll(part); + part2 = jobj_parts[2]; + HSD_JObjReqAnimAll(part2, rule_data->x64[1].start_frame); + HSD_JObjAnimAll(part2); } else { HSD_JObj* part = jobj_parts[2]; HSD_JObjReqAnimAll(part, rule_data->x7C[1].start_frame); @@ -522,26 +531,28 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) u8 hovered_u8 = hovered; u8 confirmed = mn_804A04F0.confirmed_selection; HSD_JObj* tree = data->x34[hovered][0]; - if ((s32) hovered_u8 != 5 && (s32) hovered_u8 < 5) { - switch ((s32) hovered_u8) { - case 0: - mn_802324E4(confirmed, data2); - break; - default: - if ((s32) hovered_u8 >= 0) { - 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; + 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; } } } @@ -790,10 +801,10 @@ HSD_GObj* mn_80233218(MenuState state) HSD_JObj* value_jobj; StaticModelDesc* desc; HSD_JObj* root_jobj; - f32* volatile frame_ptr; - u16* sub_count_ptr; + f32* frame_ptr; + u16* volatile sub_count_ptr; GameRules* rules; - PAD_STACK(4); + PAD_STACK(8); selected = (u8) mn_804A04F0.hovered_selection; num_options = mn_803EB6B0[15].selection_count; @@ -838,6 +849,8 @@ HSD_GObj* mn_80233218(MenuState state) mn_804A04F0.confirmed_selection = user_data->rule_values.values[user_data->hovered_selection]; + frame_ptr = mn_803ED1D0.text_start_frames; + if ((u8) state != 0) { HSD_JObj* anim_jobj = user_data->xC[2]; switch ((s32) user_data->state) { @@ -854,11 +867,10 @@ HSD_GObj* mn_80233218(MenuState state) HSD_JObjAnim(anim_jobj); } - frame_ptr = mn_803ED1D0.text_start_frames; - sub_count_ptr = &mn_803ED1D0.x10[1]; + sub_count_ptr = mn_803ED1D0.x10; for (i = 0; i < (s32) num_options; i++) { vis_before = 0; - for (j = vis_before; j < i; j++) { + for (j = vis_before; j < (s32) (u8) i; j++) { if (mn_80231F80((u8) j) != 0) { vis_before++; } @@ -903,8 +915,11 @@ HSD_GObj* mn_80233218(MenuState state) lb_8001204C(cursor_jobj, jobj_parts, jobj_map, 17); - HSD_JObjReqAnim(jobj_parts[7], frame_ptr[selected == i]); - HSD_JObjAnim(jobj_parts[7]); + { + HSD_JObj* text_jobj = jobj_parts[7]; + HSD_JObjReqAnim(text_jobj, frame_ptr[selected == i]); + HSD_JObjAnim(text_jobj); + } if ((s32) selected != i) { HSD_JObjSetFlagsAll(jobj_parts[16], JOBJ_HIDDEN); @@ -925,7 +940,7 @@ HSD_GObj* mn_80233218(MenuState state) als = &mn_803ED1D0.x7C[i == selected]; (void) als; } else { - als = &mn_803ED1D0.x64[selected == i]; + als = &mn_803ED1D0.x64[i == selected]; } HSD_JObjReqAnimAll(jobj_parts[2], als->start_frame); HSD_JObjAnimAll(jobj_parts[2]); @@ -939,12 +954,15 @@ HSD_GObj* mn_80233218(MenuState state) case 1: desc = &MenMainCursorTr02_Top; break; - default: + case 2: + case 3: desc = &MenMainCursorTr03_Top; break; case 4: desc = &MenMainCursorTr04_Top; break; + default: + break; } value_jobj = HSD_JObjLoadJoint(desc->joint); @@ -957,34 +975,45 @@ HSD_GObj* mn_80233218(MenuState state) lb_80011E24(value_jobj, &user_data->x34[i][j], j, -1); } - if (i == 0) { + switch (i) { + case 0: { JObjIndices digit_indices = mn_804DBE48; - j = 0; - do { + u8* index_ptr = digit_indices.idx; + for (j = 0; j < 4; j++, index_ptr++) { HSD_JObj* num_jobj = HSD_JObjLoadJoint(MenMainNmRl_Top.joint); HSD_JObjAddAnimAll(num_jobj, MenMainNmRl_Top.animjoint, MenMainNmRl_Top.matanim_joint, MenMainNmRl_Top.shapeanim_joint); - HSD_JObjAddChild( - user_data->x34[0][digit_indices.idx[j]], num_jobj); - j++; - } while (j < 4); + HSD_JObjAddChild(user_data->x34[0][*index_ptr], + num_jobj); + } mn_802324E4(user_data->rule_values.time_limit, user_data); - } else if (i >= 0 && i < 5) { + break; + } + case 1: + case 2: + case 3: + case 4: { u8 val = user_data->rule_values.values[i]; + u8 default_val; AnimLoopSettings* val_als; if ((u8) i != 1 && (u8) i != 2 && (u8) i != 3 && (u8) i != 4) { val_als = NULL; - } else if (val == 0) { - val_als = &mn_803ED270[mn_803ED2E8.stat[i][1]]; } else { - val_als = &mn_803ED270[val - 1]; + default_val = mn_803ED2E8.stat[(u8) i][1]; + if (val == 0) { + val_als = &mn_803ED270[default_val]; + } else { + val_als = &mn_803ED270[val - 1]; + } } HSD_JObjReqAnimAll(value_jobj, val_als->end_frame); HSD_JObjAnimAll(value_jobj); + break; + } } HSD_JObjAddChild(option_jobj, value_jobj); diff --git a/src/melee/mn/mnsnap.c b/src/melee/mn/mnsnap.c index 42d1616a52..5b84915974 100644 --- a/src/melee/mn/mnsnap.c +++ b/src/melee/mn/mnsnap.c @@ -577,30 +577,33 @@ void mnSnap_80253E90(s32 idx) } /// Animates the memory card slot selector highlights. -/// Pointer arithmetic required to match: walk[0x94] reads card_status[i], -/// and (snap + byte_off + 0x98) accesses slot_a_jobj / slot_b_jobj. +/// The walk advances through card_status, while byte_off selects the slot +/// animation pointers from the interleaved slot fields. void mnSnap_80253F60(void) { - s32 byte_off = 4; - mnSnap_State* snap = &mnSnap_804A0A10; - /* walk strides through card_status (s16 at byte 0x128) */ - s16* walk = (s16*) snap; + s32 byte_off; + s16* walk = (s16*) &mnSnap_804A0A10; s32 i; - for (i = 0; i < 2; i++, walk++, byte_off += 8) { - if (walk[0x94] != 0) { /* snap->card_status[i] */ + + for (i = 0; i < 2; i++) { + byte_off = (i * 2 + 1) * 4; + if (walk[0x94] != 0) { f32 t; - if (snap->active_slot == i) { + if (mnSnap_804A0A10.active_slot == i) { t = 1.0F; } else { t = 0.0F; } - HSD_JObjReqAnimAll(*(HSD_JObj**) ((u32) snap + byte_off + 0x98), - t); + HSD_JObjReqAnimAll( + *(HSD_JObj**) ((u32) &mnSnap_804A0A10 + byte_off + 0x98), t); } else { - HSD_JObjReqAnimAll(*(HSD_JObj**) ((u32) snap + byte_off + 0x98), - 2.0F); + HSD_JObjReqAnimAll( + *(HSD_JObj**) ((u32) &mnSnap_804A0A10 + byte_off + 0x98), + 2.0F); } - HSD_JObjAnimAll(*(HSD_JObj**) ((u32) snap + byte_off + 0x98)); + HSD_JObjAnimAll( + *(HSD_JObj**) ((u32) &mnSnap_804A0A10 + byte_off + 0x98)); + walk++; } } diff --git a/src/melee/mn/mnsound.c b/src/melee/mn/mnsound.c index bc376cd644..6ace2b976f 100644 --- a/src/melee/mn/mnsound.c +++ b/src/melee/mn/mnsound.c @@ -50,26 +50,52 @@ static void mnSound_VolumeAnim(HSD_JObj* jobj, s32 sound_music_mix, } } +static inline void mnSound_InitChannelAnim(HSD_JObj* jobj, s32 channel, + HSD_JObj** jobj_anim_0, + HSD_JObj** jobj_anim_1, + HSD_JObj** jobj_anim_2) +{ + 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); + left_frame = mn_8022F298(*jobj_anim_1); + right_frame = mn_8022F298(*jobj_anim_2); + + HSD_JObjReqAnimAll(*jobj_anim_0, channel); + HSD_JObjAnimAll(*jobj_anim_0); + + HSD_JObjReqAnimAll(*jobj_anim_1, left_frame); + mn_8022F3D8(*jobj_anim_1, 0xFFU, MOBJ_MASK); + HSD_JObjAnimAll(*jobj_anim_1); + + HSD_JObjReqAnimAll(*jobj_anim_2, right_frame); + mn_8022F3D8(*jobj_anim_2, 0xFFU, MOBJ_MASK); + HSD_JObjAnimAll(*jobj_anim_2); +} + static void mnSound_ChannelAnim(HSD_JObj* jobj, s32 channel) { - HSD_JObj* jobj_anim[3]; + HSD_JObj* jobj_anim_2; + HSD_JObj* jobj_anim_1; + 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); - left_frame = mn_8022F298(jobj_anim[1]); - right_frame = mn_8022F298(jobj_anim[2]); + lb_80011E24(jobj, &jobj_anim_0, 8, -1); + lb_80011E24(jobj, &jobj_anim_1, 10, -1); + lb_80011E24(jobj, &jobj_anim_2, 9, -1); + left_frame = mn_8022F298(jobj_anim_1); + right_frame = mn_8022F298(jobj_anim_2); - HSD_JObjReqAnimAll(jobj_anim[0], channel); - HSD_JObjAnimAll(jobj_anim[0]); + HSD_JObjReqAnimAll(jobj_anim_0, channel); + HSD_JObjAnimAll(jobj_anim_0); - HSD_JObjReqAnimAll(jobj_anim[1], left_frame); - mn_8022F3D8(jobj_anim[1], 0xFFU, MOBJ_MASK); - HSD_JObjAnimAll(jobj_anim[1]); + HSD_JObjReqAnimAll(jobj_anim_1, left_frame); + mn_8022F3D8(jobj_anim_1, 0xFFU, MOBJ_MASK); + HSD_JObjAnimAll(jobj_anim_1); - HSD_JObjReqAnimAll(jobj_anim[2], right_frame); - mn_8022F3D8(jobj_anim[2], 0xFFU, MOBJ_MASK); - HSD_JObjAnimAll(jobj_anim[2]); + HSD_JObjReqAnimAll(jobj_anim_2, right_frame); + mn_8022F3D8(jobj_anim_2, 0xFFU, MOBJ_MASK); + HSD_JObjAnimAll(jobj_anim_2); } static inline void mnSound_InitVolumeAnim(HSD_JObj* jobj, s32 sound_music_mix, @@ -248,6 +274,16 @@ void fn_80249A1C(HSD_GObj* arg0) } } +static inline void mnSound_InitUserData(Menu* user_data, HSD_GObj* gobj) +{ + HSD_GObjProc* proc; + user_data->unk3 = gmMainLib_8015ED74(); + user_data->text = NULL; + GObj_InitUserData(gobj, 0U, HSD_Free, user_data); + proc = HSD_GObj_SetupProc(gobj, fn_80249A1C, 0U); + proc->flags_3 = HSD_GObj_804D783C; +} + void mnSound_80249C08(int unused) { StaticModelDesc* model = &mnSound_804A08A8; @@ -255,8 +291,11 @@ void mnSound_80249C08(int unused) HSD_GObj* gobj = GObj_Create(HSD_GOBJ_CLASS_ITEM, 7U, 0x80U); HSD_JObj* jobj; Menu* user_data; - HSD_GObjProc* proc; - PAD_STACK(24); + UNUSED HSD_GObjProc* proc; + HSD_JObj* sound_selection_jobj; + HSD_JObj* channel_selection_jobj; + HSD_JObj* volume_cursor_jobj; + PAD_STACK(4); mnSound_804D6C30 = gobj; jobj = HSD_JObjLoadJoint(model->joint); HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); @@ -273,11 +312,7 @@ void mnSound_80249C08(int unused) user_data->cursor = 0x14; user_data->unk1 = lbAudioAx_80024BD0(); user_data->unk2 = 0U; - user_data->unk3 = gmMainLib_8015ED74(); - user_data->text = NULL; - GObj_InitUserData(gobj, 0U, HSD_Free, user_data); - proc = HSD_GObj_SetupProc(gobj, fn_80249A1C, 0U); - proc->flags_3 = HSD_GObj_804D783C; + mnSound_InitUserData(user_data, gobj); { Menu* menu = GET_MENU(mnSound_804D6C30); @@ -293,13 +328,20 @@ void mnSound_80249C08(int unused) Menu_InitCenterText(menu, text_id); } - mnSound_ChannelAnim(GET_JOBJ(gobj), user_data->unk1); + { + HSD_JObj* channel_anim_2; + HSD_JObj* channel_anim_1; + HSD_JObj* channel_anim_0; + PAD_STACK(4); + mnSound_InitChannelAnim(GET_JOBJ(gobj), user_data->unk1, + &channel_anim_0, &channel_anim_1, + &channel_anim_2); + } { - HSD_JObj* sp5C; - lb_80011E24(jobj, &sp5C, 6, -1); - HSD_JObjReqAnimAll(sp5C, anims[5].end_frame); - HSD_JObjAnimAll(sp5C); + lb_80011E24(jobj, &volume_cursor_jobj, 6, -1); + HSD_JObjReqAnimAll(volume_cursor_jobj, anims[5].end_frame); + HSD_JObjAnimAll(volume_cursor_jobj); } { @@ -308,22 +350,22 @@ void mnSound_80249C08(int unused) HSD_JObj* jobj_anim_2; HSD_JObj* jobj_anim_1; HSD_JObj* jobj_anim_0; + PAD_STACK(8); mnSound_InitVolumeAnim(GET_JOBJ(gobj), user_data->unk3, &pos_0, &pos_1, &jobj_anim_0, &jobj_anim_1, &jobj_anim_2); } { - HSD_JObj* sp64; - HSD_JObj* sp60; gm_801602C0(user_data->unk3); - lb_80011E24(jobj, &sp64, 0xE, -1); + lb_80011E24(jobj, &sound_selection_jobj, 0xE, -1); { AnimLoopSettings* anim = &anims[user_data->unk2]; - mn_8022ED6C(sp64, anim + 1); + mn_8022ED6C(sound_selection_jobj, anim + 1); } - lb_80011E24(jobj, &sp60, 0xB, -1); - HSD_JObjReqAnimAll(sp60, anims[user_data->unk1 + 3].end_frame); - HSD_JObjAnimAll(sp60); + lb_80011E24(jobj, &channel_selection_jobj, 0xB, -1); + HSD_JObjReqAnimAll(channel_selection_jobj, + anims[user_data->unk1 + 3].end_frame); + HSD_JObjAnimAll(channel_selection_jobj); HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); } } diff --git a/src/melee/mn/mnstagesw.c b/src/melee/mn/mnstagesw.c index 98a4680b17..4a12070cfe 100644 --- a/src/melee/mn/mnstagesw.c +++ b/src/melee/mn/mnstagesw.c @@ -151,17 +151,33 @@ static void mnStageSw_802359C8(MnStageSwData* data) } } -static s32 mnStageSw_80235C58(u8 arg0) +static inline s32 mnStageSw_IsRangeEmpty(u8 range_start, u8 range_end) { - s32 low; - s32 found; - s32 i; - s32 idx; - u8 high; s32 curr; + + for (curr = range_start; curr <= range_end; curr++) { + if (gm_80164430(gm_801641CC(mnStageSw_803ED4C4[(u8) curr])) != 0) { + return 0; + } + } + return 1; +} + +static inline s32 mnStageSw_GetPreviousIndex(s32 offset, s32 index) +{ + return index - offset; +} + +static s32 mnStageSw_80235C58(u8 arg0) +{ s32 next; + u8 low; + s32 idx; u8 end; + s32 curr; + s32 i; u8 start; + u8 high; if (arg0 < 15) { low = 0; @@ -178,17 +194,7 @@ static s32 mnStageSw_80235C58(u8 arg0) end = 28; } - curr = start; - while (curr <= end) { - if (gm_80164430(gm_801641CC(mnStageSw_803ED4C4[(u8) curr])) != 0) { - found = 0; - goto loop_done; - } - curr++; - } - found = 1; -loop_done: - if (found != 0) { + if (mnStageSw_IsRangeEmpty(start, end) != 0) { return -1; } @@ -198,12 +204,12 @@ static s32 mnStageSw_80235C58(u8 arg0) return arg0; } - idx = arg0; i = 1; + curr = arg0 + 1; + idx = arg0; next = idx + 1; - curr = idx + 1; while (true) { - s32 temp = idx - i; + s32 temp = mnStageSw_GetPreviousIndex(i, idx); s32 prev = temp; if (low <= prev && @@ -509,9 +515,11 @@ static void mnStageSw_80236548(HSD_GObj* gobj, u8 arg1, u8 arg2) static void fn_80236998(HSD_GObj* gobj) { HSD_JObj* jobj; - MnStageSwData* data; + MnStageSwData* current_data = gobj->user_data; + MnStageSwData* data = current_data; AnimLoopSettings* anims; s32 changed_menu; + s32 i; s32 changed_hovered; u64 pad3; HSD_JObj* child; @@ -521,7 +529,6 @@ static void fn_80236998(HSD_GObj* gobj) changed_menu = 0; changed_hovered = 0; changed_confirmed = 0; - data = gobj->user_data; state = data->x1F; PAD_STACK(4); if ((state == 0 || state == 1 || state == 3) && @@ -577,19 +584,18 @@ static void fn_80236998(HSD_GObj* gobj) if (mn_8022F298(jobj) >= anims->end_frame) { switch ((s32) data->x1F) { case 1: - case 3: { - s32 i; - - data->x1F = 0; + 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 (i = 0; i < NUM_STAGES; i++) { - jobj = mnStageSw_802364A0((MnStageSwData*) gobj, i); - if (i != ((MnStageSwData*) gobj)->x1) { + 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); } @@ -598,18 +604,14 @@ static void fn_80236998(HSD_GObj* gobj) ((MnStageSwData*) gobj)->x1); mnStageSw_804D6BF4 = 0; return; - } case 2: - case 4: { - s32 i; - + case 4: for (i = 0; i < NUM_STAGES; i++) { HSD_SisLib_803A5CC4(data->x40[i]); } HSD_GObjPLink_80390228(gobj); return; } - } } HSD_JObjAnim(jobj); } @@ -671,37 +673,76 @@ static inline void mnStageSw_SetCursorPosition(MnStageSwData* user_data) static inline void mnStageSw_InitUserData(MnStageSwData* user_data, s8 state) { s32 i; + u8 disabled; + u8* stage_ids; user_data->x0 = mn_804A04F0.cur_menu; user_data->x1 = (u8) mn_804A04F0.hovered_selection; user_data->x1F = state; - for (i = 0; i < NUM_STAGES; i++) { - u8 stage_id = mnStageSw_803ED4C4[i]; - - if (gm_80164430(gm_801641CC(stage_id)) != 0) { - user_data->x2[i] = gm_80164250(stage_id); + i = 0; + disabled = i; + stage_ids = mnStageSw_803ED4C4; + for (; (u8) i < NUM_STAGES; stage_ids++, i++) { + if (gm_80164430(gm_801641CC(mnStageSw_803ED4C4[(u8) i])) != 0) { + user_data->x2[(u8) i] = gm_80164250(*stage_ids); } else { - user_data->x2[i] = 0; + user_data->x2[(u8) i] = disabled; } } } -static inline HSD_JObj* mnStageSw_LoadCursor(void) +static inline void mnStageSw_SetCursorAnim(s32 index, MnStageSwData* user_data, + HSD_JObj* cursor_jobj, + u8* cursor_index, + HSD_JObj** cursor_anim_jobj) { - return HSD_JObjLoadJoint(MenMainCursorSs_Top.joint); + u8 enabled; + + *cursor_index = (u8) index; + enabled = user_data->x2[*cursor_index]; + lb_80011E24(cursor_jobj, cursor_anim_jobj, 2, -1); + HSD_JObjReqAnimAll(*cursor_anim_jobj, mnStageSw_804D4BB8[enabled]); +} + +static inline HSD_JObj* mnStageSw_CreateCursor(MnStageSwData* user_data, + s32 index, + AnimLoopSettings* anims) +{ + HSD_JObj* cursor_jobj; + HSD_JObj* cursor_anim_jobj; + HSD_JObj* hover_anim_jobj; + u8 hovered; + u8 idx; + + hovered = mn_804A04F0.hovered_selection; + cursor_jobj = HSD_JObjLoadJoint(MenMainCursorSs_Top.joint); + HSD_JObjAddAnimAll(cursor_jobj, MenMainCursorSs_Top.animjoint, + MenMainCursorSs_Top.matanim_joint, + MenMainCursorSs_Top.shapeanim_joint); + mnStageSw_SetCursorAnim(index, user_data, cursor_jobj, &idx, + &cursor_anim_jobj); + HSD_JObjAnimAll(cursor_anim_jobj); + lb_80011E24(cursor_jobj, &hover_anim_jobj, 3, -1); + if (idx == hovered) { + HSD_JObjReqAnimAll(hover_anim_jobj, anims[0].start_frame); + HSD_JObjAnimAll(hover_anim_jobj); + } else { + HSD_JObjSetFlagsAll(hover_anim_jobj, JOBJ_HIDDEN); + } + if (gm_80164430(gm_801641CC(mnStageSw_803ED4C4[idx])) == 0) { + HSD_JObjSetFlagsAll(cursor_jobj, JOBJ_HIDDEN); + } + return cursor_jobj; } static HSD_GObj* mnStageSw_80236CBC(s8 arg0) { HSD_GObj* gobj; HSD_JObj* jobj; - HSD_JObj* sp48; MnStageSwData* user_data; AnimLoopSettings* anims = mnStageSw_803ED488; struct StaticModelDesc* mdl = &MenMainConSs_Top; f32 y_spacing; - u8 hovered; - HSD_JObj* cursor_anim_jobj; s32 i; gobj = GObj_Create(6, 7, 0x80); @@ -732,29 +773,8 @@ static HSD_GObj* mnStageSw_80236CBC(s8 arg0) HSD_JObjGetTranslationY(user_data->x2C); for (i = 0; i < NUM_STAGES; i++) { HSD_JObj* cursor_jobj; - u8 enabled; - u8 idx; - hovered = mn_804A04F0.hovered_selection; - cursor_jobj = mnStageSw_LoadCursor(); - HSD_JObjAddAnimAll(cursor_jobj, MenMainCursorSs_Top.animjoint, - MenMainCursorSs_Top.matanim_joint, - MenMainCursorSs_Top.shapeanim_joint); - idx = i; - enabled = user_data->x2[idx]; - lb_80011E24(cursor_jobj, &cursor_anim_jobj, 2, -1); - HSD_JObjReqAnimAll(cursor_anim_jobj, mnStageSw_804D4BB8[enabled]); - HSD_JObjAnimAll(cursor_anim_jobj); - lb_80011E24(cursor_jobj, &sp48, 3, -1); - if (hovered == idx) { - HSD_JObjReqAnimAll(sp48, anims[0].start_frame); - HSD_JObjAnimAll(sp48); - } else { - HSD_JObjSetFlagsAll(sp48, JOBJ_HIDDEN); - } - if (gm_80164430(gm_801641CC(mnStageSw_803ED4C4[idx])) == 0) { - HSD_JObjSetFlagsAll(cursor_jobj, JOBJ_HIDDEN); - } + cursor_jobj = mnStageSw_CreateCursor(user_data, i, anims); if (i < 15) { HSD_JObjAddChild(user_data->x2C, cursor_jobj); HSD_JObjAddTranslationY(cursor_jobj, y_spacing * (f32) i); diff --git a/src/melee/mn/mnvibration.c b/src/melee/mn/mnvibration.c index 93fc6ca181..dae4956dd5 100644 --- a/src/melee/mn/mnvibration.c +++ b/src/melee/mn/mnvibration.c @@ -227,6 +227,15 @@ HSD_JObj* mnVibration_GetNameRowJObj(s32 count) #pragma pop #endif +static inline void mnVibration_AnimateNameRow(u8 row, u8 state) +{ + HSD_JObj* jobj; + + jobj = mnVibration_GetNameRowJObj(row); + HSD_JObjReqAnimAll(jobj, (f32) state); + HSD_JObjAnimAll(jobj); +} + void mnVibration_HandleInput(HSD_GObj* gobj) { HSD_JObj* cursor_jobj; @@ -402,9 +411,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) GetPersistentNameData(name_idx)->rumble_toggle = 1; } rumble_setting = mnVibration_GetNameRumble(name_idx); - jobj = mnVibration_GetNameRowJObj(data->x0[1]); - HSD_JObjReqAnimAll(jobj, (f32) rumble_setting); - HSD_JObjAnimAll(jobj); + mnVibration_AnimateNameRow(data->x0[1], rumble_setting); return; } @@ -433,6 +440,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) 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]; @@ -475,6 +483,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) 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]; @@ -486,8 +495,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) HSD_JObjSetTranslateZ(cursor_jobj, temp_z); } } else if (GetNameCount() > 8) { - name_idx = mnVibration_GetNameSlot(data, 8); - if (name_idx != 0xFF) { + if (mnVibration_GetNameSlot(data, 8) != 0xFF) { sfxMove(); data->scroll_offset++; if (data->scroll_offset >= GetNameCount()) { @@ -713,6 +721,7 @@ void mnVibration_Think(HSD_GObj* gobj) s32 port; s32 port_idx; u8 pad_err; + u8 pad_idx; u8 state; HSD_JObj* active_child; MnVibrationData* data; @@ -758,7 +767,8 @@ void mnVibration_Think(HSD_GObj* gobj) } while (port < 4); port_idx = 0; do { - pad_err = HSD_PadCopyStatus[(u8) port_idx].err; + pad_idx = 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))) { @@ -795,7 +805,7 @@ void mnVibration_Think(HSD_GObj* gobj) data->x0[port_idx + 2] = 0; toggle_jobj = ((MnVibrationData*) mnVibration_804D6C28->user_data) - ->jobjs[mnVibration_PortPanelJointIds[(u8) port_idx]]; + ->jobjs[mnVibration_PortPanelJointIds[pad_idx]]; state = data->x0[port_idx + 2]; HSD_JObjReqAnimAll(toggle_jobj, state); HSD_JObjAnimAll(toggle_jobj); @@ -821,7 +831,6 @@ void mnVibration_IntroProc(HSD_GObj* arg0) MnVibrationData* data2; HSD_GObj* cursor_gobj; HSD_JObj* loaded_joint; - MnVibrationData* data3; HSD_JObj* cursor_jobj; HSD_JObj* jobj; HSD_JObj* jobj2; @@ -938,21 +947,23 @@ 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); - data3 = arg0->user_data; + data2 = arg0->user_data; cursor_jobj = cursor_gobj->hsd_obj; - jobj17 = data3->jobjs[17]; + jobj17 = data2->jobjs[17]; cursor_row = data2->x0[1]; + (void) jobj17; + (void) cursor_row; base_y = mnVibration_JObjGetTranslationY(jobj17); - jobj18 = data3->jobjs[18]; + jobj18 = data2->jobjs[18]; spacing = mnVibration_GetCursorYSpacing(base_y, jobj18); - jobj17 = data3->jobjs[17]; + jobj17 = data2->jobjs[17]; temp_x = mnVibration_JObjGetTranslationX(jobj17); mnVibration_JObjSetTranslateX(cursor_jobj, temp_x); - jobj17 = data3->jobjs[17]; + jobj17 = data2->jobjs[17]; mnVibration_JObjSetTranslateY( cursor_jobj, (spacing * (f32) cursor_row) + mnVibration_JObjGetTranslationY(jobj17)); - jobj17 = data3->jobjs[17]; + jobj17 = data2->jobjs[17]; temp_z = mnVibration_JObjGetTranslationZ(jobj17); mnVibration_JObjSetTranslateZ(cursor_jobj, temp_z); } diff --git a/src/melee/ty/toy.c b/src/melee/ty/toy.c index 8f3390e975..fbc7380647 100644 --- a/src/melee/ty/toy.c +++ b/src/melee/ty/toy.c @@ -1,5 +1,22 @@ #include "toy.static.h" // IWYU pragma: associated +typedef struct ToyDisplayList { + /* 0x000 */ ToyListEntry entries[13]; + /* 0x138 */ ToyListEntry* first_entry; + /* 0x13C */ ToyListEntry* last_entry; + /* 0x140 */ ToyListEntry* selected_entry; + /* 0x144 */ u8 pad_144[0x154 - 0x144]; + /* 0x154 */ s16 selectedIdx; + /* 0x156 */ u8 pad_156; + /* 0x157 */ s8 visible_count; +} ToyDisplayList; +ASSERT_SIZE(ToyDisplayList, 0x158); + +typedef struct ToyUnkJObjData { + /* 0x00 */ u8 pad_00[0x10]; + /* 0x10 */ HSD_JObj* jobj; +} ToyUnkJObjData; + /* 3053C4 */ static void _Toy_803053C4(s32, s32, s32); /* 3062EC */ static void _Toy_803062EC(s32 arg0, u32 arg1, f32 farg0); /* 3064B8 */ static s16 _Toy_803064B8(s16 arg0, s8 arg1); @@ -21,7 +38,7 @@ /* 30B530 */ static void _Toy_8030B530(HSD_GObj*); /* 30E110 */ static void _Toy_8030E110(HSD_GObj*); /* 30FA50 */ static void _Toy_8030FA50(void); -/* 30FE48 */ static void _Toy_8030FE48(void*, s32); +/* 30FE48 */ static void _Toy_8030FE48(ToyDisplayList*, s32); /* 3102C4 */ static void _Toy_803102C4(s8 arg0); /* 3109A0 */ static void _Toy_803109A0(s32, s32, s32); /* 310B48 */ static void _Toy_80310B48(HSD_GObj*); @@ -2762,18 +2779,20 @@ f32 _Toy_80309338(Vec3* arg0, Vec3* arg1) void _Toy_80309404(HSD_GObj* gobj) { struct { - u8 pad[0x2C]; Vec3 pos; - u8 pad2[0x8]; - } eye_pad; - Vec3 eye_pos; - HSD_CObj* cobj; - Vec3 transition_interest; + u8 pad[0x10]; + } unused_eye; Vec3 transition_eye; + Vec3 transition_interest; + struct { + Vec3 pos; + u8 pad[0x14]; + } eye_pos; + ToyCameraControl* ed4; + HSD_CObj* cobj; Toy26B8* base; ToyED8Data* ed8; Toy6E68* state; - ToyCameraControl* ed4; ToyAnimState* anim; f32 dist; f32 tmp; @@ -2783,12 +2802,15 @@ void _Toy_80309404(HSD_GObj* gobj) u32 trigger; u32 button; s32 sign; - s32 sp138; - s32 sp134; - s32 sp130; - s32 sp12C; + struct { + void* next; + void* next_wrap; + void* prev; + void* prev_wrap; + u8 trailing_pad[0x78]; + } archive_symbols; - PAD_STACK(256); + PAD_STACK(164); cobj = gobj->hsd_obj; base = (Toy26B8*) &_Toy_804A26B8; @@ -2800,8 +2822,8 @@ void _Toy_80309404(HSD_GObj* gobj) movement_update = 0.0f; rotate_update = 0.0f; - HSD_CObjGetEyePosition(cobj, &eye_pos); - dist = _Toy_80309338(&eye_pos, NULL); + HSD_CObjGetEyePosition(cobj, &eye_pos.pos); + dist = _Toy_80309338(&eye_pos.pos, NULL); { f32 val; @@ -2979,21 +3001,9 @@ void _Toy_80309404(HSD_GObj* gobj) _Toy_sbss_804D6E88 = HSD_CObjGetRight(cobj); _Toy_sbss_804D6E8C = HSD_CObjGetLeft(cobj); state->x5C = 0; - { - ToyTransitionObj* obj = state->x0; - obj->x24 = 0; - obj->x20 = 0x480000; - } - { - ToyTransitionObj* obj = state->x4; - obj->x24 = 0; - obj->x20 = 0; - } - { - ToyTransitionObj* obj = state->xC; - obj->x24 = 0; - obj->x20 = 0; - } + ((HSD_GObj*) state->x0)->gxlink_prios = 0x0048000000000000ULL; + ((HSD_GObj*) state->x4)->gxlink_prios = 0; + ((HSD_GObj*) state->xC)->gxlink_prios = 0; state->x61 = 1; _Toy_8030715C(0.0f, 0.0f); return; @@ -3004,7 +3014,7 @@ void _Toy_80309404(HSD_GObj* gobj) case 1: case 3: _Toy_80308F04(cobj); - rotate_update = 1.0f; + rotate_update = 0.0f; break; case 2: trigger = Toy_80305B88(); @@ -3038,21 +3048,9 @@ void _Toy_80309404(HSD_GObj* gobj) _Toy_sbss_804D6E88 = HSD_CObjGetRight(cobj); _Toy_sbss_804D6E8C = HSD_CObjGetLeft(cobj); - { - ToyTransitionObj* obj = state->x0; - obj->x24 = 0; - obj->x20 = 0x50480000; - } - { - ToyTransitionObj* obj = state->x4; - obj->x24 = 0; - obj->x20 = (s32) 0x80000000U; - } - { - ToyTransitionObj* obj = state->xC; - obj->x24 = 0; - obj->x20 = 0x40000000; - } + ((HSD_GObj*) state->x0)->gxlink_prios = 0x5048000000000000ULL; + ((HSD_GObj*) state->x4)->gxlink_prios = 0x8000000000000000ULL; + ((HSD_GObj*) state->xC)->gxlink_prios = 0x4000000000000000ULL; jobj_node = (ToyJObjNode*) Toy_sbss_804D6ED8->xC->x28; while (jobj_node != NULL) { jobj_node->x40 = 9; @@ -3062,7 +3060,7 @@ void _Toy_80309404(HSD_GObj* gobj) state->x5C = 0; transition_eye = _Toy_803B88E0; transition_interest = _Toy_803B88EC; - HSD_CObjGetEyePosition(cobj, &eye_pad.pos); + HSD_CObjGetEyePosition(cobj, &unused_eye.pos); transition_eye.y = 8.0f; HSD_CObjGetInterest(cobj, &transition_interest); base->x0.x = (transition_eye.x - transition_interest.x) / 10.0f; @@ -3134,13 +3132,10 @@ void _Toy_80309404(HSD_GObj* gobj) } } - if (!state->x50 && !state->x54) { - button = Toy_80305C44(); - if (button & HSD_PAD_A) { - _Toy_803102C4(0); - } else { - _Toy_803102C4(1); - } + if (state->x50 || state->x54 || (Toy_80305C44() & HSD_PAD_A)) { + _Toy_803102C4(0); + } else { + _Toy_803102C4(1); } if (state->x50 || state->x54) { movement_update = 1.0f; @@ -3187,7 +3182,7 @@ void _Toy_80309404(HSD_GObj* gobj) } tmp = state->x1C; if (tmp < -360.0f) { - state->x1C = (f32) (tmp + 360.0f); + state->x1C += 360.0f; } tmp = state->x1C; if (tmp > 360.0f) { @@ -3222,15 +3217,9 @@ void _Toy_80309404(HSD_GObj* gobj) } { TyDisplayData* display; - u32 trig2; display = Toy_sbss_804D6EE0; - if (state->x30 < 0.0f) { - goto cycle_prev; - } - trig2 = Toy_80305B88(); - if (trig2 & 0x441) { - cycle_prev: { + if ((state->x30 < 0.0f) || (Toy_80305B88() & 0x441)) { s32 total; sfxMove(); @@ -3254,8 +3243,7 @@ void _Toy_80309404(HSD_GObj* gobj) } if (total > 3) { if ((display->selectedIdx - 1) < 0) { - s32 cnt; - s32 lk; + s32 list_idx; ToyListEntry* entry; HSD_Archive* oa; char* md; @@ -3264,14 +3252,15 @@ void _Toy_80309404(HSD_GObj* gobj) (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - cnt = base->trophy_count; + list_idx = base->trophy_count; } else { - cnt = *gmMainLib_GetTrophyCount(); + list_idx = *gmMainLib_GetTrophyCount(); } - lk = cnt + display->selectedIdx; - entry = display->first_entry->prev; + list_idx += display->selectedIdx; + entry = display->first_entry; + entry = entry->prev; { - s32 idx = lk - 1; + s32 idx = list_idx - 1; s16 tid = Toy_sbss_804D6EDC[idx]; md = Toy_8030813C(tid); if ((oa = entry->archive) != NULL) { @@ -3282,7 +3271,8 @@ void _Toy_80309404(HSD_GObj* gobj) entry->symbol_name = md + 0x24; entry->trophy_id = tid; entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &sp138, + entry->archive_name, + &archive_symbols.prev_wrap, entry->symbol_name, 0); } } else { @@ -3303,7 +3293,7 @@ void _Toy_80309404(HSD_GObj* gobj) entry->symbol_name = md + 0x24; entry->trophy_id = tid; entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &sp134, + entry->archive_name, &archive_symbols.prev, entry->symbol_name, 0); } { @@ -3323,16 +3313,8 @@ void _Toy_80309404(HSD_GObj* gobj) display->selected_entry = display->selected_entry->prev; } - } - } else { - if (state->x30 > 0.0f) { - goto cycle_next; - } - trig2 = Toy_80305B88(); - if (!(trig2 & 0x822)) { - goto after_cycle_direction; - } - cycle_next: { + } else if ((state->x30 > 0.0f) || (Toy_80305B88() & 0x822)) + { s32 total; sfxMove(); @@ -3391,12 +3373,10 @@ void _Toy_80309404(HSD_GObj* gobj) entry->archive_name = md + 4; entry->symbol_name = md + 0x24; entry->trophy_id = tid; - { - char* symbol_name = entry->symbol_name; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &sp130, - symbol_name, 0); - } + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, + &archive_symbols.next_wrap, + entry->symbol_name, 0); } else { ToyListEntry* entry; HSD_Archive* oa; @@ -3415,7 +3395,7 @@ void _Toy_80309404(HSD_GObj* gobj) entry->symbol_name = md + 0x24; entry->trophy_id = tid; entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &sp12C, + entry->archive_name, &archive_symbols.next, entry->symbol_name, 0); } { @@ -3436,9 +3416,7 @@ void _Toy_80309404(HSD_GObj* gobj) display->selected_entry->next; } } - } - after_cycle_direction: _Toy_80307828(0); _Toy_8030715C(0.0f, 0.0f); state->x58 = 0x95E; @@ -3456,7 +3434,11 @@ void _Toy_80309404(HSD_GObj* gobj) } if (flags[idx] & 0x8000) { - idx = Toy_sbss_804D6EDC[display->selectedIdx]; + { + s16 selected_trophy = + Toy_sbss_804D6EDC[display->selectedIdx]; + idx = selected_trophy; + } if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { @@ -3509,9 +3491,9 @@ void _Toy_80309404(HSD_GObj* gobj) anim->x0E = 0; _Toy_80307F64(2, 0); } + _Toy_80308DC8(cobj); } - _Toy_80308DC8(cobj); _Toy_8030715C(state->x50, state->x54); state->x38 = state->x30; state->x3C = state->x34; @@ -3551,17 +3533,12 @@ void _Toy_8030B530(HSD_GObj* arg0) u32 trigger; u32 button; f32 angle; - s32 sp190; - s32 sp18C; - s32 sp188; - s32 sp184; - PAD_STACK(296); + PAD_STACK(72); { - void* anim_state_ptr = M2C_FIELD(anim, void**, 0x0); - void* x28_ptr = M2C_FIELD(anim_state_ptr, void**, 0x28); - jobj_child = M2C_FIELD(x28_ptr, HSD_JObj**, 0x10); + ToyUnkJObjData* data = anim->gobj->hsd_obj; + jobj_child = data->jobj; jobj_next = jobj_child->next; } @@ -3679,32 +3656,23 @@ void _Toy_8030B530(HSD_GObj* arg0) { u8 mode = state->x61; if ((s8) mode == 0) { - ToyTransitionObj* transition = state->x0; - transition->x24 = 0; - transition->x20 = 0x480000; - transition = state->x4; - transition->x24 = 0; - transition->x20 = 0; - transition = state->xC; - transition->x24 = 0; - transition->x20 = 0; + ((HSD_GObj*) state->x0)->gxlink_prios = + 0x0048000000000000ULL; + ((HSD_GObj*) state->x4)->gxlink_prios = 0; + ((HSD_GObj*) state->xC)->gxlink_prios = 0; state->x61 = 1; state->x5C = 0; return; } if ((s8) mode == 2) { - ToyTransitionObj* transition; state->x5C = 0; _Toy_80307828(0); - transition = state->x0; - transition->x24 = 0; - transition->x20 = 0x50480000; - transition = state->x4; - transition->x24 = 0; - transition->x20 = (s32) 0x80000000U; - transition = state->xC; - transition->x24 = 0; - transition->x20 = 0x40000000; + ((HSD_GObj*) state->x0)->gxlink_prios = + 0x5048000000000000ULL; + ((HSD_GObj*) state->x4)->gxlink_prios = + 0x8000000000000000ULL; + ((HSD_GObj*) state->xC)->gxlink_prios = + 0x4000000000000000ULL; state->x5C = 0; state->x61 = 3; sfxBack(); @@ -3781,37 +3749,54 @@ void _Toy_8030B530(HSD_GObj* arg0) angle = lb_8000D008(adj_y, adj_x); if (state->x18 < -25.0f) { - f32 abs_x2 = adj_x; - *(u32*) &abs_x2 &= ~0x80000000; - if (abs_x2 > 0.8f) { + union { + f32 f; + u32 u; + } abs_x2; + abs_x2.f = adj_x; + abs_x2.u &= ~0x80000000; + if (abs_x2.f > 0.8f) { f32 dx = 0.01f * cosf(angle); HSD_JObjAddTranslationX(jobj_next, dx); _Toy_803062EC((s32) anim->xC, 0U, HSD_JObjGetTranslationX(jobj_next)); } { - f32 abs_y2 = adj_y; - *(u32*) &abs_y2 &= ~0x80000000; - if (abs_y2 > 0.8f) { - f32 dz = 0.01f * -sinf(angle); + union { + f32 f; + u32 u; + } abs_y2; + abs_y2.f = adj_y; + abs_y2.u &= ~0x80000000; + if (abs_y2.f > 0.8f) { + f32 sin = sinf(angle); + f32 dz = 0.01f * -sin; HSD_JObjAddTranslationZ(jobj_next, dz); _Toy_803062EC((s32) anim->xC, 2U, HSD_JObjGetTranslationZ(jobj_next)); } } } else { - f32 abs_x3 = adj_x; - *(u32*) &abs_x3 &= ~0x80000000; - if (abs_x3 > 0.8f) { + union { + f32 f; + u32 u; + } abs_x3; + abs_x3.f = adj_x; + abs_x3.u &= ~0x80000000; + if (abs_x3.f > 0.8f) { f32 dx = 0.01f * cosf(angle); HSD_JObjAddTranslationX(jobj_next, dx); _Toy_803062EC((s32) anim->xC, 0U, HSD_JObjGetTranslationX(jobj_next)); } { - f32 abs_y3 = adj_y; - *(u32*) &abs_y3 &= ~0x80000000; - if (abs_y3 > 0.8f) { + union { + f32 f; + u32 u; + } abs_y3; + abs_y3.f = adj_y; + abs_y3.u &= ~0x80000000; + if (abs_y3.f > 0.8f) { f32 dy = 0.01f * sinf(angle); HSD_JObjAddTranslationY(jobj_next, dy); _Toy_803062EC((s32) anim->xC, 1U, @@ -3845,7 +3830,10 @@ void _Toy_8030B530(HSD_GObj* arg0) } else if ((adj_x > 0.8f) || (Toy_80305C44() & 2)) { HSD_JObjAddScaleX(jobj_child, 0.01f); HSD_JObjAddScaleZ(jobj_child, 0.01f); - n2 = jobj_next->next; + { + HSD_JObj* next = jobj_next->next; + n2 = next; + } HSD_JObjAddScaleX(n2, 0.01f); HSD_JObjAddScaleZ(n2, 0.01f); _Toy_803062EC((s32) anim->xC, 4U, @@ -3928,73 +3916,106 @@ void _Toy_8030B530(HSD_GObj* arg0) } } - moved_x = 0.3f * adj_sx; - moved_y = 0.3f * adj_sy; + { + struct { + void* next; + void* next_wrap; + void* prev; + void* prev_wrap; + u8 trailing_pad[40]; + } archive_symbols; - trigger = Toy_80305B88(); - if (trigger & HSD_PAD_START) { - state->x58 = 0; - ed4->x10 = ed4->x10 + 1; - if (ed4->x10 == 6) { - ed4->x10 = 0; + PAD_STACK(192); + + moved_x = 0.3f * adj_sx; + moved_y = 0.3f * adj_sy; + + trigger = Toy_80305B88(); + if (trigger & HSD_PAD_START) { + state->x58 = 0; + ed4->x10 = ed4->x10 + 1; + if (ed4->x10 == 6) { + ed4->x10 = 0; + } + Toy_80306D70(ed4->x10); + _Toy_803075E8(ed4->x10); } - Toy_80306D70(ed4->x10); - _Toy_803075E8(ed4->x10); - } - _Toy_80308DC8(cobj); + _Toy_80308DC8(cobj); - trigger = Toy_80305B88(); + trigger = Toy_80305B88(); - if (trigger & (HSD_PAD_L | HSD_PAD_R)) { - TyDisplayData* display; - u32 trig2; - display = Toy_sbss_804D6EE0; + if (trigger & (HSD_PAD_L | HSD_PAD_R)) { + TyDisplayData* display; + u32 trig2; + display = Toy_sbss_804D6EE0; - trig2 = Toy_80305B88(); + trig2 = Toy_80305B88(); - if (trig2 & 0x441) { - s32 total; - sfxMove(); - display->selectedIdx = display->selectedIdx - 1; - if (display->selectedIdx < 0) { + if (trig2 & 0x441) { + s32 total; + sfxMove(); + display->selectedIdx = display->selectedIdx - 1; + if (display->selectedIdx < 0) { + if ((gm_IsCurrently1PMode() != 0) || + (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) + { + total = base->trophy_count; + } else { + total = *gmMainLib_GetTrophyCount(); + } + display->selectedIdx = (s16) (total - 1); + } if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - total = M2C_FIELD(base, s16*, 0x3EC); + total = base->trophy_count; } else { total = *gmMainLib_GetTrophyCount(); } - display->selectedIdx = (s16) (total - 1); - } - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) - { - total = M2C_FIELD(base, s16*, 0x3EC); - } else { - total = *gmMainLib_GetTrophyCount(); - } - if (total > 3) { - if ((display->selectedIdx - 1) < 0) { - s32 cnt; - s32 lk; - ToyListEntry* entry; - HSD_Archive* oa; - char* md; - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) - { - cnt = M2C_FIELD(base, s16*, 0x3EC); + if (total > 3) { + if ((display->selectedIdx - 1) < 0) { + s32 cnt; + s32 lk; + ToyListEntry* entry; + HSD_Archive* oa; + char* md; + if ((gm_IsCurrently1PMode() != 0) || + (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) + { + cnt = base->trophy_count; + } else { + cnt = *gmMainLib_GetTrophyCount(); + } + lk = cnt; + lk += display->selectedIdx; + entry = display->first_entry; + entry = entry->prev; + { + s32 idx = lk - 1; + s16 tid = Toy_sbss_804D6EDC[idx]; + md = Toy_8030813C(tid); + if ((oa = entry->archive) != NULL) { + lbArchive_80016EFC(oa); + entry->archive = NULL; + } + entry->archive_name = md + 4; + entry->symbol_name = md + 0x24; + entry->trophy_id = tid; + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, + &archive_symbols.prev_wrap, + entry->symbol_name, 0); + } } else { - cnt = *gmMainLib_GetTrophyCount(); - } - lk = cnt + display->selectedIdx; - entry = display->first_entry; - { - s16 tid = Toy_sbss_804D6EDC[lk - 1]; - oa = entry->archive; + ToyListEntry* entry; + HSD_Archive* oa; + char* md; + s16 tid; + entry = display->first_entry->prev; + tid = Toy_sbss_804D6EDC[display->selectedIdx - 1]; md = Toy_8030813C(tid); - if (oa != NULL) { + if ((oa = entry->archive) != NULL) { lbArchive_80016EFC(oa); entry->archive = NULL; } @@ -4002,190 +4023,175 @@ void _Toy_8030B530(HSD_GObj* arg0) entry->symbol_name = md + 0x24; entry->trophy_id = tid; entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &sp190, + entry->archive_name, &archive_symbols.prev, entry->symbol_name, 0); } - } else { - ToyListEntry* entry; - HSD_Archive* oa; - char* md; - s16 tid; - entry = display->first_entry; - tid = Toy_sbss_804D6EDC[display->selectedIdx - 1]; - oa = entry->archive; - md = Toy_8030813C(tid); - if (oa != NULL) { - lbArchive_80016EFC(oa); - entry->archive = NULL; + if (display->last_entry->archive != NULL) { + lbArchive_80016EFC(display->last_entry->archive); + display->last_entry->archive = NULL; } - entry->archive_name = md + 4; - entry->symbol_name = md + 0x24; - entry->trophy_id = tid; - entry->archive = - lbArchive_LoadSymbols(entry->archive_name, &sp18C, - entry->symbol_name, 0); - } - if (display->last_entry->archive != NULL) { - lbArchive_80016EFC(display->last_entry->archive); - display->last_entry->archive = NULL; + display->selected_entry = + display->selected_entry->prev; + display->first_entry = display->first_entry->prev; + display->last_entry = display->last_entry->prev; + } else { + display->selected_entry = + display->selected_entry->prev; } - display->selected_entry = display->selected_entry->prev; - display->first_entry = display->first_entry->prev; - display->last_entry = display->last_entry->prev; } else { - display->selected_entry = display->selected_entry->prev; - } - } else { - s32 total; - sfxMove(); - display->selectedIdx = display->selectedIdx + 1; - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) - { - total = M2C_FIELD(base, s16*, 0x3EC); - } else { - total = *gmMainLib_GetTrophyCount(); - } - if (display->selectedIdx >= total) { - display->selectedIdx = 0; - } - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) - { - total = M2C_FIELD(base, s16*, 0x3EC); - } else { - total = *gmMainLib_GetTrophyCount(); - } - if (total > 3) { - s32 cnt; + s32 total; + sfxMove(); + display->selectedIdx = display->selectedIdx + 1; if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - cnt = M2C_FIELD(base, s16*, 0x3EC); + total = base->trophy_count; } else { - cnt = *gmMainLib_GetTrophyCount(); + total = *gmMainLib_GetTrophyCount(); + } + if (display->selectedIdx >= total) { + display->selectedIdx = 0; + } + if ((gm_IsCurrently1PMode() != 0) || + (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) + { + total = base->trophy_count; + } else { + total = *gmMainLib_GetTrophyCount(); } - if ((s32) (display->selectedIdx + 1) >= cnt) { - s32 cnt2; - ToyListEntry* entry; - HSD_Archive* oa; - char* md; - s16 tid; - s32 lk; + if (total > 3) { + s32 cnt; if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - cnt2 = M2C_FIELD(base, s16*, 0x3EC); + cnt = base->trophy_count; } else { - cnt2 = *gmMainLib_GetTrophyCount(); + cnt = *gmMainLib_GetTrophyCount(); } - entry = display->last_entry->next; - lk = display->selectedIdx - cnt2; - tid = Toy_sbss_804D6EDC[lk + 1]; - oa = entry->archive; - md = Toy_8030813C(tid); - if (oa != NULL) { - lbArchive_80016EFC(oa); - entry->archive = NULL; + if ((s32) (display->selectedIdx + 1) >= cnt) { + s32 cnt2; + ToyListEntry* entry; + HSD_Archive* oa; + char* md; + s16 tid; + s32 lk; + if ((gm_IsCurrently1PMode() != 0) || + (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) + { + cnt2 = base->trophy_count; + } else { + cnt2 = *gmMainLib_GetTrophyCount(); + } + entry = display->last_entry->next; + lk = display->selectedIdx - cnt2; + tid = Toy_sbss_804D6EDC[lk + 1]; + md = Toy_8030813C(tid); + if ((oa = entry->archive) != NULL) { + lbArchive_80016EFC(oa); + entry->archive = NULL; + } + entry->archive_name = md + 4; + entry->symbol_name = md + 0x24; + entry->trophy_id = tid; + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, + &archive_symbols.next_wrap, entry->symbol_name, + 0); + } else { + ToyListEntry* entry; + HSD_Archive* oa; + char* md; + s16 tid; + entry = display->last_entry->next; + tid = Toy_sbss_804D6EDC[display->selectedIdx + 1]; + md = Toy_8030813C(tid); + if ((oa = entry->archive) != NULL) { + lbArchive_80016EFC(oa); + entry->archive = NULL; + } + entry->archive_name = md + 4; + entry->symbol_name = md + 0x24; + entry->trophy_id = tid; + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, &archive_symbols.next, + entry->symbol_name, 0); } - entry->archive_name = md + 4; - entry->symbol_name = md + 0x24; - entry->trophy_id = tid; - entry->archive = - lbArchive_LoadSymbols(entry->archive_name, &sp188, - entry->symbol_name, 0); - } else { - ToyListEntry* entry; - HSD_Archive* oa; - char* md; - s16 tid; - entry = display->last_entry->next; - tid = Toy_sbss_804D6EDC[display->selectedIdx + 1]; - oa = entry->archive; - md = Toy_8030813C(tid); - if (oa != NULL) { - lbArchive_80016EFC(oa); - entry->archive = NULL; + if (display->first_entry->archive != NULL) { + lbArchive_80016EFC(display->first_entry->archive); + display->first_entry->archive = NULL; } - entry->archive_name = md + 4; - entry->symbol_name = md + 0x24; - entry->trophy_id = tid; - entry->archive = - lbArchive_LoadSymbols(entry->archive_name, &sp184, - entry->symbol_name, 0); - } - if (display->first_entry->archive != NULL) { - lbArchive_80016EFC(display->first_entry->archive); - display->first_entry->archive = NULL; + display->selected_entry = + display->selected_entry->next; + display->first_entry = display->first_entry->next; + display->last_entry = display->last_entry->next; + } else { + display->selected_entry = + display->selected_entry->next; } - display->selected_entry = display->selected_entry->next; - display->first_entry = display->first_entry->next; - display->last_entry = display->last_entry->next; - } else { - display->selected_entry = display->selected_entry->next; } - } - _Toy_80307828(0); - _Toy_8030715C(0.0f, 0.0f); - state->x58 = 0x95E; - Toy_803087F4(display->selected_entry); - _Toy_803084A0(display->selected_entry->trophy_id); - Toy_803083D8(ed8->x30, (s32) display->selected_entry->trophy_id); - } - - trigger = Toy_80305B88(); - if (trigger & HSD_PAD_START) { - _Toy_80307828(0); - } - - { - f32 top = HSD_CObjGetTop(cobj); - f32 bottom = HSD_CObjGetBottom(cobj); - f32 right = HSD_CObjGetRight(cobj); - f32 left = HSD_CObjGetLeft(cobj); - if (HSD_PadCopyStatus[1].trigger & HSD_PAD_START) { - OSReport("top = %f, bottom = %f, right = %f, left = %f\n", top, - bottom, right, left); - return; - } - if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADUP) { - top += 0.001f; - bottom += 0.001f; - HSD_CObjSetTop(cobj, top); - HSD_CObjSetBottom(cobj, bottom); - OSReport("top = %f, bottom = %f\n", top, bottom); - return; - } - if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADDOWN) { - top -= 0.001f; - bottom -= 0.001f; - HSD_CObjSetTop(cobj, top); - HSD_CObjSetBottom(cobj, bottom); - OSReport("top = %f, bottom = %f\n", top, bottom); - return; + _Toy_80307828(0); + _Toy_8030715C(0.0f, 0.0f); + state->x58 = 0x95E; + Toy_803087F4(display->selected_entry); + _Toy_803084A0(display->selected_entry->trophy_id); + Toy_803083D8(ed8->x30, + (s32) display->selected_entry->trophy_id); } - if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADLEFT) { - f32 nr = HSD_CObjGetRight(cobj); - f32 nl = HSD_CObjGetLeft(cobj); - nr -= 0.001f; - nl -= 0.001f; - HSD_CObjSetRight(cobj, nr); - HSD_CObjSetLeft(cobj, nl); - OSReport("right = %f, left = %f\n", nr, nl); - return; + + trigger = Toy_80305B88(); + if (trigger & HSD_PAD_START) { + _Toy_80307828(0); } - if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADRIGHT) { - f32 nr = HSD_CObjGetRight(cobj); - f32 nl = HSD_CObjGetLeft(cobj); - nr += 0.001f; - nl += 0.001f; - HSD_CObjSetRight(cobj, nr); - HSD_CObjSetLeft(cobj, nl); - OSReport("right = %f, left = %f\n", nr, nl); - return; + + { + f32 top = HSD_CObjGetTop(cobj); + f32 bottom = HSD_CObjGetBottom(cobj); + f32 right = HSD_CObjGetRight(cobj); + f32 left = HSD_CObjGetLeft(cobj); + if (HSD_PadCopyStatus[1].trigger & HSD_PAD_START) { + OSReport("top = %f, bottom = %f, right = %f, left = %f\n", + top, bottom, right, left); + return; + } + if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADUP) { + top += 0.001f; + bottom += 0.001f; + HSD_CObjSetTop(cobj, top); + HSD_CObjSetBottom(cobj, bottom); + OSReport("top = %f, bottom = %f\n", top, bottom); + return; + } + if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADDOWN) { + top -= 0.001f; + bottom -= 0.001f; + HSD_CObjSetTop(cobj, top); + HSD_CObjSetBottom(cobj, bottom); + OSReport("top = %f, bottom = %f\n", top, bottom); + return; + } + if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADLEFT) { + f32 nr = HSD_CObjGetRight(cobj); + f32 nl = HSD_CObjGetLeft(cobj); + nr -= 0.001f; + nl -= 0.001f; + HSD_CObjSetRight(cobj, nr); + HSD_CObjSetLeft(cobj, nl); + OSReport("right = %f, left = %f\n", nr, nl); + return; + } + if (HSD_PadCopyStatus[1].button & HSD_PAD_DPADRIGHT) { + f32 nr = HSD_CObjGetRight(cobj); + f32 nl = HSD_CObjGetLeft(cobj); + nr += 0.001f; + nl += 0.001f; + HSD_CObjSetRight(cobj, nr); + HSD_CObjSetLeft(cobj, nl); + OSReport("right = %f, left = %f\n", nr, nl); + return; + } + _Toy_8030715C(moved_x, moved_y); } - _Toy_8030715C(moved_x, moved_y); } } } @@ -4194,22 +4200,27 @@ void _Toy_8030E110(HSD_GObj* arg0) { struct { Vec3 vec; - u8 pad[8]; + u8 pad[12]; } sp140; Vec3 sp134; Vec3 sp128; - void* spD8; - void* spD4; - void* spCC; - void* spC8; + struct { + void* next; + void* next_wrap; + u8 pad[4]; + void* prev; + void* prev_wrap; + u8 trailing_pad[0x4C]; + } archive_symbols; Toy26B8* base; - void* ed4; + ToyCameraControl* ed4; HSD_CObj* cobj; Toy6E68* state; ToyAnimState* anim; f32 abs_val, tmp; s32 sign; - f32 moved_x, moved_y; + f32 moved_y; + f32 moved_x; u32 trigger, button; TyDisplayData* display; ToyListEntry* entry; @@ -4217,15 +4228,15 @@ void _Toy_8030E110(HSD_GObj* arg0) s16 trophy_id; HSD_Archive* archive; - PAD_STACK(168); + PAD_STACK(56); base = (Toy26B8*) &_Toy_804A26B8; anim = &base->anim; state = _Toy_sbss_804D6E68; ed4 = Toy_sbss_804D6ED4; cobj = arg0->hsd_obj; - moved_x = 0.0f; moved_y = 0.0f; + moved_x = 0.0f; { f32 val; f32 abs; @@ -4387,8 +4398,7 @@ void _Toy_8030E110(HSD_GObj* arg0) trigger = Toy_80305B88(); tmp = state->x44 + (state->x40 + (state->x30 + state->x34)); - tmp += (f32) trigger; - if (tmp == 0.0f) { + if (!(tmp + (f32) trigger)) { state->x5C = state->x5C + 1; } else { state->x5C = 0; @@ -4426,44 +4436,20 @@ void _Toy_8030E110(HSD_GObj* arg0) } } - if (!state->x50 && !state->x54) { - button = HSD_PadCopyStatus[0].button; - if (button != 0) { - gm_801677E8(0); - } else { - button = HSD_PadCopyStatus[1].button; - if (button != 0) { - gm_801677E8(1); - } else { - button = HSD_PadCopyStatus[2].button; - if (button != 0) { - gm_801677E8(2); - } else { - button = HSD_PadCopyStatus[3].button; - if (button != 0) { - gm_801677E8(3); - } - } - } - } - if (button & HSD_PAD_A) { - goto pan_active; - } - _Toy_803102C4(1); - } else { - pan_active: + if (state->x50 || state->x54 || (Toy_80305C44() & HSD_PAD_A)) { _Toy_803102C4(0); + } else { + _Toy_803102C4(1); } if (state->x50 || state->x54) { moved_x = 1.0f; } - if (moved_x == 0.0f) { + if (!moved_x) { f32 sy = state->x34; - if (sy != 0.0f) { - f32 dist = state->x20; - state->x20 = (f32) - ((dist * (0.025f * sy)) - dist); + if (sy) { + state->x20 -= state->x20 * (0.025f * sy); moved_y = 1.0f; } if (state->x20 < 5.0f) { @@ -4492,19 +4478,19 @@ void _Toy_8030E110(HSD_GObj* arg0) } tmp = state->x1C; if (tmp < -360.0f) { - state->x1C = (f32) (tmp + 360.0f); + state->x1C += 360.0f; } tmp = state->x1C; if (tmp > 360.0f) { state->x1C = (f32) (tmp - 360.0f); } - M2C_FIELD(ed4, f32*, 0x18) = state->x1C; - M2C_FIELD(ed4, f32*, 0x14) = state->x18; - if ((state->x40 + state->x44) != 0.0f) { + ed4->x18 = state->x1C; + ed4->x14 = state->x18; + if (state->x40 + state->x44) { state->x24 = 0.0f; } - if ((moved_x == 0.0f) && (moved_y == 0.0f)) { + if (!moved_x && !moved_y) { trigger = Toy_80305B88(); if (trigger & (HSD_PAD_L | HSD_PAD_R)) { display = Toy_sbss_804D6EE0; @@ -4523,79 +4509,105 @@ void _Toy_8030E110(HSD_GObj* arg0) } } if ((state->x30 < 0.0f) || (Toy_80305B88() & 0x441)) { - sfxMove(); - display->selectedIdx = - (s16) (display->selectedIdx - 1); - if (display->selectedIdx < 0) { - s32 tc6; - if ((gm_IsCurrently1PMode() != 0) || - (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) - { - tc6 = base->trophy_count; - } else { - tc6 = *gmMainLib_GetTrophyCount(); - } - display->selectedIdx = (s16) (tc6 - 1); - } { - s32 tc7; + s32 total; + + sfxMove(); + display->selectedIdx = display->selectedIdx - 1; + if (display->selectedIdx < 0) { + if ((gm_IsCurrently1PMode() != 0) || + (gm_GetCurrentGameMode() == + GM_TOY_LOTTERY)) + { + total = base->trophy_count; + } else { + total = *gmMainLib_GetTrophyCount(); + } + display->selectedIdx = (s16) (total - 1); + } if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - tc7 = base->trophy_count; + total = base->trophy_count; } else { - tc7 = *gmMainLib_GetTrophyCount(); + total = *gmMainLib_GetTrophyCount(); } - if (tc7 > 3) { - s16 prev_trophy = display->selectedIdx; - if ((prev_trophy - 1) < 0) { - s32 tc8; - s32 calc_idx; + if (total > 3) { + if ((display->selectedIdx - 1) < 0) { + s32 list_idx; + s32 count; + ToyListEntry* list_entry; + HSD_Archive* old_archive; + char* model_data; + if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - tc8 = base->trophy_count; + count = base->trophy_count; } else { - tc8 = *gmMainLib_GetTrophyCount(); + count = *gmMainLib_GetTrophyCount(); } - calc_idx = tc8 + display->selectedIdx; - entry = display->first_entry->prev; - trophy_id = - Toy_sbss_804D6EDC[calc_idx - 1]; - result = Toy_8030813C(trophy_id); - archive = entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - entry->archive = NULL; + count += display->selectedIdx; + list_idx = count; + list_entry = display->first_entry; + list_entry = list_entry->prev; + { + s32 idx = list_idx - 1; + s16 trophy_id = Toy_sbss_804D6EDC[idx]; + model_data = Toy_8030813C(trophy_id); + if ((old_archive = + list_entry->archive) != NULL) + { + lbArchive_80016EFC(old_archive); + list_entry->archive = NULL; + } + list_entry->archive_name = + model_data + 4; + list_entry->symbol_name = + model_data + 0x24; + list_entry->trophy_id = trophy_id; + list_entry->archive = + lbArchive_LoadSymbols( + list_entry->archive_name, + &archive_symbols.prev_wrap, + list_entry->symbol_name, 0); } - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophy_id; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &spD8, - entry->symbol_name, 0); } else { - entry = display->first_entry->prev; - trophy_id = - Toy_sbss_804D6EDC[prev_trophy - 1]; - result = Toy_8030813C(trophy_id); - archive = entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - entry->archive = NULL; + ToyListEntry* list_entry; + HSD_Archive* old_archive; + char* model_data; + s16 trophy_id; + + list_entry = display->first_entry->prev; + trophy_id = Toy_sbss_804D6EDC + [display->selectedIdx - 1]; + model_data = Toy_8030813C(trophy_id); + if ((old_archive = list_entry->archive) != + NULL) + { + lbArchive_80016EFC(old_archive); + list_entry->archive = NULL; } - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophy_id; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &spD4, - entry->symbol_name, 0); + list_entry->archive_name = model_data + 4; + list_entry->symbol_name = + model_data + 0x24; + list_entry->trophy_id = trophy_id; + list_entry->archive = + lbArchive_LoadSymbols( + list_entry->archive_name, + &archive_symbols.prev, + list_entry->symbol_name, 0); } - archive = display->last_entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - display->last_entry->archive = NULL; + { + HSD_Archive* old_archive; + if ((old_archive = + display->last_entry->archive) != + NULL) + { + lbArchive_80016EFC(old_archive); + display->last_entry->archive = NULL; + } } display->selected_entry = display->selected_entry->prev; @@ -4610,90 +4622,113 @@ void _Toy_8030E110(HSD_GObj* arg0) } } else if ((state->x30 > 0.0f) || (Toy_80305B88() & 0x822)) { - sfxMove(); - display->selectedIdx = - (s16) (display->selectedIdx + 1); { - s32 tc2; + s32 total; + + sfxMove(); + display->selectedIdx = display->selectedIdx + 1; if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - tc2 = base->trophy_count; + total = base->trophy_count; } else { - tc2 = *gmMainLib_GetTrophyCount(); + total = *gmMainLib_GetTrophyCount(); } - if (display->selectedIdx >= tc2) { + if (display->selectedIdx >= total) { display->selectedIdx = 0; } - } - { - s32 tc3; if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - tc3 = base->trophy_count; + total = base->trophy_count; } else { - tc3 = *gmMainLib_GetTrophyCount(); + total = *gmMainLib_GetTrophyCount(); } - if (tc3 > 3) { - s32 tc4; - s16 cur_trophy; - s32 next_idx; + if (total > 3) { + s32 count; + if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - tc4 = base->trophy_count; + count = base->trophy_count; } else { - tc4 = *gmMainLib_GetTrophyCount(); + count = *gmMainLib_GetTrophyCount(); } - cur_trophy = display->selectedIdx; - next_idx = (s32) (cur_trophy + 1); - if (next_idx >= tc4) { - s32 tc5; + if ((s32) (display->selectedIdx + 1) >= count) + { + s32 list_idx; + ToyListEntry* list_entry; + HSD_Archive* old_archive; + char* model_data; + s16 trophy_id; + s32 count2; + if ((gm_IsCurrently1PMode() != 0) || (gm_GetCurrentGameMode() == GM_TOY_LOTTERY)) { - tc5 = base->trophy_count; + count2 = base->trophy_count; } else { - tc5 = *gmMainLib_GetTrophyCount(); + count2 = *gmMainLib_GetTrophyCount(); } - entry = display->last_entry->next; - trophy_id = Toy_sbss_804D6EDC - [display->selectedIdx - tc5]; - result = Toy_8030813C(trophy_id); - archive = entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - entry->archive = NULL; + list_entry = display->last_entry; + count2 = display->selectedIdx - count2; + list_idx = count2; + list_entry = list_entry->next; + trophy_id = + Toy_sbss_804D6EDC[list_idx + 1]; + model_data = Toy_8030813C(trophy_id); + if ((old_archive = list_entry->archive) != + NULL) + { + lbArchive_80016EFC(old_archive); + list_entry->archive = NULL; } - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophy_id; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &spCC, - entry->symbol_name, 0); + list_entry->archive_name = model_data + 4; + list_entry->symbol_name = + model_data + 0x24; + list_entry->trophy_id = trophy_id; + list_entry->archive = + lbArchive_LoadSymbols( + list_entry->archive_name, + &archive_symbols.next_wrap, + list_entry->symbol_name, 0); } else { - entry = display->last_entry->next; - trophy_id = Toy_sbss_804D6EDC[cur_trophy]; - result = Toy_8030813C(trophy_id); - archive = entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - entry->archive = NULL; + ToyListEntry* list_entry; + HSD_Archive* old_archive; + char* model_data; + s16 trophy_id; + + list_entry = display->last_entry->next; + trophy_id = Toy_sbss_804D6EDC + [display->selectedIdx + 1]; + model_data = Toy_8030813C(trophy_id); + if ((old_archive = list_entry->archive) != + NULL) + { + lbArchive_80016EFC(old_archive); + list_entry->archive = NULL; } - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophy_id; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &spC8, - entry->symbol_name, 0); + list_entry->archive_name = model_data + 4; + list_entry->symbol_name = + model_data + 0x24; + list_entry->trophy_id = trophy_id; + list_entry->archive = + lbArchive_LoadSymbols( + list_entry->archive_name, + &archive_symbols.next, + list_entry->symbol_name, 0); } - archive = display->first_entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - display->first_entry->archive = NULL; + { + HSD_Archive* old_archive; + if ((old_archive = + display->first_entry->archive) != + NULL) + { + lbArchive_80016EFC(old_archive); + display->first_entry->archive = NULL; + } } display->selected_entry = display->selected_entry->next; @@ -4721,22 +4756,22 @@ void _Toy_8030E110(HSD_GObj* arg0) if (trigger & HSD_PAD_START) { sfxMove(); state->x58 = 0; - M2C_FIELD(ed4, s32*, 0x10) = M2C_FIELD(ed4, s32*, 0x10) + 1; - if (M2C_FIELD(ed4, s32*, 0x10) == 6) { - M2C_FIELD(ed4, s32*, 0x10) = 0; + ed4->x10 = ed4->x10 + 1; + if (ed4->x10 == 6) { + ed4->x10 = 0; } - Toy_80306D70(M2C_FIELD(ed4, s32*, 0x10)); - _Toy_803075E8(M2C_FIELD(ed4, s32*, 0x10)); + Toy_80306D70(ed4->x10); + _Toy_803075E8(ed4->x10); } trigger = Toy_80305B88(); if (trigger & HSD_PAD_Z) { - void* ed4_2; + ToyCameraControl* ed4_2; _Toy_80307828(0); ed4_2 = Toy_sbss_804D6ED4; - M2C_FIELD(ed4_2, s32*, 0x10) = 0; - Toy_80306D70(M2C_FIELD(ed4_2, s32*, 0x10)); - _Toy_803075E8(M2C_FIELD(ed4_2, s32*, 0x10)); + ed4_2->x10 = 0; + Toy_80306D70(ed4_2->x10); + _Toy_803075E8(ed4_2->x10); anim->x11 = 0; anim->x10 = 0; anim->x0E = 1; @@ -4942,171 +4977,166 @@ void _Toy_8030FA50(void) } } -void _Toy_8030FE48(void* arg0, s32 arg1) +static inline s32 _Toy_GetTrophyTotal(Toy26B8* toy) { - u8* toy = (u8*) &_Toy_804A26B8; - u8* data = arg0; - u8* sel = toy + 0x3E8; - s32 arg1_copy = arg1; - s32 var_r26 = 0; - s16* ptr; + 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; + s32 sort_mode; + + sort_mode = toy->x195; + *ptr = &_Toy_sbss_804D6E64->key[sort_mode]; +} + +void _Toy_8030FE48(ToyDisplayList* data, s32 arg1) +{ + Toy26B8* toy = (Toy26B8*) &_Toy_804A26B8; + s16* sel = &toy->selectedIdx; + s32 sort_idx = 0; + void* sym2; s32 count; + s32 entry_count; char* result; s16 trophyIdx; void* sym; void* zero; - void* sym2; - s32 var_r7; + s16* ptr; s32 start; - ptr = &_Toy_sbss_804D6E64->key[(s8) toy[0x195]]; - *(s16*) (data + 0x154) = *(s16*) sel; - goto loop_check; - -loop_body: - if (*(s16*) (toy + 0x3EA) == *ptr) { - *(s16*) (data + 0x154) = (s16) var_r26; - *(s16*) sel = *(s16*) (data + 0x154); - goto loop_done; - } - - ptr = (s16*) ((u8*) ptr + 6); - var_r26 += 1; - -loop_check: - if (gm_IsCurrently1PMode() != 0 || - gm_GetCurrentGameMode() == GM_TOY_LOTTERY) - { - count = *(s16*) (toy + 0x3EC); - } else { - count = *gmMainLib_GetTrophyCount(); - } + _Toy_8030FE48_init_sort_key(&ptr); + data->selectedIdx = *sel; - if (var_r26 < count) { - goto loop_body; - } + while (sort_idx < _Toy_GetTrophyTotal(toy)) { + if (toy->selectedTrophyId == *ptr) { + data->selectedIdx = (s16) sort_idx; + *sel = data->selectedIdx; + break; + } -loop_done: - if (gm_IsCurrently1PMode() != 0 || - gm_GetCurrentGameMode() == GM_TOY_LOTTERY) - { - count = *(s16*) (toy + 0x3EC); - } else { - count = *gmMainLib_GetTrophyCount(); + ptr += TY_SORT_KEY_COUNT; + sort_idx += 1; } - var_r7 = count; + count = _Toy_GetTrophyTotal(toy); + entry_count = count; if (count > 3) { - *(s8*) (data + 0x157) = 3; - var_r7 = 0xD; + data->visible_count = 3; + entry_count = 0xD; } else { - *(s8*) (data + 0x157) = (s8) count; + data->visible_count = (s8) count; } - if (arg1_copy == 0) { - s32 last = var_r7 - 1; - u8* entry = data; + if (arg1 == 0) { + s32 last = entry_count - 1; + ToyListEntry* entry = data->entries; s32 i; - u8* last_entry = data + last * 0x18; - for (i = 0; i < var_r7; i++) { + ToyListEntry* last_entry; + + last_entry = &data->entries[last]; + for (i = 0; i < entry_count; i++) { if (i == 0) { - *(void**) (entry + 0x00) = last_entry; + entry->prev = last_entry; } else { - *(void**) (entry + 0x00) = (void*) (data + (i - 1) * 0x18); + entry->prev = &data->entries[i - 1]; } if (i == last) { - *(void**) (entry + 0x04) = (void*) data; + entry->next = data->entries; } else { - *(void**) (entry + 0x04) = (void*) (data + (i + 1) * 0x18); + entry->next = &data->entries[i + 1]; } - entry += 0x18; + entry++; } } zero = NULL; - for (start = 0; start < 0xD; start++) { - ((ToyListEntry*) data)[start].archive = zero; + for (start = 0; 0xD > start; start++) { + data->entries[start].archive = zero; } - if ((s8) * (u8*) (data + 0x157) == var_r7) { - s32 j = 0; - s32 offset = 0; - u8* entry = data; + if (data->visible_count == entry_count) { + s32 offset; + ToyListEntry* entry; - for (; j < (s8) * (u8*) (data + 0x157); - j += 1, offset += 2, entry += 0x18) - { - if (j == *(s16*) (data + 0x154)) { - trophyIdx = M2C_FIELD(Toy_sbss_804D6EDC, s16*, offset); + start = 0; + offset = start; + entry = data->entries; + for (; start < data->visible_count; start += 1, offset += 2, entry++) { + if (start == data->selectedIdx) { + trophyIdx = Toy_sbss_804D6EDC[offset / 2]; result = Toy_8030813C(trophyIdx); - if (*(HSD_Archive**) (entry + 0x14) != NULL) { - lbArchive_80016EFC(*(HSD_Archive**) (entry + 0x14)); - *(HSD_Archive**) (entry + 0x14) = NULL; + if (entry->archive != NULL) { + lbArchive_80016EFC(entry->archive); + entry->archive = NULL; } - *(char**) (entry + 0x08) = result + 4; - *(char**) (entry + 0x0C) = result + 0x24; - *(s16*) (entry + 0x10) = trophyIdx; - *(HSD_Archive**) (entry + 0x14) = - lbArchive_LoadSymbols(*(char**) (entry + 0x08), &sym, - *(char**) (entry + 0x0C), 0); + entry->archive_name = result + 4; + entry->symbol_name = result + 0x24; + entry->trophy_id = trophyIdx; + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, &sym, entry->symbol_name, 0); } else { - trophyIdx = M2C_FIELD(Toy_sbss_804D6EDC, s16*, offset); + trophyIdx = Toy_sbss_804D6EDC[offset / 2]; result = Toy_8030813C(trophyIdx); - if (*(HSD_Archive**) (entry + 0x14) != NULL) { - lbArchive_80016EFC(*(HSD_Archive**) (entry + 0x14)); - *(HSD_Archive**) (entry + 0x14) = NULL; + if (entry->archive != NULL) { + lbArchive_80016EFC(entry->archive); + entry->archive = NULL; } - *(char**) (entry + 0x08) = result + 4; - *(char**) (entry + 0x0C) = result + 0x24; - *(s16*) (entry + 0x10) = trophyIdx; + entry->archive_name = result + 4; + entry->symbol_name = result + 0x24; + entry->trophy_id = trophyIdx; } } - *(void**) (data + 0x140) = - (void*) (data + *(s16*) (data + 0x154) * 0x18); - *(void**) (data + 0x138) = data; - *(void**) (data + 0x13C) = - (void*) (data + ((s8) * (u8*) (data + 0x157) - 1) * 0x18); + data->selected_entry = &data->entries[data->selectedIdx]; + data->first_entry = data->entries; + data->last_entry = &data->entries[data->visible_count - 1]; return; } { - s32 startIdx; - s32 prevIdx; s32 loopCount; - u8* cur; + s32 prevIdx; + s32 startIdx; + ToyListEntry* cur; - prevIdx = *(s16*) (data + 0x154) - 1; + prevIdx = data->selectedIdx - 1; if (prevIdx < 0) { s32 tcount; if (gm_IsCurrently1PMode() != 0 || gm_GetCurrentGameMode() == GM_TOY_LOTTERY) { - tcount = *(s16*) (toy + 0x3EC); + tcount = toy->trophy_count; } else { tcount = *gmMainLib_GetTrophyCount(); } - startIdx = tcount + *(s16*) (data + 0x154); + startIdx = tcount + data->selectedIdx; startIdx -= 1; } else { startIdx = prevIdx; } - *(void**) (data + 0x140) = data; + data->selected_entry = data->entries; loopCount = 0; - *(void**) (data + 0x138) = *(void**) (*(u8**) (data + 0x140) + 0x00); - *(void**) (data + 0x13C) = *(void**) (*(u8**) (data + 0x140) + 0x04); - cur = *(u8**) (data + 0x138); + data->first_entry = data->selected_entry->prev; + data->last_entry = data->selected_entry->next; + cur = data->first_entry; - while (loopCount < (s8) * (u8*) (data + 0x157)) { + while (loopCount < data->visible_count) { s32 tcount2; if (gm_IsCurrently1PMode() != 0 || gm_GetCurrentGameMode() == GM_TOY_LOTTERY) { - tcount2 = *(s16*) (toy + 0x3EC); + tcount2 = toy->trophy_count; } else { tcount2 = *gmMainLib_GetTrophyCount(); } @@ -5115,33 +5145,33 @@ void _Toy_8030FE48(void* arg0, s32 arg1) startIdx = 0; } - if (startIdx == *(s16*) (data + 0x154)) { + if (startIdx == data->selectedIdx) { trophyIdx = Toy_sbss_804D6EDC[startIdx]; result = Toy_8030813C(trophyIdx); - if (*(HSD_Archive**) (cur + 0x14) != NULL) { - lbArchive_80016EFC(*(HSD_Archive**) (cur + 0x14)); - *(HSD_Archive**) (cur + 0x14) = NULL; + if (cur->archive != NULL) { + lbArchive_80016EFC(cur->archive); + cur->archive = NULL; } - *(char**) (cur + 0x08) = result + 4; - *(char**) (cur + 0x0C) = result + 0x24; - *(s16*) (cur + 0x10) = trophyIdx; - *(HSD_Archive**) (cur + 0x14) = lbArchive_LoadSymbols( - *(char**) (cur + 0x08), &sym2, *(char**) (cur + 0x0C), 0); + cur->archive_name = result + 4; + cur->symbol_name = result + 0x24; + cur->trophy_id = trophyIdx; + cur->archive = lbArchive_LoadSymbols(cur->archive_name, &sym2, + cur->symbol_name, 0); } else { trophyIdx = Toy_sbss_804D6EDC[startIdx]; result = Toy_8030813C(trophyIdx); - if (*(HSD_Archive**) (cur + 0x14) != NULL) { - lbArchive_80016EFC(*(HSD_Archive**) (cur + 0x14)); - *(HSD_Archive**) (cur + 0x14) = NULL; + if (cur->archive != NULL) { + lbArchive_80016EFC(cur->archive); + cur->archive = NULL; } - *(char**) (cur + 0x08) = result + 4; - *(char**) (cur + 0x0C) = result + 0x24; - *(s16*) (cur + 0x10) = trophyIdx; + cur->archive_name = result + 4; + cur->symbol_name = result + 0x24; + cur->trophy_id = trophyIdx; } - cur = *(u8**) (cur + 0x04); + cur = cur->next; startIdx += 1; loopCount += 1; } @@ -5306,7 +5336,7 @@ void Toy_80310324(void) if (var_r0 != 0) { memzero(&toy->anim, sizeof(toy->anim)); - _Toy_8030FE48(Toy_sbss_804D6EE0, 0); + _Toy_8030FE48((ToyDisplayList*) Toy_sbss_804D6EE0, 0); tg6 = (ToyGlobalsS_*) Toy_sbss_804D6EE0; Toy_803087F4(tg6->x140); diff --git a/src/melee/ty/tydisplay.c b/src/melee/ty/tydisplay.c index c602492abf..0a361dfa11 100644 --- a/src/melee/ty/tydisplay.c +++ b/src/melee/ty/tydisplay.c @@ -522,6 +522,7 @@ static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count) TyDspPos tmp1, tmp0; } temps; s32 mid = n2 / 2; + TyDspPos* p; s32 n; if (mid != 0) { @@ -535,8 +536,7 @@ static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count) if (grid->pos[n].z < grid->pos[0].z) { pivot += 1; if (pivot != n) { - TyDspPos* p = - (TyDspPos*) ((size_t) grid + + p = (TyDspPos*) ((size_t) grid + pivot * sizeof(TyDspPos) + 0x97C); temps.tmp1 = *p; *p = grid->pos[n]; diff --git a/src/melee/ty/tyfigupon.c b/src/melee/ty/tyfigupon.c index 9b8117598a..2961e119f4 100644 --- a/src/melee/ty/tyfigupon.c +++ b/src/melee/ty/tyfigupon.c @@ -596,22 +596,78 @@ static inline s32 tyFigupon_GetCoinCount(void) return gm_801623D8() / 10u; } +static inline void tyFigupon_CreateCoin(struct un_804D6EF4_t* ef4) +{ + HSD_GObj* gobj = GObj_Create(9, 9, 0); + HSD_JObj* jobj = HSD_JObjLoadJoint(HSD_ArchiveGetPublicAddress( + ef4->archive, "ToyFigurePonCoin_Top_joint")); + + HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); + GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0x3C, 0); + _tyFigupon_80314AA8(jobj, "ToyFigurePonCoin_Top_animjoint", + "ToyFigurePonCoin_Top_matanim_joint", + "ToyFigurePonCoin_Top_shapeanim_joint"); + HSD_JObjReqAnimAll(jobj, 0.0f); + HSD_JObjAnimAll(jobj); + HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); + HSD_GObj_SetupProc(gobj, _tyFigupon_80314C5C, 0); + HSD_GObj_80390CD4(gobj); +} + +static inline void tyFigupon_StoreDigits(s32* digits, s32 value) +{ + s32 i = 0; + + do { + digits[i++] = value % 10; + value /= 10; + } while (value > 0); +} + +static inline s32 tyFigupon_GetBetCount(struct un_804D6EF4_t* ef4) +{ + return ef4->x5E; +} + +static inline void tyFigupon_FinishCoinDrop(HSD_GObj* gobj, TyFiguponUD* ud, + struct un_804D6EF4_t* ef4) +{ + struct un_804D6EF4_t* ef4_2; + s32 anim = 0; + + ud->x8 = 0; + ef4->x5E = 0; + _tyFigupon_803153EC(gm_801623D8() / 10u, 3, 3, 1, 0); + _tyFigupon_803153EC((u32) ef4->x5E, 6, 2, 0, 0); + ef4_2 = _tyFigupon_804D6EF4; + if (ef4_2->x5E == 0x14) { + anim = 3; + } + if (ef4_2->x5E <= 1) { + anim = 4; + } + HSD_JObjReqAnimAll(ef4_2->jobjs[8], (f32) anim); + HSD_AObjSetRate(ef4_2->jobjs[8]->aobj, 1.0f); + HSD_JObjAnimAll(ef4_2->jobjs[8]); + GObj_RemoveUserData(gobj); + ef4->x58 = ef4->x56; + ef4->x58 += 0xE; + ef4->x5C = 2; + HSD_GObjProc_8038FE24(HSD_GObj_804D7838); +} + void _tyFigupon_80315C44(HSD_GObj* arg0) { struct un_804D6EF4_t* ef4 = _tyFigupon_804D6EF4; TyFiguponUD* ud; - struct un_804D6EF4_t* ef4_2; - HSD_JObj* jobj; - HSD_GObj* gobj; s32 total; s32 count; s32 anim; s32 i; - s32 idx; PAD_STACK(16); - if ((ud = arg0->user_data) != NULL) { + if ((ud = HSD_GObjGetUserData(arg0)) != NULL) { if (ud->x8 != 0) { if (ud->x10 == 0 && ud->x14 == 0 && ud->x18 != 0) { HSD_JObjAnimAll(ef4->jobjs[5]); @@ -628,45 +684,21 @@ void _tyFigupon_80315C44(HSD_GObj* arg0) HSD_JObjAnimAll(ef4->jobjs[3]); ud->x8 = ud->x8 - 1; if (ud->x8 % 2 == 0) { - ef4_2 = _tyFigupon_804D6EF4; - gobj = GObj_Create(9, 9, 0); - jobj = HSD_JObjLoadJoint(HSD_ArchiveGetPublicAddress( - ef4_2->archive, "ToyFigurePonCoin_Top_joint")); - HSD_GObjObject_80390A70(gobj, HSD_GObj_JObjKind, jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0x3C, 0); - _tyFigupon_80314AA8(jobj, "ToyFigurePonCoin_Top_animjoint", - "ToyFigurePonCoin_Top_matanim_joint", - "ToyFigurePonCoin_Top_shapeanim_joint"); - HSD_JObjReqAnimAll(jobj, 0.0f); - HSD_JObjAnimAll(jobj); - HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); - HSD_GObj_SetupProc(gobj, _tyFigupon_80314C5C, 0); - HSD_GObj_80390CD4(gobj); + tyFigupon_CreateCoin(_tyFigupon_804D6EF4); gm_801623FC(gm_801623D8() - 0xA); ef4->x5E = ef4->x5E - 1; - total = gm_801623D8() / 10u; + total = tyFigupon_GetCoinCount(); i = 0; ud->x18 = i; ud->x14 = i; ud->x10 = i; - do { - ((s32*) ud)[i + 4] = total % 10; - total /= 10; - i++; - } while (total > 0); - count = ef4->x5E; + tyFigupon_StoreDigits(&ud->x10, total); + count = tyFigupon_GetBetCount(ef4); i = 0; ud->x30 = i; ud->x2C = i; ud->x28 = i; - do { - { - s32 idx = i + 10; - ((s32*) ud)[idx] = count % 10; - } - count /= 10; - i++; - } while (count > 0); + tyFigupon_StoreDigits(&ud->x28, count); _tyFigupon_803153EC(gm_801623D8() / 10u, 3, 3, 1, 0); _tyFigupon_803153EC((u32) ef4->x5E, 6, 2, 0, 0); ef4 = _tyFigupon_804D6EF4; @@ -683,26 +715,7 @@ void _tyFigupon_80315C44(HSD_GObj* arg0) gm_801678F8((s32) gm_801677F0(), 0x10, 0); } } else { - anim = 0; - ud->x8 = 0; - ef4->x5E = 0; - _tyFigupon_803153EC(gm_801623D8() / 10u, 3, 3, 1, 0); - _tyFigupon_803153EC((u32) ef4->x5E, 6, 2, 0, 0); - ef4 = _tyFigupon_804D6EF4; - if (ef4->x5E == 0x14) { - anim = 3; - } - if (ef4->x5E <= 1) { - anim = 4; - } - HSD_JObjReqAnimAll(ef4->jobjs[8], (f32) anim); - HSD_AObjSetRate(ef4->jobjs[8]->aobj, 1.0f); - HSD_JObjAnimAll(ef4->jobjs[8]); - GObj_RemoveUserData(arg0); - ef4->x58 = ef4->x56; - ef4->x58 += 0xE; - ef4->x5C = 2; - HSD_GObjProc_8038FE24(HSD_GObj_804D7838); + tyFigupon_FinishCoinDrop(arg0, ud, ef4); } } else { ud = HSD_MemAlloc(sizeof(TyFiguponUD)); @@ -713,12 +726,7 @@ void _tyFigupon_80315C44(HSD_GObj* arg0) ud->x18 = i; ud->x14 = i; ud->x10 = i; - do { - idx = i + 4; - ((s32*) ud)[idx] = total % 10; - total /= 10; - i++; - } while (total > 0); + tyFigupon_StoreDigits(&ud->x10, total); _tyFigupon_803153EC(gm_801623D8() / 10u, 3, 3, 1, (s32) &ud->x10); HSD_AObjSetRate(ef4->jobjs[3]->child->u.dobj->mobj->tobj->aobj, 2.0f); diff --git a/src/sysdolphin/baselib/debugconsole_main.c b/src/sysdolphin/baselib/debugconsole_main.c index 326bdd9d24..0731bee554 100644 --- a/src/sysdolphin/baselib/debugconsole_main.c +++ b/src/sysdolphin/baselib/debugconsole_main.c @@ -52,7 +52,7 @@ struct ParticleScreenState { /* 0x40 */ s32 x40; /* 0x44 */ s32 x44; /* 0x48 */ s32 x48; - /* 0x4C */ void* x4C; + /* 0x4C */ u8* x4C; /* 0x50 */ void* x50; /* 0x54 */ u8 _pad4[0x68]; /* 0xBC */ u32 xBC; @@ -605,7 +605,7 @@ void hsd_80394314(void) sp->x20 = (u32) (sp->x3C - 0x28) / 11; sp->x1C = (u32) (sp->x40 - 0x50) / 14; #endif - sp->x4C = HSD_DebugFontAtlas; + sp->x4C = (u8*) HSD_DebugFontAtlas; sp->x50 = 0; sp->xC4 = 0; } @@ -620,7 +620,7 @@ void hsd_80394434(void* text) s32 y = sp->x8; s32 mode = sp->x0_b7; s32 interlace = sp->x0_b6; - u8* font = (u8*) sp->x4C; + u8* font = sp->x4C; s8* ptr = text; while (*ptr != 0) { @@ -648,16 +648,14 @@ void hsd_80394434(void* text) } } -// @TODO: Currently 91.32% match - needs register allocation fix void hsd_80394544(s32 col, s32 row, u32 num_cols, u32 num_rows, s32 x, s32 y, s32 xfb_buf, s32 xfb_w, s32 xfb_h, s32 xfb_stride, s32 font_data, void* color_data) { - s32 cur_x; - s32 interlace; u32 r; u32 c; s32 mode; + s32 interlace; u8 ch; mode = hsd_804CF810.x0_b7; @@ -665,25 +663,24 @@ void hsd_80394544(s32 col, s32 row, u32 num_cols, u32 num_rows, s32 x, s32 y, r = 0; while (r < num_rows) { - hsd_80393E68(col, row); + hsd_80393E68(col, row + r); y -= 14; - for (cur_x = x + (c = 0) * 11; c < num_cols; c++) { + for (c = 0; c < num_cols; c++) { ch = hsd_80394068(); if (ch == 0) { break; } if (mode != 0) { - hsd_803922FC((void*) (font_data + (ch & 0x7F) * 0x38), cur_x, - y, interlace, xfb_buf, xfb_w, xfb_stride, xfb_h, - color_data); + hsd_803922FC(&((DebugFontGlyph*) font_data)[ch & 0x7F], + x + c * 11, y, interlace, xfb_buf, xfb_w, xfb_h, + xfb_stride, color_data); } else { - hsd_803921B8((void*) (font_data + (ch & 0x7F) * 0x38), cur_x, - y, xfb_buf, xfb_w, xfb_stride, xfb_h, color_data); + hsd_803921B8(&((DebugFontGlyph*) font_data)[ch & 0x7F], + x + c * 11, y, xfb_buf, xfb_w, xfb_h, xfb_stride, + color_data); } - cur_x += 11; } - row++; r++; } } @@ -1040,41 +1037,111 @@ static void hsd_80394E8C(struct lbl_8040B904_t* node_ptr) // @TODO: Currently 94.46% match - BSS relocation and register allocation // differences remain +static inline const char* hsd_80394F48_get_first_entry(EventData* data) +{ + return data->entries[0]; +} + +static inline size_t hsd_80394F48_entry_length(s32 index, EventData* data) +{ + return strlen(data->entries[index]); +} + +static inline void hsd_80394F48_set_base_color(void** color) +{ + *color = &lbl_8040AB00; +} + +static inline s32 hsd_80394F48_get_x4(const s32* x4) +{ + return *x4; +} + +static inline s32 hsd_80394F48_get_x40(const s32* px40) +{ + return *px40; +} + +static inline s32 hsd_80394F48_get_x8(const s32* px8) +{ + return *px8; +} + +static inline struct lbl_8040AB00_t* +hsd_80394F48_get_highlight_color(struct lbl_8040AB00_t* base_color) +{ + return base_color + 1; +} + +static inline void hsd_80394F48_set_col_start(const s32* pxC8, s32* col_start) +{ + *col_start = *pxC8; +} + +static inline s32 hsd_80394F48_get_x_base(s32 col_start) +{ + return col_start * 11 + 0x14; +} + +static inline void** hsd_80394F48_get_x50_ptr(struct ParticleScreenState* sp) +{ + return &sp->x50; +} + +static inline s32* hsd_80394F48_get_x8_ptr(struct ParticleScreenState* sp) +{ + return &sp->x8; +} + +static inline s32* hsd_80394F48_get_xCC_ptr(struct ParticleScreenState* sp) +{ + return &sp->xCC; +} + +static inline void hsd_80394F48_init(void* data, s32* num_entries, + void*** px50, s32** pxC8, s32** pxCC) +{ + struct ParticleScreenState* sp = &hsd_804CF810; + EventData* dp = data; + PAD_STACK(64); + + *num_entries = strlen(hsd_80394F48_get_first_entry(dp)); + *px50 = hsd_80394F48_get_x50_ptr(sp); + *pxC8 = &sp->xC8; + *pxCC = hsd_80394F48_get_xCC_ptr(sp); +} + void hsd_80394F48(void* data) { - u8* base_color = (u8*) &lbl_8040AB00; + struct lbl_8040AB00_t* base_color = &lbl_8040AB00; struct ParticleScreenState* sp = &hsd_804CF810; EventData* dp = data; s32 num_entries; void** px50; - s32* pxC8; + s32 cur_row; s32* pxCC; s32* px4; s32* px40; s32* px8; s32 col_start; - s32 row_start; - void* hi_color; + struct lbl_8040AB00_t* hi_color; s32 x_base; - s32 cur_row; + s32* pxC8; s32 i; s32 b6; - PAD_STACK(64); + hsd_80394F48_init(data, &num_entries, &px50, &pxC8, &pxCC); - num_entries = strlen(dp->entries[0]); - px50 = &sp->x50; - pxC8 = &sp->xC8; - pxCC = &sp->xCC; px4 = &sp->x4; px40 = &sp->x40; - px8 = &sp->x8; - *px50 = base_color; - col_start = *pxC8; - row_start = *pxCC; - - *px4 = col_start * 11 + 0x14; - *px8 = (*px40 - 0x28) - (row_start + 1) * 14; + px8 = hsd_80394F48_get_x8_ptr(sp); + hsd_80394F48_set_base_color(px50); + hsd_80394F48_set_col_start(pxC8, &col_start); + { + cur_row = *pxCC; + *px4 = col_start * 11 + 0x14; + *px8 = (*px40 - 0x28) - (cur_row + 1) * 14; + } b6 = sp->x0_b6; if (sp->x0_b7 != 0) { @@ -1110,9 +1177,9 @@ void hsd_80394F48(void* data) } *px4 += 11; - x_base = col_start * 11 + 0x14; - hi_color = base_color + 0x20; - cur_row = row_start - 1; + x_base = hsd_80394F48_get_x_base(col_start); + hi_color = hsd_80394F48_get_highlight_color(base_color); + cur_row -= 1; for (i = 0; dp->entries[i] != 0; i++) { *px4 = x_base; @@ -1130,14 +1197,14 @@ void hsd_80394F48(void* data) if (i == dp->index) { *px50 = hi_color; } else { - *px50 = base_color; + hsd_80394F48_set_base_color(px50); } *px4 += 11; hsd_80394434(dp->entries[i]); - *px4 += strlen(dp->entries[i]) * 11; - *px50 = base_color; + *px4 += hsd_80394F48_entry_length(i, dp) * 11; + hsd_80394F48_set_base_color(px50); b6 = sp->x0_b6; if (sp->x0_b7 != 0) { @@ -1149,7 +1216,7 @@ void hsd_80394F48(void* data) } } - *px50 = base_color; + hsd_80394F48_set_base_color(px50); *px4 = x_base; *px8 = (*px40 - 0x28) - (cur_row + 1) * 14; @@ -1158,14 +1225,16 @@ void hsd_80394F48(void* data) hsd_803922FC(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, - (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); + s32 x = hsd_80394F48_get_x4(px4); + hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, x, + hsd_80394F48_get_x8(px8), (&sp->x24)[sp->x34], sp->x3C, + *px40, sp->x44, *px50); } { - s32 j = 0; + x_base = 0; *px4 += 11; - while (j < num_entries) { + while (x_base < num_entries) { b6 = sp->x0_b6; if (sp->x0_b7 != 0) { hsd_803922FC(((ParticleFontData*) sp->x4C)->x9D8, *px4, *px8, @@ -1176,7 +1245,7 @@ void hsd_80394F48(void* data) (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } - j++; + x_base++; *px4 += 11; } } @@ -1187,7 +1256,8 @@ void hsd_80394F48(void* data) (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, - (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); + (&sp->x24)[sp->x34], sp->x3C, hsd_80394F48_get_x40(px40), + sp->x44, *px50); } *px4 += 11; @@ -1363,12 +1433,12 @@ void hsd_803957C0(void* input) b6 = draw_sp->x0_b6; if (draw_sp->x0_b7) { - hsd_803922FC((void*) ((u8*) draw_sp->x4C + (ch & 0x7F) * 0x38), + hsd_803922FC((void*) (draw_sp->x4C + (ch & 0x7F) * 0x38), hsd_804CF810.x4, hsd_804CF810.x8, b6, (&hsd_804CF810.x24)[draw_sp->x34], draw_sp->x3C, hsd_804CF810.x40, hsd_804CF810.x44, hsd_804CF810.x50); } else { - hsd_803921B8((void*) ((u8*) draw_sp->x4C + (ch & 0x7F) * 0x38), + hsd_803921B8((void*) (draw_sp->x4C + (ch & 0x7F) * 0x38), hsd_804CF810.x4, hsd_804CF810.x8, (&hsd_804CF810.x24)[draw_sp->x34], draw_sp->x3C, hsd_804CF810.x40, hsd_804CF810.x44, hsd_804CF810.x50); @@ -1998,18 +2068,31 @@ struct lbl_8040BA5C_t lbl_8040BBE8 = { static char* lbl_804D62F4 = "+--------------------------+"; static char* lbl_804D62F8 = "| INPUT ADDRESS : 8%07X |"; +static inline void hsd_80396884_draw_char(s8 ch, s32 b6) +{ + hsd_803922FC(hsd_804CF810.x4C + (ch & 0x7F) * 0x38, hsd_804CF810.x4, + hsd_804CF810.x8, b6, (&hsd_804CF810.x24)[hsd_804CF810.x34], + hsd_804CF810.x3C, hsd_804CF810.x40, hsd_804CF810.x44, + hsd_804CF810.x50); +} + +static inline void* hsd_80396884_get_x50(void) +{ + return hsd_804CF810.x50; +} + void hsd_80396884(void) { - char buf[32]; - s32 b6; + void* saved; s32 x_base; + s32 b6; u8 ch; - void* saved; + char buf[32]; PAD_STACK(28); x_base = (hsd_804CF810.x20 - 30) / 2; sprintf(buf, lbl_804D62F8, lbl_8040BC3C.x10 & 0x0FFFFFFF); - saved = hsd_804CF810.x50; + saved = hsd_80396884_get_x50(); hsd_804CF810.x50 = &lbl_8040AB00; hsd_804CF810.x4 = x_base * 11 + 20; hsd_804CF810.x8 = hsd_804CF810.x40 - 82; @@ -2020,19 +2103,15 @@ void hsd_80396884(void) hsd_804CF810.x4 = x_base * 11 + 20; hsd_804CF810.x8 = hsd_804CF810.x40 - 54; hsd_80394434(lbl_804D62F4); - hsd_804CF810.x4 = (lbl_8040BC3C.x14 + 19 + x_base) * 11 + 20; + hsd_804CF810.x4 = (lbl_8040BC3C.x14 + (19 + x_base)) * 11 + 20; hsd_804CF810.x8 = hsd_804CF810.x40 - 68; hsd_804CF810.x50 = &lbl_8040AB20; b6 = hsd_804CF810.x0_b6; ch = *(&buf[19] + lbl_8040BC3C.x14); if (hsd_804CF810.x0_b7) { - void* bitmap = (void*) ((u8*) hsd_804CF810.x4C + (ch & 0x7F) * 0x38); - s32 x = hsd_804CF810.x4; - s32 dst = (&hsd_804CF810.x24)[hsd_804CF810.x34]; - hsd_803922FC(bitmap, x, hsd_804CF810.x8, b6, dst, hsd_804CF810.x3C, - hsd_804CF810.x40, hsd_804CF810.x44, hsd_804CF810.x50); + hsd_80396884_draw_char(ch, b6); } else { - void* bitmap = (void*) ((u8*) hsd_804CF810.x4C + (ch & 0x7F) * 0x38); + u8* bitmap = hsd_804CF810.x4C + (ch & 0x7F) * 0x38; s32 x = hsd_804CF810.x4; s32 dst = (&hsd_804CF810.x24)[hsd_804CF810.x34]; hsd_803921B8(bitmap, x, hsd_804CF810.x8, dst, hsd_804CF810.x3C, diff --git a/src/sysdolphin/baselib/generator.c b/src/sysdolphin/baselib/generator.c index a82693bf88..6c48a94985 100644 --- a/src/sysdolphin/baselib/generator.c +++ b/src/sysdolphin/baselib/generator.c @@ -9,6 +9,7 @@ #include #include #include +#include /* 4D78F0 */ HSD_CObj* psCamera; /* 4D0E5C */ @@ -360,16 +361,16 @@ HSD_Generator* hsd_8039D9C8(void) // switch case logic, Newton-Raphson sqrt inlining, trig matrix layout f32 hsd_8039DAD4(HSD_Generator* gen) { - Mtx rot_mtx; + f32 radius; Vec3 vel_out; - Vec3 tmpvec; - Vec3 emit_pos; Vec3 vel_copy; + Vec3 emit_pos; + Vec3 cross1; + Vec3 tmpvec; + 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; @@ -379,7 +380,6 @@ f32 hsd_8039DAD4(HSD_Generator* gen) f32 sin_el; f32 angle_step; f32 cur_angle; - f32 radius; f32 cone_angle; f32 elevation; f32 tmp; @@ -453,15 +453,9 @@ f32 hsd_8039DAD4(HSD_Generator* gen) /* Billboard orientation: kind & 0x10000 */ if (gen->kind & 0x10000) { HSD_ASSERT(677, psCamera); - { - HSD_CObj* cobj = psCamera; - void* view = *(void**) ((u8*) cobj + 0x24); - look_dir.x = *(f32*) ((u8*) view + 0x0C) - gen->pos.x; - view = *(void**) ((u8*) cobj + 0x24); - look_dir.y = *(f32*) ((u8*) view + 0x10) - gen->pos.y; - view = *(void**) ((u8*) cobj + 0x24); - look_dir.z = *(f32*) ((u8*) view + 0x14) - gen->pos.z; - } + look_dir.x = psCamera->eyepos->pos.x - gen->pos.x; + look_dir.y = psCamera->eyepos->pos.y - gen->pos.y; + look_dir.z = psCamera->eyepos->pos.z - gen->pos.z; PSVECNormalize(&look_dir, &look_dir); HSD_CObjGetUpVector(psCamera, &cam_up); PSVECNormalize(&cam_up, &cam_up); @@ -481,6 +475,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) /* Velocity-based rotation */ if ((gen->type & 0xF) != 1 && vel_mag_sq > 0.0F) { + Vec3 vel_norm; vel_norm.x = gen->vel.x; vel_norm.y = gen->vel.y; vel_norm.z = gen->vel.z; @@ -634,12 +629,16 @@ f32 hsd_8039DAD4(HSD_Generator* gen) cone_angle = (f32) (M_PI - gen->angle); } } else { - cone_angle = (f32) (M_PI - atan2f(gen->aux.cone.height, - sin_az)) - - gen->angle; + f64 cone_angle_d = + M_PI - atan2f(gen->aux.cone.height, sin_az) - + gen->angle; + cone_angle = (f32) cone_angle_d; } } else { - cur_angle = gen->aux.cone.minAngle; + { + f32 min_angle = gen->aux.cone.minAngle; + cur_angle = min_angle; + } { f32 rnd = HSD_Randf(); f32 range = gen->aux.cone.maxAngle - cur_angle; @@ -656,9 +655,10 @@ f32 hsd_8039DAD4(HSD_Generator* gen) cone_angle = (f32) (M_PI + gen->angle); } } else { - cone_angle = gen->angle + - (f32) (M_PI - atan2f(gen->aux.cone.height, - sin_az)); + f64 cone_angle_d = + gen->angle + + (M_PI - atan2f(gen->aux.cone.height, sin_az)); + cone_angle = (f32) cone_angle_d; } } break; @@ -671,8 +671,8 @@ f32 hsd_8039DAD4(HSD_Generator* gen) { f32 rnd = HSD_Randf(); f32 range = gen->aux.disc.maxAngle - cur_angle; - cone_angle = (f32) (M_PI + gen->angle); cur_angle = range * rnd + cur_angle; + cone_angle = (f32) (M_PI + gen->angle); } } break; @@ -854,7 +854,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 - r0 * c2 * a2; + f32 t2 = 1.0F - c2 * r0 * a2; if (rnd > t2) { emit_pos.y = emit_pos.y > 0.5F ? 1.0F : 0.0F; } else { diff --git a/src/sysdolphin/baselib/hsd_3915.c b/src/sysdolphin/baselib/hsd_3915.c index b3aa27b586..bdd7506790 100644 --- a/src/sysdolphin/baselib/hsd_3915.c +++ b/src/sysdolphin/baselib/hsd_3915.c @@ -387,16 +387,15 @@ static inline void hsd_80391F28_calc_tick4_y(f32 perp_y, f32* tick4_y) void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) { f32 tick6_x; - f32 dx; - f32 dy; + f32 step_y; + f32 tick6_y; f32 perp_x; f32 perp_y; - f32 tick6_y; + f32 dy; f32 tick4_x; + f32 dx; f32 tick4_y; - f32 step_y; f32 step_x; - f32 len; s32 i; u8 r, g, b, a; @@ -409,12 +408,12 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) GXWGFifo.f32 = x1; i = 0; - a = color->a; GXWGFifo.f32 = y1; - - b = color->b; - g = color->g; r = color->r; + GXWGFifo.u8 = r; + g = color->g; + b = color->b; + a = color->a; tick6_y = 6.0F * perp_y; { @@ -424,7 +423,6 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) tick4_x = 4.0F * perp_x; hsd_80391F28_calc_tick4_y(perp_y, &tick4_y); - GXWGFifo.u8 = r; GXWGFifo.u8 = g; GXWGFifo.u8 = b; GXWGFifo.u8 = a; @@ -690,7 +688,7 @@ static const u32 lbl_804DE8E0 = 0xFFFFFFFF; typedef struct { s32 count; - u32 color; + GXColor color; } DispBar; typedef struct _DispItem { @@ -705,7 +703,47 @@ typedef struct _DispItem { typedef DispItem* (*DispCallback)(void*); -// @TODO: Currently 89.78% match - needs minor control flow and register fixes +static inline s32 count_bar_units(DispItem* item) +{ + s32 total = 0; + s32 count; + + while ((count = item->content.bars[0].count) > 0) { + total += count; + item = (DispItem*) ((DispBar*) item + 1); + } + return total; +} + +static inline s32 count_text_chars(char* text) +{ + s32 count; + s32 i; + s32 len; + + if (text == NULL) { + return 0; + } + count = 0; + len = strlen(text); + i = count; + while (i < len) { + if ((s8) text[i] != '\\') { + count++; + } else { + i++; + switch ((s8) text[i]) { + case 'c': + case 'C': + i += 6; + break; + } + } + i++; + } + return count; +} + void hsd_8039254C(void) { static GXColor lbl_804D6080 = { 0x40, 0x40, 0x40 }; @@ -714,12 +752,7 @@ void hsd_8039254C(void) f32 bar_x; f32 t2; GXColor default_col; - GXColor bg_col0; - GXColor bg_col1; - GXColor txt_col; - GXColor bg_col2; - GXColor bg_col3; - GXColor bar_col; + DispItem* bar_draw_ptr; s32 char_count; s32 count; GXColor* p_bg_col0; @@ -732,12 +765,8 @@ void hsd_8039254C(void) s32 first; HSD_SList* event_node; - p_bar_col = &bar_col; - p_bg_col3 = &bg_col3; - p_bg_col2 = &bg_col2; - p_bg_col1 = &bg_col1; - p_txt_col = &txt_col; - p_bg_col0 = &bg_col0; + PAD_STACK(4); + col_pos = 60; first = 1; line = 1.0F; @@ -752,6 +781,8 @@ void hsd_8039254C(void) while (item != NULL) { if (first != 0) { + GXColor bg_col0; + p_bg_col0 = &bg_col0; if (lbl_804D6080.a != 0) { hsd_80391A04(10.0F, 10.0F, 6); bg_col0 = lbl_804D6080; @@ -760,37 +791,12 @@ void hsd_8039254C(void) first = 0; } switch (item->type) { - case 0: -#ifdef MUST_MATCH - if ((&item->content) == NULL) { - char_count = 0; - } else -#endif - { - char_count = 0; - { - s32 j = 0; - s32 len = strlen(item->content.text); - char_count = j; - while (j < len) { - if ((s8) item->content.text[j] != '\\') { - char_count++; - } else { - j++; - { - char* tmp = item->content.text; - switch ((s8) tmp[j]) { - case 'c': - case 'C': - j += 6; - break; - } - } - } - j++; - } - } - } + case 0: { + GXColor bg_col1; + GXColor txt_col; + p_bg_col1 = &bg_col1; + p_txt_col = &txt_col; + char_count = count_text_chars(item->content.text); if (col_pos + char_count > 60) { line -= 1.0F; col_pos = 0; @@ -806,7 +812,10 @@ void hsd_8039254C(void) (f32) (col_pos * 10), 10.0F * line); col_pos = col_pos + (2 + char_count); break; - case 2: + } + case 2: { + GXColor bg_col2; + p_bg_col2 = &bg_col2; if (col_pos != 0) { line = (f32) ((f64) line - 0.5); if (lbl_804D6080.a != 0) { @@ -820,18 +829,13 @@ void hsd_8039254C(void) hsd_80391E18(item->content.gradient, 0.0F, t2, 600.0F, t2); col_pos = 60; break; + } case 1: { - DispItem* bar_ptr; - DispItem* bar_draw_ptr; - - bar_ptr = item; - char_count = 0; - { - while ((count = bar_ptr->content.bars[0].count) > 0) { - char_count += count; - bar_ptr = (DispItem*) ((DispBar*) bar_ptr + 1); - } - } + GXColor bg_col3; + GXColor bar_col; + p_bar_col = &bar_col; + p_bg_col3 = &bg_col3; + char_count = count_bar_units(item); if (char_count > 0) { if (col_pos != 0) { line = (f32) ((f64) line - 0.5); @@ -851,10 +855,8 @@ void hsd_8039254C(void) { f32 prev_x; prev_x = bar_x; - bar_col = - *(GXColor*) &bar_draw_ptr->content.bars[0] - .color; bar_x += (600.0F / (f32) char_count) * (f32) count; + bar_col = bar_draw_ptr->content.bars[0].color; hsd_80391F28( p_bar_col, prev_x, bar_y, bar_x, bar_y, (f32) bar_draw_ptr->content.bars[0].count); diff --git a/src/sysdolphin/baselib/hsd_3A94.c b/src/sysdolphin/baselib/hsd_3A94.c index 6b19af58a0..816d1f96a1 100644 --- a/src/sysdolphin/baselib/hsd_3A94.c +++ b/src/sysdolphin/baselib/hsd_3A94.c @@ -4682,151 +4682,140 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) static inline s32 fn_803B1338_queue_write(CardState* state, s32 logical, s32 phys, void* data, s32 size, - s32 file_id) + s32 file_id, s32* cmd0, s32* cmd1) { - s32 cmd[10]; s32 ofs = fn_803ACBE8(state, logical); - s32 init_cmd[10]; s32 result; if (logical == 0) { if (phys != 0) { return -0x101; } - init_cmd[0] = 2; - init_cmd[1] = (s32) state; - init_cmd[4] = 0; - init_cmd[5] = 0; - init_cmd[6] = 0; - init_cmd[8] = 0; - init_cmd[7] = ofs; - fn_803AC168(init_cmd); - } - cmd[0] = 1; - cmd[1] = (s32) state; - cmd[3] = logical; - cmd[4] = phys; - cmd[5] = 0; - cmd[6] = (s32) data; - cmd[8] = size; - cmd[7] = ofs; - cmd[2] = file_id; - result = fn_803AC168(cmd); + cmd0[0] = 2; + cmd0[1] = (s32) state; + cmd0[4] = 0; + cmd0[5] = 0; + cmd0[6] = 0; + cmd0[8] = 0; + cmd0[7] = ofs; + fn_803AC168(cmd0); + } + cmd1[0] = 1; + cmd1[1] = (s32) state; + cmd1[3] = logical; + cmd1[4] = phys; + cmd1[5] = 0; + cmd1[6] = (s32) data; + cmd1[8] = size; + cmd1[7] = ofs; + cmd1[2] = file_id; + result = fn_803AC168(cmd1); return result; } +static inline u8* fn_803B1338_data_at(u8* file_payload, s32 offset) +{ + return file_payload + offset; +} + +static inline s32 fn_803B1338_data_size(CardState* state) +{ + return state->x8 - 0x20; +} + s32 fn_803B1338(CardState* state, s32 arg1) { - s32 result; - s32 offset; - s32 logical; - s32 max_redun; - s32 file_blocks; - s32 file_id; - s32 i; - s32 phys; - u8* fdata; - PAD_STACK(128); - - max_redun = 0; - phys = 1; - logical = 1; - - if ((s32) fn_803AC634(state, 0) != 0) { - s32 hdr_offset; - u32 hdr_base; - u32 sector_size; - file_blocks = fn_803AC634(state, 0); - offset = 0; - sector_size = state->x8; - hdr_base = state->x24 + 0x30; - hdr_offset = hdr_base % sector_size; - if (arg1 != 0) { - fdata = state->x70[0].ptr; - if (fdata == NULL) { - s32 ofs0 = sector_size * - ((hdr_base + sector_size - 1) / sector_size - 1); - s32 cmd[10]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs0; - fn_803AC168(cmd); - { - s32 cmd2[10]; - cmd2[0] = 1; + PAD_STACK(72); + { + s32 cmd0[10]; + s32 cmd1[10]; + s32 cmd2[10]; + s32 cmd3[10]; + s32 cmd4[10]; + s32 cmd5[10]; + s32 cmd6[10]; + s32 cmd7[10]; + s32 cmd8[10]; + s32 cmd9[10]; + s32 cmd10[10]; + s32 cmd11[10]; + s32 cmd12[10]; + s32 cmd13[10]; + s32 cmd14[10]; + s32 cmd15[10]; + s32 cmd16[10]; + s32 cmd17[10]; + s32 result; + s32 logical; + s32 max_redun; + s32 file_blocks; + s32 file_id; + s32 phys; + u8* fdata; + PAD_STACK(32); + + max_redun = 0; + phys = 1; + logical = 1; + + if ((s32) fn_803AC634(state, 0) != 0) { + s32 i; + s32 offset; + s32 hdr_offset; + u32 hdr_base; + u32 sector_size; + file_blocks = fn_803AC634(state, 0); + offset = 0; + sector_size = state->x8; + hdr_base = state->x24 + 0x30; + hdr_offset = hdr_base % sector_size; + if (arg1 != 0) { + fdata = state->x70[0].ptr; + if (fdata == NULL) { + s32 ofs0 = + sector_size * + ((hdr_base + sector_size - 1) / sector_size - 1); + cmd0[0] = 2; + cmd0[1] = (s32) state; + cmd0[4] = 0; + cmd0[5] = 0; + cmd0[6] = 0; + cmd0[8] = 0; + cmd0[7] = ofs0; + fn_803AC168(cmd0); + cmd1[0] = 1; + cmd1[1] = (s32) state; + cmd1[3] = 0; + cmd1[4] = 0; + cmd1[5] = 0; + cmd1[6] = 0; + cmd1[8] = 0; + cmd1[7] = ofs0; + cmd1[2] = 0; + result = fn_803AC168(cmd1); + } else { + s32 ofs0 = + sector_size * + ((hdr_base + sector_size - 1) / sector_size - 1); + cmd2[0] = 2; cmd2[1] = (s32) state; - cmd2[3] = 0; cmd2[4] = 0; cmd2[5] = 0; cmd2[6] = 0; cmd2[8] = 0; cmd2[7] = ofs0; - cmd2[2] = 0; - result = fn_803AC168(cmd2); - } - } else { - s32 ofs0 = sector_size * - ((hdr_base + sector_size - 1) / sector_size - 1); - s32 cmd[10]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs0; - fn_803AC168(cmd); - { - s32 cmd2[10]; - cmd2[0] = 1; - cmd2[1] = (s32) state; - cmd2[3] = 0; - cmd2[4] = 0; - cmd2[5] = 0; - cmd2[6] = (s32) fdata; - cmd2[8] = sector_size - hdr_offset - 0x20; - cmd2[7] = ofs0; - cmd2[2] = 0; - result = fn_803AC168(cmd2); - } - offset = state->x8 - hdr_offset - 0x20; - } - if (result < 0) { - return result; - } - } else { - fdata = state->x70[0].ptr; - if (fdata == NULL) { - result = fn_803ACFC0(state, 0, 0, 0, NULL, 0, 0); - } else { - result = fn_803ACFC0(state, 0, 0, 0, fdata, - sector_size - hdr_offset - 0x20, 0); - offset = state->x8 - hdr_offset - 0x20; - } - if (result < 0 && result != -0x105) { - state->x170[0] = -0x7FFF; - state->x270[0] = 0; - return result; - } - } - - for (i = 1; i < file_blocks; i++) { - if (arg1 != 0) { - fdata = state->x70[0].ptr; - if (fdata == NULL) { - result = fn_803B1338_queue_write(state, logical, phys, - NULL, 0, 0); - } else { - u8* wdata = fdata + offset; - s32 chunk = state->x8 - 0x20; - result = fn_803B1338_queue_write(state, logical, phys, - wdata, chunk, 0); - offset += state->x8; - offset -= 0x20; + fn_803AC168(cmd2); + cmd3[0] = 1; + cmd3[1] = (s32) state; + cmd3[3] = 0; + cmd3[4] = 0; + cmd3[5] = 0; + cmd3[6] = (s32) fdata; + cmd3[8] = sector_size - hdr_offset - 0x20; + cmd3[7] = ofs0; + cmd3[2] = 0; + result = fn_803AC168(cmd3); + offset = state->x8 - hdr_offset - 0x20; } if (result < 0) { return result; @@ -4834,60 +4823,48 @@ s32 fn_803B1338(CardState* state, s32 arg1) } else { fdata = state->x70[0].ptr; if (fdata == NULL) { - result = - CARD_WRITE_BLOCK(state, logical, phys, 0, NULL, 0, 0); + result = fn_803ACFC0(state, 0, 0, 0, NULL, 0, 0); } else { - result = - CARD_WRITE_BLOCK(state, logical, phys, 0, - fdata + offset, state->x8 - 0x20, 0); - offset += state->x8; - offset -= 0x20; + result = fn_803ACFC0(state, 0, 0, 0, fdata, + sector_size - hdr_offset - 0x20, 0); + offset = state->x8 - hdr_offset - 0x20; } - if (result < 0) { - state->x170[logical] = -0x7FFF; - state->x270[logical] = 0; + if (result < 0 && result != -0x105) { + state->x170[0] = -0x7FFF; + state->x270[0] = 0; return result; } - state->x170[logical] = phys; - state->x270[logical] = 0; } - logical++; - phys++; - } - } - for (file_id = 1; file_id < 9; file_id++) { - s32 j; - file_blocks = fn_803AC634(state, file_id); - offset = 0; - if (file_blocks > 0) { - for (j = 0; j < file_blocks; j++) { + for (i = 1; i < file_blocks; i++) { if (arg1 != 0) { - fdata = state->x70[file_id].ptr; + fdata = state->x70[0].ptr; if (fdata == NULL) { - result = fn_803B1338_queue_write(state, logical, phys, - NULL, 0, file_id); + result = fn_803B1338_queue_write( + state, logical, phys, NULL, 0, 0, cmd4, cmd5); } else { - u8* wdata = fdata + offset; - s32 chunk = state->x8 - 0x20; + 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); - offset += state->x8; + state, logical, phys, wdata, chunk, 0, cmd6, cmd7); + offset = state->x8 + offset; offset -= 0x20; } if (result < 0) { return result; } } else { - fdata = state->x70[file_id].ptr; + fdata = state->x70[0].ptr; if (fdata == NULL) { - result = fn_803ACFC0(state, logical, phys, 0, NULL, 0, - file_id); + result = CARD_WRITE_BLOCK(state, logical, phys, 0, + NULL, 0, 0); } else { - result = fn_803ACFC0(state, logical, phys, 0, - fdata + offset, state->x8 - 0x20, - file_id); - offset += state->x8; + result = CARD_WRITE_BLOCK(state, logical, phys, 0, + fdata + offset, + state->x8 - 0x20, 0); + offset = state->x8 + offset; offset -= 0x20; } if (result < 0) { @@ -4901,67 +4878,28 @@ s32 fn_803B1338(CardState* state, s32 arg1) logical++; phys++; } - switch (state->x28[file_id]) { - case 0: - break; - case 1: - if (max_redun < file_blocks) { - max_redun = file_blocks; - } - break; - case 2: - if (max_redun < 1) { - max_redun = 1; - } - break; - case 3: - break; - } } - } - - for (i = 0; i < max_redun; i++) { - if (arg1 != 0) { - result = fn_803B1338_queue_write(state, logical, 0xFFFF, NULL, 0, - file_id); - if (result < 0) { - return result; - } - } else { - result = fn_803ACFC0(state, logical, 0xFFFF, 0, NULL, 0, file_id); - state->x170[logical] = -0x7FFF; - state->x270[logical] = 0; - if (result < 0) { - return result; - } - } - phys++; - logical++; - } - phys = 1; - if ((s32) fn_803AC634(state, 0) != 0) { - phys = fn_803AC634(state, 0); - } - for (file_id = 1; file_id < 9; file_id++) { - s32 k; - 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++) { + for (file_id = 1; file_id < 9; file_id++) { + s32 j; + s32 offset; + file_blocks = fn_803AC634(state, file_id); + offset = 0; + if (file_blocks > 0) { + for (j = 0; j < file_blocks; j++) { if (arg1 != 0) { fdata = state->x70[file_id].ptr; if (fdata == NULL) { result = fn_803B1338_queue_write( - state, logical, phys, NULL, 0, file_id); + state, logical, phys, NULL, 0, file_id, cmd8, + cmd9); } else { - u8* wdata = fdata + offset; - s32 chunk = state->x8 - 0x20; + u8* wdata = fn_803B1338_data_at(fdata, offset); + s32 chunk = fn_803B1338_data_size(state); result = fn_803B1338_queue_write( - state, logical, phys, wdata, chunk, file_id); - offset += state->x8; + state, logical, phys, wdata, chunk, file_id, + cmd10, cmd11); + offset = state->x8 + offset; offset -= 0x20; } if (result < 0) { @@ -4970,15 +4908,13 @@ s32 fn_803B1338(CardState* state, s32 arg1) } else { fdata = state->x70[file_id].ptr; if (fdata == NULL) { - s32 write_result = fn_803ACFC0( - state, logical, phys, 0, NULL, 0, file_id); - result = write_result; + result = fn_803ACFC0(state, logical, phys, 0, NULL, + 0, file_id); } else { - s32 write_result = fn_803ACFC0( - state, logical, phys, 0, fdata + offset, - state->x8 - 0x20, file_id); - result = write_result; - offset += state->x8; + result = fn_803ACFC0(state, logical, phys, 0, + fdata + offset, + state->x8 - 0x20, file_id); + offset = state->x8 + offset; offset -= 0x20; } if (result < 0) { @@ -4992,17 +4928,118 @@ s32 fn_803B1338(CardState* state, s32 arg1) logical++; phys++; } - break; - case 1: - case 2: - case 3: - phys += file_blocks; - break; + switch (state->x28[file_id]) { + case 0: + break; + case 1: + if (max_redun < file_blocks) { + max_redun = file_blocks; + } + break; + case 2: + if (max_redun < 1) { + max_redun = 1; + } + break; + case 3: + break; + } } } - } - return 0; + { + 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); + if (result < 0) { + return result; + } + } else { + result = fn_803ACFC0(state, logical, 0xFFFF, 0, NULL, 0, + file_id); + state->x170[logical] = -0x7FFF; + state->x270[logical] = 0; + if (result < 0) { + return result; + } + } + phys++; + logical++; + } + } + + 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); + } 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; + state->x270[logical] = 0; + return result; + } + state->x170[logical] = phys; + state->x270[logical] = 0; + } + logical++; + phys++; + } + break; + case 1: + case 2: + case 3: + phys += file_blocks; + break; + } + } + } + + return 0; + } } s32 fn_803B1F78(CardState* state, s32 channel, s32 file_id, s32 seq_num, diff --git a/src/sysdolphin/baselib/hsd_3B34.c b/src/sysdolphin/baselib/hsd_3B34.c index bd2e1eac3d..f991b31c58 100644 --- a/src/sysdolphin/baselib/hsd_3B34.c +++ b/src/sysdolphin/baselib/hsd_3B34.c @@ -22,32 +22,35 @@ typedef union JpegWork { } data; } JpegWork; -typedef union JpegMetadata { - u8 raw[0x1B6]; - struct { - u8 comment[0x18]; - u8 huff_dc_luma[0x1C]; - u8 huff_dc_chroma[0x1C]; - u8 huff_ac_luma[0xB4]; - u8 huff_ac_chroma[0xB2]; - } data; -} JpegMetadata; +typedef struct JpegLumaPair { + s32 block0[0x40]; + s32 block1[0x40]; +} JpegLumaPair; -typedef struct { - u8 b[0x15]; -} JpegComment20; +typedef struct JpegComment { + char data[0x15]; +} JpegComment; -typedef struct { - u8 b[0x1C]; +typedef struct JpegHuffDc { + u8 data[0x1C]; } JpegHuffDc; -typedef struct { - u8 b[0xB2]; -} JpegHuffAcL; +typedef struct JpegHuffAc { + u8 data[0xB2]; +} JpegHuffAc; -typedef struct { - u8 b[0xB2]; -} JpegHuffAcC; +typedef union JpegMetadata { + u8 raw[0x1B6]; + struct { + JpegComment comment; + u8 comment_pad[3]; + JpegHuffDc huff_dc_luma; + JpegHuffDc huff_dc_chroma; + JpegHuffAc huff_ac_luma; + u8 huff_ac_luma_pad[2]; + JpegHuffAc huff_ac_chroma; + } data; +} JpegMetadata; static const JpegMetadata lbl_803B9670 = { { 0x48, 0x41, 0x4C, 0x20, 0x4C, 0x61, 0x62, 0x6F, 0x72, 0x61, 0x74, 0x6F, @@ -192,147 +195,155 @@ extern u16 lbl_8043169C[0xC]; extern u8 lbl_804316B4[0xC]; static s32 lbl_804D6398 = 3; -void hsd_803B3408(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 unused_arg4) +static inline s32 hsd_803B3408_inline(s32 index) { - f32 scratch_f3; - f32 scratch_f3_2; - f32 scratch_f5; - f32 scratch_f7; - s32 scratch_r22; - s32 scratch_r22_2; - s32 scratch_r22_5; - s32 scratch_r23; - s32 scratch_r26; - s32 work_r9; - s32 work_ctr; - s32 work_r28; - s32 work_r10; - s32 work_r11; - s32 work_r12; - s32 work_r26; - s32 scratch_r31; - s32 work_r7; - s32 work_r7_2; - s32 work_r30; - s32 work_r6; - u16 scratch_r22_6; - s32 work_ctr_2; - s32 work_r29; - s32 work_r8; - s32 work_r27; - u16 scratch_r21; - u16 scratch_r22_4; - s32 work_r6_2; - u16 scratch_r30; - u16* scratch_r5; - u8* scratch_r22_3; - u8* work_r5; + return (index & 1) * 0x20; +} - work_r10 = 0; - scratch_r31 = ((arg3 + 0xF + work_r10) / 16) << 6; - work_r11 = 0; - work_r12 = 0; - for (work_r28 = 0; work_r28 < 2; work_r28++) { - u8* work_r24; - work_r8 = work_r11; - work_r24 = - arg0 + - ((((arg1 / 4) * 0x10) + ((arg2 / 4) * scratch_r31) + work_r10) * - 2); - work_r9 = 0; - for (work_r27 = 0; work_r27 < 2; work_r27++) { - for (work_r7 = 0; work_r7 < 4; work_r7++) { - work_r6 = 0; - for (work_ctr = 4; work_ctr != 0; work_ctr--) { - scratch_r22 = (work_r6 & 2) * 4; - scratch_r5 = (u16*) (work_r24 + - ((((work_r6 & 1) * 2) + - (scratch_r22 + - (((work_r7 & 1) * 0x20) + - ((work_r7 & 2) * scratch_r31)))) * - 2)); - scratch_r30 = *scratch_r5; - scratch_r22_2 = (scratch_r30 >> 8U) & 0xF8; +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; + s32 chroma_row_base; + s32 second_pixel_index; + s32 luma_row_base; + s32 pixel_index; + s32 luma_row; + s32 tile_stride; + s32 luma_y; + s32 pair_count; + s32 luma_x; + s32 tile_y; + s32 tile_x; + u16 pixel; + JpegLumaPair* luma_pair; + s32 tile_row_offset; + u16* pixel_ptr; + + tile_row_offset = 0; + hsd_803B3408_set_stride(&tile_stride, width); + chroma_row_base = 0; + luma_row_base = 0; + for (tile_y = 0; tile_y < 2; tile_y++) { + 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 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--) + { + f32 green; + s32 chroma_x_offset; + s32 red_chroma; + s32 blue_chroma; + u16 pixel; + u16 pixel_again; + JpegWork* chroma_work; + + chroma_x_offset = (chroma_x & 2) * 4; + pixel_ptr = + src + + (((chroma_x & 1) * 2) + + (chroma_x_offset + (((chroma_y & 1) * 0x20) + + ((chroma_y & 2) * tile_stride)))); + pixel = *pixel_ptr; + red_chroma = (pixel >> 8U) & 0xF8; { - s32 scratch_r23_2 = scratch_r30 * 8; - f32 scratch_f3_3 = (f32) ((scratch_r30 >> 3U) & 0xFC); - scratch_r23 = scratch_r23_2 & 0xF8; - scratch_f3 = scratch_f3_3; + s32 blue_shifted = pixel * 8; + f32 green_value = (f32) ((pixel >> 3U) & 0xFC); + blue_chroma = blue_shifted & 0xF8; + green = green_value; } - scratch_r22_3 = HSD_804D2648_BUF + - (((work_r6 & 1) + scratch_r22 + - (work_r8 + (((work_r7 & 1) * 4) + - ((work_r7 & 2) * 0x10)))) * - 4); - work_r6 += 1; - M2C_FIELD(scratch_r22_3, s32*, 0x518) = - (s32) ((0.5f * (f32) scratch_r23) + - ((-0.1687f * (f32) scratch_r22_2) - - (0.3313f * scratch_f3))); - scratch_r21 = *scratch_r5; - M2C_FIELD(scratch_r22_3, s32*, 0x618) = - (s32) (((0.5f * (f32) ((scratch_r21 >> 8U) & 0xF8)) - + chroma_work = + (JpegWork*) (HSD_804D2648_BUF + + (((chroma_x & 1) + chroma_x_offset + + (chroma_block_offset + + (((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) - + (0.3313f * green))); + pixel_again = *pixel_ptr; + chroma_work->data.x618[0] = + (s32) (((0.5f * (f32) ((pixel_again >> 8U) & 0xF8)) - (0.4187f * - (f32) ((scratch_r21 >> 3U) & 0xFC))) - - (0.0813f * (f32) ((scratch_r21 * 8) & 0xF8))); + (f32) ((pixel_again >> 3U) & 0xFC))) - + (0.0813f * (f32) ((pixel_again * 8) & 0xF8))); } } - work_r7_2 = work_r12; - for (work_r30 = 0; work_r30 < 4; work_r30++) { - work_r6_2 = work_r7_2 * 8; - for (work_r29 = 0; work_r29 < 4; work_r29++) { - work_r26 = 0; - work_r5 = - HSD_804D2648_BUF + ((work_r9 + work_r6_2) * 4) + 0x118; - for (work_ctr_2 = 2; work_ctr_2 != 0; work_ctr_2--) { - scratch_r22_4 = - M2C_FIELD(work_r24, u16*, - (((work_r26 << 5) & 0x20) + - ((work_r26 & 2) * scratch_r31)) * - 2); - scratch_r26 = work_r26 + 1; - scratch_f5 = (f32) ((scratch_r22_4 >> 8U) & 0xF8); - { - f32 scratch_f3_3 = - 0.587f * (f32) ((scratch_r22_4 >> 3U) & 0xFC); - scratch_f3_2 = scratch_f3_3; - } - scratch_r22_5 = (((scratch_r26 << 5) & 0x20) + - ((scratch_r26 & 2) * scratch_r31)) * - 2; - scratch_f7 = (f32) ((scratch_r22_4 * 8) & 0xF8); - work_r26 = scratch_r26 + 1; - M2C_FIELD(work_r5, s32*, 0) = - (s32) ((s32) ((0.114f * scratch_f7) + - ((0.299f * scratch_f5) + - scratch_f3_2)) - + luma_row = luma_row_base; + for (luma_y = 0; luma_y < 4; luma_y++) { + luma_offset = luma_row * 8; + 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--) { + 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); - scratch_r22_6 = - M2C_FIELD(work_r24, u16*, scratch_r22_5); - M2C_FIELD(work_r5, s32*, 0x100) = + pixel = src[second_pixel_offset]; + luma_pair->block1[0] = (s32) ((s32) ((0.114f * - (f32) ((scratch_r22_6 * 8) & - 0xF8)) + + (f32) ((pixel * 8) & 0xF8)) + ((0.299f * - (f32) ((scratch_r22_6 >> 8U) & - 0xF8)) + + (f32) ((pixel >> 8U) & 0xF8)) + (0.587f * - (f32) ((scratch_r22_6 >> 3U) & - 0xFC)))) - + (f32) ((pixel >> 3U) & 0xFC)))) - 0x80); - work_r5 += 0x200; + luma_pair += 1; } - work_r24 += 2; - work_r6_2 += 1; + src += 1; + luma_offset += 1; } - work_r7_2 += 1; + luma_row += 1; } - work_r8 += 2; - work_r9 += 4; + chroma_block_offset += 2; + luma_block_offset += 4; } - work_r10 += scratch_r31; - work_r11 += 0x10; - work_r12 += 4; + tile_row_offset += tile_stride; + chroma_row_base += 0x10; + luma_row_base += 4; } } @@ -344,11 +355,9 @@ static void fn_803B376C(u8* arg0) f32 scratch_f11_4; f32 scratch_f11_5; f32 scratch_f11_6; - s32 scratch_r31_2; f32 scratch_f27; f32 scratch_f6; - f32 scratch_f27_3; - s32 scratch_r10_2; + f32 scratch_f8; f32 scratch_f27_6; f32 scratch_f30_4; f32 scratch_f28; @@ -368,19 +377,21 @@ static void fn_803B376C(u8* arg0) f32 scratch_f30; f32 scratch_f27_2; f32 scratch_f6_2; - f32 scratch_f8; + f32 scratch_f27_3; f32 scratch_f28_2; f32 scratch_f8_3; f32 scratch_f27_5; f32 scratch_f27_4; f32 scratch_f29; - s32 scratch_r11_2; - s32 scratch_r12_2; - s32 scratch_r29_2; - s32 scratch_r30_2; f32 scratch_f26; s32 scratch_r7_2; s32 scratch_r9_2; + s32 scratch_r10_2; + s32 scratch_r11_2; + s32 scratch_r12_2; + s32 scratch_r31_2; + s32 scratch_r30_2; + s32 scratch_r29_2; s32 work_ctr; s32 work_ctr_2; s32 work_ctr_3; @@ -418,8 +429,8 @@ static void fn_803B376C(u8* arg0) scratch_f27_3 = (f32) (scratch_r9 - scratch_r7); scratch_f8 = (f32) (scratch_r11 - scratch_r10); scratch_f11_2 = (f32) (scratch_r31 - scratch_r12); - work_r4[0] = (s32) (0.707107 * (f64) (scratch_f6 + scratch_f30)); scratch_f28_2 = (f32) (scratch_r29 - scratch_r30); + work_r4[0] = (s32) (0.707107 * (f64) (scratch_f6 + scratch_f30)); work_r4[4] = (s32) (0.707107 * (f64) (scratch_f6 - scratch_f30)); work_r4[6] = (s32) ((-0.92388 * (f64) scratch_f27_2) + (0.382683 * (f64) scratch_f26)); @@ -430,7 +441,7 @@ static void fn_803B376C(u8* arg0) 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; - scratch_f27_4 = scratch_f8_2 + scratch_f27_3; + scratch_f27_4 = scratch_f27_3 + scratch_f8_2; work_r4[7] = (s32) ((0.980785 * (f64) scratch_f26_2) + (0.19509 * (f64) scratch_f30_2)); work_r4[5] = (s32) ((0.83147 * (f64) scratch_f27_4) + @@ -462,8 +473,8 @@ static void fn_803B376C(u8* arg0) scratch_f28_6 = (f32) (scratch_r9_2 - scratch_r7_2); scratch_f8_3 = (f32) (scratch_r11_2 - scratch_r10_2); scratch_f11_5 = (f32) (scratch_r29_2 - scratch_r12_2); - work_r4_2[0] = (s32) (0.707107 * (f64) (scratch_f6_2 + scratch_f29)); scratch_f29_2 = (f32) (scratch_r31_2 - scratch_r30_2); + work_r4_2[0] = (s32) (0.707107 * (f64) (scratch_f6_2 + scratch_f29)); work_r4_2[32] = (s32) (0.707107 * (f64) (scratch_f6_2 - scratch_f29)); work_r4_2[48] = (s32) ((-0.92388 * (f64) scratch_f28_5) + (0.382683 * (f64) scratch_f27_5)); @@ -522,12 +533,13 @@ void hsd_803B3CD8(s32 arg0) { s32 work_r31; JpegWork* work; + s32 work_r28_5; s32 scratch_r5_9; s32 work_r28_2; s32 work_r28; u16* work_r6; s32 scratch_r0; - s32 scratch_r0_2; + s32 work_r28_6; s32 scratch_r3; s32 scratch_r4; s32 scratch_r4_12; @@ -539,7 +551,7 @@ void hsd_803B3CD8(s32 arg0) s32 scratch_r4_22; s32 scratch_r4_23; s32 scratch_r4_2; - s32 scratch_r4_4; + s32 work_r22; s32 scratch_r4_5; s32 scratch_r4_6; s32 scratch_r4_7; @@ -555,15 +567,15 @@ void hsd_803B3CD8(s32 arg0) s32 work_ctr; s32 work_ctr_2; s32 work_ctr_3; - s32 work_r22; + 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 work_r28_5; - s32 work_r28_6; + u8 byte_out; + s32 scratch_r0_2; s32 work_r29; s32 work_r29_2; s32 work_r29_3; @@ -590,7 +602,6 @@ void hsd_803B3CD8(s32 arg0) u8* scratch_r4_9; u8* work_r7; u16* work_r27; - u8 byte_out; PAD_STACK(24); work_r6 = arg0 == 0 ? lbl_80431678 : lbl_8043169C; @@ -1399,42 +1410,42 @@ void hsd_803B4D64(u32 arg0, u32 arg1) #endif s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) { - char comment[0x15]; - u8 huff_dc_luma[0x1C]; - u8 huff_dc_chroma[0x1C]; - u8 huff_ac_luma[0xB2]; - u8* work_r26_2; + JpegComment comment; + JpegHuffDc huff_dc_luma; + JpegHuffDc huff_dc_chroma; + JpegHuffAc huff_ac_luma; + s32* work_r26_2; s32 scratch_r6_4; s32 scratch_r6_5; s32 scratch_r7_2; s32 scratch_r7_4; - s32 work_r24; + s32 quant_scale; s32 work_r25; - s32 work_r26; + s32 work_r24; + const JpegMetadata* const metadata = &lbl_803B9670; s32 work_r3; s32 work_r3_2; u32 scratch_r23; u8 scratch_r6_3; u8 scratch_r7_3; - u8* scratch_r6; - u8* quant_table; - u8* chroma_quant_table; - u8* base; - JpegWork* work; - u8* work_r23; - u8 huff_ac_chroma[0xB2]; - u8* work_r4_4; - u8* work_r4_5; - u8* work_r5_3; - s32 scratch_r0; - s32 width; + 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 comment_size; s32 height; + s32 width; u8* src; - s32 quant_div; - PAD_STACK(44); - base = HSD_804D2648_BUF; - work = (JpegWork*) base; + PAD_STACK(0x1C); + + state.base = HSD_804D2648_BUF; + state.work = (JpegWork*) state.base; src = (u8*) arg0; width = arg1; height = arg2; @@ -1442,257 +1453,243 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) hsd_804D79AC = 0; hsd_804D79A0 = (u8*) arg3; hsd_804D79A4 = (u8*) arg3; - quant_table = lbl_80430C40; - work->data.prev_dc[0] = work->data.prev_dc[1] = work->data.prev_dc[2] = 0; - if (__setjmp((__jmp_buf*) base) != 0) { + state.quant_table = lbl_80430C40; + state.work->data.prev_dc[0] = state.work->data.prev_dc[1] = + state.work->data.prev_dc[2] = 0; + if (__setjmp((__jmp_buf*) state.base) != 0) { return 0; } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xFF; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xD8; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } hsd_803B46D4(); - *(JpegComment20*) comment = - *(const JpegComment20*) lbl_803B9670.data.comment; - scratch_r23 = strlen(comment) + 1; + comment = metadata->data.comment; + scratch_r23 = strlen(comment.data) + 1; hsd_803B3344(0xFFU); hsd_803B3344(0xFEU); - scratch_r0 = scratch_r23 + 2; - hsd_803B3344((u8) (scratch_r0 >> 8U)); + comment_size = scratch_r23 + 2; + scratch_r0 = comment_size; + hsd_803B3344((u8) (comment_size >> 8U)); hsd_803B3344((u8) scratch_r0); - hsd_803B3398(comment, scratch_r23); + hsd_803B3398(comment.data, scratch_r23); hsd_803B4A2C(); - *(JpegHuffDc*) huff_dc_luma = - *(const JpegHuffDc*) lbl_803B9670.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, 0x1CU); - *(JpegHuffDc*) huff_dc_chroma = - *(const JpegHuffDc*) lbl_803B9670.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, 0x1CU); - *(JpegHuffAcL*) huff_ac_luma = - *(const JpegHuffAcL*) lbl_803B9670.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, 0xB2U); - *(JpegHuffAcC*) huff_ac_chroma = - *(const JpegHuffAcC*) lbl_803B9670.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, 0xB2U); - hsd_803B4D64(width, height); + hsd_803B3398(huff_ac_chroma.data, 0xB2U); + { + void (*const write_frame_header)(u32, u32) = hsd_803B4D64; + write_frame_header(width, height); + } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xFF; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xDA; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xC; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 3; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 1; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0x11; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 2; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0x11; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0x3F; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } for (work_r24 = 0; work_r24 < height; work_r24 += 0x10) { for (work_r25 = 0; work_r25 < width; work_r25 += 0x10) { + s32 work_r26; + u8* work_r23; s32 work_r3_3; - u8* work_r5_4; + s32* work_r5_4; hsd_803B3408(src, work_r25, work_r24, width, height); - for (work_r26 = 0; work_r26 < 4; work_r26++) { - u8* work_r4_3; - work_r23 = base + (work_r26 * 0x100 + 0x118); + work_r23 = state.base + ((work_r26 = 0) << 8); + work_r23 += 0x118; + while (work_r26 < 4) { + s32* work_r5_3; fn_803B376C(work_r23); - quant_div = lbl_804D6398; - work_r4_3 = work_r23; - work_r5_3 = base + 0x718; + 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; - scratch_r6 = quant_table + work_r3; - scratch_r7 = M2C_FIELD(scratch_r6, u8*, 0); - M2C_FIELD(work_r5_3, s32*, 0) = - ((s32) M2C_FIELD(work_r4_3, s32*, 0) / - ((s32) scratch_r7 / quant_div)); - M2C_FIELD(work_r5_3, s32*, 4) = - ((s32) M2C_FIELD(work_r4_3, s32*, 4) / - ((s32) M2C_FIELD(scratch_r6, u8*, 1) / quant_div)); - M2C_FIELD(work_r5_3, s32*, 8) = - ((s32) M2C_FIELD(work_r4_3, s32*, 8) / - ((s32) M2C_FIELD(scratch_r6, u8*, 2) / quant_div)); - M2C_FIELD(work_r5_3, s32*, 0xC) = - ((s32) M2C_FIELD(work_r4_3, s32*, 0xC) / - ((s32) M2C_FIELD(scratch_r6, u8*, 3) / quant_div)); - M2C_FIELD(work_r5_3, s32*, 0x10) = - ((s32) M2C_FIELD(work_r4_3, s32*, 0x10) / - ((s32) M2C_FIELD(scratch_r6, u8*, 4) / quant_div)); - M2C_FIELD(work_r5_3, s32*, 0x14) = - ((s32) M2C_FIELD(work_r4_3, s32*, 0x14) / - ((s32) M2C_FIELD(scratch_r6, u8*, 5) / quant_div)); - M2C_FIELD(work_r5_3, s32*, 0x18) = - ((s32) M2C_FIELD(work_r4_3, s32*, 0x18) / - ((s32) M2C_FIELD(scratch_r6, u8*, 6) / quant_div)); - scratch_r7_2 = M2C_FIELD(work_r4_3, s32*, 0x1C); - work_r4_3 += 0x20; - M2C_FIELD(work_r5_3, s32*, 0x1C) = - (scratch_r7_2 / - ((s32) M2C_FIELD(scratch_r6, u8*, 7) / quant_div)); - work_r5_3 += 0x20; + u8* scratch_r6; + scratch_r6 = state.quant_table + work_r3; + scratch_r7 = scratch_r6[0]; + work_r5_3[0] = + (work_r4_3[0] / ((s32) scratch_r7 / quant_scale)); + work_r5_3[1] = + (work_r4_3[1] / ((s32) scratch_r6[1] / quant_scale)); + work_r5_3[2] = + (work_r4_3[2] / ((s32) scratch_r6[2] / quant_scale)); + work_r5_3[3] = + (work_r4_3[3] / ((s32) scratch_r6[3] / quant_scale)); + work_r5_3[4] = + (work_r4_3[4] / ((s32) scratch_r6[4] / quant_scale)); + work_r5_3[5] = + (work_r4_3[5] / ((s32) scratch_r6[5] / quant_scale)); + work_r5_3[6] = + (work_r4_3[6] / ((s32) scratch_r6[6] / quant_scale)); + scratch_r7_2 = work_r4_3[7]; + work_r4_3 += 8; + work_r5_3[7] = + (scratch_r7_2 / ((s32) scratch_r6[7] / quant_scale)); + work_r5_3 += 8; } hsd_803B3CD8(0); + work_r23 += 0x100; + work_r26++; } - chroma_quant_table = quant_table + 0x40; - fn_803B376C(base + 0x518); - quant_div = lbl_804D6398; - work_r26_2 = base + 0x718; - work_r5_4 = work_r26_2; - work_r4_4 = 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 = M2C_FIELD(scratch_r6_2, u8*, 0); - M2C_FIELD(work_r5_4, s32*, 0) = - ((s32) M2C_FIELD(work_r4_4, s32*, 0) / - ((s32) scratch_r7_3 / quant_div)); - M2C_FIELD(work_r5_4, s32*, 4) = - ((s32) M2C_FIELD(work_r4_4, s32*, 4) / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 1) / quant_div)); - M2C_FIELD(work_r5_4, s32*, 8) = - ((s32) M2C_FIELD(work_r4_4, s32*, 8) / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 2) / quant_div)); - M2C_FIELD(work_r5_4, s32*, 0xC) = - ((s32) M2C_FIELD(work_r4_4, s32*, 0xC) / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 3) / quant_div)); - M2C_FIELD(work_r5_4, s32*, 0x10) = - ((s32) M2C_FIELD(work_r4_4, s32*, 0x10) / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 4) / quant_div)); - M2C_FIELD(work_r5_4, s32*, 0x14) = - ((s32) M2C_FIELD(work_r4_4, s32*, 0x14) / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 5) / quant_div)); - M2C_FIELD(work_r5_4, s32*, 0x18) = - ((s32) M2C_FIELD(work_r4_4, s32*, 0x18) / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 6) / quant_div)); - scratch_r7_4 = M2C_FIELD(work_r4_4, s32*, 0x1C); - work_r4_4 += 0x20; - M2C_FIELD(work_r5_4, s32*, 0x1C) = - (scratch_r7_4 / - ((s32) M2C_FIELD(scratch_r6_2, u8*, 7) / quant_div)); - work_r5_4 += 0x20; + { + 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] = + (work_r4_4[0] / ((s32) scratch_r7_3 / quant_scale)); + work_r5_4[1] = + (work_r4_4[1] / ((s32) scratch_r6_2[1] / quant_scale)); + work_r5_4[2] = + (work_r4_4[2] / ((s32) scratch_r6_2[2] / quant_scale)); + work_r5_4[3] = + (work_r4_4[3] / ((s32) scratch_r6_2[3] / quant_scale)); + work_r5_4[4] = + (work_r4_4[4] / ((s32) scratch_r6_2[4] / quant_scale)); + work_r5_4[5] = + (work_r4_4[5] / ((s32) scratch_r6_2[5] / quant_scale)); + work_r5_4[6] = + (work_r4_4[6] / ((s32) scratch_r6_2[6] / quant_scale)); + scratch_r7_4 = work_r4_4[7]; + work_r4_4 += 8; + work_r5_4[7] = + (scratch_r7_4 / ((s32) scratch_r6_2[7] / quant_scale)); + work_r5_4 += 8; + } + hsd_803B3CD8(1); } - hsd_803B3CD8(1); - chroma_quant_table = quant_table + 0x40; - fn_803B376C(base + 0x618); - quant_div = lbl_804D6398; - work_r4_5 = 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 = M2C_FIELD(scratch_r5, u8*, 0); - M2C_FIELD(work_r26_2, s32*, 0) = - ((s32) M2C_FIELD(work_r4_5, s32*, 0) / - ((s32) scratch_r6_3 / quant_div)); - M2C_FIELD(work_r26_2, s32*, 4) = - ((s32) M2C_FIELD(work_r4_5, s32*, 4) / - ((s32) M2C_FIELD(scratch_r5, u8*, 1) / quant_div)); - M2C_FIELD(work_r26_2, s32*, 8) = - ((s32) M2C_FIELD(work_r4_5, s32*, 8) / - ((s32) M2C_FIELD(scratch_r5, u8*, 2) / quant_div)); - M2C_FIELD(work_r26_2, s32*, 0xC) = - ((s32) M2C_FIELD(work_r4_5, s32*, 0xC) / - ((s32) M2C_FIELD(scratch_r5, u8*, 3) / quant_div)); - M2C_FIELD(work_r26_2, s32*, 0x10) = - ((s32) M2C_FIELD(work_r4_5, s32*, 0x10) / - ((s32) M2C_FIELD(scratch_r5, u8*, 4) / quant_div)); - M2C_FIELD(work_r26_2, s32*, 0x14) = - ((s32) M2C_FIELD(work_r4_5, s32*, 0x14) / - ((s32) M2C_FIELD(scratch_r5, u8*, 5) / quant_div)); - M2C_FIELD(work_r26_2, s32*, 0x18) = - ((s32) M2C_FIELD(work_r4_5, s32*, 0x18) / - ((s32) M2C_FIELD(scratch_r5, u8*, 6) / quant_div)); - scratch_r6_4 = M2C_FIELD(work_r4_5, s32*, 0x1C); - work_r4_5 += 0x20; - M2C_FIELD(work_r26_2, s32*, 0x1C) = - (scratch_r6_4 / - ((s32) M2C_FIELD(scratch_r5, u8*, 7) / quant_div)); - work_r26_2 += 0x20; + { + u8* chroma_quant_table = state.quant_table + 0x40; + s32* work_r4_5; + 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] = + (work_r4_5[0] / ((s32) scratch_r6_3 / quant_scale)); + work_r26_2[1] = + (work_r4_5[1] / ((s32) scratch_r5[1] / quant_scale)); + work_r26_2[2] = + (work_r4_5[2] / ((s32) scratch_r5[2] / quant_scale)); + work_r26_2[3] = + (work_r4_5[3] / ((s32) scratch_r5[3] / quant_scale)); + work_r26_2[4] = + (work_r4_5[4] / ((s32) scratch_r5[4] / quant_scale)); + work_r26_2[5] = + (work_r4_5[5] / ((s32) scratch_r5[5] / quant_scale)); + work_r26_2[6] = + (work_r4_5[6] / ((s32) scratch_r5[6] / quant_scale)); + scratch_r6_4 = work_r4_5[7]; + work_r4_5 += 8; + work_r26_2[7] = + (scratch_r6_4 / ((s32) scratch_r5[7] / quant_scale)); + work_r26_2 += 8; + } + hsd_803B3CD8(2); } - hsd_803B3CD8(2); } } /// @todo Redundant cast improves match @@ -1703,11 +1700,13 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) #endif scratch_r6_5 = 8 - hsd_804D79AC; hsd_804D79B0 <<= scratch_r6_5; - hsd_804D79B0 |= (1 << scratch_r6_5) - 1; + scratch_r6_4 = 1 << scratch_r6_5; + hsd_804D79B0 |= scratch_r6_4 - 1; + scratch_r6_3 = hsd_804D79B0; if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - *hsd_804D79A0++ = hsd_804D79B0; + *hsd_804D79A0++ = scratch_r6_3; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } hsd_804D79B0 = 0; hsd_804D79AC = 0; @@ -1715,12 +1714,12 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xFF; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { *hsd_804D79A0++ = 0xD9; } else { - longjmp((__jmp_buf*) base, 1); + longjmp((__jmp_buf*) state.base, 1); } return hsd_804D79A0 - hsd_804D79A4; } diff --git a/src/sysdolphin/baselib/hsd_3B5C.c b/src/sysdolphin/baselib/hsd_3B5C.c index 7c61fa03a8..55e174d904 100644 --- a/src/sysdolphin/baselib/hsd_3B5C.c +++ b/src/sysdolphin/baselib/hsd_3B5C.c @@ -25,6 +25,11 @@ typedef struct JpegState { JpegWorkData work; } JpegState; +typedef struct JpegQuantTables { + u8 luma[0x40]; + u8 chroma[0x40]; +} JpegQuantTables; + u8 lbl_80431090[0x5A8] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, @@ -399,11 +404,11 @@ static void fn_803B61B4(u8* arg0) scratch_r5_3 = work_r4[6]; scratch_f13 = -scratch_f23 + scratch_f24; scratch_f13_2 = scratch_f23 + scratch_f24; - scratch_f9 = (f32) (0.707107 * (f64) (-scratch_f12 + scratch_f13)); scratch_f25 = (f32) ((-0.92388 * (f64) scratch_r5_3) + (0.382683 * (f64) scratch_r0_2)); scratch_f12_2 = (f32) ((0.382683 * (f64) scratch_r5_3) + (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_f24_2 = scratch_f11 + scratch_f25; @@ -443,18 +448,18 @@ static void fn_803B61B4(u8* arg0) scratch_r5_6 = work_r4_2[48]; scratch_f13 = -scratch_f23 + scratch_f24; scratch_f13_2 = scratch_f23 + scratch_f24; - scratch_f9 = (f32) (0.707107 * (f64) (-scratch_f12 + scratch_f13)); scratch_f25 = (f32) ((-0.92388 * (f64) scratch_r5_6) + (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)); 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)); scratch_f24_2 = scratch_f11 + scratch_f25; scratch_f25_2 = scratch_f11 - scratch_f25; work_r4_2[0] = (s32) (scratch_f23_2 + scratch_f13_2); work_r4_2[8] = (s32) (scratch_f24_2 + scratch_f9); - scratch_f13_3 = -scratch_f22 + scratch_f31; scratch_f10_2 = scratch_f10; scratch_f10_2 -= scratch_f12_2; work_r4_2[16] = (s32) (scratch_f25_2 + scratch_f22_2); @@ -507,14 +512,12 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 work_r22; s32 work_r24; s32 work_r25; - s32 work_r31; + u32 work_r31; s32 work_r4; s32 work_r5; s32 work_r6; s32 work_r7; - s32 work_r8_2; u16* work_r9_2; - s32* work_r27; u8* work_r8; u8* work_r9; @@ -572,10 +575,14 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, for (work_r7 = 0; work_r7 < 2; work_r7++) { work_r12 = work_r21 * 8; for (work_r4 = 0; work_r4 < 4; work_r4++) { - work_r31 = work_r24 + work_r12; + work_r31 = (work_r24 + work_r12) * 4; for (work_r5 = 0; work_r5 < 4; work_r5++) { + s32 work_r8_2; + s32* work_r27; + work_r8_2 = 0; - work_r27 = (s32*) (base + (work_r31 * 4 + 0x118)); + work_r27 = + &((JpegWorkData*) &base[0x118])->luma[work_r31 / 4]; for (work_ctr_2 = 4; work_ctr_2 != 0; work_ctr_2--) { f32 scratch_f0; f32 scratch_f0_2; @@ -637,7 +644,7 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, work_r8_2 += 1; } work_r9_2 += 1; - work_r31 += 1; + work_r31 += 4; } work_r12 += 8; } @@ -651,14 +658,11 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) { - s32 work_r28; - s32 work_r29; s32 scratch_r6_4; s32 scratch_r7; s32 scratch_r7_3; - s32 work_r23; - s32 work_r25; s32 work_r26; + s32 work_r25; s32 work_r3; s32 work_r3_2; s32 scratch_r0_3; @@ -685,30 +689,38 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) u8* scratch_r5_7; u8* scratch_r5_8; u8* scratch_r5_9; - u8* work_r24; - u8* work_r24_2; + s32* work_r24; + s32* work_r24_2; + s32 work_r23; u8* work_r4; u8* work_r4_2; - u8* work_r4_3; - u8* work_r4_4; - u8* work_r4_5; - u8* work_r5; - u8* work_r5_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; - u8* quant_table; - JpegState* base; + struct { + u8* base; + JpegState* work; + JpegQuantTables* quant_table; + s32 width; + s32 height; + } state; - PAD_STACK(0x40); - base = (JpegState*) hsd_804D2E70; + PAD_STACK(0x30); + state.base = hsd_804D2E70; + state.work = (JpegState*) state.base; hsd_804D79C0 = arg1; - quant_table = lbl_80431090; + state.quant_table = (JpegQuantTables*) lbl_80431090; hsd_804D79B8 = (u8*) arg0; hsd_804D79BC = (u8*) arg0; - base->work.prev_dc[0] = base->work.prev_dc[1] = base->work.prev_dc[2] = 0; + state.work->work.prev_dc[0] = state.work->work.prev_dc[1] = + state.work->work.prev_dc[2] = 0; hsd_804D79C4 = 0; - if (__setjmp((__jmp_buf*) base) != 0) { + if (__setjmp(&state.work->jmp) != 0) { return 0; } scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; @@ -719,34 +731,34 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) for (work_r3 = 0; work_r3 < 0x40; work_r3 += 8) { scratch_r5 = hsd_804D79B8; hsd_804D79B8 = scratch_r5 + 1; - *(quant_table + M2C_FIELD(work_r4, u8*, 0)) = *scratch_r5; + state.quant_table->luma[work_r4[0]] = *scratch_r5; scratch_r5_2 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_2 + 1; - *(quant_table + work_r4[1]) = *scratch_r5_2; + state.quant_table->luma[work_r4[1]] = *scratch_r5_2; scratch_r5_3 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_3 + 1; - *(quant_table + work_r4[2]) = *scratch_r5_3; + state.quant_table->luma[work_r4[2]] = *scratch_r5_3; scratch_r5_4 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_4 + 1; - *(quant_table + work_r4[3]) = *scratch_r5_4; + state.quant_table->luma[work_r4[3]] = *scratch_r5_4; scratch_r5_5 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_5 + 1; - *(quant_table + work_r4[4]) = *scratch_r5_5; + state.quant_table->luma[work_r4[4]] = *scratch_r5_5; scratch_r5_6 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_6 + 1; - *(quant_table + work_r4[5]) = *scratch_r5_6; + state.quant_table->luma[work_r4[5]] = *scratch_r5_6; scratch_r5_7 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_7 + 1; - *(quant_table + work_r4[6]) = *scratch_r5_7; + state.quant_table->luma[work_r4[6]] = *scratch_r5_7; scratch_r5_8 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_8 + 1; scratch_r0 = work_r4[7]; work_r4 += 8; - *(quant_table + scratch_r0) = *scratch_r5_8; + state.quant_table->luma[scratch_r0] = *scratch_r5_8; } } else { if (++hsd_804D79B8 >= scratch_r5) { - longjmp((__jmp_buf*) base, 1); + longjmp(&state.work->jmp, 1); } else { goto loop_3; } @@ -759,42 +771,57 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) for (work_r3_2 = 0; work_r3_2 < 0x40; work_r3_2 += 8) { scratch_r5_9 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_9 + 1; - M2C_FIELD((quant_table + M2C_FIELD(work_r4_2, u8*, 0)), u8*, - 0x40) = (*scratch_r5_9); + scratch_r0_3 = work_r4_2[0]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_9; + qptr[0x40] = qbyte; scratch_r5_10 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_10 + 1; - M2C_FIELD((quant_table + work_r4_2[1]), u8*, 0x40) = - (*scratch_r5_10); + scratch_r0_3 = work_r4_2[1]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_10; + qptr[0x40] = qbyte; scratch_r5_11 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_11 + 1; - M2C_FIELD((quant_table + work_r4_2[2]), u8*, 0x40) = - (*scratch_r5_11); + scratch_r0_3 = work_r4_2[2]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_11; + qptr[0x40] = qbyte; scratch_r5_12 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_12 + 1; - M2C_FIELD((quant_table + work_r4_2[3]), u8*, 0x40) = - (*scratch_r5_12); + scratch_r0_3 = work_r4_2[3]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_12; + qptr[0x40] = qbyte; scratch_r5_13 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_13 + 1; - M2C_FIELD((quant_table + work_r4_2[4]), u8*, 0x40) = - (*scratch_r5_13); + scratch_r0_3 = work_r4_2[4]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_13; + qptr[0x40] = qbyte; scratch_r5_14 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_14 + 1; - M2C_FIELD((quant_table + work_r4_2[5]), u8*, 0x40) = - (*scratch_r5_14); + scratch_r0_3 = work_r4_2[5]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_14; + qptr[0x40] = qbyte; scratch_r5_15 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_15 + 1; - M2C_FIELD((quant_table + work_r4_2[6]), u8*, 0x40) = - (*scratch_r5_15); + scratch_r0_3 = work_r4_2[6]; + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_15; + qptr[0x40] = qbyte; scratch_r5_16 = hsd_804D79B8; hsd_804D79B8 = scratch_r5_16 + 1; scratch_r0_3 = work_r4_2[7]; work_r4_2 += 8; - M2C_FIELD((quant_table + scratch_r0_3), u8*, 0x40) = - (*scratch_r5_16); + qptr = state.quant_table->luma + scratch_r0_3; + qbyte = *scratch_r5_16; + qptr[0x40] = qbyte; } } else { if (++hsd_804D79B8 >= scratch_r5) { - longjmp((__jmp_buf*) base, 1); + longjmp(&state.work->jmp, 1); } else { goto loop_11; } @@ -803,13 +830,13 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) loop_19: if (*(u16*) hsd_804D79B8 == 0xFFC0) { hsd_804D79B8 += 5; - work_r28 = *(u16*) hsd_804D79B8; + state.height = *(u16*) hsd_804D79B8; hsd_804D79B8 += 2; - work_r29 = *(u16*) hsd_804D79B8; + state.width = *(u16*) hsd_804D79B8; hsd_804D79B8 += 0xC; } else { if (++hsd_804D79B8 >= scratch_r5) { - longjmp((__jmp_buf*) base, 1); + longjmp(&state.work->jmp, 1); } else { goto loop_19; } @@ -821,20 +848,20 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) hsd_804D79B8 += 0xC; } else { if (++hsd_804D79B8 >= scratch_r5) { - longjmp((__jmp_buf*) base, 1); + longjmp(&state.work->jmp, 1); } else { goto loop_24; } } - for (work_r25 = 0; work_r25 < work_r28; work_r25 += 0x10) { - for (work_r26 = 0; work_r26 < work_r29; work_r26 += 0x10) { - work_r24 = (u8*) base->work.luma; + for (work_r25 = 0; work_r25 < state.height; work_r25 += 0x10) { + 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++) { hsd_803B5EA0(0); work_r5 = work_r24; - work_r4_3 = (u8*) base->work.coeff; + work_r4_3 = state.work->work.coeff; for (work_r3_3 = 0; work_r3_3 < 0x40; work_r3_3 += 8) { - u8* scratch_r6 = quant_table + work_r3_3; + 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); @@ -857,19 +884,18 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) (s32) (M2C_FIELD(work_r4_3, s32*, 0x18) * M2C_FIELD(scratch_r6, u8*, 6)); scratch_r7 = M2C_FIELD(work_r4_3, s32*, 0x1C); - work_r4_3 += 0x20; + work_r4_3 += 8; M2C_FIELD(work_r5, s32*, 0x1C) = (s32) (scratch_r7 * M2C_FIELD(scratch_r6, u8*, 7)); - work_r5 += 0x20; + work_r5 += 8; } - fn_803B61B4(work_r24); - work_r24 += 0x100; + fn_803B61B4((u8*) work_r24); + work_r24 += 0x40; } hsd_803B5EA0(1); - work_r24_2 = (u8*) base->work.coeff; - work_r4_4 = work_r24_2; - quant_chroma = quant_table + 0x40; - work_r5_2 = (u8*) base->work.cb; + 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); @@ -894,15 +920,15 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) (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 += 0x20; + 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 += 0x20; + work_r5_2 += 8; } - fn_803B61B4((u8*) base->work.cb); + fn_803B61B4((u8*) state.work->work.cb); hsd_803B5EA0(2); - quant_chroma = quant_table + 0x40; - work_r4_5 = (u8*) base->work.cr; + 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); @@ -927,16 +953,16 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) (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 += 0x20; + 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 += 0x20; + work_r4_5 += 8; } - fn_803B61B4((u8*) base->work.cr); - fn_803B6820((u8*) arg2, work_r26, work_r25, work_r29, work_r28); + fn_803B61B4((u8*) state.work->work.cr); + fn_803B6820(arg2, work_r26, work_r25, state.width, state.height); } } - return work_r29 * work_r28 * 2; + return state.width * state.height * 2; } u8 lbl_80431638[0x40] = { diff --git a/src/sysdolphin/baselib/particle.c b/src/sysdolphin/baselib/particle.c index 268d169250..a23d9ab9fd 100644 --- a/src/sysdolphin/baselib/particle.c +++ b/src/sysdolphin/baselib/particle.c @@ -612,6 +612,101 @@ s32 hsd_803991D8(HSD_Generator* gen, HSD_JObj* jobj, f32 force, f32 range) return 0; } +static inline void psUpdateParticle(HSD_Particle* pp) +{ + if (pp->kind & Tornado) { + HSD_Generator* gp = pp->gen; + f32 sinA, sinB, cosA, cosB; + f32 R; + f32 d, e, nd, vz; + f32 t0, t1, t2, t3, t4; + + sinA = sinf(pp->grav); + sinB = sinf(pp->fric); + cosA = cosf(pp->grav); + cosB = cosf(pp->fric); + + pp->vel.z += gp->aux.tornado.vel; + + R = gp->radius; + if (R < 0.0F) { + R = -R; + } + { + f32 ang = gp->angle; + if (ang < 0.0F) { + ang = -ang; + } + R = pp->vel.z * tanf(ang) + R; + } + pp->vel.x += gp->grav; + R *= pp->vel.y; + + d = R * cosf(pp->vel.x); + e = R * sinf(pp->vel.x); + nd = -d; + vz = pp->vel.z; + + t0 = vz * sinB; + t1 = e * cosA; + t2 = nd * sinA; + t3 = d * cosB + t0; + t0 = vz * sinA; + t1 = sinB * t2 + t1; + pp->pos.x = gp->pos.x + t3; + t2 = nd * cosA; + t4 = e * sinA; + t1 = cosB * t0 + t1; + t0 = vz * cosA; + t4 = sinB * t2 - t4; + pp->pos.y = gp->pos.y + t1; + t4 = cosB * t0 + t4; + pp->pos.z = gp->pos.z + t4; + } else { + if (pp->kind & 1) { + pp->vel.y -= pp->grav; + } + if (pp->kind & 2) { + pp->vel.x *= pp->fric; + pp->vel.y *= pp->fric; + pp->vel.z *= pp->fric; + } + pp->pos.x += pp->vel.x; + pp->pos.y += pp->vel.y; + pp->pos.z += pp->vel.z; + } + + if (pp->kind & 0x8000) { + s32 jobj_idx = (pp->kind >> 12) & 7; + HSD_JObj* jobj; + HSD_JObj** jobj_slot; + + if (hsd_804D08E8[jobj_idx] == NULL) { + HSD_JObj* new_jobj = HSD_JObjAlloc(); + if (new_jobj != NULL) { + hsd_8039CF4C(jobj_idx + 1, new_jobj); + HSD_JObjUnref(new_jobj); + } + } + + jobj_slot = &hsd_804D08E8[jobj_idx]; + jobj = *jobj_slot; + + if (jobj != NULL) { + HSD_JObjSetupMatrix(jobj); + + jobj = *jobj_slot; + HSD_JObjAddTranslationX(jobj, pp->pos.x - jobj->mtx[0][3]); + + jobj = *jobj_slot; + HSD_JObjAddTranslationY(jobj, pp->pos.y - jobj->mtx[1][3]); + + jobj = *jobj_slot; + HSD_JObjAddTranslationZ(jobj, pp->pos.z - jobj->mtx[2][3]); + } + } +} + // @TODO: Currently 93.95% match - register allocation differences (stmw // r20 vs r21), r27/r28 swap, and PC advance codegen patterns void* hsd_8039930C(void* pp_arg, void* prev_arg) @@ -1063,8 +1158,12 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) gchild->idnum = pp->idnum; if (pp->gen != NULL) { HSD_JObj* jobj = pp->gen->jobj; - gchild->jobj = jobj; - ref_INC(jobj); + if (gchild != NULL) { + gchild->jobj = jobj; + if (jobj != NULL) { + ref_INC(jobj); + } + } } gchild->type |= 0x100; if (pp->gen != NULL) { @@ -1122,8 +1221,12 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) gchild->idnum = pp->idnum; if (pp->gen != NULL) { HSD_JObj* jobj = pp->gen->jobj; - gchild->jobj = jobj; - ref_INC(jobj); + if (gchild != NULL) { + gchild->jobj = jobj; + if (jobj != NULL) { + ref_INC(jobj); + } + } } gchild->type |= 0x100; if (pp->gen != NULL) { @@ -1187,8 +1290,12 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) gchild->idnum = pp->idnum; if (pp->gen != NULL) { HSD_JObj* jobj = pp->gen->jobj; - gchild->jobj = jobj; - ref_INC(jobj); + if (gchild != NULL) { + gchild->jobj = jobj; + if (jobj != NULL) { + ref_INC(jobj); + } + } } gchild->type |= 0x100; if (pp->gen != NULL) { @@ -1440,16 +1547,16 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) HSD_MtxSRT(srt->mmtx, &srt->scale, (Vec3*) rot, &srt->translate, NULL); } - pp->pos.x = pp->appsrt->mmtx[0][1] * pp->pos.y + - pp->appsrt->mmtx[0][0] * pp->pos.x + + pp->pos.x = pp->appsrt->mmtx[0][0] * pp->pos.x + + pp->appsrt->mmtx[0][1] * pp->pos.y + pp->appsrt->mmtx[0][2] * pp->pos.z + pp->appsrt->mmtx[0][3]; - pp->pos.y = pp->appsrt->mmtx[1][1] * pp->pos.y + - pp->appsrt->mmtx[1][0] * pp->pos.x + + pp->pos.y = pp->appsrt->mmtx[1][0] * pp->pos.x + + pp->appsrt->mmtx[1][1] * pp->pos.y + pp->appsrt->mmtx[1][2] * pp->pos.z + pp->appsrt->mmtx[1][3]; - pp->pos.z = pp->appsrt->mmtx[2][1] * pp->pos.y + - pp->appsrt->mmtx[2][0] * pp->pos.x + + pp->pos.z = pp->appsrt->mmtx[2][0] * pp->pos.x + + pp->appsrt->mmtx[2][1] * pp->pos.y + pp->appsrt->mmtx[2][2] * pp->pos.z + pp->appsrt->mmtx[2][3]; psRemoveParticleAppSRT(pp); @@ -2765,103 +2872,7 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) } } - /* --- Physics update --- */ - if (pp->kind & Tornado) { - /* Tornado rotational physics */ - HSD_Generator* gp = pp->gen; - f32 sinA, sinB, cosA, cosB; - f32 R; - f32 d, e, nd, vz; - f32 t0, t1, t2, t3, t4; - - sinA = sinf(pp->grav); - sinB = sinf(pp->fric); - cosA = cosf(pp->grav); - cosB = cosf(pp->fric); - - pp->vel.z += gp->aux.tornado.vel; - - R = gp->radius; - if (R < 0.0F) { - R = -R; - } - { - f32 ang = gp->angle; - if (ang < 0.0F) { - ang = -ang; - } - R = pp->vel.z * tanf(ang) + R; - } - pp->vel.x += gp->grav; - R *= pp->vel.y; - - d = R * cosf(pp->vel.x); - e = R * sinf(pp->vel.x); - nd = -d; - vz = pp->vel.z; - - /* Rotation matrix application */ - t0 = vz * sinB; - t1 = e * cosA; - t2 = nd * sinA; - t3 = d * cosB + t0; - t0 = vz * sinA; - t1 = sinB * t2 + t1; - pp->pos.x = gp->pos.x + t3; - t2 = nd * cosA; - t4 = e * sinA; - t1 = cosB * t0 + t1; - t0 = vz * cosA; - t4 = sinB * t2 - t4; - pp->pos.y = gp->pos.y + t1; - t4 = cosB * t0 + t4; - pp->pos.z = gp->pos.z + t4; - } else { - /* Simple physics */ - if (pp->kind & 1) { - pp->vel.y -= pp->grav; - } - if (pp->kind & 2) { - pp->vel.x *= pp->fric; - pp->vel.y *= pp->fric; - pp->vel.z *= pp->fric; - } - pp->pos.x += pp->vel.x; - pp->pos.y += pp->vel.y; - pp->pos.z += pp->vel.z; - } - - /* JObj attachment - update JObj position to match particle */ - if (pp->kind & 0x8000) { - s32 jobj_idx = (pp->kind >> 12) & 7; - HSD_JObj* jobj; - HSD_JObj** jobj_slot; - - /* Allocate JObj if slot is empty */ - if (hsd_804D08E8[jobj_idx] == NULL) { - HSD_JObj* new_jobj = HSD_JObjAlloc(); - if (new_jobj != NULL) { - hsd_8039CF4C(jobj_idx + 1, new_jobj); - HSD_JObjUnref(new_jobj); - } - } - - jobj_slot = &hsd_804D08E8[jobj_idx]; - jobj = *jobj_slot; - - if (jobj != NULL) { - HSD_JObjSetupMatrix(jobj); - - jobj = *jobj_slot; - HSD_JObjAddTranslationX(jobj, pp->pos.x - jobj->mtx[0][3]); - - jobj = *jobj_slot; - HSD_JObjAddTranslationY(jobj, pp->pos.y - jobj->mtx[1][3]); - - jobj = *jobj_slot; - HSD_JObjAddTranslationZ(jobj, pp->pos.z - jobj->mtx[2][3]); - } - } + psUpdateParticle(pp); /* Callback */ if (pp->callback != NULL) { diff --git a/src/sysdolphin/baselib/psdisp.c b/src/sysdolphin/baselib/psdisp.c index c837fe02cb..f79b4255db 100644 --- a/src/sysdolphin/baselib/psdisp.c +++ b/src/sysdolphin/baselib/psdisp.c @@ -858,7 +858,7 @@ static inline void psDispSubMakePolygon(HSD_Particle* pp, u8* texform, f32 x, if (pp->kind & DispTexture) { GXWGFifo.u8 = ((pp->kind >> 16) & 0xC) + 1; } - GXPosition3f32(x + x0, y + y0, z + z0); + GXPosition3f32(x + x0, y + y0, z0 + z); { u8 a = color.a; u8 b = color.b; @@ -972,11 +972,11 @@ static inline void psDispSubMakePolygon(HSD_Particle* pp, u8* texform, f32 x, if (pp->kind & DispTexture) { GXWGFifo.u8 = ((pp->kind >> 16) & 0xC) + 1; } - GXPosition3f32(x + x0, y + y0, z + z0); + GXPosition3f32(x + x0, y + y0, z0 + z); if (pp->kind & DispTexture) { GXWGFifo.u8 = ((pp->kind >> 16) & 0xC) + 2; } - GXPosition3f32(x + x1, y + y1, z + z1); + GXPosition3f32(x1 + x, y1 + y, z1 + z); if (pp->kind & DispTexture) { GXWGFifo.u8 = ((pp->kind >> 16) & 0xC) + 3; } @@ -1101,7 +1101,7 @@ static inline void psDispSub(HSD_Particle* pp, u8* texform) cur_y = pvmtx[0][1] * pp->pos.y; cur_y_term = pvmtx[1][1] * pp->pos.y; prev_x_sum = pvmtx[0][0] * prev_x + prev_xy; - prev_yx = pvmtx[1][0] * prev_x + prev_y_terms; + 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))) - @@ -1159,7 +1159,10 @@ static inline void psDispSub(HSD_Particle* pp, u8* texform) f32 uz = up_z; axis.x = ry * uz - rz * up_y; - axis.y = rz * ux - rx * uz; + { + f32 axis_y_product = ux * rz; + axis.y = axis_y_product - rx * uz; + } axis.z = rx * up_y - ry * ux; PSMTXRotAxisRad(mtx, &axis, angle); t1 = mtx[1][0] * rx + mtx[1][1] * ry; @@ -1209,9 +1212,8 @@ static inline void psDispSubAPPSRTPoint(HSD_Particle* pp) Vec3* translate = &appsrt->translate; Vec3* rotate = (Vec3*) &appsrt->rot; Vec3* scale = &appsrt->scale; - MtxPtr mmtx = appsrt->mmtx; - HSD_MtxSRT(mmtx, scale, rotate, translate, NULL); + HSD_MtxSRT(appsrt->mmtx, scale, rotate, translate, NULL); } if (pp->appsrt->status == PS_APPSTATUS_ONCE) { pp->appsrt->status = PS_APPSTATUS_STILL; @@ -1249,6 +1251,7 @@ static inline void psDispSubAPPSRTPoint(HSD_Particle* pp) { HSD_psAppSRT* appsrt = pp->appsrt; f32 pos_y; + f32 transformed_x; cur_pos.z = appsrt->x88 * (pos_y = pp->pos.y); cur_pos.y = appsrt->x78 * pos_y; @@ -1256,7 +1259,8 @@ static inline void psDispSubAPPSRTPoint(HSD_Particle* pp) cur_pos.y = appsrt->x74 * pp->pos.x + cur_pos.y; cur_pos.z = (cur_pos.x = appsrt->ssx * pp->pos.x + cur_pos.x, appsrt->x84 * pp->pos.x + cur_pos.z); - cur_pos.x = appsrt->x6C * pp->pos.z + cur_pos.x; + transformed_x = appsrt->x6C * pp->pos.z + cur_pos.x; + cur_pos.x = transformed_x; cur_pos.y = appsrt->x7C * pp->pos.z + cur_pos.y; cur_pos.z = appsrt->x8C * pp->pos.z + cur_pos.z; cur_pos.x = appsrt->x70 + cur_pos.x; @@ -1287,7 +1291,7 @@ static inline void psDispSubAPPSRTPoint(HSD_Particle* pp) (pp->appsrt->ssx * dx + pp->appsrt->ssy * dy)); prev_pos.y = pp->appsrt->x80 + (pp->appsrt->x7C * dz + - (pp->appsrt->x74 * dx + pp->appsrt->x78 * dy)); + (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)); @@ -1937,25 +1941,25 @@ static inline void psUpdateProjectionCache(f32 perspective) #endif void psDispParticles(u32 target_link, u32 sw) { - s32 var_r16; - s32 var_r15; + GXColor chan_mat_color; + s32 needs_setup; s32 sp7B4; void* sp7B0; u32 sp7AC; u32 sp7A8; u8 sp7A5; u8 sp7A4; - s32 sp7A0; + GXColor chan_amb_color; void* sp79C; psdisp_Tlut tlut_obj; GXTexObj sp764; - HSD_Particle* sp760; - HSD_Particle* sp75C; + HSD_Particle* sorted_particles; + HSD_Particle* non_edge_particles; psdisp_Mtx billboard_mtx; - GXTlutObj sp71C; f32 sp700; - GXColor sp6E0; - GXColor sp6DC; + GXTlutObj gx_tlut_obj; + s32 alpha_compare_mode; + s32 prev_tex_interp_near; GXColor sp6D8; GXColor sp6D4; GXColor sp6D0; @@ -1964,11 +1968,11 @@ void psDispParticles(u32 target_link, u32 sw) /// @todo Recover this stack space from the original inline hierarchy. PAD_STACK(0x14); - var_r16 = 0; - var_r15 = 0; + alpha_compare_mode = 0; + prev_tex_interp_near = 0; sp7A5 = 0; sp7A4 = 0xFF; - sp7A0 = 1; + needs_setup = 1; if (sw == 0) { if (psFrameNum < 0xFFU) { psFrameNum += 1; @@ -1980,11 +1984,12 @@ void psDispParticles(u32 target_link, u32 sw) sp7B4 = 0; do { if (target_link & (1 << sp7B4)) { - particleSort(sp7B4, psFrameNum, &sp760, &sp75C); + particleSort(sp7B4, psFrameNum, &sorted_particles, + &non_edge_particles); if (sw == 1) { - pp = sp760; + pp = sorted_particles; } else { - pp = sp75C; + pp = non_edge_particles; } while (pp != NULL) { HSD_PSTexGroup* tex_group = NULL; @@ -2009,7 +2014,7 @@ void psDispParticles(u32 target_link, u32 sw) break; } if (!(pp->size < FLT_EPSILON)) { - if (sp7A0 != 0) { + if (needs_setup != 0) { sp79C = NULL; prevPointSize = -1; sp7B0 = NULL; @@ -2023,10 +2028,10 @@ void psDispParticles(u32 target_link, u32 sw) prevChanMat.r = prevChanMat.g = prevChanMat.b = 0xFF; prevChanAmb.r = prevChanAmb.g = prevChanAmb.b = 0xFF; prevChanMat.a = prevChanAmb.a = 0xFF; - sp6E0 = prevChanMat; - GXSetChanMatColor(GX_COLOR0A0, sp6E0); - sp6DC = prevChanAmb; - GXSetChanAmbColor(GX_COLOR0A0, sp6DC); + chan_mat_color = prevChanMat; + GXSetChanMatColor(GX_COLOR0A0, chan_mat_color); + chan_amb_color = prevChanAmb; + GXSetChanAmbColor(GX_COLOR0A0, chan_amb_color); psSetupTevInvalidState(); psSetupTevCommon(); psSetColor(&prevColorPrim, 0xFF); @@ -2057,7 +2062,7 @@ void psDispParticles(u32 target_link, u32 sw) psSetupVtxFormat(GX_VTXFMT3, true, false, GX_RGB565); psSetupVtxFormat(GX_VTXFMT4, false, true, GX_RGBA6); psSetupVtxFormat(GX_VTXFMT5, true, true, GX_RGBA6); - sp7A0 = 0; + needs_setup = 0; } blend_mode = (pp->kind >> 0x16U) & 3; @@ -2077,15 +2082,15 @@ void psDispParticles(u32 target_link, u32 sw) alpha0 = pp->aCmpParam1; alpha1 = pp->aCmpParam2; } - if ((var_r16 != pp->aCmpMode) || (sp7A5 != alpha0) || - (sp7A4 != alpha1)) + if ((alpha_compare_mode != pp->aCmpMode) || + (sp7A5 != alpha0) || (sp7A4 != alpha1)) { sp7A5 = alpha0; - var_r16 = pp->aCmpMode; + alpha_compare_mode = pp->aCmpMode; sp7A4 = alpha1; - GXSetAlphaCompare((var_r16 >> 3) & 7, sp7A5, - (var_r16 >> 6) & 3, var_r16 & 7, - sp7A4); + GXSetAlphaCompare((alpha_compare_mode >> 3) & 7, sp7A5, + (alpha_compare_mode >> 6) & 3, + alpha_compare_mode & 7, sp7A4); } psSetupTev((u32*) pp); @@ -2187,10 +2192,11 @@ void psDispParticles(u32 target_link, u32 sw) tlut_obj.tlut_name = GX_TLUT0; tlut_obj.n_entries = (fmt == GX_TF_C4) ? 0x10 : 0x100; - GXInitTlutObj(&sp71C, tlut, + GXInitTlutObj(&gx_tlut_obj, tlut, tlut_obj.fmt, tlut_obj.n_entries); - GXLoadTlut(&sp71C, tlut_obj.tlut_name); + GXLoadTlut(&gx_tlut_obj, + tlut_obj.tlut_name); sp7B0 = NULL; } } @@ -2220,19 +2226,25 @@ void psDispParticles(u32 target_link, u32 sw) HSD_ASSERT(0x8AA, 0); break; } - var_r15 = pp->kind & TexInterpNear; + prev_tex_interp_near = pp->kind & TexInterpNear; GXInitTexObjLOD( - &sp764, (var_r15 != 0) ? GX_NEAR : GX_LINEAR, + &sp764, + (prev_tex_interp_near != 0) ? GX_NEAR + : GX_LINEAR, (pp->kind & TexInterpNear) ? GX_NEAR : GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); GXLoadTexObj(&sp764, GX_TEXMAP0); } - if ((u32) var_r15 != (pp->kind & TexInterpNear)) { - var_r15 = pp->kind & TexInterpNear; + if ((u32) prev_tex_interp_near != + (pp->kind & TexInterpNear)) + { + prev_tex_interp_near = pp->kind & TexInterpNear; GXInitTexObjLOD( - &sp764, (var_r15 != 0) ? GX_NEAR : GX_LINEAR, + &sp764, + (prev_tex_interp_near != 0) ? GX_NEAR + : GX_LINEAR, (s32) (pp->kind & TexInterpNear) != 0 ? GX_NEAR : GX_LINEAR, @@ -2265,7 +2277,7 @@ void psDispParticles(u32 target_link, u32 sw) } sp7B4 += 1; } while (sp7B4 < 0x10); - if (sp7A0 == 0) { + if (needs_setup == 0) { HSD_StateInvalidate(-1); } }