diff --git a/source/animatedsprite.h b/source/animatedsprite.h index f1c84bc..1f34a03 100644 --- a/source/animatedsprite.h +++ b/source/animatedsprite.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "movingsprite.h" #ifndef ANIMATEDSPRITE_H diff --git a/source/balloon.h b/source/balloon.h index dce1b0a..d46fb8e 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "utils.h" #include "animatedsprite.h" #include @@ -69,6 +71,20 @@ class Balloon { private: + // Estructura para las variables para el efecto de los rebotes + struct bouncing + { + bool enabled; // Si el efecto está activo + Uint8 counter; // Countador para el efecto + Uint8 speed; // Velocidad a la que transcurre el efecto + float zoomW; // Zoom aplicado a la anchura + float zoomH; // Zoom aplicado a la altura + float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom + float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom + std::vector w; // Vector con los valores de zoom para el ancho del globo + std::vector h; // Vector con los valores de zoom para el alto del globo + }; + float mPosX; // Posición en el eje X float mPosY; // Posición en el eje Y Uint8 mWidth; // Ancho @@ -99,30 +115,34 @@ private: float mSpeed; // Velocidad a la que se mueven los globos Uint8 mSize; // Tamaño del globo Uint8 mPower; // Cantidad de poder que alberga el globo + bouncing mBouncing; // Contiene las variables para el efecto de rebote - struct bouncing // Estructura para las variables para el efecto de los rebotes - { - bool enabled; // Si el efecto está activo - Uint8 counter; // Countador para el efecto - Uint8 speed; // Velocidad a la que transcurre el efecto - float zoomW; // Zoom aplicado a la anchura - float zoomH; // Zoom aplicado a la altura - float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom - float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom - std::vector w; // Vector con los valores de zoom para el ancho del globo - std::vector h; // Vector con los valores de zoom para el alto del globo - }; - bouncing mBouncing; + // Alinea el circulo de colisión con la posición del objeto globo + void updateColliders(); - void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo - void bounceStart(); // Activa el efecto - void bounceStop(); // Detiene el efecto - void updateBounce(); // Aplica el efecto - void updateState(); // Actualiza los estados del globo - void updateAnimation(); // Establece la animación correspondiente - void setBeingCreated(bool state); // Establece el valor de la variable - void setTimeToLive(Uint16 time); // Establece el valor de la variable - Uint16 getTimeToLive(); // Obtiene del valor de la variable + // Activa el efecto + void bounceStart(); + + // Detiene el efecto + void bounceStop(); + + // Aplica el efecto + void updateBounce(); + + // Actualiza los estados del globo + void updateState(); + + // Establece la animación correspondiente + void updateAnimation(); + + // Establece el valor de la variable + void setBeingCreated(bool state); + + // Establece el valor de la variable + void setTimeToLive(Uint16 time); + + // Obtiene del valor de la variable + Uint16 getTimeToLive(); public: // Constructor diff --git a/source/bullet.h b/source/bullet.h index fbc7c81..5077242 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "utils.h" #include "sprite.h" diff --git a/source/coffeedrop.h b/source/coffeedrop.h index 0bf9c7a..8fea3bd 100644 --- a/source/coffeedrop.h +++ b/source/coffeedrop.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "sprite.h" #ifndef COFFEEDROP_H diff --git a/source/const.h b/source/const.h index d5c5f81..ae0ff9d 100644 --- a/source/const.h +++ b/source/const.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "utils.h" #include "lang.h" @@ -10,18 +11,10 @@ #define BLOCK 8 #define HALF_BLOCK BLOCK / 2 -// Tamaño de la pantalla que contendrá la pantalla de juego -//#define REAL_SCREEN_WIDTH 256 -//#define REAL_SCREEN_HEIGHT 192 - // Tamaño de la pantalla de juego #define SCREEN_WIDTH 256 #define SCREEN_HEIGHT 192 -// Tamaño de la pantalla que se muestra -//const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3; -//const int VIEW_HEIGHT = REAL_SCREEN_HEIGHT * 3; - // Zona de juego const int PLAY_AREA_TOP = (0 * BLOCK); const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK); diff --git a/source/director.cpp b/source/director.cpp index c5298d6..393db78 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -3,10 +3,6 @@ #include "director.h" #include #include -#ifdef __MIPSEL__ -#include -#include -#endif // Constructor Director::Director(std::string path) @@ -28,20 +24,6 @@ Director::Director(std::string path) // Crea el puntero a la estructura y carga el fichero de configuración mOptions = new options_t; loadConfigFile(); - //if (!loadConfigFile()) - //{ - // mOptions->fullScreenMode = 0; - // mOptions->windowSize = 3; - // mOptions->language = en_UK; - // mOptions->difficulty = DIFFICULTY_NORMAL; - // mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; - // mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; - // mOptions->filter = FILTER_NEAREST; - // mOptions->vSync = true; - // mOptions->screenHeight = SCREEN_HEIGHT; - // mOptions->screenWidth = SCREEN_WIDTH; - // mOptions->integerScale = true; - //} // Crea los objetos mInput = new Input(mFileList[53]); @@ -56,23 +38,8 @@ Director::Director(std::string path) initJailAudio(); // Aplica las opciones - //SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode); - //SDL_SetWindowSize(mWindow, REAL_SCREEN_WIDTH * mOptions->windowSize, REAL_SCREEN_HEIGHT * mOptions->windowSize); mLang->setLang(mOptions->language); - -#ifdef __MIPSEL__ - DIR *dir = opendir("/media/data/local/home/.coffee_crisis"); - if (dir) - { - closedir(dir); - } - else if (ENOENT == errno) - { - int status = mkdir("/media/data/local/home/.coffee_crisis", 755); - } -#endif - // Inicializa el resto de variables init(section); } @@ -118,15 +85,9 @@ void Director::init(Uint8 name) mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN); mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE); -#ifdef __MIPSEL__ - mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT); - mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE); - mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL); -#else mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q); mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W); mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E); -#endif mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE @@ -217,16 +178,10 @@ void Director::setFileList() for (int i = 0; i < MAX_FILE_LIST; i++) mFileList[i] = ""; - // Ficheros binarios -#ifdef __MIPSEL__ - mFileList[0] = "/media/data/local/home/.coffee_crisis/score.bin"; - mFileList[1] = "/media/data/local/home/.coffee_crisis/demo.bin"; - mFileList[2] = "/media/data/local/home/.coffee_crisis/config.bin"; -#else + // Ficheros binarios mFileList[0] = mExecutablePath + "/" + "../data/score.bin"; mFileList[1] = mExecutablePath + "/" + "../data/demo.bin"; mFileList[2] = mExecutablePath + "/" + "../data/config.bin"; -#endif // Musicas mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg"; diff --git a/source/director.h b/source/director.h index cc00d9a..03f53fc 100644 --- a/source/director.h +++ b/source/director.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "sprite.h" #include "movingsprite.h" #include "smartsprite.h" diff --git a/source/fade.h b/source/fade.h index 0d8247e..82050b1 100644 --- a/source/fade.h +++ b/source/fade.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "ltexture.h" #ifndef FADE_H diff --git a/source/game.cpp b/source/game.cpp index e6dc06d..7fdf0e7 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,8 +1,4 @@ #include "game.h" -#ifdef __MIPSEL__ -#include -#include -#endif // Constructor Game::Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options) @@ -79,18 +75,6 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string * mSpriteGrass = new Sprite(); mSpritePowerMeter = new Sprite(); mSpriteScoreBoard = new Sprite(); - -#ifdef __MIPSEL__ - DIR *dir = opendir("/media/data/local/home/.coffee_crisis"); - if (dir) - { - closedir(dir); - } - else if (ENOENT == errno) - { - int status = mkdir("/media/data/local/home/.coffee_crisis", 755); - } -#endif } Game::~Game() diff --git a/source/game.h b/source/game.h index a951892..5ea4ef4 100644 --- a/source/game.h +++ b/source/game.h @@ -1,9 +1,10 @@ #pragma once + +#include #include "balloon.h" #include "bullet.h" #include "const.h" #include "fade.h" -#include "ifdefs.h" #include "input.h" #include "item.h" #include "jail_audio.h" @@ -74,13 +75,11 @@ private: Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación }; - enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas struct enemyPool_t { enemyFormation_t *set[10]; // Conjunto de formaciones enemigas }; - enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas struct stage_t // Contiene todas las variables relacionadas con una fase { @@ -113,6 +112,23 @@ private: int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto }; + struct demo_t + { + bool enabled; // Indica si está activo el modo demo + bool recording; // Indica si está activado el modo para grabar la demo + Uint16 counter; // Contador para el modo demo + demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo + demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo + }; + + struct debug_t + { + bool enabled; // Indica si se va a mostrar la información de debug + Uint8 enemySet; // Escoge el set enemigo a generar + Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo + float hudW, hudH; // Multiplica el tamaño del hud de debug; + }; + SDL_Renderer *mRenderer; // El renderizador de la ventana Screen *mScreen; // Objeto encargado de dibujar en pantalla std::string *mFileList; // Lista de ficheros con los recursos @@ -193,63 +209,49 @@ private: Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa - Uint32 mHiScore; // Puntuación máxima - bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima - section_t mSection; // Seccion actual dentro del juego - stage_t mStage[10]; // Variable con los datos de cada pantalla - Uint8 mCurrentStage; // Indica la fase actual - Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage - float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto - float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto - Uint16 mDeathCounter; // Contador para la animación de muerte del jugador - Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador - Uint8 mMenaceCurrent; // Nivel de amenaza actual - Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos - bool mTimeStopped; // Indica si el tiempo está detenido - Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido - Uint8 mRemainingExplosions; // Cantidad de explosiones restantes - Uint16 mRemainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes - bool mExplosionTime; // Indica si las explosiones estan en marcha - Uint32 mCounter; // Contador para el juego - Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos - SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes - Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados - Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir; - int mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero - float mEnemySpeed; // Velocidad a la que se mueven los enemigos - float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar - effect_t mEffect; // Variable para gestionar los efectos visuales - helper_t mHelper; // Variable para gestionar las ayudas - bool mPowerBallEnabled; // Indica si hay una powerball ya activa - Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra - bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego - Uint8 mPostFade; // Qué hacer al acabar el fade - float mSin[360]; // Vector con los valores del seno para 360 grados - bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla - int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos - Uint8 mDifficulty; // Dificultad del juego - float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad - struct options_t *mOptions; // Variable con todas las variables de las opciones del programa - Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones + Uint32 mHiScore; // Puntuación máxima + bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima + section_t mSection; // Seccion actual dentro del juego + stage_t mStage[10]; // Variable con los datos de cada pantalla + Uint8 mCurrentStage; // Indica la fase actual + Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage + float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto + float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto + Uint16 mDeathCounter; // Contador para la animación de muerte del jugador + Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador + Uint8 mMenaceCurrent; // Nivel de amenaza actual + Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos + bool mTimeStopped; // Indica si el tiempo está detenido + Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido + Uint8 mRemainingExplosions; // Cantidad de explosiones restantes + Uint16 mRemainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes + bool mExplosionTime; // Indica si las explosiones estan en marcha + Uint32 mCounter; // Contador para el juego + Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos + SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes + Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados + Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir; + int mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero + float mEnemySpeed; // Velocidad a la que se mueven los enemigos + float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar + effect_t mEffect; // Variable para gestionar los efectos visuales + helper_t mHelper; // Variable para gestionar las ayudas + bool mPowerBallEnabled; // Indica si hay una powerball ya activa + Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra + bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego + Uint8 mPostFade; // Qué hacer al acabar el fade + float mSin[360]; // Vector con los valores del seno para 360 grados + bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla + int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos + Uint8 mDifficulty; // Dificultad del juego + float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad + struct options_t *mOptions; // Variable con todas las variables de las opciones del programa + Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones + enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas + enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas - struct demo_t - { - bool enabled; // Indica si está activo el modo demo - bool recording; // Indica si está activado el modo para grabar la demo - Uint16 counter; // Contador para el modo demo - demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo - demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo - }; - demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo - - struct debug_t - { - bool enabled; // Indica si se va a mostrar la información de debug - Uint8 enemySet; // Escoge el set enemigo a generar - Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo - float hudW, hudH; // Multiplica el tamaño del hud de debug; - }; - debug_t mDebug; + demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo + debug_t mDebug; // Variable con las opciones de debug // Inicializa el vector con los valores del seno void initSin(); diff --git a/source/ifdefs.h b/source/ifdefs.h deleted file mode 100644 index ee12c82..0000000 --- a/source/ifdefs.h +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#ifdef __linux__ -#ifdef __MIPSEL__ -#include "SDL.h" -#else -#include -#endif -#endif - -#define UNUSED \ No newline at end of file diff --git a/source/input.h b/source/input.h index 13dafa2..5910feb 100644 --- a/source/input.h +++ b/source/input.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include #include diff --git a/source/instructions.cpp b/source/instructions.cpp index 00eb58c..795db90 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,8 +1,4 @@ #include "instructions.h" -#ifdef __MIPSEL__ -#include -#include -#endif const Uint8 SELF = 0; diff --git a/source/instructions.h b/source/instructions.h index dc0b3e7..bc8c4e8 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -1,6 +1,7 @@ #pragma once + +#include #include "const.h" -#include "ifdefs.h" #include "jail_audio.h" #include "screen.h" #include "sprite.h" diff --git a/source/intro.cpp b/source/intro.cpp index b993c0d..4a525fa 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,8 +1,4 @@ #include "intro.h" -#ifdef __MIPSEL__ -#include -#include -#endif // Constructor Intro::Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang) diff --git a/source/intro.h b/source/intro.h index d4182e8..dd320c8 100644 --- a/source/intro.h +++ b/source/intro.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "const.h" #include "utils.h" #include "screen.h" @@ -52,6 +53,9 @@ private: Uint8 mEvents[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro JA_Music mMusic; // Musica para la intro + // Carga los recursos + bool loadMedia(); + public: // Constructor Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang); @@ -62,9 +66,6 @@ public: // Inicializa las variables void init(); - // Carga los recursos - bool loadMedia(); - // Bucle principal section_t run(); }; diff --git a/source/item.h b/source/item.h index 4515cac..8707dcc 100644 --- a/source/item.h +++ b/source/item.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "animatedsprite.h" #include "utils.h" @@ -19,15 +20,15 @@ class Item { private: - float mPosX; // Posición X del objeto - float mPosY; // Posición Y del objeto - Uint8 mWidth; // Ancho del objeto - Uint8 mHeight; // Alto del objeto - float mVelX; // Velocidad en el eje X - float mVelY; // Velocidad en el eje Y - float mAccelX; // Aceleración en el eje X - float mAccelY; // Aceleración en el eje Y - bool mFloorCollision; // Indica si el objeto colisiona con el suelo + float mPosX; // Posición X del objeto + float mPosY; // Posición Y del objeto + Uint8 mWidth; // Ancho del objeto + Uint8 mHeight; // Alto del objeto + float mVelX; // Velocidad en el eje X + float mVelY; // Velocidad en el eje Y + float mAccelX; // Aceleración en el eje X + float mAccelY; // Aceleración en el eje Y + bool mFloorCollision; // Indica si el objeto colisiona con el suelo AnimatedSprite *mSprite; // Sprite con los graficos del objeto @@ -39,6 +40,8 @@ private: void shiftColliders(); public: + Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente + // Constructor Item(); @@ -93,9 +96,6 @@ public: // Obtiene el circulo de colisión circle_t &getCollider(); - // Temporizador con el tiempo que el objeto está presente - Uint16 mTimeToLive; - // Informa si el objeto ha colisionado con el suelo bool floorCollision(); }; diff --git a/source/jail_audio.cpp b/source/jail_audio.cpp index e22b355..fc23241 100644 --- a/source/jail_audio.cpp +++ b/source/jail_audio.cpp @@ -1,6 +1,7 @@ -#ifndef __MIPSEL__ #include "jail_audio.h" #include "stb_vorbis.c" +#include +#include #define JA_MAX_SIMULTANEOUS_CHANNELS 5 @@ -30,16 +31,17 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS]; int JA_freq {48000}; SDL_AudioFormat JA_format {AUDIO_S16}; Uint8 JA_channels {2}; +int JA_volume = 128; void audioCallback(void * userdata, uint8_t * stream, int len) { SDL_memset(stream, 0, len); if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) { const int size = SDL_min(len, current_music->samples*2-current_music->pos); - SDL_memcpy(stream, current_music->output+current_music->pos, size); + SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume); current_music->pos += size/2; if (size < len) { if (current_music->times != 0) { - SDL_memcpy(stream+size, current_music->output, len-size); + SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume); current_music->pos = (len-size)/2; if (current_music->times > 0) current_music->times--; } else { @@ -52,11 +54,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { if (channels[i].state == JA_CHANNEL_PLAYING) { const int size = SDL_min(len, channels[i].sound->length - channels[i].pos); - SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, 64); + SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2); channels[i].pos += size; if (size < len) { if (channels[i].times != 0) { - SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, 64); + SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2); channels[i].pos = len-size; if (channels[i].times > 0) channels[i].times--; } else { @@ -79,7 +81,19 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) { JA_Music JA_LoadMusic(const char* filename) { int chan, samplerate; JA_Music music = new JA_Music_t(); - music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output); + + // [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid. + FILE *f = fopen(filename, "rb"); + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + Uint8 *buffer = (Uint8*)malloc(fsize + 1); + fread(buffer, fsize, 1, f); + fclose(f); + music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output); + free(buffer); + // [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert +// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output); SDL_AudioCVT cvt; SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq); @@ -134,6 +148,13 @@ void JA_DeleteMusic(JA_Music music) { delete music; } +JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) { + JA_Sound sound = new JA_Sound_t(); + sound->buffer = buffer; + sound->length = length; + return sound; +} + JA_Sound JA_LoadSound(const char* filename) { JA_Sound sound = new JA_Sound_t(); SDL_AudioSpec wavSpec; @@ -210,4 +231,8 @@ JA_Channel_state JA_GetChannelState(const int channel) { if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; return channels[channel].state; } -#endif + +int JA_SetVolume(int volume) { + JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume; + return JA_volume; +} \ No newline at end of file diff --git a/source/jail_audio.h b/source/jail_audio.h index 44b1d80..2a2fc9f 100644 --- a/source/jail_audio.h +++ b/source/jail_audio.h @@ -1,5 +1,5 @@ #pragma once -#include "ifdefs.h" +#include enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED }; enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED }; @@ -17,6 +17,7 @@ void JA_StopMusic(); JA_Music_state JA_GetMusicState(); void JA_DeleteMusic(JA_Music music); +JA_Sound JA_NewSound(Uint8* buffer, Uint32 length); JA_Sound JA_LoadSound(const char* filename); int JA_PlaySound(JA_Sound sound, const int loop = 0); void JA_PauseChannel(const int channel); @@ -24,3 +25,5 @@ void JA_ResumeChannel(const int channel); void JA_StopChannel(const int channel); JA_Channel_state JA_GetChannelState(const int channel); void JA_DeleteSound(JA_Sound sound); + +int JA_SetVolume(int volume); \ No newline at end of file diff --git a/source/jail_audio_mipsel.cpp b/source/jail_audio_mipsel.cpp deleted file mode 100644 index 4019af5..0000000 --- a/source/jail_audio_mipsel.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#ifdef __MIPSEL__ -#include "jail_audio.h" -#include - -struct JA_Sound_t { - Mix_Chunk *mix_chunk; -}; - -struct JA_Music_t { - Mix_Music* mix_music; -}; - -JA_Music current_music{NULL}; - -void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) { - Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024); - Mix_AllocateChannels(8); -} - -JA_Music JA_LoadMusic(const char* filename) { - int chan, samplerate; - JA_Music music = new JA_Music_t(); - music->mix_music = Mix_LoadMUS(filename); - return music; -} - -void JA_PlayMusic(JA_Music music, const int loop) { - if (current_music == music) return; - if (current_music != NULL) { - Mix_HaltMusic(); - } - current_music = music; - Mix_PlayMusic(music->mix_music, loop); -} - -void JA_PauseMusic() { - Mix_PauseMusic(); -} - -void JA_ResumeMusic() { - Mix_ResumeMusic(); -} - -void JA_StopMusic() { - Mix_HaltMusic(); -} - -JA_Music_state JA_GetMusicState() { - if (current_music == NULL) return JA_MUSIC_INVALID; - if (Mix_PausedMusic()) { - return JA_MUSIC_PAUSED; - } else if (Mix_PlayingMusic()) { - return JA_MUSIC_PLAYING; - } else { - return JA_MUSIC_STOPPED; - } -} - -void JA_DeleteMusic(JA_Music music) { - if (current_music == music) { - Mix_HaltMusic(); - current_music = NULL; - } - Mix_FreeMusic(music->mix_music); - delete music; -} - -JA_Sound JA_LoadSound(const char* filename) { - JA_Sound sound = new JA_Sound_t(); - sound->mix_chunk = Mix_LoadWAV(filename); - return sound; -} - -int JA_PlaySound(JA_Sound sound, const int loop) { - int channel = Mix_PlayChannel(-1, sound->mix_chunk, loop); - return channel; -} - -void JA_DeleteSound(JA_Sound sound) { - Mix_FreeChunk(sound->mix_chunk); - delete sound; -} - -void JA_PauseChannel(const int channel) { - Mix_Pause(channel); -} - -void JA_ResumeChannel(const int channel) { - Mix_Resume(channel); -} - -void JA_StopChannel(const int channel) { - Mix_HaltChannel(channel); -} - -JA_Channel_state JA_GetChannelState(const int channel) { - if (Mix_Paused(channel)) { - return JA_CHANNEL_PAUSED; - } else if (Mix_Playing(channel)) { - return JA_CHANNEL_PLAYING; - } else { - return JA_CHANNEL_FREE; - } -} - -#endif diff --git a/source/lang.h b/source/lang.h index a57ab99..f7adc30 100644 --- a/source/lang.h +++ b/source/lang.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include #ifndef LANG_H diff --git a/source/logo.cpp b/source/logo.cpp index e7489c3..b4dbd2d 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,8 +1,4 @@ #include "logo.h" -#ifdef __MIPSEL__ -#include -#include -#endif #define INIT_FADE 100 #define END_LOGO 200 diff --git a/source/logo.h b/source/logo.h index da8a545..e95222b 100644 --- a/source/logo.h +++ b/source/logo.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "const.h" #include "utils.h" #include "sprite.h" diff --git a/source/ltexture.h b/source/ltexture.h index e533620..c03a3aa 100644 --- a/source/ltexture.h +++ b/source/ltexture.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include #include diff --git a/source/menu.h b/source/menu.h index 3b2c477..6f9e229 100644 --- a/source/menu.h +++ b/source/menu.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "sprite.h" #include "text.h" #include "input.h" diff --git a/source/movingsprite.h b/source/movingsprite.h index 5e47874..de4e88d 100644 --- a/source/movingsprite.h +++ b/source/movingsprite.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "sprite.h" #ifndef MOVINGSPRITE_H diff --git a/source/player.h b/source/player.h index 1c1f5fa..6f5ca29 100644 --- a/source/player.h +++ b/source/player.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "utils.h" #include "input.h" #include "animatedsprite.h" diff --git a/source/screen.h b/source/screen.h index a7aa31d..0bcd5b0 100644 --- a/source/screen.h +++ b/source/screen.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "utils.h" #ifndef SCREEN_H diff --git a/source/smartsprite.h b/source/smartsprite.h index 12463a8..48c9de3 100644 --- a/source/smartsprite.h +++ b/source/smartsprite.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "utils.h" #include "animatedsprite.h" diff --git a/source/sprite.h b/source/sprite.h index b0d0b3e..bef20a5 100644 --- a/source/sprite.h +++ b/source/sprite.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "ltexture.h" #ifndef SPRITE_H diff --git a/source/text.h b/source/text.h index ccadef2..f7ebfae 100644 --- a/source/text.h +++ b/source/text.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "sprite.h" #include "utils.h" diff --git a/source/title.cpp b/source/title.cpp index b7ceff9..6d37852 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,8 +1,4 @@ #include "title.h" -#ifdef __MIPSEL__ -#include -#include -#endif // Constructor Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, std::string *fileList, options_t *options, Lang *lang) @@ -516,10 +512,6 @@ void Title::updateMenuLabels() // Aplica las opciones de menu seleccionadas void Title::applyOptions() { - //SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode); - //if (mOptions->fullScreenMode == 0) - // SDL_SetWindowSize(mWindow, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize); - //SDL_RenderSetLogicalSize(mRenderer, mOptions->screenWidth, mOptions->screenHeight); mScreen->setVideoMode(mOptions->fullScreenMode); mLang->setLang(mOptions->language); diff --git a/source/title.h b/source/title.h index 101d885..6d8d788 100644 --- a/source/title.h +++ b/source/title.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "const.h" #include "utils.h" #include "sprite.h" diff --git a/source/utils.h b/source/utils.h index 0669bd4..51fe105 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include "ltexture.h" #include diff --git a/source/writer.h b/source/writer.h index 0027995..d816542 100644 --- a/source/writer.h +++ b/source/writer.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "sprite.h" #include "text.h"