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-09-30 10:50:18 +02:00
|
|
|
return sys.runGraphics(anyerror, run);
|
|
|
|
}
|
2022-08-10 17:38:50 +02:00
|
|
|
|
2022-10-01 22:25:06 +02:00
|
|
|
test {
|
2022-10-03 00:57:41 +02:00
|
|
|
|
2022-10-01 22:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
fn run(event_loop: *sys.EventLoop, graphics: *sys.GraphicsContext) anyerror!void {
|
|
|
|
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-01 18:46:21 +02:00
|
|
|
const file_access = try event_loop.open(.readonly,
|
|
|
|
try sys.FileSystem.data.joinedPath(&.{"data", "ona.lua"}));
|
2022-08-10 15:52:16 +02:00
|
|
|
|
2022-10-03 00:57:41 +02:00
|
|
|
defer event_loop.close(file_access);
|
2022-08-10 15:52:16 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
const file_size = try file_access.size(event_loop);
|
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-01 18:46:21 +02:00
|
|
|
if ((try event_loop.readFile(file_access, buffer)) != file_size)
|
|
|
|
return error.ScriptLoadFailure;
|
2022-09-09 23:55:34 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
event_loop.log(buffer);
|
2022-09-30 10:50:18 +02:00
|
|
|
}
|
2022-09-09 23:55:34 +02:00
|
|
|
|
2022-09-30 10:50:18 +02:00
|
|
|
while (graphics.poll()) |_| {
|
|
|
|
graphics.present();
|
2022-08-10 15:52:16 +02:00
|
|
|
}
|
|
|
|
}
|