Skip to content

Commit

Permalink
CmptAccessTypeSet
Browse files Browse the repository at this point in the history
std::set<CmptAccessType, std::less<>>
  • Loading branch information
Ubpa committed Aug 26, 2020
1 parent 1a9c196 commit 63705bd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/UECS/ArchetypeFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace Ubpa::UECS {
// filter Archetype with all, any and none
struct ArchetypeFilter {
std::set<CmptAccessType> all;
std::set<CmptAccessType> any;
CmptAccessTypeSet all;
CmptAccessTypeSet any;
std::set<CmptType> none;

size_t HashCode() const noexcept;
Expand Down
4 changes: 2 additions & 2 deletions include/UECS/CmptLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ namespace Ubpa::UECS {

size_t HashCode() const noexcept { return hashCode; }

const std::set<CmptAccessType>& CmptAccessTypes() const noexcept { return cmptTypes; }
const CmptAccessTypeSet& CmptAccessTypes() const noexcept { return cmptTypes; }

bool operator==(const CmptLocator& rhs) const;
private:
size_t GenHashCode() const noexcept;

std::set<CmptAccessType> cmptTypes;
CmptAccessTypeSet cmptTypes;

size_t hashCode;
};
Expand Down
18 changes: 18 additions & 0 deletions include/UECS/CmptType.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <UTemplate/TypeID.h>

#include <set>

namespace Ubpa::UECS {
// Component Type
// use a hashcode to distinguish different type
Expand Down Expand Up @@ -68,10 +70,26 @@ namespace Ubpa::UECS {
constexpr bool operator>=(const CmptAccessType& rhs) const noexcept { return type >= rhs.type; }
constexpr bool operator==(const CmptAccessType& rhs) const noexcept { return type == rhs.type; }
constexpr bool operator!=(const CmptAccessType& rhs) const noexcept { return type != rhs.type; }

constexpr bool operator< (const CmptType& rhs) const noexcept { return type < rhs; }
constexpr bool operator<=(const CmptType& rhs) const noexcept { return type <= rhs; }
constexpr bool operator> (const CmptType& rhs) const noexcept { return type > rhs; }
constexpr bool operator>=(const CmptType& rhs) const noexcept { return type >= rhs; }
constexpr bool operator==(const CmptType& rhs) const noexcept { return type == rhs; }
constexpr bool operator!=(const CmptType& rhs) const noexcept { return type != rhs; }

friend constexpr bool operator< (const CmptType& lhs, const CmptAccessType& rhs) noexcept { return lhs < rhs.type; }
friend constexpr bool operator<=(const CmptType& lhs, const CmptAccessType& rhs) noexcept { return lhs <= rhs.type; }
friend constexpr bool operator> (const CmptType& lhs, const CmptAccessType& rhs) noexcept { return lhs > rhs.type; }
friend constexpr bool operator>=(const CmptType& lhs, const CmptAccessType& rhs) noexcept { return lhs >= rhs.type; }
friend constexpr bool operator==(const CmptType& lhs, const CmptAccessType& rhs) noexcept { return lhs == rhs.type; }
friend constexpr bool operator!=(const CmptType& lhs, const CmptAccessType& rhs) noexcept { return lhs != rhs.type; }
private:
CmptType type;
AccessMode mode;
};

using CmptAccessTypeSet = std::set<CmptAccessType, std::less<>>;
}

#include "detail/CmptType.inl"
2 changes: 1 addition & 1 deletion include/UECS/detail/EntityMngr.inl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace Ubpa::UECS {
template<typename Cmpt>
std::vector<Cmpt*> EntityMngr::GetCmptArray(const ArchetypeFilter& filter) const {
constexpr auto type = CmptType::Of<Cmpt>;
assert(filter.all.find(type) != filter.all.end());
assert(filter.all.find(type) != filter.all.end()); // transparent less

std::vector<Cmpt*> rst;

Expand Down
2 changes: 1 addition & 1 deletion src/core/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Ubpa::UECS::detail {
return *this;
}

set<CmptAccessType> needTypes;
set<CmptAccessType, std::less<>> needTypes;
set<CmptType> noneTypes;
set<SystemFunc*> sysFuncs;
};
Expand Down

0 comments on commit 63705bd

Please sign in to comment.