support registration point, improve locking

This commit is contained in:
HifiExperiments 2024-04-12 13:04:30 -07:00
parent eb7d97064f
commit 376be7b17e
2 changed files with 24 additions and 17 deletions

View file

@ -136,36 +136,42 @@ bool SoundEntityItem::shouldCreateSound(const EntityTreePointer& tree) const {
}
void SoundEntityItem::update(const quint64& now) {
withWriteLock([&] {
const auto tree = getTree();
if (tree) {
_updateNeeded = false;
const auto tree = getTree();
if (tree) {
_updateNeeded = false;
withWriteLock([&] {
if (shouldCreateSound(tree)) {
_sound = DependencyManager::get<SoundCache>()->getSound(_url);
}
});
withReadLock([&] {
if (_sound) {
if (_sound->isLoaded()) {
updateSound(true);
} else {
connect(_sound.data(), &Resource::finished, this, [&] { updateSound(true); });
connect(_sound.data(), &Resource::finished, this, [&] {
withReadLock([&] {
updateSound(true);
});
});
}
}
}
});
});
}
}
void SoundEntityItem::setLocalPosition(const glm::vec3& value, bool tellPhysics) {
EntityItem::setLocalPosition(value, tellPhysics);
withWriteLock([&] {
void SoundEntityItem::locationChanged(bool tellPhysics, bool tellChildren) {
EntityItem::locationChanged(tellPhysics, tellChildren);
withReadLock([&] {
updateSound();
});
}
void SoundEntityItem::setLocalOrientation(const glm::quat& value) {
EntityItem::setLocalOrientation(value);
withWriteLock([&] {
void SoundEntityItem::dimensionsChanged() {
EntityItem::dimensionsChanged();
withReadLock([&] {
updateSound();
});
}
@ -337,11 +343,12 @@ bool SoundEntityItem::restartSound() {
}
AudioInjectorOptions options;
options.position = getWorldPosition();
const glm::quat orientation = getWorldOrientation();
options.position = getWorldPosition() + orientation * (getScaledDimensions() * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
options.positionSet = _positional;
options.volume = _volume;
options.loop = _loop;
options.orientation = getWorldOrientation();
options.orientation = orientation;
options.localOnly = _localOnly || _sound->isAmbisonic(); // force localOnly when ambisonic
options.secondOffset = _timeOffset;
options.pitch = _pitch;

View file

@ -51,8 +51,8 @@ public:
virtual void update(const quint64& now) override;
bool needsToCallUpdate() const override { return _updateNeeded; }
void setLocalPosition(const glm::vec3& value, bool tellPhysics = true) override;
void setLocalOrientation(const glm::quat& value) override;
void locationChanged(bool tellPhysics = true, bool tellChildren = true) override;
void dimensionsChanged() override;
void setURL(const QString& value);
QString getURL() const;