diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index ae2be64880..e305972679 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -36,7 +36,7 @@ AvatarMixer::AvatarMixer(const QByteArray& packet) : } void attachAvatarDataToNode(Node* newNode) { - if (newNode->getLinkedData() == NULL) { + if (!newNode->getLinkedData()) { newNode->setLinkedData(new AvatarMixerClientData()); } } diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index c384c95176..c31beb7831 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -26,7 +26,7 @@ SimpleMovingAverage OctreeServer::_averageTreeWaitTime(10000); SimpleMovingAverage OctreeServer::_averageNodeWaitTime(10000); void OctreeServer::attachQueryNodeToNode(Node* newNode) { - if (newNode->getLinkedData() == NULL) { + if (!newNode->getLinkedData()) { OctreeQueryNode* newQueryNodeData = _instance->createOctreeQueryNode(); newQueryNodeData->resetOctreePacket(true); // don't bump sequence newNode->setLinkedData(newQueryNodeData); @@ -716,7 +716,7 @@ void OctreeServer::run() { strftime(localBuffer, MAX_TIME_LENGTH, "%m/%d/%Y %X", localtm); // Convert now to tm struct for UTC tm* gmtm = gmtime(&_started); - if (gmtm != NULL) { + if (gmtm) { strftime(utcBuffer, MAX_TIME_LENGTH, " [%m/%d/%Y %X UTC]", gmtm); } qDebug() << "Now running... started at: " << localBuffer << utcBuffer; diff --git a/examples/bot.js b/examples/bot.js index 89b66aa357..a3ae7f3263 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -3,7 +3,7 @@ // hifi // // Created by Stephen Birarda on 2/20/14. -// Modified by Philip on 2/26/14 +// Modified by Philip on 3/3/14 // Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // // This is an example script that demonstrates an NPC avatar. @@ -27,76 +27,32 @@ var isMoving = false; var isTurningHead = false; var isPlayingAudio = false; -var STARTING_RANGE = 18.0; -var MAX_RANGE = 25.0; +var X_MIN = 0.0; +var X_MAX = 5.0; +var Z_MIN = 0.0; +var Z_MAX = 5.0; + var MOVE_RANGE_SMALL = 0.5; -var MOVE_RANGE_BIG = 5.0; -var TURN_RANGE = 45.0; +var MOVE_RANGE_BIG = Math.max(X_MAX - X_MIN, Z_MAX - Z_MIN) / 2.0; +var TURN_RANGE = 70.0; var STOP_TOLERANCE = 0.05; var MOVE_RATE = 0.05; var TURN_RATE = 0.15; var PITCH_RATE = 0.20; var PITCH_RANGE = 30.0; - -var firstPosition = { x: getRandomFloat(0, STARTING_RANGE), y: 0, z: getRandomFloat(0, STARTING_RANGE) }; +var firstPosition = { x: getRandomFloat(X_MIN, X_MAX), y: 0, z: getRandomFloat(Z_MIN, Z_MAX) }; var targetPosition = { x: 0, y: 0, z: 0 }; - var targetDirection = { x: 0, y: 0, z: 0, w: 0 }; var currentDirection = { x: 0, y: 0, z: 0, w: 0 }; - var targetHeadPitch = 0.0; var sounds = []; -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/AB1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Anchorman2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/B1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/B1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Bale1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Bandcamp.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Big1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Big2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Brian1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Buster1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES3.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES4.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Carrie1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Carrie3.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Charlotte1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/EN1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/EN2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/EN3.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Eugene1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Francesco1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Italian1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Japanese1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Leigh1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Lucille1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Lucille2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/MeanGirls.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Murray2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Nigel1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/PennyLane.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Pitt1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Ricardo.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/SN.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Sake1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Samantha1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Samantha2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Spicoli1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Supernatural.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Swearengen1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/TheDude.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Tony.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Triumph1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Uma1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Walken1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Walken2.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Z1.raw")); -sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Z2.raw")); +loadSounds(); +function clamp(val, min, max){ + return Math.max(min, Math.min(max, val)) +} // Play a random sound from a list of conversational audio clips function audioDone() { @@ -152,6 +108,10 @@ function updateBehavior() { playRandomSound(Avatar.position); } + if (isPlayingAudio) { + Avatar.handPosition = Vec3.sum(Avatar.position, Quat.getFront(Avatar.orientation)); + } + if (!isTurningHead && (Math.random() < CHANCE_OF_HEAD_TURNING)) { targetHeadPitch = getRandomFloat(-PITCH_RANGE, PITCH_RANGE); isTurningHead = true; @@ -170,6 +130,9 @@ function updateBehavior() { } else { targetPosition = Vec3.sum(Avatar.position, Vec3.multiply(front, getRandomFloat(0.0, MOVE_RANGE_SMALL))); } + targetPosition.x = clamp(targetPosition.x, X_MIN, X_MAX); + targetPosition.z = clamp(targetPosition.z, Z_MIN, Z_MAX); + isMoving = true; } else { Avatar.position = Vec3.sum(Avatar.position, Vec3.multiply(Vec3.subtract(targetPosition, Avatar.position), MOVE_RATE)); @@ -178,10 +141,56 @@ function updateBehavior() { isMoving = false; } } - if (Vec3.length(Avatar.position) > MAX_RANGE) { - // Don't let our happy little person get out of the cage - isMoving = false; - Avatar.position = { x: 0, y: 0, z: 0 }; - } } Script.willSendVisualDataCallback.connect(updateBehavior); + +function loadSounds() { + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/AB1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Anchorman2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/B1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/B1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Bale1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Bandcamp.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Big1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Big2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Brian1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Buster1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES3.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/CES4.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Carrie1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Carrie3.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Charlotte1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/EN1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/EN2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/EN3.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Eugene1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Francesco1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Italian1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Japanese1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Leigh1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Lucille1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Lucille2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/MeanGirls.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Murray2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Nigel1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/PennyLane.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Pitt1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Ricardo.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/SN.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Sake1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Samantha1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Samantha2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Spicoli1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Supernatural.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Swearengen1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/TheDude.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Tony.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Triumph1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Uma1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Walken1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Walken2.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Z1.raw")); + sounds.push(new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Raws/Z2.raw")); +} diff --git a/examples/editVoxels.js b/examples/editVoxels.js index cfea508912..f3e3fcf46e 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -945,19 +945,32 @@ function setupMenus() { // hook up menus Menu.menuItemEvent.connect(menuItemEvent); - // delete the standard application menu item - Menu.addSeparator("Edit", "Voxels"); + // add our menuitems + Menu.addMenuItem({ menuName: "Edit", menuItemName: "Voxels", isSeparator: true, beforeItem: "Physics" }); Menu.addMenuItem({ menuName: "Edit", menuItemName: "Cut", shortcutKey: "CTRL+X", afterItem: "Voxels" }); Menu.addMenuItem({ menuName: "Edit", menuItemName: "Copy", shortcutKey: "CTRL+C", afterItem: "Cut" }); Menu.addMenuItem({ menuName: "Edit", menuItemName: "Paste", shortcutKey: "CTRL+V", afterItem: "Copy" }); Menu.addMenuItem({ menuName: "Edit", menuItemName: "Nudge", shortcutKey: "CTRL+N", afterItem: "Paste" }); Menu.addMenuItem({ menuName: "Edit", menuItemName: "Delete", shortcutKeyEvent: { text: "backspace" }, afterItem: "Nudge" }); - Menu.addSeparator("File", "Voxels"); + Menu.addMenuItem({ menuName: "File", menuItemName: "Voxels", isSeparator: true, beforeItem: "Settings" }); Menu.addMenuItem({ menuName: "File", menuItemName: "Export Voxels", shortcutKey: "CTRL+E", afterItem: "Voxels" }); Menu.addMenuItem({ menuName: "File", menuItemName: "Import Voxels", shortcutKey: "CTRL+I", afterItem: "Export Voxels" }); } +function cleanupMenus() { + // delete our menuitems + Menu.removeSeparator("Edit", "Voxels"); + Menu.removeMenuItem("Edit", "Cut"); + Menu.removeMenuItem("Edit", "Copy"); + Menu.removeMenuItem("Edit", "Paste"); + Menu.removeMenuItem("Edit", "Nudge"); + Menu.removeMenuItem("Edit", "Delete"); + Menu.removeSeparator("File", "Voxels"); + Menu.removeMenuItem("File", "Export Voxels"); + Menu.removeMenuItem("File", "Import Voxels"); +} + function menuItemEvent(menuItem) { // handle clipboard items @@ -1382,6 +1395,7 @@ function scriptEnding() { Overlays.deleteOverlay(thumb); Controller.releaseKeyEvents({ text: "+" }); Controller.releaseKeyEvents({ text: "-" }); + cleanupMenus(); } Script.scriptEnding.connect(scriptEnding); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f33c7aea32..8c865f906c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -358,6 +358,8 @@ Application::~Application() { _myAvatar = NULL; delete _glWidget; + + AccountManager::getInstance().destroy(); } void Application::restoreSizeAndPosition() { @@ -1146,7 +1148,7 @@ void Application::dropEvent(QDropEvent *event) { } SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); - if (snapshotData != NULL) { + if (snapshotData) { if (!snapshotData->getDomain().isEmpty()) { Menu::getInstance()->goToDomain(snapshotData->getDomain()); } @@ -1940,7 +1942,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { // only send to the NodeTypes that are serverType - if (node->getActiveSocket() != NULL && node->getType() == serverType) { + if (node->getActiveSocket() && node->getType() == serverType) { totalServers++; // get the server bounds for this server @@ -2000,7 +2002,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { // only send to the NodeTypes that are serverType - if (node->getActiveSocket() != NULL && node->getType() == serverType) { + if (node->getActiveSocket() && node->getType() == serverType) { // get the server bounds for this server diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index dc87cefb05..8c6cdacae1 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -509,9 +509,24 @@ void Menu::handleViewFrustumOffsetKeyModifier(int key) { } } -void Menu::addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName) { - destinationMenu->addSeparator(); - (destinationMenu->addAction(actionName))->setEnabled(false); +void Menu::addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, int menuItemLocation) { + QAction* actionBefore = NULL; + if (menuItemLocation >= 0 && destinationMenu->actions().size() > menuItemLocation) { + actionBefore = destinationMenu->actions()[menuItemLocation]; + } + if (actionBefore) { + QAction* separator = new QAction("",destinationMenu); + destinationMenu->insertAction(actionBefore, separator); + separator->setSeparator(true); + + QAction* separatorText = new QAction(actionName,destinationMenu); + separatorText->setEnabled(false); + destinationMenu->insertAction(actionBefore, separatorText); + + } else { + destinationMenu->addSeparator(); + (destinationMenu->addAction(actionName))->setEnabled(false); + } } QAction* Menu::addActionToQMenuAndActionHash(QMenu* destinationMenu, @@ -572,7 +587,10 @@ void Menu::removeAction(QMenu* menu, const QString& actionName) { } void Menu::setIsOptionChecked(const QString& menuOption, bool isChecked) { - return _actionHash.value(menuOption)->setChecked(isChecked); + QAction* menu = _actionHash.value(menuOption); + if (menu) { + menu->setChecked(isChecked); + } } bool Menu::isOptionChecked(const QString& menuOption) { @@ -1243,6 +1261,18 @@ int Menu::findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem) { return UNSPECIFIED_POSITION; // not found } +int Menu::positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition) { + QList menuActions = menu->actions(); + if (requestedPosition > 1 && requestedPosition < menuActions.size()) { + QAction* beforeRequested = menuActions[requestedPosition - 1]; + if (beforeRequested->isSeparator()) { + requestedPosition--; + } + } + return requestedPosition; +} + + QMenu* Menu::addMenu(const QString& menuName) { QStringList menuTree = menuName.split(">"); QMenu* addTo = NULL; @@ -1288,6 +1318,21 @@ void Menu::addSeparator(const QString& menuName, const QString& separatorName) { } } +void Menu::removeSeparator(const QString& menuName, const QString& separatorName) { + QMenu* menu = getMenu(menuName); + if (menu) { + int textAt = findPositionOfMenuItem(menu, separatorName); + QList menuActions = menu->actions(); + QAction* separatorText = menuActions[textAt]; + QAction* separatorLine = menuActions[textAt - 1]; + if (separatorLine->isSeparator()) { + menu->removeAction(separatorText); + menu->removeAction(separatorLine); + } + } + QMenuBar::repaint(); +} + void Menu::addMenuItem(const MenuItemProperties& properties) { QMenu* menuObj = getMenu(properties.menuName); if (menuObj) { @@ -1300,6 +1345,8 @@ void Menu::addMenuItem(const MenuItemProperties& properties) { int requestedPosition = properties.position; if (requestedPosition == UNSPECIFIED_POSITION && !properties.beforeItem.isEmpty()) { requestedPosition = findPositionOfMenuItem(menuObj, properties.beforeItem); + // double check that the requested location wasn't a separator label + requestedPosition = positionBeforeSeparatorIfNeeded(menuObj, requestedPosition); } if (requestedPosition == UNSPECIFIED_POSITION && !properties.afterItem.isEmpty()) { int afterPosition = findPositionOfMenuItem(menuObj, properties.afterItem); @@ -1308,9 +1355,11 @@ void Menu::addMenuItem(const MenuItemProperties& properties) { } } - QAction* menuItemAction; - if (properties.isCheckable) { - menuItemAction = addCheckableActionToQMenuAndActionHash(menuObj, properties.menuItemName, + QAction* menuItemAction = NULL; + if (properties.isSeparator) { + addDisabledActionAndSeparator(menuObj, properties.menuItemName, requestedPosition); + } else if (properties.isCheckable) { + menuItemAction = addCheckableActionToQMenuAndActionHash(menuObj, properties.menuItemName, properties.shortcutKeySequence, properties.isChecked, MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), requestedPosition); } else { @@ -1318,7 +1367,7 @@ void Menu::addMenuItem(const MenuItemProperties& properties) { MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), QAction::NoRole, requestedPosition); } - if (shortcut) { + if (shortcut && menuItemAction) { connect(shortcut, SIGNAL(activated()), menuItemAction, SLOT(trigger())); } QMenuBar::repaint(); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 7b4cca3b33..9d4c7eaab9 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -124,6 +124,7 @@ public slots: QMenu* addMenu(const QString& menuName); void removeMenu(const QString& menuName); void addSeparator(const QString& menuName, const QString& separatorName); + void removeSeparator(const QString& menuName, const QString& separatorName); void addMenuItem(const MenuItemProperties& properties); void removeMenuItem(const QString& menuName, const QString& menuitem); @@ -152,7 +153,8 @@ private: void scanMenu(QMenu* menu, settingsAction modifySetting, QSettings* set); /// helper method to have separators with labels that are also compatible with OS X - void addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName); + void addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, + int menuItemLocation = UNSPECIFIED_POSITION); QAction* addCheckableActionToQMenuAndActionHash(QMenu* destinationMenu, const QString& actionName, @@ -172,6 +174,7 @@ private: QAction* getMenuAction(const QString& menuName); int findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem); + int positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition); QMenu* getMenu(const QString& menuName); diff --git a/interface/src/MenuScriptingInterface.cpp b/interface/src/MenuScriptingInterface.cpp index f1a44422b3..ccb3fe5eb9 100644 --- a/interface/src/MenuScriptingInterface.cpp +++ b/interface/src/MenuScriptingInterface.cpp @@ -38,6 +38,12 @@ void MenuScriptingInterface::addSeparator(const QString& menuName, const QString Q_ARG(const QString&, separatorName)); } +void MenuScriptingInterface::removeSeparator(const QString& menuName, const QString& separatorName) { + QMetaObject::invokeMethod(Menu::getInstance(), "removeSeparator", + Q_ARG(const QString&, menuName), + Q_ARG(const QString&, separatorName)); +} + void MenuScriptingInterface::addMenuItem(const MenuItemProperties& properties) { QMetaObject::invokeMethod(Menu::getInstance(), "addMenuItem", Q_ARG(const MenuItemProperties&, properties)); } diff --git a/interface/src/MenuScriptingInterface.h b/interface/src/MenuScriptingInterface.h index 7379f2c00b..a4496e3054 100644 --- a/interface/src/MenuScriptingInterface.h +++ b/interface/src/MenuScriptingInterface.h @@ -32,6 +32,7 @@ public slots: void removeMenu(const QString& menuName); void addSeparator(const QString& menuName, const QString& separatorName); + void removeSeparator(const QString& menuName, const QString& separatorName); void addMenuItem(const MenuItemProperties& properties); void addMenuItem(const QString& menuName, const QString& menuitem, const QString& shortcutKey); diff --git a/interface/src/ParticleTreeRenderer.cpp b/interface/src/ParticleTreeRenderer.cpp index d9d0849c94..59784c8c1f 100644 --- a/interface/src/ParticleTreeRenderer.cpp +++ b/interface/src/ParticleTreeRenderer.cpp @@ -33,10 +33,7 @@ void ParticleTreeRenderer::init() { void ParticleTreeRenderer::update() { if (_tree) { ParticleTree* tree = static_cast(_tree); - if (tree->tryLockForWrite()) { - tree->update(); - tree->unlock(); - } + tree->update(); } } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index d537b86854..7ada8b0764 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -135,10 +135,10 @@ void Avatar::simulate(float deltaTime) { getHand()->simulate(deltaTime, false); _skeletonModel.setLODDistance(getLODDistance()); - _skeletonModel.simulate(deltaTime, _shouldRenderBillboard); - glm::vec3 headPosition; - if (!_skeletonModel.getHeadPosition(headPosition)) { - headPosition = _position; + glm::vec3 headPosition = _position; + if (!_shouldRenderBillboard) { + _skeletonModel.simulate(deltaTime); + _skeletonModel.getHeadPosition(headPosition); } Head* head = getHead(); head->setPosition(headPosition); diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 91cf3ab07f..74bf983eb1 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -58,7 +58,7 @@ void Head::reset() { -void Head::simulate(float deltaTime, bool isMine, bool delayLoad) { +void Head::simulate(float deltaTime, bool isMine, bool billboard) { // Update audio trailing average for rendering facial animations Faceshift* faceshift = Application::getInstance()->getFaceshift(); @@ -75,7 +75,7 @@ void Head::simulate(float deltaTime, bool isMine, bool delayLoad) { } } - if (!_isFaceshiftConnected) { + if (!(_isFaceshiftConnected || billboard)) { // Update eye saccades const float AVERAGE_MICROSACCADE_INTERVAL = 0.50f; const float AVERAGE_SACCADE_INTERVAL = 4.0f; @@ -161,11 +161,10 @@ void Head::simulate(float deltaTime, bool isMine, bool delayLoad) { if (!isMine) { _faceModel.setLODDistance(static_cast(_owningAvatar)->getLODDistance()); } - _faceModel.simulate(deltaTime, delayLoad); - - // the blend face may have custom eye meshes - if (!_faceModel.getEyePositions(_leftEyePosition, _rightEyePosition)) { - _leftEyePosition = _rightEyePosition = getPosition(); + _leftEyePosition = _rightEyePosition = getPosition(); + if (!billboard) { + _faceModel.simulate(deltaTime); + _faceModel.getEyePositions(_leftEyePosition, _rightEyePosition); } _eyePosition = calculateAverageEyePosition(); } diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 5c8e1e8769..7e7a96a3a7 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -36,7 +36,7 @@ public: void init(); void reset(); - void simulate(float deltaTime, bool isMine, bool delayLoad = false); + void simulate(float deltaTime, bool isMine, bool billboard = false); void render(float alpha); void setScale(float scale); void setPosition(glm::vec3 position) { _position = position; } diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index cbaa5c4829..967f803d61 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -105,13 +105,13 @@ void GlowEffect::end() { } static void maybeBind(QOpenGLFramebufferObject* fbo) { - if (fbo != NULL) { + if (fbo) { fbo->bind(); } } static void maybeRelease(QOpenGLFramebufferObject* fbo) { - if (fbo != NULL) { + if (fbo) { fbo->release(); } } diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index acb7b50ec9..1aab0a4dab 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -996,18 +996,18 @@ void Model::renderMeshes(float alpha, bool translucent) { Texture* diffuseMap = networkPart.diffuseTexture.data(); if (mesh.isEye) { - if (diffuseMap != NULL) { + if (diffuseMap) { diffuseMap = (_dilatedTextures[i][j] = static_cast(diffuseMap)->getDilatedTexture(_pupilDilation)).data(); } } - glBindTexture(GL_TEXTURE_2D, diffuseMap == NULL ? + glBindTexture(GL_TEXTURE_2D, !diffuseMap ? Application::getInstance()->getTextureCache()->getWhiteTextureID() : diffuseMap->getID()); if (!mesh.tangents.isEmpty()) { glActiveTexture(GL_TEXTURE1); Texture* normalMap = networkPart.normalTexture.data(); - glBindTexture(GL_TEXTURE_2D, normalMap == NULL ? + glBindTexture(GL_TEXTURE_2D, !normalMap ? Application::getInstance()->getTextureCache()->getBlueTextureID() : normalMap->getID()); glActiveTexture(GL_TEXTURE0); } diff --git a/interface/src/renderer/TextureCache.cpp b/interface/src/renderer/TextureCache.cpp index 22569f925a..794516f7b7 100644 --- a/interface/src/renderer/TextureCache.cpp +++ b/interface/src/renderer/TextureCache.cpp @@ -40,14 +40,14 @@ TextureCache::~TextureCache() { foreach (GLuint id, _fileTextureIDs) { glDeleteTextures(1, &id); } - if (_primaryFramebufferObject != NULL) { + if (_primaryFramebufferObject) { delete _primaryFramebufferObject; glDeleteTextures(1, &_primaryDepthTextureID); } - if (_secondaryFramebufferObject != NULL) { + if (_secondaryFramebufferObject) { delete _secondaryFramebufferObject; } - if (_tertiaryFramebufferObject != NULL) { + if (_tertiaryFramebufferObject) { delete _tertiaryFramebufferObject; } } @@ -138,7 +138,7 @@ QSharedPointer TextureCache::getTexture(const QUrl& url, bool no } QOpenGLFramebufferObject* TextureCache::getPrimaryFramebufferObject() { - if (_primaryFramebufferObject == NULL) { + if (!_primaryFramebufferObject) { _primaryFramebufferObject = createFramebufferObject(); glGenTextures(1, &_primaryDepthTextureID); @@ -164,21 +164,21 @@ GLuint TextureCache::getPrimaryDepthTextureID() { } QOpenGLFramebufferObject* TextureCache::getSecondaryFramebufferObject() { - if (_secondaryFramebufferObject == NULL) { + if (!_secondaryFramebufferObject) { _secondaryFramebufferObject = createFramebufferObject(); } return _secondaryFramebufferObject; } QOpenGLFramebufferObject* TextureCache::getTertiaryFramebufferObject() { - if (_tertiaryFramebufferObject == NULL) { + if (!_tertiaryFramebufferObject) { _tertiaryFramebufferObject = createFramebufferObject(); } return _tertiaryFramebufferObject; } QOpenGLFramebufferObject* TextureCache::getShadowFramebufferObject() { - if (_shadowFramebufferObject == NULL) { + if (!_shadowFramebufferObject) { const int SHADOW_MAP_SIZE = 2048; _shadowFramebufferObject = new QOpenGLFramebufferObject(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGB); @@ -212,16 +212,16 @@ GLuint TextureCache::getShadowDepthTextureID() { bool TextureCache::eventFilter(QObject* watched, QEvent* event) { if (event->type() == QEvent::Resize) { QSize size = static_cast(event)->size(); - if (_primaryFramebufferObject != NULL && _primaryFramebufferObject->size() != size) { + if (_primaryFramebufferObject && _primaryFramebufferObject->size() != size) { delete _primaryFramebufferObject; _primaryFramebufferObject = NULL; glDeleteTextures(1, &_primaryDepthTextureID); } - if (_secondaryFramebufferObject != NULL && _secondaryFramebufferObject->size() != size) { + if (_secondaryFramebufferObject && _secondaryFramebufferObject->size() != size) { delete _secondaryFramebufferObject; _secondaryFramebufferObject = NULL; } - if (_tertiaryFramebufferObject != NULL && _tertiaryFramebufferObject->size() != size) { + if (_tertiaryFramebufferObject && _tertiaryFramebufferObject->size() != size) { delete _tertiaryFramebufferObject; _tertiaryFramebufferObject = NULL; } diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index d15852e11f..7f0e5c7f1a 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -51,7 +51,7 @@ void AudioInjector::injectAudio() { packetStream << QUuid::createUuid(); // pack the flag for loopback - uchar loopbackFlag = (uchar) (_options.getLoopbackAudioInterface() == NULL); + uchar loopbackFlag = (uchar) (!_options.getLoopbackAudioInterface()); packetStream << loopbackFlag; // pack the position for injected audio diff --git a/libraries/metavoxels/src/Bitstream.cpp b/libraries/metavoxels/src/Bitstream.cpp index 919bc4cbc8..4311210da7 100644 --- a/libraries/metavoxels/src/Bitstream.cpp +++ b/libraries/metavoxels/src/Bitstream.cpp @@ -69,7 +69,7 @@ int Bitstream::registerMetaObject(const char* className, const QMetaObject* meta getMetaObjects().insert(className, metaObject); // register it as a subclass of itself and all of its superclasses - for (const QMetaObject* superClass = metaObject; superClass != NULL; superClass = superClass->superClass()) { + for (const QMetaObject* superClass = metaObject; superClass; superClass = superClass->superClass()) { getMetaObjectSubClasses().insert(superClass, metaObject); } return 0; diff --git a/libraries/metavoxels/src/MetavoxelData.cpp b/libraries/metavoxels/src/MetavoxelData.cpp index 5665e70f91..792ac1cd27 100644 --- a/libraries/metavoxels/src/MetavoxelData.cpp +++ b/libraries/metavoxels/src/MetavoxelData.cpp @@ -784,7 +784,7 @@ void ScriptedMetavoxelGuide::setURL(const ParameterizedURL& url) { bool MetavoxelVisitation::allInputNodesLeaves() const { foreach (MetavoxelNode* node, inputNodes) { - if (node != NULL && !node->isLeaf()) { + if (node && !node->isLeaf()) { return false; } } @@ -792,7 +792,7 @@ bool MetavoxelVisitation::allInputNodesLeaves() const { } AttributeValue MetavoxelVisitation::getInheritedOutputValue(int index) const { - for (const MetavoxelVisitation* visitation = previous; visitation != NULL; visitation = visitation->previous) { + for (const MetavoxelVisitation* visitation = previous; visitation; visitation = visitation->previous) { MetavoxelNode* node = visitation->outputNodes.at(index); if (node) { return node->getAttributeValue(visitor.getOutputs().at(index)); diff --git a/libraries/metavoxels/src/MetavoxelUtil.cpp b/libraries/metavoxels/src/MetavoxelUtil.cpp index 2e93fb1804..9966c1cd8d 100644 --- a/libraries/metavoxels/src/MetavoxelUtil.cpp +++ b/libraries/metavoxels/src/MetavoxelUtil.cpp @@ -62,7 +62,7 @@ DelegatingItemEditorFactory::DelegatingItemEditorFactory() : QWidget* DelegatingItemEditorFactory::createEditor(int userType, QWidget* parent) const { QWidget* editor = QItemEditorFactory::createEditor(userType, parent); - return (editor == NULL) ? _parentFactory->createEditor(userType, parent) : editor; + return (!editor) ? _parentFactory->createEditor(userType, parent) : editor; } QByteArray DelegatingItemEditorFactory::valuePropertyName(int userType) const { diff --git a/libraries/metavoxels/src/SharedObject.cpp b/libraries/metavoxels/src/SharedObject.cpp index 7e10068afe..9d26723f90 100644 --- a/libraries/metavoxels/src/SharedObject.cpp +++ b/libraries/metavoxels/src/SharedObject.cpp @@ -163,7 +163,7 @@ void SharedObjectEditor::updateType() { oldObject->disconnect(this); } const QMetaObject* metaObject = _type->itemData(_type->currentIndex()).value(); - if (metaObject == NULL) { + if (!metaObject) { _object.reset(); return; } diff --git a/libraries/octree/src/JurisdictionSender.cpp b/libraries/octree/src/JurisdictionSender.cpp index 49dddf75df..e47bcf0619 100644 --- a/libraries/octree/src/JurisdictionSender.cpp +++ b/libraries/octree/src/JurisdictionSender.cpp @@ -62,7 +62,7 @@ bool JurisdictionSender::process() { _nodesRequestingJurisdictions.pop(); SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(nodeUUID); - if (node && node->getActiveSocket() != NULL) { + if (node && node->getActiveSocket()) { _packetSender.queuePacketForSending(node, QByteArray(reinterpret_cast(bufferOut), sizeOut)); nodeCount++; } diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 446eb25a50..0847590720 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -41,7 +41,8 @@ float boundaryDistanceForRenderLevel(unsigned int renderLevel, float voxelSizeSc Octree::Octree(bool shouldReaverage) : _isDirty(true), _shouldReaverage(shouldReaverage), - _stopImport(false) { + _stopImport(false), + _lock(QReadWriteLock::Recursive) { _rootNode = NULL; _isViewing = false; } @@ -150,7 +151,7 @@ void Octree::recurseNodeWithOperationDistanceSorted(OctreeElement* node, Recurse OctreeElement* Octree::nodeForOctalCode(OctreeElement* ancestorNode, const unsigned char* needleCode, OctreeElement** parentOfFoundNode) const { // special case for NULL octcode - if (needleCode == NULL) { + if (!needleCode) { return _rootNode; } @@ -499,7 +500,7 @@ void Octree::processRemoveOctreeElementsBitstream(const unsigned char* bitstream // Note: this is an expensive call. Don't call it unless you really need to reaverage the entire tree (from startNode) void Octree::reaverageOctreeElements(OctreeElement* startNode) { - if (startNode == NULL) { + if (!startNode) { startNode = getRoot(); } // if our tree is a reaveraging tree, then we do this, otherwise we don't do anything @@ -551,7 +552,10 @@ OctreeElement* Octree::getOctreeElementAt(float x, float y, float z, float s) co OctreeElement* Octree::getOrCreateChildElementAt(float x, float y, float z, float s) { - return getRoot()->getOrCreateChildElementAt(x, y, z, s); + lockForWrite(); + OctreeElement* result = getRoot()->getOrCreateChildElementAt(x, y, z, s); + unlock(); + return result; } diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 9db83d47b1..21a6929034 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -240,11 +240,11 @@ public: bool readFromSVOFile(const char* filename); // Octree does not currently handle its own locking, caller must use these to lock/unlock - void lockForRead() { lock.lockForRead(); } - bool tryLockForRead() { return lock.tryLockForRead(); } - void lockForWrite() { lock.lockForWrite(); } - bool tryLockForWrite() { return lock.tryLockForWrite(); } - void unlock() { lock.unlock(); } + void lockForRead() { _lock.lockForRead(); } + bool tryLockForRead() { return _lock.tryLockForRead(); } + void lockForWrite() { _lock.lockForWrite(); } + bool tryLockForWrite() { return _lock.tryLockForWrite(); } + void unlock() { _lock.unlock(); } unsigned long getOctreeElementsCount(); @@ -329,7 +329,7 @@ protected: /// flushes out any Octal Codes that had to be queued void emptyDeleteQueue(); - QReadWriteLock lock; + QReadWriteLock _lock; /// This tree is receiving inbound viewer datagrams. bool _isViewing; diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 38abd15dc8..e47730ccd4 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -177,7 +177,7 @@ void OctreeEditPacketSender::queuePacketToNodes(unsigned char* buffer, ssize_t l foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { // only send to the NodeTypes that are getMyNodeType() - if (node->getActiveSocket() != NULL && node->getType() == getMyNodeType()) { + if (node->getActiveSocket() && node->getType() == getMyNodeType()) { QUuid nodeUUID = node->getUUID(); bool isMyJurisdiction = true; // we need to get the jurisdiction for this @@ -226,7 +226,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, unsigned ch foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { // only send to the NodeTypes that are getMyNodeType() - if (node->getActiveSocket() != NULL && node->getType() == getMyNodeType()) { + if (node->getActiveSocket() && node->getType() == getMyNodeType()) { QUuid nodeUUID = node->getUUID(); bool isMyJurisdiction = true; diff --git a/libraries/octree/src/OctreeElement.cpp b/libraries/octree/src/OctreeElement.cpp index c536ad3eeb..67b96b4047 100644 --- a/libraries/octree/src/OctreeElement.cpp +++ b/libraries/octree/src/OctreeElement.cpp @@ -739,7 +739,7 @@ void OctreeElement::setChildAtIndex(int childIndex, OctreeElement* child) { _externalChildrenMemoryUsage += NUMBER_OF_CHILDREN * sizeof(OctreeElement*); } else if (previousChildCount == 2 && newChildCount == 1) { - assert(child == NULL); // we are removing a child, so this must be true! + assert(!child); // we are removing a child, so this must be true! OctreeElement* previousFirstChild = _children.external[firstIndex]; OctreeElement* previousSecondChild = _children.external[secondIndex]; delete[] _children.external; diff --git a/libraries/octree/src/OctreeHeadlessViewer.cpp b/libraries/octree/src/OctreeHeadlessViewer.cpp index 4ab85e7de8..5d2ce2d287 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.cpp +++ b/libraries/octree/src/OctreeHeadlessViewer.cpp @@ -75,7 +75,7 @@ void OctreeHeadlessViewer::queryOctree() { foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { // only send to the NodeTypes that are serverType - if (node->getActiveSocket() != NULL && node->getType() == serverType) { + if (node->getActiveSocket() && node->getType() == serverType) { totalServers++; // get the server bounds for this server @@ -135,7 +135,7 @@ void OctreeHeadlessViewer::queryOctree() { foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { // only send to the NodeTypes that are serverType - if (node->getActiveSocket() != NULL && node->getType() == serverType) { + if (node->getActiveSocket() && node->getType() == serverType) { // get the server bounds for this server diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index d9f0beb81a..b493ec6bc7 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -385,7 +385,7 @@ Particle Particle::fromEditPacket(const unsigned char* data, int length, int& pr } else { // look up the existing particle - const Particle* existingParticle = tree->findParticleByID(editID, true); + const Particle* existingParticle = tree->findParticleByID(editID); // copy existing properties before over-writing with new properties if (existingParticle) { diff --git a/libraries/particles/src/ParticleTree.cpp b/libraries/particles/src/ParticleTree.cpp index b422b8e4e8..30270b8fcf 100644 --- a/libraries/particles/src/ParticleTree.cpp +++ b/libraries/particles/src/ParticleTree.cpp @@ -99,8 +99,8 @@ void ParticleTree::storeParticle(const Particle& particle, const SharedNodePoint if (!args.found) { glm::vec3 position = particle.getPosition(); float size = std::max(MINIMUM_PARTICLE_ELEMENT_SIZE, particle.getRadius()); - ParticleTreeElement* element = (ParticleTreeElement*)getOrCreateChildElementAt(position.x, position.y, position.z, size); + ParticleTreeElement* element = (ParticleTreeElement*)getOrCreateChildElementAt(position.x, position.y, position.z, size); element->storeParticle(particle); } // what else do we need to do here to get reaveraging to work @@ -149,8 +149,8 @@ void ParticleTree::addParticle(const ParticleID& particleID, const ParticlePrope Particle particle(particleID, properties); glm::vec3 position = particle.getPosition(); float size = std::max(MINIMUM_PARTICLE_ELEMENT_SIZE, particle.getRadius()); + ParticleTreeElement* element = (ParticleTreeElement*)getOrCreateChildElementAt(position.x, position.y, position.z, size); - element->storeParticle(particle); _isDirty = true; @@ -370,17 +370,12 @@ bool ParticleTree::findByIDOperation(OctreeElement* element, void* extraData) { } -const Particle* ParticleTree::findParticleByID(uint32_t id, bool alreadyLocked) { +const Particle* ParticleTree::findParticleByID(uint32_t id) { FindByIDArgs args = { id, false, NULL }; - if (!alreadyLocked) { - //qDebug() << "ParticleTree::findParticleByID().... about to call lockForRead()...."; - lockForRead(); - //qDebug() << "ParticleTree::findParticleByID().... after call lockForRead()...."; - } + + lockForRead(); recurseTreeWithOperation(findByIDOperation, &args); - if (!alreadyLocked) { - unlock(); - } + unlock(); return args.foundParticle; } @@ -487,7 +482,9 @@ void ParticleTree::update() { } // prune the tree... + lockForWrite(); recurseTreeWithOperation(pruneOperation, NULL); + unlock(); } diff --git a/libraries/particles/src/ParticleTree.h b/libraries/particles/src/ParticleTree.h index f3b8f5183d..08e8e51a05 100644 --- a/libraries/particles/src/ParticleTree.h +++ b/libraries/particles/src/ParticleTree.h @@ -44,7 +44,7 @@ public: void addParticle(const ParticleID& particleID, const ParticleProperties& properties); void deleteParticle(const ParticleID& particleID); const Particle* findClosestParticle(glm::vec3 position, float targetRadius); - const Particle* findParticleByID(uint32_t id, bool alreadyLocked = false); + const Particle* findParticleByID(uint32_t id); /// finds all particles that touch a sphere /// \param center the center of the sphere diff --git a/libraries/particles/src/ParticlesScriptingInterface.cpp b/libraries/particles/src/ParticlesScriptingInterface.cpp index a25dde1b9e..c2376e8d72 100644 --- a/libraries/particles/src/ParticlesScriptingInterface.cpp +++ b/libraries/particles/src/ParticlesScriptingInterface.cpp @@ -33,9 +33,7 @@ ParticleID ParticlesScriptingInterface::addParticle(const ParticleProperties& pr // If we have a local particle tree set, then also update it. if (_particleTree) { - _particleTree->lockForWrite(); _particleTree->addParticle(id, properties); - _particleTree->unlock(); } return id; @@ -66,7 +64,7 @@ ParticleProperties ParticlesScriptingInterface::getParticleProperties(ParticleID } if (_particleTree) { _particleTree->lockForRead(); - const Particle* particle = _particleTree->findParticleByID(identity.id, true); + const Particle* particle = _particleTree->findParticleByID(identity.id); if (particle) { results.copyFromParticle(*particle); } else { diff --git a/libraries/particles/src/ParticlesScriptingInterface.h b/libraries/particles/src/ParticlesScriptingInterface.h index 3aa19629f0..ee21424f11 100644 --- a/libraries/particles/src/ParticlesScriptingInterface.h +++ b/libraries/particles/src/ParticlesScriptingInterface.h @@ -30,12 +30,10 @@ public: private slots: /// inbound slots for external collision systems void forwardParticleCollisionWithVoxel(const ParticleID& particleID, const VoxelDetail& voxel) { - qDebug() << "forwardParticleCollisionWithVoxel()"; emit particleCollisionWithVoxel(particleID, voxel); } void forwardParticleCollisionWithParticle(const ParticleID& idA, const ParticleID& idB) { - qDebug() << "forwardParticleCollisionWithParticle()"; emit particleCollisionWithParticle(idA, idB); } diff --git a/libraries/script-engine/src/MenuItemProperties.cpp b/libraries/script-engine/src/MenuItemProperties.cpp index fc1e94f40c..f071723233 100644 --- a/libraries/script-engine/src/MenuItemProperties.cpp +++ b/libraries/script-engine/src/MenuItemProperties.cpp @@ -71,6 +71,7 @@ void menuItemPropertiesFromScriptValue(const QScriptValue& object, MenuItemPrope properties.menuItemName = object.property("menuItemName").toVariant().toString(); properties.isCheckable = object.property("isCheckable").toVariant().toBool(); properties.isChecked = object.property("isChecked").toVariant().toBool(); + properties.isSeparator = object.property("isSeparator").toVariant().toBool(); // handle the shortcut key options in order... QScriptValue shortcutKeyValue = object.property("shortcutKey"); diff --git a/libraries/script-engine/src/MenuItemProperties.h b/libraries/script-engine/src/MenuItemProperties.h index 6e0b3309b1..82f00a2bc4 100644 --- a/libraries/script-engine/src/MenuItemProperties.h +++ b/libraries/script-engine/src/MenuItemProperties.h @@ -39,6 +39,7 @@ public: // other properties bool isCheckable; bool isChecked; + bool isSeparator; }; Q_DECLARE_METATYPE(MenuItemProperties) QScriptValue menuItemPropertiesToScriptValue(QScriptEngine* engine, const MenuItemProperties& props); diff --git a/libraries/shared/src/AccountManager.cpp b/libraries/shared/src/AccountManager.cpp index 0f39ba4146..888d42ddda 100644 --- a/libraries/shared/src/AccountManager.cpp +++ b/libraries/shared/src/AccountManager.cpp @@ -35,7 +35,7 @@ const QString ACCOUNTS_GROUP = "accounts"; AccountManager::AccountManager() : _authURL(), - _networkAccessManager(), + _networkAccessManager(new QNetworkAccessManager(this)), _pendingCallbackMap(), _accountInfo() { @@ -130,16 +130,16 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager:: switch (operation) { case QNetworkAccessManager::GetOperation: - networkReply = _networkAccessManager.get(authenticatedRequest); + networkReply = _networkAccessManager->get(authenticatedRequest); break; case QNetworkAccessManager::PostOperation: case QNetworkAccessManager::PutOperation: authenticatedRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); if (operation == QNetworkAccessManager::PostOperation) { - networkReply = _networkAccessManager.post(authenticatedRequest, dataByteArray); + networkReply = _networkAccessManager->post(authenticatedRequest, dataByteArray); } else { - networkReply = _networkAccessManager.put(authenticatedRequest, dataByteArray); + networkReply = _networkAccessManager->put(authenticatedRequest, dataByteArray); } break; @@ -242,7 +242,7 @@ void AccountManager::requestAccessToken(const QString& login, const QString& pas request.setUrl(grantURL); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - QNetworkReply* requestReply = _networkAccessManager.post(request, postData); + QNetworkReply* requestReply = _networkAccessManager->post(request, postData); connect(requestReply, &QNetworkReply::finished, this, &AccountManager::requestFinished); connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); } @@ -292,4 +292,4 @@ void AccountManager::requestFinished() { void AccountManager::requestError(QNetworkReply::NetworkError error) { // TODO: error handling qDebug() << "AccountManager requestError - " << error; -} \ No newline at end of file +} diff --git a/libraries/shared/src/AccountManager.h b/libraries/shared/src/AccountManager.h index c741beb461..8b3c6b362c 100644 --- a/libraries/shared/src/AccountManager.h +++ b/libraries/shared/src/AccountManager.h @@ -23,7 +23,7 @@ public: jsonCallbackReceiver(NULL), jsonCallbackMethod(), errorCallbackReceiver(NULL), errorCallbackMethod() {}; - bool isEmpty() const { return jsonCallbackReceiver == NULL && errorCallbackReceiver == NULL; } + bool isEmpty() const { return !jsonCallbackReceiver && !errorCallbackReceiver; } QObject* jsonCallbackReceiver; QString jsonCallbackMethod; @@ -53,6 +53,8 @@ public: QString getUsername() const { return _accountInfo.getUsername(); } + void destroy() { delete _networkAccessManager; } + public slots: void requestFinished(); void requestError(QNetworkReply::NetworkError error); @@ -76,7 +78,7 @@ private: const JSONCallbackParameters& callbackParams, const QByteArray& dataByteArray); QUrl _authURL; - QNetworkAccessManager _networkAccessManager; + QNetworkAccessManager* _networkAccessManager; QMap _pendingCallbackMap; DataServerAccountInfo _accountInfo; diff --git a/libraries/shared/src/Node.cpp b/libraries/shared/src/Node.cpp index bb45265f8b..889f3e2ed0 100644 --- a/libraries/shared/src/Node.cpp +++ b/libraries/shared/src/Node.cpp @@ -98,7 +98,7 @@ void Node::activatePublicSocket() { } void Node::recordBytesReceived(int bytesReceived) { - if (_bytesReceivedMovingAverage == NULL) { + if (!_bytesReceivedMovingAverage) { _bytesReceivedMovingAverage = new SimpleMovingAverage(100); } diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index d8c6cd09f1..263e29bc94 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -264,6 +264,11 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr break; } default: + // the node decided not to do anything with this packet + // if it comes from a known source we should keep that node alive + SharedNodePointer matchingNode = sendingNodeForPacket(packet); + matchingNode->setLastHeardMicrostamp(usecTimestampNow()); + break; } } @@ -810,7 +815,7 @@ void NodeList::activateSocketFromNodeCommunication(const QByteArray& packet, con SharedNodePointer NodeList::soloNodeOfType(char nodeType) { - if (memchr(SOLO_NODE_TYPES, nodeType, sizeof(SOLO_NODE_TYPES)) != NULL) { + if (memchr(SOLO_NODE_TYPES, nodeType, sizeof(SOLO_NODE_TYPES))) { foreach (const SharedNodePointer& node, getNodeHash()) { if (node->getType() == nodeType) { return node; diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index 3f9cf8edcb..ff30dad47e 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -73,7 +73,7 @@ unsigned char* childOctalCode(const unsigned char* parentOctalCode, char childNu // find the length (in number of three bit code sequences) // in the parent - int parentCodeSections = parentOctalCode != NULL + int parentCodeSections = parentOctalCode ? numberOfThreeBitSectionsInCode(parentOctalCode) : 0; @@ -87,7 +87,7 @@ unsigned char* childOctalCode(const unsigned char* parentOctalCode, char childNu unsigned char* newCode = new unsigned char[childCodeBytes]; // copy the parent code to the child - if (parentOctalCode != NULL) { + if (parentOctalCode) { memcpy(newCode, parentOctalCode, parentCodeBytes); } diff --git a/libraries/voxels/src/VoxelTreeElement.cpp b/libraries/voxels/src/VoxelTreeElement.cpp index 5609e279d7..be6bd50e3d 100644 --- a/libraries/voxels/src/VoxelTreeElement.cpp +++ b/libraries/voxels/src/VoxelTreeElement.cpp @@ -98,7 +98,7 @@ VoxelSystem* VoxelTreeElement::getVoxelSystem() const { } void VoxelTreeElement::setVoxelSystem(VoxelSystem* voxelSystem) { - if (voxelSystem == NULL) { + if (!voxelSystem) { _voxelSystemIndex = INDEX_FOR_NULL; } else { uint8_t index; diff --git a/svo-viewer/src/Render.cpp b/svo-viewer/src/Render.cpp index f2d500db51..df28a44fc6 100755 --- a/svo-viewer/src/Render.cpp +++ b/svo-viewer/src/Render.cpp @@ -72,7 +72,7 @@ void SvoViewer::InitializePointRenderSystem() PointRenderAssembleData args; args.buffer = _pointVertices = new glm::vec3[_nodeCount]; args.colorBuffer = _pointColors = new unsigned char[_nodeCount*3]; - assert(args.buffer != NULL); + assert(args.buffer); args.count = 0; _systemTree.recurseTreeWithOperation(&PointRenderAssemblePerVoxel, &args); @@ -297,7 +297,7 @@ void SvoViewer::InitializeVoxelRenderSystem() VoxelRenderAssembleData args; args.buffer = _readVerticesArray; args.colorBuffer = _readColorsArray; - assert(args.buffer != NULL && args.colorBuffer != NULL); + assert(args.buffer && args.colorBuffer); args.leafCount = 0; args.lastBufferSegmentStart = 0; args.idxIds = _vboIndicesIds; @@ -622,12 +622,12 @@ void SvoViewer::InitializeVoxelOptRenderSystem() for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { OctreeElement* childNode1stOrder = node0fromRoot->getChildAtIndex(i); - if (childNode1stOrder == NULL) continue; + if (!childNode1stOrder) continue; // Grab 2nd order nodes for better separation. At some point, this would need to be done intelligently. for (int j = 0; j < NUMBER_OF_CHILDREN; j++) { OctreeElement* childNode2ndOrder = childNode1stOrder->getChildAtIndex(j); - if (childNode2ndOrder == NULL) continue; + if (!childNode2ndOrder) continue; //int num2ndOrderChildren = childNode2ndOrder->getChildCount(); // Figure out how populated this child is. diff --git a/svo-viewer/src/Render2.cpp b/svo-viewer/src/Render2.cpp index 1f909603f9..06410cfe4e 100755 --- a/svo-viewer/src/Render2.cpp +++ b/svo-viewer/src/Render2.cpp @@ -194,12 +194,12 @@ void SvoViewer::InitializeVoxelOpt2RenderSystem() for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { OctreeElement* childNode1stOrder = node0fromRoot->getChildAtIndex(i); - if (childNode1stOrder == NULL) continue; + if (!childNode1stOrder) continue; // Grab 2nd order nodes for better separation. At some point, this would need to be done intelligently. for (int j = 0; j < NUMBER_OF_CHILDREN; j++) { OctreeElement* childNode2ndOrder = childNode1stOrder->getChildAtIndex(j); - if (childNode2ndOrder == NULL) continue; + if (!childNode2ndOrder) continue; //int num2ndOrderChildren = childNode2ndOrder->getChildCount(); // Figure out how populated this child is. @@ -240,7 +240,7 @@ void SvoViewer::InitializeVoxelOpt2RenderSystem() for (int k = 0; k < NUM_CUBE_FACES; k++) { _segmentIdxBuffers[i].idxBuff[k] = new GLuint[2 * 3 * _numChildNodeLeaves[i]]; - assert(_segmentIdxBuffers[i].idxBuff[k] != NULL); + assert(_segmentIdxBuffers[i].idxBuff[k]); } VoxelOpt2RenderAssembleData args; @@ -267,7 +267,7 @@ void SvoViewer::InitializeVoxelOpt2RenderSystem() delete [] _readVertexStructs; //delete [] _readIndicesArray; delete [] faceCenters; - for (int k = 0; k < NUM_CUBE_FACES; k++) if (_segmentIdxBuffers[i].idxBuff[k] != NULL) delete [] _segmentIdxBuffers[i].idxBuff[k]; + for (int k = 0; k < NUM_CUBE_FACES; k++) if (_segmentIdxBuffers[i].idxBuff[k]) delete [] _segmentIdxBuffers[i].idxBuff[k]; } _voxelOptRenderInitialized = true;