Showing the changes to interface/src/scripting/SelectionScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -46,6 +46,7 @@ bool GameplayObjects::removeFromGameplayObjects(const OverlayID& overlayID) { · 45 unmodified lines | ||
| 46 | 46 | return true; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + | |
| 49 | 50 | SelectionScriptingInterface::SelectionScriptingInterface() { |
| 50 | 51 | } |
| 51 | 52 | |
| @@ -71,8 +72,9 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis · 19 unmodified lines | ||
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { |
| 74 | − if (_selectedItemsListMap.contains(listName)) { | |
| 75 | − auto currentList = _selectedItemsListMap.take(listName); | |
| 75 | + QWriteLocker writeLock(&_mapLock); | |
| 76 | + auto currentList = _selectedItemsListMap.value(listName); | |
| 77 | + if (currentList.getContainsData()) { | |
| 76 | 78 | currentList.addToGameplayObjects(idToAdd); |
| 77 | 79 | _selectedItemsListMap.insert(listName, currentList); |
| 78 | 80 | |
| @@ -84,8 +86,9 @@ template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const · 5 unmodified lines | ||
| 84 | 86 | } |
| 85 | 87 | } |
| 86 | 88 | template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { |
| 87 | − if (_selectedItemsListMap.contains(listName)) { | |
| 88 | − auto currentList = _selectedItemsListMap.take(listName); | |
| 89 | + QWriteLocker writeLock(&_mapLock); | |
| 90 | + auto currentList = _selectedItemsListMap.value(listName); | |
| 91 | + if (currentList.getContainsData()) { | |
| 89 | 92 | currentList.removeFromGameplayObjects(idToRemove); |
| 90 | 93 | _selectedItemsListMap.insert(listName, currentList); |
| 91 | 94 | |
| @@ -100,12 +103,14 @@ template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(c · 8 unmodified lines | ||
| 100 | 103 | // |
| 101 | 104 | |
| 102 | 105 | GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { |
| 106 | + QReadLocker readLock(&_mapLock); | |
| 103 | 107 | return _selectedItemsListMap.value(listName); |
| 104 | 108 | } |
| 105 | 109 | |
| 106 | 110 | void SelectionScriptingInterface::printList(const QString& listName) { |
| 107 | − if (_selectedItemsListMap.contains(listName)) { | |
| 108 | − auto currentList = _selectedItemsListMap.value(listName); | |
| 111 | + QReadLocker readLock(&_mapLock); | |
| 112 | + auto currentList = _selectedItemsListMap.value(listName); | |
| 113 | + if (currentList.getContainsData()) { | |
| 109 | 114 | |
| 110 | 115 | qDebug() << "Avatar IDs:"; |
| 111 | 116 | for (auto i : currentList.getAvatarIDs()) { |
| @@ -130,6 +135,7 @@ void SelectionScriptingInterface::printList(const QString& listName) { · 18 unmodified lines | ||
| 130 | 135 | } |
| 131 | 136 | |
| 132 | 137 | bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { |
| 138 | + QWriteLocker writeLock(&_mapLock); | |
| 133 | 139 | if (_selectedItemsListMap.remove(listName)) { |
| 134 | 140 | emit selectedItemsListChanged(listName); |
| 135 | 141 | return true; |
| @@ -142,8 +148,7 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { · 6 unmodified lines | ||
| 142 | 148 | SelectionToSceneHandler::SelectionToSceneHandler() { |
| 143 | 149 | } |
| 144 | 150 | |
| 145 | −void SelectionToSceneHandler::initialize(render::ScenePointer mainScene, const QString& listName) { | |
| 146 | − _mainScene = mainScene; | |
| 151 | +void SelectionToSceneHandler::initialize(const QString& listName) { | |
| 147 | 152 | _listName = listName; |
| 148 | 153 | } |
| 149 | 154 | |
| @@ -154,11 +159,12 @@ void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) · 4 unmodified lines | ||
| 154 | 159 | } |
| 155 | 160 | |
| 156 | 161 | void SelectionToSceneHandler::updateSceneFromSelectedList() { |
| 157 | − if (_mainScene) { | |
| 162 | + auto mainScene = qApp->getMain3DScene(); | |
| 163 | + if (mainScene) { | |
| 158 | 164 | GameplayObjects thisList = DependencyManager::get<SelectionScriptingInterface>()->getList(_listName); |
| 159 | − render::Transaction transaction; | |
| 160 | 165 | |
| 161 | 166 | if (thisList.getContainsData()) { |
| 167 | + render::Transaction transaction; | |
| 162 | 168 | render::ItemIDs finalList; |
| 163 | 169 | render::ItemID currentID; |
| 164 | 170 | auto entityTree = qApp->getEntities()->getTree(); |
| @@ -202,7 +208,7 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { · 37 unmodified lines | ||
| 202 | 208 | render::Selection selection(_listName.toStdString(), finalList); |
| 203 | 209 | transaction.resetSelection(selection); |
| 204 | 210 | |
| 205 | − _mainScene->enqueueTransaction(transaction); | |
| 211 | + mainScene->enqueueTransaction(transaction); | |
| 206 | 212 | } else { |
| 207 | 213 | qWarning() << "List of GameplayObjects doesn't exist in thisList"; |
| 208 | 214 | } |