reintroduce App.create
parent
1979fb92f4
commit
83690744b2
17
src/App.zig
17
src/App.zig
|
|
@ -76,6 +76,15 @@ first: bool = true,
|
||||||
|
|
||||||
pub const CreateError = Allocator.Error || font.SharedGridSet.InitError;
|
pub const CreateError = Allocator.Error || font.SharedGridSet.InitError;
|
||||||
|
|
||||||
|
/// Create a new app instance. This returns a stable pointer to the app
|
||||||
|
/// instance which is required for callbacks.
|
||||||
|
pub fn create(alloc: Allocator) CreateError!*App {
|
||||||
|
var app = try alloc.create(App);
|
||||||
|
errdefer alloc.destroy(app);
|
||||||
|
try app.init(alloc);
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
/// Initialize the main app instance. This creates the main window, sets
|
/// Initialize the main app instance. This creates the main window, sets
|
||||||
/// up the renderer state, compiles the shaders, etc. This is the primary
|
/// up the renderer state, compiles the shaders, etc. This is the primary
|
||||||
/// "startup" logic.
|
/// "startup" logic.
|
||||||
|
|
@ -111,6 +120,14 @@ pub fn deinit(self: *App) void {
|
||||||
self.font_grid_set.deinit();
|
self.font_grid_set.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn destroy(self: *App) void {
|
||||||
|
// Deinitialize the app
|
||||||
|
self.deinit();
|
||||||
|
|
||||||
|
// Free the app memory
|
||||||
|
self.alloc.destroy(self);
|
||||||
|
}
|
||||||
|
|
||||||
/// Tick ticks the app loop. This will drain our mailbox and process those
|
/// Tick ticks the app loop. This will drain our mailbox and process those
|
||||||
/// events. This should be called by the application runtime on every loop
|
/// events. This should be called by the application runtime on every loop
|
||||||
/// tick.
|
/// tick.
|
||||||
|
|
|
||||||
|
|
@ -1317,12 +1317,8 @@ pub const CAPI = struct {
|
||||||
opts: *const apprt.runtime.App.Options,
|
opts: *const apprt.runtime.App.Options,
|
||||||
config: *const Config,
|
config: *const Config,
|
||||||
) !*App {
|
) !*App {
|
||||||
var core_app = try global.alloc.create(CoreApp);
|
const core_app = try CoreApp.create(global.alloc);
|
||||||
try core_app.init(global.alloc);
|
errdefer core_app.destroy();
|
||||||
errdefer {
|
|
||||||
core_app.deinit();
|
|
||||||
global.alloc.destroy(core_app);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create our runtime app
|
// Create our runtime app
|
||||||
var app = try global.alloc.create(App);
|
var app = try global.alloc.create(App);
|
||||||
|
|
@ -1350,8 +1346,7 @@ pub const CAPI = struct {
|
||||||
const core_app = v.core_app;
|
const core_app = v.core_app;
|
||||||
v.terminate();
|
v.terminate();
|
||||||
global.alloc.destroy(v);
|
global.alloc.destroy(v);
|
||||||
core_app.deinit();
|
core_app.destroy();
|
||||||
global.alloc.destroy(core_app);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the focused state of the app.
|
/// Update the focused state of the app.
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,8 @@ pub fn main() !MainReturn {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create our app state
|
// Create our app state
|
||||||
var app: App = undefined;
|
const app: *App = try App.create(alloc);
|
||||||
try app.init(alloc);
|
defer app.destroy();
|
||||||
defer app.deinit();
|
|
||||||
|
|
||||||
// Create our runtime app
|
// Create our runtime app
|
||||||
var app_runtime: apprt.App = undefined;
|
var app_runtime: apprt.App = undefined;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue