mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 20:44:14 +02:00
make voxelnode population statistics static members instead of per node
This commit is contained in:
parent
86ba5e3064
commit
9d0ff1595a
6 changed files with 45 additions and 39 deletions
|
@ -42,9 +42,10 @@ bool VoxelPersistThread::process() {
|
|||
|
||||
_tree->clearDirtyBit(); // the tree is clean since we just loaded it
|
||||
qDebug("DONE loading voxels from file... fileRead=%s\n", debug::valueOf(persistantFileRead));
|
||||
unsigned long nodeCount = _tree->rootNode->getSubTreeNodeCount();
|
||||
unsigned long internalNodeCount = _tree->rootNode->getSubTreeInternalNodeCount();
|
||||
unsigned long leafNodeCount = _tree->rootNode->getSubTreeLeafNodeCount();
|
||||
|
||||
unsigned long nodeCount = VoxelNode::getNodeCount();
|
||||
unsigned long internalNodeCount = VoxelNode::getInternalNodeCount();
|
||||
unsigned long leafNodeCount = VoxelNode::getLeafNodeCount();
|
||||
qDebug("Nodes after loading scene %lu nodes %lu internal %lu leaves\n", nodeCount, internalNodeCount, leafNodeCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -139,10 +139,9 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) {
|
|||
mg_printf(connection, "Voxel Node Memory Usage: %f MB\r\n", VoxelNode::getVoxelMemoryUsage() / 1000000.f);
|
||||
mg_printf(connection, "Octcode Memory Usage: %f MB\r\n", VoxelNode::getOctcodeMemoryUsage() / 1000000.f);
|
||||
|
||||
VoxelTree* theTree = VoxelServer::GetInstance()->getTree();
|
||||
unsigned long nodeCount = theTree->rootNode->getSubTreeNodeCount();
|
||||
unsigned long internalNodeCount = theTree->rootNode->getSubTreeInternalNodeCount();
|
||||
unsigned long leafNodeCount = theTree->rootNode->getSubTreeLeafNodeCount();
|
||||
unsigned long nodeCount = VoxelNode::getNodeCount();
|
||||
unsigned long internalNodeCount = VoxelNode::getInternalNodeCount();
|
||||
unsigned long leafNodeCount = VoxelNode::getLeafNodeCount();
|
||||
|
||||
mg_printf(connection, "%s", "Current Nodes in scene\r\n");
|
||||
mg_printf(connection, " Total Nodes: %lu nodes\r\n", nodeCount);
|
||||
|
|
|
@ -23,15 +23,22 @@
|
|||
|
||||
uint64_t VoxelNode::_voxelMemoryUsage = 0;
|
||||
uint64_t VoxelNode::_octcodeMemoryUsage = 0;
|
||||
uint64_t VoxelNode::_voxelNodeCount = 0;
|
||||
uint64_t VoxelNode::_voxelNodeLeafCount = 0;
|
||||
|
||||
VoxelNode::VoxelNode() {
|
||||
unsigned char* rootCode = new unsigned char[1];
|
||||
*rootCode = 0;
|
||||
init(rootCode);
|
||||
|
||||
_voxelNodeCount++;
|
||||
_voxelNodeLeafCount++; // all nodes start as leaf nodes
|
||||
}
|
||||
|
||||
VoxelNode::VoxelNode(unsigned char * octalCode) {
|
||||
init(octalCode);
|
||||
_voxelNodeCount++;
|
||||
_voxelNodeLeafCount++; // all nodes start as leaf nodes
|
||||
}
|
||||
|
||||
void VoxelNode::init(unsigned char * octalCode) {
|
||||
|
@ -49,8 +56,6 @@ void VoxelNode::init(unsigned char * octalCode) {
|
|||
_children[i] = NULL;
|
||||
}
|
||||
_childCount = 0;
|
||||
_subtreeNodeCount = 1; // that's me
|
||||
_subtreeLeafNodeCount = 0; // that's me
|
||||
|
||||
_glBufferIndex = GLBUFFER_INDEX_UNKNOWN;
|
||||
_voxelSystem = NULL;
|
||||
|
@ -70,6 +75,11 @@ VoxelNode::~VoxelNode() {
|
|||
_voxelMemoryUsage -= sizeof(VoxelNode);
|
||||
_octcodeMemoryUsage -= bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(getOctalCode()));
|
||||
|
||||
_voxelNodeCount--;
|
||||
if (isLeaf()) {
|
||||
_voxelNodeLeafCount--;
|
||||
}
|
||||
|
||||
delete[] _octalCode;
|
||||
|
||||
// delete all of this node's children
|
||||
|
@ -97,27 +107,9 @@ void VoxelNode::handleSubtreeChanged(VoxelTree* myTree) {
|
|||
setColorFromAverageOfChildren();
|
||||
}
|
||||
|
||||
recalculateSubTreeNodeCount();
|
||||
markWithChangedTime();
|
||||
}
|
||||
|
||||
void VoxelNode::recalculateSubTreeNodeCount() {
|
||||
// Assuming the tree below me as changed, I need to recalculate my node count
|
||||
_subtreeNodeCount = 1; // that's me
|
||||
if (isLeaf()) {
|
||||
_subtreeLeafNodeCount = 1;
|
||||
} else {
|
||||
_subtreeLeafNodeCount = 0;
|
||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||
if (_children[i]) {
|
||||
_subtreeNodeCount += _children[i]->_subtreeNodeCount;
|
||||
_subtreeLeafNodeCount += _children[i]->_subtreeLeafNodeCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VoxelNode::setShouldRender(bool shouldRender) {
|
||||
// if shouldRender is changing, then consider ourselves dirty
|
||||
if (shouldRender != _shouldRender) {
|
||||
|
@ -145,6 +137,11 @@ void VoxelNode::deleteChildAtIndex(int childIndex) {
|
|||
_isDirty = true;
|
||||
_childCount--;
|
||||
markWithChangedTime();
|
||||
|
||||
// after deleting the child, check to see if we're a leaf
|
||||
if (isLeaf()) {
|
||||
_voxelNodeLeafCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,12 +153,22 @@ VoxelNode* VoxelNode::removeChildAtIndex(int childIndex) {
|
|||
_isDirty = true;
|
||||
_childCount--;
|
||||
markWithChangedTime();
|
||||
|
||||
// after removing the child, check to see if we're a leaf
|
||||
if (isLeaf()) {
|
||||
_voxelNodeLeafCount++;
|
||||
}
|
||||
}
|
||||
return returnedChild;
|
||||
}
|
||||
|
||||
VoxelNode* VoxelNode::addChildAtIndex(int childIndex) {
|
||||
if (!_children[childIndex]) {
|
||||
// before adding a child, see if we're currently a leaf
|
||||
if (isLeaf()) {
|
||||
_voxelNodeLeafCount--;
|
||||
}
|
||||
|
||||
_children[childIndex] = new VoxelNode(childOctalCode(getOctalCode(), childIndex));
|
||||
_children[childIndex]->setVoxelSystem(_voxelSystem); // our child is always part of our voxel system NULL ok
|
||||
_isDirty = true;
|
||||
|
|
|
@ -121,10 +121,9 @@ public:
|
|||
static void addUpdateHook(VoxelNodeUpdateHook* hook);
|
||||
static void removeUpdateHook(VoxelNodeUpdateHook* hook);
|
||||
|
||||
void recalculateSubTreeNodeCount();
|
||||
unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; }
|
||||
unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; }
|
||||
unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; }
|
||||
static unsigned long getNodeCount() { return _voxelNodeCount; }
|
||||
static unsigned long getInternalNodeCount() { return _voxelNodeCount - _voxelNodeLeafCount; }
|
||||
static unsigned long getLeafNodeCount() { return _voxelNodeLeafCount; }
|
||||
|
||||
static uint64_t getVoxelMemoryUsage() { return _voxelMemoryUsage; }
|
||||
static uint64_t getOctcodeMemoryUsage() { return _octcodeMemoryUsage; }
|
||||
|
@ -140,8 +139,6 @@ private:
|
|||
unsigned char* _octalCode; /// Client and server, pointer to octal code for this node, 8 bytes
|
||||
|
||||
uint64_t _lastChanged; /// Client and server, timestamp this node was last changed, 8 bytes
|
||||
unsigned long _subtreeNodeCount; /// Client and server, nodes below this node, 8 bytes
|
||||
unsigned long _subtreeLeafNodeCount; /// Client and server, leaves below this node, 8 bytes
|
||||
|
||||
glBufferIndex _glBufferIndex; /// Client only, vbo index for this voxel if being rendered, 8 bytes
|
||||
VoxelSystem* _voxelSystem; /// Client only, pointer to VoxelSystem rendering this voxel, 8 bytes
|
||||
|
@ -162,6 +159,10 @@ private:
|
|||
|
||||
static std::vector<VoxelNodeDeleteHook*> _deleteHooks;
|
||||
static std::vector<VoxelNodeUpdateHook*> _updateHooks;
|
||||
|
||||
static uint64_t _voxelNodeCount;
|
||||
static uint64_t _voxelNodeLeafCount;
|
||||
|
||||
static uint64_t _voxelMemoryUsage;
|
||||
static uint64_t _octcodeMemoryUsage;
|
||||
};
|
||||
|
|
|
@ -33,9 +33,10 @@ void VoxelSceneStats::sceneStarted(bool isFullScene, bool isMoving, VoxelNode* r
|
|||
reset(); // resets packet and voxel stats
|
||||
_isStarted = true;
|
||||
_start = usecTimestampNow();
|
||||
_totalVoxels = root->getSubTreeNodeCount();
|
||||
_totalInternal = root->getSubTreeInternalNodeCount();
|
||||
_totalLeaves = root->getSubTreeLeafNodeCount();
|
||||
|
||||
_totalVoxels = VoxelNode::getNodeCount();
|
||||
_totalInternal = VoxelNode::getInternalNodeCount();
|
||||
_totalLeaves = VoxelNode::getLeafNodeCount();
|
||||
|
||||
_isFullScene = isFullScene;
|
||||
_isMoving = isMoving;
|
||||
|
|
|
@ -647,9 +647,6 @@ void VoxelTree::reaverageVoxelColors(VoxelNode *startNode) {
|
|||
if (hasChildren && !startNode->collapseIdenticalLeaves()) {
|
||||
startNode->setColorFromAverageOfChildren();
|
||||
}
|
||||
|
||||
// this is also a good time to recalculateSubTreeNodeCount()
|
||||
startNode->recalculateSubTreeNodeCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue