fix stutter on rotating

This commit is contained in:
ZappoMan 2013-11-03 21:11:08 -08:00
parent c18de72dd4
commit 9bd27e2b2a
3 changed files with 65 additions and 34 deletions

View file

@ -1306,7 +1306,10 @@ static glm::vec3 getFaceVector(BoxFace face) {
}
void Application::idle() {
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
// Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing
// details if we're in ExtraDebugging mode. However, the ::update() and it's subcomponents will show their timing
// details normally.
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging);
PerformanceWarning warn(showWarnings, "Application::idle()");
timeval check;
@ -1996,7 +1999,7 @@ void Application::updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin,
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels()");
// If we have clicked on a voxel, update it's color
if (_isHoverVoxelSounding) {
VoxelNode* hoveredNode = _voxels.getVoxelAt(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s);
@ -2018,14 +2021,23 @@ void Application::updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin,
} else {
// Check for a new hover voxel
glm::vec4 oldVoxel(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s);
_isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face);
if (MAKE_SOUND_ON_VOXEL_HOVER && _isHoverVoxel && glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) {
_hoverVoxelOriginalColor[0] = _hoverVoxel.red;
_hoverVoxelOriginalColor[1] = _hoverVoxel.green;
_hoverVoxelOriginalColor[2] = _hoverVoxel.blue;
_hoverVoxelOriginalColor[3] = 1;
_audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY);
_isHoverVoxelSounding = true;
// only do this work if MAKE_SOUND_ON_VOXEL_HOVER or MAKE_SOUND_ON_VOXEL_CLICK is enabled,
// and make sure the tree is not already busy... because otherwise you'll have to wait.
if (!_voxels.treeIsBusy()) {
{
PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels() _voxels.findRayIntersection()");
_isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face);
}
if (MAKE_SOUND_ON_VOXEL_HOVER && _isHoverVoxel &&
glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) {
_hoverVoxelOriginalColor[0] = _hoverVoxel.red;
_hoverVoxelOriginalColor[1] = _hoverVoxel.green;
_hoverVoxelOriginalColor[2] = _hoverVoxel.blue;
_hoverVoxelOriginalColor[3] = 1;
_audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY);
_isHoverVoxelSounding = true;
}
}
}
}

View file

@ -110,6 +110,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels)
_culledOnce = false;
_inhideOutOfView = false;
_treeIsBusy = false;
}
void VoxelSystem::voxelDeleted(VoxelNode* node) {
@ -595,9 +596,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
"readBitstreamToTree()");
// ask the VoxelTree to read the bitstream into the tree
ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
pthread_mutex_unlock(&_treeLock);
unlockTree();
}
break;
case PACKET_TYPE_VOXEL_DATA_MONOCHROME: {
@ -605,9 +606,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
"readBitstreamToTree()");
// ask the VoxelTree to read the MONOCHROME bitstream into the tree
ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
pthread_mutex_unlock(&_treeLock);
unlockTree();
}
break;
case PACKET_TYPE_Z_COMMAND:
@ -1002,7 +1003,9 @@ int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool force
// not render these Voxels. We need to think about ways to keep the entire scene intact but maybe lower quality
// possibly shifting down to lower LOD or something. This debug message is to help identify, if/when/how this
// state actually occurs.
qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n");
if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) {
qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n");
}
return 0;
}
@ -1405,9 +1408,9 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) {
int VoxelSystem::_nodeCount = 0;
void VoxelSystem::killLocalVoxels() {
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->eraseAllVoxels();
pthread_mutex_unlock(&_treeLock);
unlockTree();
clearFreeBufferIndexes();
_voxelsInReadArrays = 0; // do we need to do this?
setupNewVoxelsForDrawing();
@ -1426,9 +1429,9 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(VoxelNode* node, void* extra
void VoxelSystem::clearAllNodesBufferIndex() {
_nodeCount = 0;
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation);
pthread_mutex_unlock(&_treeLock);
unlockTree();
if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
qDebug("clearing buffer index of %d nodes\n", _nodeCount);
}
@ -1916,9 +1919,9 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) {
return;
}
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args);
pthread_mutex_unlock(&_treeLock);
unlockTree();
_lastCulledViewFrustum = args.thisViewFrustum; // save last stable
_culledOnce = true;
@ -2107,10 +2110,10 @@ bool VoxelSystem::hideOutOfViewOperation(VoxelNode* node, void* extraData) {
bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelDetail& detail, float& distance, BoxFace& face) {
pthread_mutex_lock(&_treeLock);
lockTree();
VoxelNode* node;
if (!_tree->findRayIntersection(origin, direction, node, distance, face)) {
pthread_mutex_unlock(&_treeLock);
unlockTree();
return false;
}
detail.x = node->getCorner().x;
@ -2120,21 +2123,21 @@ bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3&
detail.red = node->getColor()[0];
detail.green = node->getColor()[1];
detail.blue = node->getColor()[2];
pthread_mutex_unlock(&_treeLock);
unlockTree();
return true;
}
bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) {
pthread_mutex_lock(&_treeLock);
lockTree();
bool result = _tree->findSpherePenetration(center, radius, penetration);
pthread_mutex_unlock(&_treeLock);
unlockTree();
return result;
}
bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) {
pthread_mutex_lock(&_treeLock);
lockTree();
bool result = _tree->findCapsulePenetration(start, end, radius, penetration);
pthread_mutex_unlock(&_treeLock);
unlockTree();
return result;
}
@ -2308,9 +2311,9 @@ void VoxelSystem::collectStatsForTreesAndVBOs() {
void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->deleteVoxelAt(x, y, z, s);
pthread_mutex_unlock(&_treeLock);
unlockTree();
// redraw!
setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
@ -2325,9 +2328,9 @@ void VoxelSystem::createVoxel(float x, float y, float z, float s,
unsigned char red, unsigned char green, unsigned char blue, bool destructive) {
//qDebug("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s);
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->createVoxel(x, y, z, s, red, green, blue, destructive);
pthread_mutex_unlock(&_treeLock);
unlockTree();
setupNewVoxelsForDrawing();
};
@ -2650,9 +2653,9 @@ void VoxelSystem::nodeKilled(Node* node) {
if (_voxelServerCount > 0) {
// Kill any voxels from the local tree that match this nodeID
// commenting out for removal of 16 bit node IDs
pthread_mutex_lock(&_treeLock);
lockTree();
_tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeUUID);
pthread_mutex_unlock(&_treeLock);
unlockTree();
_tree->setDirtyBit();
setupNewVoxelsForDrawing();
} else {
@ -2720,5 +2723,15 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() {
return (_initialMemoryUsageGPU - currentFreeMemory);
}
void VoxelSystem::lockTree() {
pthread_mutex_lock(&_treeLock);
_treeIsBusy = true;
}
void VoxelSystem::unlockTree() {
_treeIsBusy = false;
pthread_mutex_unlock(&_treeLock);
}

View file

@ -120,6 +120,8 @@ public:
virtual void nodeKilled(Node* node);
virtual void domainChanged(QString domain);
bool treeIsBusy() const { return _treeIsBusy; }
signals:
void importSize(float x, float y, float z);
void importProgress(int progress);
@ -302,6 +304,10 @@ private:
bool _useFastVoxelPipeline;
bool _inhideOutOfView;
bool _treeIsBusy; // is the tree mutex locked? if so, it's busy, and if you can avoid it, don't access the tree
void lockTree();
void unlockTree();
};
#endif