have ParticleEditHandle update local tree as well

This commit is contained in:
ZappoMan 2013-12-12 10:41:55 -08:00
parent 5d9b7c7f75
commit 5ec8de1bf3
6 changed files with 36 additions and 14 deletions

View file

@ -1528,7 +1528,7 @@ void Application::shootParticle() {
ParticleEditHandle* Application::makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, ParticleEditHandle* Application::makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
glm::vec3 gravity, float damping, QString updateScript) { glm::vec3 gravity, float damping, QString updateScript) {
ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender); ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree());
particleEditHandle->createParticle(position, radius, color, velocity, gravity, damping, updateScript); particleEditHandle->createParticle(position, radius, color, velocity, gravity, damping, updateScript);
return particleEditHandle; return particleEditHandle;
} }

View file

@ -34,6 +34,9 @@ public:
virtual void renderElement(OctreeElement* element, RenderArgs* args); virtual void renderElement(OctreeElement* element, RenderArgs* args);
void update(); void update();
ParticleTree* getTree() { return (ParticleTree*)_tree; }
protected: protected:
}; };

View file

@ -19,23 +19,27 @@ uint32_t Particle::_nextID = 0;
Particle::Particle(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity, Particle::Particle(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity,
float damping, glm::vec3 gravity, QString updateScript) { float damping, glm::vec3 gravity, QString updateScript, uint32_t id) {
init(position, radius, color, velocity, damping, gravity, updateScript); init(position, radius, color, velocity, damping, gravity, updateScript, id);
} }
Particle::Particle() { Particle::Particle() {
rgbColor noColor = { 0, 0, 0 }; rgbColor noColor = { 0, 0, 0 };
init(glm::vec3(0,0,0), 0, noColor, glm::vec3(0,0,0), DEFAULT_DAMPING, DEFAULT_GRAVITY, DEFAULT_SCRIPT); init(glm::vec3(0,0,0), 0, noColor, glm::vec3(0,0,0), DEFAULT_DAMPING, DEFAULT_GRAVITY, DEFAULT_SCRIPT, NEW_PARTICLE);
} }
Particle::~Particle() { Particle::~Particle() {
} }
void Particle::init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity, void Particle::init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity,
float damping, glm::vec3 gravity, QString updateScript) { float damping, glm::vec3 gravity, QString updateScript, uint32_t id) {
_id = _nextID; if (id == NEW_PARTICLE) {
_nextID++; _id = _nextID;
_nextID++;
} else {
_id = id;
}
_lastUpdated = usecTimestampNow(); _lastUpdated = usecTimestampNow();
_position = position; _position = position;

View file

@ -43,14 +43,15 @@ class Particle {
public: public:
Particle(); Particle();
Particle(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity, Particle(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity,
float damping = DEFAULT_DAMPING, glm::vec3 gravity = DEFAULT_GRAVITY, QString updateScript = DEFAULT_SCRIPT); float damping = DEFAULT_DAMPING, glm::vec3 gravity = DEFAULT_GRAVITY, QString updateScript = DEFAULT_SCRIPT,
uint32_t id = NEW_PARTICLE);
/// creates an NEW particle from an PACKET_TYPE_PARTICLE_ADD_OR_EDIT edit data buffer /// creates an NEW particle from an PACKET_TYPE_PARTICLE_ADD_OR_EDIT edit data buffer
static Particle fromEditPacket(unsigned char* data, int length, int& processedBytes); static Particle fromEditPacket(unsigned char* data, int length, int& processedBytes);
virtual ~Particle(); virtual ~Particle();
virtual void init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity, virtual void init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity,
float damping, glm::vec3 gravity, QString updateScript); float damping, glm::vec3 gravity, QString updateScript, uint32_t id);
const glm::vec3& getPosition() const { return _position; } const glm::vec3& getPosition() const { return _position; }
const rgbColor& getColor() const { return _color; } const rgbColor& getColor() const { return _color; }

View file

