Pārlūkot izejas kodu

Clock to dictate speed of 'connected devices'.

master
Bryan Miller pirms 5 gadiem
vecāks
revīzija
d669be3206
1 mainītis faili ar 37 papildinājumiem un 0 dzēšanām
  1. +37
    -0
      chip/clock.js

+ 37
- 0
chip/clock.js Parādīt failu


var TickTime = 1000;
var DT = 0;
var LTime = 0;
var CPUCLK = null:

class Clock{
constructor(){}

get hz(){return Math.floor(1000 / TickTime);}
set hz(hz){
if(hz >= 1)
TickTime = 1000 / hz;
}

get wired(){return (CPUCLK !== null);}
set wire(clk){
if(clk == null || typeof clk === 'function')
CPUCLK = clk;
}

tick(){
let ctime = Date.getTime();
if(LTime !== 0){
DT += ctime - LTime;
while(DT > TickTime){
if (CPUCLK)
CPUCLK();
DT -= TickTime
}
}
LTime = ctime;
}
}


module.exports = Clock;

Notiek ielāde…
Atcelt
Saglabāt