mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-04 03:37:59 -04:00
Update zig:
@abs (formerly @fabs) now supports integers.
This commit is contained in:
parent
045ba9c65a
commit
766dd53d06
@ -3,8 +3,8 @@
|
||||
.version = "0.0.0",
|
||||
.dependencies = .{
|
||||
.mach_freetype = .{
|
||||
.url = "https://pkg.machengine.org/mach-freetype/92773615e2480c0a6f561748f2ba1180376bbb68.tar.gz",
|
||||
.hash = "12205a6057fe43a4940c6db304449ebf3e98ff15d0eec05b75f621d7616c2e7d7f2c",
|
||||
.url = "https://pkg.machengine.org/mach-freetype/7dd97f088455fddda6832851082f68670b36c426.tar.gz",
|
||||
.hash = "12209950df2c606a03f5246dce72b3338ffd7314221b20e55df38f8b76676cb9ba13",
|
||||
},
|
||||
.portaudio = .{
|
||||
.url = "https://github.com/PortAudio/portaudio/archive/refs/tags/v19.7.0.tar.gz",
|
||||
|
2
run.sh
2
run.sh
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
version=zig-linux-x86_64-0.12.0-dev.596+2adb932ad
|
||||
version=zig-linux-x86_64-0.12.0-dev.706+62a0fbdae
|
||||
|
||||
mkdir -p compiler/zig
|
||||
touch compiler/version.txt
|
||||
|
@ -117,9 +117,9 @@ pub const ChunkPosition = struct {
|
||||
|
||||
pub fn getMinDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 {
|
||||
var halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2));
|
||||
var dx = @fabs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
|
||||
var dy = @fabs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]);
|
||||
var dz = @fabs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
|
||||
var dx = @abs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
|
||||
var dy = @abs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]);
|
||||
var dz = @abs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
|
||||
dx = @max(0, dx - halfWidth);
|
||||
dy = @max(0, dy - halfWidth);
|
||||
dz = @max(0, dz - halfWidth);
|
||||
@ -128,9 +128,9 @@ pub const ChunkPosition = struct {
|
||||
|
||||
pub fn getMaxDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 {
|
||||
var halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2));
|
||||
var dx = @fabs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
|
||||
var dy = @fabs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]);
|
||||
var dz = @fabs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
|
||||
var dx = @abs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
|
||||
var dy = @abs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]);
|
||||
var dz = @abs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
|
||||
dx = dx + halfWidth;
|
||||
dy = dy + halfWidth;
|
||||
dz = dz + halfWidth;
|
||||
@ -609,7 +609,7 @@ pub const meshing = struct {
|
||||
const fullDx = dx - Neighbors.relX[normal];
|
||||
const fullDy = dy - Neighbors.relY[normal];
|
||||
const fullDz = dz - Neighbors.relZ[normal];
|
||||
self.distance = std.math.absCast(fullDx) + std.math.absCast(fullDy) + std.math.absCast(fullDz);
|
||||
self.distance = @abs(fullDx) + @abs(fullDy) + @abs(fullDz);
|
||||
}
|
||||
};
|
||||
const BoundingRectToNeighborChunk = struct {
|
||||
|
@ -172,7 +172,7 @@ pub const World = struct {
|
||||
}
|
||||
// Ambient light:
|
||||
{
|
||||
var dayTime = std.math.absInt(@mod(self.gameTime.load(.Monotonic), dayCycle) -% dayCycle/2) catch 0;
|
||||
var dayTime = @abs(@mod(self.gameTime.load(.Monotonic), dayCycle) -% dayCycle/2);
|
||||
if(dayTime < dayCycle/4 - dayCycle/16) {
|
||||
self.ambientLight = 0.1;
|
||||
self.clearColor[0] = 0;
|
||||
|
@ -228,14 +228,14 @@ fn snapToOtherWindow(self: *GuiWindow) void {
|
||||
if(start >= end) continue;
|
||||
if(detectCycles(self, other)) continue;
|
||||
|
||||
const dist1 = @fabs(self.pos[i] - other.pos[i] - other.size[i]);
|
||||
const dist1 = @abs(self.pos[i] - other.pos[i] - other.size[i]);
|
||||
if(dist1 < minDist) {
|
||||
minDist = dist1;
|
||||
minWindow = other;
|
||||
selfAttachment = .lower;
|
||||
otherAttachment = .upper;
|
||||
}
|
||||
const dist2 = @fabs(self.pos[i] + self.size[i] - other.pos[i]);
|
||||
const dist2 = @abs(self.pos[i] + self.size[i] - other.pos[i]);
|
||||
if(dist2 < minDist) {
|
||||
minDist = dist2;
|
||||
minWindow = other;
|
||||
@ -253,17 +253,17 @@ fn positionRelativeToFrame(self: *GuiWindow) void {
|
||||
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
|
||||
for(&self.relativePosition, 0..) |*relPos, i| {
|
||||
// Snap to the center:
|
||||
if(@fabs(self.pos[i] + self.size[i] - windowSize[i]/2) <= snapDistance) {
|
||||
if(@abs(self.pos[i] + self.size[i] - windowSize[i]/2) <= snapDistance) {
|
||||
relPos.* = .{.attachedToFrame = .{
|
||||
.selfAttachmentPoint = .upper,
|
||||
.otherAttachmentPoint = .middle,
|
||||
}};
|
||||
} else if(@fabs(self.pos[i] + self.size[i]/2 - windowSize[i]/2) <= snapDistance) {
|
||||
} else if(@abs(self.pos[i] + self.size[i]/2 - windowSize[i]/2) <= snapDistance) {
|
||||
relPos.* = .{.attachedToFrame = .{
|
||||
.selfAttachmentPoint = .middle,
|
||||
.otherAttachmentPoint = .middle,
|
||||
}};
|
||||
} else if(@fabs(self.pos[i] - windowSize[i]/2) <= snapDistance) {
|
||||
} else if(@abs(self.pos[i] - windowSize[i]/2) <= snapDistance) {
|
||||
relPos.* = .{.attachedToFrame = .{
|
||||
.selfAttachmentPoint = .lower,
|
||||
.otherAttachmentPoint = .middle,
|
||||
@ -284,32 +284,32 @@ fn positionRelativeToConnectedWindow(self: *GuiWindow, other: *GuiWindow, i: usi
|
||||
const otherSize = other.size;
|
||||
const relPos = &self.relativePosition[i];
|
||||
// Snap to the center:
|
||||
if(@fabs(self.pos[i] + self.size[i] - (other.pos[i] + otherSize[i]/2)) <= snapDistance) {
|
||||
if(@abs(self.pos[i] + self.size[i] - (other.pos[i] + otherSize[i]/2)) <= snapDistance) {
|
||||
relPos.* = .{.attachedToWindow = .{
|
||||
.reference = other,
|
||||
.selfAttachmentPoint = .upper,
|
||||
.otherAttachmentPoint = .middle,
|
||||
}};
|
||||
} else if(@fabs(self.pos[i] + self.size[i]/2 - (other.pos[i] + otherSize[i]/2)) <= snapDistance) {
|
||||
} else if(@abs(self.pos[i] + self.size[i]/2 - (other.pos[i] + otherSize[i]/2)) <= snapDistance) {
|
||||
relPos.* = .{.attachedToWindow = .{
|
||||
.reference = other,
|
||||
.selfAttachmentPoint = .middle,
|
||||
.otherAttachmentPoint = .middle,
|
||||
}};
|
||||
} else if(@fabs(self.pos[i] - (other.pos[i] + otherSize[i]/2)) <= snapDistance) {
|
||||
} else if(@abs(self.pos[i] - (other.pos[i] + otherSize[i]/2)) <= snapDistance) {
|
||||
relPos.* = .{.attachedToWindow = .{
|
||||
.reference = other,
|
||||
.selfAttachmentPoint = .lower,
|
||||
.otherAttachmentPoint = .middle,
|
||||
}};
|
||||
// Snap to the edges:
|
||||
} else if(@fabs(self.pos[i] - other.pos[i]) <= snapDistance) {
|
||||
} else if(@abs(self.pos[i] - other.pos[i]) <= snapDistance) {
|
||||
relPos.* = .{.attachedToWindow = .{
|
||||
.reference = other,
|
||||
.selfAttachmentPoint = .lower,
|
||||
.otherAttachmentPoint = .lower,
|
||||
}};
|
||||
} else if(@fabs(self.pos[i] + self.size[i] - (other.pos[i] + otherSize[i])) <= snapDistance) {
|
||||
} else if(@abs(self.pos[i] + self.size[i] - (other.pos[i] + otherSize[i])) <= snapDistance) {
|
||||
relPos.* = .{.attachedToWindow = .{
|
||||
.reference = other,
|
||||
.selfAttachmentPoint = .upper,
|
||||
|
@ -651,8 +651,8 @@ const ToolPhysics = struct {
|
||||
while(y < 16) : (y += 1) {
|
||||
const angle = std.math.atan2(f32, y + 0.5 - center[1], x + 0.5 - center[0]) - initialAngle;
|
||||
const distance = @cos(angle)*vec.length(center - Vec2f{x + 0.5, y + 0.5});
|
||||
const deltaAngle = @fabs(angle - originalAngle);
|
||||
const deltaDist = @fabs(distance - originalDistance);
|
||||
const deltaAngle = @abs(angle - originalAngle);
|
||||
const deltaDist = @abs(distance - originalDistance);
|
||||
if(deltaAngle <= 0.2 and deltaDist <= 0.7) {
|
||||
numOfSmoothPixels += 1;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ fn log(_x: u16, _y: u16, _z: u16) ?u4 {
|
||||
return Neighbors.dirDown;
|
||||
}
|
||||
if(x*x + z*z < 8.0*8.0) {
|
||||
if(@fabs(x) > @fabs(z)) {
|
||||
if(@abs(x) > @abs(z)) {
|
||||
if(x < 0) return Neighbors.dirNegX;
|
||||
return Neighbors.dirPosX;
|
||||
} else {
|
||||
|
@ -1079,7 +1079,7 @@ pub const Protocols = struct {
|
||||
defer json.free(main.threadAllocator);
|
||||
var expectedTime = json.get(i64, "time", 0);
|
||||
var curTime = world.gameTime.load(.Monotonic);
|
||||
if(std.math.absInt(curTime -% expectedTime) catch std.math.maxInt(i64) >= 1000) {
|
||||
if(@abs(curTime -% expectedTime) >= 1000) {
|
||||
world.gameTime.store(expectedTime, .Monotonic);
|
||||
} else if(curTime < expectedTime) { // world.gameTime++
|
||||
while(world.gameTime.tryCompareAndSwap(curTime, curTime +% 1, .Monotonic, .Monotonic)) |actualTime| {
|
||||
|
@ -706,7 +706,7 @@ pub const MeshSelection = struct {
|
||||
// Implementation of "A Fast Voxel Traversal Algorithm for Ray Tracing" http://www.cse.yorku.ca/~amana/research/grid.pdf
|
||||
const step = vec.intFromFloat(i32, std.math.sign(dir));
|
||||
const invDir = @as(Vec3d, @splat(1))/dir;
|
||||
const tDelta = @fabs(invDir);
|
||||
const tDelta = @abs(invDir);
|
||||
var tMax = (@floor(pos) - pos)*invDir;
|
||||
tMax = @max(tMax, tMax + tDelta*vec.floatFromInt(f64, step));
|
||||
tMax = @select(f64, dir == @as(Vec3d, @splat(0)), @as(Vec3d, @splat(std.math.inf(f64))), tMax);
|
||||
@ -1020,7 +1020,7 @@ pub const RenderStructure = struct {
|
||||
var x = minX;
|
||||
while(x != maxX): (x +%= size) {
|
||||
const xIndex = @divExact(x -% startX, size);
|
||||
var deltaX: i64 = std.math.absInt(@as(i64, x +% size/2 -% px)) catch unreachable;
|
||||
var deltaX: i64 = @abs(x +% size/2 -% px);
|
||||
deltaX = @max(0, deltaX - size/2);
|
||||
const maxYRenderDistanceSquare: f64 = @floatFromInt(@as(i64, maxRenderDistance)*@as(i64, maxRenderDistance) - deltaX*deltaX);
|
||||
const maxYRenderDistance: i32 = @intFromFloat(@ceil(@sqrt(maxYRenderDistanceSquare)));
|
||||
@ -1030,7 +1030,7 @@ pub const RenderStructure = struct {
|
||||
var y = minY;
|
||||
while(y != maxY): (y +%= size) {
|
||||
const yIndex = @divExact(y -% startY, size);
|
||||
var deltaY: i64 = std.math.absInt(@as(i64, y +% size/2 -% py)) catch unreachable;
|
||||
var deltaY: i64 = @abs(y +% size/2 -% py);
|
||||
deltaY = @max(0, deltaY - size/2);
|
||||
const maxZRenderDistanceSquare: f64 = @floatFromInt(@as(i64, maxYRenderDistance)*@as(i64, maxYRenderDistance) - deltaY*deltaY);
|
||||
const maxZRenderDistance: i32 = @intFromFloat(@ceil(@sqrt(maxZRenderDistanceSquare)));
|
||||
|
@ -141,7 +141,7 @@ pub const InterpolatableCaveBiomeMapView = struct {
|
||||
return @shuffle(i32, in, undefined, Vec3i{2, 0, 1});
|
||||
}
|
||||
fn argMaxDistance0(distance: Vec3i) @Vector(3, bool) {
|
||||
const absDistance = std.math.absInt(distance) catch unreachable;
|
||||
const absDistance = @abs(distance);
|
||||
if(absDistance[0] > absDistance[1]) {
|
||||
if(absDistance[0] > absDistance[2]) {
|
||||
return .{true, false, false};
|
||||
@ -157,7 +157,7 @@ pub const InterpolatableCaveBiomeMapView = struct {
|
||||
}
|
||||
}
|
||||
fn argMaxDistance1(distance: Vec3i) @Vector(3, bool) {
|
||||
const absDistance = std.math.absInt(distance) catch unreachable;
|
||||
const absDistance = @abs(distance);
|
||||
if(absDistance[0] >= absDistance[1]) {
|
||||
if(absDistance[0] >= absDistance[2]) {
|
||||
return .{true, false, false};
|
||||
@ -333,7 +333,7 @@ pub const InterpolatableCaveBiomeMapView = struct {
|
||||
const distanceX = wx - gridPointX;
|
||||
const distanceY = wy - gridPointY;
|
||||
const distanceZ = wz - gridPointZ;
|
||||
const totalDistance = (std.math.absInt(distanceX) catch unreachable) + (std.math.absInt(distanceY) catch unreachable) + (std.math.absInt(distanceZ) catch unreachable);
|
||||
const totalDistance = @abs(distanceX) + @abs(distanceY) + @abs(distanceZ);
|
||||
if(totalDistance > CaveBiomeMapFragment.caveBiomeSize*3/4) {
|
||||
// Or with 1 to prevent errors if the value is 0.
|
||||
gridPointX += (std.math.sign(distanceX | 1) - 1)*(CaveBiomeMapFragment.caveBiomeSize/2);
|
||||
|
@ -234,7 +234,7 @@ const GenerationStructure = struct {
|
||||
var weight: f32 = @max(1.0 - @sqrt(dist), 0);
|
||||
weight *= weight;
|
||||
// The important bit is the ocean height, that's the only point where we actually need the transition point to be exact for beaches to occur.
|
||||
weight /= @fabs(biomePoint.height - 16);
|
||||
weight /= @abs(biomePoint.height - 16);
|
||||
height += biomePoint.height*weight;
|
||||
roughness += biomePoint.biome.roughness*weight;
|
||||
hills += biomePoint.biome.hills*weight;
|
||||
|
@ -150,7 +150,7 @@ pub fn generateRidgidNoise(allocator: Allocator, x: i32, y: i32, width: u31, hei
|
||||
while(x1 -% width -% x < 0) : (x1 += voxelSize) {
|
||||
var y1 = y;
|
||||
while(y1 -% y -% height < 0) : (y1 += voxelSize) {
|
||||
map.ptr(@as(u32, @intCast(x1 - x))/voxelSize, @as(u32, @intCast(y1 - y))/voxelSize).* += (1 - @fabs(context.perlin(x1-x0, y1-y0)))*fac;
|
||||
map.ptr(@as(u32, @intCast(x1 - x))/voxelSize, @as(u32, @intCast(y1 - y))/voxelSize).* += (1 - @abs(context.perlin(x1-x0, y1-y0)))*fac;
|
||||
}
|
||||
}
|
||||
fac *= reductionFactor;
|
||||
@ -182,7 +182,7 @@ pub fn generateSmoothNoise(allocator: Allocator, x: i32, y: i32, width: u31, hei
|
||||
while(x1 -% width -% x < 0) : (x1 += voxelSize) {
|
||||
var y1 = y;
|
||||
while(y1 -% y -% height < 0) : (y1 += voxelSize) {
|
||||
map.ptr(@as(u32, @intCast(x1 - x))/voxelSize, @as(u32, @intCast(y1 - y))/voxelSize).* += @fabs(context.perlin(x1-x0, y1-y0))*fac;
|
||||
map.ptr(@as(u32, @intCast(x1 - x))/voxelSize, @as(u32, @intCast(y1 - y))/voxelSize).* += @abs(context.perlin(x1-x0, y1-y0))*fac;
|
||||
}
|
||||
}
|
||||
fac *= reductionFactor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user