-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.js
384 lines (313 loc) · 12.1 KB
/
info.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
var units = ["Mbps", "MB/s", "Kbps", "KB/s"];
var units_definitions = ["Mega bits per second", "Mega Bytes per second", "Kilo bits per second", "Kilo Bytes per second"];
var server_settings = {
sv_maxrate: 0,
sv_maxupdaterate: 66,
sv_maxcmdrate: 66,
sv_minrate: 3500,
sv_minupdaterate: 10,
sv_mincmdrate: 10,
sv_client_cmdrate_difference: 20
}
var client_settings = {
player_fps: 60,
rate: 30000,
cl_updaterate: 20,
cl_cmdrate: 30,
cl_interp: 0.1,
cl_interp_ratio: 2.0
}
var client_real_settings = {
rate: 30000,
updaterate: 20,
cmdrate: 30,
interp: 0.1,
cl_interp_ratio: 2.0
}
function PageOnLoad()
{
UpdateUpload();
document.getElementById("player_fps").value = client_settings.player_fps;
SetDefaultServerSettings();
SetDefaultClientSettings();
CheckServerTickrate();
UpdateResults();
document.getElementById("loading_text").style.display="none";
}
function SetDefaultClientSettingsButton()
{
SetDefaultClientSettings();
ClientSettingsChange();
}
function CheckServerTickrate()
{
var tickrate = parseInt(document.getElementById("tickrate").value);
if(tickrate <= 10.0)
{
tickrate = 11;
}
else if(tickrate > 128)
{
tickrate = 128;
}
document.getElementById("tickrate").value = tickrate;
document.getElementById("server_fps").value = tickrate;
ClientSettingsChange();
}
function SetDefaultServerSettings()
{
document.getElementById("sv_maxrate").value = server_settings.sv_maxrate;
document.getElementById("sv_maxupdaterate").value = server_settings.sv_maxupdaterate;
document.getElementById("sv_maxcmdrate").value = server_settings.sv_maxcmdrate;
document.getElementById("sv_minrate").value = server_settings.sv_minrate;
document.getElementById("sv_minupdaterate").value = server_settings.sv_minupdaterate;
document.getElementById("sv_mincmdrate").value = server_settings.sv_mincmdrate;
document.getElementById("sv_client_cmdrate_difference").value = server_settings.sv_client_cmdrate_difference;
}
function SetDefaultClientSettings()
{
document.getElementById("rate").value = client_settings.rate;
document.getElementById("cl_updaterate").value = client_settings.cl_updaterate;
document.getElementById("cl_cmdrate").value = client_settings.cl_cmdrate;
document.getElementById("cl_interp").value = parseFloat(client_settings.cl_interp).toFixed(1);
document.getElementById("cl_interp_ratio").value = parseFloat(client_settings.cl_interp_ratio).toFixed(1);
}
function ClientSettingsChange()
{
// pick client settings
var rate = parseInt(document.getElementById("rate").value) || 0;
var cl_updaterate = parseInt(document.getElementById("cl_updaterate").value) || 0;
var cl_cmdrate = parseInt(document.getElementById("cl_cmdrate").value) || 0;
var cl_interp = parseFloat(document.getElementById("cl_interp").value) || 0.0;
var cl_interp_ratio = parseFloat(document.getElementById("cl_interp_ratio").value) || 0.0;
if(cl_interp < 0.0 || cl_interp > 0.5)
{
cl_interp = cl_interp < 0.0 ? 0.0 : 0.5;
document.getElementById("cl_interp").value = cl_interp.toFixed(2);
}
//sv_client_min_interp_ratio 1;sv_client_max_interp_ratio 5
if(cl_interp_ratio < 1.0 || cl_interp_ratio > 5.0)
{
cl_interp_ratio = cl_interp_ratio < 1.0 ? 1.0 : 5.0;
document.getElementById("cl_interp_ratio").value = cl_interp_ratio.toFixed(2);
}
client_real_settings.cl_interp_ratio = cl_interp_ratio;
// pick server settings
var sv_maxrate = parseInt(document.getElementById("sv_maxrate").value) || 0;
var sv_maxupdaterate = parseInt(document.getElementById("sv_maxupdaterate").value) || 0;
var sv_maxcmdrate = parseInt(document.getElementById("sv_maxcmdrate").value) || 0;
var sv_minrate = parseInt(document.getElementById("sv_minrate").value) || 0;
var sv_minupdaterate = parseInt(document.getElementById("sv_minupdaterate").value) || 0;
var sv_mincmdrate = parseInt(document.getElementById("sv_mincmdrate").value) || 0;
var sv_client_cmdrate_difference = parseInt(document.getElementById("sv_client_cmdrate_difference").value) || 0;
var updaterate = cl_updaterate;
var cmdrate = cl_cmdrate;
// restrictions
// wierd magic trick under rate 1000
if(sv_maxrate > 0 && rate < 1000)
{
rate = Math.min(Math.max(sv_maxrate, sv_minrate), 1000);
}
else if(sv_maxrate > 0 && rate > sv_maxrate)
{
rate = sv_maxrate;
}
// min. rate make last rectriction
if(rate < sv_minrate)
{
rate = sv_minrate;
}
// max. updaterate make last restriction
if(updaterate < sv_minupdaterate)
{
updaterate = sv_minupdaterate;
}
if(updaterate > sv_maxupdaterate)
{
updaterate = sv_maxupdaterate;
}
// server low FPS restrict updaterate
var server_fps = parseInt(document.getElementById("server_fps").value) || 0;
if(updaterate > server_fps)
{
updaterate = server_fps;
}
var fps_min = parseInt(document.getElementById("server_fps").min) || 0;
if(updaterate < fps_min) // ...pls!
{
updaterate = fps_min;
document.getElementById("server_fps").value = fps_min;
}
// max. cmrate make last restriction
if(sv_mincmdrate > 0)
{
if(cmdrate > updaterate + sv_client_cmdrate_difference)
{
cmdrate = updaterate + sv_client_cmdrate_difference;
}
else if(cmdrate < updaterate - sv_client_cmdrate_difference)
{
cmdrate = updaterate - sv_client_cmdrate_difference;
}
if(cmdrate < sv_mincmdrate)
{
cmdrate = sv_mincmdrate;
}
if(cmdrate > sv_maxcmdrate)
{
cmdrate = sv_maxcmdrate;
}
}
// client low FPS restrict cmdrate
var player_fps = parseInt(document.getElementById("player_fps").value) || 0;
if(cmdrate > player_fps)
{
cmdrate = player_fps;
}
fps_min = parseInt(document.getElementById("player_fps").min) || 0;
if(cmdrate < fps_min) // ...pls!
{
cmdrate = fps_min;
document.getElementById("player_fps").value = fps_min;
}
// low tickrate
var tickrate = parseInt(document.getElementById("tickrate").value) || 0;
if(cmdrate > tickrate)
{
cmdrate = tickrate;
}
if(updaterate > tickrate)
{
updaterate = tickrate;
}
client_real_settings.rate = rate;
client_real_settings.updaterate = updaterate;
client_real_settings.cmdrate = cmdrate;
// interpolation
// 0.1 s = 2 x ( 1.0f / cl_updaterate default of 20 ) )
client_real_settings.interp = Math.max( cl_interp, cl_interp_ratio / parseFloat(cl_updaterate) );
client_real_settings.interp = Math.max( client_real_settings.interp, 1.0 / parseFloat(cl_updaterate) );
UpdateNetGraph();
}
function UpdateNetGraph()
{
//document.getElementById("server_fps").value = document.getElementById("tickrate").value;
document.getElementById("cl_updaterate_show").value = document.getElementById("cl_updaterate").value;
document.getElementById("cl_cmdrate_show").value = document.getElementById("cl_cmdrate").value;
document.getElementById("updaterate").value = client_real_settings.updaterate;
document.getElementById("cmdrate").value = client_real_settings.cmdrate;
document.getElementById("lerp").innerHTML = (client_real_settings.interp*1000.0).toFixed(1);
document.getElementById("kilobytes").value = (client_real_settings.rate/1000).toFixed(2);
document.getElementById("packetsize").value = parseInt(client_real_settings.rate/client_real_settings.updaterate);
document.getElementById("lerp_screen").style.color = "white";
// lerp colors
if(client_real_settings.cl_interp_ratio / parseFloat(document.getElementById("cl_updaterate").value) < 2.0 / parseFloat(document.getElementById("cl_updaterate").value))
{
document.getElementById("lerp_screen").style.color = "orange";
}
if(1.0 / parseFloat(document.getElementById("server_fps").value) > client_real_settings.interp )
{
document.getElementById("lerp_screen").style.color = "yellow";
}
document.getElementById("lerp_screen").title = "Ideal\ncl_interp_ratio 2.0; cl_interp "+ (2.0 / parseFloat(client_real_settings.updaterate)).toFixed(4);
RecommendedSettings();
}
function PacketSizeChange()
{
var packetsize = parseInt(document.getElementById("packetsize").value);
if(packetsize < 1)
{
document.getElementById("packetsize").value = 1;
packetsize = 1;
}
else if(packetsize > 9999)
{
document.getElementById("packetsize").value = 9999;
packetsize = 9999;
}
//document.getElementById("rate").value = packetsize * document.getElementById("cl_updaterate").value;
document.getElementById("rate").value = packetsize * client_real_settings.updaterate;
ClientSettingsChange();
}
function RecommendedSettings()
{
document.getElementById("output_sv_maxrate").innerHTML = '\"'+0+'\"';
document.getElementById("output_sv_maxupdaterate").innerHTML = '\"'+client_real_settings.updaterate +'\"';
document.getElementById("output_sv_maxcmdrate").innerHTML = '\"'+client_real_settings.cmdrate+'\"';
document.getElementById("output_sv_minrate").innerHTML = '\"'+client_real_settings.rate+'\"';
document.getElementById("output_sv_minupdaterate").innerHTML = '\"'+20+'\"';
document.getElementById("output_sv_mincmdrate").innerHTML = '\"'+30+'\"';
document.getElementById("output_sv_client_cmdrate_difference").innerHTML = '\"'+20+'\"';
UpdateResults();
}
function ImgOn() {
document.getElementById("popup").style.display = "block";
}
function ImgOff() {
document.getElementById("popup").style.display = "none";
}
function UpdateUpload()
{
var index;
var text;
for (index = 0; index < units.length; index++) {
text += "<option>" + units[index] + "</option>";
}
document.getElementById("input_unit").innerHTML = text;
document.getElementById("output_unit_definition").innerHTML = units_definitions[0];
}
function UpdateUnitDefinition(element)
{
document.getElementById("output_unit_definition").innerHTML = units_definitions[element.selectedIndex];
UpdateResults();
}
function UpdateResults()
{
var unit_index = document.getElementById("input_unit").selectedIndex;
var elemt_upload = document.getElementById("upload");
var maxplayers = parseInt(document.getElementById("maxplayers").value) || 0;
var upload_recommended = client_real_settings.rate * maxplayers;
var upload_recommended_title;
var maxplayers_recommended = parseFloat(elemt_upload.value) || 0.0;
var upload_title = maxplayers_recommended;
switch (unit_index) {
case 0: // Mega bits per second
upload_recommended /= 1000000.0;
upload_recommended_title = "equally\n"+(upload_recommended).toFixed(2)+" MB/s\n"+(upload_recommended*1000).toFixed(0)+" KB/s";
upload_recommended *= 8.0;
maxplayers_recommended *= 1000000.0 / 8.0; // Upload Mbps to B/s
upload_title = "equally\n"+(upload_title / 8.0).toFixed(2)+" MB/s\n"+((upload_title / 8.0)*1000.0).toFixed(0)+" KB/s";
break;
case 1: // Mega Bytes per second
upload_recommended /= 1000000.0;
upload_recommended_title = "equally\n"+(upload_recommended*8.0).toFixed(2)+" Mbps\n"+(upload_recommended*8.0*1000.0).toFixed(0)+" Kbps";
maxplayers_recommended *= 1000000.0; // Upload MB/s to B/s
upload_title = "equally\n"+(upload_title * 8.0).toFixed(2)+" Mbps\n"+((upload_title * 8.0)*1000).toFixed(0)+" Kbps";
break;
case 2: // Kilo bits per second
upload_recommended /= 1000.0;
upload_recommended_title = "equally\n"+(upload_recommended).toFixed(0)+" KB/s\n"+(upload_recommended/1000.0).toFixed(2)+" MB/s";
upload_recommended *= 8.0;
maxplayers_recommended *= 1000.0 / 8.0; // Upload Kbps to B/s
upload_title = "equally\n"+(upload_title / 8.0).toFixed(0)+" KB/s\n"+((upload_title / 8.0)/1000).toFixed(2)+" MB/s";
break;
case 3: // Kilo Bytes per second
upload_recommended /= 1000.0;
upload_recommended_title = "equally\n"+(upload_recommended*8.0).toFixed(0)+" Kbps\n"+(upload_recommended*8.0/1000.0).toFixed(2)+" Mbps";
maxplayers_recommended *= 1000.0; // Upload KB/s to B/s
upload_title = "equally\n"+(upload_title * 8.0).toFixed(0)+" Kbps\n"+((upload_title * 8.0)/1000).toFixed(2)+" Mbps";
break;
}
elemt_upload.title = upload_title;
upload_recommended = upload_recommended.toFixed(2)+" "+units[unit_index];
maxplayers_recommended /= client_real_settings.rate; // Divide upload with rate
document.getElementById("output_maxplayers").innerHTML = maxplayers;
document.getElementById("output_upload_recommended").innerHTML = upload_recommended;
document.getElementById("output_upload_recommended").title = upload_recommended_title;
document.getElementById("output_maxplayers_recommended").innerHTML = parseFloat(maxplayers_recommended).toFixed(0);
}
function functiontest()
{
ClientSettingsChange();
}