Skip to content

Commit

Permalink
get chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Mar 23, 2021
1 parent 1148ac1 commit cf31e78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/UECS/EntityMngr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ namespace Ubpa::UECS {
std::vector<CmptAccessPtr> Components(Entity, AccessMode) const;
std::vector<CmptAccessPtr> WriteComponents(Entity e) const { return Components(e, AccessMode::WRITE); }
std::vector<CmptAccessPtr> ReadComponents(Entity e) const { return Components(e, AccessMode::LATEST); }

// chunk + index in chunk
std::tuple<Chunk*, std::size_t> GetChunk(Entity e) const;

bool Exist(Entity) const noexcept;

Expand Down
6 changes: 6 additions & 0 deletions src/core/EntityMngr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,9 @@ void EntityMngr::NewFrame() noexcept {
for (auto& [ts, a] : ts2a)
a->NewFrame();
}

std::tuple<Chunk*, std::size_t> EntityMngr::GetChunk(Entity e) const {
if(!Exist(e)) throw std::invalid_argument("Entity is invalid");
const auto& info = entityTable[e.index];
return { info.archetype->GetChunks()[info.chunkIdx],info.idxInChunk };
}

0 comments on commit cf31e78

Please sign in to comment.