@ -10,17 +10,19 @@
#include "Particle.h" #include "Particle.h"
#include "ParticleEditHandle.h" #include "ParticleEditHandle.h"
#include "ParticleEditPacketSender.h" #include "ParticleEditPacketSender.h"
#include "ParticleTree.h"
std::map<uint32_t,ParticleEditHandle*> ParticleEditHandle::_allHandles; std::map<uint32_t,ParticleEditHandle*> ParticleEditHandle::_allHandles;
uint32_t ParticleEditHandle::_nextCreatorTokenID = 0; uint32_t ParticleEditHandle::_nextCreatorTokenID = 0;
ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender) { ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree) {
_creatorTokenID = _nextCreatorTokenID; _creatorTokenID = _nextCreatorTokenID;
_nextCreatorTokenID++; _nextCreatorTokenID++;
_id = NEW_PARTICLE; _id = NEW_PARTICLE;
_isKnownID = false; _isKnownID = false;
_packetSender = packetSender; _packetSender = packetSender;
_localTree = localTree;
_allHandles[_creatorTokenID] = this; _allHandles[_creatorTokenID] = this;
} }
@ -43,6 +45,12 @@ void ParticleEditHandle::createParticle(glm::vec3 position, float radius, xColor
// release them // release them
_packetSender->releaseQueuedMessages(); _packetSender->releaseQueuedMessages();
// if we have a local tree, also update it...
if (_localTree) {
// we can't really do this here, because if we create a particle locally, we'll get a ghost particle
// because we can't really handle updating/deleting it locally
}
} }
bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
@ -62,6 +70,13 @@ bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor
// release them // release them
_packetSender->releaseQueuedMessages(); _packetSender->releaseQueuedMessages();
// if we have a local tree, also update it...
if (_localTree) {
rgbColor rcolor = {color.red, color.green, color.blue };
Particle tempParticle(position, radius, rcolor, velocity, damping, gravity, updateScript, _id);
_localTree->storeParticle(tempParticle);
}
return true; return true;
} }
@ -79,13 +94,10 @@ void ParticleEditHandle::handleAddResponse(unsigned char* packetData , int packe
memcpy(&particleID, dataAt, sizeof(particleID)); memcpy(&particleID, dataAt, sizeof(particleID));
dataAt += sizeof(particleID); dataAt += sizeof(particleID);
printf("handleAddResponse() creatorTokenID=%u particleID=%u\n",creatorTokenID, particleID);
// find this particle in the _allHandles map // find this particle in the _allHandles map
if (_allHandles.find(creatorTokenID) != _allHandles.end()) { if (_allHandles.find(creatorTokenID) != _allHandles.end()) {
ParticleEditHandle* theHandle = _allHandles[creatorTokenID]; ParticleEditHandle* theHandle = _allHandles[creatorTokenID];
theHandle->_id = particleID; theHandle->_id = particleID;
theHandle->_isKnownID = true; theHandle->_isKnownID = true;
printf("handleAddResponse() for creatorTokenID=%u theHandle->_id=%u\n",creatorTokenID, particleID);
} }
} }

View file

@ -20,10 +20,11 @@
#include <OctreePacketData.h> #include <OctreePacketData.h>
class ParticleEditPacketSender; class ParticleEditPacketSender;
class ParticleTree;
class ParticleEditHandle { class ParticleEditHandle {
public: public:
ParticleEditHandle(ParticleEditPacketSender* packetSender); ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree);
~ParticleEditHandle(); ~ParticleEditHandle();
uint32_t getCreatorTokenID() const { return _creatorTokenID; } uint32_t getCreatorTokenID() const { return _creatorTokenID; }
@ -45,6 +46,7 @@ private:
static uint32_t _nextCreatorTokenID; static uint32_t _nextCreatorTokenID;
static std::map<uint32_t,ParticleEditHandle*> _allHandles; static std::map<uint32_t,ParticleEditHandle*> _allHandles;
ParticleEditPacketSender* _packetSender; ParticleEditPacketSender* _packetSender;
ParticleTree* _localTree;
}; };
#endif /* defined(__hifi__ParticleEditHandle__) */ #endif /* defined(__hifi__ParticleEditHandle__) */