1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Optimize a little bit isBlockInSight, adjustDist & collisions (#7193)

* Use constexpr + unroll some calculations to cache definitively some calculations
* Unroll some calls in collision code & use a constref instead of a copy in one occurence
This commit is contained in:
Loïc Blot 2018-04-04 00:43:08 +02:00 committed by GitHub
parent 05fe3b06c8
commit a90d27e1e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View file

@ -322,9 +322,12 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
}
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
// Calculate float position only once
v3f posf = intToFloat(p, BS);
for (auto box : nodeboxes) {
box.MinEdge += intToFloat(p, BS);
box.MaxEdge += intToFloat(p, BS);
box.MinEdge += posf;
box.MaxEdge += posf;
cinfo.emplace_back(false, false, n_bouncy_value, p, box);
}
} else {
@ -437,7 +440,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
Go through every nodebox, find nearest collision
*/
for (u32 boxindex = 0; boxindex < cinfo.size(); boxindex++) {
NearbyCollisionInfo box_info = cinfo[boxindex];
const NearbyCollisionInfo &box_info = cinfo[boxindex];
// Ignore if already stepped up this nodebox.
if (box_info.is_step_up)
continue;