VERSIÓ 1.6

- [FIX] La música ja torna a sonar
This commit is contained in:
2026-03-04 09:25:52 +01:00
parent 6d09afdf09
commit e92498fd16
4 changed files with 32 additions and 18 deletions

View File

@@ -14,12 +14,18 @@ namespace audio
JA_Sound_t *chunk; JA_Sound_t *chunk;
}; };
struct music_cache_t
{
std::string name;
JA_Music_t *chunk;
};
//char *music_buffer = nullptr; //char *music_buffer = nullptr;
//JA_Music_t *music = nullptr; //JA_Music_t *music = nullptr;
std::vector<sound_cache_t> sounds; std::vector<sound_cache_t> sounds;
std::vector<sound_cache_t> songs; std::vector<music_cache_t> songs;
std::string musica_actual = ""; std::string musica_actual = "";
int musica = -1; //int musica = -1;
// Inicialitza el sistema de só // Inicialitza el sistema de só
void init() void init()
@@ -33,7 +39,7 @@ namespace audio
void quit() void quit()
{ {
//if (music) JA_DeleteMusic(music); //if (music) JA_DeleteMusic(music);
for (auto sound : songs) JA_DeleteSound(sound.chunk); for (auto music : songs) JA_DeleteMusic(music.chunk);
songs.clear(); songs.clear();
for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk); for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk);
sounds.clear(); sounds.clear();
@@ -44,12 +50,12 @@ namespace audio
{ {
int size; int size;
char *buffer = file::getFileBuffer(filename, size); char *buffer = file::getFileBuffer(filename, size);
auto chunk = JA_LoadSound((uint8_t *)buffer, size); auto chunk = JA_LoadMusic((uint8_t *)buffer, size);
free(buffer); free(buffer);
//auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1); //auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
//if (!chunk) printf("ERROR: %s\n", SDL_GetError()); //if (!chunk) printf("ERROR: %s\n", SDL_GetError());
sound_cache_t sound = { filename, chunk }; music_cache_t sound = { filename, chunk };
songs.push_back(sound); songs.push_back(sound);
} }
@@ -66,12 +72,15 @@ namespace audio
//free(buffer); //free(buffer);
//JA_PlayMusic(music, loop); //JA_PlayMusic(music, loop);
//int song_index = 0;
for (auto song : songs) for (auto song : songs)
{ {
if (song.name == filename) { if (song.name == filename) {
musica = JA_PlaySound(song.chunk, loop); JA_PlayMusic(song.chunk, loop);
//musica = song_index;
musica_actual = filename; musica_actual = filename;
return; return;
//song_index++;
} }
} }
} }
@@ -79,24 +88,24 @@ namespace audio
// Pausa la música que està sonant ara // Pausa la música que està sonant ara
void pauseMusic() void pauseMusic()
{ {
//JA_PauseMusic(); //Mix_PauseMusic(); JA_PauseMusic(); //Mix_PauseMusic();
if (musica != -1) JA_PauseChannel(musica); //if (musica != -1) JA_PauseChannel(musica);
} }
// Continua la música pausada // Continua la música pausada
void resumeMusic() void resumeMusic()
{ {
if (!config::isMusicEnabled()) return; if (!config::isMusicEnabled()) return;
//JA_ResumeMusic(); //Mix_ResumeMusic(); JA_ResumeMusic(); //Mix_ResumeMusic();
if (musica != -1) JA_ResumeChannel(musica); //if (musica != -1) JA_ResumeChannel(musica);
} }
// Para la música que estava sonant // Para la música que estava sonant
void stopMusic() void stopMusic()
{ {
//JA_StopMusic(); //Mix_HaltMusic(); JA_StopMusic(); //Mix_HaltMusic();
if (musica != -1) JA_StopChannel(musica); //if (musica != -1) JA_StopChannel(musica);
musica = -1; //musica = -1;
musica_actual = ""; musica_actual = "";
} }

View File

@@ -7,6 +7,8 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include "jaudio.h" #include "jaudio.h"
#include "actor.h" #include "actor.h"
#include "versio.h"
namespace modules namespace modules
{ {
namespace menu namespace menu
@@ -122,7 +124,7 @@ namespace modules
//draw::print2(input::getPadBtnPressed(), 3, 0, 24, RED, FONT_ZOOM_NONE); //draw::print2(input::getPadBtnPressed(), 3, 0, 24, RED, FONT_ZOOM_NONE);
draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE);
draw::print("v1.5b", 299, 233, WHITE, PAPER); draw::print(VERSIO, 299, 233, WHITE, PAPER);
draw::render(); draw::render();
return OPTION_NONE; return OPTION_NONE;

View File

@@ -116,14 +116,14 @@ void game::init()
draw::init("The Pool", 320, 240, zoom, fullscreen); draw::init("The Pool", 320, 240, zoom, fullscreen);
console::init(); console::init();
printf("Carregant mus_menu.ogg..."); printf("Carregant mus_menu.ogg...\n");
audio::loadMusic("mus_menu.ogg"); audio::loadMusic("mus_menu.ogg");
printf("Carregant mus_ingame.ogg..."); printf("Carregant mus_ingame.ogg...\n");
audio::loadMusic("mus_ingame.ogg"); audio::loadMusic("mus_ingame.ogg");
printf("Carregant mus_gameover.ogg..."); printf("Carregant mus_gameover.ogg...\n");
audio::loadMusic("mus_gameover.ogg"); audio::loadMusic("mus_gameover.ogg");
printf("Carregant arxius de só..."); printf("Carregant arxius de só...\n");
audio::loadSound("snd_logo.wav"); audio::loadSound("snd_logo.wav");
audio::loadSound("snd_walk.wav"); audio::loadSound("snd_walk.wav");
audio::loadSound("snd_push.wav"); audio::loadSound("snd_push.wav");

3
source/versio.h Normal file
View File

@@ -0,0 +1,3 @@
#pragma once
#define VERSIO "v1.6"