Skip to content

Commit b7b31f5

Browse files
committed
Upgrade to Zig v0.15.1
1 parent 109d96f commit b7b31f5

3 files changed

Lines changed: 28 additions & 22 deletions

File tree

build.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void {
1313

1414
const doom = b.addExecutable(.{
1515
.name = "terminal-doom",
16-
.root_source_file = b.path("src/main.zig"),
17-
.target = target,
18-
.optimize = optimize,
16+
.root_module = b.createModule(.{
17+
.root_source_file = b.path("src/main.zig"),
18+
.target = target,
19+
.optimize = optimize,
20+
}),
1921
});
2022
doom.root_module.addImport("vaxis", vaxis.module("vaxis"));
2123

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.version = "0.1.0",
44
.dependencies = .{
55
.vaxis = .{
6-
.url = "git+https://github.com/rockorager/libvaxis?ref=main#c49abb48241e11682b7b8b05c79d20773f1ded98",
7-
.hash = "vaxis-0.1.0-BWNV_JEMCQBskZQsnlzh6GoyHSDgOi41bCoZIB2pW-E7",
6+
.url = "git+https://github.com/rockorager/libvaxis?ref=main#6eb16bb4190dc074dafaf4f0ce7dadd50e81192a",
7+
.hash = "vaxis-0.5.1-BWNV_BMgCQDXdZzABeY4F_xwgE7nHFtYEP07KgEwJWo8",
88
},
99
},
1010
.paths = .{

src/main.zig

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ const event_t = extern struct {
4949
var state: State = undefined;
5050

5151
// Called by Doom on startup; not needed in our case
52-
pub export fn DG_Init() callconv(.C) void {}
52+
pub export fn DG_Init() callconv(.c) void {}
5353

5454
// Called by doomgeneric to draw a single frame
55-
pub export fn DG_DrawFrame() callconv(.C) void {
55+
pub export fn DG_DrawFrame() callconv(.c) void {
5656
// We need to have a window size before continuing
5757
const win = state.loop.vaxis.window();
5858
if (win.screen.width == 0) {
5959
while (state.loop.tryEvent()) |event| {
6060
switch (event) {
61-
.winsize => |ws| state.loop.vaxis.resize(std.heap.c_allocator, state.loop.tty.anyWriter(), ws) catch unreachable,
61+
.winsize => |ws| state.loop.vaxis.resize(std.heap.c_allocator, state.loop.tty.writer(), ws) catch unreachable,
6262
else => {},
6363
}
6464
}
@@ -73,7 +73,7 @@ pub export fn DG_DrawFrame() callconv(.C) void {
7373
};
7474

7575
// Write the image pixels using the Kitty image protocol
76-
const img = state.loop.vaxis.transmitImage(std.heap.c_allocator, state.loop.tty.anyWriter(), &pixels, .rgb) catch unreachable;
76+
const img = state.loop.vaxis.transmitImage(std.heap.c_allocator, state.loop.tty.writer(), &pixels, .rgb) catch unreachable;
7777

7878
// Image size measured in cells
7979
const cell_size = img.cellSize(win) catch unreachable;
@@ -174,11 +174,11 @@ pub export fn DG_DrawFrame() callconv(.C) void {
174174
D_PostEvent(&doom_event);
175175
}
176176
},
177-
.winsize => |ws| state.loop.vaxis.resize(std.heap.c_allocator, state.loop.tty.anyWriter(), ws) catch unreachable,
177+
.winsize => |ws| state.loop.vaxis.resize(std.heap.c_allocator, state.loop.tty.writer(), ws) catch unreachable,
178178
}
179179
}
180180

181-
state.loop.vaxis.render(state.loop.tty.anyWriter()) catch unreachable;
181+
state.loop.vaxis.render(state.loop.tty.writer()) catch unreachable;
182182
}
183183

184184
fn accelerateMouse(delta: c_int, clamp: f32) c_int {
@@ -187,17 +187,17 @@ fn accelerateMouse(delta: c_int, clamp: f32) c_int {
187187
}
188188

189189
/// Called by Doom when it needs to sleep
190-
pub export fn DG_SleepMs(ms: c_uint) callconv(.C) void {
191-
std.time.sleep(ms * std.time.ns_per_ms);
190+
pub export fn DG_SleepMs(ms: c_uint) callconv(.c) void {
191+
std.Thread.sleep(ms * std.time.ns_per_ms);
192192
}
193193

194194
/// Called by Doom to get milliseconds passed since startup
195-
pub export fn DG_GetTicksMs() callconv(.C) u32 {
195+
pub export fn DG_GetTicksMs() callconv(.c) u32 {
196196
return @intCast(std.time.milliTimestamp() - state.startup);
197197
}
198198

199199
/// Called by Doom to pull a keypress from the queue. Returns 0 if the queue is empty.
200-
pub export fn DG_GetKey(pressed: [*c]c_int, doom_key: [*c]u8) callconv(.C) c_int {
200+
pub export fn DG_GetKey(pressed: [*c]c_int, doom_key: [*c]u8) callconv(.c) c_int {
201201
if (state.key_queue_read_idx != state.key_queue_write_idx) {
202202
const key_data = state.key_queue[state.key_queue_read_idx];
203203
state.key_queue_read_idx +%= 1;
@@ -209,7 +209,7 @@ pub export fn DG_GetKey(pressed: [*c]c_int, doom_key: [*c]u8) callconv(.C) c_int
209209
}
210210

211211
/// Called by Doom to set window title. Not used.
212-
pub export fn DG_SetWindowTitle(title: [*c]const u8) callconv(.C) void {
212+
pub export fn DG_SetWindowTitle(title: [*c]const u8) callconv(.c) void {
213213
_ = title;
214214
}
215215

@@ -232,16 +232,20 @@ pub fn main() !void {
232232
// Use the C allocator for speed
233233
const alloc = std.heap.c_allocator;
234234
const envmap = try std.process.getEnvMap(alloc);
235+
var stderr_buffer: [1024]u8 = undefined;
236+
var stderr_writer = std.fs.File.stderr().writer(&stderr_buffer);
237+
const stderr = &stderr_writer.interface;
235238
if (envmap.get("TMUX")) |_| {
236-
try std.io.getStdErr().writer().print("Terminal Doom can not run under tmux\n", .{});
239+
try stderr.print("Terminal Doom can not run under tmux\n", .{});
237240
std.process.exit(1);
238241
}
239242

240-
var tty = try vaxis.Tty.init();
243+
var tty_buffer: [1024]u8 = undefined;
244+
var tty = try vaxis.Tty.init(&tty_buffer);
241245
defer tty.deinit();
242246

243247
var vx = try vaxis.init(alloc, .{ .kitty_keyboard_flags = .{ .report_events = true } });
244-
defer vx.deinit(alloc, tty.anyWriter());
248+
defer vx.deinit(alloc, tty.writer());
245249

246250
state = .{
247251
.key_queue = [_]u16{0} ** 32,
@@ -259,9 +263,9 @@ pub fn main() !void {
259263
try state.loop.start();
260264
defer state.loop.stop();
261265

262-
try vx.enterAltScreen(tty.anyWriter());
263-
try vx.queryTerminal(tty.anyWriter(), 1 * std.time.ns_per_s);
264-
try vx.setMouseMode(tty.anyWriter(), true);
266+
try vx.enterAltScreen(tty.writer());
267+
try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s);
268+
try vx.setMouseMode(tty.writer(), true);
265269

266270
const args = try std.process.argsAlloc(alloc);
267271

0 commit comments

Comments
 (0)