Add ability to spawn multiple raindrops per light-tested position, to enable maintaining raindrop visual density while reducing the number of light-tested positions.

This commit is contained in:
paramat 2018-08-15 22:46:48 +01:00
parent 3de69ba37a
commit 568964eabf
2 changed files with 32 additions and 27 deletions

View File

@ -1,4 +1,4 @@
snowdrift 0.6.1 by paramat snowdrift 0.6.2 by paramat
For Minetest 0.4.16 and later. Compatible with Minetest 5.0.0. For Minetest 0.4.16 and later. Compatible with Minetest 5.0.0.
Depends: default Depends: default

View File

@ -9,14 +9,15 @@ local PRECTHR = 0.2 -- Precipitation noise threshold, -1 to 1:
-- -1 = precipitation all the time -- -1 = precipitation all the time
-- 0 = precipitation half the time -- 0 = precipitation half the time
-- 1 = no precipitation -- 1 = no precipitation
local FLAKPOS = 32 -- Snowflake light-tested positions per cycle local FLAKLPOS = 32 -- Snowflake light-tested positions per cycle
-- Maximum number of snowflakes spawned per 0.5s -- Maximum number of snowflakes spawned per 0.5s
local DROPPOS = 128 -- Raindrop light-tested positions per cycle local DROPLPOS = 64 -- Raindrop light-tested positions per cycle
-- Maximum number of raindrops spawned per 0.5s -- Maximum number of raindrops spawned per 0.5s
local DROPPPOS = 2 -- Raindrops per light-tested pos
local RAINGAIN = 0.2 -- Rain sound volume local RAINGAIN = 0.2 -- Rain sound volume
local NISVAL = 39 -- Overcast sky RGB value at night (brightness) local NISVAL = 39 -- Overcast sky RGB value at night (brightness)
local DASVAL = 159 -- Overcast sky RGB value in daytime (brightness) local DASVAL = 159 -- Overcast sky RGB value in daytime (brightness)
local FLAKRAD = 24 -- Radius in which flakes are created local FLAKRAD = 16 -- Radius in which flakes are created
local DROPRAD = 16 -- Radius in which drops are created local DROPRAD = 16 -- Radius in which drops are created
local np_prec = { local np_prec = {
@ -158,13 +159,13 @@ minetest.register_globalstep(function(dtime)
-- Precipitation -- Precipitation
if freeze then if freeze then
-- Snowfall -- Snowfall
for flake = 1, FLAKPOS do for lpos = 1, FLAKLPOS do
local spawnx = pposx - FLAKRAD + local lposx = pposx - FLAKRAD +
math.random(0, FLAKRAD * 2) math.random(0, FLAKRAD * 2)
local spawnz = pposz - FLAKRAD + local lposz = pposz - FLAKRAD +
math.random(0, FLAKRAD * 2) math.random(0, FLAKRAD * 2)
if minetest.get_node_light( if minetest.get_node_light(
{x = spawnx, y = pposy + 10, z = spawnz}, {x = lposx, y = pposy + 10, z = lposz},
0.5) == 15 then 0.5) == 15 then
-- Any position above light-tested position is also -- Any position above light-tested position is also
-- light level 15. -- light level 15.
@ -175,7 +176,7 @@ minetest.register_globalstep(function(dtime)
local extime = math.min((spawny - YLIMIT) / 2, 10) local extime = math.min((spawny - YLIMIT) / 2, 10)
minetest.add_particle({ minetest.add_particle({
pos = {x = spawnx, y = spawny, z = spawnz}, pos = {x = lposx, y = spawny, z = lposz},
velocity = {x = 0, y = -2.0, z = 0}, velocity = {x = 0, y = -2.0, z = 0},
acceleration = {x = 0, y = 0, z = 0}, acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime, expirationtime = extime,
@ -191,29 +192,33 @@ minetest.register_globalstep(function(dtime)
end end
else else
-- Rainfall -- Rainfall
for drop = 1, DROPPOS do for lpos = 1, DROPLPOS do
local spawnx = pposx - DROPRAD + local lposx = pposx - DROPRAD +
math.random(0, DROPRAD * 2) math.random(0, DROPRAD * 2)
local spawnz = pposz - DROPRAD + local lposz = pposz - DROPRAD +
math.random(0, DROPRAD * 2) math.random(0, DROPRAD * 2)
if minetest.get_node_light( if minetest.get_node_light(
{x = spawnx, y = pposy + 10, z = spawnz}, {x = lposx, y = pposy + 10, z = lposz},
0.5) == 15 then 0.5) == 15 then
local spawny = pposy + 10 + math.random(0, 60) / 10 for drop = 1, DROPPPOS do
local extime = math.min((spawny - YLIMIT) / 12, 2) local spawny = pposy + 10 + math.random(0, 60) / 10
local extime = math.min((spawny - YLIMIT) / 12, 2)
local spawnx = lposx - 0.4 + math.random(0, 8) / 10
local spawnz = lposz - 0.4 + math.random(0, 8) / 10
minetest.add_particle({ minetest.add_particle({
pos = {x = spawnx, y = spawny, z = spawnz}, pos = {x = spawnx, y = spawny, z = spawnz},
velocity = {x = 0.0, y = -12.0, z = 0.0}, velocity = {x = 0.0, y = -12.0, z = 0.0},
acceleration = {x = 0, y = 0, z = 0}, acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime, expirationtime = extime,
size = 2.8, size = 2.8,
collisiondetection = true, collisiondetection = true,
collision_removal = true, collision_removal = true,
vertical = true, vertical = true,
texture = "snowdrift_raindrop.png", texture = "snowdrift_raindrop.png",
playername = player:get_player_name() playername = player:get_player_name()
}) })
end
end end
end end