Skip to content

Commit 7e1bc12

Browse files
author
mingqian.gui
committed
update
1 parent 674cc25 commit 7e1bc12

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

engine/engine/nickel/ecs/entity.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct NullEntity final {
1212
bool operator==(const Entity&) const noexcept;
1313
bool operator!=(const Entity&) const noexcept;
1414

15+
operator Entity() const noexcept;
16+
1517
private:
1618
// entity is null when all used bits are 1
1719
static constexpr EntityUnderlyingType null_entity_id =

engine/engine/nickel/ecs/world.hpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
#pragma once
2+
#include "nickel/ecs/internal/entity_operations.hpp"
23
#include "nickel/ecs/archetype.hpp"
34
#include "nickel/ecs/internal/sparse_set.hpp"
45

56
namespace nickel::ecs {
67

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+
733
class World {
834
public:
935
private:
1036
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;
1238
};
1339

1440
}

engine/engine/src/ecs/entity.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ bool NullEntity::operator!=(const Entity& e) const noexcept {
1919
return !(*this == e);
2020
}
2121

22+
NullEntity::operator Entity() const noexcept {
23+
return static_cast<Entity>(null_entity_id);
24+
}
25+
2226
bool operator==(Entity e, NullEntity n) {
2327
return n == e;
2428
}

0 commit comments

Comments
 (0)