From 5a40534c851350c8370978916af37c6017d5e1be Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 18 Feb 2023 19:33:27 +0100 Subject: [PATCH] embeddings:: star probability configurable --- config.cpp | 3 +++ sky.cpp | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config.cpp b/config.cpp index 1849f523..0811ccb5 100644 --- a/config.cpp +++ b/config.cpp @@ -2397,6 +2397,7 @@ EX void show3D_height_details() { add_edit(vid.infdeep_height); add_edit(vid.sun_size); add_edit(vid.star_size); + add_edit(star_prob); add_edit(vid.height_limits); if(euclid && msphere) add_edit(use_euclidean_infinity); } @@ -2763,6 +2764,8 @@ EX int config3 = addHook(hooks_configfile, 100, [] { ->editable(0, 10, .1, "sun size (relative to item sizes)", "", '8'); param_f(vid.star_size, "star_size", "star_size", 0.75) ->editable(0, 10, .1, "night star size (relative to item sizes)", "", '9'); + param_f(star_prob, "star_prob", 0.3) + ->editable(0, 1, .01, "star probability", "probability of star per tile", '*'); param_b(vid.height_limits, "height_limits", true) ->editable("automatically limit heights if too high", 'l'); param_b(auto_remove_roofs, "auto_remove_roofs", true) diff --git a/sky.cpp b/sky.cpp index 59f113c3..03d6893d 100644 --- a/sky.cpp +++ b/sky.cpp @@ -357,6 +357,17 @@ void draw_star(const shiftmatrix& V, const hpcshape& sh, color_t col, ld rev = f queuepolyat(V1 * zpush(val), sh, col, PPR::SKY); } +EX ld star_prob = 0.33; + +/* the first star is supposed to appear as long as probability > 0 */ +EX vector stars = {1e-20}; + +EX bool star_for(int i) { + i = i & ((1<<16)-1); + while(isize(stars) <= i) stars.push_back(randd()); + return stars[i] < star_prob; + } + void celldrawer::draw_ceiling() { if(!models::is_perspective(pmodel) || sphere) return; @@ -368,11 +379,11 @@ void celldrawer::draw_ceiling() { switch(ceiling_category(c)) { /* ceilingless levels */ case 1: { - if(fieldpattern::fieldval_uniq(c) % 3 == 0) + if(star_for(fieldpattern::fieldval_uniq(c))) draw_star(V, cgi.shNightStar, 0xFFFFFFFF); add_to_sky(0x00000F, 0x00000F); if(c->land == laAsteroids) { - if(fieldpattern::fieldval_uniq(c) % 9 < 3) + if(star_for(fieldpattern::fieldval_uniq(c) ^ 0x5555)) draw_star(V, cgi.shNightStar, 0xFFFFFFFF, true); int sk = get_skybrightness(-1); auto sky = draw_shapevec(c, V * MirrorZ, cgi.shFullFloor.levels[SIDE_SKY], 0x000000FF + 0x100 * (sk/17), PPR::SKY);