diff --git a/CMakeLists.txt b/CMakeLists.txt index 175469e..96f4664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -project(UECS VERSION 0.10.5) +project(UECS VERSION 0.10.7) message(STATUS "[Project] ${PROJECT_NAME}") include(cmake/InitUCMake.cmake) diff --git a/include/UECS/ChunkView.h b/include/UECS/ChunkView.h index fd204d8..d6c3c13 100644 --- a/include/UECS/ChunkView.h +++ b/include/UECS/ChunkView.h @@ -17,6 +17,7 @@ namespace Ubpa::UECS { void* GetCmptArray(CmptType) const; template Cmpt* GetCmptArray() const { return reinterpret_cast(GetCmptArray(CmptType::Of)); } + const Entity* GetEntityArray() const { return GetCmptArray(); } size_t EntityNum() const; private: diff --git a/include/UECS/CmptsView.h b/include/UECS/CmptsView.h index 0b92213..c9499f3 100644 --- a/include/UECS/CmptsView.h +++ b/include/UECS/CmptsView.h @@ -12,7 +12,7 @@ namespace Ubpa::UECS { // use CmptsView::Iterator to read CmptPtr class CmptsView { public: - CmptsView(EntityLocator* locator, void** cmpts) + CmptsView(const EntityLocator* locator, void** cmpts) : locator{ locator }, cmpts{ cmpts }{} // check AccessMode @@ -35,7 +35,7 @@ namespace Ubpa::UECS { void* const* Components() const noexcept { return cmpts; } private: - EntityLocator* locator; + const EntityLocator* locator; void* const* cmpts; }; } diff --git a/src/core/Archetype.cpp b/src/core/Archetype.cpp index a487cc3..95cc4a6 100644 --- a/src/core/Archetype.cpp +++ b/src/core/Archetype.cpp @@ -192,7 +192,7 @@ size_t Archetype::Erase(size_t idx) { size_t dstIdxInChunk = idx % chunkCapacity; byte* dstBuffer = chunks[idx / chunkCapacity]->Data(); - size_t movedIdx = size_t_invalid; + size_t movedIdx; if (idx != entityNum - 1) { size_t movedIdxInArchetype = entityNum - 1; @@ -207,13 +207,15 @@ size_t Archetype::Erase(size_t idx) { byte* src = srcBuffer + offset + srcIdxInChunk * size; if (type.Is()) - movedIdx = reinterpret_cast(dst)->Idx(); + movedIdx = reinterpret_cast(src)->Idx(); cmptTraits.MoveAssign(type, dst, src); cmptTraits.Destruct(type, src); } } else { + movedIdx = size_t_invalid; + for (auto type : types) { auto size = cmptTraits.Sizeof(type); auto offset = Offsetof(type);