From 67f04e72fabcad7c5140333468f1acfa15b770f2 Mon Sep 17 00:00:00 2001 From: lhofhansl Date: Mon, 23 Jul 2018 09:07:05 +0200 Subject: [PATCH] Add player position prediction. Add particle radius parameters --- init.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index c0ecd4a..013f2e6 100644 --- a/init.lua +++ b/init.lua @@ -12,6 +12,8 @@ local RAINGAIN = 0.2 -- Rain sound volume local COLLIDE = false -- Whether particles collide with nodes local NISVAL = 39 -- Clouds RGB value at night local DASVAL = 175 -- Clouds RGB value in daytime +local FRADIUS = 48 -- Radius in which flakes are created +local DRADIUS = 24 -- Radius in which drops are created local np_prec = { offset = 0, @@ -78,7 +80,10 @@ minetest.register_globalstep(function(dtime) for _, player in ipairs(minetest.get_connected_players()) do local player_name = player:get_player_name() - local ppos = player:getpos() + -- Predict player position as slightly behind the CYCLE interval. + -- Assume scheduling gets behind slighly (the 1.5), this also tested well. + local ppos = vector.add(player:getpos(), + vector.multiply(player:get_player_velocity(), GSCYCLE * 1.5)) local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming if pposy >= YLIMIT - 2 then local pposx = math.floor(ppos.x) @@ -156,9 +161,9 @@ minetest.register_globalstep(function(dtime) for flake = 1, FLAKES do minetest.add_particle({ pos = { - x = pposx - 24 + math.random(0, 48), + x = pposx - FRADIUS + math.random(0, FRADIUS * 2), y = pposy + 12, - z = pposz - 24 + math.random(0, 48) + z = pposz - FRADIUS + math.random(0, FRADIUS * 2) }, velocity = { x = (-20 + math.random(0, 40)) / 100, @@ -183,9 +188,9 @@ minetest.register_globalstep(function(dtime) local extime = math.min((spawny - YLIMIT) / 10, 1.8) minetest.add_particle({ pos = { - x = pposx - 12 + math.random(0, 24), + x = pposx - DRADIUS + math.random(0, DRADIUS * 2), y = spawny, - z = pposz - 12 + math.random(0, 24) + z = pposz - DRADIUS + math.random(0, DRADIUS * 2) }, velocity = { x = 0.0,