feat: Take sound elevation into account

This commit is contained in:
Vsevolod Kremianskii 2020-11-16 09:27:37 +07:00
parent 430c6498f8
commit 93cc5d1f83
4 changed files with 17 additions and 2 deletions

View file

@ -39,6 +39,7 @@ void SoundBlueprint::load(const GffStruct &uts) {
_maxDistance = uts.getFloat("MaxDistance"); _maxDistance = uts.getFloat("MaxDistance");
_minDistance = uts.getFloat("MinDistance"); _minDistance = uts.getFloat("MinDistance");
_continuous = uts.getInt("Continuous") != 0; _continuous = uts.getInt("Continuous") != 0;
_elevation = uts.getFloat("Elevation");
_looping = uts.getInt("Looping") != 0; _looping = uts.getInt("Looping") != 0;
_positional = uts.getInt("Positional") != 0; _positional = uts.getInt("Positional") != 0;
_interval = uts.getInt("Interval"); _interval = uts.getInt("Interval");
@ -73,6 +74,10 @@ bool SoundBlueprint::continuous() const {
return _continuous; return _continuous;
} }
float SoundBlueprint::elevation() const {
return _elevation;
}
bool SoundBlueprint::looping() const { bool SoundBlueprint::looping() const {
return _looping; return _looping;
} }

View file

@ -38,6 +38,7 @@ public:
float maxDistance() const; float maxDistance() const;
float minDistance() const; float minDistance() const;
bool continuous() const; bool continuous() const;
float elevation() const;
bool looping() const; bool looping() const;
bool positional() const; bool positional() const;
int interval() const; int interval() const;
@ -52,6 +53,7 @@ private:
float _maxDistance { 0.0f }; float _maxDistance { 0.0f };
float _minDistance { 0.0f }; float _minDistance { 0.0f };
bool _continuous { false }; bool _continuous { false };
float _elevation { 0.0f };
bool _looping { false }; bool _looping { false };
bool _positional { false }; bool _positional { false };
int _interval { 0 }; int _interval { 0 };

View file

@ -61,7 +61,7 @@ void Sound::update(float dt) {
if (_sound) { if (_sound) {
if (_audible) { if (_audible) {
_sound->setPosition(glm::vec3(_transform[3])); _sound->setPosition(getPosition());
} else { } else {
_sound->stop(); _sound->stop();
_sound.reset(); _sound.reset();
@ -93,7 +93,7 @@ void Sound::update(float dt) {
} }
void Sound::playSound(const string &resRef, bool loop) { void Sound::playSound(const string &resRef, bool loop) {
_sound = AudioPlayer::instance().play(resRef, AudioType::Sound, loop, 1.0f, _blueprint->positional(), Vector3(_transform[3])); _sound = AudioPlayer::instance().play(resRef, AudioType::Sound, loop, 1.0f, _blueprint->positional(), getPosition());
} }
void Sound::play() { void Sound::play() {
@ -122,6 +122,12 @@ bool Sound::isActive() const {
return _active; return _active;
} }
Vector3 Sound::getPosition() const {
Vector3 position(_transform[3]);
position.z += _blueprint->elevation();
return move(position);
}
int Sound::priority() const { int Sound::priority() const {
return _priority; return _priority;
} }

View file

@ -43,6 +43,8 @@ public:
bool isActive() const; bool isActive() const;
Vector3 getPosition() const;
std::shared_ptr<SoundBlueprint> blueprint() const; std::shared_ptr<SoundBlueprint> blueprint() const;
int priority() const; int priority() const;