This commit is contained in:
Philip Rosedale 2013-05-23 12:33:39 -07:00
commit 235cfc8ab2
4 changed files with 29 additions and 23 deletions

View file

@ -1237,6 +1237,7 @@ void Application::initMenu() {
_renderStatsOn->setShortcut(Qt::Key_Slash); _renderStatsOn->setShortcut(Qt::Key_Slash);
(_logOn = toolsMenu->addAction("Log"))->setCheckable(true); (_logOn = toolsMenu->addAction("Log"))->setCheckable(true);
_logOn->setChecked(false); _logOn->setChecked(false);
_logOn->setShortcut(Qt::CTRL | Qt::Key_L);
QMenu* voxelMenu = menuBar->addMenu("Voxels"); QMenu* voxelMenu = menuBar->addMenu("Voxels");
_voxelModeActions = new QActionGroup(this); _voxelModeActions = new QActionGroup(this);

View file

@ -29,9 +29,12 @@ VoxelNode::VoxelNode(unsigned char * octalCode) {
void VoxelNode::init(unsigned char * octalCode) { void VoxelNode::init(unsigned char * octalCode) {
_octalCode = octalCode; _octalCode = octalCode;
#ifdef HAS_FALSE_COLOR #ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color
_falseColored = false; // assume true color _falseColored = false; // assume true color
_currentColor[0] = _currentColor[1] = _currentColor[2] = _currentColor[3] = 0;
#endif #endif
_trueColor[0] = _trueColor[1] = _trueColor[2] = _trueColor[3] = 0;
// default pointers to child nodes to NULL // default pointers to child nodes to NULL
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
@ -104,13 +107,6 @@ VoxelNode* VoxelNode::removeChildAtIndex(int childIndex) {
void VoxelNode::addChildAtIndex(int childIndex) { void VoxelNode::addChildAtIndex(int childIndex) {
if (!_children[childIndex]) { if (!_children[childIndex]) {
_children[childIndex] = new VoxelNode(childOctalCode(_octalCode, childIndex)); _children[childIndex] = new VoxelNode(childOctalCode(_octalCode, childIndex));
// XXXBHG - When the node is constructed, it should be cleanly set up as
// true colored, but for some reason, not so much. I've added a a basecamp
// to-do to research this. But for now we'll use belt and suspenders and set
// it to not-false-colored here!
_children[childIndex]->setFalseColored(false);
_isDirty = true; _isDirty = true;
_childCount++; _childCount++;
} }
@ -273,10 +269,10 @@ void VoxelNode::printDebugDetails(const char* label) const {
} }
} }
printLog("%s - Voxel at corner=(%f,%f,%f) size=%f\n isLeaf=%s isColored=%s isDirty=%s shouldRender=%s\n children=", label, printLog("%s - Voxel at corner=(%f,%f,%f) size=%f\n isLeaf=%s isColored=%s (%d,%d,%d,%d) isDirty=%s shouldRender=%s\n children=", label,
_box.getCorner().x, _box.getCorner().y, _box.getCorner().z, _box.getSize().x, _box.getCorner().x, _box.getCorner().y, _box.getCorner().z, _box.getSize().x,
debug::valueOf(isLeaf()), debug::valueOf(isColored()), debug::valueOf(isDirty()), debug::valueOf(isLeaf()), debug::valueOf(isColored()), getColor()[0], getColor()[1], getColor()[2], getColor()[3],
debug::valueOf(getShouldRender())); debug::valueOf(isDirty()), debug::valueOf(getShouldRender()));
outputBits(childBits, false); outputBits(childBits, false);
printLog("\n octalCode="); printLog("\n octalCode=");

View file

@ -68,18 +68,18 @@ void VoxelTree::recurseNodeWithOperation(VoxelNode* node,RecurseVoxelTreeOperati
} }
} }
VoxelNode * VoxelTree::nodeForOctalCode(VoxelNode *ancestorNode, unsigned char * needleCode, VoxelNode** parentOfFoundNode) const { VoxelNode * VoxelTree::nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode) const {
// find the appropriate branch index based on this ancestorNode // find the appropriate branch index based on this ancestorNode
if (*needleCode > 0) { if (*needleCode > 0) {
int branchForNeedle = branchIndexWithDescendant(ancestorNode->getOctalCode(), needleCode); int branchForNeedle = branchIndexWithDescendant(ancestorNode->getOctalCode(), needleCode);
VoxelNode *childNode = ancestorNode->getChildAtIndex(branchForNeedle); VoxelNode* childNode = ancestorNode->getChildAtIndex(branchForNeedle);
if (childNode) { if (childNode) {
if (*childNode->getOctalCode() == *needleCode) { if (*childNode->getOctalCode() == *needleCode) {
// If the caller asked for the parent, then give them that too... // If the caller asked for the parent, then give them that too...
if (parentOfFoundNode) { if (parentOfFoundNode) {
*parentOfFoundNode=ancestorNode; *parentOfFoundNode = ancestorNode;
} }
// the fact that the number of sections is equivalent does not always guarantee // the fact that the number of sections is equivalent does not always guarantee
// that this is the same node, however due to the recursive traversal // that this is the same node, however due to the recursive traversal
@ -276,6 +276,9 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool stage, b
nodeToDelete->stageForDeletion(); nodeToDelete->stageForDeletion();
} else { } else {
parentNode->deleteChildAtIndex(childIndex); parentNode->deleteChildAtIndex(childIndex);
if (_shouldReaverage) {
parentNode->setColorFromAverageOfChildren();
}
} }
// If we're not a colored leaf, and we have no children, then delete ourselves // If we're not a colored leaf, and we have no children, then delete ourselves
@ -296,7 +299,9 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool stage, b
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (i != index) { if (i != index) {
ancestorNode->addChildAtIndex(i); ancestorNode->addChildAtIndex(i);
ancestorNode->getChildAtIndex(i)->setColor(nodeToDelete->getColor()); if (nodeToDelete->isColored()) {
ancestorNode->getChildAtIndex(i)->setColor(nodeToDelete->getColor());
}
} }
} }
if (*ancestorNode->getOctalCode() == *codeBuffer - 1) { if (*ancestorNode->getOctalCode() == *codeBuffer - 1) {
@ -304,7 +309,9 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool stage, b
} }
ancestorNode->addChildAtIndex(index); ancestorNode->addChildAtIndex(index);
ancestorNode = ancestorNode->getChildAtIndex(index); ancestorNode = ancestorNode->getChildAtIndex(index);
ancestorNode->setColor(nodeToDelete->getColor()); if (nodeToDelete->isColored()) {
ancestorNode->setColor(nodeToDelete->getColor());
}
} }
_isDirty = true; _isDirty = true;
} }
@ -319,7 +326,6 @@ void VoxelTree::eraseAllVoxels() {
void VoxelTree::readCodeColorBufferToTree(unsigned char *codeColorBuffer, bool destructive) { void VoxelTree::readCodeColorBufferToTree(unsigned char *codeColorBuffer, bool destructive) {
VoxelNode* lastCreatedNode = nodeForOctalCode(rootNode, codeColorBuffer, NULL); VoxelNode* lastCreatedNode = nodeForOctalCode(rootNode, codeColorBuffer, NULL);
// create the node if it does not exist // create the node if it does not exist
if (*lastCreatedNode->getOctalCode() != *codeColorBuffer) { if (*lastCreatedNode->getOctalCode() != *codeColorBuffer) {
lastCreatedNode = createMissingNode(lastCreatedNode, codeColorBuffer); lastCreatedNode = createMissingNode(lastCreatedNode, codeColorBuffer);

View file

@ -51,7 +51,7 @@ const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
const int ENVIRONMENT_SEND_INTERVAL_USECS = 1000000; const int ENVIRONMENT_SEND_INTERVAL_USECS = 1000000;
VoxelTree randomTree(true); // this is a reaveraging tree VoxelTree randomTree(false); // this is NOT a reaveraging tree
bool wantVoxelPersist = true; bool wantVoxelPersist = true;
bool wantLocalDomain = false; bool wantLocalDomain = false;
@ -652,18 +652,19 @@ int main(int argc, const char * argv[]) {
char* command = (char*) &packetData[1]; // start of the command char* command = (char*) &packetData[1]; // start of the command
int commandLength = strlen(command); // commands are null terminated strings int commandLength = strlen(command); // commands are null terminated strings
int totalLength = sizeof(PACKET_HEADER_Z_COMMAND) + commandLength + 1; // 1 for null termination int totalLength = sizeof(PACKET_HEADER_Z_COMMAND) + commandLength + 1; // 1 for null termination
printf("got Z message len(%ld)= %s\n", receivedBytes, command); printf("got Z message len(%ld)= %s\n", receivedBytes, command);
bool rebroadcast = true; // by default rebroadcast
while (totalLength <= receivedBytes) { while (totalLength <= receivedBytes) {
if (strcmp(command, ERASE_ALL_COMMAND) == 0) { if (strcmp(command, ERASE_ALL_COMMAND) == 0) {
printf("got Z message == erase all\n"); printf("got Z message == erase all\n");
eraseVoxelTreeAndCleanupAgentVisitData(); eraseVoxelTreeAndCleanupAgentVisitData();
rebroadcast = false;
} }
if (strcmp(command, ADD_SCENE_COMMAND) == 0) { if (strcmp(command, ADD_SCENE_COMMAND) == 0) {
printf("got Z message == add scene\n"); printf("got Z message == add scene\n");
addSphereScene(&randomTree); addSphereScene(&randomTree);
rebroadcast = false;
} }
if (strcmp(command, TEST_COMMAND) == 0) { if (strcmp(command, TEST_COMMAND) == 0) {
printf("got Z message == a message, nothing to do, just report\n"); printf("got Z message == a message, nothing to do, just report\n");
@ -671,9 +672,11 @@ int main(int argc, const char * argv[]) {
totalLength += commandLength + 1; // 1 for null termination totalLength += commandLength + 1; // 1 for null termination
} }
// Now send this to the connected agents so they can also process these messages if (rebroadcast) {
printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n"); // Now send this to the connected agents so they can also process these messages
agentList->broadcastToAgents(packetData, receivedBytes, &AGENT_TYPE_AVATAR, 1); printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n");
agentList->broadcastToAgents(packetData, receivedBytes, &AGENT_TYPE_AVATAR, 1);
}
} }
// If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_AVATAR, and we // If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_AVATAR, and we
// need to make sure we have it in our agentList. // need to make sure we have it in our agentList.