diff --git a/configure.py b/configure.py index 6c9ec4340..9b139f2aa 100644 --- a/configure.py +++ b/configure.py @@ -900,7 +900,7 @@ config.libs = [ "JMath", [ Object(NonMatching, "JSystem/JMath/JMath.cpp"), - Object(NonMatching, "JSystem/JMath/random.cpp"), + Object(Matching, "JSystem/JMath/random.cpp"), ], ), DolphinLib( diff --git a/include/JSystem/JMath/random.h b/include/JSystem/JMath/random.h index ccae23a0f..cf910298c 100644 --- a/include/JSystem/JMath/random.h +++ b/include/JSystem/JMath/random.h @@ -29,6 +29,20 @@ struct TRandom_fast_ { void setSeed(u32 seed) { value = seed; } }; + +struct TRandom_enough_ { + TRandom_enough_() { setSeed(0); } + void setSeed(u32 value); + f32 get(); + + void next_() { + field_0x0 = ((u64)field_0x0 * 0x41a7) % 0x7fffffff; + } + + u32 field_0x0; + u32 field_0x4; + u32 field_0x8[32]; +}; } // namespace JMath #endif /* RANDOM_H */ diff --git a/src/JSystem/JMath/random.cpp b/src/JSystem/JMath/random.cpp index f576d8b56..1c6997cf0 100644 --- a/src/JSystem/JMath/random.cpp +++ b/src/JSystem/JMath/random.cpp @@ -3,21 +3,38 @@ // Translation Unit: random.cpp // -#include "random.h" +#include "JSystem/JMath/random.h" #include "dolphin/types.h" /* 80301350-80301358 .text __ct__Q25JMath13TRandom_fast_FUl */ -JMath::TRandom_fast_::TRandom_fast_(unsigned long) { - /* Nonmatching */ +JMath::TRandom_fast_::TRandom_fast_(u32 value) { + this->value = value; } /* 80301358-8030142C .text setSeed__Q25JMath15TRandom_enough_FUl */ -void JMath::TRandom_enough_::setSeed(unsigned long) { - /* Nonmatching */ +void JMath::TRandom_enough_::setSeed(u32 value) { + field_0x4 = 0; + field_0x0 = value + 1; + if (field_0x0 == 0) { + field_0x0 += 1; + } + u32 i; + for (i = 8; i != 0; i--) { + next_(); + } + for (i = 32; i != 0;) { + i--; + next_(); + field_0x8[i] = field_0x0; + } } /* 8030142C-803014CC .text get__Q25JMath15TRandom_enough_Fv */ -void JMath::TRandom_enough_::get() { - /* Nonmatching */ +f32 JMath::TRandom_enough_::get() { + next_(); + u8 idx = (field_0x4 >> 24 & ~3) / 4; + field_0x4 = field_0x8[idx]; + field_0x8[idx] = field_0x0; + f32 var3 = field_0x4 * 4.656613E-10f; + return var3 < 0.9999999f ? var3 : 0.9999999f; } -