| @@ -9,13 +9,17 @@ class Clock{ | |||
| get hz(){return Math.floor(1000 / this.__ticktime);} | |||
| set hz(hz){ | |||
| if(hz >= 1) | |||
| if(hz >= 1){ | |||
| this.__ticktime = 1000 / hz; | |||
| this.__dt = 0; | |||
| this.__ltime = 0; | |||
| } | |||
| } | |||
| clk(fn){ | |||
| if (typeof(fn) === 'function') | |||
| this.__out.push(fn); | |||
| return this; | |||
| } | |||
| tick(){ | |||
| @@ -26,8 +30,13 @@ class Clock{ | |||
| this.__out.forEach((fn)=>{fn();}); | |||
| 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; | |||
| return this; | |||
| } | |||
| } | |||