mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-05-23 15:22:28 +00:00
Add test for component Whitelists
This commit is contained in:
parent
a68fa69e7a
commit
1c23f3c030
@ -89,6 +89,41 @@
|
|||||||
#include "CDSkillBehaviorTable.h"
|
#include "CDSkillBehaviorTable.h"
|
||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
|
|
||||||
|
const std::vector<ComponentWhitelist> Entity::m_ComponentWhitelists = {
|
||||||
|
{ // Unknown use case
|
||||||
|
eReplicaComponentType::CONTROLLABLE_PHYSICS,
|
||||||
|
eReplicaComponentType::SIMPLE_PHYSICS,
|
||||||
|
eReplicaComponentType::RENDER
|
||||||
|
},
|
||||||
|
{ // Used for BBB
|
||||||
|
eReplicaComponentType::RENDER,
|
||||||
|
eReplicaComponentType::DESTROYABLE,
|
||||||
|
eReplicaComponentType::ITEM,
|
||||||
|
eReplicaComponentType::BLUEPRINT,
|
||||||
|
eReplicaComponentType::MODEL_BEHAVIOR,
|
||||||
|
eReplicaComponentType::CONTROLLABLE_PHYSICS,
|
||||||
|
eReplicaComponentType::SIMPLE_PHYSICS,
|
||||||
|
eReplicaComponentType::SPAWN
|
||||||
|
},
|
||||||
|
{ // Unknown use case
|
||||||
|
eReplicaComponentType::RENDER,
|
||||||
|
eReplicaComponentType::ITEM,
|
||||||
|
eReplicaComponentType::BLUEPRINT,
|
||||||
|
},
|
||||||
|
{ // Used for Pets
|
||||||
|
eReplicaComponentType::PET,
|
||||||
|
eReplicaComponentType::SKILL,
|
||||||
|
eReplicaComponentType::DESTROYABLE,
|
||||||
|
eReplicaComponentType::RENDER,
|
||||||
|
eReplicaComponentType::CONTROLLABLE_PHYSICS
|
||||||
|
},
|
||||||
|
{ // Unknown use case
|
||||||
|
eReplicaComponentType::CONTROLLABLE_PHYSICS,
|
||||||
|
eReplicaComponentType::SIMPLE_PHYSICS,
|
||||||
|
eReplicaComponentType::RENDER,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) {
|
Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) {
|
||||||
m_ObjectID = objectID;
|
m_ObjectID = objectID;
|
||||||
m_TemplateID = info.lot;
|
m_TemplateID = info.lot;
|
||||||
@ -135,6 +170,16 @@ Entity::~Entity() {
|
|||||||
if (m_ParentEntity) m_ParentEntity->RemoveChild(this);
|
if (m_ParentEntity) m_ParentEntity->RemoveChild(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Entity::ApplyComponentWhitelist(std::vector<eReplicaComponentType>& components) {
|
||||||
|
const auto whitelistIndex = GetVar<int32_t>(u"componentWhitelist");
|
||||||
|
if (whitelistIndex < 0 || whitelistIndex >= m_ComponentWhitelists.size()) return;
|
||||||
|
|
||||||
|
for (const auto& componentToKeep : m_ComponentWhitelists.at(whitelistIndex)) {
|
||||||
|
const auto componentIter = std::find(components.begin(), components.end(), componentToKeep);
|
||||||
|
if (componentIter != components.end()) components.erase(componentIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Entity::Initialize() {
|
void Entity::Initialize() {
|
||||||
// A few edge cases to tackle first
|
// A few edge cases to tackle first
|
||||||
const auto triggerInfo = GetVarAsString(u"trigger_id");
|
const auto triggerInfo = GetVarAsString(u"trigger_id");
|
||||||
|
@ -49,12 +49,15 @@ namespace CppScripts {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using ComponentPtr = std::unique_ptr<Component>;
|
using ComponentPtr = std::unique_ptr<Component>;
|
||||||
|
using ComponentWhitelist = std::vector<eReplicaComponentType>;
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr);
|
explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr);
|
||||||
virtual ~Entity();
|
virtual ~Entity();
|
||||||
|
|
||||||
|
void ApplyComponentWhitelist(std::vector<eReplicaComponentType>& components);
|
||||||
|
static const std::vector<ComponentWhitelist>& GetComponentWhitelists() { return m_ComponentWhitelists; }
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
|
|
||||||
bool operator==(const Entity& other) const;
|
bool operator==(const Entity& other) const;
|
||||||
@ -342,6 +345,8 @@ protected:
|
|||||||
* Collision
|
* Collision
|
||||||
*/
|
*/
|
||||||
std::vector<LWOOBJID> m_TargetsInPhantom;
|
std::vector<LWOOBJID> m_TargetsInPhantom;
|
||||||
|
|
||||||
|
static const std::vector<ComponentWhitelist> m_ComponentWhitelists;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "Entity.tcc"
|
#include "Entity.tcc"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
set(DGAMETEST_SOURCES
|
set(DGAMETEST_SOURCES
|
||||||
"GameDependencies.cpp"
|
"GameDependencies.cpp"
|
||||||
|
"EntityTests.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(dComponentsTests)
|
add_subdirectory(dComponentsTests)
|
||||||
|
49
tests/dGameTests/EntityTests.cpp
Normal file
49
tests/dGameTests/EntityTests.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "GameDependencies.h"
|
||||||
|
#include "dCommonVars.h"
|
||||||
|
#include "eReplicaComponentType.h"
|
||||||
|
|
||||||
|
class EntityTests : public GameDependenciesTest {
|
||||||
|
protected:
|
||||||
|
std::unique_ptr<Entity> entity;
|
||||||
|
|
||||||
|
virtual void SetUp() {
|
||||||
|
entity = std::move(std::make_unique<Entity>(LWOOBJID_EMPTY, EntityInfo()));
|
||||||
|
this->SetUpDependencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void TearDown() {
|
||||||
|
this->TearDownDependencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunWhitelistTest(const int32_t componentIndex, std::vector<eReplicaComponentType>& whitelist) {
|
||||||
|
entity->SetVar<int32_t>(u"componentWhitelist", componentIndex);
|
||||||
|
entity->ApplyComponentWhitelist(whitelist);
|
||||||
|
const auto whitelists = Entity::GetComponentWhitelists();
|
||||||
|
for (const auto& component : whitelists.at(componentIndex)) {
|
||||||
|
EXPECT_FALSE(std::find(whitelist.begin(), whitelist.end(), component) != whitelist.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(EntityTests, WhitelistTest) {
|
||||||
|
const auto whitelists = Entity::GetComponentWhitelists();
|
||||||
|
std::vector<eReplicaComponentType> whitelist = {
|
||||||
|
eReplicaComponentType::RACING_STATS,
|
||||||
|
eReplicaComponentType::SIMPLE_PHYSICS,
|
||||||
|
eReplicaComponentType::CONTROLLABLE_PHYSICS,
|
||||||
|
eReplicaComponentType::RENDER,
|
||||||
|
eReplicaComponentType::DESTROYABLE,
|
||||||
|
eReplicaComponentType::RACING_CONTROL
|
||||||
|
};
|
||||||
|
RunWhitelistTest(0, whitelist);
|
||||||
|
RunWhitelistTest(1, whitelist);
|
||||||
|
RunWhitelistTest(2, whitelist);
|
||||||
|
RunWhitelistTest(3, whitelist);
|
||||||
|
RunWhitelistTest(4, whitelist);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user