Fix compilation errors
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
49557f32bc
commit
af1976b69c
|
@ -38,7 +38,7 @@ fn run(event_loop: *sys.EventLoop, graphics: *sys.GraphicsContext) anyerror!void
|
||||||
if ((try event_loop.readFile(file_access, buffer)) != file_size)
|
if ((try event_loop.readFile(file_access, buffer)) != file_size)
|
||||||
return error.ScriptLoadFailure;
|
return error.ScriptLoadFailure;
|
||||||
|
|
||||||
event_loop.log(buffer);
|
event_loop.log(.debug, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (graphics.poll()) |_| {
|
while (graphics.poll()) |_| {
|
||||||
|
|
92
src/sys.zig
92
src/sys.zig
|
@ -8,7 +8,7 @@ const stack = @import("./stack.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
/// A thread-safe platform abstraction over multiplexing system I/O processing and event handling.
|
||||||
///
|
///
|
||||||
pub const EventLoop = opaque {
|
pub const EventLoop = opaque {
|
||||||
///
|
///
|
||||||
|
@ -23,7 +23,7 @@ pub const EventLoop = opaque {
|
||||||
exit,
|
exit,
|
||||||
|
|
||||||
close: struct {
|
close: struct {
|
||||||
file_system_path: *FileAccess,
|
file_access: *FileAccess,
|
||||||
},
|
},
|
||||||
|
|
||||||
log: struct {
|
log: struct {
|
||||||
|
@ -33,7 +33,7 @@ pub const EventLoop = opaque {
|
||||||
|
|
||||||
open: struct {
|
open: struct {
|
||||||
mode: OpenMode,
|
mode: OpenMode,
|
||||||
path: *const FileSystem.Path,
|
file_system_path: *const FileSystem.Path,
|
||||||
result: OpenError!*FileAccess = error.NotFound,
|
result: OpenError!*FileAccess = error.NotFound,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -138,13 +138,15 @@ pub const EventLoop = opaque {
|
||||||
///
|
///
|
||||||
/// Closes access to the file referenced by `file_access` via `event_loop`.
|
/// Closes access to the file referenced by `file_access` via `event_loop`.
|
||||||
///
|
///
|
||||||
|
/// *Note* that nothing happens to `file_access` if it is already closed.
|
||||||
|
///
|
||||||
pub fn close(event_loop: *EventLoop, file_access: *FileAccess) void {
|
pub fn close(event_loop: *EventLoop, file_access: *FileAccess) void {
|
||||||
var message = FileSystemMessage{
|
var file_system_message = FileSystemMessage{
|
||||||
.frame = @frame(),
|
.frame = @frame(),
|
||||||
.request = .{.close = .{.file_access = file_access}},
|
.request = .{.close = .{.file_access = file_access}},
|
||||||
};
|
};
|
||||||
|
|
||||||
suspend event_loop.enqueueFileSystemMessage(&message);
|
suspend event_loop.enqueueFileSystemMessage(&file_system_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -174,7 +176,7 @@ pub const EventLoop = opaque {
|
||||||
/// *Note* that `message` is not guaranteed to be partly, wholely, or at all written.
|
/// *Note* that `message` is not guaranteed to be partly, wholely, or at all written.
|
||||||
///
|
///
|
||||||
pub fn log(event_loop: *EventLoop, kind: LogKind, message: []const u8) void {
|
pub fn log(event_loop: *EventLoop, kind: LogKind, message: []const u8) void {
|
||||||
var message = FileSystemMessage{
|
var file_system_message = FileSystemMessage{
|
||||||
.frame = @frame(),
|
.frame = @frame(),
|
||||||
|
|
||||||
.request = .{.log = .{
|
.request = .{.log = .{
|
||||||
|
@ -183,7 +185,7 @@ pub const EventLoop = opaque {
|
||||||
}},
|
}},
|
||||||
};
|
};
|
||||||
|
|
||||||
suspend event_loop.enqueueFileSystemMessage(&message);
|
suspend event_loop.enqueueFileSystemMessage(&file_system_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -199,24 +201,26 @@ pub const EventLoop = opaque {
|
||||||
pub fn open(event_loop: *EventLoop, mode: OpenMode,
|
pub fn open(event_loop: *EventLoop, mode: OpenMode,
|
||||||
file_system_path: FileSystem.Path) OpenError!*FileAccess {
|
file_system_path: FileSystem.Path) OpenError!*FileAccess {
|
||||||
|
|
||||||
var message = FileSystemMessage{
|
var file_system_message = FileSystemMessage{
|
||||||
.frame = @frame(),
|
.frame = @frame(),
|
||||||
|
|
||||||
.request = .{
|
.request = .{.open = .{
|
||||||
.open = .{
|
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.file_system_path = &file_system_path,
|
.file_system_path = &file_system_path,
|
||||||
},
|
}},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
suspend event_loop.enqueueFileSystemMessage(&message);
|
suspend event_loop.enqueueFileSystemMessage(&file_system_message);
|
||||||
|
|
||||||
return message.request.open.result;
|
return file_system_message.request.open.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
/// [FileSystemMessage] processing function used by a dedicated worker thread, where `data` is
|
||||||
|
/// a type-erased reference to a [EventLoop].
|
||||||
///
|
///
|
||||||
|
/// The processor returns `0` if it exited normally or any other value if an erroneous exit
|
||||||
|
/// occured.
|
||||||
///
|
///
|
||||||
fn processFileSystemMessages(data: ?*anyopaque) callconv(.C) c_int {
|
fn processFileSystemMessages(data: ?*anyopaque) callconv(.C) c_int {
|
||||||
const implementation = Implementation.cast(@ptrCast(*EventLoop, data orelse unreachable));
|
const implementation = Implementation.cast(@ptrCast(*EventLoop, data orelse unreachable));
|
||||||
|
@ -266,20 +270,23 @@ pub const EventLoop = opaque {
|
||||||
},
|
},
|
||||||
|
|
||||||
.close => |*close_request| {
|
.close => |*close_request| {
|
||||||
// Don't care if this doesn't work.
|
// TODO: Use this result somehow.
|
||||||
_ = ext.SDL_RWclose(@ptrCast(*ext.SDL_RWops, @alignCast(
|
_ = ext.SDL_RWclose(@ptrCast(*ext.SDL_RWops, @alignCast(
|
||||||
@alignOf(ext.SDL_RWops), close_request.file_access)));
|
@alignOf(ext.SDL_RWops), close_request.file_access)));
|
||||||
},
|
},
|
||||||
|
|
||||||
.read_file => |read_request| {
|
.read_file => |read_request| {
|
||||||
|
// TODO: Implement.
|
||||||
_ = read_request;
|
_ = read_request;
|
||||||
},
|
},
|
||||||
|
|
||||||
.seek_file => |seek_request| {
|
.seek_file => |seek_request| {
|
||||||
|
// TODO: Implement.
|
||||||
_ = seek_request;
|
_ = seek_request;
|
||||||
},
|
},
|
||||||
|
|
||||||
.tell_file => |tell_request| {
|
.tell_file => |tell_request| {
|
||||||
|
// TODO: Implement.
|
||||||
_ = tell_request;
|
_ = tell_request;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -304,29 +311,45 @@ pub const EventLoop = opaque {
|
||||||
pub fn readFile(event_loop: *EventLoop, file_access: *FileAccess,
|
pub fn readFile(event_loop: *EventLoop, file_access: *FileAccess,
|
||||||
buffer: []const u8) FileError!usize {
|
buffer: []const u8) FileError!usize {
|
||||||
|
|
||||||
var message = FileSystemMessage{
|
var file_system_message = FileSystemMessage{
|
||||||
.frame = @frame(),
|
.frame = @frame(),
|
||||||
|
|
||||||
.request = .{
|
.request = .{.read_file = .{
|
||||||
.read_file = .{
|
|
||||||
.file_access = file_access,
|
.file_access = file_access,
|
||||||
.buffer = buffer,
|
.buffer = buffer,
|
||||||
},
|
}},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
suspend event_loop.enqueueFileSystemMessage(&message);
|
suspend event_loop.enqueueFileSystemMessage(&file_system_message);
|
||||||
|
|
||||||
return message.request.read_file.result;
|
return file_system_message.request.read_file.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
/// Attempts to tell the current file cursor position for the file referenced by `file_access`.
|
||||||
///
|
///
|
||||||
|
/// Returns the number of bytes into the file that the cursor is relative to its beginning or a
|
||||||
|
/// [FileError] if the file failed to be queried.
|
||||||
|
///
|
||||||
|
pub fn queryFile(event_loop: *EventLoop, file_access: *FileAccess) FileError!usize {
|
||||||
|
var file_system_message = FileSystemMessage{
|
||||||
|
.frame = @frame(),
|
||||||
|
.request = .{.tell_file = .{.file_access = file_access}},
|
||||||
|
};
|
||||||
|
|
||||||
|
suspend event_loop.enqueueFileSystemMessage(&file_system_message);
|
||||||
|
|
||||||
|
return file_system_message.request.tell_file.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Attempts to seek the file cursor through the file referenced by `file_access` from `origin`
|
||||||
|
/// to `offset` via `event_loop`, returning a [FileError] if the file failed to be sought.
|
||||||
///
|
///
|
||||||
pub fn seekFile(event_loop: *EventLoop, file_access: *FileAccess,
|
pub fn seekFile(event_loop: *EventLoop, file_access: *FileAccess,
|
||||||
origin: SeekOrigin, offset: usize) FileError!void {
|
origin: SeekOrigin, offset: usize) FileError!void {
|
||||||
|
|
||||||
var message = FileSystemMessage{
|
var file_system_message = FileSystemMessage{
|
||||||
.frame = @frame(),
|
.frame = @frame(),
|
||||||
|
|
||||||
.request = .{
|
.request = .{
|
||||||
|
@ -338,23 +361,9 @@ pub const EventLoop = opaque {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
suspend event_loop.enqueueFileSystemMessage(&message);
|
suspend event_loop.enqueueFileSystemMessage(&file_system_message);
|
||||||
|
|
||||||
return message.request.seek_file.result;
|
return file_system_message.request.seek_file.result;
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
///
|
|
||||||
///
|
|
||||||
pub fn tellFile(event_loop: *EventLoop, file_access: *FileAccess) FileError!usize {
|
|
||||||
var message = FileSystemMessage{
|
|
||||||
.frame = @frame(),
|
|
||||||
.request = .{.tell_file = .{.file_access = file_access}},
|
|
||||||
};
|
|
||||||
|
|
||||||
suspend event_loop.enqueueFileSystemMessage(&message);
|
|
||||||
|
|
||||||
return message.request.tell_file.result;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -391,14 +400,15 @@ pub const FileError = error {
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
/// Platform-agnostic mechanism for working with an abstraction of the underlying file-system(s)
|
||||||
|
/// available to the application in a sandboxed environment.
|
||||||
///
|
///
|
||||||
pub const FileSystem = enum {
|
pub const FileSystem = enum {
|
||||||
data,
|
data,
|
||||||
user,
|
user,
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Platform-agnostic mechanism for referencing files and directories on a [FileSystem]
|
/// Platform-agnostic mechanism for referencing files and directories on a [FileSystem].
|
||||||
///
|
///
|
||||||
pub const Path = struct {
|
pub const Path = struct {
|
||||||
file_system: FileSystem,
|
file_system: FileSystem,
|
||||||
|
|
Loading…
Reference in New Issue