parent
6bd035b69f
commit
5c77e58ecd
15
init.lua
15
init.lua
|
@ -51,6 +51,7 @@ local rad_0 = 0
|
||||||
|
|
||||||
function Timekeeper( this )
|
function Timekeeper( this )
|
||||||
local timer_defs = { }
|
local timer_defs = { }
|
||||||
|
local pending_timer_defs = { }
|
||||||
local clock = 0.0
|
local clock = 0.0
|
||||||
local delay = 0.0
|
local delay = 0.0
|
||||||
local self = { }
|
local self = { }
|
||||||
|
@ -64,22 +65,30 @@ function Timekeeper( this )
|
||||||
end
|
end
|
||||||
|
|
||||||
self.start = function ( period, name, func )
|
self.start = function ( period, name, func )
|
||||||
timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + delay + period, started = clock, func = func }
|
timer_defs[ name ] = nil
|
||||||
|
pending_timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + delay + period, started = clock, func = func }
|
||||||
end
|
end
|
||||||
|
|
||||||
self.start_now = function ( period, name, func )
|
self.start_now = function ( period, name, func )
|
||||||
|
timer_defs[ name ] = nil
|
||||||
if not func( this, 0, period, 0.0, 0.0 ) then
|
if not func( this, 0, period, 0.0, 0.0 ) then
|
||||||
timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + period, started = clock, func = func }
|
pending_timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + period, started = clock, func = func }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.clear = function ( name )
|
self.clear = function ( name )
|
||||||
|
pending_timer_defs[ name ] = nil
|
||||||
timer_defs[ name ] = nil
|
timer_defs[ name ] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
self.on_step = function ( dtime )
|
self.on_step = function ( dtime )
|
||||||
clock = clock + dtime
|
clock = clock + dtime
|
||||||
|
|
||||||
|
for k, v in pairs( pending_timer_defs ) do
|
||||||
|
timer_defs[ k ] = v
|
||||||
|
pending_timer_defs[ k ] = nil
|
||||||
|
end
|
||||||
|
|
||||||
local timers = { }
|
local timers = { }
|
||||||
for k, v in pairs( timer_defs ) do
|
for k, v in pairs( timer_defs ) do
|
||||||
if clock >= v.expiry and clock > v.started then
|
if clock >= v.expiry and clock > v.started then
|
||||||
|
@ -679,7 +688,7 @@ mobs.register_mob = function ( name, def )
|
||||||
|
|
||||||
-- alertness and awareness functions --
|
-- alertness and awareness functions --
|
||||||
|
|
||||||
start_awareness = function ( self, target )
|
start_awareness = function ( self )
|
||||||
local awareness = self.awareness_stages[ self.state ]
|
local awareness = self.awareness_stages[ self.state ]
|
||||||
|
|
||||||
if awareness then
|
if awareness then
|
||||||
|
|
Loading…
Reference in New Issue