mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
support registration point, improve locking
This commit is contained in:
parent
eb7d97064f
commit
376be7b17e
2 changed files with 24 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue