73 lines
2.5 KiB
C++
73 lines
2.5 KiB
C++
#include <Tourmaline/Containers/DualkeyMap.hpp>
|
|
#include <Tourmaline/Systems/ECS.hpp>
|
|
#include <Tourmaline/Systems/Random.hpp>
|
|
#include <Tourmaline/Types.hpp>
|
|
#include <any>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <print>
|
|
#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;
|
|
};
|
|
|
|
int main() {
|
|
// [Key1,NULL] = {{Key2, Value},{Key2, Value},{Key2, Value},{Key2, Value}}
|
|
// [NULL,Key2] = {{Key1, Value},{Key1, Value}}
|
|
// [Key1,Key2] = Value
|
|
|
|
DualkeyMap<UUID, std::type_index, std::any> q;
|
|
auto p = Random::GenerateUUID();
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(1));
|
|
q.insert(p, typeid(Transform), Transform(2));
|
|
q.insert(p, typeid(Transform), Transform(3));
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(4));
|
|
q.insert(p, typeid(Transform), Transform(5));
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(6));
|
|
|
|
for (decltype(q)::QueryResult result :
|
|
q.query(std::nullopt, typeid(Transform))) {
|
|
auto &uuid =
|
|
std::get<std::reference_wrapper<const UUID>>(result.first).get();
|
|
auto &component = std::any_cast<Transform &>(result.second);
|
|
|
|
std::print("{}, {}\n", uuid.asString(), component.x);
|
|
}
|
|
|
|
for (decltype(q)::QueryResult result : q.query(p, std::nullopt)) {
|
|
auto &component = std::any_cast<Transform &>(result.second);
|
|
std::print(
|
|
"{} x = {} y = {} z = {}\n",
|
|
std::get<std::reference_wrapper<const std::type_index>>(result.first)
|
|
.get()
|
|
.name(),
|
|
component.x, component.y, component.z);
|
|
}
|
|
|
|
std::print("Deleted {} entries as {} as first key\n",
|
|
q.remove(p, std::nullopt), p.asString());
|
|
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(-1));
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(-2));
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(-3));
|
|
q.insert(Random::GenerateUUID(), typeid(Transform), Transform(-4));
|
|
|
|
for (decltype(q)::QueryResult result :
|
|
q.query(std::nullopt, typeid(Transform))) {
|
|
auto &uuid =
|
|
std::get<std::reference_wrapper<const UUID>>(result.first).get();
|
|
auto &component = std::any_cast<Transform &>(result.second);
|
|
|
|
std::print("{}, {}\n", uuid.asString(), component.x);
|
|
}
|
|
return 0;
|
|
}
|