Remove boolcast uses from code

This commit is contained in:
Tal Hayon 2022-02-10 18:59:54 +02:00
parent 16d8e14488
commit ad2b1bc0c3
22 changed files with 91 additions and 72 deletions

View File

@ -65,7 +65,6 @@
#define min(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
#define max(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 static_assert(cond) extern char assertion[(cond) ? 1 : -1]
#define super (&this->base) #define super (&this->base)

View File

@ -358,8 +358,7 @@ NONMATCH("asm/non_matching/eyegore/sub_08031024.inc", void sub_08031024(EyegoreE
u32 uVar8; u32 uVar8;
u32 tmp, tmp2; u32 tmp, tmp2;
u32 res = sub_08049FDC(super, 1); boolresult = sub_08049FDC(super, 1) != 0;
boolresult = BOOLCAST(res);
if (this->unk_79 == 0) { if (this->unk_79 == 0) {
if (boolresult != 0) { if (boolresult != 0) {
super->direction = CalculateDirectionTo(super->x.HALF.HI + super->hitbox->offset_x, super->direction = CalculateDirectionTo(super->x.HALF.HI + super->hitbox->offset_x,

View File

@ -342,8 +342,11 @@ bool32 sub_0802C0E8(Entity* this) {
Entity* ent = this->collisionLayer == 2 ? &gUnk_0200D654 : &gUnk_02027EB4; Entity* ent = this->collisionLayer == 2 ? &gUnk_0200D654 : &gUnk_02027EB4;
u32 ret = FALSE; u32 ret = FALSE;
if (!sub_0806FC24(TILE(x, y), 9)) { if (!sub_0806FC24(TILE(x, y), 9)) {
u32 tmp = sub_080AE4CC(ent, x, y, 0); if (sub_080AE4CC(ent, x, y, 0)) {
ret = BOOLCAST(tmp); ret = 1;
} else {
ret = 0;
}
} }
return ret; return ret;
} }

View File

@ -805,7 +805,7 @@ void OctorokBoss_Action1_ChargeAttack(Entity* this) {
ProcessMovement(this); ProcessMovement(this);
knockbackCondition = 0; knockbackCondition = 0;
if ((this->direction != 0) && (this->direction != 0x10)) { 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)) { if (((this->direction != 0x18) && (this->direction != 8)) && ((this->collisions & 0xee) != 0)) {
knockbackCondition = 1; knockbackCondition = 1;

View File

@ -171,7 +171,6 @@ const Defaults sDefaultSettings = {
// single misplaced ldr // single misplaced ldr
NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) {
u32 temp;
u32 b; u32 b;
if (!CheckHeaderValid()) { if (!CheckHeaderValid()) {
@ -188,8 +187,7 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) {
} }
} }
temp = gUnk_02000010.signature ^ SIGNATURE; b = (gUnk_02000010.signature ^ SIGNATURE) != 0;
b = BOOLCAST(temp);
if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) { if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) {
b = TRUE; b = TRUE;

View File

@ -69,8 +69,9 @@ void sub_080672C8(Entity* this) {
u32 dialog = 0; u32 dialog = 0;
u32 tmp; u32 tmp;
if (GetInventoryValue(0x11) == 0) { if (GetInventoryValue(0x11) == 0) {
tmp = CheckGlobalFlag(TABIDACHI); if (CheckGlobalFlag(TABIDACHI)) {
dialog = BOOLCAST(tmp); dialog = 1;
}
} }
MessageNoOverlap(gUnk_08110CE8[(dialog * 2 + this->type * 6) / 2], this); MessageNoOverlap(gUnk_08110CE8[(dialog * 2 + this->type * 6) / 2], this);
} }

View File

@ -49,13 +49,19 @@ void Maid_Head(Entity* this) {
void sub_08064570(Entity* this) { void sub_08064570(Entity* this) {
u32 tmp; u32 tmp;
u32 tmp2; u32 tmp2;
u32 tmp3;
SpriteLoadData* data; SpriteLoadData* data;
switch (this->action) { switch (this->action) {
case 0: case 0:
tmp = this->id; tmp = this->id;
tmp ^= 0x16; 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) { if (LoadExtraSpriteData(this, data) == 0) {
return; return;
} }

View File

@ -13,8 +13,10 @@ void sub_0806DD90(Entity* this) {
u32 y; u32 y;
this->action = 1; this->action = 1;
uVar1 = CheckGlobalFlag(DRUG_1); uVar2 = 0;
uVar2 = BOOLCAST(uVar1); if (CheckGlobalFlag(DRUG_1)) {
uVar2 = 1;
}
if (CheckGlobalFlag(DRUG_2) != 0) { if (CheckGlobalFlag(DRUG_2) != 0) {
uVar2 = 2; uVar2 = 2;
} }

View File

@ -22,8 +22,11 @@ void Farmers_Head(Entity* this) {
} }
void sub_0806BC94(Entity* this, ScriptExecutionContext* context) { void sub_0806BC94(Entity* this, ScriptExecutionContext* context) {
InitializeAnimation(this, context->intVariable + (BOOLCAST(this->spriteSettings.flipX) & 8U) + u32 offset = 0;
(this->animationState >> 1)); if (this->spriteSettings.flipX) {
offset = 8;
}
InitializeAnimation(this, context->intVariable + offset + (this->animationState >> 1));
} }
void sub_0806BCB8(Entity* this) { void sub_0806BCB8(Entity* this) {

View File

@ -130,14 +130,14 @@ void sub_08060158(Entity* this) {
} }
void sub_080601D4(Entity* this) { void sub_080601D4(Entity* this) {
u32 temp;
u32 uVar2; u32 uVar2;
if (CheckGlobalFlag(LV3_CLEAR) == 0) { if (CheckGlobalFlag(LV3_CLEAR) == 0) {
uVar2 = 2; uVar2 = 2;
} else if (CheckKinstoneFused(0x17)) {
uVar2 = 1;
} else { } else {
temp = CheckKinstoneFused(0x17); uVar2 = 0;
uVar2 = BOOLCAST(temp);
} }
MessageNoOverlap(gUnk_0810A354[uVar2], this); MessageNoOverlap(gUnk_0810A354[uVar2], this);
} }
@ -147,12 +147,12 @@ void sub_08060208(Entity* this) {
} }
void sub_0806021C(Entity* this) { void sub_0806021C(Entity* this) {
u32 uVar1; u32 uVar2 = 0;
u32 uVar2;
// jabber nut // jabber nut
uVar1 = GetInventoryValue(0x5B); if (GetInventoryValue(0x5B)) {
uVar2 = BOOLCAST(uVar1); uVar2 = 1;
}
// earth element // earth element
if (GetInventoryValue(0x40)) { if (GetInventoryValue(0x40)) {

View File

@ -65,8 +65,7 @@ void sub_08069428(Entity* this, s32 offsetX, bool32 createFx65);
void sub_080693D0(Entity* this) { void sub_080693D0(Entity* this) {
sub_0807DD94(this, NULL); sub_0807DD94(this, NULL);
if (this->animIndex == 8) { if (this->animIndex == 8) {
u32 var0 = this->field_0x82.HWORD & 0xF; bool32 createFx65 = (this->field_0x82.HWORD & 0xF) != 0;
bool32 createFx65 = BOOLCAST(var0); // = !var0
if (this->frame == 1) { if (this->frame == 1) {
this->frame = 0; this->frame = 0;

View File

@ -99,7 +99,6 @@ void sub_080696B0(void) {
static u32 GoronMerchant_GetSalePrice(Entity* this) { static u32 GoronMerchant_GetSalePrice(Entity* this) {
u32 restockCount; u32 restockCount;
u32 temp;
u32 kinstoneType; u32 kinstoneType;
s32 itemForSale; s32 itemForSale;
@ -113,8 +112,10 @@ static u32 GoronMerchant_GetSalePrice(Entity* this) {
kinstoneType = 2; kinstoneType = 2;
} }
temp = CheckGlobalFlag(GORON_KAKERA_LV2); restockCount = 0;
restockCount = BOOLCAST(temp); if (CheckGlobalFlag(GORON_KAKERA_LV2)) {
restockCount = 1;
}
if (CheckGlobalFlag(GORON_KAKERA_LV3)) { if (CheckGlobalFlag(GORON_KAKERA_LV3)) {
restockCount = 2; restockCount = 2;

View File

@ -46,15 +46,13 @@ void sub_08063D24(Entity* this) {
void sub_08063D44(Entity* this) { void sub_08063D44(Entity* this) {
Entity* ent; Entity* ent;
u32 temp, idx; u32 idx;
if (gEntCount > 0x46) if (gEntCount > 0x46)
return; return;
temp = this->id; idx = (this->id ^ 0x15) ? 1 : 0;
temp ^= 0x15; if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx * 4]))
idx = BOOLCAST(temp) * 4;
if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx]))
return; return;
InitializeAnimation(this, 4); InitializeAnimation(this, 4);
@ -111,13 +109,11 @@ void sub_08063E6C(Entity* this) {
} }
void sub_08063E90(Entity* this) { void sub_08063E90(Entity* this) {
u32 temp, idx; u32 idx;
u32 unk; u32 unk;
temp = this->id; idx = (this->id ^ 0x15) ? 1 : 0;
temp ^= 0x15; if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx * 4]))
idx = BOOLCAST(temp) * 4;
if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx]))
return; return;
this->action++; this->action++;

View File

@ -48,12 +48,14 @@ void sub_0806BB7C(Entity* this, ScriptExecutionContext* context) {
} }
void sub_0806BBB0(Entity* this) { void sub_0806BBB0(Entity* this) {
u32 flag;
u32 tmp; u32 tmp;
if (GetInventoryValue(0x46) == 0) { if (GetInventoryValue(0x46) == 0) {
flag = CheckGlobalFlag(0x29); if (CheckGlobalFlag(0x29)) {
tmp = BOOLCAST(flag); tmp = 1;
} else {
tmp = 0;
}
} else { } else {
tmp = 2; tmp = 2;
} }

View File

@ -67,7 +67,6 @@ void sub_08068104(Entity* this) {
ASM_FUNC("asm/non_matching/mountainMinish/sub_0806811C.inc", void sub_0806811C(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)) { NONMATCH("asm/non_matching/mountainMinish/sub_08068190.inc", void sub_08068190(Entity* this)) {
u32 uVar1;
u32 uVar2; u32 uVar2;
u32 uVar3; u32 uVar3;
@ -75,8 +74,11 @@ NONMATCH("asm/non_matching/mountainMinish/sub_08068190.inc", void sub_08068190(E
if (uVar3 > 8) { if (uVar3 > 8) {
uVar3 = 8; uVar3 = 8;
} }
uVar1 = CheckLocalFlag(0x7e);
uVar2 = BOOLCAST(uVar1); uVar2 = 0;
if (CheckLocalFlag(0x7e)) {
uVar2 = 1;
}
if (GetInventoryValue(0x41) != 0) { if (GetInventoryValue(0x41) != 0) {
uVar2 = 2; uVar2 = 2;
} }

View File

@ -48,13 +48,13 @@ void Mutoh_Head(Entity* this) {
} }
void sub_080670B4(Entity* this) { void sub_080670B4(Entity* this) {
u32 uVar1;
u32 uVar2; u32 uVar2;
uVar2 = 0; uVar2 = 0;
if (GetInventoryValue(0x11) == 0) { if (GetInventoryValue(0x11) == 0) {
uVar1 = CheckGlobalFlag(TABIDACHI); if (CheckGlobalFlag(TABIDACHI)) {
uVar2 = BOOLCAST(uVar1); uVar2 = 1;
}
} }
MessageNoOverlap(gUnk_08110C0C[uVar2], this); MessageNoOverlap(gUnk_08110C0C[uVar2], this);
} }

View File

@ -67,8 +67,11 @@ void sub_08063830(Entity* this) {
} }
void sub_08063850(Entity* this, ScriptExecutionContext* context) { void sub_08063850(Entity* this, ScriptExecutionContext* context) {
InitializeAnimation(this, context->intVariable + (BOOLCAST(this->spriteSettings.flipX) & 4U) + u32 offset = 0;
(this->animationState >> 1)); if (this->spriteSettings.flipX) {
offset = 4;
}
InitializeAnimation(this, context->intVariable + offset + (this->animationState >> 1));
} }
void sub_08063874(Entity* this) { void sub_08063874(Entity* this) {

View File

@ -94,8 +94,11 @@ void sub_08064CD8(Entity* this) {
u32 flag; u32 flag;
u32 tmp = 2; u32 tmp = 2;
if (GetInventoryValue(0x46) == 0) { if (GetInventoryValue(0x46) == 0) {
flag = CheckLocalFlag(0x73); if (CheckLocalFlag(0x73)) {
tmp = BOOLCAST(flag); tmp = 1;
} else {
tmp = 0;
}
} }
MessageNoOverlap(gUnk_0810FA54[tmp], this); MessageNoOverlap(gUnk_0810FA54[tmp], this);
} }

View File

@ -282,14 +282,14 @@ void sub_0806B064(Entity* this) {
} }
void sub_0806B098(Entity* this) { void sub_0806B098(Entity* this) {
u32 f;
int idx = 2; int idx = 2;
if (GetInventoryValue(0x46) == 0) { if (GetInventoryValue(0x46) == 0) {
idx = 1; idx = 1;
if (CheckGlobalFlag(MIZUKAKI_START)) { if (CheckGlobalFlag(MIZUKAKI_START)) {
f = CheckGlobalFlag(MIZUKAKI_HARIFALL); if (!CheckGlobalFlag(MIZUKAKI_HARIFALL)) {
idx = BOOLCAST(f); idx = 0;
}
} }
} }
MessageNoOverlap(gUnk_08112C50[(this->type2 - 7) * 3 + idx], this); MessageNoOverlap(gUnk_08112C50[(this->type2 - 7) * 3 + idx], this);

View File

@ -137,19 +137,19 @@ void sub_0806C944(Entity* this) {
} }
void sub_0806C978(Entity* this) { void sub_0806C978(Entity* this) {
u32 flag; u32 flagAsBool = 0;
u32 flagAsBool; if (CheckGlobalFlag(0x58)) {
flag = CheckGlobalFlag(0x58); flagAsBool = 1;
flagAsBool = BOOLCAST(flag); }
MessageNoOverlap(gUnk_08113B12[flagAsBool], this); MessageNoOverlap(gUnk_08113B12[flagAsBool], this);
} }
void sub_0806C99C(Entity* this) { void sub_0806C99C(Entity* this) {
s32 flag; u32 flagAsBool = 0;
u32 flagAsBool;
flag = CheckGlobalFlag(0x58); if (CheckGlobalFlag(0x58)) {
flagAsBool = BOOLCAST(flag) & 2; flagAsBool = 2;
}
if (CheckLocalFlag(99) != 0) { if (CheckLocalFlag(99) != 0) {
flagAsBool += 1; flagAsBool += 1;
} }
@ -165,10 +165,10 @@ void sub_0806C9D0(Entity* this) {
} }
void sub_0806C9F8(Entity* this) { void sub_0806C9F8(Entity* this) {
u32 flag; u32 flagAsBool = 0;
u32 flagAsBool; if (CheckGlobalFlag(0x58)) {
flag = CheckGlobalFlag(0x58); flagAsBool = 1;
flagAsBool = BOOLCAST(flag); }
MessageNoOverlap(gUnk_08113B22[flagAsBool], this); MessageNoOverlap(gUnk_08113B22[flagAsBool], this);
} }

View File

@ -54,11 +54,11 @@ void sub_0809EA80(Entity* this) {
} }
void sub_0809EABC(Entity* this) { void sub_0809EABC(Entity* this) {
bool32 anySet; bool32 anySet = 0;
u32 f;
f = CheckFlags(this->field_0x86.HWORD); if (CheckFlags(this->field_0x86.HWORD)) {
anySet = BOOLCAST(f); anySet = 1;
}
if (this->frameIndex != anySet) { if (this->frameIndex != anySet) {
this->frameIndex = anySet; this->frameIndex = anySet;
} }

View File

@ -4531,8 +4531,10 @@ void sub_StateChange_SimonsSimulation_Main(void) {
u32 r; u32 r;
u32 index; u32 index;
u32 tmp; u32 tmp;
tmp = CheckGlobalFlag(LV4_CLEAR); index = 0;
index = BOOLCAST(tmp); if (CheckGlobalFlag(LV4_CLEAR)) {
index = 1;
}
if (CheckGlobalFlag(LV5_CLEAR)) { if (CheckGlobalFlag(LV5_CLEAR)) {
index = 2; index = 2;
} }