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
8 changes: 4 additions & 4 deletions mods/cubyz/rotation/branch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ fn rotateQuad(originalCorners: [4]Vec2f, pattern: Pattern, min: f32, max: f32, s
@as(Vec3f, @floatFromInt(side.textureX()))*@as(Vec3f, @splat(corners[3][0] - offX)) + @as(Vec3f, @floatFromInt(side.textureY()))*@as(Vec3f, @splat(corners[3][1] - offY)),
};

var offset: Vec3f = .{0.0, 0.0, 0.0};
offset[@intFromEnum(side.vectorComponent())] = if(side.isPositive()) max else min;
const offset: Vec3f = @as(Vec3f, @floatFromInt(@abs(side.relPos())))*@as(Vec3f, @splat(if(side.isPositive()) max else min));

const res: main.models.QuadInfo = .{
.corners = .{
Expand All @@ -117,7 +116,7 @@ fn rotateQuad(originalCorners: [4]Vec2f, pattern: Pattern, min: f32, max: f32, s
corners3d[2] + offset,
corners3d[3] + offset,
},
.cornerUV = originalCorners,
.cornerUV = .{originalCorners[0], originalCorners[1], originalCorners[2], originalCorners[3]},
.normal = @as(Vec3f, @floatFromInt(side.relPos())),
.textureSlot = textureSlotOffset + @intFromEnum(pattern),
};
Expand Down Expand Up @@ -327,7 +326,8 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
if(data > 0b111111) return 0;
const rotationIndex = (data & 0b111100) >> 2;
const upDownFlags = data & 0b000011;
return rotationTable[@intFromEnum(angle)][rotationIndex] | upDownFlags;
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][rotationIndex] | upDownFlags;
}

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

pub fn init() void {
Expand Down
3 changes: 2 additions & 1 deletion mods/cubyz/rotation/direction.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
}
};
if(data >= 6) return 0;
return rotationTable[@intFromEnum(angle)][data];
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
}

pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i, neighbor: ?Neighbor, currentData: *Block, _: Block, blockPlacing: bool) bool {
Expand Down
5 changes: 3 additions & 2 deletions mods/cubyz/rotation/fence.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
}
};
if(data >= 16) return 0;
return rotationTable[@intFromEnum(angle)][data];
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
}

fn fenceTransform(quad: *main.models.QuadInfo, data: FenceData) void {
Expand Down Expand Up @@ -106,7 +107,7 @@ pub fn updateData(block: *Block, neighbor: Neighbor, neighborBlock: Block) bool
const blockBaseModelIndex = blocks.meshes.modelIndexStart(block.*);
const neighborBaseModelIndex = blocks.meshes.modelIndexStart(neighborBlock);
const neighborModel = blocks.meshes.model(neighborBlock).model();
const targetVal = !neighborBlock.replacable() and (blockBaseModelIndex == neighborBaseModelIndex or neighborModel.isNeighborOccluded[neighbor.reverse().toInt()]);
const targetVal = !neighborBlock.replacable() and !neighborBlock.transparent() and (blockBaseModelIndex == neighborBaseModelIndex or neighborModel.isNeighborOccluded[neighbor.reverse().toInt()]);
var currentData: FenceData = @bitCast(@as(u4, @truncate(block.data)));
switch(neighbor) {
.dirNegX => {
Expand Down
5 changes: 2 additions & 3 deletions mods/cubyz/rotation/log.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ fn rotateQuad(pattern: Pattern, side: Neighbor) main.models.QuadInfo {
@as(Vec3f, @floatFromInt(side.textureX()))*@as(Vec3f, @splat(originalCorners[3][0] - offX)) + @as(Vec3f, @floatFromInt(side.textureY()))*@as(Vec3f, @splat(originalCorners[3][1] - offY)),
};

var offset: Vec3f = .{0.0, 0.0, 0.0};
offset[@intFromEnum(side.vectorComponent())] = @floatFromInt(@intFromBool(side.isPositive()));
const offset: Vec3f = @floatFromInt(@intFromBool(side.relPos() == Vec3i{1, 1, 1}));

const res: main.models.QuadInfo = .{
.corners = .{
Expand All @@ -117,7 +116,7 @@ fn rotateQuad(pattern: Pattern, side: Neighbor) main.models.QuadInfo {
corners3d[2] + offset,
corners3d[3] + offset,
},
.cornerUV = corners,
.cornerUV = .{corners[0], corners[1], corners[2], corners[3]},
.normal = @as(Vec3f, @floatFromInt(side.relPos())),
.textureSlot = @intFromEnum(pattern),
};
Expand Down
3 changes: 2 additions & 1 deletion mods/cubyz/rotation/planar.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
}
};
if(data >= 4) return 0;
return rotationTable[@intFromEnum(angle)][data];
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
}

pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, playerDir: Vec3f, _: Vec3i, _: ?Neighbor, currentData: *Block, _: Block, blockPlacing: bool) bool {
Expand Down
3 changes: 2 additions & 1 deletion mods/cubyz/rotation/stairs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
}
};
if(data >= 256) return 0;
return rotationTable[@intFromEnum(angle)][data];
const runtimeTable = rotationTable;
return runtimeTable[@intFromEnum(angle)][data];
}

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

pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, relativeDir: Vec3i, neighbor: ?Neighbor, currentData: *Block, neighborBlock: Block, _: bool) bool {
Expand Down
2 changes: 1 addition & 1 deletion src/chunk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub const Neighbor = enum(u3) { // MARK: Neighbor
pub fn extractDirectionComponent(self: Neighbor, in: anytype) @TypeOf(in[0]) {
switch(self) {
inline else => |val| {
return in[@intFromEnum(val.vectorComponent())];
return in[@intFromEnum(comptime val.vectorComponent())];
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/gui/GuiWindow.zig
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn detectCycles(self: *GuiWindow, other: *GuiWindow) bool {
}

fn snapToOtherWindow(self: *GuiWindow) void {
for(&self.relativePosition, 0..) |*relPos, i| {
inline for(&self.relativePosition, 0..) |*relPos, i| {
var minDist: f32 = snapDistance;
var minWindow: ?*GuiWindow = null;
var selfAttachment: AttachmentPoint = undefined;
Expand Down Expand Up @@ -270,7 +270,7 @@ fn snapToOtherWindow(self: *GuiWindow) void {

fn positionRelativeToFrame(self: *GuiWindow) void {
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(&self.relativePosition, 0..) |*relPos, i| {
inline for(&self.relativePosition, 0..) |*relPos, i| {
// Snap to the center:
if(@abs(self.pos[i] + self.size[i] - windowSize[i]/2) <= snapDistance) {
relPos.* = .{.attachedToFrame = .{
Expand Down Expand Up @@ -299,7 +299,7 @@ fn positionRelativeToFrame(self: *GuiWindow) void {
}
}

fn positionRelativeToConnectedWindow(self: *GuiWindow, other: *GuiWindow, i: usize) void {
fn positionRelativeToConnectedWindow(self: *GuiWindow, other: *GuiWindow, comptime i: usize) void {
const otherSize = other.size;
const relPos = &self.relativePosition[i];
// Snap to the center:
Expand Down Expand Up @@ -391,7 +391,7 @@ pub fn updateWindowPosition(self: *GuiWindow) void {
}
self.size = self.contentSize*@as(Vec2f, @splat(self.scale));
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(self.relativePosition, 0..) |relPos, i| {
inline for(self.relativePosition, 0..) |relPos, i| {
switch(relPos) {
.ratio => |ratio| {
self.pos[i] = windowSize[i]*ratio - self.size[i]/2;
Expand Down Expand Up @@ -439,10 +439,10 @@ pub fn updateWindowPosition(self: *GuiWindow) void {
fn drawOrientationLines(self: *const GuiWindow) void {
draw.setColor(0x80000000);
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(self.relativePosition, 0..) |relPos, i| {
inline for(self.relativePosition, 0..) |relPos, i| _continue: {
switch(relPos) {
.ratio, .relativeToWindow => {
continue;
break :_continue;
},
.attachedToFrame => |attachedToFrame| {
const pos = switch(attachedToFrame.otherAttachmentPoint) {
Expand Down
18 changes: 9 additions & 9 deletions src/models.zig
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ pub const Model = struct {
}

fn solveDepth(normal: Vec3f, v0: Vec3f, xIndex: usize, yIndex: usize, zIndex: usize, u: f32, v: f32) f32 {
const nX = normal[xIndex];
const nY = normal[yIndex];
const nZ = normal[zIndex];
const nX = @as([3]f32, normal)[xIndex];
const nY = @as([3]f32, normal)[yIndex];
const nZ = @as([3]f32, normal)[zIndex];

const planeOffset = -vec.dot(v0, normal);

Expand Down Expand Up @@ -250,9 +250,9 @@ pub const Model = struct {
const voxelMin: Vec3i = @max(@as(Vec3i, @intFromFloat(@floor(min))), @as(Vec3i, @splat(0)));
const voxelMax: Vec3i = @max(@as(Vec3i, @intFromFloat(@ceil(max))), @as(Vec3i, @splat(0)));

var p0 = Vec2f{v0[xIndex], v0[yIndex]};
var p1 = Vec2f{v1[xIndex], v1[yIndex]};
var p2 = Vec2f{v2[xIndex], v2[yIndex]};
var p0 = Vec2f{@as([3]f32, v0)[xIndex], @as([3]f32, v0)[yIndex]};
var p1 = Vec2f{@as([3]f32, v1)[xIndex], @as([3]f32, v1)[yIndex]};
var p2 = Vec2f{@as([3]f32, v2)[xIndex], @as([3]f32, v2)[yIndex]};

if(p0[1] > p1[1]) {
std.mem.swap(Vec2f, &p0, &p1);
Expand All @@ -264,9 +264,9 @@ pub const Model = struct {
std.mem.swap(Vec2f, &p1, &p2);
}

for(@intCast(voxelMin[yIndex])..@intCast(voxelMax[yIndex])) |y| {
for(@intCast(@as([3]i32, voxelMin)[yIndex])..@intCast(@as([3]i32, voxelMax)[yIndex])) |y| {
if(y >= collisionGridSize) continue;
const yf = std.math.clamp(@as(f32, @floatFromInt(y)) + 0.5, min[yIndex], max[yIndex]);
const yf = std.math.clamp(@as(f32, @floatFromInt(y)) + 0.5, @as([3]f32, min)[yIndex], @as([3]f32, max)[yIndex]);
var xa: f32 = undefined;
var xb: f32 = undefined;
if(yf < p1[1]) {
Expand Down Expand Up @@ -309,7 +309,7 @@ pub const Model = struct {

for(modelQuads) |quad| {
var shift = Vec3f{0, 0, 0};
for(0..3) |i| {
inline for(0..3) |i| {
if(@abs(quad.normalVec()[i]) == 1.0 and @floor(quad.corners[0][i]*collisionGridSize) == quad.corners[0][i]*collisionGridSize) {
shift = quad.normalVec()*voxelSize*@as(Vec3f, @splat(0.5));
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/terrain/mapgen/MapGenV1.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn generateMapFragment(map: *MapFragment, worldSeed: u64) void {
const biomeMapX = @as(usize, @intCast(xBiome)) + dx;
const biomeMapY = @as(usize, @intCast(yBiome)) + dy;
const biomeSample = biomePositions.get(biomeMapX, biomeMapY);
const weight = interpolationCoefficientsX[dx]*interpolationCoefficientsY[dy]*biomeSample.biome.interpolationWeight;
const weight = @as([2]f32, interpolationCoefficientsX)[dx]*@as([2]f32, interpolationCoefficientsY)[dy]*biomeSample.biome.interpolationWeight;
coefficientsX += interpolationWeights(relXBiome, biomeSample.biome.interpolation)*@as(Vec2f, @splat(weight));
coefficientsY += interpolationWeights(relYBiome, biomeSample.biome.interpolation)*@as(Vec2f, @splat(weight));
totalWeight += weight;
Expand All @@ -122,7 +122,7 @@ pub fn generateMapFragment(map: *MapFragment, worldSeed: u64) void {
for(0..2) |dy| {
const biomeMapX = @as(usize, @intCast(xBiome)) + dx;
const biomeMapY = @as(usize, @intCast(yBiome)) + dy;
const weight = coefficientsX[dx]*coefficientsY[dy];
const weight = @as([2]f32, coefficientsX)[dx]*@as([2]f32, coefficientsY)[dy];
const biomeSample = biomePositions.get(biomeMapX, biomeMapY);
height += biomeSample.height*weight;
roughness += biomeSample.roughness*weight;
Expand Down
3 changes: 2 additions & 1 deletion src/server/terrain/simple_structures/SbbGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ fn alignDirections(input: Neighbor, desired: Neighbor) !sbb.Rotation.FixedRotati
alignTable[in.toInt()][out.toInt()] = error.NotPossibleToAlign;
}
};
return alignTable[input.toInt()][desired.toInt()];
const runtimeTable = alignTable;
return runtimeTable[input.toInt()][desired.toInt()];
}
4 changes: 2 additions & 2 deletions src/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub const Compression = struct { // MARK: Compression
}

pub fn inflateTo(buf: []u8, data: []const u8) !usize {
var streamIn = std.io.fixedBufferStream(data);
var streamIn = std.Io.fixedBufferStream(data);
var decomp = std.compress.flate.decompressor(streamIn.reader());
var streamOut = std.io.fixedBufferStream(buf);
var streamOut = std.Io.fixedBufferStream(buf);
try decomp.decompress(streamOut.writer());
return streamOut.getWritten().len;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub fn List(comptime T: type) type {
@compileError("The Writer interface is only defined for ArrayList(u8) " ++
"but the given type is ArrayList(" ++ @typeName(T) ++ ")")
else
std.io.GenericWriter(*@This(), error{}, appendWrite);
std.Io.GenericWriter(*@This(), error{}, appendWrite);

pub fn writer(self: *@This()) Writer {
return .{.context = self};
Expand Down