disable LTO for now, entity micro-optimizations

This commit is contained in:
Tropical 2026-04-10 09:55:57 -05:00
parent abeead819e
commit 85a4e09e17
3 changed files with 26 additions and 19 deletions

View file

@ -12,8 +12,8 @@ project(
'unity_size=8', # TODO: mess around with this 'unity_size=8', # TODO: mess around with this
'buildtype=debugoptimized', # needed for _FORTIFY_SOURCE 'buildtype=debugoptimized', # needed for _FORTIFY_SOURCE
'b_pch=true', # precompiled headers 'b_pch=true', # precompiled headers
'b_lto=true', # link-time optimisation (ThinLTO under clang+lld) # 'b_lto=true', # link-time optimisation (ThinLTO under clang+lld)
'b_ndebug=if-release', # drop assert() in --buildtype=release # 'b_ndebug=if-release', # drop assert() in --buildtype=release
], ],
) )
@ -27,7 +27,6 @@ global_cpp_defs = [
'-DSPLIT_SAVES', '-DSPLIT_SAVES',
'-D_LARGE_WORLDS', '-D_LARGE_WORLDS',
'-D_EXTENDED_ACHIEVEMENTS', '-D_EXTENDED_ACHIEVEMENTS',
'-D_FORTIFY_SOURCE=2',
'-DMULTITHREAD_ENABLE', # always-on threading flag (formerly in App_Defines.h) '-DMULTITHREAD_ENABLE', # always-on threading flag (formerly in App_Defines.h)
] ]
@ -42,6 +41,10 @@ if get_option('buildtype') in ['debug', 'debugoptimized']
] ]
endif endif
if get_option('buildtype') == 'debugoptimized'
global_cpp_defs += ['-D_FORTIFY_SOURCE=2']
endif
# MARK: meson options # MARK: meson options
if get_option('enable_vsync') if get_option('enable_vsync')

View file

@ -684,12 +684,14 @@ void Entity::move(double xa, double ya, double za,
bool isPlayerSneaking = bool isPlayerSneaking =
onGround && isSneaking() && instanceof(eTYPE_PLAYER); onGround && isSneaking() && instanceof(eTYPE_PLAYER);
auto shared = shared_from_this();
if (isPlayerSneaking) { if (isPlayerSneaking) {
double d = 0.05; double d = 0.05;
AABB translated_bb = bb.move(xa, -1.0, 0.0); AABB translated_bb = bb.move(xa, -1.0, 0.0);
while (xa != 0 && while (xa != 0 &&
level->getCubes(shared_from_this(), &translated_bb)->empty()) { level->getCubes(shared, &translated_bb)->empty()) {
if (xa < d && xa >= -d) if (xa < d && xa >= -d)
xa = 0; xa = 0;
else if (xa > 0) else if (xa > 0)
@ -701,7 +703,7 @@ void Entity::move(double xa, double ya, double za,
translated_bb = bb.move(0, -1.0, za); translated_bb = bb.move(0, -1.0, za);
while (za != 0 && while (za != 0 &&
level->getCubes(shared_from_this(), &translated_bb)->empty()) { level->getCubes(shared, &translated_bb)->empty()) {
if (za < d && za >= -d) if (za < d && za >= -d)
za = 0; za = 0;
else if (za > 0) else if (za > 0)
@ -713,7 +715,7 @@ void Entity::move(double xa, double ya, double za,
translated_bb = bb.move(xa, -1.0, za); translated_bb = bb.move(xa, -1.0, za);
while (xa != 0 && za != 0 && while (xa != 0 && za != 0 &&
level->getCubes(shared_from_this(), &translated_bb)->empty()) { level->getCubes(shared, &translated_bb)->empty()) {
if (xa < d && xa >= -d) if (xa < d && xa >= -d)
xa = 0; xa = 0;
else if (xa > 0) else if (xa > 0)
@ -733,7 +735,7 @@ void Entity::move(double xa, double ya, double za,
AABB expanded = bb.expand(xa, ya, za); AABB expanded = bb.expand(xa, ya, za);
std::vector<AABB>* aABBs = std::vector<AABB>* aABBs =
level->getCubes(shared_from_this(), &expanded, noEntityCubes, true); level->getCubes(shared, &expanded, noEntityCubes, true);
// LAND FIRST, then x and z // LAND FIRST, then x and z
auto itEndAABB = aABBs->end(); auto itEndAABB = aABBs->end();

View file

@ -1244,8 +1244,12 @@ void LivingEntity::jumpFromGround() {
} }
void LivingEntity::travel(float xa, float ya) { void LivingEntity::travel(float xa, float ya) {
std::shared_ptr<Player> thisPlayer = // AP - dynamic_pointer_cast is a non-trivial call, use raw pointer instead
std::dynamic_pointer_cast<Player>(shared_from_this()); Player* thisPlayer = nullptr;
if (this->instanceof(eTYPE_PLAYER)) {
thisPlayer = (Player*)this;
}
if (isInWater() && !(thisPlayer && thisPlayer->abilities.flying)) { if (isInWater() && !(thisPlayer && thisPlayer->abilities.flying)) {
double yo = y; double yo = y;
moveRelative(xa, ya, useNewAi() ? 0.04f : 0.02f); moveRelative(xa, ya, useNewAi() ? 0.04f : 0.02f);
@ -1273,13 +1277,13 @@ void LivingEntity::travel(float xa, float ya) {
} }
} else { } else {
float friction = 0.91f; float friction = 0.91f;
int frictionTile = 0;
if (onGround) { if (onGround) {
friction = 0.6f * 0.91f; friction = 0.6f * 0.91f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, frictionTile = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, Mth::floor(z));
Mth::floor(z)); if (frictionTile > 0) {
if (t > 0) { friction = Tile::tiles[frictionTile]->friction * 0.91f;
friction = Tile::tiles[t]->friction * 0.91f; }
}
} }
float friction2 = (0.6f * 0.6f * 0.91f * 0.91f * 0.6f * 0.91f) / float friction2 = (0.6f * 0.6f * 0.91f * 0.91f * 0.6f * 0.91f) /
@ -1297,11 +1301,9 @@ void LivingEntity::travel(float xa, float ya) {
friction = 0.91f; friction = 0.91f;
if (onGround) { if (onGround) {
friction = 0.6f * 0.91f; friction = 0.6f * 0.91f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, if (frictionTile > 0) {
Mth::floor(z)); friction = Tile::tiles[frictionTile]->friction * 0.91f;
if (t > 0) { }
friction = Tile::tiles[t]->friction * 0.91f;
}
} }
if (onLadder()) { if (onLadder()) {
float max = 0.15f; float max = 0.15f;