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