From abb33b6f1f3abb64f546d1a338c92264cda9fb8a Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 9 Nov 2025 14:06:00 +0100 Subject: [PATCH] gen random device once --- src/Main.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index a78fdcf..26c18b5 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -100,6 +100,10 @@ static const std::filesystem::path s_ComputeShaderPath = "Shaders/Compute.glsl"; static const std::filesystem::path s_VertexShaderPath = "Shaders/Vertex.glsl"; static const std::filesystem::path s_FragmentShaderPath = "Shaders/Fragment.glsl"; +static std::random_device s_RandomDevice; +static std::mt19937 s_Generator(s_RandomDevice()); +static std::uniform_real_distribution s_Distrib(0, 1); + static void ErrorCallback(int error, const char* description) { std::cerr << "Error: " << description << std::endl; } @@ -110,33 +114,29 @@ static void ApplyTransforms(const std::vector& transformations) { } static void GenNewFractal() { - std::random_device randomDevice; - std::mt19937 generator(randomDevice()); - std::uniform_real_distribution distrib(0, 1); - // scale, rotation, shear, translation std::vector transformations(TRANSFORMATION_COUNT); for (std::size_t i = 0; i < transformations.size(); i++) { - float scaleX = distrib(generator) * 0.4 + 0.4; - float scaleY = distrib(generator) * 0.4 + 0.4; - float scaleZ = distrib(generator) * 0.4 + 0.4; + float scaleX = s_Distrib(s_Generator) * 0.4 + 0.4; + float scaleY = s_Distrib(s_Generator) * 0.4 + 0.4; + float scaleZ = s_Distrib(s_Generator) * 0.4 + 0.4; - float rotX = distrib(generator) * 2 * 3.14; - float rotY = distrib(generator) * 2 * 3.14; - float rotZ = distrib(generator) * 2 * 3.14; + float rotX = s_Distrib(s_Generator) * 2 * 3.14; + float rotY = s_Distrib(s_Generator) * 2 * 3.14; + float rotZ = s_Distrib(s_Generator) * 2 * 3.14; - float shearXY = distrib(generator) * 0.2f - 0.1f; - float shearXZ = distrib(generator) * 0.2f - 0.1f; - float shearYX = distrib(generator) * 0.2f - 0.1f; - float shearYZ = distrib(generator) * 0.2f - 0.1f; - float shearZX = distrib(generator) * 0.2f - 0.1f; - float shearZY = distrib(generator) * 0.2f - 0.1f; + float shearXY = s_Distrib(s_Generator) * 0.2f - 0.1f; + float shearXZ = s_Distrib(s_Generator) * 0.2f - 0.1f; + float shearYX = s_Distrib(s_Generator) * 0.2f - 0.1f; + float shearYZ = s_Distrib(s_Generator) * 0.2f - 0.1f; + float shearZX = s_Distrib(s_Generator) * 0.2f - 0.1f; + float shearZY = s_Distrib(s_Generator) * 0.2f - 0.1f; - float translateX = distrib(generator) * 1.2f - 0.6f; - float translateY = distrib(generator) * 1.2f - 0.6f; - float translateZ = distrib(generator) * 1.2f - 0.6f; + float translateX = s_Distrib(s_Generator) * 1.2f - 0.6f; + float translateY = s_Distrib(s_Generator) * 1.2f - 0.6f; + float translateZ = s_Distrib(s_Generator) * 1.2f - 0.6f; auto scale = glm::scale(glm::mat4(1), {scaleX, scaleY, scaleZ}); auto rotateX = glm::rotate(scale, rotX, {1, 0, 0});