From 8c229d88a8e30f5a9d0815d7aa3811b4ec5463a7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 19 Oct 2015 11:59:44 -0700 Subject: [PATCH] moving whitelist code out of octree --- libraries/entities/src/EntityTree.cpp | 46 +++++++++++++++++++++++++++ libraries/entities/src/EntityTree.h | 8 +++++ libraries/octree/src/Octree.cpp | 24 +------------- libraries/octree/src/Octree.h | 2 +- 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 6e487cbfe3..d40e4e6e96 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -448,6 +448,52 @@ bool EntityTree::findNearPointOperation(OctreeElementPointer element, void* extr // if this element doesn't contain the point, then none of its children can contain the point, so stop searching return false; } +// combines the ray cast arguments into a single object +class RayArgs { +public: + glm::vec3 origin; + glm::vec3 direction; + OctreeElementPointer& element; + float& distance; + BoxFace& face; + glm::vec3& surfaceNormal; + const QVector& entityIdsToInclude; + void** intersectedObject; + bool found; + bool precisionPicking; +}; + + +bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { + RayArgs* args = static_cast(extraData); + bool keepSearching = true; + if (element->findRayIntersection(args->origin, args->direction, keepSearching, + args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, + args->intersectedObject, args->precisionPicking)) { + args->found = true; + } + return keepSearching; +} + +bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + OctreeElementPointer& element, float& distance, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, + Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { + RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking }; + distance = FLT_MAX; + + bool requireLock = lockType == Octree::Lock; + bool lockResult = withReadLock([&]{ + recurseTreeWithOperation(findRayIntersectionOp, &args); + }, requireLock); + + if (accurateResult) { + *accurateResult = lockResult; // if user asked to accuracy or result, let them know this is accurate + } + + return args.found; +} + EntityItemPointer EntityTree::findClosestEntity(glm::vec3 position, float targetRadius) { FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX }; diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index ff84a79088..17c7347b2e 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -80,6 +80,14 @@ public: virtual int processEditPacketData(NLPacket& packet, const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode); + virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, + const QVector& entityIdsToInclude = QVector(), + void** intersectedObject = NULL, + Octree::lockType lockType = Octree::TryLock, + bool* accurateResult = NULL, + bool precisionPicking = false); + virtual bool rootElementHasData() const { return true; } // the root at least needs to store the number of entities in the packet/buffer diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 3b6467401c..f573161255 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -709,34 +709,12 @@ public: bool precisionPicking; }; -bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { - RayArgs* args = static_cast(extraData); - bool keepSearching = true; - if (element->findRayIntersection(args->origin, args->direction, keepSearching, - args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, - args->intersectedObject, args->precisionPicking)) { - args->found = true; - } - return keepSearching; -} bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { - RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking}; - distance = FLT_MAX; - - bool requireLock = lockType == Octree::Lock; - bool lockResult = withReadLock([&]{ - recurseTreeWithOperation(findRayIntersectionOp, &args); - }, requireLock); - - if (accurateResult) { - *accurateResult = lockResult; // if user asked to accuracy or result, let them know this is accurate - } - - return args.found; + return false; } class SphereArgs { diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index f0a4d2c9c0..c785bf47fb 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -298,7 +298,7 @@ public: TryLock } lockType; - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude = QVector(), void** intersectedObject = NULL,