-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
40 lines (34 loc) · 761 Bytes
/
clock.js
File metadata and controls
40 lines (34 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const perf_hooks = require('perf_hooks');
exports.FPS = class FPS {
constructor() {
this.get_now = perf_hooks.performance.now.bind(this);
this.delta = 0.0;
this.last_tick = this.get_now();
}
tick() {
const now = this.get_now();
this.delta = (now - this.last_tick) / 1000;
this.last_tick = now;
return this.delta;
}
get_fps() {
return 1 / this.delta;
}
get_fps_int() {
return Math.floor(1 / this.delta);
}
}
exports.IfTimer = class IfTimer {
constructor(timeout) {
this.timeout = timeout;
this.counter = 0.0;
this.triggered = 0;
}
tick(delta) {
this.counter += delta;
while (this.counter > this.timeout) {
this.triggered++;
this.counter -= this.timeout;
}
}
}