This commit is contained in:
Andrzej Kapolka 2013-10-25 14:42:43 -07:00
commit 3ebb4e3ba9
9 changed files with 86 additions and 62 deletions

View file

@ -159,26 +159,25 @@ void Agent::run() {
// find the audio-mixer in the NodeList so we can inject audio at it // find the audio-mixer in the NodeList so we can inject audio at it
Node* audioMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); Node* audioMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
if (audioMixer && audioMixer->getActiveSocket()) { if (audioMixer && audioMixer->getActiveSocket()) {
emit willSendAudioDataCallback(); emit willSendAudioDataCallback();
}
if (scriptedAudioInjector.hasSamplesToInject()) { int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * INJECT_INTERVAL_USECS) - usecTimestampNow();
int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * INJECT_INTERVAL_USECS) - usecTimestampNow(); if (usecToSleep > 0) {
if (usecToSleep > 0) { usleep(usecToSleep);
usleep(usecToSleep); }
}
scriptedAudioInjector.injectAudio(NodeList::getInstance()->getNodeSocket(), audioMixer->getActiveSocket()); if (audioMixer && audioMixer->getActiveSocket() && scriptedAudioInjector.hasSamplesToInject()) {
// we have an audio mixer and samples to inject, send those off
scriptedAudioInjector.injectAudio(NodeList::getInstance()->getNodeSocket(), audioMixer->getActiveSocket());
// clear out the audio injector so that it doesn't re-send what we just sent // clear out the audio injector so that it doesn't re-send what we just sent
scriptedAudioInjector.clear(); scriptedAudioInjector.clear();
} }
} else if (audioMixer) {
int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * INJECT_INTERVAL_USECS) - usecTimestampNow();
if (usecToSleep > 0) {
usleep(usecToSleep);
}
if (audioMixer && !audioMixer->getActiveSocket()) {
// don't have an active socket for the audio-mixer, ping it now // don't have an active socket for the audio-mixer, ping it now
NodeList::getInstance()->pingPublicAndLocalSocketsForInactiveNode(audioMixer); NodeList::getInstance()->pingPublicAndLocalSocketsForInactiveNode(audioMixer);
} }

View file

@ -533,6 +533,7 @@ void Application::resetProfile(const QString& username) {
// call the destructor on the old profile and construct a new one // call the destructor on the old profile and construct a new one
(&_profile)->~Profile(); (&_profile)->~Profile();
new (&_profile) Profile(username); new (&_profile) Profile(username);
updateWindowTitle();
} }
void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes,
@ -3790,13 +3791,25 @@ void Application::attachNewHeadToNode(Node* newNode) {
} }
} }
void Application::domainChanged(QString domain) { void Application::updateWindowTitle(){
qDebug("Application title set to: %s.\n", domain.toStdString().c_str()); QString title = "";
_window->setWindowTitle(domain); QString username = _profile.getUsername();
if(!username.isEmpty()){
title += _profile.getUsername();
title += " @ ";
}
title += _profile.getLastDomain();
qDebug("Application title set to: %s.\n", title.toStdString().c_str());
_window->setWindowTitle(title);
}
void Application::domainChanged(QString domain) {
// update the user's last domain in their Profile (which will propagate to data-server) // update the user's last domain in their Profile (which will propagate to data-server)
_profile.updateDomain(domain); _profile.updateDomain(domain);
updateWindowTitle();
// reset the environment so that we don't erroneously end up with multiple // reset the environment so that we don't erroneously end up with multiple
_environment.resetToDefault(); _environment.resetToDefault();
} }

View file

@ -109,6 +109,8 @@ public:
void touchEndEvent(QTouchEvent* event); void touchEndEvent(QTouchEvent* event);
void touchUpdateEvent(QTouchEvent* event); void touchUpdateEvent(QTouchEvent* event);
void updateWindowTitle();
void wheelEvent(QWheelEvent* event); void wheelEvent(QWheelEvent* event);
const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel); const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel);

View file

