Update zig, forcing constness

This commit is contained in:
IntegratedQuantum 2023-11-21 16:23:24 +01:00
parent e61709cb69
commit 4f789c4cca
13 changed files with 48 additions and 48 deletions

View File

@ -1 +1 @@
0.12.0-dev.1390+94cee4fb2 0.12.0-dev.1664+8ca4a5240

View File

@ -219,7 +219,7 @@ pub fn loadWorldAssets(assetFolder: []const u8, palette: *BlockPalette) !void {
json = value; json = value;
} else { } else {
std.log.err("Missing block: {s}. Replacing it with default block.", .{id}); 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); map.* = std.StringHashMap(JsonElement).init(main.globalAllocator);
json = JsonElement{.JsonObject=map}; json = JsonElement{.JsonObject=map};
} }

View File

@ -156,9 +156,9 @@ pub const ChunkPosition = struct {
pub fn getCenterDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 { pub fn getCenterDistanceSquared(self: ChunkPosition, playerPosition: Vec3d) f64 {
const halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2)); const halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(chunkSize, 2));
var dx = @as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]; const dx = @as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0];
var dy = @as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1]; const dy = @as(f64, @floatFromInt(self.wy)) + halfWidth - playerPosition[1];
var dz = @as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]; const dz = @as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2];
return dx*dx + dy*dy + dz*dz; return dx*dx + dy*dy + dz*dz;
} }

View File

