2022-09-25 00:09:02 +02:00
|
|
|
const ext = @cImport({
|
|
|
|
@cInclude("SDL2/SDL.h");
|
|
|
|
});
|
|
|
|
|
2022-09-27 22:45:32 +02:00
|
|
|
const io = @import("./io.zig");
|
2022-09-25 00:09:02 +02:00
|
|
|
const mem = @import("./mem.zig");
|
|
|
|
const stack = @import("./stack.zig");
|
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub const EventLoop = opaque {
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
2022-10-01 18:46:21 +02:00
|
|
|
const FileSystemMessage = struct {
|
|
|
|
next: ?*FileSystemMessage = null,
|
2022-09-30 17:07:18 +02:00
|
|
|
frame: anyframe,
|
|
|
|
|
|
|
|
request: union(enum) {
|
2022-10-01 18:46:21 +02:00
|
|
|
close: struct {
|
|
|
|
file_access: *FileAccess,
|
|
|
|
},
|
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
open: struct {
|
|
|
|
mode: OpenMode,
|
|
|
|
path: *const FileSystem.Path,
|
2022-10-01 18:46:21 +02:00
|
|
|
result: OpenError!*FileAccess = error.NotFound,
|
|
|
|
},
|
|
|
|
|
|
|
|
read_file: struct {
|
|
|
|
file_access: *FileAccess,
|
|
|
|
buffer: []const u8,
|
|
|
|
result: FileError!usize = error.Inaccessible,
|
|
|
|
},
|
|
|
|
|
|
|
|
seek_file: struct {
|
|
|
|
file_access: *FileAccess,
|
|
|
|
origin: SeekOrigin,
|
|
|
|
offset: usize,
|
|
|
|
result: FileError!void = error.Inaccessible,
|
|
|
|
},
|
|
|
|
|
|
|
|
tell_file: struct {
|
|
|
|
file_access: *FileAccess,
|
|
|
|
result: FileError!usize = error.Inaccessible,
|
2022-09-30 17:07:18 +02:00
|
|
|
},
|
|
|
|
},
|
2022-10-01 18:46:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
const Implementation = struct {
|
|
|
|
user_prefix: []const u8,
|
2022-10-01 21:12:58 +02:00
|
|
|
file_system_semaphore: *ext.SDL_sem,
|
2022-10-01 18:46:21 +02:00
|
|
|
file_system_thread: *ext.SDL_Thread,
|
|
|
|
file_system_messages: ?*FileSystemMessage = null,
|
2022-09-30 17:07:18 +02:00
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
fn cast(event_loop: *EventLoop) *Implementation {
|
|
|
|
return @ptrCast(*Implementation, @alignCast(@alignOf(Implementation), event_loop));
|
|
|
|
}
|
2022-09-30 17:07:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub const OpenError = error {
|
|
|
|
NotFound,
|
2022-10-01 18:46:21 +02:00
|
|
|
BadFileSystem,
|
2022-09-30 17:07:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub const OpenMode = enum {
|
|
|
|
readonly,
|
|
|
|
overwrite,
|
|
|
|
append,
|
|
|
|
};
|
2022-09-25 00:09:02 +02:00
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub const SeekOrigin = enum {
|
|
|
|
head,
|
|
|
|
tail,
|
|
|
|
current,
|
|
|
|
};
|
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn close(event_loop: *EventLoop, file_access: *FileAccess) void {
|
2022-10-01 18:46:21 +02:00
|
|
|
var message = FileSystemMessage{
|
2022-09-30 17:07:18 +02:00
|
|
|
.frame = @frame(),
|
2022-10-01 18:46:21 +02:00
|
|
|
.request = .{.close = .{.file_access = file_access}},
|
2022-09-30 17:07:18 +02:00
|
|
|
};
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
suspend event_loop.enqueueFileSystemMessage(&message);
|
2022-09-30 17:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
2022-10-01 18:46:21 +02:00
|
|
|
pub fn enqueueFileSystemMessage(event_loop: *EventLoop, message: *FileSystemMessage) void {
|
|
|
|
const implementation = Implementation.cast(event_loop);
|
2022-09-30 17:07:18 +02:00
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
if (implementation.file_system_messages) |messages| {
|
|
|
|
messages.next = message;
|
2022-09-30 17:07:18 +02:00
|
|
|
} else {
|
2022-10-01 18:46:21 +02:00
|
|
|
implementation.file_system_messages = message;
|
2022-09-30 17:07:18 +02:00
|
|
|
}
|
2022-10-01 18:46:21 +02:00
|
|
|
|
|
|
|
// TODO: Post message to FS thread to perform task.
|
2022-09-30 17:07:18 +02:00
|
|
|
}
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub fn log(event_loop: *EventLoop, message: []const u8) void {
|
|
|
|
// TODO: Implement.
|
|
|
|
_ = event_loop;
|
|
|
|
_ = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn open(event_loop: *EventLoop, mode: OpenMode,
|
|
|
|
path: FileSystem.Path) OpenError!*FileAccess {
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
var message = FileSystemMessage{
|
2022-09-30 17:07:18 +02:00
|
|
|
.frame = @frame(),
|
|
|
|
|
|
|
|
.request = .{
|
|
|
|
.open = .{
|
|
|
|
.mode = mode,
|
|
|
|
.path = &path,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
suspend event_loop.enqueueFileSystemMessage(&message);
|
|
|
|
|
|
|
|
return message.request.open.result;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
fn processFileSystemMessages(data: ?*anyopaque) callconv(.C) c_int {
|
|
|
|
const implementation = Implementation.cast(@ptrCast(*EventLoop, data orelse unreachable));
|
|
|
|
|
|
|
|
while (implementation.file_system_messages) |messages| {
|
|
|
|
switch (messages.request) {
|
|
|
|
.open => |*open_request| {
|
|
|
|
switch (open_request.path.file_system) {
|
|
|
|
.data => {
|
|
|
|
// TODO: Implement
|
|
|
|
open_request.result = error.NotFound;
|
|
|
|
},
|
|
|
|
|
|
|
|
.user => {
|
|
|
|
var path_buffer = std.mem.zeroes([4096]u8);
|
|
|
|
var path = stack.Fixed(u8){.buffer = path_buffer[0 .. ]};
|
|
|
|
|
|
|
|
path.pushAll(implementation.user_prefix) catch {
|
|
|
|
open_request.result = error.BadFileSystem;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!open_request.path.write(path.writer())) {
|
|
|
|
open_request.result = error.NotFound;
|
2022-09-30 17:07:18 +02:00
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext.SDL_RWFromFile(&path_buffer, switch (open_request.mode) {
|
|
|
|
.readonly => "rb",
|
|
|
|
.overwrite => "wb",
|
|
|
|
.append => "ab",
|
|
|
|
})) |rw_ops| {
|
|
|
|
open_request.result = @ptrCast(*FileAccess, rw_ops);
|
|
|
|
} else {
|
|
|
|
open_request.result = error.NotFound;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
.close => |*close_request| {
|
|
|
|
// Don't care if this doesn't work.
|
|
|
|
_ = ext.SDL_RWclose(@ptrCast(*ext.SDL_RWops, @alignCast(
|
|
|
|
@alignOf(ext.SDL_RWops), close_request.file_access)));
|
|
|
|
},
|
|
|
|
|
|
|
|
.read_file => |read_request| {
|
|
|
|
_ = read_request;
|
|
|
|
},
|
|
|
|
|
|
|
|
.seek_file => |seek_request| {
|
|
|
|
_ = seek_request;
|
|
|
|
},
|
|
|
|
|
|
|
|
.tell_file => |tell_request| {
|
|
|
|
_ = tell_request;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
resume messages.frame;
|
|
|
|
|
|
|
|
implementation.file_system_messages = messages.next;
|
2022-09-30 17:07:18 +02:00
|
|
|
}
|
2022-10-01 18:46:21 +02:00
|
|
|
|
|
|
|
return 0;
|
2022-09-30 17:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn readFile(event_loop: *EventLoop, file_access: *FileAccess,
|
|
|
|
buffer: []const u8) FileError!usize {
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
var message = FileSystemMessage{
|
2022-09-30 17:07:18 +02:00
|
|
|
.frame = @frame(),
|
|
|
|
|
|
|
|
.request = .{
|
|
|
|
.read_file = .{
|
|
|
|
.file_access = file_access,
|
|
|
|
.buffer = buffer,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
suspend event_loop.enqueueFileSystemMessage(&message);
|
2022-09-30 17:07:18 +02:00
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
return message.request.read_file.result;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn seekFile(event_loop: *EventLoop, file_access: *FileAccess,
|
|
|
|
origin: SeekOrigin, offset: usize) FileError!void {
|
|
|
|
|
|
|
|
var message = FileSystemMessage{
|
|
|
|
.frame = @frame(),
|
|
|
|
|
|
|
|
.request = .{
|
|
|
|
.seek_file = .{
|
|
|
|
.file_access = file_access,
|
|
|
|
.origin = origin,
|
|
|
|
.offset = offset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
suspend event_loop.enqueueFileSystemMessage(&message);
|
|
|
|
|
|
|
|
return 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;
|
2022-09-30 17:07:18 +02:00
|
|
|
}
|
2022-09-30 10:50:18 +02:00
|
|
|
};
|
2022-09-25 00:09:02 +02:00
|
|
|
|
2022-09-30 10:50:18 +02:00
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub const FileAccess = opaque {
|
2022-09-25 00:09:02 +02:00
|
|
|
///
|
2022-09-30 10:50:18 +02:00
|
|
|
/// Scans the number of bytes in the file referenced by `file_access` via `event_loop`, returing
|
|
|
|
/// its byte size or a [FileError] if it failed.
|
2022-09-25 00:09:02 +02:00
|
|
|
///
|
2022-09-30 10:50:18 +02:00
|
|
|
pub fn size(file_access: *FileAccess, event_loop: *EventLoop) FileError!usize {
|
2022-09-30 17:07:18 +02:00
|
|
|
// Save cursor to return to it later.
|
|
|
|
const origin_cursor = try event_loop.tellFile(file_access);
|
2022-09-27 22:45:32 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
try event_loop.seekFile(file_access, .tail, 0);
|
2022-09-27 22:45:32 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
const ending_cursor = try event_loop.tellFile(file_access);
|
2022-09-27 22:45:32 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
// Return to original cursor.
|
|
|
|
try event_loop.seekFile(file_access, .head, origin_cursor);
|
2022-09-27 22:45:32 +02:00
|
|
|
|
2022-09-30 10:50:18 +02:00
|
|
|
return ending_cursor;
|
2022-09-25 00:09:02 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-27 22:45:32 +02:00
|
|
|
///
|
|
|
|
/// With files typically being backed by a block device, they can produce a variety of errors -
|
|
|
|
/// from physical to virtual errors - these are all encapsulated by the API as general
|
|
|
|
/// [Error.Inaccessible] errors.
|
|
|
|
///
|
|
|
|
pub const FileError = error {
|
|
|
|
Inaccessible,
|
|
|
|
};
|
2022-09-25 00:09:02 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
///
|
|
|
|
pub const FileSystem = enum {
|
|
|
|
data,
|
|
|
|
user,
|
2022-09-25 00:09:02 +02:00
|
|
|
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
/// Platform-agnostic mechanism for referencing files and directories on a [FileSystem]
|
2022-09-25 00:09:02 +02:00
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub const Path = struct {
|
|
|
|
file_system: FileSystem,
|
|
|
|
length: u16,
|
|
|
|
buffer: [max]u8,
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Returns `true` if the length of `path` is empty, otherwise `false`.
|
|
|
|
///
|
|
|
|
pub fn isEmpty(path: Path) bool {
|
|
|
|
return (path.length == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Returns `true` if `this` is equal to `that`, otherwise `false`.
|
|
|
|
///
|
|
|
|
pub fn equals(this: Path, that: Path) bool {
|
|
|
|
return std.mem.eql(u8, this.buffer[0 .. this.length], that.buffer[0 .. that.length]);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// The maximum possible byte-length of a [Path].
|
|
|
|
///
|
|
|
|
/// Note that paths are encoded using UTF-8, meaning that a character may be bigger than one
|
|
|
|
/// byte. Because of this, it is not safe to asume that a path may hold [max] individual
|
|
|
|
/// characters.
|
|
|
|
///
|
|
|
|
pub const max = 1000;
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn write(path: Path, writer: io.Writer) bool {
|
|
|
|
return (writer.write(path.buffer[0 .. path.length]) == path.length);
|
|
|
|
}
|
2022-09-25 00:09:02 +02:00
|
|
|
};
|
|
|
|
|
2022-09-30 10:50:18 +02:00
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
/// [PathError.TooLong] occurs when creating a path that is greater than the maximum size **in
|
|
|
|
/// bytes**.
|
2022-09-30 10:50:18 +02:00
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub const PathError = error {
|
|
|
|
TooLong,
|
|
|
|
};
|
2022-09-25 00:09:02 +02:00
|
|
|
|
2022-09-30 10:50:18 +02:00
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
/// Creates and returns a [Path] value in the file system to the location specified by the
|
2022-10-01 18:46:21 +02:00
|
|
|
/// joining of the `sequences` path values.
|
2022-09-30 10:50:18 +02:00
|
|
|
///
|
2022-10-01 18:46:21 +02:00
|
|
|
pub fn joinedPath(file_system: FileSystem, sequences: []const []const u8) PathError!Path {
|
2022-09-30 10:50:18 +02:00
|
|
|
var path = Path{
|
|
|
|
.file_system = file_system,
|
2022-09-30 17:07:18 +02:00
|
|
|
.buffer = std.mem.zeroes([Path.max]u8),
|
2022-09-30 10:50:18 +02:00
|
|
|
.length = 0,
|
|
|
|
};
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
for (sequences) |sequence| if (sequence.len != 0) {
|
2022-09-30 17:07:18 +02:00
|
|
|
var components = mem.Spliterator(u8){
|
2022-10-01 18:46:21 +02:00
|
|
|
.source = sequence,
|
2022-09-30 10:50:18 +02:00
|
|
|
.delimiter = "/",
|
|
|
|
};
|
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
while (components.next()) |component| if (component.len != 0) {
|
2022-09-30 10:50:18 +02:00
|
|
|
for (component) |byte| {
|
2022-09-30 17:07:18 +02:00
|
|
|
if (path.length == Path.max) return error.TooLong;
|
2022-09-30 10:50:18 +02:00
|
|
|
|
|
|
|
path.buffer[path.length] = byte;
|
|
|
|
path.length += 1;
|
|
|
|
}
|
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
if (path.length == Path.max) return error.TooLong;
|
2022-09-30 10:50:18 +02:00
|
|
|
|
|
|
|
path.buffer[path.length] = '/';
|
|
|
|
path.length += 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2022-09-30 17:07:18 +02:00
|
|
|
};
|
2022-09-30 10:50:18 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub const GraphicsContext = opaque {
|
2022-09-25 00:09:02 +02:00
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub const Event = struct {
|
2022-10-01 18:46:21 +02:00
|
|
|
keys_up: Keys = std.mem.zeroes(Keys),
|
|
|
|
keys_down: Keys = std.mem.zeroes(Keys),
|
|
|
|
keys_held: Keys = std.mem.zeroes(Keys),
|
2022-09-30 17:07:18 +02:00
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
const Keys = [256]bool;
|
2022-09-30 17:07:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const Implementation = struct {
|
|
|
|
event: Event,
|
|
|
|
};
|
2022-09-25 00:09:02 +02:00
|
|
|
|
2022-09-27 22:45:32 +02:00
|
|
|
///
|
2022-09-25 00:09:02 +02:00
|
|
|
///
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub fn poll(graphics_context: *GraphicsContext) ?*const Event {
|
|
|
|
_ = graphics_context;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn present(graphics_context: *GraphicsContext) void {
|
|
|
|
// TODO: Implement;
|
|
|
|
_ = graphics_context;
|
2022-09-27 22:45:32 +02:00
|
|
|
}
|
2022-09-25 00:09:02 +02:00
|
|
|
};
|
2022-09-30 10:50:18 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
2022-09-30 17:07:18 +02:00
|
|
|
pub fn GraphicsRunner(comptime Errors: type) type {
|
|
|
|
return fn (*EventLoop, *GraphicsContext) Errors!void;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
pub fn runGraphics(comptime Errors: anytype, run: GraphicsRunner(Errors)) Errors!void {
|
|
|
|
if (ext.SDL_Init(ext.SDL_INIT_EVERYTHING) != 0) {
|
|
|
|
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize SDL2 runtime");
|
|
|
|
|
|
|
|
return error.InitFailure;
|
|
|
|
}
|
|
|
|
|
|
|
|
defer ext.SDL_Quit();
|
|
|
|
|
|
|
|
const pref_path = create_pref_path: {
|
|
|
|
const path = ext.SDL_GetPrefPath("ona", "ona") orelse {
|
|
|
|
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to load user path");
|
|
|
|
|
|
|
|
return error.InitFailure;
|
|
|
|
};
|
|
|
|
|
|
|
|
break: create_pref_path path[0 .. std.mem.len(path)];
|
|
|
|
};
|
|
|
|
|
|
|
|
defer ext.SDL_free(pref_path.ptr);
|
|
|
|
|
|
|
|
const window = create_window: {
|
|
|
|
const pos = ext.SDL_WINDOWPOS_UNDEFINED;
|
|
|
|
var flags = @as(u32, 0);
|
|
|
|
|
|
|
|
break: create_window ext.SDL_CreateWindow("Ona", pos, pos, 640, 480, flags) orelse {
|
|
|
|
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to load SDL2 window");
|
|
|
|
|
|
|
|
return error.InitFailure;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
defer ext.SDL_DestroyWindow(window);
|
|
|
|
|
|
|
|
const renderer = create_renderer: {
|
|
|
|
var flags = @as(u32, 0);
|
|
|
|
|
|
|
|
break: create_renderer ext.SDL_CreateRenderer(window, -1, flags) orelse {
|
|
|
|
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to load SDL2 renderer");
|
|
|
|
|
|
|
|
return error.InitFailure;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
defer ext.SDL_DestroyRenderer(renderer);
|
|
|
|
|
|
|
|
var event_loop = EventLoop.Implementation{
|
2022-10-01 18:46:21 +02:00
|
|
|
.file_system_semaphore = ext.SDL_CreateSemaphore(0) orelse return error.InitFailure,
|
2022-10-01 21:12:58 +02:00
|
|
|
.file_system_thread = unreachable,
|
2022-10-01 18:46:21 +02:00
|
|
|
.user_prefix = pref_path,
|
2022-09-30 17:07:18 +02:00
|
|
|
};
|
|
|
|
|
2022-10-01 21:12:58 +02:00
|
|
|
event_loop.file_system_thread = ext.SDL_CreateThread(EventLoop.processFileSystemMessages,
|
|
|
|
"File System Worker", &event_loop) orelse return error.InitFailure;
|
|
|
|
|
2022-10-01 18:46:21 +02:00
|
|
|
defer {
|
|
|
|
ext.SDL_DestroyThread(event_loop.file_system_thread);
|
|
|
|
ext.SDL_DestroySemaphore(event_loop.file_system_semaphore);
|
|
|
|
}
|
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
var graphics_context = GraphicsContext.Implementation{
|
|
|
|
.event = .{
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|
2022-09-30 10:50:18 +02:00
|
|
|
|
2022-09-30 17:07:18 +02:00
|
|
|
return run(@ptrCast(*EventLoop, &event_loop), @ptrCast(*GraphicsContext, &graphics_context));
|
2022-09-30 10:50:18 +02:00
|
|
|
}
|