aboutsummaryrefslogtreecommitdiffstats
path: root/lib/time.moon
diff options
context:
space:
mode:
Diffstat (limited to 'lib/time.moon')
-rw-r--r--lib/time.moon16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/time.moon b/lib/time.moon
index c49a7d7..a726af3 100644
--- a/lib/time.moon
+++ b/lib/time.moon
@@ -87,19 +87,22 @@ class tick extends Op
counts upwards by one every period seconds and returns the number of completed ticks."
new: =>
- super 'num'
+ super 'num', 0
@phase = 0
setup: (params) =>
+ super params
@assert_types 'num', 'num'
- update: (dt) =>
+ tick: (first) =>
-- if clock is dirty
- if @inputs[1].dirty
+ if first or @inputs[1].dirty
dt, period = @unwrap_inputs!
@phase += dt / period
- @out\set math.floor @phase
+ next_num = math.floor @phase
+ if next_num != @.out!
+ @out\set next_num
class every extends Op
@doc: "(every clock period) - trigger every period seconds
@@ -110,11 +113,12 @@ returns true once every period seconds."
@phase = 0
setup: (@period) =>
+ super params
@assert_types 'num', 'num'
- update: (dt) =>
+ tick: (first) =>
-- if clock is dirty
- if @inputs[1].dirty
+ if first or @inputs[1].dirty
dt, period = @unwrap_inputs!
@phase += dt / period