mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Better chunk load order, and better loading priority.
This commit is contained in:
parent
aa3a769dbe
commit
bb2786c36f
@ -93,6 +93,10 @@ pub const ChunkPosition = struct {
|
|||||||
dz = @maximum(0, dz - halfWidth);
|
dz = @maximum(0, dz - halfWidth);
|
||||||
return dx*dx + dy*dy + dz*dz;
|
return dx*dx + dy*dy + dz*dz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getPriority(self: ChunkPosition, playerPos: Vec3d) f32 {
|
||||||
|
return -@floatCast(f32, self.getMinDistanceSquared(playerPos))/@intToFloat(f32, self.voxelSize*self.voxelSize) + 2*@intToFloat(f32, std.math.log2_int(UChunkCoordinate, self.voxelSize)*chunkSize*chunkSize);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Chunk = struct {
|
pub const Chunk = struct {
|
||||||
|
@ -341,6 +341,7 @@ pub const ConnectionManager = struct {
|
|||||||
errdefer Socket.deinit(result.socket);
|
errdefer Socket.deinit(result.socket);
|
||||||
|
|
||||||
result.thread = try std.Thread.spawn(.{}, run, .{result});
|
result.thread = try std.Thread.spawn(.{}, run, .{result});
|
||||||
|
try result.thread.setName("Network Thread");
|
||||||
if(online) {
|
if(online) {
|
||||||
result.makeOnline();
|
result.makeOnline();
|
||||||
}
|
}
|
||||||
@ -743,27 +744,6 @@ pub const Protocols = blk: {
|
|||||||
// Bits.putInt(data, 8, ch.wz);
|
// Bits.putInt(data, 8, ch.wz);
|
||||||
// Bits.putInt(data, 12, ch.voxelSize);
|
// Bits.putInt(data, 12, ch.voxelSize);
|
||||||
// conn.sendImportant(this, data);
|
// conn.sendImportant(this, data);
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static class ChunkLoadTask extends ThreadPool.Task {
|
|
||||||
// private final VisibleChunk ch;
|
|
||||||
// public ChunkLoadTask(VisibleChunk ch) {
|
|
||||||
// this.ch = ch;
|
|
||||||
// }
|
|
||||||
// @Override
|
|
||||||
// public float getPriority() {
|
|
||||||
// return ch.getPriority(Cubyz.player);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean isStillNeeded() {
|
|
||||||
// return Cubyz.chunkTree.findNode(ch) != null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// ch.load();
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
}),
|
}),
|
||||||
playerPosition: type = addProtocol(&comptimeList, struct {
|
playerPosition: type = addProtocol(&comptimeList, struct {
|
||||||
|
@ -658,7 +658,17 @@ pub const RenderStructure = struct {
|
|||||||
mutex.lock();
|
mutex.lock();
|
||||||
defer mutex.unlock();
|
defer mutex.unlock();
|
||||||
while(updatableList.items.len != 0) {
|
while(updatableList.items.len != 0) {
|
||||||
const pos = updatableList.orderedRemove(0);
|
// TODO: Find a faster solution than going through the entire list.
|
||||||
|
var closestPriority: f32 = -std.math.floatMax(f32);
|
||||||
|
var closestIndex: usize = 0;
|
||||||
|
for(updatableList.items) |pos, i| {
|
||||||
|
const priority = pos.getPriority(game.playerPos);
|
||||||
|
if(priority > closestPriority) {
|
||||||
|
closestPriority = priority;
|
||||||
|
closestIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const pos = updatableList.orderedRemove(closestIndex);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
defer mutex.lock();
|
defer mutex.lock();
|
||||||
const nullNode = _getNode(pos);
|
const nullNode = _getNode(pos);
|
||||||
@ -698,7 +708,7 @@ pub const RenderStructure = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getPriority(self: *MeshGenerationTask) f32 {
|
pub fn getPriority(self: *MeshGenerationTask) f32 {
|
||||||
return -@floatCast(f32, self.mesh.pos.getMinDistanceSquared(game.playerPos))/@intToFloat(f32, self.mesh.pos.voxelSize*self.mesh.pos.voxelSize);
|
return self.mesh.pos.getPriority(game.playerPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isStillNeeded(self: *MeshGenerationTask) bool {
|
pub fn isStillNeeded(self: *MeshGenerationTask) bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user