only mark devices updated if they change by a whole num
This commit is contained in:
parent
5360aef59b
commit
1770841753
26
main.fs
26
main.fs
|
@ -21,9 +21,15 @@ include debug.fs
|
|||
\ the word changed? leaves a -1 if the value has changed since last clear, 0 otherwise.
|
||||
: changed? ( addr offset -- flag ) cells + @ ;
|
||||
|
||||
\ the variable "devices" holds the amount of devices currently in the pool. It has a change flag. It begins with the change flag set, to draw the screen the first time.
|
||||
\ the variable "devices" holds the amount of devices currently in the pool. It has two values a change flag.
|
||||
\ The first value contains the current number of devices, the second contains the number of devices in the previous tick.
|
||||
\ (this is used to determine if the change flag needs to be set)
|
||||
\ It begins with the change flag set, to draw the screen the first time.
|
||||
\ this variable can contain decimal-point amounts of devices. Things that need a non-decimal amount can round it with ftrunc.
|
||||
create devices 0e f, -1 ,
|
||||
\ old devices is the old device count. For convenience.
|
||||
: old-devices devices float + ;
|
||||
|
||||
\ the variable "base-devices/tick" is the base amount of devices added per tick.
|
||||
variable base-devices/tick
|
||||
0.0005e base-devices/tick f!
|
||||
|
@ -48,9 +54,9 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
: f+! ( addr -- ) ( F: r -- ) dup f@ f+ f! ;
|
||||
|
||||
\ any-change? leaves a -1 on the stack if any value has changed, 0 otherwise
|
||||
: any-change? ( -- flag ) membercost 1 changed? devices 1 changed? message 2 changed? or or ;
|
||||
: any-change? ( -- flag ) membercost 1 changed? devices 2 changed? message 2 changed? or or ;
|
||||
\ clear-all clears the change flag on all values.
|
||||
: clear-all membercost 1 cleared devices 1 cleared message 2 cleared ;
|
||||
: clear-all membercost 1 cleared devices 2 cleared message 2 cleared ;
|
||||
\ the word !0= tests if something is non-zero
|
||||
: !0= ( n -- flag ) 0= 0= ;
|
||||
\ the word f!0= tests if a floating thing is non-zero
|
||||
|
@ -88,13 +94,19 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
1 count-messages-shown +!
|
||||
then ;
|
||||
|
||||
\ update-devices updates the device count, setting the change flag as needed
|
||||
: update-devices
|
||||
devices f@ old-devices f! \ store old value of devices
|
||||
devices/tick devices f+!
|
||||
devices f@ ftrunc old-devices f@ ftrunc f= 0= if \ if devices has changed by an integer amount
|
||||
devices 2 changed
|
||||
then ;
|
||||
|
||||
|
||||
\ the word game-tick runs a single tick of the game
|
||||
: game-tick unlock
|
||||
devices/tick devices f+!
|
||||
update-devices
|
||||
set-count-message
|
||||
\ TODO only set devices as changed on an integer change
|
||||
\ this seems to somehow cause a float overflow lol
|
||||
devices 1 changed
|
||||
;
|
||||
|
||||
\ TODO saving
|
||||
|
|
Reference in New Issue