mach: Added runtime application options
Reused mach.Options for run time options. It is set with Engine.setOptions function. ``pub const options`` on top level App has no effect and will be ignored completely. Added a blank struct StartupOptions which would be used for startup time options in future. Currently they aren't used for anything.
This commit is contained in:
parent
01eee68f5b
commit
ed0e6f5c61
4 changed files with 27 additions and 9 deletions
|
|
@ -235,6 +235,11 @@ pub const Platform = struct {
|
|||
platform.window.setFramebufferSizeCallback(framebuffer_size_callback);
|
||||
}
|
||||
|
||||
pub fn setOptions(platform: *Platform, options: structs.Options) !void {
|
||||
try platform.window.setSize(.{ .width = options.width, .height = options.height });
|
||||
try platform.window.setTitle(options.title);
|
||||
}
|
||||
|
||||
pub fn setShouldClose(platform: *Platform, value: bool) void {
|
||||
platform.window.setShouldClose(value);
|
||||
}
|
||||
|
|
@ -410,8 +415,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const options = if (@hasDecl(App, "options")) App.options else structs.Options{};
|
||||
var engine = try Engine.init(allocator, options);
|
||||
var engine = try Engine.init(allocator);
|
||||
var app: App = undefined;
|
||||
|
||||
try app.init(&engine);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,13 @@ pub const Platform = struct {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn setOptions(platform: *Platform, options: structs.Options) !void {
|
||||
js.machCanvasSetSize(platform.id, options.width, options.height);
|
||||
|
||||
const title = std.mem.span(options.title);
|
||||
js.machCanvasSetTitle(platform.id, title.ptr, title.len);
|
||||
}
|
||||
|
||||
pub fn setShouldClose(_: *Platform, _: bool) void {}
|
||||
|
||||
pub fn getFramebufferSize(platform: *Platform) structs.Size {
|
||||
|
|
@ -116,11 +123,7 @@ export fn wasmInit() void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
// NOTE: On wasm, vsync is double by default and cannot be changed.
|
||||
// Hence options.vsync is not used anywhere.
|
||||
const options = if (@hasDecl(App, "options")) App.options else structs.Options{};
|
||||
engine = Engine.init(allocator, options) catch unreachable;
|
||||
|
||||
engine = Engine.init(allocator) catch unreachable;
|
||||
app.init(&engine) catch {};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue