aboutsummaryrefslogtreecommitdiffstats
path: root/lib/time.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-23 22:16:25 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-28 12:22:25 +0000
commit0b284ac60916142cadb8b65fa5ca9f9cffcfc200 (patch)
tree07fc75330d813d54751f42a2f55b979398929814 /lib/time.moon
parentmerge Const and Stream into Value; Dataflow logic (diff)
downloadalive-0b284ac60916142cadb8b65fa5ca9f9cffcfc200.tar.gz
alive-0b284ac60916142cadb8b65fa5ca9f9cffcfc200.zip
lots of fixes
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