latest hacking

This commit is contained in:
ZappoMan 2013-05-20 15:51:47 -07:00
parent 4298b922a2
commit a53f84fcb9
5 changed files with 49 additions and 29 deletions

View file

@ -107,6 +107,10 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()");
// ask the VoxelTree to read the bitstream into the tree
// printLog("PACKET_HEADER_VOXEL_DATA = \n");
// outputBufferBits(sourceBuffer, numBytes);
_tree->readBitstreamToTree(voxelData, numBytes - 1, true, _wantsExistBits);
}
break;

View file

@ -56,8 +56,8 @@ AvatarData::AvatarData() :
_keyState(NO_KEY_DOWN),
_wantResIn(false),
_wantColor(true),
_wantDelta(true),
_wantExistsBits(true)
_wantDelta(false),
_wantExistsBits(false)
{
};

View file

@ -67,6 +67,7 @@ public:
float distanceToPoint(const glm::vec3& point) const;
bool isLeaf() const { return _childCount == 0; }
int getChildCount() const { return _childCount; }
void printDebugDetails(const char* label) const;
bool isDirty() const { return _isDirty; };
void clearDirtyBit() { _isDirty = false; };

View file

@ -102,23 +102,21 @@ VoxelNode* VoxelTree::createMissingNode(VoxelNode* lastParentNode, unsigned char
int indexOfNewChild = branchIndexWithDescendant(lastParentNode->getOctalCode(), codeToReach);
/****
// we could be coming down a branch that was already created, so don't stomp on it.
if (!lastParentNode->getChildAtIndex(indexOfNewChild)) {
lastParentNode->addChildAtIndex(indexOfNewChild);
}
/****
***/
if (lastParentNode->isLeaf() && lastParentNode->isColored()) {
// for colored leaves, we must add *all* the children
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
printLog(">>>>>>>> createMissingNode() add *all* the children - calling addChildAtIndex() at %d <<<<<<<\n",i);
lastParentNode->addChildAtIndex(i);
lastParentNode->getChildAtIndex(i)->setColor(lastParentNode->getColor());
}
} else if (!lastParentNode->getChildAtIndex(indexOfNewChild)) {
lastParentNode->addChildAtIndex(indexOfNewChild);
}
***/
// This works because we know we traversed down the same tree so if the length is the same, then the whole code is the same
if (*lastParentNode->getChildAtIndex(indexOfNewChild)->getOctalCode() == *codeToReach) {
@ -304,15 +302,16 @@ void VoxelTree::deleteVoxelAt(float x, float y, float z, float s, bool stage) {
// Note: uses the codeColorBuffer format, but the color's are ignored, because
// this only finds and deletes the node from the tree.
void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage) {
//printLog(">>>>>>>> deleteVoxelCodeFromTree() <<<<<<<\n");
void VoxelTree::deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool stage) {
VoxelNode* parentNode = NULL;
VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode);
// If the node exists...
int lengthInBytes = bytesRequiredForCodeLength(*codeBuffer); // includes octet count, not color!
if (0 == memcmp(nodeToDelete->getOctalCode(),codeBuffer,lengthInBytes)) {
// if the code we got back matches our target, then we know we can actually delete it
if (0 == memcmp(nodeToDelete->getOctalCode(), codeBuffer, lengthInBytes)) {
if (parentNode) {
int childIndex = branchIndexWithDescendant(parentNode->getOctalCode(), codeBuffer);
@ -322,6 +321,17 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage) {
parentNode->deleteChildAtIndex(childIndex);
}
// ok, also make sure, that if this is the last child of this parent, then we should
// delete the parent also... is that right?
if (parentNode->getChildCount() < 2) {
printLog("deleteVoxelCodeFromTree()... parentNode->getChildCount() = %d\n", parentNode->getChildCount() );
parentNode->printDebugDetails("deleteVoxelCodeFromTree()");
if (parentNode->getChildCount() == 0 && !parentNode->isColored()) {
printLog("deleteVoxelCodeFromTree()... no more children and not colored... deleting parentNode\n" );
deleteVoxelCodeFromTree(parentNode->getOctalCode(),stage);
}
}
reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode
_isDirty = true;
}
@ -332,7 +342,6 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage) {
int index = branchIndexWithDescendant(ancestorNode->getOctalCode(), codeBuffer);
for (int i = 0; i < 8; i++) {
if (i != index) {
//printLog(">>>>>>>> deleteVoxelCodeFromTree() calling addChildAtIndex() at %d <<<<<<<\n",i);
ancestorNode->addChildAtIndex(i);
ancestorNode->getChildAtIndex(i)->setColor(nodeToDelete->getColor());
}
@ -340,7 +349,6 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage) {
if (*ancestorNode->getOctalCode() == *codeBuffer - 1) {
break;
}
//printLog(">>>>>>>> deleteVoxelCodeFromTree() calling addChildAtIndex() at %d <<<<<<<\n",index);
ancestorNode->addChildAtIndex(index);
ancestorNode = ancestorNode->getChildAtIndex(index);
ancestorNode->setColor(nodeToDelete->getColor());
@ -874,6 +882,8 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag,
const ViewFrustum* viewFrustum, bool includeColor, bool includeExistsBits,
bool deltaViewFrustum, const ViewFrustum* lastViewFrustum) const {
//printLog("encodeTreeBitstreamRecursion() currentEncodeLevel=%d\n",currentEncodeLevel);
// How many bytes have we written so far at this level;
int bytesAtThisLevel = 0;
@ -974,13 +984,13 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
bytesAtThisLevel += sizeof(childrenColoredBits); // keep track of byte count
// if the caller wants to include childExistsBits, then include them even if not in view
if (includeExistsBits) {
printLog("includeExistsBits, writing color exists bits...\n");
printLog("childrenColoredBits=");
outputBits(childrenColoredBits);
printLog(" colorsExistInTreeBits=");
outputBits(colorsExistInTreeBits);
printLog(" childrenExistInTreeBits=");
outputBits(childrenExistInTreeBits);
//printLog("includeExistsBits, writing color exists bits...\n");
//printLog("childrenColoredBits=");
//outputBits(childrenColoredBits);
//printLog(" colorsExistInTreeBits=");
//outputBits(colorsExistInTreeBits);
//printLog(" childrenExistInTreeBits=");
//outputBits(childrenExistInTreeBits);
*writeToThisLevelBuffer = colorsExistInTreeBits;
writeToThisLevelBuffer += sizeof(colorsExistInTreeBits); // move the pointer
@ -1001,7 +1011,7 @@ outputBits(childrenExistInTreeBits);
// if the caller wants to include childExistsBits, then include them even if not in view, put them before the
// childrenExistInPacketBits, so that the lower code can properly repair the packet exists bits
if (includeExistsBits) {
printLog("includeExistsBits, writing subtree exists bits\n");
//printLog("includeExistsBits, writing subtree exists bits\n");
*writeToThisLevelBuffer = childrenExistInTreeBits;
writeToThisLevelBuffer += sizeof(childrenExistInTreeBits); // move the pointer
bytesAtThisLevel += sizeof(childrenExistInTreeBits); // keep track of byte count
@ -1068,7 +1078,7 @@ printLog("includeExistsBits, writing subtree exists bits\n");
// we can make this act like no bytes out, by just resetting the bytes out in this case
if (includeColor && childTreeBytesOut == 2) {
childTreeBytesOut = 0; // this is the degenerate case of a tree with no colors and no child trees
printLog("childTreeBytesOut==2.... lopping empty lower tree\n");
//printLog("childTreeBytesOut==2.... lopping empty lower tree\n");
}
bytesAtThisLevel += childTreeBytesOut;
@ -1078,7 +1088,7 @@ printLog("childTreeBytesOut==2.... lopping empty lower tree\n");
// If we had previously started writing, and if the child DIDN'T write any bytes,
// then we want to remove their bit from the childExistsPlaceHolder bitmask
if (childTreeBytesOut == 0) {
printLog("childTreeBytesOut == 0... actually lopping empty lower tree\n");
//printLog("childTreeBytesOut == 0... actually lopping empty lower tree\n");
// remove this child's bit...
childrenExistInPacketBits -= (1 << (7 - i));
// repair the child exists mask

View file

@ -175,8 +175,8 @@ void resInVoxelDistributor(AgentList* agentList,
} else {
agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength());
printf("sending packet...");
outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
//printf("sending packet...");
//outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength();
truePacketsSent++;
packetsSentThisInterval++;
@ -187,8 +187,8 @@ void resInVoxelDistributor(AgentList* agentList,
if (agentData->isPacketWaiting()) {
agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength());
printf("sending packet...");
outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
//printf("sending packet...");
//outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength();
truePacketsSent++;
agentData->resetVoxelPacket();
@ -236,6 +236,8 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
VoxelAgentData* agentData,
bool viewFrustumChanged) {
//printf("deepestLevelVoxelDistributor()\n");
int maxLevelReached = 0;
double start = usecTimestampNow();
@ -254,12 +256,15 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
// If the current view frustum has changed OR we have nothing to send, then search against
// the current view frustum for things to send.
if (viewFrustumChanged || agentData->nodeBag.isEmpty()) {
//printf("bag empty, search for stuff in view...\n");
// If the bag was empty, then send everything in view, not just the delta
maxLevelReached = randomTree.searchForColoredNodes(INT_MAX, randomTree.rootNode, agentData->getCurrentViewFrustum(),
agentData->nodeBag, wantDelta, lastViewFrustum);
// if nothing was found in view, send the root node.
if (agentData->nodeBag.isEmpty()){
//printf("huh... bag STILL empty, what to do? Add the root?...\n");
agentData->nodeBag.insert(randomTree.rootNode);
}
agentData->setViewSent(false);
@ -305,8 +310,8 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength());
printf("sending packet...");
outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
//printf("sending packet...");
//outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength();
truePacketsSent++;
packetsSentThisInterval++;
@ -317,8 +322,8 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
if (agentData->isPacketWaiting()) {
agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength());
printf("sending packet...");
outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
//printf("sending packet...");
//outputBufferBits((unsigned char*)agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength();
truePacketsSent++;
agentData->resetVoxelPacket();