Danbias/Code/GamePhysics/Implementation/Octree.h

78 lines
2.2 KiB
C
Raw Normal View History

2013-11-26 10:21:20 +01:00
#ifndef OCTREE_H
#define OCTREE_H
#include <vector>
#include <map>
#include "Sphere.h"
#include "BoxAxisAligned.h"
#include "Utilities.h"
#include "../PhysicsAPI.h"
namespace Oyster
{
namespace Physics
{
class Octree
{
public:
2013-11-28 17:59:12 +01:00
static const unsigned int invalid_ref;
typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int);
2014-01-28 10:18:26 +01:00
typedef void(*VisitorActionCollideable)(ICustomBody*, void*);
2013-11-28 14:18:44 +01:00
2013-11-26 10:21:20 +01:00
struct Data
{
Data* prev;
Data* next;
Collision3D::Sphere container;
2013-11-28 14:18:44 +01:00
::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef;
2013-11-26 10:21:20 +01:00
unsigned int queueRef;
};
struct OctreeNode
{
OctreeNode* children[8];
Data* dataPtr;
Collision3D::BoxAxisAligned container;
2013-11-26 10:21:20 +01:00
};
2013-11-28 14:18:44 +01:00
Octree(unsigned int bufferSize = 0, unsigned char numLayers = 0, Math::Float3 worldSize = Math::Float3::null);
2013-11-26 10:21:20 +01:00
virtual ~Octree();
2013-11-28 14:18:44 +01:00
Octree& operator=(const Octree& orig);
void AddObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
void MoveToUpdateQueue(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
2013-11-26 10:21:20 +01:00
std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& updateList);
void Visit(ICustomBody* customBodyRef, VisitorAction hitAction );
2014-01-28 10:18:26 +01:00
void Visit(const Oyster::Collision3D::ICollideable& collideable, void* args, VisitorActionCollideable hitAction );
2013-11-26 10:21:20 +01:00
2013-11-28 14:18:44 +01:00
ICustomBody* GetCustomBody(const unsigned int tempRef);
2013-11-26 10:21:20 +01:00
2013-11-28 17:59:12 +01:00
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( const ICustomBody* objRef );
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( unsigned int tempRef ); // Dan vill ha
unsigned int GetTemporaryReferenceOf( const ICustomBody* objRef ) const; // Dan vill ha
void SetAsAltered( unsigned int tempRef ); // Dan vill ha
void EvaluatePosition( unsigned int tempRef ); // Dan vill ha
2013-11-26 10:21:20 +01:00
private:
std::vector < Data > leafData;
std::vector < Data* > updateQueue;
2013-11-26 10:21:20 +01:00
2013-11-28 17:59:12 +01:00
std::map< const ICustomBody*, unsigned int > mapReferences;
2013-11-26 10:21:20 +01:00
OctreeNode worldNode;
2013-11-26 10:21:20 +01:00
};
}
}
#endif