use after instead of globalstep

M  src/falling_snow.lua
M  src/snowball.lua
This commit is contained in:
HybridDog 2016-08-01 11:03:39 +02:00
parent a5ae53fbeb
commit 90e08fe0bc
2 changed files with 20 additions and 23 deletions

View File

@ -61,13 +61,7 @@ end
weather_legacy = read_weather_legacy() or "" weather_legacy = read_weather_legacy() or ""
local timer = 0 local function leg_step()
minetest.register_globalstep(function(dtime)
timer = timer+dtime
if timer < 2 then
return
end
timer = 0
if weather_legacy == "snow" then if weather_legacy == "snow" then
if math.random(1000) == 1 then if math.random(1000) == 1 then
weather_legacy = "none" weather_legacy = "none"
@ -77,7 +71,9 @@ minetest.register_globalstep(function(dtime)
weather_legacy = "snow" weather_legacy = "snow"
save_weather_legacy() save_weather_legacy()
end end
end) minetest.after(2, leg_step)
end
minetest.after(4, leg_step)
local function infolog(msg) local function infolog(msg)
minetest.log("info", "[snow] falling_snow: "..msg) minetest.log("info", "[snow] falling_snow: "..msg)

View File

@ -31,8 +31,7 @@ local function get_gravity()
return grav*snowball_gravity return grav*snowball_gravity
end end
local someone_throwing local someone_throwing, just_acitvated
local timer = 0
--Shoot snowball --Shoot snowball
local function snow_shoot_snowball(item, player) local function snow_shoot_snowball(item, player)
@ -49,7 +48,7 @@ local function snow_shoot_snowball(item, player)
if creative_mode then if creative_mode then
if not someone_throwing then if not someone_throwing then
someone_throwing = true someone_throwing = true
timer = -0.5 just_acitvated = true
end end
return return
end end
@ -58,13 +57,7 @@ local function snow_shoot_snowball(item, player)
end end
if creative_mode then if creative_mode then
local function update_step(dtime) local function update_step()
timer = timer+dtime
if timer < 0.006 then
return
end
timer = 0
local active local active
for _,player in pairs(minetest.get_connected_players()) do for _,player in pairs(minetest.get_connected_players()) do
if player:get_player_control().LMB then if player:get_player_control().LMB then
@ -84,13 +77,21 @@ if creative_mode then
end end
end end
-- do automatic throwing using a globalstep -- do automatic throwing using minetest.after
minetest.register_globalstep(function(dtime) local function do_step()
local timer
-- only if one holds left click -- only if one holds left click
if someone_throwing then if someone_throwing
update_step(dtime) and not just_acitvated then
update_step()
timer = 0.006
else
timer = 0.5
just_acitvated = false
end end
end) minetest.after(timer, do_step)
end
minetest.after(3, do_step)
end end
--The snowball Entity --The snowball Entity