diff --git a/CMakeLists.txt b/CMakeLists.txt index 253bfc5..68a857e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(UECS VERSION 0.12.0) +project(UECS VERSION 0.12.1) message(STATUS "[Project] ${PROJECT_NAME}") include(cmake/InitUCMake.cmake) diff --git a/doc/todo.md b/doc/todo.md index ba6eb64..b90cde9 100644 --- a/doc/todo.md +++ b/doc/todo.md @@ -28,6 +28,7 @@ - [x] serialize (`IListner`) - [x] system base -> `System` - [x] singleton +- [ ] doxygen ### maybe support in future diff --git a/include/UECS/CmptPtr.h b/include/UECS/CmptPtr.h index 71b0af4..13c7068 100644 --- a/include/UECS/CmptPtr.h +++ b/include/UECS/CmptPtr.h @@ -8,9 +8,10 @@ namespace Ubpa::UECS { // CmptType + void* class CmptPtr { public: - constexpr CmptPtr(CmptType type, void* p) noexcept : type{ type }, p{ p }{} + constexpr CmptPtr(CmptType type, void* p) noexcept : type{ type }, p{ p } {} template - constexpr CmptPtr(Cmpt* p) noexcept : type{ CmptType::Of }, p{ p }{} + constexpr CmptPtr(Cmpt* p) noexcept : type{ CmptType::Of }, p{ p } {} + constexpr CmptPtr() noexcept : CmptPtr{ Invalid() } {} constexpr void* Ptr() const noexcept { return p; } @@ -35,6 +36,7 @@ namespace Ubpa::UECS { template constexpr CmptAccessPtr(TaggedCmpt p) noexcept : accessType{ CmptAccessType::Of }, p{ CastToVoidPointer(p) } {} explicit constexpr CmptAccessPtr(CmptPtr p) noexcept : CmptAccessPtr{ p, AccessMode::LATEST } {} + explicit constexpr CmptAccessPtr() noexcept : CmptAccessPtr{ Invalid() } {} explicit constexpr operator CmptPtr() const noexcept { return { CmptType{accessType}, p }; } diff --git a/include/UECS/CmptType.h b/include/UECS/CmptType.h index e0b432b..471f274 100644 --- a/include/UECS/CmptType.h +++ b/include/UECS/CmptType.h @@ -13,6 +13,7 @@ namespace Ubpa::UECS { public: explicit constexpr CmptType(size_t id) noexcept : hashcode{ id } {} explicit constexpr CmptType(std::string_view type_name) noexcept : hashcode{ RuntimeTypeID(type_name) } {} + explicit constexpr CmptType() noexcept : CmptType{ Invalid() } {} template, int> = 0> static constexpr CmptType Of = CmptType{ TypeID }; @@ -45,6 +46,7 @@ namespace Ubpa::UECS { constexpr CmptAccessType(CmptType type, AccessMode mode) noexcept : type{ type }, mode{ mode } {} explicit constexpr CmptAccessType(CmptType type) noexcept : CmptAccessType{ type, AccessMode::LATEST } {} + explicit constexpr CmptAccessType() noexcept : CmptAccessType{ Invalid() } {} template static constexpr CmptAccessType Of = CmptAccessType{ CmptType::Of>, AccessModeOf_default }; diff --git a/include/UECS/Entity.h b/include/UECS/Entity.h index 6af3618..2a5ea70 100644 --- a/include/UECS/Entity.h +++ b/include/UECS/Entity.h @@ -6,20 +6,20 @@ namespace Ubpa::UECS { // index + version class Entity { public: - size_t Idx() const noexcept { return idx; } - size_t Version() const noexcept { return version; } + constexpr Entity(size_t idx, size_t version) noexcept : idx(idx), version(version) {} + constexpr Entity() noexcept : Entity{ Invalid() } {} + constexpr size_t Idx() const noexcept { return idx; } + constexpr size_t Version() const noexcept { return version; } static constexpr Entity Invalid() noexcept { return { size_t_invalid,size_t_invalid }; } constexpr bool IsValid() const noexcept { return idx == size_t_invalid; } - bool operator==(const Entity& rhs) const noexcept { + constexpr bool operator==(const Entity& rhs) const noexcept { return idx == rhs.idx && version == rhs.version; } - bool operator<(const Entity& rhs) const noexcept { + constexpr bool operator<(const Entity& rhs) const noexcept { return idx < rhs.idx || (idx == rhs.idx && version < rhs.version); } private: friend class EntityMngr; - friend class Archetype; - constexpr Entity(size_t idx, size_t version) noexcept : idx(idx), version(version) {} size_t idx; size_t version; }; diff --git a/include/UECS/EntityMngr.h b/include/UECS/EntityMngr.h index 58af4d9..6b090a9 100644 --- a/include/UECS/EntityMngr.h +++ b/include/UECS/EntityMngr.h @@ -24,6 +24,8 @@ namespace Ubpa::UECS { // [important] // - some API with CmptType need RTDCmptTraits to get {size|alignment|lifecycle function} (throw std::logic_error) // - API with Entity require Entity exist (throw std::invalid_argument) + // [details] + // - when free entries is empty, use new entity entry (version is 0) class EntityMngr { public: RTDCmptTraits cmptTraits; @@ -64,7 +66,11 @@ namespace Ubpa::UECS { void Destroy(Entity); + size_t TotalEntityNum() const noexcept { return entityTable.size() - entityTableFreeEntry.size(); } size_t EntityNum(const EntityQuery&) const; + // use entry in reverse + const std::vector& GetEntityFreeEntries() const noexcept { return entityTableFreeEntry; } + size_t GetEntityVersion(size_t idx) const noexcept { return entityTable.at(idx).version; } std::tuple> LocateSingletons(const SingletonLocator&) const;