CoriEngine
Loading...
Searching...
No Matches
Sound.hpp
Go to the documentation of this file.
1#pragma once
3#include "Mixer.hpp"
4
5namespace Cori {
6 class AssetManager;
7 namespace Audio {
8
12 class Sound : public Profiling::Trackable<Sound> {
13 public:
17 class Descriptor {
18 public:
25 constexpr Descriptor(std::string name, std::filesystem::path path, const bool preDecode = true) noexcept
26 : m_Path(std::move(path)),
27 m_Name(std::move(name)),
28 m_PreDecode(preDecode),
29 m_RuntimeID(s_NextRuntimeID.fetch_add(1, std::memory_order_relaxed))
30 { }
31
32 using AssetType = Sound;
33
34 [[nodiscard]] uint32_t GetRuntimeID() const { return m_RuntimeID; }
35
36 constexpr bool operator==(const Descriptor& other) const noexcept {
37 return m_RuntimeID == other.m_RuntimeID;
38 }
39
40 struct Hasher {
41 std::size_t operator()(const Descriptor& handle) const noexcept {
42 return std::hash<uint32_t>{}(handle.m_RuntimeID);
43 }
44 };
45
46 const std::filesystem::path m_Path;
47 const std::string m_Name;
48 const bool m_PreDecode;
49
50 private:
51 const uint32_t m_RuntimeID{ 0 };
52 inline static std::atomic<uint32_t> s_NextRuntimeID{ 1 };
53 };
54
55 ~Sound();
56
62 [[nodiscard]] bool IsValid() const;
63
68 [[nodiscard]] bool IsPlaceholder() const;
69
73 [[nodiscard]] SoundID GetID() const;
74
75 const std::string m_Name;
76
84 [[nodiscard]] static std::shared_ptr<Sound> Create(const std::string& name, const std::filesystem::path& path, const bool preDecode = true);
85 private:
86 friend AssetManager;
87 [[nodiscard]] static std::shared_ptr<Sound> Create(const Descriptor& descriptor);
88 Sound(std::string name, const std::filesystem::path& path, const bool preDecode);
89
90 bool m_Valid{ false };
91 bool m_Placeholder{ false };
92 const SoundID m_ID{ 0 };
93 inline static std::atomic<SoundID> s_NextIndex{ 1 };
94 };
95 }
96}
Used when you want to manually control the asset lifetime, loading, preloading, unloading.
Sound Descriptor meant to be used with AssetManager only.
Definition Sound.hpp:17
constexpr Descriptor(std::string name, std::filesystem::path path, const bool preDecode=true) noexcept
Constructs a descriptor.
Definition Sound.hpp:25
constexpr bool operator==(const Descriptor &other) const noexcept
Definition Sound.hpp:36
const std::string m_Name
Definition Sound.hpp:47
uint32_t GetRuntimeID() const
Definition Sound.hpp:34
const std::filesystem::path m_Path
Definition Sound.hpp:46
bool IsPlaceholder() const
Checks if the sound was created with a placeholder.
Definition Sound.cpp:17
static std::shared_ptr< Sound > Create(const std::string &name, const std::filesystem::path &path, const bool preDecode=true)
Creates a Sound object.
Definition Sound.cpp:25
const std::string m_Name
Definition Sound.hpp:75
SoundID GetID() const
Returns the SoundID associated with Sound.
Definition Sound.cpp:21
bool IsValid() const
Check if the Sound is valid.
Definition Sound.cpp:13
For InstanceMetrics to work with a type it should derive from this.
Definition Trackable.hpp:29
Everything connected to audio is in this namespace.
Definition IDDefs.hpp:4
uint32_t SoundID
Definition IDDefs.hpp:6
Global engine namespace.
std::size_t operator()(const Descriptor &handle) const noexcept
Definition Sound.hpp:41