mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 04:13:11 +02:00
fix failed lock causing particle collisions to not work
This commit is contained in:
parent
6d1748e5b9
commit
c90d4a9514
3 changed files with 79 additions and 33 deletions
|
@ -590,16 +590,26 @@ bool findRayIntersectionOp(OctreeElement* node, void* extraData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
OctreeElement*& node, float& distance, BoxFace& face, bool tryLock) {
|
OctreeElement*& node, float& distance, BoxFace& face, Octree::lockType lockType) {
|
||||||
RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face };
|
RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face };
|
||||||
|
|
||||||
if (!tryLock) {
|
bool gotLock = false;
|
||||||
|
if (lockType == Octree::Lock) {
|
||||||
lockForRead();
|
lockForRead();
|
||||||
|
gotLock = true;
|
||||||
|
} else if (lockType == Octree::TryLock) {
|
||||||
|
gotLock = tryLockForRead();
|
||||||
|
if (!gotLock) {
|
||||||
|
return args.found; // if we wanted to tryLock, and we couldn't then just bail...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (tryLock && tryLockForRead()) {
|
|
||||||
recurseTreeWithOperation(findRayIntersectionOp, &args);
|
recurseTreeWithOperation(findRayIntersectionOp, &args);
|
||||||
|
|
||||||
|
if (gotLock) {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.found;
|
return args.found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,7 +645,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
|
bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
|
||||||
void** penetratedObject, bool tryLock) {
|
void** penetratedObject, Octree::lockType lockType) {
|
||||||
|
|
||||||
SphereArgs args = {
|
SphereArgs args = {
|
||||||
center / (float)(TREE_SCALE),
|
center / (float)(TREE_SCALE),
|
||||||
|
@ -644,17 +654,27 @@ bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::v
|
||||||
false,
|
false,
|
||||||
NULL };
|
NULL };
|
||||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
if (!tryLock) {
|
bool gotLock = false;
|
||||||
|
if (lockType == Octree::Lock) {
|
||||||
lockForRead();
|
lockForRead();
|
||||||
}
|
gotLock = true;
|
||||||
if (tryLock && tryLockForRead()) {
|
} else if (lockType == Octree::TryLock) {
|
||||||
recurseTreeWithOperation(findSpherePenetrationOp, &args);
|
gotLock = tryLockForRead();
|
||||||
if (penetratedObject) {
|
if (!gotLock) {
|
||||||
*penetratedObject = args.penetratedObject;
|
return args.found; // if we wanted to tryLock, and we couldn't then just bail...
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recurseTreeWithOperation(findSpherePenetrationOp, &args);
|
||||||
|
if (penetratedObject) {
|
||||||
|
*penetratedObject = args.penetratedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gotLock) {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.found;
|
return args.found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,7 +709,7 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||||
glm::vec3& penetration, bool tryLock) {
|
glm::vec3& penetration, Octree::lockType lockType) {
|
||||||
|
|
||||||
CapsuleArgs args = {
|
CapsuleArgs args = {
|
||||||
start / (float)(TREE_SCALE),
|
start / (float)(TREE_SCALE),
|
||||||
|
@ -699,11 +719,20 @@ bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end
|
||||||
false };
|
false };
|
||||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
if (!tryLock) {
|
bool gotLock = false;
|
||||||
|
if (lockType == Octree::Lock) {
|
||||||
lockForRead();
|
lockForRead();
|
||||||
|
gotLock = true;
|
||||||
|
} else if (lockType == Octree::TryLock) {
|
||||||
|
gotLock = tryLockForRead();
|
||||||
|
if (!gotLock) {
|
||||||
|
return args.found; // if we wanted to tryLock, and we couldn't then just bail...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (tryLock && tryLockForRead()) {
|
|
||||||
recurseTreeWithOperation(findCapsulePenetrationOp, &args);
|
recurseTreeWithOperation(findCapsulePenetrationOp, &args);
|
||||||
|
|
||||||
|
if (gotLock) {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
return args.found;
|
return args.found;
|
||||||
|
@ -732,18 +761,28 @@ bool getElementEnclosingOperation(OctreeElement* element, void* extraData) {
|
||||||
return true; // keep looking
|
return true; // keep looking
|
||||||
}
|
}
|
||||||
|
|
||||||
OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, bool tryLock) {
|
OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType) {
|
||||||
GetElementEnclosingArgs args;
|
GetElementEnclosingArgs args;
|
||||||
args.point = point;
|
args.point = point;
|
||||||
args.element = NULL;
|
args.element = NULL;
|
||||||
|
|
||||||
if (!tryLock) {
|
bool gotLock = false;
|
||||||
|
if (lockType == Octree::Lock) {
|
||||||
lockForRead();
|
lockForRead();
|
||||||
|
gotLock = true;
|
||||||
|
} else if (lockType == Octree::TryLock) {
|
||||||
|
gotLock = tryLockForRead();
|
||||||
|
if (!gotLock) {
|
||||||
|
return args.element; // if we wanted to tryLock, and we couldn't then just bail...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (tryLock && tryLockForRead()) {
|
|
||||||
recurseTreeWithOperation(getElementEnclosingOperation, (void*)&args);
|
recurseTreeWithOperation(getElementEnclosingOperation, (void*)&args);
|
||||||
|
|
||||||
|
if (gotLock) {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.element;
|
return args.element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,16 +221,29 @@ public:
|
||||||
void clearDirtyBit() { _isDirty = false; }
|
void clearDirtyBit() { _isDirty = false; }
|
||||||
void setDirtyBit() { _isDirty = true; }
|
void setDirtyBit() { _isDirty = true; }
|
||||||
|
|
||||||
|
// Octree does not currently handle its own locking, caller must use these to lock/unlock
|
||||||
|
void lockForRead() { _lock.lockForRead(); }
|
||||||
|
bool tryLockForRead() { return _lock.tryLockForRead(); }
|
||||||
|
void lockForWrite() { _lock.lockForWrite(); }
|
||||||
|
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||||
|
void unlock() { _lock.unlock(); }
|
||||||
|
// output hints from the encode process
|
||||||
|
typedef enum {
|
||||||
|
Lock,
|
||||||
|
TryLock,
|
||||||
|
NoLock
|
||||||
|
} lockType;
|
||||||
|
|
||||||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
OctreeElement*& node, float& distance, BoxFace& face, bool tryLock = true);
|
OctreeElement*& node, float& distance, BoxFace& face, Octree::lockType lockType = Octree::TryLock);
|
||||||
|
|
||||||
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
|
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
|
||||||
void** penetratedObject = NULL, bool tryLock = true);
|
void** penetratedObject = NULL, Octree::lockType lockType = Octree::TryLock);
|
||||||
|
|
||||||
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||||
glm::vec3& penetration, bool tryLock = true);
|
glm::vec3& penetration, Octree::lockType lockType = Octree::TryLock);
|
||||||
|
|
||||||
OctreeElement* getElementEnclosingPoint(const glm::vec3& point, bool tryLock = true);
|
OctreeElement* getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType = Octree::TryLock);
|
||||||
|
|
||||||
// Note: this assumes the fileFormat is the HIO individual voxels code files
|
// Note: this assumes the fileFormat is the HIO individual voxels code files
|
||||||
void loadOctreeFile(const char* fileName, bool wantColorRandomizer);
|
void loadOctreeFile(const char* fileName, bool wantColorRandomizer);
|
||||||
|
@ -238,13 +251,7 @@ public:
|
||||||
// these will read/write files that match the wireformat, excluding the 'V' leading
|
// these will read/write files that match the wireformat, excluding the 'V' leading
|
||||||
void writeToSVOFile(const char* filename, OctreeElement* node = NULL);
|
void writeToSVOFile(const char* filename, OctreeElement* node = NULL);
|
||||||
bool readFromSVOFile(const char* filename);
|
bool readFromSVOFile(const char* filename);
|
||||||
|
|
||||||
// Octree does not currently handle its own locking, caller must use these to lock/unlock
|
|
||||||
void lockForRead() { _lock.lockForRead(); }
|
|
||||||
bool tryLockForRead() { return _lock.tryLockForRead(); }
|
|
||||||
void lockForWrite() { _lock.lockForWrite(); }
|
|
||||||
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
|
||||||
void unlock() { _lock.unlock(); }
|
|
||||||
|
|
||||||
unsigned long getOctreeElementsCount();
|
unsigned long getOctreeElementsCount();
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ bool ParticleCollisionSystem::updateOperation(OctreeElement* element, void* extr
|
||||||
|
|
||||||
void ParticleCollisionSystem::update() {
|
void ParticleCollisionSystem::update() {
|
||||||
// update all particles
|
// update all particles
|
||||||
if (_particles->tryLockForWrite()) {
|
if (_particles->tryLockForRead()) {
|
||||||
_particles->recurseTreeWithOperation(updateOperation, this);
|
_particles->recurseTreeWithOperation(updateOperation, this);
|
||||||
_particles->unlock();
|
_particles->unlock();
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA)
|
||||||
const float COLLISION_FREQUENCY = 0.5f;
|
const float COLLISION_FREQUENCY = 0.5f;
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
Particle* particleB;
|
Particle* particleB;
|
||||||
if (_particles->findSpherePenetration(center, radius, penetration, (void**)&particleB)) {
|
if (_particles->findSpherePenetration(center, radius, penetration, (void**)&particleB, Octree::NoLock)) {
|
||||||
// NOTE: 'penetration' is the depth that 'particleA' overlaps 'particleB'.
|
// NOTE: 'penetration' is the depth that 'particleA' overlaps 'particleB'.
|
||||||
// That is, it points from A into B.
|
// That is, it points from A into B.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue