StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
Emitter.hpp
1#pragma once
2#ifdef StevEngine_AUDIO
3#include "utilities/Stream.hpp"
4#include "main/Component.hpp"
5#include <SDL_mixer.h>
6
7#define EMITTER_TYPE "Emitter"
8
9namespace StevEngine::Audio {
10
17 class Emitter : public Component {
18 friend class StevEngine::GameObject;
19 public:
21 bool loop;
22
24 double volume;
25
28
29 private:
31 std::string audioPath;
32
34 Mix_Chunk* audioData;
35
36 public:
43 Emitter(std::string audioPath, bool loop = false, double volume = 1);
44
50
55 std::string GetType() const { return EMITTER_TYPE; }
56
62 Utilities::Stream Export(Utilities::StreamType type) const;
63
70 void Play();
71
78 void ChangeSource(std::string path);
79
84 Mix_Chunk* GetData() const { return audioData; };
85
90 bool isPlaying() const { return channel != -1; }
91
92 private:
96 void Deactivate();
97
101 ~Emitter();
102 };
103
105 inline bool emitter = CreateComponents::RegisterComponentType<Emitter>(EMITTER_TYPE);
106}
107#endif
Component for playing sound effects from game objects.
Definition Emitter.hpp:17
Mix_Chunk * GetData() const
Get the raw audio data.
Definition Emitter.hpp:84
Emitter(std::string audioPath, bool loop=false, double volume=1)
Create a new audio emitter.
Definition Emitter.cpp:11
void ChangeSource(std::string path)
Change the audio source file.
Definition Emitter.cpp:26
double volume
Volume level from 0.0 to 1.0.
Definition Emitter.hpp:24
bool loop
Whether the sound should loop when playing.
Definition Emitter.hpp:21
void Play()
Play the sound.
Definition Emitter.cpp:22
int channel
Current audio channel ID, or -1 if not playing.
Definition Emitter.hpp:27
std::string GetType() const
Get component type.
Definition Emitter.hpp:55
Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition Emitter.cpp:52
bool isPlaying() const
Check if sound is currently playing.
Definition Emitter.hpp:90
Component()
Create new component.
Definition Component.cpp:10
static bool RegisterComponentType(std::string type)
Register a component type for creation.
Definition Component.hpp:133
Core game object class.
Definition GameObject.hpp:35
Stream for serialization of data.
Definition Stream.hpp:20