mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-07 11:10:52 -04:00
parent
9d786abcb5
commit
471210f585
@ -45,7 +45,7 @@ pub const ClientEntity = struct {
|
|||||||
@floatCast(self.rot[1]),
|
@floatCast(self.rot[1]),
|
||||||
@floatCast(self.rot[2]),
|
@floatCast(self.rot[2]),
|
||||||
};
|
};
|
||||||
self._interpolationVel = [_]f64{0} ** 6;
|
self._interpolationVel = @splat(0);
|
||||||
self.interpolatedValues.init(&self._interpolationPos, &self._interpolationVel);
|
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
|
if(ent.id == game.Player.id) continue; // don't render local player
|
||||||
|
|
||||||
const blockPos: vec.Vec3i = @intFromFloat(@floor(ent.pos));
|
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 |
|
const light = (@as(u32, lightVals[0] >> 3) << 25 |
|
||||||
@as(u32, lightVals[1] >> 3) << 20 |
|
@as(u32, lightVals[1] >> 3) << 20 |
|
||||||
@as(u32, lightVals[2] >> 3) << 15 |
|
@as(u32, lightVals[2] >> 3) << 15 |
|
||||||
|
@ -479,7 +479,7 @@ pub const GLFWCallbacks = struct { // MARK: GLFWCallbacks
|
|||||||
}
|
}
|
||||||
// Mouse deltas are averaged over multiple frames using a circular buffer:
|
// Mouse deltas are averaged over multiple frames using a circular buffer:
|
||||||
const deltasLen: u2 = 3;
|
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 deltaBufferPosition: u2 = 0;
|
||||||
var currentPos: Vec2f = Vec2f{0, 0};
|
var currentPos: Vec2f = Vec2f{0, 0};
|
||||||
var ignoreDataAfterRecentGrab: bool = true;
|
var ignoreDataAfterRecentGrab: bool = true;
|
||||||
|
@ -682,7 +682,7 @@ pub const ItemDropRenderer = struct { // MARK: ItemDropRenderer
|
|||||||
var pos = itemDrops.list.items(.pos)[i];
|
var pos = itemDrops.list.items(.pos)[i];
|
||||||
const rot = itemDrops.list.items(.rot)[i];
|
const rot = itemDrops.list.items(.rot)[i];
|
||||||
const blockPos: Vec3i = @intFromFloat(@floor(pos));
|
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(
|
c.glUniform3fv(itemUniforms.ambientLight, 1, @ptrCast(&@max(
|
||||||
ambientLight*@as(Vec3f, @as(Vec3f, @floatFromInt(Vec3i{light[0], light[1], light[2]}))/@as(Vec3f, @splat(255))),
|
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)),
|
@as(Vec3f, @floatFromInt(Vec3i{light[3], light[4], light[5]}))/@as(Vec3f, @splat(255)),
|
||||||
|
@ -109,7 +109,7 @@ pub const Model = struct {
|
|||||||
var internalAmount: usize = 0;
|
var internalAmount: usize = 0;
|
||||||
self.min = .{1, 1, 1};
|
self.min = .{1, 1, 1};
|
||||||
self.max = .{0, 0, 0};
|
self.max = .{0, 0, 0};
|
||||||
self.isNeighborOccluded = .{false} ** 6;
|
self.isNeighborOccluded = @splat(false);
|
||||||
for(adjustedQuads) |*quad| {
|
for(adjustedQuads) |*quad| {
|
||||||
for(quad.corners) |corner| {
|
for(quad.corners) |corner| {
|
||||||
self.min = @min(self.min, corner);
|
self.min = @min(self.min, corner);
|
||||||
|
@ -255,7 +255,7 @@ const STUN = struct { // MARK: STUN
|
|||||||
|
|
||||||
fn requestAddress(connection: *ConnectionManager) Address {
|
fn requestAddress(connection: *ConnectionManager) Address {
|
||||||
var oldAddress: ?Address = null;
|
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.
|
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);
|
var random = std.Random.DefaultCsprng.init(seed);
|
||||||
for(0..16) |_| {
|
for(0..16) |_| {
|
||||||
@ -631,11 +631,11 @@ const UnconfirmedPacket = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// MARK: Protocols
|
// MARK: Protocols
|
||||||
pub var bytesReceived: [256]Atomic(usize) = .{Atomic(usize).init(0)} ** 256;
|
pub var bytesReceived: [256]Atomic(usize) = @splat(.init(0));
|
||||||
pub var packetsReceived: [256]Atomic(usize) = .{Atomic(usize).init(0)} ** 256;
|
pub var packetsReceived: [256]Atomic(usize) = @splat(.init(0));
|
||||||
pub const Protocols = struct {
|
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 list: [256]?*const fn(*Connection, *utils.BinaryReader) anyerror!void = @splat(null);
|
||||||
pub var isAsynchronous: [256]bool = .{false} ** 256;
|
pub var isAsynchronous: [256]bool = @splat(false);
|
||||||
|
|
||||||
pub const keepAlive: u8 = 0;
|
pub const keepAlive: u8 = 0;
|
||||||
pub const important: u8 = 0xff;
|
pub const important: u8 = 0xff;
|
||||||
@ -1257,7 +1257,7 @@ pub const Connection = struct { // MARK: Connection
|
|||||||
packetQueue: main.utils.CircularBufferQueue(UnconfirmedPacket) = undefined,
|
packetQueue: main.utils.CircularBufferQueue(UnconfirmedPacket) = undefined,
|
||||||
unconfirmedPackets: main.List(UnconfirmedPacket) = undefined,
|
unconfirmedPackets: main.List(UnconfirmedPacket) = undefined,
|
||||||
receivedPackets: [3]main.List(u32) = 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.
|
lastReceivedPackets: []?[]const u8, // TODO: Wait for #12215 fix.
|
||||||
packetMemory: *[65536][maxImportantPacketSize]u8 = undefined,
|
packetMemory: *[65536][maxImportantPacketSize]u8 = undefined,
|
||||||
lastIndex: u32 = 0,
|
lastIndex: u32 = 0,
|
||||||
@ -1268,8 +1268,8 @@ pub const Connection = struct { // MARK: Connection
|
|||||||
lastKeepAliveReceived: u32 = 0,
|
lastKeepAliveReceived: u32 = 0,
|
||||||
otherKeepAliveReceived: u32 = 0,
|
otherKeepAliveReceived: u32 = 0,
|
||||||
|
|
||||||
congestionControl_bandWidthSentHistory: [congestionControl_historySize]usize = .{0} ** 16,
|
congestionControl_bandWidthSentHistory: [congestionControl_historySize]usize = @splat(0),
|
||||||
congestionControl_bandWidthReceivedHistory: [congestionControl_historySize]usize = .{0} ** 16,
|
congestionControl_bandWidthReceivedHistory: [congestionControl_historySize]usize = @splat(0),
|
||||||
congestionControl_bandWidthEstimate: usize = minimumBandWidth,
|
congestionControl_bandWidthEstimate: usize = minimumBandWidth,
|
||||||
congestionControl_inversebandWidth: f32 = timeUnit/minimumBandWidth,
|
congestionControl_inversebandWidth: f32 = timeUnit/minimumBandWidth,
|
||||||
congestionControl_lastSendTime: i64,
|
congestionControl_lastSendTime: i64,
|
||||||
|
@ -287,18 +287,18 @@ pub const IndirectData = extern struct {
|
|||||||
|
|
||||||
const PrimitiveMesh = struct { // MARK: PrimitiveMesh
|
const PrimitiveMesh = struct { // MARK: PrimitiveMesh
|
||||||
coreFaces: main.ListUnmanaged(FaceData) = .{},
|
coreFaces: main.ListUnmanaged(FaceData) = .{},
|
||||||
neighborFacesSameLod: [6]main.ListUnmanaged(FaceData) = [_]main.ListUnmanaged(FaceData){.{}} ** 6,
|
neighborFacesSameLod: [6]main.ListUnmanaged(FaceData) = @splat(.{}),
|
||||||
neighborFacesHigherLod: [6]main.ListUnmanaged(FaceData) = [_]main.ListUnmanaged(FaceData){.{}} ** 6,
|
neighborFacesHigherLod: [6]main.ListUnmanaged(FaceData) = @splat(.{}),
|
||||||
optionalFaces: main.ListUnmanaged(FaceData) = .{},
|
optionalFaces: main.ListUnmanaged(FaceData) = .{},
|
||||||
completeList: []FaceData = &.{},
|
completeList: []FaceData = &.{},
|
||||||
coreLen: u32 = 0,
|
coreLen: u32 = 0,
|
||||||
sameLodLens: [6]u32 = .{0} ** 6,
|
sameLodLens: [6]u32 = @splat(0),
|
||||||
higherLodLens: [6]u32 = .{0} ** 6,
|
higherLodLens: [6]u32 = @splat(0),
|
||||||
optionalLen: u32 = 0,
|
optionalLen: u32 = 0,
|
||||||
mutex: std.Thread.Mutex = .{},
|
mutex: std.Thread.Mutex = .{},
|
||||||
bufferAllocation: graphics.SubAllocation = .{.start = 0, .len = 0},
|
bufferAllocation: graphics.SubAllocation = .{.start = 0, .len = 0},
|
||||||
vertexCount: u31 = 0,
|
vertexCount: u31 = 0,
|
||||||
byNormalCount: [14]u32 = .{0} ** 14,
|
byNormalCount: [14]u32 = @splat(0),
|
||||||
wasChanged: bool = false,
|
wasChanged: bool = false,
|
||||||
min: Vec3f = undefined,
|
min: Vec3f = undefined,
|
||||||
max: Vec3f = undefined,
|
max: Vec3f = undefined,
|
||||||
@ -523,7 +523,7 @@ const PrimitiveMesh = struct { // MARK: PrimitiveMesh
|
|||||||
for(0..6) |i| {
|
for(0..6) |i| {
|
||||||
rawVals[i] = std.math.lossyCast(u5, fullValues[i]/8);
|
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.
|
if(models.extraQuadInfos.items[quadIndex].hasOnlyCornerVertices) { // Fast path for simple quads.
|
||||||
var rawVals: [4][6]u5 = undefined;
|
var rawVals: [4][6]u5 = undefined;
|
||||||
@ -689,9 +689,9 @@ pub const ChunkMesh = struct { // MARK: ChunkMesh
|
|||||||
lightListNeedsUpload: bool = false,
|
lightListNeedsUpload: bool = false,
|
||||||
lightAllocation: graphics.SubAllocation = .{.start = 0, .len = 0},
|
lightAllocation: graphics.SubAllocation = .{.start = 0, .len = 0},
|
||||||
|
|
||||||
lastNeighborsSameLod: [6]?*const ChunkMesh = [_]?*const ChunkMesh{null} ** 6,
|
lastNeighborsSameLod: [6]?*const ChunkMesh = @splat(null),
|
||||||
lastNeighborsHigherLod: [6]?*const ChunkMesh = [_]?*const ChunkMesh{null} ** 6,
|
lastNeighborsHigherLod: [6]?*const ChunkMesh = @splat(null),
|
||||||
isNeighborLod: [6]bool = .{false} ** 6,
|
isNeighborLod: [6]bool = @splat(false),
|
||||||
currentSorting: []SortingData = &.{},
|
currentSorting: []SortingData = &.{},
|
||||||
sortingOutputBuffer: []FaceData = &.{},
|
sortingOutputBuffer: []FaceData = &.{},
|
||||||
culledSortingCount: u31 = 0,
|
culledSortingCount: u31 = 0,
|
||||||
|
@ -26,7 +26,7 @@ const ChunkMeshNode = struct {
|
|||||||
finishedMeshing: bool = false, // Must be synced with mesh.finishedMeshing
|
finishedMeshing: bool = false, // Must be synced with mesh.finishedMeshing
|
||||||
finishedMeshingHigherResolution: u8 = 0, // Must be synced with finishedMeshing of the 8 higher resolution chunks.
|
finishedMeshingHigherResolution: u8 = 0, // Must be synced with finishedMeshing of the 8 higher resolution chunks.
|
||||||
pos: chunk.ChunkPosition = undefined,
|
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 = .{},
|
mutex: std.Thread.Mutex = .{},
|
||||||
};
|
};
|
||||||
const storageSize = 64;
|
const storageSize = 64;
|
||||||
@ -371,7 +371,7 @@ fn freeOldMeshes(olderPx: i32, olderPy: i32, olderPz: i32, olderRD: u16) void {
|
|||||||
updateHigherLodNodeFinishedMeshing(mesh.pos, false);
|
updateHigherLodNodeFinishedMeshing(mesh.pos, false);
|
||||||
mesh.decreaseRefCount();
|
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| {
|
for(nodeList.items) |node| {
|
||||||
const pos = node.pos;
|
const pos = node.pos;
|
||||||
var isNeighborLod: [6]bool = .{false} ** 6;
|
var isNeighborLod: [6]bool = @splat(false);
|
||||||
if(pos.voxelSize != @as(i32, 1) << settings.highestLod) {
|
if(pos.voxelSize != @as(i32, 1) << settings.highestLod) {
|
||||||
for(chunk.Neighbor.iterable) |neighbor| {
|
for(chunk.Neighbor.iterable) |neighbor| {
|
||||||
var neighborPos = chunk.ChunkPosition{
|
var neighborPos = chunk.ChunkPosition{
|
||||||
|
@ -17,7 +17,7 @@ pub const RegionFile = struct { // MARK: RegionFile
|
|||||||
|
|
||||||
const headerSize = 8 + regionSize*regionSize*regionSize*@sizeOf(u32);
|
const headerSize = 8 + regionSize*regionSize*regionSize*@sizeOf(u32);
|
||||||
|
|
||||||
chunks: [regionVolume][]u8 = .{&.{}} ** regionVolume,
|
chunks: [regionVolume][]u8 = @splat(&.{}),
|
||||||
pos: chunk.ChunkPosition,
|
pos: chunk.ChunkPosition,
|
||||||
mutex: std.Thread.Mutex = .{},
|
mutex: std.Thread.Mutex = .{},
|
||||||
modified: bool = false,
|
modified: bool = false,
|
||||||
|
@ -577,8 +577,8 @@ pub fn regenerateLOD(worldName: []const u8) !void { // MARK: regenerateLOD()
|
|||||||
const offSetY: usize = @intCast((cur.pos.wy -% nextPos.wy) >> nextPos.voxelSizeShift);
|
const offSetY: usize = @intCast((cur.pos.wy -% nextPos.wy) >> nextPos.voxelSizeShift);
|
||||||
for(0..MapFragment.mapSize/2) |x| {
|
for(0..MapFragment.mapSize/2) |x| {
|
||||||
for(0..MapFragment.mapSize/2) |y| {
|
for(0..MapFragment.mapSize/2) |y| {
|
||||||
var biomes: [4]?*const Biome = .{null} ** 4;
|
var biomes: [4]?*const Biome = @splat(null);
|
||||||
var biomeCounts: [4]u8 = .{0} ** 4;
|
var biomeCounts: [4]u8 = @splat(0);
|
||||||
var height: i32 = 0;
|
var height: i32 = 0;
|
||||||
for(0..2) |dx| {
|
for(0..2) |dx| {
|
||||||
for(0..2) |dy| {
|
for(0..2) |dy| {
|
||||||
|
@ -1555,7 +1555,7 @@ pub fn Cache(comptime T: type, comptime numberOfBuckets: u32, comptime bucketSiz
|
|||||||
|
|
||||||
const Bucket = struct {
|
const Bucket = struct {
|
||||||
mutex: std.Thread.Mutex = .{},
|
mutex: std.Thread.Mutex = .{},
|
||||||
items: [bucketSize]?*T = [_]?*T{null} ** bucketSize,
|
items: [bucketSize]?*T = @splat(null),
|
||||||
|
|
||||||
fn find(self: *@This(), compare: anytype) ?*T {
|
fn find(self: *@This(), compare: anytype) ?*T {
|
||||||
assertLocked(&self.mutex);
|
assertLocked(&self.mutex);
|
||||||
@ -1615,7 +1615,7 @@ pub fn Cache(comptime T: type, comptime numberOfBuckets: u32, comptime bucketSiz
|
|||||||
};
|
};
|
||||||
|
|
||||||
return struct {
|
return struct {
|
||||||
buckets: [numberOfBuckets]Bucket = [_]Bucket{Bucket{}} ** numberOfBuckets,
|
buckets: [numberOfBuckets]Bucket = @splat(.{}),
|
||||||
cacheRequests: Atomic(usize) = .init(0),
|
cacheRequests: Atomic(usize) = .init(0),
|
||||||
cacheMisses: Atomic(usize) = .init(0),
|
cacheMisses: Atomic(usize) = .init(0),
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user