GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
SoundInstanceID.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_AUDIO_SOUND_INSTANCE_ID_HPP
5#define GREM_AUDIO_SOUND_INSTANCE_ID_HPP
6
8
9#include <compare> // std::strong_ordering
10#include <cstddef> // std::size_t
11#include <functional> // std::hash
12
13namespace grem::audio {
14
15class SoundStage; // Forward declaration, to avoid a circular include of SoundStage.hpp.
16class SoundMix; // Forward declaration, to avoid a circular include of SoundMix.hpp.
17class DuckingFilter; // Forward declaration, to avoid a circular include of filters.hpp.
18
27 constexpr SoundInstanceID() noexcept = default;
28
35 constexpr explicit operator bool() const noexcept {
36 return *this != SoundInstanceID{};
37 }
38
46 [[nodiscard]] constexpr bool operator==(const SoundInstanceID& other) const noexcept = default;
47
55 [[nodiscard]] constexpr std::strong_ordering operator<=>(const SoundInstanceID& other) const noexcept = default;
56
57private:
58 friend SoundStage;
59 friend SoundMix;
60 friend DuckingFilter;
61 friend std::hash<SoundInstanceID>;
62
63 constexpr explicit SoundInstanceID(unsigned value) noexcept
64 : value(value) {}
65
66 unsigned value = 0;
67};
68
69} // namespace grem::audio
70
71template <>
72struct std::hash<grem::audio::SoundInstanceID> {
73 [[nodiscard]] std::size_t operator()(const grem::audio::SoundInstanceID& soundInstanceID) const {
74 return hasher(soundInstanceID.value);
75 }
76
77private:
78 [[no_unique_address]] std::hash<unsigned> hasher;
79};
80
81#endif
Ducking filter for reducing the volume of a sound when another sound is active.
Definition filters.hpp:696
Container for a mix of sound waves that can be played in a SoundStage.
Definition SoundMix.hpp:58
Persistent system for playing sound in a simulated 3D arena to the default audio device.
Definition SoundStage.hpp:122
Definition Error.hpp:12
Definition aliases.hpp:9
Opaque handle to a specific instance of a sound or sound mix playing in a sound stage or sound mix.
Definition SoundInstanceID.hpp:23
constexpr std::strong_ordering operator<=>(const SoundInstanceID &other) const noexcept=default
Compare this handle to another.
constexpr SoundInstanceID() noexcept=default
Construct an invalid sound instance handle.
constexpr bool operator==(const SoundInstanceID &other) const noexcept=default
Compare this handle to another for equality.
std::size_t operator()(const grem::audio::SoundInstanceID &soundInstanceID) const
Definition SoundInstanceID.hpp:73