update to compile apk

This commit is contained in:
Théophyl Hoguet committed 2022-04-07 17:15:54 +02:00
1 parent e7ed64efa0
commit 7fb4e12454
4 files changed
+101 -104

No files matched your search

+10 -14
View File
@@ -2,20 +2,16 @@
cd jni
wget -c https://www.libsdl.org/release/SDL2-2.0.20.zip
unzip SDL2-2.0.20.zip
mv SDL2-2.0.20 SDL
wget -c https://www.libsdl.org/release/SDL2-2.0.5.zip
unzip SDL2-2.0.5.zip
mv SDL2-2.0.5 SDL
wget -c https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.18.zip
unzip SDL2_ttf-2.0.18.zip
mv SDL2_ttf-2.0.18 SDL_ttf
wget -c https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.zip
unzip SDL2_ttf-2.0.14.zip
mv SDL2_ttf-2.0.14 SDL_ttf
wget -c https://libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.zip
unzip SDL2_mixer-2.0.4.zip
mv SDL2_mixer-2.0.4 SDL_mixer
wget -c https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.zip
unzip SDL2_image-2.0.1.zip
mv SDL2_image-2.0.1 SDL_image
wget -c https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.zip
unzip SDL2_image-2.0.5.zip
mv SDL2_image-2.0.5 SDL_image
cd ..
cd ..
+2 -2
View File
@@ -530,8 +530,8 @@ static uint nb_neigh_lightbulbs(cgame g, uint i, uint j) {
assert(g);
int nb_rows = game_nb_rows(g);
int nb_cols = game_nb_cols(g);
assert(i < nb_rows);
assert(j < nb_cols);
assert(i < (uint)nb_rows);
assert(j < (uint)nb_cols);
int i_up = i - 1;
int i_down = i + 1;
+3 -3
View File
@@ -2,7 +2,7 @@
#include <SDL.h>
#include <SDL_image.h> // required to load transparent texture from PNG
#include <SDL_mixer.h>
// #include <SDL_mixer.h>
#include <SDL_ttf.h> // required to use TTF fonts
#include <stdbool.h>
#include <stdio.h>
@@ -18,8 +18,8 @@ int main(int argc, char* argv[]) {
ERROR("Error: IMG_Init PNG (%s)", SDL_GetError());
if (TTF_Init() != 0)
ERROR("Error: TTF_Init (%s)", SDL_GetError());
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) < 0)
ERROR("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
// if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) < 0)
// ERROR("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
/* create window and renderer */
SDL_Window* win =
+86 -85
View File
@@ -3,11 +3,12 @@
#include "model.h"
#include <SDL.h>
#include <SDL_image.h> // required to load transparent texture from PNG
#include <SDL_mixer.h> // required to play musics
#include <SDL_ttf.h> // required to use TTF fonts
// #include <SDL_mixer.h> // required to play musics
#include <SDL_ttf.h> // required to use TTF fonts
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "game.h"
#include "game_aux.h"
#include "game_ext.h"
@@ -22,16 +23,16 @@
#define MUTED_PRESSED "muted_pressed.png"
#define NOTMUTED "notmuted.png"
#define NOTMUTED_PRESSED "notmuted_pressed.png"
#define LB1 "lb1.mp3"
#define LB2 "lb2.mp3"
#define LB3 "lb3.mp3"
#define ERR1 "error1.mp3"
#define ERR2 "error2.mp3"
#define ERR3 "error3.mp3"
#define MARK1 "mark1.wav"
#define MARK2 "mark2.wav"
#define MARK3 "mark3.wav"
#define WIN "win.mp3"
// #define LB1 "lb1.mp3"
// #define LB2 "lb2.mp3"
// #define LB3 "lb3.mp3"
// #define ERR1 "error1.mp3"
// #define ERR2 "error2.mp3"
// #define ERR3 "error3.mp3"
// #define MARK1 "mark1.wav"
// #define MARK2 "mark2.wav"
// #define MARK3 "mark3.wav"
// #define WIN "win.mp3"
#define FONT "Roboto-Regular.ttf"
#define NB_MUSIC 10
@@ -110,10 +111,10 @@ struct Env_t {
SDL_Rect* rec_save; // ^^
SDL_Rect* rec_mute; // ^^
Mix_Music** lb_music; // array of three musics for each action
Mix_Music** err_music; // Same
Mix_Music** mark_music; // Same
Mix_Music* win_music; // Only one music when wining
// Mix_Music** lb_music; // array of three musics for each action
// Mix_Music** err_music; // Same
// Mix_Music** mark_music; // Same
// Mix_Music* win_music; // Only one music when wining
bool pressed_restart; // used to update color of the button when the mouse is overing it
bool pressed_undo; // ^^
@@ -125,9 +126,9 @@ struct Env_t {
bool muted; // when the sound is mute or not
bool win; // used to avoid music being played multiple times
uint lb_music_cpt; // used to altern musics
uint err_music_cpt; // ^^
uint mark_music_cpt; // ^^
// uint lb_music_cpt; // used to altern musics
// uint err_music_cpt; // ^^
// uint mark_music_cpt; // ^^
int i;
int j;
@@ -177,36 +178,36 @@ void init_malloc(void** tab[], unsigned long size_to_allocate[], uint size_tab)
* @param nb_music total number of music to allocate
* @param nb_music_per_array number of music per array (all array have the same amount of music)
*/
void init_musics(Mix_Music*** music_to_load[], char* path_to_musics[], uint nb_music, uint nb_music_per_array) {
for (uint index_music_to_load = 0; index_music_to_load < nb_music / nb_music_per_array; index_music_to_load++) {
// allocate the array for the musics
*(music_to_load[index_music_to_load]) = malloc(sizeof(Mix_Music*) * nb_music_per_array);
for (uint i = 0; i < nb_music_per_array; i++) {
// allocate the musics in the array
(*(music_to_load[index_music_to_load]))[i] = Mix_LoadMUS(path_to_musics[index_music_to_load * nb_music_per_array + i]);
if ((*(music_to_load[index_music_to_load]))[i] == NULL)
ERROR("Cannot load music %s\n", path_to_musics[index_music_to_load * nb_music_per_array + i]);
}
}
}
// void init_musics(Mix_Music*** music_to_load[], char* path_to_musics[], uint nb_music, uint nb_music_per_array) {
// for (uint index_music_to_load = 0; index_music_to_load < nb_music / nb_music_per_array; index_music_to_load++) {
// // allocate the array for the musics
// *(music_to_load[index_music_to_load]) = malloc(sizeof(Mix_Music*) * nb_music_per_array);
// for (uint i = 0; i < nb_music_per_array; i++) {
// // allocate the musics in the array
// (*(music_to_load[index_music_to_load]))[i] = Mix_LoadMUS(path_to_musics[index_music_to_load * nb_music_per_array + i]);
// if ((*(music_to_load[index_music_to_load]))[i] == NULL)
// ERROR("Cannot load music %s\n", path_to_musics[index_music_to_load * nb_music_per_array + i]);
// }
// }
// }
Env* init(SDL_Renderer* ren, int argc, char* argv[]) {
Env* env = malloc(sizeof(struct Env_t));
Mix_Music*** music_to_load[] = {&(env->lb_music), &(env->err_music), &(env->mark_music)};
// Mix_Music*** music_to_load[] = {&(env->lb_music), &(env->err_music), &(env->mark_music)};
#ifdef __ANDROID__
// WIP
char* path_to_get[NB_MUSIC] = {LB1, LB2, LB3, ERR1, ERR2, ERR3, MARK1, MARK2, MARK3, WIN};
char* paths[NB_MUSIC];
const char* dir = SDL_AndroidGetInternalStoragePath();
char new_path[1024];
for (uint i = 0; i < NB_MUSIC; i++) {
paths[i] = malloc(sizeof(char) * 1024);
sprintf(new_path, "%s/%s", dir, path_to_get[i]);
copy_asset(path_to_get[i], new_path);
strcpy(paths[i], new_path);
}
// char* path_to_get[NB_MUSIC] = {LB1, LB2, LB3, ERR1, ERR2, ERR3, MARK1, MARK2, MARK3, WIN};
// char* paths[NB_MUSIC];
// const char* dir = SDL_AndroidGetInternalStoragePath();
// char new_path[1024];
// for (uint i = 0; i < NB_MUSIC; i++) {
// paths[i] = malloc(sizeof(char) * 1024);
// sprintf(new_path, "%s/%s", dir, path_to_get[i]);
// copy_asset(path_to_get[i], new_path);
// strcpy(paths[i], new_path);
// }
#else
char* path_musics[NB_MUSIC] = {LB1, LB2, LB3, ERR1, ERR2, ERR3, MARK1, MARK2, MARK3, WIN};
// char* path_musics[NB_MUSIC] = {LB1, LB2, LB3, ERR1, ERR2, ERR3, MARK1, MARK2, MARK3, WIN};
#endif
// init bool
env->pressed_restart = false;
@@ -283,25 +284,25 @@ Env* init(SDL_Renderer* ren, int argc, char* argv[]) {
if (!env->mute[3])
ERROR("IMG_LoadTexture: %s\n", MUTED_PRESSED);
// load the musics
init_musics(music_to_load, path_musics, NB_MUSIC, 3);
// init value
env->lb_music_cpt = 0;
env->err_music_cpt = 0;
env->mark_music_cpt = 0;
// init_musics(music_to_load, path_musics, NB_MUSIC, 3);
// // init value
// env->lb_music_cpt = 0;
// env->err_music_cpt = 0;
// env->mark_music_cpt = 0;
env->i = -1;
env->j = -1;
// Music win
env->win_music = Mix_LoadMUS(WIN);
if (env->win_music == NULL)
ERROR("Cannot load music %s\n", WIN);
// env->win_music = Mix_LoadMUS(WIN);
// if (env->win_music == NULL)
// ERROR("Cannot load music %s\n", WIN);
env->win = false;
#ifdef __ANDROID__
// WIP
for (uint i = 0; i < NB_MUSIC; i++) {
free(paths[i]);
}
// for (uint i = 0; i < NB_MUSIC; i++) {
// free(paths[i]);
// }
#endif
/*Creation of the differents textures and place them in env*/
@@ -331,7 +332,7 @@ Env* init(SDL_Renderer* ren, int argc, char* argv[]) {
tab_textures_double[i][j] = render_blended_text(ren, color_of_texts[cpt++], tab_texts_double[i]);
}
}
Mix_VolumeMusic(MIX_MAX_VOLUME);
// Mix_VolumeMusic(MIX_MAX_VOLUME);
return env;
}
@@ -522,20 +523,20 @@ void render(SDL_Window* win, SDL_Renderer* ren, Env* env) {
/**
* @brief play only one music depend of parms (error priors others)
*/
void play_Music(Env* env, bool lightbulb, bool error, bool mark) {
if (!game_is_over(env->g)) {
if (error && game_has_error_general_intero(env->g)) {
Mix_PlayMusic(env->err_music[env->err_music_cpt % 3], 0);
env->err_music_cpt++;
} else if (lightbulb) {
Mix_PlayMusic(env->lb_music[env->lb_music_cpt % 3], 0);
env->lb_music_cpt++;
} else if (mark) {
Mix_PlayMusic(env->mark_music[env->mark_music_cpt % 3], 0);
env->mark_music_cpt++;
}
}
}
// void play_Music(Env* env, bool lightbulb, bool error, bool mark) {
// if (!game_is_over(env->g)) {
// if (error && game_has_error_general_intero(env->g)) {
// Mix_PlayMusic(env->err_music[env->err_music_cpt % 3], 0);
// env->err_music_cpt++;
// } else if (lightbulb) {
// Mix_PlayMusic(env->lb_music[env->lb_music_cpt % 3], 0);
// env->lb_music_cpt++;
// } else if (mark) {
// Mix_PlayMusic(env->mark_music[env->mark_music_cpt % 3], 0);
// env->mark_music_cpt++;
// }
// }
// }
void ToggleFullscreen(SDL_Window* Window) {
Uint32 FullscreenFlag = SDL_WINDOW_FULLSCREEN;
@@ -547,20 +548,20 @@ void ToggleFullscreen(SDL_Window* Window) {
void play_light(uint i, uint j, Env* env) {
if (game_is_blank(env->g, i, j) || game_is_marked(env->g, i, j)) {
game_play_move(env->g, i, j, S_LIGHTBULB);
play_Music(env, true, true, false);
// play_Music(env, true, true, false);
} else if (game_is_lightbulb(env->g, i, j)) {
game_play_move(env->g, i, j, S_BLANK);
play_Music(env, true, true, false);
// play_Music(env, true, true, false);
}
}
void play_mark(uint i, uint j, Env* env) {
if (game_is_blank(env->g, i, j) || game_is_lightbulb(env->g, i, j)) {
game_play_move(env->g, i, j, S_MARK);
play_Music(env, false, true, true);
// play_Music(env, false, true, true);
} else if (game_is_marked(env->g, i, j)) {
game_play_move(env->g, i, j, S_BLANK);
play_Music(env, false, true, true);
// play_Music(env, false, true, true);
}
}
@@ -590,7 +591,7 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb
return true;
// test if game is over (env->win used to play win music only once)
if (game_is_over(env->g) && !env->win) {
Mix_PlayMusic(env->win_music, 1);
// Mix_PlayMusic(env->win_music, 1);
env->win = true;
} else if (env->win && !game_is_over(env->g)) {
env->win = false;
@@ -637,7 +638,7 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb
break;
case SDLK_m: // M to mute
env->muted = !env->muted;
Mix_VolumeMusic(env->muted ? 0 : 128);
// Mix_VolumeMusic(env->muted ? 0 : 128);
update_pressed(env, &(env->pressed_mute));
break;
case SDLK_LEFT:
@@ -757,7 +758,7 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb
(*nb_coups) = 0;
} else if (SDL_PointInRect(&mouse, env->rec_mute)) {
env->muted = env->muted ? 0 : 1;
Mix_VolumeMusic(env->muted ? 0 : 128);
// Mix_VolumeMusic(env->muted ? 0 : 128);
} else if (SDL_PointInRect(&mouse, env->rec_save)) {
game_save(env->g, "save.txt");
update_pressed(env, &(env->pressed_savED));
@@ -819,16 +820,16 @@ void clean(Env* env) {
SDL_Rect* free_tab[] = {env->rec_game, env->rec_redo, env->rec_restart, env->rec_solve, env->rec_undo};
freeall(free_tab, sizeof(free_tab) / sizeof(free_tab[0]));
// free every musics
for (uint i = 0; i < NB_MUSIC_PER_ARRAY; i++) {
Mix_FreeMusic(env->lb_music[i]);
Mix_FreeMusic(env->mark_music[i]);
Mix_FreeMusic(env->err_music[i]);
}
Mix_FreeMusic(env->win_music);
// for (uint i = 0; i < NB_MUSIC_PER_ARRAY; i++) {
// Mix_FreeMusic(env->lb_music[i]);
// Mix_FreeMusic(env->mark_music[i]);
// Mix_FreeMusic(env->err_music[i]);
// }
// Mix_FreeMusic(env->win_music);
// free the array
free(env->lb_music);
free(env->mark_music);
free(env->err_music);
// free(env->lb_music);
// free(env->mark_music);
// free(env->err_music);
free(env);
}