From bcb012fc65e7e3ac979122deb5dd77487f9b51b0 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Thu, 1 Apr 2021 13:15:34 +0200 Subject: [PATCH] Basic opendingux support --- .gitignore | 1 + default.gcw0.desktop | 9 +++ generate_opendingux | 7 +++ icon.png | Bin 0 -> 4047 bytes source/gamedirector.cpp | 32 +++++++++-- source/ifdefs.h | 6 +- source/jail_audio.cpp | 4 +- source/jail_audio_mipsel.cpp | 106 +++++++++++++++++++++++++++++++++++ 8 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 default.gcw0.desktop create mode 100755 generate_opendingux create mode 100644 icon.png create mode 100644 source/jail_audio_mipsel.cpp diff --git a/.gitignore b/.gitignore index 9544ef7..af6d928 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ scripts todo.txt data/config.bin data/score.bin +*.opk diff --git a/default.gcw0.desktop b/default.gcw0.desktop new file mode 100644 index 0000000..8d0c767 --- /dev/null +++ b/default.gcw0.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Coffee Crisis +Comment=Coffee Crisis +Icon=icon +Exec=bin/coffee_crisis +Categories=games;Game;SDL; +Terminal=false diff --git a/generate_opendingux b/generate_opendingux new file mode 100755 index 0000000..5c3a7fe --- /dev/null +++ b/generate_opendingux @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +cd source +/opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ -g -D_GCWZERO -O2 -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lSDL2_mixer -std=c++11 *.cpp -o coffee_crisis_gcw0 +mv coffee_crisis_gcw0 ../bin/coffee_crisis +cd .. +/opt/gcw0-toolchain/usr/bin/mksquashfs ./default.gcw0.desktop ./icon.png ./bin ./data ./media coffee_crisis.opk -all-root -noappend -no-exports -no-xattrs diff --git a/icon.png b/icon.png new file mode 100644 index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yq(_C?Xv>?@(#+6 zjs&}d^E*$ZKPr9wgW|L+#v*LlzLd*{t{K+N(N_RK35Xq08}G zMa55FY``7UGip4Vf;nJrmpCV?p{ViI?e89RM3OhB&N@45IVMqedlH3#U0(_)tPEVy zIU1p!If{iva6YshV}4Y)1n;47o6%~y*?{6-T;qRDChr}8<3 zveWzjs2RF$?D1#&t97j*GFm5XS-CaVPlu|N(Di!TSaE-f-G#X~v#q=(VO^QBZ;dmx v%pW9O+jq!8P`%RlU6O-lr|yybnvq3@8(JwGR@y`5za%erU$+ykVc-1+=F_@h literal 0 HcmV?d00001 diff --git a/source/gamedirector.cpp b/source/gamedirector.cpp index 5a062da..26c5a89 100644 --- a/source/gamedirector.cpp +++ b/source/gamedirector.cpp @@ -2,6 +2,10 @@ #include "utils.h" #include "gamedirector.h" #include +#ifdef __MIPSEL __ +#include +#include +#endif const Uint8 *keystates; float mSin[360]; // Vector con los valores del seno para 360 grados @@ -41,6 +45,14 @@ GameDirector::GameDirector(std::string path) // Inicializa JailAudio initJailAudio(); +#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 + // Carga recursos loadMediaProg(); loadScoreFile(); @@ -129,9 +141,15 @@ void GameDirector::initProg() mProg.keyboard.right = SDL_SCANCODE_RIGHT; mProg.keyboard.accept = SDL_SCANCODE_RETURN; mProg.keyboard.cancel = SDL_SCANCODE_ESCAPE; +#ifdef __MIPSEL__ + mProg.keyboard.fire = SDL_SCANCODE_SPACE; + mProg.keyboard.fireLeft = SDL_SCANCODE_LSHIFT; + mProg.keyboard.fireRight = SDL_SCANCODE_LCTRL; +#else mProg.keyboard.fire = SDL_SCANCODE_W; mProg.keyboard.fireLeft = SDL_SCANCODE_Q; mProg.keyboard.fireRight = SDL_SCANCODE_E; +#endif mProg.keyboard.pause = SDL_SCANCODE_ESCAPE; mProg.keyboard.escape = SDL_SCANCODE_ESCAPE; @@ -1132,9 +1150,11 @@ void GameDirector::quitGame() void GameDirector::setFileList() { // Ficheros binarios - mBinFile[BINFILE_SCORE].file = mProg.executablePath + "/" + "../data/score.bin"; - mBinFile[BINFILE_DEMO].file = mProg.executablePath + "/" + "../data/demo.bin"; - mBinFile[BINFILE_CONFIG].file = mProg.executablePath + "/" + "../data/config.bin"; +#ifdef __MIPSEL__ + mBinFile[BINFILE_SCORE].file = "/media/data/local/home/.coffee_crisis/score.bin"; + mBinFile[BINFILE_DEMO].file = "/media/data/local/home/.coffee_crisis/demo.bin"; + mBinFile[BINFILE_CONFIG].file = "/media/data/local/home/.coffee_crisis/config.bin"; +#endif // Musicas mMusic[MUSIC_INTRO].file = mProg.executablePath + "/" + "../media/music/intro.ogg"; @@ -4248,7 +4268,7 @@ void GameDirector::runIntro() if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { // Reproduce la música - JA_PlayMusic(mMusic[MUSIC_INTRO].music, false); + JA_PlayMusic(mMusic[MUSIC_INTRO].music, 0); } while ((mProg.section == PROG_SECTION_INTRO) && (!exit())) @@ -4543,7 +4563,7 @@ void GameDirector::runTitle(Uint8 subsection) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { // Reproduce la música - JA_PlayMusic(mMusic[MUSIC_TITLE].music, true); + JA_PlayMusic(mMusic[MUSIC_TITLE].music, -1); } // Calcula la lógica de los objetos @@ -4745,7 +4765,7 @@ void GameDirector::runGame() { // Reproduce la música if (mGame.player->isAlive()) - JA_PlayMusic(mMusic[MUSIC_PLAYING].music, true); + JA_PlayMusic(mMusic[MUSIC_PLAYING].music, -1); } // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego diff --git a/source/ifdefs.h b/source/ifdefs.h index 14980c7..a9322d8 100644 --- a/source/ifdefs.h +++ b/source/ifdefs.h @@ -11,7 +11,11 @@ #endif #ifdef __linux__ -#include "/usr/include/SDL2/SDL.h" +#ifdef __MIPSEL__ +#include "SDL.h" +#else +#include +#endif #endif #define UNUSED \ No newline at end of file diff --git a/source/jail_audio.cpp b/source/jail_audio.cpp index a4d379f..e22b355 100644 --- a/source/jail_audio.cpp +++ b/source/jail_audio.cpp @@ -1,6 +1,6 @@ +#ifndef __MIPSEL__ #include "jail_audio.h" #include "stb_vorbis.c" -//#include #define JA_MAX_SIMULTANEOUS_CHANNELS 5 @@ -210,4 +210,4 @@ 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 diff --git a/source/jail_audio_mipsel.cpp b/source/jail_audio_mipsel.cpp new file mode 100644 index 0000000..4544cdb --- /dev/null +++ b/source/jail_audio_mipsel.cpp @@ -0,0 +1,106 @@ +#ifdef __MIPSEL__ +#include "jail_audio.h" +#include "SDL_mixer.h" + +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