Migració de SDL_Mixer a JailAudio completa

This commit is contained in:
2021-02-21 12:07:04 +01:00
parent 87a88a3684
commit 5ee2830480
3 changed files with 72 additions and 69 deletions

2
source/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.vscode
volcano

View File

@@ -21,13 +21,13 @@ void allocatePointers()
prog.sprite = new LTexture(); prog.sprite = new LTexture();
// Sounds // Sounds
game.sound_drop_enemy = new Mix_Chunk(); //game.sound_drop_enemy = new Mix_Chunk();
game.sound_drop_splat = new Mix_Chunk(); //game.sound_drop_splat = new Mix_Chunk();
menu.sound_logo = new Mix_Chunk(); //menu.sound_logo = new Mix_Chunk();
menu.sound_start = new Mix_Chunk(); //menu.sound_start = new Mix_Chunk();
player.sound_coin = new Mix_Chunk(); //player.sound_coin = new Mix_Chunk();
player.sound_death = new Mix_Chunk(); //player.sound_death = new Mix_Chunk();
player.sound_jump = new Mix_Chunk(); //player.sound_jump = new Mix_Chunk();
// Music // Music
//game.music = new Mix_Music(); //game.music = new Mix_Music();
@@ -47,13 +47,13 @@ void deletePointers()
delete prog.sprite; delete prog.sprite;
// Sounds // Sounds
delete game.sound_drop_enemy; JA_DeleteSound(game.sound_drop_enemy);
delete game.sound_drop_splat; JA_DeleteSound(game.sound_drop_splat);
delete menu.sound_logo; JA_DeleteSound(menu.sound_logo);
delete menu.sound_start; JA_DeleteSound(menu.sound_start);
delete player.sound_coin; JA_DeleteSound(player.sound_coin);
delete player.sound_death; JA_DeleteSound(player.sound_death);
delete player.sound_jump; JA_DeleteSound(player.sound_jump);
// Music // Music
//game.music = new Mix_Music(); //game.music = new Mix_Music();
@@ -75,17 +75,17 @@ bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *rend
return success; return success;
} }
void CloseSound(Mix_Chunk *sound) void CloseSound(JA_Sound sound)
{ {
if (sound != nullptr) if (sound != nullptr)
Mix_FreeChunk(sound); JA_DeleteSound(sound);
sound = nullptr; sound = nullptr;
} }
void CloseMusic(Mix_Music *music) void CloseMusic(JA_Music music)
{ {
if (music != nullptr) if (music != nullptr)
Mix_FreeMusic(music); JA_DeleteMusic(music);
music = nullptr; music = nullptr;
} }
@@ -154,11 +154,11 @@ void SetMapMusic(Uint8 zone)
switch (zone) switch (zone)
{ {
case ZONE_SURFACE: case ZONE_SURFACE:
game.music = Mix_LoadMUS(FILE_MUSIC_SURFACE.c_str()); game.music = JA_LoadMusic(FILE_MUSIC_SURFACE.c_str());
break; break;
case ZONE_VOLCANO: case ZONE_VOLCANO:
game.music = Mix_LoadMUS(FILE_MUSIC_VOLCANO.c_str()); game.music = JA_LoadMusic(FILE_MUSIC_VOLCANO.c_str());
break; break;
} }
} }
@@ -187,7 +187,7 @@ void SetZone(int room)
SetMapGFX(game.zone); SetMapGFX(game.zone);
SetMapMusic(game.zone); SetMapMusic(game.zone);
Mix_PlayMusic(game.music, -1); JA_PlayMusic(game.music, -1);
} }
void SetPlayerAnimation(Uint8 anim) void SetPlayerAnimation(Uint8 anim)
@@ -473,9 +473,9 @@ void IniMenu()
menu.enabled = true; menu.enabled = true;
menu.section = MENU_SECTION_ANIMATION; menu.section = MENU_SECTION_ANIMATION;
menu.music = Mix_LoadMUS(FILE_MUSIC_MENU.c_str()); menu.music = JA_LoadMusic(FILE_MUSIC_MENU.c_str());
menu.sound_logo = Mix_LoadWAV(FILE_SOUND_MENU_LOGO.c_str()); menu.sound_logo = JA_LoadSound(FILE_SOUND_MENU_LOGO.c_str());
menu.sound_start = Mix_LoadWAV(FILE_SOUND_MENU_START.c_str()); menu.sound_start = JA_LoadSound(FILE_SOUND_MENU_START.c_str());
loadTextureFromFile(menu.sprite, FILE_MENU.c_str(), renderer); loadTextureFromFile(menu.sprite, FILE_MENU.c_str(), renderer);
menu.frame = 0; menu.frame = 0;
@@ -685,9 +685,9 @@ void IniPlayer()
player.coins = 0; player.coins = 0;
for (Uint8 i = 0; i < 6; i++) for (Uint8 i = 0; i < 6; i++)
player.key[i] = false; player.key[i] = false;
player.sound_jump = Mix_LoadWAV(FILE_SOUND_JUMP.c_str()); player.sound_jump = JA_LoadSound(FILE_SOUND_JUMP.c_str());
player.sound_death = Mix_LoadWAV(FILE_SOUND_DEATH.c_str()); player.sound_death = JA_LoadSound(FILE_SOUND_DEATH.c_str());
player.sound_coin = Mix_LoadWAV(FILE_SOUND_COIN.c_str()); player.sound_coin = JA_LoadSound(FILE_SOUND_COIN.c_str());
player.animation[0].num_frames = 33; player.animation[0].num_frames = 33;
player.animation[0].index = 0; player.animation[0].index = 0;
@@ -826,8 +826,8 @@ void EndHud()
void IniGame(Uint8 zone) void IniGame(Uint8 zone)
{ {
game.sound_drop_enemy = Mix_LoadWAV(FILE_SOUND_DROP_ENEMY.c_str()); game.sound_drop_enemy = JA_LoadSound(FILE_SOUND_DROP_ENEMY.c_str());
game.sound_drop_splat = Mix_LoadWAV(FILE_SOUND_DROP_SPLAT.c_str()); game.sound_drop_splat = JA_LoadSound(FILE_SOUND_DROP_SPLAT.c_str());
game.enabled = true; game.enabled = true;
game.zone = zone; game.zone = zone;
@@ -859,8 +859,8 @@ void EndGame()
EndMap(); EndMap();
CloseSound(game.sound_drop_enemy); CloseSound(game.sound_drop_enemy);
CloseSound(game.sound_drop_splat); CloseSound(game.sound_drop_splat);
if (Mix_PlayingMusic() == 1) if (JA_GetMusicState() == JA_MUSIC_PLAYING)
Mix_HaltMusic(); JA_StopMusic();
CloseMusic(game.music); CloseMusic(game.music);
game.enabled = false; game.enabled = false;
} }
@@ -876,7 +876,7 @@ void KillPlayer()
else else
SetPlayerAnimation(PLAYER_ANIMATION_DYING_RIGHT); SetPlayerAnimation(PLAYER_ANIMATION_DYING_RIGHT);
Mix_PlayChannel(-1, player.sound_death, 0); JA_PlaySound(player.sound_death, 0);
} }
bool OnFloor() bool OnFloor()
@@ -1195,7 +1195,7 @@ void MoveActors()
while (actor[k].enabled) while (actor[k].enabled)
k++; k++;
CreateActor(actor[k], KIND_DROP_ENEMY, 0, actor[i].dst_rect.x, actor[i].dst_rect.y, 16, 16, 0, 8 * 16, 0, 2, 0, 0, DOWN, i); CreateActor(actor[k], KIND_DROP_ENEMY, 0, actor[i].dst_rect.x, actor[i].dst_rect.y, 16, 16, 0, 8 * 16, 0, 2, 0, 0, DOWN, i);
Mix_PlayChannel(-1, game.sound_drop_enemy, 0); JA_PlaySound(game.sound_drop_enemy, 0);
} }
// Animacio // Animacio
@@ -1226,7 +1226,7 @@ void MoveActors()
actor[i].frame = 0; actor[i].frame = 0;
actor[i].timer = 30; actor[i].timer = 30;
actor[i].src_rect.y = 11 * 16; actor[i].src_rect.y = 11 * 16;
Mix_PlayChannel(-1, game.sound_drop_splat, 0); JA_PlaySound(game.sound_drop_splat, 0);
} }
// Animacio // Animacio
@@ -1302,7 +1302,7 @@ void MovePlayer(int direction)
player.dst_rect.y = player.dst_rect.y + player.speed_y; player.dst_rect.y = player.dst_rect.y + player.speed_y;
// Soroll de saltar // Soroll de saltar
Mix_PlayChannel(-1, player.sound_jump, 0); JA_PlaySound(player.sound_jump, 0);
} }
// Nou frame d'animaci<63> // Nou frame d'animaci<63>
@@ -1629,7 +1629,7 @@ void CheckPlayerCollisionWithActors()
player.coins++; player.coins++;
actor[i].enabled = false; actor[i].enabled = false;
SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0); SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0);
Mix_PlayChannel(-1, player.sound_coin, 0); JA_PlaySound(player.sound_coin, 0);
} }
break; break;
@@ -1647,7 +1647,7 @@ void CheckPlayerCollisionWithActors()
player.lifes++; player.lifes++;
actor[i].enabled = false; actor[i].enabled = false;
SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0); SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0);
Mix_PlayChannel(-1, player.sound_coin, 0); JA_PlaySound(player.sound_coin, 0);
} }
break; break;
@@ -1664,7 +1664,7 @@ void CheckPlayerCollisionWithActors()
player.key[actor[i].id] = true; player.key[actor[i].id] = true;
actor[i].enabled = false; actor[i].enabled = false;
SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0); SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0);
Mix_PlayChannel(-1, player.sound_coin, 0); JA_PlaySound(player.sound_coin, 0);
} }
break; break;
@@ -1739,10 +1739,10 @@ void IniProgram()
SetProgSection(SECTION_MENU); SetProgSection(SECTION_MENU);
prog.debug = false; prog.debug = false;
if (prog.music_enabled) /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum
Mix_VolumeMusic(100); Mix_VolumeMusic(100);
else else
Mix_VolumeMusic(0); Mix_VolumeMusic(0); */
loadTextureFromFile(prog.sprite, FILE_FILTER.c_str(), renderer); loadTextureFromFile(prog.sprite, FILE_FILTER.c_str(), renderer);
@@ -1777,8 +1777,9 @@ int main(int argc, char *args[])
SDL_RenderSetLogicalSize(renderer, 320, 240); SDL_RenderSetLogicalSize(renderer, 320, 240);
// Inicializa el audio // Inicializa el audio
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048); //Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048);
JA_Init(22050, AUDIO_S16SYS, 2);
allocatePointers(); allocatePointers();
// Inicializa el programa // Inicializa el programa
IniProgram(); IniProgram();
@@ -1801,7 +1802,7 @@ int main(int argc, char *args[])
LoadRoom(STARTING_ROOM); LoadRoom(STARTING_ROOM);
// Conecta la musica // Conecta la musica
Mix_PlayMusic(game.music, -1); JA_PlayMusic(game.music, -1);
// Bucle de joc // Bucle de joc
while (game.enabled) while (game.enabled)
@@ -1859,10 +1860,10 @@ int main(int argc, char *args[])
case SDL_SCANCODE_M: case SDL_SCANCODE_M:
prog.music_enabled = !prog.music_enabled; prog.music_enabled = !prog.music_enabled;
if (prog.music_enabled) /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum
Mix_VolumeMusic(100); Mix_VolumeMusic(100);
else else
Mix_VolumeMusic(0); Mix_VolumeMusic(0);*/
break; break;
case SDL_SCANCODE_T: case SDL_SCANCODE_T:
@@ -2021,7 +2022,7 @@ int main(int argc, char *args[])
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
// Apaga la musica // Apaga la musica
Mix_HaltMusic(); JA_StopMusic();
while (menu.enabled) while (menu.enabled)
{ {
@@ -2063,10 +2064,10 @@ int main(int argc, char *args[])
// (Des)Activa la musica // (Des)Activa la musica
case SDL_SCANCODE_M: case SDL_SCANCODE_M:
prog.music_enabled = !prog.music_enabled; prog.music_enabled = !prog.music_enabled;
if (prog.music_enabled) /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum
Mix_VolumeMusic(100); Mix_VolumeMusic(100);
else else
Mix_VolumeMusic(0); Mix_VolumeMusic(0);*/
break; break;
// (Des)Activa les scanlines // (Des)Activa les scanlines
@@ -2079,9 +2080,9 @@ int main(int argc, char *args[])
if (menu.timer > 99) if (menu.timer > 99)
{ {
menu.timer = 99; menu.timer = 99;
Mix_HaltMusic(); JA_StopMusic();
Mix_HaltChannel(-1); JA_StopChannel(-1);
Mix_PlayChannel(-1, menu.sound_start, 0); JA_PlaySound(menu.sound_start, 0);
menu.frame = 0; menu.frame = 0;
} }
break; break;
@@ -2118,10 +2119,10 @@ int main(int argc, char *args[])
DrawSprite(menu.sprite, menu.src_rect_logo, menu.dst_rect_logo_zoom); DrawSprite(menu.sprite, menu.src_rect_logo, menu.dst_rect_logo_zoom);
if (menu.frame == (154 / 4)) if (menu.frame == (154 / 4))
Mix_PlayChannel(-1, menu.sound_logo, 0); JA_PlaySound(menu.sound_logo, 0);
if (menu.frame == (300 / 4)) if (menu.frame == (300 / 4))
// Conecta la musica // Conecta la musica
Mix_PlayMusic(menu.music, -1); JA_PlayMusic(menu.music, -1);
if (menu.frame > (300 / 4)) if (menu.frame > (300 / 4))
{ {
@@ -2210,8 +2211,8 @@ int main(int argc, char *args[])
else else
// Animaci<63> segona en loop // Animaci<63> segona en loop
{ {
if (Mix_PlayingMusic() == 0) if (JA_GetMusicState() != JA_MUSIC_PLAYING)
Mix_PlayMusic(menu.music, -1); JA_PlayMusic(menu.music, -1);
// Borrem pantalla // Borrem pantalla
SDL_RenderSetLogicalSize(renderer, 320, 240); SDL_RenderSetLogicalSize(renderer, 320, 240);
@@ -2244,7 +2245,7 @@ int main(int argc, char *args[])
else else
// Hem pulsat el bot<6F> d'start // Hem pulsat el bot<6F> d'start
{ {
Mix_HaltMusic(); JA_StopMusic();
// Borrem pantalla // Borrem pantalla
SDL_RenderSetLogicalSize(renderer, 320, 240); SDL_RenderSetLogicalSize(renderer, 320, 240);
@@ -2299,12 +2300,12 @@ int main(int argc, char *args[])
CloseSound(game.sound_drop_enemy); CloseSound(game.sound_drop_enemy);
CloseSound(game.sound_drop_splat); CloseSound(game.sound_drop_splat);
Mix_HaltMusic(); JA_StopMusic();
CloseMusic(game.music); CloseMusic(game.music);
CloseMusic(menu.music); CloseMusic(menu.music);
Mix_CloseAudio(); //Mix_CloseAudio();
EndProgram(); EndProgram();

View File

@@ -32,9 +32,9 @@ struct Tprogram
struct Tgame struct Tgame
{ {
bool enabled; bool enabled;
Mix_Chunk *sound_drop_enemy; JA_Sound sound_drop_enemy;
Mix_Chunk *sound_drop_splat; JA_Sound sound_drop_splat;
Mix_Music *music; JA_Music music;
Uint8 zone; // Zona en la que estamos Uint8 zone; // Zona en la que estamos
}; };
@@ -45,9 +45,9 @@ struct Tmenu
int timer; int timer;
LTexture *sprite_animation; LTexture *sprite_animation;
LTexture *sprite; LTexture *sprite;
Mix_Chunk *sound_logo; JA_Sound sound_logo;
Mix_Chunk *sound_start; JA_Sound sound_start;
Mix_Music *music; JA_Music music;
SDL_Rect dst_rect_animation; SDL_Rect dst_rect_animation;
SDL_Rect dst_rect_fondo; SDL_Rect dst_rect_fondo;
SDL_Rect dst_rect_logo_zoom; SDL_Rect dst_rect_logo_zoom;
@@ -80,9 +80,9 @@ struct Tplayer
int speed_x; // Cantidad de pixeles a desplazarse int speed_x; // Cantidad de pixeles a desplazarse
int speed_y; // Cantidad de pixels a desplazarse int speed_y; // Cantidad de pixels a desplazarse
LTexture *sprite; // Textura con los graficos del jugador LTexture *sprite; // Textura con los graficos del jugador
Mix_Chunk *sound_coin; // Sonido al coger monedas JA_Sound sound_coin; // Sonido al coger monedas
Mix_Chunk *sound_death; // Sonido al morir JA_Sound sound_death; // Sonido al morir
Mix_Chunk *sound_jump; // Sonido al saltar JA_Sound sound_jump; // Sonido al saltar
SDL_Rect dst_rect; // Rectangulo donde dibujar el sprite del jugador. Es la posición del jugador SDL_Rect dst_rect; // Rectangulo donde dibujar el sprite del jugador. Es la posición del jugador
SDL_Rect src_rect; // Rectangulo con el dibujo del jugador a pintar SDL_Rect src_rect; // Rectangulo con el dibujo del jugador a pintar
Tanimation animation[8]; // Vector con las animaciones del jugador Tanimation animation[8]; // Vector con las animaciones del jugador
@@ -171,9 +171,9 @@ void ApplyGravity();
void CheckPlayerCollisionWithActors(); void CheckPlayerCollisionWithActors();
void CheckPlayerCollisionWithActors(); void CheckPlayerCollisionWithActors();
void CheckPlayerCollisionWithMap(); void CheckPlayerCollisionWithMap();
void CloseMusic(Mix_Music *music); void CloseMusic(JA_Music music);
void ClosePicture(LTexture *picture); void ClosePicture(LTexture *picture);
void CloseSound(Mix_Chunk *sound); void CloseSound(JA_Sound sound);
void CreateActor(Tactor &a, Uint8 kind, Uint8 id, Sint16 dstx, Sint16 dsty, Sint16 dstw, Sint16 dsth, Sint16 srcx, Sint16 srcy, Sint16 sx, Sint16 sy, Sint16 timer, Sint16 frame, Uint8 direction, Uint8 parent); void CreateActor(Tactor &a, Uint8 kind, Uint8 id, Sint16 dstx, Sint16 dsty, Sint16 dstw, Sint16 dsth, Sint16 srcx, Sint16 srcy, Sint16 sx, Sint16 sy, Sint16 timer, Sint16 frame, Uint8 direction, Uint8 parent);
void DrawHud(); void DrawHud();
void DrawMap(); void DrawMap();