mirror of https://github.com/minetest/minetest.git
It's Working!
This commit is contained in:
parent
de34280250
commit
20e50029d5
|
@ -1,10 +1,10 @@
|
|||
set (BENCHMARK_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_activeobjectmgr.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_lighting.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_serialize.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_mapblock.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_mapmodify.cpp
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_lighting.cpp
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_serialize.cpp
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_mapblock.cpp
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_mapmodify.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
set (BENCHMARK_CLIENT_SRCS
|
||||
|
|
|
@ -81,6 +81,7 @@ void benchGetObjectsInArea(Catch::Benchmark::Chronometer &meter)
|
|||
return false;
|
||||
};
|
||||
fill(mgr, N);
|
||||
mgr.step(0,[](ServerActiveObject*){});
|
||||
meter.measure([&] {
|
||||
x = 0;
|
||||
v3f pos = randpos();
|
||||
|
@ -103,9 +104,11 @@ void benchGetObjectsInArea(Catch::Benchmark::Chronometer &meter)
|
|||
{ benchGetObjectsInArea<_count>(meter); };
|
||||
|
||||
TEST_CASE("ActiveObjectMgr") {
|
||||
BENCH_INSIDE_RADIUS(200)
|
||||
BENCH_INSIDE_RADIUS(1450)
|
||||
// BENCH_INSIDE_RADIUS(200)
|
||||
// BENCH_INSIDE_RADIUS(1450)
|
||||
// BENCH_INSIDE_RADIUS(10000)
|
||||
|
||||
BENCH_IN_AREA(200)
|
||||
BENCH_IN_AREA(1450)
|
||||
BENCH_IN_AREA(10000)
|
||||
}
|
||||
|
|
|
@ -158,17 +158,17 @@ void ActiveObjectMgr::getObjectsInArea(const aabb3f &box,
|
|||
std::vector<ServerActiveObject *> &result,
|
||||
std::function<bool(ServerActiveObject *obj)> include_obj_cb)
|
||||
{
|
||||
for (auto &activeObject : m_active_objects.iter()) {
|
||||
ServerActiveObject *obj = activeObject.second.get();
|
||||
m_spatial_map.getRelevantObjectIds(box,[&](u16 id) {
|
||||
auto obj = m_active_objects.get(id).get();
|
||||
if (!obj)
|
||||
continue;
|
||||
return;
|
||||
const v3f &objectpos = obj->getBasePosition();
|
||||
if (!box.isPointInside(objectpos))
|
||||
continue;
|
||||
return;
|
||||
|
||||
if (!include_obj_cb || include_obj_cb(obj))
|
||||
result.push_back(obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ActiveObjectMgr::getAddedActiveObjectsAroundPos(v3f player_pos, f32 radius,
|
||||
|
|
|
@ -98,7 +98,7 @@ void SpatialMap::cacheUpdate(const std::function<v3f(u16)> &getPos)
|
|||
}
|
||||
}
|
||||
|
||||
void SpatialMap::getRelevantObjectIds(const aabb3f &box, std::vector<u16> &relevant_objs)
|
||||
void SpatialMap::getRelevantObjectIds(const aabb3f &box, const std::function<void(u16 id)> &callback)
|
||||
{
|
||||
if(!m_cached.empty()) {
|
||||
// when searching, we must round to maximum extent of relevant mapblock indexes
|
||||
|
@ -112,14 +112,15 @@ void SpatialMap::getRelevantObjectIds(const aabb3f &box, std::vector<u16> &relev
|
|||
v3s16 min(absoluteRoundUp(box.MinEdge.X), absoluteRoundUp(box.MinEdge.Y), absoluteRoundUp(box.MinEdge.Z)),
|
||||
max(absoluteRoundUp(box.MaxEdge.X), absoluteRoundUp(box.MaxEdge.Y), absoluteRoundUp(box.MaxEdge.Z));
|
||||
|
||||
for (int x = box.MinEdge.X; x < box.MaxEdge.X;x++) {
|
||||
for (int y = box.MinEdge.Y; y < box.MaxEdge.Y;y++) {
|
||||
for (int z = box.MinEdge.Z; z < box.MaxEdge.Z;z++) {
|
||||
std::vector<std::unordered_map<SpatialKey, std::vector<u16>, SpatialKeyHash>::iterator> matchingVectors;
|
||||
for (s16 x = min.X; x < max.X;x++) {
|
||||
for (s16 y = min.Y; y < max.Y;y++) {
|
||||
for (s16 z = min.Z; z < max.Z;z++) {
|
||||
SpatialKey key(x,y,z);
|
||||
if (m_cached.find(key) != m_cached.end()) {
|
||||
auto range = m_cached.equal_range(key);
|
||||
for (auto &it = range.first; it != range.second; ++it) {
|
||||
relevant_objs.push_back(it->second);
|
||||
callback(it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +129,9 @@ void SpatialMap::getRelevantObjectIds(const aabb3f &box, std::vector<u16> &relev
|
|||
}
|
||||
|
||||
// add the the rest, uncached objectIDs
|
||||
relevant_objs.insert(relevant_objs.end(), m_uncached.begin(), m_uncached.end());
|
||||
for (auto id : m_uncached) {
|
||||
callback(id);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
void cacheUpdate(const std::function<v3f(u16)> &getPos);
|
||||
|
||||
// Use the same basic algorithm for both area and radius lookups
|
||||
void getRelevantObjectIds(const aabb3f &box, std::vector<u16> &relevant_objs);
|
||||
void getRelevantObjectIds(const aabb3f &box, const std::function<void(u16 id)> &callback);
|
||||
|
||||
protected:
|
||||
typedef struct SpatialKey{
|
||||
|
|
Loading…
Reference in New Issue