mirror of
https://github.com/zeldaret/st
synced 2026-09-06 19:00:57 -04:00
Misc things (#30)
* match random init * UnkSystem2_UnkSubSystem1_Derived1 related docs * match func_ov031_020e9108 and FileSelect_UnkClass7::vfunc_00 * improve func_02017ea4 * rename next functions * actor rupee improvements * update gitignore * fix broken match * fileselectmain improvements * fix broken match * more misc progress * fix build issues * fix regressions
This commit is contained in:
+48
-10
@@ -1,26 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "global.h"
|
||||
#include "nitro/math.h"
|
||||
#include "types.h"
|
||||
|
||||
struct Random {
|
||||
/* 00 */ u64 mRandomValue;
|
||||
/* 00 */ u16 mRandomValue[4];
|
||||
/* 08 */ u64 mFactor;
|
||||
/* 10 */ u64 mAddend;
|
||||
/* 18 */
|
||||
|
||||
/**
|
||||
* Generate a random number from 0 (inclusive) to `max` (exclusive)
|
||||
* @brief Gets the seed's value
|
||||
*/
|
||||
u32 Next(u64 min, u64 max) {
|
||||
mRandomValue = mAddend + mFactor * mRandomValue;
|
||||
u64 result;
|
||||
if ((max - min) == 0x100000000) {
|
||||
result = mRandomValue;
|
||||
} else {
|
||||
result = (mRandomValue >> 32) * (max - min);
|
||||
u64 GetRandomValue() {
|
||||
return *(u64 *) this->mRandomValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the seed's value
|
||||
*/
|
||||
void UpdateRandomValue() {
|
||||
*(u64 *) this->mRandomValue = this->mAddend + (this->mFactor * this->GetRandomValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generates a random number as a u16
|
||||
*/
|
||||
u16 Next16() {
|
||||
this->UpdateRandomValue();
|
||||
return this->GetRandomValue() >> 48;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generates a random number from 0 (inclusive) to `max` (exclusive) as a u32
|
||||
*/
|
||||
u32 Next32(u64 min, u64 max) {
|
||||
this->UpdateRandomValue();
|
||||
return (((this->GetRandomValue() >> 32) * (max - min)) >> 32) + min;
|
||||
}
|
||||
|
||||
u32 ConditionalNext32(u32 value) {
|
||||
this->UpdateRandomValue();
|
||||
|
||||
u64 result = this->GetRandomValue() >> 32;
|
||||
|
||||
if (value != 0) {
|
||||
result = (result * value) >> 32;
|
||||
}
|
||||
return (result >> 32) + min;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec2us &NextPos(u16 xMax, u16 yMax) {
|
||||
Vec2us pos;
|
||||
|
||||
pos.x = this->Next32(0, xMax);
|
||||
pos.y = this->Next32(0, yMax);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void Init();
|
||||
|
||||
Reference in New Issue
Block a user