all: rename setShouldClose to close

Closes #550
This commit is contained in:
Ali Chraghi 2022-09-18 19:22:03 +04:30 committed by Stephen Gutekanst
parent 308d413f09
commit 15dfb2867a
15 changed files with 21 additions and 21 deletions

View file

@ -54,7 +54,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
while (core.pollEvent()) |event| { while (core.pollEvent()) |event| {
switch (event) { switch (event) {
.key_press => |ev| switch (ev.key) { .key_press => |ev| switch (ev.key) {
.q, .escape, .space => core.setShouldClose(true), .q, .escape, .space => core.close(),
.w, .up => { .w, .up => {
app.keys |= Dir.up; app.keys |= Dir.up;
}, },

View file

@ -248,7 +248,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -193,7 +193,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -238,7 +238,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -122,7 +122,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -82,5 +82,5 @@ pub fn init(_: *App, core: *mach.Core) !void {
pub fn deinit(_: *App, _: *mach.Core) void {} pub fn deinit(_: *App, _: *mach.Core) void {}
pub fn update(_: *App, core: *mach.Core) !void { pub fn update(_: *App, core: *mach.Core) !void {
core.setShouldClose(true); core.close();
} }

View file

@ -64,7 +64,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -120,7 +120,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -169,7 +169,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -137,7 +137,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }

View file

@ -88,7 +88,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
switch (event) { switch (event) {
.key_press => |ev| { .key_press => |ev| {
if (ev.key == .space) if (ev.key == .space)
core.setShouldClose(true); core.close();
}, },
else => {}, else => {},
} }
@ -101,7 +101,7 @@ pub fn update(app: *App, core: *mach.Core) !void {
app.fragment_shader_file.seekTo(0) catch unreachable; app.fragment_shader_file.seekTo(0) catch unreachable;
app.fragment_shader_code = app.fragment_shader_file.readToEndAllocOptions(core.allocator, std.math.maxInt(u32), null, 1, 0) catch |err| { app.fragment_shader_code = app.fragment_shader_file.readToEndAllocOptions(core.allocator, std.math.maxInt(u32), null, 1, 0) catch |err| {
std.log.err("Err: {}", .{err}); std.log.err("Err: {}", .{err});
return core.setShouldClose(true); return core.close();
}; };
app.pipeline = recreatePipeline(core, app.fragment_shader_code, null); app.pipeline = recreatePipeline(core, app.fragment_shader_code, null);
} }

View file

@ -50,8 +50,8 @@ pub fn setOptions(core: *Core, options: structs.Options) !void {
} }
// Signals mach to stop the update loop. // Signals mach to stop the update loop.
pub fn setShouldClose(core: *Core, value: bool) void { pub fn close(core: *Core) void {
core.internal.setShouldClose(value); core.internal.close();
} }
// Sets seconds to wait for an event with timeout before calling update() // Sets seconds to wait for an event with timeout before calling update()

View file

@ -22,8 +22,8 @@ pub fn update(_: *App, _: *Core) !void {}
// 2. Core might need to expose more state so more API functions can be exposed (for example, the WebGPU API) // 2. Core might need to expose more state so more API functions can be exposed (for example, the WebGPU API)
// 3. Be very careful about arguments, types, memory, etc - any mismatch will result in undefined behavior // 3. Be very careful about arguments, types, memory, etc - any mismatch will result in undefined behavior
pub export fn mach_core_set_should_close(core: *Core) void { pub export fn mach_core_close(core: *Core) void {
core.setShouldClose(true); core.close();
} }
pub export fn mach_core_delta_time(core: *Core) f32 { pub export fn mach_core_delta_time(core: *Core) f32 {

View file

@ -329,8 +329,8 @@ pub const Platform = struct {
if (options.headless) platform.window.hide() catch {}; if (options.headless) platform.window.hide() catch {};
} }
pub fn setShouldClose(platform: *Platform, value: bool) void { pub fn close(platform: *Platform) void {
platform.window.setShouldClose(value); platform.window.setShouldClose(true);
} }
pub fn getFramebufferSize(platform: *Platform) structs.Size { pub fn getFramebufferSize(platform: *Platform) structs.Size {

View file

@ -95,8 +95,8 @@ pub const Platform = struct {
js.machCanvasSetFullscreen(platform.id, options.fullscreen); js.machCanvasSetFullscreen(platform.id, options.fullscreen);
} }
pub fn setShouldClose(_: *Platform, value: bool) void { pub fn close(_: *Platform) void {
if (value) js.machEmitCloseEvent(); js.machEmitCloseEvent();
} }
pub fn setWaitEvent(_: *Platform, timeout: f64) void { pub fn setWaitEvent(_: *Platform, timeout: f64) void {
@ -297,7 +297,7 @@ export fn wasmUpdate() void {
core.delta_time_ns = core.timer.lapPrecise(); core.delta_time_ns = core.timer.lapPrecise();
core.delta_time = @intToFloat(f32, core.delta_time_ns) / @intToFloat(f32, std.time.ns_per_s); core.delta_time = @intToFloat(f32, core.delta_time_ns) / @intToFloat(f32, std.time.ns_per_s);
app.update(&core) catch core.setShouldClose(true); app.update(&core) catch core.close();
} }
export fn wasmDeinit() void { export fn wasmDeinit() void {