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,
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);
return particleEditHandle;
}

View file

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

View file

@ -19,23 +19,27 @@ uint32_t Particle::_nextID = 0;
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() {
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() {
}
void Particle::init(glm::vec3 position, float radius, rgbColor color, glm::vec3 velocity,
float damping, glm::vec3 gravity, QString updateScript) {
_id = _nextID;
_nextID++;
float damping, glm::vec3 gravity, QString updateScript, uint32_t id) {
if (id == NEW_PARTICLE) {
_id = _nextID;
_nextID++;
} else {
_id = id;
}
_lastUpdated = usecTimestampNow();
_position = position;

View file

@ -43,14 +43,15 @@ class Particle {
public:
Particle();
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
static Particle fromEditPacket(unsigned char* data, int length, int& processedBytes);
virtual ~Particle();
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 rgbColor& getColor() const { return _color; }

View file

@ -10,17 +10,19 @@
#include "Particle.h"
#include "ParticleEditHandle.h"
#include "ParticleEditPacketSender.h"
#include "ParticleTree.h"
std::map<uint32_t,ParticleEditHandle*> ParticleEditHandle::_allHandles;
uint32_t ParticleEditHandle::_nextCreatorTokenID = 0;
ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender) {
ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree) {
_creatorTokenID = _nextCreatorTokenID;
_nextCreatorTokenID++;
_id = NEW_PARTICLE;
_isKnownID = false;
_packetSender = packetSender;
_localTree = localTree;
_allHandles[_creatorTokenID] = this;
}
@ -43,6 +45,12 @@ void ParticleEditHandle::createParticle(glm::vec3 position, float radius, xColor
// release them
_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,
@ -62,6 +70,13 @@ bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor
// release them
_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;
}
@ -79,13 +94,10 @@ void ParticleEditHandle::handleAddResponse(unsigned char* packetData , int packe
memcpy(&particleID, dataAt, sizeof(particleID));
dataAt += sizeof(particleID);
printf("handleAddResponse() creatorTokenID=%u particleID=%u\n",creatorTokenID, particleID);
// find this particle in the _allHandles map
if (_allHandles.find(creatorTokenID) != _allHandles.end()) {
ParticleEditHandle* theHandle = _allHandles[creatorTokenID];
theHandle->_id = particleID;
theHandle->_isKnownID = true;
printf("handleAddResponse() for creatorTokenID=%u theHandle->_id=%u\n",creatorTokenID, particleID);
}
}

View file

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