~yujiri/spacestation-defense

34a7f879fbc1f89c38ff06331b9407ed7560466a — Evin Yulo 5 months ago 72f445a master
get wasm build working again
4 files changed, 8 insertions(+), 22 deletions(-)

M client/binding.js
M client/index.html
M client/main_desktop.zig
M client/main_web.zig
M client/binding.js => client/binding.js +1 -1
@@ 3,7 3,7 @@ mergeInto(LibraryManager.library, {
        return (new Date()).getTime();
    },
    websocketSend: function websocketSend(ptr, len) {
        const bytes = new Uint8Array(Module.asm.memory.buffer, ptr, len);
        const bytes = new Uint8Array(wasmExports.memory.buffer, ptr, len);
        websocket.send(bytes);
    },
});

M client/index.html => client/index.html +4 -4
@@ 7,20 7,20 @@
		<canvas oncontextmenu="return false;"></canvas>
	</body>
	<script>
		websocket = new WebSocket("wss://spacestation-defense.com:9002");
		websocket = new WebSocket("wss://ssd.yujiri.xyz:9002");
		recvPtr = null;
		websocket.onmessage = async e => {
			if (!recvPtr) {
				const array = new Uint8Array(await e.data.arrayBuffer());
				setTimeout(() => {
					recvPtr = Module.asm.init(array[0], array[1], array[2], array[3]);
					recvPtr = wasmExports.init(array[0], array[1], array[2], array[3]);
				}, 2000);
				return;
			}
			const jsArray = new Uint8Array(await e.data.arrayBuffer());
			const wasmArray = new Uint8Array(Module.asm.memory.buffer, recvPtr, jsArray.length);
			const wasmArray = new Uint8Array(wasmExports.memory.buffer, recvPtr, jsArray.length);
			wasmArray.set(jsArray);
			Module.asm.websocketRecv(jsArray.length);
			wasmExports.websocketRecv(jsArray.length);
		};
		Module = {
			canvas: document.querySelector('canvas'),

M client/main_desktop.zig => client/main_desktop.zig +1 -1
@@ 63,7 63,7 @@ fn run() !void {
    // Connect.
    const args = try process.argsAlloc(globals.alloc);
    defer process.argsFree(globals.alloc, args);
    const host = if (args.len > 1) args[1] else "spacestation-defense.com";
    const host = if (args.len > 1) args[1] else "ssd.yujiri.xyz";
    const stream = try net.tcpConnectToHost(globals.alloc, host, 9000);
    const writer = stream.writer();
    try writer.writeAll(&sealed);

M client/main_web.zig => client/main_web.zig +2 -16
@@ 11,20 11,6 @@ const emsdk = @cImport({
const globals = @import("globals.zig");
const main_common = @import("main_common.zig");

pub const std_options = struct {
    pub fn logFn(
        comptime level: std.log.Level,
        comptime scope: @TypeOf(.EnumLiteral),
        comptime format: []const u8,
        args: anytype,
    ) void {
        _ = level;
        _ = scope;
        _ = format;
        _ = args;
    }
};

pub fn panic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn {
    emsdk.emscripten_log(0, msg.ptr);
    emsdk.emscripten_force_exit(1);


@@ 98,10 84,10 @@ const EmscriptenAllocator = struct {
        // Thin wrapper around regular malloc, overallocate to account for
        // alignment padding and store the orignal malloc()'ed pointer before
        // the aligned address.
        var unaligned_ptr: [*]u8 = @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null);
        const unaligned_ptr: [*]u8 = @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null);
        const unaligned_addr = @intFromPtr(unaligned_ptr);
        const aligned_addr = mem.alignForward(unaligned_addr + @sizeOf(usize), alignment);
        var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
        const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
        getHeader(aligned_ptr).* = unaligned_ptr;

        return aligned_ptr;