]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Reuse seed when updating stars
authornumzero <numzer0@yandex.ru>
Sun, 22 Nov 2020 13:41:36 +0000 (16:41 +0300)
committerlhofhansl <larsh@apache.org>
Thu, 26 Nov 2020 20:49:10 +0000 (12:49 -0800)
The only currently relevant parameter is scale which can now be changed
without resetting stars position

src/client/sky.cpp
src/client/sky.h

index 29a0545ab11c90925113a8b75c04c25b71209713..cc9fb7d36f9aab3f43842c466d24f5755918bf3a 100644 (file)
@@ -830,6 +830,7 @@ void Sky::setStarCount(u16 star_count, bool force_update)
        // Allow force updating star count at game init.
        if (m_star_params.count != star_count || force_update) {
                m_star_params.count = star_count;
+               m_seed = (u64)myrand() << 32 | myrand();
                updateStars();
        }
 }
@@ -847,12 +848,13 @@ void Sky::updateStars() {
        m_stars->Vertices.reallocate(4 * m_star_params.count);
        m_stars->Indices.reallocate(6 * m_star_params.count);
 
+       PcgRandom rgen(m_seed);
        float d = (0.006 / 2) * m_star_params.scale;
        for (u16 i = 0; i < m_star_params.count; i++) {
                v3f r = v3f(
-                       myrand_range(-10000, 10000),
-                       myrand_range(-10000, 10000),
-                       myrand_range(-10000, 10000)
+                       rgen.range(-10000, 10000),
+                       rgen.range(-10000, 10000),
+                       rgen.range(-10000, 10000)
                );
                core::CMatrix4<f32> a;
                a.buildRotateFromTo(v3f(0, 1, 0), r);
index 17654501575ce7e961389e1ebf97fa18f245e036..9f859f961bf606b7187796eb3e82ce925552abba 100644 (file)
@@ -179,6 +179,7 @@ class Sky : public scene::ISceneNode
 
        bool m_default_tint = true;
 
+       u64 m_seed = 0;
        irr_ptr<scene::SMeshBuffer> m_stars;
 
        video::ITexture *m_sun_texture;