Implement first pass of Oar archive reading mechanism
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kayomn 2022-10-09 23:10:13 +01:00
parent c42885bf61
commit 9ae6e8b4a7
5 changed files with 714 additions and 451 deletions

View File

@ -21,29 +21,29 @@ test {
_ = sys; _ = sys;
} }
fn run(ev: *sys.EventLoop, fs: *const sys.FileSystem, gr: *sys.GraphicsContext) anyerror!void { fn run(app: *sys.App, graphics: *sys.GraphicsContext) anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit(); defer _ = gpa.deinit();
{ {
const file_access = try ev.open(.readonly, try fs.data.joinedPath(&.{"ona.lua"})); const file_access = try (try app.data().joinedPath(&.{"ona.lua"})).open(app, .readonly);
defer ev.close(file_access); defer file_access.close(app);
const file_size = try file_access.size(ev); const file_size = try file_access.queryLength(app);
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const buffer = try allocator.alloc(u8, file_size); const buffer = try allocator.alloc(u8, file_size);
defer allocator.free(buffer); defer allocator.free(buffer);
if ((try ev.readFile(file_access, buffer)) != file_size) if ((try file_access.read(app, buffer)) != file_size)
return error.ScriptLoadFailure; return error.ScriptLoadFailure;
ev.log(.debug, buffer); sys.Log.debug.write(app, buffer);
} }
while (gr.poll()) |_| { while (graphics.poll()) |_| {
gr.present(); graphics.present();
} }
} }

6
src/math.zig Normal file
View File

@ -0,0 +1,6 @@
///
/// Rounds the `Number` `value` up to the nearest `multiple`.
///
pub fn roundUp(comptime Number: type, value: Number, multiple: Number) Number {
return value + @mod(@mod(multiple - value, multiple), multiple);
}

14
src/oar.zig Normal file
View File

@ -0,0 +1,14 @@
const std = @import("std");
const sys = @import("./sys.zig");
///
/// An entry block of an Oar archive file.
///
/// Typically, following this block in memory is the file data it holds the meta-information for.
///
pub const Entry = extern struct {
name_length: u8,
name_buffer: [255]u8 = std.mem.zeroes([255]u8),
file_size: u64,
padding: [248]u8,
};

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +0,0 @@
const std = @import("std");
///
///
///
pub const Archive = struct {
allocator: std.mem.Allocator,
pub const LoadError = error {
FileNotFound,
};
///
///
///
pub fn init(allocator: std.mem.Allocator) Archive {
return Archive{
.allocator = allocator,
};
}
///
///
///
pub fn load(archive: *Archive, file_path: []const u8) LoadError!void {
_ = file_path;
_ = archive;
}
};