Merge branch 'OctTree' of github.com:teamfisk/TacticalZ into OctTree
# Conflicts: # src/Engine/Core/OctTree.cpp
This commit is contained in:
@@ -92,11 +92,12 @@ BOOST_AUTO_TEST_CASE(octTest)
|
||||
glm::vec3 mini = glm::vec3(-1, -1, -1);
|
||||
glm::vec3 maxi = glm::vec3(1, 1, 1);
|
||||
OctTree tree(AABB(mini, maxi), 2);
|
||||
tree.AddBox(AABB(mini, 0.1f*maxi));
|
||||
tree.AddBox(AABB(mini, -0.9f*maxi));
|
||||
OctTree::Output data;
|
||||
BOOST_CHECK(tree.RayCollides({ glm::vec3(0, 0, 0), glm::normalize(mini) }, data));
|
||||
glm::vec3 origin = 3.0f * mini;
|
||||
BOOST_CHECK(tree.RayCollides({origin , glm::normalize(mini - origin) }, data));
|
||||
tree.ClearBoxes();
|
||||
BOOST_CHECK(!tree.RayCollides({ glm::vec3(0, 0, 0), glm::normalize(mini) }, data));
|
||||
BOOST_CHECK(!tree.RayCollides({ origin , glm::normalize(mini - origin) }, data));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "Core/ComponentPool.h"
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ComponentPoolTest)
|
||||
{
|
||||
// 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);
|
||||
|
||||
//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++;
|
||||
//}
|
||||
|
||||
//pool.Delete(wrappers[1]);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
namespace utf = boost::unit_test;
|
||||
|
||||
#include "Common.h"
|
||||
#include "GLM.h"
|
||||
#include "Core/World.h"
|
||||
|
||||
BOOST_AUTO_TEST_CASE(WorldTestSingleAllocation, * boost::unit_test::tolerance(0.001))
|
||||
{
|
||||
World w;
|
||||
|
||||
auto f = ComponentWrapperFactory("Test");
|
||||
f.AddProperty("TestInteger", 1337);
|
||||
f.AddProperty("TestDouble", 13.37);
|
||||
f.AddProperty("TestString", std::string("Carlito"));
|
||||
f.AddProperty("TestVec3", glm::vec3(1.f, 2.f, 3.f));
|
||||
w.RegisterComponent(f);
|
||||
|
||||
EntityID e = w.CreateEntity();
|
||||
ComponentWrapper c = w.AttachComponent(e, "Test");
|
||||
|
||||
// Check default values
|
||||
BOOST_TEST((int)c["TestInteger"] == c.Property<int>("TestInteger"));
|
||||
BOOST_TEST((int)c["TestInteger"] == 1337);
|
||||
BOOST_TEST((double)c["TestDouble"] == 13.37);
|
||||
BOOST_TEST((std::string)c["TestString"] == "Carlito");
|
||||
glm::vec3 vec3 = c["TestVec3"];
|
||||
BOOST_TEST(vec3.x == 1.f);
|
||||
BOOST_TEST(vec3.y == 2.f);
|
||||
BOOST_TEST(vec3.z == 3.f);
|
||||
|
||||
// Change values
|
||||
((int&)c["TestInteger"]) += 1;
|
||||
BOOST_TEST((int)c["TestInteger"] == 1338);
|
||||
((double&)c["TestDouble"]) += 1.11;
|
||||
std::cout << (double)c["TestDouble"] << std::endl;
|
||||
BOOST_TEST((double)c["TestDouble"] == 14.48);
|
||||
c["TestString"] = "Siesta";
|
||||
BOOST_TEST((std::string)c["TestString"] == "Siesta");
|
||||
((glm::vec3&)c["TestVec3"]).y += 1.f;
|
||||
BOOST_TEST(((glm::vec3)c["TestVec3"]).y == 3.f);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(WorldTestMultipleAllocations, * utf::tolerance(0.00001))
|
||||
{
|
||||
World w;
|
||||
|
||||
// Create allocation for 3 entities
|
||||
auto f = ComponentWrapperFactory("Test", 3);
|
||||
f.AddProperty("TestInteger", 1337);
|
||||
f.AddProperty("TestDouble", 13.37);
|
||||
f.AddProperty("TestString", std::string("Carlito"));
|
||||
f.AddProperty("TestVec3", glm::vec3(1.f, 2.f, 3.f));
|
||||
w.RegisterComponent(f);
|
||||
|
||||
// Create 6 entities with Test components
|
||||
// 3 will reside in contiguous memory
|
||||
// 3 will be allocated dynamically
|
||||
for (int i = 0; i < 6; i++) {
|
||||
EntityID e = w.CreateEntity();
|
||||
ComponentWrapper c = w.AttachComponent(e, "Test");
|
||||
c["TestInteger"] = i;
|
||||
}
|
||||
|
||||
// Loop through them and check data
|
||||
int i = 0;
|
||||
for (auto& c : w.GetComponents("Test")) {
|
||||
BOOST_TEST((int)c["TestInteger"] == i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user