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

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


Loading…
Cancel
Save