mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 15:59:49 +02:00
Merge branch 'master' of ssh://github.com/highfidelity/hifi into cleanup
This commit is contained in:
commit
32df731aae
7 changed files with 55 additions and 42 deletions
|
@ -32,10 +32,11 @@ void ParticleTreeRenderer::init() {
|
||||||
|
|
||||||
void ParticleTreeRenderer::update() {
|
void ParticleTreeRenderer::update() {
|
||||||
if (_tree) {
|
if (_tree) {
|
||||||
ParticleTree* tree = (ParticleTree*)_tree;
|
ParticleTree* tree = static_cast<ParticleTree*>(_tree);
|
||||||
_tree->lockForWrite();
|
if (tree->tryLockForWrite()) {
|
||||||
tree->update();
|
tree->update();
|
||||||
_tree->unlock();
|
tree->unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,9 +240,9 @@ public:
|
||||||
|
|
||||||
// Octree does not currently handle its own locking, caller must use these to lock/unlock
|
// Octree does not currently handle its own locking, caller must use these to lock/unlock
|
||||||
void lockForRead() { lock.lockForRead(); }
|
void lockForRead() { lock.lockForRead(); }
|
||||||
void tryLockForRead() { lock.tryLockForRead(); }
|
bool tryLockForRead() { return lock.tryLockForRead(); }
|
||||||
void lockForWrite() { lock.lockForWrite(); }
|
void lockForWrite() { lock.lockForWrite(); }
|
||||||
void tryLockForWrite() { lock.tryLockForWrite(); }
|
bool tryLockForWrite() { return lock.tryLockForWrite(); }
|
||||||
void unlock() { lock.unlock(); }
|
void unlock() { lock.unlock(); }
|
||||||
|
|
||||||
unsigned long getOctreeElementsCount();
|
unsigned long getOctreeElementsCount();
|
||||||
|
|
|
@ -60,8 +60,6 @@ void Particle::handleAddParticleResponse(const QByteArray& packet) {
|
||||||
memcpy(&particleID, dataAt, sizeof(particleID));
|
memcpy(&particleID, dataAt, sizeof(particleID));
|
||||||
dataAt += sizeof(particleID);
|
dataAt += sizeof(particleID);
|
||||||
|
|
||||||
//qDebug() << "handleAddParticleResponse()... particleID=" << particleID << " creatorTokenID=" << creatorTokenID;
|
|
||||||
|
|
||||||
// add our token to id mapping
|
// add our token to id mapping
|
||||||
_tokenIDsToIDs[creatorTokenID] = particleID;
|
_tokenIDsToIDs[creatorTokenID] = particleID;
|
||||||
}
|
}
|
||||||
|
@ -361,8 +359,6 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
|
||||||
dataAt += sizeof(editID);
|
dataAt += sizeof(editID);
|
||||||
processedBytes += sizeof(editID);
|
processedBytes += sizeof(editID);
|
||||||
|
|
||||||
//qDebug() << "editID:" << editID;
|
|
||||||
|
|
||||||
bool isNewParticle = (editID == NEW_PARTICLE);
|
bool isNewParticle = (editID == NEW_PARTICLE);
|
||||||
|
|
||||||
// special case for handling "new" particles
|
// special case for handling "new" particles
|
||||||
|
@ -411,7 +407,6 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
|
||||||
memcpy(&packetContainsBits, dataAt, sizeof(packetContainsBits));
|
memcpy(&packetContainsBits, dataAt, sizeof(packetContainsBits));
|
||||||
dataAt += sizeof(packetContainsBits);
|
dataAt += sizeof(packetContainsBits);
|
||||||
processedBytes += sizeof(packetContainsBits);
|
processedBytes += sizeof(packetContainsBits);
|
||||||
//qDebug() << "packetContainsBits:" << packetContainsBits;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -528,7 +523,6 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr
|
||||||
if (wantDebugging) {
|
if (wantDebugging) {
|
||||||
qDebug("Particle::fromEditPacket()...");
|
qDebug("Particle::fromEditPacket()...");
|
||||||
qDebug() << " Particle id in packet:" << editID;
|
qDebug() << " Particle id in packet:" << editID;
|
||||||
//qDebug() << " position: " << newParticle._position;
|
|
||||||
newParticle.debugDump();
|
newParticle.debugDump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,8 +729,6 @@ bool Particle::encodeParticleEditMessageDetails(PacketType command, ParticleID i
|
||||||
// cleanup
|
// cleanup
|
||||||
delete[] octcode;
|
delete[] octcode;
|
||||||
|
|
||||||
//qDebug() << "encoding... sizeOut:" << sizeOut;
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,12 +816,8 @@ void Particle::update(const quint64& now) {
|
||||||
_lastUpdated = now;
|
_lastUpdated = now;
|
||||||
|
|
||||||
// calculate our default shouldDie state... then allow script to change it if it wants...
|
// calculate our default shouldDie state... then allow script to change it if it wants...
|
||||||
float speed = glm::length(_velocity);
|
|
||||||
bool isStopped = (speed < MIN_VALID_SPEED);
|
|
||||||
const quint64 REALLY_OLD = 30 * USECS_PER_SECOND; // 30 seconds
|
|
||||||
bool isReallyOld = ((now - _created) > REALLY_OLD);
|
|
||||||
bool isInHand = getInHand();
|
bool isInHand = getInHand();
|
||||||
bool shouldDie = (getAge() > getLifetime()) || getShouldDie() || (!isInHand && isStopped && isReallyOld);
|
bool shouldDie = (getAge() > getLifetime()) || getShouldDie();
|
||||||
setShouldDie(shouldDie);
|
setShouldDie(shouldDie);
|
||||||
|
|
||||||
executeUpdateScripts(); // allow the javascript to alter our state
|
executeUpdateScripts(); // allow the javascript to alter our state
|
||||||
|
@ -1068,7 +1056,7 @@ QScriptValue ParticleProperties::copyToScriptValue(QScriptEngine* engine) const
|
||||||
|
|
||||||
if (_idSet) {
|
if (_idSet) {
|
||||||
properties.setProperty("id", _id);
|
properties.setProperty("id", _id);
|
||||||
properties.setProperty("isKnownID", (_id == UNKNOWN_PARTICLE_ID));
|
properties.setProperty("isKnownID", (_id != UNKNOWN_PARTICLE_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
|
|
|
@ -56,9 +56,10 @@ bool ParticleCollisionSystem::updateOperation(OctreeElement* element, void* extr
|
||||||
|
|
||||||
void ParticleCollisionSystem::update() {
|
void ParticleCollisionSystem::update() {
|
||||||
// update all particles
|
// update all particles
|
||||||
_particles->lockForWrite();
|
if (_particles->tryLockForWrite()) {
|
||||||
_particles->recurseTreeWithOperation(updateOperation, this);
|
_particles->recurseTreeWithOperation(updateOperation, this);
|
||||||
_particles->unlock();
|
_particles->unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,12 +69,12 @@ void ParticleCollisionSystem::checkParticle(Particle* particle) {
|
||||||
updateCollisionWithAvatars(particle);
|
updateCollisionWithAvatars(particle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleCollisionSystem::emitGlobalParicleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails) {
|
void ParticleCollisionSystem::emitGlobalParticleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails) {
|
||||||
ParticleID particleID = particle->getParticleID();
|
ParticleID particleID = particle->getParticleID();
|
||||||
emit particleCollisionWithVoxel(particleID, *voxelDetails);
|
emit particleCollisionWithVoxel(particleID, *voxelDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleCollisionSystem::emitGlobalParicleCollisionWithParticle(Particle* particleA, Particle* particleB) {
|
void ParticleCollisionSystem::emitGlobalParticleCollisionWithParticle(Particle* particleA, Particle* particleB) {
|
||||||
ParticleID idA = particleA->getParticleID();
|
ParticleID idA = particleA->getParticleID();
|
||||||
ParticleID idB = particleB->getParticleID();
|
ParticleID idB = particleB->getParticleID();
|
||||||
emit particleCollisionWithParticle(idA, idB);
|
emit particleCollisionWithParticle(idA, idB);
|
||||||
|
@ -95,7 +96,7 @@ void ParticleCollisionSystem::updateCollisionWithVoxels(Particle* particle) {
|
||||||
particle->collisionWithVoxel(voxelDetails);
|
particle->collisionWithVoxel(voxelDetails);
|
||||||
|
|
||||||
// let the global script run their collision scripts for particles if they have them
|
// let the global script run their collision scripts for particles if they have them
|
||||||
emitGlobalParicleCollisionWithVoxel(particle, voxelDetails);
|
emitGlobalParticleCollisionWithVoxel(particle, voxelDetails);
|
||||||
|
|
||||||
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY);
|
||||||
collisionInfo._penetration /= (float)(TREE_SCALE);
|
collisionInfo._penetration /= (float)(TREE_SCALE);
|
||||||
|
@ -124,7 +125,7 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA)
|
||||||
if (glm::dot(relativeVelocity, penetration) > 0.0f) {
|
if (glm::dot(relativeVelocity, penetration) > 0.0f) {
|
||||||
particleA->collisionWithParticle(particleB);
|
particleA->collisionWithParticle(particleB);
|
||||||
particleB->collisionWithParticle(particleA);
|
particleB->collisionWithParticle(particleA);
|
||||||
emitGlobalParicleCollisionWithParticle(particleA, particleB);
|
emitGlobalParticleCollisionWithParticle(particleA, particleB);
|
||||||
|
|
||||||
glm::vec3 axis = glm::normalize(penetration);
|
glm::vec3 axis = glm::normalize(penetration);
|
||||||
glm::vec3 axialVelocity = glm::dot(relativeVelocity, axis) * axis;
|
glm::vec3 axialVelocity = glm::dot(relativeVelocity, axis) * axis;
|
||||||
|
|
|
@ -58,8 +58,8 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool updateOperation(OctreeElement* element, void* extraData);
|
static bool updateOperation(OctreeElement* element, void* extraData);
|
||||||
void emitGlobalParicleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails);
|
void emitGlobalParticleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails);
|
||||||
void emitGlobalParicleCollisionWithParticle(Particle* particleA, Particle* particleB);
|
void emitGlobalParticleCollisionWithParticle(Particle* particleA, Particle* particleB);
|
||||||
|
|
||||||
ParticleEditPacketSender* _packetSender;
|
ParticleEditPacketSender* _packetSender;
|
||||||
ParticleTree* _particles;
|
ParticleTree* _particles;
|
||||||
|
|
|
@ -43,6 +43,7 @@ ParticleID ParticlesScriptingInterface::addParticle(const ParticleProperties& pr
|
||||||
|
|
||||||
ParticleID ParticlesScriptingInterface::identifyParticle(ParticleID particleID) {
|
ParticleID ParticlesScriptingInterface::identifyParticle(ParticleID particleID) {
|
||||||
uint32_t actualID = particleID.id;
|
uint32_t actualID = particleID.id;
|
||||||
|
|
||||||
if (!particleID.isKnownID) {
|
if (!particleID.isKnownID) {
|
||||||
actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID);
|
actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID);
|
||||||
if (actualID == UNKNOWN_PARTICLE_ID) {
|
if (actualID == UNKNOWN_PARTICLE_ID) {
|
||||||
|
@ -65,8 +66,12 @@ ParticleProperties ParticlesScriptingInterface::getParticleProperties(ParticleID
|
||||||
}
|
}
|
||||||
if (_particleTree) {
|
if (_particleTree) {
|
||||||
_particleTree->lockForRead();
|
_particleTree->lockForRead();
|
||||||
const Particle* particle = _particleTree->findParticleByID(identity.id);
|
const Particle* particle = _particleTree->findParticleByID(identity.id, true);
|
||||||
results.copyFromParticle(*particle);
|
if (particle) {
|
||||||
|
results.copyFromParticle(*particle);
|
||||||
|
} else {
|
||||||
|
results.setIsUnknownID();
|
||||||
|
}
|
||||||
_particleTree->unlock();
|
_particleTree->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,22 +118,19 @@ void ParticlesScriptingInterface::deleteParticle(ParticleID particleID) {
|
||||||
properties.setShouldDie(true);
|
properties.setShouldDie(true);
|
||||||
|
|
||||||
uint32_t actualID = particleID.id;
|
uint32_t actualID = particleID.id;
|
||||||
|
|
||||||
|
// if the particle is unknown, attempt to look it up
|
||||||
if (!particleID.isKnownID) {
|
if (!particleID.isKnownID) {
|
||||||
actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID);
|
actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID);
|
||||||
|
|
||||||
// hmmm... we kind of want to bail if someone attempts to edit an unknown
|
|
||||||
if (actualID == UNKNOWN_PARTICLE_ID) {
|
|
||||||
//qDebug() << "ParticlesScriptingInterface::deleteParticle(), bailing - unknown particle...";
|
|
||||||
return; // bailing early
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
particleID.id = actualID;
|
// if at this point, we know the id, send the update to the particle server
|
||||||
particleID.isKnownID = true;
|
if (actualID != UNKNOWN_PARTICLE_ID) {
|
||||||
|
particleID.id = actualID;
|
||||||
|
particleID.isKnownID = true;
|
||||||
|
queueParticleMessage(PacketTypeParticleAddOrEdit, particleID, properties);
|
||||||
|
}
|
||||||
|
|
||||||
//qDebug() << "ParticlesScriptingInterface::deleteParticle(), queueParticleMessage......";
|
|
||||||
queueParticleMessage(PacketTypeParticleAddOrEdit, particleID, properties);
|
|
||||||
|
|
||||||
// If we have a local particle tree set, then also update it.
|
// If we have a local particle tree set, then also update it.
|
||||||
if (_particleTree) {
|
if (_particleTree) {
|
||||||
_particleTree->lockForWrite();
|
_particleTree->lockForWrite();
|
||||||
|
|
|
@ -260,6 +260,27 @@ void ScriptEngine::run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit scriptEnding();
|
emit scriptEnding();
|
||||||
|
|
||||||
|
if (_voxelsScriptingInterface.getVoxelPacketSender()->serversExist()) {
|
||||||
|
// release the queue of edit voxel messages.
|
||||||
|
_voxelsScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages();
|
||||||
|
|
||||||
|
// since we're in non-threaded mode, call process so that the packets are sent
|
||||||
|
if (!_voxelsScriptingInterface.getVoxelPacketSender()->isThreaded()) {
|
||||||
|
_voxelsScriptingInterface.getVoxelPacketSender()->process();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_particlesScriptingInterface.getParticlePacketSender()->serversExist()) {
|
||||||
|
// release the queue of edit voxel messages.
|
||||||
|
_particlesScriptingInterface.getParticlePacketSender()->releaseQueuedMessages();
|
||||||
|
|
||||||
|
// since we're in non-threaded mode, call process so that the packets are sent
|
||||||
|
if (!_particlesScriptingInterface.getParticlePacketSender()->isThreaded()) {
|
||||||
|
_particlesScriptingInterface.getParticlePacketSender()->process();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cleanMenuItems();
|
cleanMenuItems();
|
||||||
|
|
||||||
// If we were on a thread, then wait till it's done
|
// If we were on a thread, then wait till it's done
|
||||||
|
|
Loading…
Reference in a new issue