diff options
| author | Tharo <17233964+Thar0@users.noreply.github.com> | 2020-05-15 18:58:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-15 13:58:14 -0400 |
| commit | 47e25298a01a167e29af566e16aee031035850f2 (patch) | |
| tree | 41126ff262a55541877d78f2312ef16d6fbd9bf3 /src/code | |
| parent | 82b464b8642e3ba212a54bcf8ab00d81ec71ad9b (diff) | |
Decompile code_800FD970 (#141)
* Decompile code_800FD970
* Comment cleanups, ensure formatter won't cause a matching issue later
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/code_800FD970.c | 85 | ||||
| -rw-r--r-- | src/code/z_play.c | 2 |
2 files changed, 86 insertions, 1 deletions
diff --git a/src/code/code_800FD970.c b/src/code/code_800FD970.c new file mode 100644 index 000000000..ba981a07b --- /dev/null +++ b/src/code/code_800FD970.c @@ -0,0 +1,85 @@ +#include <ultra64.h> +#include <global.h> + +// The latest generated random number, used to generate the next number in the sequence. +u32 randomNumber = 1; + +// Space to store a value to be re-interpreted as a float. +u32 floatStore; + +/** + * Gets the next integer in the sequence of pseudo-random numbers. + */ +u32 Math_Rand_Next() { + return randomNumber = (randomNumber * 1664525) + 1013904223; +} + +/** + * Seeds the pseudo-random number generator by providing a starting value. + */ +void Math_Rand_Seed(u32 seed) { + randomNumber = 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. + */ +f32 Math_Rand_ZeroOne() { + randomNumber = (randomNumber * 1664525) + 1013904223; + floatStore = ((randomNumber >> 9) | 0x3F800000); + return *((f32*)&floatStore) - 1.0f; +} + +/** + * Returns a pseudo-random floating-point number between -0.5f and 0.5f by the same + * manner in which Math_Rand_ZeroOne generates its result. + */ +f32 Math_Rand_Centered() { + randomNumber = (randomNumber * 1664525) + 1013904223; + floatStore = ((randomNumber >> 9) | 0x3F800000); + return *((f32*)&floatStore) - 1.5f; +} + +/** + * Seeds a pseudo-random number at rndNum with a provided seed. + */ +void Math_Rand_Seed_Variable(u32* rndNum, u32 seed) { + *rndNum = seed; +} + +/** + * Generates the next pseudo-random integer from the provided rndNum. + */ +u32 Math_Rand_Next_Variable(u32* rndNum) { + return *rndNum = (*rndNum * 1664525) + 1013904223; +} + +/** + * Generates the next pseudo-random floating-point number between 0.0f and + * 1.0f from the provided rndNum. + */ +f32 Math_Rand_ZeroOne_Variable(u32* rndNum) { + u32 next; + + next = (*rndNum * 1664525) + 1013904223; + // clang-format off + *rndNum = next; floatStore = (next >> 9) | 0x3F800000; + // clang-format on + return *((f32*)&floatStore) - 1.0f; +} + +/** + * Generates the next pseudo-random floating-point number between -0.5f and + * 0.5f from the provided rndNum. + */ +f32 Math_Rand_Centered_Variable(u32* rndNum) { + u32 next; + + next = (*rndNum * 1664525) + 1013904223; + // clang-format off + *rndNum = next; floatStore = (next >> 9) | 0x3F800000; + // clang-format on + return *((f32*)&floatStore) - 1.5f; +} diff --git a/src/code/z_play.c b/src/code/z_play.c index 291c993ad..1ee3e00b4 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -339,7 +339,7 @@ void Gameplay_Init(GlobalContext* globalCtx) { gTrnsnUnkState = 0; globalCtx->transitionMode = 0; func_8008E6A0(&globalCtx->sub_7B8); - func_800FD9A0((u32)osGetTime()); + Math_Rand_Seed((u32)osGetTime()); Matrix_Init(&globalCtx->state); globalCtx->state.main = Gameplay_Main; globalCtx->state.destroy = Gameplay_Destroy; |
