2026-02-11 19:40:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-02-26 21:17:11 +08:00
|
|
|
#include <core/intrusive_ptr.h>
|
2026-02-11 19:40:26 +08:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
namespace extra2d {
|
|
|
|
|
|
|
|
|
|
class Sound;
|
|
|
|
|
|
|
|
|
|
class AudioEngine {
|
|
|
|
|
public:
|
|
|
|
|
static AudioEngine& getInstance();
|
|
|
|
|
|
|
|
|
|
AudioEngine(const AudioEngine&) = delete;
|
|
|
|
|
AudioEngine& operator=(const AudioEngine&) = delete;
|
|
|
|
|
AudioEngine(AudioEngine&&) = delete;
|
|
|
|
|
AudioEngine& operator=(AudioEngine&&) = delete;
|
|
|
|
|
|
|
|
|
|
bool initialize();
|
|
|
|
|
void shutdown();
|
|
|
|
|
|
2026-02-26 21:17:11 +08:00
|
|
|
IntrusivePtr<Sound> loadSound(const std::string& filePath);
|
|
|
|
|
IntrusivePtr<Sound> loadSound(const std::string& name, const std::string& filePath);
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-26 21:17:11 +08:00
|
|
|
IntrusivePtr<Sound> getSound(const std::string& name);
|
2026-02-11 19:40:26 +08:00
|
|
|
void unloadSound(const std::string& name);
|
|
|
|
|
void unloadAllSounds();
|
|
|
|
|
|
|
|
|
|
void setMasterVolume(float volume);
|
|
|
|
|
float getMasterVolume() const;
|
|
|
|
|
|
|
|
|
|
void pauseAll();
|
|
|
|
|
void resumeAll();
|
|
|
|
|
void stopAll();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
AudioEngine() = default;
|
|
|
|
|
~AudioEngine();
|
|
|
|
|
|
2026-02-26 21:17:11 +08:00
|
|
|
std::unordered_map<std::string, IntrusivePtr<Sound>> sounds_;
|
2026-02-11 19:40:26 +08:00
|
|
|
float masterVolume_ = 1.0f;
|
|
|
|
|
bool initialized_ = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace extra2d
|