Skip to content

Commit

Permalink
fix application path for android
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Mar 16, 2024
1 parent 37d196e commit ffc5eae
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:appCategory="game"
Expand Down
12 changes: 6 additions & 6 deletions src/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ w_config *load_config() {
if (config_path == NULL)
return NULL;
config_path[0] = 0;
#if defined(WISPY_ANDROID)
strcat(config_path, GetAndroidApp()->activity->internalDataPath);
strcat(config_path, "/");
#else
strcat(config_path, GetApplicationDirectory());
#endif
strcat(config_path, CONFIG_NAME);

if (FileExists(config_path)) {
Expand Down Expand Up @@ -80,6 +85,7 @@ void save_config(w_config *config) {
return;

config_path[0] = 0;

strcat(config_path, GetApplicationDirectory());
strcat(config_path, CONFIG_NAME);

Expand Down Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions src/core/utils/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/screens/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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

Expand Down
15 changes: 11 additions & 4 deletions src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@
#define WISPY_ANDROID

#include <pthread.h>
#include <sys/stat.h>
#include <unistd.h>
#include <jni.h>

#include <android/log.h>
#include <android/window.h>
#include <android_native_app_glue.h>
#include <jni.h>

extern struct android_app *GetAndroidApp(void);

#endif

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/terrain/terrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/terrain/terrain_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ffc5eae

Please sign in to comment.