Last active
December 18, 2015 05:49
-
-
Save Shaptic/5735961 to your computer and use it in GitHub Desktop.
Testing IronClad quad tree insertion of 1000000 objects and collision with one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/timeb.h> | |
#include "IronClad.hpp" | |
using namespace ic; | |
// For tracking time. | |
uint32_t now() | |
{ | |
timeb t; | |
ftime(&t); | |
return t.time * 1000 + t.millitm; | |
} | |
// Inserts BIG_NUM objects and tests collision with one. | |
int test() | |
{ | |
const unsigned int BIG_NUM = 1000000; | |
std::cout << "Pre-test: Creating " << BIG_NUM + 1 << " entities.\n"; | |
std::vector<obj::CRigidBody*> pObjs; | |
pObjs.resize(BIG_NUM); | |
for(size_t i = 0; i < BIG_NUM; ++i) | |
{ | |
obj::CRigidBody* pObj = new obj::CRigidBody; | |
pObj->m_CollisionBox = math::rect_t(0, 0, 32, 32); | |
pObj->Move(rand() % 800, rand() % 600); | |
pObjs.push_back(pObj); | |
} | |
obj::CRigidBody* pCollider = new obj::CRigidBody; | |
pCollider->m_CollisionBox = math::rect_t(0, 0, 32, 32); | |
pCollider->Move(rand() % 600, rand() % 800); | |
std::cout << "Testing single collision against " << BIG_NUM << " objects.\n"; | |
uint32_t start = now(); | |
CQuadTree Tree(800, 600); | |
auto i = pObjs.begin(), j = pObjs.end(); | |
for( ; i != j; ++i) | |
{ | |
Tree.Insert(*i); | |
} | |
Tree.Collides(pCollider); | |
uint32_t final = now() - start; | |
std::cout << final << "ms." << std::endl; | |
return final; | |
} | |
// Runs test 10 times and computes avg. | |
int main() | |
{ | |
Init(); | |
uint64_t total = 0; | |
for(size_t i = 0; i < 10; ++i) | |
total += test(); | |
std::cout << "Average over 10 runs: " << (total / 10.0) << "ms.\n"; | |
Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment