P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches
RaySound.hpp
Go to the documentation of this file.
1
10
11#ifndef RAYSOUND_HPP_
12#define RAYSOUND_HPP_
13
14//Raylib (without conflict)
15#include "RaylibAliases.hpp"
16
17//Interface
18#include "ISound.hpp"
19
20//encapsulation
21#include "RaySoundBuffer.hpp"
22
31class RaySound : public audio::ISound {
32
33 public:
34 RaySound(RaySoundBuffer &buffer) : _buffer(buffer) {
35 _alias = raylib::LoadSoundAlias(buffer.handle());
36 _volume = 1.0f;
37 }
38
39 ~RaySound() override {
40 raylib::UnloadSoundAlias(_alias);
41 }
42
43 bool isReady() const override {
44 return raylib::IsSoundValid(_alias);
45 }
46
47 void play() override {
48 //restart rather than overlap : matches sf::Sound's native
49 //behaviour instead of raylib's default auto-pooling, so the
50 //contract's play() semantics are the same across vendors
51 raylib::StopSound(_alias);
52 raylib::PlaySound(_alias);
53 }
54
55 void pause() override {
56 raylib::PauseSound(_alias);
57 }
58
59 void stop() override {
60 raylib::StopSound(_alias);
61 }
62
63 void setVolume(float volume) override {
64 _volume = volume;
65 raylib::SetSoundVolume(_alias, volume);
66 }
67
68 float getVolume() const override {
69 return _volume;
70 }
71
72 //raylib has no positional audio in its core Sound API : store and
73 //keep playing at full volume, a graceful no-op, not a broken one
74 void setPosition(Vector3f position) override {
75 _position = position;
76 }
77 Vector3f getPosition() const override {
78 return _position;
79 }
80
81 void setVelocity(Vector3f velocity) override {
82 _velocity = velocity;
83 }
84 Vector3f getVelocity() const override {
85 return _velocity;
86 }
87
88 private:
89 RaySoundBuffer &_buffer;
90 raylib::Sound _alias;
91 float _volume;
92 Vector3f _position{};
93 Vector3f _velocity{};
94};
95
97
98#endif /* !RAYSOUND_HPP_ */
Raylib SoundBuffer class - owns the loaded samples (raylib's own LoadSound() result)....
Definition RaySoundBuffer.hpp:25
raylib::Sound handle() const
Definition RaySoundBuffer.hpp:44
void setVolume(float volume) override
set the volume of the sound
Definition RaySound.hpp:63
void stop() override
Stops the sound AND rewinds to zero.
Definition RaySound.hpp:59
void setVelocity(Vector3f velocity) override
set the velocity of the sound, used by backends that apply a doppler effect
Definition RaySound.hpp:81
Vector3f getPosition() const override
get the 3D position of the sound
Definition RaySound.hpp:77
void pause() override
Suspends the sound without touching the position.
Definition RaySound.hpp:55
Vector3f getVelocity() const override
get the velocity of the sound
Definition RaySound.hpp:84
~RaySound() override
Definition RaySound.hpp:39
void setPosition(Vector3f position) override
set the 3D position of the sound, for backends that spatialize against a listener....
Definition RaySound.hpp:74
bool isReady() const override
Definition RaySound.hpp:43
float getVolume() const override
get the volume of the sound
Definition RaySound.hpp:68
RaySound(RaySoundBuffer &buffer)
Definition RaySound.hpp:34
void play() override
Fires the sound from the beginning.
Definition RaySound.hpp:47
Definition ISound.hpp:19
Vector3< double > Vector3f
Definition Vector3.hpp:121