Change Rand_Next to u32, document rand.c a bit more (#819)

* Change Rand_Next to u32, document rand.c a bit more

* Clean up the quotes a bit, add another note

* Format

* — -> -

* Review

* Remove unnecessary casts

* Remove quote, reformat the comments

* Fix new files

* Make docs a bit more consistent and specific

* Format
This commit is contained in:
EllipticEllipsis
2022-06-19 04:14:55 +01:00
committed by GitHub
parent 56c517dc07
commit 7ca70d496d
43 changed files with 239 additions and 228 deletions
+1 -1
View File
@@ -171,7 +171,7 @@ f64 func_80086D6C(f64 param_1);
s32 func_80086D8C(f32 param_1);
s32 func_80086DAC(f64 param_1);
s32 Rand_Next(void);
u32 Rand_Next(void);
void Rand_Seed(u32 seed);
f32 Rand_ZeroOne(void);
f32 Rand_Centered(void);
+36 -24
View File
@@ -1,33 +1,39 @@
#include "global.h"
// The latest generated random number, used to generate the next number in the sequence.
//! The latest generated random number, used to generate the next number in the sequence.
static u32 sRandInt = 1;
// Space to store a value to be re-interpreted as a float.
// This can't be static because it is used in z_kankyo
//! Space to store a value to be re-interpreted as a float.
//! This can't be static because it is used in z_kankyo.
u32 sRandFloat;
//! These values are recommended by the algorithms book *Numerical Recipes in C. The Art of Scientific Computing*, 2nd
//! Edition, 1992, ISBN 0-521-43108-5. (p. 284):
//! > This is about as good as any 32-bit linear congruential generator, entirely adequate for many uses.
#define RAND_MULTIPLIER 1664525
#define RAND_INCREMENT 1013904223
/**
* Gets the next integer in the sequence of pseudo-random numbers.
* Generates the next pseudo-random integer.
*/
s32 Rand_Next(void) {
return sRandInt = (sRandInt * 1664525) + 1013904223;
u32 Rand_Next(void) {
return sRandInt = (sRandInt * RAND_MULTIPLIER) + RAND_INCREMENT;
}
/**
* Seeds the pseudo-random number generator by providing a starting value.
* Seeds the internal pseudo-random number generator with a provided starting value.
*/
void Rand_Seed(u32 seed) {
sRandInt = seed;
}
/**
* Returns a pseudo-random floating-point number between 0.0f and 1.0f, by generating
* the next integer and masking it to an IEEE-754 compliant floating-point number
* between 1.0f and 2.0f, returning the result subtract 1.0f.
* Returns a pseudo-random float between 0.0f and 1.0f from the internal PRNG.
*
* @note Works by generating the next integer, masking it to an IEEE-754 compliant float between 1.0f and 2.0f, and
* subtracting 1.0f.
*
* @remark This is also recommended by Numerical Recipes, pp. 284-5.
*/
f32 Rand_ZeroOne(void) {
sRandInt = (sRandInt * RAND_MULTIPLIER) + RAND_INCREMENT;
@@ -36,8 +42,7 @@ f32 Rand_ZeroOne(void) {
}
/**
* Returns a pseudo-random floating-point number between -0.5f and 0.5f by the same
* manner in which Rand_ZeroOne generates its result.
* Returns a pseudo-random float between -0.5f and 0.5f in the same way as Rand_ZeroOne().
*/
f32 Rand_Centered(void) {
sRandInt = (sRandInt * RAND_MULTIPLIER) + RAND_INCREMENT;
@@ -45,40 +50,47 @@ f32 Rand_Centered(void) {
return *((f32*)&sRandFloat) - 1.5f;
}
//! All functions below are unused variants of the above four, that use a provided random number variable instead of the
//! internal `sRandInt`
/**
* Seeds a pseudo-random number at rndNum with a provided seed.
* Seeds a provided pseudo-random number with a provided starting value.
*
* @see Rand_Seed
*/
void Rand_Seed_Variable(u32* rndNum, u32 seed) {
*rndNum = seed;
}
/**
* Generates the next pseudo-random integer from the provided rndNum.
* Generates the next pseudo-random number from the provided rndNum.
*
* @see Rand_Next
*/
u32 Rand_Next_Variable(u32* rndNum) {
return *rndNum = (*rndNum * RAND_MULTIPLIER) + RAND_INCREMENT;
}
/**
* Generates the next pseudo-random floating-point number between 0.0f and
* 1.0f from the provided rndNum.
* Generates the next pseudo-random float between 0.0f and 1.0f from the provided rndNum.
*
* @see Rand_ZeroOne
*/
f32 Rand_ZeroOne_Variable(u32* rndNum) {
u32 next = (*rndNum * RAND_MULTIPLIER) + RAND_INCREMENT;
// clang-format off
*rndNum = next; sRandFloat = (next >> 9) | 0x3F800000;
// clang-format on
sRandFloat = ((*rndNum = next) >> 9) | 0x3F800000;
return *((f32*)&sRandFloat) - 1.0f;
}
/**
* Generates the next pseudo-random floating-point number between -0.5f and
* 0.5f from the provided rndNum.
* Generates the next pseudo-random float between -0.5f and 0.5f from the provided rndNum.
*
* @see Rand_ZeroOne, Rand_Centered
*/
f32 Rand_Centered_Variable(u32* rndNum) {
u32 next = (*rndNum * RAND_MULTIPLIER) + RAND_INCREMENT;
// clang-format off
*rndNum = next; sRandFloat = (next >> 9) | 0x3F800000;
// clang-format on
sRandFloat = ((*rndNum = next) >> 9) | 0x3F800000;
return *((f32*)&sRandFloat) - 1.5f;
}
+24 -24
View File
@@ -77,57 +77,57 @@ u16 sATan2Tbl[] = {
0x1FF6, 0x1FFB, 0x2000,
};
u16 Math_GetAtan2Tbl(f32 opposite, f32 adjacent) {
return sATan2Tbl[(s32)((opposite / adjacent) * 0x400)];
u16 Math_GetAtan2Tbl(f32 y, f32 x) {
return sATan2Tbl[(s32)((y / x) * 0x400)];
}
s16 Math_Atan2S(f32 opposite, f32 adjacent) {
s16 Math_Atan2S(f32 y, f32 x) {
s32 angle;
if (opposite == 0.0f) {
if (adjacent >= 0.0f) {
if (y == 0.0f) {
if (x >= 0.0f) {
angle = 0;
} else {
angle = 0x8000;
}
} else if (adjacent == 0.0f) {
if (opposite >= 0.0f) {
} else if (x == 0.0f) {
if (y >= 0.0f) {
angle = 0x4000;
} else {
angle = 0xC000;
}
} else if (opposite >= 0.0f) {
if (adjacent >= 0.0f) {
if (opposite <= adjacent) {
angle = Math_GetAtan2Tbl(opposite, adjacent);
} else if (y >= 0.0f) {
if (x >= 0.0f) {
if (y <= x) {
angle = Math_GetAtan2Tbl(y, x);
} else {
angle = 0x4000 - Math_GetAtan2Tbl(adjacent, opposite);
angle = 0x4000 - Math_GetAtan2Tbl(x, y);
}
} else {
if (-adjacent < opposite) {
angle = Math_GetAtan2Tbl(-adjacent, opposite) + 0x4000;
if (-x < y) {
angle = Math_GetAtan2Tbl(-x, y) + 0x4000;
} else {
angle = 0x8000 - Math_GetAtan2Tbl(opposite, -adjacent);
angle = 0x8000 - Math_GetAtan2Tbl(y, -x);
}
}
} else if (adjacent < 0.0f) {
if (-opposite <= -adjacent) {
angle = Math_GetAtan2Tbl(-opposite, -adjacent) + 0x8000;
} else if (x < 0.0f) {
if (-y <= -x) {
angle = Math_GetAtan2Tbl(-y, -x) + 0x8000;
} else {
angle = 0xC000 - Math_GetAtan2Tbl(-adjacent, -opposite);
angle = 0xC000 - Math_GetAtan2Tbl(-x, -y);
}
} else {
if (adjacent < -opposite) {
angle = Math_GetAtan2Tbl(adjacent, -opposite) + 0xC000;
if (x < -y) {
angle = Math_GetAtan2Tbl(x, -y) + 0xC000;
} else {
angle = -Math_GetAtan2Tbl(-opposite, adjacent);
angle = -Math_GetAtan2Tbl(-y, x);
}
}
return angle;
}
f32 Math_Atan2F(f32 opposite, f32 adjacent) {
return Math_Atan2S(opposite, adjacent) * (M_PI / 0x8000);
f32 Math_Atan2F(f32 y, f32 x) {
return Math_Atan2S(y, x) * (M_PI / 0x8000);
}
s16 Math_FAtan2F(f32 adjacent, f32 opposite) {
+1 -1
View File
@@ -4782,7 +4782,7 @@ void Actor_SpawnIceEffects(GlobalContext* globalCtx, Actor* actor, Vec3f limbPos
yaw = Actor_YawToPoint(actor, limbPos);
for (j = 0; j < effectsPerLimb; j++) {
randomYaw = (Rand_Next() >> 0x13) + yaw;
randomYaw = ((s32)Rand_Next() >> 0x13) + yaw;
velocity.z = Rand_ZeroFloat(5.0f);
@@ -78,7 +78,7 @@ void BgCtowerGear_Splash(BgCtowerGear* this, GlobalContext* globalCtx) {
Matrix_RotateXS(this->dyna.actor.home.rot.x, MTXMODE_APPLY);
Matrix_RotateZS(this->dyna.actor.home.rot.z, MTXMODE_APPLY);
for (i = 0; i < 4; i++) {
if ((u32)Rand_Next() >= 0x40000000) {
if (Rand_Next() >= 0x40000000) {
splashOffset.x = sExitSplashOffsets[i].x - (Rand_ZeroOne() * 30.0f);
splashOffset.y = sExitSplashOffsets[i].y;
splashOffset.z = sExitSplashOffsets[i].z;
@@ -86,7 +86,7 @@ void BgCtowerGear_Splash(BgCtowerGear* this, GlobalContext* globalCtx) {
splashSpawnPos.x += this->dyna.actor.world.pos.x + ((Rand_ZeroOne() * 20.0f) - 10.0f);
splashSpawnPos.y += this->dyna.actor.world.pos.y;
splashSpawnPos.z += this->dyna.actor.world.pos.z + ((Rand_ZeroOne() * 20.0f) - 10.0f);
EffectSsGSplash_Spawn(globalCtx, &splashSpawnPos, NULL, NULL, 0, ((u32)Rand_Next() >> 25) + 340);
EffectSsGSplash_Spawn(globalCtx, &splashSpawnPos, NULL, NULL, 0, (Rand_Next() >> 25) + 340);
}
}
}
@@ -104,7 +104,7 @@ void BgCtowerGear_Splash(BgCtowerGear* this, GlobalContext* globalCtx) {
splashSpawnPos.x += this->dyna.actor.world.pos.x + ((Rand_ZeroOne() * 20.0f) - 10.0f);
splashSpawnPos.y += this->dyna.actor.world.pos.y;
splashSpawnPos.z += this->dyna.actor.world.pos.z + ((Rand_ZeroOne() * 20.0f) - 10.0f);
EffectSsGSplash_Spawn(globalCtx, &splashSpawnPos, NULL, NULL, 0, ((u32)Rand_Next() >> 25) + 280);
EffectSsGSplash_Spawn(globalCtx, &splashSpawnPos, NULL, NULL, 0, (Rand_Next() >> 25) + 280);
}
}
}
@@ -276,7 +276,7 @@ void func_80B8296C(GlobalContext* globalCtx, Vec3f* arg1, f32 arg2) {
for (i = 0; i < ARRAY_COUNT(D_80B83A94); i++) {
temp_f0 = Rand_ZeroOne();
temp_f20 = 1.0f - SQ(temp_f0);
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
temp_f20 = -temp_f20;
}
@@ -285,7 +285,7 @@ void func_80B8296C(GlobalContext* globalCtx, Vec3f* arg1, f32 arg2) {
temp_f0 = Rand_ZeroOne();
temp_f20 = 1.0f - SQ(temp_f0);
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
temp_f20 = -temp_f20;
}
sp60.z = (temp_f20 * arg2) + arg1->z;
@@ -295,7 +295,7 @@ void func_80B84610(BgDblueWaterfall* this, GlobalContext* globalCtx) {
if (this->unk_1A7 <= 0) {
this->unk_1A7 = 16;
} else {
this->unk_1A7 -= (s8)((u32)Rand_Next() >> 0x1F);
this->unk_1A7 -= (s8)(Rand_Next() >> 0x1F);
}
if (this->unk_1A7 >= 6) {
@@ -138,7 +138,7 @@ void func_80ABBFC0(BgHakuginBombwall* this, GlobalContext* globalCtx) {
for (i = 0; i < 6; i++) {
temp = (i + 1) * (80.0f / 3.0f);
for (j = 0; j < ARRAY_COUNT(D_80ABD020); j++) {
spD8.x = D_80ABD020[j] + (s32)((u32)Rand_Next() >> 0x1C);
spD8.x = D_80ABD020[j] + (s32)(Rand_Next() >> 0x1C);
spD8.y = ((Rand_ZeroOne() - 0.5f) * 15.0f) + temp;
spD8.z = (Rand_ZeroOne() * 20.0f) - 10.0f;
@@ -159,11 +159,11 @@ void func_80ABBFC0(BgHakuginBombwall* this, GlobalContext* globalCtx) {
phi_s0 = 64;
}
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
phi_s0 |= 1;
phi_s1 = 1;
func_800B0E48(globalCtx, &spF0, &gZeroVec3f, &D_80ABCFB4, &D_80ABCFAC, &D_80ABCFB0,
((u32)Rand_Next() >> 0x1B) + 70, ((u32)Rand_Next() >> 0x1A) + 60);
(Rand_Next() >> 0x1B) + 70, (Rand_Next() >> 0x1A) + 60);
} else {
phi_s1 = 0;
}
@@ -224,7 +224,7 @@ void func_80ABC2E0(BgHakuginBombwall* this, GlobalContext* globalCtx) {
if ((i & 1) == 0) {
func_800B0E48(globalCtx, &spC8, &D_80ABD034, &D_80ABCFB4, &D_80ABCFAC, &D_80ABCFB0,
((u32)Rand_Next() >> 0x1B) + 60, ((u32)Rand_Next() >> 0x1A) + 50);
(Rand_Next() >> 0x1B) + 60, (Rand_Next() >> 0x1A) + 50);
}
}
}
@@ -269,8 +269,8 @@ void func_80ABC58C(BgHakuginBombwall* this, GlobalContext* globalCtx) {
spC0.y += this->dyna.actor.world.pos.y;
spC0.z += this->dyna.actor.world.pos.z;
func_800B0E48(globalCtx, &spC0, &spCC, &spD8, &D_80ABCFAC, &D_80ABCFB0, ((u32)Rand_Next() >> 0x1A) + 60,
((u32)Rand_Next() >> 0x1B) + 60);
func_800B0E48(globalCtx, &spC0, &spCC, &spD8, &D_80ABCFAC, &D_80ABCFB0, (Rand_Next() >> 0x1A) + 60,
(Rand_Next() >> 0x1B) + 60);
}
}
@@ -303,8 +303,8 @@ void func_80ABC7FC(BgHakuginBombwall* this, GlobalContext* globalCtx) {
spB8.x = spAC.x * -0.095f;
spB8.z = spAC.z * -0.095f;
func_800B0E48(globalCtx, &spA0, &spAC, &spB8, &D_80ABCFAC, &D_80ABCFB0, ((u32)Rand_Next() >> 0x1A) + 60,
((u32)Rand_Next() >> 0x1B) + 60);
func_800B0E48(globalCtx, &spA0, &spAC, &spB8, &D_80ABCFAC, &D_80ABCFB0, (Rand_Next() >> 0x1A) + 60,
(Rand_Next() >> 0x1B) + 60);
}
}
@@ -343,9 +343,9 @@ void func_80A9B554(BgHakuginPost* this, GlobalContext* globalCtx, BgHakuginPostU
temp_f0 = spAC.z;
unkStruct2->unk_10.z = ((Rand_ZeroOne() * 60.0f - 30.0f) + temp_f28 * 50.0f) * temp_f22 + temp_f0 * temp_f20;
unkStruct2->unk_1C = 0.90999997f - (0.04f - unkStruct2->unk_00) * (500.0f / 19.0f) * 0.02f;
unkStruct2->unk_20.x = Rand_Next() >> 0x10;
unkStruct2->unk_20.y = Rand_Next() >> 0x10;
unkStruct2->unk_20.z = Rand_Next() >> 0x10;
unkStruct2->unk_20.x = (s32)Rand_Next() >> 0x10;
unkStruct2->unk_20.y = (s32)Rand_Next() >> 0x10;
unkStruct2->unk_20.z = (s32)Rand_Next() >> 0x10;
unkStruct2->unk_26 = (Rand_Next() & 0x3FFF) - 0x1FFF;
unkStruct2->unk_28 = (Rand_Next() & 0x1FFF) - 0xFFF;
unkStruct2->unk_2A = (Rand_Next() & 0x1FFF) - 0xFFF;
@@ -359,7 +359,7 @@ void func_80A9B554(BgHakuginPost* this, GlobalContext* globalCtx, BgHakuginPostU
spA0.y = (Rand_ZeroOne() * 1.2f - 0.1f) * spE4 + spB8.y;
spA0.z = Math_CosS(val) * temp_f20 + spB8.z;
func_800B0E48(globalCtx, &spA0, &gZeroVec3f, &D_80A9D8EC, &D_80A9D8E4, &D_80A9D8E8,
(Rand_Next() >> 0x1A) + 0x82, (Rand_Next() >> 0x1A) + 0x6E);
((s32)Rand_Next() >> 0x1A) + 0x82, ((s32)Rand_Next() >> 0x1A) + 0x6E);
}
unkStruct1Temp = func_80A9B32C(unkStruct, unkStruct1);
@@ -386,9 +386,9 @@ void func_80A9B554(BgHakuginPost* this, GlobalContext* globalCtx, BgHakuginPostU
unkStruct2->unk_10.y = 0.0f;
unkStruct2->unk_10.z = Rand_ZeroOne() + temp_f28 * 7.0f;
unkStruct2->unk_1C = 0.90999997f - (0.04f - unkStruct2->unk_00) * (500.0f / 19.0f) * 0.075f;
unkStruct2->unk_20.x = Rand_Next() >> 0x10;
unkStruct2->unk_20.y = Rand_Next() >> 0x10;
unkStruct2->unk_20.z = Rand_Next() >> 0x10;
unkStruct2->unk_20.x = (s32)Rand_Next() >> 0x10;
unkStruct2->unk_20.y = (s32)Rand_Next() >> 0x10;
unkStruct2->unk_20.z = (s32)Rand_Next() >> 0x10;
unkStruct2->unk_26 = (Rand_Next() & 0x1FFF) - 0xFFF;
unkStruct2->unk_28 = (Rand_Next() & 0x1FFF) - 0xFFF;
unkStruct2->unk_2A = (Rand_Next() & 0x1FFF) - 0xFFF;
@@ -47,7 +47,7 @@ void BgLotus_Init(Actor* thisx, GlobalContext* globalCtx) {
this->dyna.actor.floorHeight = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &thisx->floorPoly, &bgId,
&this->dyna.actor, &this->dyna.actor.world.pos);
this->timer2 = 96;
this->dyna.actor.world.rot.y = Rand_Next() >> 0x10;
this->dyna.actor.world.rot.y = (s32)Rand_Next() >> 0x10;
this->actionFunc = BgLotus_Wait;
}
@@ -82,7 +82,7 @@ void BgLotus_Wait(BgLotus* this, GlobalContext* globalCtx) {
if (this->timer2 == 0) {
this->timer2 = 96;
this->dyna.actor.world.rot.y += (s16)(Rand_Next() >> 0x12);
this->dyna.actor.world.rot.y += (s16)((s32)Rand_Next() >> 0x12);
}
}
+1 -1
View File
@@ -241,7 +241,7 @@ void EnBb_SetupFlyIdle(EnBb* this) {
if ((this->actor.xzDistToPlayer < (this->attackRange + 120.0f)) ||
(Actor_XZDistanceToPoint(&this->actor, &this->actor.home.pos) < 300.0f)) {
this->targetYRotation += (s16)(Rand_Next() >> 0x11);
this->targetYRotation += (s16)((s32)Rand_Next() >> 0x11);
}
this->collider.base.atFlags |= AT_ON;
@@ -505,7 +505,7 @@ void EnBigpo_WarpingOut(EnBigpo* this, GlobalContext* globalCtx) {
void EnBigpo_SetupWarpIn(EnBigpo* this, GlobalContext* globalCtx) {
Player* player = GET_PLAYER(globalCtx);
f32 distance = CLAMP_MIN(this->actor.xzDistToPlayer, 200.0f);
s16 randomYaw = (Rand_Next() >> 0x14) + this->actor.yawTowardsPlayer;
s16 randomYaw = ((s32)Rand_Next() >> 0x14) + this->actor.yawTowardsPlayer;
Actor_PlaySfxAtPos(&this->actor, NA_SE_EN_STALKIDS_APPEAR);
Animation_PlayLoop(&this->skelAnime, &gBigpoAwakenStretchAnim);
@@ -565,7 +565,7 @@ void EnBigpo_IdleFlying(EnBigpo* this, GlobalContext* globalCtx) {
}
if (Math_ScaledStepToS(&this->actor.shape.rot.y, this->unk208, 0x200) && (Rand_ZeroOne() < 0.075f)) {
this->unk208 += (s16)((((u32)Rand_Next() >> 0x14) + 0x1000) * ((Rand_ZeroOne() < 0.5f) ? -1 : 1));
this->unk208 += (s16)(((Rand_Next() >> 0x14) + 0x1000) * ((Rand_ZeroOne() < 0.5f) ? -1 : 1));
}
this->actor.world.rot.y = this->actor.shape.rot.y;
@@ -2089,9 +2089,9 @@ void EnBigslime_SetupIdleLookAround(EnBigslime* this) {
this->idleTimer = 60;
this->actor.speedXZ = 0.0f;
if (BINANG_SUB(Actor_YawToPoint(&this->actor, &this->actor.home.pos), this->gekkoRot.y) > 0) {
this->gekkoYaw = this->gekkoRot.y + ((u32)Rand_Next() >> 20) + 0x2000;
this->gekkoYaw = this->gekkoRot.y + (Rand_Next() >> 20) + 0x2000;
} else {
this->gekkoYaw = this->gekkoRot.y - ((u32)Rand_Next() >> 20) - 0x2000;
this->gekkoYaw = this->gekkoRot.y - (Rand_Next() >> 20) - 0x2000;
}
this->actionFunc = EnBigslime_IdleLookAround;
}
@@ -2111,9 +2111,9 @@ void EnBigslime_IdleLookAround(EnBigslime* this, GlobalContext* globalCtx) {
if ((this->skelAnime.animation == &gGekkoNervousIdleAnim) &&
Math_ScaledStepToS(&this->gekkoRot.y, this->gekkoYaw, 0x400)) {
if (BINANG_SUB(Actor_YawToPoint(&this->actor, &this->actor.home.pos), this->gekkoRot.y) > 0) {
this->gekkoYaw = this->gekkoRot.y + ((u32)Rand_Next() >> 20) + 0x2000;
this->gekkoYaw = this->gekkoRot.y + (Rand_Next() >> 20) + 0x2000;
} else {
this->gekkoYaw = this->gekkoRot.y - ((u32)Rand_Next() >> 20) - 0x2000;
this->gekkoYaw = this->gekkoRot.y - (Rand_Next() >> 20) - 0x2000;
}
}
@@ -2700,9 +2700,9 @@ void EnBigslime_AddIceShardEffect(EnBigslime* this, GlobalContext* globalCtx) {
iceShardEffect->pos.x = (targetVtx->n.ob[0] * this->actor.scale.x) + this->actor.world.pos.x;
iceShardEffect->pos.y = (targetVtx->n.ob[1] * this->actor.scale.y) + this->actor.world.pos.y;
iceShardEffect->pos.z = (targetVtx->n.ob[2] * this->actor.scale.z) + this->actor.world.pos.z;
iceShardEffect->rotation.x = Rand_Next() >> 0x10;
iceShardEffect->rotation.y = Rand_Next() >> 0x10;
iceShardEffect->rotation.z = Rand_Next() >> 0x10;
iceShardEffect->rotation.x = (s32)Rand_Next() >> 0x10;
iceShardEffect->rotation.y = (s32)Rand_Next() >> 0x10;
iceShardEffect->rotation.z = (s32)Rand_Next() >> 0x10;
iceShardEffect->isActive = true;
randPitch = Rand_S16Offset(0x1000, 0x3000);
vtxZ = targetVtx->n.ob[2];
@@ -2742,9 +2742,9 @@ void EnBigslime_UpdateEffects(EnBigslime* this) {
if (iceShardEffect->pos.y < (GBT_ROOM_5_MIN_Y - 20.0f)) {
iceShardEffect->isActive = false;
}
iceShardEffect->rotation.x += (s16)(((u32)Rand_Next() >> 0x17) + 0x700);
iceShardEffect->rotation.y += (s16)(((u32)Rand_Next() >> 0x17) + 0x900);
iceShardEffect->rotation.z += (s16)(((u32)Rand_Next() >> 0x17) + 0xB00);
iceShardEffect->rotation.x += (s16)((Rand_Next() >> 0x17) + 0x700);
iceShardEffect->rotation.y += (s16)((Rand_Next() >> 0x17) + 0x900);
iceShardEffect->rotation.z += (s16)((Rand_Next() >> 0x17) + 0xB00);
}
}
@@ -449,7 +449,7 @@ void func_80876DC4(EnDodongo* this, GlobalContext* globalCtx) {
f32 temp_f20;
Math_Vec3f_Copy(&sp68, &this->limbPos[0]);
sp66 = (Rand_Next() >> 0x12) + this->actor.shape.rot.y;
sp66 = ((s32)Rand_Next() >> 0x12) + this->actor.shape.rot.y;
temp_f20 = Math_CosS(sp66);
temp_f22 = Math_SinS(sp66);
@@ -482,7 +482,7 @@ void func_80876DC4(EnDodongo* this, GlobalContext* globalCtx) {
sp62 = this->unk_334 * 25.0f;
func_800B0EB0(globalCtx, &sp68, &sp80, &sp74, &this->unk_32C, &this->unk_330, sp64, sp62, 0x14);
sp66 = ((u32)Rand_Next() >> 0x13) + this->actor.shape.rot.y;
sp66 = (Rand_Next() >> 0x13) + this->actor.shape.rot.y;
temp_f20 = Math_CosS(sp66);
temp_f22 = Math_SinS(sp66);
+12 -13
View File
@@ -226,15 +226,15 @@ void EnFamos_SetupAttackDebris(EnFamos* this) {
this->debrisTimer = 40;
rock = &this->rocks[0];
for (i = 0; i < ARRAY_COUNT(this->rocks); i++, rock++) {
randVelDirection = Rand_Next() >> 0x10;
randVelDirection = (s32)Rand_Next() >> 0x10;
randOffset = Rand_S16Offset(0x1800, 0x2800);
randFloat = Rand_ZeroFloat(5.0f) + 5.0f;
rock->velocity.x = randFloat * Math_CosS(randOffset) * Math_SinS(randVelDirection);
rock->velocity.y = Math_SinS(randOffset) * randFloat + 3.0f;
rock->velocity.z = randFloat * Math_CosS(randOffset) * Math_CosS(randVelDirection);
rock->rotation.x = Rand_Next() >> 0x10;
rock->rotation.y = Rand_Next() >> 0x10;
rock->rotation.z = Rand_Next() >> 0x10;
rock->rotation.x = (s32)Rand_Next() >> 0x10;
rock->rotation.y = (s32)Rand_Next() >> 0x10;
rock->rotation.z = (s32)Rand_Next() >> 0x10;
rock->pos.x = (Math_SinS(randVelDirection) * 20.0f) + this->actor.world.pos.x;
rock->pos.y = this->actor.floorHeight;
rock->pos.z = (Math_CosS(randVelDirection) * 20.0f) + this->actor.world.pos.z;
@@ -255,15 +255,15 @@ void EnFamos_SetupDeathDebris(EnFamos* this) {
this->debrisTimer = 40;
rock = &this->rocks[0];
for (i = 0; i < ARRAY_COUNT(this->rocks); i++, rock++) {
randVelDirection = Rand_Next() >> 0x10;
randSmaller = (u32)Rand_Next() >> 0x12;
randVelDirection = (s32)Rand_Next() >> 0x10;
randSmaller = Rand_Next() >> 0x12;
randFloat = Rand_ZeroFloat(6.0f) + 7.0f;
rock->velocity.x = randFloat * Math_CosS(randSmaller) * Math_SinS(randVelDirection);
rock->velocity.y = Math_SinS(randSmaller) * randFloat + 4.5f;
rock->velocity.z = randFloat * Math_CosS(randSmaller) * Math_CosS(randVelDirection);
rock->rotation.x = Rand_Next() >> 0x10;
rock->rotation.y = Rand_Next() >> 0x10;
rock->rotation.z = Rand_Next() >> 0x10;
rock->rotation.x = (s32)Rand_Next() >> 0x10;
rock->rotation.y = (s32)Rand_Next() >> 0x10;
rock->rotation.z = (s32)Rand_Next() >> 0x10;
rock->pos.x = Math_SinS(randVelDirection) * 20.0f + this->actor.world.pos.x;
rock->pos.y = randPlusMinusPoint5Scaled(60.0f) + (this->actor.world.pos.y + 40.0f);
rock->pos.z = Math_CosS(randVelDirection) * 20.0f + this->actor.world.pos.z;
@@ -735,10 +735,9 @@ void EnFamos_UpdateDebrisPosRot(EnFamos* this) {
for (i = 0; i < ARRAY_COUNT(this->rocks); i++, rock++) {
rock->velocity.y -= 1.0f;
Math_Vec3f_Sum(&rock->pos, &rock->velocity, &rock->pos);
// all casts seem required
rock->rotation.x += (s16)(((u32)Rand_Next() >> 0x17) + 0x700);
rock->rotation.y += (s16)(((u32)Rand_Next() >> 0x17) + 0x900);
rock->rotation.z += (s16)(((u32)Rand_Next() >> 0x17) + 0xB00);
rock->rotation.x += (s16)((Rand_Next() >> 0x17) + 0x700);
rock->rotation.y += (s16)((Rand_Next() >> 0x17) + 0x900);
rock->rotation.z += (s16)((Rand_Next() >> 0x17) + 0xB00);
}
}
+4 -4
View File
@@ -210,8 +210,8 @@ void EnFish_Init(Actor* thisx, GlobalContext* globalCtx) {
Collider_SetJntSph(globalCtx, &this->collider, &this->actor, &sJntSphInit, this->colliderElements);
this->actor.colChkInfo.mass = this->unk_25C * 30.0f;
this->unk_244 = (u32)Rand_Next() >> 0x10;
this->unk_246 = (u32)Rand_Next() >> 0x10;
this->unk_244 = Rand_Next() >> 0x10;
this->unk_246 = Rand_Next() >> 0x10;
if (sp36 == ENFISH_0) {
this->actor.flags |= ACTOR_FLAG_10;
@@ -707,12 +707,12 @@ void func_8091EFE8(Actor* thisx, GlobalContext* globalCtx) {
this->actor.speedXZ *= 0.5f;
}
if (!((u32)Rand_Next() >> 0x1B) || ((this->actor.bgCheckFlags & 8) && !((u32)Rand_Next() >> 0x1E)) ||
if (((Rand_Next() >> 0x1B) == 0) || ((this->actor.bgCheckFlags & 8) && ((Rand_Next() >> 0x1E) == 0)) ||
!(this->actor.bgCheckFlags & 0x20)) {
temp_f0 = Rand_ZeroOne();
sp34 = (1.0f - SQ(temp_f0)) * sp3C->home.rot.x;
sp30 = Rand_ZeroOne() * sp3C->home.rot.z;
sp2E = (u32)Rand_Next() >> 0x10;
sp2E = Rand_Next() >> 0x10;
this->actor.home.pos.x = (Math_SinS(sp2E) * sp34) + sp3C->world.pos.x;
this->actor.home.pos.y = sp3C->world.pos.y + sp30;
this->actor.home.pos.z = (Math_CosS(sp2E) * sp34) + sp3C->world.pos.z;
@@ -201,7 +201,7 @@ void func_80ACE850(EnFuMato* this, GlobalContext* globalCtx) {
s32 phi_s2;
s32 i;
this->unk_308 = (u32)Rand_Next() % ARRAY_COUNT(this->unk_1B8);
this->unk_308 = Rand_Next() % ARRAY_COUNT(this->unk_1B8);
this->unk_302 = 1;
this->dyna.actor.gravity = -1.0f;
this->dyna.actor.velocity.y = Rand_ZeroOne();
@@ -599,7 +599,7 @@ void func_8093FC6C(EnGoroiwa* this, GlobalContext* globalCtx) {
temp = 0x10000 / sp80;
for (i = 0, phi_s0 = 0; i < sp80; i++, phi_s0 += temp) {
temp_s3 = (u32)Rand_Next() >> 0x10;
temp_s3 = Rand_Next() >> 0x10;
temp_f20 = Math_SinS(temp_s3);
temp_f22 = Math_CosS(temp_s3);
@@ -701,7 +701,7 @@ void func_80940090(EnGoroiwa* this, GlobalContext* globalCtx) {
phi_s1 = D_80942E0C[sp120][0];
phi_s3 = 1;
phi_f22 = 0.8f;
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
phi_s0 = 0x21;
} else {
phi_s0 = 0x41;
@@ -779,7 +779,7 @@ void func_80940588(GlobalContext* globalCtx, Vec3f* arg1, Gfx* arg2[], Color_RGB
phi_s7 = arg2[0];
phi_fp = -0x190;
spC8 = 1;
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
phi_s0 = 0x21;
} else {
phi_s0 = 0x41;
@@ -856,7 +856,7 @@ void func_80940A1C(GlobalContext* globalCtx, Vec3f* arg1, Gfx** arg2, Color_RGBA
if ((i & 3) == 1) {
phi_s1 = arg2[1];
phi_s2 = -0x154;
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
phi_s0 = 0x21;
} else {
phi_s0 = 0x41;
@@ -864,7 +864,7 @@ void func_80940A1C(GlobalContext* globalCtx, Vec3f* arg1, Gfx** arg2, Color_RGBA
} else {
phi_s1 = arg2[0];
phi_s2 = -0x190;
if (Rand_Next() > 0) {
if ((s32)Rand_Next() > 0) {
phi_s0 = 0x21;
} else {
phi_s0 = 0x41;
@@ -102,7 +102,7 @@ void func_80B21BE0(BossHakugin* parent, Vec3f* arg1, s32 arg2) {
Math_Vec3f_Copy(&gohtParticle->unk_0, arg1);
sp2C = Rand_S16Offset(0x1000, 0x3000);
sp2E = (u32)Rand_Next() >> 0x10;
sp2E = Rand_Next() >> 0x10;
sp28 = Rand_ZeroFloat(5.0f) + 10.0f;
gohtParticle->unk_C.x = (sp28 * Math_CosS(sp2C)) * Math_SinS(sp2E);
gohtParticle->unk_C.y = (Math_SinS(sp2C) * sp28);
@@ -120,9 +120,9 @@ void func_80B21BE0(BossHakugin* parent, Vec3f* arg1, s32 arg2) {
gohtParticle->unk_0.z = ((Rand_ZeroFloat(2.0f) + 3.0f) * gohtParticle->unk_C.z) + arg1->z;
gohtParticle->unk_1A = 0;
}
gohtParticle->unk_1C.x = Rand_Next() >> 0x10;
gohtParticle->unk_1C.y = Rand_Next() >> 0x10;
gohtParticle->unk_1C.z = Rand_Next() >> 0x10;
gohtParticle->unk_1C.x = (s32)Rand_Next() >> 0x10;
gohtParticle->unk_1C.y = (s32)Rand_Next() >> 0x10;
gohtParticle->unk_1C.z = (s32)Rand_Next() >> 0x10;
gohtParticle->unk_18 = 0x28;
return;
}
@@ -189,10 +189,10 @@ void func_80B220A8(EnHakurock* this) {
this->actor.speedXZ = Rand_ZeroFloat(3.5f) + 2.5f;
this->actor.velocity.y = Rand_ZeroFloat(4.5f) + 18.0f;
Actor_SetScale(&this->actor, (Rand_ZeroFloat(5.0f) + 15.0f) * 0.001f);
this->actor.world.rot.y = (Rand_Next() >> 0x12) + this->actor.parent->shape.rot.y + 0x8000;
this->actor.shape.rot.x = Rand_Next() >> 0x10;
this->actor.shape.rot.y = Rand_Next() >> 0x10;
this->actor.shape.rot.z = Rand_Next() >> 0x10;
this->actor.world.rot.y = ((s32)Rand_Next() >> 0x12) + this->actor.parent->shape.rot.y + 0x8000;
this->actor.shape.rot.x = (s32)Rand_Next() >> 0x10;
this->actor.shape.rot.y = (s32)Rand_Next() >> 0x10;
this->actor.shape.rot.z = (s32)Rand_Next() >> 0x10;
this->collider.dim.radius = (this->actor.scale.x * 2500.0f);
this->collider.dim.yShift = -this->collider.dim.radius;
this->collider.dim.height = this->collider.dim.radius * 2;
@@ -222,8 +222,8 @@ void func_80B222AC(EnHakurock* this, GlobalContext* globalCtx) {
s16 angle;
this->actor.draw = EnHakurock_Draw;
angle = (Rand_Next() >> 0x13) + player->actor.shape.rot.y;
this->actor.shape.rot.y = Rand_Next() >> 0x10;
angle = ((s32)Rand_Next() >> 0x13) + player->actor.shape.rot.y;
this->actor.shape.rot.y = (s32)Rand_Next() >> 0x10;
this->actor.world.pos.x = (Math_SinS(angle) * 600.0f) + player->actor.world.pos.x;
this->actor.world.pos.y = player->actor.world.pos.y + 700.0f;
this->actor.world.pos.z = (Math_CosS(angle) * 600.0f) + player->actor.world.pos.z;
@@ -2656,7 +2656,7 @@ void func_80B48AD4(EnInvadepoh* this, GlobalContext* globalCtx) {
if (this->actionTimer > 0) {
temp_v1_3 = this->actionTimer & 0x1F;
if ((temp_v1_3 == 0) && (Rand_ZeroOne() < 0.3f)) {
temp_v1_3 = Rand_Next() % 4;
temp_v1_3 = (s32)Rand_Next() % 4;
if (temp_v1_3 != this->rand) {
this->rand = temp_v1_3;
if (this->rand == 0) {

Some files were not shown because too many files have changed in this diff Show More