From c31ea9730b9d989cc71a434e12eb4a56f6fa36cc Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 29 Nov 2013 09:03:37 +0100 Subject: [PATCH] Added overloads for visitor and sample functions They now have an overload for accepting ICollideable --- Code/GamePhysics/Implementation/Octree.cpp | 34 ++++++++++++++++++---- Code/GamePhysics/Implementation/Octree.h | 4 ++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index baa431da..70d2842a 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -72,15 +72,13 @@ void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef) this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef); } -std::vector Octree::Sample(ICustomBody* customBodyRef) +std::vector& Octree::Sample(ICustomBody* customBodyRef, std::vector& updateList) { - std::vector list; - auto object = this->mapReferences.find(customBodyRef); if(object == this->mapReferences.end()) { - return list; + return updateList; } unsigned int tempRef = object->second; @@ -89,11 +87,24 @@ std::vector Octree::Sample(ICustomBody* customBodyRef) { if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) { - list.push_back(this->leafData[i].customBodyRef); + updateList.push_back(this->leafData[i].customBodyRef); } } - return list; + return updateList; +} + +std::vector& Octree::Sample(::Collision3D::ICollideable* collideable, std::vector& updateList) +{ + for(unsigned int i = 0; ileafData.size(); i++) + { + if(this->leafData[i].container.Intersects(*collideable)) + { + updateList.push_back(this->leafData[i].customBodyRef); + } + } + + return updateList; } void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) @@ -116,6 +127,17 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) } } +void Octree::Visit(::Collision3D::ICollideable* collideable, VistorAction hitAction) +{ + for(unsigned int i = 0; ileafData.size(); i++) + { + if(this->leafData[i].container.Intersects(*collideable)) + { + //hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable + } + } +} + ICustomBody* Octree::GetCustomBody(const unsigned int tempRef) { return this->leafData[tempRef].customBodyRef; diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 5ef3b0a8..6340fa58 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -49,8 +49,10 @@ namespace Oyster void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); - std::vector Sample(ICustomBody* customBodyRef); + std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList); + std::vector& Sample(Oyster::Collision3D::ICollideable* collideable, std::vector& updateList); void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); + void Visit(Oyster::Collision3D::ICollideable* collideable, VistorAction hitAction ); ICustomBody* GetCustomBody(const unsigned int tempRef);