Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
77dd634
list printing and other small stuff
IntegratedQuantum Oct 14, 2025
562324f
Compression, but someone squashed all my mistakes
IntegratedQuantum Oct 14, 2025
f9b4834
The scary Io update
IntegratedQuantum Nov 21, 2025
cc4382b
Update .zigversion and scripts
IntegratedQuantum Nov 22, 2025
35fc3a1
fix network hostname lookup code
IntegratedQuantum Nov 22, 2025
169cf14
Always use the same version formatter as the zig version
IntegratedQuantum Nov 22, 2025
1e6c8b2
Actually, we should hardcode the version there, so we can update the …
IntegratedQuantum Nov 22, 2025
0f2c6c0
aligncast comes first
IntegratedQuantum Nov 22, 2025
16d29ac
fix windows socket problems
IntegratedQuantum Nov 22, 2025
7d00d0d
Disable aarch64-windows target in the CI
IntegratedQuantum Nov 22, 2025
3a1956b
Update test runner dependency
IntegratedQuantum Nov 22, 2025
c44b3e9
Remove commented line in release.yml which seems to break everything
IntegratedQuantum Nov 22, 2025
611b15c
Fix the formatter
IntegratedQuantum Nov 22, 2025
a56318d
Switch to real time on windows
IntegratedQuantum Nov 23, 2025
942738b
Make the controller code work again
IntegratedQuantum Nov 23, 2025
37e7f08
Switch run to ReleaseFast since ReleaseSafe doesn't compile
IntegratedQuantum Nov 23, 2025
71490a9
Reinstate ReleaseSafe on Linux
IntegratedQuantum Nov 23, 2025
fc4df86
unintended change
IntegratedQuantum Nov 23, 2025
a05ca39
Fix the advanced controls slider range
IntegratedQuantum Nov 23, 2025
96fdc11
I remember now why this needs to use fast compression
IntegratedQuantum Nov 23, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
version: ${{ env.VERSION }}
- run: sudo apt install glslang-tools
- run: wget -O ./Cubyz-fmt https://github.com/PixelGuys/Cubyz-formatter/releases/download/0.15.0-dev.1034%2Bbd97b6618/Cubyz-fmt-x86_64-linux
- run: wget -O ./Cubyz-fmt https://github.com/PixelGuys/Cubyz-formatter/releases/download/0.16.0-dev.1424+d3e20e71b/Cubyz-fmt-x86_64-linux
- run: chmod +x ./Cubyz-fmt
- run: |
if ./Cubyz-fmt *.zig src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig src/*/*/*/*/*.zig src/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*/*/*.zig src/*/*/*/*/*/*/*/*/*/*.zig | grep -q . ; then
Expand All @@ -44,7 +44,7 @@ jobs:
- run: zig build
- run: zig build -Dtarget=x86_64-windows-gnu
- run: zig build -Dtarget=aarch64-linux-gnu
- run: zig build -Dtarget=aarch64-windows-gnu
# - run: zig build -Dtarget=aarch64-windows-gnu
- run: zig build test
- run: zig build format --summary none
- run: find assets/cubyz/shaders -type f | xargs -L1 glslangValidator -G100
9 changes: 4 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
- run: tar -czf Windows-x86_64.tar.gz --transform 's,^,Cubyz/,' assets/cubyz launchConfig.zon -C zig-out/bin Cubyz.exe
- run: tar -xf Windows-x86_64.tar.gz && zip -r Windows-x86_64.zip Cubyz && rm -r Cubyz

- run: zig build -Dtarget=aarch64-windows-gnu -Doptimize=ReleaseFast -Drelease=true -Dcpu=baseline
- run: tar -czf Windows-aarch64.tar.gz --transform 's,^,Cubyz/,' assets/cubyz launchConfig.zon -C zig-out/bin Cubyz.exe
- run: tar -xf Windows-aarch64.tar.gz && zip -r Windows-aarch64.zip Cubyz && rm -r Cubyz
# - run: zig build -Dtarget=aarch64-windows-gnu -Doptimize=ReleaseFast -Drelease=true -Dcpu=baseline
# - run: tar -czf Windows-aarch64.tar.gz --transform 's,^,Cubyz/,' assets/cubyz launchConfig.zon -C zig-out/bin Cubyz.exe
# - run: tar -xf Windows-aarch64.tar.gz && zip -r Windows-aarch64.zip Cubyz && rm -r Cubyz

- name: Create release
env:
Expand All @@ -43,6 +43,5 @@ jobs:
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
Linux-x86_64.tar.gz \
Linux-aarch64.tar.gz \
Windows-x86_64.zip \
Windows-aarch64.zip
Windows-x86_64.zip
gh release
2 changes: 1 addition & 1 deletion .zigversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.15.0-dev.1034+bd97b6618
0.16.0-dev.1424+d3e20e71b
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
.hash = "N-V-__8AACQYrweKK0-hEabTekSwmGwxKrIbdY_2QTOEA7TN",
},
.cubyz_test_runner = .{
.url = "https://github.com/PixelGuys/Cubyz-std-lib/archive/refs/tags/0.15.0-dev.1034+bd97b6618+runner-build.zig.tar.gz",
.hash = "zig-0.0.0-Fp4XJConDA0olqTe3d3oYNH6UOlQb_jIZ0YOWKZGHLYQ",
.url = "https://github.com/PixelGuys/Cubyz-std-lib/archive/refs/tags/0.16.0-dev.1424+1.tar.gz",
.hash = "zig-0.0.0-Fp4XJAXmXQ1r23tqehV14LpPFILnnXSyg7bPitqs8mrf",
.lazy = true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion debug_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi

echo "Building Zig Cubyz ($@) from source. This may take a few minutes..."

./compiler/zig/zig build --prominent-compile-errors "$@"
./compiler/zig/zig build --error-style minimal "$@"

if [ $? != 0 ]
then
Expand Down
2 changes: 1 addition & 1 deletion debug_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if errorlevel 1 (

echo Building Zig Cubyz (%*^) from source. This may take a few minutes...

compiler\zig\zig build --prominent-compile-errors %*
compiler\zig\zig build --error-style minimal %*

if errorlevel 1 (
exit /b 1
Expand Down
2 changes: 1 addition & 1 deletion run_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cd /D "%~dp0"

call debug_windows.bat -Doptimize=ReleaseSafe %*
call debug_windows.bat -Doptimize=ReleaseFast %*

IF "%NO_PAUSE%" == "" (
echo Press enter key to continue. (Or set NO_PAUSE=1 to skip this prompt.^)
Expand Down
3 changes: 1 addition & 2 deletions src/audio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const main = @import("main");
const utils = main.utils;

const c = @cImport({
@cDefine("_BITS_STDIO2_H", ""); // TODO: Zig fails to include this header file
@cInclude("miniaudio.h");
@cDefine("STB_VORBIS_HEADER_ONLY", "");
@cInclude("stb/stb_vorbis.h");
Expand Down Expand Up @@ -192,7 +193,6 @@ pub fn init() error{miniaudioError}!void {
try handleError(c.ma_device_start(&device));

sampleRate = 44100;
lastTime = std.time.milliTimestamp();
}

pub fn deinit() void {
Expand Down Expand Up @@ -239,7 +239,6 @@ const currentMusic = struct {
};

var activeMusicId: []const u8 = &.{};
var lastTime: i64 = 0;
var partialFrame: f32 = 0;
const animationLengthInSeconds = 5.0;

Expand Down
2 changes: 1 addition & 1 deletion src/entity.zig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub const ClientEntityManager = struct {

fn update() void {
main.utils.assertLocked(&mutex);
var time: i16 = @truncate(std.time.milliTimestamp() -% settings.entityLookback);
var time: i16 = @truncate(main.timestamp().toMilliseconds() -% settings.entityLookback);
time -%= timeDifference.difference.load(.monotonic);
for(entities.items()) |*ent| {
ent.update(time, lastTime);
Expand Down
2 changes: 1 addition & 1 deletion src/files.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub const Dir = struct {
}

pub fn read(self: Dir, allocator: NeverFailingAllocator, path: []const u8) ![]u8 {
return self.dir.readFileAlloc(allocator.allocator, path, std.math.maxInt(usize));
return self.dir.readFileAlloc(path, allocator.allocator, .unlimited);
}

pub fn readToZon(self: Dir, allocator: NeverFailingAllocator, path: []const u8) !ZonElement {
Expand Down
10 changes: 5 additions & 5 deletions src/formatter/format.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ fn printError(msg: []const u8, filePath: []const u8, data: []const u8, charIndex
}
}

var startLineChars = std.ArrayList(u8).init(globalAllocator);
defer startLineChars.deinit();
var startLineChars: std.ArrayList(u8) = .{};
defer startLineChars.deinit(globalAllocator);
for(data[lineStart..charIndex]) |c| {
if(c == '\t') {
startLineChars.append('\t') catch {};
startLineChars.append(globalAllocator, '\t') catch {};
} else {
startLineChars.append(' ') catch {};
startLineChars.append(globalAllocator, ' ') catch {};
}
}

Expand All @@ -38,7 +38,7 @@ fn printError(msg: []const u8, filePath: []const u8, data: []const u8, charIndex
}

fn checkFile(dir: std.fs.Dir, filePath: []const u8) !void {
const data = try dir.readFileAlloc(globalAllocator, filePath, std.math.maxInt(usize));
const data = try dir.readFileAlloc(filePath, globalAllocator, .unlimited);
defer globalAllocator.free(data);

var lineStart: bool = true;
Expand Down
26 changes: 13 additions & 13 deletions src/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ pub const World = struct { // MARK: World
.conn = try Connection.init(manager, ip, null),
.manager = manager,
.name = "client",
.milliTime = std.time.milliTimestamp(),
.milliTime = main.timestamp().toMilliseconds(),
};
errdefer self.conn.deinit();

Expand Down Expand Up @@ -737,7 +737,7 @@ pub const World = struct { // MARK: World
}

pub fn update(self: *World) void {
const newTime: i64 = std.time.milliTimestamp();
const newTime: i64 = main.timestamp().toMilliseconds();
while(self.milliTime +% 100 -% newTime < 0) {
self.milliTime +%= 100;
var curTime = self.gameTime.load(.monotonic);
Expand Down Expand Up @@ -765,12 +765,12 @@ pub var projectionMatrix: Mat4f = Mat4f.identity();
var biomeFog = Fog{.skyColor = .{0.8, 0.8, 1}, .fogColor = .{0.8, 0.8, 1}, .density = 1.0/15.0/128.0, .fogLower = 100, .fogHigher = 1000};
pub var fog = Fog{.skyColor = .{0.8, 0.8, 1}, .fogColor = .{0.8, 0.8, 1}, .density = 1.0/15.0/128.0, .fogLower = 100, .fogHigher = 1000};

var nextBlockPlaceTime: ?i64 = null;
var nextBlockBreakTime: ?i64 = null;
var nextBlockPlaceTime: ?std.Io.Timestamp = null;
var nextBlockBreakTime: ?std.Io.Timestamp = null;

pub fn pressPlace(mods: main.Window.Key.Modifiers) void {
const time = std.time.milliTimestamp();
nextBlockPlaceTime = time + main.settings.updateRepeatDelay;
const time = main.timestamp();
nextBlockPlaceTime = time.addDuration(main.settings.updateRepeatDelay);
Player.placeBlock(mods);
}

Expand All @@ -779,8 +779,8 @@ pub fn releasePlace(_: main.Window.Key.Modifiers) void {
}

pub fn pressBreak(_: main.Window.Key.Modifiers) void {
const time = std.time.milliTimestamp();
nextBlockBreakTime = time + main.settings.updateRepeatDelay;
const time = main.timestamp();
nextBlockBreakTime = time.addDuration(main.settings.updateRepeatDelay);
Player.breakBlock(0);
}

Expand Down Expand Up @@ -972,16 +972,16 @@ pub fn update(deltaTime: f64) void { // MARK: update()

physics.update(deltaTime, acc, jumping);

const time = std.time.milliTimestamp();
const time = main.timestamp();
if(nextBlockPlaceTime) |*placeTime| {
if(time -% placeTime.* >= 0) {
placeTime.* += main.settings.updateRepeatSpeed;
if(placeTime.durationTo(time).nanoseconds >= 0) {
placeTime.* = placeTime.addDuration(main.settings.updateRepeatSpeed);
Player.placeBlock(main.KeyBoard.key("placeBlock").modsOnPress);
}
}
if(nextBlockBreakTime) |*breakTime| {
if(time -% breakTime.* >= 0 or !Player.isCreative()) {
breakTime.* += main.settings.updateRepeatSpeed;
if(breakTime.durationTo(time).nanoseconds >= 0 or !Player.isCreative()) {
breakTime.* = breakTime.addDuration(main.settings.updateRepeatSpeed);
Player.breakBlock(deltaTime);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/graphics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const std = @import("std");

pub const hbft = @cImport({
@cDefine("_BITS_STDIO2_H", ""); // TODO: Zig fails to include this header file
@cInclude("freetype/ftadvanc.h");
@cInclude("freetype/ftbbox.h");
@cInclude("freetype/ftbitmap.h");
Expand Down Expand Up @@ -35,6 +36,7 @@ pub const c = @cImport({
});

pub const stb_image = @cImport({
@cDefine("_BITS_STDIO2_H", ""); // TODO: Zig fails to include this header file
@cInclude("stb/stb_image.h");
@cInclude("stb/stb_image_write.h");
});
Expand Down Expand Up @@ -1930,10 +1932,10 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer
pub fn beginRender(self: *Self) void {
self.activeFence += 1;
if(self.activeFence == self.fences.len) self.activeFence = 0;
const startTime = std.time.milliTimestamp();
const endTime = main.timestamp().addDuration(.fromMilliseconds(5));
while(self.fencedFreeLists[self.activeFence].popOrNull()) |allocation| {
self.finalFree(allocation);
if(std.time.milliTimestamp() -% startTime > 5) break; // TODO: Remove after #1434
if(main.timestamp().durationTo(endTime).nanoseconds > 0) break; // TODO: Remove after #1434
}
_ = c.glClientWaitSync(self.fences[self.activeFence], 0, c.GL_TIMEOUT_IGNORED); // Make sure the render calls that accessed these parts of the buffer have finished.
}
Expand Down
16 changes: 8 additions & 8 deletions src/graphics/Window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ pub const Gamepad = struct {
pub fn run(self: *ControllerMappingDownloadTask) void {
std.log.info("Starting controller mapping download...", .{});
defer self.clean();
var client: std.http.Client = .{.allocator = main.stackAllocator.allocator};
var client: std.http.Client = .{.allocator = main.stackAllocator.allocator, .io = main.io};
defer client.deinit();
var list = std.ArrayList(u8).init(main.stackAllocator.allocator);
defer list.deinit();
var writer = std.Io.Writer.Allocating.init(main.stackAllocator.allocator);
defer writer.deinit();
defer controllerMappingsDownloaded.store(true, std.builtin.AtomicOrder.release);
const fetchResult = client.fetch(.{
.method = .GET,
.location = .{.url = "https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/master/gamecontrollerdb.txt"},
.response_storage = .{.dynamic = &list},
.response_writer = &writer.writer,
}) catch |err| {
std.log.err("Failed to download controller mappings: {s}", .{@errorName(err)});
return;
Expand All @@ -184,7 +184,7 @@ pub const Gamepad = struct {
std.log.err("Failed to download controller mappings: HTTP error {d}", .{@intFromEnum(fetchResult.status)});
return;
}
files.cwd().write("./gamecontrollerdb.txt", list.items) catch |err| {
files.cwd().write("./gamecontrollerdb.txt", writer.written()) catch |err| {
std.log.err("Failed to write controller mappings: {s}", .{@errorName(err)});
return;
};
Expand All @@ -206,11 +206,11 @@ pub const Gamepad = struct {
pub fn downloadControllerMappings() void {
if(builtin.mode == .Debug) return; // TODO: The http fetch adds ~5 seconds to the compile time, so it's disabled in debug mode, see #24435
var needsDownload: bool = false;
const curTimestamp = std.time.nanoTimestamp();
const timestamp: i128 = blk: {
const curTimestamp: i96 = (std.Io.Clock.Timestamp.now(main.io, .real) catch unreachable).raw.nanoseconds;
const timestamp: i96 = blk: {
const stamp = files.cwd().read(main.stackAllocator, "./gamecontrollerdb.stamp") catch break :blk 0;
defer main.stackAllocator.free(stamp);
break :blk std.fmt.parseInt(i128, stamp, 16) catch 0;
break :blk std.fmt.parseInt(i96, stamp, 16) catch 0;
};
const delta = curTimestamp -% timestamp;
needsDownload = delta >= 7*std.time.ns_per_day;
Expand Down
12 changes: 6 additions & 6 deletions src/gui/components/TextInput.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TextInput = @This();
const scrollBarWidth = 5;
const border: f32 = 3;
const fontSize: f32 = 16;
const blinkDurationMs: i64 = 500;
const blinkDuration: std.Io.Duration = .fromMilliseconds(500);

var texture: Texture = undefined;

Expand All @@ -35,7 +35,7 @@ textSize: Vec2f = undefined,
scrollBar: *ScrollBar,
onNewline: gui.Callback,
optional: OptionalCallbacks,
lastBlinkTime: i64 = 0,
lastBlinkTime: std.Io.Timestamp = .fromNanoseconds(0),
showCusor: bool = true,

pub fn __init() void {
Expand Down Expand Up @@ -477,7 +477,7 @@ pub fn newline(self: *TextInput, mods: main.Window.Key.Modifiers) void {

fn ensureCursorVisibility(self: *TextInput) void {
self.showCusor = true;
self.lastBlinkTime = std.time.milliTimestamp();
self.lastBlinkTime = main.timestamp();
if(self.textSize[1] > self.maxHeight - 2*border) {
var y: f32 = 0;
const diff = self.textSize[1] - (self.maxHeight - 2*border);
Expand Down Expand Up @@ -521,9 +521,9 @@ pub fn render(self: *TextInput, mousePosition: Vec2f) void {
self.textBuffer.drawSelection(textPos, @min(selectionStart, cursor), @max(selectionStart, cursor));
}

const milliTime = std.time.milliTimestamp();
if(milliTime -% self.lastBlinkTime > blinkDurationMs) {
self.lastBlinkTime = milliTime;
const currentTime = main.timestamp();
if(self.lastBlinkTime.durationTo(currentTime).nanoseconds > blinkDuration.nanoseconds) {
self.lastBlinkTime = currentTime;
self.showCusor = !self.showCusor;
}

Expand Down
16 changes: 8 additions & 8 deletions src/gui/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,10 @@ pub const inventory = struct { // MARK: inventory
var rightClickSlots: List(*ItemSlot) = .init(main.globalAllocator);
var recipeItem: ?main.items.Item = null;
var initialized: bool = false;
const minCraftingCooldown = 20;
const maxCraftingCooldown = 400;
var nextCraftingAction: i64 = undefined;
var craftingCooldown: u63 = undefined;
const minCraftingCooldown: std.Io.Duration = .fromMilliseconds(20);
const maxCraftingCooldown: std.Io.Duration = .fromMilliseconds(400);
var nextCraftingAction: std.Io.Timestamp = undefined;
var craftingCooldown: std.Io.Duration = undefined;
var isCrafting: bool = false;

pub fn init() void {
Expand Down Expand Up @@ -663,15 +663,15 @@ pub const inventory = struct { // MARK: inventory
const item = itemSlot.inventory.getItem(itemSlot.itemSlot);
if(recipeItem == null and item != null) recipeItem = item.?.clone();
if(!std.meta.eql(item, recipeItem)) return;
const time = std.time.milliTimestamp();
const time = main.timestamp();
if(!isCrafting) {
isCrafting = true;
craftingCooldown = maxCraftingCooldown;
nextCraftingAction = time;
}
while(time -% nextCraftingAction >= 0) {
nextCraftingAction +%= craftingCooldown;
craftingCooldown -= (craftingCooldown - minCraftingCooldown)*craftingCooldown/1000;
while(time.durationTo(nextCraftingAction).nanoseconds <= 0) {
nextCraftingAction = nextCraftingAction.addDuration(craftingCooldown);
craftingCooldown.nanoseconds -= @divTrunc((craftingCooldown.nanoseconds - minCraftingCooldown.nanoseconds)*craftingCooldown.nanoseconds, 1000);
if(mainGuiButton.modsOnPress.shift) {
itemSlot.inventory.depositToAny(itemSlot.itemSlot, main.game.Player.inventory, itemSlot.inventory.getAmount(itemSlot.itemSlot));
} else {
Expand Down
Loading