Minor fixes/changes
This commit is contained in:
parent
c3f90ec6b0
commit
635eed34a4
3 changed files with 58 additions and 2 deletions
|
@ -16,12 +16,24 @@ namespace EC
|
||||||
{
|
{
|
||||||
using Combined = EC::Meta::Combine<ComponentsList, TagsList>;
|
using Combined = EC::Meta::Combine<ComponentsList, TagsList>;
|
||||||
|
|
||||||
|
template <typename Component>
|
||||||
|
constexpr auto getComponentBit() const
|
||||||
|
{
|
||||||
|
return (*this)[EC::Meta::IndexOf<Component, Combined>::value];
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
constexpr auto getComponentBit()
|
constexpr auto getComponentBit()
|
||||||
{
|
{
|
||||||
return (*this)[EC::Meta::IndexOf<Component, Combined>::value];
|
return (*this)[EC::Meta::IndexOf<Component, Combined>::value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Tag>
|
||||||
|
constexpr auto getTagBit() const
|
||||||
|
{
|
||||||
|
return (*this)[EC::Meta::IndexOf<Tag, Combined>::value];
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template <typename Tag>
|
||||||
constexpr auto getTagBit()
|
constexpr auto getTagBit()
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,18 +98,48 @@ namespace EC
|
||||||
return std::get<std::vector<Component> >(componentsStorage).at(std::get<std::size_t>(entities.at(index)));
|
return std::get<std::vector<Component> >(componentsStorage).at(std::get<std::size_t>(entities.at(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Component>
|
||||||
|
bool hasComponent(std::size_t index) const
|
||||||
|
{
|
||||||
|
return std::get<BitsetType>(entities.at(index)).template getComponentBit<Component>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Tag>
|
||||||
|
bool hasTag(std::size_t index) const
|
||||||
|
{
|
||||||
|
return std::get<BitsetType>(entities.at(index)).template getTagBit<Tag>();
|
||||||
|
}
|
||||||
|
|
||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
|
if(currentSize == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t rhs = currentSize - 1;
|
std::size_t rhs = currentSize - 1;
|
||||||
std::size_t lhs = 0;
|
std::size_t lhs = 0;
|
||||||
|
|
||||||
while(lhs < rhs)
|
while(lhs < rhs)
|
||||||
{
|
{
|
||||||
if(!std::get<bool>(entities[lhs]))
|
while(!std::get<bool>(entities[rhs]))
|
||||||
|
{
|
||||||
|
--rhs;
|
||||||
|
if(rhs == 0)
|
||||||
|
{
|
||||||
|
currentSize = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(lhs >= rhs)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(!std::get<bool>(entities[lhs]))
|
||||||
{
|
{
|
||||||
// lhs is marked for deletion
|
// lhs is marked for deletion
|
||||||
// swap lhs entity with rhs entity
|
// swap lhs entity with rhs entity
|
||||||
std::swap(entities[lhs], entities[rhs]);
|
std::swap(entities[lhs], entities.at(rhs));
|
||||||
|
|
||||||
// clear deleted bitset
|
// clear deleted bitset
|
||||||
std::get<BitsetType>(entities[rhs]).reset();
|
std::get<BitsetType>(entities[rhs]).reset();
|
||||||
|
|
|
@ -99,6 +99,16 @@ TEST(EC, Manager)
|
||||||
EXPECT_EQ(pos.y, 7);
|
EXPECT_EQ(pos.y, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
bool has = manager.hasComponent<C0>(e1);
|
||||||
|
|
||||||
|
EXPECT_TRUE(has);
|
||||||
|
|
||||||
|
has = manager.hasTag<T0>(e1);
|
||||||
|
|
||||||
|
EXPECT_TRUE(has);
|
||||||
|
}
|
||||||
|
|
||||||
manager.deleteEntity(e0);
|
manager.deleteEntity(e0);
|
||||||
manager.cleanup();
|
manager.cleanup();
|
||||||
|
|
||||||
|
@ -119,5 +129,9 @@ TEST(EC, Manager)
|
||||||
manager.forMatchingSignature<EC::Meta::TypeList<T0> >(updateTagOnly);
|
manager.forMatchingSignature<EC::Meta::TypeList<T0> >(updateTagOnly);
|
||||||
|
|
||||||
EXPECT_EQ(2, count);
|
EXPECT_EQ(2, count);
|
||||||
|
|
||||||
|
manager.deleteEntity(e1);
|
||||||
|
manager.deleteEntity(e2);
|
||||||
|
manager.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue