Files
JailDesigner 6d0df85e5e Lint: rename de métodos privados (camelBack + traducción al inglés)
Tanda grande de identifier-naming: 47 métodos privados pasan de
snake_case (en su mayoría catalán/spanish) a camelBack inglés. Solo
afecta a sus archivos hpp+cpp; ningún símbolo cruza fichero (los
públicos quedan para una pasada manual con VS Code).

Renames por clase:

- ShapeLoader: resolve_path → resolvePath.
- VectorText: load_charset → loadCharset, get_shape_filename →
  getShapeFilename.
- Shape: starts_with → startsWith (cuidado de no tocar
  std::string::starts_with que también usaba), extract_value →
  extractValue, parse_center → parseCenter, parse_points → parsePoints.
- Starfield: inicialitzar_estrella → initStar, fora_area →
  isOutsideArea, calcular_escala → computeScale, calcular_brightness →
  computeBrightness.
- TitleScene: actualitzar_animacio_logo → updateLogoAnimation,
  inicialitzar_titol → initTitle.
- LogoScene: inicialitzar_lletres → initLetters, actualitzar_explosions
  → updateExplosions, canviar_estat → changeState,
  totes_lletres_completes → allLettersComplete.
- SpawnController: generar_spawn_events → generateSpawnEvents,
  seleccionar_tipus_aleatori → selectRandomType, spawn_enemic →
  spawnEnemy, aplicar_multiplicadors → applyMultipliers.
- ShipAnimator: actualitzar_entering/floating/exiting →
  updateEntering/Floating/Exiting, configurar_nau_p1/p2 →
  configureShipP1/P2, calcular_posicio_fora_pantalla →
  computeOffscreenPosition.
- GameScene: dibuixar_marges → drawMargins, dibuixar_marcador →
  drawScoreboard, disparar_bala → fireBullet, obtenir_punt_spawn →
  getSpawnPoint, unir_jugador → joinPlayer, dibuixar_continue →
  drawContinue, dibuixar_missatge_stage → drawStageMessage.
- StageLoader: parse_metadata/stage/spawn_config/distribution/multipliers/
  spawn_mode → parseMetadata/Stage/SpawnConfig/Distribution/Multipliers/
  SpawnMode, validar_config → validateConfig.
- StageManager: canviar_estat → changeState,
  processar_init_hud/level_start/playing/level_completed →
  processInitHud/LevelStart/Playing/LevelCompleted, carregar_stage →
  loadStage.

Métodos públicos y funciones libres (cross-file) quedan a propósito sin
tocar — los renombrará el usuario con la herramienta de rename de VS Code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 11:55:21 +02:00

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.
auto musicCache() -> std::unordered_map<std::string, std::unique_ptr<Ja::Music>>& {
static std::unordered_map<std::string, std::unique_ptr<Ja::Music>> cache_;
return cache_;
}
auto soundCache() -> std::unordered_map<std::string, std::unique_ptr<Ja::Sound>>& {
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"
auto normalizeMusicPath(const std::string& name) -> std::string {
return (name.starts_with("music/")) ? name : "music/" + name;
}
auto normalizeSoundPath(const std::string& name) -> std::string {
return (name.starts_with("sounds/")) ? 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