diff --git a/.zig-version b/.zig-version index 36250b77..0078b6f8 100644 --- a/.zig-version +++ b/.zig-version @@ -1 +1 @@ -0.12.0-dev.1390+94cee4fb2 \ No newline at end of file +0.12.0-dev.1664+8ca4a5240 \ No newline at end of file diff --git a/src/assets.zig b/src/assets.zig index 28152f07..3811ef37 100644 --- a/src/assets.zig +++ b/src/assets.zig @@ -219,7 +219,7 @@ pub fn loadWorldAssets(assetFolder: []const u8, palette: *BlockPalette) !void { json = value; } else { std.log.err("Missing block: {s}. Replacing it with default block.", .{id}); - var map: *std.StringHashMap(JsonElement) = try main.globalAllocator.create(std.StringHashMap(JsonElement)); + const map: *std.StringHashMap(JsonElement) = try main.globalAllocator.create(std.StringHashMap(JsonElement)); map.* = std.StringHashMap(JsonElement).init(main.globalAllocator); json = JsonElement{.JsonObject=map}; } diff --git a/src/chunk.zig b/src/chunk.zig index 09ff6ed5..0a1c94a0 100644 --- a/src/chunk.zig +++ b/src/chunk.zig @@ -156,9 +156,9 @@ pub const ChunkPosition = struct { pub fn getCenterDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 { const halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2)); - var dx = @as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]; - var dy = @as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]; - var dz = @as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]; + const dx = @as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]; + const dy = @as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]; + const dz = @as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]; return dx*dx + dy*dy + dz*dz; } diff --git a/src/graphics.zig b/src/graphics.zig index e39e97ca..a1a83d2e 100644 --- a/src/graphics.zig +++ b/src/graphics.zig @@ -309,8 +309,8 @@ pub const draw = struct { pub fn circle(_center: Vec2f, _radius: f32) void { var center = _center; var radius = _radius; - _center *= @splat(scale); - _center += translation; + center *= @splat(scale); + center += translation; radius *= scale; circleShader.bind(); diff --git a/src/gui/gui.zig b/src/gui/gui.zig index d74c045f..1a720ef6 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -474,7 +474,7 @@ pub fn mainButtonPressed() void { pub fn mainButtonReleased() void { if(main.Window.grabbed) return; inventory.applyChanges(true); - var oldWindow = selectedWindow; + const oldWindow = selectedWindow; selectedWindow = null; for(openWindows.items) |window| { var mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale)); diff --git a/src/itemdrop.zig b/src/itemdrop.zig index b1fafb8b..7af29eb8 100644 --- a/src/itemdrop.zig +++ b/src/itemdrop.zig @@ -339,7 +339,7 @@ pub const ItemDropManager = struct { return; } var drag: f64 = self.airDragFactor; - var acceleration: Vec3d = Vec3d{0, -self.gravity*deltaTime, 0}; + const acceleration: Vec3d = Vec3d{0, -self.gravity*deltaTime, 0}; // Update gravity: inline for(0..3) |i| { const old = pos.*[i]; diff --git a/src/json.zig b/src/json.zig index 67abf502..7833d8b5 100644 --- a/src/json.zig +++ b/src/json.zig @@ -537,7 +537,7 @@ const Parser = struct { break; } } - var lineEnd: u32 = i; + const lineEnd: u32 = i; std.log.warn("Error in line {}: {s}", .{lineNumber, msg}); std.log.warn("{s}", .{chars[lineStart..lineEnd]}); // Mark the position: diff --git a/src/models.zig b/src/models.zig index ec084195..53de36e1 100644 --- a/src/models.zig +++ b/src/models.zig @@ -59,18 +59,18 @@ fn cube(_: u4, _: u4, _: u4) ?u4 { const Fence = struct { fn fence0(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); - var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); - var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); + const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); + const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); + const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); _ = y; if(x < 2 and z < 2) return 6; return null; } fn fence1(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); - var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); - var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); + const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); + const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); + const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); if(x < 2 and z < 2) return 6; if(y < 5 and y >= 2) { if(z == 0 and _x < 8) return 6; @@ -79,9 +79,9 @@ const Fence = struct { } fn fence2_neighbor(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); - var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); - var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); + const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); + const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); + const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); if(x < 2 and z < 2) return 6; if(y < 5 and y >= 2) { if(z == 0 and _x < 8) return 6; @@ -91,9 +91,9 @@ const Fence = struct { } fn fence2_oppose(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); - var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); - var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); + const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); + const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); + const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); if(x < 2 and z < 2) return 6; if(y < 5 and y >= 2) { if(z == 0) return 6; @@ -102,9 +102,9 @@ const Fence = struct { } fn fence3(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); - var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); - var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); + const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); + const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); + const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); if(x < 2 and z < 2) return 6; if(y < 5 and y >= 2) { if(z == 0 and _x >= 8) return 6; @@ -114,9 +114,9 @@ const Fence = struct { } fn fence4(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); - var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); - var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); + const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); + const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); + const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); if(x < 2 and z < 2) return 6; if(y < 5 and y >= 2) { if(x == 0 or z == 0) return 6; @@ -126,9 +126,9 @@ const Fence = struct { }; fn log(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @as(f32, @floatFromInt(_x)) - 7.5; - var y = @as(f32, @floatFromInt(_y)) - 7.5; - var z = @as(f32, @floatFromInt(_z)) - 7.5; + const x = @as(f32, @floatFromInt(_x)) - 7.5; + const y = @as(f32, @floatFromInt(_y)) - 7.5; + const z = @as(f32, @floatFromInt(_z)) - 7.5; if(x*x + z*z < 7.2*7.2) { if(y > 0) return Neighbors.dirUp; return Neighbors.dirDown; @@ -146,9 +146,9 @@ fn log(_x: u4, _y: u4, _z: u4) ?u4 { } fn sphere(_x: u4, _y: u4, _z: u4) ?u4 { - var x = @as(f32, @floatFromInt(_x)) - 7.5; - var y = @as(f32, @floatFromInt(_y)) - 7.5; - var z = @as(f32, @floatFromInt(_z)) - 7.5; + const x = @as(f32, @floatFromInt(_x)) - 7.5; + const y = @as(f32, @floatFromInt(_y)) - 7.5; + const z = @as(f32, @floatFromInt(_z)) - 7.5; if(x*x + y*y + z*z < 8.0*8.0) { return 6; } diff --git a/src/network.zig b/src/network.zig index 2a563a24..f95c1941 100644 --- a/src/network.zig +++ b/src/network.zig @@ -1382,7 +1382,7 @@ pub const Connection = struct { remaining = remaining[8..]; var j: usize = 0; while(j < self.unconfirmedPackets.items.len) { - var diff = self.unconfirmedPackets.items[j].id -% start; + const diff = self.unconfirmedPackets.items[j].id -% start; if(diff < len) { main.globalAllocator.free(self.unconfirmedPackets.items[j].data); _ = self.unconfirmedPackets.swapRemove(j); @@ -1436,7 +1436,7 @@ pub const Connection = struct { } } { // Cycle the receivedPackets lists: - var putBackToFront: std.ArrayList(u32) = self.receivedPackets[self.receivedPackets.len - 1]; + const putBackToFront: std.ArrayList(u32) = self.receivedPackets[self.receivedPackets.len - 1]; var i: u32 = self.receivedPackets.len - 1; while(i >= 1): (i -= 1) { self.receivedPackets[i] = self.receivedPackets[i-1]; @@ -1510,7 +1510,7 @@ pub const Connection = struct { id += 1; receivedPacket = self.lastReceivedPackets[id & 65535] orelse return; } - var nextByte = receivedPacket[newIndex]; + const nextByte = receivedPacket[newIndex]; newIndex += 1; len |= @as(u32, @intCast(nextByte & 0x7f)) << shift; if(nextByte & 0x80 != 0) { diff --git a/src/renderer.zig b/src/renderer.zig index 7e16f2fc..fb3ea29f 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -167,7 +167,7 @@ pub fn renderWorld(world: *World, ambientLight: Vec3f, skyColor: Vec3f, playerPo game.camera.updateViewMatrix(); // Uses FrustumCulling on the chunks. - var frustum = Frustum.init(Vec3f{0, 0, 0}, game.camera.viewMatrix, lastFov, lastWidth, lastHeight); + const frustum = Frustum.init(Vec3f{0, 0, 0}, game.camera.viewMatrix, lastFov, lastWidth, lastHeight); _ = frustum; const time: u32 = @intCast(std.time.milliTimestamp() & std.math.maxInt(u32)); @@ -703,9 +703,9 @@ pub const MeshSelection = struct { var lastDir: Vec3f = undefined; pub fn select(_pos: Vec3d, _dir: Vec3f) void { var pos = _pos; - // TODO: pos.y += Player.cameraHeight; + _ = &pos;// TODO: pos.y += Player.cameraHeight; lastPos = pos; - var dir: Vec3d = @floatCast(_dir); + const dir: Vec3d = @floatCast(_dir); lastDir = _dir; // Test blocks: @@ -1019,8 +1019,8 @@ pub const RenderStructure = struct { fn freeOldMeshes(px: i32, py: i32, pz: i32, renderDistance: i32) !void { for(0..storageLists.len) |_lod| { const lod: u5 = @intCast(_lod); - var maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod; - var maxRenderDistanceOld = lastRD*chunk.chunkSize << lod; + const maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod; + const maxRenderDistanceOld = lastRD*chunk.chunkSize << lod; const size: u31 = chunk.chunkSize << lod; const mask: i32 = size - 1; const invMask: i32 = ~mask; @@ -1104,8 +1104,8 @@ pub const RenderStructure = struct { fn createNewMeshes(px: i32, py: i32, pz: i32, renderDistance: i32, meshRequests: *std.ArrayList(chunk.ChunkPosition)) !void { for(0..storageLists.len) |_lod| { const lod: u5 = @intCast(_lod); - var maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod; - var maxRenderDistanceOld = lastRD*chunk.chunkSize << lod; + const maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod; + const maxRenderDistanceOld = lastRD*chunk.chunkSize << lod; const size: u31 = chunk.chunkSize << lod; const mask: i32 = size - 1; const invMask: i32 = ~mask; diff --git a/src/server/terrain/cavebiomegen/RandomBiomeDistribution.zig b/src/server/terrain/cavebiomegen/RandomBiomeDistribution.zig index c80f24a1..cd5a7369 100644 --- a/src/server/terrain/cavebiomegen/RandomBiomeDistribution.zig +++ b/src/server/terrain/cavebiomegen/RandomBiomeDistribution.zig @@ -76,7 +76,7 @@ pub fn generate(map: *CaveBiomeMapFragment, worldSeed: u64) Allocator.Error!void randomValue -= biome.chance; if(randomValue < 0) break; } - var index = CaveBiomeMapFragment.getIndex(x, y, z); + const index = CaveBiomeMapFragment.getIndex(x, y, z); map.biomeMap[index][_map] = biome; } } diff --git a/src/server/terrain/chunkgen/OreGenerator.zig b/src/server/terrain/chunkgen/OreGenerator.zig index e406d0a7..7d3a6efa 100644 --- a/src/server/terrain/chunkgen/OreGenerator.zig +++ b/src/server/terrain/chunkgen/OreGenerator.zig @@ -47,7 +47,7 @@ pub fn generate(worldSeed: u64, chunk: *main.chunk.Chunk, caveMap: CaveMap.CaveM while(y < cy + 1) : (y +%= 1) { var z = cz - 1; while(z < cz + 1) : (z +%= 1) { - var seed = random.initSeed3D(worldSeed, .{x, y, z}); + const seed = random.initSeed3D(worldSeed, .{x, y, z}); const relX: f32 = @floatFromInt(x-cx << main.chunk.chunkShift); const relY: f32 = @floatFromInt(y-cy << main.chunk.chunkShift); const relZ: f32 = @floatFromInt(z-cz << main.chunk.chunkShift); diff --git a/src/utils.zig b/src/utils.zig index ffd61efd..e21ce246 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -373,7 +373,7 @@ pub const StackAllocator = struct { fn alloc(ctx: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 { const self: *StackAllocator = @ptrCast(@alignCast(ctx)); if(len >= self.buffer.len) return self.backingAllocator.rawAlloc(len, ptr_align, ret_addr); - var start = std.mem.alignForward(usize, self.index, @as(usize, 1) << @intCast(ptr_align)); + const start = std.mem.alignForward(usize, self.index, @as(usize, 1) << @intCast(ptr_align)); if(start + len >= self.buffer.len) return self.backingAllocator.rawAlloc(len, ptr_align, ret_addr); self.allocationList.append(.{.start = @intCast(start), .len = @intCast(len)}) catch return null; self.index = start + len; @@ -601,7 +601,7 @@ pub const ThreadPool = struct { allocator: Allocator, pub fn init(allocator: Allocator, threadCount: usize) !ThreadPool { - var self = ThreadPool { + const self = ThreadPool { .threads = try allocator.alloc(std.Thread, threadCount), .currentTasks = try allocator.alloc(std.atomic.Atomic(?*const VTable), threadCount), .loadList = try BlockingMaxHeap(Task).init(allocator),