mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Avoid unnecessary syscalls from checking the millitime in each call of isStillNeeded
Reduces lag caused by updating the priorities in the threadpool.
This commit is contained in:
parent
22a482eb65
commit
c9f9dbf634
@ -110,7 +110,7 @@ const MusicLoadTask = struct {
|
||||
return std.math.floatMax(f32);
|
||||
}
|
||||
|
||||
pub fn isStillNeeded(_: *MusicLoadTask) bool {
|
||||
pub fn isStillNeeded(_: *MusicLoadTask, _: i64) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -539,7 +539,7 @@ pub const ChunkMesh = struct {
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
pub fn isStillNeeded(_: *LightRefreshTask) bool {
|
||||
pub fn isStillNeeded(_: *LightRefreshTask, _: i64) bool {
|
||||
return true; // TODO: Is it worth checking for this?
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1011,7 @@ pub const MeshGenerationTask = struct {
|
||||
return self.mesh.pos.getPriority(game.Player.getPosBlocking()); // TODO: This is called in loop, find a way to do this without calling the mutex every time.
|
||||
}
|
||||
|
||||
pub fn isStillNeeded(self: *MeshGenerationTask) bool {
|
||||
pub fn isStillNeeded(self: *MeshGenerationTask, _: i64) bool {
|
||||
const distanceSqr = self.mesh.pos.getMinDistanceSquared(game.Player.getPosBlocking()); // TODO: This is called in loop, find a way to do this without calling the mutex every time.
|
||||
var maxRenderDistance = settings.renderDistance*chunk.chunkSize*self.mesh.pos.voxelSize;
|
||||
maxRenderDistance += 2*self.mesh.pos.voxelSize*chunk.chunkSize;
|
||||
|
@ -59,7 +59,7 @@ const ChunkManager = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn isStillNeeded(self: *ChunkLoadTask) bool {
|
||||
pub fn isStillNeeded(self: *ChunkLoadTask, milliTime: i64) bool {
|
||||
// TODO:
|
||||
if(self.source) |source| {
|
||||
_ = source;
|
||||
@ -75,7 +75,7 @@ const ChunkManager = struct {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
if(std.time.milliTimestamp() - self.creationTime > 10000) { // Only remove stuff after 10 seconds to account for trouble when for example teleporting.
|
||||
if(milliTime - self.creationTime > 10000) { // Only remove stuff after 10 seconds to account for trouble when for example teleporting.
|
||||
server.mutex.lock();
|
||||
defer server.mutex.unlock();
|
||||
for(server.users.items) |user| {
|
||||
@ -132,7 +132,7 @@ const ChunkManager = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn isStillNeeded(self: *LightMapLoadTask) bool {
|
||||
pub fn isStillNeeded(self: *LightMapLoadTask, _: i64) bool {
|
||||
_ = self; // TODO: Do these tasks need to be culled?
|
||||
return true;
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ pub const ThreadPool = struct {
|
||||
};
|
||||
pub const VTable = struct {
|
||||
getPriority: *const fn(*anyopaque) f32,
|
||||
isStillNeeded: *const fn(*anyopaque) bool,
|
||||
isStillNeeded: *const fn(*anyopaque, milliTime: i64) bool,
|
||||
run: *const fn(*anyopaque) void,
|
||||
clean: *const fn(*anyopaque) void,
|
||||
};
|
||||
@ -1080,7 +1080,7 @@ pub const ThreadPool = struct {
|
||||
var i: u32 = 0;
|
||||
while(i < self.loadList.size) {
|
||||
const task = &self.loadList.array[i];
|
||||
if(!task.vtable.isStillNeeded(task.self)) {
|
||||
if(!task.vtable.isStillNeeded(task.self, lastUpdate)) {
|
||||
task.vtable.clean(task.self);
|
||||
self.loadList.removeIndex(i);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user