more work on update

This commit is contained in:
ZappoMan 2013-12-09 16:33:12 -08:00
parent 68a51f5205
commit 99e3a58a68
6 changed files with 50 additions and 16 deletions

View file

@ -24,7 +24,7 @@ JurisdictionListener::JurisdictionListener(NODE_TYPE type, PacketSenderNotify* n
NodeList* nodeList = NodeList::getInstance();
nodeList->addHook(this);
qDebug("JurisdictionListener::JurisdictionListener(NODE_TYPE type=%c)\n", type);
//qDebug("JurisdictionListener::JurisdictionListener(NODE_TYPE type=%c)\n", type);
}
@ -44,7 +44,7 @@ void JurisdictionListener::nodeKilled(Node* node) {
}
bool JurisdictionListener::queueJurisdictionRequest() {
qDebug() << "JurisdictionListener::queueJurisdictionRequest()\n";
//qDebug() << "JurisdictionListener::queueJurisdictionRequest()\n";
static unsigned char buffer[MAX_PACKET_SIZE];
unsigned char* bufferOut = &buffer[0];
@ -54,7 +54,7 @@ qDebug() << "JurisdictionListener::queueJurisdictionRequest()\n";
NodeList* nodeList = NodeList::getInstance();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
qDebug() << "Hello..." << *node << "\n";
//qDebug() << "Hello..." << *node << "\n";
if (nodeList->getNodeActiveSocketOrPing(&(*node)) &&
node->getType() == getNodeType()) {

View file

@ -204,16 +204,16 @@ void Particle::update() {
uint64_t USECS_PER_MINUTE = 60 * USECS_PER_SECOND;
uint64_t USECS_PER_HOUR = 60 * USECS_PER_MINUTE;
float timeElapsed = (float)((float)elapsed/(float)USECS_PER_SECOND);
printf("elapsed=%llu timeElapsed=%f\n", elapsed, timeElapsed);
//printf("elapsed=%llu timeElapsed=%f\n", elapsed, timeElapsed);
glm::vec3 position = getPosition() * (float)TREE_SCALE;
printf("OLD position=%f, %f, %f\n", position.x, position.y, position.z);
printf("velocity=%f, %f, %f\n", getVelocity().x, getVelocity().y, getVelocity().z);
//printf("OLD position=%f, %f, %f\n", position.x, position.y, position.z);
//printf("velocity=%f, %f, %f\n", getVelocity().x, getVelocity().y, getVelocity().z);
_position += _velocity * timeElapsed;
position = getPosition() * (float)TREE_SCALE;
printf("NEW position=%f, %f, %f\n", position.x, position.y, position.z);
//printf("NEW position=%f, %f, %f\n", position.x, position.y, position.z);
_lastUpdated = now;
}

View file

@ -66,20 +66,23 @@ int ParticleTree::processEditPacketData(PACKET_TYPE packetType, unsigned char* p
}
class UpdateArgs {
public:
};
bool ParticleTree::updateOperation(OctreeElement* element, void* extraData) {
UpdateArgs* args = static_cast<UpdateArgs*>(extraData);
ParticleTreeUpdateArgs* args = static_cast<ParticleTreeUpdateArgs*>(extraData);
ParticleTreeElement* particleTreeElement = static_cast<ParticleTreeElement*>(element);
particleTreeElement->update();
particleTreeElement->update(*args);
return true;
}
void ParticleTree::update() {
UpdateArgs args = { };
ParticleTreeUpdateArgs args = { };
recurseTreeWithOperation(updateOperation, &args);
// now add back any of the particles that moved elements....
int movingParticles = args._movingParticles.size();
for (int i = 0; i < movingParticles; i++) {
printf("re-storing moved particle...\n");
storeParticle(args._movingParticles[i]);
}
}

View file

@ -12,6 +12,13 @@
#include <Octree.h>
#include "ParticleTreeElement.h"
class ParticleTreeUpdateArgs {
public:
std::vector<Particle> _movingParticles;
};
class ParticleTree : public Octree {
Q_OBJECT
public:

View file

@ -59,12 +59,34 @@ bool ParticleTreeElement::appendElementData(OctreePacketData* packetData) const
return success;
}
void ParticleTreeElement::update() {
void ParticleTreeElement::update(ParticleTreeUpdateArgs& args) {
// update our contained particles
uint16_t numberOfParticles = _particles.size();
for (uint16_t i = 0; i < numberOfParticles; i++) {
_particles[i].update();
// what if this update moves the particle to a new element??
if (!_box.contains(_particles[i].getPosition())) {
glm::vec3 position = _particles[i].getPosition() * (float)TREE_SCALE;
glm::vec3 boxBRN =_box.getCorner() * (float)TREE_SCALE;
glm::vec3 boxTLF =_box.calcTopFarLeft() * (float)TREE_SCALE;
printf("particle [%f,%f,%f] no longer contained in ParticleTreeElement() box [%f,%f,%f] -> [%f,%f,%f]\n",
position.x, position.y, position.z,
boxBRN.x, boxBRN.y, boxBRN.z,
boxTLF.x, boxTLF.y, boxTLF.z);
args._movingParticles.push_back(_particles[i]);
// erase this particle
_particles.erase(_particles.begin()+i);
printf("removed particle[%d]\n",i);
// reduce our index since we just removed this item
i--;
numberOfParticles--;
printf("numberOfParticles=%d]\n",numberOfParticles);
}
}
}

View file

@ -15,9 +15,11 @@
#include <OctreeElement.h>
#include "Particle.h"
#include "ParticleTree.h"
class ParticleTree;
class ParticleTreeElement;
class ParticleTreeUpdateArgs;
class ParticleTreeElement : public OctreeElement {
friend class ParticleTree; // to allow createElement to new us...
@ -71,7 +73,7 @@ public:
const std::vector<Particle>& getParticles() const { return _particles; }
void update();
void update(ParticleTreeUpdateArgs& args);
protected:
void storeParticle(const Particle& particle);