2022-09-22 22:03:25 +01:00
|
|
|
const ext = @cImport({
|
2022-08-10 14:52:16 +01:00
|
|
|
@cInclude("SDL2/SDL.h");
|
|
|
|
});
|
|
|
|
|
2022-09-09 22:55:34 +01:00
|
|
|
const io = @import("./io.zig");
|
|
|
|
const stack = @import("./stack.zig");
|
2022-08-10 14:52:16 +01:00
|
|
|
const std = @import("std");
|
2022-09-24 23:09:02 +01:00
|
|
|
const sys = @import("./sys.zig");
|
2022-09-09 22:55:34 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Entry point.
|
|
|
|
///
|
2022-08-10 14:52:16 +01:00
|
|
|
pub fn main() anyerror!void {
|
2022-10-15 11:38:22 +01:00
|
|
|
return nosuspend await async sys.runGraphics(anyerror, run);
|
2022-09-30 09:50:18 +01:00
|
|
|
}
|
2022-08-10 16:38:50 +01:00
|
|
|
|
2022-10-01 21:25:06 +01:00
|
|
|
test {
|
2022-10-03 22:58:38 +01:00
|
|
|
_ = io;
|
|
|
|
_ = stack;
|
|
|
|
_ = std;
|
|
|
|
_ = sys;
|
2022-10-01 21:25:06 +01:00
|
|
|
}
|
|
|
|
|
2022-10-10 10:15:45 +01:00
|
|
|
fn run(app: *sys.AppContext, graphics: *sys.GraphicsContext) anyerror!void {
|
2022-09-30 16:07:18 +01:00
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
2022-08-10 16:38:50 +01:00
|
|
|
|
2022-10-01 17:46:21 +01:00
|
|
|
defer _ = gpa.deinit();
|
|
|
|
|
2022-09-30 09:50:18 +01:00
|
|
|
{
|
2022-10-13 14:37:38 +01:00
|
|
|
var file_access = try (try app.data().joinedPath(&.{"ona.lua"})).open(.readonly);
|
2022-08-10 14:52:16 +01:00
|
|
|
|
2022-10-10 17:46:25 +01:00
|
|
|
defer file_access.close();
|
2022-08-10 14:52:16 +01:00
|
|
|
|
2022-10-10 17:46:25 +01:00
|
|
|
const file_size = try file_access.queryLength();
|
2022-10-01 17:46:21 +01:00
|
|
|
const allocator = gpa.allocator();
|
|
|
|
const buffer = try allocator.alloc(u8, file_size);
|
|
|
|
|
|
|
|
defer allocator.free(buffer);
|
2022-08-10 16:38:50 +01:00
|
|
|
|
2022-10-10 17:46:25 +01:00
|
|
|
if ((try file_access.read(buffer)) != file_size)
|
2022-10-01 17:46:21 +01:00
|
|
|
return error.ScriptLoadFailure;
|
2022-09-09 22:55:34 +01:00
|
|
|
|
2022-10-10 17:46:25 +01:00
|
|
|
sys.Log.debug.write(buffer);
|
2022-09-30 09:50:18 +01:00
|
|
|
}
|
2022-09-09 22:55:34 +01:00
|
|
|
|
2022-10-09 23:10:13 +01:00
|
|
|
while (graphics.poll()) |_| {
|
|
|
|
graphics.present();
|
2022-08-10 14:52:16 +01:00
|
|
|
}
|
|
|
|
}
|