Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.16.0+0/Cubyz-fmt-x86_64-linux
- run: wget -O ./Cubyz-fmt https://github.com/PixelGuys/Cubyz-formatter/releases/download/0.17.0+0/Cubyz-fmt-x86_64-linux
- run: chmod +x ./Cubyz-fmt
- run: |
shopt -s nullglob
Expand All @@ -31,7 +31,7 @@ jobs:
git diff --color=always;
exit 1;
fi
- run: wget -O ./Cubyz-linter https://github.com/PixelGuys/Cubyz-linter/releases/download/0.16.0+6/Cubyz-linter-x86_64-linux
- run: wget -O ./Cubyz-linter https://github.com/PixelGuys/Cubyz-linter/releases/download/0.17.0+0/Cubyz-linter-x86_64-linux
- run: chmod +x ./Cubyz-linter
- run: ./Cubyz-linter assets/ mods/ src/ *.zon
- run: 'find assets/cubyz/shaders -type f ! -name "*.glsl" | xargs -L1 glslangValidator -G100 -P"#extension GL_GOOGLE_include_directive : enable" -Iassets/cubyz/shaders/include -Dgl_VertexIndex=gl_VertexID -DOPEN_GL'
Expand Down
2 changes: 1 addition & 1 deletion .zigversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.0
0.17.0
4 changes: 1 addition & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ pub fn build(b: *std.Build) !void {

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
run_cmd.addPassthruArgs();

const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
Expand Down
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-__8AABst_gbWhL_Rl--L4bUSOeu2484UhidGfW1DNlOJ",
},
.cubyz_test_runner = .{
.url = "https://github.com/PixelGuys/Cubyz-std-lib/archive/refs/tags/0.16.0+1.tar.gz",
.hash = "zig-0.0.0-Fp4XJG_h5A3OLpPXqVTJ1DRl3lZhqHp_fClrI7MUVjU_",
.url = "https://github.com/PixelGuys/Cubyz-std-lib/archive/refs/tags/0.17.0+0.tar.gz",
.hash = "zig-0.0.0-Fp4XJHPdSQ6qeLlHt5m6z6F4LAZbP4F8mJqo6ufkkqvX",
.lazy = true,
},
},
Expand Down
6 changes: 3 additions & 3 deletions mods/cubyz/rotations/branch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn rotateQuad(originalCorners: [4]Vec2f, pattern: Pattern, min: f32, max: f32, s
switch (pattern) {
.dot, .cross => {},
inline else => |typ| {
const angle: f32 = @as(f32, @floatFromInt(@intFromEnum(typ)))*std.math.pi/2.0;
const angle: f32 = @as(f32, @floatFromInt(@backingInt(typ)))*std.math.pi/2.0;
corners = .{
vec.rotate2d(originalCorners[0], angle, @splat(0.5)),
vec.rotate2d(originalCorners[1], angle, @splat(0.5)),
Expand Down Expand Up @@ -119,7 +119,7 @@ fn rotateQuad(originalCorners: [4]Vec2f, pattern: Pattern, min: f32, max: f32, s
},
.cornerUV = .{originalCorners[0], originalCorners[1], originalCorners[2], originalCorners[3]},
.normal = @as(Vec3f, @floatFromInt(side.relPos())),
.textureSlot = textureSlotOffset + @intFromEnum(pattern),
.textureSlot = textureSlotOffset + @backingInt(pattern),
};

return res;
Expand Down Expand Up @@ -360,7 +360,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
const rotationIndex = (data & 0b111100) >> 2;
const upDownFlags = data & 0b000011;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][rotationIndex] | upDownFlags;
return runtimeTable[@backingInt(angle)][rotationIndex] | upDownFlags;
}

pub fn generateData(
Expand Down
2 changes: 1 addition & 1 deletion mods/cubyz/rotations/carpet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
};
if (data >= 64) return 0;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
return runtimeTable[@backingInt(angle)][data];
}

pub fn init() void {
Expand Down
6 changes: 3 additions & 3 deletions mods/cubyz/rotations/direction.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
};
comptime for (1..4) |a| {
for (0..6) |i| {
const neighbor: Neighbor = @enumFromInt(rotationTable[a - 1][i]);
const neighbor: Neighbor = @fromBackingInt(rotationTable[a - 1][i]);
rotationTable[a][i] = neighbor.rotateZ().toInt();
}
};
if (data >= 6) return 0;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
return runtimeTable[@backingInt(angle)][data];
}

pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i, neighbor: ?Neighbor, currentData: *Block, _: Block, blockPlacing: bool) bool {
Expand All @@ -78,5 +78,5 @@ pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i,

pub fn updateBlockFromNeighborConnectivity(block: *Block, neighborSupportive: [6]bool) void {
if (block.data >= 6) return;
if (!neighborSupportive[@as(Neighbor, @enumFromInt(block.data)).reverse().toInt()]) block.* = .air;
if (!neighborSupportive[@as(Neighbor, @fromBackingInt(@intCast(block.data))).reverse().toInt()]) block.* = .air;
}
2 changes: 1 addition & 1 deletion mods/cubyz/rotations/fence.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
};
if (data >= 16) return 0;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
return runtimeTable[@backingInt(angle)][data];
}

fn fenceTransform(quad: *main.models.QuadInfo, data: FenceData) void {
Expand Down
6 changes: 3 additions & 3 deletions mods/cubyz/rotations/log.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn rotateQuad(pattern: Pattern, side: Neighbor) main.models.QuadInfo {
switch (pattern) {
.dot, .cross, .cut => {},
.line => |dir| {
var angle: f32 = @as(f32, @floatFromInt(@intFromEnum(dir)))*std.math.pi/2.0;
var angle: f32 = @as(f32, @floatFromInt(@backingInt(dir)))*std.math.pi/2.0;
if (side.relZ() != 0) {
angle *= -1;
}
Expand All @@ -89,7 +89,7 @@ fn rotateQuad(pattern: Pattern, side: Neighbor) main.models.QuadInfo {
.bend, .intersection => |dir| {
corners = originalCorners;

const angle: f32 = -@as(f32, @floatFromInt(@intFromEnum(dir)))*std.math.pi/2.0;
const angle: f32 = -@as(f32, @floatFromInt(@backingInt(dir)))*std.math.pi/2.0;
corners = .{
vec.rotate2d(originalCorners[0], angle, @splat(0.5)),
vec.rotate2d(originalCorners[1], angle, @splat(0.5)),
Expand Down Expand Up @@ -120,7 +120,7 @@ fn rotateQuad(pattern: Pattern, side: Neighbor) main.models.QuadInfo {
},
.cornerUV = .{corners[0], corners[1], corners[2], corners[3]},
.normal = @as(Vec3f, @floatFromInt(side.relPos())),
.textureSlot = @intFromEnum(pattern),
.textureSlot = @backingInt(pattern),
};

return res;
Expand Down
4 changes: 2 additions & 2 deletions mods/cubyz/rotations/planar.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
};
comptime for (1..4) |a| {
for (0..4) |i| {
const neighbor: Neighbor = @enumFromInt(rotationTable[a - 1][i] + 2);
const neighbor: Neighbor = @fromBackingInt(rotationTable[a - 1][i] + 2);
rotationTable[a][i] = neighbor.rotateZ().toInt() - 2;
}
};
if (data >= 4) return 0;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
return runtimeTable[@backingInt(angle)][data];
}

pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, playerDir: Vec3f, _: Vec3i, _: ?Neighbor, currentData: *Block, _: Block, blockPlacing: bool) bool {
Expand Down
2 changes: 1 addition & 1 deletion mods/cubyz/rotations/sign.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
},
};
if (data >= 2*centerRotations + sideRotations) return 0;
return rotationTable[@intFromEnum(angle)][data];
return rotationTable[@backingInt(angle)][data];
}

fn getRotationFromDir(dir: Vec3f) u16 {
Expand Down
2 changes: 1 addition & 1 deletion mods/cubyz/rotations/stairs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
};
if (data >= 256) return 0;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
return runtimeTable[@backingInt(angle)][data];
}

pub fn init() void {}
Expand Down
2 changes: 1 addition & 1 deletion mods/cubyz/rotations/torch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
};
if (data >= 32) return 0;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
return runtimeTable[@backingInt(angle)][data];
}

pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, relativeDir: Vec3i, neighbor: ?Neighbor, currentData: *Block, neighborBlock: Block, _: bool) bool {
Expand Down
46 changes: 23 additions & 23 deletions src/Inventory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ProceduralItemTypeIndex = main.items.ProceduralItemTypeIndex;
pub const InventoryId = enum(u32) { _ };

pub const client = struct { // MARK: client
var maxId: InventoryId = @enumFromInt(0);
var maxId: InventoryId = @fromBackingInt(0);
var freeIdList: main.List(InventoryId) = .empty;
var serverToClientMap: std.AutoHashMap(InventoryId, Inventory) = undefined;

Expand All @@ -32,7 +32,7 @@ pub const client = struct { // MARK: client
}

pub fn deinit() void {
std.debug.assert(freeIdList.items.len == @intFromEnum(maxId)); // leak
std.debug.assert(freeIdList.items.len == @backingInt(maxId)); // leak
freeIdList.clearAndFree(main.globalAllocator);
serverToClientMap.deinit();
}
Expand All @@ -44,7 +44,7 @@ pub const client = struct { // MARK: client
if (freeIdList.popOrNull()) |id| {
return id;
}
defer maxId = @enumFromInt(@intFromEnum(maxId) + 1);
defer maxId = @fromBackingInt(@backingInt(maxId) + 1);
return maxId;
}

Expand Down Expand Up @@ -163,7 +163,7 @@ pub const server = struct { // MARK: server
};

var inventories: main.utils.VirtualList(ServerInventory, 1 << 24) = undefined;
var maxId: InventoryId = @enumFromInt(0);
var maxId: InventoryId = @fromBackingInt(0);
var freeIdList: main.List(InventoryId) = .empty;
var inventoryCreationMutex: main.utils.Mutex = .{};

Expand All @@ -177,10 +177,10 @@ pub const server = struct { // MARK: server
std.log.err("Leaked inventory with source {}", .{inv.source});
}
}
std.debug.assert(freeIdList.items.len == @intFromEnum(maxId)); // leak
std.debug.assert(freeIdList.items.len == @backingInt(maxId)); // leak
freeIdList.clearAndFree(main.globalAllocator);
inventories.deinit();
maxId = @enumFromInt(0);
maxId = @fromBackingInt(0);
}

