Merge pull request #2135 from ZappoMan/bugfixes

bug fixes
This commit is contained in:
Philip Rosedale 2014-02-27 20:43:48 -08:00
commit bde7152246
5 changed files with 58 additions and 17 deletions

View file

@ -37,6 +37,18 @@ OctreeQueryNode::OctreeQueryNode() :
_sequenceNumber = 0; _sequenceNumber = 0;
} }
OctreeQueryNode::~OctreeQueryNode() {
if (_octreeSendThread) {
_octreeSendThread->terminate();
delete _octreeSendThread;
}
delete[] _octreePacket;
delete[] _lastOctreePacket;
}
void OctreeQueryNode::initializeOctreeSendThread(OctreeServer* octreeServer, const QUuid& nodeUUID) { void OctreeQueryNode::initializeOctreeSendThread(OctreeServer* octreeServer, const QUuid& nodeUUID) {
// Create octree sending thread... // Create octree sending thread...
_octreeSendThread = new OctreeSendThread(nodeUUID, octreeServer); _octreeSendThread = new OctreeSendThread(nodeUUID, octreeServer);
@ -158,16 +170,6 @@ void OctreeQueryNode::writeToPacket(const unsigned char* buffer, int bytes) {
} }
} }
OctreeQueryNode::~OctreeQueryNode() {
if (_octreeSendThread) {
_octreeSendThread->terminate();
delete _octreeSendThread;
}
delete[] _octreePacket;
delete[] _lastOctreePacket;
}
bool OctreeQueryNode::updateCurrentViewFrustum() { bool OctreeQueryNode::updateCurrentViewFrustum() {
bool currentViewFrustumChanged = false; bool currentViewFrustumChanged = false;
ViewFrustum newestViewFrustum; ViewFrustum newestViewFrustum;

View file

@ -20,7 +20,8 @@ quint64 endSceneSleepTime = 0;
OctreeSendThread::OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer) : OctreeSendThread::OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer) :
_nodeUUID(nodeUUID), _nodeUUID(nodeUUID),
_myServer(myServer), _myServer(myServer),
_packetData() _packetData(),
_nodeMissingCount(0)
{ {
qDebug() << "client connected"; qDebug() << "client connected";
_myServer->clientConnected(); _myServer->clientConnected();
@ -33,6 +34,14 @@ OctreeSendThread::~OctreeSendThread() {
bool OctreeSendThread::process() { bool OctreeSendThread::process() {
const int MAX_NODE_MISSING_CHECKS = 10;
if (_nodeMissingCount > MAX_NODE_MISSING_CHECKS) {
qDebug() << "our target node:" << _nodeUUID << "has been missing the last" << _nodeMissingCount
<< "times we checked, we are going to stop attempting to send.";
return false; // stop processing and shutdown, our node no longer exists
}
quint64 start = usecTimestampNow(); quint64 start = usecTimestampNow();
bool gotLock = false; bool gotLock = false;
@ -41,6 +50,7 @@ bool OctreeSendThread::process() {
SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(_nodeUUID); SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);
if (node) { if (node) {
_nodeMissingCount = 0;
// make sure the node list doesn't kill our node while we're using it // make sure the node list doesn't kill our node while we're using it
if (node->getMutex().tryLock()) { if (node->getMutex().tryLock()) {
gotLock = true; gotLock = true;
@ -61,6 +71,8 @@ bool OctreeSendThread::process() {
node->getMutex().unlock(); // we're done with this node for now. node->getMutex().unlock(); // we're done with this node for now.
} }
} else {
_nodeMissingCount++;
} }
} else { } else {
if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) { if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) {

View file

@ -16,6 +16,7 @@
#include "OctreeQueryNode.h" #include "OctreeQueryNode.h"
#include "OctreeServer.h" #include "OctreeServer.h"
/// Threaded processor for sending voxel packets to a single client /// Threaded processor for sending voxel packets to a single client
class OctreeSendThread : public GenericThread { class OctreeSendThread : public GenericThread {
public: public:
@ -41,6 +42,8 @@ private:
int packetDistributor(const SharedNodePointer& node, OctreeQueryNode* nodeData, bool viewFrustumChanged); int packetDistributor(const SharedNodePointer& node, OctreeQueryNode* nodeData, bool viewFrustumChanged);
OctreePacketData _packetData; OctreePacketData _packetData;
int _nodeMissingCount;
}; };
#endif // __octree_server__OctreeSendThread__ #endif // __octree_server__OctreeSendThread__

View file

@ -56,6 +56,7 @@ Menu* Menu::getInstance() {
const ViewFrustumOffset DEFAULT_FRUSTUM_OFFSET = {-135.0f, 0.0f, 0.0f, 25.0f, 0.0f}; const ViewFrustumOffset DEFAULT_FRUSTUM_OFFSET = {-135.0f, 0.0f, 0.0f, 25.0f, 0.0f};
const float DEFAULT_FACESHIFT_EYE_DEFLECTION = 0.25f; const float DEFAULT_FACESHIFT_EYE_DEFLECTION = 0.25f;
const int FIVE_SECONDS_OF_FRAMES = 5 * 60;
Menu::Menu() : Menu::Menu() :
_actionHash(), _actionHash(),
@ -72,6 +73,7 @@ Menu::Menu() :
_boundaryLevelAdjust(0), _boundaryLevelAdjust(0),
_maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS),
_lastAdjust(usecTimestampNow()), _lastAdjust(usecTimestampNow()),
_fpsAverage(FIVE_SECONDS_OF_FRAMES),
_loginAction(NULL) _loginAction(NULL)
{ {
Application *appInstance = Application::getInstance(); Application *appInstance = Application::getInstance();
@ -1105,22 +1107,43 @@ void Menu::voxelStatsDetailsClosed() {
} }
void Menu::autoAdjustLOD(float currentFPS) { void Menu::autoAdjustLOD(float currentFPS) {
// NOTE: our first ~100 samples at app startup are completely all over the place, and we don't
// really want to count them in our average, so we will ignore the real frame rates and stuff
// our moving average with simulated good data
const int IGNORE_THESE_SAMPLES = 100;
const float ASSUMED_FPS = 60.0f;
if (_fpsAverage.getSampleCount() < IGNORE_THESE_SAMPLES) {
currentFPS = ASSUMED_FPS;
}
_fpsAverage.updateAverage(currentFPS);
bool changed = false; bool changed = false;
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
quint64 elapsed = now - _lastAdjust; quint64 elapsed = now - _lastAdjust;
if (elapsed > ADJUST_LOD_DOWN_DELAY && currentFPS < ADJUST_LOD_DOWN_FPS && _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS
&& _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
_voxelSizeScale *= ADJUST_LOD_DOWN_BY; _voxelSizeScale *= ADJUST_LOD_DOWN_BY;
if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
_voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
}
changed = true; changed = true;
_lastAdjust = now; _lastAdjust = now;
qDebug() << "adjusting LOD down... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale; qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
<< "_voxelSizeScale=" << _voxelSizeScale;
} }
if (elapsed > ADJUST_LOD_UP_DELAY && currentFPS > ADJUST_LOD_UP_FPS && _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS
&& _voxelSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
_voxelSizeScale *= ADJUST_LOD_UP_BY; _voxelSizeScale *= ADJUST_LOD_UP_BY;
if (_voxelSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
_voxelSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
}
changed = true; changed = true;
_lastAdjust = now; _lastAdjust = now;
qDebug() << "adjusting LOD up... currentFPS=" << currentFPS << "_voxelSizeScale=" << _voxelSizeScale; qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
<< "_voxelSizeScale=" << _voxelSizeScale;
} }
if (changed) { if (changed) {

View file

@ -27,7 +27,7 @@ const quint64 ADJUST_LOD_UP_DELAY = ADJUST_LOD_DOWN_DELAY * 2;
const float ADJUST_LOD_DOWN_BY = 0.9f; const float ADJUST_LOD_DOWN_BY = 0.9f;
const float ADJUST_LOD_UP_BY = 1.1f; const float ADJUST_LOD_UP_BY = 1.1f;
const float ADJUST_LOD_MIN_SIZE_SCALE = TREE_SCALE * 1.0f; const float ADJUST_LOD_MIN_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE * 0.25f;
const float ADJUST_LOD_MAX_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE; const float ADJUST_LOD_MAX_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE;
enum FrustumDrawMode { enum FrustumDrawMode {
@ -193,6 +193,7 @@ private:
QMenu* _activeScriptsMenu; QMenu* _activeScriptsMenu;
QString replaceLastOccurrence(QChar search, QChar replace, QString string); QString replaceLastOccurrence(QChar search, QChar replace, QString string);
quint64 _lastAdjust; quint64 _lastAdjust;
SimpleMovingAverage _fpsAverage;
QAction* _loginAction; QAction* _loginAction;
}; };