Skip to content

Commit 560627e

Browse files
numberZerolhofhansl
authored andcommittedNov 26, 2020
Reuse seed when updating stars
The only currently relevant parameter is scale which can now be changed without resetting stars position
1 parent 3077afc commit 560627e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
 

‎src/client/sky.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ void Sky::setStarCount(u16 star_count, bool force_update)
830830
// Allow force updating star count at game init.
831831
if (m_star_params.count != star_count || force_update) {
832832
m_star_params.count = star_count;
833+
m_seed = (u64)myrand() << 32 | myrand();
833834
updateStars();
834835
}
835836
}
@@ -847,12 +848,13 @@ void Sky::updateStars() {
847848
m_stars->Vertices.reallocate(4 * m_star_params.count);
848849
m_stars->Indices.reallocate(6 * m_star_params.count);
849850

851+
PcgRandom rgen(m_seed);
850852
float d = (0.006 / 2) * m_star_params.scale;
851853
for (u16 i = 0; i < m_star_params.count; i++) {
852854
v3f r = v3f(
853-
myrand_range(-10000, 10000),
854-
myrand_range(-10000, 10000),
855-
myrand_range(-10000, 10000)
855+
rgen.range(-10000, 10000),
856+
rgen.range(-10000, 10000),
857+
rgen.range(-10000, 10000)
856858
);
857859
core::CMatrix4<f32> a;
858860
a.buildRotateFromTo(v3f(0, 1, 0), r);

‎src/client/sky.h

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class Sky : public scene::ISceneNode
179179

180180
bool m_default_tint = true;
181181

182+
u64 m_seed = 0;
182183
irr_ptr<scene::SMeshBuffer> m_stars;
183184

184185
video::ITexture *m_sun_texture;

0 commit comments

Comments
 (0)
Please sign in to comment.