mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Add spatial index for objects (#14631)
This commit is contained in:
parent
bed36139db
commit
a3648b0b16
17 changed files with 982 additions and 116 deletions
|
@ -4,10 +4,12 @@
|
|||
|
||||
#include "collision.h"
|
||||
#include <cmath>
|
||||
#include "irr_aabb3d.h"
|
||||
#include "mapblock.h"
|
||||
#include "map.h"
|
||||
#include "nodedef.h"
|
||||
#include "gamedef.h"
|
||||
#include "util/numeric.h"
|
||||
#if CHECK_CLIENT_BUILD()
|
||||
#include "client/clientenvironment.h"
|
||||
#include "client/localplayer.h"
|
||||
|
@ -311,13 +313,14 @@ static void add_object_boxes(Environment *env,
|
|||
}
|
||||
};
|
||||
|
||||
// Calculate distance by speed, add own extent and 1.5m of tolerance
|
||||
const f32 distance = speed_f.getLength() * dtime +
|
||||
box_0.getExtent().getLength() + 1.5f * BS;
|
||||
constexpr f32 tolerance = 1.5f * BS;
|
||||
|
||||
#if CHECK_CLIENT_BUILD()
|
||||
ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
|
||||
if (c_env) {
|
||||
// Calculate distance by speed, add own extent and tolerance
|
||||
const f32 distance = speed_f.getLength() * dtime +
|
||||
box_0.getExtent().getLength() + tolerance;
|
||||
std::vector<DistanceSortedActiveObject> clientobjects;
|
||||
c_env->getActiveObjects(pos_f, distance, clientobjects);
|
||||
|
||||
|
@ -356,9 +359,14 @@ static void add_object_boxes(Environment *env,
|
|||
return false;
|
||||
};
|
||||
|
||||
// Calculate distance by speed, add own extent and tolerance
|
||||
const v3f movement = speed_f * dtime;
|
||||
const v3f min = pos_f + box_0.MinEdge - v3f(tolerance) + componentwise_min(movement, v3f());
|
||||
const v3f max = pos_f + box_0.MaxEdge + v3f(tolerance) + componentwise_max(movement, v3f());
|
||||
|
||||
// nothing is put into this vector
|
||||
std::vector<ServerActiveObject*> s_objects;
|
||||
s_env->getObjectsInsideRadius(s_objects, pos_f, distance, include_obj_cb);
|
||||
s_env->getObjectsInArea(s_objects, aabb3f(min, max), include_obj_cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue