Use array @splat

progress towards #1160
This commit is contained in:
IntegratedQuantum 2025-03-06 22:08:15 +01:00
parent 9d786abcb5
commit 471210f585
10 changed files with 30 additions and 30 deletions

View File

@ -45,7 +45,7 @@ pub const ClientEntity = struct {
@floatCast(self.rot[1]),
@floatCast(self.rot[2]),
};
self._interpolationVel = [_]f64{0} ** 6;
self._interpolationVel = @splat(0);
self.interpolatedValues.init(&self._interpolationPos, &self._interpolationVel);
}
@ -176,7 +176,7 @@ pub const ClientEntityManager = struct {
if(ent.id == game.Player.id) continue; // don't render local player
const blockPos: vec.Vec3i = @intFromFloat(@floor(ent.pos));
const lightVals: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse .{0} ** 6;
const lightVals: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse @splat(0);
const light = (@as(u32, lightVals[0] >> 3) << 25 |
@as(u32, lightVals[1] >> 3) << 20 |
@as(u32, lightVals[2] >> 3) << 15 |

View File

@ -479,7 +479,7 @@ pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
}
// Mouse deltas are averaged over multiple frames using a circular buffer:
const deltasLen: u2 = 3;
var deltas: [deltasLen]Vec2f = [_]Vec2f{Vec2f{0, 0}} ** 3;
var deltas: [deltasLen]Vec2f = @splat(.{0, 0});
var deltaBufferPosition: u2 = 0;
var currentPos: Vec2f = Vec2f{0, 0};
var ignoreDataAfterRecentGrab: bool = true;

View File

@ -682,7 +682,7 @@ pub const ItemDropRenderer = struct { // MARK: ItemDropRenderer
var pos = itemDrops.list.items(.pos)[i];
const rot = itemDrops.list.items(.rot)[i];
const blockPos: Vec3i = @intFromFloat(@floor(pos));
const light: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse .{0} ** 6;
const light: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse @splat(0);
c.glUniform3fv(itemUniforms.ambientLight, 1, @ptrCast(&@max(
ambientLight*@as(Vec3f, @as(Vec3f, @floatFromInt(Vec3i{light[0], light[1], light[2]}))/@as(Vec3f, @splat(255))),
@as(Vec3f, @floatFromInt(Vec3i{light[3], light[4], light[5]}))/@as(Vec3f, @splat(255)),

View File

@ -109,7 +109,7 @@ pub const Model = struct {
var internalAmount: usize = 0;
self.min = .{1, 1, 1};
self.max = .{0, 0, 0};
self.isNeighborOccluded = .{false} ** 6;
self.isNeighborOccluded = @splat(false);
for(adjustedQuads) |*quad| {
for(quad.corners) |corner| {
self.min = @min(self.min, corner);

View File

@ -255,7 +255,7 @@ const STUN = struct { // MARK: STUN
fn requestAddress(connection: *ConnectionManager) Address {
var oldAddress: ?Address = null;
var seed = [_]u8{0} ** std.Random.DefaultCsprng.secret_seed_length;
var seed: [std.Random.DefaultCsprng.secret_seed_length]u8 = @splat(0);
std.mem.writeInt(i128, seed[0..16], std.time.nanoTimestamp(), builtin.cpu.arch.endian()); // Not the best seed, but it's not that important.
var random = std.Random.DefaultCsprng.init(seed);
for(0..16) |_| {
@ -631,11 +631,11 @@ const UnconfirmedPacket = struct {
};
// MARK: Protocols
pub var bytesReceived: [256]Atomic(usize) = .{Atomic(usize).init(0)} ** 256;
pub var packetsReceived: [256]Atomic(usize) = .{Atomic(usize).init(0)} ** 256;
pub var bytesReceived: [256]Atomic(usize) = @splat(.init(0));
pub var packetsReceived: [256]Atomic(usize) = @splat(.init(0));
pub const Protocols = struct {
pub var list: [256]?*const fn(*Connection, *utils.BinaryReader) anyerror!void = [_]?*const fn(*Connection, *utils.BinaryReader) anyerror!void{null} ** 256;
pub var isAsynchronous: [256]bool = .{false} ** 256;
pub var list: [256]?*const fn(*Connection, *utils.BinaryReader) anyerror!void = @splat(null);
pub var isAsynchronous: [256]bool = @splat(false);
pub const keepAlive: u8 = 0;
pub const important: u8 = 0xff;
@ -1257,7 +1257,7 @@ pub const Connection = struct { // MARK: Connection
packetQueue: main.utils.CircularBufferQueue(UnconfirmedPacket) = undefined,
unconfirmedPackets: main.List(UnconfirmedPacket) = undefined,
receivedPackets: [3]main.List(u32) = undefined,
__lastReceivedPackets: [65536]?[]const u8 = [_]?[]const u8{null} ** 65536, // TODO: Wait for #12215 fix.
__lastReceivedPackets: [65536]?[]const u8 = @splat(null), // TODO: Wait for #12215 fix.
lastReceivedPackets: []?[]const u8, // TODO: Wait for #12215 fix.
packetMemory: *[65536][maxImportantPacketSize]u8 = undefined,
lastIndex: u32 = 0,
@ -1268,8 +1268,8 @@ pub const Connection = struct { // MARK: Connection
lastKeepAliveReceived: u32 = 0,
otherKeepAliveReceived: u32 = 0,
congestionControl_bandWidthSentHistory: [congestionControl_historySize]usize = .{0} ** 16,
congestionControl_bandWidthReceivedHistory: [congestionControl_historySize]usize = .{0} ** 16,
congestionControl_bandWidthSentHistory: [congestionControl_historySize]usize = @splat(0),
congestionControl_bandWidthReceivedHistory: [congestionControl_historySize]usize = @splat(0),
congestionControl_bandWidthEstimate: usize = minimumBandWidth,
congestionControl_inversebandWidth: f32 = timeUnit/minimumBandWidth,
congestionControl_lastSendTime: i64,

View File

@ -287,18 +287,18 @@ pub const IndirectData = extern struct {
const PrimitiveMesh = struct { // MARK: PrimitiveMesh
coreFaces: main.ListUnmanaged(FaceData) = .{},
neighborFacesSameLod: [6]main.ListUnmanaged(FaceData) = [_]main.ListUnmanaged(FaceData){.{}} ** 6,
neighborFacesHigherLod: [6]main.ListUnmanaged(FaceData) = [_]main.ListUnmanaged(FaceData){.{}} ** 6,
neighborFacesSameLod: [6]main.ListUnmanaged(FaceData) = @splat(.{}),
neighborFacesHigherLod: [6]main.ListUnmanaged(FaceData) = @splat(.{}),
optionalFaces: main.ListUnmanaged(FaceData) = .{},
completeList: []FaceData = &.{},
coreLen: u32 = 0,
sameLodLens: [6]u32 = .{0} ** 6,
higherLodLens: [6]u32 = .{0} ** 6,
sameLodLens: [6]u32 = @splat(0),
higherLodLens: [6]u32 = @splat(0),
optionalLen: u32 = 0,
mutex: std.Thread.Mutex = .{},
bufferAllocation: graphics.SubAllocation = .{.start = 0, .len = 0},
vertexCount: u31 = 0,
byNormalCount: [14]u32 = .{0} ** 14,
byNormalCount: [14]u32 = @splat(0),
wasChanged: bool = false,
min: Vec3f = undefined,
max: Vec3f = undefined,
@ -523,7 +523,7 @@ const PrimitiveMesh = struct { // MARK: PrimitiveMesh
for(0..6) |i| {
rawVals[i] = std.math.lossyCast(u5, fullValues[i]/8);
}
return packLightValues(.{rawVals} ** 4);
return packLightValues(@splat(rawVals));
}
if(models.extraQuadInfos.items[quadIndex].hasOnlyCornerVertices) { // Fast path for simple quads.
var rawVals: [4][6]u5 = undefined;
@ -689,9 +689,9 @@ pub const ChunkMesh = struct { // MARK: ChunkMesh
lightListNeedsUpload: bool = false,
lightAllocation: graphics.SubAllocation = .{.start = 0, .len = 0},
lastNeighborsSameLod: [6]?*const ChunkMesh = [_]?*const ChunkMesh{null} ** 6,
lastNeighborsHigherLod: [6]?*const ChunkMesh = [_]?*const ChunkMesh{null} ** 6,
isNeighborLod: [6]bool = .{false} ** 6,
lastNeighborsSameLod: [6]?*const ChunkMesh = @splat(null),
lastNeighborsHigherLod: [6]?*const ChunkMesh = @splat(null),
isNeighborLod: [6]bool = @splat(false),
currentSorting: []SortingData = &.{},
sortingOutputBuffer: []FaceData = &.{},
culledSortingCount: u31 = 0,

View File

@ -26,7 +26,7 @@ const ChunkMeshNode = struct {
finishedMeshing: bool = false, // Must be synced with mesh.finishedMeshing
finishedMeshingHigherResolution: u8 = 0, // Must be synced with finishedMeshing of the 8 higher resolution chunks.
pos: chunk.ChunkPosition = undefined,
isNeighborLod: [6]bool = .{false} ** 6, // Must be synced with mesh.isNeighborLod
isNeighborLod: [6]bool = @splat(false), // Must be synced with mesh.isNeighborLod
mutex: std.Thread.Mutex = .{},
};
const storageSize = 64;
@ -371,7 +371,7 @@ fn freeOldMeshes(olderPx: i32, olderPy: i32, olderPz: i32, olderRD: u16) void {
updateHigherLodNodeFinishedMeshing(mesh.pos, false);
mesh.decreaseRefCount();
}
node.isNeighborLod = .{false} ** 6;
node.isNeighborLod = @splat(false);
}
}
}
@ -700,7 +700,7 @@ pub noinline fn updateAndGetRenderChunks(conn: *network.Connection, frustum: *co
}
for(nodeList.items) |node| {
const pos = node.pos;
var isNeighborLod: [6]bool = .{false} ** 6;
var isNeighborLod: [6]bool = @splat(false);
if(pos.voxelSize != @as(i32, 1) << settings.highestLod) {
for(chunk.Neighbor.iterable) |neighbor| {
var neighborPos = chunk.ChunkPosition{

View File

@ -17,7 +17,7 @@ pub const RegionFile = struct { // MARK: RegionFile
const headerSize = 8 + regionSize*regionSize*regionSize*@sizeOf(u32);
chunks: [regionVolume][]u8 = .{&.{}} ** regionVolume,
chunks: [regionVolume][]u8 = @splat(&.{}),
pos: chunk.ChunkPosition,
mutex: std.Thread.Mutex = .{},
modified: bool = false,

View File

@ -577,8 +577,8 @@ pub fn regenerateLOD(worldName: []const u8) !void { // MARK: regenerateLOD()
const offSetY: usize = @intCast((cur.pos.wy -% nextPos.wy) >> nextPos.voxelSizeShift);
for(0..MapFragment.mapSize/2) |x| {
for(0..MapFragment.mapSize/2) |y| {
var biomes: [4]?*const Biome = .{null} ** 4;
var biomeCounts: [4]u8 = .{0} ** 4;
var biomes: [4]?*const Biome = @splat(null);
var biomeCounts: [4]u8 = @splat(0);
var height: i32 = 0;
for(0..2) |dx| {
for(0..2) |dy| {

View File

@ -1555,7 +1555,7 @@ pub fn Cache(comptime T: type, comptime numberOfBuckets: u32, comptime bucketSiz
const Bucket = struct {
mutex: std.Thread.Mutex = .{},
items: [bucketSize]?*T = [_]?*T{null} ** bucketSize,
items: [bucketSize]?*T = @splat(null),
fn find(self: *@This(), compare: anytype) ?*T {
assertLocked(&self.mutex);
@ -1615,7 +1615,7 @@ pub fn Cache(comptime T: type, comptime numberOfBuckets: u32, comptime bucketSiz
};
return struct {
buckets: [numberOfBuckets]Bucket = [_]Bucket{Bucket{}} ** numberOfBuckets,
buckets: [numberOfBuckets]Bucket = @splat(.{}),
cacheRequests: Atomic(usize) = .init(0),
cacheMisses: Atomic(usize) = .init(0),