performance: Apply culling to tile entities and throttle PathNavigation::updatePath to run every 8 ticks
Cull tile entities and throttle mob pathfinding to every 8 ticks. The players won't see the difference on the pathfinding and the culling improves the performance by a lot in zones with a lot of tile entities in TileEntityRenderDispatcher.cpp: Calculate if the tile entities are visible in the camera. Early return if they are so they don't get rendered while the players don't look at those tile entities so . in PathNavigation.cpp: Do a simple modulo operation on the current number of ticks to test if its been 8 ticks since last operation. UpdatePath(); doesn't get executed if elapsed time isn't enough
This commit is contained in:
@@ -149,12 +149,14 @@ Path *PathNavigation::getPath()
|
||||
return path;
|
||||
}
|
||||
|
||||
void PathNavigation::tick()
|
||||
{
|
||||
++_tick;
|
||||
if (isDone()) return;
|
||||
void PathNavigation::tick()
|
||||
{
|
||||
++_tick;
|
||||
if (isDone()) return;
|
||||
|
||||
if (canUpdatePath()) updatePath();
|
||||
// Instead of calculating the path every tick, do it only once every 8 ticks
|
||||
// Players won't see the difference
|
||||
if (_tick % 8 == 0 && canUpdatePath()) updatePath();
|
||||
|
||||
if (isDone()) return;
|
||||
Vec3 *target = path->currentPos(mob->shared_from_this());
|
||||
@@ -384,4 +386,4 @@ bool PathNavigation::canWalkAbove(int startX, int startY, int startZ, int sx, in
|
||||
void PathNavigation::setLevel(Level *level)
|
||||
{
|
||||
this->level = level;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user