@ -532,6 +532,7 @@ void Menu::loadSettings(QSettings* settings) {
Application::getInstance()->getAvatar()->loadData(settings); Application::getInstance()->getAvatar()->loadData(settings);
Application::getInstance()->getSwatch()->loadData(settings); Application::getInstance()->getSwatch()->loadData(settings);
Application::getInstance()->getProfile()->loadData(settings); Application::getInstance()->getProfile()->loadData(settings);
Application::getInstance()->updateWindowTitle();
NodeList::getInstance()->loadData(settings); NodeList::getInstance()->loadData(settings);
} }

View file

@ -90,6 +90,7 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
if (dataBuffer[numBytesRead] != '\0') { if (dataBuffer[numBytesRead] != '\0') {
// read the pool from the data buffer // read the pool from the data buffer
setPool((const char*) dataBuffer + numBytesRead); setPool((const char*) dataBuffer + numBytesRead);
numBytesRead += strlen(_pool) + sizeof('\0');
} else { } else {
// skip past the null pool and null out our pool // skip past the null pool and null out our pool
setPool(NULL); setPool(NULL);
@ -192,7 +193,7 @@ int Assignment::packToBuffer(unsigned char* buffer) {
numPackedBytes += NUM_BYTES_RFC4122_UUID; numPackedBytes += NUM_BYTES_RFC4122_UUID;
} }
if (_pool) { if (hasPool()) {
// pack the pool for this assignment, it exists // pack the pool for this assignment, it exists
int numBytesNullTerminatedPool = strlen(_pool) + sizeof('\0'); int numBytesNullTerminatedPool = strlen(_pool) + sizeof('\0');
memcpy(buffer + numPackedBytes, _pool, numBytesNullTerminatedPool); memcpy(buffer + numPackedBytes, _pool, numBytesNullTerminatedPool);

View file

@ -492,10 +492,10 @@ void NodeList::sendDomainServerCheckIn() {
// check in packet has header, optional UUID, node type, port, IP, node types of interest, null termination // check in packet has header, optional UUID, node type, port, IP, node types of interest, null termination
int numPacketBytes = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION) + sizeof(NODE_TYPE) + int numPacketBytes = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION) + sizeof(NODE_TYPE) +
NUM_BYTES_RFC4122_UUID + (2 * (sizeof(uint16_t) + IP_ADDRESS_BYTES)) + NUM_BYTES_RFC4122_UUID + (2 * (sizeof(uint16_t) + IP_ADDRESS_BYTES)) +
numBytesNodesOfInterest + sizeof(unsigned char); numBytesNodesOfInterest + sizeof(unsigned char);
unsigned char* checkInPacket = new unsigned char[numPacketBytes]; unsigned char checkInPacket[numPacketBytes];
unsigned char* packetPosition = checkInPacket; unsigned char* packetPosition = checkInPacket;
PACKET_TYPE nodePacketType = (memchr(SOLO_NODE_TYPES, _ownerType, sizeof(SOLO_NODE_TYPES))) PACKET_TYPE nodePacketType = (memchr(SOLO_NODE_TYPES, _ownerType, sizeof(SOLO_NODE_TYPES)))
@ -534,8 +534,6 @@ void NodeList::sendDomainServerCheckIn() {
_nodeSocket.send(_domainIP.toString().toLocal8Bit().constData(), _domainPort, checkInPacket, _nodeSocket.send(_domainIP.toString().toLocal8Bit().constData(), _domainPort, checkInPacket,
packetPosition - checkInPacket); packetPosition - checkInPacket);
delete[] checkInPacket; // clean up
const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5; const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5;
static unsigned int numDomainCheckins = 0; static unsigned int numDomainCheckins = 0;

View file

@ -74,6 +74,8 @@ bool PacketSender::process() {
// we can determine how many packets we need to send per call to achieve our desired // we can determine how many packets we need to send per call to achieve our desired
// packets per second send rate. // packets per second send rate.
int callsPerSecond = USECS_PER_SECOND / averageCallTime; int callsPerSecond = USECS_PER_SECOND / averageCallTime;
// make sure our number of calls per second doesn't cause a divide by zero
glm::clamp(callsPerSecond, 1, _packetsPerSecond);
packetsPerCall = ceil(_packetsPerSecond / callsPerSecond); packetsPerCall = ceil(_packetsPerSecond / callsPerSecond);
// send at least one packet per call, if we have it // send at least one packet per call, if we have it

View file

@ -351,6 +351,7 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const {
int indexTwo = getNthBit(_childBitmask, 2); int indexTwo = getNthBit(_childBitmask, 2);
if (_childrenExternal) { if (_childrenExternal) {
//assert(_children.external);
if (indexOne == childIndex) { if (indexOne == childIndex) {
result = _children.external[0]; result = _children.external[0];
} else if (indexTwo == childIndex) { } else if (indexTwo == childIndex) {
@ -375,6 +376,7 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const {
int indexThree = getNthBit(_childBitmask, 3); int indexThree = getNthBit(_childBitmask, 3);
if (_childrenExternal) { if (_childrenExternal) {
//assert(_children.external);
if (indexOne == childIndex) { if (indexOne == childIndex) {
result = _children.external[0]; result = _children.external[0];
} else if (indexTwo == childIndex) { } else if (indexTwo == childIndex) {
@ -407,7 +409,12 @@ VoxelNode* VoxelNode::getChildAtIndex(int childIndex) const {
for (int ordinal = 1; ordinal <= childCount; ordinal++) { for (int ordinal = 1; ordinal <= childCount; ordinal++) {
int index = getNthBit(_childBitmask, ordinal); int index = getNthBit(_childBitmask, ordinal);
if (index == childIndex) { if (index == childIndex) {
result = _children.external[ordinal-1]; int externalIndex = ordinal-1;
if (externalIndex < childCount && externalIndex >= 0) {
result = _children.external[externalIndex];
} else {
qDebug("getChildAtIndex() attempt to access external client out of bounds externalIndex=%d <<<<<<<<<< WARNING!!! \n",externalIndex);
}
break; break;
} }
} }
@ -430,9 +437,11 @@ void VoxelNode::storeTwoChildren(VoxelNode* childOne, VoxelNode* childTwo) {
const int64_t minOffset = std::numeric_limits<int32_t>::min(); const int64_t minOffset = std::numeric_limits<int32_t>::min();
const int64_t maxOffset = std::numeric_limits<int32_t>::max(); const int64_t maxOffset = std::numeric_limits<int32_t>::max();
if (isBetween(offsetOne, maxOffset, minOffset) && isBetween(offsetTwo, maxOffset, minOffset)) { bool forceExternal = true;
if (!forceExternal && isBetween(offsetOne, maxOffset, minOffset) && isBetween(offsetTwo, maxOffset, minOffset)) {
// if previously external, then clean it up... // if previously external, then clean it up...
if (_childrenExternal) { if (_childrenExternal) {
//assert(_children.external);
const int previousChildCount = 2; const int previousChildCount = 2;
_externalChildrenMemoryUsage -= previousChildCount * sizeof(VoxelNode*); _externalChildrenMemoryUsage -= previousChildCount * sizeof(VoxelNode*);
delete[] _children.external; delete[] _children.external;
@ -539,7 +548,9 @@ void VoxelNode::storeThreeChildren(VoxelNode* childOne, VoxelNode* childTwo, Vox
const int64_t minOffset = -1048576; // what can fit in 20 bits // std::numeric_limits<int16_t>::min(); const int64_t minOffset = -1048576; // what can fit in 20 bits // std::numeric_limits<int16_t>::min();
const int64_t maxOffset = 1048576; // what can fit in 20 bits // std::numeric_limits<int16_t>::max(); const int64_t maxOffset = 1048576; // what can fit in 20 bits // std::numeric_limits<int16_t>::max();
if (isBetween(offsetOne, maxOffset, minOffset) && bool forceExternal = true;
if (!forceExternal &&
isBetween(offsetOne, maxOffset, minOffset) &&
isBetween(offsetTwo, maxOffset, minOffset) && isBetween(offsetTwo, maxOffset, minOffset) &&
isBetween(offsetThree, maxOffset, minOffset)) { isBetween(offsetThree, maxOffset, minOffset)) {
// if previously external, then clean it up... // if previously external, then clean it up...
@ -601,7 +612,9 @@ void VoxelNode::checkStoreFourChildren(VoxelNode* childOne, VoxelNode* childTwo,
const int64_t minOffset = std::numeric_limits<int16_t>::min(); const int64_t minOffset = std::numeric_limits<int16_t>::min();
const int64_t maxOffset = std::numeric_limits<int16_t>::max(); const int64_t maxOffset = std::numeric_limits<int16_t>::max();
if (isBetween(offsetOne, maxOffset, minOffset) && bool forceExternal = true;
if (!forceExternal &&
isBetween(offsetOne, maxOffset, minOffset) &&
isBetween(offsetTwo, maxOffset, minOffset) && isBetween(offsetTwo, maxOffset, minOffset) &&
isBetween(offsetThree, maxOffset, minOffset) && isBetween(offsetThree, maxOffset, minOffset) &&
isBetween(offsetFour, maxOffset, minOffset) isBetween(offsetFour, maxOffset, minOffset)
@ -720,7 +733,7 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
storeTwoChildren(childOne, childTwo); storeTwoChildren(childOne, childTwo);
} else if (previousChildCount == 2 && newChildCount == 1) { } else if (previousChildCount == 2 && newChildCount == 1) {
// If we had 2 children, and we're removing one, then we know we can go down to single mode // If we had 2 children, and we're removing one, then we know we can go down to single mode
assert(child == NULL); // this is the only logical case //assert(child == NULL); // this is the only logical case
int indexTwo = getNthBit(previousChildMask, 2); int indexTwo = getNthBit(previousChildMask, 2);
bool keepChildOne = indexTwo == childIndex; bool keepChildOne = indexTwo == childIndex;
@ -743,31 +756,19 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
int indexOne = getNthBit(previousChildMask, 1); int indexOne = getNthBit(previousChildMask, 1);
bool replaceChildOne = indexOne == childIndex; bool replaceChildOne = indexOne == childIndex;
// If we previously had an external array, then just replace the right one... that's easy. // Get the existing two children out of their encoding...
if (_childrenExternal) { VoxelNode* childOne;
// technically, we could look to see if these are now in the offsets to handle be encoded, but VoxelNode* childTwo;
// we're going to go ahead and keep this as an array. retrieveTwoChildren(childOne, childTwo);
if (replaceChildOne) {
_children.external[0] = child; if (replaceChildOne) {
} else { childOne = child;
_children.external[1] = child;
}
} else { } else {
// If we were previously encoded as offsets, then we need to see if we can still encode as offsets childTwo = child;
VoxelNode* childOne;
VoxelNode* childTwo;
if (replaceChildOne) {
childOne = child;
childTwo = (VoxelNode*)((uint8_t*)this + _children.offsetsTwoChildren[1]);
} else {
childOne = (VoxelNode*)((uint8_t*)this + _children.offsetsTwoChildren[0]);
childTwo = child;
}
_twoChildrenOffsetCount--; // will end up one or the other
storeTwoChildren(childOne, childTwo);
} }
storeTwoChildren(childOne, childTwo);
} else if (previousChildCount == 2 && newChildCount == 3) { } else if (previousChildCount == 2 && newChildCount == 3) {
// If we had 2 children, and now have 3, then we know we are going to an external case... // If we had 2 children, and now have 3, then we know we are going to an external case...
@ -893,7 +894,7 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
_externalChildrenCount++; _externalChildrenCount++;
} else if (previousChildCount == 4 && newChildCount == 3) { } else if (previousChildCount == 4 && newChildCount == 3) {
// If we had 4 children, and now have 3, then we know we are going from an external case to a potential internal case // If we had 4 children, and now have 3, then we know we are going from an external case to a potential internal case
assert(_childrenExternal); //assert(_children.external && _childrenExternal && previousChildCount == 4);
// We need to determine which children we had, and which one we got rid of... // We need to determine which children we had, and which one we got rid of...
int indexOne = getNthBit(previousChildMask, 1); int indexOne = getNthBit(previousChildMask, 1);
@ -928,10 +929,11 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
_children.external = NULL; _children.external = NULL;
_externalChildrenCount--; _externalChildrenCount--;
_externalChildrenMemoryUsage -= previousChildCount * sizeof(VoxelNode*); _externalChildrenMemoryUsage -= previousChildCount * sizeof(VoxelNode*);
storeThreeChildren(childOne, childTwo, childThree); storeThreeChildren(childOne, childTwo, childThree);
} else if (previousChildCount == newChildCount) { } else if (previousChildCount == newChildCount) {
//assert(_children.external && _childrenExternal && previousChildCount >= 4);
//assert(previousChildCount == newChildCount);
// 4 or more children, one item being replaced, we know we're stored externally, we just need to find the one // 4 or more children, one item being replaced, we know we're stored externally, we just need to find the one
// that needs to be replaced and replace it. // that needs to be replaced and replace it.
for (int ordinal = 1; ordinal <= 8; ordinal++) { for (int ordinal = 1; ordinal <= 8; ordinal++) {
@ -944,6 +946,10 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
} }
} }
} else if (previousChildCount < newChildCount) { } else if (previousChildCount < newChildCount) {
// Growing case... previous must be 4 or greater
//assert(_children.external && _childrenExternal && previousChildCount >= 4);
//assert(previousChildCount == newChildCount-1);
// 4 or more children, one item being added, we know we're stored externally, we just figure out where to insert // 4 or more children, one item being added, we know we're stored externally, we just figure out where to insert
// this child pointer into our external list // this child pointer into our external list
VoxelNode** newExternalList = new VoxelNode*[newChildCount]; VoxelNode** newExternalList = new VoxelNode*[newChildCount];
@ -975,13 +981,16 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
_externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*); _externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*);
} else if (previousChildCount > newChildCount) { } else if (previousChildCount > newChildCount) {
//assert(_children.external && _childrenExternal && previousChildCount >= 4);
//assert(previousChildCount == newChildCount+1);
// 4 or more children, one item being removed, we know we're stored externally, we just figure out which // 4 or more children, one item being removed, we know we're stored externally, we just figure out which
// item to remove from our external list // item to remove from our external list
VoxelNode** newExternalList = new VoxelNode*[newChildCount]; VoxelNode** newExternalList = new VoxelNode*[newChildCount];
for (int ordinal = 1; ordinal <= previousChildCount; ordinal++) { for (int ordinal = 1; ordinal <= previousChildCount; ordinal++) {
int index = getNthBit(previousChildMask, ordinal); int index = getNthBit(previousChildMask, ordinal);
assert(index != -1); //assert(index != -1);
if (index < childIndex) { if (index < childIndex) {
newExternalList[ordinal - 1] = _children.external[ordinal - 1]; newExternalList[ordinal - 1] = _children.external[ordinal - 1];
} else { } else {
@ -997,7 +1006,7 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
_externalChildrenMemoryUsage -= previousChildCount * sizeof(VoxelNode*); _externalChildrenMemoryUsage -= previousChildCount * sizeof(VoxelNode*);
_externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*); _externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*);
} else { } else {
assert(false); //assert(false);
qDebug("THIS SHOULD NOT HAPPEN previousChildCount == %d && newChildCount == %d\n",previousChildCount, newChildCount); qDebug("THIS SHOULD NOT HAPPEN previousChildCount == %d && newChildCount == %d\n",previousChildCount, newChildCount);
} }
@ -1024,7 +1033,6 @@ VoxelNode* VoxelNode::addChildAtIndex(int childIndex) {
childAt = new VoxelNode(childOctalCode(getOctalCode(), childIndex)); childAt = new VoxelNode(childOctalCode(getOctalCode(), childIndex));
childAt->setVoxelSystem(getVoxelSystem()); // our child is always part of our voxel system NULL ok childAt->setVoxelSystem(getVoxelSystem()); // our child is always part of our voxel system NULL ok
setChildAtIndex(childIndex, childAt); setChildAtIndex(childIndex, childAt);
_isDirty = true; _isDirty = true;