From 85a4e09e17db32be67f0049f8d94a5d8722bae25 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Fri, 10 Apr 2026 09:55:57 -0500 Subject: [PATCH] disable LTO for now, entity micro-optimizations --- meson.build | 9 ++++--- targets/minecraft/world/entity/Entity.cpp | 10 ++++--- .../minecraft/world/entity/LivingEntity.cpp | 26 ++++++++++--------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/meson.build b/meson.build index 14daf954d..9bce9372c 100644 --- a/meson.build +++ b/meson.build @@ -12,8 +12,8 @@ project( 'unity_size=8', # TODO: mess around with this 'buildtype=debugoptimized', # needed for _FORTIFY_SOURCE 'b_pch=true', # precompiled headers - 'b_lto=true', # link-time optimisation (ThinLTO under clang+lld) - 'b_ndebug=if-release', # drop assert() in --buildtype=release + # 'b_lto=true', # link-time optimisation (ThinLTO under clang+lld) + # 'b_ndebug=if-release', # drop assert() in --buildtype=release ], ) @@ -27,7 +27,6 @@ global_cpp_defs = [ '-DSPLIT_SAVES', '-D_LARGE_WORLDS', '-D_EXTENDED_ACHIEVEMENTS', - '-D_FORTIFY_SOURCE=2', '-DMULTITHREAD_ENABLE', # always-on threading flag (formerly in App_Defines.h) ] @@ -42,6 +41,10 @@ if get_option('buildtype') in ['debug', 'debugoptimized'] ] endif +if get_option('buildtype') == 'debugoptimized' + global_cpp_defs += ['-D_FORTIFY_SOURCE=2'] +endif + # MARK: meson options if get_option('enable_vsync') diff --git a/targets/minecraft/world/entity/Entity.cpp b/targets/minecraft/world/entity/Entity.cpp index e97b7fd72..7af9d16e4 100644 --- a/targets/minecraft/world/entity/Entity.cpp +++ b/targets/minecraft/world/entity/Entity.cpp @@ -684,12 +684,14 @@ void Entity::move(double xa, double ya, double za, bool isPlayerSneaking = onGround && isSneaking() && instanceof(eTYPE_PLAYER); + auto shared = shared_from_this(); + if (isPlayerSneaking) { double d = 0.05; AABB translated_bb = bb.move(xa, -1.0, 0.0); while (xa != 0 && - level->getCubes(shared_from_this(), &translated_bb)->empty()) { + level->getCubes(shared, &translated_bb)->empty()) { if (xa < d && xa >= -d) 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); while (za != 0 && - level->getCubes(shared_from_this(), &translated_bb)->empty()) { + level->getCubes(shared, &translated_bb)->empty()) { if (za < d && za >= -d) 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); while (xa != 0 && za != 0 && - level->getCubes(shared_from_this(), &translated_bb)->empty()) { + level->getCubes(shared, &translated_bb)->empty()) { if (xa < d && xa >= -d) 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); std::vector* aABBs = - level->getCubes(shared_from_this(), &expanded, noEntityCubes, true); + level->getCubes(shared, &expanded, noEntityCubes, true); // LAND FIRST, then x and z auto itEndAABB = aABBs->end(); diff --git a/targets/minecraft/world/entity/LivingEntity.cpp b/targets/minecraft/world/entity/LivingEntity.cpp index 4bc74cb99..0299b688a 100644 --- a/targets/minecraft/world/entity/LivingEntity.cpp +++ b/targets/minecraft/world/entity/LivingEntity.cpp @@ -1244,8 +1244,12 @@ void LivingEntity::jumpFromGround() { } void LivingEntity::travel(float xa, float ya) { - std::shared_ptr thisPlayer = - std::dynamic_pointer_cast(shared_from_this()); + // AP - dynamic_pointer_cast is a non-trivial call, use raw pointer instead + Player* thisPlayer = nullptr; + if (this->instanceof(eTYPE_PLAYER)) { + thisPlayer = (Player*)this; + } + if (isInWater() && !(thisPlayer && thisPlayer->abilities.flying)) { double yo = y; moveRelative(xa, ya, useNewAi() ? 0.04f : 0.02f); @@ -1273,13 +1277,13 @@ void LivingEntity::travel(float xa, float ya) { } } else { float friction = 0.91f; + int frictionTile = 0; if (onGround) { friction = 0.6f * 0.91f; - int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, - Mth::floor(z)); - if (t > 0) { - friction = Tile::tiles[t]->friction * 0.91f; - } + frictionTile = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, Mth::floor(z)); + if (frictionTile > 0) { + friction = Tile::tiles[frictionTile]->friction * 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; if (onGround) { friction = 0.6f * 0.91f; - int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, - Mth::floor(z)); - if (t > 0) { - friction = Tile::tiles[t]->friction * 0.91f; - } + if (frictionTile > 0) { + friction = Tile::tiles[frictionTile]->friction * 0.91f; + } } if (onLadder()) { float max = 0.15f;