Skip to content

Commit

Permalink
fix bug : Archetype::Erase
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Aug 6, 2020
1 parent 9f7adaa commit 45b0e05
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/UECS/ChunkView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Ubpa::UECS {
void* GetCmptArray(CmptType) const;
template<typename Cmpt>
Cmpt* GetCmptArray() const { return reinterpret_cast<Cmpt*>(GetCmptArray(CmptType::Of<Cmpt>)); }
const Entity* GetEntityArray() const { return GetCmptArray<Entity>(); }
size_t EntityNum() const;

private:
Expand Down
4 changes: 2 additions & 2 deletions include/UECS/CmptsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +35,7 @@ namespace Ubpa::UECS {

void* const* Components() const noexcept { return cmpts; }
private:
EntityLocator* locator;
const EntityLocator* locator;
void* const* cmpts;
};
}
6 changes: 4 additions & 2 deletions src/core/Archetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -207,13 +207,15 @@ size_t Archetype::Erase(size_t idx) {
byte* src = srcBuffer + offset + srcIdxInChunk * size;

if (type.Is<Entity>())
movedIdx = reinterpret_cast<Entity*>(dst)->Idx();
movedIdx = reinterpret_cast<Entity*>(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);
Expand Down

0 comments on commit 45b0e05

Please sign in to comment.