-
Notifications
You must be signed in to change notification settings - Fork 131
/
stats.js
190 lines (177 loc) · 4.33 KB
/
stats.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* Keeps track of statistics. Initially only a UI, but can also be used "headless" by given a false value for the `active` constructor argument
*/
export class Stats {
constructor(active = true) {
this.active = active;
this.parameters = {};
this.dirty = true;
this.updateRequested = true;
this.statsId = "stats";
this.groups = {
"Tiling": [
"Rendering",
"Empty",
"Full",
"Loading",
"Loaded"
],
"Loading time": [
"Layer 1",
"Layer 2",
"Total"
], "Rendering": [
"FPS"
], "Stats": [
"Updates"
], "Models": [
"Name",
"Models to load",
"Models loaded",
"Objects",
"Geometries",
"Geometries reused",
], "Primitives": [
"Primitives to load (L1)",
"Primitives to load (L2)",
"Nr primitives loaded",
"Nr primitives hidden"
], "Data": [
"GPU bytes",
"GPU bytes reuse",
"GPU bytes total"
], "Drawing": [
"Triangles to draw (L1)",
"Triangles to draw (L2)",
"Draw calls per frame (L1)",
"Draw calls per frame (L2)"
], "Network": [
"Bytes OTL"
], "Buffers": [
"Buffer groups",
], "BufferSet pool": [
"Used",
"Available",
"Total memory"
], "Renderer settings": [
"Object colors",
"Small indices if possible",
"Quantize normals",
"Quantize vertices"
], "Loader settings": [
"Object colors",
"Quantize normals",
"Quantize vertices",
]
};
this.init();
}
init() {
for (var groupName in this.groups) {
var group = this.groups[groupName];
var groupObject = {};
this.parameters[groupName] = groupObject;
for (var key of group) {
groupObject[key] = 0;
}
}
}
get(group, key) {
return this.parameters[group][key];
}
setParameter(group, key, value) {
var group = this.parameters[group];
if (group[key] == value) {
return;
}
group[key] = value;
this.dirty = true;
}
inc(groupName, key, value) {
var group = this.parameters[groupName];
if (group[key] == null) {
group[key] = 0;
}
if (value == null) {
group[key] = group[key] + 1;
} else {
group[key] = group[key] + value;
}
this.dirty = true;
}
dec(groupName, key, value) {
var group = this.parameters[groupName];
if (group[key] == null) {
group[key] = 0;
}
if (value == null) {
group[key] = group[key] - 1;
} else {
group[key] = group[key] - value;
}
this.dirty = true;
}
numberWithCommas(x) {
return Number(x).toLocaleString();
}
requestUpdate() {
this.updateRequested = true;
}
update() {
if (this.active && document.getElementById(this.statsId)) {
if (!this.updateRequested) {
return;
}
this.inc("Stats", "Updates");
this.updates++;
for (var groupName in this.groups) {
var group = this.groups[groupName];
var groupElement = document.getElementById(groupName + "-group");
if (groupElement == null) {
groupElement = document.createElement("div");
groupElement.id = groupName + "-group";
document.getElementById(this.statsId).appendChild(groupElement);
var groupTitle = document.createElement("h3");
groupTitle.innerHTML = groupName;
groupElement.appendChild(groupTitle);
}
for (var key of group) {
var fullKey = groupName + "_" + key;
var value = this.parameters[groupName][key];
var element = document.getElementById(fullKey);
if (element == null) {
element = document.createElement("div");
element.id = fullKey;
groupElement.appendChild(element);
}
var newStringValue = value;
if (value == null) {
newStringValue = key + ": 0";
} else {
if (typeof value == "number") {
newStringValue = key + ": " + this.numberWithCommas(value);
} else {
newStringValue = key + ": " + value;
}
}
if (newStringValue != element.textContent) {
element.textContent = newStringValue;
}
}
}
this.updateRequested = false;
this.dirty = false;
}
}
cleanup() {
this.parameters = {};
this.init();
var stats = document.getElementById(this.statsId);
if (stats != null) {
while (stats.firstChild) {
stats.removeChild(stats.firstChild);
}
this.dirty = true;
}
}
}