Browse Source

Minor tweaks to Clock

master
Bryan Miller 5 years ago
parent
commit
a9ba4f14ec
1 changed files with 10 additions and 1 deletions
  1. +10
    -1
      src/common/clock.js

+ 10
- 1
src/common/clock.js View File



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;
} }
} }



Loading…
Cancel
Save