Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
speaker.hpp
Go to the documentation of this file.
1/*
2 Wizard Engine
3 Copyright (C) 2023-2024 Zana Domán
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef WIZARD_ENGINE_SPEAKER_HPP
23#define WIZARD_ENGINE_SPEAKER_HPP
24
28
29namespace wze {
35class speaker final : public component {
36 private:
37 static std::vector<speaker*> _instances;
38 int32_t _channel;
39 std::shared_ptr<wze::sound> _sound;
40 float _range;
41 bool _auto_panning;
42 float _x;
43 float _y;
44 float _z;
45 bool _spatial;
46 float _x_offset;
47 float _y_offset;
48 bool _attach_x;
49 bool _attach_y;
50 bool _x_angle_lock;
51 bool _y_angle_lock;
52
58 void set_angle(float _) final;
59
65 [[nodiscard]] float angle_offset() const final;
66
72 [[nodiscard]] bool attach_angle() const final;
73
74 public:
75#ifdef __WIZARD_ENGINE_INTERNAL__
82 [[nodiscard]] static std::vector<speaker*> const& instances();
83#endif /* __WIZARD_ENGINE_INTERNAL__ */
84
91 [[nodiscard]] std::shared_ptr<wze::sound> const& sound() const;
92
99 void set_sound(std::shared_ptr<wze::sound> const& sound);
100
107 [[nodiscard]] int8_t volume() const;
108
115 void set_volume(int8_t volume);
116
123 [[nodiscard]] float range() const;
124
131 void set_range(float range);
132
139 [[nodiscard]] bool auto_panning() const;
140
147 void set_auto_panning(bool auto_panning);
148
155 [[nodiscard]] float x() const;
156
163 void set_x(float x) final;
164
171 [[nodiscard]] float y() const;
172
179 void set_y(float y) final;
180
187 [[nodiscard]] float z() const;
188
195 void set_z(float z);
196
203 [[nodiscard]] bool spatial() const;
204
211 void set_spatial(bool spatial);
212
219 [[nodiscard]] float x_offset() const final;
220
227 void set_x_offset(float x_offset);
228
235 [[nodiscard]] float y_offset() const final;
236
243 void set_y_offset(float y_offset);
244
251 [[nodiscard]] bool attach_x() const final;
252
259 void set_attach_x(bool attach_x);
260
267 [[nodiscard]] bool attach_y() const final;
268
275 void set_attach_y(bool attach_y);
276
283 [[nodiscard]] bool x_angle_lock() const final;
284
291 void set_x_angle_lock(bool x_angle_lock);
292
299 [[nodiscard]] bool y_angle_lock() const final;
300
307 void set_y_angle_lock(bool y_angle_lock);
308
315 [[nodiscard]] bool playing() const;
316
323 [[nodiscard]] bool paused() const;
324
344 explicit speaker(std::shared_ptr<wze::sound> const& sound = {},
345 int8_t volume = std::numeric_limits<int8_t>::max(),
346 float range = std::numeric_limits<int16_t>::max(),
347 bool auto_panning = false, float x = 0, float y = 0,
348 float z = 0, bool spatial = false, float x_offset = 0,
349 float y_offset = 0, bool attach_x = true,
350 bool attach_y = true, bool x_angle_lock = true,
351 bool y_angle_lock = true);
352
359 speaker(speaker const& other);
360
367 speaker(speaker&& other) noexcept(false);
368
374 ~speaker() final;
375
383 speaker& operator=(speaker const& other);
384
392 speaker& operator=(speaker&& other) noexcept(false);
393
402 void play(uint16_t fade_in = 0, uint16_t loops = 0);
403
409 void pause();
410
416 void resume();
417
424 void stop(uint16_t fade_out = 0);
425
432 void align_panning();
433};
434} /* namespace wze */
435
436#endif /* WIZARD_ENGINE_SPEAKER_HPP */
Image file in host memory.
Interface to make an object composable.
Export header of the Wizard Engine.
Wizard Engine.