Use proper method for getting OS time. Use per-server-session time offset to vary precipitation timing each server session
parent
c1d0fe4142
commit
3342939257
10
README.txt
10
README.txt
|
@ -1,11 +1,11 @@
|
||||||
snowdrift 0.6.3 by paramat
|
snowdrift 0.6.4 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.
|
||||||
|
|
||||||
Licenses
|
Licenses
|
||||||
--------
|
--------
|
||||||
Source code: MIT by paramat
|
Source code: MIT by paramat.
|
||||||
Media:
|
Media:
|
||||||
Textures CC BY-SA (3.0) by paramat
|
Textures CC BY-SA (3.0) by paramat.
|
||||||
Sounds CC BY (3.0) by inchadney
|
Sounds CC BY (3.0) by inchadney.
|
||||||
http://freesound.org/people/inchadney/sounds/58835/
|
http://freesound.org/people/inchadney/sounds/58835/
|
||||||
|
|
48
init.lua
48
init.lua
|
@ -1,20 +1,20 @@
|
||||||
-- Parameters
|
-- Parameters
|
||||||
|
|
||||||
local YWATER = 1 -- Normally set this to world's water level
|
local YWATER = 1 -- Normally set this to world's water level
|
||||||
-- Particles are timed to disappear at this y
|
-- Particles are timed to disappear at this y
|
||||||
-- Particles are not spawned for players below this y
|
-- Particles are not spawned for players below this y
|
||||||
-- Rain sound is not played for players below this y
|
-- Rain sound is not played for players below this y
|
||||||
local YMIN = -48 -- Normally set this to deepest ocean
|
local YMIN = -48 -- Normally set this to deepest ocean
|
||||||
local YMAX = 120 -- Normally set this to cloud level
|
local YMAX = 120 -- Normally set this to cloud level
|
||||||
-- Weather does not occur for players outside this y range
|
-- Weather does not occur for players outside this y range
|
||||||
local PRECTIM = 5 -- Precipitation noise 'spread'
|
local PRECTIM = 300 -- Precipitation noise 'spread'
|
||||||
-- Time scale for precipitation variation, in minutes
|
-- Time scale for precipitation variation, in seconds
|
||||||
local PRECTHR = 0.2 -- Precipitation noise threshold, -1 to 1:
|
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 FLAKLPOS = 32 -- Snowflake light-tested positions per 0.5s cycle
|
local FLAKLPOS = 32 -- Snowflake light-tested positions per 0.5s cycle
|
||||||
-- Maximum number of snowflakes spawned per 0.5s
|
-- Maximum number of snowflakes spawned per 0.5s
|
||||||
local DROPLPOS = 64 -- Raindrop light-tested positions per 0.5s cycle
|
local DROPLPOS = 64 -- Raindrop light-tested positions per 0.5s cycle
|
||||||
local DROPPPOS = 2 -- Number of raindrops spawned per light-tested position
|
local DROPPPOS = 2 -- Number of raindrops spawned per light-tested position
|
||||||
local RAINGAIN = 0.2 -- Rain sound volume
|
local RAINGAIN = 0.2 -- Rain sound volume
|
||||||
|
@ -85,6 +85,9 @@ 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
|
local timer = 0
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
@ -101,28 +104,35 @@ minetest.register_globalstep(function(dtime)
|
||||||
-- Point just above player head, to ensure precipitation when swimming
|
-- Point just above player head, to ensure precipitation when swimming
|
||||||
local pposy = math.floor(ppos.y) + 2
|
local pposy = math.floor(ppos.y) + 2
|
||||||
if pposy >= YMIN and pposy <= YMAX then
|
if pposy >= YMIN and pposy <= YMAX then
|
||||||
--TODO Predict player position? Only horizontally
|
|
||||||
--local ppos = vector.add(player:getpos(),
|
|
||||||
--vector.multiply(player:get_player_velocity(), ?))
|
|
||||||
local pposx = math.floor(ppos.x)
|
local pposx = math.floor(ppos.x)
|
||||||
local pposz = math.floor(ppos.z)
|
local pposz = math.floor(ppos.z)
|
||||||
local ppos = {x = pposx, y = pposy, z = pposz}
|
local ppos = {x = pposx, y = pposy, z = pposz}
|
||||||
|
|
||||||
-- Heat and humidity calculations
|
-- Heat, humidity and precipitation noises
|
||||||
|
|
||||||
|
-- Time in seconds.
|
||||||
|
-- Add the per-server-session random time offset to avoid identical behaviour
|
||||||
|
-- each server session.
|
||||||
|
local time = os.difftime(os.time(), os_time_0) - t_offset
|
||||||
|
|
||||||
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
|
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
|
||||||
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
|
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
|
||||||
local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
|
local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
|
||||||
|
|
||||||
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
|
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
|
||||||
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
|
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
|
||||||
local nval_prec = nobj_prec:get2d({x = os.clock() / 60, y = 0})
|
local nval_prec = nobj_prec:get2d({x = time, y = 0})
|
||||||
-- Biome system: Frozen biomes below heat 35,
|
|
||||||
|
-- Default Minetest Game biome system:
|
||||||
|
-- Frozen biomes below heat 35
|
||||||
-- deserts below line 14 * t - 95 * h = -1496
|
-- deserts below line 14 * t - 95 * h = -1496
|
||||||
-- h = (14 * t + 1496) / 95
|
-- h = (14 * t + 1496) / 95
|
||||||
-- h = 14/95 * t + 1496/95
|
-- h = 14/95 * t + 1496/95
|
||||||
-- where 14/95 is gradient and 1496/95 is y intersection
|
-- where 14/95 is gradient and 1496/95 is 'y-intersection'
|
||||||
-- h - 14/95 t = 1496/95 y intersection
|
-- h - 14/95 * t = 1496/95
|
||||||
-- so area above line is
|
-- so area above line is
|
||||||
-- h - 14/95 t > 1496/95
|
-- h - 14/95 * t > 1496/95
|
||||||
|
|
||||||
local freeze = nval_temp < 35
|
local freeze = nval_temp < 35
|
||||||
local precip = nval_prec > PRECTHR and
|
local precip = nval_prec > PRECTHR and
|
||||||
nval_humid - grad * nval_temp > yint
|
nval_humid - grad * nval_temp > yint
|
||||||
|
|
Loading…
Reference in New Issue