mach: wasm: initial implementation of Core, added js polyfill and

application html
This commit is contained in:
iddev5 2022-05-22 12:43:21 +05:30 committed by Stephen Gutekanst
parent ccb1063e3f
commit c8c6dab65b
3 changed files with 145 additions and 5 deletions

View file

@ -4,17 +4,42 @@ const Engine = @import("Engine.zig");
const structs = @import("structs.zig");
const enums = @import("enums.zig");
const js = struct {};
const js = struct {
extern fn machCanvasInit(width: u32, height: u32, selector_id: *u8) CanvasId;
extern fn machCanvasDeinit(canvas: CanvasId) void;
extern fn machCanvasSetTitle(canvas: CanvasId, title: [*]const u8, len: u32) void;
extern fn machCanvasSetSize(canvas: CanvasId, width: u32, height: u32) void;
extern fn machCanvasGetWidth(canvas: CanvasId) u32;
extern fn machCanvasGetHeight(canvas: CanvasId) u32;
};
pub const CanvasId = u32;
pub const CoreWasm = struct {
pub fn init(_: std.mem.Allocator, _: *Engine) !CoreWasm {
return CoreWasm{};
id: CanvasId,
selector_id: []const u8,
pub fn init(allocator: std.mem.Allocator, eng: *Engine) !CoreWasm {
const options = eng.options;
var selector = [1]u8{0} ** 15;
const id = js.machCanvasInit(options.width, options.height, &selector[0]);
const title = std.mem.span(options.title);
js.machCanvasSetTitle(id, title.ptr, title.len);
return CoreWasm{
.id = id,
.selector_id = try allocator.dupe(u8, selector[0 .. selector.len - @as(u32, if (selector[selector.len - 1] == 0) 1 else 0)]),
};
}
pub fn setShouldClose(_: *CoreWasm, _: bool) void {}
pub fn getFramebufferSize(_: *CoreWasm) !structs.Size {
return structs.Size{ .width = 0, .height = 0 };
pub fn getFramebufferSize(core: *CoreWasm) !structs.Size {
return structs.Size{
.width = js.machCanvasGetWidth(core.id),
.height = js.machCanvasGetHeight(core.id),
};
}
pub fn setSizeLimits(_: *CoreWasm, _: structs.SizeOptional, _: structs.SizeOptional) !void {}