Compare commits

...

10 Commits

Author SHA1 Message Date
paramat
3342939257 Use proper method for getting OS time. Use per-server-session time offset to vary precipitation timing each server session 2020-02-24 23:46:29 +00:00
paramat
c1d0fe4142 Add y limits for skybox effects, set to deep ocean and cloud level, independent of the set water level where particles and sounds stop. Add 'skybox' table to track player sky status to attempt to avoid turning off skyboxes set by other mods, therefore remove randomised and lazy setting of skybox, now happens within 0.5s. For now, remove predicted player position due to issues, to be re-added later acting horizontally only 2019-01-31 01:38:17 +00:00
paramat
568964eabf Add ability to spawn multiple raindrops per light-tested position, to enable maintaining raindrop visual density while reducing the number of light-tested positions. 2018-08-15 22:46:48 +01:00
paramat
3de69ba37a Tune parameters. Remove broken PRECOFF and replace with a fixed noise threshold. Improve comments. Use clouds bool in set_sky() to remove clouds from overcast sky 2018-08-08 21:20:42 +01:00
paramat
aa1ae896ef Version 0.6.0. Only spawn particles under open sky (light == 15) and use collision detection 2018-07-24 18:46:04 +01:00
lhofhansl
67f04e72fa Add player position prediction. Add particle radius parameters 2018-07-23 08:07:05 +01:00
paramat
0a0787a8f1 Update deprecated 'acc','vel'. 12 new 5x5 snowflake textures. Time particles to disappear at water level. Randomise snowflake XZ velocities 2017-12-12 19:26:29 +00:00
paramat
fcb0537b32 Disable under a y limit set by parameter, usually set to a world's water level 2017-04-15 23:24:14 +01:00
paramat
78b6e10d73 Clear sound handles on leaveplayer. Tune rain speed, particle volumes. More raindrops. Add option for collision detection 2017-04-15 22:38:40 +01:00
paramat
a8644f2c29 Add rain sound. Use timer for globalstep cycle. Improve raindrop texture. Disable rainfall in deserts below savanna-desert border voronoi line. Sample light at player head position for precipitation while swimming 2017-04-14 21:40:53 +01:00
17 changed files with 291 additions and 95 deletions

View File

@ -1,4 +1,11 @@
snowdrift 0.5.0 by paramat snowdrift 0.6.4 by paramat.
For Minetest 0.4.12 and later For Minetest 0.4.16 and later. Compatible with Minetest 5.0.0.
Depends default Depends: default.
Licenses: Source code MIT. Media (textures) CC BY-SA (3.0)
Licenses
--------
Source code: MIT by paramat.
Media:
Textures CC BY-SA (3.0) by paramat.
Sounds CC BY (3.0) by inchadney.
http://freesound.org/people/inchadney/sounds/58835/

302
init.lua
View File

