mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
moving whitelist code out of octree
This commit is contained in:
parent
c04cdc4964
commit
8c229d88a8
4 changed files with 56 additions and 24 deletions
|
@ -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
|
// if this element doesn't contain the point, then none of its children can contain the point, so stop searching
|
||||||
return false;
|
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<QUuid>& entityIdsToInclude;
|
||||||
|
void** intersectedObject;
|
||||||
|
bool found;
|
||||||
|
bool precisionPicking;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) {
|
||||||
|
RayArgs* args = static_cast<RayArgs*>(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<QUuid>& 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) {
|
EntityItemPointer EntityTree::findClosestEntity(glm::vec3 position, float targetRadius) {
|
||||||
FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX };
|
FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX };
|
||||||
|
|
|
@ -80,6 +80,14 @@ public:
|
||||||
virtual int processEditPacketData(NLPacket& packet, const unsigned char* editData, int maxLength,
|
virtual int processEditPacketData(NLPacket& packet, const unsigned char* editData, int maxLength,
|
||||||
const SharedNodePointer& senderNode);
|
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<QUuid>& entityIdsToInclude = QVector<QUuid>(),
|
||||||
|
void** intersectedObject = NULL,
|
||||||
|
Octree::lockType lockType = Octree::TryLock,
|
||||||
|
bool* accurateResult = NULL,
|
||||||
|
bool precisionPicking = false);
|
||||||
|
|
||||||
virtual bool rootElementHasData() const { return true; }
|
virtual bool rootElementHasData() const { return true; }
|
||||||
|
|
||||||
// the root at least needs to store the number of entities in the packet/buffer
|
// the root at least needs to store the number of entities in the packet/buffer
|
||||||
|
|
|
@ -709,34 +709,12 @@ public:
|
||||||
bool precisionPicking;
|
bool precisionPicking;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) {
|
|
||||||
RayArgs* args = static_cast<RayArgs*>(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,
|
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
OctreeElementPointer& element, float& distance,
|
OctreeElementPointer& element, float& distance,
|
||||||
BoxFace& face, glm::vec3& surfaceNormal, const QVector<QUuid>& entityIdsToInclude, void** intersectedObject,
|
BoxFace& face, glm::vec3& surfaceNormal, const QVector<QUuid>& entityIdsToInclude, void** intersectedObject,
|
||||||
Octree::lockType lockType, bool* accurateResult, bool precisionPicking) {
|
Octree::lockType lockType, bool* accurateResult, bool precisionPicking) {
|
||||||
RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking};
|
return false;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SphereArgs {
|
class SphereArgs {
|
||||||
|
|
|
@ -298,7 +298,7 @@ public:
|
||||||
TryLock
|
TryLock
|
||||||
} lockType;
|
} 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,
|
OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal,
|
||||||
const QVector<QUuid>& entityIdsToInclude = QVector<QUuid>(),
|
const QVector<QUuid>& entityIdsToInclude = QVector<QUuid>(),
|
||||||
void** intersectedObject = NULL,
|
void** intersectedObject = NULL,
|
||||||
|
|
Loading…
Reference in a new issue