From 1962e97cf9bde70340b0d03c3261ec21e3ce49be Mon Sep 17 00:00:00 2001 From: NukeBird Date: Fri, 14 Feb 2025 21:35:40 +0300 Subject: [PATCH] Make entity and verify its existence --- tests/zecsy.cpp | 11 +++++++++-- zecsy.hpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index ffb589a..faee0e0 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -1,7 +1,14 @@ +#include #define CATCH_CONFIG_MAIN #include +#include "../zecsy.hpp" -TEST_CASE("dumb") +using namespace zecsy; + +TEST_CASE("Create a single entity and verify its existence") { - REQUIRE(true); + world w; + + auto e = w.make_entity(); + REQUIRE(w.is_alive(e)); } diff --git a/zecsy.hpp b/zecsy.hpp index 863f475..abefeab 100644 --- a/zecsy.hpp +++ b/zecsy.hpp @@ -1,2 +1,45 @@ -//oh hi -int foo() {} +#pragma once +#include +#include +#include + +#ifndef MAX_ZECSY_ENTITIES + #define MAX_ZECSY_ENTITIES 65536 +#endif // !MAX_ZECSY_ENTITIES + + +namespace zecsy +{ + using entity_id = uint64_t; + + class world final + { + public: + world() = default; + world(const world &) = default; + world(world &&) = default; + world &operator=(const world &) = default; + world &operator=(world &&) = default; + + entity_id make_entity(); + bool is_alive(entity_id e) const; + private: + std::bitset entities_bitset; + entity_id entity_counter = 0; + }; + + inline entity_id world::make_entity() + { + auto id = entity_counter; + entities_bitset.set(id); + + entity_counter++; + + return id; + } + + inline bool world::is_alive(entity_id e) const + { + return entities_bitset.test(e); + } +};