From e6cefe73c34e8d8ae16d9d788cef27d5817e5c4f Mon Sep 17 00:00:00 2001 From: Ubpa <641614112@qq.com> Date: Tue, 25 Aug 2020 14:50:16 +0800 Subject: [PATCH] clean up --- doc/todo.md | 7 ++++--- include/UECS/ChunkView.h | 1 - include/UECS/CmptPtr.h | 2 ++ include/UECS/CmptType.h | 4 ++-- include/UECS/Entity.h | 4 ++-- include/UECS/SystemFunc.h | 2 +- include/UECS/config.h | 14 ++++++++++++++ include/UECS/detail/Chunk.h | 6 ++++-- include/UECS/detail/CmptType.inl | 8 ++++++++ 9 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 include/UECS/config.h diff --git a/doc/todo.md b/doc/todo.md index 0d2de5b..ba6eb64 100644 --- a/doc/todo.md +++ b/doc/todo.md @@ -29,15 +29,16 @@ - [x] system base -> `System` - [x] singleton -### unimportant +### maybe support in future - [x] exception: invalid `Entity` -- [ ] batch create/instantiate (need benchmark) - [x] lock `FilterChange` - [ ] `EntityMngr` `Query`-driven API - [x] `CmptsView` = `const EntityLocator* locator + void** cmpts` +- [ ] pmr +- [ ] batch create/instantiate (need benchmark) -### maybe deprecate +### maybe not support in future - [ ] shared component - [ ] system group diff --git a/include/UECS/ChunkView.h b/include/UECS/ChunkView.h index 2d9952e..c29e3d5 100644 --- a/include/UECS/ChunkView.h +++ b/include/UECS/ChunkView.h @@ -4,7 +4,6 @@ namespace Ubpa::UECS { class Archetype; - struct Chunk; class ChunkView { public: diff --git a/include/UECS/CmptPtr.h b/include/UECS/CmptPtr.h index 6572068..71b0af4 100644 --- a/include/UECS/CmptPtr.h +++ b/include/UECS/CmptPtr.h @@ -36,6 +36,8 @@ namespace Ubpa::UECS { constexpr CmptAccessPtr(TaggedCmpt p) noexcept : accessType{ CmptAccessType::Of }, p{ CastToVoidPointer(p) } {} explicit constexpr CmptAccessPtr(CmptPtr p) noexcept : CmptAccessPtr{ p, AccessMode::LATEST } {} + explicit constexpr operator CmptPtr() const noexcept { return { CmptType{accessType}, p }; } + constexpr void* Ptr() const noexcept { return p; } constexpr CmptAccessType AccessType() const noexcept { return accessType; } diff --git a/include/UECS/CmptType.h b/include/UECS/CmptType.h index c83f3bd..e0b432b 100644 --- a/include/UECS/CmptType.h +++ b/include/UECS/CmptType.h @@ -22,8 +22,8 @@ namespace Ubpa::UECS { static constexpr CmptType Invalid() noexcept { return CmptType{ size_t_invalid }; } constexpr bool Valid() const noexcept { return hashcode == size_t_invalid; } - template, int> = 0> - constexpr bool Is() const noexcept { return hashcode == TypeID; } + template + constexpr bool Is() const noexcept; constexpr bool operator< (const CmptType& rhs) const noexcept { return hashcode < rhs.hashcode; } constexpr bool operator<=(const CmptType& rhs) const noexcept { return hashcode <= rhs.hashcode; } diff --git a/include/UECS/Entity.h b/include/UECS/Entity.h index f5b8f20..6af3618 100644 --- a/include/UECS/Entity.h +++ b/include/UECS/Entity.h @@ -8,14 +8,14 @@ namespace Ubpa::UECS { public: size_t Idx() const noexcept { return idx; } 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 { return idx == rhs.idx && version == rhs.version; } bool operator<(const Entity& rhs) const noexcept { return idx < rhs.idx || (idx == rhs.idx && version < rhs.version); } - static constexpr Entity Invalid() noexcept { return { size_t_invalid,size_t_invalid }; } - constexpr bool IsValid() const noexcept { return idx == size_t_invalid; } private: friend class EntityMngr; friend class Archetype; diff --git a/include/UECS/SystemFunc.h b/include/UECS/SystemFunc.h index 2d52ec0..8fbc324 100644 --- a/include/UECS/SystemFunc.h +++ b/include/UECS/SystemFunc.h @@ -14,7 +14,7 @@ namespace Ubpa::UECS { // system function registered by Schedule in ::OnUpdate(Schedule&) // name + query(archetype filter + component locator) + singleton locator + function<...> // name('s hashcode) must be unique in global - // query.filter can be change dynamically by other with + // query.filter.none can be change dynamically by other with // [- system function kind] (distinguish by argument list) // common arguments : World*, SingletonsView, {LastFrame|Latest}> // 1. Mode::Entity: per entity function diff --git a/include/UECS/config.h b/include/UECS/config.h new file mode 100644 index 0000000..ecc36ea --- /dev/null +++ b/include/UECS/config.h @@ -0,0 +1,14 @@ +#pragma once + +namespace Ubpa::UECS { + // compile time config + + // Cache-Lines size is (typically) 64 bytes + // it has to be an exponent of 2 and >= 16 + constexpr size_t CHUNK_ALIGNMENT = 64; + + // 16384 bytes : 16 KB + // it has to be a multiple of UECS_CHUNK_ALIGNMENT and an exponent of 2 + constexpr size_t CHUNK_SIZE = 16384; +} + diff --git a/include/UECS/detail/Chunk.h b/include/UECS/detail/Chunk.h index 697a1f8..ed7019b 100644 --- a/include/UECS/detail/Chunk.h +++ b/include/UECS/detail/Chunk.h @@ -5,11 +5,13 @@ #include #include +#include "../config.h" + namespace Ubpa::UECS { using byte = uint8_t; static_assert(sizeof(byte) == 1); - struct alignas(128) Chunk { - static constexpr size_t size = 16 * 1024; + struct alignas(CHUNK_ALIGNMENT) Chunk { + static constexpr size_t size = CHUNK_SIZE; struct Layout { size_t capacity; diff --git a/include/UECS/detail/CmptType.inl b/include/UECS/detail/CmptType.inl index c8ff82e..f1e6eda 100644 --- a/include/UECS/detail/CmptType.inl +++ b/include/UECS/detail/CmptType.inl @@ -1,5 +1,13 @@ #pragma once +namespace Ubpa::UECS { + template + constexpr bool CmptType::Is() const noexcept { + static_assert(!IsTaggedCmpt_v); + return hashcode == TypeID; + } +} + namespace std { template struct hash;