mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 21:06:43 +00:00
Unify random generator usage
This commit is contained in:
parent
46bf45a6e2
commit
41e90bd56c
2 changed files with 10 additions and 5 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/fallback/validate.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
#include <components/nifosg/nifloader.hpp>
|
||||
|
||||
#include "model/doc/document.hpp"
|
||||
|
@ -355,6 +356,8 @@ int CS::Editor::run()
|
|||
if (mLocal.empty())
|
||||
return 1;
|
||||
|
||||
Misc::Rng::init();
|
||||
|
||||
mStartup.show();
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed (true);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <osg/Geometry>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
#include <components/nif/controlled.hpp>
|
||||
#include <components/nif/nifkey.hpp>
|
||||
#include <components/nif/data.hpp>
|
||||
|
@ -81,17 +82,17 @@ ParticleShooter::ParticleShooter(const ParticleShooter ©, const osg::CopyOp
|
|||
|
||||
void ParticleShooter::shoot(osgParticle::Particle *particle) const
|
||||
{
|
||||
float hdir = mHorizontalDir + mHorizontalAngle * (2.f * (std::rand() / static_cast<double>(RAND_MAX)) - 1.f);
|
||||
float vdir = mVerticalDir + mVerticalAngle * (2.f * (std::rand() / static_cast<double>(RAND_MAX)) - 1.f);
|
||||
float hdir = mHorizontalDir + mHorizontalAngle * (2.f * Misc::Rng::rollClosedProbability() - 1.f);
|
||||
float vdir = mVerticalDir + mVerticalAngle * (2.f * Misc::Rng::rollClosedProbability() - 1.f);
|
||||
|
||||
osg::Vec3f dir = (osg::Quat(vdir, osg::Vec3f(0,1,0)) * osg::Quat(hdir, osg::Vec3f(0,0,1)))
|
||||
* osg::Vec3f(0,0,1);
|
||||
|
||||
float vel = mMinSpeed + (mMaxSpeed - mMinSpeed) * std::rand() / static_cast<float>(RAND_MAX);
|
||||
float vel = mMinSpeed + (mMaxSpeed - mMinSpeed) * Misc::Rng::rollClosedProbability();
|
||||
particle->setVelocity(dir * vel);
|
||||
|
||||
// Not supposed to set this here, but there doesn't seem to be a better way of doing it
|
||||
particle->setLifeTime(mLifetime + mLifetimeRandom * std::rand() / static_cast<float>(RAND_MAX));
|
||||
particle->setLifeTime(mLifetime + mLifetimeRandom * Misc::Rng::rollClosedProbability());
|
||||
}
|
||||
|
||||
GrowFadeAffector::GrowFadeAffector(float growTime, float fadeTime)
|
||||
|
@ -277,7 +278,8 @@ void Emitter::emitParticles(double dt)
|
|||
|
||||
if (!mTargets.empty())
|
||||
{
|
||||
int randomRecIndex = mTargets[(std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * mTargets.size()];
|
||||
int randomIndex = Misc::Rng::rollClosedProbability() * (mTargets.size() - 1);
|
||||
int randomRecIndex = mTargets[randomIndex];
|
||||
|
||||
// we could use a map here for faster lookup
|
||||
FindGroupByRecIndex visitor(randomRecIndex);
|
||||
|
|
Loading…
Reference in a new issue