Stable, ready for testing and optimization.

This commit is contained in:
ExeVirus 2024-05-13 17:39:20 -04:00
parent 0975a98dfe
commit 9540f016e2
3 changed files with 5 additions and 45 deletions

View File

@ -47,46 +47,15 @@ inline void fill(server::ActiveObjectMgr &mgr, size_t n)
}
template <size_t N>
void benchInsertObjects(Catch::Benchmark::Chronometer &meter)
{
server::ActiveObjectMgr mgr;
meter.measure([&] {
fill(mgr, N);
});
mgr.clear(); // implementation expects this
}
template <size_t N>
void benchRemoveObjects(Catch::Benchmark::Chronometer &meter)
{
server::ActiveObjectMgr mgr;
fill(mgr, N);
meter.measure([&] {
mgr.clear();
});
mgr.clear();
}
template <size_t N>
void benchUpdateObjectPositions(Catch::Benchmark::Chronometer &meter)
{
server::ActiveObjectMgr mgr;
std::vector<v3f> newPositions;
newPositions.reserve(N);
fill(mgr, N);
for (size_t i = 0; i < N; i++) {
newPositions.push_back(randpos());
}
meter.measure([&] {
size_t i = 0;
mgr.step(0,[&](ServerActiveObject* obj){
obj->setBasePosition(newPositions.at(i++));
obj->setBasePosition(randpos());
});
});
mgr.clear();
@ -147,20 +116,11 @@ void benchGetObjectsInArea(Catch::Benchmark::Chronometer &meter)
BENCHMARK_ADVANCED("in_area_" #_count)(Catch::Benchmark::Chronometer meter) \
{ benchGetObjectsInArea<_count>(meter); };
#define BENCH_INSERT(_count) \
BENCHMARK_ADVANCED("insert_objects_" #_count)(Catch::Benchmark::Chronometer meter) \
{ benchInsertObjects<_count>(meter); };
#define BENCH_REMOVE(_count) \
BENCHMARK_ADVANCED("remove_objects_" #_count)(Catch::Benchmark::Chronometer meter) \
{ benchRemoveObjects<_count>(meter); };
#define BENCH_UPDATE(_count) \
BENCHMARK_ADVANCED("update_objects_" #_count)(Catch::Benchmark::Chronometer meter) \
{ benchUpdateObjectPositions<_count>(meter); };
TEST_CASE("ActiveObjectMgr") {
BENCH_INSERT(10000)
BENCH_REMOVE(10000)
BENCH_UPDATE(10000)

View File

@ -1,6 +1,6 @@
/*
Minetest
Copyright (C) 2010-2018 nerzhul, Loic BLOT <loic.blot@unix-experience.fr>
Copyright (C) 2024, ExeVirus <nodecastmt@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,6 +1,6 @@
/*
Minetest
Copyright (C) 2010-2018 nerzhul, Loic BLOT <loic.blot@unix-experience.fr>
Copyright (C) 2024, ExeVirus <nodecastmt@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@ -38,7 +38,7 @@ public:
void handleInsertsAndDeletes();
protected:
typedef struct SpatialKey {
struct SpatialKey {
u16 padding_or_optional_id{0};
s16 x;
s16 y;
@ -65,7 +65,7 @@ protected:
bool operator==(const SpatialKey &other) const {
return (x == other.x && y == other.y && z == other.z);
}
} SpatialKey;
};
struct SpatialKeyHash {
auto operator()(const SpatialKey &key) const -> size_t {