diff --git a/include/UECS/ArchetypeFilter.h b/include/UECS/ArchetypeFilter.h index ed80aed..1521717 100644 --- a/include/UECS/ArchetypeFilter.h +++ b/include/UECS/ArchetypeFilter.h @@ -15,6 +15,6 @@ namespace Ubpa::UECS { size_t HashCode() const noexcept; - bool operator==(const ArchetypeFilter& rhs) const noexcept; + bool operator==(const ArchetypeFilter& rhs) const; }; } diff --git a/include/UECS/ChunkView.h b/include/UECS/ChunkView.h index d6c3c13..cc662e8 100644 --- a/include/UECS/ChunkView.h +++ b/include/UECS/ChunkView.h @@ -8,8 +8,8 @@ namespace Ubpa::UECS { class ChunkView { public: - ChunkView(Archetype* archetype, size_t chunkIdx, Chunk* chunk) - : archetype{ archetype }, chunkIdx{ chunkIdx }, chunk{ chunk } {} + ChunkView(Archetype* archetype, size_t chunkIdx) + : archetype{ archetype }, chunkIdx{ chunkIdx } {} bool Contains(CmptType) const; @@ -18,11 +18,10 @@ namespace Ubpa::UECS { template Cmpt* GetCmptArray() const { return reinterpret_cast(GetCmptArray(CmptType::Of)); } const Entity* GetEntityArray() const { return GetCmptArray(); } - size_t EntityNum() const; + size_t EntityNum() const noexcept; private: Archetype* archetype; size_t chunkIdx; - Chunk* chunk; }; } diff --git a/include/UECS/CmptLocator.h b/include/UECS/CmptLocator.h index d2742f0..3374795 100644 --- a/include/UECS/CmptLocator.h +++ b/include/UECS/CmptLocator.h @@ -25,7 +25,7 @@ namespace Ubpa::UECS { const std::set& CmptTypes() const noexcept { return cmptTypes; } - bool operator==(const CmptLocator& rhs) const noexcept; + bool operator==(const CmptLocator& rhs) const; private: size_t GenHashCode() const noexcept; diff --git a/include/UECS/CmptPtr.h b/include/UECS/CmptPtr.h index c641b1e..c2c83b9 100644 --- a/include/UECS/CmptPtr.h +++ b/include/UECS/CmptPtr.h @@ -8,9 +8,9 @@ namespace Ubpa::UECS { // CmptType + void* class CmptPtr { public: - CmptPtr(CmptType type, void* p) :type{ type }, p{ p }{} + CmptPtr(CmptType type, void* p) noexcept : type{ type }, p{ p }{} template - CmptPtr(Cmpt* p) : type{ CmptType::Of }, p{ p }{} + CmptPtr(Cmpt* p) noexcept : type{ CmptType::Of }, p{ p }{} // unchecked void* Ptr() const noexcept { return p; } @@ -23,6 +23,7 @@ namespace Ubpa::UECS { template Cmpt* As() const noexcept { return reinterpret_cast(p); } + // check: type's access mode must be equal to template auto As() const noexcept { assert(type.GetAccessMode() == mode); diff --git a/include/UECS/CmptTag.h b/include/UECS/CmptTag.h index f70ea59..6990e1b 100644 --- a/include/UECS/CmptTag.h +++ b/include/UECS/CmptTag.h @@ -198,7 +198,7 @@ namespace Ubpa::UECS { IsLastFrameSingleton_v ? AccessMode::LAST_FRAME_SINGLETON : ( IsWriteSingleton_v ? AccessMode::WRITE_SINGLETON : ( IsLatestSingleton_v ? AccessMode::LATEST_SINGLETON : - AccessMode::WRITE // default, TODO : use static_assert + AccessMode::WRITE // default ))))); } diff --git a/include/UECS/CmptType.h b/include/UECS/CmptType.h index 1fb202f..e5921f0 100644 --- a/include/UECS/CmptType.h +++ b/include/UECS/CmptType.h @@ -9,9 +9,9 @@ namespace Ubpa::UECS { // use a hashcode to distinguish different type class CmptType { public: - explicit constexpr CmptType(size_t id, AccessMode mode = AccessMode::WRITE) + explicit constexpr CmptType(size_t id, AccessMode mode = AccessMode::WRITE) noexcept : hashcode{ id }, mode{ mode } {} - explicit constexpr CmptType(std::string_view type_name, AccessMode mode = AccessMode::WRITE) + explicit constexpr CmptType(std::string_view type_name, AccessMode mode = AccessMode::WRITE) noexcept : hashcode{ RuntimeTypeID(type_name) }, mode{ mode } {} template // non-tagged component's access mode is AccessMode::WRITE diff --git a/include/UECS/CmptsView.h b/include/UECS/CmptsView.h index 45a50c4..0f8d4ef 100644 --- a/include/UECS/CmptsView.h +++ b/include/UECS/CmptsView.h @@ -5,10 +5,10 @@ namespace Ubpa::UECS { class CmptsView { public: - CmptsView(const CmptPtr* cmpts, size_t num) + CmptsView(const CmptPtr* cmpts, size_t num) noexcept : cmpts{ cmpts }, num{ num } {} - CmptPtr GetCmpt(CmptType) const; + CmptPtr GetCmpt(CmptType) const noexcept; const CmptPtr* Components() const noexcept { return cmpts; } size_t NumberOfComponents() const noexcept { return num; } diff --git a/include/UECS/Entity.h b/include/UECS/Entity.h index f936567..6ed3e44 100644 --- a/include/UECS/Entity.h +++ b/include/UECS/Entity.h @@ -18,7 +18,7 @@ namespace Ubpa::UECS { private: friend class EntityMngr; friend class Archetype; - constexpr Entity(size_t idx, size_t version) : idx(idx), version(version) {} + 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 072d0d0..12e0a42 100644 --- a/include/UECS/EntityMngr.h +++ b/include/UECS/EntityMngr.h @@ -41,12 +41,11 @@ namespace Ubpa::UECS { // use RTDCmptTraits void Attach(Entity, const CmptType* types, size_t num); - // if not exist cmpt, attach with Args... + // if not exist cmpt, attach with ... // else return it directly template Cmpt* Emplace(Entity, Args&&...); - // use RTDCmptTraits void Detach(Entity, const CmptType* types, size_t num); bool Have(Entity, CmptType) const; @@ -81,7 +80,7 @@ namespace Ubpa::UECS { friend class World; EntityMngr() = default; - static bool IsSet(const CmptType* types, size_t num); + static bool IsSet(const CmptType* types, size_t num) noexcept; const std::set& QueryArchetypes(const EntityQuery& query) const; diff --git a/include/UECS/EntityQuery.h b/include/UECS/EntityQuery.h index e96bf7f..fe9b326 100644 --- a/include/UECS/EntityQuery.h +++ b/include/UECS/EntityQuery.h @@ -19,7 +19,7 @@ namespace Ubpa::UECS { size_t HashCode() const noexcept { return hash_combine(filter.HashCode(), locator.HashCode()); } - bool operator==(const EntityQuery& query) const noexcept { + bool operator==(const EntityQuery& query) const { return filter == query.filter && locator == query.locator; } }; diff --git a/include/UECS/SingletonLocator.h b/include/UECS/SingletonLocator.h index 8318d1f..166a738 100644 --- a/include/UECS/SingletonLocator.h +++ b/include/UECS/SingletonLocator.h @@ -10,8 +10,7 @@ namespace Ubpa::UECS { class SingletonLocator { public: SingletonLocator(const CmptType* types, size_t num); - - SingletonLocator(); + SingletonLocator() = default; template static SingletonLocator Generate(); diff --git a/include/UECS/SystemFunc.h b/include/UECS/SystemFunc.h index 5b0cce5..2d52ec0 100644 --- a/include/UECS/SystemFunc.h +++ b/include/UECS/SystemFunc.h @@ -10,24 +10,22 @@ #include namespace Ubpa::UECS { - // [description] + // [- description] // system function registered by Schedule in ::OnUpdate(Schedule&) - // name + query + function<...> + // 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 Schedule - // [system function kind] (distinguish by argument list) - // common : World*, SingletonsView + // query.filter 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 - // * {LastFrame|Latest}> // * Entity // * size_t indexInQuery // * : {LastFrame|Write|Latest}... // * CmptsView // 2. Mode::Chunk - // * {LastFrame|Latest}> // * ChunkView (necessary) // 3. Mode::Job - // * {LastFrame|Write|Latest}> + // * Write> (only job can write singletons) class SystemFunc { public: enum class Mode { @@ -53,7 +51,7 @@ namespace Ubpa::UECS { const std::string& Name() const noexcept { return name; } - static constexpr size_t HashCode(std::string_view name) { return hash_string(name); } + static constexpr size_t HashCode(std::string_view name) noexcept { return hash_string(name); } size_t HashCode() const noexcept { return hashCode; } diff --git a/include/UECS/SystemMngr.h b/include/UECS/SystemMngr.h index 1ddd364..56de673 100644 --- a/include/UECS/SystemMngr.h +++ b/include/UECS/SystemMngr.h @@ -19,6 +19,7 @@ namespace Ubpa::UECS{ SystemMngr(World* world) : world { world } {} void Register(std::unique_ptr system) { + assert(system.get() != nullptr); systems.emplace(system->GetName(), std::move(system)); } bool IsRegister(std::string_view name) const { diff --git a/include/UECS/detail/Archetype.h b/include/UECS/detail/Archetype.h index 434c46d..4d1a82c 100644 --- a/include/UECS/detail/Archetype.h +++ b/include/UECS/detail/Archetype.h @@ -51,7 +51,7 @@ namespace Ubpa::UECS { void* At(CmptType, size_t idx) const; template - Cmpt* At(size_t idx) const; + Cmpt* At(size_t idx) const{ return reinterpret_cast(At(CmptType::Of, idx)); } // no Entity std::vector Components(size_t idx) const; @@ -66,7 +66,7 @@ namespace Ubpa::UECS { // use RTDCmptTraits's default constructor size_t Create(Entity); - + // return index in archetype size_t Instantiate(Entity, size_t srcIdx); @@ -101,7 +101,7 @@ namespace Ubpa::UECS { void SetLayout(); size_t Offsetof(CmptType type) const { return type2offset.find(type)->second; } - static bool NotContainEntity(const CmptType* types, size_t num); + static bool NotContainEntity(const CmptType* types, size_t num) noexcept; friend class EntityMngr; diff --git a/include/UECS/detail/Archetype.inl b/include/UECS/detail/Archetype.inl index d1a619f..7d04d74 100644 --- a/include/UECS/detail/Archetype.inl +++ b/include/UECS/detail/Archetype.inl @@ -16,6 +16,7 @@ namespace Ubpa::UECS { template Archetype* Archetype::Add(const Archetype* from) { + static_assert(sizeof...(Cmpts) > 0); assert(((!from->types.Contains(CmptType::Of)) &&...)); Archetype* rst = new Archetype; @@ -30,11 +31,6 @@ namespace Ubpa::UECS { return rst; } - template - Cmpt* Archetype::At(size_t idx) const { - return reinterpret_cast(At(CmptType::Of, idx)); - } - template std::tuple> Archetype::Create(Entity e) { assert((types.Contains(CmptType::Of) &&...) && types.data.size() == 1 + sizeof...(Cmpts)); diff --git a/include/UECS/detail/CmptTypeSet.inl b/include/UECS/detail/CmptTypeSet.inl index 423d7a8..9b3df59 100644 --- a/include/UECS/detail/CmptTypeSet.inl +++ b/include/UECS/detail/CmptTypeSet.inl @@ -2,11 +2,13 @@ namespace Ubpa::UECS { inline void CmptTypeSet::Insert(const CmptType* types, size_t num) { + assert(types || num == 0); for (size_t i = 0; i < num; i++) data.insert(types[i]); } inline void CmptTypeSet::Erase(const CmptType* types, size_t num) { + assert(types || num == 0); for (size_t i = 0; i < num; i++) data.erase(types[i]); } @@ -16,6 +18,7 @@ namespace Ubpa::UECS { } inline bool CmptTypeSet::Contains(const CmptType* types, size_t num) const { + assert(types || num == 0); for (size_t i = 0; i < num; i++) { if (!Contains(types[i])) return false; @@ -33,6 +36,7 @@ namespace Ubpa::UECS { } inline bool CmptTypeSet::ContainsAny(const CmptType* types, size_t num) const { + assert(types || num == 0); for (size_t i = 0; i < num; i++) { if (Contains(types[i])) return true; diff --git a/include/UECS/detail/RTDCmptTraits.inl b/include/UECS/detail/RTDCmptTraits.inl index 7171b77..7297611 100644 --- a/include/UECS/detail/RTDCmptTraits.inl +++ b/include/UECS/detail/RTDCmptTraits.inl @@ -9,42 +9,42 @@ namespace Ubpa::UECS { } inline RTDCmptTraits& RTDCmptTraits::RegisterSize(CmptType type, size_t size) { - sizeofs[type] = size; + sizeofs.emplace(type, size); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterAlignment(CmptType type, size_t alignment) { - alignments[type] = alignment; + alignments.emplace(type, alignment); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterDefaultConstructor(CmptType type, std::function f) { - default_constructors[type] = std::move(f); + default_constructors.emplace(type, std::move(f)); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterCopyConstructor(CmptType type, std::function f) { - copy_constructors[type] = std::move(f); + copy_constructors.emplace(type, std::move(f)); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterMoveConstructor(CmptType type, std::function f) { - move_constructors[type] = std::move(f); + move_constructors.emplace(type, move(f)); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterMoveAssignment(CmptType type, std::function f) { - move_assignments[type] = std::move(f); + move_assignments.emplace(type, std::move(f)); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterDestructor(CmptType type, std::function f) { - destructors[type] = std::move(f); + destructors.emplace(type, std::move(f)); return *this; } inline RTDCmptTraits& RTDCmptTraits::RegisterName(CmptType type, std::string name) { - names[type] = std::move(name); + names.emplace(type, std::move(name)); return *this; } @@ -114,34 +114,34 @@ namespace Ubpa::UECS { constexpr CmptType type = CmptType::Of; - sizeofs[type] = sizeof(Cmpt); - alignments[type] = alignof(Cmpt); - names[type] = std::string{ nameof::nameof_type() }; + sizeofs.emplace(type, sizeof(Cmpt)); + alignments.emplace(type, alignof(Cmpt)); + names.emplace(type, std::string{ nameof::nameof_type() }); if constexpr (!std::is_trivially_default_constructible_v) { - default_constructors[type] = [](void* cmpt) { + default_constructors.emplace(type, [](void* cmpt) { new(cmpt)Cmpt; - }; + }); } if constexpr (!std::is_trivially_destructible_v) { - destructors[type] = [](void* cmpt) { + destructors.emplace(type, [](void* cmpt) { reinterpret_cast(cmpt)->~Cmpt(); - }; + }); } if constexpr (!std::is_trivially_move_constructible_v) { - move_constructors[type] = [](void* dst, void* src) { + move_constructors.emplace(type, [](void* dst, void* src) { new(dst)Cmpt(std::move(*reinterpret_cast(src))); - }; + }); } if constexpr (!std::is_trivially_move_assignable_v) { - move_assignments[type] = [](void* dst, void* src) { + move_assignments.emplace(type, [](void* dst, void* src) { *reinterpret_cast(dst) = std::move(*reinterpret_cast(src)); - }; + }); } if constexpr (!std::is_trivially_copy_constructible_v) { - copy_constructors[type] = [](void* dst, void* src) { + copy_constructors.emplace(type, [](void* dst, void* src) { new(dst)Cmpt(*reinterpret_cast(src)); - }; + }); } } diff --git a/include/UECS/detail/RTSCmptTraits.h b/include/UECS/detail/RTSCmptTraits.h index 149e628..8f3d9e4 100644 --- a/include/UECS/detail/RTSCmptTraits.h +++ b/include/UECS/detail/RTSCmptTraits.h @@ -18,6 +18,8 @@ namespace Ubpa::UECS { template void Register(); + + // use RTDCmptTraits void Register(CmptType type); template diff --git a/include/UECS/detail/RTSCmptTraits.inl b/include/UECS/detail/RTSCmptTraits.inl index af2bf67..c11ad34 100644 --- a/include/UECS/detail/RTSCmptTraits.inl +++ b/include/UECS/detail/RTSCmptTraits.inl @@ -57,28 +57,28 @@ namespace Ubpa::UECS { constexpr CmptType type = CmptType::Of; - sizeofs[type] = sizeof(Cmpt); - alignments[type] = alignof(Cmpt); + sizeofs.emplace(type, sizeof(Cmpt)); + alignments.emplace(type, alignof(Cmpt)); if constexpr (!std::is_trivially_destructible_v) { - destructors[type] = [](void* cmpt) { + destructors.emplace(type, [](void* cmpt) { reinterpret_cast(cmpt)->~Cmpt(); - }; + }); } if constexpr (!std::is_trivially_move_constructible_v) { - move_constructors[type] = [](void* dst, void* src) { + move_constructors.emplace(type, [](void* dst, void* src) { new(dst)Cmpt(std::move(*reinterpret_cast(src))); - }; + }); } if constexpr (!std::is_trivially_copy_assignable_v) { - move_assignments[type] = [](void* dst, void* src) { + move_assignments.emplace(type, [](void* dst, void* src) { *reinterpret_cast(dst) = std::move(*reinterpret_cast(src)); - }; + }); } if constexpr (!std::is_trivially_copy_constructible_v) { - copy_constructors[type] = [](void* dst, void* src) { + copy_constructors.emplace(type, [](void* dst, void* src) { new(dst)Cmpt(*reinterpret_cast(src)); - }; + }); } } @@ -118,13 +118,13 @@ namespace Ubpa::UECS { auto move_assignments_target = rtdct.move_assignments.find(type); if (destructor_target != rtdct.destructors.end()) - destructors[type] = destructor_target->second; + destructors.emplace(type, destructor_target->second); if (copy_constructor_target != rtdct.copy_constructors.end()) - copy_constructors[type] = copy_constructor_target->second; + copy_constructors.emplace(type, copy_constructor_target->second); if (move_constructor_target != rtdct.move_constructors.end()) - move_constructors[type] = move_constructor_target->second; + move_constructors.emplace(type, move_constructor_target->second); if (move_assignments_target != rtdct.move_assignments.end()) - move_assignments[type] = move_assignments_target->second; + move_assignments.emplace(type, move_assignments_target->second); } inline void RTSCmptTraits::Deregister(CmptType type) noexcept { diff --git a/include/UECS/detail/SystemFunc.inl b/include/UECS/detail/SystemFunc.inl index dd47fd6..c274220 100644 --- a/include/UECS/detail/SystemFunc.inl +++ b/include/UECS/detail/SystemFunc.inl @@ -37,7 +37,6 @@ namespace Ubpa::UECS { && !singletonLocator.HasWriteSingletonType()); } - // Mode::Chunk template SystemFunc::SystemFunc( diff --git a/src/core/Archetype.cpp b/src/core/Archetype.cpp index 80256c1..89186d8 100644 --- a/src/core/Archetype.cpp +++ b/src/core/Archetype.cpp @@ -22,6 +22,12 @@ void Archetype::SetLayout() { vector alignments; vector sizes; + const size_t numType = types.data.size(); + + alignments.reserve(numType); + sizes.reserve(numType); + type2offset.reserve(numType); + for (const auto& type : types.data) { alignments.push_back(cmptTraits.Alignof(type)); sizes.push_back(cmptTraits.Sizeof(type)); @@ -32,7 +38,7 @@ void Archetype::SetLayout() { size_t i = 0; for (const auto& type : types.data) - type2offset[type] = layout.offsets[i++]; + type2offset.emplace(type, layout.offsets[i++]); } Archetype* Archetype::New(const CmptType* types, size_t num) { @@ -66,6 +72,7 @@ Archetype* Archetype::Add(const Archetype* from, const CmptType* types, size_t n } Archetype* Archetype::Remove(const Archetype* from, const CmptType* types, size_t num) { + assert(NotContainEntity(types, num)); assert(from->types.Contains(types, num)); Archetype* rst = new Archetype; @@ -129,6 +136,7 @@ void* Archetype::At(CmptType type, size_t idx) const { size_t Archetype::Instantiate(Entity e, size_t srcIdx) { assert(srcIdx < entityNum); + size_t dstIdx = RequestBuffer(); size_t srcIdxInChunk = srcIdx % chunkCapacity; @@ -158,19 +166,23 @@ size_t Archetype::Instantiate(Entity e, size_t srcIdx) { tuple, vector>, vector> Archetype::Locate(const CmptLocator& locator) const { assert(types.IsMatch(locator)); - vector> chunkCmpts(chunks.size()); - vector chunkEntity; + const size_t numChunk = chunks.size(); + const size_t numType = locator.CmptTypes().size(); + const size_t offsetEntity = Offsetof(CmptType::Of); - for (size_t i = 0; i < chunks.size(); i++) { + vector> chunkCmpts(numChunk); + vector chunkEntity(numChunk); + + for (size_t i = 0; i < numChunk; i++) { auto data = chunks[i]->Data(); - chunkCmpts[i].reserve(locator.CmptTypes().size()); + chunkCmpts[i].reserve(numType); for (const auto& type : locator.CmptTypes()) chunkCmpts[i].emplace_back(type, data + Offsetof(type)); - chunkEntity.push_back(reinterpret_cast(data + Offsetof(CmptType::Of))); + chunkEntity[i] = reinterpret_cast(data + offsetEntity); } vector sizes; - sizes.reserve(locator.CmptTypes().size()); + sizes.reserve(numType); for (const auto& type : locator.CmptTypes()) sizes.push_back(cmptTraits.Sizeof(type)); @@ -246,6 +258,8 @@ vector Archetype::Components(size_t idx) const { } size_t Archetype::EntityNumOfChunk(size_t chunkIdx) const noexcept { + assert(chunkIdx < chunks.size()); + if (chunkIdx == chunks.size() - 1) return entityNum - (chunks.size() - 1) * chunkCapacity; else @@ -261,7 +275,8 @@ CmptTypeSet Archetype::GenCmptTypeSet(const CmptType* types, size_t num) { } -bool Archetype::NotContainEntity(const CmptType* types, size_t num) { +bool Archetype::NotContainEntity(const CmptType* types, size_t num) noexcept { + assert(types || num == 0); for (size_t i = 0; i < num; i++) { if (types[i].Is()) return false; diff --git a/src/core/ArchetypeFilter.cpp b/src/core/ArchetypeFilter.cpp index 548df50..74499f4 100644 --- a/src/core/ArchetypeFilter.cpp +++ b/src/core/ArchetypeFilter.cpp @@ -15,7 +15,7 @@ size_t ArchetypeFilter::HashCode() const noexcept { return rst; } -bool ArchetypeFilter::operator==(const ArchetypeFilter& rhs) const noexcept { +bool ArchetypeFilter::operator==(const ArchetypeFilter& rhs) const { return all == rhs.all && any == rhs.any && none == rhs.none; diff --git a/src/core/Chunk.cpp b/src/core/Chunk.cpp index 1d6bb1a..972a9cc 100644 --- a/src/core/Chunk.cpp +++ b/src/core/Chunk.cpp @@ -16,9 +16,9 @@ Chunk::Layout Chunk::GenLayout(const vector& alignments, const vector items; + vector items(sizes.size()); for (size_t i = 0; i < sizes.size(); i++) - items.push_back(Item{ alignments[i], i }); + items[i] = Item{ alignments[i], i }; sort(items.begin(), items.end()); constexpr size_t chunkSize = 16 * 1024; diff --git a/src/core/ChunkView.cpp b/src/core/ChunkView.cpp index 6c2c369..d73f919 100644 --- a/src/core/ChunkView.cpp +++ b/src/core/ChunkView.cpp @@ -8,7 +8,7 @@ void* ChunkView::GetCmptArray(CmptType t) const { return Contains(t) ? archetype->Locate(chunkIdx, t) : nullptr; } -size_t ChunkView::EntityNum() const { +size_t ChunkView::EntityNum() const noexcept { return archetype->EntityNumOfChunk(chunkIdx); } diff --git a/src/core/CmptLocator.cpp b/src/core/CmptLocator.cpp index 0070237..d7bc99a 100644 --- a/src/core/CmptLocator.cpp +++ b/src/core/CmptLocator.cpp @@ -25,6 +25,6 @@ size_t CmptLocator::GenHashCode() const noexcept { return rst; } -bool CmptLocator::operator==(const CmptLocator& rhs) const noexcept { +bool CmptLocator::operator==(const CmptLocator& rhs) const { return cmptTypes == rhs.cmptTypes; } diff --git a/src/core/CmptsView.cpp b/src/core/CmptsView.cpp index 13d247e..1ca0485 100644 --- a/src/core/CmptsView.cpp +++ b/src/core/CmptsView.cpp @@ -2,7 +2,7 @@ using namespace Ubpa::UECS; -CmptPtr CmptsView::GetCmpt(CmptType t) const { +CmptPtr CmptsView::GetCmpt(CmptType t) const noexcept { for (size_t i = 0; i < num; i++) { if (cmpts[i].Type() == t) { assert(cmpts[i].Type().GetAccessMode() == t.GetAccessMode()); diff --git a/src/core/EntityMngr.cpp b/src/core/EntityMngr.cpp index fc826f1..8bceb8e 100644 --- a/src/core/EntityMngr.cpp +++ b/src/core/EntityMngr.cpp @@ -196,7 +196,7 @@ Entity EntityMngr::Instantiate(Entity srcEntity) { return dstEntity; } -bool EntityMngr::IsSet(const CmptType* types, size_t num) { +bool EntityMngr::IsSet(const CmptType* types, size_t num) noexcept { for (size_t i = 0; i < num; i++) { for (size_t j = 0; j < i; j++) if (types[i] == types[j]) @@ -310,7 +310,7 @@ void EntityMngr::GenChunkJob(World* w, Job* job, SystemFunc* sys) const { (*sys)( w, SingletonsView{ singletons.data(), singletons.size() }, - ChunkView{ archetype, i, archetype->GetChunk(i) } + ChunkView{ archetype, i } ); }); } diff --git a/src/core/SingletonLocator.cpp b/src/core/SingletonLocator.cpp index bc8f123..2385ae3 100644 --- a/src/core/SingletonLocator.cpp +++ b/src/core/SingletonLocator.cpp @@ -8,13 +8,11 @@ using namespace Ubpa::UECS; using namespace std; SingletonLocator::SingletonLocator(const CmptType* types, size_t num) { - assert(types != nullptr && num > 0); + assert(types || num == 0); for (size_t i = 0; i < num; i++) singletonTypes.insert(types[i]); } -SingletonLocator::SingletonLocator() {} - bool SingletonLocator::HasWriteSingletonType() const noexcept { for (const auto& type : singletonTypes) { if (type.GetAccessMode() == AccessMode::WRITE_SINGLETON) diff --git a/src/core/SystemFunc.cpp b/src/core/SystemFunc.cpp index 1d29d6b..cc01d90 100644 --- a/src/core/SystemFunc.cpp +++ b/src/core/SystemFunc.cpp @@ -10,7 +10,7 @@ void SystemFunc::operator()(World* w, SingletonsView singletonsView, Entity e, s e, entityIndexInQuery, cmptsView, - ChunkView{ nullptr, size_t_invalid, nullptr } + ChunkView{ nullptr, size_t_invalid } ); } @@ -34,6 +34,6 @@ void SystemFunc::operator()(World* w, SingletonsView singletonsView) { Entity::Invalid(), size_t_invalid, CmptsView{ nullptr, 0 }, - ChunkView{ nullptr, size_t_invalid, nullptr } + ChunkView{ nullptr, size_t_invalid } ); }