Basic and working entity system with a really ugly test case
This commit is contained in:
@@ -4,25 +4,31 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ComponentPoolTest)
|
||||
{
|
||||
ComponentInfo ci;
|
||||
ci.Name = "Test";
|
||||
ci.FieldTypes["Field"] = "int";
|
||||
ci.FieldOffsets["Field"] = sizeof(EntityID);
|
||||
ci.Meta.Allocation = 4;
|
||||
ci.Meta.Stride = sizeof(EntityID) + sizeof(int);
|
||||
// TODO: Write an updated test for component pool
|
||||
BOOST_CHECK(false);
|
||||
//ComponentInfo ci;
|
||||
//ci.Name = "Test";
|
||||
//ci.FieldTypes["Field"] = "int";
|
||||
//ci.FieldOffsets["Field"] = 0;
|
||||
//ci.Meta.Allocation = 3;
|
||||
//ci.Meta.Stride = sizeof(EntityID) + sizeof(int);
|
||||
|
||||
ComponentPool pool(ci);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ComponentWrapper c = pool.New();
|
||||
c.EntityID = i;
|
||||
unsigned int offset = c.Info.FieldOffsets.at("Field");
|
||||
memcpy(&c.Data[offset], &i, sizeof(int));
|
||||
}
|
||||
//std::vector<ComponentWrapper> wrappers;
|
||||
//ComponentPool pool(ci);
|
||||
//for (int i = 0; i < 4; i++) {
|
||||
// ComponentWrapper c = pool.New();
|
||||
// c.EntityID = i;
|
||||
// unsigned int offset = c.Info.FieldOffsets.at("Field");
|
||||
// memcpy(&c.Data[offset], &i, sizeof(int));
|
||||
// wrappers.push_back(c);
|
||||
//}
|
||||
|
||||
int i = 0;
|
||||
for (auto& c : pool) {
|
||||
BOOST_CHECK(c.EntityID == i);
|
||||
BOOST_CHECK((int)c["Field"] == i);
|
||||
i++;
|
||||
}
|
||||
//int i = 0;
|
||||
//for (auto& c : pool) {
|
||||
// BOOST_CHECK(c.EntityID == i);
|
||||
// BOOST_CHECK((int)c["Field"] == i);
|
||||
// i++;
|
||||
//}
|
||||
|
||||
//pool.Delete(wrappers[1]);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/World.h"
|
||||
|
||||
BOOST_AUTO_TEST_CASE(WorldTest)
|
||||
{
|
||||
ComponentInfo ci;
|
||||
ci.Name = "Test";
|
||||
ci.FieldTypes["Field"] = "int";
|
||||
ci.FieldOffsets["Field"] = 0;
|
||||
ci.Meta.Stride = sizeof(int);
|
||||
ci.Meta.Allocation = 3;
|
||||
|
||||
ci.Defaults = std::shared_ptr<char>(new char[ci.Meta.Stride]);
|
||||
int default_Field = 1337;
|
||||
memcpy(ci.Defaults.get(), &default_Field, ci.Meta.Stride);
|
||||
|
||||
World w;
|
||||
w.RegisterComponent(ci);
|
||||
|
||||
std::vector<EntityID> ids;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
EntityID e = w.CreateEntity();
|
||||
ids.push_back(e);
|
||||
w.AttachComponent(e, "Test");
|
||||
ComponentWrapper c = w.GetComponent(e, "Test");
|
||||
BOOST_CHECK(c.EntityID == e);
|
||||
BOOST_CHECK((int)c["Field"] == 1337);
|
||||
c.SetProperty("Field", i);
|
||||
BOOST_CHECK((int)c["Field"] == i);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (auto& c : w.GetComponents("Test")) {
|
||||
EntityID e = ids.at(i);
|
||||
BOOST_CHECK(c.EntityID == e);
|
||||
BOOST_CHECK((int)c["Field"] == i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user