Compare commits
3 Commits
20b9a95619
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bdb5c207c | |||
| 6246b5d89d | |||
| 34a41ad25c |
@@ -265,6 +265,7 @@ if(CPPCHECK_EXE)
|
|||||||
--inline-suppr
|
--inline-suppr
|
||||||
--suppress=missingIncludeSystem
|
--suppress=missingIncludeSystem
|
||||||
--suppress=toomanyconfigs
|
--suppress=toomanyconfigs
|
||||||
|
--suppress=*:*/source/external/*
|
||||||
--quiet
|
--quiet
|
||||||
-I ${CMAKE_SOURCE_DIR}/source
|
-I ${CMAKE_SOURCE_DIR}/source
|
||||||
${CPPCHECK_SOURCES}
|
${CPPCHECK_SOURCES}
|
||||||
|
|||||||
67
Makefile
67
Makefile
@@ -166,12 +166,28 @@ _macos_release:
|
|||||||
@$(MAKE) pack
|
@$(MAKE) pack
|
||||||
@echo "Creando release para macOS - Version: $(VERSION)"
|
@echo "Creando release para macOS - Version: $(VERSION)"
|
||||||
|
|
||||||
# Verificar e instalar create-dmg si es necesario
|
# Verifica dependencias necesarias (create-dmg). Si falta, intenta instalarla
|
||||||
@which create-dmg > /dev/null || (echo "Instalando create-dmg..." && brew install create-dmg)
|
# con brew; si brew tampoco está, indica el comando exacto al usuario.
|
||||||
|
@command -v create-dmg >/dev/null 2>&1 || { \
|
||||||
# Compila la versión para procesadores Intel con cmake
|
echo ""; \
|
||||||
@cmake -S . -B build/intel -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DMACOS_BUNDLE=ON -DGIT_HASH=$(GIT_HASH)
|
echo "============================================"; \
|
||||||
@cmake --build build/intel
|
echo " Falta la dependencia: create-dmg"; \
|
||||||
|
echo "============================================"; \
|
||||||
|
if command -v brew >/dev/null 2>&1; then \
|
||||||
|
echo " Instalando con: brew install create-dmg"; \
|
||||||
|
brew install create-dmg || { \
|
||||||
|
echo ""; \
|
||||||
|
echo " ERROR: 'brew install create-dmg' ha fallado."; \
|
||||||
|
echo " Ejecuta el comando manualmente y vuelve a probar."; \
|
||||||
|
exit 1; \
|
||||||
|
}; \
|
||||||
|
else \
|
||||||
|
echo " Homebrew no está instalado."; \
|
||||||
|
echo " Instálalo desde https://brew.sh y luego ejecuta:"; \
|
||||||
|
echo " brew install create-dmg"; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
}
|
||||||
|
|
||||||
# Elimina datos de compilaciones anteriores
|
# Elimina datos de compilaciones anteriores
|
||||||
$(RMDIR) "$(RELEASE_FOLDER)"
|
$(RMDIR) "$(RELEASE_FOLDER)"
|
||||||
@@ -200,14 +216,20 @@ _macos_release:
|
|||||||
sed -i '' '/<key>CFBundleShortVersionString<\/key>/{n;s|<string>.*</string>|<string>'"$$RAW_VERSION"'</string>|;}' "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Info.plist"; \
|
sed -i '' '/<key>CFBundleShortVersionString<\/key>/{n;s|<string>.*</string>|<string>'"$$RAW_VERSION"'</string>|;}' "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Info.plist"; \
|
||||||
sed -i '' '/<key>CFBundleVersion<\/key>/{n;s|<string>.*</string>|<string>'"$$RAW_VERSION"'</string>|;}' "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Info.plist"
|
sed -i '' '/<key>CFBundleVersion<\/key>/{n;s|<string>.*</string>|<string>'"$$RAW_VERSION"'</string>|;}' "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Info.plist"
|
||||||
|
|
||||||
# Copia el ejecutable Intel al bundle
|
# Compila y empaqueta la versión Intel (best-effort: si falla, se omite el
|
||||||
cp "$(TARGET_FILE)" "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)"
|
# DMG Intel y continúa con la build de Apple Silicon).
|
||||||
|
@echo ""
|
||||||
# Firma la aplicación
|
@echo "============================================"
|
||||||
codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
|
@echo " Compilando version Intel (x86_64)"
|
||||||
|
@echo "============================================"
|
||||||
# Empaqueta el .dmg de la versión Intel con create-dmg
|
@if cmake -S . -B build/intel -DCMAKE_BUILD_TYPE=Release \
|
||||||
@echo "Creando DMG Intel..."
|
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
|
||||||
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 \
|
||||||
|
-DMACOS_BUNDLE=ON -DGIT_HASH=$(GIT_HASH) \
|
||||||
|
&& cmake --build build/intel; then \
|
||||||
|
cp "$(TARGET_FILE)" "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)"; \
|
||||||
|
codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"; \
|
||||||
|
echo "Creando DMG Intel..."; \
|
||||||
create-dmg \
|
create-dmg \
|
||||||
--volname "$(APP_NAME)" \
|
--volname "$(APP_NAME)" \
|
||||||
--window-pos 200 120 \
|
--window-pos 200 120 \
|
||||||
@@ -220,10 +242,23 @@ _macos_release:
|
|||||||
--app-drop-link 115 102 \
|
--app-drop-link 115 102 \
|
||||||
--hide-extension "$(APP_NAME).app" \
|
--hide-extension "$(APP_NAME).app" \
|
||||||
"$(MACOS_INTEL_RELEASE)" \
|
"$(MACOS_INTEL_RELEASE)" \
|
||||||
"$(RELEASE_FOLDER)" || true
|
"$(RELEASE_FOLDER)" || true; \
|
||||||
@echo "Release Intel creado: $(MACOS_INTEL_RELEASE)"
|
echo "Release Intel creado: $(MACOS_INTEL_RELEASE)"; \
|
||||||
|
else \
|
||||||
|
echo ""; \
|
||||||
|
echo "============================================"; \
|
||||||
|
echo " WARNING: la build Intel ha fallado."; \
|
||||||
|
echo " Se omite el DMG Intel y se continúa con"; \
|
||||||
|
echo " la build de Apple Silicon."; \
|
||||||
|
echo "============================================"; \
|
||||||
|
echo ""; \
|
||||||
|
fi
|
||||||
|
|
||||||
# Compila la versión para procesadores Apple Silicon con cmake
|
# Compila la versión para procesadores Apple Silicon con cmake
|
||||||
|
@echo ""
|
||||||
|
@echo "============================================"
|
||||||
|
@echo " Compilando version Apple Silicon (arm64)"
|
||||||
|
@echo "============================================"
|
||||||
@cmake -S . -B build/arm -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DMACOS_BUNDLE=ON -DGIT_HASH=$(GIT_HASH)
|
@cmake -S . -B build/arm -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DMACOS_BUNDLE=ON -DGIT_HASH=$(GIT_HASH)
|
||||||
@cmake --build build/arm
|
@cmake --build build/arm
|
||||||
cp "$(TARGET_FILE)" "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)"
|
cp "$(TARGET_FILE)" "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)"
|
||||||
|
|||||||
212
source/core/audio/audio.cpp
Normal file
212
source/core/audio/audio.cpp
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
#include "core/audio/audio.hpp"
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h> // Para SDL_GetError, SDL_Init
|
||||||
|
|
||||||
|
#include <algorithm> // Para clamp
|
||||||
|
#include <iostream> // Para std::cout
|
||||||
|
|
||||||
|
// Implementación de stb_vorbis (debe estar ANTES de incluir jail_audio.hpp).
|
||||||
|
// clang-format off
|
||||||
|
#undef STB_VORBIS_HEADER_ONLY
|
||||||
|
#include "external/stb_vorbis.c"
|
||||||
|
// stb_vorbis.c filtra les macros L, C i R (i PLAYBACK_*) al TU. Les netegem
|
||||||
|
// perquè xocarien amb noms de paràmetres de plantilla en altres headers.
|
||||||
|
#undef L
|
||||||
|
#undef C
|
||||||
|
#undef R
|
||||||
|
#undef PLAYBACK_MONO
|
||||||
|
#undef PLAYBACK_LEFT
|
||||||
|
#undef PLAYBACK_RIGHT
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
#include "core/audio/audio_adapter.hpp" // Para AudioResource::getMusic/getSound
|
||||||
|
#include "core/audio/jail_audio.hpp" // Para JA_*
|
||||||
|
#include "game/options.hpp" // Para Options::audio
|
||||||
|
|
||||||
|
// Singleton
|
||||||
|
Audio* Audio::instance = nullptr;
|
||||||
|
|
||||||
|
// Inicializa la instancia única del singleton
|
||||||
|
void Audio::init() { Audio::instance = new Audio(); }
|
||||||
|
|
||||||
|
// Libera la instancia
|
||||||
|
void Audio::destroy() {
|
||||||
|
delete Audio::instance;
|
||||||
|
Audio::instance = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la instancia
|
||||||
|
auto Audio::get() -> Audio* { return Audio::instance; }
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Audio::Audio() { initSDLAudio(); }
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Audio::~Audio() {
|
||||||
|
JA_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método principal
|
||||||
|
void Audio::update() {
|
||||||
|
JA_Update();
|
||||||
|
|
||||||
|
// Sincronizar estado: detectar cuando la música se para (ej. fade-out completado)
|
||||||
|
if (instance && instance->music_.state == MusicState::PLAYING && JA_GetMusicState() != JA_MUSIC_PLAYING) {
|
||||||
|
instance->music_.state = MusicState::STOPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reproduce la música por nombre (con crossfade opcional)
|
||||||
|
void Audio::playMusic(const std::string& name, const int loop, const int crossfade_ms) {
|
||||||
|
bool new_loop = (loop != 0);
|
||||||
|
|
||||||
|
// Si ya está sonando exactamente la misma pista y mismo modo loop, no hacemos nada
|
||||||
|
if (music_.state == MusicState::PLAYING && music_.name == name && music_.loop == new_loop) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!music_enabled_) return;
|
||||||
|
|
||||||
|
auto* resource = AudioResource::getMusic(name);
|
||||||
|
if (resource == nullptr) return;
|
||||||
|
|
||||||
|
if (crossfade_ms > 0 && music_.state == MusicState::PLAYING) {
|
||||||
|
JA_CrossfadeMusic(resource, crossfade_ms, loop);
|
||||||
|
} else {
|
||||||
|
if (music_.state == MusicState::PLAYING) {
|
||||||
|
JA_StopMusic();
|
||||||
|
}
|
||||||
|
JA_PlayMusic(resource, loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
music_.name = name;
|
||||||
|
music_.loop = new_loop;
|
||||||
|
music_.state = MusicState::PLAYING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reproduce la música por puntero (con crossfade opcional)
|
||||||
|
void Audio::playMusic(JA_Music_t* music, const int loop, const int crossfade_ms) {
|
||||||
|
if (!music_enabled_ || music == nullptr) return;
|
||||||
|
|
||||||
|
if (crossfade_ms > 0 && music_.state == MusicState::PLAYING) {
|
||||||
|
JA_CrossfadeMusic(music, crossfade_ms, loop);
|
||||||
|
} else {
|
||||||
|
if (music_.state == MusicState::PLAYING) {
|
||||||
|
JA_StopMusic();
|
||||||
|
}
|
||||||
|
JA_PlayMusic(music, loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
music_.name.clear(); // nom desconegut quan es passa per punter
|
||||||
|
music_.loop = (loop != 0);
|
||||||
|
music_.state = MusicState::PLAYING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pausa la música
|
||||||
|
void Audio::pauseMusic() {
|
||||||
|
if (music_enabled_ && music_.state == MusicState::PLAYING) {
|
||||||
|
JA_PauseMusic();
|
||||||
|
music_.state = MusicState::PAUSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continua la música pausada
|
||||||
|
void Audio::resumeMusic() {
|
||||||
|
if (music_enabled_ && music_.state == MusicState::PAUSED) {
|
||||||
|
JA_ResumeMusic();
|
||||||
|
music_.state = MusicState::PLAYING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detiene la música
|
||||||
|
void Audio::stopMusic() {
|
||||||
|
if (music_enabled_) {
|
||||||
|
JA_StopMusic();
|
||||||
|
music_.state = MusicState::STOPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reproduce un sonido por nombre
|
||||||
|
void Audio::playSound(const std::string& name, Group group) const {
|
||||||
|
if (sound_enabled_) {
|
||||||
|
JA_PlaySound(AudioResource::getSound(name), 0, static_cast<int>(group));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reproduce un sonido por puntero directo
|
||||||
|
void Audio::playSound(JA_Sound_t* sound, Group group) const {
|
||||||
|
if (sound_enabled_ && sound != nullptr) {
|
||||||
|
JA_PlaySound(sound, 0, static_cast<int>(group));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detiene todos los sonidos
|
||||||
|
void Audio::stopAllSounds() const {
|
||||||
|
if (sound_enabled_) {
|
||||||
|
JA_StopChannel(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Realiza un fundido de salida de la música
|
||||||
|
void Audio::fadeOutMusic(int milliseconds) const {
|
||||||
|
if (music_enabled_ && getRealMusicState() == MusicState::PLAYING) {
|
||||||
|
JA_FadeOutMusic(milliseconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consulta directamente el estado real de la música en jailaudio
|
||||||
|
auto Audio::getRealMusicState() -> MusicState {
|
||||||
|
JA_Music_state ja_state = JA_GetMusicState();
|
||||||
|
switch (ja_state) {
|
||||||
|
case JA_MUSIC_PLAYING:
|
||||||
|
return MusicState::PLAYING;
|
||||||
|
case JA_MUSIC_PAUSED:
|
||||||
|
return MusicState::PAUSED;
|
||||||
|
case JA_MUSIC_STOPPED:
|
||||||
|
case JA_MUSIC_INVALID:
|
||||||
|
case JA_MUSIC_DISABLED:
|
||||||
|
default:
|
||||||
|
return MusicState::STOPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el volumen de los sonidos (float 0.0..1.0)
|
||||||
|
void Audio::setSoundVolume(float sound_volume, Group group) const {
|
||||||
|
if (sound_enabled_) {
|
||||||
|
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||||
|
const float CONVERTED_VOLUME = sound_volume * Options::audio.volume;
|
||||||
|
JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el volumen de la música (float 0.0..1.0)
|
||||||
|
void Audio::setMusicVolume(float music_volume) const {
|
||||||
|
if (music_enabled_) {
|
||||||
|
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||||
|
const float CONVERTED_VOLUME = music_volume * Options::audio.volume;
|
||||||
|
JA_SetMusicVolume(CONVERTED_VOLUME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aplica la configuración
|
||||||
|
void Audio::applySettings() {
|
||||||
|
enable(Options::audio.enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establecer estado general
|
||||||
|
void Audio::enable(bool value) {
|
||||||
|
enabled_ = value;
|
||||||
|
|
||||||
|
setSoundVolume(enabled_ ? Options::audio.sound.volume : MIN_VOLUME);
|
||||||
|
setMusicVolume(enabled_ ? Options::audio.music.volume : MIN_VOLUME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa SDL Audio
|
||||||
|
void Audio::initSDLAudio() {
|
||||||
|
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
||||||
|
std::cout << "SDL_AUDIO could not initialize! SDL Error: " << SDL_GetError() << '\n';
|
||||||
|
} else {
|
||||||
|
JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2);
|
||||||
|
enable(Options::audio.enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
114
source/core/audio/audio.hpp
Normal file
114
source/core/audio/audio.hpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint> // Para int8_t, uint8_t
|
||||||
|
#include <string> // Para string
|
||||||
|
#include <utility> // Para move
|
||||||
|
|
||||||
|
// --- Clase Audio: gestor de audio (singleton) ---
|
||||||
|
// Implementació canònica, byte-idèntica entre projectes.
|
||||||
|
// Els volums es manegen internament com a float 0.0–1.0; la capa de
|
||||||
|
// presentació (menús, notificacions) usa les helpers toPercent/fromPercent
|
||||||
|
// per mostrar 0–100 a l'usuari.
|
||||||
|
class Audio {
|
||||||
|
public:
|
||||||
|
// --- Enums ---
|
||||||
|
enum class Group : std::int8_t {
|
||||||
|
ALL = -1, // Todos los grupos
|
||||||
|
GAME = 0, // Sonidos del juego
|
||||||
|
INTERFACE = 1 // Sonidos de la interfaz
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class MusicState : std::uint8_t {
|
||||||
|
PLAYING, // Reproduciendo música
|
||||||
|
PAUSED, // Música pausada
|
||||||
|
STOPPED, // Música detenida
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Constantes ---
|
||||||
|
static constexpr float MAX_VOLUME = 1.0F; // Volumen máximo (float 0..1)
|
||||||
|
static constexpr float MIN_VOLUME = 0.0F; // Volumen mínimo (float 0..1)
|
||||||
|
static constexpr float VOLUME_STEP = 0.05F; // Pas estàndard per a UI (5%)
|
||||||
|
static constexpr int FREQUENCY = 48000; // Frecuencia de audio
|
||||||
|
static constexpr int DEFAULT_CROSSFADE_MS = 1500; // Duració del crossfade per defecte (ms)
|
||||||
|
|
||||||
|
// --- Singleton ---
|
||||||
|
static void init(); // Inicializa el objeto Audio
|
||||||
|
static void destroy(); // Libera el objeto Audio
|
||||||
|
static auto get() -> Audio*; // Obtiene el puntero al objeto Audio
|
||||||
|
Audio(const Audio&) = delete; // Evitar copia
|
||||||
|
auto operator=(const Audio&) -> Audio& = delete; // Evitar asignación
|
||||||
|
|
||||||
|
static void update(); // Actualización del sistema de audio
|
||||||
|
|
||||||
|
// --- Control de música ---
|
||||||
|
void playMusic(const std::string& name, int loop = -1, int crossfade_ms = 0); // Reproducir música por nombre (con crossfade opcional)
|
||||||
|
void playMusic(struct JA_Music_t* music, int loop = -1, int crossfade_ms = 0); // Reproducir música por puntero (con crossfade opcional)
|
||||||
|
void pauseMusic(); // Pausar reproducción de música
|
||||||
|
void resumeMusic(); // Continua la música pausada
|
||||||
|
void stopMusic(); // Detener completamente la música
|
||||||
|
void fadeOutMusic(int milliseconds) const; // Fundido de salida de la música
|
||||||
|
|
||||||
|
// --- Control de sonidos ---
|
||||||
|
void playSound(const std::string& name, Group group = Group::GAME) const; // Reproducir sonido puntual por nombre
|
||||||
|
void playSound(struct JA_Sound_t* sound, Group group = Group::GAME) const; // Reproducir sonido puntual por puntero
|
||||||
|
void stopAllSounds() const; // Detener todos los sonidos
|
||||||
|
|
||||||
|
// --- Control de volumen (API interna: float 0.0..1.0) ---
|
||||||
|
void setSoundVolume(float volume, Group group = Group::ALL) const; // Ajustar volumen de efectos
|
||||||
|
void setMusicVolume(float volume) const; // Ajustar volumen de música
|
||||||
|
|
||||||
|
// --- Helpers de conversió per a la capa de presentació ---
|
||||||
|
// UI (menús, notificacions) manega enters 0..100; internament viu float 0..1.
|
||||||
|
static constexpr auto toPercent(float volume) -> int {
|
||||||
|
return static_cast<int>(volume * 100.0F + 0.5F);
|
||||||
|
}
|
||||||
|
static constexpr auto fromPercent(int percent) -> float {
|
||||||
|
return static_cast<float>(percent) / 100.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Configuración general ---
|
||||||
|
void enable(bool value); // Establecer estado general
|
||||||
|
void toggleEnabled() { enabled_ = !enabled_; } // Alternar estado general
|
||||||
|
void applySettings(); // Aplica la configuración
|
||||||
|
|
||||||
|
// --- Configuración de sonidos ---
|
||||||
|
void enableSound() { sound_enabled_ = true; } // Habilitar sonidos
|
||||||
|
void disableSound() { sound_enabled_ = false; } // Deshabilitar sonidos
|
||||||
|
void enableSound(bool value) { sound_enabled_ = value; } // Establecer estado de sonidos
|
||||||
|
void toggleSound() { sound_enabled_ = !sound_enabled_; } // Alternar estado de sonidos
|
||||||
|
|
||||||
|
// --- Configuración de música ---
|
||||||
|
void enableMusic() { music_enabled_ = true; } // Habilitar música
|
||||||
|
void disableMusic() { music_enabled_ = false; } // Deshabilitar música
|
||||||
|
void enableMusic(bool value) { music_enabled_ = value; } // Establecer estado de música
|
||||||
|
void toggleMusic() { music_enabled_ = !music_enabled_; } // Alternar estado de música
|
||||||
|
|
||||||
|
// --- Consultas de estado ---
|
||||||
|
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
||||||
|
[[nodiscard]] auto isSoundEnabled() const -> bool { return sound_enabled_; }
|
||||||
|
[[nodiscard]] auto isMusicEnabled() const -> bool { return music_enabled_; }
|
||||||
|
[[nodiscard]] auto getMusicState() const -> MusicState { return music_.state; }
|
||||||
|
[[nodiscard]] static auto getRealMusicState() -> MusicState;
|
||||||
|
[[nodiscard]] auto getCurrentMusicName() const -> const std::string& { return music_.name; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// --- Tipos anidados ---
|
||||||
|
struct Music {
|
||||||
|
MusicState state{MusicState::STOPPED}; // Estado actual de la música
|
||||||
|
std::string name; // Última pista de música reproducida
|
||||||
|
bool loop{false}; // Indica si se reproduce en bucle
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Métodos ---
|
||||||
|
Audio(); // Constructor privado
|
||||||
|
~Audio(); // Destructor privado
|
||||||
|
void initSDLAudio(); // Inicializa SDL Audio
|
||||||
|
|
||||||
|
// --- Variables miembro ---
|
||||||
|
static Audio* instance; // Instancia única de Audio
|
||||||
|
|
||||||
|
Music music_; // Estado de la música
|
||||||
|
bool enabled_{true}; // Estado general del audio
|
||||||
|
bool sound_enabled_{true}; // Estado de los efectos de sonido
|
||||||
|
bool music_enabled_{true}; // Estado de la música
|
||||||
|
};
|
||||||
13
source/core/audio/audio_adapter.cpp
Normal file
13
source/core/audio/audio_adapter.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "core/audio/audio_adapter.hpp"
|
||||||
|
|
||||||
|
#include "core/resources/resource.h"
|
||||||
|
|
||||||
|
namespace AudioResource {
|
||||||
|
JA_Music_t* getMusic(const std::string& name) {
|
||||||
|
return Resource::get()->getMusic(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Sound_t* getSound(const std::string& name) {
|
||||||
|
return Resource::get()->getSound(name);
|
||||||
|
}
|
||||||
|
} // namespace AudioResource
|
||||||
17
source/core/audio/audio_adapter.hpp
Normal file
17
source/core/audio/audio_adapter.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// --- Audio Resource Adapter ---
|
||||||
|
// Aquest fitxer exposa una interfície comuna a Audio per obtenir JA_Music_t* /
|
||||||
|
// JA_Sound_t* per nom. Cada projecte la implementa en audio_adapter.cpp
|
||||||
|
// delegant al seu singleton de recursos (Resource::get(), Resource::Cache::get(),
|
||||||
|
// etc.). Això permet que audio.hpp/audio.cpp siguin idèntics entre projectes.
|
||||||
|
|
||||||
|
#include <string> // Para string
|
||||||
|
|
||||||
|
struct JA_Music_t;
|
||||||
|
struct JA_Sound_t;
|
||||||
|
|
||||||
|
namespace AudioResource {
|
||||||
|
JA_Music_t* getMusic(const std::string& name);
|
||||||
|
JA_Sound_t* getSound(const std::string& name);
|
||||||
|
} // namespace AudioResource
|
||||||
@@ -3,24 +3,41 @@
|
|||||||
// --- Includes ---
|
// --- Includes ---
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <stdint.h> // Para uint32_t, uint8_t
|
#include <stdint.h> // Para uint32_t, uint8_t
|
||||||
#include <stdio.h> // Para NULL, fseek, printf, fclose, fopen, fread, ftell, FILE, SEEK_END, SEEK_SET
|
#include <stdio.h> // Para NULL, fseek, fclose, fopen, fread, ftell, FILE, SEEK_END, SEEK_SET
|
||||||
#include <stdlib.h> // Para free, malloc
|
#include <stdlib.h> // Para free, malloc
|
||||||
#include <string.h> // Para strcpy, strlen
|
|
||||||
|
#include <iostream> // Para std::cout
|
||||||
|
#include <memory> // Para std::unique_ptr
|
||||||
|
#include <string> // Para std::string
|
||||||
|
#include <vector> // Para std::vector
|
||||||
|
|
||||||
#define STB_VORBIS_HEADER_ONLY
|
#define STB_VORBIS_HEADER_ONLY
|
||||||
#include "external/stb_vorbis.c"
|
#include "external/stb_vorbis.c" // Para stb_vorbis_open_memory i streaming
|
||||||
|
|
||||||
|
// Deleter stateless per a buffers reservats amb `SDL_malloc` / `SDL_LoadWAV*`.
|
||||||
|
// Compatible amb `std::unique_ptr<Uint8[], SDLFreeDeleter>` — zero size
|
||||||
|
// overhead gràcies a EBO, igual que un unique_ptr amb default_delete.
|
||||||
|
struct SDLFreeDeleter {
|
||||||
|
void operator()(Uint8* p) const noexcept {
|
||||||
|
if (p) SDL_free(p);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// --- Public Enums ---
|
// --- Public Enums ---
|
||||||
enum JA_Channel_state { JA_CHANNEL_INVALID,
|
enum JA_Channel_state {
|
||||||
|
JA_CHANNEL_INVALID,
|
||||||
JA_CHANNEL_FREE,
|
JA_CHANNEL_FREE,
|
||||||
JA_CHANNEL_PLAYING,
|
JA_CHANNEL_PLAYING,
|
||||||
JA_CHANNEL_PAUSED,
|
JA_CHANNEL_PAUSED,
|
||||||
JA_SOUND_DISABLED };
|
JA_SOUND_DISABLED,
|
||||||
enum JA_Music_state { JA_MUSIC_INVALID,
|
};
|
||||||
|
enum JA_Music_state {
|
||||||
|
JA_MUSIC_INVALID,
|
||||||
JA_MUSIC_PLAYING,
|
JA_MUSIC_PLAYING,
|
||||||
JA_MUSIC_PAUSED,
|
JA_MUSIC_PAUSED,
|
||||||
JA_MUSIC_STOPPED,
|
JA_MUSIC_STOPPED,
|
||||||
JA_MUSIC_DISABLED };
|
JA_MUSIC_DISABLED,
|
||||||
|
};
|
||||||
|
|
||||||
// --- Struct Definitions ---
|
// --- Struct Definitions ---
|
||||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 20
|
#define JA_MAX_SIMULTANEOUS_CHANNELS 20
|
||||||
@@ -29,7 +46,9 @@ enum JA_Music_state { JA_MUSIC_INVALID,
|
|||||||
struct JA_Sound_t {
|
struct JA_Sound_t {
|
||||||
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
||||||
Uint32 length{0};
|
Uint32 length{0};
|
||||||
Uint8* buffer{NULL};
|
// Buffer descomprimit (PCM) propietat del sound. Reservat per SDL_LoadWAV
|
||||||
|
// via SDL_malloc; el deleter `SDLFreeDeleter` allibera amb SDL_free.
|
||||||
|
std::unique_ptr<Uint8[], SDLFreeDeleter> buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JA_Channel_t {
|
struct JA_Channel_t {
|
||||||
@@ -44,21 +63,22 @@ struct JA_Channel_t {
|
|||||||
struct JA_Music_t {
|
struct JA_Music_t {
|
||||||
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
||||||
|
|
||||||
// OGG comprimit en memòria. Propietat nostra; es copia des del fitxer una
|
// OGG comprimit en memòria. Propietat nostra; es copia des del buffer
|
||||||
// sola vegada en JA_LoadMusic i es descomprimix en chunks per streaming.
|
// d'entrada una sola vegada en JA_LoadMusic i es descomprimix en chunks
|
||||||
Uint8* ogg_data{nullptr};
|
// per streaming. Com que stb_vorbis guarda un punter persistent al
|
||||||
Uint32 ogg_length{0};
|
// `.data()` d'aquest vector, no el podem resize'jar un cop establert
|
||||||
stb_vorbis* vorbis{nullptr}; // Handle del decoder, viu tot el cicle del JA_Music_t
|
// (una reallocation invalidaria el punter que el decoder conserva).
|
||||||
|
std::vector<Uint8> ogg_data;
|
||||||
|
stb_vorbis* vorbis{nullptr}; // handle del decoder, viu tot el cicle del JA_Music_t
|
||||||
|
|
||||||
char* filename{nullptr};
|
std::string filename;
|
||||||
|
|
||||||
int times{0}; // Loops restants (-1 = infinit, 0 = un sol play)
|
int times{0}; // loops restants (-1 = infinit, 0 = un sol play)
|
||||||
SDL_AudioStream* stream{nullptr};
|
SDL_AudioStream* stream{nullptr};
|
||||||
JA_Music_state state{JA_MUSIC_INVALID};
|
JA_Music_state state{JA_MUSIC_INVALID};
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Internal Global State ---
|
// --- Internal Global State (inline, C++17) ---
|
||||||
// Marcado 'inline' (C++17) para asegurar una única instancia.
|
|
||||||
|
|
||||||
inline JA_Music_t* current_music{nullptr};
|
inline JA_Music_t* current_music{nullptr};
|
||||||
inline JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
inline JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||||
@@ -70,15 +90,27 @@ inline bool JA_musicEnabled{true};
|
|||||||
inline bool JA_soundEnabled{true};
|
inline bool JA_soundEnabled{true};
|
||||||
inline SDL_AudioDeviceID sdlAudioDevice{0};
|
inline SDL_AudioDeviceID sdlAudioDevice{0};
|
||||||
|
|
||||||
inline bool fading{false};
|
// --- Crossfade / Fade State ---
|
||||||
inline int fade_start_time{0};
|
struct JA_FadeState {
|
||||||
inline int fade_duration{0};
|
bool active{false};
|
||||||
inline float fade_initial_volume{0.0f};
|
Uint64 start_time{0};
|
||||||
|
int duration_ms{0};
|
||||||
|
float initial_volume{0.0f};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JA_OutgoingMusic {
|
||||||
|
SDL_AudioStream* stream{nullptr};
|
||||||
|
JA_FadeState fade;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline JA_OutgoingMusic outgoing_music;
|
||||||
|
inline JA_FadeState incoming_fade;
|
||||||
|
|
||||||
// --- Forward Declarations ---
|
// --- Forward Declarations ---
|
||||||
inline void JA_StopMusic();
|
inline void JA_StopMusic();
|
||||||
inline void JA_StopChannel(const int channel);
|
inline void JA_StopChannel(const int channel);
|
||||||
inline int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop = 0, const int group = 0);
|
inline int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop = 0, const int group = 0);
|
||||||
|
inline void JA_CrossfadeMusic(JA_Music_t* music, int crossfade_ms, int loop = -1);
|
||||||
|
|
||||||
// --- Music streaming internals ---
|
// --- Music streaming internals ---
|
||||||
// Bytes-per-sample per canal (sempre s16)
|
// Bytes-per-sample per canal (sempre s16)
|
||||||
@@ -96,15 +128,15 @@ inline int JA_FeedMusicChunk(JA_Music_t* music) {
|
|||||||
if (!music || !music->vorbis || !music->stream) return 0;
|
if (!music || !music->vorbis || !music->stream) return 0;
|
||||||
|
|
||||||
short chunk[JA_MUSIC_CHUNK_SHORTS];
|
short chunk[JA_MUSIC_CHUNK_SHORTS];
|
||||||
const int numChannels = music->spec.channels;
|
const int num_channels = music->spec.channels;
|
||||||
const int samples_per_channel = stb_vorbis_get_samples_short_interleaved(
|
const int samples_per_channel = stb_vorbis_get_samples_short_interleaved(
|
||||||
music->vorbis,
|
music->vorbis,
|
||||||
numChannels,
|
num_channels,
|
||||||
chunk,
|
chunk,
|
||||||
JA_MUSIC_CHUNK_SHORTS);
|
JA_MUSIC_CHUNK_SHORTS);
|
||||||
if (samples_per_channel <= 0) return 0;
|
if (samples_per_channel <= 0) return 0;
|
||||||
|
|
||||||
const int bytes = samples_per_channel * numChannels * JA_MUSIC_BYTES_PER_SAMPLE;
|
const int bytes = samples_per_channel * num_channels * JA_MUSIC_BYTES_PER_SAMPLE;
|
||||||
SDL_PutAudioStreamData(music->stream, chunk, bytes);
|
SDL_PutAudioStreamData(music->stream, chunk, bytes);
|
||||||
return samples_per_channel;
|
return samples_per_channel;
|
||||||
}
|
}
|
||||||
@@ -131,20 +163,51 @@ inline void JA_PumpMusic(JA_Music_t* music) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-carrega `duration_ms` de so dins l'stream actual abans que l'stream
|
||||||
|
// siga robat per outgoing_music (crossfade o fade-out). Imprescindible amb
|
||||||
|
// streaming: l'stream robat no es pot re-alimentar perquè perd la referència
|
||||||
|
// al seu vorbis decoder. No aplica loop — si el vorbis s'esgota abans, parem.
|
||||||
|
inline void JA_PreFillOutgoing(JA_Music_t* music, int duration_ms) {
|
||||||
|
if (!music || !music->vorbis || !music->stream) return;
|
||||||
|
|
||||||
|
const int bytes_per_second = music->spec.freq * music->spec.channels * JA_MUSIC_BYTES_PER_SAMPLE;
|
||||||
|
const int needed_bytes = static_cast<int>((static_cast<int64_t>(duration_ms) * bytes_per_second) / 1000);
|
||||||
|
|
||||||
|
while (SDL_GetAudioStreamAvailable(music->stream) < needed_bytes) {
|
||||||
|
const int decoded = JA_FeedMusicChunk(music);
|
||||||
|
if (decoded <= 0) break; // EOF: deixem drenar el que hi haja
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- Core Functions ---
|
// --- Core Functions ---
|
||||||
|
|
||||||
inline void JA_Update() {
|
inline void JA_Update() {
|
||||||
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING) {
|
// --- Outgoing music fade-out (crossfade o fade-out a silencio) ---
|
||||||
if (fading) {
|
if (outgoing_music.stream && outgoing_music.fade.active) {
|
||||||
int time = SDL_GetTicks();
|
Uint64 now = SDL_GetTicks();
|
||||||
if (time > (fade_start_time + fade_duration)) {
|
Uint64 elapsed = now - outgoing_music.fade.start_time;
|
||||||
fading = false;
|
if (elapsed >= (Uint64)outgoing_music.fade.duration_ms) {
|
||||||
JA_StopMusic();
|
SDL_DestroyAudioStream(outgoing_music.stream);
|
||||||
return;
|
outgoing_music.stream = nullptr;
|
||||||
|
outgoing_music.fade.active = false;
|
||||||
} else {
|
} else {
|
||||||
const int time_passed = time - fade_start_time;
|
float percent = (float)elapsed / (float)outgoing_music.fade.duration_ms;
|
||||||
const float percent = (float)time_passed / (float)fade_duration;
|
SDL_SetAudioStreamGain(outgoing_music.stream, outgoing_music.fade.initial_volume * (1.0f - percent));
|
||||||
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume * (1.0 - percent));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Current music ---
|
||||||
|
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING) {
|
||||||
|
// Fade-in (parte de un crossfade)
|
||||||
|
if (incoming_fade.active) {
|
||||||
|
Uint64 now = SDL_GetTicks();
|
||||||
|
Uint64 elapsed = now - incoming_fade.start_time;
|
||||||
|
if (elapsed >= (Uint64)incoming_fade.duration_ms) {
|
||||||
|
incoming_fade.active = false;
|
||||||
|
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
|
||||||
|
} else {
|
||||||
|
float percent = (float)elapsed / (float)incoming_fade.duration_ms;
|
||||||
|
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume * percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +219,13 @@ inline void JA_Update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Sound channels ---
|
||||||
if (JA_soundEnabled) {
|
if (JA_soundEnabled) {
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i)
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i)
|
||||||
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||||
if (channels[i].times != 0) {
|
if (channels[i].times != 0) {
|
||||||
if ((Uint32)SDL_GetAudioStreamAvailable(channels[i].stream) < (channels[i].sound->length / 2)) {
|
if ((Uint32)SDL_GetAudioStreamAvailable(channels[i].stream) < (channels[i].sound->length / 2)) {
|
||||||
SDL_PutAudioStreamData(channels[i].stream, channels[i].sound->buffer, channels[i].sound->length);
|
SDL_PutAudioStreamData(channels[i].stream, channels[i].sound->buffer.get(), channels[i].sound->length);
|
||||||
if (channels[i].times > 0) channels[i].times--;
|
if (channels[i].times > 0) channels[i].times--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -172,19 +236,19 @@ inline void JA_Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) {
|
inline void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) {
|
||||||
#ifdef DEBUG
|
|
||||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
JA_audioSpec = {format, num_channels, freq};
|
JA_audioSpec = {format, num_channels, freq};
|
||||||
if (sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
|
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
|
||||||
if (sdlAudioDevice == 0) SDL_Log("Failed to initialize SDL audio!");
|
if (sdlAudioDevice == 0) std::cout << "Failed to initialize SDL audio!" << '\n';
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE;
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE;
|
||||||
for (int i = 0; i < JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f;
|
for (int i = 0; i < JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void JA_Quit() {
|
inline void JA_Quit() {
|
||||||
|
if (outgoing_music.stream) {
|
||||||
|
SDL_DestroyAudioStream(outgoing_music.stream);
|
||||||
|
outgoing_music.stream = nullptr;
|
||||||
|
}
|
||||||
if (sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
sdlAudioDevice = 0;
|
sdlAudioDevice = 0;
|
||||||
}
|
}
|
||||||
@@ -194,26 +258,25 @@ inline void JA_Quit() {
|
|||||||
inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) {
|
inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) {
|
||||||
if (!buffer || length == 0) return nullptr;
|
if (!buffer || length == 0) return nullptr;
|
||||||
|
|
||||||
// Còpia del OGG comprimit: stb_vorbis llig de forma persistent aquesta
|
// Allocem el JA_Music_t primer per aprofitar el seu `std::vector<Uint8>`
|
||||||
// memòria mentre el handle estiga viu, així que hem de posseir-la nosaltres.
|
// com a propietari del OGG comprimit. stb_vorbis guarda un punter
|
||||||
Uint8* ogg_copy = static_cast<Uint8*>(SDL_malloc(length));
|
// persistent al buffer; com que ací no el resize'jem, el .data() és
|
||||||
if (!ogg_copy) return nullptr;
|
// estable durant tot el cicle de vida del music.
|
||||||
SDL_memcpy(ogg_copy, buffer, length);
|
auto* music = new JA_Music_t();
|
||||||
|
music->ogg_data.assign(buffer, buffer + length);
|
||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
stb_vorbis* vorbis = stb_vorbis_open_memory(ogg_copy, static_cast<int>(length), &error, nullptr);
|
music->vorbis = stb_vorbis_open_memory(music->ogg_data.data(),
|
||||||
if (!vorbis) {
|
static_cast<int>(length),
|
||||||
SDL_free(ogg_copy);
|
&error,
|
||||||
SDL_Log("JA_LoadMusic: stb_vorbis_open_memory failed (error %d)", error);
|
nullptr);
|
||||||
|
if (!music->vorbis) {
|
||||||
|
std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << error << ")" << '\n';
|
||||||
|
delete music;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* music = new JA_Music_t();
|
const stb_vorbis_info info = stb_vorbis_get_info(music->vorbis);
|
||||||
music->ogg_data = ogg_copy;
|
|
||||||
music->ogg_length = length;
|
|
||||||
music->vorbis = vorbis;
|
|
||||||
|
|
||||||
const stb_vorbis_info info = stb_vorbis_get_info(vorbis);
|
|
||||||
music->spec.channels = info.channels;
|
music->spec.channels = info.channels;
|
||||||
music->spec.freq = static_cast<int>(info.sample_rate);
|
music->spec.freq = static_cast<int>(info.sample_rate);
|
||||||
music->spec.format = SDL_AUDIO_S16;
|
music->spec.format = SDL_AUDIO_S16;
|
||||||
@@ -222,30 +285,36 @@ inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) {
|
|||||||
return music;
|
return music;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Overload amb filename — els callers l'usen per poder comparar la música
|
||||||
|
// en curs amb JA_GetMusicFilename() i no rearrancar-la si ja és la mateixa.
|
||||||
|
inline JA_Music_t* JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename) {
|
||||||
|
JA_Music_t* music = JA_LoadMusic(static_cast<const Uint8*>(buffer), length);
|
||||||
|
if (music && filename) music->filename = filename;
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
inline JA_Music_t* JA_LoadMusic(const char* filename) {
|
inline JA_Music_t* JA_LoadMusic(const char* filename) {
|
||||||
|
// Carreguem primer el arxiu en memòria i després el descomprimim.
|
||||||
FILE* f = fopen(filename, "rb");
|
FILE* f = fopen(filename, "rb");
|
||||||
if (!f) return NULL;
|
if (!f) return nullptr;
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
long fsize = ftell(f);
|
long fsize = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
auto* buffer = static_cast<Uint8*>(malloc(fsize + 1));
|
auto* buffer = static_cast<Uint8*>(malloc(fsize + 1));
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (fread(buffer, fsize, 1, f) != 1) {
|
if (fread(buffer, fsize, 1, f) != 1) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
JA_Music_t* music = JA_LoadMusic(buffer, fsize);
|
JA_Music_t* music = JA_LoadMusic(static_cast<const Uint8*>(buffer), static_cast<Uint32>(fsize));
|
||||||
if (music) {
|
if (music) {
|
||||||
music->filename = static_cast<char*>(malloc(strlen(filename) + 1));
|
music->filename = filename;
|
||||||
if (music->filename) {
|
|
||||||
strcpy(music->filename, filename);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@@ -268,7 +337,7 @@ inline void JA_PlayMusic(JA_Music_t* music, const int loop = -1) {
|
|||||||
|
|
||||||
current_music->stream = SDL_CreateAudioStream(¤t_music->spec, &JA_audioSpec);
|
current_music->stream = SDL_CreateAudioStream(¤t_music->spec, &JA_audioSpec);
|
||||||
if (!current_music->stream) {
|
if (!current_music->stream) {
|
||||||
SDL_Log("Failed to create audio stream!");
|
std::cout << "Failed to create audio stream!" << '\n';
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -277,13 +346,15 @@ inline void JA_PlayMusic(JA_Music_t* music, const int loop = -1) {
|
|||||||
// Pre-cargem el buffer abans de bindejar per evitar un underrun inicial.
|
// Pre-cargem el buffer abans de bindejar per evitar un underrun inicial.
|
||||||
JA_PumpMusic(current_music);
|
JA_PumpMusic(current_music);
|
||||||
|
|
||||||
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) printf("[ERROR] SDL_BindAudioStream failed!\n");
|
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) {
|
||||||
|
std::cout << "[ERROR] SDL_BindAudioStream failed!" << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char* JA_GetMusicFilename(const JA_Music_t* music = nullptr) {
|
inline const char* JA_GetMusicFilename(const JA_Music_t* music = nullptr) {
|
||||||
if (!music) music = current_music;
|
if (!music) music = current_music;
|
||||||
if (!music) return nullptr;
|
if (!music || music->filename.empty()) return nullptr;
|
||||||
return music->filename;
|
return music->filename.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void JA_PauseMusic() {
|
inline void JA_PauseMusic() {
|
||||||
@@ -303,6 +374,14 @@ inline void JA_ResumeMusic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void JA_StopMusic() {
|
inline void JA_StopMusic() {
|
||||||
|
// Limpiar outgoing crossfade si existe
|
||||||
|
if (outgoing_music.stream) {
|
||||||
|
SDL_DestroyAudioStream(outgoing_music.stream);
|
||||||
|
outgoing_music.stream = nullptr;
|
||||||
|
outgoing_music.fade.active = false;
|
||||||
|
}
|
||||||
|
incoming_fade.active = false;
|
||||||
|
|
||||||
if (!current_music || current_music->state == JA_MUSIC_INVALID || current_music->state == JA_MUSIC_STOPPED) return;
|
if (!current_music || current_music->state == JA_MUSIC_INVALID || current_music->state == JA_MUSIC_STOPPED) return;
|
||||||
|
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
@@ -319,12 +398,69 @@ inline void JA_StopMusic() {
|
|||||||
|
|
||||||
inline void JA_FadeOutMusic(const int milliseconds) {
|
inline void JA_FadeOutMusic(const int milliseconds) {
|
||||||
if (!JA_musicEnabled) return;
|
if (!JA_musicEnabled) return;
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
if (!current_music || current_music->state != JA_MUSIC_PLAYING) return;
|
||||||
|
|
||||||
fading = true;
|
// Destruir outgoing anterior si existe
|
||||||
fade_start_time = SDL_GetTicks();
|
if (outgoing_music.stream) {
|
||||||
fade_duration = milliseconds;
|
SDL_DestroyAudioStream(outgoing_music.stream);
|
||||||
fade_initial_volume = JA_musicVolume;
|
outgoing_music.stream = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pre-omplim l'stream amb `milliseconds` de so: un cop robat, ja no
|
||||||
|
// tindrà accés al vorbis decoder i només podrà drenar el que tinga.
|
||||||
|
JA_PreFillOutgoing(current_music, milliseconds);
|
||||||
|
|
||||||
|
// Robar el stream del current_music al outgoing
|
||||||
|
outgoing_music.stream = current_music->stream;
|
||||||
|
outgoing_music.fade = {true, SDL_GetTicks(), milliseconds, JA_musicVolume};
|
||||||
|
|
||||||
|
// Dejar current_music sin stream (ya lo tiene outgoing)
|
||||||
|
current_music->stream = nullptr;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
if (current_music->vorbis) stb_vorbis_seek_start(current_music->vorbis);
|
||||||
|
incoming_fade.active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void JA_CrossfadeMusic(JA_Music_t* music, const int crossfade_ms, const int loop) {
|
||||||
|
if (!JA_musicEnabled || !music || !music->vorbis) return;
|
||||||
|
|
||||||
|
// Destruir outgoing anterior si existe (crossfade durante crossfade)
|
||||||
|
if (outgoing_music.stream) {
|
||||||
|
SDL_DestroyAudioStream(outgoing_music.stream);
|
||||||
|
outgoing_music.stream = nullptr;
|
||||||
|
outgoing_music.fade.active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Robar el stream de la musica actual al outgoing para el fade-out.
|
||||||
|
// Pre-omplim amb `crossfade_ms` de so perquè no es quede en silenci
|
||||||
|
// abans d'acabar el fade (l'stream robat ja no pot alimentar-se).
|
||||||
|
if (current_music && current_music->state == JA_MUSIC_PLAYING && current_music->stream) {
|
||||||
|
JA_PreFillOutgoing(current_music, crossfade_ms);
|
||||||
|
outgoing_music.stream = current_music->stream;
|
||||||
|
outgoing_music.fade = {true, SDL_GetTicks(), crossfade_ms, JA_musicVolume};
|
||||||
|
current_music->stream = nullptr;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
if (current_music->vorbis) stb_vorbis_seek_start(current_music->vorbis);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iniciar la nueva pista con gain=0 (el fade-in la sube gradualmente)
|
||||||
|
current_music = music;
|
||||||
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
|
current_music->times = loop;
|
||||||
|
|
||||||
|
stb_vorbis_seek_start(current_music->vorbis);
|
||||||
|
current_music->stream = SDL_CreateAudioStream(¤t_music->spec, &JA_audioSpec);
|
||||||
|
if (!current_music->stream) {
|
||||||
|
std::cout << "Failed to create audio stream for crossfade!" << '\n';
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SDL_SetAudioStreamGain(current_music->stream, 0.0f);
|
||||||
|
JA_PumpMusic(current_music); // pre-carrega abans de bindejar
|
||||||
|
SDL_BindAudioStream(sdlAudioDevice, current_music->stream);
|
||||||
|
|
||||||
|
// Configurar fade-in
|
||||||
|
incoming_fade = {true, SDL_GetTicks(), crossfade_ms, 0.0f};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline JA_Music_state JA_GetMusicState() {
|
inline JA_Music_state JA_GetMusicState() {
|
||||||
@@ -342,8 +478,8 @@ inline void JA_DeleteMusic(JA_Music_t* music) {
|
|||||||
}
|
}
|
||||||
if (music->stream) SDL_DestroyAudioStream(music->stream);
|
if (music->stream) SDL_DestroyAudioStream(music->stream);
|
||||||
if (music->vorbis) stb_vorbis_close(music->vorbis);
|
if (music->vorbis) stb_vorbis_close(music->vorbis);
|
||||||
SDL_free(music->ogg_data);
|
// ogg_data (std::vector) i filename (std::string) s'alliberen sols
|
||||||
free(music->filename);
|
// al destructor de JA_Music_t.
|
||||||
delete music;
|
delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,48 +492,40 @@ inline float JA_SetMusicVolume(float volume) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void JA_SetMusicPosition(float /*value*/) {
|
inline void JA_SetMusicPosition(float /*value*/) {
|
||||||
// No implementat amb el backend de streaming. Mai va arribar a usar-se
|
// No implementat amb el backend de streaming.
|
||||||
// en el codi existent, així que es manté com a stub.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float JA_GetMusicPosition() {
|
inline float JA_GetMusicPosition() {
|
||||||
// Veure nota a JA_SetMusicPosition.
|
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void JA_EnableMusic(const bool value) {
|
inline void JA_EnableMusic(const bool value) {
|
||||||
if (!value && current_music && (current_music->state == JA_MUSIC_PLAYING)) JA_StopMusic();
|
if (!value && current_music && (current_music->state == JA_MUSIC_PLAYING)) JA_StopMusic();
|
||||||
|
|
||||||
JA_musicEnabled = value;
|
JA_musicEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Sound Functions ---
|
// --- Sound Functions ---
|
||||||
|
|
||||||
inline JA_Sound_t* JA_NewSound(Uint8* buffer, Uint32 length) {
|
|
||||||
JA_Sound_t* sound = new JA_Sound_t();
|
|
||||||
sound->buffer = buffer;
|
|
||||||
sound->length = length;
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline JA_Sound_t* JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
inline JA_Sound_t* JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
||||||
JA_Sound_t* sound = new JA_Sound_t();
|
auto sound = std::make_unique<JA_Sound_t>();
|
||||||
if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &sound->buffer, &sound->length)) {
|
Uint8* raw = nullptr;
|
||||||
SDL_Log("Failed to load WAV from memory: %s", SDL_GetError());
|
if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &raw, &sound->length)) {
|
||||||
delete sound;
|
std::cout << "Failed to load WAV from memory: " << SDL_GetError() << '\n';
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return sound;
|
sound->buffer.reset(raw); // adopta el SDL_malloc'd buffer
|
||||||
|
return sound.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline JA_Sound_t* JA_LoadSound(const char* filename) {
|
inline JA_Sound_t* JA_LoadSound(const char* filename) {
|
||||||
JA_Sound_t* sound = new JA_Sound_t();
|
auto sound = std::make_unique<JA_Sound_t>();
|
||||||
if (!SDL_LoadWAV(filename, &sound->spec, &sound->buffer, &sound->length)) {
|
Uint8* raw = nullptr;
|
||||||
SDL_Log("Failed to load WAV file: %s", SDL_GetError());
|
if (!SDL_LoadWAV(filename, &sound->spec, &raw, &sound->length)) {
|
||||||
delete sound;
|
std::cout << "Failed to load WAV file: " << SDL_GetError() << '\n';
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return sound;
|
sound->buffer.reset(raw); // adopta el SDL_malloc'd buffer
|
||||||
|
return sound.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int JA_PlaySound(JA_Sound_t* sound, const int loop = 0, const int group = 0) {
|
inline int JA_PlaySound(JA_Sound_t* sound, const int loop = 0, const int group = 0) {
|
||||||
@@ -406,6 +534,7 @@ inline int JA_PlaySound(JA_Sound_t* sound, const int loop = 0, const int group =
|
|||||||
int channel = 0;
|
int channel = 0;
|
||||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||||
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) {
|
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||||
|
// No hay canal libre, reemplazamos el primero
|
||||||
channel = 0;
|
channel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,12 +555,12 @@ inline int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int
|
|||||||
channels[channel].stream = SDL_CreateAudioStream(&channels[channel].sound->spec, &JA_audioSpec);
|
channels[channel].stream = SDL_CreateAudioStream(&channels[channel].sound->spec, &JA_audioSpec);
|
||||||
|
|
||||||
if (!channels[channel].stream) {
|
if (!channels[channel].stream) {
|
||||||
SDL_Log("Failed to create audio stream for sound!");
|
std::cout << "Failed to create audio stream for sound!" << '\n';
|
||||||
channels[channel].state = JA_CHANNEL_FREE;
|
channels[channel].state = JA_CHANNEL_FREE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_PutAudioStreamData(channels[channel].stream, channels[channel].sound->buffer, channels[channel].sound->length);
|
SDL_PutAudioStreamData(channels[channel].stream, channels[channel].sound->buffer.get(), channels[channel].sound->length);
|
||||||
SDL_SetAudioStreamGain(channels[channel].stream, JA_soundVolume[group]);
|
SDL_SetAudioStreamGain(channels[channel].stream, JA_soundVolume[group]);
|
||||||
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
|
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
|
||||||
|
|
||||||
@@ -443,7 +572,7 @@ inline void JA_DeleteSound(JA_Sound_t* sound) {
|
|||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].sound == sound) JA_StopChannel(i);
|
if (channels[i].sound == sound) JA_StopChannel(i);
|
||||||
}
|
}
|
||||||
SDL_free(sound->buffer);
|
// buffer es destrueix automàticament via RAII (SDLFreeDeleter).
|
||||||
delete sound;
|
delete sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +618,7 @@ inline void JA_StopChannel(const int channel) {
|
|||||||
channels[i].stream = nullptr;
|
channels[i].stream = nullptr;
|
||||||
channels[i].state = JA_CHANNEL_FREE;
|
channels[i].state = JA_CHANNEL_FREE;
|
||||||
channels[i].pos = 0;
|
channels[i].pos = 0;
|
||||||
channels[i].sound = NULL;
|
channels[i].sound = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||||
@@ -498,7 +627,7 @@ inline void JA_StopChannel(const int channel) {
|
|||||||
channels[channel].stream = nullptr;
|
channels[channel].stream = nullptr;
|
||||||
channels[channel].state = JA_CHANNEL_FREE;
|
channels[channel].state = JA_CHANNEL_FREE;
|
||||||
channels[channel].pos = 0;
|
channels[channel].pos = 0;
|
||||||
channels[channel].sound = NULL;
|
channels[channel].sound = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,6 +652,7 @@ inline float JA_SetSoundVolume(float volume, const int group = -1) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aplicar volum als canals actius.
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if ((channels[i].state == JA_CHANNEL_PLAYING) || (channels[i].state == JA_CHANNEL_PAUSED)) {
|
if ((channels[i].state == JA_CHANNEL_PLAYING) || (channels[i].state == JA_CHANNEL_PAUSED)) {
|
||||||
if (group == -1 || channels[i].group == group) {
|
if (group == -1 || channels[i].group == group) {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class AnimatedSprite : public MovingSprite {
|
|||||||
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
|
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~AnimatedSprite();
|
~AnimatedSprite() override;
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación actual
|
// Calcula el frame correspondiente a la animación actual
|
||||||
void animate();
|
void animate();
|
||||||
@@ -86,7 +86,7 @@ class AnimatedSprite : public MovingSprite {
|
|||||||
void setCurrentAnimation(int index = 0);
|
void setCurrentAnimation(int index = 0);
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
void update() override;
|
||||||
|
|
||||||
// OLD - Establece el rectangulo para un frame de una animación
|
// OLD - Establece el rectangulo para un frame de una animación
|
||||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||||
|
|||||||
@@ -70,11 +70,13 @@ void MovingSprite::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
|
// cppcheck-suppress duplInheritedMember
|
||||||
float MovingSprite::getPosX() {
|
float MovingSprite::getPosX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
|
// cppcheck-suppress duplInheritedMember
|
||||||
float MovingSprite::getPosY() {
|
float MovingSprite::getPosY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ class Texture;
|
|||||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||||
class MovingSprite : public Sprite {
|
class MovingSprite : public Sprite {
|
||||||
protected:
|
protected:
|
||||||
float x; // Posición en el eje X
|
// cppcheck-suppress duplInheritedMember
|
||||||
float y; // Posición en el eje Y
|
float x; // Posición en el eje X (sub-pixel; Sprite::x es int)
|
||||||
|
// cppcheck-suppress duplInheritedMember
|
||||||
|
float y; // Posición en el eje Y (sub-pixel; Sprite::y es int)
|
||||||
|
|
||||||
float xPrev; // Posición anterior en el eje X
|
float xPrev; // Posición anterior en el eje X
|
||||||
float yPrev; // Posición anterior en el eje Y
|
float yPrev; // Posición anterior en el eje Y
|
||||||
@@ -42,18 +44,20 @@ class MovingSprite : public Sprite {
|
|||||||
void rotate();
|
void rotate();
|
||||||
|
|
||||||
// Actualiza las variables internas del objeto
|
// Actualiza las variables internas del objeto
|
||||||
void update();
|
virtual void update();
|
||||||
|
|
||||||
// Reinicia todas las variables
|
// Reinicia todas las variables
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void render();
|
void render() override;
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
|
// cppcheck-suppress duplInheritedMember
|
||||||
float getPosX();
|
float getPosX();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
|
// cppcheck-suppress duplInheritedMember
|
||||||
float getPosY();
|
float getPosY();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
@@ -84,7 +88,7 @@ class MovingSprite : public Sprite {
|
|||||||
Uint16 getRotateSpeed();
|
Uint16 getRotateSpeed();
|
||||||
|
|
||||||
// Establece la posición y el tamaño del objeto
|
// Establece la posición y el tamaño del objeto
|
||||||
void setRect(SDL_Rect rect);
|
void setRect(SDL_Rect rect) override;
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosX(float value);
|
void setPosX(float value);
|
||||||
@@ -144,7 +148,7 @@ class MovingSprite : public Sprite {
|
|||||||
SDL_FlipMode getFlip();
|
SDL_FlipMode getFlip();
|
||||||
|
|
||||||
// Devuelve el rectangulo donde está el sprite
|
// Devuelve el rectangulo donde está el sprite
|
||||||
SDL_Rect getRect();
|
SDL_Rect getRect() override;
|
||||||
|
|
||||||
// Deshace el último movimiento
|
// Deshace el último movimiento
|
||||||
void undoMove();
|
void undoMove();
|
||||||
|
|||||||
@@ -46,16 +46,6 @@ void SmartSprite::render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool SmartSprite::isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void SmartSprite::setEnabled(bool enabled) {
|
|
||||||
this->enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int SmartSprite::getEnabledCounter() {
|
int SmartSprite::getEnabledCounter() {
|
||||||
return enabledCounter;
|
return enabledCounter;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ class Texture;
|
|||||||
class SmartSprite : public AnimatedSprite {
|
class SmartSprite : public AnimatedSprite {
|
||||||
private:
|
private:
|
||||||
// Variables
|
// Variables
|
||||||
bool enabled; // Indica si esta habilitado
|
|
||||||
bool onDestination; // Indica si está en el destino
|
bool onDestination; // Indica si está en el destino
|
||||||
int destX; // Posicion de destino en el eje X
|
int destX; // Posicion de destino en el eje X
|
||||||
int destY; // Posicion de destino en el eje Y
|
int destY; // Posicion de destino en el eje Y
|
||||||
@@ -30,16 +29,10 @@ class SmartSprite : public AnimatedSprite {
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||||
void update();
|
void update() override;
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void render();
|
void render() override;
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool isEnabled();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setEnabled(bool enabled);
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getEnabledCounter();
|
int getEnabledCounter();
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ class Sprite {
|
|||||||
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
|
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Sprite();
|
virtual ~Sprite();
|
||||||
|
|
||||||
// Muestra el sprite por pantalla
|
// Muestra el sprite por pantalla
|
||||||
void render();
|
virtual void render();
|
||||||
|
|
||||||
// Obten el valor de la variable
|
// Obten el valor de la variable
|
||||||
int getPosX();
|
int getPosX();
|
||||||
@@ -77,14 +77,14 @@ class Sprite {
|
|||||||
void setRenderer(SDL_Renderer *renderer);
|
void setRenderer(SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setEnabled(bool value);
|
virtual void setEnabled(bool value);
|
||||||
|
|
||||||
// Comprueba si el objeto está habilitado
|
// Comprueba si el objeto está habilitado
|
||||||
bool isEnabled();
|
virtual bool isEnabled();
|
||||||
|
|
||||||
// Devuelve el rectangulo donde está el sprite
|
// Devuelve el rectangulo donde está el sprite
|
||||||
SDL_Rect getRect();
|
virtual SDL_Rect getRect();
|
||||||
|
|
||||||
// Establece los valores de posición y tamaño del sprite
|
// Establece los valores de posición y tamaño del sprite
|
||||||
void setRect(SDL_Rect rect);
|
virtual void setRect(SDL_Rect rect);
|
||||||
};
|
};
|
||||||
@@ -18,8 +18,7 @@ ResourcePack::~ResourcePack() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) {
|
uint32_t ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) {
|
||||||
return std::accumulate(data.begin(), data.end(), uint32_t(0x12345678),
|
return std::accumulate(data.begin(), data.end(), uint32_t(0x12345678), [](uint32_t acc, uint8_t b) { return ((acc << 5) + acc) + b; });
|
||||||
[](uint32_t acc, uint8_t b) { return ((acc << 5) + acc) + b; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
|
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
|
||||||
@@ -157,6 +156,7 @@ bool ResourcePack::addDirectory(const std::string& directory) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress useStlAlgorithm
|
||||||
for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) {
|
for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) {
|
||||||
if (entry.is_regular_file()) {
|
if (entry.is_regular_file()) {
|
||||||
std::string filepath = entry.path().string();
|
std::string filepath = entry.path().string();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <string> // for basic_string, operator+, char_t...
|
#include <string> // for basic_string, operator+, char_t...
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_Init
|
#include "core/audio/audio.hpp" // for Audio::init, Audio::destroy
|
||||||
#include "core/input/input.h" // for Input, inputs_e, INPUT_USE_GAME...
|
#include "core/input/input.h" // for Input, inputs_e, INPUT_USE_GAME...
|
||||||
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
|
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
|
||||||
#include "core/locale/lang.h" // for Lang, MAX_LANGUAGES, ba_BA, en_UK
|
#include "core/locale/lang.h" // for Lang, MAX_LANGUAGES, ba_BA, en_UK
|
||||||
@@ -173,6 +173,8 @@ Director::~Director() {
|
|||||||
Lang::destroy();
|
Lang::destroy();
|
||||||
delete section;
|
delete section;
|
||||||
|
|
||||||
|
Audio::destroy();
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
|
||||||
@@ -236,7 +238,7 @@ void Director::initInput() {
|
|||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
void Director::initJailAudio() {
|
void Director::initJailAudio() {
|
||||||
JA_Init(48000, SDL_AUDIO_S16, 2);
|
Audio::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arranca SDL y crea la ventana
|
// Arranca SDL y crea la ventana
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ class Director {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Director();
|
~Director();
|
||||||
|
|
||||||
|
Director(const Director &) = delete;
|
||||||
|
Director &operator=(const Director &) = delete;
|
||||||
|
|
||||||
// Ejecuta un frame del juego
|
// Ejecuta un frame del juego
|
||||||
SDL_AppResult iterate();
|
SDL_AppResult iterate();
|
||||||
|
|
||||||
|
|||||||
101
source/external/stb_vorbis.c
vendored
101
source/external/stb_vorbis.c
vendored
@@ -1,4 +1,4 @@
|
|||||||
// Ogg Vorbis audio decoder - v1.20 - public domain
|
// Ogg Vorbis audio decoder - v1.22 - public domain
|
||||||
// http://nothings.org/stb_vorbis/
|
// http://nothings.org/stb_vorbis/
|
||||||
//
|
//
|
||||||
// Original version written by Sean Barrett in 2007.
|
// Original version written by Sean Barrett in 2007.
|
||||||
@@ -29,12 +29,15 @@
|
|||||||
// Bernhard Wodo Evan Balster github:alxprd
|
// Bernhard Wodo Evan Balster github:alxprd
|
||||||
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
|
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
|
||||||
// Phillip Bennefall Rohit Thiago Goulart
|
// Phillip Bennefall Rohit Thiago Goulart
|
||||||
// github:manxorist saga musix github:infatum
|
// github:manxorist Saga Musix github:infatum
|
||||||
// Timur Gagiev Maxwell Koo Peter Waller
|
// Timur Gagiev Maxwell Koo Peter Waller
|
||||||
// github:audinowho Dougall Johnson David Reid
|
// github:audinowho Dougall Johnson David Reid
|
||||||
// github:Clownacy Pedro J. Estebanez Remi Verschelde
|
// github:Clownacy Pedro J. Estebanez Remi Verschelde
|
||||||
|
// AnthoFoxo github:morlat Gabriel Ravier
|
||||||
//
|
//
|
||||||
// Partial history:
|
// Partial history:
|
||||||
|
// 1.22 - 2021-07-11 - various small fixes
|
||||||
|
// 1.21 - 2021-07-02 - fix bug for files with no comments
|
||||||
// 1.20 - 2020-07-11 - several small fixes
|
// 1.20 - 2020-07-11 - several small fixes
|
||||||
// 1.19 - 2020-02-05 - warnings
|
// 1.19 - 2020-02-05 - warnings
|
||||||
// 1.18 - 2020-02-02 - fix seek bugs; parse header comments; misc warnings etc.
|
// 1.18 - 2020-02-02 - fix seek bugs; parse header comments; misc warnings etc.
|
||||||
@@ -220,6 +223,12 @@ extern int stb_vorbis_decode_frame_pushdata(
|
|||||||
// channel. In other words, (*output)[0][0] contains the first sample from
|
// channel. In other words, (*output)[0][0] contains the first sample from
|
||||||
// the first channel, and (*output)[1][0] contains the first sample from
|
// the first channel, and (*output)[1][0] contains the first sample from
|
||||||
// the second channel.
|
// the second channel.
|
||||||
|
//
|
||||||
|
// *output points into stb_vorbis's internal output buffer storage; these
|
||||||
|
// buffers are owned by stb_vorbis and application code should not free
|
||||||
|
// them or modify their contents. They are transient and will be overwritten
|
||||||
|
// once you ask for more data to get decoded, so be sure to grab any data
|
||||||
|
// you need before then.
|
||||||
|
|
||||||
extern void stb_vorbis_flush_pushdata(stb_vorbis *f);
|
extern void stb_vorbis_flush_pushdata(stb_vorbis *f);
|
||||||
// inform stb_vorbis that your next datablock will not be contiguous with
|
// inform stb_vorbis that your next datablock will not be contiguous with
|
||||||
@@ -579,7 +588,7 @@ enum STBVorbisError
|
|||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
|
#if defined(__linux__) || defined(__linux) || defined(__sun__) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
#endif
|
#endif
|
||||||
#else // STB_VORBIS_NO_CRT
|
#else // STB_VORBIS_NO_CRT
|
||||||
@@ -646,6 +655,12 @@ typedef signed int int32;
|
|||||||
|
|
||||||
typedef float codetype;
|
typedef float codetype;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define STBV_NOTUSED(v) (void)(v)
|
||||||
|
#else
|
||||||
|
#define STBV_NOTUSED(v) (void)sizeof(v)
|
||||||
|
#endif
|
||||||
|
|
||||||
// @NOTE
|
// @NOTE
|
||||||
//
|
//
|
||||||
// Some arrays below are tagged "//varies", which means it's actually
|
// Some arrays below are tagged "//varies", which means it's actually
|
||||||
@@ -1046,7 +1061,7 @@ static float float32_unpack(uint32 x)
|
|||||||
uint32 sign = x & 0x80000000;
|
uint32 sign = x & 0x80000000;
|
||||||
uint32 exp = (x & 0x7fe00000) >> 21;
|
uint32 exp = (x & 0x7fe00000) >> 21;
|
||||||
double res = sign ? -(double)mantissa : (double)mantissa;
|
double res = sign ? -(double)mantissa : (double)mantissa;
|
||||||
return (float) ldexp((float)res, exp-788);
|
return (float) ldexp((float)res, (int)exp-788);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1077,6 +1092,7 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|||||||
// find the first entry
|
// find the first entry
|
||||||
for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
|
for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
|
||||||
if (k == n) { assert(c->sorted_entries == 0); return TRUE; }
|
if (k == n) { assert(c->sorted_entries == 0); return TRUE; }
|
||||||
|
assert(len[k] < 32); // no error return required, code reading lens checks this
|
||||||
// add to the list
|
// add to the list
|
||||||
add_entry(c, 0, k, m++, len[k], values);
|
add_entry(c, 0, k, m++, len[k], values);
|
||||||
// add all available leaves
|
// add all available leaves
|
||||||
@@ -1090,6 +1106,7 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|||||||
uint32 res;
|
uint32 res;
|
||||||
int z = len[i], y;
|
int z = len[i], y;
|
||||||
if (z == NO_CODE) continue;
|
if (z == NO_CODE) continue;
|
||||||
|
assert(z < 32); // no error return required, code reading lens checks this
|
||||||
// find lowest available leaf (should always be earliest,
|
// find lowest available leaf (should always be earliest,
|
||||||
// which is what the specification calls for)
|
// which is what the specification calls for)
|
||||||
// note that this property, and the fact we can never have
|
// note that this property, and the fact we can never have
|
||||||
@@ -1099,12 +1116,10 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|||||||
while (z > 0 && !available[z]) --z;
|
while (z > 0 && !available[z]) --z;
|
||||||
if (z == 0) { return FALSE; }
|
if (z == 0) { return FALSE; }
|
||||||
res = available[z];
|
res = available[z];
|
||||||
assert(z >= 0 && z < 32);
|
|
||||||
available[z] = 0;
|
available[z] = 0;
|
||||||
add_entry(c, bit_reverse(res), i, m++, len[i], values);
|
add_entry(c, bit_reverse(res), i, m++, len[i], values);
|
||||||
// propagate availability up the tree
|
// propagate availability up the tree
|
||||||
if (z != len[i]) {
|
if (z != len[i]) {
|
||||||
assert(len[i] >= 0 && len[i] < 32);
|
|
||||||
for (y=len[i]; y > z; --y) {
|
for (y=len[i]; y > z; --y) {
|
||||||
assert(available[y] == 0);
|
assert(available[y] == 0);
|
||||||
available[y] = res + (1 << (32-y));
|
available[y] = res + (1 << (32-y));
|
||||||
@@ -2577,34 +2592,33 @@ static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A,
|
|||||||
|
|
||||||
while (z > base) {
|
while (z > base) {
|
||||||
float k00,k11;
|
float k00,k11;
|
||||||
|
float l00,l11;
|
||||||
|
|
||||||
k00 = z[-0] - z[ -8];
|
k00 = z[-0] - z[ -8];
|
||||||
k11 = z[-1] - z[ -9];
|
k11 = z[-1] - z[ -9];
|
||||||
|
l00 = z[-2] - z[-10];
|
||||||
|
l11 = z[-3] - z[-11];
|
||||||
z[ -0] = z[-0] + z[ -8];
|
z[ -0] = z[-0] + z[ -8];
|
||||||
z[ -1] = z[-1] + z[ -9];
|
z[ -1] = z[-1] + z[ -9];
|
||||||
z[-8] = k00;
|
|
||||||
z[-9] = k11 ;
|
|
||||||
|
|
||||||
k00 = z[ -2] - z[-10];
|
|
||||||
k11 = z[ -3] - z[-11];
|
|
||||||
z[ -2] = z[-2] + z[-10];
|
z[ -2] = z[-2] + z[-10];
|
||||||
z[ -3] = z[-3] + z[-11];
|
z[ -3] = z[-3] + z[-11];
|
||||||
z[-10] = (k00+k11) * A2;
|
z[ -8] = k00;
|
||||||
z[-11] = (k11-k00) * A2;
|
z[ -9] = k11;
|
||||||
|
z[-10] = (l00+l11) * A2;
|
||||||
|
z[-11] = (l11-l00) * A2;
|
||||||
|
|
||||||
k00 = z[-12] - z[ -4]; // reverse to avoid a unary negation
|
k00 = z[ -4] - z[-12];
|
||||||
k11 = z[ -5] - z[-13];
|
k11 = z[ -5] - z[-13];
|
||||||
|
l00 = z[ -6] - z[-14];
|
||||||
|
l11 = z[ -7] - z[-15];
|
||||||
z[ -4] = z[ -4] + z[-12];
|
z[ -4] = z[ -4] + z[-12];
|
||||||
z[ -5] = z[ -5] + z[-13];
|
z[ -5] = z[ -5] + z[-13];
|
||||||
z[-12] = k11;
|
|
||||||
z[-13] = k00;
|
|
||||||
|
|
||||||
k00 = z[-14] - z[ -6]; // reverse to avoid a unary negation
|
|
||||||
k11 = z[ -7] - z[-15];
|
|
||||||
z[ -6] = z[ -6] + z[-14];
|
z[ -6] = z[ -6] + z[-14];
|
||||||
z[ -7] = z[ -7] + z[-15];
|
z[ -7] = z[ -7] + z[-15];
|
||||||
z[-14] = (k00+k11) * A2;
|
z[-12] = k11;
|
||||||
z[-15] = (k00-k11) * A2;
|
z[-13] = -k00;
|
||||||
|
z[-14] = (l11-l00) * A2;
|
||||||
|
z[-15] = (l00+l11) * -A2;
|
||||||
|
|
||||||
iter_54(z);
|
iter_54(z);
|
||||||
iter_54(z-8);
|
iter_54(z-8);
|
||||||
@@ -3069,6 +3083,7 @@ static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *f
|
|||||||
for (q=1; q < g->values; ++q) {
|
for (q=1; q < g->values; ++q) {
|
||||||
j = g->sorted_order[q];
|
j = g->sorted_order[q];
|
||||||
#ifndef STB_VORBIS_NO_DEFER_FLOOR
|
#ifndef STB_VORBIS_NO_DEFER_FLOOR
|
||||||
|
STBV_NOTUSED(step2_flag);
|
||||||
if (finalY[j] >= 0)
|
if (finalY[j] >= 0)
|
||||||
#else
|
#else
|
||||||
if (step2_flag[j])
|
if (step2_flag[j])
|
||||||
@@ -3171,6 +3186,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|||||||
|
|
||||||
// WINDOWING
|
// WINDOWING
|
||||||
|
|
||||||
|
STBV_NOTUSED(left_end);
|
||||||
n = f->blocksize[m->blockflag];
|
n = f->blocksize[m->blockflag];
|
||||||
map = &f->mapping[m->mapping];
|
map = &f->mapping[m->mapping];
|
||||||
|
|
||||||
@@ -3368,7 +3384,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|||||||
// this isn't to spec, but spec would require us to read ahead
|
// this isn't to spec, but spec would require us to read ahead
|
||||||
// and decode the size of all current frames--could be done,
|
// and decode the size of all current frames--could be done,
|
||||||
// but presumably it's not a commonly used feature
|
// but presumably it's not a commonly used feature
|
||||||
f->current_loc = -n2; // start of first frame is positioned for discard
|
f->current_loc = 0u - n2; // start of first frame is positioned for discard (NB this is an intentional unsigned overflow/wrap-around)
|
||||||
// we might have to discard samples "from" the next frame too,
|
// we might have to discard samples "from" the next frame too,
|
||||||
// if we're lapping a large block then a small at the start?
|
// if we're lapping a large block then a small at the start?
|
||||||
f->discard_samples_deferred = n - right_end;
|
f->discard_samples_deferred = n - right_end;
|
||||||
@@ -3642,7 +3658,9 @@ static int start_decoder(vorb *f)
|
|||||||
f->vendor[len] = (char)'\0';
|
f->vendor[len] = (char)'\0';
|
||||||
//user comments
|
//user comments
|
||||||
f->comment_list_length = get32_packet(f);
|
f->comment_list_length = get32_packet(f);
|
||||||
if (f->comment_list_length > 0) {
|
f->comment_list = NULL;
|
||||||
|
if (f->comment_list_length > 0)
|
||||||
|
{
|
||||||
f->comment_list = (char**) setup_malloc(f, sizeof(char*) * (f->comment_list_length));
|
f->comment_list = (char**) setup_malloc(f, sizeof(char*) * (f->comment_list_length));
|
||||||
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
|
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
|
||||||
}
|
}
|
||||||
@@ -3867,8 +3885,7 @@ static int start_decoder(vorb *f)
|
|||||||
unsigned int div=1;
|
unsigned int div=1;
|
||||||
for (k=0; k < c->dimensions; ++k) {
|
for (k=0; k < c->dimensions; ++k) {
|
||||||
int off = (z / div) % c->lookup_values;
|
int off = (z / div) % c->lookup_values;
|
||||||
float val = mults[off];
|
float val = mults[off]*c->delta_value + c->minimum_value + last;
|
||||||
val = mults[off]*c->delta_value + c->minimum_value + last;
|
|
||||||
c->multiplicands[j*c->dimensions + k] = val;
|
c->multiplicands[j*c->dimensions + k] = val;
|
||||||
if (c->sequence_p)
|
if (c->sequence_p)
|
||||||
last = val;
|
last = val;
|
||||||
@@ -3951,7 +3968,7 @@ static int start_decoder(vorb *f)
|
|||||||
if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
||||||
}
|
}
|
||||||
for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
|
for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
|
||||||
g->subclass_books[j][k] = get_bits(f,8)-1;
|
g->subclass_books[j][k] = (int16)get_bits(f,8)-1;
|
||||||
if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4509,6 +4526,7 @@ stb_vorbis *stb_vorbis_open_pushdata(
|
|||||||
*error = VORBIS_need_more_data;
|
*error = VORBIS_need_more_data;
|
||||||
else
|
else
|
||||||
*error = p.error;
|
*error = p.error;
|
||||||
|
vorbis_deinit(&p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
f = vorbis_alloc(&p);
|
f = vorbis_alloc(&p);
|
||||||
@@ -4566,7 +4584,7 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
|
|||||||
header[i] = get8(f);
|
header[i] = get8(f);
|
||||||
if (f->eof) return 0;
|
if (f->eof) return 0;
|
||||||
if (header[4] != 0) goto invalid;
|
if (header[4] != 0) goto invalid;
|
||||||
goal = header[22] + (header[23] << 8) + (header[24]<<16) + (header[25]<<24);
|
goal = header[22] + (header[23] << 8) + (header[24]<<16) + ((uint32)header[25]<<24);
|
||||||
for (i=22; i < 26; ++i)
|
for (i=22; i < 26; ++i)
|
||||||
header[i] = 0;
|
header[i] = 0;
|
||||||
crc = 0;
|
crc = 0;
|
||||||
@@ -4970,7 +4988,7 @@ unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
|
|||||||
// set. whoops!
|
// set. whoops!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
previous_safe = last_page_loc+1;
|
//previous_safe = last_page_loc+1; // NOTE: not used after this point, but note for debugging
|
||||||
last_page_loc = stb_vorbis_get_file_offset(f);
|
last_page_loc = stb_vorbis_get_file_offset(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5081,7 +5099,10 @@ stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const st
|
|||||||
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
|
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
|
||||||
{
|
{
|
||||||
stb_vorbis *f, p;
|
stb_vorbis *f, p;
|
||||||
if (data == NULL) return NULL;
|
if (!data) {
|
||||||
|
if (error) *error = VORBIS_unexpected_eof;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
vorbis_init(&p, alloc);
|
vorbis_init(&p, alloc);
|
||||||
p.stream = (uint8 *) data;
|
p.stream = (uint8 *) data;
|
||||||
p.stream_end = (uint8 *) data + len;
|
p.stream_end = (uint8 *) data + len;
|
||||||
@@ -5156,11 +5177,11 @@ static void copy_samples(short *dest, float *src, int len)
|
|||||||
|
|
||||||
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
|
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
|
||||||
{
|
{
|
||||||
#define BUFFER_SIZE 32
|
#define STB_BUFFER_SIZE 32
|
||||||
float buffer[BUFFER_SIZE];
|
float buffer[STB_BUFFER_SIZE];
|
||||||
int i,j,o,n = BUFFER_SIZE;
|
int i,j,o,n = STB_BUFFER_SIZE;
|
||||||
check_endianness();
|
check_endianness();
|
||||||
for (o = 0; o < len; o += BUFFER_SIZE) {
|
for (o = 0; o < len; o += STB_BUFFER_SIZE) {
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
if (o + n > len) n = len - o;
|
if (o + n > len) n = len - o;
|
||||||
for (j=0; j < num_c; ++j) {
|
for (j=0; j < num_c; ++j) {
|
||||||
@@ -5177,16 +5198,17 @@ static void compute_samples(int mask, short *output, int num_c, float **data, in
|
|||||||
output[o+i] = v;
|
output[o+i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#undef STB_BUFFER_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
|
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
|
||||||
{
|
{
|
||||||
#define BUFFER_SIZE 32
|
#define STB_BUFFER_SIZE 32
|
||||||
float buffer[BUFFER_SIZE];
|
float buffer[STB_BUFFER_SIZE];
|
||||||
int i,j,o,n = BUFFER_SIZE >> 1;
|
int i,j,o,n = STB_BUFFER_SIZE >> 1;
|
||||||
// o is the offset in the source data
|
// o is the offset in the source data
|
||||||
check_endianness();
|
check_endianness();
|
||||||
for (o = 0; o < len; o += BUFFER_SIZE >> 1) {
|
for (o = 0; o < len; o += STB_BUFFER_SIZE >> 1) {
|
||||||
// o2 is the offset in the output data
|
// o2 is the offset in the output data
|
||||||
int o2 = o << 1;
|
int o2 = o << 1;
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
@@ -5216,6 +5238,7 @@ static void compute_stereo_samples(short *output, int num_c, float **data, int d
|
|||||||
output[o2+i] = v;
|
output[o2+i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#undef STB_BUFFER_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
|
static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
|
||||||
@@ -5288,8 +5311,6 @@ int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short
|
|||||||
float **outputs;
|
float **outputs;
|
||||||
int len = num_shorts / channels;
|
int len = num_shorts / channels;
|
||||||
int n=0;
|
int n=0;
|
||||||
int z = f->channels;
|
|
||||||
if (z > channels) z = channels;
|
|
||||||
while (n < len) {
|
while (n < len) {
|
||||||
int k = f->channel_buffer_end - f->channel_buffer_start;
|
int k = f->channel_buffer_end - f->channel_buffer_start;
|
||||||
if (n+k >= len) k = len - n;
|
if (n+k >= len) k = len - n;
|
||||||
@@ -5308,8 +5329,6 @@ int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, in
|
|||||||
{
|
{
|
||||||
float **outputs;
|
float **outputs;
|
||||||
int n=0;
|
int n=0;
|
||||||
int z = f->channels;
|
|
||||||
if (z > channels) z = channels;
|
|
||||||
while (n < len) {
|
while (n < len) {
|
||||||
int k = f->channel_buffer_end - f->channel_buffer_start;
|
int k = f->channel_buffer_end - f->channel_buffer_start;
|
||||||
if (n+k >= len) k = len - n;
|
if (n+k >= len) k = len - n;
|
||||||
|
|||||||
@@ -30,17 +30,17 @@ namespace Defaults::Video {
|
|||||||
|
|
||||||
namespace Defaults::Audio {
|
namespace Defaults::Audio {
|
||||||
constexpr bool ENABLED = true;
|
constexpr bool ENABLED = true;
|
||||||
constexpr int VOLUME = 100;
|
constexpr float VOLUME = 1.0F;
|
||||||
} // namespace Defaults::Audio
|
} // namespace Defaults::Audio
|
||||||
|
|
||||||
namespace Defaults::Music {
|
namespace Defaults::Music {
|
||||||
constexpr bool ENABLED = true;
|
constexpr bool ENABLED = true;
|
||||||
constexpr int VOLUME = 100;
|
constexpr float VOLUME = 0.8F;
|
||||||
} // namespace Defaults::Music
|
} // namespace Defaults::Music
|
||||||
|
|
||||||
namespace Defaults::Sound {
|
namespace Defaults::Sound {
|
||||||
constexpr bool ENABLED = true;
|
constexpr bool ENABLED = true;
|
||||||
constexpr int VOLUME = 100;
|
constexpr float VOLUME = 1.0F;
|
||||||
} // namespace Defaults::Sound
|
} // namespace Defaults::Sound
|
||||||
|
|
||||||
namespace Defaults::Loading {
|
namespace Defaults::Loading {
|
||||||
|
|||||||
@@ -146,6 +146,9 @@ class Balloon {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Balloon();
|
~Balloon();
|
||||||
|
|
||||||
|
Balloon(const Balloon &) = delete;
|
||||||
|
Balloon &operator=(const Balloon &) = delete;
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ class Bullet {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Bullet();
|
~Bullet();
|
||||||
|
|
||||||
|
Bullet(const Bullet &) = delete;
|
||||||
|
Bullet &operator=(const Bullet &) = delete;
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ class Item {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Item();
|
~Item();
|
||||||
|
|
||||||
|
Item(const Item &) = delete;
|
||||||
|
Item &operator=(const Item &) = delete;
|
||||||
|
|
||||||
// Centra el objeto en la posición X
|
// Centra el objeto en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ class Player {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Player();
|
~Player();
|
||||||
|
|
||||||
|
Player(const Player &) = delete;
|
||||||
|
Player &operator=(const Player &) = delete;
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
|
|
||||||
#include <algorithm> // for max, min
|
#include <algorithm> // for max, min
|
||||||
#include <numeric> // for accumulate
|
|
||||||
#include <fstream> // for basic_ifstream
|
#include <fstream> // for basic_ifstream
|
||||||
#include <iostream> // for basic_ostream, char_traits, operator<<
|
#include <iostream> // for basic_ostream, char_traits, operator<<
|
||||||
|
#include <numeric> // for accumulate
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_PlaySound, JA_DeleteSound, JA_LoadSound
|
#include "core/audio/audio.hpp" // for Audio
|
||||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||||
#include "core/input/input.h" // for inputs_e, Input, REPEAT_TRUE, REPEAT_FALSE
|
#include "core/input/input.h" // for inputs_e, Input, REPEAT_TRUE, REPEAT_FALSE
|
||||||
#include "core/locale/lang.h" // for Lang
|
#include "core/locale/lang.h" // for Lang
|
||||||
@@ -1307,7 +1307,7 @@ void Game::updateHiScore() {
|
|||||||
// Si se supera la máxima puntuación emite sonido
|
// Si se supera la máxima puntuación emite sonido
|
||||||
if (hiScoreAchieved == false) {
|
if (hiScoreAchieved == false) {
|
||||||
hiScoreAchieved = true;
|
hiScoreAchieved = true;
|
||||||
JA_PlaySound(hiScoreSound);
|
Audio::get()->playSound(hiScoreSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1459,9 +1459,9 @@ void Game::updateStage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
JA_PlaySound(stageChangeSound);
|
Audio::get()->playSound(stageChangeSound);
|
||||||
stageBitmapCounter = 0;
|
stageBitmapCounter = 0;
|
||||||
enemySpeed = defaultEnemySpeed;
|
enemySpeed = defaultEnemySpeed;
|
||||||
setBalloonSpeed(enemySpeed);
|
setBalloonSpeed(enemySpeed);
|
||||||
@@ -1499,7 +1499,7 @@ void Game::updateDeath() {
|
|||||||
if (!demo.enabled) {
|
if (!demo.enabled) {
|
||||||
const Uint8 index = rand() % 4;
|
const Uint8 index = rand() % 4;
|
||||||
JA_Sound_t *sound[4] = {bubble1Sound, bubble2Sound, bubble3Sound, bubble4Sound};
|
JA_Sound_t *sound[4] = {bubble1Sound, bubble2Sound, bubble3Sound, bubble4Sound};
|
||||||
JA_PlaySound(sound[index], 0);
|
Audio::get()->playSound(sound[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1746,7 +1746,7 @@ void Game::destroyAllBalloons() {
|
|||||||
|
|
||||||
enemyDeployCounter = 255;
|
enemyDeployCounter = 255;
|
||||||
if (!demo.enabled) {
|
if (!demo.enabled) {
|
||||||
JA_PlaySound(powerBallSound);
|
Audio::get()->playSound(powerBallSound);
|
||||||
}
|
}
|
||||||
effect.flash = true;
|
effect.flash = true;
|
||||||
effect.shake = true;
|
effect.shake = true;
|
||||||
@@ -1811,26 +1811,26 @@ void Game::checkPlayerItemCollision(Player *player) {
|
|||||||
player->addScore(1000);
|
player->addScore(1000);
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n1000Sprite->getWidth() / 2), player->getPosY(), n1000Sprite);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n1000Sprite->getWidth() / 2), player->getPosY(), n1000Sprite);
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_2_GAVINA:
|
case ITEM_POINTS_2_GAVINA:
|
||||||
player->addScore(2500);
|
player->addScore(2500);
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n2500Sprite->getWidth() / 2), player->getPosY(), n2500Sprite);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n2500Sprite->getWidth() / 2), player->getPosY(), n2500Sprite);
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_POINTS_3_PACMAR:
|
case ITEM_POINTS_3_PACMAR:
|
||||||
player->addScore(5000);
|
player->addScore(5000);
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_CLOCK:
|
case ITEM_CLOCK:
|
||||||
enableTimeStopItem();
|
enableTimeStopItem();
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_COFFEE:
|
case ITEM_COFFEE:
|
||||||
@@ -1840,12 +1840,12 @@ void Game::checkPlayerItemCollision(Player *player) {
|
|||||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
|
||||||
}
|
}
|
||||||
player->giveExtraHit();
|
player->giveExtraHit();
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_COFFEE_MACHINE:
|
case ITEM_COFFEE_MACHINE:
|
||||||
player->setPowerUp(true);
|
player->setPowerUp(true);
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
coffeeMachineEnabled = false;
|
coffeeMachineEnabled = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1876,7 +1876,7 @@ void Game::checkBulletBalloonCollision() {
|
|||||||
|
|
||||||
// Si no es el modo demo, genera un sonido
|
// Si no es el modo demo, genera un sonido
|
||||||
if (!demo.enabled) {
|
if (!demo.enabled) {
|
||||||
JA_PlaySound(balloonSound);
|
Audio::get()->playSound(balloonSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilita la bala
|
// Deshabilita la bala
|
||||||
@@ -1887,7 +1887,7 @@ void Game::checkBulletBalloonCollision() {
|
|||||||
if ((droppeditem != NO_KIND) && !(demo.enabled) && !(demo.recording)) {
|
if ((droppeditem != NO_KIND) && !(demo.enabled) && !(demo.recording)) {
|
||||||
if (droppeditem != ITEM_COFFEE_MACHINE) {
|
if (droppeditem != ITEM_COFFEE_MACHINE) {
|
||||||
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
|
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
|
||||||
JA_PlaySound(itemDropSound);
|
Audio::get()->playSound(itemDropSound);
|
||||||
} else {
|
} else {
|
||||||
createItem(droppeditem, players[index]->getPosX(), 0);
|
createItem(droppeditem, players[index]->getPosX(), 0);
|
||||||
coffeeMachineEnabled = true;
|
coffeeMachineEnabled = true;
|
||||||
@@ -1945,7 +1945,7 @@ void Game::updateItems() {
|
|||||||
if (item->isEnabled()) {
|
if (item->isEnabled()) {
|
||||||
item->update();
|
item->update();
|
||||||
if (item->isOnFloor()) {
|
if (item->isOnFloor()) {
|
||||||
JA_PlaySound(coffeeMachineSound);
|
Audio::get()->playSound(coffeeMachineSound);
|
||||||
effect.shake = true;
|
effect.shake = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2132,12 +2132,12 @@ void Game::killPlayer(Player *player) {
|
|||||||
player->removeExtraHit();
|
player->removeExtraHit();
|
||||||
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
||||||
if (!demo.enabled) {
|
if (!demo.enabled) {
|
||||||
JA_PlaySound(coffeeOutSound);
|
Audio::get()->playSound(coffeeOutSound);
|
||||||
}
|
}
|
||||||
} else if (deathSequence.phase == DeathPhase::None) {
|
} else if (deathSequence.phase == DeathPhase::None) {
|
||||||
if (!demo.enabled) {
|
if (!demo.enabled) {
|
||||||
JA_PauseMusic();
|
Audio::get()->pauseMusic();
|
||||||
JA_PlaySound(playerCollisionSound);
|
Audio::get()->playSound(playerCollisionSound);
|
||||||
}
|
}
|
||||||
stopAllBalloons(10);
|
stopAllBalloons(10);
|
||||||
shakeScreen();
|
shakeScreen();
|
||||||
@@ -2167,11 +2167,11 @@ void Game::updateDeathSequence() {
|
|||||||
// Espera 500ms antes de completar la muerte
|
// Espera 500ms antes de completar la muerte
|
||||||
if (SDL_GetTicks() - deathSequence.phaseStartTicks >= 500) {
|
if (SDL_GetTicks() - deathSequence.phaseStartTicks >= 500) {
|
||||||
if (!demo.enabled) {
|
if (!demo.enabled) {
|
||||||
JA_PlaySound(coffeeOutSound);
|
Audio::get()->playSound(coffeeOutSound);
|
||||||
if (allPlayersAreDead()) {
|
if (allPlayersAreDead()) {
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
} else {
|
} else {
|
||||||
JA_ResumeMusic();
|
Audio::get()->resumeMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deathSequence.player->setAlive(false);
|
deathSequence.player->setAlive(false);
|
||||||
@@ -2184,8 +2184,7 @@ void Game::updateDeathSequence() {
|
|||||||
|
|
||||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||||
void Game::evaluateAndSetMenace() {
|
void Game::evaluateAndSetMenace() {
|
||||||
menaceCurrent = std::accumulate(balloons.begin(), balloons.end(), Uint8(0),
|
menaceCurrent = std::accumulate(balloons.begin(), balloons.end(), Uint8(0), [](Uint8 acc, Balloon *b) { return b->isEnabled() ? acc + b->getMenace() : acc; });
|
||||||
[](Uint8 acc, Balloon *b) { return b->isEnabled() ? acc + b->getMenace() : acc; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
@@ -2235,7 +2234,7 @@ void Game::updateEnemyDeployCounter() {
|
|||||||
// Actualiza el juego
|
// Actualiza el juego
|
||||||
void Game::update() {
|
void Game::update() {
|
||||||
// Actualiza el audio
|
// Actualiza el audio
|
||||||
JA_Update();
|
Audio::update();
|
||||||
|
|
||||||
// Actualiza los efectos basados en tiempo real (no en el throttle del juego)
|
// Actualiza los efectos basados en tiempo real (no en el throttle del juego)
|
||||||
updateDeathShake();
|
updateDeathShake();
|
||||||
@@ -2542,7 +2541,7 @@ void Game::checkGameInput() {
|
|||||||
player->setFireCooldown(10);
|
player->setFireCooldown(10);
|
||||||
|
|
||||||
// Reproduce el sonido de disparo
|
// Reproduce el sonido de disparo
|
||||||
JA_PlaySound(bulletSound);
|
Audio::get()->playSound(bulletSound);
|
||||||
|
|
||||||
demo.keys.fire = 1;
|
demo.keys.fire = 1;
|
||||||
}
|
}
|
||||||
@@ -2556,7 +2555,7 @@ void Game::checkGameInput() {
|
|||||||
player->setFireCooldown(10);
|
player->setFireCooldown(10);
|
||||||
|
|
||||||
// Reproduce el sonido de disparo
|
// Reproduce el sonido de disparo
|
||||||
JA_PlaySound(bulletSound);
|
Audio::get()->playSound(bulletSound);
|
||||||
|
|
||||||
demo.keys.fireLeft = 1;
|
demo.keys.fireLeft = 1;
|
||||||
}
|
}
|
||||||
@@ -2570,7 +2569,7 @@ void Game::checkGameInput() {
|
|||||||
player->setFireCooldown(10);
|
player->setFireCooldown(10);
|
||||||
|
|
||||||
// Reproduce el sonido de disparo
|
// Reproduce el sonido de disparo
|
||||||
JA_PlaySound(bulletSound);
|
Audio::get()->playSound(bulletSound);
|
||||||
|
|
||||||
demo.keys.fireRight = 1;
|
demo.keys.fireRight = 1;
|
||||||
}
|
}
|
||||||
@@ -2611,11 +2610,11 @@ void Game::renderMessages() {
|
|||||||
|
|
||||||
if (timeStoppedCounter > 100) {
|
if (timeStoppedCounter > 100) {
|
||||||
if (timeStoppedCounter % 30 == 0) {
|
if (timeStoppedCounter % 30 == 0) {
|
||||||
JA_PlaySound(clockSound, false);
|
Audio::get()->playSound(clockSound);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (timeStoppedCounter % 15 == 0) {
|
if (timeStoppedCounter % 15 == 0) {
|
||||||
JA_PlaySound(clockSound, false);
|
Audio::get()->playSound(clockSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2653,8 +2652,8 @@ void Game::enableTimeStopItem() {
|
|||||||
stopAllBalloons(TIME_STOPPED_COUNTER);
|
stopAllBalloons(TIME_STOPPED_COUNTER);
|
||||||
setTimeStopped(true);
|
setTimeStopped(true);
|
||||||
incTimeStoppedCounter(TIME_STOPPED_COUNTER);
|
incTimeStoppedCounter(TIME_STOPPED_COUNTER);
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING) {
|
if (Audio::getRealMusicState() == Audio::MusicState::PLAYING) {
|
||||||
JA_PauseMusic();
|
Audio::get()->pauseMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2663,8 +2662,8 @@ void Game::disableTimeStopItem() {
|
|||||||
timeStopped = false;
|
timeStopped = false;
|
||||||
setTimeStoppedCounter(0);
|
setTimeStoppedCounter(0);
|
||||||
startAllBalloons();
|
startAllBalloons();
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PAUSED) {
|
if (Audio::getRealMusicState() == Audio::MusicState::PAUSED) {
|
||||||
JA_ResumeMusic();
|
Audio::get()->resumeMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2730,11 +2729,11 @@ void Game::iterate() {
|
|||||||
gameOverInitialized = false;
|
gameOverInitialized = false;
|
||||||
|
|
||||||
// Si la música no está sonando
|
// Si la música no está sonando
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) {
|
if ((Audio::getRealMusicState() == Audio::MusicState::STOPPED) || (Audio::getRealMusicState() == Audio::MusicState::STOPPED)) {
|
||||||
// Reproduce la música (nunca en modo demo: deja sonar la del título)
|
// Reproduce la música (nunca en modo demo: deja sonar la del título)
|
||||||
if (!gameCompleted && !demo.enabled) {
|
if (!gameCompleted && !demo.enabled) {
|
||||||
if (players[0]->isAlive()) {
|
if (players[0]->isAlive()) {
|
||||||
JA_PlayMusic(gameMusic);
|
Audio::get()->playMusic(gameMusic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2782,7 +2781,7 @@ void Game::handleEvent(const SDL_Event *event) {
|
|||||||
if (gameCompleted) {
|
if (gameCompleted) {
|
||||||
gameOverPostFade = 1;
|
gameOverPostFade = 1;
|
||||||
fade->activateFade();
|
fade->activateFade();
|
||||||
JA_PlaySound(itemPickUpSound);
|
Audio::get()->playSound(itemPickUpSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2811,15 +2810,15 @@ void Game::updatePausedGame() {
|
|||||||
const bool b = pauseCounter == 60;
|
const bool b = pauseCounter == 60;
|
||||||
const bool c = pauseCounter == 30;
|
const bool c = pauseCounter == 30;
|
||||||
if (a || b || c) {
|
if (a || b || c) {
|
||||||
JA_PlaySound(clockSound);
|
Audio::get()->playSound(clockSound);
|
||||||
}
|
}
|
||||||
pauseCounter--;
|
pauseCounter--;
|
||||||
} else { // Ha finalizado el contador
|
} else { // Ha finalizado el contador
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
|
section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
|
||||||
|
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PAUSED) {
|
if (Audio::getRealMusicState() == Audio::MusicState::PAUSED) {
|
||||||
JA_ResumeMusic();
|
Audio::get()->resumeMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // Actualiza la lógica del menu de pausa
|
} else { // Actualiza la lógica del menu de pausa
|
||||||
@@ -2848,7 +2847,7 @@ void Game::updatePausedGame() {
|
|||||||
if (fade->hasEnded()) {
|
if (fade->hasEnded()) {
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2898,8 +2897,8 @@ void Game::renderPausedGame() {
|
|||||||
// Inicializa el estado de pausa del juego
|
// Inicializa el estado de pausa del juego
|
||||||
void Game::enterPausedGame() {
|
void Game::enterPausedGame() {
|
||||||
// Pone en pausa la música
|
// Pone en pausa la música
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING) {
|
if (Audio::getRealMusicState() == Audio::MusicState::PLAYING) {
|
||||||
JA_PauseMusic();
|
Audio::get()->pauseMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reinicia el menu
|
// Reinicia el menu
|
||||||
@@ -3048,8 +3047,7 @@ bool Game::canPowerBallBeCreated() {
|
|||||||
|
|
||||||
// Calcula el poder actual de los globos en pantalla
|
// Calcula el poder actual de los globos en pantalla
|
||||||
int Game::calculateScreenPower() {
|
int Game::calculateScreenPower() {
|
||||||
return std::accumulate(balloons.begin(), balloons.end(), 0,
|
return std::accumulate(balloons.begin(), balloons.end(), 0, [](int acc, Balloon *b) { return b->isEnabled() ? acc + b->getPower() : acc; });
|
||||||
[](int acc, Balloon *b) { return b->isEnabled() ? acc + b->getPower() : acc; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ class Game {
|
|||||||
Uint8 lastStageReached; // Contiene el numero de la última pantalla que se ha alcanzado
|
Uint8 lastStageReached; // Contiene el numero de la última pantalla que se ha alcanzado
|
||||||
demo_t demo; // Variable con todas las variables relacionadas con el modo demo
|
demo_t demo; // Variable con todas las variables relacionadas con el modo demo
|
||||||
int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases
|
int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases
|
||||||
int cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
int cloudsSpeed{0}; // Velocidad a la que se desplazan las nubes
|
||||||
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
||||||
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
||||||
bool pauseInitialized; // Indica si la pausa ha sido inicializada
|
bool pauseInitialized; // Indica si la pausa ha sido inicializada
|
||||||
@@ -524,6 +524,9 @@ class Game {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
|
Game(const Game &) = delete;
|
||||||
|
Game &operator=(const Game &) = delete;
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace Options {
|
|||||||
parseBoolField(aud, "enabled", audio.enabled);
|
parseBoolField(aud, "enabled", audio.enabled);
|
||||||
if (aud.contains("volume")) {
|
if (aud.contains("volume")) {
|
||||||
try {
|
try {
|
||||||
audio.volume = std::clamp(aud["volume"].get_value<int>(), 0, 100);
|
audio.volume = std::clamp(aud["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
if (aud.contains("music")) {
|
if (aud.contains("music")) {
|
||||||
@@ -122,7 +122,7 @@ namespace Options {
|
|||||||
parseBoolField(mus, "enabled", audio.music.enabled);
|
parseBoolField(mus, "enabled", audio.music.enabled);
|
||||||
if (mus.contains("volume")) {
|
if (mus.contains("volume")) {
|
||||||
try {
|
try {
|
||||||
audio.music.volume = std::clamp(mus["volume"].get_value<int>(), 0, 100);
|
audio.music.volume = std::clamp(mus["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ namespace Options {
|
|||||||
parseBoolField(snd, "enabled", audio.sound.enabled);
|
parseBoolField(snd, "enabled", audio.sound.enabled);
|
||||||
if (snd.contains("volume")) {
|
if (snd.contains("volume")) {
|
||||||
try {
|
try {
|
||||||
audio.sound.volume = std::clamp(snd["volume"].get_value<int>(), 0, 100);
|
audio.sound.volume = std::clamp(snd["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,7 +307,7 @@ namespace Options {
|
|||||||
file << " current_crtpi_preset: \"" << video.shader.current_crtpi_preset_name << "\"\n\n";
|
file << " current_crtpi_preset: \"" << video.shader.current_crtpi_preset_name << "\"\n\n";
|
||||||
|
|
||||||
// AUDIO
|
// AUDIO
|
||||||
file << "# AUDIO (volume range: 0..100)\n";
|
file << "# AUDIO (volume range: 0.0..1.0)\n";
|
||||||
file << "audio:\n";
|
file << "audio:\n";
|
||||||
file << " enabled: " << boolToString(audio.enabled) << "\n";
|
file << " enabled: " << boolToString(audio.enabled) << "\n";
|
||||||
file << " volume: " << audio.volume << "\n";
|
file << " volume: " << audio.volume << "\n";
|
||||||
|
|||||||
@@ -56,17 +56,17 @@ namespace Options {
|
|||||||
|
|
||||||
struct Music {
|
struct Music {
|
||||||
bool enabled = Defaults::Music::ENABLED;
|
bool enabled = Defaults::Music::ENABLED;
|
||||||
int volume = Defaults::Music::VOLUME;
|
float volume = Defaults::Music::VOLUME;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sound {
|
struct Sound {
|
||||||
bool enabled = Defaults::Sound::ENABLED;
|
bool enabled = Defaults::Sound::ENABLED;
|
||||||
int volume = Defaults::Sound::VOLUME;
|
float volume = Defaults::Sound::VOLUME;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Audio {
|
struct Audio {
|
||||||
bool enabled = Defaults::Audio::ENABLED;
|
bool enabled = Defaults::Audio::ENABLED;
|
||||||
int volume = Defaults::Audio::VOLUME;
|
float volume = Defaults::Audio::VOLUME;
|
||||||
Music music;
|
Music music;
|
||||||
Sound sound;
|
Sound sound;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <iostream> // for char_traits, basic_ostream, operator<<
|
#include <iostream> // for char_traits, basic_ostream, operator<<
|
||||||
#include <string> // for basic_string
|
#include <string> // for basic_string
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
|
#include "core/audio/audio.hpp" // for Audio::update
|
||||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
#include "core/locale/lang.h" // for Lang
|
#include "core/locale/lang.h" // for Lang
|
||||||
@@ -71,7 +71,7 @@ Instructions::~Instructions() {
|
|||||||
void Instructions::update() {
|
void Instructions::update() {
|
||||||
// Bombea el stream de música: si no se llama, el buffer se vacía y la
|
// Bombea el stream de música: si no se llama, el buffer se vacía y la
|
||||||
// música se corta hasta que volvamos a una escena que sí lo haga.
|
// música se corta hasta que volvamos a una escena que sí lo haga.
|
||||||
JA_Update();
|
Audio::update();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class Instructions {
|
|||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
bool manualQuit; // Indica si se quiere salir del modo manual
|
bool manualQuit; // Indica si se quiere salir del modo manual
|
||||||
mode_e mode; // Modo en el que se van a ejecutar las instrucciones
|
mode_e mode{m_auto}; // Modo en el que se van a ejecutar las instrucciones
|
||||||
bool finished; // Indica si las instrucciones han terminado
|
bool finished; // Indica si las instrucciones han terminado
|
||||||
bool quitRequested; // Indica si se ha solicitado salir de la aplicación
|
bool quitRequested; // Indica si se ha solicitado salir de la aplicación
|
||||||
|
|
||||||
@@ -45,6 +45,9 @@ class Instructions {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Instructions();
|
~Instructions();
|
||||||
|
|
||||||
|
Instructions(const Instructions &) = delete;
|
||||||
|
Instructions &operator=(const Instructions &) = delete;
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run(mode_e mode);
|
void run(mode_e mode);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <string> // for basic_string
|
#include <string> // for basic_string
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic, JA_DeleteMusic, JA_LoadMusic
|
#include "core/audio/audio.hpp" // for Audio::get, Audio::update
|
||||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
#include "core/locale/lang.h" // for Lang
|
#include "core/locale/lang.h" // for Lang
|
||||||
@@ -149,7 +149,7 @@ Intro::Intro(SDL_Renderer *renderer, section_t *section) {
|
|||||||
t->center(GAMECANVAS_CENTER_X);
|
t->center(GAMECANVAS_CENTER_X);
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_PlayMusic(music, 0);
|
Audio::get()->playMusic(music, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -177,7 +177,7 @@ void Intro::checkInput() {
|
|||||||
if (GlobalInputs::handle()) { return; }
|
if (GlobalInputs::handle()) { return; }
|
||||||
|
|
||||||
if (Input::get()->checkInput(input_pause, REPEAT_FALSE) || Input::get()->checkInput(input_accept, REPEAT_FALSE) || Input::get()->checkInput(input_fire_left, REPEAT_FALSE) || Input::get()->checkInput(input_fire_center, REPEAT_FALSE) || Input::get()->checkInput(input_fire_right, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_pause, REPEAT_FALSE) || Input::get()->checkInput(input_accept, REPEAT_FALSE) || Input::get()->checkInput(input_fire_left, REPEAT_FALSE) || Input::get()->checkInput(input_fire_center, REPEAT_FALSE) || Input::get()->checkInput(input_fire_right, REPEAT_FALSE)) {
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
@@ -307,7 +307,7 @@ void Intro::updateScenes() {
|
|||||||
if (bitmaps[5]->hasFinished() && texts[8]->hasFinished()) {
|
if (bitmaps[5]->hasFinished() && texts[8]->hasFinished()) {
|
||||||
bitmaps[5]->setEnabled(false);
|
bitmaps[5]->setEnabled(false);
|
||||||
texts[8]->setEnabled(false);
|
texts[8]->setEnabled(false);
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ void Intro::updateScenes() {
|
|||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Intro::update() {
|
void Intro::update() {
|
||||||
JA_Update();
|
Audio::update();
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
||||||
@@ -365,7 +365,7 @@ void Intro::render() {
|
|||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void Intro::run() {
|
void Intro::run() {
|
||||||
JA_PlayMusic(music, 0);
|
Audio::get()->playMusic(music, 0);
|
||||||
|
|
||||||
while (section->name == SECTION_PROG_INTRO) {
|
while (section->name == SECTION_PROG_INTRO) {
|
||||||
iterate();
|
iterate();
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ class Intro {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Intro();
|
~Intro();
|
||||||
|
|
||||||
|
Intro(const Intro &) = delete;
|
||||||
|
Intro &operator=(const Intro &) = delete;
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <algorithm> // for min
|
#include <algorithm> // for min
|
||||||
#include <string> // for basic_string
|
#include <string> // for basic_string
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
|
#include "core/audio/audio.hpp" // for Audio::get, Audio::update
|
||||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
#include "core/rendering/screen.h" // for Screen
|
#include "core/rendering/screen.h" // for Screen
|
||||||
@@ -38,7 +38,7 @@ Logo::Logo(SDL_Renderer *renderer, section_t *section) {
|
|||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
|
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -85,7 +85,7 @@ void Logo::renderFade() {
|
|||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Logo::update() {
|
void Logo::update() {
|
||||||
JA_Update();
|
Audio::update();
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
||||||
@@ -120,7 +120,7 @@ void Logo::render() {
|
|||||||
|
|
||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
void Logo::run() {
|
void Logo::run() {
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
|
|
||||||
while (section->name == SECTION_PROG_LOGO) {
|
while (section->name == SECTION_PROG_LOGO) {
|
||||||
iterate();
|
iterate();
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ class Logo {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Logo();
|
~Logo();
|
||||||
|
|
||||||
|
Logo(const Logo &) = delete;
|
||||||
|
Logo &operator=(const Logo &) = delete;
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <iostream> // for basic_ostream, operator<<, basic_ostrea...
|
#include <iostream> // for basic_ostream, operator<<, basic_ostrea...
|
||||||
#include <string> // for basic_string, operator+, char_traits
|
#include <string> // for basic_string, operator+, char_traits
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_StopMusic, JA_GetMusicState, JA_Play...
|
#include "core/audio/audio.hpp" // for Audio
|
||||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||||
#include "core/input/input.h" // for Input, INPUT_USE_GAMECONTROLLER, INPUT_...
|
#include "core/input/input.h" // for Input, INPUT_USE_GAMECONTROLLER, INPUT_...
|
||||||
#include "core/locale/lang.h" // for Lang, ba_BA, en_UK, es_ES
|
#include "core/locale/lang.h" // for Lang, ba_BA, en_UK, es_ES
|
||||||
@@ -212,7 +212,7 @@ void Title::init() {
|
|||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Title::update() {
|
void Title::update() {
|
||||||
// Actualiza el audio
|
// Actualiza el audio
|
||||||
JA_Update();
|
Audio::update();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -243,7 +243,7 @@ void Title::update() {
|
|||||||
Screen::get()->blit();
|
Screen::get()->blit();
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(crashSound);
|
Audio::get()->playSound(crashSound);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -276,8 +276,8 @@ void Title::update() {
|
|||||||
// Sección 3 - La pantalla de titulo con el menú y la música
|
// Sección 3 - La pantalla de titulo con el menú y la música
|
||||||
case SUBSECTION_TITLE_3: {
|
case SUBSECTION_TITLE_3: {
|
||||||
if (counter > 0) { // Reproduce la música
|
if (counter > 0) { // Reproduce la música
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) {
|
if (Audio::getRealMusicState() == Audio::MusicState::STOPPED) {
|
||||||
JA_PlayMusic(titleMusic);
|
Audio::get()->playMusic(titleMusic);
|
||||||
}
|
}
|
||||||
|
|
||||||
dustBitmapR->update();
|
dustBitmapR->update();
|
||||||
@@ -291,19 +291,19 @@ void Title::update() {
|
|||||||
case 0: // 1 PLAYER
|
case 0: // 1 PLAYER
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // 2 PLAYERS
|
case 1: // 2 PLAYERS
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
section->subsection = SUBSECTION_GAME_PLAY_2P;
|
section->subsection = SUBSECTION_GAME_PLAY_2P;
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // QUIT
|
case 2: // QUIT
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
JA_StopMusic();
|
Audio::get()->stopMusic();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -860,11 +860,13 @@ void Title::iterate() {
|
|||||||
demoGame->iterate();
|
demoGame->iterate();
|
||||||
|
|
||||||
if (demoGame->hasFinished()) {
|
if (demoGame->hasFinished()) {
|
||||||
bool wasQuit = (section->name == SECTION_PROG_QUIT);
|
// cppcheck-suppress knownConditionTrueFalse
|
||||||
|
const bool wasQuit = (section->name == SECTION_PROG_QUIT);
|
||||||
delete demoGame;
|
delete demoGame;
|
||||||
demoGame = nullptr;
|
demoGame = nullptr;
|
||||||
demoGameActive = false;
|
demoGameActive = false;
|
||||||
|
|
||||||
|
// cppcheck-suppress knownConditionTrueFalse
|
||||||
if (wasQuit) {
|
if (wasQuit) {
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
} else if (demoThenInstructions) {
|
} else if (demoThenInstructions) {
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ class Title {
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Instructions *instructions; // Objeto para la sección de las instrucciones
|
Instructions *instructions{nullptr}; // Objeto para la sección de las instrucciones
|
||||||
Game *demoGame; // Objeto para lanzar la demo del juego
|
Game *demoGame{nullptr}; // Objeto para lanzar la demo del juego
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
section_t *section; // Indicador para el bucle del titulo
|
section_t *section; // Indicador para el bucle del titulo
|
||||||
|
|
||||||
@@ -88,14 +88,14 @@ class Title {
|
|||||||
|
|
||||||
// Variables para la vibración del título (SUBSECTION_TITLE_2)
|
// Variables para la vibración del título (SUBSECTION_TITLE_2)
|
||||||
int vibrationStep; // Paso actual de la vibración
|
int vibrationStep; // Paso actual de la vibración
|
||||||
int vibrationCoffeeBaseX; // Posición X base del bitmap Coffee
|
int vibrationCoffeeBaseX{0}; // Posición X base del bitmap Coffee
|
||||||
int vibrationCrisisBaseX; // Posición X base del bitmap Crisis
|
int vibrationCrisisBaseX{0}; // Posición X base del bitmap Crisis
|
||||||
bool vibrationInitialized; // Indica si se han capturado las posiciones base
|
bool vibrationInitialized; // Indica si se han capturado las posiciones base
|
||||||
|
|
||||||
// Variables para sub-estados delegados (instrucciones y demo)
|
// Variables para sub-estados delegados (instrucciones y demo)
|
||||||
bool instructionsActive; // Indica si las instrucciones están activas
|
bool instructionsActive; // Indica si las instrucciones están activas
|
||||||
bool demoGameActive; // Indica si el juego demo está activo
|
bool demoGameActive; // Indica si el juego demo está activo
|
||||||
mode_e instructionsMode; // Modo de las instrucciones activas
|
mode_e instructionsMode{m_auto}; // Modo de las instrucciones activas
|
||||||
bool demoThenInstructions; // Indica si tras la demo hay que mostrar instrucciones
|
bool demoThenInstructions; // Indica si tras la demo hay que mostrar instrucciones
|
||||||
|
|
||||||
// Inicializa los valores
|
// Inicializa los valores
|
||||||
@@ -147,6 +147,9 @@ class Title {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Title();
|
~Title();
|
||||||
|
|
||||||
|
Title(const Title &) = delete;
|
||||||
|
Title &operator=(const Title &) = delete;
|
||||||
|
|
||||||
// Bucle para el titulo del juego
|
// Bucle para el titulo del juego
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
#include <numeric> // for accumulate
|
#include <numeric> // for accumulate
|
||||||
#include <sstream> // for basic_stringstream
|
#include <sstream> // for basic_stringstream
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp" // for JA_LoadSound, JA_PlaySound, JA_DeleteSound
|
#include "core/audio/audio.hpp" // for Audio::get (playSound)
|
||||||
|
#include "core/audio/jail_audio.hpp" // for JA_LoadSound, JA_DeleteSound (propietat local)
|
||||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
#include "core/rendering/text.h" // for Text
|
#include "core/rendering/text.h" // for Text
|
||||||
#include "core/resources/asset.h" // for Asset
|
#include "core/resources/asset.h" // for Asset
|
||||||
@@ -430,8 +431,7 @@ void Menu::setSelectorPos(int index) {
|
|||||||
|
|
||||||
// Obtiene la anchura del elemento más ancho del menu
|
// Obtiene la anchura del elemento más ancho del menu
|
||||||
int Menu::getWidestItem() {
|
int Menu::getWidestItem() {
|
||||||
return std::accumulate(item.begin(), item.end(), 0,
|
return std::accumulate(item.begin(), item.end(), 0, [](int acc, const item_t &i) { return std::max(acc, i.rect.w); });
|
||||||
[](int acc, const item_t &i) { return std::max(acc, i.rect.w); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deja el menu apuntando al primer elemento
|
// Deja el menu apuntando al primer elemento
|
||||||
@@ -759,28 +759,28 @@ void Menu::checkInput() {
|
|||||||
if (Input::get()->checkInput(input_up, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_up, REPEAT_FALSE)) {
|
||||||
decreaseSelectorIndex();
|
decreaseSelectorIndex();
|
||||||
if (soundMove) {
|
if (soundMove) {
|
||||||
JA_PlaySound(soundMove);
|
Audio::get()->playSound(soundMove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::get()->checkInput(input_down, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_down, REPEAT_FALSE)) {
|
||||||
increaseSelectorIndex();
|
increaseSelectorIndex();
|
||||||
if (soundMove) {
|
if (soundMove) {
|
||||||
JA_PlaySound(soundMove);
|
Audio::get()->playSound(soundMove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) {
|
||||||
itemSelected = selector.index;
|
itemSelected = selector.index;
|
||||||
if (soundAccept) {
|
if (soundAccept) {
|
||||||
JA_PlaySound(soundAccept);
|
Audio::get()->playSound(soundAccept);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::get()->checkInput(input_cancel, REPEAT_FALSE)) {
|
if (Input::get()->checkInput(input_cancel, REPEAT_FALSE)) {
|
||||||
itemSelected = defaultActionWhenCancel;
|
itemSelected = defaultActionWhenCancel;
|
||||||
if (soundCancel) {
|
if (soundCancel) {
|
||||||
JA_PlaySound(soundCancel);
|
Audio::get()->playSound(soundCancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -792,8 +792,7 @@ int Menu::findWidth() {
|
|||||||
|
|
||||||
// Calcula el alto del menu
|
// Calcula el alto del menu
|
||||||
int Menu::findHeight() {
|
int Menu::findHeight() {
|
||||||
const int height = std::accumulate(item.begin(), item.end(), 0,
|
const int height = std::accumulate(item.begin(), item.end(), 0, [](int acc, const item_t &i) { return acc + i.rect.h + i.hPaddingDown; });
|
||||||
[](int acc, const item_t &i) { return acc + i.rect.h + i.hPaddingDown; });
|
|
||||||
|
|
||||||
return height - item.back().hPaddingDown;
|
return height - item.back().hPaddingDown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ Reescribiendo el código el 27/09/2022
|
|||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
|
|
||||||
#include "core/system/director.h"
|
#include "core/system/director.h"
|
||||||
#include "external/stb_vorbis.c"
|
|
||||||
|
|
||||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
||||||
auto *director = new Director(argc, const_cast<const char **>(argv));
|
auto *director = new Director(argc, const_cast<const char **>(argv));
|
||||||
|
|||||||
Reference in New Issue
Block a user