@ -1,22 +1,39 @@
-- Parameters -- Parameters
local PRECSPR = 11 -- Time scale for precipitation variation in minutes local YWATER = 1 -- Normally set this to world's water level
local PRECOFF = 0.8 -- Precipitation noise threshold offset -- Particles are timed to disappear at this y
local PROCHA = 0.2 -- Per player per globalstep processing chance -- Particles are not spawned for players below this y
local FLAKES = 8 -- Snowflake density -- Rain sound is not played for players below this y
local DROPS = 16 -- Rainfall density local YMIN = -48 -- Normally set this to deepest ocean
local NISVAL = 39 -- Clouds RGB value at night local YMAX = 120 -- Normally set this to cloud level
local DASVAL = 175 -- Clouds RGB value in daytime -- Weather does not occur for players outside this y range
local PRECTIM = 300 -- Precipitation noise 'spread'
-- Time scale for precipitation variation, in seconds
local PRECTHR = 0.2 -- Precipitation noise threshold, -1 to 1:
-- -1 = precipitation all the time
-- 0 = precipitation half the time
-- 1 = no precipitation
local FLAKLPOS = 32 -- Snowflake light-tested positions per 0.5s cycle
-- Maximum number of snowflakes spawned per 0.5s
local DROPLPOS = 64 -- Raindrop light-tested positions per 0.5s cycle
local DROPPPOS = 2 -- Number of raindrops spawned per light-tested position
local RAINGAIN = 0.2 -- Rain sound volume
local NISVAL = 39 -- Overcast sky RGB value at night (brightness)
local DASVAL = 159 -- Overcast sky RGB value in daytime (brightness)
local FLAKRAD = 16 -- Radius in which flakes are created
local DROPRAD = 16 -- Radius in which drops are created
-- Precipitation noise
local np_prec = { local np_prec = {
offset = 0, offset = 0,
scale = 1, scale = 1,
spread = {x = PRECSPR, y = PRECSPR, z = PRECSPR}, spread = {x = PRECTIM, y = PRECTIM, z = PRECTIM},
seed = 813, seed = 813,
octaves = 1, octaves = 1,
persist = 0, persist = 0,
lacunarity = 2.0, lacunarity = 2.0,
--flags = "" flags = "defaults"
} }
-- These 2 must match biome heat and humidity noise parameters for a world -- These 2 must match biome heat and humidity noise parameters for a world
@ -29,7 +46,7 @@ local np_temp = {
octaves = 3, octaves = 3,
persist = 0.5, persist = 0.5,
lacunarity = 2.0, lacunarity = 2.0,
--flags = "" flags = "defaults"
} }
local np_humid = { local np_humid = {
@ -40,13 +57,17 @@ local np_humid = {
octaves = 3, octaves = 3,
persist = 0.5, persist = 0.5,
lacunarity = 2.0, lacunarity = 2.0,
--flags = "" flags = "defaults"
} }
-- End parameters
-- Stuff
-- Some stuff
local difsval = DASVAL - NISVAL local difsval = DASVAL - NISVAL
local grad = 14 / 95
local yint = 1496 / 95
-- Initialise noise objects to nil -- Initialise noise objects to nil
@ -56,46 +77,74 @@ local nobj_humid = nil
local nobj_prec = nil local nobj_prec = nil
-- Player tables
local handles = {}
local skybox = {} -- true/false. To not turn off skyboxes of other mods
-- Globalstep function -- Globalstep function
local os_time_0 = os.time()
local t_offset = math.random(0, 300000)
local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 0.5 then
return
end
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
-- Randomise and spread processing load local player_name = player:get_player_name()
if math.random() > PROCHA then
return
end
local ppos = player:getpos() local ppos = player:getpos()
local pposx = math.floor(ppos.x) -- Point just above player head, to ensure precipitation when swimming
local pposy = math.floor(ppos.y) local pposy = math.floor(ppos.y) + 2
local pposz = math.floor(ppos.z) if pposy >= YMIN and pposy <= YMAX then
local pposx = math.floor(ppos.x)
local pposz = math.floor(ppos.z)
local ppos = {x = pposx, y = pposy, z = pposz}
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp) -- Heat, humidity and precipitation noises
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz}) -- Time in seconds.
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz}) -- Add the per-server-session random time offset to avoid identical behaviour
local nval_prec = nobj_prec:get2d({x = os.clock() / 60, y = 0}) -- each server session.
local time = os.difftime(os.time(), os_time_0) - t_offset
-- Biome system: frozen biomes below heat 35, local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
-- deserts below humidity 20 local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
local freeze = nval_temp < 35 local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
local precip = nval_prec > (nval_humid - 50) / 50 + PRECOFF
-- Check if player is outside local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
local outside = minetest.get_node_light(ppos, 0.5) == 15 local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
local nval_prec = nobj_prec:get2d({x = time, y = 0})
-- Occasionally reset player sky -- Default Minetest Game biome system:
if math.random() < 0.05 then -- Frozen biomes below heat 35
if precip then -- deserts below line 14 * t - 95 * h = -1496
-- Set overcast sky -- h = (14 * t + 1496) / 95
-- h = 14/95 * t + 1496/95
-- where 14/95 is gradient and 1496/95 is 'y-intersection'
-- h - 14/95 * t = 1496/95
-- so area above line is
-- h - 14/95 * t > 1496/95
local freeze = nval_temp < 35
local precip = nval_prec > PRECTHR and
nval_humid - grad * nval_temp > yint
-- Set sky
if precip and not skybox[player_name] then
-- Set overcast sky only if normal
local sval local sval
local time = minetest.get_timeofday() local time = minetest.get_timeofday()
if time >= 0.5 then if time >= 0.5 then
time = 1 - time time = 1 - time
end end
-- Sky brightness transitions: -- Sky brightness transitions:
-- First transition (24000 -) 4500, (1 -) 0.1875 -- First transition (24000 -) 4500, (1 -) 0.1875
-- Last transition (24000 -) 5750, (1 -) 0.2396 -- Last transition (24000 -) 5750, (1 -) 0.2396
@ -104,65 +153,138 @@ minetest.register_globalstep(function(dtime)
elseif time >= 0.2396 then elseif time >= 0.2396 then
sval = DASVAL sval = DASVAL
else else
sval = math.floor(NISVAL + ((time - 0.1875) / 0.0521) * difsval) sval = math.floor(NISVAL +
((time - 0.1875) / 0.0521) * difsval)
end end
player:set_sky({r = sval, g = sval, b = sval + 16, a = 255},
player:set_sky({r = sval, g = sval, b = sval + 16, a = 255}, "plain", {}) "plain", {}, false)
else skybox[player_name] = true
-- Reset sky to normal elseif not precip and skybox[player_name] then
player:set_sky({}, "regular", {}) -- Set normal sky only if skybox
player:set_sky({}, "regular", {}, true)
skybox[player_name] = nil
end end
end
if precip and outside then -- Stop looping sound.
-- Precipitation -- Stop sound if head below water level.
if freeze then if not precip or freeze or pposy < YWATER then
-- Snowfall if handles[player_name] then
for flake = 1, FLAKES do minetest.sound_stop(handles[player_name])
minetest.add_particle({ handles[player_name] = nil
pos = {
x = pposx - 32 + math.random(0, 63),
y = pposy + 10 + math.random(0, 4),
z = pposz - 26 + math.random(0, 63)
},
vel = {
x = 0.0,
y = -2.0,
z = -1.0
},
acc = {x = 0, y = 0, z = 0},
expirationtime = 12,
size = 2.8,
collisiondetection = false,
vertical = false,
texture = "snowdrift_snowflake" .. math.random(1, 4) .. ".png",
playername = player:get_player_name()
})
end end
else end
-- Rainfall
for flake = 1, DROPS do -- Particles and sounds.
minetest.add_particle({ -- Only if head above water level.
pos = { if precip and pposy >= YWATER then
x = pposx - 8 + math.random(0, 16), if freeze then
y = pposy + 6 + math.random(0, 4), -- Snowfall particles
z = pposz - 8 + math.random(0, 16) for lpos = 1, FLAKLPOS do
}, local lposx = pposx - FLAKRAD +
vel = { math.random(0, FLAKRAD * 2)
x = 0.0, local lposz = pposz - FLAKRAD +
y = -8.0, math.random(0, FLAKRAD * 2)
z = 0.0 if minetest.get_node_light(
}, {x = lposx, y = pposy + 10, z = lposz},
acc = {x = 0, y = 0, z = 0}, 0.5) == 15 then
expirationtime = 2, -- Any position above light-tested position is also
size = 2.8, -- light level 15.
collisiondetection = false, -- Spawn Y randomised to avoid particles falling
vertical = true, -- in separated layers.
texture = "snowdrift_raindrop.png", -- Random range = speed * cycle time
playername = player:get_player_name() local spawny = pposy + 10 + math.random(0, 10) / 10
}) local extime = math.min((spawny - YWATER) / 2, 10)
minetest.add_particle({
pos = {x = lposx, y = spawny, z = lposz},
velocity = {x = 0, y = -2.0, z = 0},
acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime,
size = 2.8,
collisiondetection = true,
collision_removal = true,
vertical = false,
texture = "snowdrift_snowflake" ..
math.random(1, 12) .. ".png",
playername = player:get_player_name()
})
end
end
else
-- Rainfall particles
for lpos = 1, DROPLPOS do
local lposx = pposx - DROPRAD +
math.random(0, DROPRAD * 2)
local lposz = pposz - DROPRAD +
math.random(0, DROPRAD * 2)
if minetest.get_node_light(
{x = lposx, y = pposy + 10, z = lposz},
0.5) == 15 then
for drop = 1, DROPPPOS do
local spawny = pposy + 10 + math.random(0, 60) / 10
local extime = math.min((spawny - YWATER) / 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({
pos = {x = spawnx, y = spawny, z = spawnz},
velocity = {x = 0.0, y = -12.0, z = 0.0},
acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime,
size = 2.8,
collisiondetection = true,
collision_removal = true,
vertical = true,
texture = "snowdrift_raindrop.png",
playername = player:get_player_name()
})
end
end
end
-- Start looping sound
if not handles[player_name] then
local handle = minetest.sound_play(
"snowdrift_rain",
{
to_player = player_name,
gain = RAINGAIN,
loop = true,
}
)
if handle then
handles[player_name] = handle
end
end
end end
end end
else
-- Player outside y limits.
-- Stop sound if playing.
if handles[player_name] then
minetest.sound_stop(handles[player_name])
handles[player_name] = nil
end
-- Set normal sky if skybox
if skybox[player_name] then
player:set_sky({}, "regular", {}, true)
skybox[player_name] = nil
end
end end
end end
end) end)
-- On leaveplayer function
minetest.register_on_leaveplayer(function(player)
local player_name = player:get_player_name()
-- Stop sound if playing and remove handle
if handles[player_name] then
minetest.sound_stop(handles[player_name])
handles[player_name] = nil
end
-- Remove skybox bool if necessary
if skybox[player_name] then
skybox[player_name] = nil
end
end)

View File

@ -2,7 +2,7 @@ License of source code
---------------------- ----------------------
The MIT License (MIT) The MIT License (MIT)
Copyright (C) 2014-2016 paramat Copyright (C) 2017 paramat
Permission is hereby granted, free of charge, to any person obtaining a copy of this Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software software and associated documentation files (the "Software"), to deal in the Software
@ -22,3 +22,70 @@ DEALINGS IN THE SOFTWARE.
For more details: For more details:
https://opensource.org/licenses/MIT https://opensource.org/licenses/MIT
License of media (textures)
---------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Copyright (C) 2017 paramat
You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by-sa/3.0/
License of media (sounds)
-------------------------
Attribution 3.0 Unported (CC BY 3.0)
Copyright (C) 2008 inchadney
You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by/3.0/

BIN
sounds/snowdrift_rain.ogg Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 B

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 B

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 197 B

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 B

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B