mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
use tryLock in some cases where we don't want to block and pass already locked to the findParticleByID() in scripting interface
This commit is contained in:
parent
5b825ecd5b
commit
289be04f0f
3 changed files with 17 additions and 10 deletions
|
@ -32,10 +32,11 @@ void ParticleTreeRenderer::init() {
|
|||
|
||||
void ParticleTreeRenderer::update() {
|
||||
if (_tree) {
|
||||
ParticleTree* tree = (ParticleTree*)_tree;
|
||||
_tree->lockForWrite();
|
||||
tree->update();
|
||||
_tree->unlock();
|
||||
ParticleTree* tree = static_cast<ParticleTree*>(_tree);
|
||||
if (tree->tryLockForWrite()) {
|
||||
tree->update();
|
||||
tree->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,9 +56,10 @@ bool ParticleCollisionSystem::updateOperation(OctreeElement* element, void* extr
|
|||
|
||||
void ParticleCollisionSystem::update() {
|
||||
// update all particles
|
||||
_particles->lockForWrite();
|
||||
_particles->recurseTreeWithOperation(updateOperation, this);
|
||||
_particles->unlock();
|
||||
if (_particles->tryLockForWrite()) {
|
||||
_particles->recurseTreeWithOperation(updateOperation, this);
|
||||
_particles->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ ParticleID ParticlesScriptingInterface::addParticle(const ParticleProperties& pr
|
|||
|
||||
ParticleID ParticlesScriptingInterface::identifyParticle(ParticleID particleID) {
|
||||
uint32_t actualID = particleID.id;
|
||||
|
||||
if (!particleID.isKnownID) {
|
||||
actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID);
|
||||
if (actualID == UNKNOWN_PARTICLE_ID) {
|
||||
|
@ -65,8 +66,12 @@ ParticleProperties ParticlesScriptingInterface::getParticleProperties(ParticleID
|
|||
}
|
||||
if (_particleTree) {
|
||||
_particleTree->lockForRead();
|
||||
const Particle* particle = _particleTree->findParticleByID(identity.id);
|
||||
results.copyFromParticle(*particle);
|
||||
const Particle* particle = _particleTree->findParticleByID(identity.id, true);
|
||||
if (particle) {
|
||||
results.copyFromParticle(*particle);
|
||||
} else {
|
||||
results.setIsUnknownID();
|
||||
}
|
||||
_particleTree->unlock();
|
||||
}
|
||||
|
||||
|
@ -123,7 +128,7 @@ void ParticlesScriptingInterface::deleteParticle(ParticleID particleID) {
|
|||
if (actualID != UNKNOWN_PARTICLE_ID) {
|
||||
particleID.id = actualID;
|
||||
particleID.isKnownID = true;
|
||||
queueParticleMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties);
|
||||
queueParticleMessage(PacketTypeParticleAddOrEdit, particleID, properties);
|
||||
}
|
||||
|
||||
// If we have a local particle tree set, then also update it.
|
||||
|
|
Loading…
Reference in a new issue