support non-localOnly sound avatar entities

This commit is contained in:
HifiExperiments 2024-04-07 12:54:37 -07:00
parent aa5e8e635e
commit b7a3fb1072
2 changed files with 10 additions and 3 deletions

View file

@ -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<SoundCache>()->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<SoundCache>()->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<SoundCache>()->getSound(_url);
} else {
_sound = nullptr;

View file

@ -81,6 +81,7 @@ public:
bool restartSound();
protected:
bool shouldCreateSound(const EntityTreePointer& tree) const;
void updateSound(bool restart = false);
QString _url { "" };