From 2a75d970066bb84d3f72175e62d50d00ff2170f7 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 22 Aug 2017 12:51:28 -0700 Subject: [PATCH 01/22] First steps --- interface/src/Application.cpp | 11 -------- .../ItemHighlightScriptingInterface.cpp | 16 +++++++++++ .../ItemHighlightScriptingInterface.h | 28 +++++++++++++++++++ .../ui/overlays/ContextOverlayInterface.cpp | 18 ++---------- .../src/RenderableModelEntityItem.cpp | 15 ---------- libraries/entities/src/EntityItem.cpp | 20 ------------- libraries/entities/src/EntityItem.h | 4 --- .../entities/src/EntityItemProperties.cpp | 6 ---- libraries/entities/src/EntityItemProperties.h | 1 - .../src/EntityItemPropertiesDefaults.h | 1 - libraries/entities/src/EntityPropertyFlags.h | 1 - .../networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 1 + libraries/render/src/render/Args.h | 7 ----- 14 files changed, 48 insertions(+), 83 deletions(-) create mode 100644 interface/src/scripting/ItemHighlightScriptingInterface.cpp create mode 100644 interface/src/scripting/ItemHighlightScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 398b2dbdb4..65929228bb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5551,17 +5551,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se } renderArgs->_debugFlags = renderDebugFlags; //ViveControllerManager::getInstance().updateRendering(renderArgs, _main3DScene, transaction); - - RenderArgs::OutlineFlags renderOutlineFlags = RenderArgs::RENDER_OUTLINE_NONE; - auto contextOverlayInterface = DependencyManager::get(); - if (contextOverlayInterface->getEnabled()) { - if (DependencyManager::get()->getIsInMarketplaceInspectionMode()) { - renderOutlineFlags = RenderArgs::RENDER_OUTLINE_MARKETPLACE_MODE; - } else { - renderOutlineFlags = RenderArgs::RENDER_OUTLINE_WIREFRAMES; - } - } - renderArgs->_outlineFlags = renderOutlineFlags; } } diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.cpp b/interface/src/scripting/ItemHighlightScriptingInterface.cpp new file mode 100644 index 0000000000..4f59c71beb --- /dev/null +++ b/interface/src/scripting/ItemHighlightScriptingInterface.cpp @@ -0,0 +1,16 @@ +// +// ItemHighlightScriptingInterface.cpp +// interface/src/scripting +// +// Created by Zach Fox on 2017-08-22. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ItemHighlightScriptingInterface.h" + +ItemHighlightScriptingInterface::ItemHighlightScriptingInterface() { + +} diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.h b/interface/src/scripting/ItemHighlightScriptingInterface.h new file mode 100644 index 0000000000..a6b7d33be5 --- /dev/null +++ b/interface/src/scripting/ItemHighlightScriptingInterface.h @@ -0,0 +1,28 @@ + +// ItemHighlightScriptingInterface.h +// interface/src/scripting +// +// Created by Zach Fox on 2017-08-22. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ItemHighlightScriptingInterface_h +#define hifi_ItemHighlightScriptingInterface_h + +class ItemHighlightScriptingInterface : public Dependency { + Q_OBJECT + +public: + +signals: + +public: + ItemHighlightScriptingInterface(); + +private: +}; + +#endif // hifi_ItemHighlightScriptingInterface_h diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 46fb2df007..00c99f3d51 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -260,25 +260,11 @@ void ContextOverlayInterface::openMarketplace() { } void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) { - auto entityTree = qApp->getEntities()->getTree(); - entityTree->withReadLock([&] { - auto entityItem = entityTree->findEntityByEntityItemID(entityItemID); - if ((entityItem != NULL) && !entityItem->getShouldHighlight()) { - qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'true' for Entity ID:" << entityItemID; - entityItem->setShouldHighlight(true); - } - }); + } void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) { - auto entityTree = qApp->getEntities()->getTree(); - entityTree->withReadLock([&] { - auto entityItem = entityTree->findEntityByEntityItemID(entityItemID); - if ((entityItem != NULL) && entityItem->getShouldHighlight()) { - qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << entityItemID; - entityItem->setShouldHighlight(false); - } - }); + } void ContextOverlayInterface::deletingEntity(const EntityItemID& entityID) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 6a2b7678a8..4217675cac 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -381,21 +381,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) { _model->updateRenderItems(); } - // this simple logic should say we set showingEntityHighlight to true whenever we are in marketplace mode and we have a marketplace id, or - // whenever we are not set to none and shouldHighlight is true. - bool showingEntityHighlight = ((bool)(args->_outlineFlags & (int)RenderArgs::RENDER_OUTLINE_MARKETPLACE_MODE) && getMarketplaceID().length() != 0) || - (args->_outlineFlags != RenderArgs::RENDER_OUTLINE_NONE && getShouldHighlight()); - if (showingEntityHighlight) { - static glm::vec4 yellowColor(1.0f, 1.0f, 0.0f, 1.0f); - gpu::Batch& batch = *args->_batch; - bool success; - auto shapeTransform = getTransformToCenter(success); - if (success) { - batch.setModelTransform(shapeTransform); // we want to include the scale as well - DependencyManager::get()->renderWireCubeInstance(args, batch, yellowColor); - } - } - if (!hasModel() || (_model && _model->didVisualGeometryRequestFail())) { static glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); gpu::Batch& batch = *args->_batch; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index c4136a0430..422488f86f 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -133,7 +133,6 @@ EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& param requestedProperties += PROP_LOCKED; requestedProperties += PROP_USER_DATA; requestedProperties += PROP_MARKETPLACE_ID; - requestedProperties += PROP_SHOULD_HIGHLIGHT; requestedProperties += PROP_NAME; requestedProperties += PROP_HREF; requestedProperties += PROP_DESCRIPTION; @@ -279,7 +278,6 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_LOCKED, getLocked()); APPEND_ENTITY_PROPERTY(PROP_USER_DATA, getUserData()); APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, getMarketplaceID()); - APPEND_ENTITY_PROPERTY(PROP_SHOULD_HIGHLIGHT, getShouldHighlight()); APPEND_ENTITY_PROPERTY(PROP_NAME, getName()); APPEND_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, getCollisionSoundURL()); APPEND_ENTITY_PROPERTY(PROP_HREF, getHref()); @@ -831,10 +829,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, QString, setMarketplaceID); } - if (args.bitstreamVersion >= VERSION_ENTITIES_HAS_SHOULD_HIGHLIGHT) { - READ_ENTITY_PROPERTY(PROP_SHOULD_HIGHLIGHT, bool, setShouldHighlight); - } - READ_ENTITY_PROPERTY(PROP_NAME, QString, setName); READ_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, QString, setCollisionSoundURL); READ_ENTITY_PROPERTY(PROP_HREF, QString, setHref); @@ -2809,20 +2803,6 @@ void EntityItem::setMarketplaceID(const QString& value) { }); } -bool EntityItem::getShouldHighlight() const { - bool result; - withReadLock([&] { - result = _shouldHighlight; - }); - return result; -} - -void EntityItem::setShouldHighlight(const bool value) { - withWriteLock([&] { - _shouldHighlight = value; - }); -} - uint32_t EntityItem::getDirtyFlags() const { uint32_t result; withReadLock([&] { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 0801c32cea..062f9cb2ed 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -316,9 +316,6 @@ public: QString getMarketplaceID() const; void setMarketplaceID(const QString& value); - bool getShouldHighlight() const; - void setShouldHighlight(const bool value); - // TODO: get rid of users of getRadius()... float getRadius() const; @@ -535,7 +532,6 @@ protected: QString _userData; SimulationOwner _simulationOwner; QString _marketplaceID; - bool _shouldHighlight { false }; QString _name; QString _href; //Hyperlink href QString _description; //Hyperlink description diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 1bd75f78d4..20b541f563 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -289,7 +289,6 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_RADIUS_START, radiusStart); CHECK_PROPERTY_CHANGE(PROP_RADIUS_FINISH, radiusFinish); CHECK_PROPERTY_CHANGE(PROP_MARKETPLACE_ID, marketplaceID); - CHECK_PROPERTY_CHANGE(PROP_SHOULD_HIGHLIGHT, shouldHighlight); CHECK_PROPERTY_CHANGE(PROP_NAME, name); CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode); CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); @@ -407,7 +406,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LOCKED, locked); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_USER_DATA, userData); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MARKETPLACE_ID, marketplaceID); - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_SHOULD_HIGHLIGHT, shouldHighlight); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_NAME, name); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_COLLISION_SOUND_URL, collisionSoundURL); @@ -984,7 +982,6 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_RADIUS_START, RadiusStart, radiusStart, float); ADD_PROPERTY_TO_MAP(PROP_RADIUS_FINISH, RadiusFinish, radiusFinish, float); ADD_PROPERTY_TO_MAP(PROP_MARKETPLACE_ID, MarketplaceID, marketplaceID, QString); - ADD_PROPERTY_TO_MAP(PROP_SHOULD_HIGHLIGHT, ShouldHighlight, shouldHighlight, bool); ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_COLOR, KeyLightColor, keyLightColor, xColor); ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_INTENSITY, KeyLightIntensity, keyLightIntensity, float); ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLightAmbientIntensity, keyLightAmbientIntensity, float); @@ -1337,7 +1334,6 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_SHAPE, properties.getShape()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); - APPEND_ENTITY_PROPERTY(PROP_SHOULD_HIGHLIGHT, properties.getShouldHighlight()); APPEND_ENTITY_PROPERTY(PROP_NAME, properties.getName()); APPEND_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, properties.getCollisionSoundURL()); APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, properties.getActionData()); @@ -1636,7 +1632,6 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHOULD_HIGHLIGHT, bool, setShouldHighlight); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NAME, QString, setName); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLLISION_SOUND_URL, QString, setCollisionSoundURL); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ACTION_DATA, QByteArray, setActionData); @@ -1751,7 +1746,6 @@ void EntityItemProperties::markAllChanged() { //_alphaFinishChanged = true; _marketplaceIDChanged = true; - _shouldHighlightChanged = true; _keyLight.markAllChanged(); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 8c636addb5..90afd39fbf 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -171,7 +171,6 @@ public: DEFINE_PROPERTY(PROP_RADIUS_FINISH, RadiusFinish, radiusFinish, float, ParticleEffectEntityItem::DEFAULT_RADIUS_FINISH); DEFINE_PROPERTY(PROP_EMITTER_SHOULD_TRAIL, EmitterShouldTrail, emitterShouldTrail, bool, ParticleEffectEntityItem::DEFAULT_EMITTER_SHOULD_TRAIL); DEFINE_PROPERTY_REF(PROP_MARKETPLACE_ID, MarketplaceID, marketplaceID, QString, ENTITY_ITEM_DEFAULT_MARKETPLACE_ID); - DEFINE_PROPERTY_REF(PROP_SHOULD_HIGHLIGHT, ShouldHighlight, shouldHighlight, bool, ENTITY_ITEM_DEFAULT_SHOULD_HIGHLIGHT); DEFINE_PROPERTY_GROUP(KeyLight, keyLight, KeyLightPropertyGroup); DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE); DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray, PolyVoxEntityItem::DEFAULT_VOXEL_DATA); diff --git a/libraries/entities/src/EntityItemPropertiesDefaults.h b/libraries/entities/src/EntityItemPropertiesDefaults.h index 43d0e33ba6..d52c5d9aab 100644 --- a/libraries/entities/src/EntityItemPropertiesDefaults.h +++ b/libraries/entities/src/EntityItemPropertiesDefaults.h @@ -27,7 +27,6 @@ const glm::vec3 ENTITY_ITEM_HALF_VEC3 = glm::vec3(0.5f); const bool ENTITY_ITEM_DEFAULT_LOCKED = false; const QString ENTITY_ITEM_DEFAULT_USER_DATA = QString(""); const QString ENTITY_ITEM_DEFAULT_MARKETPLACE_ID = QString(""); -const bool ENTITY_ITEM_DEFAULT_SHOULD_HIGHLIGHT = false; const QUuid ENTITY_ITEM_DEFAULT_SIMULATOR_ID = QUuid(); const float ENTITY_ITEM_DEFAULT_ALPHA = 1.0f; diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 9600d0d4fe..b3cfc143c2 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -78,7 +78,6 @@ enum EntityPropertyList { PROP_COMPOUND_SHAPE_URL, // used by Model + zones entities PROP_MARKETPLACE_ID, // all entities - PROP_SHOULD_HIGHLIGHT, // all entities PROP_ACCELERATION, // all entities PROP_SIMULATION_OWNER, // formerly known as PROP_SIMULATOR_ID PROP_NAME, // all entities diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 241ccaf5d6..3c6147d6a6 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -30,7 +30,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityEdit: case PacketType::EntityData: case PacketType::EntityPhysics: - return VERSION_ENTITIES_HAS_SHOULD_HIGHLIGHT; + return VERSION_ENTITIES_HAS_HIGHLIGHT_SCRIPTING_INTERFACE; case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::JSONFilterWithFamilyTree); case PacketType::AvatarIdentity: diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 3314e69d78..c1408307be 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -259,6 +259,7 @@ const PacketVersion VERSION_ENTITIES_ZONE_FILTERS = 68; const PacketVersion VERSION_ENTITIES_HINGE_CONSTRAINT = 69; const PacketVersion VERSION_ENTITIES_BULLET_DYNAMICS = 70; const PacketVersion VERSION_ENTITIES_HAS_SHOULD_HIGHLIGHT = 71; +const PacketVersion VERSION_ENTITIES_HAS_HIGHLIGHT_SCRIPTING_INTERFACE = 72; enum class EntityQueryPacketVersion: PacketVersion { JSONFilter = 18, diff --git a/libraries/render/src/render/Args.h b/libraries/render/src/render/Args.h index 12f9506286..7070a4def5 100644 --- a/libraries/render/src/render/Args.h +++ b/libraries/render/src/render/Args.h @@ -63,12 +63,6 @@ namespace render { public: enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE, MIRROR_RENDER_MODE, SECONDARY_CAMERA_RENDER_MODE }; enum DisplayMode { MONO, STEREO_MONITOR, STEREO_HMD }; - enum OutlineFlags { - RENDER_OUTLINE_NONE = 0, - RENDER_OUTLINE_WIREFRAMES = 1, - RENDER_OUTLINE_MARKETPLACE_MODE = 2, - RENDER_OUTLINE_SHADER = 4 - }; enum DebugFlags { RENDER_DEBUG_NONE = 0, RENDER_DEBUG_HULLS = 1 @@ -115,7 +109,6 @@ namespace render { int _boundaryLevelAdjust { 0 }; RenderMode _renderMode { DEFAULT_RENDER_MODE }; DisplayMode _displayMode { MONO }; - OutlineFlags _outlineFlags{ RENDER_OUTLINE_NONE }; DebugFlags _debugFlags { RENDER_DEBUG_NONE }; gpu::Batch* _batch = nullptr; From ec2a27e68c1f22917038c3b7bb9d395e323a9c6e Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 22 Aug 2017 15:02:06 -0700 Subject: [PATCH 02/22] Progress --- interface/src/Application.cpp | 2 + .../ItemHighlightScriptingInterface.cpp | 68 ++++++++++++++++++- .../ItemHighlightScriptingInterface.h | 27 ++++++-- .../ui/overlays/ContextOverlayInterface.cpp | 5 +- .../src/ui/overlays/ContextOverlayInterface.h | 2 + 5 files changed, 96 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 65929228bb..06a33983fc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -166,6 +166,7 @@ #include "scripting/WindowScriptingInterface.h" #include "scripting/ControllerScriptingInterface.h" #include "scripting/RatesScriptingInterface.h" +#include "scripting/ItemHighlightScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" #endif @@ -611,6 +612,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(qApp); DependencyManager::set(); DependencyManager::set(); diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.cpp b/interface/src/scripting/ItemHighlightScriptingInterface.cpp index 4f59c71beb..1b808b3691 100644 --- a/interface/src/scripting/ItemHighlightScriptingInterface.cpp +++ b/interface/src/scripting/ItemHighlightScriptingInterface.cpp @@ -10,7 +10,71 @@ // #include "ItemHighlightScriptingInterface.h" +#include "Application.h" -ItemHighlightScriptingInterface::ItemHighlightScriptingInterface() { - +ItemHighlightScriptingInterface::ItemHighlightScriptingInterface(AbstractViewStateInterface* viewState) { + _viewState = viewState; +} + +bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const EntityItemID& entityID) { + auto entityTree = qApp->getEntities()->getTree(); + entityTree->withReadLock([&] { + auto entityItem = entityTree->findEntityByEntityItemID(entityID); + if ((entityItem != NULL)) { + addToHighlightedItemsList(entityItem->getRenderItemID()); + } + }); +} +bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(const EntityItemID& entityID) { +} + +bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const OverlayID& overlayID) { + auto& overlays = qApp->getOverlays(); + auto overlay = overlays.getOverlay(overlayID); + if (overlay != NULL) { + auto itemID = overlay->getRenderItemID(); + if (itemID != render::Item::INVALID_ITEM_ID) { + addToHighlightedItemsList(overlay->getRenderItemID()); + } + } +} +bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(const OverlayID& overlayID) { + auto& overlays = qApp->getOverlays(); + auto overlay = overlays.getOverlay(overlayID); + if (overlay != NULL) { + auto itemID = overlay->getRenderItemID(); + if (itemID != render::Item::INVALID_ITEM_ID) { + removeFromHighlightedItemsList(overlay->getRenderItemID()); + } + } +} + +bool ItemHighlightScriptingInterface::addToHighlightedItemsList(render::ItemID idToAdd) { + _highlightedItemsList.push_back(idToAdd); + updateRendererHighlightList(); + return true; +} +bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(render::ItemID idToRemove) { + auto itr = std::find(_highlightedItemsList.begin(), _highlightedItemsList.end(), idToRemove); + if (itr == _highlightedItemsList.end()) { + return false; + } else { + _highlightedItemsList.erase(itr); + updateRendererHighlightList(); + return true; + } +} + +void ItemHighlightScriptingInterface::updateRendererHighlightList() { + auto scene = _viewState->getMain3DScene(); + if (scene) { + render::Transaction transaction; + + render::Selection selection("Highlight", _highlightedItemsList); + transaction.resetSelection(selection); + + scene->enqueueTransaction(transaction); + } else { + qWarning() << "ItemHighlightScriptingInterface::updateRendererHighlightList(), Unexpected null scene, possibly during application shutdown"; + } } diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.h b/interface/src/scripting/ItemHighlightScriptingInterface.h index a6b7d33be5..ad5e9db83e 100644 --- a/interface/src/scripting/ItemHighlightScriptingInterface.h +++ b/interface/src/scripting/ItemHighlightScriptingInterface.h @@ -12,17 +12,36 @@ #ifndef hifi_ItemHighlightScriptingInterface_h #define hifi_ItemHighlightScriptingInterface_h -class ItemHighlightScriptingInterface : public Dependency { +#include +#include + +#include + +#include "EntityItemID.h" +#include "ui/overlays/Overlay.h" + +class ItemHighlightScriptingInterface : public QObject, public Dependency { Q_OBJECT public: + ItemHighlightScriptingInterface(AbstractViewStateInterface* viewState); -signals: + Q_INVOKABLE bool addToHighlightedItemsList(const EntityItemID& entityID); + Q_INVOKABLE bool removeFromHighlightedItemsList(const EntityItemID& entityID); + + Q_INVOKABLE bool addToHighlightedItemsList(const OverlayID& overlayID); + Q_INVOKABLE bool removeFromHighlightedItemsList(const OverlayID& overlayID); -public: - ItemHighlightScriptingInterface(); +//signals: private: + AbstractViewStateInterface* _viewState; + render::ItemIDs _highlightedItemsList; + + bool addToHighlightedItemsList(render::ItemID idToAdd); + bool removeFromHighlightedItemsList(render::ItemID idToRemove); + + void updateRendererHighlightList(); }; #endif // hifi_ItemHighlightScriptingInterface_h diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 00c99f3d51..79447e8f4c 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -27,6 +27,7 @@ ContextOverlayInterface::ContextOverlayInterface() { _entityScriptingInterface = DependencyManager::get(); _hmdScriptingInterface = DependencyManager::get(); _tabletScriptingInterface = DependencyManager::get(); + _itemHighlightScriptingInterface = DependencyManager::get(); _entityPropertyFlags += PROP_POSITION; _entityPropertyFlags += PROP_ROTATION; @@ -260,11 +261,11 @@ void ContextOverlayInterface::openMarketplace() { } void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) { - + _itemHighlightScriptingInterface->addToHighlightedItemsList(entityItemID); } void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) { - + _itemHighlightScriptingInterface->removeFromHighlightedItemsList(entityItemID); } void ContextOverlayInterface::deletingEntity(const EntityItemID& entityID) { diff --git a/interface/src/ui/overlays/ContextOverlayInterface.h b/interface/src/ui/overlays/ContextOverlayInterface.h index b386de08cc..ccfd675e64 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.h +++ b/interface/src/ui/overlays/ContextOverlayInterface.h @@ -25,6 +25,7 @@ #include "ui/overlays/Image3DOverlay.h" #include "ui/overlays/Overlays.h" #include "scripting/HMDScriptingInterface.h" +#include "scripting/ItemHighlightScriptingInterface.h" #include "EntityTree.h" #include "ContextOverlayLogging.h" @@ -42,6 +43,7 @@ class ContextOverlayInterface : public QObject, public Dependency { EntityPropertyFlags _entityPropertyFlags; QSharedPointer _hmdScriptingInterface; QSharedPointer _tabletScriptingInterface; + QSharedPointer _itemHighlightScriptingInterface; OverlayID _contextOverlayID { UNKNOWN_OVERLAY_ID }; std::shared_ptr _contextOverlay { nullptr }; public: From edb64b047f309040413a381a9d6cb6caa81f477b Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 22 Aug 2017 15:51:00 -0700 Subject: [PATCH 03/22] It compiles! --- .../ItemHighlightScriptingInterface.cpp | 68 +++++++++++++++---- .../ItemHighlightScriptingInterface.h | 2 +- .../src/RenderableEntityItem.h | 4 ++ .../src/RenderableLightEntityItem.h | 2 + .../src/RenderableModelEntityItem.h | 2 + .../src/RenderableParticleEffectEntityItem.h | 2 + .../src/RenderablePolyVoxEntityItem.h | 2 + .../src/RenderableZoneEntityItem.h | 2 + 8 files changed, 69 insertions(+), 15 deletions(-) diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.cpp b/interface/src/scripting/ItemHighlightScriptingInterface.cpp index 1b808b3691..be2e43176e 100644 --- a/interface/src/scripting/ItemHighlightScriptingInterface.cpp +++ b/interface/src/scripting/ItemHighlightScriptingInterface.cpp @@ -16,46 +16,83 @@ ItemHighlightScriptingInterface::ItemHighlightScriptingInterface(AbstractViewSta _viewState = viewState; } -bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const EntityItemID& entityID) { +// +// START HANDLING ENTITIES +// +render::ItemID getItemIDFromEntityID(const EntityItemID& entityID) { auto entityTree = qApp->getEntities()->getTree(); entityTree->withReadLock([&] { auto entityItem = entityTree->findEntityByEntityItemID(entityID); - if ((entityItem != NULL)) { - addToHighlightedItemsList(entityItem->getRenderItemID()); + if (entityItem != NULL) { + auto renderableInterface = entityItem->getRenderableInterface(); + if (renderableInterface != NULL) { + return renderableInterface->getMetaRenderItemID(); + } } + return render::Item::INVALID_ITEM_ID; }); + return render::Item::INVALID_ITEM_ID; +} +bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const EntityItemID& entityID) { + render::ItemID itemID = getItemIDFromEntityID(entityID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return addToHighlightedItemsList(itemID); + } + return false; } bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(const EntityItemID& entityID) { + render::ItemID itemID = getItemIDFromEntityID(entityID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return removeFromHighlightedItemsList(itemID); + } + return false; } +// +// END HANDLING ENTITIES +// -bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const OverlayID& overlayID) { +// +// START HANDLING OVERLAYS +// +render::ItemID getItemIDFromOverlayID(const OverlayID& overlayID) { auto& overlays = qApp->getOverlays(); auto overlay = overlays.getOverlay(overlayID); if (overlay != NULL) { auto itemID = overlay->getRenderItemID(); if (itemID != render::Item::INVALID_ITEM_ID) { - addToHighlightedItemsList(overlay->getRenderItemID()); + return overlay->getRenderItemID(); } } + return render::Item::INVALID_ITEM_ID; +} +bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const OverlayID& overlayID) { + render::ItemID itemID = getItemIDFromOverlayID(overlayID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return addToHighlightedItemsList(itemID); + } + return false; } bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(const OverlayID& overlayID) { - auto& overlays = qApp->getOverlays(); - auto overlay = overlays.getOverlay(overlayID); - if (overlay != NULL) { - auto itemID = overlay->getRenderItemID(); - if (itemID != render::Item::INVALID_ITEM_ID) { - removeFromHighlightedItemsList(overlay->getRenderItemID()); - } + render::ItemID itemID = getItemIDFromOverlayID(overlayID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return removeFromHighlightedItemsList(itemID); } + return false; } +// +// END HANDLING OVERLAYS +// +// +// START HANDLING GENERIC ITEMS +// bool ItemHighlightScriptingInterface::addToHighlightedItemsList(render::ItemID idToAdd) { - _highlightedItemsList.push_back(idToAdd); + _highlightedItemsList.push_back(idToAdd); // TODO: Ensure thread safety updateRendererHighlightList(); return true; } bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(render::ItemID idToRemove) { - auto itr = std::find(_highlightedItemsList.begin(), _highlightedItemsList.end(), idToRemove); + auto itr = std::find(_highlightedItemsList.begin(), _highlightedItemsList.end(), idToRemove); // TODO: Ensure thread safety if (itr == _highlightedItemsList.end()) { return false; } else { @@ -64,6 +101,9 @@ bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(render::Ite return true; } } +// +// END HANDLING GENERIC ITEMS +// void ItemHighlightScriptingInterface::updateRendererHighlightList() { auto scene = _viewState->getMain3DScene(); diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.h b/interface/src/scripting/ItemHighlightScriptingInterface.h index ad5e9db83e..00349629db 100644 --- a/interface/src/scripting/ItemHighlightScriptingInterface.h +++ b/interface/src/scripting/ItemHighlightScriptingInterface.h @@ -17,7 +17,7 @@ #include -#include "EntityItemID.h" +#include "RenderableEntityItem.h" #include "ui/overlays/Overlay.h" class ItemHighlightScriptingInterface : public QObject, public Dependency { diff --git a/libraries/entities-renderer/src/RenderableEntityItem.h b/libraries/entities-renderer/src/RenderableEntityItem.h index 93cd524acd..819aee15c7 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableEntityItem.h @@ -44,6 +44,9 @@ public: const SharedSoundPointer& getCollisionSound() { return _collisionSound; } void setCollisionSound(const SharedSoundPointer& sound) { _collisionSound = sound; } virtual RenderableEntityInterface* getRenderableInterface() { return nullptr; } + + virtual render::ItemID getMetaRenderItemID() { return render::Item::INVALID_ITEM_ID; } + private: SharedSoundPointer _collisionSound; }; @@ -86,6 +89,7 @@ public: \ virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); notifyChanged(); } \ virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); notifyChanged(); } \ virtual RenderableEntityInterface* getRenderableInterface() override { return this; } \ + render::ItemID getMetaRenderItemID() override { return render::Item::INVALID_ITEM_ID; } \ void checkFading() { \ bool transparent = isTransparent(); \ if (transparent != _prevIsTransparent) { \ diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.h b/libraries/entities-renderer/src/RenderableLightEntityItem.h index a9f4ba84b6..68a231c8e0 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.h @@ -24,6 +24,8 @@ public: RenderableEntityInterface* getRenderableInterface() override { return this; } + render::ItemID getMetaRenderItemID() override { return render::Item::INVALID_ITEM_ID; } + virtual bool supportsDetailedRayIntersection() const override { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 63c212891f..ae55f83ce1 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -34,6 +34,8 @@ public: RenderableEntityInterface* getRenderableInterface() override { return this; } + render::ItemID getMetaRenderItemID() override { return _myMetaItem; } + virtual void setDimensions(const glm::vec3& value) override; virtual void setModelURL(const QString& url) override; diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h index b0d7e1c920..e8f734256e 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h @@ -23,6 +23,8 @@ public: RenderableEntityInterface* getRenderableInterface() override { return this; } + render::ItemID getMetaRenderItemID() override { return _renderItemId; } + virtual void update(const quint64& now) override; void updateRenderItem(); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 5741931ea2..676f807da6 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -68,6 +68,8 @@ public: RenderableEntityInterface* getRenderableInterface() override { return this; } + render::ItemID getMetaRenderItemID() override { return _myItem; } + void initializePolyVox(); virtual void somethingChangedNotification() override { diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 4685a0d3e1..1fcc36e158 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -33,6 +33,8 @@ public: RenderableEntityInterface* getRenderableInterface() override { return this; } + render::ItemID getMetaRenderItemID() override { return _myMetaItem; } + virtual bool setProperties(const EntityItemProperties& properties) override; virtual void somethingChangedNotification() override; From 69364f2ecd7137d54c736e3125096b8618897e1e Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 22 Aug 2017 16:57:04 -0700 Subject: [PATCH 04/22] Initial progress --- interface/src/Application.cpp | 4 +- .../ItemHighlightScriptingInterface.cpp | 120 -------------- .../ItemHighlightScriptingInterface.h | 47 ------ .../scripting/SelectionScriptingInterface.cpp | 146 ++++++++++++++++++ .../scripting/SelectionScriptingInterface.h | 48 ++++++ .../ui/overlays/ContextOverlayInterface.cpp | 6 +- .../src/ui/overlays/ContextOverlayInterface.h | 4 +- .../src/RenderableLightEntityItem.h | 2 +- 8 files changed, 202 insertions(+), 175 deletions(-) delete mode 100644 interface/src/scripting/ItemHighlightScriptingInterface.cpp delete mode 100644 interface/src/scripting/ItemHighlightScriptingInterface.h create mode 100644 interface/src/scripting/SelectionScriptingInterface.cpp create mode 100644 interface/src/scripting/SelectionScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 06a33983fc..0a2f319841 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -166,7 +166,7 @@ #include "scripting/WindowScriptingInterface.h" #include "scripting/ControllerScriptingInterface.h" #include "scripting/RatesScriptingInterface.h" -#include "scripting/ItemHighlightScriptingInterface.h" +#include "scripting/SelectionScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" #endif @@ -612,7 +612,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(qApp); + DependencyManager::set(qApp); DependencyManager::set(); DependencyManager::set(); diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.cpp b/interface/src/scripting/ItemHighlightScriptingInterface.cpp deleted file mode 100644 index be2e43176e..0000000000 --- a/interface/src/scripting/ItemHighlightScriptingInterface.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// -// ItemHighlightScriptingInterface.cpp -// interface/src/scripting -// -// Created by Zach Fox on 2017-08-22. -// Copyright 2017 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "ItemHighlightScriptingInterface.h" -#include "Application.h" - -ItemHighlightScriptingInterface::ItemHighlightScriptingInterface(AbstractViewStateInterface* viewState) { - _viewState = viewState; -} - -// -// START HANDLING ENTITIES -// -render::ItemID getItemIDFromEntityID(const EntityItemID& entityID) { - auto entityTree = qApp->getEntities()->getTree(); - entityTree->withReadLock([&] { - auto entityItem = entityTree->findEntityByEntityItemID(entityID); - if (entityItem != NULL) { - auto renderableInterface = entityItem->getRenderableInterface(); - if (renderableInterface != NULL) { - return renderableInterface->getMetaRenderItemID(); - } - } - return render::Item::INVALID_ITEM_ID; - }); - return render::Item::INVALID_ITEM_ID; -} -bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const EntityItemID& entityID) { - render::ItemID itemID = getItemIDFromEntityID(entityID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return addToHighlightedItemsList(itemID); - } - return false; -} -bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(const EntityItemID& entityID) { - render::ItemID itemID = getItemIDFromEntityID(entityID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return removeFromHighlightedItemsList(itemID); - } - return false; -} -// -// END HANDLING ENTITIES -// - -// -// START HANDLING OVERLAYS -// -render::ItemID getItemIDFromOverlayID(const OverlayID& overlayID) { - auto& overlays = qApp->getOverlays(); - auto overlay = overlays.getOverlay(overlayID); - if (overlay != NULL) { - auto itemID = overlay->getRenderItemID(); - if (itemID != render::Item::INVALID_ITEM_ID) { - return overlay->getRenderItemID(); - } - } - return render::Item::INVALID_ITEM_ID; -} -bool ItemHighlightScriptingInterface::addToHighlightedItemsList(const OverlayID& overlayID) { - render::ItemID itemID = getItemIDFromOverlayID(overlayID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return addToHighlightedItemsList(itemID); - } - return false; -} -bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(const OverlayID& overlayID) { - render::ItemID itemID = getItemIDFromOverlayID(overlayID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return removeFromHighlightedItemsList(itemID); - } - return false; -} -// -// END HANDLING OVERLAYS -// - -// -// START HANDLING GENERIC ITEMS -// -bool ItemHighlightScriptingInterface::addToHighlightedItemsList(render::ItemID idToAdd) { - _highlightedItemsList.push_back(idToAdd); // TODO: Ensure thread safety - updateRendererHighlightList(); - return true; -} -bool ItemHighlightScriptingInterface::removeFromHighlightedItemsList(render::ItemID idToRemove) { - auto itr = std::find(_highlightedItemsList.begin(), _highlightedItemsList.end(), idToRemove); // TODO: Ensure thread safety - if (itr == _highlightedItemsList.end()) { - return false; - } else { - _highlightedItemsList.erase(itr); - updateRendererHighlightList(); - return true; - } -} -// -// END HANDLING GENERIC ITEMS -// - -void ItemHighlightScriptingInterface::updateRendererHighlightList() { - auto scene = _viewState->getMain3DScene(); - if (scene) { - render::Transaction transaction; - - render::Selection selection("Highlight", _highlightedItemsList); - transaction.resetSelection(selection); - - scene->enqueueTransaction(transaction); - } else { - qWarning() << "ItemHighlightScriptingInterface::updateRendererHighlightList(), Unexpected null scene, possibly during application shutdown"; - } -} diff --git a/interface/src/scripting/ItemHighlightScriptingInterface.h b/interface/src/scripting/ItemHighlightScriptingInterface.h deleted file mode 100644 index 00349629db..0000000000 --- a/interface/src/scripting/ItemHighlightScriptingInterface.h +++ /dev/null @@ -1,47 +0,0 @@ - -// ItemHighlightScriptingInterface.h -// interface/src/scripting -// -// Created by Zach Fox on 2017-08-22. -// Copyright 2017 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_ItemHighlightScriptingInterface_h -#define hifi_ItemHighlightScriptingInterface_h - -#include -#include - -#include - -#include "RenderableEntityItem.h" -#include "ui/overlays/Overlay.h" - -class ItemHighlightScriptingInterface : public QObject, public Dependency { - Q_OBJECT - -public: - ItemHighlightScriptingInterface(AbstractViewStateInterface* viewState); - - Q_INVOKABLE bool addToHighlightedItemsList(const EntityItemID& entityID); - Q_INVOKABLE bool removeFromHighlightedItemsList(const EntityItemID& entityID); - - Q_INVOKABLE bool addToHighlightedItemsList(const OverlayID& overlayID); - Q_INVOKABLE bool removeFromHighlightedItemsList(const OverlayID& overlayID); - -//signals: - -private: - AbstractViewStateInterface* _viewState; - render::ItemIDs _highlightedItemsList; - - bool addToHighlightedItemsList(render::ItemID idToAdd); - bool removeFromHighlightedItemsList(render::ItemID idToRemove); - - void updateRendererHighlightList(); -}; - -#endif // hifi_ItemHighlightScriptingInterface_h diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp new file mode 100644 index 0000000000..9c74565c5f --- /dev/null +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -0,0 +1,146 @@ +// +// SelectionScriptingInterface.cpp +// interface/src/scripting +// +// Created by Zach Fox on 2017-08-22. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "SelectionScriptingInterface.h" +#include "Application.h" + +SelectionScriptingInterface::SelectionScriptingInterface(AbstractViewStateInterface* viewState) { + _viewState = viewState; +} + +// +// START HANDLING ENTITIES +// +render::ItemID getItemIDFromEntityID(const EntityItemID& entityID) { + auto entityTree = qApp->getEntities()->getTree(); + entityTree->withReadLock([&] { + auto entityItem = entityTree->findEntityByEntityItemID(entityID); + if (entityItem != NULL) { + auto renderableInterface = entityItem->getRenderableInterface(); + if (renderableInterface != NULL) { + return renderableInterface->getMetaRenderItemID(); + } + } + return render::Item::INVALID_ITEM_ID; + }); + return render::Item::INVALID_ITEM_ID; +} +bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID) { + render::ItemID itemID = getItemIDFromEntityID(entityID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return addToSelectedItemsList(listName, itemID); + } + return false; +} +bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID) { + render::ItemID itemID = getItemIDFromEntityID(entityID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return removeFromSelectedItemsList(listName, itemID); + } + return false; +} +// +// END HANDLING ENTITIES +// + +// +// START HANDLING OVERLAYS +// +render::ItemID getItemIDFromOverlayID(const OverlayID& overlayID) { + auto& overlays = qApp->getOverlays(); + auto overlay = overlays.getOverlay(overlayID); + if (overlay != NULL) { + auto itemID = overlay->getRenderItemID(); + if (itemID != render::Item::INVALID_ITEM_ID) { + return overlay->getRenderItemID(); + } + } + return render::Item::INVALID_ITEM_ID; +} +bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID) { + render::ItemID itemID = getItemIDFromOverlayID(overlayID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return addToSelectedItemsList(listName, itemID); + } + return false; +} +bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID) { + render::ItemID itemID = getItemIDFromOverlayID(overlayID); + if (itemID != render::Item::INVALID_ITEM_ID) { + return removeFromSelectedItemsList(listName, itemID); + } + return false; +} +// +// END HANDLING OVERLAYS +// + +// +// START HANDLING GENERIC ITEMS +// +bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToAdd) { + if (_selectedItemsListMap.contains(listName)) { + auto currentList = _selectedItemsListMap.take(listName); + currentList.push_back(idToAdd); // TODO: Ensure thread safety + _selectedItemsListMap.insert(listName, currentList); + updateRendererSelectedList(listName); + return true; + } else { + _selectedItemsListMap.insert(listName, render::ItemIDs()); + return addToSelectedItemsList(listName, idToAdd); + } +} +bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToRemove) { + auto hashItr = _selectedItemsListMap.find(listName); + if (hashItr != _selectedItemsListMap.end()) { + auto currentList = _selectedItemsListMap.take(listName); + auto listItr = std::find(currentList.begin(), currentList.end(), idToRemove); // TODO: Ensure thread safety + if (listItr == currentList.end()) { + return false; + } else { + currentList.erase(listItr); + _selectedItemsListMap.insert(listName, currentList); + updateRendererSelectedList(listName); + return true; + } + } else { + return false; + } +} +// +// END HANDLING GENERIC ITEMS +// + +bool SelectionScriptingInterface::removeListFromMap(const render::Selection::Name& listName) { + if (_selectedItemsListMap.remove(listName)) { + return true; + } else { + return false; + } +} + +void SelectionScriptingInterface::updateRendererSelectedList(const render::Selection::Name& listName) { + auto scene = _viewState->getMain3DScene(); + if (scene) { + render::Transaction transaction; + + if (_selectedItemsListMap.contains(listName)) { + render::Selection selection(listName, _selectedItemsListMap.value(listName)); + transaction.resetSelection(selection); + + scene->enqueueTransaction(transaction); + } else { + qWarning() << "List of ItemIDs doesn't exist in _selectedItemsListMap"; + } + } else { + qWarning() << "SelectionScriptingInterface::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; + } +} diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h new file mode 100644 index 0000000000..24cc66aefe --- /dev/null +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -0,0 +1,48 @@ + +// SelectionScriptingInterface.h +// interface/src/scripting +// +// Created by Zach Fox on 2017-08-22. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_SelectionScriptingInterface_h +#define hifi_SelectionScriptingInterface_h + +#include +#include +#include + +#include + +#include "RenderableEntityItem.h" +#include "ui/overlays/Overlay.h" + +class SelectionScriptingInterface : public QObject, public Dependency { + Q_OBJECT + +public: + SelectionScriptingInterface(AbstractViewStateInterface* viewState); + + Q_INVOKABLE bool removeListFromMap(const render::Selection::Name& listName); + + Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID); + Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID); + + Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID); + Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID); + +private: + AbstractViewStateInterface* _viewState; + QMap _selectedItemsListMap; + + bool addToSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToAdd); + bool removeFromSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToRemove); + + void updateRendererSelectedList(const render::Selection::Name& listName); +}; + +#endif // hifi_SelectionScriptingInterface_h diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 79447e8f4c..d4dbe467a9 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -27,7 +27,7 @@ ContextOverlayInterface::ContextOverlayInterface() { _entityScriptingInterface = DependencyManager::get(); _hmdScriptingInterface = DependencyManager::get(); _tabletScriptingInterface = DependencyManager::get(); - _itemHighlightScriptingInterface = DependencyManager::get(); + _selectionScriptingInterface = DependencyManager::get(); _entityPropertyFlags += PROP_POSITION; _entityPropertyFlags += PROP_ROTATION; @@ -261,11 +261,11 @@ void ContextOverlayInterface::openMarketplace() { } void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) { - _itemHighlightScriptingInterface->addToHighlightedItemsList(entityItemID); + _selectionScriptingInterface->addToSelectedItemsList("contextOverlayHighlightList", entityItemID); } void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) { - _itemHighlightScriptingInterface->removeFromHighlightedItemsList(entityItemID); + _selectionScriptingInterface->removeFromSelectedItemsList("contextOverlayHighlightList", entityItemID); } void ContextOverlayInterface::deletingEntity(const EntityItemID& entityID) { diff --git a/interface/src/ui/overlays/ContextOverlayInterface.h b/interface/src/ui/overlays/ContextOverlayInterface.h index ccfd675e64..bc650a0ef2 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.h +++ b/interface/src/ui/overlays/ContextOverlayInterface.h @@ -25,7 +25,7 @@ #include "ui/overlays/Image3DOverlay.h" #include "ui/overlays/Overlays.h" #include "scripting/HMDScriptingInterface.h" -#include "scripting/ItemHighlightScriptingInterface.h" +#include "scripting/SelectionScriptingInterface.h" #include "EntityTree.h" #include "ContextOverlayLogging.h" @@ -43,7 +43,7 @@ class ContextOverlayInterface : public QObject, public Dependency { EntityPropertyFlags _entityPropertyFlags; QSharedPointer _hmdScriptingInterface; QSharedPointer _tabletScriptingInterface; - QSharedPointer _itemHighlightScriptingInterface; + QSharedPointer _selectionScriptingInterface; OverlayID _contextOverlayID { UNKNOWN_OVERLAY_ID }; std::shared_ptr _contextOverlay { nullptr }; public: diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.h b/libraries/entities-renderer/src/RenderableLightEntityItem.h index 68a231c8e0..b16a93bc2c 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.h @@ -24,7 +24,7 @@ public: RenderableEntityInterface* getRenderableInterface() override { return this; } - render::ItemID getMetaRenderItemID() override { return render::Item::INVALID_ITEM_ID; } + render::ItemID getMetaRenderItemID() override { return _myItem; } virtual bool supportsDetailedRayIntersection() const override { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, From 88c24c16d70d153affdf147d0df9350397b9eed1 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 23 Aug 2017 14:45:04 -0700 Subject: [PATCH 05/22] I finally understand - initial progress --- .../scripting/SelectionScriptingInterface.cpp | 161 +++++++++++------- .../scripting/SelectionScriptingInterface.h | 32 +++- .../src/avatars-renderer/Avatar.h | 1 + 3 files changed, 129 insertions(+), 65 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 9c74565c5f..8c002b28f2 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -12,40 +12,61 @@ #include "SelectionScriptingInterface.h" #include "Application.h" +GameplayObjects::GameplayObjects() { +} + +bool GameplayObjects::addToGameplayObjects(const QUuid& avatarID) { + _avatarIDs.push_back(avatarID); + return true; +} +bool GameplayObjects::removeFromGameplayObjects(const QUuid& avatarID) { + _avatarIDs.erase(std::remove(_avatarIDs.begin(), _avatarIDs.end(), avatarID), _avatarIDs.end()); + return true; +} + +bool GameplayObjects::addToGameplayObjects(const EntityItemID& entityID) { + _entityIDs.push_back(entityID); + return true; +} +bool GameplayObjects::removeFromGameplayObjects(const EntityItemID& entityID) { + _entityIDs.erase(std::remove(_entityIDs.begin(), _entityIDs.end(), entityID), _entityIDs.end()); + return true; +} + +bool GameplayObjects::addToGameplayObjects(const OverlayID& overlayID) { + _overlayIDs.push_back(overlayID); + return true; +} +bool GameplayObjects::removeFromGameplayObjects(const OverlayID& overlayID) { + _overlayIDs.erase(std::remove(_overlayIDs.begin(), _overlayIDs.end(), overlayID), _overlayIDs.end()); + return true; +} + SelectionScriptingInterface::SelectionScriptingInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; } +// +// START HANDLING AVATARS +// +bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID) { + return addToGameplayObjects(listName, avatarSessionID); +} +bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID) { + return addToGameplayObjects(listName, avatarSessionID); +} +// +// END HANDLING AVATARS +// + // // START HANDLING ENTITIES // -render::ItemID getItemIDFromEntityID(const EntityItemID& entityID) { - auto entityTree = qApp->getEntities()->getTree(); - entityTree->withReadLock([&] { - auto entityItem = entityTree->findEntityByEntityItemID(entityID); - if (entityItem != NULL) { - auto renderableInterface = entityItem->getRenderableInterface(); - if (renderableInterface != NULL) { - return renderableInterface->getMetaRenderItemID(); - } - } - return render::Item::INVALID_ITEM_ID; - }); - return render::Item::INVALID_ITEM_ID; -} bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID) { - render::ItemID itemID = getItemIDFromEntityID(entityID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return addToSelectedItemsList(listName, itemID); - } - return false; + return addToGameplayObjects(listName, entityID); } bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID) { - render::ItemID itemID = getItemIDFromEntityID(entityID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return removeFromSelectedItemsList(listName, itemID); - } - return false; + return addToGameplayObjects(listName, entityID); } // // END HANDLING ENTITIES @@ -54,30 +75,11 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Sele // // START HANDLING OVERLAYS // -render::ItemID getItemIDFromOverlayID(const OverlayID& overlayID) { - auto& overlays = qApp->getOverlays(); - auto overlay = overlays.getOverlay(overlayID); - if (overlay != NULL) { - auto itemID = overlay->getRenderItemID(); - if (itemID != render::Item::INVALID_ITEM_ID) { - return overlay->getRenderItemID(); - } - } - return render::Item::INVALID_ITEM_ID; -} bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID) { - render::ItemID itemID = getItemIDFromOverlayID(overlayID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return addToSelectedItemsList(listName, itemID); - } - return false; + return addToGameplayObjects(listName, overlayID); } bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID) { - render::ItemID itemID = getItemIDFromOverlayID(overlayID); - if (itemID != render::Item::INVALID_ITEM_ID) { - return removeFromSelectedItemsList(listName, itemID); - } - return false; + return addToGameplayObjects(listName, overlayID); } // // END HANDLING OVERLAYS @@ -86,31 +88,25 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Sele // // START HANDLING GENERIC ITEMS // -bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToAdd) { +template bool SelectionScriptingInterface::addToGameplayObjects(const render::Selection::Name& listName, T idToAdd) { if (_selectedItemsListMap.contains(listName)) { auto currentList = _selectedItemsListMap.take(listName); - currentList.push_back(idToAdd); // TODO: Ensure thread safety + currentList.addToGameplayObjects(idToAdd); _selectedItemsListMap.insert(listName, currentList); updateRendererSelectedList(listName); return true; } else { - _selectedItemsListMap.insert(listName, render::ItemIDs()); + _selectedItemsListMap.insert(listName, GameplayObjects()); return addToSelectedItemsList(listName, idToAdd); } } -bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToRemove) { - auto hashItr = _selectedItemsListMap.find(listName); - if (hashItr != _selectedItemsListMap.end()) { +template bool SelectionScriptingInterface::removeFromGameplayObjects(const render::Selection::Name& listName, T idToRemove) { + if (_selectedItemsListMap.contains(listName)) { auto currentList = _selectedItemsListMap.take(listName); - auto listItr = std::find(currentList.begin(), currentList.end(), idToRemove); // TODO: Ensure thread safety - if (listItr == currentList.end()) { - return false; - } else { - currentList.erase(listItr); - _selectedItemsListMap.insert(listName, currentList); - updateRendererSelectedList(listName); - return true; - } + currentList.removeFromGameplayObjects(idToRemove); + _selectedItemsListMap.insert(listName, currentList); + updateRendererSelectedList(listName); + return true; } else { return false; } @@ -133,12 +129,53 @@ void SelectionScriptingInterface::updateRendererSelectedList(const render::Selec render::Transaction transaction; if (_selectedItemsListMap.contains(listName)) { - render::Selection selection(listName, _selectedItemsListMap.value(listName)); + render::ItemIDs finalList; + render::ItemID currentID; + auto entityTree = qApp->getEntities()->getTree(); + auto& overlays = qApp->getOverlays(); + auto currentList = _selectedItemsListMap.value(listName); + + for (QUuid& currentAvatarID : currentList.getAvatarIDs()) { + auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); + if (avatar) { + currentID = avatar->getRenderItemID(); + if (currentID != render::Item::INVALID_ITEM_ID) { + finalList.push_back(currentID); + } + } + } + + for (EntityItemID& currentEntityID : currentList.getEntityIDs()) { + entityTree->withReadLock([&] { + auto entityItem = entityTree->findEntityByEntityItemID(currentEntityID); + if (entityItem != NULL) { + auto renderableInterface = entityItem->getRenderableInterface(); + if (renderableInterface != NULL) { + currentID = renderableInterface->getMetaRenderItemID(); + if (currentID != render::Item::INVALID_ITEM_ID) { + finalList.push_back(currentID); + } + } + } + }); + } + + for (OverlayID& currentOverlayID : currentList.getOverlayIDs()) { + auto overlay = overlays.getOverlay(currentOverlayID); + if (overlay != NULL) { + currentID = overlay->getRenderItemID(); + if (currentID != render::Item::INVALID_ITEM_ID) { + finalList.push_back(currentID); + } + } + } + + render::Selection selection(listName, finalList); transaction.resetSelection(selection); scene->enqueueTransaction(transaction); } else { - qWarning() << "List of ItemIDs doesn't exist in _selectedItemsListMap"; + qWarning() << "List of GameplayObjects doesn't exist in _selectedItemsListMap"; } } else { qWarning() << "SelectionScriptingInterface::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 24cc66aefe..682531d928 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -20,6 +20,29 @@ #include "RenderableEntityItem.h" #include "ui/overlays/Overlay.h" +#include + +class GameplayObjects { +public: + GameplayObjects(); + + std::vector getAvatarIDs() { return _avatarIDs; } + bool addToGameplayObjects(const QUuid& avatarID); + bool removeFromGameplayObjects(const QUuid& avatarID); + + std::vector getEntityIDs() { return _entityIDs; } + bool addToGameplayObjects(const EntityItemID& entityID); + bool removeFromGameplayObjects(const EntityItemID& entityID); + + std::vector getOverlayIDs() { return _overlayIDs; } + bool addToGameplayObjects(const OverlayID& overlayID); + bool removeFromGameplayObjects(const OverlayID& overlayID); + +private: + std::vector _avatarIDs; + std::vector _entityIDs; + std::vector _overlayIDs; +}; class SelectionScriptingInterface : public QObject, public Dependency { Q_OBJECT @@ -29,6 +52,9 @@ public: Q_INVOKABLE bool removeListFromMap(const render::Selection::Name& listName); + Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID); + Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID); + Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID); Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID); @@ -37,10 +63,10 @@ public: private: AbstractViewStateInterface* _viewState; - QMap _selectedItemsListMap; + QMap _selectedItemsListMap; - bool addToSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToAdd); - bool removeFromSelectedItemsList(const render::Selection::Name& listName, render::ItemID idToRemove); + template bool addToGameplayObjects(const render::Selection::Name& listName, T idToAdd); + template bool removeFromGameplayObjects(const render::Selection::Name& listName, T idToRemove); void updateRendererSelectedList(const render::Selection::Name& listName); }; diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 5b64d79484..4e9c8324f4 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -240,6 +240,7 @@ public: void addToScene(AvatarSharedPointer self, const render::ScenePointer& scene); void ensureInScene(AvatarSharedPointer self, const render::ScenePointer& scene); bool isInScene() const { return render::Item::isValidID(_renderItemID); } + render::ItemID getRenderItemID() { return _renderItemID; } bool isMoving() const { return _moving; } void setPhysicsCallback(AvatarPhysicsCallback cb); From 52ef0f20376dd8cbc313ae5c8eebe0d23e16b922 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 23 Aug 2017 16:37:13 -0700 Subject: [PATCH 06/22] More progress --- .../scripting/SelectionScriptingInterface.cpp | 54 ++++++++++++++----- .../scripting/SelectionScriptingInterface.h | 23 ++++---- libraries/render/src/render/Scene.h | 2 + 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 8c002b28f2..9ed24df013 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -10,6 +10,7 @@ // #include "SelectionScriptingInterface.h" +#include #include "Application.h" GameplayObjects::GameplayObjects() { @@ -49,10 +50,10 @@ SelectionScriptingInterface::SelectionScriptingInterface(AbstractViewStateInterf // // START HANDLING AVATARS // -bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID) { +bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const QUuid& avatarSessionID) { return addToGameplayObjects(listName, avatarSessionID); } -bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID) { +bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const QUuid& avatarSessionID) { return addToGameplayObjects(listName, avatarSessionID); } // @@ -62,10 +63,10 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Sele // // START HANDLING ENTITIES // -bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID) { +bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const EntityItemID& entityID) { return addToGameplayObjects(listName, entityID); } -bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID) { +bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const EntityItemID& entityID) { return addToGameplayObjects(listName, entityID); } // @@ -75,10 +76,10 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Sele // // START HANDLING OVERLAYS // -bool SelectionScriptingInterface::addToSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID) { +bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const OverlayID& overlayID) { return addToGameplayObjects(listName, overlayID); } -bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID) { +bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const OverlayID& overlayID) { return addToGameplayObjects(listName, overlayID); } // @@ -88,23 +89,25 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const render::Sele // // START HANDLING GENERIC ITEMS // -template bool SelectionScriptingInterface::addToGameplayObjects(const render::Selection::Name& listName, T idToAdd) { +template bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { if (_selectedItemsListMap.contains(listName)) { auto currentList = _selectedItemsListMap.take(listName); currentList.addToGameplayObjects(idToAdd); _selectedItemsListMap.insert(listName, currentList); + updateRendererSelectedList(listName); return true; } else { _selectedItemsListMap.insert(listName, GameplayObjects()); - return addToSelectedItemsList(listName, idToAdd); + return addToGameplayObjects(listName, idToAdd); } } -template bool SelectionScriptingInterface::removeFromGameplayObjects(const render::Selection::Name& listName, T idToRemove) { +template bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { if (_selectedItemsListMap.contains(listName)) { auto currentList = _selectedItemsListMap.take(listName); currentList.removeFromGameplayObjects(idToRemove); _selectedItemsListMap.insert(listName, currentList); + updateRendererSelectedList(listName); return true; } else { @@ -115,15 +118,42 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c // END HANDLING GENERIC ITEMS // -bool SelectionScriptingInterface::removeListFromMap(const render::Selection::Name& listName) { +void SelectionScriptingInterface::printList(const QString& listName) { + if (_selectedItemsListMap.contains(listName)) { + auto currentList = _selectedItemsListMap.value(listName); + + qDebug() << "Avatar IDs:"; + for (auto i : currentList.getAvatarIDs()) { + qDebug() << i << '; '; + } + qDebug() << ""; + + qDebug() << "Entity IDs:"; + for (auto j : currentList.getEntityIDs()) { + qDebug() << j << '; '; + } + qDebug() << ""; + + qDebug() << "Overlay IDs:"; + for (auto k : currentList.getOverlayIDs()) { + qDebug() << k << '; '; + } + qDebug() << ""; + } else { + qDebug() << "List named" << listName << "doesn't exist."; + } +} + +bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { if (_selectedItemsListMap.remove(listName)) { + updateRendererSelectedList(listName); return true; } else { return false; } } -void SelectionScriptingInterface::updateRendererSelectedList(const render::Selection::Name& listName) { +void SelectionScriptingInterface::updateRendererSelectedList(const QString& listName) { auto scene = _viewState->getMain3DScene(); if (scene) { render::Transaction transaction; @@ -170,7 +200,7 @@ void SelectionScriptingInterface::updateRendererSelectedList(const render::Selec } } - render::Selection selection(listName, finalList); + render::Selection selection(listName.toStdString(), finalList); transaction.resetSelection(selection); scene->enqueueTransaction(transaction); diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 682531d928..81a024f77a 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -50,25 +50,26 @@ class SelectionScriptingInterface : public QObject, public Dependency { public: SelectionScriptingInterface(AbstractViewStateInterface* viewState); - Q_INVOKABLE bool removeListFromMap(const render::Selection::Name& listName); + Q_INVOKABLE void printList(const QString& listName); + Q_INVOKABLE bool removeListFromMap(const QString& listName); - Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID); - Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const QUuid& avatarSessionID); + Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const QUuid& avatarSessionID); + Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const QUuid& avatarSessionID); - Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID); - Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const EntityItemID& entityID); + Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const EntityItemID& entityID); + Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const EntityItemID& entityID); - Q_INVOKABLE bool addToSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID); - Q_INVOKABLE bool removeFromSelectedItemsList(const render::Selection::Name& listName, const OverlayID& overlayID); + Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const OverlayID& overlayID); + Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const OverlayID& overlayID); private: AbstractViewStateInterface* _viewState; - QMap _selectedItemsListMap; + QMap _selectedItemsListMap; - template bool addToGameplayObjects(const render::Selection::Name& listName, T idToAdd); - template bool removeFromGameplayObjects(const render::Selection::Name& listName, T idToRemove); + template bool addToGameplayObjects(const QString& listName, T idToAdd); + template bool removeFromGameplayObjects(const QString& listName, T idToRemove); - void updateRendererSelectedList(const render::Selection::Name& listName); + void updateRendererSelectedList(const QString& listName); }; #endif // hifi_SelectionScriptingInterface_h diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 3b61a20f24..418dcd3bd0 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -60,6 +60,8 @@ public: // Selection transactions void resetSelection(const Selection& selection); + void pushSelection(const Selection& selection); + void popSelection(const Selection& selection); void merge(const Transaction& transaction); From 657beef70fb5237d80cf52833df13ddf0a774186 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 23 Aug 2017 17:42:02 -0700 Subject: [PATCH 07/22] I understand again...getting started again --- interface/src/Application.cpp | 2 + .../scripting/SelectionScriptingInterface.cpp | 79 ++++++++----------- .../scripting/SelectionScriptingInterface.h | 28 ++++--- .../ui/overlays/ContextOverlayInterface.cpp | 6 +- .../src/ui/overlays/ContextOverlayInterface.h | 2 + 5 files changed, 60 insertions(+), 57 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0a2f319841..bd711e534b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2219,6 +2219,7 @@ void Application::initializeUi() { surfaceContext->setContextProperty("AvatarInputs", AvatarInputs::getInstance()); surfaceContext->setContextProperty("ContextOverlay", DependencyManager::get().data()); + surfaceContext->setContextProperty("Selection", DependencyManager::get().data()); if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) { surfaceContext->setContextProperty("Steam", new SteamScriptingInterface(engine, steamClient.get())); @@ -6020,6 +6021,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data()); scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance()); scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("Selection", DependencyManager::get().data()); qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue); diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 9ed24df013..d5bef5a28e 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -47,48 +47,27 @@ SelectionScriptingInterface::SelectionScriptingInterface(AbstractViewStateInterf _viewState = viewState; } -// -// START HANDLING AVATARS -// -bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const QUuid& avatarSessionID) { - return addToGameplayObjects(listName, avatarSessionID); +bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id) { + if (itemType == "avatar") { + return addToGameplayObjects(listName, (QUuid)id); + } else if (itemType == "entity") { + return addToGameplayObjects(listName, (EntityItemID)id); + } else if (itemType == "overlay") { + return addToGameplayObjects(listName, (OverlayID)id); + } + return false; } -bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const QUuid& avatarSessionID) { - return addToGameplayObjects(listName, avatarSessionID); +bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id) { + if (itemType == "avatar") { + return removeFromGameplayObjects(listName, (QUuid)id); + } else if (itemType == "entity") { + return removeFromGameplayObjects(listName, (EntityItemID)id); + } else if (itemType == "overlay") { + return removeFromGameplayObjects(listName, (OverlayID)id); + } + return false; } -// -// END HANDLING AVATARS -// -// -// START HANDLING ENTITIES -// -bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const EntityItemID& entityID) { - return addToGameplayObjects(listName, entityID); -} -bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const EntityItemID& entityID) { - return addToGameplayObjects(listName, entityID); -} -// -// END HANDLING ENTITIES -// - -// -// START HANDLING OVERLAYS -// -bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const OverlayID& overlayID) { - return addToGameplayObjects(listName, overlayID); -} -bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& listName, const OverlayID& overlayID) { - return addToGameplayObjects(listName, overlayID); -} -// -// END HANDLING OVERLAYS -// - -// -// START HANDLING GENERIC ITEMS -// template bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { if (_selectedItemsListMap.contains(listName)) { auto currentList = _selectedItemsListMap.take(listName); @@ -153,17 +132,25 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { } } -void SelectionScriptingInterface::updateRendererSelectedList(const QString& listName) { - auto scene = _viewState->getMain3DScene(); - if (scene) { + +SelectionToSceneHandler::SelectionToSceneHandler() { +} + +void SelectionToSceneHandler::initialize(render::ScenePointer mainScene, const QString& listName) { + _mainScene = mainScene; + _listName = listName; +} + +void SelectionToSceneHandler::updateRendererSelectedList() { + if (_mainScene) { render::Transaction transaction; - if (_selectedItemsListMap.contains(listName)) { + if (_selectedItemsListMap.contains(_listName)) { render::ItemIDs finalList; render::ItemID currentID; auto entityTree = qApp->getEntities()->getTree(); auto& overlays = qApp->getOverlays(); - auto currentList = _selectedItemsListMap.value(listName); + auto currentList = _selectedItemsListMap.value(_listName); for (QUuid& currentAvatarID : currentList.getAvatarIDs()) { auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); @@ -200,10 +187,10 @@ void SelectionScriptingInterface::updateRendererSelectedList(const QString& list } } - render::Selection selection(listName.toStdString(), finalList); + render::Selection selection(_listName.toStdString(), finalList); transaction.resetSelection(selection); - scene->enqueueTransaction(transaction); + _mainScene->enqueueTransaction(transaction); } else { qWarning() << "List of GameplayObjects doesn't exist in _selectedItemsListMap"; } diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 81a024f77a..750e835418 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -53,23 +53,33 @@ public: Q_INVOKABLE void printList(const QString& listName); Q_INVOKABLE bool removeListFromMap(const QString& listName); - Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const QUuid& avatarSessionID); - Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const QUuid& avatarSessionID); + Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); - Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const EntityItemID& entityID); - Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const EntityItemID& entityID); - - Q_INVOKABLE bool addToSelectedItemsList(const QString& listName, const OverlayID& overlayID); - Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const OverlayID& overlayID); +signals: + void addedToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + void removedFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); private: - AbstractViewStateInterface* _viewState; QMap _selectedItemsListMap; template bool addToGameplayObjects(const QString& listName, T idToAdd); template bool removeFromGameplayObjects(const QString& listName, T idToRemove); +}; - void updateRendererSelectedList(const QString& listName); + +class SelectionToSceneHandler { +public: + SelectionToSceneHandler(); + void initialize(render::ScenePointer mainScene, const QString& listName); + +public slots: + void addedToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + void removedFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + +private: + render::ScenePointer _mainScene; + QString _listName { "" }; }; #endif // hifi_SelectionScriptingInterface_h diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index d4dbe467a9..2f1fb75c2b 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -29,6 +29,8 @@ ContextOverlayInterface::ContextOverlayInterface() { _tabletScriptingInterface = DependencyManager::get(); _selectionScriptingInterface = DependencyManager::get(); + _selectionToSceneHandler.initialize(qApp->getMain3DScene(), "contextOverlayHighlightList"); + _entityPropertyFlags += PROP_POSITION; _entityPropertyFlags += PROP_ROTATION; _entityPropertyFlags += PROP_MARKETPLACE_ID; @@ -261,11 +263,11 @@ void ContextOverlayInterface::openMarketplace() { } void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) { - _selectionScriptingInterface->addToSelectedItemsList("contextOverlayHighlightList", entityItemID); + //_selectionScriptingInterface->addToSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID); } void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) { - _selectionScriptingInterface->removeFromSelectedItemsList("contextOverlayHighlightList", entityItemID); + //_selectionScriptingInterface->removeFromSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID); } void ContextOverlayInterface::deletingEntity(const EntityItemID& entityID) { diff --git a/interface/src/ui/overlays/ContextOverlayInterface.h b/interface/src/ui/overlays/ContextOverlayInterface.h index bc650a0ef2..c14262029e 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.h +++ b/interface/src/ui/overlays/ContextOverlayInterface.h @@ -83,6 +83,8 @@ private: void disableEntityHighlight(const EntityItemID& entityItemID); void deletingEntity(const EntityItemID& entityItemID); + + SelectionToSceneHandler _selectionToSceneHandler; }; #endif // hifi_ContextOverlayInterface_h From 92e8f84dc5a5d5c8953d2b3056f4eac43f476b4f Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 24 Aug 2017 09:43:35 -0700 Subject: [PATCH 08/22] I understood last night at midnight --- .../scripting/SelectionScriptingInterface.cpp | 18 +++++++++++++----- .../scripting/SelectionScriptingInterface.h | 4 +++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index d5bef5a28e..bed6423caf 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -43,8 +43,7 @@ bool GameplayObjects::removeFromGameplayObjects(const OverlayID& overlayID) { return true; } -SelectionScriptingInterface::SelectionScriptingInterface(AbstractViewStateInterface* viewState) { - _viewState = viewState; +SelectionScriptingInterface::SelectionScriptingInterface() { } bool SelectionScriptingInterface::addToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id) { @@ -97,6 +96,14 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c // END HANDLING GENERIC ITEMS // +GameplayObjects* SelectionScriptingInterface::getList(const QString& listName) { + if (_selectedItemsListMap.contains(listName)) { + return _selectedItemsListMap.value(listName); + } else { + return NULL; + } +} + void SelectionScriptingInterface::printList(const QString& listName) { if (_selectedItemsListMap.contains(listName)) { auto currentList = _selectedItemsListMap.value(listName); @@ -143,14 +150,15 @@ void SelectionToSceneHandler::initialize(render::ScenePointer mainScene, const Q void SelectionToSceneHandler::updateRendererSelectedList() { if (_mainScene) { + GameplayObjects* thisList = DependencyManager::get()->getList(_listName); render::Transaction transaction; - if (_selectedItemsListMap.contains(_listName)) { + if (thisList != NULL) { render::ItemIDs finalList; render::ItemID currentID; auto entityTree = qApp->getEntities()->getTree(); auto& overlays = qApp->getOverlays(); - auto currentList = _selectedItemsListMap.value(_listName); + auto currentList = thisList.value(_listName); for (QUuid& currentAvatarID : currentList.getAvatarIDs()) { auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); @@ -192,7 +200,7 @@ void SelectionToSceneHandler::updateRendererSelectedList() { _mainScene->enqueueTransaction(transaction); } else { - qWarning() << "List of GameplayObjects doesn't exist in _selectedItemsListMap"; + qWarning() << "List of GameplayObjects doesn't exist in thisList"; } } else { qWarning() << "SelectionScriptingInterface::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 750e835418..19a8a7caec 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -48,7 +48,9 @@ class SelectionScriptingInterface : public QObject, public Dependency { Q_OBJECT public: - SelectionScriptingInterface(AbstractViewStateInterface* viewState); + SelectionScriptingInterface(); + + GameplayObjects getList(const QString& listName); Q_INVOKABLE void printList(const QString& listName); Q_INVOKABLE bool removeListFromMap(const QString& listName); From e834e9d7a705048a830a94a26a0ce658cbfa2785 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 24 Aug 2017 10:43:08 -0700 Subject: [PATCH 09/22] Progress --- interface/src/Application.cpp | 2 +- .../scripting/SelectionScriptingInterface.cpp | 25 +++++++++++-------- .../scripting/SelectionScriptingInterface.h | 11 ++++---- .../ui/overlays/ContextOverlayInterface.cpp | 6 +++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bd711e534b..2a3d8548e1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -612,7 +612,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(qApp); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index bed6423caf..d102c5c1e5 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -73,7 +73,7 @@ template bool SelectionScriptingInterface::addToGameplayObjects(const currentList.addToGameplayObjects(idToAdd); _selectedItemsListMap.insert(listName, currentList); - updateRendererSelectedList(listName); + emit selectedItemsListChanged(listName); return true; } else { _selectedItemsListMap.insert(listName, GameplayObjects()); @@ -86,7 +86,7 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c currentList.removeFromGameplayObjects(idToRemove); _selectedItemsListMap.insert(listName, currentList); - updateRendererSelectedList(listName); + emit selectedItemsListChanged(listName); return true; } else { return false; @@ -132,7 +132,7 @@ void SelectionScriptingInterface::printList(const QString& listName) { bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { if (_selectedItemsListMap.remove(listName)) { - updateRendererSelectedList(listName); + //updateRendererSelectedList(listName); return true; } else { return false; @@ -148,9 +148,15 @@ void SelectionToSceneHandler::initialize(render::ScenePointer mainScene, const Q _listName = listName; } -void SelectionToSceneHandler::updateRendererSelectedList() { +void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) { + if (listName == _listName) { + updateSceneFromSelectedList(); + } +} + +void SelectionToSceneHandler::updateSceneFromSelectedList() { if (_mainScene) { - GameplayObjects* thisList = DependencyManager::get()->getList(_listName); + GameplayObjects* thisList = &DependencyManager::get()->getList(_listName); render::Transaction transaction; if (thisList != NULL) { @@ -158,9 +164,8 @@ void SelectionToSceneHandler::updateRendererSelectedList() { render::ItemID currentID; auto entityTree = qApp->getEntities()->getTree(); auto& overlays = qApp->getOverlays(); - auto currentList = thisList.value(_listName); - for (QUuid& currentAvatarID : currentList.getAvatarIDs()) { + for (QUuid& currentAvatarID : thisList->getAvatarIDs()) { auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); if (avatar) { currentID = avatar->getRenderItemID(); @@ -170,7 +175,7 @@ void SelectionToSceneHandler::updateRendererSelectedList() { } } - for (EntityItemID& currentEntityID : currentList.getEntityIDs()) { + for (EntityItemID& currentEntityID : thisList->getEntityIDs()) { entityTree->withReadLock([&] { auto entityItem = entityTree->findEntityByEntityItemID(currentEntityID); if (entityItem != NULL) { @@ -185,7 +190,7 @@ void SelectionToSceneHandler::updateRendererSelectedList() { }); } - for (OverlayID& currentOverlayID : currentList.getOverlayIDs()) { + for (OverlayID& currentOverlayID : thisList->getOverlayIDs()) { auto overlay = overlays.getOverlay(currentOverlayID); if (overlay != NULL) { currentID = overlay->getRenderItemID(); @@ -203,6 +208,6 @@ void SelectionToSceneHandler::updateRendererSelectedList() { qWarning() << "List of GameplayObjects doesn't exist in thisList"; } } else { - qWarning() << "SelectionScriptingInterface::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; + qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; } } diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 19a8a7caec..2194b251c1 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -59,8 +59,7 @@ public: Q_INVOKABLE bool removeFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); signals: - void addedToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); - void removedFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + void selectedItemsListChanged(const QString& listName); private: QMap _selectedItemsListMap; @@ -70,14 +69,16 @@ private: }; -class SelectionToSceneHandler { +class SelectionToSceneHandler : public QObject { + Q_OBJECT public: SelectionToSceneHandler(); void initialize(render::ScenePointer mainScene, const QString& listName); + void updateSceneFromSelectedList(); + public slots: - void addedToSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); - void removedFromSelectedItemsList(const QString& listName, const QString& itemType, const QUuid& id); + void selectedItemsListChanged(const QString& listName); private: render::ScenePointer _mainScene; diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 2f1fb75c2b..7924620ef3 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -60,6 +60,8 @@ ContextOverlayInterface::ContextOverlayInterface() { }); auto entityScriptingInterface = DependencyManager::get().data(); connect(entityScriptingInterface, &EntityScriptingInterface::deletingEntity, this, &ContextOverlayInterface::deletingEntity); + + connect(_selectionScriptingInterface.data(), &SelectionScriptingInterface::selectedItemsListChanged, &_selectionToSceneHandler, &SelectionToSceneHandler::selectedItemsListChanged); } static const uint32_t LEFT_HAND_HW_ID = 1; @@ -263,11 +265,11 @@ void ContextOverlayInterface::openMarketplace() { } void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) { - //_selectionScriptingInterface->addToSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID); + _selectionScriptingInterface->addToSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID); } void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) { - //_selectionScriptingInterface->removeFromSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID); + _selectionScriptingInterface->removeFromSelectedItemsList("contextOverlayHighlightList", "entity", entityItemID); } void ContextOverlayInterface::deletingEntity(const EntityItemID& entityID) { From d370eeea2fc96f7adfd17600e68647179b92edcb Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 24 Aug 2017 11:07:58 -0700 Subject: [PATCH 10/22] Just gotta test --- .../scripting/SelectionScriptingInterface.cpp | 23 +++++++++---------- .../scripting/SelectionScriptingInterface.h | 3 +++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index d102c5c1e5..cc29fccdba 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -17,6 +17,7 @@ GameplayObjects::GameplayObjects() { } bool GameplayObjects::addToGameplayObjects(const QUuid& avatarID) { + containsData = true; _avatarIDs.push_back(avatarID); return true; } @@ -26,6 +27,7 @@ bool GameplayObjects::removeFromGameplayObjects(const QUuid& avatarID) { } bool GameplayObjects::addToGameplayObjects(const EntityItemID& entityID) { + containsData = true; _entityIDs.push_back(entityID); return true; } @@ -35,6 +37,7 @@ bool GameplayObjects::removeFromGameplayObjects(const EntityItemID& entityID) { } bool GameplayObjects::addToGameplayObjects(const OverlayID& overlayID) { + containsData = true; _overlayIDs.push_back(overlayID); return true; } @@ -96,12 +99,8 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c // END HANDLING GENERIC ITEMS // -GameplayObjects* SelectionScriptingInterface::getList(const QString& listName) { - if (_selectedItemsListMap.contains(listName)) { - return _selectedItemsListMap.value(listName); - } else { - return NULL; - } +GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { + return _selectedItemsListMap.value(listName); } void SelectionScriptingInterface::printList(const QString& listName) { @@ -132,7 +131,7 @@ void SelectionScriptingInterface::printList(const QString& listName) { bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { if (_selectedItemsListMap.remove(listName)) { - //updateRendererSelectedList(listName); + emit selectedItemsListChanged(listName); return true; } else { return false; @@ -156,16 +155,16 @@ void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) void SelectionToSceneHandler::updateSceneFromSelectedList() { if (_mainScene) { - GameplayObjects* thisList = &DependencyManager::get()->getList(_listName); + GameplayObjects thisList = DependencyManager::get()->getList(_listName); render::Transaction transaction; - if (thisList != NULL) { + if (thisList.getContainsData()) { render::ItemIDs finalList; render::ItemID currentID; auto entityTree = qApp->getEntities()->getTree(); auto& overlays = qApp->getOverlays(); - for (QUuid& currentAvatarID : thisList->getAvatarIDs()) { + for (QUuid& currentAvatarID : thisList.getAvatarIDs()) { auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); if (avatar) { currentID = avatar->getRenderItemID(); @@ -175,7 +174,7 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { } } - for (EntityItemID& currentEntityID : thisList->getEntityIDs()) { + for (EntityItemID& currentEntityID : thisList.getEntityIDs()) { entityTree->withReadLock([&] { auto entityItem = entityTree->findEntityByEntityItemID(currentEntityID); if (entityItem != NULL) { @@ -190,7 +189,7 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { }); } - for (OverlayID& currentOverlayID : thisList->getOverlayIDs()) { + for (OverlayID& currentOverlayID : thisList.getOverlayIDs()) { auto overlay = overlays.getOverlay(currentOverlayID); if (overlay != NULL) { currentID = overlay->getRenderItemID(); diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 2194b251c1..98faf4368b 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -26,6 +26,8 @@ class GameplayObjects { public: GameplayObjects(); + bool getContainsData() { return containsData; } + std::vector getAvatarIDs() { return _avatarIDs; } bool addToGameplayObjects(const QUuid& avatarID); bool removeFromGameplayObjects(const QUuid& avatarID); @@ -39,6 +41,7 @@ public: bool removeFromGameplayObjects(const OverlayID& overlayID); private: + bool containsData { false }; std::vector _avatarIDs; std::vector _entityIDs; std::vector _overlayIDs; From baad5f195ee47a9cf65f22d6eef15576382f8b81 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 24 Aug 2017 12:21:19 -0700 Subject: [PATCH 11/22] I'm locking something wrong --- .../scripting/SelectionScriptingInterface.cpp | 28 +++++++++++-------- .../scripting/SelectionScriptingInterface.h | 6 ++-- .../ui/overlays/ContextOverlayInterface.cpp | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index cc29fccdba..50f536bf20 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -46,6 +46,7 @@ bool GameplayObjects::removeFromGameplayObjects(const OverlayID& overlayID) { return true; } + SelectionScriptingInterface::SelectionScriptingInterface() { } @@ -71,8 +72,9 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis } template bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { - if (_selectedItemsListMap.contains(listName)) { - auto currentList = _selectedItemsListMap.take(listName); + QWriteLocker writeLock(&_mapLock); + auto currentList = _selectedItemsListMap.value(listName); + if (currentList.getContainsData()) { currentList.addToGameplayObjects(idToAdd); _selectedItemsListMap.insert(listName, currentList); @@ -84,8 +86,9 @@ template bool SelectionScriptingInterface::addToGameplayObjects(const } } template bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { - if (_selectedItemsListMap.contains(listName)) { - auto currentList = _selectedItemsListMap.take(listName); + QWriteLocker writeLock(&_mapLock); + auto currentList = _selectedItemsListMap.value(listName); + if (currentList.getContainsData()) { currentList.removeFromGameplayObjects(idToRemove); _selectedItemsListMap.insert(listName, currentList); @@ -100,12 +103,14 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c // GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { + QReadLocker readLock(&_mapLock); return _selectedItemsListMap.value(listName); } void SelectionScriptingInterface::printList(const QString& listName) { - if (_selectedItemsListMap.contains(listName)) { - auto currentList = _selectedItemsListMap.value(listName); + QReadLocker readLock(&_mapLock); + auto currentList = _selectedItemsListMap.value(listName); + if (currentList.getContainsData()) { qDebug() << "Avatar IDs:"; for (auto i : currentList.getAvatarIDs()) { @@ -130,6 +135,7 @@ void SelectionScriptingInterface::printList(const QString& listName) { } bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { + QWriteLocker writeLock(&_mapLock); if (_selectedItemsListMap.remove(listName)) { emit selectedItemsListChanged(listName); return true; @@ -142,8 +148,7 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { SelectionToSceneHandler::SelectionToSceneHandler() { } -void SelectionToSceneHandler::initialize(render::ScenePointer mainScene, const QString& listName) { - _mainScene = mainScene; +void SelectionToSceneHandler::initialize(const QString& listName) { _listName = listName; } @@ -154,11 +159,12 @@ void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) } void SelectionToSceneHandler::updateSceneFromSelectedList() { - if (_mainScene) { + auto mainScene = qApp->getMain3DScene(); + if (mainScene) { GameplayObjects thisList = DependencyManager::get()->getList(_listName); - render::Transaction transaction; if (thisList.getContainsData()) { + render::Transaction transaction; render::ItemIDs finalList; render::ItemID currentID; auto entityTree = qApp->getEntities()->getTree(); @@ -202,7 +208,7 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { render::Selection selection(_listName.toStdString(), finalList); transaction.resetSelection(selection); - _mainScene->enqueueTransaction(transaction); + mainScene->enqueueTransaction(transaction); } else { qWarning() << "List of GameplayObjects doesn't exist in thisList"; } diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 98faf4368b..7b2880a8a3 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -47,6 +47,7 @@ private: std::vector _overlayIDs; }; + class SelectionScriptingInterface : public QObject, public Dependency { Q_OBJECT @@ -67,6 +68,8 @@ signals: private: QMap _selectedItemsListMap; + QReadWriteLock _mapLock; + template bool addToGameplayObjects(const QString& listName, T idToAdd); template bool removeFromGameplayObjects(const QString& listName, T idToRemove); }; @@ -76,7 +79,7 @@ class SelectionToSceneHandler : public QObject { Q_OBJECT public: SelectionToSceneHandler(); - void initialize(render::ScenePointer mainScene, const QString& listName); + void initialize(const QString& listName); void updateSceneFromSelectedList(); @@ -84,7 +87,6 @@ public slots: void selectedItemsListChanged(const QString& listName); private: - render::ScenePointer _mainScene; QString _listName { "" }; }; diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 7924620ef3..898ce49e9e 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -29,7 +29,7 @@ ContextOverlayInterface::ContextOverlayInterface() { _tabletScriptingInterface = DependencyManager::get(); _selectionScriptingInterface = DependencyManager::get(); - _selectionToSceneHandler.initialize(qApp->getMain3DScene(), "contextOverlayHighlightList"); + _selectionToSceneHandler.initialize("contextOverlayHighlightList"); _entityPropertyFlags += PROP_POSITION; _entityPropertyFlags += PROP_ROTATION; From 56950e4614d0300433a2896d1dd940bdee76bdfb Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 24 Aug 2017 14:17:39 -0700 Subject: [PATCH 12/22] It's working! --- interface/src/Application.cpp | 6 ++--- .../scripting/SelectionScriptingInterface.cpp | 24 ++++++------------- .../scripting/SelectionScriptingInterface.h | 2 -- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2a3d8548e1..ea3ecd8176 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -609,10 +609,10 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -2218,8 +2218,8 @@ void Application::initializeUi() { surfaceContext->setContextProperty("ApplicationCompositor", &getApplicationCompositor()); surfaceContext->setContextProperty("AvatarInputs", AvatarInputs::getInstance()); - surfaceContext->setContextProperty("ContextOverlay", DependencyManager::get().data()); surfaceContext->setContextProperty("Selection", DependencyManager::get().data()); + surfaceContext->setContextProperty("ContextOverlay", DependencyManager::get().data()); if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) { surfaceContext->setContextProperty("Steam", new SteamScriptingInterface(engine, steamClient.get())); @@ -6020,8 +6020,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri auto entityScriptServerLog = DependencyManager::get(); scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data()); scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance()); - scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Selection", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get().data()); qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue); diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 50f536bf20..a61dd05acf 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -72,22 +72,15 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis } template bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { - QWriteLocker writeLock(&_mapLock); - auto currentList = _selectedItemsListMap.value(listName); - if (currentList.getContainsData()) { - currentList.addToGameplayObjects(idToAdd); - _selectedItemsListMap.insert(listName, currentList); + GameplayObjects currentList = _selectedItemsListMap.value(listName); + currentList.addToGameplayObjects(idToAdd); + _selectedItemsListMap.insert(listName, currentList); - emit selectedItemsListChanged(listName); - return true; - } else { - _selectedItemsListMap.insert(listName, GameplayObjects()); - return addToGameplayObjects(listName, idToAdd); - } + emit selectedItemsListChanged(listName); + return true; } template bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { - QWriteLocker writeLock(&_mapLock); - auto currentList = _selectedItemsListMap.value(listName); + GameplayObjects currentList = _selectedItemsListMap.value(listName); if (currentList.getContainsData()) { currentList.removeFromGameplayObjects(idToRemove); _selectedItemsListMap.insert(listName, currentList); @@ -103,13 +96,11 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c // GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { - QReadLocker readLock(&_mapLock); return _selectedItemsListMap.value(listName); } void SelectionScriptingInterface::printList(const QString& listName) { - QReadLocker readLock(&_mapLock); - auto currentList = _selectedItemsListMap.value(listName); + GameplayObjects currentList = _selectedItemsListMap.value(listName); if (currentList.getContainsData()) { qDebug() << "Avatar IDs:"; @@ -135,7 +126,6 @@ void SelectionScriptingInterface::printList(const QString& listName) { } bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { - QWriteLocker writeLock(&_mapLock); if (_selectedItemsListMap.remove(listName)) { emit selectedItemsListChanged(listName); return true; diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 7b2880a8a3..d1a372c5c4 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -68,8 +68,6 @@ signals: private: QMap _selectedItemsListMap; - QReadWriteLock _mapLock; - template bool addToGameplayObjects(const QString& listName, T idToAdd); template bool removeFromGameplayObjects(const QString& listName, T idToRemove); }; From 3c7fadb1cee8f6e3cf11fec427622720f8147118 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 24 Aug 2017 14:29:37 -0700 Subject: [PATCH 13/22] Final touch --- .../scripting/SelectionScriptingInterface.cpp | 75 +++++++++---------- libraries/render/src/render/Scene.h | 2 - 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index a61dd05acf..c652136a5d 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -152,56 +152,51 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { auto mainScene = qApp->getMain3DScene(); if (mainScene) { GameplayObjects thisList = DependencyManager::get()->getList(_listName); + render::Transaction transaction; + render::ItemIDs finalList; + render::ItemID currentID; + auto entityTree = qApp->getEntities()->getTree(); + auto& overlays = qApp->getOverlays(); - if (thisList.getContainsData()) { - render::Transaction transaction; - render::ItemIDs finalList; - render::ItemID currentID; - auto entityTree = qApp->getEntities()->getTree(); - auto& overlays = qApp->getOverlays(); - - for (QUuid& currentAvatarID : thisList.getAvatarIDs()) { - auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); - if (avatar) { - currentID = avatar->getRenderItemID(); - if (currentID != render::Item::INVALID_ITEM_ID) { - finalList.push_back(currentID); - } + for (QUuid& currentAvatarID : thisList.getAvatarIDs()) { + auto avatar = std::static_pointer_cast(DependencyManager::get()->getAvatarBySessionID(currentAvatarID)); + if (avatar) { + currentID = avatar->getRenderItemID(); + if (currentID != render::Item::INVALID_ITEM_ID) { + finalList.push_back(currentID); } } + } - for (EntityItemID& currentEntityID : thisList.getEntityIDs()) { - entityTree->withReadLock([&] { - auto entityItem = entityTree->findEntityByEntityItemID(currentEntityID); - if (entityItem != NULL) { - auto renderableInterface = entityItem->getRenderableInterface(); - if (renderableInterface != NULL) { - currentID = renderableInterface->getMetaRenderItemID(); - if (currentID != render::Item::INVALID_ITEM_ID) { - finalList.push_back(currentID); - } + for (EntityItemID& currentEntityID : thisList.getEntityIDs()) { + entityTree->withReadLock([&] { + auto entityItem = entityTree->findEntityByEntityItemID(currentEntityID); + if (entityItem != NULL) { + auto renderableInterface = entityItem->getRenderableInterface(); + if (renderableInterface != NULL) { + currentID = renderableInterface->getMetaRenderItemID(); + if (currentID != render::Item::INVALID_ITEM_ID) { + finalList.push_back(currentID); } } - }); - } + } + }); + } - for (OverlayID& currentOverlayID : thisList.getOverlayIDs()) { - auto overlay = overlays.getOverlay(currentOverlayID); - if (overlay != NULL) { - currentID = overlay->getRenderItemID(); - if (currentID != render::Item::INVALID_ITEM_ID) { - finalList.push_back(currentID); - } + for (OverlayID& currentOverlayID : thisList.getOverlayIDs()) { + auto overlay = overlays.getOverlay(currentOverlayID); + if (overlay != NULL) { + currentID = overlay->getRenderItemID(); + if (currentID != render::Item::INVALID_ITEM_ID) { + finalList.push_back(currentID); } } - - render::Selection selection(_listName.toStdString(), finalList); - transaction.resetSelection(selection); - - mainScene->enqueueTransaction(transaction); - } else { - qWarning() << "List of GameplayObjects doesn't exist in thisList"; } + + render::Selection selection(_listName.toStdString(), finalList); + transaction.resetSelection(selection); + + mainScene->enqueueTransaction(transaction); } else { qWarning() << "SelectionToSceneHandler::updateRendererSelectedList(), Unexpected null scene, possibly during application shutdown"; } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 418dcd3bd0..3b61a20f24 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -60,8 +60,6 @@ public: // Selection transactions void resetSelection(const Selection& selection); - void pushSelection(const Selection& selection); - void popSelection(const Selection& selection); void merge(const Transaction& transaction); From 10eaed71f95c6fcb4a1f47a873d5e1d1071c44a6 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 24 Aug 2017 16:00:36 -0700 Subject: [PATCH 14/22] crash on shutdown --- interface/src/Application.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index c951b25930..6a11751061 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -707,8 +707,8 @@ private: QUrl _avatarOverrideUrl; bool _saveAvatarOverrideUrl { false }; - LaserPointerManager _laserPointerManager; RayPickManager _rayPickManager; + LaserPointerManager _laserPointerManager; }; #endif // hifi_Application_h From 35459a7b93afdc51f4edec9f1f4346f591494f87 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 28 Aug 2017 17:01:01 -0700 Subject: [PATCH 15/22] cherry-pick --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index a2d2d34837..414509cf0c 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -55,6 +55,13 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf _displayModelBounds(false), _layeredZones(this) { + setMouseRayPickResultOperator([&](QUuid rayPickID) { + RayToEntityIntersectionResult entityResult; + return entityResult; + }); + setSetPrecisionPickingOperator([&](QUuid rayPickID, bool value) {}); + EntityRenderer::initEntityRenderers(); + REGISTER_ENTITY_TYPE_WITH_FACTORY(Model, RenderableModelEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, RenderableLightEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Text, RenderableTextEntityItem::factory) From b8795c3ea9b23b624f8f0fe5ad05ff0dbf4c8067 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 28 Aug 2017 17:08:59 -0700 Subject: [PATCH 16/22] remove unneeded bind-by-ref thing from lambdas --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 414509cf0c..972ca9d777 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -55,11 +55,11 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf _displayModelBounds(false), _layeredZones(this) { - setMouseRayPickResultOperator([&](QUuid rayPickID) { + setMouseRayPickResultOperator([](QUuid rayPickID) { RayToEntityIntersectionResult entityResult; return entityResult; }); - setSetPrecisionPickingOperator([&](QUuid rayPickID, bool value) {}); + setSetPrecisionPickingOperator([](QUuid rayPickID, bool value) {}); EntityRenderer::initEntityRenderers(); REGISTER_ENTITY_TYPE_WITH_FACTORY(Model, RenderableModelEntityItem::factory) From a6aa71f8fd4a73729635eac00b587f65f777d277 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 29 Aug 2017 09:51:08 -0700 Subject: [PATCH 17/22] unmangle merge --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 972ca9d777..abb7f3bb88 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -60,7 +60,6 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf return entityResult; }); setSetPrecisionPickingOperator([](QUuid rayPickID, bool value) {}); - EntityRenderer::initEntityRenderers(); REGISTER_ENTITY_TYPE_WITH_FACTORY(Model, RenderableModelEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, RenderableLightEntityItem::factory) From 180acbc188db5c7fb43df46dfaf4185567c7ec23 Mon Sep 17 00:00:00 2001 From: beholder Date: Tue, 29 Aug 2017 23:49:44 +0300 Subject: [PATCH 18/22] 6819 - Create button not disabled --- interface/resources/qml/hifi/toolbars/ToolbarButton.qml | 3 ++- scripts/system/edit.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml index 3d4231ced7..bbf2d019fb 100644 --- a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml +++ b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 1.4 StateImage { id: button + property string captionColorOverride: "" property bool buttonEnabled: true property bool isActive: false property bool isEntered: false @@ -97,7 +98,7 @@ StateImage { Text { id: caption - color: button.isActive ? "#000000" : "#ffffff" + color: captionColorOverride !== "" ? captionColorOverride: (button.isActive ? "#000000" : "#ffffff") text: button.isActive ? (button.isEntered ? button.activeHoverText : button.activeText) : (button.isEntered ? button.hoverText : button.text) font.bold: false font.pixelSize: 9 diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 7ee6c64858..8b61226235 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -405,9 +405,11 @@ var toolBar = (function () { } }); - var createButtonIconRsrc = ((Entities.canRez() || Entities.canRezTmp()) ? CREATE_ENABLED_ICON : CREATE_DISABLED_ICON); + var hasRezPermissions = (Entities.canRez() || Entities.canRezTmp()); + var createButtonIconRsrc = (hasRezPermissions ? CREATE_ENABLED_ICON : CREATE_DISABLED_ICON); tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); activeButton = tablet.addButton({ + captionColorOverride: hasRezPermissions ? "" : "#888888", icon: createButtonIconRsrc, activeIcon: "icons/tablet-icons/edit-a.svg", text: "CREATE", @@ -789,6 +791,7 @@ function handleDomainChange() { var hasRezPermissions = (Entities.canRez() || Entities.canRezTmp()); createButton.editProperties({ icon: (hasRezPermissions ? CREATE_ENABLED_ICON : CREATE_DISABLED_ICON), + captionColorOverride: (hasRezPermissions ? "" : "#888888"), }); } From 492d05301667a93eeca73e077e3ffdd6d02583ee Mon Sep 17 00:00:00 2001 From: Liv Date: Wed, 23 Aug 2017 17:38:24 -0700 Subject: [PATCH 19/22] Create home path for new content sets loaded in --- interface/src/Application.cpp | 6 +++++- interface/src/LocationBookmarks.cpp | 4 ++++ interface/src/LocationBookmarks.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d3b547a54c..ea4a3db465 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6284,7 +6284,11 @@ bool Application::askToReplaceDomainContent(const QString& url) { octreeFilePacket->write(urlData); limitedNodeList->sendPacket(std::move(octreeFilePacket), *octreeNode); }); - DependencyManager::get()->handleLookupString(DOMAIN_SPAWNING_POINT); + auto addressManager = DependencyManager::get(); + addressManager->handleLookupString(DOMAIN_SPAWNING_POINT); + QString newHomeAddress = addressManager->getHost() + DOMAIN_SPAWNING_POINT; + qCDebug(interfaceapp) << "Setting new home bookmark to: " << newHomeAddress; + DependencyManager::get()->setHomeLocationToAddress(newHomeAddress); methodDetails = "SuccessfulRequestToReplaceContent"; } else { methodDetails = "UserDeclinedToReplaceContent"; diff --git a/interface/src/LocationBookmarks.cpp b/interface/src/LocationBookmarks.cpp index eee6cdf3c8..b234f8c07b 100644 --- a/interface/src/LocationBookmarks.cpp +++ b/interface/src/LocationBookmarks.cpp @@ -63,6 +63,10 @@ void LocationBookmarks::setHomeLocation() { Bookmarks::addBookmarkToFile(HOME_BOOKMARK, bookmarkAddress); } +void LocationBookmarks::setHomeLocationToAddress(const QVariant& address) { + Bookmarks::insert("Home", address); +} + void LocationBookmarks::teleportToBookmark() { QAction* action = qobject_cast(sender()); QString address = action->data().toString(); diff --git a/interface/src/LocationBookmarks.h b/interface/src/LocationBookmarks.h index 6cac56ae04..9a800ba35e 100644 --- a/interface/src/LocationBookmarks.h +++ b/interface/src/LocationBookmarks.h @@ -27,6 +27,7 @@ public: public slots: void addBookmark(); + void setHomeLocationToAddress(const QVariant& address); protected: void addBookmarkToMenu(Menu* menubar, const QString& name, const QVariant& address) override; From 3f0d44990ada9173ca87b62da0dfa7bcc4361272 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 30 Aug 2017 14:54:23 -0700 Subject: [PATCH 20/22] Hook up bounding box rendering to Selection Scripting Interface --- libraries/render-utils/src/RenderDeferredTask.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 68c0250bec..27abc8c282 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -210,6 +210,10 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren } task.addJob("DrawZoneStack", deferredFrameTransform); + + // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true + const auto selectedMetas = task.addJob("PassTestSelection", metas, "contextOverlayHighlightList"); + task.addJob("DrawSelectionBounds", selectedMetas); } // AA job to be revisited From dbb7023fc1e581ee45adf89dc596176f32c47e9f Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 30 Aug 2017 15:26:25 -0700 Subject: [PATCH 21/22] Fix warnings --- interface/src/scripting/SelectionScriptingInterface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index bc558928ec..808396c901 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -105,19 +105,19 @@ void SelectionScriptingInterface::printList(const QString& listName) { qDebug() << "Avatar IDs:"; for (auto i : currentList.getAvatarIDs()) { - qDebug() << i << '; '; + qDebug() << i << ';'; } qDebug() << ""; qDebug() << "Entity IDs:"; for (auto j : currentList.getEntityIDs()) { - qDebug() << j << '; '; + qDebug() << j << ';'; } qDebug() << ""; qDebug() << "Overlay IDs:"; for (auto k : currentList.getOverlayIDs()) { - qDebug() << k << '; '; + qDebug() << k << ';'; } qDebug() << ""; } else { From 164eeaae64b8e8e080fbe79c39c8c7f8d285a798 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 31 Aug 2017 10:41:44 -0700 Subject: [PATCH 22/22] Fix the duplicated buy buttons for admins on Marketplace --- scripts/system/html/js/marketplacesInject.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index 2675bb97b6..28d116d3ec 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -173,16 +173,16 @@ function injectHiFiItemPageCode() { if (confirmAllPurchases) { - var href = $('#side-info').find('.btn').attr('href'); - $('#side-info').find('.btn').attr('href', '#'); + var href = $('#side-info').find('.btn').first().attr('href'); + $('#side-info').find('.btn').first().attr('href', '#'); var cost = $('.item-cost').text(); if (parseInt(cost) > 0 && $('#side-info').find('#buyItemButton').size() === 0) { - $('#side-info').find('.btn').html('Own Item: ' + (parseFloat(cost / 100).toFixed(2)) + ' HFC'); + $('#side-info').find('.btn').first().html('Own Item: ' + (parseFloat(cost / 100).toFixed(2)) + ' HFC'); } - $('#side-info').find('.btn').on('click', function () { + $('#side-info').find('.btn').first().on('click', function () { buyButtonClicked(window.location.pathname.split("/")[3], $('#top-center').find('h1').text(), $('#creator').find('.value').text(),