From 117e302b2af7400b5694bb3fd7898ad2d08d1ab6 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 12 Jan 2017 15:40:37 -0800 Subject: [PATCH 01/17] First pass --- interface/resources/qml/hifi/NameCard.qml | 72 ++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index c6daf53b9a..c1b93b92ca 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -55,12 +55,82 @@ Item { width: parent.width - /*avatarImage.width - parent.spacing - */parent.anchors.leftMargin - parent.anchors.rightMargin height: childrenRect.height anchors.verticalCenter: parent.verticalCenter - // DisplayName Text + + // DisplayName field for my card + Rectangle { + id: myDisplayName + visible: isMyCard + color: "#C5C5C5" + anchors.left: parent.left + anchors.leftMargin: -10 + width: parent.width + 70 + height: 35 + TextInput { + id: myDisplayNameText + // Properties + text: thisNameCard.displayName + autoScroll: false + maximumLength: 64 + width: parent.width + height: parent.height + wrapMode: TextInput.Wrap + // Anchors + anchors.fill: parent + anchors.leftMargin: 10 + // Text Positioning + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + // Style + color: hifi.colors.darkGray + FontLoader { id: firaSansSemiBold; source: "../../fonts/FiraSans-SemiBold.ttf"; } + font.family: firaSansSemiBold.name + font.pointSize: thisNameCard.displayTextHeight + // Signals + onEditingFinished: { + console.log("New displayName: ", text) + } + } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton + hoverEnabled: true + propagateComposedEvents: true + onClicked: { + myDisplayNameText.selectAll(); + myDisplayNameText.focus = true; + } + onEntered: myDisplayName.color = hifi.colors.lightGrayText + onExited: myDisplayName.color = "#C5C5C5" + } + // Edit pencil glyph + HiFiGlyphs { + text: hifi.glyphs.edit + // Size + size: thisNameCard.displayTextHeight + // Anchors + anchors.right: parent.right + anchors.rightMargin: size/2 + anchors.verticalCenter: parent.verticalCenter + // Style + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + color: hifi.colors.baseGray + } + } + // Spacer for DisplayName for my card + Rectangle { + width: myDisplayName.width + height: 5 + visible: isMyCard + opacity: 0 + } + // DisplayName Text for others' cards FiraSansSemiBold { id: displayNameText // Properties text: thisNameCard.displayName elide: Text.ElideRight + visible: !isMyCard // Size width: parent.width // Anchors From 6e4a4da92ab2ec2920ac135493d935b73d62f5f3 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 12 Jan 2017 16:40:47 -0800 Subject: [PATCH 02/17] Checkpoint --- interface/resources/qml/hifi/NameCard.qml | 18 ++++++++++-------- scripts/system/pal.js | 6 ++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index c1b93b92ca..906e81a08d 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -69,17 +69,15 @@ Item { id: myDisplayNameText // Properties text: thisNameCard.displayName - autoScroll: false maximumLength: 64 - width: parent.width - height: parent.height - wrapMode: TextInput.Wrap + clip: true // Anchors anchors.fill: parent anchors.leftMargin: 10 + anchors.rightMargin: editGlyph.implicitWidth + editGlyph.anchors.rightMargin // Text Positioning - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignLeft + verticalAlignment: TextInput.AlignVCenter + horizontalAlignment: TextInput.AlignLeft // Style color: hifi.colors.darkGray FontLoader { id: firaSansSemiBold; source: "../../fonts/FiraSans-SemiBold.ttf"; } @@ -87,15 +85,18 @@ Item { font.pointSize: thisNameCard.displayTextHeight // Signals onEditingFinished: { - console.log("New displayName: ", text) + pal.sendToScript({method: 'displayNameUpdate', params: text}) } } MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton hoverEnabled: true - propagateComposedEvents: true onClicked: { + myDisplayNameText.focus ? myDisplayNameText.cursorPosition = myDisplayNameText.positionAt(mouseX, mouseY, TextInput.CursorOnCharacter) : myDisplayNameText.selectAll(); + myDisplayNameText.focus = true; + } + onDoubleClicked: { myDisplayNameText.selectAll(); myDisplayNameText.focus = true; } @@ -104,6 +105,7 @@ Item { } // Edit pencil glyph HiFiGlyphs { + id: editGlyph text: hifi.glyphs.edit // Size size: thisNameCard.displayTextHeight diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 6b3fd00c3b..c6ac1056de 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -237,6 +237,12 @@ pal.fromQml.connect(function (message) { // messages are {method, params}, like data = message.params; Users.setAvatarGain(data['sessionId'], data['gain']); break; + case 'displayNameUpdate': + if (MyAvatar.displayName != message.params) { + MyAvatar.displayName = message.params; + } + break; + default: default: print('Unrecognized message from Pal.qml:', JSON.stringify(message)); } From 2f176f50fae4ff06d9ab2e92b92acdf81b63e38c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 13 Jan 2017 12:56:59 -0800 Subject: [PATCH 03/17] Another checkpoint --- interface/resources/fonts/hifi-glyphs.ttf | Bin 24580 -> 24772 bytes interface/resources/qml/hifi/NameCard.qml | 13 +++++++++---- interface/resources/qml/hifi/Pal.qml | 13 +++++++++++-- .../qml/styles-uit/HifiConstants.qml | 3 ++- libraries/avatars/src/AvatarData.cpp | 1 + 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/interface/resources/fonts/hifi-glyphs.ttf b/interface/resources/fonts/hifi-glyphs.ttf index 09aefffdfef007aa94f3cbdfd02a61612c0ee9e7..c139a196d0f70536b980d7cbbad81c416d237e0b 100644 GIT binary patch delta 684 zcmX|;O-Phs5Xb-XywCf*>%Q(6$S&oZx@9eHv}!B62_*z(6xCL4;;xpy=;jLh1+Jh( z>Y;-|hw`~Z*sVi>V9P>>2uv~|=n@!tkdO}2rArZH1jc^Qz|8y(GsFC6?!BS)HJSwh zuwf1guJ-gqFHcTK2Z7;d0F3k9=X$UN0SwOrXo~cQqI-(GC(KMSZ&foL?DFh{Mi9}57s0fdst#H`8NXa}G=0L{sC ze(Jz(-5NkI0PLo+Bj%l^hur{Q2e6Yir*il}w*Wd-S}0?t6W_wG`heJPfQq^7MBZ}$ z>nbp?4DgR-aRiK-7nX+{r+-0bDB0$dt&K`%TN{gXhO)AYZjwzd(Oz({T%rJFH_9_W z%}~l@fRm*p4i;2~&Ft9ZI{QhP;!DLr@-6?&{QlySTIiisFo+nf&y? zVy4k%5F@MqxvQY7cFh^-AZZBA>D4M7hyAs@)MEA3Qw?Wa+-3QK`kR zDeVZ#SUkYmgK|DTDgVa3l$8ww+l*4hKLhU+yPg;w&!5O8G9%+DK&}ooP)2?ks@MPj HXlvsiT0xGP delta 494 zcmX|+Pe>GT6vsbrW_Gp4>>>-+5?hq(sSUw@UQl~C_V^eb z5-UJuYW%_I)Aqmn;9G#$Qab63obA}G1$Kd^bUK-Hj2p5CQUhE~yVJ9^&udmemVlq* z6T{BKQ0f90%fNTnna%Q520>c9hcb?v91A~s5B*Uulbx8F{?oob3GpK^J{IK!=6Zj0 zCeF7VU}|`^t*m@$YF7S*+?0&EB?D5W7UVF3Cs6EQF^^n9FH#Ug{GJ$D=U6E9HrGeVw}Msz}qtW z2(VRVKLP%$+x9h8i1$dNs<5w1qiVKi)Ehe_8MSHe7GB@~tgGD6C2`f_&_(mq(#oFz Dg()->killNodeWithUUID(getSessionUUID()); qCDebug(avatars) << "Changing display name for avatar to" << displayName; } From 32e330320e0e50d84d8d7bb1a03d0831732fcb17 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Jan 2017 11:26:57 -0800 Subject: [PATCH 04/17] Cleanup after rebase --- interface/resources/qml/hifi/NameCard.qml | 17 ++++++++++++----- interface/resources/qml/hifi/Pal.qml | 8 -------- libraries/avatars/src/AvatarData.cpp | 2 +- scripts/system/pal.js | 1 - 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index 250dad7f7f..b389891255 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -60,11 +60,15 @@ Item { Rectangle { id: myDisplayName visible: isMyCard - color: "#C5C5C5" - anchors.left: parent.left - anchors.leftMargin: -10 + // Size width: parent.width + 70 height: 35 + // Anchors + anchors.top: parent.top + anchors.left: parent.left + anchors.leftMargin: -10 + // Style + color: "#C5C5C5" border.color: hifi.colors.blueHighlight border.width: 0 TextInput { @@ -126,7 +130,10 @@ Item { } // Spacer for DisplayName for my card Rectangle { + id: myDisplayNameSpacer width: myDisplayName.width + // Anchors + anchors.top: myDisplayName.bottom height: 5 visible: isMyCard opacity: 0 @@ -160,7 +167,7 @@ Item { // Size width: parent.width // Anchors - anchors.top: displayNameText.bottom + anchors.top: isMyCard ? myDisplayNameSpacer.bottom : displayNameText.bottom // Text Size size: thisNameCard.usernameTextHeight // Text Positioning @@ -182,7 +189,7 @@ Item { Rectangle { id: nameCardVUMeter // Size - width: ((gainSlider.value - gainSlider.minimumValue)/(gainSlider.maximumValue - gainSlider.minimumValue)) * parent.width + width: isMyCard ? gainSlider.width : ((gainSlider.value - gainSlider.minimumValue)/(gainSlider.maximumValue - gainSlider.minimumValue)) * parent.width height: 8 // Anchors anchors.top: spacer.bottom diff --git a/interface/resources/qml/hifi/Pal.qml b/interface/resources/qml/hifi/Pal.qml index 8fa8fe8514..68ad3f811c 100644 --- a/interface/resources/qml/hifi/Pal.qml +++ b/interface/resources/qml/hifi/Pal.qml @@ -346,11 +346,6 @@ Rectangle { visible: iAmAdmin color: hifi.colors.lightGrayText } - function letterbox(message) { - letterboxMessage.text = message; - letterboxMessage.visible = true - - } // This Rectangle refers to the [?] popup button next to "NAMES" Rectangle { color: hifi.colors.tableBackgroundLight @@ -411,9 +406,6 @@ Rectangle { onExited: adminHelpText.color = hifi.colors.redHighlight } } - LetterboxMessage { - id: letterboxMessage - } } function findSessionIndex(sessionId, optionalData) { // no findIndex in .qml diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 0381363ef3..0350e73d2e 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1094,7 +1094,7 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) { void AvatarData::setDisplayName(const QString& displayName) { _displayName = displayName; - DependencyManager::get()->killNodeWithUUID(getSessionUUID()); + DependencyManager::get()->getDomainHandler().softReset(); qCDebug(avatars) << "Changing display name for avatar to" << displayName; } diff --git a/scripts/system/pal.js b/scripts/system/pal.js index c6ac1056de..6fd386b00f 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -242,7 +242,6 @@ pal.fromQml.connect(function (message) { // messages are {method, params}, like MyAvatar.displayName = message.params; } break; - default: default: print('Unrecognized message from Pal.qml:', JSON.stringify(message)); } From 3b56f46206a3267c8016c9959c90958f343f5fb3 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Jan 2017 13:18:24 -0800 Subject: [PATCH 05/17] Style changes --- interface/resources/qml/hifi/NameCard.qml | 34 ++++++++++++++--------- libraries/avatars/src/AvatarData.cpp | 3 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index b389891255..367ef3b25b 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -28,7 +28,7 @@ Item { property string uuid: "" property string displayName: "" property string userName: "" - property int displayTextHeight: 18 + property real displayNameTextPixelSize: 18 property int usernameTextHeight: 12 property real audioLevel: 0.0 property bool isMyCard: false @@ -68,7 +68,7 @@ Item { anchors.left: parent.left anchors.leftMargin: -10 // Style - color: "#C5C5C5" + color: hifi.colors.textFieldLightBackground border.color: hifi.colors.blueHighlight border.width: 0 TextInput { @@ -77,23 +77,30 @@ Item { text: thisNameCard.displayName maximumLength: 64 clip: true + // Size + width: parent.width + height: parent.height // Anchors - anchors.fill: parent + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left anchors.leftMargin: 10 anchors.rightMargin: editGlyph.implicitWidth + editGlyph.anchors.rightMargin - // Text Positioning - verticalAlignment: TextInput.AlignVCenter - horizontalAlignment: TextInput.AlignLeft // Style color: hifi.colors.darkGray FontLoader { id: firaSansSemiBold; source: "../../fonts/FiraSans-SemiBold.ttf"; } font.family: firaSansSemiBold.name - font.pointSize: thisNameCard.displayTextHeight + font.pixelSize: displayNameTextPixelSize + selectionColor: hifi.colors.blueHighlight + selectedTextColor: "black" + // Text Positioning + verticalAlignment: TextInput.AlignVCenter + horizontalAlignment: TextInput.AlignLeft // Signals onEditingFinished: { pal.sendToScript({method: 'displayNameUpdate', params: text}) focus = false myDisplayName.border.width = 0 + color = hifi.colors.darkGray } } MouseArea { @@ -101,23 +108,24 @@ Item { acceptedButtons: Qt.LeftButton hoverEnabled: true onClicked: { - myDisplayName.border.width = 3 + myDisplayName.border.width = 1 myDisplayNameText.focus ? myDisplayNameText.cursorPosition = myDisplayNameText.positionAt(mouseX, mouseY, TextInput.CursorOnCharacter) : myDisplayNameText.selectAll(); myDisplayNameText.focus = true + myDisplayNameText.color = "black" } onDoubleClicked: { myDisplayNameText.selectAll(); myDisplayNameText.focus = true; } onEntered: myDisplayName.color = hifi.colors.lightGrayText - onExited: myDisplayName.color = "#C5C5C5" + onExited: myDisplayName.color = hifi.colors.textFieldLightBackground } // Edit pencil glyph HiFiGlyphs { id: editGlyph text: hifi.glyphs.editPencil - // Size - size: thisNameCard.displayTextHeight*1.5 + // Text Size + size: displayNameTextPixelSize*1.5 // Anchors anchors.right: parent.right anchors.rightMargin: 5 @@ -150,7 +158,7 @@ Item { // Anchors anchors.top: parent.top // Text Size - size: thisNameCard.displayTextHeight + size: displayNameTextPixelSize // Text Positioning verticalAlignment: Text.AlignVCenter // Style @@ -189,7 +197,7 @@ Item { Rectangle { id: nameCardVUMeter // Size - width: isMyCard ? gainSlider.width : ((gainSlider.value - gainSlider.minimumValue)/(gainSlider.maximumValue - gainSlider.minimumValue)) * parent.width + width: isMyCard ? myDisplayName.width - 20 : ((gainSlider.value - gainSlider.minimumValue)/(gainSlider.maximumValue - gainSlider.minimumValue)) * parent.width height: 8 // Anchors anchors.top: spacer.bottom diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 0350e73d2e..3d09be0679 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1047,7 +1047,7 @@ bool AvatarData::processAvatarIdentity(const Identity& identity) { } if (identity.displayName != _displayName) { - setDisplayName(identity.displayName); + _displayName = identity.displayName; hasIdentityChanged = true; } maybeUpdateSessionDisplayNameFromTransport(identity.sessionDisplayName); @@ -1094,6 +1094,7 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) { void AvatarData::setDisplayName(const QString& displayName) { _displayName = displayName; + DependencyManager::get()->getDomainHandler().softReset(); qCDebug(avatars) << "Changing display name for avatar to" << displayName; From e98a40c30e287897fddef8be2fe20f256f7a8485 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Jan 2017 14:43:30 -0800 Subject: [PATCH 06/17] Does this work? --- assignment-client/src/avatars/AvatarMixer.cpp | 12 +++++++++--- .../src/avatars/AvatarMixerClientData.h | 6 +++--- libraries/avatars/src/AvatarData.cpp | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 11cbd73970..8ac2f3922b 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -262,8 +262,13 @@ void AvatarMixer::broadcastAvatarData() { // setup a PacketList for the avatarPackets auto avatarPacketList = NLPacketList::create(PacketType::BulkAvatarData); - if (avatar.getSessionDisplayName().isEmpty() && // We haven't set it yet... - nodeData->getReceivedIdentity()) { // ... but we have processed identity (with possible displayName). + if (nodeData->getAvatarSessionDisplayNameMustChange()) { // ... but we have processed identity (with possible displayName). + const QString& existingBaseDisplayName = nodeData->getBaseDisplayName(); + // No sense guarding against very rare case of a node with no entry, as this will work without the guard and do one less lookup in the common case. + if (--_sessionDisplayNames[existingBaseDisplayName].second <= 0) { + _sessionDisplayNames.remove(existingBaseDisplayName); + } + QString baseName = avatar.getDisplayName().trimmed(); const QRegularExpression curses{ "fuck|shit|damn|cock|cunt" }; // POC. We may eventually want something much more elaborate (subscription?). baseName = baseName.replace(curses, "*"); // Replace rather than remove, so that people have a clue that the person's a jerk. @@ -280,6 +285,7 @@ void AvatarMixer::broadcastAvatarData() { highWater++; soFar.second++; // refcount nodeData->flagIdentityChange(); + nodeData->setAvatarSessionDisplayNameMustChange(false); sendIdentityPacket(nodeData, node); // Tell new node about its sessionUUID. Others will find out below. } @@ -584,7 +590,7 @@ void AvatarMixer::handleAvatarIdentityPacket(QSharedPointer mes if (avatar.processAvatarIdentity(identity)) { QMutexLocker nodeDataLocker(&nodeData->getMutex()); nodeData->flagIdentityChange(); - nodeData->setReceivedIdentity(); + nodeData->setAvatarSessionDisplayNameMustChange(); } } } diff --git a/assignment-client/src/avatars/AvatarMixerClientData.h b/assignment-client/src/avatars/AvatarMixerClientData.h index f18cfdde1b..38db2e74d2 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.h +++ b/assignment-client/src/avatars/AvatarMixerClientData.h @@ -53,8 +53,8 @@ public: HRCTime getIdentityChangeTimestamp() const { return _identityChangeTimestamp; } void flagIdentityChange() { _identityChangeTimestamp = p_high_resolution_clock::now(); } - bool getReceivedIdentity() const { return _gotIdentity; } - void setReceivedIdentity() { _gotIdentity = true; } + bool getAvatarSessionDisplayNameMustChange() const { return _avatarSessionDisplayNameMustChange; } + void setAvatarSessionDisplayNameMustChange(bool set = true) { _avatarSessionDisplayNameMustChange = set; } void setFullRateDistance(float fullRateDistance) { _fullRateDistance = fullRateDistance; } float getFullRateDistance() const { return _fullRateDistance; } @@ -112,7 +112,7 @@ private: std::unordered_set _hasReceivedFirstPacketsFrom; HRCTime _identityChangeTimestamp; - bool _gotIdentity { false }; + bool _avatarSessionDisplayNameMustChange{ false }; float _fullRateDistance = FLT_MAX; float _maxAvatarDistance = FLT_MAX; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 3d09be0679..1fb68fce14 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1094,8 +1094,9 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) { void AvatarData::setDisplayName(const QString& displayName) { _displayName = displayName; + _sessionDisplayName = ""; - DependencyManager::get()->getDomainHandler().softReset(); + sendIdentityPacket(); qCDebug(avatars) << "Changing display name for avatar to" << displayName; } From e72c25736e804bbd625c5855b6d85e7b15086eff Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Jan 2017 15:21:18 -0800 Subject: [PATCH 07/17] Cleanup --- assignment-client/src/avatars/AvatarMixer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 8ac2f3922b..4127719b7b 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -262,9 +262,8 @@ void AvatarMixer::broadcastAvatarData() { // setup a PacketList for the avatarPackets auto avatarPacketList = NLPacketList::create(PacketType::BulkAvatarData); - if (nodeData->getAvatarSessionDisplayNameMustChange()) { // ... but we have processed identity (with possible displayName). + if (nodeData->getAvatarSessionDisplayNameMustChange()) { const QString& existingBaseDisplayName = nodeData->getBaseDisplayName(); - // No sense guarding against very rare case of a node with no entry, as this will work without the guard and do one less lookup in the common case. if (--_sessionDisplayNames[existingBaseDisplayName].second <= 0) { _sessionDisplayNames.remove(existingBaseDisplayName); } @@ -286,7 +285,7 @@ void AvatarMixer::broadcastAvatarData() { soFar.second++; // refcount nodeData->flagIdentityChange(); nodeData->setAvatarSessionDisplayNameMustChange(false); - sendIdentityPacket(nodeData, node); // Tell new node about its sessionUUID. Others will find out below. + sendIdentityPacket(nodeData, node); // Tell node whose name changed about its new session display name. Others will find out below. } // this is an AGENT we have received head data from @@ -590,7 +589,7 @@ void AvatarMixer::handleAvatarIdentityPacket(QSharedPointer mes if (avatar.processAvatarIdentity(identity)) { QMutexLocker nodeDataLocker(&nodeData->getMutex()); nodeData->flagIdentityChange(); - nodeData->setAvatarSessionDisplayNameMustChange(); + nodeData->setAvatarSessionDisplayNameMustChange(true); } } } From 1e8effdcc42d85b6326b0c4d240088e23b36cee1 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Jan 2017 15:28:53 -0800 Subject: [PATCH 08/17] Packet verison bump --- libraries/networking/src/udt/PacketHeaders.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index c012ed8f67..9bbd139138 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -211,7 +211,8 @@ enum class AvatarMixerPacketVersion : PacketVersion { HandControllerJoints, HasKillAvatarReason, SessionDisplayName, - Unignore + Unignore, + ImmediateSessionDisplayNameUpdates }; enum class DomainConnectRequestVersion : PacketVersion { From 6c701bb0f0124002fb8e57c6a1cec8cfec1394ab Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 16 Jan 2017 18:22:53 -0800 Subject: [PATCH 09/17] remove ignored avatars from PAL when they disconnect --- interface/resources/qml/hifi/Pal.qml | 4 ++++ interface/src/avatar/AvatarManager.cpp | 5 +++++ libraries/networking/src/NodeList.cpp | 12 ++++++++++++ libraries/networking/src/NodeList.h | 2 ++ .../script-engine/src/UsersScriptingInterface.h | 6 ++++++ scripts/system/pal.js | 8 +++++++- 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/Pal.qml b/interface/resources/qml/hifi/Pal.qml index 3438baa217..a57e76f864 100644 --- a/interface/resources/qml/hifi/Pal.qml +++ b/interface/resources/qml/hifi/Pal.qml @@ -502,6 +502,10 @@ Rectangle { ignored = {}; gainSliderValueDB = {}; break; + case 'avatarDisconnected': + var sessionID = message.params[0]; + delete ignored[sessionID]; + break; default: console.log('Unrecognized message:', JSON.stringify(message)); } diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 1f5726acba..848218a27e 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -261,6 +261,11 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble || removalReason == YourAvatarEnteredTheirBubble) { DependencyManager::get()->radiusIgnoreNodeBySessionID(avatar->getSessionUUID(), true); } + if (removalReason == KillAvatarReason::AvatarDisconnected) { + // remove from node sets, if present + DependencyManager::get()->maintainIgnoreMuteSets(avatar->getSessionUUID()); + DependencyManager::get()->avatarDisconnected(avatar->getSessionUUID()); + } _avatarFades.push_back(removedAvatar); } diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 98a563c4e5..0ad31b70fe 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -847,6 +847,18 @@ void NodeList::ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled) { } } +// removes this UUID from ignore and mute lists. +void NodeList::maintainIgnoreMuteSets(const QUuid& nodeID) { + // don't remove yourself, or nobody + if (!nodeID.isNull() && _sessionUUID != nodeID) { + QWriteLocker ignoredSetLocker{ &_ignoredSetLock }; + QWriteLocker personalMutedSetLocker{ &_personalMutedSetLock }; + _ignoredNodeIDs.unsafe_erase(nodeID); + _personalMutedNodeIDs.unsafe_erase(nodeID); + qCDebug(networking) << "removed" << nodeID.toString() << "from ignore/mute sets (if present)"; + } +} + bool NodeList::isIgnoringNode(const QUuid& nodeID) const { QReadLocker ignoredSetLocker{ &_ignoredSetLock }; return _ignoredNodeIDs.find(nodeID) != _ignoredNodeIDs.cend(); diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 5c477303e2..4cbe3b1c3b 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -90,6 +90,8 @@ public: bool getRequestsDomainListData() { return _requestsDomainListData; } void setRequestsDomainListData(bool isRequesting); + void maintainIgnoreMuteSets(const QUuid& nodeID); + public slots: void reset(); void sendDomainServerCheckIn(); diff --git a/libraries/script-engine/src/UsersScriptingInterface.h b/libraries/script-engine/src/UsersScriptingInterface.h index 0b6b7855b5..2dcff02c77 100644 --- a/libraries/script-engine/src/UsersScriptingInterface.h +++ b/libraries/script-engine/src/UsersScriptingInterface.h @@ -139,6 +139,12 @@ signals: */ void usernameFromIDReply(const QString& nodeID, const QString& username, const QString& machineFingerprint); + /**jsdoc + * Notifies scripts that a user has disconnected from the domain + * @function Users.avatar.avatarDisconnected + */ + void avatarDisconnected(const QUuid& nodeID); + private: bool getRequestsDomainListData(); void setRequestsDomainListData(bool requests); diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 5c5b84e3e8..ad7d2bd7b5 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -580,7 +580,11 @@ function onClicked() { } pal.setVisible(!pal.visible); } - +function avatarDisconnected(nodeID) { + // remove from the pal list + print("got avatarDisconnected for " + nodeID); + pal.sendToQml({method: 'avatarDisconnected', params: [nodeID]}); +} // // Button state. // @@ -593,6 +597,8 @@ button.clicked.connect(onClicked); pal.visibleChanged.connect(onVisibleChanged); pal.closed.connect(off); Users.usernameFromIDReply.connect(usernameFromIDReply); +Users.avatarDisconnected.connect(avatarDisconnected); + function clearLocalQMLDataAndClosePAL() { pal.sendToQml({ method: 'clearLocalQMLData' }); if (pal.visible) { From 6c07a9aece6920794cc0d69a5f60d585911877ae Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 16 Jan 2017 19:06:36 -0800 Subject: [PATCH 10/17] remove debuggng logspam --- libraries/networking/src/NodeList.cpp | 1 - scripts/system/pal.js | 1 - 2 files changed, 2 deletions(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 0ad31b70fe..8451b2c4a0 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -855,7 +855,6 @@ void NodeList::maintainIgnoreMuteSets(const QUuid& nodeID) { QWriteLocker personalMutedSetLocker{ &_personalMutedSetLock }; _ignoredNodeIDs.unsafe_erase(nodeID); _personalMutedNodeIDs.unsafe_erase(nodeID); - qCDebug(networking) << "removed" << nodeID.toString() << "from ignore/mute sets (if present)"; } } diff --git a/scripts/system/pal.js b/scripts/system/pal.js index ad7d2bd7b5..7ecce80480 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -582,7 +582,6 @@ function onClicked() { } function avatarDisconnected(nodeID) { // remove from the pal list - print("got avatarDisconnected for " + nodeID); pal.sendToQml({method: 'avatarDisconnected', params: [nodeID]}); } // From 2460e89a574613ab615c05c0d2ba283a6d2a5d71 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Tue, 17 Jan 2017 09:53:04 -0800 Subject: [PATCH 11/17] CR feedback --- interface/src/avatar/AvatarManager.cpp | 2 +- libraries/networking/src/NodeList.cpp | 3 +-- libraries/networking/src/NodeList.h | 2 +- scripts/system/pal.js | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 848218a27e..ef08a463f4 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -263,7 +263,7 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar } if (removalReason == KillAvatarReason::AvatarDisconnected) { // remove from node sets, if present - DependencyManager::get()->maintainIgnoreMuteSets(avatar->getSessionUUID()); + DependencyManager::get()->removeFromIgnoreMuteSets(avatar->getSessionUUID()); DependencyManager::get()->avatarDisconnected(avatar->getSessionUUID()); } _avatarFades.push_back(removedAvatar); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 8451b2c4a0..0fcd207b94 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -847,8 +847,7 @@ void NodeList::ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled) { } } -// removes this UUID from ignore and mute lists. -void NodeList::maintainIgnoreMuteSets(const QUuid& nodeID) { +void NodeList::removeFromIgnoreMuteSets(const QUuid& nodeID) { // don't remove yourself, or nobody if (!nodeID.isNull() && _sessionUUID != nodeID) { QWriteLocker ignoredSetLocker{ &_ignoredSetLock }; diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 4cbe3b1c3b..c4564c0889 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -90,7 +90,7 @@ public: bool getRequestsDomainListData() { return _requestsDomainListData; } void setRequestsDomainListData(bool isRequesting); - void maintainIgnoreMuteSets(const QUuid& nodeID); + void removeFromIgnoreMuteSets(const QUuid& nodeID); public slots: void reset(); diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 7ecce80480..fb0d2b310b 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -620,6 +620,7 @@ Script.scriptEnding.connect(function () { Window.domainConnectionRefused.disconnect(clearLocalQMLDataAndClosePAL); Messages.unsubscribe(CHANNEL); Messages.messageReceived.disconnect(receiveMessage); + Users.avatarDisconnected.disconnect(avatarDisconnected); off(); }); From 1e04aebb8d33e9e9bb4a4e072690dc7d5b7f381f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 17 Jan 2017 11:25:40 -0800 Subject: [PATCH 12/17] add --fast-hearbeat command line switch for 1s stats --- interface/src/Application.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ceda6c6598..4f35b10a1b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1238,8 +1238,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo // Add periodic checks to send user activity data static int CHECK_NEARBY_AVATARS_INTERVAL_MS = 10000; - static int SEND_STATS_INTERVAL_MS = 10000; static int NEARBY_AVATAR_RADIUS_METERS = 10; + + // setup the stats interval depending on if the 1s faster hearbeat was requested + static const QString FAST_STATS_ARG = "--fast-heartbeat"; + static int SEND_STATS_INTERVAL_MS = arguments().indexOf(FAST_STATS_ARG) != -1 ? 1000 : 10000; static glm::vec3 lastAvatarPosition = myAvatar->getPosition(); static glm::mat4 lastHMDHeadPose = getHMDSensorPose(); From 246f5fb7f5da02172c45e8c8032bb8274ffd8ef0 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 17 Jan 2017 11:51:09 -0800 Subject: [PATCH 13/17] Add log; fix whitespace --- assignment-client/src/avatars/AvatarMixer.cpp | 4 +++- libraries/networking/src/udt/PacketHeaders.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 4127719b7b..cd866cecb2 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -280,12 +280,14 @@ void AvatarMixer::broadcastAvatarData() { QPair& soFar = _sessionDisplayNames[baseName]; // Inserts and answers 0, 0 if not already present, which is what we want. int& highWater = soFar.first; nodeData->setBaseDisplayName(baseName); - avatar.setSessionDisplayName((highWater > 0) ? baseName + "_" + QString::number(highWater) : baseName); + QString sessionDisplayName = (highWater > 0) ? baseName + "_" + QString::number(highWater) : baseName; + avatar.setSessionDisplayName(sessionDisplayName); highWater++; soFar.second++; // refcount nodeData->flagIdentityChange(); nodeData->setAvatarSessionDisplayNameMustChange(false); sendIdentityPacket(nodeData, node); // Tell node whose name changed about its new session display name. Others will find out below. + qDebug() << "Giving session display name" << sessionDisplayName << "to node with ID" << node->getUUID(); } // this is an AGENT we have received head data from diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 9bbd139138..5cef6013d9 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -212,7 +212,7 @@ enum class AvatarMixerPacketVersion : PacketVersion { HasKillAvatarReason, SessionDisplayName, Unignore, - ImmediateSessionDisplayNameUpdates + ImmediateSessionDisplayNameUpdates }; enum class DomainConnectRequestVersion : PacketVersion { From 9b1aaf3bfeb9a136a79396f75565eb02abd110a0 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Tue, 17 Jan 2017 12:09:47 -0800 Subject: [PATCH 14/17] CR feedback --- interface/src/avatar/AvatarManager.cpp | 3 +-- libraries/script-engine/src/UsersScriptingInterface.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index ef08a463f4..b0dc9922ff 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -260,8 +260,7 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar } if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble || removalReason == YourAvatarEnteredTheirBubble) { DependencyManager::get()->radiusIgnoreNodeBySessionID(avatar->getSessionUUID(), true); - } - if (removalReason == KillAvatarReason::AvatarDisconnected) { + } else if (removalReason == KillAvatarReason::AvatarDisconnected) { // remove from node sets, if present DependencyManager::get()->removeFromIgnoreMuteSets(avatar->getSessionUUID()); DependencyManager::get()->avatarDisconnected(avatar->getSessionUUID()); diff --git a/libraries/script-engine/src/UsersScriptingInterface.h b/libraries/script-engine/src/UsersScriptingInterface.h index 2dcff02c77..758868ac63 100644 --- a/libraries/script-engine/src/UsersScriptingInterface.h +++ b/libraries/script-engine/src/UsersScriptingInterface.h @@ -142,6 +142,7 @@ signals: /**jsdoc * Notifies scripts that a user has disconnected from the domain * @function Users.avatar.avatarDisconnected + * @param {nodeID} NodeID The session ID of the avatar that has disconnected */ void avatarDisconnected(const QUuid& nodeID); From 59ff970d5b400867506418da8761442fdca6dc3d Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 17 Jan 2017 15:01:02 -0800 Subject: [PATCH 15/17] CR feedback --- interface/resources/qml/hifi/NameCard.qml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index 367ef3b25b..2725ea1617 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -75,7 +75,7 @@ Item { id: myDisplayNameText // Properties text: thisNameCard.displayName - maximumLength: 64 + maximumLength: 256 clip: true // Size width: parent.width @@ -84,7 +84,8 @@ Item { anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.leftMargin: 10 - anchors.rightMargin: editGlyph.implicitWidth + editGlyph.anchors.rightMargin + anchors.right: parent.right + anchors.rightMargin: editGlyph.width + editGlyph.anchors.rightMargin // Style color: hifi.colors.darkGray FontLoader { id: firaSansSemiBold; source: "../../fonts/FiraSans-SemiBold.ttf"; } @@ -98,6 +99,7 @@ Item { // Signals onEditingFinished: { pal.sendToScript({method: 'displayNameUpdate', params: text}) + cursorPosition = 0 focus = false myDisplayName.border.width = 0 color = hifi.colors.darkGray From cbc89e77ab11a9d1a0d0657b4eb9405e6b641618 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 17 Jan 2017 09:32:58 -0800 Subject: [PATCH 16/17] Consume fewer resources in AssetServer when interface is running locally --- assignment-client/src/assets/AssetServer.cpp | 48 +++++++++++++++++ interface/src/main.cpp | 2 +- libraries/shared/src/SharedUtil.cpp | 54 +++++++++++++++++++- libraries/shared/src/SharedUtil.h | 4 ++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 2fbe2f6dfe..69f3d83583 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -12,6 +12,8 @@ #include "AssetServer.h" +#include + #include #include #include @@ -21,6 +23,7 @@ #include #include +#include #include #include "NetworkLogging.h" @@ -30,6 +33,37 @@ const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server"; +bool interfaceRunning() { + bool result = false; + +#ifdef Q_OS_WIN + QSharedMemory sharedMemory { getInterfaceSharedMemoryName() }; + result = sharedMemory.attach(QSharedMemory::ReadOnly); + if (result) { + sharedMemory.detach(); + } +#endif + return result; +} + +void updateConsumedCores() { + static bool wasInterfaceRunning = false; + bool isInterfaceRunning = interfaceRunning(); + // If state is unchanged, return early + if (isInterfaceRunning == wasInterfaceRunning) { + return; + } + + wasInterfaceRunning = isInterfaceRunning; + auto coreCount = std::thread::hardware_concurrency(); + if (isInterfaceRunning) { + coreCount = coreCount > 4 ? 2 : 1; + } + qDebug() << "Setting max consumed cores to " << coreCount; + setMaxCores(coreCount); +} + + AssetServer::AssetServer(ReceivedMessage& message) : ThreadedAssignment(message), _taskPool(this) @@ -45,6 +79,20 @@ AssetServer::AssetServer(ReceivedMessage& message) : packetReceiver.registerListener(PacketType::AssetGetInfo, this, "handleAssetGetInfo"); packetReceiver.registerListener(PacketType::AssetUpload, this, "handleAssetUpload"); packetReceiver.registerListener(PacketType::AssetMappingOperation, this, "handleAssetMappingOperation"); + +#ifdef Q_OS_WIN + updateConsumedCores(); + QTimer* timer = new QTimer(this); + auto timerConnection = connect(timer, &QTimer::timeout, [] { + updateConsumedCores(); + }); + connect(qApp, &QCoreApplication::aboutToQuit, [this, timerConnection] { + disconnect(timerConnection); + }); + timer->setInterval(1000); + timer->setTimerType(Qt::CoarseTimer); + timer->start(); +#endif } void AssetServer::run() { diff --git a/interface/src/main.cpp b/interface/src/main.cpp index c83f7a989c..d33dba535e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -56,7 +56,7 @@ int main(int argc, const char* argv[]) { QCoreApplication::setOrganizationDomain(BuildInfo::ORGANIZATION_DOMAIN); QCoreApplication::setApplicationVersion(BuildInfo::VERSION); - QString applicationName = "High Fidelity Interface - " + qgetenv("USERNAME"); + const QString& applicationName = getInterfaceSharedMemoryName(); bool instanceMightBeRunning = true; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 89116aa924..4b8699befd 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include @@ -1022,4 +1024,54 @@ bool getProcessorInfo(ProcessorInfo& info) { #endif return false; -} \ No newline at end of file +} + + +const QString& getInterfaceSharedMemoryName() { + static const QString applicationName = "High Fidelity Interface - " + qgetenv("USERNAME"); + return applicationName; +} + +const std::vector& getAvailableCores() { + static std::vector availableCores; +#ifdef Q_OS_WIN + static std::once_flag once; + std::call_once(once, [&] { + DWORD_PTR defaultProcessAffinity = 0, defaultSystemAffinity = 0; + HANDLE process = GetCurrentProcess(); + GetProcessAffinityMask(process, &defaultProcessAffinity, &defaultSystemAffinity); + for (uint64_t i = 0; i < sizeof(DWORD_PTR) * 8; ++i) { + DWORD_PTR coreMask = 1; + coreMask <<= i; + if (0 != (defaultSystemAffinity & coreMask)) { + availableCores.push_back(i); + } + } + }); +#endif + return availableCores; +} + +void setMaxCores(uint8_t maxCores) { +#ifdef Q_OS_WIN + HANDLE process = GetCurrentProcess(); + auto availableCores = getAvailableCores(); + if (availableCores.size() <= maxCores) { + DWORD_PTR currentProcessAffinity = 0, currentSystemAffinity = 0; + GetProcessAffinityMask(process, ¤tProcessAffinity, ¤tSystemAffinity); + SetProcessAffinityMask(GetCurrentProcess(), currentSystemAffinity); + return; + } + + DWORD_PTR newProcessAffinity = 0; + while (maxCores) { + int index = randIntInRange(0, (int)availableCores.size() - 1); + DWORD_PTR coreMask = 1; + coreMask <<= availableCores[index]; + newProcessAffinity |= coreMask; + availableCores.erase(availableCores.begin() + index); + maxCores--; + } + SetProcessAffinityMask(process, newProcessAffinity); +#endif +} diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 77204c9608..0f30842f47 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -231,4 +231,8 @@ struct ProcessorInfo { bool getProcessorInfo(ProcessorInfo& info); +const QString& getInterfaceSharedMemoryName(); + +void setMaxCores(uint8_t maxCores); + #endif // hifi_SharedUtil_h From a593a2116a069bc8625e8ad2ca57f9d629f56000 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 17 Jan 2017 13:40:19 -0800 Subject: [PATCH 17/17] Removing magic numbers --- assignment-client/src/assets/AssetServer.cpp | 9 +++++++-- libraries/shared/src/SharedUtil.cpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 69f3d83583..2498af8010 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -31,6 +31,11 @@ #include "SendAssetTask.h" #include "UploadAssetTask.h" +static const uint8_t MIN_CORES_FOR_MULTICORE = 4; +static const uint8_t CPU_AFFINITY_COUNT_HIGH = 2; +static const uint8_t CPU_AFFINITY_COUNT_LOW = 1; +static const int INTERFACE_RUNNING_CHECK_FREQUENCY_MS = 1000; + const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server"; bool interfaceRunning() { @@ -57,7 +62,7 @@ void updateConsumedCores() { wasInterfaceRunning = isInterfaceRunning; auto coreCount = std::thread::hardware_concurrency(); if (isInterfaceRunning) { - coreCount = coreCount > 4 ? 2 : 1; + coreCount = coreCount > MIN_CORES_FOR_MULTICORE ? CPU_AFFINITY_COUNT_HIGH : CPU_AFFINITY_COUNT_LOW; } qDebug() << "Setting max consumed cores to " << coreCount; setMaxCores(coreCount); @@ -89,7 +94,7 @@ AssetServer::AssetServer(ReceivedMessage& message) : connect(qApp, &QCoreApplication::aboutToQuit, [this, timerConnection] { disconnect(timerConnection); }); - timer->setInterval(1000); + timer->setInterval(INTERFACE_RUNNING_CHECK_FREQUENCY_MS); timer->setTimerType(Qt::CoarseTimer); timer->start(); #endif diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 4b8699befd..a7e251f0e0 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -1040,7 +1040,7 @@ const std::vector& getAvailableCores() { DWORD_PTR defaultProcessAffinity = 0, defaultSystemAffinity = 0; HANDLE process = GetCurrentProcess(); GetProcessAffinityMask(process, &defaultProcessAffinity, &defaultSystemAffinity); - for (uint64_t i = 0; i < sizeof(DWORD_PTR) * 8; ++i) { + for (uint64_t i = 0; i < sizeof(DWORD_PTR) * BITS_IN_BYTE; ++i) { DWORD_PTR coreMask = 1; coreMask <<= i; if (0 != (defaultSystemAffinity & coreMask)) {