mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-05-24 15:52:32 +00:00
Use std algorithms
This commit is contained in:
parent
2a2799793d
commit
5714ac558e
@ -174,13 +174,11 @@ void Entity::ApplyComponentWhitelist(std::vector<eReplicaComponentType>& compone
|
|||||||
const auto whitelistIndex = GetVar<int32_t>(u"componentWhitelist");
|
const auto whitelistIndex = GetVar<int32_t>(u"componentWhitelist");
|
||||||
if (whitelistIndex < 0 || whitelistIndex >= m_ComponentWhitelists.size()) return;
|
if (whitelistIndex < 0 || whitelistIndex >= m_ComponentWhitelists.size()) return;
|
||||||
|
|
||||||
for (const auto& componentToKeep : m_ComponentWhitelists.at(whitelistIndex)) {
|
const auto& whitelist = m_ComponentWhitelists.at(whitelistIndex);
|
||||||
while (true) {
|
const auto endRange = std::remove_if(components.begin(), components.end(), [&whitelist](const eReplicaComponentType& componentCandidate) {
|
||||||
const auto componentIter = std::find(components.begin(), components.end(), componentToKeep);
|
return std::find(whitelist.begin(), whitelist.end(), componentCandidate) == whitelist.end();
|
||||||
if (componentIter == components.end()) break;
|
});
|
||||||
components.erase(componentIter);
|
components.erase(endRange, components.end());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::Initialize() {
|
void Entity::Initialize() {
|
||||||
|
@ -21,19 +21,20 @@ protected:
|
|||||||
this->TearDownDependencies();
|
this->TearDownDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunWhitelistTest(const int32_t componentIndex, std::vector<eReplicaComponentType>& whitelist) {
|
void RunWhitelistTest(const int32_t whitelistIndex, std::vector<eReplicaComponentType> componentList) {
|
||||||
entity->SetVar<int32_t>(u"componentWhitelist", componentIndex);
|
Game::logger->Log("EntityTests", "whitelist test %i", whitelistIndex);
|
||||||
entity->ApplyComponentWhitelist(whitelist);
|
entity->SetVar<int32_t>(u"componentWhitelist", whitelistIndex);
|
||||||
const auto whitelists = Entity::GetComponentWhitelists();
|
entity->ApplyComponentWhitelist(componentList);
|
||||||
for (const auto& component : whitelists.at(componentIndex)) {
|
const auto whitelist = Entity::GetComponentWhitelists().at(whitelistIndex);
|
||||||
EXPECT_FALSE(std::find(whitelist.begin(), whitelist.end(), component) != whitelist.end());
|
std::for_each(whitelist.begin(), whitelist.end(), [&componentList](const eReplicaComponentType& keptComponent) {
|
||||||
}
|
EXPECT_EQ(std::count(componentList.begin(), componentList.end(), keptComponent), 2);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(EntityTests, WhitelistTest) {
|
TEST_F(EntityTests, WhitelistTest) {
|
||||||
const auto whitelists = Entity::GetComponentWhitelists();
|
const auto whitelists = Entity::GetComponentWhitelists();
|
||||||
std::vector<eReplicaComponentType> whitelist = {
|
std::vector<eReplicaComponentType> components = {
|
||||||
eReplicaComponentType::CONTROLLABLE_PHYSICS,
|
eReplicaComponentType::CONTROLLABLE_PHYSICS,
|
||||||
eReplicaComponentType::SIMPLE_PHYSICS,
|
eReplicaComponentType::SIMPLE_PHYSICS,
|
||||||
eReplicaComponentType::MODEL_BEHAVIOR,
|
eReplicaComponentType::MODEL_BEHAVIOR,
|
||||||
@ -55,9 +56,9 @@ TEST_F(EntityTests, WhitelistTest) {
|
|||||||
eReplicaComponentType::SKILL,
|
eReplicaComponentType::SKILL,
|
||||||
eReplicaComponentType::DESTROYABLE,
|
eReplicaComponentType::DESTROYABLE,
|
||||||
};
|
};
|
||||||
RunWhitelistTest(0, whitelist);
|
RunWhitelistTest(0, components);
|
||||||
RunWhitelistTest(1, whitelist);
|
RunWhitelistTest(1, components);
|
||||||
RunWhitelistTest(2, whitelist);
|
RunWhitelistTest(2, components);
|
||||||
RunWhitelistTest(3, whitelist);
|
RunWhitelistTest(3, components);
|
||||||
RunWhitelistTest(4, whitelist);
|
RunWhitelistTest(4, components);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user