mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
- avoid inflation of random functions.
This commit is contained in:
parent
85e4022f77
commit
04e98f2f77
3 changed files with 23 additions and 17 deletions
|
@ -21,6 +21,11 @@ constexpr fixed_t FloatToFixed(double f)
|
|||
return int(f * (1 << b));
|
||||
}
|
||||
|
||||
constexpr fixed_t FloatToFixed(double f, int b)
|
||||
{
|
||||
return int(f * (1 << b));
|
||||
}
|
||||
|
||||
template<int b = 16>
|
||||
inline constexpr fixed_t IntToFixed(int32_t f)
|
||||
{
|
||||
|
@ -33,6 +38,11 @@ inline constexpr double FixedToFloat(fixed_t f)
|
|||
return f * (1. / (1 << b));
|
||||
}
|
||||
|
||||
inline constexpr double FixedToFloat(fixed_t f, int b)
|
||||
{
|
||||
return f * (1. / (1 << b));
|
||||
}
|
||||
|
||||
template<int b = 16>
|
||||
inline constexpr int32_t FixedToInt(fixed_t f)
|
||||
{
|
||||
|
|
|
@ -537,19 +537,20 @@ inline uint8_t Chance(int a1)
|
|||
return wrand() < (a1 >> 1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
inline unsigned int Random(int a1)
|
||||
{
|
||||
return MulScale(wrand(), a1, 15);
|
||||
}
|
||||
|
||||
inline double RandomX(double a1)
|
||||
inline double RandomF(int a1)
|
||||
{
|
||||
return FixedToFloat<4>(Random(FloatToFixed<4>(a1)));
|
||||
return FixedToFloat(Random(a1));
|
||||
}
|
||||
|
||||
inline double RandomZ(double a1)
|
||||
inline double RandomF(double val, int scale)
|
||||
{
|
||||
return FixedToFloat<8>(Random(FloatToFixed<8>(a1)));
|
||||
return FixedToFloat(Random(FloatToFixed(val, scale)), scale);
|
||||
}
|
||||
|
||||
inline DAngle RandomAngle(int base = 2048)
|
||||
|
@ -557,6 +558,7 @@ inline DAngle RandomAngle(int base = 2048)
|
|||
return DAngle::fromBuild(MulScale(wrand(), base, 15));
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
inline int Random2(int a1)
|
||||
{
|
||||
return MulScale(wrand(), a1, 14) - a1;
|
||||
|
@ -564,21 +566,15 @@ inline int Random2(int a1)
|
|||
|
||||
inline double Random2F(int a1)
|
||||
{
|
||||
return FixedToFloat(MulScale(wrand(), a1, 14) - a1);
|
||||
return FixedToFloat(Random2(a1));
|
||||
}
|
||||
|
||||
inline double Random2X(double a1)
|
||||
inline double Random2F(double val, int scale)
|
||||
{
|
||||
return FixedToFloat<4>(Random2(FloatToFixed<4>(a1)));
|
||||
return FixedToFloat(Random2(FloatToFixed(val, scale)), scale);
|
||||
}
|
||||
|
||||
inline double Random2Z(double a1)
|
||||
{
|
||||
return FixedToFloat<8>(Random2(FloatToFixed<8>(a1)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------
|
||||
inline int Random3(int a1)
|
||||
{
|
||||
return MulScale(wrand() + wrand(), a1, 15) - a1;
|
||||
|
|
|
@ -455,9 +455,9 @@ void GibFX(walltype* pWall, GIBFX* pGFX, double ceilZ, const DVector3& spread, C
|
|||
for (int i = 0; i < nCount; i++)
|
||||
{
|
||||
DVector3 r;
|
||||
r.Z = RandomZ(spread.Z) + ceilZ;
|
||||
r.Y = RandomX(spread.Y) + pWall->pos.Y;
|
||||
r.X = RandomX(spread.X) + pWall->pos.X;
|
||||
r.Z = RandomF(spread.Z, 8) + ceilZ;
|
||||
r.Y = RandomF(spread.Y, 4) + pWall->pos.Y;
|
||||
r.X = RandomF(spread.X, 4) + pWall->pos.X;
|
||||
auto pGib = gFX.fxSpawnActor(pGFX->fxId, pSector, r, 0);
|
||||
if (pGib)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue