b746578bc8
Sustituye en bloque las cabeceras de los archivos por una sola línea de copyright. Cero rastro de "Visente", "Sergi" o "1999" en el árbol del proyecto. Se eliminan también las variantes "© 2025 Port a C++20", "© 2025 Port a C++20 con SDL3" y "© 2025 Orni Attack" (con todas sus colas descriptivas como "Arquitectura de entidades" o "Sistema de física"), que en este punto eran ruido histórico. Aplicado con un par de sed (find -type f, excluyendo source/external y source/legacy): 1. \|^// © 1999 Visente i Sergi (versión Pascal)$|d 2. s|^// © 2025 (Port a C++20.*|Orni Attack.*)$|// © 2026 JailDesigner| Verificado: la única variante de cabecera tras el sweep es "// © 2026 JailDesigner". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
100 lines
3.3 KiB
C++
100 lines
3.3 KiB
C++
// audio_adapter.cpp - Implementación de AudioResource para orni_attack
|
|
// © 2026 JailDesigner
|
|
//
|
|
// Implementa AudioResource::getMusic / getSound delegando a
|
|
// Resource::Helper::loadFile (que abstrae el resources.pack y el fallback
|
|
// a filesystem). Cache local de Ja::Music* / Ja::Sound* con lazy load:
|
|
// cada recurso se carga la primera vez que se pide y se mantiene vivo
|
|
// hasta el shutdown.
|
|
|
|
#include "core/audio/audio_adapter.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include "core/audio/jail_audio.hpp"
|
|
#include "core/resources/resource_helper.hpp"
|
|
|
|
namespace {
|
|
|
|
// Cachés locales: indexados por nombre lógico ("title.ogg", "effects/laser_shoot.wav", etc.)
|
|
// Mantienen ownership con unique_ptr; se liberan al salir del programa.
|
|
std::unordered_map<std::string, std::unique_ptr<Ja::Music>>& musicCache() {
|
|
static std::unordered_map<std::string, std::unique_ptr<Ja::Music>> cache;
|
|
return cache;
|
|
}
|
|
|
|
std::unordered_map<std::string, std::unique_ptr<Ja::Sound>>& soundCache() {
|
|
static std::unordered_map<std::string, std::unique_ptr<Ja::Sound>> cache;
|
|
return cache;
|
|
}
|
|
|
|
// Normaliza el nombre añadiendo la subcarpeta correspondiente si no la trae:
|
|
// "title.ogg" -> "music/title.ogg"
|
|
// "music/title.ogg" -> "music/title.ogg"
|
|
// "effects/laser.wav" -> "sounds/effects/laser.wav"
|
|
std::string normalizeMusicPath(const std::string& name) {
|
|
return (name.rfind("music/", 0) == 0) ? name : "music/" + name;
|
|
}
|
|
|
|
std::string normalizeSoundPath(const std::string& name) {
|
|
return (name.rfind("sounds/", 0) == 0) ? name : "sounds/" + name;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace AudioResource {
|
|
|
|
auto getMusic(const std::string& name) -> Ja::Music* {
|
|
auto& cache = musicCache();
|
|
if (auto it = cache.find(name); it != cache.end()) {
|
|
return it->second.get();
|
|
}
|
|
|
|
const std::string path = normalizeMusicPath(name);
|
|
auto bytes = Resource::Helper::loadFile(path);
|
|
if (bytes.empty()) {
|
|
std::cerr << "[AudioResource] no se ha podido cargar música: " << path << "\n";
|
|
return nullptr;
|
|
}
|
|
|
|
Ja::Music* raw = Ja::loadMusic(bytes.data(), static_cast<std::uint32_t>(bytes.size()), name.c_str());
|
|
if (raw == nullptr) {
|
|
std::cerr << "[AudioResource] decodificación de música falló: " << path << "\n";
|
|
return nullptr;
|
|
}
|
|
|
|
cache.emplace(name, std::unique_ptr<Ja::Music>(raw));
|
|
std::cout << "[AudioResource] música cargada: " << path << "\n";
|
|
return raw;
|
|
}
|
|
|
|
auto getSound(const std::string& name) -> Ja::Sound* {
|
|
auto& cache = soundCache();
|
|
if (auto it = cache.find(name); it != cache.end()) {
|
|
return it->second.get();
|
|
}
|
|
|
|
const std::string path = normalizeSoundPath(name);
|
|
auto bytes = Resource::Helper::loadFile(path);
|
|
if (bytes.empty()) {
|
|
std::cerr << "[AudioResource] no se ha podido cargar sonido: " << path << "\n";
|
|
return nullptr;
|
|
}
|
|
|
|
Ja::Sound* raw = Ja::loadSound(bytes.data(), static_cast<std::uint32_t>(bytes.size()));
|
|
if (raw == nullptr) {
|
|
std::cerr << "[AudioResource] decodificación de sonido falló: " << path << "\n";
|
|
return nullptr;
|
|
}
|
|
|
|
cache.emplace(name, std::unique_ptr<Ja::Sound>(raw));
|
|
std::cout << "[AudioResource] sonido cargado: " << path << "\n";
|
|
return raw;
|
|
}
|
|
|
|
} // namespace AudioResource
|