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;
} 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};
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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));

View File

@ -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];

View File

@ -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:

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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),