From 03b2ace488c5fe89ca589b915c748d0dd672b953 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 28 Oct 2013 12:54:37 -0700 Subject: [PATCH] moved blended _children union into BLENDED_UNION_CHILDREN --- .../voxel-server-library/src/VoxelServer.cpp | 16 +++++++++++--- libraries/voxels/src/VoxelNode.cpp | 21 +++++++++++++++---- libraries/voxels/src/VoxelNode.h | 21 ++++++++++++------- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 1167ef8b46..a7fe8869d9 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -136,7 +136,9 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) { mg_printf(connection, "%s", "\r\n"); mg_printf(connection, "%s", "VoxelNode Children Encoding Statistics...\r\n"); - mg_printf(connection, " Single or No Children: %10.llu nodes (%5.2f%%)\r\n", + +#ifdef BLENDED_UNION_CHILDREN + mg_printf(connection, " Single or No Children: %10.llu nodes (%5.2f%%)\r\n", VoxelNode::getSingleChildrenCount(), ((float)VoxelNode::getSingleChildrenCount()/(float)nodeCount) * AS_PERCENT); mg_printf(connection, " Two Children as Offset: %10.llu nodes (%5.2f%%)\r\n", VoxelNode::getTwoChildrenOffsetCount(), @@ -150,14 +152,19 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) { mg_printf(connection, " Three Children as External: %10.llu nodes (%5.2f%%)\r\n", VoxelNode::getThreeChildrenExternalCount(), ((float)VoxelNode::getThreeChildrenExternalCount()/(float)nodeCount) * AS_PERCENT); - mg_printf(connection, " Children as External Array: %10.llu nodes (%5.2f%%)\r\n", +#endif + mg_printf(connection, " Children as External Array: %10.llu nodes (%5.2f%%)\r\n", VoxelNode::getExternalChildrenCount(), ((float)VoxelNode::getExternalChildrenCount()/(float)nodeCount) * AS_PERCENT); - uint64_t checkSum = VoxelNode::getSingleChildrenCount() + +#ifdef BLENDED_UNION_CHILDREN + uint64_t checkSum = VoxelNode::getSingleChildrenCount() + VoxelNode::getTwoChildrenOffsetCount() + VoxelNode::getTwoChildrenExternalCount() + VoxelNode::getThreeChildrenOffsetCount() + VoxelNode::getThreeChildrenExternalCount() + VoxelNode::getExternalChildrenCount(); +#else + uint64_t checkSum = VoxelNode::getExternalChildrenCount(); +#endif mg_printf(connection, "%s", " ----------------\r\n"); mg_printf(connection, " Total: %10.llu nodes\r\n", checkSum); @@ -175,11 +182,14 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) { mg_printf(connection, " Total: %10.llu nodes\r\n", checkSum); mg_printf(connection, "%s", "\r\n"); + +#ifdef BLENDED_UNION_CHILDREN mg_printf(connection, "%s", "In other news....\r\n"); mg_printf(connection, "could store 4 children internally: %10.llu nodes\r\n", VoxelNode::getCouldStoreFourChildrenInternally()); mg_printf(connection, "could NOT store 4 children internally: %10.llu nodes\r\n", VoxelNode::getCouldNotStoreFourChildrenInternally()); +#endif return 1; } else { diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 3eb6047242..a1f6d9aa7e 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -65,8 +65,11 @@ void VoxelNode::init(unsigned char * octalCode) { // set up the _children union _childBitmask = 0; _childrenExternal = false; + +#ifdef BLENDED_UNION_CHILDREN _children.external = NULL; _singleChildrenCount++; +#endif _childrenCount[0]++; // default pointers to child nodes to NULL @@ -314,20 +317,25 @@ uint64_t VoxelNode::_getChildAtIndexCalls = 0; uint64_t VoxelNode::_setChildAtIndexTime = 0; uint64_t VoxelNode::_setChildAtIndexCalls = 0; +#ifdef BLENDED_UNION_CHILDREN uint64_t VoxelNode::_singleChildrenCount = 0; uint64_t VoxelNode::_twoChildrenOffsetCount = 0; uint64_t VoxelNode::_twoChildrenExternalCount = 0; uint64_t VoxelNode::_threeChildrenOffsetCount = 0; uint64_t VoxelNode::_threeChildrenExternalCount = 0; -uint64_t VoxelNode::_externalChildrenCount = 0; -uint64_t VoxelNode::_childrenCount[NUMBER_OF_CHILDREN + 1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; uint64_t VoxelNode::_couldStoreFourChildrenInternally = 0; uint64_t VoxelNode::_couldNotStoreFourChildrenInternally = 0; +#endif + +uint64_t VoxelNode::_externalChildrenCount = 0; +uint64_t VoxelNode::_childrenCount[NUMBER_OF_CHILDREN + 1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const { #ifdef SIMPLE_CHILD_ARRAY return _simpleChildArray[childIndex]; -#else +#endif // SIMPLE_CHILD_ARRAY + +#ifdef BLENDED_UNION_CHILDREN PerformanceWarning warn(false,"getChildAtIndex",false,&_getChildAtIndexTime,&_getChildAtIndexCalls); VoxelNode* result = NULL; int childCount = getChildCount(); @@ -439,6 +447,7 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const { #endif } +#ifdef BLENDED_UNION_CHILDREN void VoxelNode::storeTwoChildren(VoxelNode* childOne, VoxelNode* childTwo) { int64_t offsetOne = (uint8_t*)childOne - (uint8_t*)this; int64_t offsetTwo = (uint8_t*)childTwo - (uint8_t*)this; @@ -633,6 +642,7 @@ void VoxelNode::checkStoreFourChildren(VoxelNode* childOne, VoxelNode* childTwo, _couldNotStoreFourChildrenInternally++; } } +#endif void VoxelNode::deleteAllChildren() { // first delete all the VoxelNode objects... @@ -643,6 +653,7 @@ void VoxelNode::deleteAllChildren() { } } +#ifdef BLENDED_UNION_CHILDREN // now, reset our internal state and ANY and all population data int childCount = getChildCount(); switch (childCount) { @@ -686,6 +697,7 @@ void VoxelNode::deleteAllChildren() { delete[] _children.external; } _children.single = NULL; +#endif // BLENDED_UNION_CHILDREN } void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) { @@ -707,7 +719,8 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) { _childrenCount[newChildCount]++; } -#else +#endif +#ifdef BLENDED_UNION_CHILDREN PerformanceWarning warn(false,"setChildAtIndex",false,&_setChildAtIndexTime,&_setChildAtIndexCalls); // Here's how we store things... diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index c9e892ebb9..07a49e75b9 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -131,16 +131,18 @@ public: static uint64_t getSetChildAtIndexTime() { return _setChildAtIndexTime; } static uint64_t getSetChildAtIndexCalls() { return _setChildAtIndexCalls; } +#ifdef BLENDED_UNION_CHILDREN static uint64_t getSingleChildrenCount() { return _singleChildrenCount; } static uint64_t getTwoChildrenOffsetCount() { return _twoChildrenOffsetCount; } static uint64_t getTwoChildrenExternalCount() { return _twoChildrenExternalCount; } static uint64_t getThreeChildrenOffsetCount() { return _threeChildrenOffsetCount; } static uint64_t getThreeChildrenExternalCount() { return _threeChildrenExternalCount; } - static uint64_t getExternalChildrenCount() { return _externalChildrenCount; } - static uint64_t getChildrenCount(int childCount) { return _childrenCount[childCount]; } - static uint64_t getCouldStoreFourChildrenInternally() { return _couldStoreFourChildrenInternally; } static uint64_t getCouldNotStoreFourChildrenInternally() { return _couldNotStoreFourChildrenInternally; } +#endif + + static uint64_t getExternalChildrenCount() { return _externalChildrenCount; } + static uint64_t getChildrenCount(int childCount) { return _childrenCount[childCount]; } #ifdef HAS_AUDIT_CHILDREN void auditChildren(const char* label) const; @@ -149,6 +151,8 @@ public: private: void deleteAllChildren(); void setChildAtIndex(int childIndex, VoxelNode* child); + +#ifdef BLENDED_UNION_CHILDREN void storeTwoChildren(VoxelNode* childOne, VoxelNode* childTwo); void retrieveTwoChildren(VoxelNode*& childOne, VoxelNode*& childTwo); void storeThreeChildren(VoxelNode* childOne, VoxelNode* childTwo, VoxelNode* childThree); @@ -156,7 +160,7 @@ private: void decodeThreeOffsets(int64_t& offsetOne, int64_t& offsetTwo, int64_t& offsetThree) const; void encodeThreeOffsets(int64_t offsetOne, int64_t offsetTwo, int64_t offsetThree); void checkStoreFourChildren(VoxelNode* childOne, VoxelNode* childTwo, VoxelNode* childThree, VoxelNode* childFour); - +#endif void calculateAABox(); void init(unsigned char * octalCode); void notifyDeleteHooks(); @@ -177,12 +181,14 @@ private: VoxelNode* _simpleChildArray[8]; /// Only used when HAS_AUDIT_CHILDREN is enabled to help debug children encoding #endif +#ifdef BLENDED_UNION_CHILDREN union children_t { VoxelNode* single; int32_t offsetsTwoChildren[2]; uint64_t offsetsThreeChildrenEncoded; VoxelNode** external; } _children; +#endif //def BLENDED_UNION_CHILDREN #ifdef HAS_AUDIT_CHILDREN VoxelNode* _childrenArray[8]; /// Only used when HAS_AUDIT_CHILDREN is enabled to help debug children encoding @@ -237,16 +243,17 @@ private: static uint64_t _setChildAtIndexTime; static uint64_t _setChildAtIndexCalls; +#ifdef BLENDED_UNION_CHILDREN static uint64_t _singleChildrenCount; static uint64_t _twoChildrenOffsetCount; static uint64_t _twoChildrenExternalCount; static uint64_t _threeChildrenOffsetCount; static uint64_t _threeChildrenExternalCount; - static uint64_t _externalChildrenCount; - static uint64_t _childrenCount[NUMBER_OF_CHILDREN + 1]; - static uint64_t _couldStoreFourChildrenInternally; static uint64_t _couldNotStoreFourChildrenInternally; +#endif + static uint64_t _externalChildrenCount; + static uint64_t _childrenCount[NUMBER_OF_CHILDREN + 1]; }; #endif /* defined(__hifi__VoxelNode__) */ \ No newline at end of file