mach: App.update will now return !void instead of !bool
In order to close the application, there is already Engine.setShouldClose() which would roughly do the same thing.
This commit is contained in:
parent
3234b6c0dd
commit
40c0659cc9
4 changed files with 6 additions and 9 deletions
|
|
@ -2,5 +2,5 @@ pub fn checkApplication(comptime App: type) void {
|
||||||
// TODO: check signature
|
// TODO: check signature
|
||||||
if (!@hasDecl(App, "init")) @compileError("App must export 'pub fn init(app: *App, engine: *mach.Engine) !void'");
|
if (!@hasDecl(App, "init")) @compileError("App must export 'pub fn init(app: *App, engine: *mach.Engine) !void'");
|
||||||
if (!@hasDecl(App, "deinit")) @compileError("App must export 'pub fn deinit(app: *App, engine: *mach.Engine) void'");
|
if (!@hasDecl(App, "deinit")) @compileError("App must export 'pub fn deinit(app: *App, engine: *mach.Engine) void'");
|
||||||
if (!@hasDecl(App, "update")) @compileError("App must export 'pub fn update(app: *App, engine: *mach.Engine) !bool'");
|
if (!@hasDecl(App, "update")) @compileError("App must export 'pub fn update(app: *App, engine: *mach.Engine) !void'");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -511,8 +511,6 @@ pub fn main() !void {
|
||||||
engine.current_desc = engine.target_desc;
|
engine.current_desc = engine.target_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
const success = try app.update(&engine);
|
try app.update(&engine);
|
||||||
if (!success)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,14 +196,14 @@ export fn wasmInit() void {
|
||||||
app.init(&engine) catch {};
|
app.init(&engine) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn wasmUpdate() bool {
|
export fn wasmUpdate() void {
|
||||||
// Poll internal events, like resize
|
// Poll internal events, like resize
|
||||||
engine.internal.pollChanges();
|
engine.internal.pollChanges();
|
||||||
|
|
||||||
engine.delta_time_ns = engine.timer.lapPrecise();
|
engine.delta_time_ns = engine.timer.lapPrecise();
|
||||||
engine.delta_time = @intToFloat(f32, engine.delta_time_ns) / @intToFloat(f32, std.time.ns_per_s);
|
engine.delta_time = @intToFloat(f32, engine.delta_time_ns) / @intToFloat(f32, std.time.ns_per_s);
|
||||||
|
|
||||||
return app.update(&engine) catch false;
|
app.update(&engine) catch engine.setShouldClose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn wasmDeinit() void {
|
export fn wasmDeinit() void {
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,8 @@
|
||||||
instance.exports.wasmInit();
|
instance.exports.wasmInit();
|
||||||
|
|
||||||
let update = function() {{
|
let update = function() {{
|
||||||
const r = instance.exports.wasmUpdate();
|
instance.exports.wasmUpdate();
|
||||||
if (r) requestAnimationFrame(update)
|
requestAnimationFrame(update);
|
||||||
else instance.exports.wasmDeinit();
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
requestAnimationFrame(update);
|
requestAnimationFrame(update);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue