瀏覽代碼

Minor tweaks to Clock

master
Bryan Miller 5 年之前
父節點
當前提交
a9ba4f14ec
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. +10
    -1
      src/common/clock.js

+ 10
- 1
src/common/clock.js 查看文件

@@ -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…
取消
儲存