From 164e703decce788b14f31745e65ad58c4553548d Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 21 Jan 2014 20:05:00 -0800 Subject: [PATCH] tweaks to JS particle editing api --- libraries/particles/src/Particle.cpp | 26 ++++++++------- libraries/particles/src/Particle.h | 1 + .../src/ParticlesScriptingInterface.cpp | 32 +++++++++++++------ 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index 0e732d72ef..057ad07c36 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -847,7 +847,8 @@ ParticleProperties::ParticleProperties() : _lifetimeChanged(false), _scriptChanged(false), _inHandChanged(false), - _shouldDieChanged(false) + _shouldDieChanged(false), + _defaultSettings(true) { } @@ -937,7 +938,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { newPosition.x = x.toVariant().toFloat(); newPosition.y = y.toVariant().toFloat(); newPosition.z = z.toVariant().toFloat(); - if (newPosition != _position) { + if (_defaultSettings || newPosition != _position) { _position = newPosition; _positionChanged = true; } @@ -954,9 +955,9 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { newColor.red = red.toVariant().toInt(); newColor.green = green.toVariant().toInt(); newColor.blue = blue.toVariant().toInt(); - if (newColor.red != _color.red || + if (_defaultSettings || (newColor.red != _color.red || newColor.green != _color.green || - newColor.blue != _color.blue) { + newColor.blue != _color.blue)) { _color = newColor; _colorChanged = true; } @@ -967,7 +968,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { if (radius.isValid()) { float newRadius; newRadius = radius.toVariant().toFloat(); - if (newRadius != _radius) { + if (_defaultSettings || newRadius != _radius) { _radius = newRadius; _radiusChanged = true; } @@ -983,7 +984,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { newVelocity.x = x.toVariant().toFloat(); newVelocity.y = y.toVariant().toFloat(); newVelocity.z = z.toVariant().toFloat(); - if (newVelocity != _velocity) { + if (_defaultSettings || newVelocity != _velocity) { _velocity = newVelocity; _velocityChanged = true; } @@ -1000,7 +1001,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { newGravity.x = x.toVariant().toFloat(); newGravity.y = y.toVariant().toFloat(); newGravity.z = z.toVariant().toFloat(); - if (newGravity != _gravity) { + if (_defaultSettings || newGravity != _gravity) { _gravity = newGravity; _gravityChanged = true; } @@ -1011,7 +1012,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { if (damping.isValid()) { float newDamping; newDamping = damping.toVariant().toFloat(); - if (newDamping != _damping) { + if (_defaultSettings || newDamping != _damping) { _damping = newDamping; _dampingChanged = true; } @@ -1021,7 +1022,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { if (lifetime.isValid()) { float newLifetime; newLifetime = lifetime.toVariant().toFloat(); - if (newLifetime != _lifetime) { + if (_defaultSettings || newLifetime != _lifetime) { _lifetime = newLifetime; _lifetimeChanged = true; } @@ -1031,7 +1032,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { if (script.isValid()) { QString newScript; newScript = script.toVariant().toString(); - if (newScript != _script) { + if (_defaultSettings || newScript != _script) { _script = newScript; _scriptChanged = true; } @@ -1041,7 +1042,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { if (inHand.isValid()) { bool newInHand; newInHand = inHand.toVariant().toBool(); - if (newInHand != _inHand) { + if (_defaultSettings || newInHand != _inHand) { _inHand = newInHand; _inHandChanged = true; } @@ -1051,7 +1052,7 @@ void ParticleProperties::copyFromScriptValue(const QScriptValue &object) { if (shouldDie.isValid()) { bool newShouldDie; newShouldDie = shouldDie.toVariant().toBool(); - if (newShouldDie != _shouldDie) { + if (_defaultSettings || newShouldDie != _shouldDie) { _shouldDie = newShouldDie; _shouldDieChanged = true; } @@ -1124,6 +1125,7 @@ void ParticleProperties::copyFromParticle(const Particle& particle) { _scriptChanged = false; _inHandChanged = false; _shouldDieChanged = false; + _defaultSettings = false; } QScriptValue ParticlePropertiesToScriptValue(QScriptEngine* engine, const ParticleProperties& properties) { diff --git a/libraries/particles/src/Particle.h b/libraries/particles/src/Particle.h index a0d9ca45f0..da8cf35ac2 100644 --- a/libraries/particles/src/Particle.h +++ b/libraries/particles/src/Particle.h @@ -112,6 +112,7 @@ private: bool _scriptChanged; bool _inHandChanged; bool _shouldDieChanged; + bool _defaultSettings; }; Q_DECLARE_METATYPE(ParticleProperties); QScriptValue ParticlePropertiesToScriptValue(QScriptEngine* engine, const ParticleProperties& properties); diff --git a/libraries/particles/src/ParticlesScriptingInterface.cpp b/libraries/particles/src/ParticlesScriptingInterface.cpp index 8f69a07bc8..14388b6ac4 100644 --- a/libraries/particles/src/ParticlesScriptingInterface.cpp +++ b/libraries/particles/src/ParticlesScriptingInterface.cpp @@ -38,24 +38,38 @@ void ParticlesScriptingInterface::editParticle(ParticleID particleID, const Part uint32_t actualID = particleID.id; if (!particleID.isKnownID) { 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::editParticle()... BAILING!!! particleID.creatorTokenID=" << particleID.creatorTokenID; - + //qDebug() << "ParticlesScriptingInterface::editParticle()... BAILING!!! particleID.creatorTokenID=" + // << particleID.creatorTokenID; return; // bailing early } } particleID.id = actualID; particleID.isKnownID = true; -qDebug() << "ParticlesScriptingInterface::editParticle()... FOUND IT!!! actualID=" << actualID; -qDebug() << "ParticlesScriptingInterface::editParticle()... properties.getPositon()=" - << properties.getPosition().x << ", " - << properties.getPosition().y << ", " - << properties.getPosition().z << "..."; + //qDebug() << "ParticlesScriptingInterface::editParticle()... FOUND IT!!! actualID=" << actualID; + bool wantDebugging = false; + if (wantDebugging) { + uint16_t containsBits = properties.getChangedBits(); + qDebug() << "ParticlesScriptingInterface::editParticle()... containsBits=" << containsBits; + if ((containsBits & PACKET_CONTAINS_POSITION) == PACKET_CONTAINS_POSITION) { + qDebug() << "ParticlesScriptingInterface::editParticle()... properties.getPositon()=" + << properties.getPosition().x << ", " + << properties.getPosition().y << ", " + << properties.getPosition().z << "..."; + } + if ((containsBits & PACKET_CONTAINS_VELOCITY) == PACKET_CONTAINS_VELOCITY) { + qDebug() << "ParticlesScriptingInterface::editParticle()... properties.getVelocity()=" + << properties.getVelocity().x << ", " + << properties.getVelocity().y << ", " + << properties.getVelocity().z << "..."; + } + if ((containsBits & PACKET_CONTAINS_INHAND) == PACKET_CONTAINS_INHAND) { + qDebug() << "ParticlesScriptingInterface::editParticle()... properties.getInHand()=" << properties.getInHand(); + } + } queueParticleMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties); }