-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSoundSourcePool.h
More file actions
49 lines (42 loc) · 1.11 KB
/
Copy pathSoundSourcePool.h
File metadata and controls
49 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "Export.h"
#include "Core/Singleton.hpp"
#include <cstdint>
#include <memory>
#include <vector>
namespace sh::sound
{
class SoundClip;
class SoundSource;
class SoundSourcePool : public core::Singleton<SoundSourcePool>
{
friend core::Singleton<SoundSourcePool>;
public:
struct Handle
{
static constexpr uint32_t InvalidIndex = static_cast<uint32_t>(-1);
uint32_t index = InvalidIndex;
uint32_t generation = 0;
auto IsValid() const -> bool
{
return index != InvalidIndex;
}
};
public:
SH_SOUND_API auto Acquire(const SoundClip* clip = nullptr) -> Handle;
SH_SOUND_API void Release(Handle handle);
SH_SOUND_API void Clear();
SH_SOUND_API auto GetSource(Handle handle) -> SoundSource*;
SH_SOUND_API auto GetSource(Handle handle) const -> const SoundSource*;
protected:
SH_SOUND_API SoundSourcePool();
SH_SOUND_API ~SoundSourcePool();
private:
void CollectFinishedSources();
auto IsHandleValid(Handle handle) const -> bool;
private:
struct PoolItem;
std::vector<std::unique_ptr<PoolItem>> items;
std::vector<uint32_t> freeIndices;
};
}//namespace