Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Aug 25, 2020
1 parent bc53e54 commit e6cefe7
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 11 deletions.
7 changes: 4 additions & 3 deletions doc/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
- [x] system base -> `System`
- [x] singleton

### unimportant
### maybe support in future

- [x] exception: invalid `Entity`
- [ ] batch create/instantiate (need benchmark)
- [x] lock `FilterChange`
- [ ] `EntityMngr` `Query`-driven API
- [x] `CmptsView` = `const EntityLocator* locator + void** cmpts`
- [ ] pmr
- [ ] batch create/instantiate (need benchmark)

### maybe deprecate
### maybe not support in future

- [ ] shared component
- [ ] system group
Expand Down
1 change: 0 additions & 1 deletion include/UECS/ChunkView.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ubpa::UECS {
class Archetype;
struct Chunk;

class ChunkView {
public:
Expand Down
2 changes: 2 additions & 0 deletions include/UECS/CmptPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace Ubpa::UECS {
constexpr CmptAccessPtr(TaggedCmpt p) noexcept : accessType{ CmptAccessType::Of<TaggedCmpt> }, p{ CastToVoidPointer(p) } {}
explicit constexpr CmptAccessPtr(CmptPtr p) noexcept : CmptAccessPtr{ p, AccessMode::LATEST } {}

explicit constexpr operator CmptPtr() const noexcept { return { CmptType{accessType}, p }; }

constexpr void* Ptr() const noexcept { return p; }

constexpr CmptAccessType AccessType() const noexcept { return accessType; }
Expand Down
4 changes: 2 additions & 2 deletions include/UECS/CmptType.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace Ubpa::UECS {
static constexpr CmptType Invalid() noexcept { return CmptType{ size_t_invalid }; }
constexpr bool Valid() const noexcept { return hashcode == size_t_invalid; }

template<typename Cmpt, std::enable_if_t<!IsTaggedCmpt_v<Cmpt>, int> = 0>
constexpr bool Is() const noexcept { return hashcode == TypeID<Cmpt>; }
template<typename Cmpt>
constexpr bool Is() const noexcept;

constexpr bool operator< (const CmptType& rhs) const noexcept { return hashcode < rhs.hashcode; }
constexpr bool operator<=(const CmptType& rhs) const noexcept { return hashcode <= rhs.hashcode; }
Expand Down
4 changes: 2 additions & 2 deletions include/UECS/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Ubpa::UECS {
public:
size_t Idx() const noexcept { return idx; }
size_t Version() const noexcept { return version; }
static constexpr Entity Invalid() noexcept { return { size_t_invalid,size_t_invalid }; }
constexpr bool IsValid() const noexcept { return idx == size_t_invalid; }
bool operator==(const Entity& rhs) const noexcept {
return idx == rhs.idx && version == rhs.version;
}
bool operator<(const Entity& rhs) const noexcept {
return idx < rhs.idx || (idx == rhs.idx && version < rhs.version);
}
static constexpr Entity Invalid() noexcept { return { size_t_invalid,size_t_invalid }; }
constexpr bool IsValid() const noexcept { return idx == size_t_invalid; }
private:
friend class EntityMngr;
friend class Archetype;
Expand Down
2 changes: 1 addition & 1 deletion include/UECS/SystemFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Ubpa::UECS {
// system function registered by Schedule in <System>::OnUpdate(Schedule&)
// name + query(archetype filter + component locator) + singleton locator + function<...>
// name('s hashcode) must be unique in global
// query.filter can be change dynamically by other <System> with <Schedule>
// query.filter.none can be change dynamically by other <System> with <Schedule>
// [- system function kind] (distinguish by argument list)
// common arguments : World*, SingletonsView, {LastFrame|Latest}<Singleton<Cmpt>>
// 1. Mode::Entity: per entity function
Expand Down
14 changes: 14 additions & 0 deletions include/UECS/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace Ubpa::UECS {
// compile time config

// Cache-Lines size is (typically) 64 bytes
// it has to be an exponent of 2 and >= 16
constexpr size_t CHUNK_ALIGNMENT = 64;

// 16384 bytes : 16 KB
// it has to be a multiple of UECS_CHUNK_ALIGNMENT and an exponent of 2
constexpr size_t CHUNK_SIZE = 16384;
}

6 changes: 4 additions & 2 deletions include/UECS/detail/Chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include <tuple>
#include <vector>

#include "../config.h"

namespace Ubpa::UECS {
using byte = uint8_t;
static_assert(sizeof(byte) == 1);
struct alignas(128) Chunk {
static constexpr size_t size = 16 * 1024;
struct alignas(CHUNK_ALIGNMENT) Chunk {
static constexpr size_t size = CHUNK_SIZE;

struct Layout {
size_t capacity;
Expand Down
8 changes: 8 additions & 0 deletions include/UECS/detail/CmptType.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#pragma once

namespace Ubpa::UECS {
template<typename Cmpt>
constexpr bool CmptType::Is() const noexcept {
static_assert(!IsTaggedCmpt_v<Cmpt>);
return hashcode == TypeID<Cmpt>;
}
}

namespace std {
template<typename T>
struct hash;
Expand Down

0 comments on commit e6cefe7

Please sign in to comment.