diff --git a/CMakeLists.txt b/CMakeLists.txt index c3fd472..c8280e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,9 @@ if(ANDROID) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") add_definitions(-D__ANDROID__) + list(APPEND raylib_sources ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) + include_directories(${ANDROID_NDK}/sources/android/native_app_glue) + add_library(${PROJECT_NAME} SHARED ${SOURCES}) target_link_libraries(${PROJECT_NAME} raylib zlibstatic json-c android log) elseif(UNIX AND NOT ANDROID) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 936ab28..fc47e87 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,6 +2,10 @@ + + + + activity->internalDataPath); + strcat(config_path, "/"); +#else strcat(config_path, GetApplicationDirectory()); +#endif strcat(config_path, CONFIG_NAME); if (FileExists(config_path)) { @@ -80,6 +85,7 @@ void save_config(w_config *config) { return; config_path[0] = 0; + strcat(config_path, GetApplicationDirectory()); strcat(config_path, CONFIG_NAME); @@ -111,12 +117,6 @@ void save_config(w_config *config) { json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY_TAB); SaveFileText(config_path, (char *)data); - json_object_put(js_fullscreen); - json_object_put(js_msaa4x); - json_object_put(js_vsync); - json_object_put(js_width); - json_object_put(js_height); - json_object_put(js_max_fps); json_object_put(root); free(config_path); } diff --git a/src/core/utils/camera.c b/src/core/utils/camera.c index 6f30c0d..7115bc9 100644 --- a/src/core/utils/camera.c +++ b/src/core/utils/camera.c @@ -45,9 +45,13 @@ void destroy_camera(w_camera *camera) { LOG("camera (null) already destroyed"); return; } + +#if defined(WISPY_LINUX) || defined(WISPY_WINDOWS) if (camera->matrix != NULL) { free(camera->matrix); } +#endif + free(camera); } diff --git a/src/screens/game/game.c b/src/screens/game/game.c index 48d30ce..c98329f 100644 --- a/src/screens/game/game.c +++ b/src/screens/game/game.c @@ -46,7 +46,7 @@ void game_screen(w_state *state) { return; } - w_guiaction *break_button = create_action(ctx, VEC(RENDER_W - PERCENT_W(0.05), PERCENT_H(0.75)), + w_guiiconbutton *break_button = create_iconbutton(ctx, VEC(RENDER_W - PERCENT_W(0.05), PERCENT_H(0.75)), PERCENT_W(0.05), break_icon); if (break_button == NULL) { destroy_bridge(td); @@ -57,13 +57,13 @@ void game_screen(w_state *state) { return; } - w_guiaction *jump_button = create_action(ctx, VEC(PERCENT_W(0.85), RENDER_H - PERCENT_H(0.05)), + w_guiiconbutton *jump_button = create_iconbutton(ctx, VEC(PERCENT_W(0.85), RENDER_H - PERCENT_H(0.05)), PERCENT_W(0.05), player_textures[3]); if (jump_button == NULL) { destroy_bridge(td); destroy_blockbreaker(bb); - destroy_action(break_button); + destroy_iconbutton(break_button); destroy_joystick(js); destroy_gui(ctx); return; @@ -136,8 +136,8 @@ void game_screen(w_state *state) { VEC_ZERO, 0, WHITE); #if defined(WISPY_ANDROID) td->ctrl->joystick = update_joystick(js); - td->ctrl->is_breaking = update_action(break_button); - td->ctrl->is_jumping = update_action(jump_button); + td->ctrl->is_breaking = update_iconbutton(break_button); + td->ctrl->is_jumping = update_iconbutton(jump_button); #endif DrawText(TextFormat("FPS: %i", GetFPS()), 50, 50, 30, WHITE); EndTextureMode(); @@ -156,8 +156,8 @@ void game_screen(w_state *state) { #if defined(WISPY_ANDROID) destroy_joystick(js); - destroy_action(break_button); - destroy_action(jump_button); + destroy_iconbutton(break_button); + destroy_iconbutton(jump_button); destroy_gui(ctx); #endif diff --git a/src/stdafx.h b/src/stdafx.h index 3b9fd48..1613def 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -58,9 +58,15 @@ #define WISPY_ANDROID #include +#include #include -#include + #include +#include +#include +#include + +extern struct android_app *GetAndroidApp(void); #endif @@ -72,8 +78,8 @@ if (x) \ free(x); -#define PERCENT_W(x) RENDER_W * x -#define PERCENT_H(x) RENDER_H * x +#define PERCENT_W(x) RENDER_W *x +#define PERCENT_H(x) RENDER_H *x #define FORMAT_TO(x, size, target) (((float)x / (float)size) * (float)target) #define FORMAT_W(x) FORMAT_TO(x, GetRenderWidth(), RENDER_W) @@ -124,7 +130,8 @@ printf(__VA_ARGS__); \ printf("\n"); #elif defined(_DEBUG) && defined(WISPY_ANDROID) -#define LOG(...) __android_log_print(ANDROID_LOG_INFO, "wispy_log", __VA_ARGS__); +#define LOG(...) \ + __android_log_print(ANDROID_LOG_INFO, "wispy_log", __VA_ARGS__); #else #define LOG(...) #endif // _DEBUG diff --git a/src/terrain/terrain.c b/src/terrain/terrain.c index 790c580..bb1f0ab 100644 --- a/src/terrain/terrain.c +++ b/src/terrain/terrain.c @@ -10,10 +10,10 @@ w_terrain *create_terrain(unsigned int start_position) { char *terrain_path = get_terrain_path_folder(); if (!DirectoryExists(terrain_path)) { -#ifdef WISPY_WINDOWS +#if defined(WISPY_WINDOWS) if (!CreateDirectoryA(terrain_path, NULL)) -#elif WISPY_LINUX || WISPY_ANDROID - if (mkdir(map_path, 0777) == -1) +#elif defined(WISPY_LINUX) || defined(WISPY_ANDROID) + if (mkdir(terrain_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0) #endif { free(terrain_path); diff --git a/src/terrain/terrain_data.c b/src/terrain/terrain_data.c index b9428a3..955ace4 100644 --- a/src/terrain/terrain_data.c +++ b/src/terrain/terrain_data.c @@ -7,9 +7,13 @@ char *get_terrain_path_folder() { } path[0] = 0; - strcat(path, GetApplicationDirectory()); +#if defined(WISPY_ANDROID) + strcat(path, GetAndroidApp()->activity->internalDataPath); + strcat(path, "/"); +#else + strcat(config_path, GetApplicationDirectory()); +#endif strcat(path, TERRAIN_FOLDER); - return path; }