| get hz(){return Math.floor(1000 / this.__ticktime);} | get hz(){return Math.floor(1000 / this.__ticktime);} | ||||
| set hz(hz){ | set hz(hz){ | ||||
| if(hz >= 1) | |||||
| if(hz >= 1){ | |||||
| this.__ticktime = 1000 / hz; | this.__ticktime = 1000 / hz; | ||||
| this.__dt = 0; | |||||
| this.__ltime = 0; | |||||
| } | |||||
| } | } | ||||
| clk(fn){ | clk(fn){ | ||||
| if (typeof(fn) === 'function') | if (typeof(fn) === 'function') | ||||
| this.__out.push(fn); | this.__out.push(fn); | ||||
| return this; | |||||
| } | } | ||||
| tick(){ | tick(){ | ||||
| this.__out.forEach((fn)=>{fn();}); | this.__out.forEach((fn)=>{fn();}); | ||||
| this.__dt -= this.__ticktime | this.__dt -= this.__ticktime | ||||
| } | } | ||||
| } else { | |||||
| // Call all of the callbacks immediately. This is the first | |||||
| // legit tick! | |||||
| this.__out.forEach((fn)=>{fn();}); | |||||
| } | } | ||||
| this.__ltime = ctime; | this.__ltime = ctime; | ||||
| return this; | |||||
| } | } | ||||
| } | } | ||||