diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0fbea37d9a..385172ee2c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2183,6 +2183,9 @@ void Application::init() { // initialize the GlowEffect with our widget bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect); DependencyManager::get()->init(glow); + + // Make sure any new sounds are loaded as soon as know about them. + connect(tree, &EntityTree::newCollisionSoundURL, DependencyManager::get().data(), &SoundCache::getSound); } void Application::closeMirrorView() { diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 0cee73c584..5eec93e8f5 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -84,6 +84,7 @@ void EntityTree::postAddEntity(EntityItemPointer entity) { _simulation->unlock(); } _isDirty = true; + maybeNotifyNewCollisionSoundURL("", entity->getCollisionSoundURL()); emit addingEntity(entity->getEntityItemID()); } @@ -184,6 +185,7 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI // else client accepts what the server says QString entityScriptBefore = entity->getScript(); + QString collisionSoundURLBefore = entity->getCollisionSoundURL(); uint32_t preFlags = entity->getDirtyFlags(); UpdateEntityOperator theOperator(this, containingElement, entity, properties); recurseTreeWithOperator(&theOperator); @@ -206,8 +208,9 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI QString entityScriptAfter = entity->getScript(); if (entityScriptBefore != entityScriptAfter) { emitEntityScriptChanging(entity->getEntityItemID()); // the entity script has changed - } - } + } + maybeNotifyNewCollisionSoundURL(collisionSoundURLBefore, entity->getCollisionSoundURL()); + } // TODO: this final containingElement check should eventually be removed (or wrapped in an #ifdef DEBUG). containingElement = getContainingElement(entity->getEntityItemID()); @@ -266,6 +269,11 @@ EntityItemPointer EntityTree::addEntity(const EntityItemID& entityID, const Enti void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID) { emit entityScriptChanging(entityItemID); } +void EntityTree::maybeNotifyNewCollisionSoundURL(const QString& previousCollisionSoundURL, const QString& nextCollisionSoundURL) { + if (!nextCollisionSoundURL.isEmpty() && (nextCollisionSoundURL != previousCollisionSoundURL)) { + emit newCollisionSoundURL(QUrl(nextCollisionSoundURL)); + } +} void EntityTree::setSimulation(EntitySimulation* simulation) { if (simulation) { diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index b18e989571..0d99c8e82d 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -171,6 +171,7 @@ signals: void deletingEntity(const EntityItemID& entityID); void addingEntity(const EntityItemID& entityID); void entityScriptChanging(const EntityItemID& entityItemID); + void newCollisionSoundURL(const QUrl& url); void clearingEntities(); private: @@ -199,6 +200,7 @@ private: EntitySimulation* _simulation; bool _wantEditLogging = false; + void maybeNotifyNewCollisionSoundURL(const QString& oldCollisionSoundURL, const QString& newCollisionSoundURL); }; #endif // hifi_EntityTree_h