forked from btarg/Xash3D-Emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xash-test.html~
845 lines (778 loc) · 24.8 KB
/
xash-test.html~
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="MobileOptimized" content="640"/>
<meta name="HandheldFriendly" content="true"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="apple-touch-icon" href="icon.png" />
<link rel="apple-touch-startup-image" href="home.png" />
<meta name="apple-mobile-web-app-title" content="Xash3D">
<meta name="mobile-web-app-capable" content="yes">
<link rel="manifest" href="xash.webmanifest">
<title>Xash3D Emscripten Port</title>
<style>
html {
-webkit-text-size-adjust: 100%;
}
body {
font-family: arial;
margin: 0;
padding: none;
background-color: #555555;
color: #f0b418;
}
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 0px solid #000000; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; background-color: black; }
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
#output {
width: 100%;
max-width: 100%;
min-width: 100%;
height: 200px;
margin: 0 auto;
margin-top: 10px;
border-left: 0px;
border-right: 0px;
border-style: solid;
padding-left: 0px;
padding-right: 0px;
display: block;
background-color: black;
color: white;
font-family: 'Lucida Console', Monaco, monospace;
outline: none;
border-color:#f0B418;
}
</style>
</head>
<body onerror=alert(event); bgcolor=#555555 text=#F0B418 link=#aaa000 vlink=#aaa000>
<div class="emscripten_border">
<canvas style="display:none" class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
</div>
<p><div style=width:100%;height:0px>
<div style="float:left;margin:15px" id="status">Downloading...</div>
<div id="progress1" style=position:relative;z-index:10;display:none;float:right;width:70%;border-color:#F0B418;border-style:solid;border-width:2px;height:20px><div id=progress style=text-align:center;background-color:#F0B418;border-color:#555555;border-style:solid:border-width:3px;width:50%;height:20px></div></div><br>
</div><br></p>
<textarea id="output" rows="8"></textarea><div id="asyncDialog" style="float:left"></div>
<form style="display:none;margin:10px" id=fSettings>Select filesystem for settings and saverestore:<br>
<div id=idbHider style=display:none><input name=a type=radio id=rIndexedDB />IndexedDB (Need exit correctly to save changes)<br></div>
<input name=a type=radio id=rLocalStorage />LocalStorage (Only 5MB availiable, downloads ignored)<br>
<input name=a type=radio id=rNone checked=true />None(in RAM)<br>
Select game data source:<br>
<div id=pkgHider style=display:none><input name=b type=radio id=rPackage checked=true />Emscripten package from server (cached in IndexedDB if availiable)<select id=selectPkg style=display:none></select><br></div>
<div id=zipHider style=display:none><input name=b type=radio id=rZip />ZIP archive from server (slower, but smaller, IndexedDB cache if availiable)<select id=selectZip style=display:none></select><br></div>
<div id=aczHider style=display:none><input name=b type=radio id=rACZip />ZIP archive with offline cache (maybe unstable)<select id=selectACZip style=display:none></select><br></div>
<input name=b type=radio id=rLocalZip />Local ZIP file:<input type=file name=c id=iZipFile /><br>
Command-line arguments: <input name=d type=text id=iArgs /><br>
<input type=button onclick="startXash();return false;" value="Launch Xash3D" />
<input type=button onclick="savePageArgs();saveHash();return false;" value="Update link" />
<div id='linksPlaceholder' style=display:none>Download archives to load locally next time:</div>
</form>
<div style=width:100%><span id='controls' style='display:none;'>
<span><input type="button" value="Fullscreen" onclick="Module.requestFullscreen(true, false)"></span>
</span></div>
<script type='text/javascript' src='browserfs.min.js'></script>
<script type='text/javascript'>
var zipMods = [];
var pkgMods = [];
var aczMods = [];
</script>
<script type='text/javascript' src='mods.js'></script>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var asyncDialog = document.getElementById('asyncDialog');
var myerrorbuf = ''
var myerrordate = new Date();
var mounted = false;
var gamedir = 'valve';
var moduleCount = 0;
var mem = 30;
var mfs;
var libprefix = '';
var zipSize;
var idb = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
// make BrowserFS to work on ES5 browsers
if (!ArrayBuffer['isView']) {
ArrayBuffer.isView = function(a) {
return a !== null && typeof(a) === "object" && a['buffer'] instanceof ArrayBuffer;
};
}
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
function prepareSelects()
{
var len = zipMods.length;
var select = document.getElementById('selectZip');
if( len )
{
showElement('zipHider', true);
if(len > 1)
{
var links = '';
for(var i = 0; i < len; i++)
{
select.options[i] = new Option(zipMods[i][1], zipMods[i][0]);
links += '<br><a href="'+zipMods[i][0]+'">'+zipMods[i][1]+'</a>';
}
select.style.display = 'block';
document.getElementById('linksPlaceholder').innerHTML += links;
showElement('linksPlaceholder', true);
}
}
else
document.getElementById('rZip').checked = false;
len = aczMods.length;
select = document.getElementById('selectACZip');
if( len )
{
showElement('aczHider', true);
if(len > 1)
{
for(var i = 0; i < len; i++)
{
select.options[i] = new Option(aczMods[i][1], aczMods[i][0]);
}
select.style.display = 'block';
}
}
else
document.getElementById('rACZip').checked = false;
len = pkgMods.length;
select = document.getElementById('selectPkg');
if( len )
{
showElement('pkgHider', true);
if(len > 1)
{
for(var i = 0; i < len; i++)
select.options[i] = new Option(pkgMods[i][1], pkgMods[i][0]);
select.style.display = 'block';
}
}
else
document.getElementById('rPackage').checked = false;
loadHash();
if( !zipMods.length && !len )
{
document.getElementById('rLocalZip').checked = true;
showElement('rLocalZip', false);
}
}
function loadHash()
{
try
{
pageargs = parseHashBangArgs(document.location.hash);
}
catch(e){}
switch(pageargs.src)
{
case 'zip':
document.getElementById('rZip').checked = true;
break;
case 'ac':
document.getElementById('rACZip').checked = true;
break;
case 'pkg':
document.getElementById('rPackage').checked = true;
break;
case 'local':
document.getElementById('rLocalZip').checked = true;
break;
}
switch(pageargs.fs)
{
case 'idb':
document.getElementById('rIndexedDB').checked = true;
break;
case 'ls':
document.getElementById('rLocalStorage').checked = true;
break;
case 'none':
document.getElementById('rNone').checked = true;
break;
}
if( pageargs.pkg )
for(var i = 0; i < pkgMods.length;i++)
if( pkgMods[i][0] == pageargs.pkg )
document.getElementById('selectPkg').selectedIndex = i;
if( pageargs.zip )
for(var i = 0; i < zipMods.length;i++)
if( zipMods[i][0] == pageargs.zip )
document.getElementById('selectZip').selectedIndex = i;
if( pageargs.ac )
for(var i = 0; i < aczMods.length;i++)
if( aczMods[i][0] == pageargs.ac )
document.getElementById('selectACZip').selectedIndex = i;
if( pageargs.cmd )
{
var args = pageargs.cmd.split(',');
var str = args[0];
for(var i = 1; i < args.length; i++)
str = str + ' ' + args[i];
document.getElementById('iArgs').value = str;
}
}
function parseHashBangArgs(aURL) {
aURL = aURL || window.location.href;
var vars = {};
var hashes = aURL.slice(aURL.indexOf('#') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
var hash = hashes[i].split('=');
if(hash.length > 1) {
vars[hash[0]] = hash[1];
} else {
vars[hash[0]] = null;
}
}
return vars;
}
var pageargs = [];
try
{
pageargs = parseHashBangArgs();
if ("onhashchange" in window)
window.onhashchange = loadHash;
if( pageargs.mem ) mem = parseInt(pageargs.mem);
}
catch(e){};
var Module = {
TOTAL_MEMORY: mem * 1024 * 1024,
preRun: [],
postRun: [],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&");
//text = text.replace(/</g, "<");
//text = text.replace(/>/g, ">");
//text = text.replace('\n', '<br>', 'g');
//console.log(text);
if(text)
myerrorbuf += text + '\n';
if (element) {
if(element.value.length > 65536)
element.value = element.value.substring(512) + myerrorbuf;
else
element.value += myerrorbuf;
element.scrollTop = element.scrollHeight; // focus on bottom
}
myerrorbuf = ''
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
if (0) { // XXX disabled for safety typeof dump == 'function') {
dump(text + '\n'); // fast, straight to the real console
} else {
if( myerrorbuf.length > 2048 )
myerrorbuf = 'some lines skipped\n'+ myerrorbuf.substring(512);
myerrorbuf += text + '\n';
if( new Date() - myerrordate > 3000 )
{
myerrordate = new Date();
Module.print();
}
}
},
canvas: (function() {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;
if( new Date() - myerrordate > 3000 )
{
myerrordate = new Date();
Module.print();
}
statusElement.innerHTML = text;
if( progressElement )
{
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
if(m)
{
var progress = Math.round(parseInt(m[2])*100/parseInt(m[4]));
progressElement.style.color = progress > 5?'#303030':'#aaa000';
progressElement.style.width = progressElement.innerHTML = ''+progress+'%';
}
showElement('progress1', !!m);
}
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
if(left)
Module.setStatus('Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')');
}
};
window.onerror = function(event) {
if(mounted)
FS.syncfs(false, function(err){Module.print('Saving IDBFS: '+err);});
if( (''+event).indexOf('SimulateInfiniteLoop') > 0 )
return;
var text = 'Exception thrown: ' + event;
text = text.replace(/&/g, "&");
text = text.replace(/</g, "<");
text = text.replace(/>/g, ">");
text = text.replace('\n', '<br>', 'g');
Module.setStatus(text);
Module.print('Exception thrown: ' + event);
};
function haltRun()
{
}
var savedRun;
function radioChecked(id)
{
var r = document.getElementById('r'+id);
if(r) return r.checked;
return false;
}
function showElement(id, show)
{
var e = document.getElementById(id);
if(!e) return;
e.style.display=show?'block':'none';
}
Module.setStatus('Downloading...');
function savePageArgs()
{
var val = document.getElementById('iArgs').value || ' ';
var base_args = val.split(' ');
pageargs.cmd = ''+base_args;
if( radioChecked('Package') )
pageargs.src = 'pkg';
else if( radioChecked('Zip') )
pageargs.src = 'zip';
else if( radioChecked('ACZip') )
pageargs.src = 'ac';
else if( radioChecked('LocalZip') )
pageargs.src = 'local';
if( radioChecked( 'IndexedDB' ) )
pageargs.fs = 'idb';
else if( radioChecked( 'LocalStorage' ) )
pageargs.fs = 'ls';
else if( radioChecked( 'None' ) )
pageargs.fs = 'none';
try
{
pageargs.zip = zipMods.length>1?document.getElementById('selectZip').value:zipMods[0][0];
pageargs.pkg = pkgMods.length>1?document.getElementById('selectPkg').value:pkgMods[0][0];
pageargs.ac = aczMods.length>1?document.getElementById('selectACZip').value:aczMods[0][0];
}
catch(e){}
}
function saveHash()
{
var str = '';
for(arg in pageargs)
if( pageargs[arg] )
str += arg + '=' + pageargs[arg]+'&';
str=str.substring(0,str.length-1);
document.location.hash=str;
}
function offlineCacheFallback()
{
if( !pageargs.autostart )
{
alert('Failed to use offline cache. Use ZIP mode or check browser limits');
}
else
{
alert('Failed to use offline cache. Will use uncached mode');
pageargs.src ='zip';
saveHash();
document.location.reload();
}
}
function isTouchDevice() {
var prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
var mq = function(query) {
return window.matchMedia(query).matches;
}
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
return true;
}
var query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join('');
return mq(query);
}
function startXash()
{
showElement('fSettings', false);
showElement('controls',true);
window.scrollTo(0, 0);
savePageArgs();
saveHash();
setupFS();
var base_args = [];
if( pageargs.cmd )
base_args = pageargs.cmd.split(',');
if( pageargs.touchdetect && isTouchDevice() )
base_args = base_args.concat(['+touch_enable','1','+m_ignore','1']);
if( pageargs.calcres )
{
// try calculate dpi-avare resolution
var scrWidth = window.screen.availWidth;
var scrHeight = window.screen.availHeight;
var docWidth = document.body.clientWidth;
var scale = docWidth / scrWidth;
if( scale && pageargs.calcres == 2 )
scrHeight *= scale, scrWidth *= scale;
if( scrHeight > scrWidth ) // screen will be rotated
{
var tmp = scrHeight;
scrHeight = scrWidth;
scrWidth = tmp;
}
Module.print('Detected screen resolution: '+scrWidth+'x'+scrHeight);
base_args = base_args.concat(['-width', ''+(Math.round(scrWidth)),'-height',''+(Math.round(scrHeight))]);
}
Module.arguments = ['xash'].concat(base_args);
Module.run = run = savedRun;
if( pageargs.src == 'zip' )
loadZIP(pageargs.zip);
else if( pageargs.src == 'ac' )
{
var el = document.createElement('iframe');
el.src = pageargs.ac;
el.style.display = 'none';
document.body.appendChild(el);
}
else if( (!zipMods.length && !pkgMods.length) || pageargs.src == 'local' )
{
var el = document.getElementById('iZipFile');
if( !el.files[0] )
el.click();
var reader = new FileReader();
reader.onload = function(){
mountZIP(reader.result);
Module.print("Loaded zip data");
savedRun();
};
reader.readAsArrayBuffer(el.files[0]);
}
else if( pageargs.src == 'pkg' )
{
var script = document.createElement('script');
script.onload = savedRun;
document.body.appendChild(script);
script.src = pkgMods.length>1?document.getElementById('selectPkg').value:pkgMods[0][0];
}
showElement('canvas', true);
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = 'Leave the game?';
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});
}
function mountZIP(data)
{
var Buffer = BrowserFS.BFSRequire('buffer').Buffer;
var buf;
// workaround for bug when passing buffer from frame
try
{
buf = Buffer.from(data);
}
catch( e )
{
// try construct without new, it is faster
try
{
buf = Buffer.from(Uint8Array(data));
}
catch( e )
{
// new required in some firefox versions
buf = Buffer.from(new Uint8Array(data));
}
}
mfs.mount('/zip', new BrowserFS.FileSystem.ZipFS(buf));
FS.mount(new BrowserFS.EmscriptenFS(), {root:'/zip'}, '/rodir');
}
function loadZIP(packageName)
{
try
{
var req = idb.open(packageName, 1);
req.onsuccess = function(event)
{
try
{
var db = event.target.result;
var transaction = db.transaction(['data'], 'readonly');
var package = transaction.objectStore('data');
var get = package.get('data');
get.onsuccess = function(event)
{
event.target.result
try
{
mountZIP(event.target.result)
savedRun();
}
catch(e)
{
Module.print(e); fetchZIP(packageName, savedRun);
}
}
req.onerror = function(event)
{
Module.print(e); fetchZIP(packageName, savedRun);
}
}
catch(e)
{
Module.print(e); fetchZIP(packageName, savedRun);
}
}
req.onerror = function(event)
{
Module.print(event); fetchZIP(packageName, savedRun)
}
req.onupgradeneeded = function(event)
{
var db = event.target.result;
db.createObjectStore('data');
}
}
catch( e )
{
fetchZIP(packageName, savedRun)
Module.print(e);
}
}
function saveZIP(packageName, data)
{
function zipErr(e)
{
Module.print('Error saving idb cache: ' +e);
mountZIP(data);
savedRun();
}
try
{
var req = idb.open(packageName, 1);
req.onsuccess = function(event)
{
try
{
var db = event.target.result;
var transaction = db.transaction(['data'], 'readwrite');
var package = transaction.objectStore('data');
var get = package.put(data, 'data');
get.onsuccess = function(event) {
Module.print('save success');
mountZIP(data);
savedRun();
}
get.onerror = zipErr;
}
catch(e)
{
zipErr(e);
}
}
req.onupgradeneeded = function(event)
{
var db = event.target.result;
db.createObjectStore('data');
}
req.onerror = zipErr;
}
catch( e )
{
zipErr(e);
}
}
function fetchZIP(packageName, cb)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', packageName, true);
xhr.responseType = 'arraybuffer';
xhr.onprogress = function(event) {
var url = packageName;
var size;
if (event.total) size = event.total;
else size = zipMods[document.getElementById('selectZip').selectedIndex][2];
if (event.loaded) {
var total = size;
var loaded = event.loaded;
var num = 0;
if (Module['setStatus']) Module['setStatus']('Downloading data... (' + loaded + '/' + total + ')');
} else if (!Module.dataFileDownloads) {
if (Module['setStatus']) Module['setStatus']('Downloading data...');
}
};
xhr.onerror = function(event) {
throw new Error("NetworkError");
}
xhr.onload = function(event) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
saveZIP(packageName, xhr.response);
} else {
throw new Error(xhr.statusText + " : " + xhr.responseURL);
}
};
xhr.send(null);
}
function setupFS()
{
FS.mkdir('/rodir');
FS.mkdir('/xash');
try
{
mfs = new BrowserFS.FileSystem.MountableFileSystem();
BrowserFS.initialize(mfs);
}
catch(e)
{
mfs = undefined;
Module.print('Failed to initialize BrowserFS: '+e);
}
if( pageargs.fs == 'idb' )
{
FS.mount(IDBFS,{},'/xash');
FS.syncfs(true,function(err){if(err)Module.print('Loading IDBFS: ' + err);});
mounted = true;
}
if( pageargs.fs == 'ls' && mfs)
{
mfs.mount('/ls', new BrowserFS.FileSystem.LocalStorage());
FS.mount(new BrowserFS.EmscriptenFS(), {root:'/ls'}, '/xash');
// LocalStorage is not suitable for downloads
// only allow to keep saverestore and configs here
try
{
FS.mkdir('/xash/valve');
FS.mkdir('/xash/valve/downloaded');
}
catch(e){}
try
{
FS.mount(MEMFS,{}, '/xash/valve/downloaded');
}
catch(e)
{
Module.print(e);
}
Module.print('LocalStorage mounted');
}
FS.chdir('/xash/');
}
function skipRun()
{
savedRun = run;
Module.run = haltRun;
run = haltRun;
Module.setStatus("Engine downloaded!");
if(idb)
showElement('idbHider', true);
prepareSelects();
if( !pageargs.autostart || pageargs.src == 'local' )
showElement('fSettings',true);
ENV.XASH3D_GAMEDIR = gamedir;
ENV.XASH3D_RODIR = '/rodir'
function loadModule(name)
{
var script = document.createElement('script');
script.onload = function() {
moduleCount++;
if(moduleCount==3) {
Module.setStatus("Libraries downloaded!");
if( pageargs.autostart == '1' )
startXash();
}
};
document.body.appendChild(script);
script.src = libprefix + name + ".js";
}
loadModule("server");
loadModule("client");
loadModule("menu");
};
Module.preInit = [skipRun];
Module.websocket = [];
Module.websocket.url = 'wsproxy://mittorn.fwgs.ru:3000/'
ENV = [];
var appCache = window.applicationCache;
if( appCache )
{
var initState = appCache.status;
Module.print("appCache status: "+ appCache.status);
appCache.addEventListener('cached', function(e) {Module.print('Appcache cached, status:' + appCache.status)}, false);
appCache.addEventListener('downloading', function(e) {Module.print('Appcache downloading, status:' + appCache.status)}, false);
appCache.addEventListener('progress', function(e) {Module.print('Appcache progress, status:' + appCache.status); if(initState != 0 && appCache.status == 0) Module.print("appCache error detected");}, false);
appCache.addEventListener('updateready', function(e) {
Module.print('Appcache updateready, status:' + appCache.status);
try{appCache.swapCache();}catch(e){}
}, false);
appCache.addEventListener('error', function(e) {Module.print('Appcache error: '+e+', status:' + appCache.status)}, false);
appCache.addEventListener('checking', function(e) {Module.print('Appcache checking, status:' + appCache.status)}, false);
}
else
Module.print("appCache not supported!");
</script>
<script>
(function() {
var memoryInitializer = 'xash.html.mem';
if (typeof Module['locateFile'] === 'function') {
memoryInitializer = Module['locateFile'](memoryInitializer);
} else if (Module['memoryInitializerPrefixURL']) {
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
}
var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
xhr.open('GET', memoryInitializer, true);
xhr.responseType = 'arraybuffer';
xhr.send(null);
})();
var script = document.createElement('script');
script.src = "xash.js";
document.body.appendChild(script);
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-68666752-4', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>