Skip to content

Commit

Permalink
Clean up hot shader reload thread on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
bfeldpw committed Nov 15, 2023
1 parent 1f1c85f commit 73c0482
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 1,280 deletions.
9 changes: 8 additions & 1 deletion src/gfx_hsr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ pub fn init() void {

}

pub fn rmWatch() void {
const r = lnx.inotify_rm_watch(fd, wd);
_ = r;
}

pub fn readEvent() void {
log_gfx_hsr.debug("Watching directory for hot shader reload", .{});

const event_size = (@sizeOf(lnx.inotify_event) + std.os.PATH_MAX) * 10;
var buf: [event_size]u8 = undefined;

while (true) {
while (is_running) {
const len = lnx.read(fd, &buf, event_size);
_ = len;
log_gfx_hsr.debug("Shader file(s) modified", .{});
is_reload_triggered.value = true;
}
log_gfx_hsr.debug("Stopping file watch", .{});
}

//-----------------------------------------------------------------------------//
Expand All @@ -48,6 +54,7 @@ pub fn readEvent() void {
const log_gfx_hsr = std.log.scoped(.gfx_hsr);

pub var is_reload_triggered = std.atomic.Atomic(bool).init(false);
pub var is_running: bool = true;

var fd: i32 = 0;
var wd: i32 = 0;
111 changes: 0 additions & 111 deletions src/gfx_impl.zig

This file was deleted.

5 changes: 0 additions & 5 deletions src/gfx_rw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ pub fn init() !void {
}
try gfx_core.bindEBOAndBufferData(ebo, buffer_size*6, ebo_buf.items, .Static);
ebo_buf.deinit();

if (builtin.os.tag == .linux) {
const gfx_hsr= @import("gfx_hsr.zig");
gfx_hsr.init();
}
}

pub fn deinit() void {
Expand Down
Loading

0 comments on commit 73c0482

Please sign in to comment.