mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
math: Rename frandom() to random_float() to match with random_int()
(cherry picked from commit 5e4c7b66c5
)
This commit is contained in:
parent
3d3c190cd4
commit
ed8955e60f
|
@ -38,7 +38,7 @@ constexpr inline T mix(const T a, const T b, TB amount)
|
|||
return a + (b - a) * amount;
|
||||
}
|
||||
|
||||
inline float frandom() { return rand() / (float)(RAND_MAX); }
|
||||
inline float random_float() { return rand() / (float)(RAND_MAX); }
|
||||
|
||||
// float to fixed
|
||||
constexpr inline int f2fx(float v) { return (int)(v * (float)(1 << 10)); }
|
||||
|
|
|
@ -42,7 +42,7 @@ void CDamageInd::Create(vec2 Pos, vec2 Dir)
|
|||
i->m_Pos = Pos;
|
||||
i->m_StartTime = LocalTime();
|
||||
i->m_Dir = Dir * -1;
|
||||
i->m_StartAngle = (((float)rand() / (float)RAND_MAX) - 1.0f) * 2.0f * pi;
|
||||
i->m_StartAngle = (random_float() - 1.0f) * 2.0f * pi;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "effects.h"
|
||||
|
||||
inline vec2 RandomDir() { return normalize(vec2(frandom() - 0.5f, frandom() - 0.5f)); }
|
||||
inline vec2 RandomDir() { return normalize(vec2(random_float() - 0.5f, random_float() - 0.5f)); }
|
||||
|
||||
CEffects::CEffects()
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ void CEffects::AirJump(vec2 Pos)
|
|||
p.m_LifeSpan = 0.5f;
|
||||
p.m_StartSize = 48.0f;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Rot = frandom() * pi * 2;
|
||||
p.m_Rot = random_float() * pi * 2;
|
||||
p.m_Rotspeed = pi * 2;
|
||||
p.m_Gravity = 500;
|
||||
p.m_Friction = 0.7f;
|
||||
|
@ -69,12 +69,12 @@ void CEffects::PowerupShine(vec2 Pos, vec2 size)
|
|||
CParticle p;
|
||||
p.SetDefault();
|
||||
p.m_Spr = SPRITE_PART_SLICE;
|
||||
p.m_Pos = Pos + vec2((frandom() - 0.5f) * size.x, (frandom() - 0.5f) * size.y);
|
||||
p.m_Pos = Pos + vec2((random_float() - 0.5f) * size.x, (random_float() - 0.5f) * size.y);
|
||||
p.m_Vel = vec2(0, 0);
|
||||
p.m_LifeSpan = 0.5f;
|
||||
p.m_StartSize = 16.0f;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Rot = frandom() * pi * 2;
|
||||
p.m_Rot = random_float() * pi * 2;
|
||||
p.m_Rotspeed = pi * 2;
|
||||
p.m_Gravity = 500;
|
||||
p.m_Friction = 0.9f;
|
||||
|
@ -92,11 +92,11 @@ void CEffects::SmokeTrail(vec2 Pos, vec2 Vel, float Alpha, float TimePassed)
|
|||
p.m_Spr = SPRITE_PART_SMOKE;
|
||||
p.m_Pos = Pos;
|
||||
p.m_Vel = Vel + RandomDir() * 50.0f;
|
||||
p.m_LifeSpan = 0.5f + frandom() * 0.5f;
|
||||
p.m_StartSize = 12.0f + frandom() * 8;
|
||||
p.m_LifeSpan = 0.5f + random_float() * 0.5f;
|
||||
p.m_StartSize = 12.0f + random_float() * 8;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Friction = 0.7f;
|
||||
p.m_Gravity = frandom() * -500.0f;
|
||||
p.m_Gravity = random_float() * -500.0f;
|
||||
p.m_Color.a *= Alpha;
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_PROJECTILE_TRAIL, &p, TimePassed);
|
||||
}
|
||||
|
@ -111,11 +111,11 @@ void CEffects::SkidTrail(vec2 Pos, vec2 Vel)
|
|||
p.m_Spr = SPRITE_PART_SMOKE;
|
||||
p.m_Pos = Pos;
|
||||
p.m_Vel = Vel + RandomDir() * 50.0f;
|
||||
p.m_LifeSpan = 0.5f + frandom() * 0.5f;
|
||||
p.m_StartSize = 24.0f + frandom() * 12;
|
||||
p.m_LifeSpan = 0.5f + random_float() * 0.5f;
|
||||
p.m_StartSize = 24.0f + random_float() * 12;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Friction = 0.7f;
|
||||
p.m_Gravity = frandom() * -500.0f;
|
||||
p.m_Gravity = random_float() * -500.0f;
|
||||
p.m_Color = ColorRGBA(0.75f, 0.75f, 0.75f, 1.0f);
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_GENERAL, &p);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ void CEffects::BulletTrail(vec2 Pos, float Alpha, float TimePassed)
|
|||
p.SetDefault();
|
||||
p.m_Spr = SPRITE_PART_BALL;
|
||||
p.m_Pos = Pos;
|
||||
p.m_LifeSpan = 0.25f + frandom() * 0.25f;
|
||||
p.m_LifeSpan = 0.25f + random_float() * 0.25f;
|
||||
p.m_StartSize = 8.0f;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Friction = 0.7f;
|
||||
|
@ -145,13 +145,13 @@ void CEffects::PlayerSpawn(vec2 Pos)
|
|||
p.SetDefault();
|
||||
p.m_Spr = SPRITE_PART_SHELL;
|
||||
p.m_Pos = Pos;
|
||||
p.m_Vel = RandomDir() * (powf(frandom(), 3) * 600.0f);
|
||||
p.m_LifeSpan = 0.3f + frandom() * 0.3f;
|
||||
p.m_StartSize = 64.0f + frandom() * 32;
|
||||
p.m_Vel = RandomDir() * (powf(random_float(), 3) * 600.0f);
|
||||
p.m_LifeSpan = 0.3f + random_float() * 0.3f;
|
||||
p.m_StartSize = 64.0f + random_float() * 32;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Rot = frandom() * pi * 2;
|
||||
p.m_Rotspeed = frandom();
|
||||
p.m_Gravity = frandom() * -400.0f;
|
||||
p.m_Rot = random_float() * pi * 2;
|
||||
p.m_Rotspeed = random_float();
|
||||
p.m_Gravity = random_float() * -400.0f;
|
||||
p.m_Friction = 0.7f;
|
||||
p.m_Color = ColorRGBA(0xb5 / 255.0f, 0x50 / 255.0f, 0xcb / 255.0f, 1.0f);
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_GENERAL, &p);
|
||||
|
@ -180,15 +180,15 @@ void CEffects::PlayerDeath(vec2 Pos, int ClientID)
|
|||
p.SetDefault();
|
||||
p.m_Spr = SPRITE_PART_SPLAT01 + (rand() % 3);
|
||||
p.m_Pos = Pos;
|
||||
p.m_Vel = RandomDir() * ((frandom() + 0.1f) * 900.0f);
|
||||
p.m_LifeSpan = 0.3f + frandom() * 0.3f;
|
||||
p.m_StartSize = 24.0f + frandom() * 16;
|
||||
p.m_Vel = RandomDir() * ((random_float() + 0.1f) * 900.0f);
|
||||
p.m_LifeSpan = 0.3f + random_float() * 0.3f;
|
||||
p.m_StartSize = 24.0f + random_float() * 16;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Rot = frandom() * pi * 2;
|
||||
p.m_Rotspeed = (frandom() - 0.5f) * pi;
|
||||
p.m_Rot = random_float() * pi * 2;
|
||||
p.m_Rotspeed = (random_float() - 0.5f) * pi;
|
||||
p.m_Gravity = 800.0f;
|
||||
p.m_Friction = 0.8f;
|
||||
ColorRGBA c = BloodColor.v4() * (0.75f + frandom() * 0.25f);
|
||||
ColorRGBA c = BloodColor.v4() * (0.75f + random_float() * 0.25f);
|
||||
p.m_Color = ColorRGBA(c.r, c.g, c.b, 0.75f);
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_GENERAL, &p);
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ void CEffects::Explosion(vec2 Pos)
|
|||
p.m_LifeSpan = 0.4f;
|
||||
p.m_StartSize = 150.0f;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Rot = frandom() * pi * 2;
|
||||
p.m_Rot = random_float() * pi * 2;
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_EXPLOSIONS, &p);
|
||||
|
||||
// add the smoke
|
||||
|
@ -225,13 +225,13 @@ void CEffects::Explosion(vec2 Pos)
|
|||
p.SetDefault();
|
||||
p.m_Spr = SPRITE_PART_SMOKE;
|
||||
p.m_Pos = Pos;
|
||||
p.m_Vel = RandomDir() * ((1.0f + frandom() * 0.2f) * 1000.0f);
|
||||
p.m_LifeSpan = 0.5f + frandom() * 0.4f;
|
||||
p.m_StartSize = 32.0f + frandom() * 8;
|
||||
p.m_Vel = RandomDir() * ((1.0f + random_float() * 0.2f) * 1000.0f);
|
||||
p.m_LifeSpan = 0.5f + random_float() * 0.4f;
|
||||
p.m_StartSize = 32.0f + random_float() * 8;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Gravity = frandom() * -800.0f;
|
||||
p.m_Gravity = random_float() * -800.0f;
|
||||
p.m_Friction = 0.4f;
|
||||
p.m_Color = mix(vec4(0.75f, 0.75f, 0.75f, 1.0f), vec4(0.5f, 0.5f, 0.5f, 1.0f), frandom());
|
||||
p.m_Color = mix(vec4(0.75f, 0.75f, 0.75f, 1.0f), vec4(0.5f, 0.5f, 0.5f, 1.0f), random_float());
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_GENERAL, &p);
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ void CEffects::HammerHit(vec2 Pos)
|
|||
p.m_LifeSpan = 0.3f;
|
||||
p.m_StartSize = 120.0f;
|
||||
p.m_EndSize = 0;
|
||||
p.m_Rot = frandom() * pi * 2;
|
||||
p.m_Rot = random_float() * pi * 2;
|
||||
m_pClient->m_Particles.Add(CParticles::GROUP_EXPLOSIONS, &p);
|
||||
if(g_Config.m_SndGame)
|
||||
m_pClient->m_Sounds.PlayAt(CSounds::CHN_WORLD, SOUND_HAMMER_HIT, 1.0f, Pos);
|
||||
|
|
|
@ -550,7 +550,7 @@ void CItems::ReconstructSmokeTrail(const CProjectileData *pCurrent, int DestroyT
|
|||
float Step = maximum(Client()->FrameTimeAvg(), (pCurrent->m_Type == WEAPON_GRENADE) ? 0.02f : 0.01f);
|
||||
for(int i = 1 + (int)(Gt / Step); i < (int)(T / Step); i++)
|
||||
{
|
||||
float t = Step * (float)i + 0.4f * Step * (frandom() - 0.5f);
|
||||
float t = Step * (float)i + 0.4f * Step * (random_float() - 0.5f);
|
||||
vec2 Pos = CalcPos(pCurrent->m_StartPos, pCurrent->m_StartVel, Curvature, Speed, t);
|
||||
vec2 PrevPos = CalcPos(pCurrent->m_StartPos, pCurrent->m_StartVel, Curvature, Speed, t - 0.001f);
|
||||
vec2 Vel = Pos - PrevPos;
|
||||
|
|
|
@ -105,7 +105,7 @@ void CParticles::Update(float TimePassed)
|
|||
|
||||
// move the point
|
||||
vec2 Vel = m_aParticles[i].m_Vel * TimePassed;
|
||||
Collision()->MovePoint(&m_aParticles[i].m_Pos, &Vel, 0.1f + 0.9f * frandom(), NULL);
|
||||
Collision()->MovePoint(&m_aParticles[i].m_Pos, &Vel, 0.1f + 0.9f * random_float(), NULL);
|
||||
m_aParticles[i].m_Vel = Vel * (1.0f / TimePassed);
|
||||
|
||||
m_aParticles[i].m_Life += TimePassed;
|
||||
|
|
Loading…
Reference in a new issue