diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2020-04-16 08:25:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 08:25:48 +0200 |
commit | e8ac5a31cf12afcfddf8e3ed31e8038930edb06f (patch) | |
tree | 5bdc776c5bbe190e32e42899b455e6d16179e3b5 /src/collision.cpp | |
parent | 62ae7adab2bebde04864c12543caefbffab24963 (diff) | |
download | minetest-e8ac5a31cf12afcfddf8e3ed31e8038930edb06f.tar.gz minetest-e8ac5a31cf12afcfddf8e3ed31e8038930edb06f.tar.bz2 minetest-e8ac5a31cf12afcfddf8e3ed31e8038930edb06f.zip |
Optimize get_objects_inside_radius calls (#9671)
* Optimize getObjectsInsideRadius calls
our previous implementation calls the ActiveObjectMgr to return ids and then lookup those ids in the same map and test each object
Instead now we call the global map to return the pointers directly and we ask filtering when building the list using lamba.
This drop double looping over ranges of active objects (and then filtered one) and drop x lookups on the map regarding the first call results
Diffstat (limited to 'src/collision.cpp')
-rw-r--r-- | src/collision.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/collision.cpp b/src/collision.cpp index d9fbd3202..6d24bc699 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -360,17 +360,19 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, // Calculate distance by speed, add own extent and 1.5m of tolerance f32 distance = speed_f->getLength() * dtime + box_0.getExtent().getLength() + 1.5f * BS; - std::vector<u16> s_objects; - s_env->getObjectsInsideRadius(s_objects, *pos_f, distance); - for (u16 obj_id : s_objects) { - ServerActiveObject *current = s_env->getActiveObject(obj_id); - - if (!self || (self != current && - self != current->getParent())) { - objects.push_back((ActiveObject*)current); + // search for objects which are not us, or we are not its parent + // we directly use the callback to populate the result to prevent + // a useless result loop here + auto include_obj_cb = [self, &objects] (ServerActiveObject *obj) { + if (!self || (self != obj && self != obj->getParent())) { + objects.push_back((ActiveObject *)obj); } - } + return false; + }; + + std::vector<ServerActiveObject *> s_objects; + s_env->getObjectsInsideRadius(s_objects, *pos_f, distance, include_obj_cb); } } |