diff --git a/inc/canvas/BackGround.hpp b/inc/canvas/BackGround.hpp index 04916c0..51672e1 100644 --- a/inc/canvas/BackGround.hpp +++ b/inc/canvas/BackGround.hpp @@ -1,11 +1,9 @@ #include -#include "values/RandBuffer.hpp" #include "canvas/Sun.hpp" #include - struct Moon { float x; @@ -31,8 +29,6 @@ private: Sun sun; - RandBuffer starBuff; - RandBuffer mountenBuff; Moon m_moon; int colorSet; int time; diff --git a/src/App.cpp b/src/App.cpp index b1fbab9..aca7a7d 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -14,7 +14,7 @@ void App::init(int screenWidth, int screenHeight) this->screenHeight = screenHeight; this->canvas.init(screenWidth); - mrand::setSeed((unsigned int)time(NULL)); + mrand::setSeed(1); for (size_t i = 0; i < canvasTexure.size(); i++) { diff --git a/src/canvas/BackGround.cpp b/src/canvas/BackGround.cpp index 443cdd5..a5597b6 100644 --- a/src/canvas/BackGround.cpp +++ b/src/canvas/BackGround.cpp @@ -23,8 +23,7 @@ void BackGround::deinit() void BackGround::newGen() { - starBuff.reset(); - mountenBuff.reset(); + m_moon = {mrand::getFloat(), mrand::getFloat(), mrand::getFloat()}; colorSet = mrand::getValue(0, 3); time = floor(Remap(m_moon.y, 0, 1, 4, 0)); @@ -61,10 +60,10 @@ void BackGround::drawStarts() for (size_t i = 0; i < numOfStarts; i++) { - int x = starBuff.next() * size; - int y = starBuff.next() * size; - int weight = starBuff.next() * 3 + 1; - float alph = Normalize(starBuff.next(), 0.04f, 0.8f); + int x = mrand::getFloat() * size; + int y = mrand::getFloat() * size; + int weight = mrand::getFloat() * 3 + 1; + float alph = Normalize(mrand::getFloat(), 0.04f, 0.8f); Color color = ColorLerp(BackGroundColors::backGroundColor, BackGroundColors::starColor, alph); rlColor4ub(color.r, color.g, color.b, color.a); @@ -121,7 +120,7 @@ void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color col int x = 0; int diff = size / (mountenSegments - 1); - float p = mountenBuff.next(); + float p = mrand::getFloat(); int y = Lerp(min, max, p); rlSetTexture(1); @@ -136,7 +135,7 @@ void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color col // bottomLeft rlVertex2f(x, size); - p = mountenBuff.next(); + p = mrand::getFloat(); y = Lerp(min, max, p); x += diff; // topRight diff --git a/src/values/mrand.cpp b/src/values/mrand.cpp index c710d0a..9aaf25f 100644 --- a/src/values/mrand.cpp +++ b/src/values/mrand.cpp @@ -3,7 +3,6 @@ #include "values/mrand.hpp" static uint32_t rprand_state[4] = {0}; -static uint64_t rprand_seed = 0; static inline uint32_t my_rotate_left(const uint32_t x, int k) { @@ -27,7 +26,7 @@ uint32_t my_rprand_xoshiro(uint32_t state[4]) return result; } -uint64_t rprand_splitmix64() +uint64_t rprand_splitmix64(uint64_t &rprand_seed) { uint64_t z = (rprand_seed += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; @@ -39,14 +38,14 @@ namespace mrand { void setSeed(unsigned long long seed) { - rprand_seed = (uint64_t)seed; // Set SplitMix64 seed for further use + uint64_t rprand_seed = (uint64_t)seed; // Set SplitMix64 seed for further use // To generate the Xoshiro128** state, we use SplitMix64 generator first // We generate 4 pseudo-random 64bit numbers that we combine using their LSB|MSB - rprand_state[0] = (uint32_t)(rprand_splitmix64() & 0xffffffff); - rprand_state[1] = (uint32_t)((rprand_splitmix64() & 0xffffffff00000000) >> 32); - rprand_state[2] = (uint32_t)(rprand_splitmix64() & 0xffffffff); - rprand_state[3] = (uint32_t)((rprand_splitmix64() & 0xffffffff00000000) >> 32); + rprand_state[0] = (uint32_t)(rprand_splitmix64(rprand_seed) & 0xffffffff); + rprand_state[1] = (uint32_t)((rprand_splitmix64(rprand_seed) & 0xffffffff00000000) >> 32); + rprand_state[2] = (uint32_t)(rprand_splitmix64(rprand_seed) & 0xffffffff); + rprand_state[3] = (uint32_t)((rprand_splitmix64(rprand_seed) & 0xffffffff00000000) >> 32); } int getValue(int min, int max) @@ -60,4 +59,16 @@ namespace mrand { return my_rprand_xoshiro(rprand_state) / 4294967295.0f; } + + int getValue(int min, int max, uint32_t state[4]) + { + int value = my_rprand_xoshiro(state) % (std::abs(max - min) + 1) + min; + + return value; + } + + float getFloat(uint32_t state[4]) + { + return my_rprand_xoshiro(state) / 4294967295.0f; + } } \ No newline at end of file