Cogs.Core
AudioSystem.h
1#pragma once
2
3#include "AudioComponent.h"
4
5#include "Systems/ComponentSystem.h"
6
7#include <xaudio2.h>
8
9namespace Cogs
10{
11 namespace Core
12 {
13 enum class AudioState
14 {
15 None = 0,
16 StartPlaying,
17 Playing,
18 StopPlaying,
19 Stopped
20 };
21
22 struct AudioData
23 {
24 IXAudio2SourceVoice * sourceVoice = nullptr;
25 IXAudio2SubmixVoice * submixVoice = nullptr;
26
27 AudioState state = AudioState::None;
28
29 glm::vec3 prevListener;
30 glm::vec3 previousPosition;
31 };
32
33 struct AudioDevice;
34
35 class AudioSystem : public ComponentSystemWithDataPool<AudioComponent, AudioData>
36 {
37 public:
40
41 void initialize(Context * context) override;
42 void update(Context * context) override;
43 void cleanup(Context * context) override;
44
45 void destroyComponent(ComponentHandle handle) override;
46
47 void setAudioListener(ComponentHandle handle);
48
49 private:
50 std::unique_ptr<AudioDevice> subSystem;
51 ComponentHandle listenerHandle = ComponentHandle::Empty();
52 double prevTime = 0;
53 };
54 }
55}
void initialize(Context *context) override
Initialize the system.
Definition: AudioSystem.cpp:89
void destroyComponent(ComponentHandle handle) override
void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
Component system with parallel data per component stored in a pool similar to how the components them...
size_t size()
Returns the number of active components.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Base allocator implementation.
Definition: Allocator.h:30
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67
static ComponentHandle Empty()
Returns an empty, invalid handle. Will evaluate to false if tested against using operator bool().
Definition: Component.h:119