JMath::random

This commit is contained in:
Jcw87
2023-12-14 18:39:42 -08:00
parent 71c4493009
commit c285bf4aca
3 changed files with 40 additions and 9 deletions
+1 -1
View File
@@ -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(
+14
View File
@@ -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 */
+25 -8
View File
@@ -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;
}