Adjust emitters to not produce side-effects in 'wire-state' method.
This commit is contained in:
parent
a5e9011678
commit
bed3604685
1 changed files with 19 additions and 21 deletions
|
@ -127,20 +127,19 @@
|
|||
(match-lambda*
|
||||
(('type) 'emitter)
|
||||
(('position) position)
|
||||
(('tick grid-info) ($ timer (+ ($ timer) 1)))
|
||||
(('tick grid-info)
|
||||
(let ((t (modulo (+ ($ timer) 1) interval)))
|
||||
($ timer t)
|
||||
(when (= t 0)
|
||||
($ grid-info 'append-event `(emit ,x ,y)))))
|
||||
(('post-tick grid-info) #f)
|
||||
(('enter obj grid-info) #f)
|
||||
(('exit obj grid-info) #f)
|
||||
(('wire-state grid-info)
|
||||
(let ((t ($ timer)))
|
||||
(cond
|
||||
((= (modulo t interval) 0)
|
||||
($ grid-info 'append-event `(emit ,x ,y))
|
||||
'electron-head)
|
||||
((= (modulo t interval) 1)
|
||||
'electron-tail)
|
||||
(else
|
||||
'copper))))
|
||||
(match ($ timer)
|
||||
(0 'electron-head)
|
||||
(1 'electron-tail)
|
||||
(_ 'copper)))
|
||||
(('update-wire-state grid-info) #f)
|
||||
(('alive?) #t)
|
||||
(('describe) `(clock-emitter ,position))
|
||||
|
@ -155,27 +154,26 @@
|
|||
(('position) position)
|
||||
(('tick grid-info)
|
||||
(when ($ on?)
|
||||
($ timer (+ ($ timer) 1))))
|
||||
(let ((t (modulo (+ ($ timer) 1) interval)))
|
||||
($ timer t)
|
||||
(when (= t 0)
|
||||
($ grid-info 'append-event `(emit ,x ,y))))))
|
||||
(('post-tick grid-info) #f)
|
||||
(('enter obj grid-info) #f)
|
||||
(('exit obj grid-info) #f)
|
||||
(('activate grid-info)
|
||||
($ on? #t)
|
||||
($ timer 0)
|
||||
($ timer -1)
|
||||
($ grid-info 'append-event `(emitter-on ,x ,y)))
|
||||
(('deactivate grid-info)
|
||||
($ on? #f)
|
||||
($ grid-info 'append-event `(emitter-off ,x ,y)))
|
||||
(('wire-state grid-info)
|
||||
(when ($ on?)
|
||||
(let ((t ($ timer)))
|
||||
(cond
|
||||
((= (modulo t interval) 0)
|
||||
'electron-head)
|
||||
((= (modulo t interval) 1)
|
||||
'electron-tail)
|
||||
(else
|
||||
'copper)))))
|
||||
(and ($ on?)
|
||||
(match ($ timer)
|
||||
(0 'electron-head)
|
||||
(1 'electron-tail)
|
||||
(_ 'copper))))
|
||||
(('update-wire-state grid-info) #f)
|
||||
(('alive?) #t)
|
||||
(('on?) ($ on?))
|
||||
|
|
Loading…
Add table
Reference in a new issue