Optimizations

This solves an FPS problem when 10 or more entities take damage
This commit is contained in:
GabsPuNs
2026-05-28 22:22:22 -04:00
parent 338604d7c5
commit 8dececbf90
11 changed files with 230 additions and 480 deletions

View File

@@ -730,24 +730,26 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
bool isPlayerSneaking = onGround && isSneaking() && instanceof(eTYPE_PLAYER);
auto shared = shared_from_this();
if (isPlayerSneaking)
{
double d = 0.05;
while (xa != 0 && level->getCubes(shared_from_this(), bb->cloneMove(xa, -1.0, 0))->empty())
while (xa != 0 && level->getCubes(shared, bb->cloneMove(xa, -1.0, 0))->empty())
{
if (xa < d && xa >= -d) xa = 0;
else if (xa > 0) xa -= d;
else xa += d;
xaOrg = xa;
}
while (za != 0 && level->getCubes(shared_from_this(), bb->cloneMove(0, -1.0, za))->empty())
while (za != 0 && level->getCubes(shared, bb->cloneMove(0, -1.0, za))->empty())
{
if (za < d && za >= -d) za = 0;
else if (za > 0) za -= d;
else za += d;
zaOrg = za;
}
while (xa != 0 && za != 0 && level->getCubes(shared_from_this(), bb->cloneMove(xa, -1.0, za))->empty())
while (xa != 0 && za != 0 && level->getCubes(shared, bb->cloneMove(xa, -1.0, za))->empty())
{
if (xa < d && xa >= -d) xa = 0;
else if (xa > 0) xa -= d;
@@ -760,8 +762,7 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
}
}
AABBList *aABBs = level->getCubes(shared_from_this(), bb->expand(xa, ya, za), noEntityCubes, true);
AABBList *aABBs = level->getCubes(shared, bb->expand(xa, ya, za), noEntityCubes, true);
// 4J Stu - Particles (and possibly other entities) don't have xChunk and zChunk set, so calculate the chunk instead
int xc = Mth::floor(x / 16);
@@ -815,7 +816,7 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
bb->set(bbOrg);
// 4J - added extra expand, as if we don't move up by footSize by hitting a block above us, then overall we could be trying to move as much as footSize downwards,
// so we'd better include cubes under our feet in this list of things we might possibly collide with
aABBs = level->getCubes(shared_from_this(), bb->expand(xa, ya, za)->expand(0,-ya,0),false,true);
aABBs = level->getCubes(shared, bb->expand(xa, ya, za)->expand(0,-ya,0),false,true);
if(!level->isClientSide || level->reallyHasChunk(xc, zc))
{
@@ -925,7 +926,7 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
playSound(eSoundType_LIQUID_SWIM, speed, 1 + (random->nextFloat() - random->nextFloat()) * 0.4f);
}
playStepSound(xt, yt, zt, t);
Tile::tiles[t]->stepOn(level, xt, yt, zt, shared_from_this());
Tile::tiles[t]->stepOn(level, xt, yt, zt, shared);
}
}