Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhardcode many for loop conditions #1179

Merged
merged 8 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions include/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,17 @@ typedef struct RadiatingEnergyOrbFXData {
/* 0x30 */ f32 unk_30;
} RadiatingEnergyOrbFXData; // size = 0x34

#define UNK_ARRAY_SIZE_1 4

typedef struct MotionBlurFlameFXData {
/* 0x00 */ s32 unk_00;
/* 0x04 */ f32 unk_04;
/* 0x08 */ f32 unk_08;
/* 0x0C */ f32 unk_0C;
/* 0x10 */ Vec3f pos;
/* 0x1C */ f32 unk_1C[4];
/* 0x2C */ f32 unk_2C[4];
/* 0x3C */ f32 unk_3C[4];
/* 0x1C */ f32 unk_1C[UNK_ARRAY_SIZE_1];
/* 0x2C */ f32 unk_2C[UNK_ARRAY_SIZE_1];
/* 0x3C */ f32 unk_3C[UNK_ARRAY_SIZE_1];
/* 0x4C */ s32 unk_4C;
/* 0x50 */ s32 unk_50;
/* 0x54 */ s32 unk_54;
Expand Down Expand Up @@ -2131,6 +2133,8 @@ typedef struct Effect75FXData {
/* 0x7C */ f32 unk_7C;
} Effect75FXData; // size = 0x80

#define ROCKET_BUF_SIZE 4

typedef struct FireworkRocketFXData {
/* 0x00 */ s32 variation;
/* 0x04 */ Vec3f pos;
Expand All @@ -2148,12 +2152,12 @@ typedef struct FireworkRocketFXData {
/* 0x44 */ f32 radius;
/* 0x48 */ f32 maxRadius;
/* 0x4C */ s32 isExploded;
/* 0x50 */ f32 rocketX[4];
/* 0x60 */ f32 rocketY[4];
/* 0x70 */ f32 rocketZ[4];
/* 0x80 */ f32 rocketVelX[4];
/* 0x90 */ f32 rocketVelY[4];
/* 0xA0 */ f32 rocketVelZ[4];
/* 0x50 */ f32 rocketX[ROCKET_BUF_SIZE];
/* 0x60 */ f32 rocketY[ROCKET_BUF_SIZE];
/* 0x70 */ f32 rocketZ[ROCKET_BUF_SIZE];
/* 0x80 */ f32 rocketVelX[ROCKET_BUF_SIZE];
/* 0x90 */ f32 rocketVelY[ROCKET_BUF_SIZE];
/* 0xA0 */ f32 rocketVelZ[ROCKET_BUF_SIZE];
} FireworkRocketFXData; // size = 0xB0

typedef struct PeachStarBeamSpirit {
Expand Down
22 changes: 12 additions & 10 deletions include/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,21 @@ typedef struct PadlockData {
/* 0x18 */ Gfx* shackleGfx;
} PadlockData; // size = 0x1C

#define FRAGMENT_BUF_SIZE 13

typedef struct BoardedFloorData {
/* 0x000 */ Gfx** fragmentsGfx;
/* 0x004 */ f32 inititalY;
/* 0x008 */ s8 fragmentRebounds[13];
/* 0x015 */ u8 fragmentMoveAngle[13];
/* 0x022 */ u8 fragmentRotX[13];
/* 0x02F */ u8 fragmentRotY[13];
/* 0x03C */ u8 fragmentLateralSpeed[13];
/* 0x04C */ f32 fragmentRotSpeed[13];
/* 0x080 */ f32 fragmentPosX[13];
/* 0x0B4 */ f32 fragmentPosY[13];
/* 0x0E8 */ f32 fragmentPosZ[13];
/* 0x11C */ f32 fragmentFallSpeed[13];
/* 0x008 */ s8 fragmentRebounds[FRAGMENT_BUF_SIZE];
/* 0x015 */ u8 fragmentMoveAngle[FRAGMENT_BUF_SIZE];
/* 0x022 */ u8 fragmentRotX[FRAGMENT_BUF_SIZE];
/* 0x02F */ u8 fragmentRotY[FRAGMENT_BUF_SIZE];
/* 0x03C */ u8 fragmentLateralSpeed[FRAGMENT_BUF_SIZE];
/* 0x04C */ f32 fragmentRotSpeed[FRAGMENT_BUF_SIZE];
/* 0x080 */ f32 fragmentPosX[FRAGMENT_BUF_SIZE];
/* 0x0B4 */ f32 fragmentPosY[FRAGMENT_BUF_SIZE];
/* 0x0E8 */ f32 fragmentPosZ[FRAGMENT_BUF_SIZE];
/* 0x11C */ f32 fragmentFallSpeed[FRAGMENT_BUF_SIZE];
} BoardedFloorData; // size = 0x150

typedef struct BombableRockData {
Expand Down
8 changes: 4 additions & 4 deletions src/23680.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void spawn_drops(Enemy* enemy) {
if (drops->itemDropChance > rand_int(100)) {
tempMax = 0;

for (i = 0; i < 8; i++) {
for (i = 0; i < ARRAY_COUNT(drops->itemDrops) / 3; i++) {
if (drops->itemDrops[3 * i] != 0) {
tempMax += drops->itemDrops[3 * i + 1];
} else {
Expand All @@ -63,7 +63,7 @@ void spawn_drops(Enemy* enemy) {
dropCount = rand_int(tempMax);
itemToDrop = ITEM_NONE;

for (i = 0; i < 8; i++) {
for (i = 0; i < ARRAY_COUNT(drops->itemDrops) / 3; i++) {
if (drops->itemDrops[3 * i] == 0) {
break;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ void spawn_drops(Enemy* enemy) {
itemToDrop = ITEM_NONE;
fraction = playerData->curHP / (f32) playerData->curMaxHP;

for (i = 0; i < 8; i++) {
for (i = 0; i < ARRAY_COUNT(drops->itemDrops) / 3; i++) {
attempts = drops->heartDrops[4 * i];
threshold = drops->heartDrops[4 * i + 1];
attempts /= 32767.0f;
Expand Down Expand Up @@ -176,7 +176,7 @@ void spawn_drops(Enemy* enemy) {
itemToDrop = ITEM_NONE;
fraction = playerData->curFP / (f32) playerData->curMaxFP;

for (i = 0; i < 8; i++) {
for (i = 0; i < ARRAY_COUNT(drops->itemDrops) / 3; i++) {
attempts = drops->flowerDrops[4 * i + 0];
threshold = drops->flowerDrops[4 * i + 1];
attempts /= 32767.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/8a160_len_700.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void func_800F0D5C(void) {
Unk8a160Outer* outer = &D_8010D000[0];
s32 i;

for (i = 0; i < 1; i++) {
for (i = 0; i < ARRAY_COUNT(D_8010D000); i++) {
outer[i].subs[0].alive = FALSE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/audio/28910_len_5090.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void au_bgm_update_main(BGMPlayer* player) {
BGMDrumInfo* drum = &player->drumsInfo[i];
player->drums[i] = drum;
}
for (; i < 12; i++) {
for (; i < ARRAY_COUNT(player->drums); i++) {
player->drums[i] = player->drums[0];
}
} else {
Expand Down Expand Up @@ -1799,7 +1799,7 @@ void au_BGMCmd_FF(BGMPlayer* player, BGMPlayerTrack* track) {
if (arg1 == 0) {
if (track->unk_4E != 0) {
track->unk_4E = 0;
for (i = 0; i < 16; i++) {
for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
BGMPlayerTrack* otherTrack = &player->tracks[i];
if (player->proxMixVolume == 0x7F) {
if (otherTrack->unk_4F != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/audio/2e230_len_2190.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void au_engine_init(s32 outputRate) {
globals->unk_globals_6C[i].unk_5 = 0;
}

for (i = 0; i < 4; i++) {
for (i = 0; i < ARRAY_COUNT(globals->effectChanges); i++) {
globals->effectChanges[i].type = AU_FX_NONE;
globals->effectChanges[i].changed = FALSE;
}
Expand Down
6 changes: 3 additions & 3 deletions src/audio/e0b30_len_b80.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ void bgm_reset_volume(void) {

//TODO refactor out constants
void bgm_update_music_settings(void) {
MusicSettings* music = &gMusicSettings[0];
MusicSettings* music = gMusicSettings;
s32 i = 0;
s16 state2 = 2;
s16 flag4 = MUSIC_SETTINGS_FLAG_4;
s32 flags;

for (i; i < 2; i++, music++) {
for (i; i < ARRAY_COUNT(gMusicSettings); i++, music++) {
switch (music->state) {
case 0:
break;
Expand Down Expand Up @@ -360,7 +360,7 @@ s32 func_8014AD40(void) {
MusicSettings* settings = gMusicSettings;
s32 i;

for (i = 0; i < 2; i++, settings++) {
for (i = 0; i < ARRAY_COUNT(gMusicSettings); i++, settings++) {
if (!(settings->flags & MUSIC_SETTINGS_FLAG_1)) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/audio/reverb.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void _init_lpfilter(AuLowPass* lp) {
timeConstant = timeConstant >> 1;
lp->fgain = SCALE - timeConstant;

for (i = 0; i < 8; i++) {
for (i = 0; i < ARRAY_COUNT(lp->fccoef) / 2; i++) {
lp->fccoef[i] = 0;
}

Expand All @@ -125,7 +125,7 @@ static void _init_lpfilter(AuLowPass* lp) {
// ith value is 16384 * (timeConstant / 16384)^(i-7)
// ex: i = 9 --> timeConstant^2 / 16384
attenuation = ((f64)timeConstant / SCALE);
for (i = 9; i < 16; i++) {
for (i = 9; i < ARRAY_COUNT(lp->fccoef); i++) {
attenuation *= ((f64)timeConstant /SCALE);
lp->fccoef[i] = attenuation * SCALE;
}
Expand Down
44 changes: 24 additions & 20 deletions src/background_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ s32 gfx_frame_filter_pass_0(const u16* frameBuffer0, const u16* frameBuffer1, s3
}

void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u16* out) {
#define RGBA_BUF_SIZE 32
Color_RGBA8 sp0;
Color_RGBA8 sp8;
Color_RGBA8 final;
u8 rs[0x20];
u8 gs[0x20];
u8 bs[0x20];
u8 rs[RGBA_BUF_SIZE];
u8 gs[RGBA_BUF_SIZE];
u8 bs[RGBA_BUF_SIZE];
s32 i;

sp8 = filterBuf1;
sp0 = filterBuf1;

for (i = 0; i < ARRAY_COUNT(rs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
rs[i] = 0;
gs[i] = 0;
bs[i] = 0;
Expand All @@ -71,13 +72,13 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
}
}

for (i = 0; i < ARRAY_COUNT(rs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
if (rs[i] != 0) {
rs[i]--;
break;
}
}
for (; i < ARRAY_COUNT(rs); i++) {
for (; i < RGBA_BUF_SIZE; i++) {
if (rs[i] != 0) {
break;
}
Expand All @@ -86,13 +87,13 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
sp0.r = i;
}

for (i = 0; i < ARRAY_COUNT(gs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
if (gs[i] != 0) {
gs[i]--;
break;
}
}
for (; i < ARRAY_COUNT(gs); i++) {
for (; i < RGBA_BUF_SIZE; i++) {
if (gs[i] != 0) {
break;
}
Expand All @@ -101,13 +102,13 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
sp0.g = i;
}

for (i = 0; i < ARRAY_COUNT(bs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
if (bs[i] != 0) {
bs[i]--;
break;
}
}
for (; i < ARRAY_COUNT(bs); i++) {
for (; i < RGBA_BUF_SIZE; i++) {
if (bs[i] != 0) {
break;
}
Expand All @@ -116,7 +117,7 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
sp0.b = i;
}

for (i = ARRAY_COUNT(rs) - 1; i >= 0; i--) {
for (i = RGBA_BUF_SIZE - 1; i >= 0; i--) {
if (rs[i] != 0) {
break;
}
Expand All @@ -125,7 +126,7 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
sp8.r = i;
}

for (i = ARRAY_COUNT(gs) - 1; i >= 0; i--) {
for (i = RGBA_BUF_SIZE - 1; i >= 0; i--) {
if (gs[i] != 0) {
break;
}
Expand All @@ -134,7 +135,7 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
sp8.g = i;
}

for (i = ARRAY_COUNT(bs) - 1; i >= 0; i--) {
for (i = RGBA_BUF_SIZE - 1; i >= 0; i--) {
if (bs[i] != 0) {
break;
}
Expand All @@ -152,17 +153,19 @@ void gfx_frame_filter_pass_1(Color_RGBA8* filterBuf0, Color_RGBA8 filterBuf1, u1
final.b = ((filterBuf1.b * filterBuf1.a) + (final.b * (8 - filterBuf1.a))) >> 3;

*out = (final.r << 11) + (final.g << 6) + (final.b << 1) + 1;
#undef RGBA_BUF_SIZE
}

void func_80027600(Color_RGBA8* arg0, s16* out) {
#define RGBA_BUF_SIZE 32
Color_RGBA8 final;
u8 rs[0x20];
u8 gs[0x20];
u8 bs[0x20];
u8 rs[RGBA_BUF_SIZE];
u8 gs[RGBA_BUF_SIZE];
u8 bs[RGBA_BUF_SIZE];
s32 i;
s32 sum;

for (i = 0; i < ARRAY_COUNT(rs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
rs[i] = 0;
gs[i] = 0;
bs[i] = 0;
Expand All @@ -175,7 +178,7 @@ void func_80027600(Color_RGBA8* arg0, s16* out) {
}

sum = 0;
for (i = 0; i < ARRAY_COUNT(rs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
sum += rs[i];
if (sum >= 5) {
break;
Expand All @@ -184,7 +187,7 @@ void func_80027600(Color_RGBA8* arg0, s16* out) {
final.r = i;

sum = 0;
for (i = 0; i < ARRAY_COUNT(gs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
sum += gs[i];
if (sum >= 5) {
break;
Expand All @@ -193,7 +196,7 @@ void func_80027600(Color_RGBA8* arg0, s16* out) {
final.g = i;

sum = 0;
for (i = 0; i < ARRAY_COUNT(bs); i++) {
for (i = 0; i < RGBA_BUF_SIZE; i++) {
sum += bs[i];
if (sum >= 5) {
break;
Expand All @@ -202,6 +205,7 @@ void func_80027600(Color_RGBA8* arg0, s16* out) {
final.b = i;

*out = (final.r << 11) + (final.g << 6) + (final.b << 1) + 1;
#undef RGBA_BUF_SIZE
}

void func_80027774(u16* frameBuffer0, u16* frameBuffer1, u16* zBuffer) {
Expand Down
6 changes: 3 additions & 3 deletions src/battle/action_cmd/tidal_wave.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ API_CALLABLE(N(init)) {
hud_element_set_render_depth(id, 0);
hud_element_set_flags(id, HUD_ELEMENT_FLAG_80 | HUD_ELEMENT_FLAG_DISABLED);

for (i = 1; i < 15; i++) {
for (i = 1; i < ARRAY_COUNT(actionCommandStatus->hudElements) - 1; i++) {
id = hud_element_create(&HES_AButton);
actionCommandStatus->hudElements[i] = id;
hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
Expand Down Expand Up @@ -298,7 +298,7 @@ void N(update)(void) {
void N(draw)(void) {
s32 i;

for (i = 1; i < 15; i++) {
for (i = 1; i < ARRAY_COUNT(gActionCommandStatus.hudElements) - 1; i++) {
hud_element_draw_clipped(gActionCommandStatus.hudElements[i]);
}
}
Expand All @@ -308,7 +308,7 @@ void N(free)(void) {

hud_element_free(gActionCommandStatus.hudElements[0]);

for (i = 1; i < 15; i++) {
for (i = 1; i < ARRAY_COUNT(gActionCommandStatus.hudElements) - 1; i++) {
hud_element_free(gActionCommandStatus.hudElements[i]);
}
}
Loading
Loading