Fantasy 8Bit system (F8), is a fantasy 8bit console and a set of libraries for creating fantasy 8bit consoles.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
-
- class Clock{
- constructor(){
- this.__ticktime = 1000;
- this.__dt = 0;
- this.__ltime = 0;
- this.__out = [];
- }
-
- get hz(){return Math.floor(1000 / this.__ticktime);}
- set hz(hz){
- if(hz >= 1)
- this.__ticktime = 1000 / hz;
- }
-
- clk(fn){
- if (typeof(fn) === 'function')
- this.__out.push(fn);
- }
-
- tick(){
- let ctime = (new Date()).getTime();
- if(this.__ltime !== 0){
- this.__dt += ctime - this.__ltime;
- while(this.__dt > this.__ticktime){
- this.__out.forEach((fn)=>{fn();});
- this.__dt -= this.__ticktime
- }
- }
- this.__ltime = ctime;
- }
- }
-
-
- module.exports = Clock;
|