Skip to content

Commit 1bdb1df

Browse files
committed
Fix websocket issue
1 parent 594e355 commit 1bdb1df

File tree

6 files changed

+76
-37
lines changed

6 files changed

+76
-37
lines changed

public/websockets-doom.wasm

-34.1 KB
Binary file not shown.

public/websockets-doom.wasm.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import GameContextProvider from "./context/GameContextProvider";
88
const queryClient = new QueryClient();
99

1010
export default function App() {
11-
const [isGameStarted, setIsGameStarted] = useState(true);
11+
const [isGameStarted, setIsGameStarted] = useState(false);
1212

1313
return (
1414
<QueryClientProvider client={queryClient}>

src/components/DoomCanvas/DoomCanvas.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import { EmscriptenModule } from "../../types";
33

44
const DoomCanvas: React.FC = () => {
55
const canvasRef = useRef<HTMLCanvasElement>(null);
6+
const isEffectRan = useRef(false);
67

78
useEffect(() => {
9+
// Prevent effect from running twice
10+
if (isEffectRan.current) return;
11+
isEffectRan.current = true;
12+
813
const canvas = canvasRef.current;
914

1015
if (!canvas) {
@@ -42,6 +47,19 @@ const DoomCanvas: React.FC = () => {
4247
setStatus: (text: string) => {
4348
console.log("setStatus:", text);
4449
},
50+
onRuntimeInitialized: function () {
51+
window.callMain([
52+
"-iwad",
53+
"freedoom2.wad",
54+
"-file",
55+
"Cardano.wad",
56+
"-window",
57+
"-nogui",
58+
"-nomusic",
59+
"-config",
60+
"default.cfg",
61+
]);
62+
},
4563
};
4664

4765
// Attach Module to the window object to make it globally accessible

src/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ interface FileSystem {
4242
}
4343

4444
export interface EmscriptenModule {
45+
canvas?: HTMLCanvasElement;
46+
FS?: FileSystem;
4547
noInitialRun?: boolean;
46-
preRun?: () => void;
48+
onRuntimeInitialized?: () => void;
4749
postRun?: () => void;
50+
preRun?: () => void;
4851
print?: (text: string) => void;
4952
printErr?: (text: string) => void;
5053
setStatus?: (text: string) => void;
51-
canvas?: HTMLCanvasElement;
52-
FS?: FileSystem;
5354
}
5455

5556
declare global {
5657
interface Window {
58+
callMain: (args: string[]) => void;
5759
Module: EmscriptenModule;
5860
}
5961
}

websockets-doom.js

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -491,31 +491,31 @@ var tempDouble;
491491
var tempI64;
492492

493493
var ASM_CONSTS = {
494-
448950: $0 => {
494+
449322: $0 => {
495495
var str = UTF8ToString($0) + "\n\n" + "Abort/Retry/Ignore/AlwaysIgnore? [ariA] :";
496496
var reply = window.prompt(str, "i");
497497
if (reply === null) {
498498
reply = "i";
499499
}
500500
return allocate(intArrayFromString(reply), "i8", ALLOC_NORMAL);
501501
},
502-
449175: () => {
502+
449547: () => {
503503
if (typeof (AudioContext) !== "undefined") {
504504
return true;
505505
} else if (typeof (webkitAudioContext) !== "undefined") {
506506
return true;
507507
}
508508
return false;
509509
},
510-
449322: () => {
510+
449694: () => {
511511
if ((typeof (navigator.mediaDevices) !== "undefined") && (typeof (navigator.mediaDevices.getUserMedia) !== "undefined")) {
512512
return true;
513513
} else if (typeof (navigator.webkitGetUserMedia) !== "undefined") {
514514
return true;
515515
}
516516
return false;
517517
},
518-
449556: $0 => {
518+
449928: $0 => {
519519
if (typeof (Module["SDL2"]) === "undefined") {
520520
Module["SDL2"] = {};
521521
}
@@ -537,11 +537,11 @@ var ASM_CONSTS = {
537537
}
538538
return SDL2.audioContext === undefined ? -1 : 0;
539539
},
540-
450049: () => {
540+
450421: () => {
541541
var SDL2 = Module["SDL2"];
542542
return SDL2.audioContext.sampleRate;
543543
},
544-
450117: ($0, $1, $2, $3) => {
544+
450489: ($0, $1, $2, $3) => {
545545
var SDL2 = Module["SDL2"];
546546
var have_microphone = function(stream) {
547547
if (SDL2.capture.silenceTimer !== undefined) {
@@ -582,7 +582,7 @@ var ASM_CONSTS = {
582582
}, have_microphone, no_microphone);
583583
}
584584
},
585-
451769: ($0, $1, $2, $3) => {
585+
452141: ($0, $1, $2, $3) => {
586586
var SDL2 = Module["SDL2"];
587587
SDL2.audio.scriptProcessorNode = SDL2.audioContext["createScriptProcessor"]($1, 0, $0);
588588
SDL2.audio.scriptProcessorNode["onaudioprocess"] = function(e) {
@@ -594,7 +594,7 @@ var ASM_CONSTS = {
594594
};
595595
SDL2.audio.scriptProcessorNode["connect"](SDL2.audioContext["destination"]);
596596
},
597-
452179: ($0, $1) => {
597+
452551: ($0, $1) => {
598598
var SDL2 = Module["SDL2"];
599599
var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels;
600600
for (var c = 0; c < numChannels; ++c) {
@@ -613,7 +613,7 @@ var ASM_CONSTS = {
613613
}
614614
}
615615
},
616-
452784: ($0, $1) => {
616+
453156: ($0, $1) => {
617617
var SDL2 = Module["SDL2"];
618618
var numChannels = SDL2.audio.currentOutputBuffer["numberOfChannels"];
619619
for (var c = 0; c < numChannels; ++c) {
@@ -626,7 +626,7 @@ var ASM_CONSTS = {
626626
}
627627
}
628628
},
629-
453264: $0 => {
629+
453636: $0 => {
630630
var SDL2 = Module["SDL2"];
631631
if ($0) {
632632
if (SDL2.capture.silenceTimer !== undefined) {
@@ -664,7 +664,7 @@ var ASM_CONSTS = {
664664
SDL2.audioContext = undefined;
665665
}
666666
},
667-
454436: ($0, $1, $2) => {
667+
454808: ($0, $1, $2) => {
668668
var w = $0;
669669
var h = $1;
670670
var pixels = $2;
@@ -735,7 +735,7 @@ var ASM_CONSTS = {
735735
}
736736
SDL2.ctx.putImageData(SDL2.image, 0, 0);
737737
},
738-
455905: ($0, $1, $2, $3, $4) => {
738+
456277: ($0, $1, $2, $3, $4) => {
739739
var w = $0;
740740
var h = $1;
741741
var hot_x = $2;
@@ -772,50 +772,69 @@ var ASM_CONSTS = {
772772
stringToUTF8(url, urlBuf, url.length + 1);
773773
return urlBuf;
774774
},
775-
456894: $0 => {
775+
457266: $0 => {
776776
if (Module["canvas"]) {
777777
Module["canvas"].style["cursor"] = UTF8ToString($0);
778778
}
779779
},
780-
456977: () => {
780+
457349: () => {
781781
if (Module["canvas"]) {
782782
Module["canvas"].style["cursor"] = "none";
783783
}
784784
},
785-
457046: () => window.innerWidth,
786-
457076: () => window.innerHeight,
787-
457107: ($0, $1) => {
785+
457418: () => window.innerWidth,
786+
457448: () => window.innerHeight,
787+
457479: ($0, $1) => {
788788
alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
789789
}
790790
};
791791

792-
function __asyncjs__hydra_send(cmd, playerstate, killcount, health, floorz, momx, momy, momz, z, angle, gamestate) {
792+
function __asyncjs__hydra_send(forwardmove, sidemove, angleturn, chatchar, buttons, consistency, buttons2, inventory, lookfly, artyi, player_state, kill_count, secret_count, item_count, cheats, health, x, y, z, gamestate, leveltics, gamemap, gameskill, gameepisode, demoplayback) {
793793
return Asyncify.handleAsync(async () => {
794794
await hydraSend({
795-
forwardMove: SAFE_HEAP_LOAD(cmd, 1, 0),
796-
sideMove: SAFE_HEAP_LOAD(cmd + 1, 1, 0)
795+
forwardMove: forwardmove,
796+
sideMove: sidemove,
797+
angleTurn: angleturn,
798+
chatChar: chatchar,
799+
buttons: buttons,
800+
consistancy: consistency,
801+
buttons2: buttons2,
802+
inventory: inventory,
803+
lookFly: lookfly,
804+
arti: artyi
797805
}, {
798806
mapObject: {
799807
position: {
800-
floorZ: floorz,
801-
momentumX: momx,
802-
momentumY: momy,
803-
momentumZ: momz,
804-
z: z,
805-
angle: angle
808+
x: x,
809+
y: y,
810+
z: z
806811
},
807812
health: health
808813
},
809-
playerState: playerstate,
810-
killCount: killcount
811-
}, gamestate);
814+
playerState: player_state,
815+
totalStats: {
816+
killCount: -1,
817+
secretCount: -1,
818+
itemCount: -1
819+
},
820+
levelStats: {
821+
killCount: kill_count,
822+
secretCount: secret_count,
823+
itemCount: item_count
824+
},
825+
cheats: cheats
826+
}, gamestate, leveltics, {
827+
map: gamemap,
828+
skill: gameskill,
829+
episode: gameepisode,
830+
demoplayback: demoplayback === 1
831+
});
812832
});
813833
}
814834

815835
function __asyncjs__hydra_recv(cmd) {
816836
return Asyncify.handleAsync(async () => {
817837
const res = await hydraRecv();
818-
console.log("hydra_recv", res);
819838
if (res == null) {
820839
return;
821840
}
@@ -8762,9 +8781,9 @@ var _asyncify_start_rewind = a0 => (_asyncify_start_rewind = wasmExports["asynci
87628781

87638782
var _asyncify_stop_rewind = () => (_asyncify_stop_rewind = wasmExports["asyncify_stop_rewind"])();
87648783

8765-
var ___start_em_js = Module["___start_em_js"] = 448256;
8784+
var ___start_em_js = Module["___start_em_js"] = 448096;
87668785

8767-
var ___stop_em_js = Module["___stop_em_js"] = 448950;
8786+
var ___stop_em_js = Module["___stop_em_js"] = 449322;
87688787

87698788
function intArrayFromBase64(s) {
87708789
if (typeof ENVIRONMENT_IS_NODE != "undefined" && ENVIRONMENT_IS_NODE) {

0 commit comments

Comments
 (0)