Plasma Engine  2.0
Loading...
Searching...
No Matches
AudioSystemComponent.h
1#pragma once
2
3#include <AudioSystemPlugin/AudioSystemPluginDLL.h>
4
5#include <AudioSystemPlugin/Core/AudioSystemData.h>
6#include <AudioSystemPlugin/Core/AudioSystemMessages.h>
7
8#include <Core/World/Component.h>
9#include <Core/World/World.h>
10
12template <typename T>
13class plAudioSystemComponentManager final : public plComponentManager<T, plBlockStorageType::FreeList>
14{
15 // plComponentManager
16
17public:
18 void Initialize() override;
19
20 // plAudioSystemComponentManager
21
22public:
23 explicit plAudioSystemComponentManager(plWorld* pWorld);
24
25private:
27 void Update(const plWorldModule::UpdateContext& context);
28
29 static void UpdateFunctionName(plStringBuilder& out_sName);
30};
31
33class PL_AUDIOSYSTEMPLUGIN_DLL plAudioSystemComponent : public plComponent
34{
35 PL_DECLARE_ABSTRACT_COMPONENT_TYPE(plAudioSystemComponent, plComponent);
36
37 // plAudioSystemComponent
38
39protected:
40 // Dummy method to hide this component in the editor UI.
41 virtual void plAudioSystemComponentIsAbstract() = 0;
42};
43
45class PL_AUDIOSYSTEMPLUGIN_DLL plAudioSystemProxyDependentComponent : public plAudioSystemComponent
46{
47 PL_DECLARE_ABSTRACT_COMPONENT_TYPE(plAudioSystemProxyDependentComponent, plAudioSystemComponent);
48
49 // plComponent
50
51public:
52 void Initialize() override;
53 void OnSimulationStarted() override;
54 void Deinitialize() override;
55
56 // plAudiSystemProxyDependentComponent
57
58protected:
60 [[nodiscard]] plAudioSystemDataID GetEntityId() const;
61
62 class plAudioProxyComponent* m_pProxyComponent{nullptr};
63};
64
67{
69
70 // plAudioSystemEnvironmentComponent
71
72public:
74
75 void OnActivated() override;
76 void OnDeactivated() override;
77
81 [[nodiscard]] virtual float GetEnvironmentAmount(plAudioProxyComponent* pProxyComponent) const = 0;
82
84 [[nodiscard]] plAudioSystemDataID GetEnvironmentId() const;
85
88 [[nodiscard]] virtual float GetMaxDistance() const;
89
92 virtual void SetMaxDistance(float fFadeDistance);
93
96 void OverrideEnvironmentAmount(float fValue);
97
98 void OnSetAmount(plMsgAudioSystemSetEnvironmentAmount& msg);
99
100protected:
101 float m_fMaxDistance;
102 plString m_sEnvironmentName;
103 plColor m_ShapeColor;
104
105 bool m_bOverrideValue;
106 float m_fOverrideValue;
107};
108
109template <typename T>
111 : plComponentManager<T, plBlockStorageType::FreeList>(pWorld)
112{
113}
114
115template <typename T>
117{
118 plStringBuilder functionName;
119 UpdateFunctionName(functionName);
120
122 desc.m_bOnlyUpdateWhenSimulating = true;
123 desc.m_Phase = plWorldModule::UpdateFunctionDesc::Phase::PostTransform; // Should we apply entity transform after game object transform?
124
125 this->RegisterUpdateFunction(desc);
126}
127
128template <typename T>
130{
131 for (auto it = this->m_ComponentStorage.GetIterator(context.m_uiFirstComponentIndex, context.m_uiComponentCount); it.IsValid(); ++it)
132 {
133 if (T* pComponent = it; pComponent->IsActiveAndInitialized())
134 {
135 pComponent->Update();
136 }
137 }
138}
139
140// static
141template <typename T>
143{
144 plStringView sName(PL_SOURCE_FUNCTION);
145 const char* szEnd = sName.FindSubString(",");
146
147 if (szEnd != nullptr && sName.StartsWith("plAudioSystemComponentManager<class "))
148 {
149 const plStringView sChoppedName(sName.GetStartPointer() + plStringUtils::GetStringElementCount("plAudioSystemComponentManager<class "), szEnd);
150
151 PL_ASSERT_DEV(!sChoppedName.IsEmpty(), "Chopped name is empty: '{0}'", sName);
152
153 out_sName = sChoppedName;
154 out_sName.Append("::Update");
155 }
156 else
157 {
158 out_sName = sName;
159 }
160}
Component that represent an audio entity in the scene graph.
Definition AudioProxyComponent.h:30
Base class for audio system components.
Definition AudioSystemComponent.h:34
Base class for audio system component manager which need to update their states (eg....
Definition AudioSystemComponent.h:14
void Initialize() override
This method is called after the constructor. A derived type can override this method to do initializa...
Definition AudioSystemComponent.h:116
Base class for audio system environment components.
Definition AudioSystemComponent.h:67
virtual float GetEnvironmentAmount(plAudioProxyComponent *pProxyComponent) const =0
Gets the environment amount for the specified audio proxy component.
Base class for audio system components that depends on an audio proxy component.
Definition AudioSystemComponent.h:46
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
Base class of all component types.
Definition Component.h:25
virtual void OnDeactivated()
This method is called when the component gets deactivated.
Definition Component.cpp:142
virtual void Deinitialize()
This method is called before the component is destroyed. A derived type can override this method to d...
Definition Component.cpp:133
virtual void OnSimulationStarted()
This method is called once for active components, at the start of the next world update,...
Definition Component.cpp:144
virtual void Initialize()
Can be overridden for basic initialization that depends on a valid hierarchy and position.
Definition Component.cpp:131
virtual void OnActivated()
This method is called when the component gets activated.
Definition Component.cpp:140
Definition ComponentManager.h:88
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
void Append(plUInt32 uiChar)
Appends a single Utf32 character.
Definition StringBuilder_inl.h:94
static constexpr plUInt32 GetStringElementCount(const T *pString)
Returns the number of elements of type T that the string contains, until it hits an element that is z...
Definition StringUtils_inl.h:45
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Definition BlockStorage.h:7
Definition AudioSystemMessages.h:41
Definition WorldModule.h:33
Description of an update function that can be registered at the world.
Definition WorldModule.h:43