From ad2b1bc0c3d85cb34b70e1750507a12b462c2ac7 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 10 Feb 2022 18:59:54 +0200 Subject: [PATCH] Remove boolcast uses from code --- include/global.h | 1 - src/enemy/eyegore.c | 3 +-- src/enemy/helmasaur.c | 7 +++++-- src/enemy/octorokBoss.c | 2 +- src/main.c | 4 +--- src/npc/carpenter.c | 5 +++-- src/npc/castleMaid.c | 8 +++++++- src/npc/clothesRack.c | 6 ++++-- src/npc/farmers.c | 7 +++++-- src/npc/forestMinish.c | 14 +++++++------- src/npc/goron.c | 3 +-- src/npc/goronMerchant.c | 7 ++++--- src/npc/guard.c | 16 ++++++---------- src/npc/librarians.c | 8 +++++--- src/npc/mountainMinish.c | 8 +++++--- src/npc/mutoh.c | 6 +++--- src/npc/sittingPerson.c | 7 +++++-- src/npc/sturgeon.c | 7 +++++-- src/npc/townMinish.c | 6 +++--- src/npc/windTribespeople.c | 24 ++++++++++++------------ src/object/lightableSwitch.c | 8 ++++---- src/roomInit.c | 6 ++++-- 22 files changed, 91 insertions(+), 72 deletions(-) diff --git a/include/global.h b/include/global.h index 8521b77c..5664b1f5 100644 --- a/include/global.h +++ b/include/global.h @@ -65,7 +65,6 @@ #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) >= (b) ? (a) : (b)) -#define BOOLCAST(x) ((-(x) | (x)) >> 31) #define static_assert(cond) extern char assertion[(cond) ? 1 : -1] #define super (&this->base) diff --git a/src/enemy/eyegore.c b/src/enemy/eyegore.c index 4f2d81f8..23acd17f 100644 --- a/src/enemy/eyegore.c +++ b/src/enemy/eyegore.c @@ -358,8 +358,7 @@ NONMATCH("asm/non_matching/eyegore/sub_08031024.inc", void sub_08031024(EyegoreE u32 uVar8; u32 tmp, tmp2; - u32 res = sub_08049FDC(super, 1); - boolresult = BOOLCAST(res); + boolresult = sub_08049FDC(super, 1) != 0; if (this->unk_79 == 0) { if (boolresult != 0) { super->direction = CalculateDirectionTo(super->x.HALF.HI + super->hitbox->offset_x, diff --git a/src/enemy/helmasaur.c b/src/enemy/helmasaur.c index f0485770..fc90c307 100644 --- a/src/enemy/helmasaur.c +++ b/src/enemy/helmasaur.c @@ -342,8 +342,11 @@ bool32 sub_0802C0E8(Entity* this) { Entity* ent = this->collisionLayer == 2 ? &gUnk_0200D654 : &gUnk_02027EB4; u32 ret = FALSE; if (!sub_0806FC24(TILE(x, y), 9)) { - u32 tmp = sub_080AE4CC(ent, x, y, 0); - ret = BOOLCAST(tmp); + if (sub_080AE4CC(ent, x, y, 0)) { + ret = 1; + } else { + ret = 0; + } } return ret; } diff --git a/src/enemy/octorokBoss.c b/src/enemy/octorokBoss.c index bdbd9144..4af9d5b8 100644 --- a/src/enemy/octorokBoss.c +++ b/src/enemy/octorokBoss.c @@ -805,7 +805,7 @@ void OctorokBoss_Action1_ChargeAttack(Entity* this) { ProcessMovement(this); knockbackCondition = 0; if ((this->direction != 0) && (this->direction != 0x10)) { - knockbackCondition = BOOLCAST((u32)this->collisions & 0xee00); + knockbackCondition = ((u32)this->collisions & 0xee00) != 0; } if (((this->direction != 0x18) && (this->direction != 8)) && ((this->collisions & 0xee) != 0)) { knockbackCondition = 1; diff --git a/src/main.c b/src/main.c index b1bb1c5a..235a8ef9 100644 --- a/src/main.c +++ b/src/main.c @@ -171,7 +171,6 @@ const Defaults sDefaultSettings = { // single misplaced ldr NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { - u32 temp; u32 b; if (!CheckHeaderValid()) { @@ -188,8 +187,7 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { } } - temp = gUnk_02000010.signature ^ SIGNATURE; - b = BOOLCAST(temp); + b = (gUnk_02000010.signature ^ SIGNATURE) != 0; if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) { b = TRUE; diff --git a/src/npc/carpenter.c b/src/npc/carpenter.c index b2341e33..aa016c84 100644 --- a/src/npc/carpenter.c +++ b/src/npc/carpenter.c @@ -69,8 +69,9 @@ void sub_080672C8(Entity* this) { u32 dialog = 0; u32 tmp; if (GetInventoryValue(0x11) == 0) { - tmp = CheckGlobalFlag(TABIDACHI); - dialog = BOOLCAST(tmp); + if (CheckGlobalFlag(TABIDACHI)) { + dialog = 1; + } } MessageNoOverlap(gUnk_08110CE8[(dialog * 2 + this->type * 6) / 2], this); } diff --git a/src/npc/castleMaid.c b/src/npc/castleMaid.c index 154d1b0c..81483829 100644 --- a/src/npc/castleMaid.c +++ b/src/npc/castleMaid.c @@ -49,13 +49,19 @@ void Maid_Head(Entity* this) { void sub_08064570(Entity* this) { u32 tmp; u32 tmp2; + u32 tmp3; SpriteLoadData* data; switch (this->action) { case 0: tmp = this->id; tmp ^= 0x16; - data = &gUnk_0810F874[BOOLCAST(tmp) * 3]; + if (tmp) { + tmp3 = 1; + } else { + tmp3 = 0; + } + data = &gUnk_0810F874[tmp3 * 3]; if (LoadExtraSpriteData(this, data) == 0) { return; } diff --git a/src/npc/clothesRack.c b/src/npc/clothesRack.c index f616eccc..5c6c0831 100644 --- a/src/npc/clothesRack.c +++ b/src/npc/clothesRack.c @@ -13,8 +13,10 @@ void sub_0806DD90(Entity* this) { u32 y; this->action = 1; - uVar1 = CheckGlobalFlag(DRUG_1); - uVar2 = BOOLCAST(uVar1); + uVar2 = 0; + if (CheckGlobalFlag(DRUG_1)) { + uVar2 = 1; + } if (CheckGlobalFlag(DRUG_2) != 0) { uVar2 = 2; } diff --git a/src/npc/farmers.c b/src/npc/farmers.c index d3c9d94c..06dea3c3 100644 --- a/src/npc/farmers.c +++ b/src/npc/farmers.c @@ -22,8 +22,11 @@ void Farmers_Head(Entity* this) { } void sub_0806BC94(Entity* this, ScriptExecutionContext* context) { - InitializeAnimation(this, context->intVariable + (BOOLCAST(this->spriteSettings.flipX) & 8U) + - (this->animationState >> 1)); + u32 offset = 0; + if (this->spriteSettings.flipX) { + offset = 8; + } + InitializeAnimation(this, context->intVariable + offset + (this->animationState >> 1)); } void sub_0806BCB8(Entity* this) { diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c index 23de6af6..ea0b9bb7 100644 --- a/src/npc/forestMinish.c +++ b/src/npc/forestMinish.c @@ -130,14 +130,14 @@ void sub_08060158(Entity* this) { } void sub_080601D4(Entity* this) { - u32 temp; u32 uVar2; if (CheckGlobalFlag(LV3_CLEAR) == 0) { uVar2 = 2; + } else if (CheckKinstoneFused(0x17)) { + uVar2 = 1; } else { - temp = CheckKinstoneFused(0x17); - uVar2 = BOOLCAST(temp); + uVar2 = 0; } MessageNoOverlap(gUnk_0810A354[uVar2], this); } @@ -147,12 +147,12 @@ void sub_08060208(Entity* this) { } void sub_0806021C(Entity* this) { - u32 uVar1; - u32 uVar2; + u32 uVar2 = 0; // jabber nut - uVar1 = GetInventoryValue(0x5B); - uVar2 = BOOLCAST(uVar1); + if (GetInventoryValue(0x5B)) { + uVar2 = 1; + } // earth element if (GetInventoryValue(0x40)) { diff --git a/src/npc/goron.c b/src/npc/goron.c index ab17ce82..04602ffd 100644 --- a/src/npc/goron.c +++ b/src/npc/goron.c @@ -65,8 +65,7 @@ void sub_08069428(Entity* this, s32 offsetX, bool32 createFx65); void sub_080693D0(Entity* this) { sub_0807DD94(this, NULL); if (this->animIndex == 8) { - u32 var0 = this->field_0x82.HWORD & 0xF; - bool32 createFx65 = BOOLCAST(var0); // = !var0 + bool32 createFx65 = (this->field_0x82.HWORD & 0xF) != 0; if (this->frame == 1) { this->frame = 0; diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c index 8862610f..07f6117f 100644 --- a/src/npc/goronMerchant.c +++ b/src/npc/goronMerchant.c @@ -99,7 +99,6 @@ void sub_080696B0(void) { static u32 GoronMerchant_GetSalePrice(Entity* this) { u32 restockCount; - u32 temp; u32 kinstoneType; s32 itemForSale; @@ -113,8 +112,10 @@ static u32 GoronMerchant_GetSalePrice(Entity* this) { kinstoneType = 2; } - temp = CheckGlobalFlag(GORON_KAKERA_LV2); - restockCount = BOOLCAST(temp); + restockCount = 0; + if (CheckGlobalFlag(GORON_KAKERA_LV2)) { + restockCount = 1; + } if (CheckGlobalFlag(GORON_KAKERA_LV3)) { restockCount = 2; diff --git a/src/npc/guard.c b/src/npc/guard.c index f22487c8..27496fe3 100644 --- a/src/npc/guard.c +++ b/src/npc/guard.c @@ -46,15 +46,13 @@ void sub_08063D24(Entity* this) { void sub_08063D44(Entity* this) { Entity* ent; - u32 temp, idx; + u32 idx; if (gEntCount > 0x46) return; - temp = this->id; - temp ^= 0x15; - idx = BOOLCAST(temp) * 4; - if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx])) + idx = (this->id ^ 0x15) ? 1 : 0; + if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx * 4])) return; InitializeAnimation(this, 4); @@ -111,13 +109,11 @@ void sub_08063E6C(Entity* this) { } void sub_08063E90(Entity* this) { - u32 temp, idx; + u32 idx; u32 unk; - temp = this->id; - temp ^= 0x15; - idx = BOOLCAST(temp) * 4; - if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx])) + idx = (this->id ^ 0x15) ? 1 : 0; + if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx * 4])) return; this->action++; diff --git a/src/npc/librarians.c b/src/npc/librarians.c index 95d1fd2f..6013594c 100644 --- a/src/npc/librarians.c +++ b/src/npc/librarians.c @@ -48,12 +48,14 @@ void sub_0806BB7C(Entity* this, ScriptExecutionContext* context) { } void sub_0806BBB0(Entity* this) { - u32 flag; u32 tmp; if (GetInventoryValue(0x46) == 0) { - flag = CheckGlobalFlag(0x29); - tmp = BOOLCAST(flag); + if (CheckGlobalFlag(0x29)) { + tmp = 1; + } else { + tmp = 0; + } } else { tmp = 2; } diff --git a/src/npc/mountainMinish.c b/src/npc/mountainMinish.c index 90a370db..a3350db4 100644 --- a/src/npc/mountainMinish.c +++ b/src/npc/mountainMinish.c @@ -67,7 +67,6 @@ void sub_08068104(Entity* this) { ASM_FUNC("asm/non_matching/mountainMinish/sub_0806811C.inc", void sub_0806811C(Entity* this)) NONMATCH("asm/non_matching/mountainMinish/sub_08068190.inc", void sub_08068190(Entity* this)) { - u32 uVar1; u32 uVar2; u32 uVar3; @@ -75,8 +74,11 @@ NONMATCH("asm/non_matching/mountainMinish/sub_08068190.inc", void sub_08068190(E if (uVar3 > 8) { uVar3 = 8; } - uVar1 = CheckLocalFlag(0x7e); - uVar2 = BOOLCAST(uVar1); + + uVar2 = 0; + if (CheckLocalFlag(0x7e)) { + uVar2 = 1; + } if (GetInventoryValue(0x41) != 0) { uVar2 = 2; } diff --git a/src/npc/mutoh.c b/src/npc/mutoh.c index 7d0751c7..d314de7e 100644 --- a/src/npc/mutoh.c +++ b/src/npc/mutoh.c @@ -48,13 +48,13 @@ void Mutoh_Head(Entity* this) { } void sub_080670B4(Entity* this) { - u32 uVar1; u32 uVar2; uVar2 = 0; if (GetInventoryValue(0x11) == 0) { - uVar1 = CheckGlobalFlag(TABIDACHI); - uVar2 = BOOLCAST(uVar1); + if (CheckGlobalFlag(TABIDACHI)) { + uVar2 = 1; + } } MessageNoOverlap(gUnk_08110C0C[uVar2], this); } diff --git a/src/npc/sittingPerson.c b/src/npc/sittingPerson.c index 2cbe4e9b..de3a129f 100644 --- a/src/npc/sittingPerson.c +++ b/src/npc/sittingPerson.c @@ -67,8 +67,11 @@ void sub_08063830(Entity* this) { } void sub_08063850(Entity* this, ScriptExecutionContext* context) { - InitializeAnimation(this, context->intVariable + (BOOLCAST(this->spriteSettings.flipX) & 4U) + - (this->animationState >> 1)); + u32 offset = 0; + if (this->spriteSettings.flipX) { + offset = 4; + } + InitializeAnimation(this, context->intVariable + offset + (this->animationState >> 1)); } void sub_08063874(Entity* this) { diff --git a/src/npc/sturgeon.c b/src/npc/sturgeon.c index 60f77c1c..13ef24ab 100644 --- a/src/npc/sturgeon.c +++ b/src/npc/sturgeon.c @@ -94,8 +94,11 @@ void sub_08064CD8(Entity* this) { u32 flag; u32 tmp = 2; if (GetInventoryValue(0x46) == 0) { - flag = CheckLocalFlag(0x73); - tmp = BOOLCAST(flag); + if (CheckLocalFlag(0x73)) { + tmp = 1; + } else { + tmp = 0; + } } MessageNoOverlap(gUnk_0810FA54[tmp], this); } diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c index 96bc355e..5b30edc6 100644 --- a/src/npc/townMinish.c +++ b/src/npc/townMinish.c @@ -282,14 +282,14 @@ void sub_0806B064(Entity* this) { } void sub_0806B098(Entity* this) { - u32 f; int idx = 2; if (GetInventoryValue(0x46) == 0) { idx = 1; if (CheckGlobalFlag(MIZUKAKI_START)) { - f = CheckGlobalFlag(MIZUKAKI_HARIFALL); - idx = BOOLCAST(f); + if (!CheckGlobalFlag(MIZUKAKI_HARIFALL)) { + idx = 0; + } } } MessageNoOverlap(gUnk_08112C50[(this->type2 - 7) * 3 + idx], this); diff --git a/src/npc/windTribespeople.c b/src/npc/windTribespeople.c index ff20d96d..b342616e 100644 --- a/src/npc/windTribespeople.c +++ b/src/npc/windTribespeople.c @@ -137,19 +137,19 @@ void sub_0806C944(Entity* this) { } void sub_0806C978(Entity* this) { - u32 flag; - u32 flagAsBool; - flag = CheckGlobalFlag(0x58); - flagAsBool = BOOLCAST(flag); + u32 flagAsBool = 0; + if (CheckGlobalFlag(0x58)) { + flagAsBool = 1; + } MessageNoOverlap(gUnk_08113B12[flagAsBool], this); } void sub_0806C99C(Entity* this) { - s32 flag; - u32 flagAsBool; + u32 flagAsBool = 0; - flag = CheckGlobalFlag(0x58); - flagAsBool = BOOLCAST(flag) & 2; + if (CheckGlobalFlag(0x58)) { + flagAsBool = 2; + } if (CheckLocalFlag(99) != 0) { flagAsBool += 1; } @@ -165,10 +165,10 @@ void sub_0806C9D0(Entity* this) { } void sub_0806C9F8(Entity* this) { - u32 flag; - u32 flagAsBool; - flag = CheckGlobalFlag(0x58); - flagAsBool = BOOLCAST(flag); + u32 flagAsBool = 0; + if (CheckGlobalFlag(0x58)) { + flagAsBool = 1; + } MessageNoOverlap(gUnk_08113B22[flagAsBool], this); } diff --git a/src/object/lightableSwitch.c b/src/object/lightableSwitch.c index a8d9dffd..13dae7bc 100644 --- a/src/object/lightableSwitch.c +++ b/src/object/lightableSwitch.c @@ -54,11 +54,11 @@ void sub_0809EA80(Entity* this) { } void sub_0809EABC(Entity* this) { - bool32 anySet; - u32 f; + bool32 anySet = 0; - f = CheckFlags(this->field_0x86.HWORD); - anySet = BOOLCAST(f); + if (CheckFlags(this->field_0x86.HWORD)) { + anySet = 1; + } if (this->frameIndex != anySet) { this->frameIndex = anySet; } diff --git a/src/roomInit.c b/src/roomInit.c index fc86e9ca..456f318e 100644 --- a/src/roomInit.c +++ b/src/roomInit.c @@ -4531,8 +4531,10 @@ void sub_StateChange_SimonsSimulation_Main(void) { u32 r; u32 index; u32 tmp; - tmp = CheckGlobalFlag(LV4_CLEAR); - index = BOOLCAST(tmp); + index = 0; + if (CheckGlobalFlag(LV4_CLEAR)) { + index = 1; + } if (CheckGlobalFlag(LV5_CLEAR)) { index = 2; }