From b7a3fb107295872fdd7b605446a705ecfbc4a3cd Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Sun, 7 Apr 2024 12:54:37 -0700 Subject: [PATCH] support non-localOnly sound avatar entities --- libraries/entities/src/SoundEntityItem.cpp | 12 +++++++++--- libraries/entities/src/SoundEntityItem.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/SoundEntityItem.cpp b/libraries/entities/src/SoundEntityItem.cpp index 997225515c..57ce158ee0 100644 --- a/libraries/entities/src/SoundEntityItem.cpp +++ b/libraries/entities/src/SoundEntityItem.cpp @@ -129,13 +129,19 @@ void SoundEntityItem::debugDump() const { qCDebug(entities) << "SOUND EntityItem Ptr:" << this; } +bool SoundEntityItem::shouldCreateSound(const EntityTreePointer& tree) const { + bool clientShouldMakeSound = _localOnly || isMyAvatarEntity() || tree->isServerlessMode(); + bool serverShouldMakeSound = !_localOnly; + return (clientShouldMakeSound && tree->getIsClient()) || (serverShouldMakeSound && tree->isEntityServer()); +} + void SoundEntityItem::update(const quint64& now) { withWriteLock([&] { const auto tree = getTree(); if (tree) { _updateNeeded = false; - if ((_localOnly && tree->getIsClient()) || (!_localOnly && (tree->isEntityServer() || tree->isServerlessMode()))) { + if (shouldCreateSound(tree)) { _sound = DependencyManager::get()->getSound(_url); } @@ -175,7 +181,7 @@ void SoundEntityItem::setURL(const QString& value) { return; } - if ((_localOnly && tree->getIsClient()) || (!_localOnly && (tree->isEntityServer() || tree->isServerlessMode()))) { + if (shouldCreateSound(tree)) { _sound = DependencyManager::get()->getSound(_url); } @@ -297,7 +303,7 @@ void SoundEntityItem::setLocalOnly(bool value) { return; } - if ((_localOnly && tree->getIsClient()) || (!_localOnly && (tree->isEntityServer() || tree->isServerlessMode()))) { + if (shouldCreateSound(tree)) { _sound = DependencyManager::get()->getSound(_url); } else { _sound = nullptr; diff --git a/libraries/entities/src/SoundEntityItem.h b/libraries/entities/src/SoundEntityItem.h index 781c270d45..5cbd4bb814 100644 --- a/libraries/entities/src/SoundEntityItem.h +++ b/libraries/entities/src/SoundEntityItem.h @@ -81,6 +81,7 @@ public: bool restartSound(); protected: + bool shouldCreateSound(const EntityTreePointer& tree) const; void updateSound(bool restart = false); QString _url { "" };