updated registry/sparse_set
This commit is contained in:
@@ -228,10 +228,22 @@ public:
|
||||
Registry & operator=(const Registry &) = delete;
|
||||
Registry & operator=(Registry &&) = delete;
|
||||
|
||||
template<typename Comp>
|
||||
size_type size() const noexcept {
|
||||
constexpr auto index = ident<Component...>.template get<Comp>();
|
||||
return std::get<index>(pool).size();
|
||||
}
|
||||
|
||||
size_type size() const noexcept {
|
||||
return entities.size() - available.size();
|
||||
}
|
||||
|
||||
template<typename Comp>
|
||||
size_type capacity() const noexcept {
|
||||
constexpr auto index = ident<Component...>.template get<Comp>();
|
||||
return std::get<index>(pool).capacity();
|
||||
}
|
||||
|
||||
size_type capacity() const noexcept {
|
||||
return entities.size();
|
||||
}
|
||||
|
||||
@@ -78,6 +78,14 @@ public:
|
||||
SparseSet & operator=(const SparseSet &) = delete;
|
||||
SparseSet & operator=(SparseSet &&) = default;
|
||||
|
||||
size_type size() const noexcept {
|
||||
return direct.size();
|
||||
}
|
||||
|
||||
size_t capacity() const noexcept {
|
||||
return direct.capacity();
|
||||
}
|
||||
|
||||
bool empty() const noexcept {
|
||||
return direct.empty();
|
||||
}
|
||||
@@ -86,10 +94,6 @@ public:
|
||||
return direct.data();
|
||||
}
|
||||
|
||||
size_type size() const noexcept {
|
||||
return direct.size();
|
||||
}
|
||||
|
||||
iterator_type begin() const noexcept {
|
||||
return SparseSetIterator{&direct, direct.size()};
|
||||
}
|
||||
@@ -143,7 +147,7 @@ public:
|
||||
}
|
||||
|
||||
void reset() {
|
||||
reverse.resize(0);
|
||||
reverse.clear();
|
||||
direct.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,20 @@ TEST(DefaultRegistry, Functionalities) {
|
||||
ASSERT_EQ(registry.capacity(), registry_type::size_type{0});
|
||||
ASSERT_TRUE(registry.empty());
|
||||
|
||||
ASSERT_EQ(registry.size<int>(), registry_type::size_type{0});
|
||||
ASSERT_EQ(registry.size<char>(), registry_type::size_type{0});
|
||||
ASSERT_EQ(registry.capacity<int>(), registry_type::size_type{0});
|
||||
ASSERT_EQ(registry.capacity<char>(), registry_type::size_type{0});
|
||||
ASSERT_TRUE(registry.empty<int>());
|
||||
ASSERT_TRUE(registry.empty<char>());
|
||||
|
||||
registry_type::entity_type e1 = registry.create();
|
||||
registry_type::entity_type e2 = registry.create<int, char>();
|
||||
|
||||
ASSERT_EQ(registry.size<int>(), registry_type::size_type{1});
|
||||
ASSERT_EQ(registry.size<char>(), registry_type::size_type{1});
|
||||
ASSERT_GE(registry.capacity<int>(), registry_type::size_type{1});
|
||||
ASSERT_GE(registry.capacity<char>(), registry_type::size_type{1});
|
||||
ASSERT_FALSE(registry.empty<int>());
|
||||
ASSERT_FALSE(registry.empty<char>());
|
||||
|
||||
@@ -96,16 +104,28 @@ TEST(DefaultRegistry, Functionalities) {
|
||||
|
||||
registry.create<int, char>();
|
||||
|
||||
ASSERT_EQ(registry.size<int>(), registry_type::size_type{1});
|
||||
ASSERT_EQ(registry.size<char>(), registry_type::size_type{1});
|
||||
ASSERT_GE(registry.capacity<int>(), registry_type::size_type{1});
|
||||
ASSERT_GE(registry.capacity<char>(), registry_type::size_type{1});
|
||||
ASSERT_FALSE(registry.empty<int>());
|
||||
ASSERT_FALSE(registry.empty<char>());
|
||||
|
||||
ASSERT_NO_THROW(registry.reset<int>());
|
||||
|
||||
ASSERT_EQ(registry.size<int>(), registry_type::size_type{0});
|
||||
ASSERT_EQ(registry.size<char>(), registry_type::size_type{1});
|
||||
ASSERT_GE(registry.capacity<int>(), registry_type::size_type{0});
|
||||
ASSERT_GE(registry.capacity<char>(), registry_type::size_type{1});
|
||||
ASSERT_TRUE(registry.empty<int>());
|
||||
ASSERT_FALSE(registry.empty<char>());
|
||||
|
||||
ASSERT_NO_THROW(registry.reset());
|
||||
|
||||
ASSERT_EQ(registry.size<int>(), registry_type::size_type{0});
|
||||
ASSERT_EQ(registry.size<char>(), registry_type::size_type{0});
|
||||
ASSERT_GE(registry.capacity<int>(), registry_type::size_type{0});
|
||||
ASSERT_GE(registry.capacity<char>(), registry_type::size_type{1});
|
||||
ASSERT_TRUE(registry.empty<int>());
|
||||
ASSERT_TRUE(registry.empty<char>());
|
||||
|
||||
@@ -114,6 +134,11 @@ TEST(DefaultRegistry, Functionalities) {
|
||||
|
||||
ASSERT_NO_THROW(registry.reset<int>(e1));
|
||||
ASSERT_NO_THROW(registry.reset<int>(e2));
|
||||
|
||||
ASSERT_EQ(registry.size<int>(), registry_type::size_type{0});
|
||||
ASSERT_EQ(registry.size<char>(), registry_type::size_type{0});
|
||||
ASSERT_GE(registry.capacity<int>(), registry_type::size_type{0});
|
||||
ASSERT_GE(registry.capacity<char>(), registry_type::size_type{0});
|
||||
ASSERT_TRUE(registry.empty<int>());
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ TEST(SparseSetNoType, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
ASSERT_EQ(set.capacity(), 0u);
|
||||
ASSERT_EQ(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_FALSE(set.has(42));
|
||||
@@ -16,6 +17,7 @@ TEST(SparseSetNoType, Functionalities) {
|
||||
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(set.size(), 1u);
|
||||
ASSERT_GE(set.capacity(), 1u);
|
||||
ASSERT_NE(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_TRUE(set.has(42));
|
||||
@@ -25,6 +27,7 @@ TEST(SparseSetNoType, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
ASSERT_GE(set.capacity(), 1u);
|
||||
ASSERT_EQ(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_FALSE(set.has(42));
|
||||
@@ -35,6 +38,7 @@ TEST(SparseSetNoType, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
ASSERT_GE(set.capacity(), 0u);
|
||||
ASSERT_EQ(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_FALSE(set.has(42));
|
||||
@@ -90,6 +94,7 @@ TEST(SparseSetWithType, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
ASSERT_EQ(set.capacity(), 0u);
|
||||
ASSERT_EQ(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_FALSE(set.has(42));
|
||||
@@ -98,6 +103,7 @@ TEST(SparseSetWithType, Functionalities) {
|
||||
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(set.size(), 1u);
|
||||
ASSERT_GE(set.capacity(), 1u);
|
||||
ASSERT_NE(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_TRUE(set.has(42));
|
||||
@@ -107,6 +113,7 @@ TEST(SparseSetWithType, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
ASSERT_GE(set.capacity(), 1u);
|
||||
ASSERT_EQ(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_FALSE(set.has(42));
|
||||
@@ -117,6 +124,7 @@ TEST(SparseSetWithType, Functionalities) {
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
ASSERT_EQ(set.size(), 0u);
|
||||
ASSERT_GE(set.capacity(), 0u);
|
||||
ASSERT_EQ(set.begin(), set.end());
|
||||
ASSERT_FALSE(set.has(0));
|
||||
ASSERT_FALSE(set.has(42));
|
||||
|
||||
Reference in New Issue
Block a user