mach: wasm: Add initial framework bones

This commit is contained in:
iddev5 2022-05-21 23:50:37 +05:30 committed by Stephen Gutekanst
parent 66cc8281e5
commit ccb1063e3f
3 changed files with 78 additions and 1 deletions

52
src/wasm.zig Normal file
View file

@ -0,0 +1,52 @@
const std = @import("std");
const App = @import("app");
const Engine = @import("Engine.zig");
const structs = @import("structs.zig");
const enums = @import("enums.zig");
const js = struct {};
pub const CoreWasm = struct {
pub fn init(_: std.mem.Allocator, _: *Engine) !CoreWasm {
return CoreWasm{};
}
pub fn setShouldClose(_: *CoreWasm, _: bool) void {}
pub fn getFramebufferSize(_: *CoreWasm) !structs.Size {
return structs.Size{ .width = 0, .height = 0 };
}
pub fn setSizeLimits(_: *CoreWasm, _: structs.SizeOptional, _: structs.SizeOptional) !void {}
pub fn pollEvent(_: *CoreWasm) ?structs.Event {
return null;
}
};
pub const GpuDriverWeb = struct {
pub fn init(_: std.mem.Allocator, _: *Engine) !GpuDriverWeb {
return GpuDriverWeb{};
}
};
var app: App = undefined;
var engine: Engine = undefined;
export fn wasmInit() void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const options = if (@hasDecl(App, "options")) App.options else structs.Options{};
engine = Engine.init(allocator, options) catch unreachable;
app.init(&engine) catch {};
}
export fn wasmUpdate() bool {
return app.update(&engine) catch false;
}
export fn wasmDeinit() void {
app.deinit(&engine);
}