Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ jobs:
name: Compilation Check
steps:
- uses: actions/checkout@v3
- uses: mlugg/setup-zig@v1
- uses: mlugg/setup-zig@v2
with:
version: 0.14.0
version: 0.15.0-dev.1034+bd97b6618
- run: sudo apt install libgl-dev libasound2-dev libx11-dev glslang-tools
- run: wget -O /opt/hostedtoolcache/zig/0.14.0/x64/lib/std/zig/render.zig https://github.com/PixelGuys/Cubyz-std-lib/releases/download/0.14.0/render.zig
- run: echo "zigPath=$(command -v zig | sed 's/.\{3\}$//')" >> $GITHUB_ENV
- run: wget -O $zigPath/lib/std/zig/render.zig https://github.com/PixelGuys/Cubyz-std-lib/releases/download/0.15.0-dev.1034+bd97b6618/render.zig
- run: zig build
- run: zig build -Dtarget=x86_64-windows-gnu
- run: zig build test
Expand Down
2 changes: 1 addition & 1 deletion .zig-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.0
0.15.0-dev.1034+bd97b6618
47 changes: 23 additions & 24 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn linkLibraries(b: *std.Build, exe: *std.Build.Step.Compile, useLocalDeps: bool
exe.addObjectFile(subPath.path(b, libName(b, "SPIRV-Tools-opt", t)));

if(t.os.tag == .windows) {
exe.linkSystemLibrary("crypt32");
exe.linkSystemLibrary("gdi32");
exe.linkSystemLibrary("opengl32");
exe.linkSystemLibrary("ws2_32");
Expand Down Expand Up @@ -168,15 +169,19 @@ pub fn build(b: *std.Build) !void {
.install_dir = .{.custom = ".."},
});

const exe = b.addExecutable(.{
.name = "Cubyzig",
const mainModule = b.addModule("main", .{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});

const exe = b.addExecutable(.{
.name = "Cubyzig",
.root_module = mainModule,
//.sanitize_thread = true,
//.use_llvm = false,
.use_llvm = true,
});
exe.root_module.addImport("main", exe.root_module);
exe.root_module.addImport("main", mainModule);
try addModFeatures(b, exe);

linkLibraries(b, exe, useLocalDeps);
Expand All @@ -193,13 +198,11 @@ pub fn build(b: *std.Build) !void {
run_step.dependOn(&run_cmd.step);

const exe_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.root_module = mainModule,
.test_runner = .{.path = b.path("test/runner.zig"), .mode = .simple},
.target = target,
.optimize = optimize,
});
linkLibraries(b, exe_tests, useLocalDeps);
exe_tests.root_module.addImport("main", exe_tests.root_module);
exe_tests.root_module.addImport("main", mainModule);
try addModFeatures(b, exe_tests);
const run_exe_tests = b.addRunArtifact(exe_tests);

Expand All @@ -210,16 +213,14 @@ pub fn build(b: *std.Build) !void {

const formatter = b.addExecutable(.{
.name = "CubyzigFormatter",
.root_source_file = b.path("src/formatter/format.zig"),
.target = target,
.optimize = optimize,
.root_module = b.addModule("format", .{
.root_source_file = b.path("src/formatter/format.zig"),
.target = target,
.optimize = optimize,
}),
});
// ZLS is stupid and cannot detect which executable is the main one, so we add the import everywhere...
formatter.root_module.addAnonymousImport("main", .{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
});
formatter.root_module.addImport("main", mainModule);

const formatter_install = b.addInstallArtifact(formatter, .{});

Expand All @@ -234,16 +235,14 @@ pub fn build(b: *std.Build) !void {

const zig_fmt = b.addExecutable(.{
.name = "zig_fmt",
.root_source_file = b.path("src/formatter/fmt.zig"),
.target = target,
.optimize = optimize,
.root_module = b.addModule("fmt", .{
.root_source_file = b.path("src/formatter/fmt.zig"),
.target = target,
.optimize = optimize,
}),
});
// ZLS is stupid and cannot detect which executable is the main one, so we add the import everywhere...
zig_fmt.root_module.addAnonymousImport("main", .{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
});
zig_fmt.root_module.addImport("main", mainModule);

const zig_fmt_install = b.addInstallArtifact(zig_fmt, .{});

Expand Down
2 changes: 1 addition & 1 deletion scripts/install_compiler_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ then
esac
fi

VERSION=zig-$OS-$ARCH-$BASE_VERSION
VERSION=zig-$ARCH-$OS-$BASE_VERSION

mkdir -p compiler/zig
touch compiler/version.txt
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_compiler_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ IF "%arch%"=="" (
set arch=x86_64
)

set version=zig-windows-%arch%-%baseVersion%
set version=zig-%arch%-windows-%baseVersion%

if not exist compiler mkdir compiler
if not exist compiler\version.txt copy NUL compiler\version.txt >NUL
Expand Down
6 changes: 3 additions & 3 deletions src/Inventory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub const Sync = struct { // MARK: Sync
const typ = try reader.readEnum(Command.PayloadType);
@setEvalBranchQuota(100000);
const payload: Command.Payload = switch(typ) {
inline else => |_typ| @unionInit(Command.Payload, @tagName(_typ), try std.meta.FieldType(Command.Payload, _typ).deserialize(reader, .server, source)),
inline else => |_typ| @unionInit(Command.Payload, @tagName(_typ), try @FieldType(Command.Payload, @tagName(_typ)).deserialize(reader, .server, source)),
};
executeCommand(payload, source);
}
Expand Down Expand Up @@ -2001,7 +2001,7 @@ pub fn save(self: Inventory, allocator: NeverFailingAllocator) ZonElement {
for(self._items, 0..) |stack, i| {
if(!stack.empty()) {
var buf: [1024]u8 = undefined;
zonObject.put(buf[0..std.fmt.formatIntBuf(&buf, i, 10, .lower, .{})], stack.store(allocator));
zonObject.put(buf[0..std.fmt.printInt(&buf, i, 10, .lower, .{})], stack.store(allocator));
}
}
return zonObject;
Expand All @@ -2011,7 +2011,7 @@ pub fn loadFromZon(self: Inventory, zon: ZonElement) void {
for(self._items, 0..) |*stack, i| {
stack.clear();
var buf: [1024]u8 = undefined;
const stackZon = zon.getChild(buf[0..std.fmt.formatIntBuf(&buf, i, 10, .lower, .{})]);
const stackZon = zon.getChild(buf[0..std.fmt.printInt(&buf, i, 10, .lower, .{})]);
if(stackZon == .object) {
stack.item = Item.init(stackZon) catch |err| {
const msg = stackZon.toStringEfficient(main.stackAllocator, "");
Expand Down
4 changes: 2 additions & 2 deletions src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ pub fn loadWorldAssets(assetFolder: []const u8, blockPalette: *Palette, itemPale
break :blk null;
}) |addon| {
if(addon.kind == .directory) {
const path = std.fmt.allocPrintZ(main.stackAllocator.allocator, "assets/{s}/blocks/textures", .{addon.name}) catch unreachable;
const path = std.fmt.allocPrintSentinel(main.stackAllocator.allocator, "assets/{s}/blocks/textures", .{addon.name}, 0) catch unreachable;
defer main.stackAllocator.free(path);
std.fs.cwd().access(path, .{}) catch continue;
main.utils.file_monitor.listenToPath(path, main.blocks.meshes.reloadTextures, 0);
Expand Down Expand Up @@ -680,7 +680,7 @@ pub fn unloadAssets() void { // MARK: unloadAssets()
break :blk null;
}) |addon| {
if(addon.kind == .directory) {
const path = std.fmt.allocPrintZ(main.stackAllocator.allocator, "assets/{s}/blocks/textures", .{addon.name}) catch unreachable;
const path = std.fmt.allocPrintSentinel(main.stackAllocator.allocator, "assets/{s}/blocks/textures", .{addon.name}, 0) catch unreachable;
defer main.stackAllocator.free(path);
std.fs.cwd().access(path, .{}) catch continue;
main.utils.file_monitor.removePath(path);
Expand Down
6 changes: 3 additions & 3 deletions src/audio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const AudioData = struct {
};
const addon = id[0..colonIndex];
const fileName = id[colonIndex + 1 ..];
const path1 = std.fmt.allocPrintZ(main.stackAllocator.allocator, "assets/{s}/music/{s}.ogg", .{addon, fileName}) catch unreachable;
const path1 = std.fmt.allocPrintSentinel(main.stackAllocator.allocator, "assets/{s}/music/{s}.ogg", .{addon, fileName}, 0) catch unreachable;
defer main.stackAllocator.free(path1);
var err: c_int = 0;
if(c.stb_vorbis_open_filename(path1.ptr, &err, null)) |ogg_stream| return ogg_stream;
const path2 = std.fmt.allocPrintZ(main.stackAllocator.allocator, "serverAssets/{s}/music/{s}.ogg", .{addon, fileName}) catch unreachable;
const path2 = std.fmt.allocPrintSentinel(main.stackAllocator.allocator, "serverAssets/{s}/music/{s}.ogg", .{addon, fileName}, 0) catch unreachable;
defer main.stackAllocator.free(path2);
if(c.stb_vorbis_open_filename(path2.ptr, &err, null)) |ogg_stream| return ogg_stream;
std.log.err("Couldn't find music with id \"{s}\". Searched path \"{s}\" and \"{s}\"", .{id, path1, path2});
Expand Down Expand Up @@ -309,7 +309,7 @@ fn miniaudioCallback(
output: ?*anyopaque,
input: ?*const anyopaque,
frameCount: u32,
) callconv(.C) void {
) callconv(.c) void {
_ = input;
_ = maDevice;
const valuesPerBuffer = 2*frameCount; // Stereo
Expand Down
29 changes: 15 additions & 14 deletions src/formatter/fmt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ pub fn main() !void {
}

// zig fmt: off
/// Everything below is a direct copy of fmt.zig from the zig compiler
/// Everything below is a direct copy of src/fmt.zig from the zig compiler

const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const process = std.process;
const Allocator = std.mem.Allocator;
const Color = std.zig.Color;
const fatal = std.process.fatal;

const usage_fmt =
\\Usage: zig fmt [file]...
Expand Down Expand Up @@ -63,7 +71,7 @@ pub fn run(
const arg = args[i];
if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
const stdout = std.io.getStdOut().writer();
const stdout = std.fs.File.stdout().deprecatedWriter();
try stdout.writeAll(usage_fmt);
return process.cleanExit();
} else if (mem.eql(u8, arg, "--color")) {
Expand Down Expand Up @@ -104,7 +112,7 @@ pub fn run(
fatal("cannot use --stdin with positional arguments", .{});
}

const stdin = std.io.getStdIn();
const stdin: fs.File = .stdin();
const source_code = std.zig.readSourceFileToEndAlloc(gpa, stdin, null) catch |err| {
fatal("unable to read stdin: {}", .{err});
};
Expand Down Expand Up @@ -157,7 +165,7 @@ pub fn run(
process.exit(code);
}

return std.io.getStdOut().writeAll(formatted);
return std.fs.File.stdout().writeAll(formatted);
}

if (input_files.items.len == 0) {
Expand Down Expand Up @@ -213,6 +221,7 @@ const FmtError = error{
DestinationAddressRequired,
DiskQuota,
FileTooBig,
MessageTooBig,
InputOutput,
NoSpaceLeft,
AccessDenied,
Expand Down Expand Up @@ -373,7 +382,7 @@ fn fmtPathFile(
return;

if (check_mode) {
const stdout = std.io.getStdOut().writer();
const stdout = std.fs.File.stdout().deprecatedWriter();
try stdout.print("{s}\n", .{file_path});
fmt.any_error = true;
} else {
Expand All @@ -382,15 +391,7 @@ fn fmtPathFile(

try af.file.writeAll(fmt.out_buffer.items);
try af.finish();
const stdout = std.io.getStdOut().writer();
const stdout = std.fs.File.stdout().deprecatedWriter();
try stdout.print("{s}\n", .{file_path});
}
}

const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const process = std.process;
const Allocator = std.mem.Allocator;
const Color = std.zig.Color;
const fatal = std.process.fatal;
5 changes: 3 additions & 2 deletions src/graphics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer
}

pub fn init(self: *Self, allocator: NeverFailingAllocator, size: u31, binding: c_uint) void {
self.used = 0;
self.binding = binding;
self.createBuffer(size);
self.activeFence = 0;
Expand Down Expand Up @@ -2512,7 +2513,7 @@ pub const Image = struct { // MARK: Image
pub fn readFromFile(allocator: NeverFailingAllocator, path: []const u8) !Image {
var result: Image = undefined;
var channel: c_int = undefined;
const nullTerminatedPath = std.fmt.allocPrintZ(main.stackAllocator.allocator, "{s}", .{path}) catch unreachable; // TODO: Find a more zig-friendly image loading library.
const nullTerminatedPath = main.stackAllocator.dupeZ(u8, path); // TODO: Find a more zig-friendly image loading library.
errdefer main.stackAllocator.free(nullTerminatedPath);
stb_image.stbi_set_flip_vertically_on_load(1);
const data = stb_image.stbi_load(nullTerminatedPath.ptr, @ptrCast(&result.width), @ptrCast(&result.height), &channel, 4) orelse {
Expand All @@ -2526,7 +2527,7 @@ pub const Image = struct { // MARK: Image
pub fn readUnflippedFromFile(allocator: NeverFailingAllocator, path: []const u8) !Image {
var result: Image = undefined;
var channel: c_int = undefined;
const nullTerminatedPath = std.fmt.allocPrintZ(main.stackAllocator.allocator, "{s}", .{path}) catch unreachable; // TODO: Find a more zig-friendly image loading library.
const nullTerminatedPath = main.stackAllocator.dupeZ(u8, path); // TODO: Find a more zig-friendly image loading library.
errdefer main.stackAllocator.free(nullTerminatedPath);
const data = stb_image.stbi_load(nullTerminatedPath.ptr, @ptrCast(&result.width), @ptrCast(&result.height), &channel, 4) orelse {
return error.FileNotFound;
Expand Down
16 changes: 8 additions & 8 deletions src/graphics/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ pub const Key = struct { // MARK: Key
};

pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
fn errorCallback(errorCode: c_int, description: [*c]const u8) callconv(.C) void {
fn errorCallback(errorCode: c_int, description: [*c]const u8) callconv(.c) void {
std.log.err("GLFW Error({}): {s}", .{errorCode, description});
}
fn keyCallback(_: ?*c.GLFWwindow, glfw_key: c_int, scancode: c_int, action: c_int, _mods: c_int) callconv(.C) void {
fn keyCallback(_: ?*c.GLFWwindow, glfw_key: c_int, scancode: c_int, action: c_int, _mods: c_int) callconv(.c) void {
const mods: Key.Modifiers = @bitCast(@as(u6, @intCast(_mods)));
if(!mods.control and main.gui.selectedTextInput != null and c.glfwGetKeyName(glfw_key, scancode) != null) return; // Don't send events for keys that are used in writing letters.
const isGrabbed = grabbed;
Expand Down Expand Up @@ -465,13 +465,13 @@ pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
}
}
}
fn charCallback(_: ?*c.GLFWwindow, codepoint: c_uint) callconv(.C) void {
fn charCallback(_: ?*c.GLFWwindow, codepoint: c_uint) callconv(.c) void {
if(!grabbed) {
main.gui.textCallbacks.char(@intCast(codepoint));
}
}

pub fn framebufferSize(_: ?*c.GLFWwindow, newWidth: c_int, newHeight: c_int) callconv(.C) void {
pub fn framebufferSize(_: ?*c.GLFWwindow, newWidth: c_int, newHeight: c_int) callconv(.c) void {
std.log.info("Framebuffer: {}, {}", .{newWidth, newHeight});
width = @intCast(newWidth);
height = @intCast(newHeight);
Expand All @@ -485,7 +485,7 @@ pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
var deltaBufferPosition: u2 = 0;
var currentPos: Vec2f = Vec2f{0, 0};
var ignoreDataAfterRecentGrab: bool = true;
fn cursorPosition(_: ?*c.GLFWwindow, x: f64, y: f64) callconv(.C) void {
fn cursorPosition(_: ?*c.GLFWwindow, x: f64, y: f64) callconv(.c) void {
const newPos = Vec2f{
@floatCast(x),
@floatCast(y),
Expand All @@ -509,7 +509,7 @@ pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
currentPos = newPos;
lastUsedMouse = true;
}
fn mouseButton(_: ?*c.GLFWwindow, button: c_int, action: c_int, _mods: c_int) callconv(.C) void {
fn mouseButton(_: ?*c.GLFWwindow, button: c_int, action: c_int, _mods: c_int) callconv(.c) void {
const mods: Key.Modifiers = @bitCast(@as(u6, @intCast(_mods)));
const isGrabbed = grabbed;
if(action == c.GLFW_PRESS or action == c.GLFW_RELEASE) {
Expand All @@ -526,11 +526,11 @@ pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
}
}
}
fn scroll(_: ?*c.GLFWwindow, xOffset: f64, yOffset: f64) callconv(.C) void {
fn scroll(_: ?*c.GLFWwindow, xOffset: f64, yOffset: f64) callconv(.c) void {
_ = xOffset;
scrollOffset += @floatCast(yOffset);
}
fn glDebugOutput(source: c_uint, typ: c_uint, _: c_uint, severity: c_uint, length: c_int, message: [*c]const u8, _: ?*const anyopaque) callconv(.C) void {
fn glDebugOutput(source: c_uint, typ: c_uint, _: c_uint, severity: c_uint, length: c_int, message: [*c]const u8, _: ?*const anyopaque) callconv(.c) void {
const sourceString: []const u8 = switch(source) {
c.GL_DEBUG_SOURCE_API => "API",
c.GL_DEBUG_SOURCE_APPLICATION => "Application",
Expand Down
8 changes: 4 additions & 4 deletions src/gui/components/TextInput.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ fn moveCursorLeft(self: *TextInput, mods: main.Window.Key.Modifiers) void {
if(self.cursor.? == 0) return;
self.cursor.? -= 1;
// Find end of previous "word":
while(!std.ascii.isAlphabetic(text[self.cursor.?]) and std.ascii.isASCII(text[self.cursor.?])) {
while(!std.ascii.isAlphabetic(text[self.cursor.?]) and std.ascii.isAscii(text[self.cursor.?])) {
if(self.cursor.? == 0) return;
self.cursor.? -= 1;
}
// Find the start of the previous "word":
while(std.ascii.isAlphabetic(text[self.cursor.?]) or !std.ascii.isASCII(text[self.cursor.?])) {
while(std.ascii.isAlphabetic(text[self.cursor.?]) or !std.ascii.isAscii(text[self.cursor.?])) {
if(self.cursor.? == 0) return;
self.cursor.? -= 1;
}
Expand Down Expand Up @@ -213,12 +213,12 @@ fn moveCursorRight(self: *TextInput, mods: main.Window.Key.Modifiers) void {
if(mods.control) {
const text = self.currentString.items;
// Find start of next "word":
while(!std.ascii.isAlphabetic(text[self.cursor.?]) and std.ascii.isASCII(text[self.cursor.?])) {
while(!std.ascii.isAlphabetic(text[self.cursor.?]) and std.ascii.isAscii(text[self.cursor.?])) {
self.cursor.? += 1;
if(self.cursor.? >= self.currentString.items.len) return;
}
// Find the end of the next "word":
while(std.ascii.isAlphabetic(text[self.cursor.?]) or !std.ascii.isASCII(text[self.cursor.?])) {
while(std.ascii.isAlphabetic(text[self.cursor.?]) or !std.ascii.isAscii(text[self.cursor.?])) {
self.cursor.? += 1;
if(self.cursor.? >= self.currentString.items.len) return;
}
Expand Down
Loading