Update zig:

@abs (formerly @fabs) now supports integers.
This commit is contained in:
IntegratedQuantum 2023-10-04 12:36:00 +02:00
parent 045ba9c65a
commit 766dd53d06
12 changed files with 34 additions and 34 deletions

View File

@ -3,8 +3,8 @@
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{ .dependencies = .{
.mach_freetype = .{ .mach_freetype = .{
.url = "https://pkg.machengine.org/mach-freetype/92773615e2480c0a6f561748f2ba1180376bbb68.tar.gz", .url = "https://pkg.machengine.org/mach-freetype/7dd97f088455fddda6832851082f68670b36c426.tar.gz",
.hash = "12205a6057fe43a4940c6db304449ebf3e98ff15d0eec05b75f621d7616c2e7d7f2c", .hash = "12209950df2c606a03f5246dce72b3338ffd7314221b20e55df38f8b76676cb9ba13",
}, },
.portaudio = .{ .portaudio = .{
.url = "https://github.com/PortAudio/portaudio/archive/refs/tags/v19.7.0.tar.gz", .url = "https://github.com/PortAudio/portaudio/archive/refs/tags/v19.7.0.tar.gz",

2
run.sh
View File

@ -1,6 +1,6 @@
#!/bin/bash #!/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 mkdir -p compiler/zig
touch compiler/version.txt touch compiler/version.txt

View File

@ -117,9 +117,9 @@ pub const ChunkPosition = struct {
pub fn getMinDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 { pub fn getMinDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 {
var halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2)); var halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2));
var dx = @fabs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]); var dx = @abs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
var dy = @fabs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]); var dy = @abs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]);
var dz = @fabs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]); var dz = @abs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
dx = @max(0, dx - halfWidth); dx = @max(0, dx - halfWidth);
dy = @max(0, dy - halfWidth); dy = @max(0, dy - halfWidth);
dz = @max(0, dz - halfWidth); dz = @max(0, dz - halfWidth);
@ -128,9 +128,9 @@ pub const ChunkPosition = struct {
pub fn getMaxDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 { pub fn getMaxDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 {
var halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2)); var halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2));
var dx = @fabs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]); var dx = @abs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
var dy = @fabs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]); var dy = @abs(@as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]);
var dz = @fabs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]); var dz = @abs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
dx = dx + halfWidth; dx = dx + halfWidth;
dy = dy + halfWidth; dy = dy + halfWidth;
dz = dz + halfWidth; dz = dz + halfWidth;
@ -609,7 +609,7 @@ pub const meshing = struct {
const fullDx = dx - Neighbors.relX[normal]; const fullDx = dx - Neighbors.relX[normal];
const fullDy = dy - Neighbors.relY[normal]; const fullDy = dy - Neighbors.relY[normal];
const fullDz = dz - Neighbors.relZ[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 { const BoundingRectToNeighborChunk = struct {

View File

@ -172,7 +172,7 @@ pub const World = struct {
} }
// Ambient light: // 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) { if(dayTime < dayCycle/4 - dayCycle/16) {
self.ambientLight = 0.1; self.ambientLight = 0.1;
self.clearColor[0] = 0; self.clearColor[0] = 0;

View File

@ -228,14 +228,14 @@ fn snapToOtherWindow(self: *GuiWindow) void {
if(start >= end) continue; if(start >= end) continue;
if(detectCycles(self, other)) 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) { if(dist1 < minDist) {
minDist = dist1; minDist = dist1;
minWindow = other; minWindow = other;
selfAttachment = .lower; selfAttachment = .lower;
otherAttachment = .upper; 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) { if(dist2 < minDist) {
minDist = dist2; minDist = dist2;
minWindow = other; minWindow = other;
@ -253,17 +253,17 @@ fn positionRelativeToFrame(self: *GuiWindow) void {
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale)); const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
for(&self.relativePosition, 0..) |*relPos, i| { for(&self.relativePosition, 0..) |*relPos, i| {
// Snap to the center: // 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 = .{ relPos.* = .{.attachedToFrame = .{
.selfAttachmentPoint = .upper, .selfAttachmentPoint = .upper,
.otherAttachmentPoint = .middle, .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 = .{ relPos.* = .{.attachedToFrame = .{
.selfAttachmentPoint = .middle, .selfAttachmentPoint = .middle,
.otherAttachmentPoint = .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 = .{ relPos.* = .{.attachedToFrame = .{
.selfAttachmentPoint = .lower, .selfAttachmentPoint = .lower,
.otherAttachmentPoint = .middle, .otherAttachmentPoint = .middle,
@ -284,32 +284,32 @@ fn positionRelativeToConnectedWindow(self: *GuiWindow, other: *GuiWindow, i: usi
const otherSize = other.size; const otherSize = other.size;
const relPos = &self.relativePosition[i]; const relPos = &self.relativePosition[i];
// Snap to the center: // 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 = .{ relPos.* = .{.attachedToWindow = .{
.reference = other, .reference = other,
.selfAttachmentPoint = .upper, .selfAttachmentPoint = .upper,
.otherAttachmentPoint = .middle, .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 = .{ relPos.* = .{.attachedToWindow = .{
.reference = other, .reference = other,
.selfAttachmentPoint = .middle, .selfAttachmentPoint = .middle,
.otherAttachmentPoint = .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 = .{ relPos.* = .{.attachedToWindow = .{
.reference = other, .reference = other,
.selfAttachmentPoint = .lower, .selfAttachmentPoint = .lower,
.otherAttachmentPoint = .middle, .otherAttachmentPoint = .middle,
}}; }};
// Snap to the edges: // 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 = .{ relPos.* = .{.attachedToWindow = .{
.reference = other, .reference = other,
.selfAttachmentPoint = .lower, .selfAttachmentPoint = .lower,
.otherAttachmentPoint = .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 = .{ relPos.* = .{.attachedToWindow = .{
.reference = other, .reference = other,
.selfAttachmentPoint = .upper, .selfAttachmentPoint = .upper,

View File

@ -651,8 +651,8 @@ const ToolPhysics = struct {
while(y < 16) : (y += 1) { while(y < 16) : (y += 1) {
const angle = std.math.atan2(f32, y + 0.5 - center[1], x + 0.5 - center[0]) - initialAngle; 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 distance = @cos(angle)*vec.length(center - Vec2f{x + 0.5, y + 0.5});
const deltaAngle = @fabs(angle - originalAngle); const deltaAngle = @abs(angle - originalAngle);
const deltaDist = @fabs(distance - originalDistance); const deltaDist = @abs(distance - originalDistance);
if(deltaAngle <= 0.2 and deltaDist <= 0.7) { if(deltaAngle <= 0.2 and deltaDist <= 0.7) {
numOfSmoothPixels += 1; numOfSmoothPixels += 1;
} }

View File

@ -173,7 +173,7 @@ fn log(_x: u16, _y: u16, _z: u16) ?u4 {
return Neighbors.dirDown; return Neighbors.dirDown;
} }
if(x*x + z*z < 8.0*8.0) { 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; if(x < 0) return Neighbors.dirNegX;
return Neighbors.dirPosX; return Neighbors.dirPosX;
} else { } else {

View File

@ -1079,7 +1079,7 @@ pub const Protocols = struct {
defer json.free(main.threadAllocator); defer json.free(main.threadAllocator);
var expectedTime = json.get(i64, "time", 0); var expectedTime = json.get(i64, "time", 0);
var curTime = world.gameTime.load(.Monotonic); 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); world.gameTime.store(expectedTime, .Monotonic);
} else if(curTime < expectedTime) { // world.gameTime++ } else if(curTime < expectedTime) { // world.gameTime++
while(world.gameTime.tryCompareAndSwap(curTime, curTime +% 1, .Monotonic, .Monotonic)) |actualTime| { while(world.gameTime.tryCompareAndSwap(curTime, curTime +% 1, .Monotonic, .Monotonic)) |actualTime| {

View File

@ -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 // 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 step = vec.intFromFloat(i32, std.math.sign(dir));
const invDir = @as(Vec3d, @splat(1))/dir; const invDir = @as(Vec3d, @splat(1))/dir;
const tDelta = @fabs(invDir); const tDelta = @abs(invDir);
var tMax = (@floor(pos) - pos)*invDir; var tMax = (@floor(pos) - pos)*invDir;
tMax = @max(tMax, tMax + tDelta*vec.floatFromInt(f64, step)); 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); 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; var x = minX;
while(x != maxX): (x +%= size) { while(x != maxX): (x +%= size) {
const xIndex = @divExact(x -% startX, 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); deltaX = @max(0, deltaX - size/2);
const maxYRenderDistanceSquare: f64 = @floatFromInt(@as(i64, maxRenderDistance)*@as(i64, maxRenderDistance) - deltaX*deltaX); const maxYRenderDistanceSquare: f64 = @floatFromInt(@as(i64, maxRenderDistance)*@as(i64, maxRenderDistance) - deltaX*deltaX);
const maxYRenderDistance: i32 = @intFromFloat(@ceil(@sqrt(maxYRenderDistanceSquare))); const maxYRenderDistance: i32 = @intFromFloat(@ceil(@sqrt(maxYRenderDistanceSquare)));
@ -1030,7 +1030,7 @@ pub const RenderStructure = struct {
var y = minY; var y = minY;
while(y != maxY): (y +%= size) { while(y != maxY): (y +%= size) {
const yIndex = @divExact(y -% startY, 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); deltaY = @max(0, deltaY - size/2);
const maxZRenderDistanceSquare: f64 = @floatFromInt(@as(i64, maxYRenderDistance)*@as(i64, maxYRenderDistance) - deltaY*deltaY); const maxZRenderDistanceSquare: f64 = @floatFromInt(@as(i64, maxYRenderDistance)*@as(i64, maxYRenderDistance) - deltaY*deltaY);
const maxZRenderDistance: i32 = @intFromFloat(@ceil(@sqrt(maxZRenderDistanceSquare))); const maxZRenderDistance: i32 = @intFromFloat(@ceil(@sqrt(maxZRenderDistanceSquare)));

View File

@ -141,7 +141,7 @@ pub const InterpolatableCaveBiomeMapView = struct {
return @shuffle(i32, in, undefined, Vec3i{2, 0, 1}); return @shuffle(i32, in, undefined, Vec3i{2, 0, 1});
} }
fn argMaxDistance0(distance: Vec3i) @Vector(3, bool) { 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[1]) {
if(absDistance[0] > absDistance[2]) { if(absDistance[0] > absDistance[2]) {
return .{true, false, false}; return .{true, false, false};
@ -157,7 +157,7 @@ pub const InterpolatableCaveBiomeMapView = struct {
} }
} }
fn argMaxDistance1(distance: Vec3i) @Vector(3, bool) { 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[1]) {
if(absDistance[0] >= absDistance[2]) { if(absDistance[0] >= absDistance[2]) {
return .{true, false, false}; return .{true, false, false};
@ -333,7 +333,7 @@ pub const InterpolatableCaveBiomeMapView = struct {
const distanceX = wx - gridPointX; const distanceX = wx - gridPointX;
const distanceY = wy - gridPointY; const distanceY = wy - gridPointY;
const distanceZ = wz - gridPointZ; 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) { if(totalDistance > CaveBiomeMapFragment.caveBiomeSize*3/4) {
// Or with 1 to prevent errors if the value is 0. // Or with 1 to prevent errors if the value is 0.
gridPointX += (std.math.sign(distanceX | 1) - 1)*(CaveBiomeMapFragment.caveBiomeSize/2); gridPointX += (std.math.sign(distanceX | 1) - 1)*(CaveBiomeMapFragment.caveBiomeSize/2);

View File

@ -234,7 +234,7 @@ const GenerationStructure = struct {
var weight: f32 = @max(1.0 - @sqrt(dist), 0); var weight: f32 = @max(1.0 - @sqrt(dist), 0);
weight *= weight; 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. // 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; height += biomePoint.height*weight;
roughness += biomePoint.biome.roughness*weight; roughness += biomePoint.biome.roughness*weight;
hills += biomePoint.biome.hills*weight; hills += biomePoint.biome.hills*weight;

View File

@ -150,7 +150,7 @@ pub fn generateRidgidNoise(allocator: Allocator, x: i32, y: i32, width: u31, hei
while(x1 -% width -% x < 0) : (x1 += voxelSize) { while(x1 -% width -% x < 0) : (x1 += voxelSize) {
var y1 = y; var y1 = y;
while(y1 -% y -% height < 0) : (y1 += voxelSize) { 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; 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) { while(x1 -% width -% x < 0) : (x1 += voxelSize) {
var y1 = y; var y1 = y;
while(y1 -% y -% height < 0) : (y1 += voxelSize) { 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; fac *= reductionFactor;