File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ struct NullEntity final {
12
12
bool operator ==(const Entity&) const noexcept ;
13
13
bool operator !=(const Entity&) const noexcept ;
14
14
15
+ operator Entity () const noexcept ;
16
+
15
17
private:
16
18
// entity is null when all used bits are 1
17
19
static constexpr EntityUnderlyingType null_entity_id =
Original file line number Diff line number Diff line change 1
1
#pragma once
2
+ #include " nickel/ecs/internal/entity_operations.hpp"
2
3
#include " nickel/ecs/archetype.hpp"
3
4
#include " nickel/ecs/internal/sparse_set.hpp"
4
5
5
6
namespace nickel ::ecs {
6
7
8
+ struct EntitySparseSetPolicy {
9
+ using key_type = Entity;
10
+ using value_type = std::shared_ptr<Record>;
11
+
12
+ size_t GetIndexFromKey (const key_type& key) const noexcept {
13
+ return EntityGetID (key);
14
+ }
15
+
16
+ size_t GetIndexFromValue (const value_type& value) const noexcept {
17
+ return value->m_dense ;
18
+ }
19
+
20
+ Entity GetInvalidKey () const noexcept { return null_entity; }
21
+
22
+ value_type GetInvalidValue () const noexcept { return nullptr ; }
23
+
24
+ void RecordDenseIndex (value_type& value, size_t idx) noexcept {
25
+ value->m_dense = idx;
26
+ }
27
+
28
+ void ReuseKey (key_type& key) noexcept {
29
+ // make next generation key
30
+ }
31
+ };
32
+
7
33
class World {
8
34
public:
9
35
private:
10
36
std::shared_ptr<Table> m_root_table;
11
- // SparseSet<Entity, std::shared_ptr<Record>> m_records;
37
+ SparseSet<Entity, std::shared_ptr<Record>, EntitySparseSetPolicy > m_records;
12
38
};
13
39
14
40
}
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ bool NullEntity::operator!=(const Entity& e) const noexcept {
19
19
return !(*this == e);
20
20
}
21
21
22
+ NullEntity::operator Entity () const noexcept {
23
+ return static_cast <Entity>(null_entity_id);
24
+ }
25
+
22
26
bool operator ==(Entity e, NullEntity n) {
23
27
return n == e;
24
28
}
You can’t perform that action at this time.
0 commit comments