@ -309,8 +309,8 @@ pub const draw = struct {
pub fn circle(_center: Vec2f, _radius: f32) void { pub fn circle(_center: Vec2f, _radius: f32) void {
var center = _center; var center = _center;
var radius = _radius; var radius = _radius;
_center *= @splat(scale); center *= @splat(scale);
_center += translation; center += translation;
radius *= scale; radius *= scale;
circleShader.bind(); circleShader.bind();

View File

@ -474,7 +474,7 @@ pub fn mainButtonPressed() void {
pub fn mainButtonReleased() void { pub fn mainButtonReleased() void {
if(main.Window.grabbed) return; if(main.Window.grabbed) return;
inventory.applyChanges(true); inventory.applyChanges(true);
var oldWindow = selectedWindow; const oldWindow = selectedWindow;
selectedWindow = null; selectedWindow = null;
for(openWindows.items) |window| { for(openWindows.items) |window| {
var mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale)); var mousePosition = main.Window.getMousePosition()/@as(Vec2f, @splat(scale));

View File

@ -339,7 +339,7 @@ pub const ItemDropManager = struct {
return; return;
} }
var drag: f64 = self.airDragFactor; 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: // Update gravity:
inline for(0..3) |i| { inline for(0..3) |i| {
const old = pos.*[i]; const old = pos.*[i];

View File

@ -537,7 +537,7 @@ const Parser = struct {
break; break;
} }
} }
var lineEnd: u32 = i; const lineEnd: u32 = i;
std.log.warn("Error in line {}: {s}", .{lineNumber, msg}); std.log.warn("Error in line {}: {s}", .{lineNumber, msg});
std.log.warn("{s}", .{chars[lineStart..lineEnd]}); std.log.warn("{s}", .{chars[lineStart..lineEnd]});
// Mark the position: // Mark the position:

View File

@ -59,18 +59,18 @@ fn cube(_: u4, _: u4, _: u4) ?u4 {
const Fence = struct { const Fence = struct {
fn fence0(_x: u4, _y: u4, _z: u4) ?u4 { fn fence0(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7);
var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7);
var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7);
_ = y; _ = y;
if(x < 2 and z < 2) return 6; if(x < 2 and z < 2) return 6;
return null; return null;
} }
fn fence1(_x: u4, _y: u4, _z: u4) ?u4 { fn fence1(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7);
var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7);
var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7);
if(x < 2 and z < 2) return 6; if(x < 2 and z < 2) return 6;
if(y < 5 and y >= 2) { if(y < 5 and y >= 2) {
if(z == 0 and _x < 8) return 6; 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 { fn fence2_neighbor(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7);
var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7);
var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7);
if(x < 2 and z < 2) return 6; if(x < 2 and z < 2) return 6;
if(y < 5 and y >= 2) { if(y < 5 and y >= 2) {
if(z == 0 and _x < 8) return 6; 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 { fn fence2_oppose(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7);
var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7);
var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7);
if(x < 2 and z < 2) return 6; if(x < 2 and z < 2) return 6;
if(y < 5 and y >= 2) { if(y < 5 and y >= 2) {
if(z == 0) return 6; if(z == 0) return 6;
@ -102,9 +102,9 @@ const Fence = struct {
} }
fn fence3(_x: u4, _y: u4, _z: u4) ?u4 { fn fence3(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7);
var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7);
var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7);
if(x < 2 and z < 2) return 6; if(x < 2 and z < 2) return 6;
if(y < 5 and y >= 2) { if(y < 5 and y >= 2) {
if(z == 0 and _x >= 8) return 6; if(z == 0 and _x >= 8) return 6;
@ -114,9 +114,9 @@ const Fence = struct {
} }
fn fence4(_x: u4, _y: u4, _z: u4) ?u4 { fn fence4(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @max(@as(i32, _x)-8, -@as(i32, _x)+7); const x = @max(@as(i32, _x)-8, -@as(i32, _x)+7);
var y = @max(@as(i32, _y)-8, -@as(i32, _y)+7); const y = @max(@as(i32, _y)-8, -@as(i32, _y)+7);
var z = @max(@as(i32, _z)-8, -@as(i32, _z)+7); const z = @max(@as(i32, _z)-8, -@as(i32, _z)+7);
if(x < 2 and z < 2) return 6; if(x < 2 and z < 2) return 6;
if(y < 5 and y >= 2) { if(y < 5 and y >= 2) {
if(x == 0 or z == 0) return 6; if(x == 0 or z == 0) return 6;
@ -126,9 +126,9 @@ const Fence = struct {
}; };
fn log(_x: u4, _y: u4, _z: u4) ?u4 { fn log(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @as(f32, @floatFromInt(_x)) - 7.5; const x = @as(f32, @floatFromInt(_x)) - 7.5;
var y = @as(f32, @floatFromInt(_y)) - 7.5; const y = @as(f32, @floatFromInt(_y)) - 7.5;
var z = @as(f32, @floatFromInt(_z)) - 7.5; const z = @as(f32, @floatFromInt(_z)) - 7.5;
if(x*x + z*z < 7.2*7.2) { if(x*x + z*z < 7.2*7.2) {
if(y > 0) return Neighbors.dirUp; if(y > 0) return Neighbors.dirUp;
return Neighbors.dirDown; 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 { fn sphere(_x: u4, _y: u4, _z: u4) ?u4 {
var x = @as(f32, @floatFromInt(_x)) - 7.5; const x = @as(f32, @floatFromInt(_x)) - 7.5;
var y = @as(f32, @floatFromInt(_y)) - 7.5; const y = @as(f32, @floatFromInt(_y)) - 7.5;
var z = @as(f32, @floatFromInt(_z)) - 7.5; const z = @as(f32, @floatFromInt(_z)) - 7.5;
if(x*x + y*y + z*z < 8.0*8.0) { if(x*x + y*y + z*z < 8.0*8.0) {
return 6; return 6;
} }

View File

@ -1382,7 +1382,7 @@ pub const Connection = struct {
remaining = remaining[8..]; remaining = remaining[8..];
var j: usize = 0; var j: usize = 0;
while(j < self.unconfirmedPackets.items.len) { 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) { if(diff < len) {
main.globalAllocator.free(self.unconfirmedPackets.items[j].data); main.globalAllocator.free(self.unconfirmedPackets.items[j].data);
_ = self.unconfirmedPackets.swapRemove(j); _ = self.unconfirmedPackets.swapRemove(j);
@ -1436,7 +1436,7 @@ pub const Connection = struct {
} }
} }
{ // Cycle the receivedPackets lists: { // 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; var i: u32 = self.receivedPackets.len - 1;
while(i >= 1): (i -= 1) { while(i >= 1): (i -= 1) {
self.receivedPackets[i] = self.receivedPackets[i-1]; self.receivedPackets[i] = self.receivedPackets[i-1];
@ -1510,7 +1510,7 @@ pub const Connection = struct {
id += 1; id += 1;
receivedPacket = self.lastReceivedPackets[id & 65535] orelse return; receivedPacket = self.lastReceivedPackets[id & 65535] orelse return;
} }
var nextByte = receivedPacket[newIndex]; const nextByte = receivedPacket[newIndex];
newIndex += 1; newIndex += 1;
len |= @as(u32, @intCast(nextByte & 0x7f)) << shift; len |= @as(u32, @intCast(nextByte & 0x7f)) << shift;
if(nextByte & 0x80 != 0) { if(nextByte & 0x80 != 0) {

View File

@ -167,7 +167,7 @@ pub fn renderWorld(world: *World, ambientLight: Vec3f, skyColor: Vec3f, playerPo
game.camera.updateViewMatrix(); game.camera.updateViewMatrix();
// Uses FrustumCulling on the chunks. // 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; _ = frustum;
const time: u32 = @intCast(std.time.milliTimestamp() & std.math.maxInt(u32)); const time: u32 = @intCast(std.time.milliTimestamp() & std.math.maxInt(u32));
@ -703,9 +703,9 @@ pub const MeshSelection = struct {
var lastDir: Vec3f = undefined; var lastDir: Vec3f = undefined;
pub fn select(_pos: Vec3d, _dir: Vec3f) void { pub fn select(_pos: Vec3d, _dir: Vec3f) void {
var pos = _pos; var pos = _pos;
// TODO: pos.y += Player.cameraHeight; _ = &pos;// TODO: pos.y += Player.cameraHeight;
lastPos = pos; lastPos = pos;
var dir: Vec3d = @floatCast(_dir); const dir: Vec3d = @floatCast(_dir);
lastDir = _dir; lastDir = _dir;
// Test blocks: // Test blocks:
@ -1019,8 +1019,8 @@ pub const RenderStructure = struct {
fn freeOldMeshes(px: i32, py: i32, pz: i32, renderDistance: i32) !void { fn freeOldMeshes(px: i32, py: i32, pz: i32, renderDistance: i32) !void {
for(0..storageLists.len) |_lod| { for(0..storageLists.len) |_lod| {
const lod: u5 = @intCast(_lod); const lod: u5 = @intCast(_lod);
var maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod; const maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod;
var maxRenderDistanceOld = lastRD*chunk.chunkSize << lod; const maxRenderDistanceOld = lastRD*chunk.chunkSize << lod;
const size: u31 = chunk.chunkSize << lod; const size: u31 = chunk.chunkSize << lod;
const mask: i32 = size - 1; const mask: i32 = size - 1;
const invMask: i32 = ~mask; 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 { fn createNewMeshes(px: i32, py: i32, pz: i32, renderDistance: i32, meshRequests: *std.ArrayList(chunk.ChunkPosition)) !void {
for(0..storageLists.len) |_lod| { for(0..storageLists.len) |_lod| {
const lod: u5 = @intCast(_lod); const lod: u5 = @intCast(_lod);
var maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod; const maxRenderDistanceNew = renderDistance*chunk.chunkSize << lod;
var maxRenderDistanceOld = lastRD*chunk.chunkSize << lod; const maxRenderDistanceOld = lastRD*chunk.chunkSize << lod;
const size: u31 = chunk.chunkSize << lod; const size: u31 = chunk.chunkSize << lod;
const mask: i32 = size - 1; const mask: i32 = size - 1;
const invMask: i32 = ~mask; const invMask: i32 = ~mask;

View File

@ -76,7 +76,7 @@ pub fn generate(map: *CaveBiomeMapFragment, worldSeed: u64) Allocator.Error!void
randomValue -= biome.chance; randomValue -= biome.chance;
if(randomValue < 0) break; if(randomValue < 0) break;
} }
var index = CaveBiomeMapFragment.getIndex(x, y, z); const index = CaveBiomeMapFragment.getIndex(x, y, z);
map.biomeMap[index][_map] = biome; map.biomeMap[index][_map] = biome;
} }
} }

View File

@ -47,7 +47,7 @@ pub fn generate(worldSeed: u64, chunk: *main.chunk.Chunk, caveMap: CaveMap.CaveM
while(y < cy + 1) : (y +%= 1) { while(y < cy + 1) : (y +%= 1) {
var z = cz - 1; var z = cz - 1;
while(z < cz + 1) : (z +%= 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 relX: f32 = @floatFromInt(x-cx << main.chunk.chunkShift);
const relY: f32 = @floatFromInt(y-cy << main.chunk.chunkShift); const relY: f32 = @floatFromInt(y-cy << main.chunk.chunkShift);
const relZ: f32 = @floatFromInt(z-cz << main.chunk.chunkShift); const relZ: f32 = @floatFromInt(z-cz << main.chunk.chunkShift);

View File

@ -373,7 +373,7 @@ pub const StackAllocator = struct {
fn alloc(ctx: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 { fn alloc(ctx: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 {
const self: *StackAllocator = @ptrCast(@alignCast(ctx)); const self: *StackAllocator = @ptrCast(@alignCast(ctx));
if(len >= self.buffer.len) return self.backingAllocator.rawAlloc(len, ptr_align, ret_addr); 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); 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.allocationList.append(.{.start = @intCast(start), .len = @intCast(len)}) catch return null;
self.index = start + len; self.index = start + len;
@ -601,7 +601,7 @@ pub const ThreadPool = struct {
allocator: Allocator, allocator: Allocator,
pub fn init(allocator: Allocator, threadCount: usize) !ThreadPool { pub fn init(allocator: Allocator, threadCount: usize) !ThreadPool {
var self = ThreadPool { const self = ThreadPool {
.threads = try allocator.alloc(std.Thread, threadCount), .threads = try allocator.alloc(std.Thread, threadCount),
.currentTasks = try allocator.alloc(std.atomic.Atomic(?*const VTable), threadCount), .currentTasks = try allocator.alloc(std.atomic.Atomic(?*const VTable), threadCount),
.loadList = try BlockingMaxHeap(Task).init(allocator), .loadList = try BlockingMaxHeap(Task).init(allocator),