aboutsummaryrefslogtreecommitdiffstats
path: root/src/control.zig
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2023-10-27 18:29:26 +0000
committers-ol <s+removethis@s-ol.nu>2023-10-29 22:43:58 +0000
commita250d5bbe6eb215e345de4900e784140dfe73161 (patch)
tree3a9f3aa116f7d0ac2faca30b6ceab6a110d6eef2 /src/control.zig
parentupdate for zig 0.9.0 (diff)
downloadglsl-view-a250d5bbe6eb215e345de4900e784140dfe73161.tar.gz
glsl-view-a250d5bbe6eb215e345de4900e784140dfe73161.zip
update for zig 0.11.0
Diffstat (limited to 'src/control.zig')
-rw-r--r--src/control.zig50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/control.zig b/src/control.zig
index 43c232e..d7ce531 100644
--- a/src/control.zig
+++ b/src/control.zig
@@ -6,7 +6,7 @@ const cfg = @import("config.zig");
fn verify_args(expected: u8, got: []const u8) !void {
for (got) |typ| {
if (typ != expected) {
- std.debug.warn("expected '{c}' but got '{c}' element (expected {s})\n", .{ expected, typ, got });
+ std.debug.print("expected '{c}' but got '{c}' element (expected {s})\n", .{ expected, typ, got });
return error.typeMismatch;
}
}
@@ -25,26 +25,26 @@ fn set_array(
switch (T) {
f32 => {
try verify_args('f', types);
- for (dest) |*v, i|
+ for (dest, 0..) |*v, i|
v.* = argv[i].*.f;
},
f64 => {
try verify_args('d', types);
- for (dest) |*v, i|
+ for (dest, 0..) |*v, i|
v.* = argv[i].*.d;
},
i32 => {
try verify_args('i', types);
- for (dest) |*v, i|
+ for (dest, 0..) |*v, i|
v.* = argv[i].*.i;
},
u32 => {
try verify_args('i', types);
- for (dest) |*v, i| {
+ for (dest, 0..) |*v, i| {
const val = argv[i].*.i;
if (val < 0)
return error.signDisallowed;
- v.* = @intCast(u32, argv[i].*.i);
+ v.* = @as(u32, @intCast(argv[i].*.i));
}
},
else => return error.invalidType,
@@ -54,13 +54,15 @@ fn set_array(
pub const ControlServer = struct {
server: c.lo_server,
cache: *gl.UniformCache,
+ allocator: std.mem.Allocator,
pub fn init(
- allocator: *std.mem.Allocator,
+ allocator: std.mem.Allocator,
config: cfg.OSCConfig,
cache: *gl.UniformCache,
) !*ControlServer {
var self: *ControlServer = try allocator.create(ControlServer);
+ self.allocator = allocator;
self.cache = cache;
switch (config) {
@@ -73,21 +75,21 @@ pub const ControlServer = struct {
.unix => c.LO_UNIX,
};
- std.debug.warn(
+ std.debug.print(
"listening for OSC messages on {} port {}\n",
.{ conf.protocol, conf.port },
);
self.server = c.lo_server_new_with_proto(port[0..], proto, handle_error);
},
.URL => |url| {
- std.debug.warn("listening for OSC messages at {s}\n", .{url});
+ std.debug.print("listening for OSC messages at {s}\n", .{url});
self.server = c.lo_server_new_from_url(url[0..].ptr, handle_error);
},
}
if (self.server == null)
return error.serverInitializationError;
- _ = c.lo_server_add_method(self.server, null, null, handle_method, @ptrCast(*c_void, self));
+ _ = c.lo_server_add_method(self.server, null, null, handle_method, @as(*anyopaque, @ptrCast(self)));
return self;
}
@@ -101,9 +103,9 @@ pub const ControlServer = struct {
}
fn handle_error(num: c_int, msg: [*c]const u8, where: [*c]const u8) callconv(.C) void {
- std.debug.warn(
+ std.debug.print(
"OSC error {} @ {s}: {s}\n",
- .{ num, @ptrCast([*:0]const u8, where), @ptrCast([*:0]const u8, msg) },
+ .{ num, @as([*:0]const u8, @ptrCast(where)), @as([*:0]const u8, @ptrCast(msg)) },
);
}
@@ -121,11 +123,11 @@ pub const ControlServer = struct {
const uniform = (try self.cache.get(name)) orelse return error.notFound;
try switch (uniform.value) {
- .FLOAT => |*val| set_array(f32, @ptrCast([*]f32, val)[0..1], argc, argv, types),
- .DOUBLE => |*val| set_array(f64, @ptrCast([*]f64, val)[0..1], argc, argv, types),
- .INT => |*val| set_array(i32, @ptrCast([*]i32, val)[0..1], argc, argv, types),
- .UNSIGNED_INT => |*val| set_array(u32, @ptrCast([*]u32, val)[0..1], argc, argv, types),
- .BOOL => |*val| set_array(u32, @ptrCast([*]u32, val)[0..1], argc, argv, types),
+ .FLOAT => |*val| set_array(f32, @as([*]f32, @ptrCast(val))[0..1], argc, argv, types),
+ .DOUBLE => |*val| set_array(f64, @as([*]f64, @ptrCast(val))[0..1], argc, argv, types),
+ .INT => |*val| set_array(i32, @as([*]i32, @ptrCast(val))[0..1], argc, argv, types),
+ .UNSIGNED_INT => |*val| set_array(u32, @as([*]u32, @ptrCast(val))[0..1], argc, argv, types),
+ .BOOL => |*val| set_array(u32, @as([*]u32, @ptrCast(val))[0..1], argc, argv, types),
.FLOAT_VEC2 => |*val| set_array(f32, val[0..], argc, argv, types),
.FLOAT_VEC3 => |*val| set_array(f32, val[0..], argc, argv, types),
.FLOAT_VEC4 => |*val| set_array(f32, val[0..], argc, argv, types),
@@ -171,32 +173,32 @@ pub const ControlServer = struct {
argv: [*c][*c]c.lo_arg,
argc: c_int,
msg: c.lo_message,
- userdata: ?*c_void,
+ userdata: ?*anyopaque,
) callconv(.C) c_int {
_ = msg;
- const self = @ptrCast(*ControlServer, @alignCast(@alignOf(ControlServer), userdata.?));
+ const self = @as(*ControlServer, @ptrCast(@alignCast(userdata.?)));
const path = _path[0..c.strlen(_path)];
- const types = _types[0..@intCast(u32, argc)];
+ const types = _types[0..@as(u32, @intCast(argc))];
if (!std.mem.startsWith(u8, path, "/")) {
- std.debug.warn("invalid OSC message {s} ({s})\n", .{ path, types });
+ std.debug.print("invalid OSC message {s} ({s})\n", .{ path, types });
return 1;
}
self.set_uniform(path[1..], argv, argc, types) catch |err| {
- std.debug.warn("{} while processing {s}\n", .{ err, path });
+ std.debug.print("{} while processing {s}\n", .{ err, path });
};
return 0;
}
- fn handle_bundle_start(time: c.lo_timetag, userdata: ?*c_void) callconv(.C) c_int {
+ fn handle_bundle_start(time: c.lo_timetag, userdata: ?*anyopaque) callconv(.C) c_int {
_ = time;
_ = userdata;
return 1;
}
- fn handle_bundle_end(userdata: ?*c_void) callconv(.C) c_int {
+ fn handle_bundle_end(userdata: ?*anyopaque) callconv(.C) c_int {
_ = userdata;
return 1;
}