pub fn disconnectUser(user: *main.server.User) void {
Expand All @@ -198,7 +198,7 @@ pub const server = struct { // MARK: server
if (freeIdList.popOrNull()) |id| {
return id;
}
defer maxId = @enumFromInt(@intFromEnum(maxId) + 1);
defer maxId = @fromBackingInt(@backingInt(maxId) + 1);
_ = inventories.addOne();
return maxId;
}
Expand All @@ -212,28 +212,28 @@ pub const server = struct { // MARK: server
inventoryCreationMutex.lock();
defer inventoryCreationMutex.unlock();
const inventory = ServerInventory.init(len, source, .externallyManaged, callbacks);
inventories.items()[@intFromEnum(inventory.inv.id)] = inventory;
inventories.items()[@backingInt(inventory.inv.id)] = inventory;
inventory.inv.fromBytes(data);
return inventory.inv.id;
}

pub fn destroyExternallyManagedInventory(invId: InventoryId) void {
switch (sync.threadContext) {
.server => {},
.chunkDeiniting => std.debug.assert(inventories.items()[@intFromEnum(invId)].users.items.len == 0), // There should be no users here, since chunks shouldn't be deinited while players are still interacting with them.
.chunkDeiniting => std.debug.assert(inventories.items()[@backingInt(invId)].users.items.len == 0), // There should be no users here, since chunks shouldn't be deinited while players are still interacting with them.
else => unreachable,
}
std.debug.assert(inventories.items()[@intFromEnum(invId)].managed == .externallyManaged);
std.debug.assert(inventories.items()[@backingInt(invId)].managed == .externallyManaged);

inventoryCreationMutex.lock();
defer inventoryCreationMutex.unlock();
inventories.items()[@intFromEnum(invId)].deinit();
inventories.items()[@backingInt(invId)].deinit();
}

pub fn destroyAndDropExternallyManagedInventory(invId: InventoryId, pos: Vec3i) void {
sync.threadContext.assertCorrectContext(.server);
std.debug.assert(inventories.items()[@intFromEnum(invId)].managed == .externallyManaged);
const inv = &inventories.items()[@intFromEnum(invId)];
std.debug.assert(inventories.items()[@backingInt(invId)].managed == .externallyManaged);
const inv = &inventories.items()[@backingInt(invId)];
for (inv.inv._items) |*itemStack| {
if (itemStack.amount == 0) continue;
main.server.world.?.drop(
Expand Down Expand Up @@ -301,8 +301,8 @@ pub const server = struct { // MARK: server
const inventory = ServerInventory.init(len, source, .internallyManaged, callbacks);
inventoryCreationMutex.unlock();

inventories.items()[@intFromEnum(inventory.inv.id)] = inventory;
inventories.items()[@intFromEnum(inventory.inv.id)].addUser(user, clientId);
inventories.items()[@backingInt(inventory.inv.id)] = inventory;
inventories.items()[@backingInt(inventory.inv.id)].addUser(user, clientId);

switch (source) {
.blockInventory => unreachable, // Should be loaded by the block entity
Expand All @@ -316,13 +316,13 @@ pub const server = struct { // MARK: server
pub fn closeInventory(user: *main.server.User, clientId: InventoryId) !void {
sync.threadContext.assertCorrectContext(.server);
const serverId = user.inventoryClientToServerIdMap.get(clientId) orelse return error.InventoryNotFound;
inventories.items()[@intFromEnum(serverId)].removeUser(user, clientId);
inventories.items()[@backingInt(serverId)].removeUser(user, clientId);
}

pub fn getInventory(user: *main.server.User, clientId: InventoryId) ?Inventory {
sync.threadContext.assertCorrectContext(.server);
const serverId = user.inventoryClientToServerIdMap.get(clientId) orelse return null;
return inventories.items()[@intFromEnum(serverId)].inv;
return inventories.items()[@backingInt(serverId)].inv;
}

pub fn getInventoryFromSource(source: Source) ?Inventory {
Expand All @@ -339,20 +339,20 @@ pub const server = struct { // MARK: server

pub fn getInventoryFromId(serverId: InventoryId) Inventory {
sync.threadContext.assertCorrectContext(.server);
return inventories.items()[@intFromEnum(serverId)].inv;
return inventories.items()[@backingInt(serverId)].inv;
}

pub fn getServerInventory(serverId: InventoryId) ServerInventory {
sync.threadContext.assertCorrectContext(.server);
return inventories.items()[@intFromEnum(serverId)];
return inventories.items()[@backingInt(serverId)];
}

pub fn clearPlayerInventory(user: *main.server.User) void {
sync.threadContext.assertCorrectContext(.server);
var inventoryIdIterator = user.inventoryClientToServerIdMap.valueIterator();
while (inventoryIdIterator.next()) |inventoryId| {
if (inventories.items()[@intFromEnum(inventoryId.*)].source == .playerInventory) {
sync.server.executeCommand(.{.clear = .{.inv = inventories.items()[@intFromEnum(inventoryId.*)].inv}}, null);
if (inventories.items()[@backingInt(inventoryId.*)].source == .playerInventory) {
sync.server.executeCommand(.{.clear = .{.inv = inventories.items()[@backingInt(inventoryId.*)].inv}}, null);
}
}
}
Expand All @@ -362,8 +362,8 @@ pub const server = struct { // MARK: server
sync.threadContext.assertCorrectContext(.server);
var inventoryIdIterator = user.inventoryClientToServerIdMap.valueIterator();
outer: while (inventoryIdIterator.next()) |inventoryId| {
if (inventories.items()[@intFromEnum(inventoryId.*)].source == .playerInventory) {
const inv = inventories.items()[@intFromEnum(inventoryId.*)].inv;
if (inventories.items()[@backingInt(inventoryId.*)].source == .playerInventory) {
const inv = inventories.items()[@backingInt(inventoryId.*)].inv;
for (inv._items, 0..) |invStack, slot| {
if (std.meta.eql(invStack.item, itemStack.item)) {
const amount = @min(itemStack.item.stackSize() - invStack.amount, itemStack.amount);
Expand Down
20 changes: 10 additions & 10 deletions src/argparse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ pub fn Parser(comptime T: type, comptime options: Options) type {

var nextArgument: ?[]const u8 = tokens.next();

inline for (s.fields) |field| {
const value = resolveArgument(field.type, arena, field.name[0..], nextArgument, &tempErrorMessage);
inline for (s.field_names, s.field_types) |field, FieldType| {
const value = resolveArgument(FieldType, arena, field[0..], nextArgument, &tempErrorMessage);

if (value == error.ParseError) {
if (@typeInfo(field.type) == .optional) {
@field(result, field.name) = null;
if (@typeInfo(FieldType) == .optional) {
@field(result, field) = null;
tempErrorMessage.clearRetainingCapacity();
} else {
errorMessage.appendSlice(tempErrorMessage.items);
return error.ParseError;
}
} else {
@field(result, field.name) = value catch unreachable;
@field(result, field) = value catch unreachable;
tempErrorMessage.clearRetainingCapacity();
nextArgument = tokens.next();
}
}

if (nextArgument != null) {
errorMessage.print("Too many arguments for command, expected {}", .{s.fields.len});
errorMessage.print("Too many arguments for command, expected {}", .{s.field_names.len});
return error.ParseError;
}

Expand Down Expand Up @@ -153,14 +153,14 @@ pub fn Parser(comptime T: type, comptime options: Options) type {

tempErrorMessage.appendSlice("---");

inline for (u.fields) |field| {
inline for (u.field_names, u.field_types) |field, FieldType| {
tempErrorMessage.append('\n');
tempErrorMessage.appendSlice(field.name);
tempErrorMessage.appendSlice(field);
tempErrorMessage.append('\n');

const result = Parser(field.type, options).resolve(.parse, arena, args, &tempErrorMessage);
const result = Parser(FieldType, options).resolve(.parse, arena, args, &tempErrorMessage);
if (result != error.ParseError) {
return @unionInit(T, field.name, result catch unreachable);
return @unionInit(T, field, result catch unreachable);
}
tempErrorMessage.appendSlice("\n---");
}
Expand Down
Loading
Loading