Skip to content

Commit

Permalink
RTDCmptsView::CmptHandle::Mode -> CmptTag::Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Jun 5, 2020
1 parent 445937a commit 6f9e4d5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
6 changes: 6 additions & 0 deletions include/UECS/CmptTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace Ubpa {
namespace CmptTag {
// LastFrame -> Write -> Latest

enum class Mode {
LAST_FRAME,
WRITE,
LATEST
};

template<typename Cmpt>
class LastFrame {
public:
Expand Down
2 changes: 2 additions & 0 deletions include/UECS/EntityLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace Ubpa {
const std::set<CmptType>& LatestCmptTypes() const noexcept { return latestCmptTypes; }
const std::set<CmptType>& CmptTypes() const noexcept { return cmptTypes; }

CmptTag::Mode GetCmptTagMode(CmptType type) const;

bool operator==(const EntityLocator& locator) const noexcept;
private:
size_t GenHashCode() const noexcept;
Expand Down
33 changes: 10 additions & 23 deletions include/UECS/RTDCmptsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "CmptPtr.h"
#include "CmptType.h"
#include "CmptTag.h"

#include <set>

Expand All @@ -16,35 +17,28 @@ namespace Ubpa {
// for read/write control
class CmptHandle {
public:
enum class Mode {
INVALID,
LAST_FRAME,
WRITE,
LATEST
};

CmptHandle(CmptType type, void* cmpt, Mode mode)
CmptHandle(CmptType type, void* cmpt, CmptTag::Mode mode)
: type{ type }, cmpt{ cmpt }, mode{ mode }{}

CmptType GetCmptType() const noexcept { return type; }
Mode GetMode() const noexcept { return mode; }
CmptTag::Mode GetMode() const noexcept { return mode; }

CmptCPtr AsLastFrame() const noexcept {
assert(mode == Mode::LAST_FRAME);
assert(mode == CmptTag::Mode::LAST_FRAME);
return { type, cmpt };
}
CmptPtr AsWrite() const noexcept {
assert(mode == Mode::WRITE);
assert(mode == CmptTag::Mode::WRITE);
return { type, cmpt };
}
CmptCPtr AsLatest() const noexcept {
assert(mode == Mode::LATEST);
assert(mode == CmptTag::Mode::LATEST);
return { type, cmpt };
}
private:
CmptType type;
void* cmpt;
Mode mode;
CmptTag::Mode mode;
};

// forward
Expand All @@ -64,25 +58,18 @@ namespace Ubpa {
bool operator!=(const Iterator& rhs) const noexcept {
return ptr_cmpt != rhs.ptr_cmpt;
}
CmptHandle operator*() const {
return { *typeIter, *ptr_cmpt, GetMode() };
}
const CmptHandle* operator->() const noexcept {
handle = { *typeIter, *ptr_cmpt, GetMode() };
return &handle;
}
CmptHandle operator*() const;
const CmptHandle* operator->() const noexcept;
Iterator& operator++() {
typeIter++;
ptr_cmpt++;
return *this;
}
private:
CmptHandle::Mode GetMode() const;

EntityLocator* locator;
std::set<CmptType>::iterator typeIter;
void* const* ptr_cmpt;
mutable CmptHandle handle{ CmptType::Invalid(), nullptr, CmptHandle::Mode::INVALID };
mutable CmptHandle handle{ CmptType::Invalid(), nullptr, CmptTag::Mode{} };
};

RTDCmptsView(EntityLocator* locator, void** cmpts)
Expand Down
10 changes: 10 additions & 0 deletions src/core/EntityLocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ bool EntityLocator::operator==(const EntityLocator& locator) const noexcept {
&& writeCmptTypes == locator.writeCmptTypes
&& latestCmptTypes == latestCmptTypes;
}

CmptTag::Mode EntityLocator::GetCmptTagMode(CmptType type) const {
assert(cmptTypes.find(type) != cmptTypes.end());
if (lastFrameCmptTypes.find(type) != lastFrameCmptTypes.end())
return CmptTag::Mode::LAST_FRAME;
else if (writeCmptTypes.find(type) != writeCmptTypes.end())
return CmptTag::Mode::WRITE;
else // lastestCmptTypes.find(type) != lastestCmptTypes.end())
return CmptTag::Mode::LATEST;
}
21 changes: 9 additions & 12 deletions src/core/RTDCmptsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
using namespace Ubpa;
using namespace std;

RTDCmptsView::CmptHandle::Mode RTDCmptsView::Iterator::GetMode() const {
auto type = *typeIter;
if (locator->LastFrameCmptTypes().find(type) != locator->LastFrameCmptTypes().end())
return CmptHandle::Mode::LAST_FRAME;
else if (locator->WriteCmptTypes().find(type) != locator->WriteCmptTypes().end())
return CmptHandle::Mode::WRITE;
else if (locator->LatestCmptTypes().find(type) != locator->LatestCmptTypes().end())
return CmptHandle::Mode::LATEST;
else
return CmptHandle::Mode::INVALID;
}

RTDCmptsView::Iterator RTDCmptsView::begin() const noexcept {
return { locator, locator->CmptTypes().begin(), cmpts };
}
Expand All @@ -28,3 +16,12 @@ RTDCmptsView::Iterator RTDCmptsView::end() const noexcept {
const set<CmptType>& RTDCmptsView::CmptTypes() const noexcept {
return locator->CmptTypes();
}

RTDCmptsView::CmptHandle RTDCmptsView::Iterator::operator*() const {
return { *typeIter, *ptr_cmpt, locator->GetCmptTagMode(*typeIter) };
}

const RTDCmptsView::CmptHandle* RTDCmptsView::Iterator::operator->() const noexcept {
handle = { *typeIter, *ptr_cmpt, locator->GetCmptTagMode(*typeIter) };
return &handle;
}

0 comments on commit 6f9e4d5

Please sign in to comment.