From 04e70a9e93f47bd70e031e7f6fe60448590427e8 Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 4 Mar 2026 07:05:37 +0200 Subject: [PATCH] Init --- .gitignore | 3 ++ test_DKM.cpp | 60 ++++++++++++++++++++++++++++++++++ test_Hashmap.cpp | 39 ++++++++++++++++++++++ test_allocationsDKM.cpp | 25 ++++++++++++++ test_allocationsECS.cpp | 16 +++++++++ test_getcomponent.cpp | 33 +++++++++++++++++++ test_tombstones.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 248 insertions(+) create mode 100644 test_DKM.cpp create mode 100644 test_Hashmap.cpp create mode 100644 test_allocationsDKM.cpp create mode 100644 test_allocationsECS.cpp create mode 100644 test_getcomponent.cpp create mode 100644 test_tombstones.cpp diff --git a/.gitignore b/.gitignore index 7fd9c4e..2e3f784 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,6 @@ Module.symvers Mkfile.old dkms.conf +# Custom garbage +program +heaptrack* diff --git a/test_DKM.cpp b/test_DKM.cpp new file mode 100644 index 0000000..76fae36 --- /dev/null +++ b/test_DKM.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +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 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( + {typeid(Transform), typeid(Rotate), typeid(Scale)}); + + std::cout << queryResult.size() << "\n"; + for (const auto &result : queryResult) { + Transform &transform = any_cast(*result.valueQueryResults[0]); + Rotate &rotate = any_cast(*result.valueQueryResults[1]); + Scale &scale = any_cast(*result.valueQueryResults[2]); + transform.x += Random::Generate(10) - 5; + rotate.y -= Random::Generate(10) - 5; + scale.z *= Random::Generate(10) - 5; + } + return 0; +} diff --git a/test_Hashmap.cpp b/test_Hashmap.cpp new file mode 100644 index 0000000..dd2a905 --- /dev/null +++ b/test_Hashmap.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +using namespace Tourmaline; +int main() { + Containers::Hashmap count; + std::string input = "74 eb ff 5c f0 a9 4f 93 2e e1 1b 47 a4 13 3b 93 "; + std::string buffer = ""; + for (char letter : input) { + if (letter == ' ') { + if (count.Has(buffer)) { + count.Get(buffer)++; + } else { + count.Insert(buffer, 1); + } + buffer.clear(); + continue; + } + + buffer += letter; + } + + for (char letter : input) { + if (letter == ' ') { + if (count.Has(buffer)) { + Systems::Logging::Log(std::format("{} = {}", buffer, count.Get(buffer)), + "Test"); + count.Remove(buffer); + } + buffer.clear(); + continue; + } + + buffer += letter; + } + + return 0; +} diff --git a/test_allocationsDKM.cpp b/test_allocationsDKM.cpp new file mode 100644 index 0000000..4a98dc7 --- /dev/null +++ b/test_allocationsDKM.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include + +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() { + DualkeyMap q; + for (int x = 0; x < 100000; x++) { + q.Insert(Random::GenerateUUID(), typeid(Transform), std::any(Transform())); + } + + return 0; +} diff --git a/test_allocationsECS.cpp b/test_allocationsECS.cpp new file mode 100644 index 0000000..461d49c --- /dev/null +++ b/test_allocationsECS.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +using namespace Tourmaline::Containers; +using namespace Tourmaline::Type; +using namespace Tourmaline::Systems; + +int main() { + ECS::World gameWorld; + for (int x = 0; x < 100000; x++) { + gameWorld.CreateEntity(); + } + return 0; +} diff --git a/test_getcomponent.cpp b/test_getcomponent.cpp new file mode 100644 index 0000000..e9ddd31 --- /dev/null +++ b/test_getcomponent.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace Tourmaline; +using namespace Systems; +int main() { + ECS::World game; + auto player = game.CreateEntity(); + auto &coordinates = game.GetComponent(player); + + std::print("Entity {}, x = {}, y = {}, z = {}\n", player.asString(), + coordinates.x, coordinates.y, coordinates.z); + + /* + for (int x = 0; x < 100000; x++) { + // Bad idea, for testing we do need to do this + game.CreateEntity(); + } + */ + + coordinates.x += 4; + coordinates.y -= 2.5; + coordinates.z = -10; + + std::print("Entity {}, x = {}, y = {}, z = {}\n", player.asString(), + coordinates.x, coordinates.y, coordinates.z); + return 0; +} diff --git a/test_tombstones.cpp b/test_tombstones.cpp new file mode 100644 index 0000000..e6458fb --- /dev/null +++ b/test_tombstones.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 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>(result.first).get(); + auto &component = std::any_cast(result.second); + + std::print("{}, {}\n", uuid.asString(), component.x); + } + + for (decltype(q)::QueryResult result : q.query(p, std::nullopt)) { + auto &component = std::any_cast(result.second); + std::print( + "{} x = {} y = {} z = {}\n", + std::get>(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>(result.first).get(); + auto &component = std::any_cast(result.second); + + std::print("{}, {}\n", uuid.asString(), component.x); + } + return 0; +}