mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-09 20:24:16 +00:00
initial implementation
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "Game.h"
|
||||
#include "MessageType/Game.h"
|
||||
#include "MessageType/World.h"
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
#define ENUM_EQ(e, y, z)\
|
||||
LOG("%s %s", StringifiedEnum::ToString(static_cast<e>(y)).data(), #z);\
|
||||
|
@@ -3,7 +3,7 @@ add_executable(dECSTests
|
||||
)
|
||||
|
||||
# Link needed libraries
|
||||
target_link_libraries(dECSTests PRIVATE dCommon dECS GTest::gtest_main)
|
||||
target_link_libraries(dECSTests PRIVATE dCommon dGame dECS GTest::gtest_main)
|
||||
|
||||
# Discover the tests
|
||||
gtest_discover_tests(dECSTests)
|
||||
|
@@ -1,10 +1,67 @@
|
||||
#include <cstdio>
|
||||
#include <gtest/gtest.h>
|
||||
#include "ECS.h"
|
||||
#include "Core.h"
|
||||
#include <dComponents/Component.h>
|
||||
#include <eReplicaComponentType.h>
|
||||
|
||||
TEST(ECSTest, MakeStorage) {
|
||||
const auto storage = Component::Storage<Component::Pet>();
|
||||
const Component::IStorage* const storagePtr = &storage;
|
||||
using namespace dECS;
|
||||
|
||||
ASSERT_EQ(storagePtr->GetKind(), Component::Kind::PET);
|
||||
ASSERT_NE(storagePtr->GetKind(), Component::Kind::DESTROYABLE);
|
||||
struct TestComponent {
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::CHOICE_BUILD;
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
// Test that entity IDs increment correctly
|
||||
TEST(ECSTest, IncrementEntityIdsSingleThread) {
|
||||
auto w = World{};
|
||||
|
||||
auto ea = w.MakeEntity();
|
||||
ASSERT_EQ(ea.Id(), 1);
|
||||
|
||||
auto eb = w.MakeEntity();
|
||||
ASSERT_EQ(eb.Id(), 2);
|
||||
|
||||
auto ec = w.MakeEntity();
|
||||
ASSERT_EQ(ec.Id(), 3);
|
||||
}
|
||||
|
||||
// Test adding and getting components
|
||||
TEST(ECSTest, MakeOneEntityAndAddComponents) {
|
||||
auto w = World{};
|
||||
auto e = w.MakeEntity();
|
||||
ASSERT_EQ(e.Id(), 1);
|
||||
|
||||
// add component
|
||||
auto* const testCompPtr = e.AddComponent<TestComponent>();
|
||||
ASSERT_NE(testCompPtr, nullptr);
|
||||
ASSERT_EQ(testCompPtr->ComponentType, eReplicaComponentType::CHOICE_BUILD);
|
||||
ASSERT_EQ(testCompPtr->value, 0);
|
||||
testCompPtr->value = 15;
|
||||
|
||||
// try getting the same component we just added
|
||||
auto* const getTestCompPtr = e.GetComponent<TestComponent>();
|
||||
ASSERT_NE(getTestCompPtr, nullptr);
|
||||
ASSERT_EQ(testCompPtr, getTestCompPtr);
|
||||
ASSERT_NE(getTestCompPtr->value, 0);
|
||||
ASSERT_EQ(getTestCompPtr->value, 15);
|
||||
}
|
||||
|
||||
// Test world scoping
|
||||
TEST(ECSTest, WorldScope) {
|
||||
auto e = std::optional<dECS::Entity>{};
|
||||
|
||||
{
|
||||
auto w = World{};
|
||||
e.emplace(w.MakeEntity());
|
||||
ASSERT_EQ(e->Id(), 1);
|
||||
|
||||
// add component within scope
|
||||
auto* const cPtr = e->AddComponent<TestComponent>();
|
||||
ASSERT_NE(cPtr, nullptr);
|
||||
}
|
||||
|
||||
// Attempting to access this component now that the world has gone
|
||||
// out of scope should return nullptr
|
||||
ASSERT_EQ(e->GetComponent<TestComponent>(), nullptr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user