Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
audio_service.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <memory>
9#include <optional>
10#include <string>
11#include <unordered_map>
12#include <vector>
13
18 public:
19 AudioService() = default;
20
21 std::optional<std::shared_ptr<SoundResource>> register_sound(
22 const std::string& file_path, const std::string& name,
24 bool unregister_sound(const std::string& name);
25
26 std::optional<std::shared_ptr<SoundResource>> get_sound_resource(
27 const std::string& file_path,
28 const std::string& name = "") const noexcept;
29
30 std::reference_wrapper<SoundInstance> play_sound(
31 std::shared_ptr<SoundResource> sound_resource, float volume = 1.0f,
32 bool loop = false);
33 std::reference_wrapper<SoundInstance> play_sound(const std::string& name,
34 float volume = 1.0f,
35 bool loop = false);
36
37 void stop_sound(SoundInstance& instance);
38 void stop_sound(const std::string& name);
40
41 bool has_sound_instance(const std::string& name) const noexcept;
42 std::optional<std::reference_wrapper<SoundInstance>> get_sound_instance(
43 const std::string& name) const;
44 std::vector<std::reference_wrapper<SoundInstance>> get_all_playing_sounds()
45 const;
46
50 void update();
51
52 private:
53 std::unordered_map<std::string, std::shared_ptr<SoundResource>>
54 sound_resources_;
55 std::vector<std::unique_ptr<SoundInstance>> active_instances_;
56};
Manages audio playback and sound instances within the engine.
Definition audio_service.h:17
void stop_sound(SoundInstance &instance)
bool has_sound_instance(const std::string &name) const noexcept
std::vector< std::reference_wrapper< SoundInstance > > get_all_playing_sounds() const
std::reference_wrapper< SoundInstance > play_sound(std::shared_ptr< SoundResource > sound_resource, float volume=1.0f, bool loop=false)
void update()
Updates the audio manager, meaning it cleans up finished sounds.
AudioService()=default
std::optional< std::shared_ptr< SoundResource > > get_sound_resource(const std::string &file_path, const std::string &name="") const noexcept
bool unregister_sound(const std::string &name)
std::optional< std::shared_ptr< SoundResource > > register_sound(const std::string &file_path, const std::string &name, SoundType type=SoundType::GENERIC)
void stop_all_sounds()
std::optional< std::reference_wrapper< SoundInstance > > get_sound_instance(const std::string &name) const
Definition iEngineService.h:4
Represents an instance of a generic sound within the audio system. The reason for separating SoundIns...
Definition sound_instance.h:14
Represents a generic sound resource in the audio engine. This class serves as a base for specific sou...
Definition sound_resource.h:12
SoundType
Definition sound_type.h:5