-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdebug_class.js
75 lines (64 loc) · 1.8 KB
/
debug_class.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class DebugClass {
constructor() {
this.frameCounter = new FrameCounter();
this.debugInfoVisible = true;
this.debugGraphicsVisible = false;
this.debugLowQualityMap = true;
this.black = false;
}
frame() {
this.frameCounter.frame();
}
drawDebugInfo(drawingContext) {
if (!this.debugInfoVisible) {
return;
}
var debugTexts = [];
//
debugTexts.push("FPS: " + this.frameCounter.getFps());
debugTexts.push("Latency: " + systemClass.networkClass.getLatency() + "ms");
//
debugTexts.push("[F2]: Debug Graphics: " + this.debugGraphicsVisible);
//
debugTexts.push(
"[F3]: Character Lock Mode: " + systemClass.pointerLockMode
);
//
debugTexts.push("[F4]: Muted: " + systemClass.soundClass.muted);
//
debugTexts.push("[F6]: Low Quality Map: " + this.debugLowQualityMap);
//
debugTexts.push(
"[F9]: imageSmoothingEnabled: " +
systemClass.graphicsClass.drawingContext.imageSmoothingEnabled
);
const fontHeightPixel = 12;
drawingContext.font = "normal " + fontHeightPixel + "px Arial";
drawingContext.textBaseline = "top";
drawingContext.textAlign = "left";
drawingContext.fillStyle = "white";
for (let i = 0; i < debugTexts.length; i++) {
drawingContext.fillText(debugTexts[i], 3, 3 + 12 * i);
}
}
}
class FrameCounter {
constructor() {
this.fps = 0;
this.count = 0;
this.startTimestamp = performance.now();
}
getFps() {
return this.fps;
}
frame() {
this.count++;
var now = performance.now();
if (now - this.startTimestamp >= 1000) {
this.fps = this.count;
this.count = 0;
this.startTimestamp = now;
}
}
}
let debugClass = new DebugClass();