Skip to content

Commit

Permalink
Traktor: Property to enable/disable ListenerComponent from script.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Apr 16, 2024
1 parent 64d13c5 commit 2519e24
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/Runtime/Impl/AudioServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool AudioServer::create(const PropertyGroup* settings, const SystemApplication&
}

// Create surround environment.
const float surroundMaxDistance = 50.0f; // settings->getProperty< float >(L"Audio.Surround/MaxDistance", 50.0f);
const float surroundMaxDistance = 25.0f; // settings->getProperty< float >(L"Audio.Surround/MaxDistance", 50.0f);
const float surroundInnerRadius = 5.0f; // settings->getProperty< float >(L"Audio.Surround/InnerRadius", 5.0f);
const float surroundFallOffExponent = 4.0f; // settings->getProperty< float >(L"Audio.Surround/FallOffExponent", 4.0f);
m_surroundEnvironment = new sound::SurroundEnvironment(
Expand Down
22 changes: 22 additions & 0 deletions code/Spray/ListenerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,26 @@ void ListenerComponent::update(const world::UpdateParams& update)
{
}

void ListenerComponent::setEnable(bool enable)
{
if (m_soundPlayer == nullptr || enable == isEnable())
return;

if (enable)
{
m_soundListener = m_soundPlayer->createListener();
m_soundPlayer->addListener(m_soundListener);
}
else
{
m_soundPlayer->removeListener(m_soundListener);
m_soundPlayer = nullptr;
}
}

bool ListenerComponent::isEnable() const
{
return m_soundListener != nullptr;
}

}
4 changes: 4 additions & 0 deletions code/Spray/ListenerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class T_DLLCLASS ListenerComponent : public world::IEntityComponent

virtual void update(const world::UpdateParams& update) override final;

void setEnable(bool enable);

bool isEnable() const;

private:
Ref< sound::ISoundPlayer > m_soundPlayer;
Ref< sound::ISoundListener > m_soundListener;
Expand Down
5 changes: 5 additions & 0 deletions code/Spray/SprayClassFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Core/Class/AutoRuntimeClass.h"
#include "Core/Class/IRuntimeClassRegistrar.h"
#include "Spray/EffectComponent.h"
#include "Spray/ListenerComponent.h"
#include "Spray/SoundComponent.h"
#include "Spray/SprayClassFactory.h"

Expand All @@ -26,6 +27,10 @@ void SprayClassFactory::createClasses(IRuntimeClassRegistrar* registrar) const
classEffectComponent->addMethod("reset", &EffectComponent::reset);
registrar->registerClass(classEffectComponent);

auto classListenerComponent = new AutoRuntimeClass< ListenerComponent >();
classListenerComponent->addProperty("enable", &ListenerComponent::setEnable, &ListenerComponent::isEnable);
registrar->registerClass(classListenerComponent);

auto classSoundComponent = new AutoRuntimeClass< SoundComponent >();
classSoundComponent->addMethod("play", &SoundComponent::play);
classSoundComponent->addMethod("stop", &SoundComponent::stop);
Expand Down

0 comments on commit 2519e24

Please sign in to comment.