From eee42b2ea3aadd0af1ce67ed0fa07b8de0dd1770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 8 Apr 2023 23:10:05 +0200 Subject: [PATCH] Fix RNG usage Mostly boils down to having graphics functions use Renderer's RNG, update and similar functions Simulation's. --- src/PowderToy.cpp | 2 - src/PowderToyFontEditor.cpp | 2 - src/PowderToyRenderer.cpp | 1 - src/common/platform/Common.cpp | 2 +- src/common/tpt-rand.cpp | 18 ++++----- src/common/tpt-rand.h | 17 ++++---- src/graphics/Renderer.cpp | 6 +-- src/graphics/Renderer.h | 3 ++ src/gui/game/GOLTool.cpp | 12 +++--- src/gui/preview/PreviewView.cpp | 4 +- src/simulation/Air.cpp | 2 +- src/simulation/Element.cpp | 22 +++++------ src/simulation/Simulation.cpp | 66 +++++++++++++++---------------- src/simulation/Simulation.h | 2 + src/simulation/elements/ACID.cpp | 10 ++--- src/simulation/elements/AMTR.cpp | 2 +- src/simulation/elements/ANAR.cpp | 4 +- src/simulation/elements/ARAY.cpp | 4 +- src/simulation/elements/BANG.cpp | 12 +++--- src/simulation/elements/BCLN.cpp | 8 ++-- src/simulation/elements/BMTL.cpp | 6 +-- src/simulation/elements/BOMB.cpp | 4 +- src/simulation/elements/BOYL.cpp | 4 +- src/simulation/elements/BREC.cpp | 2 +- src/simulation/elements/BRMT.cpp | 4 +- src/simulation/elements/C5.cpp | 4 +- src/simulation/elements/CAUS.cpp | 2 +- src/simulation/elements/CBNW.cpp | 18 ++++----- src/simulation/elements/CFLM.cpp | 2 +- src/simulation/elements/CLNE.cpp | 6 +-- src/simulation/elements/CLST.cpp | 4 +- src/simulation/elements/CO2.cpp | 10 ++--- src/simulation/elements/COAL.cpp | 2 +- src/simulation/elements/CRMC.cpp | 2 +- src/simulation/elements/DEST.cpp | 10 ++--- src/simulation/elements/DEUT.cpp | 8 ++-- src/simulation/elements/DSTW.cpp | 12 +++--- src/simulation/elements/ELEC.cpp | 10 ++--- src/simulation/elements/EMP.cpp | 26 ++++++------ src/simulation/elements/EXOT.cpp | 14 +++---- src/simulation/elements/FILT.cpp | 10 ++--- src/simulation/elements/FIRE.cpp | 40 +++++++++---------- src/simulation/elements/FIRW.cpp | 14 +++---- src/simulation/elements/FOG.cpp | 4 +- src/simulation/elements/FRZW.cpp | 4 +- src/simulation/elements/FRZZ.cpp | 2 +- src/simulation/elements/FSEP.cpp | 6 +-- src/simulation/elements/FUSE.cpp | 6 +-- src/simulation/elements/FWRK.cpp | 24 +++++------ src/simulation/elements/GEL.cpp | 10 ++--- src/simulation/elements/GLOW.cpp | 4 +- src/simulation/elements/GOLD.cpp | 6 +-- src/simulation/elements/GOO.cpp | 2 +- src/simulation/elements/GRAV.cpp | 2 +- src/simulation/elements/GRVT.cpp | 4 +- src/simulation/elements/H2.cpp | 12 +++--- src/simulation/elements/ICEI.cpp | 4 +- src/simulation/elements/IGNT.cpp | 10 ++--- src/simulation/elements/IRON.cpp | 10 ++--- src/simulation/elements/ISOZ.cpp | 6 +-- src/simulation/elements/ISZS.cpp | 6 +-- src/simulation/elements/LAVA.cpp | 2 +- src/simulation/elements/LIGH.cpp | 26 ++++++------ src/simulation/elements/LITH.cpp | 12 +++--- src/simulation/elements/MERC.cpp | 8 ++-- src/simulation/elements/NBLE.cpp | 8 ++-- src/simulation/elements/NEUT.cpp | 44 ++++++++++----------- src/simulation/elements/O2.cpp | 10 ++--- src/simulation/elements/PBCN.cpp | 6 +-- src/simulation/elements/PCLN.cpp | 4 +- src/simulation/elements/PHOT.cpp | 26 ++++++------ src/simulation/elements/PIPE.cpp | 4 +- src/simulation/elements/PLNT.cpp | 10 ++--- src/simulation/elements/PLSM.cpp | 2 +- src/simulation/elements/PLUT.cpp | 2 +- src/simulation/elements/POLO.cpp | 4 +- src/simulation/elements/PQRT.cpp | 2 +- src/simulation/elements/PROT.cpp | 8 ++-- src/simulation/elements/PRTI.cpp | 12 +++--- src/simulation/elements/PRTO.cpp | 10 ++--- src/simulation/elements/PTNM.cpp | 8 ++-- src/simulation/elements/QRTZ.cpp | 14 +++---- src/simulation/elements/RIME.cpp | 2 +- src/simulation/elements/ROCK.cpp | 2 +- src/simulation/elements/RPEL.cpp | 4 +- src/simulation/elements/SHLD1.cpp | 4 +- src/simulation/elements/SHLD2.cpp | 4 +- src/simulation/elements/SHLD3.cpp | 4 +- src/simulation/elements/SHLD4.cpp | 2 +- src/simulation/elements/SING.cpp | 16 ++++---- src/simulation/elements/SLCN.cpp | 10 ++--- src/simulation/elements/SLTW.cpp | 8 ++-- src/simulation/elements/SNOW.cpp | 2 +- src/simulation/elements/SPNG.cpp | 14 +++---- src/simulation/elements/SPRK.cpp | 10 ++--- src/simulation/elements/STKM.cpp | 10 ++--- src/simulation/elements/THDR.cpp | 4 +- src/simulation/elements/TRON.cpp | 8 ++-- src/simulation/elements/TUNG.cpp | 14 +++---- src/simulation/elements/VIBR.cpp | 12 +++--- src/simulation/elements/VINE.cpp | 2 +- src/simulation/elements/VIRS.cpp | 6 +-- src/simulation/elements/WARP.cpp | 12 +++--- src/simulation/elements/WATR.cpp | 14 +++---- src/simulation/elements/WTRV.cpp | 2 +- src/simulation/elements/YEST.cpp | 4 +- src/simulation/simtools/MIX.cpp | 6 +-- 107 files changed, 466 insertions(+), 467 deletions(-) diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp index 4a3a85530..39b663858 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToy.cpp @@ -164,7 +164,6 @@ struct ExplicitSingletons http::RequestManagerPtr requestManager; std::unique_ptr client; std::unique_ptr saveRenderer; - std::unique_ptr rng; std::unique_ptr favorite; std::unique_ptr engine; std::unique_ptr gameController; @@ -344,7 +343,6 @@ int main(int argc, char * argv[]) Client::Ref().Initialize(); explicitSingletons->saveRenderer = std::make_unique(); - explicitSingletons->rng = std::make_unique(); explicitSingletons->favorite = std::make_unique(); explicitSingletons->engine = std::make_unique(); diff --git a/src/PowderToyFontEditor.cpp b/src/PowderToyFontEditor.cpp index 7421bf4b9..a4f140805 100644 --- a/src/PowderToyFontEditor.cpp +++ b/src/PowderToyFontEditor.cpp @@ -28,7 +28,6 @@ void TickClient() struct ExplicitSingletons { // These need to be listed in the order they are populated in main. - std::unique_ptr rng; std::unique_ptr engine; }; static std::unique_ptr explicitSingletons; @@ -61,7 +60,6 @@ int main(int argc, char * argv[]) if(scale < 1 || scale > 10) scale = 1; - explicitSingletons->rng = std::make_unique(); explicitSingletons->engine = std::make_unique(); SDLOpen(); diff --git a/src/PowderToyRenderer.cpp b/src/PowderToyRenderer.cpp index 73dbe9c60..18f911bca 100644 --- a/src/PowderToyRenderer.cpp +++ b/src/PowderToyRenderer.cpp @@ -39,7 +39,6 @@ int main(int argc, char *argv[]) throw e; } - auto rng = std::make_unique(); Simulation * sim = new Simulation(); Renderer * ren = new Renderer(sim); diff --git a/src/common/platform/Common.cpp b/src/common/platform/Common.cpp index af9013e61..2b15b4d47 100644 --- a/src/common/platform/Common.cpp +++ b/src/common/platform/Common.cpp @@ -76,7 +76,7 @@ bool WriteFile(const std::vector &fileData, ByteString filename) { while (true) { - writeFileName = ByteString::Build(filename, ".temp.", Format::Width(5), Format::Fill('0'), random_gen() % 100000); + writeFileName = ByteString::Build(filename, ".temp.", Format::Width(5), Format::Fill('0'), interfaceRng() % 100000); if (!FileExists(writeFileName)) { break; diff --git a/src/common/tpt-rand.cpp b/src/common/tpt-rand.cpp index 1c00a922e..5a076d8c7 100644 --- a/src/common/tpt-rand.cpp +++ b/src/common/tpt-rand.cpp @@ -9,7 +9,7 @@ static inline uint64_t rotl(const uint64_t x, int k) return (x << k) | (x >> (64 - k)); } -uint64_t RNGType::next() +uint64_t RNG::next() { const uint64_t s0 = s[0]; uint64_t s1 = s[1]; @@ -22,44 +22,44 @@ uint64_t RNGType::next() return result; } -unsigned int RNGType::gen() +unsigned int RNG::gen() { return next() & 0x7FFFFFFF; } -unsigned int RNGType::operator()() +unsigned int RNG::operator()() { return next()&0xFFFFFFFF; } -int RNGType::between(int lower, int upper) +int RNG::between(int lower, int upper) { unsigned int r = next(); return static_cast(r % (upper - lower + 1)) + lower; } -bool RNGType::chance(int nominator, unsigned int denominator) +bool RNG::chance(int nominator, unsigned int denominator) { if (nominator < 0) return false; return next() % denominator < static_cast(nominator); } -float RNGType::uniform01() +float RNG::uniform01() { return static_cast(next()&0xFFFFFFFF)/(float)0xFFFFFFFF; } -RNGType::RNGType() +RNG::RNG() { s[0] = time(NULL); s[1] = 614; } -void RNGType::seed(unsigned int sd) +void RNG::seed(unsigned int sd) { s[0] = sd; s[1] = sd; } -RNGType random_gen; +RNG interfaceRng; diff --git a/src/common/tpt-rand.h b/src/common/tpt-rand.h index 73ecb1584..508521def 100644 --- a/src/common/tpt-rand.h +++ b/src/common/tpt-rand.h @@ -1,11 +1,12 @@ #pragma once #include "ExplicitSingleton.h" #include +#include -class RNGType +class RNG { private: - uint64_t s[2]; + std::array s; uint64_t next(); public: unsigned int operator()(); @@ -14,13 +15,11 @@ public: bool chance(int nominator, unsigned int denominator); float uniform01(); - RNGType(); + RNG(); void seed(unsigned int sd); }; -// Needed because we also have random_gen, and that would take the singleton role if RNGType had an ExplicitSingleton base. -class RNG : public RNGType, public ExplicitSingleton -{ -}; - -extern RNGType random_gen; +// Please only use this on the main thread and never for simulation stuff. +// For simulation stuff, use Simulation::rng. For renderer stuff, use Renderer::rng. +// For anything else, prefer a dedicated RNG instance over this one. +extern RNG interfaceRng; diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 48792f577..cc3ccf52e 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -589,7 +589,7 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_SPARK) { - flicker = float(random_gen()%20); + flicker = float(rng()%20); gradv = 4*sim->parts[i].life + flicker; for (x = 0; gradv>0.5; x++) { addpixel(nx+x, ny, colr, colg, colb, int(gradv)); @@ -602,7 +602,7 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_FLARE) { - flicker = float(random_gen()%20); + flicker = float(rng()%20); gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; blendpixel(nx, ny, colr, colg, colb, int((gradv*4)>255?255:(gradv*4)) ); blendpixel(nx+1, ny, colr, colg, colb,int( (gradv*2)>255?255:(gradv*2)) ); @@ -624,7 +624,7 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_LFLARE) { - flicker = float(random_gen()%20); + flicker = float(rng()%20); gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; blendpixel(nx, ny, colr, colg, colb, int((gradv*4)>255?255:(gradv*4)) ); blendpixel(nx+1, ny, colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ); diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index 55df6f507..9fc1206d0 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -5,6 +5,7 @@ #include #include "Graphics.h" #include "gui/interface/Point.h" +#include "common/tpt-rand.h" #include "SimulationConfig.h" class RenderPreset; @@ -58,6 +59,8 @@ public: return video.data(); } + RNG rng; + Simulation * sim; gcache_item *graphicscache; diff --git a/src/gui/game/GOLTool.cpp b/src/gui/game/GOLTool.cpp index 1f87cd63d..57347ef1e 100644 --- a/src/gui/game/GOLTool.cpp +++ b/src/gui/game/GOLTool.cpp @@ -111,13 +111,13 @@ GOLWindow::GOLWindow(GameModel &gameModel_, Simulation *sim_, int toolSelection, auto &prefs = GlobalPrefs::Ref(); ruleField->SetText(prefs.Get("CustomGOL.Rule", String("B3/S23"))); nameField->SetText(prefs.Get("CustomGOL.Name", String("CGOL"))); - highColour.Red = RNG::Ref().between(0x80, 0xFF); - highColour.Green = RNG::Ref().between(0x80, 0xFF); - highColour.Blue = RNG::Ref().between(0x80, 0xFF); + highColour.Red = interfaceRng.between(0x80, 0xFF); + highColour.Green = interfaceRng.between(0x80, 0xFF); + highColour.Blue = interfaceRng.between(0x80, 0xFF); highColour.Alpha = 0xFF; - lowColour.Red = RNG::Ref().between(0x00, 0x7F); - lowColour.Green = RNG::Ref().between(0x00, 0x7F); - lowColour.Blue = RNG::Ref().between(0x00, 0x7F); + lowColour.Red = interfaceRng.between(0x00, 0x7F); + lowColour.Green = interfaceRng.between(0x00, 0x7F); + lowColour.Blue = interfaceRng.between(0x00, 0x7F); lowColour.Alpha = 0xFF; } updateGradient(); diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index cece12d2b..c517c07b1 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -222,7 +222,7 @@ void PreviewView::CheckComment() { if (!commentHelpText) { - if (random_gen()%2) + if (interfaceRng()%2) commentWarningLabel->SetText("Stolen? Report the save instead"); else commentWarningLabel->SetText("Please report stolen saves"); @@ -238,7 +238,7 @@ void PreviewView::CheckComment() { if (!commentHelpText) { - if (random_gen()%2) + if (interfaceRng()%2) commentWarningLabel->SetText("Please do not swear"); else commentWarningLabel->SetText("Bad language may be deleted"); diff --git a/src/simulation/Air.cpp b/src/simulation/Air.cpp index 6fae5230e..13409f1e0 100644 --- a/src/simulation/Air.cpp +++ b/src/simulation/Air.cpp @@ -376,7 +376,7 @@ void Air::RecalculateBlockAirMaps() } } // mostly accurate insulator blocking, besides checking GEL - else if ((type == PT_HSWC && sim.parts[i].life != 10) || sim.elements[type].HeatConduct <= (random_gen()%250)) + else if ((type == PT_HSWC && sim.parts[i].life != 10) || sim.elements[type].HeatConduct <= (sim.rng()%250)) { int x = ((int)(sim.parts[i].x+0.5f))/CELL, y = ((int)(sim.parts[i].y+0.5f))/CELL; if (sim.InBounds(x, y) && !(bmap_blockairh[y][x]&0x8)) diff --git a/src/simulation/Element.cpp b/src/simulation/Element.cpp index a1dc23708..b503cb9eb 100644 --- a/src/simulation/Element.cpp +++ b/src/simulation/Element.cpp @@ -107,15 +107,15 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_WATR||TYP(r)==PT_DSTW||TYP(r)==PT_SLTW) && RNG::Ref().chance(1, 1000)) + if ((TYP(r)==PT_WATR||TYP(r)==PT_DSTW||TYP(r)==PT_SLTW) && sim->rng.chance(1, 1000)) { sim->part_change_type(i,x,y,PT_WATR); sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR); } - if ((TYP(r)==PT_ICEI || TYP(r)==PT_SNOW) && RNG::Ref().chance(1, 1000)) + if ((TYP(r)==PT_ICEI || TYP(r)==PT_SNOW) && sim->rng.chance(1, 1000)) { sim->part_change_type(i,x,y,PT_WATR); - if (RNG::Ref().chance(1, 1000)) + if (sim->rng.chance(1, 1000)) sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR); } } @@ -129,7 +129,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && RNG::Ref().chance(1, 10)) + if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && sim->rng.chance(1, 10)) { sim->part_change_type(i,x,y,PT_WTRV); } @@ -144,9 +144,9 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && RNG::Ref().chance(1, 10)) + if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && sim->rng.chance(1, 10)) { - if (RNG::Ref().chance(1, 4)) + if (sim->rng.chance(1, 4)) sim->part_change_type(i,x,y,PT_SALT); else sim->part_change_type(i,x,y,PT_WTRV); @@ -162,7 +162,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && RNG::Ref().chance(1, 10)) + if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && sim->rng.chance(1, 10)) { sim->part_change_type(i,x,y,PT_WTRV); } @@ -176,7 +176,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(1, 1000)) + if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && sim->rng.chance(1, 1000)) { sim->part_change_type(i,x,y,PT_ICEI); sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI); @@ -191,12 +191,12 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(1, 1000)) + if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && sim->rng.chance(1, 1000)) { sim->part_change_type(i,x,y,PT_ICEI); sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI); } - if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(3, 200)) + if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && sim->rng.chance(3, 200)) sim->part_change_type(i,x,y,PT_WATR); } } @@ -209,7 +209,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { if (t==PT_DESL && sim->pv[y/CELL][x/CELL]>12.0f) { sim->part_change_type(i,x,y,PT_FIRE); - parts[i].life = RNG::Ref().between(120, 169); + parts[i].life = sim->rng.between(120, 169); } return 0; } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index af3629c69..70a013eba 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -760,7 +760,7 @@ bool Simulation::flood_water(int x, int y, int i) if ((y - 1) > originalY && !pmap[y - 1][x]) { // Try to move the water to a random position on this line, because there's probably a free location somewhere - int randPos = RNG::Ref().between(x, x2); + int randPos = rng.between(x, x2); if (!pmap[y - 1][randPos] && eval_move(parts[i].type, randPos, y - 1, nullptr)) x = randPos; // Couldn't move to random position, so try the original position on the left @@ -975,7 +975,7 @@ int Simulation::get_wavelength_bin(int *wm) if (wM - w0 < 5) return wM + w0; - r = RNG::Ref().gen(); + r = rng.gen(); i = (r >> 1) % (wM-w0-4); i += w0; @@ -1387,7 +1387,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) e = eval_move(parts[i].type, nx, ny, &r); /* half-silvered mirror */ - if (!e && parts[i].type==PT_PHOT && ((TYP(r)==PT_BMTL && RNG::Ref().chance(1, 2)) || TYP(pmap[y][x])==PT_BMTL)) + if (!e && parts[i].type==PT_PHOT && ((TYP(r)==PT_BMTL && rng.chance(1, 2)) || TYP(pmap[y][x])==PT_BMTL)) e = 2; if (!e) //if no movement @@ -1437,7 +1437,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) return 0; } - int Element_FILT_interactWavelengths(Particle* cpart, int origWl); + int Element_FILT_interactWavelengths(Simulation *sim, Particle* cpart, int origWl); if (e == 2) //if occupy same space { switch (parts[i].type) @@ -1447,14 +1447,14 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) switch (TYP(r)) { case PT_GLOW: - if (!parts[ID(r)].life && RNG::Ref().chance(29, 30)) + if (!parts[ID(r)].life && rng.chance(29, 30)) { parts[ID(r)].life = 120; create_gain_photon(i); } break; case PT_FILT: - parts[i].ctype = Element_FILT_interactWavelengths(&parts[ID(r)], parts[i].ctype); + parts[i].ctype = Element_FILT_interactWavelengths(this, &parts[ID(r)], parts[i].ctype); break; case PT_C5: if (parts[ID(r)].life > 0 && (parts[ID(r)].ctype & parts[i].ctype & 0xFFFFFFC0)) @@ -1534,7 +1534,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) } case PT_NEUT: if (TYP(r) == PT_GLAS || TYP(r) == PT_BGLA) - if (RNG::Ref().chance(9, 10)) + if (rng.chance(9, 10)) create_cherenkov_photon(i); break; case PT_ELEC: @@ -1551,7 +1551,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) case PT_BIZR: case PT_BIZRG: if (TYP(r) == PT_FILT) - parts[i].ctype = Element_FILT_interactWavelengths(&parts[ID(r)], parts[i].ctype); + parts[i].ctype = Element_FILT_interactWavelengths(this, &parts[ID(r)], parts[i].ctype); break; } return 1; @@ -1611,7 +1611,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) case PT_SOAP: if (parts[i].type == PT_OIL) { - if (RNG::Ref().chance(19, 20) || std::abs(parts[i].x - nx) > 3 || std::abs(parts[i].y - ny) > 3) + if (rng.chance(19, 20) || std::abs(parts[i].x - nx) > 3 || std::abs(parts[i].y - ny) > 3) return 0; } break; @@ -2124,13 +2124,13 @@ int Simulation::create_part(int p, int x, int y, int t, int v) if((elements[t].Properties & TYPE_PART) && pretty_powder) { int colr, colg, colb; - colr = PIXR(elements[t].Colour) + int(sandcolour * 1.3) + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); - colg = PIXG(elements[t].Colour) + int(sandcolour * 1.3) + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); - colb = PIXB(elements[t].Colour) + int(sandcolour * 1.3) + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15); + colr = PIXR(elements[t].Colour) + int(sandcolour * 1.3) + rng.between(-20, 20) + rng.between(-15, 15); + colg = PIXG(elements[t].Colour) + int(sandcolour * 1.3) + rng.between(-20, 20) + rng.between(-15, 15); + colb = PIXB(elements[t].Colour) + int(sandcolour * 1.3) + rng.between(-20, 20) + rng.between(-15, 15); colr = colr>255 ? 255 : (colr<0 ? 0 : colr); colg = colg>255 ? 255 : (colg<0 ? 0 : colg); colb = colb>255 ? 255 : (colb<0 ? 0 : colb); - parts[i].dcolour = (RNG::Ref().between(0, 149)<<24) | (colr<<16) | (colg<<8) | colb; + parts[i].dcolour = (rng.between(0, 149)<<24) | (colr<<16) | (colg<<8) | colb; } // Set non-static properties (such as randomly generated ones) @@ -2192,7 +2192,7 @@ void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLO return; i = pfree; - lr = 2*RNG::Ref().between(0, 1) - 1; // -1 or 1 + lr = 2*rng.between(0, 1) - 1; // -1 or 1 xx = parts[pp].x - lr*0.3*parts[pp].vy; yy = parts[pp].y + lr*0.3*parts[pp].vx; @@ -2247,7 +2247,7 @@ void Simulation::create_cherenkov_photon(int pp)//photons from NEUT going throug pfree = parts[i].life; if (i>parts_lastActiveIndex) parts_lastActiveIndex = i; - lr = RNG::Ref().between(0, 1); + lr = rng.between(0, 1); parts[i].type = PT_PHOT; parts[i].ctype = 0x00000F80; @@ -2398,11 +2398,11 @@ void Simulation::UpdateParticles(int start, int end) { #ifdef REALISTIC //The magic number controls diffusion speed - parts[i].vx += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f); - parts[i].vy += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f); + parts[i].vx += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); + parts[i].vy += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); #else - parts[i].vx += elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f); - parts[i].vy += elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f); + parts[i].vx += elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); + parts[i].vy += elements[t].Diffusion*(2.0f*rng.uniform01()-1.0f); #endif } @@ -2425,7 +2425,7 @@ void Simulation::UpdateParticles(int start, int end) if (!legacy_enable) { - if ((elements[t].Properties&TYPE_LIQUID) && (t!=PT_GEL || gel_scale > (1 + RNG::Ref().between(0, 254)))) + if ((elements[t].Properties&TYPE_LIQUID) && (t!=PT_GEL || gel_scale > (1 + rng.between(0, 254)))) { float convGravX, convGravY; GetGravityField(x, y, -2.0f, -2.0f, convGravX, convGravY); @@ -2448,7 +2448,7 @@ void Simulation::UpdateParticles(int start, int end) #ifdef REALISTIC if (t&&(t!=PT_HSWC||parts[i].life==10)&&(elements[t].HeatConduct*gel_scale)) #else - if (t && (t!=PT_HSWC||parts[i].life==10) && RNG::Ref().chance(int(elements[t].HeatConduct*gel_scale), 250)) + if (t && (t!=PT_HSWC||parts[i].life==10) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250)) #endif { if (aheat_enable && !(elements[t].Properties&PROP_NOAMBHEAT)) @@ -2605,7 +2605,7 @@ void Simulation::UpdateParticles(int start, int end) { pt = (c_heat - platent[t])/c_Cm; - t = RNG::Ref().chance(1, 4) ? PT_SALT : PT_WTRV; + t = rng.chance(1, 4) ? PT_SALT : PT_WTRV; } else { @@ -2613,7 +2613,7 @@ void Simulation::UpdateParticles(int start, int end) s = 0; } #else - t = RNG::Ref().chance(1, 4) ? PT_SALT : PT_WTRV; + t = rng.chance(1, 4) ? PT_SALT : PT_WTRV; #endif } else if (t == PT_BRMT) @@ -2759,7 +2759,7 @@ void Simulation::UpdateParticles(int start, int end) goto killed; if (t==PT_FIRE || t==PT_PLSM || t==PT_CFLM) - parts[i].life = RNG::Ref().between(120, 169); + parts[i].life = rng.between(120, 169); if (t == PT_LAVA) { if (parts[i].ctype == PT_BRMT) parts[i].ctype = PT_BMTL; @@ -2767,7 +2767,7 @@ void Simulation::UpdateParticles(int start, int end) else if (parts[i].ctype == PT_BGLA) parts[i].ctype = PT_GLAS; else if (parts[i].ctype == PT_PQRT) parts[i].ctype = PT_QRTZ; else if (parts[i].ctype == PT_LITH && parts[i].tmp2 > 3) parts[i].ctype = PT_GLAS; - parts[i].life = RNG::Ref().between(240, 359); + parts[i].life = rng.between(240, 359); } transitionOccurred = true; } @@ -2841,7 +2841,7 @@ void Simulation::UpdateParticles(int start, int end) //the basic explosion, from the .explosive variable if ((elements[t].Explosive&2) && pv[y/CELL][x/CELL]>2.5f) { - parts[i].life = RNG::Ref().between(180, 259); + parts[i].life = rng.between(180, 259); parts[i].temp = restrict_flt(elements[PT_FIRE].DefaultProperties.temp + (elements[t].Flammable/2), MIN_TEMP, MAX_TEMP); t = PT_FIRE; part_change_type(i,x,y,t); @@ -2897,7 +2897,7 @@ void Simulation::UpdateParticles(int start, int end) if (part_change_type(i,x,y,t)) goto killed; if (t == PT_FIRE) - parts[i].life = RNG::Ref().between(120, 169); + parts[i].life = rng.between(120, 169); transitionOccurred = true; } @@ -3143,7 +3143,7 @@ killed: continue; // reflection parts[i].flags |= FLAG_STAGNANT; - if (t==PT_NEUT && RNG::Ref().chance(1, 10)) + if (t==PT_NEUT && rng.chance(1, 10)) { kill_part(i); continue; @@ -3178,7 +3178,7 @@ killed: { if (TYP(r) == PT_CRMC) { - float r = RNG::Ref().between(-50, 50) * 0.01f, rx, ry, anrx, anry; + float r = rng.between(-50, 50) * 0.01f, rx, ry, anrx, anry; r = r * r * r; rx = cosf(r); ry = sinf(r); anrx = rx * nrx + ry * nry; @@ -3240,7 +3240,7 @@ killed: else { // Checking stagnant is cool, but then it doesn't update when you change it later. - if (water_equal_test && elements[t].Falldown == 2 && RNG::Ref().chance(1, 200)) + if (water_equal_test && elements[t].Falldown == 2 && rng.chance(1, 200)) { if (flood_water(x, y, i)) goto movedone; @@ -3263,7 +3263,7 @@ killed: else { s = 1; - r = RNG::Ref().between(0, 1) * 2 - 1;// position search direction (left/right first) + r = rng.between(0, 1) * 2 - 1;// position search direction (left/right first) if ((clear_x!=x || clear_y!=y || nt || surround_space) && (fabsf(parts[i].vx)>0.01f || fabsf(parts[i].vy)>0.01f)) { @@ -3745,7 +3745,7 @@ void Simulation::CheckStacking() excessive_stacking_found = 1; } } - else if (pmap_count[y][x]>1500 || (unsigned int)RNG::Ref().between(0, 1599) <= (pmap_count[y][x]+100)) + else if (pmap_count[y][x]>1500 || (unsigned int)rng.between(0, 1599) <= (pmap_count[y][x]+100)) { pmap_count[y][x] = pmap_count[y][x] + NPART; excessive_stacking_found = true; @@ -3846,7 +3846,7 @@ void Simulation::BeforeSim() } // check for stacking and create BHOL if found - if (force_stacking_check || RNG::Ref().chance(1, 10)) + if (force_stacking_check || rng.chance(1, 10)) { CheckStacking(); } diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 52397aef4..98944b97d 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -8,6 +8,7 @@ #include "MenuSection.h" #include "CoordStack.h" #include "gravity/GravityPtr.h" +#include "common/tpt-rand.h" #include "Element.h" #include "SimulationConfig.h" #include @@ -38,6 +39,7 @@ public: GravityPtr grav; Air * air; + RNG rng; std::vector signs; std::array elements; diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp index a0707bac5..2fe4e4f02 100644 --- a/src/simulation/elements/ACID.cpp +++ b/src/simulation/elements/ACID.cpp @@ -72,14 +72,14 @@ static int update(UPDATE_FUNC_ARGS) } else if (rt == PT_WTRV) { - if (RNG::Ref().chance(1, 250)) + if (sim->rng.chance(1, 250)) { sim->part_change_type(i, x, y, PT_CAUS); - parts[i].life = RNG::Ref().between(25, 74); + parts[i].life = sim->rng.between(25, 74); sim->kill_part(ID(r)); } } - else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && RNG::Ref().chance(sim->elements[rt].Hardness, 1000)) + else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && sim->rng.chance(sim->elements[rt].Hardness, 1000)) { if (sim->parts_avg(i, ID(r),PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid { @@ -110,8 +110,8 @@ static int update(UPDATE_FUNC_ARGS) } for (trade = 0; trade<2; trade++) { - rx = RNG::Ref().between(-2, 2); - ry = RNG::Ref().between(-2, 2); + rx = sim->rng.between(-2, 2); + ry = sim->rng.between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/AMTR.cpp b/src/simulation/elements/AMTR.cpp index bcf4428d4..b20169cee 100644 --- a/src/simulation/elements/AMTR.cpp +++ b/src/simulation/elements/AMTR.cpp @@ -66,7 +66,7 @@ static int update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } - if (RNG::Ref().chance(1, 10)) + if (sim->rng.chance(1, 10)) sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); else sim->kill_part(ID(r)); diff --git a/src/simulation/elements/ANAR.cpp b/src/simulation/elements/ANAR.cpp index 6864a75cf..666247ce7 100644 --- a/src/simulation/elements/ANAR.cpp +++ b/src/simulation/elements/ANAR.cpp @@ -59,10 +59,10 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_CFLM && RNG::Ref().chance(1, 4)) + if (TYP(r)==PT_CFLM && sim->rng.chance(1, 4)) { sim->part_change_type(i,x,y,PT_CFLM); - parts[i].life = RNG::Ref().between(50, 199); + parts[i].life = sim->rng.between(50, 199); parts[ID(r)].temp = parts[i].temp = 0; sim->pv[y/CELL][x/CELL] -= 0.5; } diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index 745ff1a2c..a8459dd61 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -128,8 +128,8 @@ static int update(UPDATE_FUNC_ARGS) { if (parts[r].tmp != 6) { - int Element_FILT_interactWavelengths(Particle* cpart, int origWl); - colored = Element_FILT_interactWavelengths(&parts[r], colored); + int Element_FILT_interactWavelengths(Simulation *sim, Particle* cpart, int origWl); + colored = Element_FILT_interactWavelengths(sim, &parts[r], colored); if (!colored) break; } diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp index ceb5fe1b9..e15074391 100644 --- a/src/simulation/elements/BANG.cpp +++ b/src/simulation/elements/BANG.cpp @@ -87,29 +87,29 @@ static int update(UPDATE_FUNC_ARGS) //Explode!! sim->pv[y/CELL][x/CELL] += 0.5f; parts[i].tmp = 0; - if (RNG::Ref().chance(1, 3)) + if (sim->rng.chance(1, 3)) { - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) { sim->create_part(i, x, y, PT_FIRE); } else { sim->create_part(i, x, y, PT_SMKE); - parts[i].life = RNG::Ref().between(500, 549); + parts[i].life = sim->rng.between(500, 549); } parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP); } else { - if (RNG::Ref().chance(1, 15)) + if (sim->rng.chance(1, 15)) { sim->create_part(i, x, y, PT_EMBR); parts[i].tmp = 0; parts[i].life = 50; parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP); - parts[i].vx = float(RNG::Ref().between(-10, 10)); - parts[i].vy = float(RNG::Ref().between(-10, 10)); + parts[i].vx = float(sim->rng.between(-10, 10)); + parts[i].vy = float(sim->rng.between(-10, 10)); } else { diff --git a/src/simulation/elements/BCLN.cpp b/src/simulation/elements/BCLN.cpp index e58431a3a..76565b2bf 100644 --- a/src/simulation/elements/BCLN.cpp +++ b/src/simulation/elements/BCLN.cpp @@ -52,7 +52,7 @@ constexpr float ADVECTION = 0.1f; static int update(UPDATE_FUNC_ARGS) { if (!parts[i].life && sim->pv[y/CELL][x/CELL]>4.0f) - parts[i].life = RNG::Ref().between(80, 119); + parts[i].life = sim->rng.between(80, 119); if (parts[i].life) { parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; @@ -84,10 +84,10 @@ static int update(UPDATE_FUNC_ARGS) } else { - if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_LIFE, parts[i].tmp); - else if (parts[i].ctype!=PT_LIGH || RNG::Ref().chance(1, 30)) + if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_LIFE, parts[i].tmp); + else if (parts[i].ctype!=PT_LIGH || sim->rng.chance(1, 30)) { - int np = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), TYP(parts[i].ctype)); + int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), TYP(parts[i].ctype)); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/BMTL.cpp b/src/simulation/elements/BMTL.cpp index aafaf0a1c..25bb58fec 100644 --- a/src/simulation/elements/BMTL.cpp +++ b/src/simulation/elements/BMTL.cpp @@ -58,14 +58,14 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_METL || TYP(r)==PT_IRON) && RNG::Ref().chance(1, 100)) + if ((TYP(r)==PT_METL || TYP(r)==PT_IRON) && sim->rng.chance(1, 100)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_BMTL); - parts[ID(r)].tmp = (parts[i].tmp<=7) ? parts[i].tmp=1 : parts[i].tmp - RNG::Ref().between(0, 4); + parts[ID(r)].tmp = (parts[i].tmp<=7) ? parts[i].tmp=1 : parts[i].tmp - sim->rng.between(0, 4); } } } - else if (parts[i].tmp==1 && RNG::Ref().chance(1, 1000)) + else if (parts[i].tmp==1 && sim->rng.chance(1, 1000)) { parts[i].tmp = 0; sim->part_change_type(i,x,y,PT_BRMT); diff --git a/src/simulation/elements/BOMB.cpp b/src/simulation/elements/BOMB.cpp index 6f3409813..bc44bc264 100644 --- a/src/simulation/elements/BOMB.cpp +++ b/src/simulation/elements/BOMB.cpp @@ -99,8 +99,8 @@ static int update(UPDATE_FUNC_ARGS) parts[nb].tmp = 0; parts[nb].life = 50; parts[nb].temp = MAX_TEMP; - parts[nb].vx = float(RNG::Ref().between(-20, 20)); - parts[nb].vy = float(RNG::Ref().between(-20, 20)); + parts[nb].vx = float(sim->rng.between(-20, 20)); + parts[nb].vy = float(sim->rng.between(-20, 20)); } } return 1; diff --git a/src/simulation/elements/BOYL.cpp b/src/simulation/elements/BOYL.cpp index 831970f94..34e5b81ba 100644 --- a/src/simulation/elements/BOYL.cpp +++ b/src/simulation/elements/BOYL.cpp @@ -71,12 +71,12 @@ static int update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_WATR) { - if (RNG::Ref().chance(1, 30)) + if (sim->rng.chance(1, 30)) sim->part_change_type(ID(r),x+rx,y+ry,PT_FOG); } else if (TYP(r)==PT_O2) { - if (RNG::Ref().chance(1, 9)) + if (sim->rng.chance(1, 9)) { sim->kill_part(ID(r)); sim->part_change_type(i,x,y,PT_WATR); diff --git a/src/simulation/elements/BREC.cpp b/src/simulation/elements/BREC.cpp index 070514599..eb54b9c87 100644 --- a/src/simulation/elements/BREC.cpp +++ b/src/simulation/elements/BREC.cpp @@ -51,7 +51,7 @@ static int update(UPDATE_FUNC_ARGS) { if (sim->pv[y/CELL][x/CELL]>10.0f) { - if (parts[i].temp>9000 && sim->pv[y/CELL][x/CELL]>30.0f && RNG::Ref().chance(1, 200)) + if (parts[i].temp>9000 && sim->pv[y/CELL][x/CELL]>30.0f && sim->rng.chance(1, 200)) { sim->part_change_type(i, x ,y ,PT_EXOT); parts[i].life = 1000; diff --git a/src/simulation/elements/BRMT.cpp b/src/simulation/elements/BRMT.cpp index 5413a92da..df63db836 100644 --- a/src/simulation/elements/BRMT.cpp +++ b/src/simulation/elements/BRMT.cpp @@ -60,9 +60,9 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_BREC && RNG::Ref().chance(1, tempFactor)) + if (TYP(r)==PT_BREC && sim->rng.chance(1, tempFactor)) { - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) { sim->create_part(ID(r), x+rx, y+ry, PT_THRM); } diff --git a/src/simulation/elements/C5.cpp b/src/simulation/elements/C5.cpp index 908eac6e9..baa78e60d 100644 --- a/src/simulation/elements/C5.cpp +++ b/src/simulation/elements/C5.cpp @@ -59,11 +59,11 @@ static int update(UPDATE_FUNC_ARGS) continue; if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||parts[ID(r)].life==10)) || TYP(r)==PT_CFLM) { - if (RNG::Ref().chance(1, 6)) + if (sim->rng.chance(1, 6)) { sim->part_change_type(i,x,y,PT_CFLM); parts[ID(r)].temp = parts[i].temp = 0; - parts[i].life = RNG::Ref().between(50, 199); + parts[i].life = sim->rng.between(50, 199); sim->pv[y/CELL][x/CELL] += 1.5; } } diff --git a/src/simulation/elements/CAUS.cpp b/src/simulation/elements/CAUS.cpp index 9aaec5e57..96faf1a04 100644 --- a/src/simulation/elements/CAUS.cpp +++ b/src/simulation/elements/CAUS.cpp @@ -66,7 +66,7 @@ static int update(UPDATE_FUNC_ARGS) } else if (TYP(r) != PT_ACID && TYP(r) != PT_CAUS && TYP(r) != PT_RFRG && TYP(r) != PT_RFGL) { - if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && RNG::Ref().chance(sim->elements[TYP(r)].Hardness, 1000)) && parts[i].life >= 50) + if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && sim->rng.chance(sim->elements[TYP(r)].Hardness, 1000)) && parts[i].life >= 50) { // GLAS protects stuff from acid if (sim->parts_avg(i, ID(r),PT_GLAS) != PT_GLAS) diff --git a/src/simulation/elements/CBNW.cpp b/src/simulation/elements/CBNW.cpp index 37e21cc95..2583bb311 100644 --- a/src/simulation/elements/CBNW.cpp +++ b/src/simulation/elements/CBNW.cpp @@ -53,7 +53,7 @@ static int update(UPDATE_FUNC_ARGS) int r, rx, ry; if (sim->pv[y/CELL][x/CELL]<=3) { - if (sim->pv[y/CELL][x/CELL] <= -0.5 || RNG::Ref().chance(1, 4000)) + if (sim->pv[y/CELL][x/CELL] <= -0.5 || sim->rng.chance(1, 4000)) { sim->part_change_type(i,x,y,PT_CO2); parts[i].ctype = 5; @@ -63,15 +63,15 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].tmp2!=20) { parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1; } - else if (RNG::Ref().chance(1, 200)) + else if (sim->rng.chance(1, 200)) { - parts[i].tmp2 = RNG::Ref().between(0, 39); + parts[i].tmp2 = sim->rng.between(0, 39); } if(parts[i].tmp>0) { //Explode - if(parts[i].tmp==1 && RNG::Ref().chance(3, 4)) + if(parts[i].tmp==1 && sim->rng.chance(3, 4)) { sim->part_change_type(i,x,y,PT_CO2); parts[i].ctype = 5; @@ -86,12 +86,12 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((sim->elements[TYP(r)].Properties&TYPE_PART) && parts[i].tmp == 0 && RNG::Ref().chance(1, 83)) + if ((sim->elements[TYP(r)].Properties&TYPE_PART) && parts[i].tmp == 0 && sim->rng.chance(1, 83)) { //Start explode - parts[i].tmp = RNG::Ref().between(0, 24); + parts[i].tmp = sim->rng.between(0, 24); } - else if((sim->elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && RNG::Ref().chance(int(2 - sim->pv[y/CELL][x/CELL]), 6667)) + else if((sim->elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && sim->rng.chance(int(2 - sim->pv[y/CELL][x/CELL]), 6667)) { sim->part_change_type(i,x,y,PT_CO2); parts[i].ctype = 5; @@ -117,7 +117,7 @@ static int update(UPDATE_FUNC_ARGS) } else if (TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) { - if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && RNG::Ref().chance(1, 166)) + if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && sim->rng.chance(1, 166)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -126,7 +126,7 @@ static int update(UPDATE_FUNC_ARGS) } else if (TYP(r)==PT_FIRE && parts[ID(r)].ctype!=PT_WATR){ sim->kill_part(ID(r)); - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { sim->kill_part(i); return 1; diff --git a/src/simulation/elements/CFLM.cpp b/src/simulation/elements/CFLM.cpp index cbc465af4..13b0c4cf4 100644 --- a/src/simulation/elements/CFLM.cpp +++ b/src/simulation/elements/CFLM.cpp @@ -68,5 +68,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].life = RNG::Ref().between(50, 199); + sim->parts[i].life = sim->rng.between(50, 199); } diff --git a/src/simulation/elements/CLNE.cpp b/src/simulation/elements/CLNE.cpp index 51188687d..21a57cba6 100644 --- a/src/simulation/elements/CLNE.cpp +++ b/src/simulation/elements/CLNE.cpp @@ -75,10 +75,10 @@ static int update(UPDATE_FUNC_ARGS) } else { - if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_LIFE, parts[i].tmp); - else if (parts[i].ctype!=PT_LIGH || RNG::Ref().chance(1, 30)) + if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_LIFE, parts[i].tmp); + else if (parts[i].ctype!=PT_LIGH || sim->rng.chance(1, 30)) { - int np = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), TYP(parts[i].ctype)); + int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), TYP(parts[i].ctype)); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/CLST.cpp b/src/simulation/elements/CLST.cpp index 25442207d..09b5c6f85 100644 --- a/src/simulation/elements/CLST.cpp +++ b/src/simulation/elements/CLST.cpp @@ -62,7 +62,7 @@ static int update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_WATR) { - if (RNG::Ref().chance(1, 1500)) + if (sim->rng.chance(1, 1500)) { sim->create_part(i, x, y, PT_PSTS); sim->kill_part(ID(r)); @@ -101,5 +101,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].tmp = RNG::Ref().between(0, 6); + sim->parts[i].tmp = sim->rng.between(0, 6); } diff --git a/src/simulation/elements/CO2.cpp b/src/simulation/elements/CO2.cpp index ca99fe5fb..256cba211 100644 --- a/src/simulation/elements/CO2.cpp +++ b/src/simulation/elements/CO2.cpp @@ -55,7 +55,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) { - if (parts[i].ctype==5 && RNG::Ref().chance(1, 2000)) + if (parts[i].ctype==5 && sim->rng.chance(1, 2000)) { if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0) parts[i].ctype = 0; @@ -65,13 +65,13 @@ static int update(UPDATE_FUNC_ARGS) if (TYP(r)==PT_FIRE) { sim->kill_part(ID(r)); - if (RNG::Ref().chance(1, 30)) + if (sim->rng.chance(1, 30)) { sim->kill_part(i); return 1; } } - else if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(1, 50)) + else if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && sim->rng.chance(1, 50)) { sim->part_change_type(ID(r), x+rx, y+ry, PT_CBNW); if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet @@ -88,14 +88,14 @@ static int update(UPDATE_FUNC_ARGS) } if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f) { - if (RNG::Ref().chance(1, 5)) + if (sim->rng.chance(1, 5)) { int j; sim->create_part(i,x,y,PT_O2); j = sim->create_part(-3,x,y,PT_NEUT); if (j != -1) parts[j].temp = MAX_TEMP; - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { j = sim->create_part(-3,x,y,PT_ELEC); if (j != -1) diff --git a/src/simulation/elements/COAL.cpp b/src/simulation/elements/COAL.cpp index c5d2b06cc..ce4e70eef 100644 --- a/src/simulation/elements/COAL.cpp +++ b/src/simulation/elements/COAL.cpp @@ -58,7 +58,7 @@ int Element_COAL_update(UPDATE_FUNC_ARGS) return 1; } else if (parts[i].life < 100) { parts[i].life--; - sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_FIRE); + sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_FIRE); } if (parts[i].type == PT_COAL) { diff --git a/src/simulation/elements/CRMC.cpp b/src/simulation/elements/CRMC.cpp index 517e07e3c..9dea24139 100644 --- a/src/simulation/elements/CRMC.cpp +++ b/src/simulation/elements/CRMC.cpp @@ -67,5 +67,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].tmp2 = RNG::Ref().between(0, 4); + sim->parts[i].tmp2 = sim->rng.between(0, 4); } diff --git a/src/simulation/elements/DEST.cpp b/src/simulation/elements/DEST.cpp index f7331e616..fd8172250 100644 --- a/src/simulation/elements/DEST.cpp +++ b/src/simulation/elements/DEST.cpp @@ -49,8 +49,8 @@ void Element::Element_DEST() static int update(UPDATE_FUNC_ARGS) { - int rx = RNG::Ref().between(-2, 2); - int ry = RNG::Ref().between(-2, 2); + int rx = sim->rng.between(-2, 2); + int ry = sim->rng.between(-2, 2); int r = pmap[y+ry][x+rx]; if (!r) return 0; @@ -60,13 +60,13 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].life<=0 || parts[i].life>37) { - parts[i].life = RNG::Ref().between(30, 49); + parts[i].life = sim->rng.between(30, 49); sim->pv[y/CELL][x/CELL]+=60.0f; } if (rt == PT_PLUT || rt == PT_DEUT) { sim->pv[y/CELL][x/CELL]+=20.0f; - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) { sim->create_part(ID(r), x+rx, y+ry, PT_NEUT); parts[ID(r)].temp = MAX_TEMP; @@ -78,7 +78,7 @@ static int update(UPDATE_FUNC_ARGS) { sim->create_part(ID(r), x+rx, y+ry, PT_PLSM); } - else if (RNG::Ref().chance(1, 3)) + else if (sim->rng.chance(1, 3)) { sim->kill_part(ID(r)); parts[i].life -= 4*((sim->elements[rt].Properties&TYPE_SOLID)?3:1); diff --git a/src/simulation/elements/DEUT.cpp b/src/simulation/elements/DEUT.cpp index 29e8525a0..d424d3ee9 100644 --- a/src/simulation/elements/DEUT.cpp +++ b/src/simulation/elements/DEUT.cpp @@ -58,7 +58,7 @@ static int update(UPDATE_FUNC_ARGS) // Prevent division by 0 float temp = std::max(1.0f, (parts[i].temp + 1)); auto maxlife = int(((10000/(temp + 1))-1)); - if (RNG::Ref().chance(10000 % static_cast(temp + 1), static_cast(temp + 1))) + if (sim->rng.chance(10000 % static_cast(temp + 1), static_cast(temp + 1))) maxlife++; // Compress when Newtonian gravity is applied // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf @@ -72,7 +72,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r || (parts[i].life >=maxlife)) continue; - if (TYP(r)==PT_DEUT&& RNG::Ref().chance(1, 3)) + if (TYP(r)==PT_DEUT&& sim->rng.chance(1, 3)) { // If neighbour life+1 fits in the free capacity for this particle, absorb neighbour // Condition is written in this way so that large neighbour life values don't cause integer overflow @@ -105,8 +105,8 @@ static int update(UPDATE_FUNC_ARGS) trade: for ( trade = 0; trade<4; trade ++) { - rx = RNG::Ref().between(-2, 2); - ry = RNG::Ref().between(-2, 2); + rx = sim->rng.between(-2, 2); + ry = sim->rng.between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/DSTW.cpp b/src/simulation/elements/DSTW.cpp index b557fbf41..4325edaaa 100644 --- a/src/simulation/elements/DSTW.cpp +++ b/src/simulation/elements/DSTW.cpp @@ -57,29 +57,29 @@ static int update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_SALT: - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { sim->part_change_type(i,x,y,PT_SLTW); // on average, convert 3 DSTW to SLTW before SALT turns into SLTW - if (RNG::Ref().chance(1, 3)) + if (sim->rng.chance(1, 3)) sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); } break; case PT_SLTW: - if (RNG::Ref().chance(1, 2000)) + if (sim->rng.chance(1, 2000)) { sim->part_change_type(i,x,y,PT_SLTW); break; } case PT_WATR: - if (RNG::Ref().chance(1, 100)) + if (sim->rng.chance(1, 100)) { sim->part_change_type(i,x,y,PT_WATR); } break; case PT_RBDM: case PT_LRBD: - if ((sim->legacy_enable||parts[i].temp>12.0f) && RNG::Ref().chance(1, 100)) + if ((sim->legacy_enable||parts[i].temp>12.0f) && sim->rng.chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -87,7 +87,7 @@ static int update(UPDATE_FUNC_ARGS) break; case PT_FIRE: sim->kill_part(ID(r)); - if (RNG::Ref().chance(1, 30)) + if (sim->rng.chance(1, 30)) { sim->kill_part(i); return 1; diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp index f8df72039..3ba475153 100644 --- a/src/simulation/elements/ELEC.cpp +++ b/src/simulation/elements/ELEC.cpp @@ -73,20 +73,20 @@ static int update(UPDATE_FUNC_ARGS) parts[nb].tmp = 0; parts[nb].life = 50; parts[nb].temp = parts[i].temp*0.8f; - parts[nb].vx = float(RNG::Ref().between(-10, 10)); - parts[nb].vy = float(RNG::Ref().between(-10, 10)); + parts[nb].vx = float(sim->rng.between(-10, 10)); + parts[nb].vy = float(sim->rng.between(-10, 10)); } } sim->kill_part(i); return 1; case PT_LCRY: - parts[ID(r)].tmp2 = RNG::Ref().between(5, 9); + parts[ID(r)].tmp2 = sim->rng.between(5, 9); break; case PT_WATR: case PT_DSTW: case PT_SLTW: case PT_CBNW: - if (RNG::Ref().chance(1, 3)) + if (sim->rng.chance(1, 3)) sim->create_part(ID(r), x+rx, y+ry, PT_O2); else sim->create_part(ID(r), x+rx, y+ry, PT_H2); @@ -139,7 +139,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + float a = sim->rng.between(0, 359) * 3.14159f / 180.0f; sim->parts[i].life = 680; sim->parts[i].vx = 2.0f * cosf(a); sim->parts[i].vy = 2.0f * sinf(a); diff --git a/src/simulation/elements/EMP.cpp b/src/simulation/elements/EMP.cpp index 20f3fdd34..c6ebabd26 100644 --- a/src/simulation/elements/EMP.cpp +++ b/src/simulation/elements/EMP.cpp @@ -66,7 +66,7 @@ public: } void apply(Simulation *sim, Particle &p) { - p.temp = restrict_flt(p.temp+getDelta(RNG::Ref().uniform01()), MIN_TEMP, MAX_TEMP); + p.temp = restrict_flt(p.temp+getDelta(sim->rng.uniform01()), MIN_TEMP, MAX_TEMP); } }; @@ -118,9 +118,9 @@ void Element_EMP_Trigger(Simulation *sim, int triggerCount) { is_elec = true; temp_center.apply(sim, parts[r]); - if (RNG::Ref().uniform01() < prob_changeCenter) + if (sim->rng.uniform01() < prob_changeCenter) { - if (RNG::Ref().chance(2, 5)) + if (sim->rng.chance(2, 5)) sim->part_change_type(r, rx, ry, PT_BREC); else sim->part_change_type(r, rx, ry, PT_NTCT); @@ -143,10 +143,10 @@ void Element_EMP_Trigger(Simulation *sim, int triggerCount) { case PT_METL: temp_metal.apply(sim, parts[n]); - if (RNG::Ref().uniform01() < prob_breakMETL) + if (sim->rng.uniform01() < prob_breakMETL) { sim->part_change_type(n, rx+nx, ry+ny, PT_BMTL); - if (RNG::Ref().uniform01() < prob_breakMETLMore) + if (sim->rng.uniform01() < prob_breakMETLMore) { sim->part_change_type(n, rx+nx, ry+ny, PT_BRMT); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); @@ -155,19 +155,19 @@ void Element_EMP_Trigger(Simulation *sim, int triggerCount) break; case PT_BMTL: temp_metal.apply(sim, parts[n]); - if (RNG::Ref().uniform01() < prob_breakBMTL) + if (sim->rng.uniform01() < prob_breakBMTL) { sim->part_change_type(n, rx+nx, ry+ny, PT_BRMT); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); } break; case PT_WIFI: - if (RNG::Ref().uniform01() < prob_randWIFI) + if (sim->rng.uniform01() < prob_randWIFI) { // Randomize channel - parts[n].temp = float(RNG::Ref().between(0, int(MAX_TEMP)-1)); + parts[n].temp = float(sim->rng.between(0, int(MAX_TEMP)-1)); } - if (RNG::Ref().uniform01() < prob_breakWIFI) + if (sim->rng.uniform01() < prob_breakWIFI) { sim->create_part(n, rx+nx, ry+ny, PT_BREC); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); @@ -180,22 +180,22 @@ void Element_EMP_Trigger(Simulation *sim, int triggerCount) switch (ntype) { case PT_SWCH: - if (RNG::Ref().uniform01() < prob_breakSWCH) + if (sim->rng.uniform01() < prob_breakSWCH) sim->part_change_type(n, rx+nx, ry+ny, PT_BREC); temp_SWCH.apply(sim, parts[n]); break; case PT_ARAY: - if (RNG::Ref().uniform01() < prob_breakARAY) + if (sim->rng.uniform01() < prob_breakARAY) { sim->create_part(n, rx+nx, ry+ny, PT_BREC); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); } break; case PT_DLAY: - if (RNG::Ref().uniform01() < prob_randDLAY) + if (sim->rng.uniform01() < prob_randDLAY) { // Randomize delay - parts[n].temp = RNG::Ref().between(0, 255) + 273.15f; + parts[n].temp = sim->rng.between(0, 255) + 273.15f; } break; default: diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index 331250906..3e9301245 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -64,7 +64,7 @@ static int update(UPDATE_FUNC_ARGS) rt = TYP(r); if (rt == PT_WARP) { - if (parts[ID(r)].tmp2>2000 && RNG::Ref().chance(1, 100)) + if (parts[ID(r)].tmp2>2000 && sim->rng.chance(1, 100)) { parts[i].tmp2 += 100; } @@ -73,7 +73,7 @@ static int update(UPDATE_FUNC_ARGS) { if (parts[ID(r)].ctype == PT_PROT) parts[i].ctype = PT_PROT; - if (parts[ID(r)].life == 1500 && RNG::Ref().chance(1, 1000)) + if (parts[ID(r)].life == 1500 && sim->rng.chance(1, 1000)) parts[i].life = 1500; } else if (rt == PT_LAVA) @@ -81,7 +81,7 @@ static int update(UPDATE_FUNC_ARGS) //turn molten TTAN or molten GOLD to molten VIBR if (parts[ID(r)].ctype == PT_TTAN || parts[ID(r)].ctype == PT_GOLD) { - if (RNG::Ref().chance(1, 10)) + if (sim->rng.chance(1, 10)) { parts[ID(r)].ctype = PT_VIBR; sim->kill_part(i); @@ -91,7 +91,7 @@ static int update(UPDATE_FUNC_ARGS) //molten VIBR will kill the leftover EXOT though, so the VIBR isn't killed later else if (parts[ID(r)].ctype == PT_VIBR) { - if (RNG::Ref().chance(1, 1000)) + if (sim->rng.chance(1, 1000)) { sim->kill_part(i); return 1; @@ -138,8 +138,8 @@ static int update(UPDATE_FUNC_ARGS) { for (trade = 0; trade < 9; trade++) { - rx = RNG::Ref().between(-2, 2); - ry = RNG::Ref().between(-2, 2); + rx = sim->rng.between(-2, 2); + ry = sim->rng.between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; @@ -193,7 +193,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) auto c = cpart->tmp2; if (cpart->life < 1001) { - if (RNG::Ref().chance(cpart->tmp2 - 1, 1000)) + if (ren->rng.chance(cpart->tmp2 - 1, 1000)) { float frequency = 0.04045f; *colr = int(sin(frequency*c + 4) * 127 + 150); diff --git a/src/simulation/elements/FILT.cpp b/src/simulation/elements/FILT.cpp index c377396db..659a66f8f 100644 --- a/src/simulation/elements/FILT.cpp +++ b/src/simulation/elements/FILT.cpp @@ -2,7 +2,7 @@ static int graphics(GRAPHICS_FUNC_ARGS); static void create(ELEMENT_CREATE_FUNC_ARGS); -int Element_FILT_interactWavelengths(Particle* cpart, int origWl); +int Element_FILT_interactWavelengths(Simulation *sim, Particle* cpart, int origWl); int Element_FILT_getWavelengths(Particle* cpart); void Element::Element_FILT() @@ -81,7 +81,7 @@ static void create(ELEMENT_CREATE_FUNC_ARGS) // Returns the wavelengths in a particle after FILT interacts with it (e.g. a photon) // cpart is the FILT particle, origWl the original wavelengths in the interacting particle -int Element_FILT_interactWavelengths(Particle* cpart, int origWl) +int Element_FILT_interactWavelengths(Simulation *sim, Particle* cpart, int origWl) { const int mask = 0x3FFFFFFF; int filtWl = Element_FILT_getWavelengths(cpart); @@ -115,9 +115,9 @@ int Element_FILT_interactWavelengths(Particle* cpart, int origWl) return (~origWl) & mask; // Invert colours case 9: { - int t1 = (origWl & 0x0000FF) + RNG::Ref().between(-2, 2); - int t2 = ((origWl & 0x00FF00)>>8) + RNG::Ref().between(-2, 2); - int t3 = ((origWl & 0xFF0000)>>16) + RNG::Ref().between(-2, 2); + int t1 = (origWl & 0x0000FF) + sim->rng.between(-2, 2); + int t2 = ((origWl & 0x00FF00)>>8) + sim->rng.between(-2, 2); + int t3 = ((origWl & 0xFF0000)>>16) + sim->rng.between(-2, 2); return (origWl & 0xFF000000) | (t3<<16) | (t2<<8) | t1; } case 10: diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index 8e62a1c2a..b97f64310 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -83,7 +83,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) else if (parts[i].temp<625) { sim->part_change_type(i,x,y,PT_SMKE); - parts[i].life = RNG::Ref().between(250, 269); + parts[i].life = sim->rng.between(250, 269); } } break; @@ -97,34 +97,34 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) break; } - if (pres >= 25 && RNG::Ref().chance(1, 12500)) + if (pres >= 25 && sim->rng.chance(1, 12500)) { if (pres <= 50) { - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) parts[i].ctype = PT_BRMT; else parts[i].ctype = PT_CNCT; } else if (pres <= 75) { - if (pres >= 73 || RNG::Ref().chance(1, 8)) + if (pres >= 73 || sim->rng.chance(1, 8)) parts[i].ctype = PT_GOLD; else parts[i].ctype = PT_QRTZ; } else if (pres <= 100 && parts[i].temp >= 5000) { - if (RNG::Ref().chance(1, 5)) // 1 in 5 chance IRON to TTAN + if (sim->rng.chance(1, 5)) // 1 in 5 chance IRON to TTAN parts[i].ctype = PT_TTAN; else parts[i].ctype = PT_IRON; } - else if (parts[i].temp >= 5000 && RNG::Ref().chance(1, 5)) + else if (parts[i].temp >= 5000 && sim->rng.chance(1, 5)) { - if (RNG::Ref().chance(1, 5)) + if (sim->rng.chance(1, 5)) parts[i].ctype = PT_URAN; - else if (RNG::Ref().chance(1, 5)) + else if (sim->rng.chance(1, 5)) parts[i].ctype = PT_PLUT; else parts[i].ctype = PT_TUNG; @@ -133,7 +133,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) } else if ((parts[i].ctype == PT_STNE || !parts[i].ctype) && pres >= 30.0f && (parts[i].temp > sim->elements[PT_ROCK].HighTemperature || pres < sim->elements[PT_ROCK].HighPressure)) // Form ROCK with pressure, if it will stay molten or not immediately break { - parts[i].tmp2 = RNG::Ref().between(0, 10); // Provide tmp2 for color noise + parts[i].tmp2 = sim->rng.between(0, 10); // Provide tmp2 for color noise parts[i].ctype = PT_ROCK; } break; @@ -153,7 +153,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) //THRM burning if (rt==PT_THRM && (t==PT_FIRE || t==PT_PLSM || t==PT_LAVA)) { - if (RNG::Ref().chance(1, 500)) { + if (sim->rng.chance(1, 500)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_LAVA); parts[ID(r)].ctype = PT_BMTL; parts[ID(r)].temp = 3500.0f; @@ -172,20 +172,20 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) { if ((t==PT_FIRE || t==PT_PLSM)) { - if (parts[ID(r)].life>100 && RNG::Ref().chance(1, 500)) + if (parts[ID(r)].life>100 && sim->rng.chance(1, 500)) { parts[ID(r)].life = 99; } } else if (t==PT_LAVA) { - if (parts[i].ctype == PT_IRON && RNG::Ref().chance(1, 500)) + if (parts[i].ctype == PT_IRON && sim->rng.chance(1, 500)) { parts[i].ctype = PT_METL; sim->kill_part(ID(r)); continue; } - if ((parts[i].ctype == PT_STNE || parts[i].ctype == PT_NONE) && RNG::Ref().chance(1, 60)) + if ((parts[i].ctype == PT_STNE || parts[i].ctype == PT_NONE) && sim->rng.chance(1, 60)) { parts[i].ctype = PT_SLCN; sim->kill_part(ID(r)); @@ -208,7 +208,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) } else if (rt == PT_O2 && parts[i].ctype == PT_SLCN) { - switch (RNG::Ref().between(0, 2)) + switch (sim->rng.between(0, 2)) { case 0: parts[i].ctype = PT_SAND; @@ -246,7 +246,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) } } else if (parts[i].ctype == PT_ROCK && rt == PT_LAVA && parts[ID(r)].ctype == PT_GOLD && parts[ID(r)].tmp == 0 && - sim->pv[y / CELL][x / CELL] >= 50 && RNG::Ref().chance(1, 10000)) // Produce GOLD veins/clusters + sim->pv[y / CELL][x / CELL] >= 50 && sim->rng.chance(1, 10000)) // Produce GOLD veins/clusters { parts[i].ctype = PT_GOLD; if (rx > 1 || rx < -1) // Trend veins vertical @@ -259,7 +259,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) } if ((surround_space || sim->elements[rt].Explosive) && - sim->elements[rt].Flammable && RNG::Ref().chance(int(sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f)), 1000) && + sim->elements[rt].Flammable && sim->rng.chance(int(sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f)), 1000) && //exceptions, t is the thing causing the spark and rt is what's burning (t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && rt != PT_INSL)) && (t != PT_PHOT || rt != PT_INSL) && @@ -267,7 +267,7 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) { sim->part_change_type(ID(r), x+rx, y+ry, PT_FIRE); parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].DefaultProperties.temp + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); - parts[ID(r)].life = RNG::Ref().between(180, 259); + parts[ID(r)].life = sim->rng.between(180, 259); parts[ID(r)].tmp = parts[ID(r)].ctype = 0; if (sim->elements[rt].Explosive) sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; @@ -297,7 +297,7 @@ static int updateLegacy(UPDATE_FUNC_ARGS) if (sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) - && RNG::Ref().chance(sim->elements[rt].Meltable*lpv, 1000)) + && sim->rng.chance(sim->elements[rt].Meltable*lpv, 1000)) { if (t!=PT_LAVA || parts[i].life>0) { @@ -308,7 +308,7 @@ static int updateLegacy(UPDATE_FUNC_ARGS) else parts[ID(r)].ctype = rt; sim->part_change_type(ID(r),x+rx,y+ry,PT_LAVA); - parts[ID(r)].life = RNG::Ref().between(240, 359); + parts[ID(r)].life = sim->rng.between(240, 359); } else { @@ -371,5 +371,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].life = RNG::Ref().between(120, 169); + sim->parts[i].life = sim->rng.between(120, 169); } diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp index f818a8208..d6700a721 100644 --- a/src/simulation/elements/FIRW.cpp +++ b/src/simulation/elements/FIRW.cpp @@ -65,12 +65,12 @@ static int update(UPDATE_FUNC_ARGS) sim->GetGravityField(x, y, sim->elements[PT_FIRW].Gravity, 1.0f, gx, gy); if (gx*gx+gy*gy < 0.001f) { - float angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) + float angle = sim->rng.between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) gx += sinf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; gy += cosf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; } parts[i].tmp = 1; - parts[i].life = RNG::Ref().between(20, 29); + parts[i].life = sim->rng.between(20, 29); multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy); parts[i].vx -= gx*multiplier; parts[i].vy -= gy*multiplier; @@ -87,20 +87,20 @@ static int update(UPDATE_FUNC_ARGS) } else //if (parts[i].tmp>=2) { - unsigned col = Renderer::firwTableAt(RNG::Ref().between(0, 199)); + unsigned col = Renderer::firwTableAt(sim->rng.between(0, 199)); for (int n=0; n<40; n++) { np = sim->create_part(-3, x, y, PT_EMBR); if (np>-1) { - auto magnitude = RNG::Ref().between(40, 99) * 0.05f; - auto angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) + auto magnitude = sim->rng.between(40, 99) * 0.05f; + auto angle = sim->rng.between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].ctype = col; parts[np].tmp = 1; - parts[np].life = RNG::Ref().between(70, 109); - parts[np].temp = float(RNG::Ref().between(5750, 6249)); + parts[np].life = sim->rng.between(70, 109); + parts[np].temp = float(sim->rng.between(5750, 6249)); parts[np].dcolour = parts[i].dcolour; } } diff --git a/src/simulation/elements/FOG.cpp b/src/simulation/elements/FOG.cpp index 9b655e1f7..6968591e7 100644 --- a/src/simulation/elements/FOG.cpp +++ b/src/simulation/elements/FOG.cpp @@ -56,13 +56,13 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((sim->elements[TYP(r)].Properties&TYPE_SOLID) && RNG::Ref().chance(1, 10) && parts[i].life==0 && !(TYP(r)==PT_CLNE || TYP(r)==PT_PCLN)) // TODO: should this also exclude BCLN? + if ((sim->elements[TYP(r)].Properties&TYPE_SOLID) && sim->rng.chance(1, 10) && parts[i].life==0 && !(TYP(r)==PT_CLNE || TYP(r)==PT_PCLN)) // TODO: should this also exclude BCLN? { sim->part_change_type(i,x,y,PT_RIME); } if (TYP(r)==PT_SPRK) { - parts[i].life += RNG::Ref().between(0, 19); + parts[i].life += sim->rng.between(0, 19); } } return 0; diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp index a5306bbae..20732f6e2 100644 --- a/src/simulation/elements/FRZW.cpp +++ b/src/simulation/elements/FRZW.cpp @@ -58,12 +58,12 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 14)) + if (TYP(r)==PT_WATR && sim->rng.chance(1, 14)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW); } } - if ((parts[i].life==0 && RNG::Ref().chance(1, 192)) || RNG::Ref().chance(100-parts[i].life, 50000)) + if ((parts[i].life==0 && sim->rng.chance(1, 192)) || sim->rng.chance(100-parts[i].life, 50000)) { sim->part_change_type(i,x,y,PT_ICEI); parts[i].ctype=PT_FRZW; diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp index 5cf71423b..cd430425d 100644 --- a/src/simulation/elements/FRZZ.cpp +++ b/src/simulation/elements/FRZZ.cpp @@ -56,7 +56,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 20)) + if (TYP(r)==PT_WATR && sim->rng.chance(1, 20)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW); parts[ID(r)].life = 100; diff --git a/src/simulation/elements/FSEP.cpp b/src/simulation/elements/FSEP.cpp index e5d7b6b3b..c36097e0a 100644 --- a/src/simulation/elements/FSEP.cpp +++ b/src/simulation/elements/FSEP.cpp @@ -58,8 +58,8 @@ static int update(UPDATE_FUNC_ARGS) } else if (parts[i].life < 40) { parts[i].life--; - if (RNG::Ref().chance(1, 10)) { - r = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_PLSM); + if (sim->rng.chance(1, 10)) { + r = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_PLSM); if (r>-1) parts[r].life = 50; } @@ -72,7 +72,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && parts[i].life>40 && RNG::Ref().chance(1, 15)) + if ((TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && parts[i].life>40 && sim->rng.chance(1, 15)) { parts[i].life = 39; } diff --git a/src/simulation/elements/FUSE.cpp b/src/simulation/elements/FUSE.cpp index 4d00aecaa..ffabb1838 100644 --- a/src/simulation/elements/FUSE.cpp +++ b/src/simulation/elements/FUSE.cpp @@ -59,8 +59,8 @@ static int update(UPDATE_FUNC_ARGS) } else if (parts[i].life < 40) { parts[i].life--; - if (RNG::Ref().chance(1, 100)) { - r = sim->create_part(-1, x + RNG::Ref().chance(-1, 1), y + RNG::Ref().chance(-1, 1), PT_PLSM); + if (sim->rng.chance(1, 100)) { + r = sim->create_part(-1, x + sim->rng.chance(-1, 1), y + sim->rng.chance(-1, 1), PT_PLSM); if (r>-1) parts[r].life = 50; } @@ -81,7 +81,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+700.0f) && RNG::Ref().chance(1, 20))) + if (TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+700.0f) && sim->rng.chance(1, 20))) { if (parts[i].life > 40) parts[i].life = 39; diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp index 8f6f52396..432c1856e 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -48,14 +48,14 @@ void Element::Element_FWRK() static int update(UPDATE_FUNC_ARGS) { - if (parts[i].life == 0 && ((surround_space && parts[i].temp>400 && RNG::Ref().chance(int(9+parts[i].temp/40), 100000)) || parts[i].ctype == PT_DUST)) + if (parts[i].life == 0 && ((surround_space && parts[i].temp>400 && sim->rng.chance(int(9+parts[i].temp/40), 100000)) || parts[i].ctype == PT_DUST)) { float gx, gy, multiplier, gmax; int randTmp; sim->GetGravityField(x, y, sim->elements[PT_FWRK].Gravity, 1.0f, gx, gy); if (gx*gx+gy*gy < 0.001f) { - float angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) + float angle = sim->rng.between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) gx += sinf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; gy += cosf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; } @@ -65,15 +65,15 @@ static int update(UPDATE_FUNC_ARGS) multiplier = 15.0f/sqrtf(gx*gx+gy*gy); //Some variation in speed parallel to gravity direction - randTmp = RNG::Ref().between(-100, 100); + randTmp = sim->rng.between(-100, 100); gx += gx*randTmp*0.002f; gy += gy*randTmp*0.002f; //and a bit more variation in speed perpendicular to gravity direction - randTmp = RNG::Ref().between(-100, 100); + randTmp = sim->rng.between(-100, 100); gx += -gy*randTmp*0.005f; gy += gx*randTmp*0.005f; - parts[i].life = RNG::Ref().between(18, 27); + parts[i].life = sim->rng.between(18, 27); parts[i].ctype=0; parts[i].vx -= gx*multiplier; parts[i].vy -= gy*multiplier; @@ -82,9 +82,9 @@ static int update(UPDATE_FUNC_ARGS) } if (parts[i].life<3&&parts[i].life>0) { - int r = RNG::Ref().between(11, 255); - int g = RNG::Ref().between(11, 255); - int b = RNG::Ref().between(11, 255); + int r = sim->rng.between(11, 255); + int g = sim->rng.between(11, 255); + int b = sim->rng.between(11, 255); int n; float angle, magnitude; unsigned col = (r<<16) | (g<<8) | b; @@ -93,14 +93,14 @@ static int update(UPDATE_FUNC_ARGS) int np = sim->create_part(-3, x, y, PT_EMBR); if (np>-1) { - magnitude = RNG::Ref().between(40, 99) * 0.05f; - angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) + magnitude = sim->rng.between(40, 99) * 0.05f; + angle = sim->rng.between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].ctype = col; parts[np].tmp = 1; - parts[np].life = RNG::Ref().between(70, 109); - parts[np].temp = float(RNG::Ref().between(5750, 6249)); + parts[np].life = sim->rng.between(70, 109); + parts[np].temp = float(sim->rng.between(5750, 6249)); parts[np].dcolour = parts[i].dcolour; } } diff --git a/src/simulation/elements/GEL.cpp b/src/simulation/elements/GEL.cpp index aa0b8a7fc..b175209eb 100644 --- a/src/simulation/elements/GEL.cpp +++ b/src/simulation/elements/GEL.cpp @@ -72,31 +72,31 @@ static int update(UPDATE_FUNC_ARGS) case PT_WATR: case PT_DSTW: case PT_FRZW: - if (parts[i].tmp<100 && RNG::Ref().chance(500, absorbChanceDenom)) + if (parts[i].tmp<100 && sim->rng.chance(500, absorbChanceDenom)) { parts[i].tmp++; sim->kill_part(ID(r)); } break; case PT_PSTE: - if (parts[i].tmp<100 && RNG::Ref().chance(20, absorbChanceDenom)) + if (parts[i].tmp<100 && sim->rng.chance(20, absorbChanceDenom)) { parts[i].tmp++; sim->create_part(ID(r), x+rx, y+ry, PT_CLST); } break; case PT_SLTW: - if (parts[i].tmp<100 && RNG::Ref().chance(50, absorbChanceDenom)) + if (parts[i].tmp<100 && sim->rng.chance(50, absorbChanceDenom)) { parts[i].tmp++; - if (RNG::Ref().chance(3, 4)) + if (sim->rng.chance(3, 4)) sim->kill_part(ID(r)); else sim->part_change_type(ID(r), x+rx, y+ry, PT_SALT); } break; case PT_CBNW: - if (parts[i].tmp < 100 && RNG::Ref().chance(100, absorbChanceDenom)) + if (parts[i].tmp < 100 && sim->rng.chance(100, absorbChanceDenom)) { parts[i].tmp++; sim->part_change_type(ID(r), x+rx, y+ry, PT_CO2); diff --git a/src/simulation/elements/GLOW.cpp b/src/simulation/elements/GLOW.cpp index 686bbbdbe..5a764a080 100644 --- a/src/simulation/elements/GLOW.cpp +++ b/src/simulation/elements/GLOW.cpp @@ -58,7 +58,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 400)) + if (TYP(r)==PT_WATR && sim->rng.chance(1, 400)) { sim->kill_part(i); sim->part_change_type(ID(r),x+rx,y+ry,PT_DEUT); @@ -87,7 +87,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) *colg = int(restrict_flt(64.0f+cpart->ctype, 0, 255)); *colb = int(restrict_flt(64.0f+cpart->tmp, 0, 255)); - int rng = RNG::Ref().between(1, 32); // + int rng = ren->rng.between(1, 32); // if(((*colr) + (*colg) + (*colb)) > (256 + rng)) { *colr -= 54; *colg -= 54; diff --git a/src/simulation/elements/GOLD.cpp b/src/simulation/elements/GOLD.cpp index 3908bba13..4a0ceaa1f 100644 --- a/src/simulation/elements/GOLD.cpp +++ b/src/simulation/elements/GOLD.cpp @@ -56,7 +56,7 @@ static int update(UPDATE_FUNC_ARGS) static int checkCoordsY[] = { 0, 0, -4, 4 }; //Find nearby rusted iron (BMTL with tmp 1+) for(int j = 0; j < 8; j++){ - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); rx = (rndstore % 9)-4; rndstore >>= 4; ry = (rndstore % 9)-4; @@ -90,7 +90,7 @@ static int update(UPDATE_FUNC_ARGS) } if (TYP(sim->photons[y][x]) == PT_NEUT) { - if (RNG::Ref().chance(1, 7)) + if (sim->rng.chance(1, 7)) { sim->kill_part(ID(sim->photons[y][x])); } @@ -100,7 +100,7 @@ static int update(UPDATE_FUNC_ARGS) static int graphics(GRAPHICS_FUNC_ARGS) { - int rndstore = RNG::Ref().gen(); + int rndstore = ren->rng.gen(); *colr += (rndstore % 10) - 5; rndstore >>= 4; *colg += (rndstore % 10)- 5; diff --git a/src/simulation/elements/GOO.cpp b/src/simulation/elements/GOO.cpp index 2916c9ba0..b21d30a6d 100644 --- a/src/simulation/elements/GOO.cpp +++ b/src/simulation/elements/GOO.cpp @@ -51,7 +51,7 @@ constexpr float ADVECTION = 0.1f; static int update(UPDATE_FUNC_ARGS) { if (!parts[i].life && sim->pv[y/CELL][x/CELL]>1.0f) - parts[i].life = RNG::Ref().between(300, 379); + parts[i].life = sim->rng.between(300, 379); if (parts[i].life) { parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; diff --git a/src/simulation/elements/GRAV.cpp b/src/simulation/elements/GRAV.cpp index 4fca0d105..190f3bc82 100644 --- a/src/simulation/elements/GRAV.cpp +++ b/src/simulation/elements/GRAV.cpp @@ -50,7 +50,7 @@ void Element::Element_GRAV() static int update(UPDATE_FUNC_ARGS) { - if (parts[i].vx*parts[i].vx + parts[i].vy*parts[i].vy >= 0.1f && RNG::Ref().chance(1, 512)) + if (parts[i].vx*parts[i].vx + parts[i].vy*parts[i].vy >= 0.1f && sim->rng.chance(1, 512)) { if (!parts[i].life) parts[i].life = 48; diff --git a/src/simulation/elements/GRVT.cpp b/src/simulation/elements/GRVT.cpp index 0f5e5746c..cddfc97d1 100644 --- a/src/simulation/elements/GRVT.cpp +++ b/src/simulation/elements/GRVT.cpp @@ -76,8 +76,8 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; - sim->parts[i].life = 250 + RNG::Ref().between(0, 199); + float a = sim->rng.between(0, 359) * 3.14159f / 180.0f; + sim->parts[i].life = 250 + sim->rng.between(0, 199); sim->parts[i].vx = 2.0f*cosf(a); sim->parts[i].vy = 2.0f*sinf(a); } diff --git a/src/simulation/elements/H2.cpp b/src/simulation/elements/H2.cpp index 35004ae59..002a4cf13 100644 --- a/src/simulation/elements/H2.cpp +++ b/src/simulation/elements/H2.cpp @@ -77,14 +77,14 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].temp=2473.15f; parts[ID(r)].tmp |= 1; sim->create_part(i,x,y,PT_FIRE); - parts[i].temp += RNG::Ref().between(0, 99); + parts[i].temp += sim->rng.between(0, 99); parts[i].tmp |= 1; return 1; } else if ((rt==PT_PLSM && !(parts[ID(r)].tmp&4)) || (rt==PT_LAVA && parts[ID(r)].ctype != PT_BMTL)) { sim->create_part(i,x,y,PT_FIRE); - parts[i].temp += RNG::Ref().between(0, 99); + parts[i].temp += sim->rng.between(0, 99); parts[i].tmp |= 1; return 1; } @@ -92,7 +92,7 @@ static int update(UPDATE_FUNC_ARGS) } if (parts[i].temp > 2273.15 && sim->pv[y/CELL][x/CELL] > 50.0f) { - if (RNG::Ref().chance(1, 5)) + if (sim->rng.chance(1, 5)) { int j; float temp = parts[i].temp; @@ -102,7 +102,7 @@ static int update(UPDATE_FUNC_ARGS) j = sim->create_part(-3,x,y,PT_NEUT); if (j>-1) parts[j].temp = temp; - if (RNG::Ref().chance(1, 10)) + if (sim->rng.chance(1, 10)) { j = sim->create_part(-3,x,y,PT_ELEC); if (j>-1) @@ -115,7 +115,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].temp = temp; parts[j].tmp = 0x1; } - rx = x + RNG::Ref().between(-1, 1), ry = y + RNG::Ref().between(-1, 1), rt = TYP(pmap[ry][rx]); + rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.between(-1, 1), rt = TYP(pmap[ry][rx]); if (sim->can_move[PT_PLSM][rt] || rt == PT_H2) { j = sim->create_part(-3,rx,ry,PT_PLSM); @@ -125,7 +125,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].tmp |= 4; } } - parts[i].temp = temp + RNG::Ref().between(750, 1249); + parts[i].temp = temp + sim->rng.between(750, 1249); sim->pv[y/CELL][x/CELL] += 30; return 1; } diff --git a/src/simulation/elements/ICEI.cpp b/src/simulation/elements/ICEI.cpp index 5445783f8..d51508f57 100644 --- a/src/simulation/elements/ICEI.cpp +++ b/src/simulation/elements/ICEI.cpp @@ -64,14 +64,14 @@ static int update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_SALT || TYP(r)==PT_SLTW) { - if (parts[i].temp > sim->elements[PT_SLTW].LowTemperature && RNG::Ref().chance(1, 200)) + if (parts[i].temp > sim->elements[PT_SLTW].LowTemperature && sim->rng.chance(1, 200)) { sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); return 0; } } - else if ((TYP(r)==PT_FRZZ) && RNG::Ref().chance(1, 200)) + else if ((TYP(r)==PT_FRZZ) && sim->rng.chance(1, 200)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI); parts[ID(r)].ctype = PT_FRZW; diff --git a/src/simulation/elements/IGNT.cpp b/src/simulation/elements/IGNT.cpp index 624a68b3d..dc32ff2af 100644 --- a/src/simulation/elements/IGNT.cpp +++ b/src/simulation/elements/IGNT.cpp @@ -68,20 +68,20 @@ static int update(UPDATE_FUNC_ARGS) } else if(parts[i].life > 0) { - if (RNG::Ref().chance(2, 3)) + if (sim->rng.chance(2, 3)) { - int nb = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_EMBR); + int nb = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_EMBR); if (nb!=-1) { parts[nb].tmp = 0; parts[nb].life = 30; - parts[nb].vx = float(RNG::Ref().between(-10, 10)); - parts[nb].vy = float(RNG::Ref().between(-10, 10)); + parts[nb].vx = float(sim->rng.between(-10, 10)); + parts[nb].vy = float(sim->rng.between(-10, 10)); parts[nb].temp = restrict_flt(parts[i].temp-273.15f+400.0f, MIN_TEMP, MAX_TEMP); } } else { - sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_FIRE); + sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_FIRE); } parts[i].life--; } diff --git a/src/simulation/elements/IRON.cpp b/src/simulation/elements/IRON.cpp index 528a094db..9c9ef6884 100644 --- a/src/simulation/elements/IRON.cpp +++ b/src/simulation/elements/IRON.cpp @@ -58,19 +58,19 @@ static int update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_SALT: - if (RNG::Ref().chance(1, 47)) + if (sim->rng.chance(1, 47)) goto succ; break; case PT_SLTW: - if (RNG::Ref().chance(1, 67)) + if (sim->rng.chance(1, 67)) goto succ; break; case PT_WATR: - if (RNG::Ref().chance(1, 1200)) + if (sim->rng.chance(1, 1200)) goto succ; break; case PT_O2: - if (RNG::Ref().chance(1, 250)) + if (sim->rng.chance(1, 250)) goto succ; break; case PT_LO2: @@ -82,6 +82,6 @@ static int update(UPDATE_FUNC_ARGS) return 0; succ: sim->part_change_type(i,x,y,PT_BMTL); - parts[i].tmp = RNG::Ref().between(20, 29); + parts[i].tmp = sim->rng.between(20, 29); return 0; } diff --git a/src/simulation/elements/ISOZ.cpp b/src/simulation/elements/ISOZ.cpp index 20480cd0a..f5c5e3fad 100644 --- a/src/simulation/elements/ISOZ.cpp +++ b/src/simulation/elements/ISOZ.cpp @@ -49,11 +49,11 @@ void Element::Element_ISOZ() static int update(UPDATE_FUNC_ARGS) { float rr, rrr; - if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(int(-4.0f * sim->pv[y/CELL][x/CELL]), 1000)) + if (sim->rng.chance(1, 200) && sim->rng.chance(int(-4.0f * sim->pv[y/CELL][x/CELL]), 1000)) { sim->create_part(i, x, y, PT_PHOT); - rr = RNG::Ref().between(128, 355) / 127.0f; - rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + rr = sim->rng.between(128, 355) / 127.0f; + rrr = sim->rng.between(0, 359) * 3.14159f / 180.0f; parts[i].vx = rr*cosf(rrr); parts[i].vy = rr*sinf(rrr); } diff --git a/src/simulation/elements/ISZS.cpp b/src/simulation/elements/ISZS.cpp index 2864f5268..f8b971bd7 100644 --- a/src/simulation/elements/ISZS.cpp +++ b/src/simulation/elements/ISZS.cpp @@ -49,11 +49,11 @@ void Element::Element_ISZS() static int update(UPDATE_FUNC_ARGS) { float rr, rrr; - if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(int(-4.0f * sim->pv[y/CELL][x/CELL]), 1000)) + if (sim->rng.chance(1, 200) && sim->rng.chance(int(-4.0f * sim->pv[y/CELL][x/CELL]), 1000)) { sim->create_part(i, x, y, PT_PHOT); - rr = RNG::Ref().between(128, 355) / 127.0f; - rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + rr = sim->rng.between(128, 355) / 127.0f; + rrr = sim->rng.between(0, 359) * 3.14159f / 180.0f; parts[i].vx = rr*cosf(rrr); parts[i].vy = rr*sinf(rrr); } diff --git a/src/simulation/elements/LAVA.cpp b/src/simulation/elements/LAVA.cpp index a0dd034aa..3ceaf74ff 100644 --- a/src/simulation/elements/LAVA.cpp +++ b/src/simulation/elements/LAVA.cpp @@ -72,5 +72,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].life = RNG::Ref().between(240, 359); + sim->parts[i].life = sim->rng.between(240, 359); } diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index ade7e005d..fc0d32c1b 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -91,11 +91,11 @@ static int update(UPDATE_FUNC_ARGS) rt = TYP(r); if ((surround_space || sim->elements[rt].Explosive) && (rt!=PT_SPNG || parts[ID(r)].life==0) && - sim->elements[rt].Flammable && RNG::Ref().chance(sim->elements[rt].Flammable + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f), 1000)) + sim->elements[rt].Flammable && sim->rng.chance(sim->elements[rt].Flammable + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f), 1000)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_FIRE); parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].DefaultProperties.temp + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); - parts[ID(r)].life = RNG::Ref().between(180, 259); + parts[ID(r)].life = sim->rng.between(180, 259); parts[ID(r)].tmp = parts[ID(r)].ctype = 0; if (sim->elements[rt].Explosive) sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; @@ -115,12 +115,12 @@ static int update(UPDATE_FUNC_ARGS) case PT_PLUT: parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful, MIN_TEMP, MAX_TEMP); sim->pv[y/CELL][x/CELL] +=powderful/35; - if (RNG::Ref().chance(1, 3)) + if (sim->rng.chance(1, 3)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_NEUT); - parts[ID(r)].life = RNG::Ref().between(480, 959); - parts[ID(r)].vx = float(RNG::Ref().between(-5, 5)); - parts[ID(r)].vy = float(RNG::Ref().between(-5, 5)); + parts[ID(r)].life = sim->rng.between(480, 959); + parts[ID(r)].vx = float(sim->rng.between(-5, 5)); + parts[ID(r)].vy = float(sim->rng.between(-5, 5)); } break; case PT_COAL: @@ -167,14 +167,14 @@ static int update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } - angle = float((parts[i].tmp + RNG::Ref().between(-30, 30)) % 360); - multipler = int(parts[i].life * 1.5) + RNG::Ref().between(0, parts[i].life); + angle = float((parts[i].tmp + sim->rng.between(-30, 30)) % 360); + multipler = int(parts[i].life * 1.5) + sim->rng.between(0, parts[i].life); rx=int(cos(angle*TPT_PI_FLT/180)*multipler); ry=int(-sin(angle*TPT_PI_FLT/180)*multipler); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle), parts[i].tmp2, i); if (parts[i].tmp2 == 2)// && pNear == -1) { - angle2 = float(((int)angle + RNG::Ref().between(-100, 100)) % 360); + angle2 = float(((int)angle + sim->rng.between(-100, 100)) % 360); rx=int(cos(angle2*TPT_PI_FLT/180)*multipler); ry=int(-sin(angle2*TPT_PI_FLT/180)*multipler); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle2), parts[i].tmp2, i); @@ -193,12 +193,12 @@ static bool create_LIGH(Simulation * sim, int x, int y, int c, float temp, int l sim->parts[p].tmp = tmp; if (last) { - int nextSegmentLife = (int)(life/1.5 - RNG::Ref().between(0, 1)); + int nextSegmentLife = (int)(life/1.5 - sim->rng.between(0, 1)); sim->parts[p].life = nextSegmentLife; if (nextSegmentLife > 1) { // Decide whether to branch or to bend - bool doBranch = RNG::Ref().chance(7, 10); + bool doBranch = sim->rng.chance(7, 10); sim->parts[p].tmp2 = (doBranch ? 2 : 0) + (p > i && tmp2 != 4 ? 1 : 0); } // Not enough energy to continue @@ -315,12 +315,12 @@ static void create(ELEMENT_CREATE_FUNC_ARGS) gsize = gx * gx + gy * gy; if (gsize < 0.0016f) { - float angle = RNG::Ref().between(0, 6283) * 0.001f; //(in radians, between 0 and 2*pi) + float angle = sim->rng.between(0, 6283) * 0.001f; //(in radians, between 0 and 2*pi) gsize = sqrtf(gsize); // randomness in weak gravity fields (more randomness with weaker fields) gx += cosf(angle) * (0.04f - gsize); gy += sinf(angle) * (0.04f - gsize); } - sim->parts[i].tmp = (static_cast(atan2f(-gy, gx) * (180.0f / TPT_PI_FLT)) + RNG::Ref().between(-20, 20) + 360) % 360; + sim->parts[i].tmp = (static_cast(atan2f(-gy, gx) * (180.0f / TPT_PI_FLT)) + sim->rng.between(-20, 20) + 360) % 360; sim->parts[i].tmp2 = 4; } diff --git a/src/simulation/elements/LITH.cpp b/src/simulation/elements/LITH.cpp index ad804c388..2ee901b7a 100644 --- a/src/simulation/elements/LITH.cpp +++ b/src/simulation/elements/LITH.cpp @@ -85,7 +85,7 @@ static int update(UPDATE_FUNC_ARGS) int neighborData = pmap[y + ry][x + rx]; if (!neighborData) { - if (burnTimer > 1012 && RNG::Ref().chance(1, 10)) + if (burnTimer > 1012 && sim->rng.chance(1, 10)) { sim->create_part(-1, x + rx, y + ry, PT_FIRE); } @@ -163,7 +163,7 @@ static int update(UPDATE_FUNC_ARGS) break; case PT_FIRE: - if (self.temp > 440.f && RNG::Ref().chance(1, 40) && hydrogenationFactor < 6) + if (self.temp > 440.f && sim->rng.chance(1, 40) && hydrogenationFactor < 6) { burnTimer = 1013; hydrogenationFactor += 1; @@ -171,7 +171,7 @@ static int update(UPDATE_FUNC_ARGS) break; case PT_O2: - if (burnTimer > 1000 && RNG::Ref().chance(1, 10)) + if (burnTimer > 1000 && sim->rng.chance(1, 10)) { sim->part_change_type(i, x, y, PT_PLSM); sim->part_change_type(ID(neighborData), x + rx, y + ry, PT_PLSM); @@ -196,8 +196,8 @@ static int update(UPDATE_FUNC_ARGS) for (int trade = 0; trade < 9; ++trade) { - int rx = RNG::Ref().between(-3, 3); - int ry = RNG::Ref().between(-3, 3); + int rx = sim->rng.between(-3, 3); + int ry = sim->rng.between(-3, 3); if (BOUNDS_CHECK && (rx || ry)) { int neighborData = pmap[y + ry][x + rx]; @@ -257,7 +257,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) // Charged lith else if (cpart->ctype > 0) { - int mult = RNG::Ref().between(cpart->ctype / 3, cpart->ctype) / 15; + int mult = ren->rng.between(cpart->ctype / 3, cpart->ctype) / 15; mult = std::min(6, mult); *colr -= 30 * mult; *colb += 20 * mult; diff --git a/src/simulation/elements/MERC.cpp b/src/simulation/elements/MERC.cpp index a546b2d89..b32c6a153 100644 --- a/src/simulation/elements/MERC.cpp +++ b/src/simulation/elements/MERC.cpp @@ -56,7 +56,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].temp + 1 == 0) parts[i].temp = 0; int maxtmp = int(absorbScale/(parts[i].temp + 1))-1; - if (RNG::Ref().chance(absorbScale%(int(parts[i].temp)+1), int(parts[i].temp)+1)) + if (sim->rng.chance(absorbScale%(int(parts[i].temp)+1), int(parts[i].temp)+1)) maxtmp ++; if (parts[i].tmp < 0) @@ -77,7 +77,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r || (parts[i].tmp >=maxtmp)) continue; - if (TYP(r)==PT_MERC&& RNG::Ref().chance(1, 3)) + if (TYP(r)==PT_MERC&& sim->rng.chance(1, 3)) { if ((parts[i].tmp + parts[ID(r)].tmp + 1) <= maxtmp) { @@ -107,8 +107,8 @@ static int update(UPDATE_FUNC_ARGS) } for ( trade = 0; trade<4; trade ++) { - rx = RNG::Ref().between(-2, 2); - ry = RNG::Ref().between(-2, 2); + rx = sim->rng.between(-2, 2); + ry = sim->rng.between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/NBLE.cpp b/src/simulation/elements/NBLE.cpp index baa6de670..7660619fc 100644 --- a/src/simulation/elements/NBLE.cpp +++ b/src/simulation/elements/NBLE.cpp @@ -52,7 +52,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].temp > 5273.15 && sim->pv[y/CELL][x/CELL] > 100.0f) { parts[i].tmp |= 0x1; - if (RNG::Ref().chance(1, 5)) + if (sim->rng.chance(1, 5)) { int j; float temp = parts[i].temp; @@ -61,7 +61,7 @@ static int update(UPDATE_FUNC_ARGS) j = sim->create_part(-3,x,y,PT_NEUT); if (j != -1) parts[j].temp = temp; - if (RNG::Ref().chance(1, 25)) + if (sim->rng.chance(1, 25)) { j = sim->create_part(-3,x,y,PT_ELEC); if (j != -1) @@ -74,7 +74,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].temp = temp; parts[j].tmp = 0x1; } - int rx = x + RNG::Ref().between(-1, 1), ry = y + RNG::Ref().between(-1, 1), rt = TYP(pmap[ry][rx]); + int rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.between(-1, 1), rt = TYP(pmap[ry][rx]); if (sim->can_move[PT_PLSM][rt] || rt == PT_NBLE) { j = sim->create_part(-3,rx,ry,PT_PLSM); @@ -84,7 +84,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].tmp |= 4; } } - parts[i].temp = temp + 1750 + RNG::Ref().between(0, 499); + parts[i].temp = temp + 1750 + sim->rng.between(0, 499); sim->pv[y/CELL][x/CELL] += 50; } } diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index cacba8068..003a9313a 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -64,7 +64,7 @@ static int update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_WATR: - if (RNG::Ref().chance(3, 20)) + if (sim->rng.chance(3, 20)) sim->part_change_type(ID(r),x+rx,y+ry,PT_DSTW); case PT_ICEI: case PT_SNOW: @@ -72,11 +72,11 @@ static int update(UPDATE_FUNC_ARGS) parts[i].vy *= 0.995f; break; case PT_PLUT: - if (RNG::Ref().chance(pressureFactor, 1000)) + if (sim->rng.chance(pressureFactor, 1000)) { - if (RNG::Ref().chance(1, 3)) + if (sim->rng.chance(1, 3)) { - sim->create_part(ID(r), x+rx, y+ry, RNG::Ref().chance(2, 3) ? PT_LAVA : PT_URAN); + sim->create_part(ID(r), x+rx, y+ry, sim->rng.chance(2, 3) ? PT_LAVA : PT_URAN); parts[ID(r)].temp = MAX_TEMP; if (parts[ID(r)].type==PT_LAVA) { parts[ID(r)].tmp = 100; @@ -94,73 +94,73 @@ static int update(UPDATE_FUNC_ARGS) } break; case PT_DEUT: - if (RNG::Ref().chance(pressureFactor + 1 + (parts[ID(r)].life/100), 1000)) + if (sim->rng.chance(pressureFactor + 1 + (parts[ID(r)].life/100), 1000)) { DeutExplosion(sim, parts[ID(r)].life, x+rx, y+ry, restrict_flt(parts[ID(r)].temp + parts[ID(r)].life*500.0f, MIN_TEMP, MAX_TEMP), PT_NEUT); sim->kill_part(ID(r)); } break; case PT_GUNP: - if (RNG::Ref().chance(3, 200)) + if (sim->rng.chance(3, 200)) sim->part_change_type(ID(r),x+rx,y+ry,PT_DUST); break; case PT_DYST: - if (RNG::Ref().chance(3, 200)) + if (sim->rng.chance(3, 200)) sim->part_change_type(ID(r),x+rx,y+ry,PT_YEST); break; case PT_YEST: sim->part_change_type(ID(r),x+rx,y+ry,PT_DYST); break; case PT_PLEX: - if (RNG::Ref().chance(3, 200)) + if (sim->rng.chance(3, 200)) sim->part_change_type(ID(r),x+rx,y+ry,PT_GOO); break; case PT_NITR: - if (RNG::Ref().chance(3, 200)) + if (sim->rng.chance(3, 200)) sim->part_change_type(ID(r),x+rx,y+ry,PT_DESL); break; case PT_PLNT: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); break; case PT_DESL: case PT_OIL: - if (RNG::Ref().chance(3, 200)) + if (sim->rng.chance(3, 200)) sim->part_change_type(ID(r),x+rx,y+ry,PT_GAS); break; case PT_COAL: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); break; case PT_BCOL: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_SAWD); break; case PT_DUST: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) sim->part_change_type(ID(r), x+rx, y+ry, PT_FWRK); break; case PT_FWRK: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) parts[ID(r)].ctype = PT_DUST; break; case PT_ACID: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_ISOZ); break; case PT_TTAN: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) { sim->kill_part(i); return 1; } break; case PT_EXOT: - if (RNG::Ref().chance(1, 20)) + if (sim->rng.chance(1, 20)) parts[ID(r)].life = 1500; break; case PT_RFRG: - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) sim->create_part(ID(r), x+rx, y+ry, PT_GAS); else sim->create_part(ID(r), x+rx, y+ry, PT_CAUS); @@ -185,9 +185,9 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - float r = RNG::Ref().between(128, 255) / 127.0f; - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; - sim->parts[i].life = RNG::Ref().between(480, 959); + float r = sim->rng.between(128, 255) / 127.0f; + float a = sim->rng.between(0, 359) * 3.14159f / 180.0f; + sim->parts[i].life = sim->rng.between(480, 959); sim->parts[i].vx = r * cosf(a); sim->parts[i].vy = r * sinf(a); } diff --git a/src/simulation/elements/O2.cpp b/src/simulation/elements/O2.cpp index 383eb6327..f8cb9c1a4 100644 --- a/src/simulation/elements/O2.cpp +++ b/src/simulation/elements/O2.cpp @@ -58,19 +58,19 @@ static int update(UPDATE_FUNC_ARGS) if (TYP(r)==PT_FIRE) { - parts[ID(r)].temp += RNG::Ref().between(0, 99); + parts[ID(r)].temp += sim->rng.between(0, 99); if (parts[ID(r)].tmp & 0x01) parts[ID(r)].temp = 3473; parts[ID(r)].tmp |= 2; sim->create_part(i,x,y,PT_FIRE); - parts[i].temp += RNG::Ref().between(0, 99); + parts[i].temp += sim->rng.between(0, 99); parts[i].tmp |= 2; } else if (TYP(r)==PT_PLSM && !(parts[ID(r)].tmp&4)) { sim->create_part(i,x,y,PT_FIRE); - parts[i].temp += RNG::Ref().between(0, 99); + parts[i].temp += sim->rng.between(0, 99); parts[i].tmp |= 2; } } @@ -81,7 +81,7 @@ static int update(UPDATE_FUNC_ARGS) float gravy = sim->gravy[gravPos]; if (gravx*gravx + gravy*gravy > 400) { - if (RNG::Ref().chance(1, 5)) + if (sim->rng.chance(1, 5)) { int j; sim->create_part(i,x,y,PT_BRMT); @@ -95,7 +95,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].temp = MAX_TEMP; parts[j].tmp = 0x1; } - rx = x + RNG::Ref().between(-1, 1), ry = y + RNG::Ref().between(-1, 1), r = TYP(pmap[ry][rx]); + rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.between(-1, 1), r = TYP(pmap[ry][rx]); if (sim->can_move[PT_PLSM][r] || r == PT_O2) { j = sim->create_part(-3,rx,ry,PT_PLSM); diff --git a/src/simulation/elements/PBCN.cpp b/src/simulation/elements/PBCN.cpp index 0b9defc8d..5bcf88a11 100644 --- a/src/simulation/elements/PBCN.cpp +++ b/src/simulation/elements/PBCN.cpp @@ -56,7 +56,7 @@ static int update(UPDATE_FUNC_ARGS) { int r, rx, ry, rt; if (!parts[i].tmp2 && sim->pv[y/CELL][x/CELL]>4.0f) - parts[i].tmp2 = RNG::Ref().between(80, 119); + parts[i].tmp2 = sim->rng.between(80, 119); if (parts[i].tmp2) { parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; @@ -136,9 +136,9 @@ static int update(UPDATE_FUNC_ARGS) for (ry=-1; ry<2; ry++) sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); - else if (parts[i].ctype!=PT_LIGH || RNG::Ref().chance(1, 30)) + else if (parts[i].ctype!=PT_LIGH || sim->rng.chance(1, 30)) { - int np = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), TYP(parts[i].ctype)); + int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), TYP(parts[i].ctype)); if (np>-1) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/PCLN.cpp b/src/simulation/elements/PCLN.cpp index fd2841d13..b90af3bc2 100644 --- a/src/simulation/elements/PCLN.cpp +++ b/src/simulation/elements/PCLN.cpp @@ -127,9 +127,9 @@ static int update(UPDATE_FUNC_ARGS) for (ry=-1; ry<2; ry++) sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); - else if (parts[i].ctype != PT_LIGH || RNG::Ref().chance(1, 30)) + else if (parts[i].ctype != PT_LIGH || sim->rng.chance(1, 30)) { - int np = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), TYP(parts[i].ctype)); + int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), TYP(parts[i].ctype)); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/PHOT.cpp b/src/simulation/elements/PHOT.cpp index 8efbd9f19..242b7aa52 100644 --- a/src/simulation/elements/PHOT.cpp +++ b/src/simulation/elements/PHOT.cpp @@ -63,7 +63,7 @@ static int update(UPDATE_FUNC_ARGS) return 1; } if (parts[i].temp > 506) - if (RNG::Ref().chance(1, 10)) + if (sim->rng.chance(1, 10)) Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS); for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) @@ -73,16 +73,16 @@ static int update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_ISOZ || TYP(r)==PT_ISZS) { - if (RNG::Ref().chance(1, 400)) + if (sim->rng.chance(1, 400)) { parts[i].vx *= 0.90f; parts[i].vy *= 0.90f; sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); - rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + rrr = sim->rng.between(0, 359) * 3.14159f / 180.0f; if (TYP(r) == PT_ISOZ) - rr = RNG::Ref().between(128, 255) / 127.0f; + rr = sim->rng.between(128, 255) / 127.0f; else - rr = RNG::Ref().between(128, 355) / 127.0f; + rr = sim->rng.between(128, 355) / 127.0f; parts[ID(r)].vx = rr*cosf(rrr); parts[ID(r)].vy = rr*sinf(rrr); sim->pv[y/CELL][x/CELL] -= 15.0f * CFDS; @@ -90,17 +90,17 @@ static int update(UPDATE_FUNC_ARGS) } else if((TYP(r) == PT_QRTZ || TYP(r) == PT_PQRT) && !ry && !rx)//if on QRTZ { - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + float a = sim->rng.between(0, 359) * 3.14159f / 180.0f; parts[i].vx = 3.0f*cosf(a); parts[i].vy = 3.0f*sinf(a); if(parts[i].ctype == 0x3FFFFFFF) - parts[i].ctype = 0x1F << RNG::Ref().between(0, 25); + parts[i].ctype = 0x1F << sim->rng.between(0, 25); if (parts[i].life) parts[i].life++; //Delay death } else if(TYP(r) == PT_BGLA && !ry && !rx)//if on BGLA { - float a = RNG::Ref().between(-50, 50) * 0.001f; + float a = sim->rng.between(-50, 50) * 0.001f; float rx = cosf(a), ry = sinf(a), vx, vy; vx = rx * parts[i].vx + ry * parts[i].vy; vy = rx * parts[i].vy - ry * parts[i].vx; @@ -109,8 +109,8 @@ static int update(UPDATE_FUNC_ARGS) } else if (TYP(r) == PT_FILT && parts[ID(r)].tmp==9) { - parts[i].vx += ((float)RNG::Ref().between(-500, 500))/1000.0f; - parts[i].vy += ((float)RNG::Ref().between(-500, 500))/1000.0f; + parts[i].vx += ((float)sim->rng.between(-500, 500))/1000.0f; + parts[i].vy += ((float)sim->rng.between(-500, 500))/1000.0f; } } return 0; @@ -147,10 +147,10 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - float a = RNG::Ref().between(0, 7) * 0.78540f; + float a = sim->rng.between(0, 7) * 0.78540f; sim->parts[i].vx = 3.0f * cosf(a); sim->parts[i].vy = 3.0f * sinf(a); - int Element_FILT_interactWavelengths(Particle* cpart, int origWl); + int Element_FILT_interactWavelengths(Simulation *sim, Particle* cpart, int origWl); if (TYP(sim->pmap[y][x]) == PT_FILT) - sim->parts[i].ctype = Element_FILT_interactWavelengths(&sim->parts[ID(sim->pmap[y][x])], sim->parts[i].ctype); + sim->parts[i].ctype = Element_FILT_interactWavelengths(sim, &sim->parts[ID(sim->pmap[y][x])], sim->parts[i].ctype); } diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 506527050..aced13a49 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -257,7 +257,7 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) if (nt)//there is something besides PIPE around current particle { - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); rnd = rndstore&7; //rndstore = rndstore>>3; rx = pos_1_rx[rnd]; @@ -495,7 +495,7 @@ static void pushParticle(Simulation * sim, int i, int count, int original) if( !(sim->parts[i].tmp&0x200) ) { //normal random push - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); // RAND_MAX is at least 32767 on all platforms i.e. pow(8,5)-1 // so can go 5 cycles without regenerating rndstore // (although now we use our own randomizer so maybe should reevaluate all the rndstore usages in every element) diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp index 72be9aad9..a8ae1a92d 100644 --- a/src/simulation/elements/PLNT.cpp +++ b/src/simulation/elements/PLNT.cpp @@ -60,7 +60,7 @@ static int update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_WATR: - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { np = sim->create_part(ID(r),x+rx,y+ry,PT_PLNT); if (np<0) continue; @@ -68,7 +68,7 @@ static int update(UPDATE_FUNC_ARGS) } break; case PT_LAVA: - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -76,14 +76,14 @@ static int update(UPDATE_FUNC_ARGS) break; case PT_SMKE: case PT_CO2: - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { sim->kill_part(ID(r)); - parts[i].life = RNG::Ref().between(60, 119); + parts[i].life = sim->rng.between(60, 119); } break; case PT_WOOD: - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); if (surround_space && !(rndstore%4) && parts[i].tmp==1) { rndstore >>= 3; diff --git a/src/simulation/elements/PLSM.cpp b/src/simulation/elements/PLSM.cpp index e9519e49e..1c70cb664 100644 --- a/src/simulation/elements/PLSM.cpp +++ b/src/simulation/elements/PLSM.cpp @@ -70,5 +70,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].life = RNG::Ref().between(50, 199); + sim->parts[i].life = sim->rng.between(50, 199); } diff --git a/src/simulation/elements/PLUT.cpp b/src/simulation/elements/PLUT.cpp index 1ce583af9..273315458 100644 --- a/src/simulation/elements/PLUT.cpp +++ b/src/simulation/elements/PLUT.cpp @@ -49,7 +49,7 @@ void Element::Element_PLUT() static int update(UPDATE_FUNC_ARGS) { - if (RNG::Ref().chance(1, 100) && RNG::Ref().chance(int(5.0f*sim->pv[y/CELL][x/CELL]), 1000)) + if (sim->rng.chance(1, 100) && sim->rng.chance(int(5.0f*sim->pv[y/CELL][x/CELL]), 1000)) { sim->create_part(i, x, y, PT_NEUT); } diff --git a/src/simulation/elements/POLO.cpp b/src/simulation/elements/POLO.cpp index fdd8ba8ca..1e57553ec 100644 --- a/src/simulation/elements/POLO.cpp +++ b/src/simulation/elements/POLO.cpp @@ -57,7 +57,7 @@ static int update(UPDATE_FUNC_ARGS) int r = sim->photons[y][x]; if (parts[i].tmp < LIMIT && !parts[i].life) { - if (RNG::Ref().chance(1, 10000) && !parts[i].tmp) + if (sim->rng.chance(1, 10000) && !parts[i].tmp) { int s = sim->create_part(-3, x, y, PT_NEUT); if (s >= 0) @@ -70,7 +70,7 @@ static int update(UPDATE_FUNC_ARGS) } } - if (r && RNG::Ref().chance(1, 100)) + if (r && sim->rng.chance(1, 100)) { int s = sim->create_part(-3, x, y, PT_NEUT); if (s >= 0) diff --git a/src/simulation/elements/PQRT.cpp b/src/simulation/elements/PQRT.cpp index 99962a0f0..d5cd5ba23 100644 --- a/src/simulation/elements/PQRT.cpp +++ b/src/simulation/elements/PQRT.cpp @@ -51,5 +51,5 @@ void Element::Element_PQRT() static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].tmp2 = RNG::Ref().between(0, 10); + sim->parts[i].tmp2 = sim->rng.between(0, 10); } diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index e3adfbb12..d464260d2 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -74,7 +74,7 @@ static int update(UPDATE_FUNC_ARGS) break; } case PT_DEUT: - if (RNG::Ref().chance(-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100), 200)) + if (sim->rng.chance(-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100), 200)) { DeutImplosion(sim, parts[uID].life, x, y, restrict_flt(parts[uID].temp + parts[uID].life * 500, MIN_TEMP, MAX_TEMP), PT_PROT); sim->kill_part(uID); @@ -82,7 +82,7 @@ static int update(UPDATE_FUNC_ARGS) break; case PT_LCRY: //Powered LCRY reaction: PROT->PHOT - if (parts[uID].life > 5 && RNG::Ref().chance(1, 10)) + if (parts[uID].life > 5 && sim->rng.chance(1, 10)) { sim->part_change_type(i, x, y, PT_PHOT); parts[i].life *= 2; @@ -149,7 +149,7 @@ static int update(UPDATE_FUNC_ARGS) element = PT_CO2; else element = PT_NBLE; - newID = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), element); + newID = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), element); if (newID >= 0) parts[newID].temp = restrict_flt(100.0f*parts[i].tmp, MIN_TEMP, MAX_TEMP); sim->kill_part(i); @@ -209,7 +209,7 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - float a = RNG::Ref().between(0, 35) * 0.17453f; + float a = sim->rng.between(0, 35) * 0.17453f; sim->parts[i].life = 680; sim->parts[i].vx = 2.0f * cosf(a); sim->parts[i].vy = 2.0f * sinf(a); diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp index d53f13ca4..ab5060c86 100644 --- a/src/simulation/elements/PRTI.cpp +++ b/src/simulation/elements/PRTI.cpp @@ -119,22 +119,22 @@ static int update(UPDATE_FUNC_ARGS) if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!sim->parts[i].life) parts[i].life = RNG::Ref().gen(); - if (!sim->parts[i].ctype) parts[i].ctype = RNG::Ref().gen(); + if (!sim->parts[i].life) parts[i].life = sim->rng.gen(); + if (!sim->parts[i].ctype) parts[i].ctype = sim->rng.gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (int r = 0; r < 4; r++) { if (orbd[r]>1) { orbd[r] -= 12; if (orbd[r]<1) { - orbd[r] = RNG::Ref().between(128, 255); - orbl[r] = RNG::Ref().between(0, 254); + orbd[r] = sim->rng.between(128, 255); + orbl[r] = sim->rng.between(0, 254); } else { orbl[r] += 2; orbl[r] = orbl[r]%255; } } else { - orbd[r] = RNG::Ref().between(128, 255); - orbl[r] = RNG::Ref().between(0, 254); + orbd[r] = sim->rng.between(128, 255); + orbl[r] = sim->rng.between(0, 254); } } sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); diff --git a/src/simulation/elements/PRTO.cpp b/src/simulation/elements/PRTO.cpp index 48a07862f..07ef0db6a 100644 --- a/src/simulation/elements/PRTO.cpp +++ b/src/simulation/elements/PRTO.cpp @@ -74,7 +74,7 @@ static int update(UPDATE_FUNC_ARGS) fe = 1; for ( nnx =0 ; nnx<80; nnx++) { - int randomness = (count + RNG::Ref().between(-1, 1) + 4) % 8;//add -1,0,or 1 to count + int randomness = (count + sim->rng.between(-1, 1) + 4) % 8;//add -1,0,or 1 to count if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_SPRK)// TODO: make it look better, spark creation { sim->create_part(-1,x+1,y,PT_SPRK); @@ -142,15 +142,15 @@ static int update(UPDATE_FUNC_ARGS) if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!sim->parts[i].life) parts[i].life = RNG::Ref().gen(); - if (!sim->parts[i].ctype) parts[i].ctype = RNG::Ref().gen(); + if (!sim->parts[i].life) parts[i].life = sim->rng.gen(); + if (!sim->parts[i].ctype) parts[i].ctype = sim->rng.gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (r = 0; r < 4; r++) { if (orbd[r]<254) { orbd[r] += 16; if (orbd[r]>254) { orbd[r] = 0; - orbl[r] = RNG::Ref().between(0, 254); + orbl[r] = sim->rng.between(0, 254); } else { @@ -161,7 +161,7 @@ static int update(UPDATE_FUNC_ARGS) //orbl[r] = orbl[r]%255; } else { orbd[r] = 0; - orbl[r] = RNG::Ref().between(0, 254); + orbl[r] = sim->rng.between(0, 254); } } sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); diff --git a/src/simulation/elements/PTNM.cpp b/src/simulation/elements/PTNM.cpp index 34acfe507..37e790083 100644 --- a/src/simulation/elements/PTNM.cpp +++ b/src/simulation/elements/PTNM.cpp @@ -109,7 +109,7 @@ static void hygn_reactions(int hygn1_id, UPDATE_FUNC_ARGS) } // Cold fusion: 2 hydrogen > 500 C has a chance to fuse - if (rt == PT_H2 && RNG::Ref().chance(1, 1000) && parts[ID(r)].temp > 500.0f + 273.15f && parts[hygn1_id].temp > 500.0f + 273.15f) + if (rt == PT_H2 && sim->rng.chance(1, 1000) && parts[ID(r)].temp > 500.0f + 273.15f && parts[hygn1_id].temp > 500.0f + 273.15f) { sim->part_change_type(ID(r), x + rx, y + ry, PT_NBLE); sim->part_change_type(hygn1_id, (int)(parts[hygn1_id].x + 0.5f), (int)(parts[hygn1_id].y + 0.5f), PT_NEUT); @@ -125,7 +125,7 @@ static void hygn_reactions(int hygn1_id, UPDATE_FUNC_ARGS) parts[j].temp = parts[ID(r)].temp; parts[j].tmp = 0x1; } - if (RNG::Ref().chance(1, 10)) + if (sim->rng.chance(1, 10)) { int j = sim->create_part(-3, x + rx, y + ry, PT_ELEC); if (j > -1) @@ -212,7 +212,7 @@ static int update(UPDATE_FUNC_ARGS) float prob = std::min(1.0f, parts[i].temp / (273.15f + 1500.0f)); prob *= prob; - if (RNG::Ref().uniform01() <= prob) + if (sim->rng.uniform01() <= prob) { switch (rt) { @@ -266,6 +266,6 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - if (RNG::Ref().chance(1, 15)) + if (sim->rng.chance(1, 15)) sim->parts[i].tmp = 1; } diff --git a/src/simulation/elements/QRTZ.cpp b/src/simulation/elements/QRTZ.cpp index ac3a1f937..ca1e9e860 100644 --- a/src/simulation/elements/QRTZ.cpp +++ b/src/simulation/elements/QRTZ.cpp @@ -74,7 +74,7 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - else if (TYP(r)==PT_SLTW && RNG::Ref().chance(1, 500)) + else if (TYP(r)==PT_SLTW && sim->rng.chance(1, 500)) { sim->kill_part(ID(r)); parts[i].tmp++; @@ -87,7 +87,7 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) int rnd, sry, srx; for (trade = 0; trade < 9; trade++) { - rnd = RNG::Ref().gen() % 0x3FF; + rnd = sim->rng.gen() % 0x3FF; rx = (rnd%5)-2; srx = (rnd%3)-1; rnd >>= 3; @@ -104,9 +104,9 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) { parts[np].temp = parts[i].temp; parts[np].tmp2 = parts[i].tmp2; - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) { - parts[np].tmp2 = std::clamp(parts[np].tmp2 + RNG::Ref().between(-1, 1), 0, 10); + parts[np].tmp2 = std::clamp(parts[np].tmp2 + sim->rng.between(-1, 1), 0, 10); } parts[i].tmp--; if (t == PT_PQRT) @@ -114,11 +114,11 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) // If PQRT is stationary and has started growing particles of QRTZ, the PQRT is basically part of a new QRTZ crystal. So turn it back into QRTZ so that it behaves more like part of the crystal. sim->part_change_type(i,x,y,PT_QRTZ); } - if (RNG::Ref().chance(1, 2)) + if (sim->rng.chance(1, 2)) { parts[np].tmp=-1;//dead qrtz } - else if (!parts[i].tmp && RNG::Ref().chance(1, 15)) + else if (!parts[i].tmp && sim->rng.chance(1, 15)) { parts[i].tmp=-1; } @@ -164,6 +164,6 @@ int Element_QRTZ_graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].tmp2 = RNG::Ref().between(0, 10); + sim->parts[i].tmp2 = sim->rng.between(0, 10); sim->parts[i].tmp3 = int(sim->pv[y/CELL][x/CELL] * 64); } diff --git a/src/simulation/elements/RIME.cpp b/src/simulation/elements/RIME.cpp index 1bee19ea1..ab0e5afab 100644 --- a/src/simulation/elements/RIME.cpp +++ b/src/simulation/elements/RIME.cpp @@ -59,7 +59,7 @@ static int update(UPDATE_FUNC_ARGS) if (TYP(r)==PT_SPRK) { sim->part_change_type(i,x,y,PT_FOG); - parts[i].life = RNG::Ref().between(60, 119); + parts[i].life = sim->rng.between(60, 119); } else if (TYP(r)==PT_FOG&&parts[ID(r)].life>0) { diff --git a/src/simulation/elements/ROCK.cpp b/src/simulation/elements/ROCK.cpp index 96239433d..e7a4a4263 100644 --- a/src/simulation/elements/ROCK.cpp +++ b/src/simulation/elements/ROCK.cpp @@ -69,5 +69,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].tmp2 = RNG::Ref().between(0, 10); + sim->parts[i].tmp2 = sim->rng.between(0, 10); } diff --git a/src/simulation/elements/RPEL.cpp b/src/simulation/elements/RPEL.cpp index a1dfdf351..bc6177400 100644 --- a/src/simulation/elements/RPEL.cpp +++ b/src/simulation/elements/RPEL.cpp @@ -52,8 +52,8 @@ static int update(UPDATE_FUNC_ARGS) int r, rx, ry, ri; for(ri = 0; ri <= 10; ri++) { - rx = RNG::Ref().between(-10, 10); - ry = RNG::Ref().between(-10, 10); + rx = sim->rng.between(-10, 10); + ry = sim->rng.between(-10, 10); if (x+rx >= 0 && x+rx < XRES && y+ry >= 0 && y+ry < YRES && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/SHLD1.cpp b/src/simulation/elements/SHLD1.cpp index 5dc8b8ed8..f660e6803 100644 --- a/src/simulation/elements/SHLD1.cpp +++ b/src/simulation/elements/SHLD1.cpp @@ -57,7 +57,7 @@ static int update(UPDATE_FUNC_ARGS) continue; else if (TYP(r)==PT_SPRK&&parts[i].life==0) { - if (RNG::Ref().chance(11, 40)) + if (sim->rng.chance(11, 40)) { sim->part_change_type(i,x,y,PT_SHLD2); parts[i].life = 7; @@ -72,7 +72,7 @@ static int update(UPDATE_FUNC_ARGS) } } } - else if (TYP(r) == PT_SHLD3 && RNG::Ref().chance(2, 5)) + else if (TYP(r) == PT_SHLD3 && sim->rng.chance(2, 5)) { sim->part_change_type(i,x,y,PT_SHLD2); parts[i].life = 7; diff --git a/src/simulation/elements/SHLD2.cpp b/src/simulation/elements/SHLD2.cpp index d9b081d1c..662c97b69 100644 --- a/src/simulation/elements/SHLD2.cpp +++ b/src/simulation/elements/SHLD2.cpp @@ -61,7 +61,7 @@ static int update(UPDATE_FUNC_ARGS) } else if (TYP(r)==PT_SPRK&&parts[i].life==0) { - if (RNG::Ref().chance(1, 8)) + if (sim->rng.chance(1, 8)) { sim->part_change_type(i,x,y,PT_SHLD3); parts[i].life = 7; @@ -77,7 +77,7 @@ static int update(UPDATE_FUNC_ARGS) } } } - else if (TYP(r) == PT_SHLD4 && RNG::Ref().chance(2, 5)) + else if (TYP(r) == PT_SHLD4 && sim->rng.chance(2, 5)) { sim->part_change_type(i,x,y,PT_SHLD3); parts[i].life = 7; diff --git a/src/simulation/elements/SHLD3.cpp b/src/simulation/elements/SHLD3.cpp index 882a5f56f..c79435c86 100644 --- a/src/simulation/elements/SHLD3.cpp +++ b/src/simulation/elements/SHLD3.cpp @@ -55,7 +55,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) { - if (RNG::Ref().chance(1, 2500)) + if (sim->rng.chance(1, 2500)) { np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); if (np<0) continue; @@ -71,7 +71,7 @@ static int update(UPDATE_FUNC_ARGS) } else if (TYP(r)==PT_SPRK&&parts[i].life==0) { - if (RNG::Ref().chance(3, 500)) + if (sim->rng.chance(3, 500)) { sim->part_change_type(i,x,y,PT_SHLD4); parts[i].life = 7; diff --git a/src/simulation/elements/SHLD4.cpp b/src/simulation/elements/SHLD4.cpp index e57d18c5a..cf9ce179f 100644 --- a/src/simulation/elements/SHLD4.cpp +++ b/src/simulation/elements/SHLD4.cpp @@ -55,7 +55,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) { - if (RNG::Ref().chance(1, 5500)) + if (sim->rng.chance(1, 5500)) { np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); if (np<0) continue; diff --git a/src/simulation/elements/SING.cpp b/src/simulation/elements/SING.cpp index 1c8665b07..904bc22e0 100644 --- a/src/simulation/elements/SING.cpp +++ b/src/simulation/elements/SING.cpp @@ -80,7 +80,7 @@ static int update(UPDATE_FUNC_ARGS) spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*TPT_PI_FLT); for (int j = 0;j < spawncount; j++) { - switch (RNG::Ref().gen() % 3) + switch (sim->rng.gen() % 3) { case 0: nb = sim->create_part(-3, x, y, PT_PHOT); @@ -93,10 +93,10 @@ static int update(UPDATE_FUNC_ARGS) break; } if (nb!=-1) { - parts[nb].life = RNG::Ref().between(0, 299); + parts[nb].life = sim->rng.between(0, 299); parts[nb].temp = MAX_TEMP/2; - angle = RNG::Ref().uniform01()*2.0f*TPT_PI_FLT; - v = RNG::Ref().uniform01()*5.0f; + angle = sim->rng.uniform01()*2.0f*TPT_PI_FLT; + v = sim->rng.uniform01()*5.0f; parts[nb].vx = v*cosf(angle); parts[nb].vy = v*sinf(angle); } @@ -113,7 +113,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)!=PT_DMND&& RNG::Ref().chance(1, 3)) + if (TYP(r)!=PT_DMND&& sim->rng.chance(1, 3)) { if (TYP(r)==PT_SING && parts[ID(r)].life >10) { @@ -125,11 +125,11 @@ static int update(UPDATE_FUNC_ARGS) { if (parts[i].life+3 > 255) { - if (parts[ID(r)].type!=PT_SING && RNG::Ref().chance(1, 1000)) + if (parts[ID(r)].type!=PT_SING && sim->rng.chance(1, 1000)) { int np; np = sim->create_part(ID(r),x+rx,y+ry,PT_SING); - parts[np].life = RNG::Ref().between(60, 109); + parts[np].life = sim->rng.between(60, 109); } continue; } @@ -145,5 +145,5 @@ static int update(UPDATE_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].life = RNG::Ref().between(60, 109); + sim->parts[i].life = sim->rng.between(60, 109); } diff --git a/src/simulation/elements/SLCN.cpp b/src/simulation/elements/SLCN.cpp index c740f3de9..fe3e6e703 100644 --- a/src/simulation/elements/SLCN.cpp +++ b/src/simulation/elements/SLCN.cpp @@ -56,26 +56,26 @@ static const int SLCN_COLOUR[16] = { PIXPACK(0x8594AD), PIXPACK(0x262F47), PIXPACK(0xA9AEBC), PIXPACK(0xC2E1F7), }; -static void initSparkles(Particle &part) +static void initSparkles(Simulation *sim, Particle &part) { // bits 31-20: phase increment (randomised to a value between 1 and 9) // bits 19-16: next colour index // bits 15-12: current colour index // bits 11-00: phase - part.tmp = RNG::Ref().between(0x100000, 0x9FFFFF); + part.tmp = sim->rng.between(0x100000, 0x9FFFFF); } static int update(UPDATE_FUNC_ARGS) { if (!parts[i].tmp) { - initSparkles(parts[i]); + initSparkles(sim, parts[i]); } int phase = (parts[i].tmp & 0xFFF) + ((parts[i].tmp >> 20) & 0xFFF); if (phase & 0x1000) { // discard current, current <- next, next <- random, wrap phase - parts[i].tmp = (parts[i].tmp & 0xFFF00000) | (phase & 0xFFF) | (RNG::Ref().between(0, 15) << 16) | ((parts[i].tmp >> 4) & 0xF000); + parts[i].tmp = (parts[i].tmp & 0xFFF00000) | (phase & 0xFFF) | (sim->rng.between(0, 15) << 16) | ((parts[i].tmp >> 4) & 0xF000); } else { @@ -137,5 +137,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - initSparkles(sim->parts[i]); + initSparkles(sim, sim->parts[i]); } diff --git a/src/simulation/elements/SLTW.cpp b/src/simulation/elements/SLTW.cpp index f1c6f1d67..950095425 100644 --- a/src/simulation/elements/SLTW.cpp +++ b/src/simulation/elements/SLTW.cpp @@ -56,16 +56,16 @@ static int update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_SALT: - if (RNG::Ref().chance(1, 2000)) + if (sim->rng.chance(1, 2000)) sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); break; case PT_PLNT: - if (RNG::Ref().chance(1, 40)) + if (sim->rng.chance(1, 40)) sim->kill_part(ID(r)); break; case PT_RBDM: case PT_LRBD: - if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && RNG::Ref().chance(1, 100)) + if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && sim->rng.chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -76,7 +76,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[ID(r)].ctype!=PT_WATR) { sim->kill_part(ID(r)); - if (RNG::Ref().chance(1, 30)) + if (sim->rng.chance(1, 30)) { sim->kill_part(i); return 1; diff --git a/src/simulation/elements/SNOW.cpp b/src/simulation/elements/SNOW.cpp index 33c6be4d3..414e719fe 100644 --- a/src/simulation/elements/SNOW.cpp +++ b/src/simulation/elements/SNOW.cpp @@ -61,7 +61,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_SALT || TYP(r)==PT_SLTW) && RNG::Ref().chance(1, 333)) + if ((TYP(r)==PT_SALT || TYP(r)==PT_SLTW) && sim->rng.chance(1, 333)) { sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); diff --git a/src/simulation/elements/SPNG.cpp b/src/simulation/elements/SPNG.cpp index 6b1bfd112..b2c7e1001 100644 --- a/src/simulation/elements/SPNG.cpp +++ b/src/simulation/elements/SPNG.cpp @@ -64,31 +64,31 @@ static int update(UPDATE_FUNC_ARGS) case PT_WATR: case PT_DSTW: case PT_FRZW: - if (parts[i].liferng.chance(500, absorbChanceDenom)) { parts[i].life++; sim->kill_part(ID(r)); } break; case PT_SLTW: - if (parts[i].liferng.chance(50, absorbChanceDenom)) { parts[i].life++; - if (RNG::Ref().chance(3, 4)) + if (sim->rng.chance(3, 4)) sim->kill_part(ID(r)); else sim->part_change_type(ID(r), x+rx, y+ry, PT_SALT); } break; case PT_CBNW: - if (parts[i].liferng.chance(100, absorbChanceDenom)) { parts[i].life++; sim->part_change_type(ID(r), x+rx, y+ry, PT_CO2); } break; case PT_PSTE: - if (parts[i].liferng.chance(20, absorbChanceDenom)) { parts[i].life++; sim->create_part(ID(r), x+rx, y+ry, PT_CLST); @@ -113,8 +113,8 @@ static int update(UPDATE_FUNC_ARGS) } for ( trade = 0; trade<9; trade ++) { - rx = RNG::Ref().between(-2, 2); - ry = RNG::Ref().between(-2, 2); + rx = sim->rng.between(-2, 2); + ry = sim->rng.between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index 4496a716c..de19e6607 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -104,7 +104,7 @@ static int update(UPDATE_FUNC_ARGS) case PT_NBLE: if (parts[i].life<=1 && !(parts[i].tmp&0x1)) { - parts[i].life = RNG::Ref().between(50, 199); + parts[i].life = sim->rng.between(50, 199); sim->part_change_type(i,x,y,PT_PLSM); parts[i].ctype = PT_NBLE; if (parts[i].temp > 5273.15) @@ -123,12 +123,12 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (r) continue; - if (parts[i].tmp>4 && RNG::Ref().chance(1, parts[i].tmp*parts[i].tmp/20+6)) + if (parts[i].tmp>4 && sim->rng.chance(1, parts[i].tmp*parts[i].tmp/20+6)) { int p = sim->create_part(-1, x+rx*2, y+ry*2, PT_LIGH); if (p!=-1) { - parts[p].life = RNG::Ref().between(0, 2+parts[i].tmp/15) + parts[i].tmp/7; + parts[p].life = sim->rng.between(0, 2+parts[i].tmp/15) + parts[i].tmp/7; if (parts[i].life>60) parts[i].life=60; parts[p].temp=parts[p].life*parts[i].tmp/2.5; @@ -156,7 +156,7 @@ static int update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_DSTW || TYP(r)==PT_SLTW || TYP(r)==PT_WATR) { - int rndstore = RNG::Ref().gen()%100; + int rndstore = sim->rng.gen()%100; if (!rndstore) sim->part_change_type(ID(r),x+rx,y+ry,PT_O2); else if (3 > rndstore) @@ -166,7 +166,7 @@ static int update(UPDATE_FUNC_ARGS) break; case PT_TUNG: if(parts[i].temp < 3595.0){ - parts[i].temp += RNG::Ref().between(-4, 15); + parts[i].temp += sim->rng.between(-4, 15); } default: break; diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index 19c04f489..7ee9f9fde 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -445,7 +445,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) //Spawn if (((int)(playerp->comm)&0x08) == 0x08) { - ry -= 2 * RNG::Ref().between(0, 1) + 1; + ry -= 2 * sim->rng.between(0, 1) + 1; r = pmap[ry][rx]; if (sim->elements[TYP(r)].Properties&TYPE_SOLID) { @@ -481,7 +481,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { if (playerp->elem == PT_PHOT) { - int random = abs((RNG::Ref().between(-1, 1)))*3; + int random = abs((sim->rng.between(-1, 1)))*3; if (random==0) { sim->kill_part(np); @@ -502,7 +502,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) if (gvx!=0 || gvy!=0) angle = int(atan2(mvx, mvy)*180.0f/TPT_PI_FLT); else - angle = RNG::Ref().between(0, 359); + angle = sim->rng.between(0, 359); if (((int)playerp->pcomm)&0x01) angle += 180; if (angle>360) @@ -510,7 +510,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) if (angle<0) angle+=360; parts[np].tmp = angle; - parts[np].life = RNG::Ref().between(0, 1+power/15) + power/7; + parts[np].life = sim->rng.between(0, 1+power/15) + power/7; parts[np].temp = parts[np].life*power/2.5; parts[np].tmp2 = 1; } @@ -633,7 +633,7 @@ void Element_STKM_interact(Simulation *sim, playerst *playerp, int i, int x, int { if (TYP(r)==PT_SPRK && playerp->elem!=PT_LIGH) //If on charge { - sim->parts[i].life -= RNG::Ref().between(32, 51); + sim->parts[i].life -= sim->rng.between(32, 51); } if (sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||sim->parts[ID(r)].life==10) && ((playerp->elem!=PT_LIGH && sim->parts[ID(r)].temp>=323) || sim->parts[ID(r)].temp<=243) && (!playerp->rocketBoots || TYP(r)!=PT_PLSM)) diff --git a/src/simulation/elements/THDR.cpp b/src/simulation/elements/THDR.cpp index e716317a2..7dd937132 100644 --- a/src/simulation/elements/THDR.cpp +++ b/src/simulation/elements/THDR.cpp @@ -70,9 +70,9 @@ static int update(UPDATE_FUNC_ARGS) else if (rt!=PT_CLNE&&rt!=PT_THDR&&rt!=PT_SPRK&&rt!=PT_DMND&&rt!=PT_FIRE) { sim->pv[y/CELL][x/CELL] += 100.0f; - if (sim->legacy_enable && RNG::Ref().chance(1, 200)) + if (sim->legacy_enable && sim->rng.chance(1, 200)) { - parts[i].life = RNG::Ref().between(120, 169); + parts[i].life = sim->rng.between(120, 169); sim->part_change_type(i,x,y,PT_FIRE); } else diff --git a/src/simulation/elements/TRON.cpp b/src/simulation/elements/TRON.cpp index b6d385229..171e27293 100644 --- a/src/simulation/elements/TRON.cpp +++ b/src/simulation/elements/TRON.cpp @@ -109,7 +109,7 @@ static int update(UPDATE_FUNC_ARGS) int originaldir = direction; //random turn - int random = RNG::Ref().between(0, 339); + int random = sim->rng.between(0, 339); if ((random==1 || random==3) && !(parts[i].tmp & TRON_NORANDOM)) { //randomly turn left(3) or right(1) @@ -133,7 +133,7 @@ static int update(UPDATE_FUNC_ARGS) } else { - seconddir = (direction + (RNG::Ref().between(0, 1)*2)+1)% 4; + seconddir = (direction + (sim->rng.between(0, 1)*2)+1)% 4; lastdir = (seconddir + 2)%4; } seconddircheck = trymovetron(sim,x,y,seconddir,i,parts[i].tmp2); @@ -192,8 +192,8 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - int randhue = RNG::Ref().between(0, 359); - int randomdir = RNG::Ref().between(0, 3); + int randhue = sim->rng.between(0, 359); + int randomdir = sim->rng.between(0, 3); // Set as a head and a direction sim->parts[i].tmp = 1 | (randomdir << 5) | (randhue << 7); // Tail diff --git a/src/simulation/elements/TUNG.cpp b/src/simulation/elements/TUNG.cpp index 69e7da3f0..8166ac1e3 100644 --- a/src/simulation/elements/TUNG.cpp +++ b/src/simulation/elements/TUNG.cpp @@ -69,16 +69,16 @@ static int update(UPDATE_FUNC_ARGS) } } } - if((parts[i].temp > MELTING_POINT && RNG::Ref().chance(1, 20)) || splode) + if((parts[i].temp > MELTING_POINT && sim->rng.chance(1, 20)) || splode) { - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) { sim->pv[y/CELL][x/CELL] += 50.0f; } - else if (RNG::Ref().chance(1, 100)) + else if (sim->rng.chance(1, 100)) { sim->part_change_type(i, x, y, PT_FIRE); - parts[i].life = RNG::Ref().between(0, 499); + parts[i].life = sim->rng.between(0, 499); return 1; } else @@ -89,10 +89,10 @@ static int update(UPDATE_FUNC_ARGS) } if(splode) { - parts[i].temp = restrict_flt(MELTING_POINT + RNG::Ref().between(200, 799), MIN_TEMP, MAX_TEMP); + parts[i].temp = restrict_flt(MELTING_POINT + sim->rng.between(200, 799), MIN_TEMP, MAX_TEMP); } - parts[i].vx += RNG::Ref().between(-50, 50); - parts[i].vy += RNG::Ref().between(-50, 50); + parts[i].vx += sim->rng.between(-50, 50); + parts[i].vy += sim->rng.between(-50, 50); return 1; } auto press = int(sim->pv[y/CELL][x/CELL] * 64); diff --git a/src/simulation/elements/VIBR.cpp b/src/simulation/elements/VIBR.cpp index 7862016e9..51b8168da 100644 --- a/src/simulation/elements/VIBR.cpp +++ b/src/simulation/elements/VIBR.cpp @@ -83,7 +83,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) else //if it is exploding { //Release sparks before explode - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); if (parts[i].life < 300) { rx = rndstore%3-1; @@ -117,7 +117,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) { if (!parts[i].tmp2) { - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); int index = sim->create_part(-3,x+((rndstore>>4)&3)-1,y+((rndstore>>6)&3)-1,PT_ELEC); if (index != -1) parts[index].temp = 7000; @@ -125,7 +125,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) if (index != -1) parts[index].temp = 7000; int rx = ((rndstore>>12)&3)-1; - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); index = sim->create_part(-1,x+rx-1,y+rndstore%3-1,PT_BREC); if (index != -1) parts[index].temp = 7000; @@ -159,7 +159,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) { if (!parts[ID(r)].life) parts[ID(r)].tmp += 45; - else if (parts[i].tmp2 && parts[i].life > 75 && RNG::Ref().chance(1, 2)) + else if (parts[i].tmp2 && parts[i].life > 75 && sim->rng.chance(1, 2)) { parts[ID(r)].tmp2 = 1; parts[i].tmp = 0; @@ -174,7 +174,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) else { //Melts into EXOT - if (TYP(r) == PT_EXOT && RNG::Ref().chance(1, 25)) + if (TYP(r) == PT_EXOT && sim->rng.chance(1, 25)) { sim->part_change_type(i, x, y, PT_EXOT); return 1; @@ -190,7 +190,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) for (trade = 0; trade < 9; trade++) { if (!(trade%2)) - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); rx = rndstore%7-3; rndstore >>= 3; ry = rndstore%7-3; diff --git a/src/simulation/elements/VINE.cpp b/src/simulation/elements/VINE.cpp index 566d7c1de..82377ac21 100644 --- a/src/simulation/elements/VINE.cpp +++ b/src/simulation/elements/VINE.cpp @@ -52,7 +52,7 @@ void Element::Element_VINE() static int update(UPDATE_FUNC_ARGS) { - int r, np, rx, ry, rndstore = RNG::Ref().gen(); + int r, np, rx, ry, rndstore = sim->rng.gen(); rx = (rndstore % 3) - 1; rndstore >>= 2; ry = (rndstore % 3) - 1; diff --git a/src/simulation/elements/VIRS.cpp b/src/simulation/elements/VIRS.cpp index 2c81c89b4..75f87d1dc 100644 --- a/src/simulation/elements/VIRS.cpp +++ b/src/simulation/elements/VIRS.cpp @@ -55,7 +55,7 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) { //tmp3 measures how many frames until it is cured (0 if still actively spreading and not being cured) //tmp4 measures how many frames until it dies - int r, rx, ry, rndstore = RNG::Ref().gen(); + int r, rx, ry, rndstore = sim->rng.gen(); if (parts[i].tmp3) { parts[i].tmp3 -= (rndstore & 0x1) ? 0:1; @@ -106,7 +106,7 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) } else if (TYP(r) == PT_PLSM) { - if (surround_space && RNG::Ref().chance(10 + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL]), 100)) + if (surround_space && sim->rng.chance(10 + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL]), 100)) { sim->create_part(i, x, y, PT_PLSM); return 1; @@ -140,7 +140,7 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) } //reset rndstore only once, halfway through else if (!rx && !ry) - rndstore = RNG::Ref().gen(); + rndstore = sim->rng.gen(); } return 0; } diff --git a/src/simulation/elements/WARP.cpp b/src/simulation/elements/WARP.cpp index cc6737868..412308ea4 100644 --- a/src/simulation/elements/WARP.cpp +++ b/src/simulation/elements/WARP.cpp @@ -55,13 +55,13 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].temp = 10000; sim->pv[y/CELL][x/CELL] += (parts[i].tmp2 / 5000) * CFDS; - if (RNG::Ref().chance(1, 50)) + if (sim->rng.chance(1, 50)) sim->create_part(-3, x, y, PT_ELEC); } for (int trade = 0; trade < 5; trade ++) { - int rx = RNG::Ref().between(-1, 1); - int ry = RNG::Ref().between(-1, 1); + int rx = sim->rng.between(-1, 1); + int ry = sim->rng.between(-1, 1); if (BOUNDS_CHECK && (rx || ry)) { int r = pmap[y + ry][x + rx]; @@ -73,8 +73,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].y = parts[ID(r)].y; parts[ID(r)].x = float(x); parts[ID(r)].y = float(y); - parts[ID(r)].vx = RNG::Ref().between(-2, 1) + 0.5f; - parts[ID(r)].vy = float(RNG::Ref().between(-2, 1)); + parts[ID(r)].vx = sim->rng.between(-2, 1) + 0.5f; + parts[ID(r)].vy = float(sim->rng.between(-2, 1)); parts[i].life += 4; pmap[y][x] = r; pmap[y + ry][x + rx] = PMAP(i, parts[i].type); @@ -94,5 +94,5 @@ static int graphics(GRAPHICS_FUNC_ARGS) static void create(ELEMENT_CREATE_FUNC_ARGS) { - sim->parts[i].life = RNG::Ref().between(70, 164); + sim->parts[i].life = sim->rng.between(70, 164); } diff --git a/src/simulation/elements/WATR.cpp b/src/simulation/elements/WATR.cpp index 3adcc2a80..0b7247671 100644 --- a/src/simulation/elements/WATR.cpp +++ b/src/simulation/elements/WATR.cpp @@ -56,14 +56,14 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_SALT && RNG::Ref().chance(1, 50)) + if (TYP(r)==PT_SALT && sim->rng.chance(1, 50)) { sim->part_change_type(i,x,y,PT_SLTW); // on average, convert 3 WATR to SLTW before SALT turns into SLTW - if (RNG::Ref().chance(1, 3)) + if (sim->rng.chance(1, 3)) sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); } - else if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && RNG::Ref().chance(1, 100)) + else if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && sim->rng.chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -72,19 +72,19 @@ static int update(UPDATE_FUNC_ARGS) else if (TYP(r)==PT_FIRE && parts[ID(r)].ctype!=PT_WATR) { sim->kill_part(ID(r)); - if (RNG::Ref().chance(1, 30)) + if (sim->rng.chance(1, 30)) { sim->kill_part(i); return 1; } } - else if (TYP(r)==PT_SLTW && RNG::Ref().chance(1, 2000)) + else if (TYP(r)==PT_SLTW && sim->rng.chance(1, 2000)) { sim->part_change_type(i,x,y,PT_SLTW); } - else if (TYP(r)==PT_ROCK && fabs(parts[i].vx)+fabs(parts[i].vy) >= 0.5 && RNG::Ref().chance(1, 1000)) // ROCK erosion + else if (TYP(r)==PT_ROCK && fabs(parts[i].vx)+fabs(parts[i].vy) >= 0.5 && sim->rng.chance(1, 1000)) // ROCK erosion { - if (RNG::Ref().chance(1,3)) + if (sim->rng.chance(1,3)) sim->part_change_type(ID(r),x+rx,y+ry,PT_SAND); else sim->part_change_type(ID(r),x+rx,y+ry,PT_STNE); diff --git a/src/simulation/elements/WTRV.cpp b/src/simulation/elements/WTRV.cpp index 3ea937082..696778820 100644 --- a/src/simulation/elements/WTRV.cpp +++ b/src/simulation/elements/WTRV.cpp @@ -56,7 +56,7 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && RNG::Ref().chance(1, 100)) + if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && sim->rng.chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; diff --git a/src/simulation/elements/YEST.cpp b/src/simulation/elements/YEST.cpp index 772b90175..e82be9e6b 100644 --- a/src/simulation/elements/YEST.cpp +++ b/src/simulation/elements/YEST.cpp @@ -55,13 +55,13 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_DYST && RNG::Ref().chance(1, 6) && !sim->legacy_enable) + if (TYP(r)==PT_DYST && sim->rng.chance(1, 6) && !sim->legacy_enable) { sim->part_change_type(i,x,y,PT_DYST); } } if (parts[i].temp > 303 && parts[i].temp < 317) { - sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_YEST); + sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_YEST); } return 0; } diff --git a/src/simulation/simtools/MIX.cpp b/src/simulation/simtools/MIX.cpp index 2d28e463b..36ea4adc9 100644 --- a/src/simulation/simtools/MIX.cpp +++ b/src/simulation/simtools/MIX.cpp @@ -20,7 +20,7 @@ static int perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, if(!thisPart) return 0; - if(random_gen() % 100 != 0) + if(sim->rng() % 100 != 0) return 0; int distance = (int)(std::pow(strength, .5f) * 10); @@ -28,8 +28,8 @@ static int perform(Simulation * sim, Particle * cpart, int x, int y, int brushX, if(!(sim->elements[TYP(thisPart)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS))) return 0; - int newX = x + (random_gen() % distance) - (distance/2); - int newY = y + (random_gen() % distance) - (distance/2); + int newX = x + (sim->rng() % distance) - (distance/2); + int newY = y + (sim->rng() % distance) - (distance/2); if(newX < 0 || newY < 0 || newX >= XRES || newY >= YRES) return 0;