mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Merge pull request #1362 from ZappoMan/edit_particles
Implement Prune for Particle Tree to fix long run time stability.
This commit is contained in:
commit
d9573f6d6c
10 changed files with 49 additions and 17 deletions
|
@ -2815,8 +2815,11 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node
|
|||
|
||||
int packetLength = endOfVoxelQueryPacket - voxelQueryPacket;
|
||||
|
||||
nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength,
|
||||
// make sure we still have an active socket
|
||||
if (node->getActiveSocket()) {
|
||||
nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength,
|
||||
node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort());
|
||||
}
|
||||
|
||||
// Feed number of bytes to corresponding channel of the bandwidth meter
|
||||
_bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength);
|
||||
|
|
|
@ -23,6 +23,7 @@ const float FINGERTIP_VOXEL_SIZE = 0.05;
|
|||
const int TOY_BALL_HAND = 1;
|
||||
const float TOY_BALL_RADIUS = 0.05f;
|
||||
const float TOY_BALL_DAMPING = 0.99f;
|
||||
const glm::vec3 NO_GRAVITY = glm::vec3(0,0,0);
|
||||
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-1,0);
|
||||
const QString TOY_BALL_UPDATE_SCRIPT("");
|
||||
const QString TOY_BALL_DONT_DIE_SCRIPT("Particle.setShouldDie(false);");
|
||||
|
@ -101,7 +102,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||
TOY_BALL_ON_SERVER_COLOR,
|
||||
_toyBallVelocity / (float)TREE_SCALE,
|
||||
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
||||
NO_GRAVITY / (float) TREE_SCALE,
|
||||
TOY_BALL_DAMPING,
|
||||
TOY_BALL_DONT_DIE_SCRIPT);
|
||||
}
|
||||
|
@ -115,7 +116,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||
TOY_BALL_ON_SERVER_COLOR,
|
||||
_toyBallVelocity / (float)TREE_SCALE,
|
||||
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
||||
NO_GRAVITY / (float) TREE_SCALE,
|
||||
TOY_BALL_DAMPING,
|
||||
TOY_BALL_DONT_DIE_SCRIPT);
|
||||
}
|
||||
|
@ -130,6 +131,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
//printVector(avatarRotation * handVelocity);
|
||||
_toyBallVelocity += avatarRotation * fingerTipVelocity;
|
||||
|
||||
// ball is no longer in hand...
|
||||
_ballParticleEditHandle->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||
TOY_BALL_ON_SERVER_COLOR,
|
||||
|
|
|
@ -68,7 +68,9 @@ bool OctreePersistThread::process() {
|
|||
usleep(USECS_TO_SLEEP);
|
||||
|
||||
// do our updates then check to save...
|
||||
_tree->lockForWrite();
|
||||
_tree->update();
|
||||
_tree->unlock();
|
||||
|
||||
uint64_t now = usecTimestampNow();
|
||||
uint64_t sinceLastSave = now - _lastCheck;
|
||||
|
|
|
@ -1083,19 +1083,22 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
|
|||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||
if (oneAtBit(childrenColoredBits, i)) {
|
||||
OctreeElement* childNode = node->getChildAtIndex(i);
|
||||
continueThisLevel = childNode->appendElementData(packetData);
|
||||
|
||||
if (!continueThisLevel) {
|
||||
break; // no point in continuing
|
||||
}
|
||||
|
||||
bytesAtThisLevel += BYTES_PER_COLOR; // keep track of byte count for color
|
||||
if (childNode) {
|
||||
int bytesBeforeChild = packetData->getUncompressedSize();
|
||||
continueThisLevel = childNode->appendElementData(packetData);
|
||||
int bytesAfterChild = packetData->getUncompressedSize();
|
||||
|
||||
if (!continueThisLevel) {
|
||||
break; // no point in continuing
|
||||
}
|
||||
|
||||
bytesAtThisLevel += (bytesAfterChild - bytesBeforeChild); // keep track of byte count for this child
|
||||
|
||||
// don't need to check childNode here, because we can't get here with no childNode
|
||||
if (params.stats) {
|
||||
params.stats->colorSent(childNode);
|
||||
// don't need to check childNode here, because we can't get here with no childNode
|
||||
if (params.stats) {
|
||||
params.stats->colorSent(childNode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ void OctreeElement::calculateAABox() {
|
|||
void OctreeElement::deleteChildAtIndex(int childIndex) {
|
||||
OctreeElement* childAt = getChildAtIndex(childIndex);
|
||||
if (childAt) {
|
||||
printf("deleteChildAtIndex()... about to call delete childAt=%p\n",childAt);
|
||||
//printf("deleteChildAtIndex()... about to call delete childAt=%p\n",childAt);
|
||||
delete childAt;
|
||||
setChildAtIndex(childIndex, NULL);
|
||||
_isDirty = true;
|
||||
|
@ -1292,7 +1292,9 @@ OctreeElement* OctreeElement::getOrCreateChildElementAt(float x, float y, float
|
|||
float ourScale = getScale();
|
||||
float halfOurScale = ourScale / 2.0f;
|
||||
|
||||
assert(s <= ourScale); // This should never happen
|
||||
if(s > ourScale) {
|
||||
printf("UNEXPECTED -- OctreeElement::getOrCreateChildElementAt() s=[%f] > ourScale=[%f] \n", s, ourScale);
|
||||
}
|
||||
|
||||
if (s > halfOurScale) {
|
||||
return this;
|
||||
|
|
|
@ -249,6 +249,9 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe
|
|||
void Particle::debugDump() const {
|
||||
printf("Particle id :%u\n", _id);
|
||||
printf(" last updated:%llu\n", _lastUpdated);
|
||||
printf(" position:%f,%f,%f\n", _position.x, _position.y, _position.z);
|
||||
printf(" velocity:%f,%f,%f\n", _velocity.x, _velocity.y, _velocity.z);
|
||||
printf(" gravity:%f,%f,%f\n", _gravity.x, _gravity.y, _gravity.z);
|
||||
}
|
||||
|
||||
bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, int count, const ParticleDetail* details,
|
||||
|
|
|
@ -169,6 +169,17 @@ bool ParticleTree::updateOperation(OctreeElement* element, void* extraData) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ParticleTree::pruneOperation(OctreeElement* element, void* extraData) {
|
||||
ParticleTreeElement* particleTreeElement = static_cast<ParticleTreeElement*>(element);
|
||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||
ParticleTreeElement* childAt = particleTreeElement->getChildAtIndex(i);
|
||||
if (childAt && childAt->isLeaf() && !childAt->hasParticles()) {
|
||||
particleTreeElement->deleteChildAtIndex(i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticleTree::update() {
|
||||
_isDirty = true;
|
||||
|
||||
|
@ -187,6 +198,9 @@ void ParticleTree::update() {
|
|||
storeParticle(args._movingParticles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// prune the tree...
|
||||
recurseTreeWithOperation(pruneOperation, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ private:
|
|||
static bool updateOperation(OctreeElement* element, void* extraData);
|
||||
static bool findAndUpdateOperation(OctreeElement* element, void* extraData);
|
||||
static bool findNearPointOperation(OctreeElement* element, void* extraData);
|
||||
static bool pruneOperation(OctreeElement* element, void* extraData);
|
||||
|
||||
void notifyNewlyCreatedParticle(const Particle& newParticle, Node* senderNode);
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ 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();
|
||||
|
||||
|
|
|
@ -71,9 +71,10 @@ public:
|
|||
/// shouldRender() state, the tree will remark elements as changed even in cases there the elements have not changed.
|
||||
virtual bool isRendered() const { return getShouldRender(); }
|
||||
|
||||
virtual bool deleteApproved() const { return (_particles.size() == 0); }
|
||||
virtual bool deleteApproved() const { return !hasParticles(); }
|
||||
|
||||
const std::vector<Particle>& getParticles() const { return _particles; }
|
||||
bool hasParticles() const { return _particles.size() > 0; }
|
||||
|
||||
void update(ParticleTreeUpdateArgs& args);
|
||||
void setTree(ParticleTree* tree) { _myTree = tree; }
|
||||
|
|
Loading…
Reference in a new issue