NWengine 0.9
Loading...
Searching...
No Matches
Audio.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <string>
9#include <unordered_map>
10#include "Globals.h"
11#include "Asset.h"
12
18 std::string path;
19 uint64 runtimeID;
26 bool operator==(const SoundIdentifier& other) const {
27 return path == other.path && runtimeID == other.runtimeID;
28 }
29};
30
35template <>
36struct std::hash<SoundIdentifier> {
42 std::size_t operator()(const SoundIdentifier& t) const {
43 std::size_t res = 0;
44 hashCombine(res, t.path);
45 hashCombine(res, t.runtimeID);
46 return res;
47 }
48};
49
54class Sound : Asset {
55public:
56 uint32 _buffID = 0;
57 uint32 _source = 0;
58 float volume = 1.0f;
59 float frequency = 1.0f;
60 bool isLooping = false;
61 bool isPlaying = false;
66 Sound() = default;
67
71 void Play();
72
77 void SetVolume(float volume);
78
83 void SetFrequency(float frequency);
84
89 void SetLoop(bool loop);
90
94 void Stop();
95
100 bool HasFinished();
101
105 void Clean() override;
106
112 Asset* GetFromCache(void* id);
113
120 Asset* LoadFromFile(const char* path, void* id);
121
128 Asset* LoadFromBuffer(void* alBuffer, void* id);
129
134
139 static bool Init();
140
144 static void Destroy();
145};
The base class for all assets.
Definition Asset.h:9
Represents a sound asset.
Definition Audio.h:54
float volume
Definition Audio.h:58
void Stop()
Stops the sound.
Definition Audio.cpp:96
bool isPlaying
Definition Audio.h:61
Asset * LoadFromFile(const char *path, void *id)
Loads the sound asset from a file.
Definition Audio.cpp:40
Asset * GetFromCache(void *id)
Gets the sound asset from the cache.
Definition Audio.cpp:33
bool isLooping
Definition Audio.h:60
void Clean() override
Cleans up the sound.
Definition Audio.cpp:78
void SetVolume(float volume)
Sets the volume of the sound.
Definition Audio.cpp:102
void Play()
Plays the sound.
Definition Audio.cpp:90
float frequency
Definition Audio.h:59
NW_DECL_RES_LIST(SoundIdentifier, Sound)
Declares the resource list for SoundIdentifier and Sound.
void SetFrequency(float frequency)
Sets the frequency of the sound.
Definition Audio.cpp:114
bool HasFinished()
Checks if the sound has finished playing.
Definition Audio.cpp:108
Sound()=default
Default constructor for the Sound class.
uint32 _buffID
Definition Audio.h:56
static void Destroy()
Destroys the Sound class.
Definition Audio.cpp:25
uint32 _source
Definition Audio.h:57
Asset * LoadFromBuffer(void *alBuffer, void *id)
Loads the sound asset from a buffer.
Definition Audio.cpp:67
static bool Init()
Initializes the Sound class.
Definition Audio.cpp:9
void SetLoop(bool loop)
Sets whether the sound should loop or not.
Definition Audio.cpp:121
Structure representing a sound identifier.
Definition Audio.h:17
uint64 runtimeID
Definition Audio.h:19
bool operator==(const SoundIdentifier &other) const
Overloaded equality operator for comparing SoundIdentifier objects.
Definition Audio.h:26
std::string path
Definition Audio.h:18
std::size_t operator()(const SoundIdentifier &t) const
Calculates the hash value for a SoundIdentifier object.
Definition Audio.h:42