Moved to SFML 3.0 now.

This commit is contained in:
Zed A. Shaw 2025-01-29 12:55:33 -05:00
parent 7c56f350ab
commit e05b2c304c
12 changed files with 167 additions and 173 deletions

View file

@ -3,6 +3,7 @@
#include <fmt/core.h>
using namespace fmt;
using std::make_shared;
namespace fs = std::filesystem;
SoundManager::SoundManager(std::string base_path) : $base_path(base_path) {
@ -13,31 +14,29 @@ void SoundManager::load(const std::string name, const std::string sound_path) {
// get the sound file with base_path
fs::path full_path = $base_path / sound_path;
// confirm it's there
dbc::check(fs::exists(full_path), format("sound file {} does not exist", sound_path));
dbc::check(fs::exists(full_path), fmt::format("sound file {} does not exist", sound_path));
// create the buffer and keep in the buffer map
SoundPair* pair = new SoundPair();
$sounds[name] = pair;
bool good = pair->buffer.loadFromFile(full_path.string());
dbc::check(good, format("failed to load sound {}", sound_path));
auto buffer = make_shared<sf::SoundBuffer>(full_path);
// set it on the sound and keep in the sound map
pair->sound.setBuffer(pair->buffer);
pair->sound.setRelativeToListener(false);
pair->sound.setPosition(0.0f, 0.0f, 1.0f);
auto sound = make_shared<sf::Sound>(*buffer);
sound->setRelativeToListener(false);
sound->setPosition({0.0f, 0.0f, 1.0f});
$sounds.try_emplace(name, buffer, sound);
}
void SoundManager::play(const std::string name) {
dbc::check($sounds.contains(name), format("sound {} is not loaded in map", name));
dbc::check($sounds.contains(name), fmt::format("sound {} is not loaded in map", name));
// get the sound from the sound map
auto pair = $sounds.at(name);
// play it
pair->sound.play();
pair.sound->play();
}
void SoundManager::playAt(const std::string name, float x, float y, float z) {
auto pair = $sounds.at(name);
pair->sound.setPosition(x, y, z);
pair->sound.play();
pair.sound->setPosition({x, y, z});
pair.sound->play();
}