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:
@@ -16,6 +16,7 @@
|
||||
#include "BeaconRenderer.h"
|
||||
#include "BannerRenderer.h"
|
||||
#include "BannerModel.h"
|
||||
#include "Frustum.h"
|
||||
|
||||
TileEntityRenderDispatcher *TileEntityRenderDispatcher::instance = nullptr;
|
||||
double TileEntityRenderDispatcher::xOff = 0;
|
||||
@@ -137,11 +138,19 @@ void TileEntityRenderDispatcher::render(shared_ptr<TileEntity> e, float a, bool
|
||||
|
||||
void TileEntityRenderDispatcher::render(shared_ptr<TileEntity> entity, double x, double y, double z, float a, bool setColor/*=true*/, float alpha, bool useCompiled)
|
||||
{
|
||||
TileEntityRenderer *renderer = getRenderer(entity);
|
||||
if (renderer != nullptr)
|
||||
{
|
||||
renderer->render(entity, x, y, z, a, setColor, alpha, useCompiled);
|
||||
}
|
||||
AABB *bb = AABB::newTemp(x - 1.0, y - 0.5, z - 1.0, x + 2.0, y + 1.5, z + 2.0);
|
||||
|
||||
// Check if the tile entity is in the camera field.. If it isn't, don't render it
|
||||
if (bb != nullptr && !Frustum::getFrustum()->isVisible(bb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntityRenderer *renderer = getRenderer(entity);
|
||||
if (renderer != nullptr)
|
||||
{
|
||||
renderer->render(entity, x, y, z, a, setColor, alpha, useCompiled);
|
||||
}
|
||||
}
|
||||
|
||||
void TileEntityRenderDispatcher::setLevel(Level *level)
|
||||
|
||||
@@ -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