Init
This commit is contained in:
60
test_DKM.cpp
Normal file
60
test_DKM.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <Tourmaline/Containers/DualkeyMap.hpp>
|
||||
#include <Tourmaline/Systems/ECS.hpp>
|
||||
#include <Tourmaline/Systems/Logging.hpp>
|
||||
#include <Tourmaline/Systems/Random.hpp>
|
||||
#include <Tourmaline/Types.hpp>
|
||||
|
||||
#include <any>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <typeindex>
|
||||
|
||||
using namespace Tourmaline::Containers;
|
||||
using namespace Tourmaline::Type;
|
||||
using namespace Tourmaline::Systems;
|
||||
|
||||
struct Transform : public ECS::Component {
|
||||
Transform(int64_t x = 10, int64_t y = 0, int64_t z = -10)
|
||||
: x(x), y(y), z(z) {}
|
||||
int64_t x, y, z;
|
||||
};
|
||||
struct Rotate : public ECS::Component {
|
||||
Rotate(int64_t x = 50, int64_t y = 0, int64_t z = -1) : x(x), y(y), z(z) {}
|
||||
int64_t x, y, z;
|
||||
};
|
||||
struct Scale : public ECS::Component {
|
||||
Scale(int64_t x = 1, int64_t y = 1, int64_t z = 1) : x(x), y(y), z(z) {}
|
||||
int64_t x, y, z;
|
||||
};
|
||||
|
||||
int main() {
|
||||
// Adding random data
|
||||
DualkeyMap<UUID, std::type_index, std::any> DKMtest;
|
||||
for (int x = 0; x < 100000; x++) {
|
||||
UUID currentEntity = Random::GenerateUUID();
|
||||
if (Random::Generate(2) == 0) {
|
||||
DKMtest.Insert(currentEntity, typeid(Transform), Transform());
|
||||
}
|
||||
if (Random::Generate(2) == 0) {
|
||||
DKMtest.Insert(currentEntity, typeid(Rotate), Rotate());
|
||||
}
|
||||
if (Random::Generate(2) == 0) {
|
||||
DKMtest.Insert(currentEntity, typeid(Scale), Scale());
|
||||
}
|
||||
}
|
||||
|
||||
// Actual query
|
||||
auto queryResult = DKMtest.QueryWithAll<std::type_index>(
|
||||
{typeid(Transform), typeid(Rotate), typeid(Scale)});
|
||||
|
||||
std::cout << queryResult.size() << "\n";
|
||||
for (const auto &result : queryResult) {
|
||||
Transform &transform = any_cast<Transform &>(*result.valueQueryResults[0]);
|
||||
Rotate &rotate = any_cast<Rotate &>(*result.valueQueryResults[1]);
|
||||
Scale &scale = any_cast<Scale &>(*result.valueQueryResults[2]);
|
||||
transform.x += Random::Generate(10) - 5;
|
||||
rotate.y -= Random::Generate(10) - 5;
|
||||
scale.z *= Random::Generate(10) - 5;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user