Skip to content

Commit

Permalink
fix android laggy camera bug
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Mar 2, 2024
1 parent 9555944 commit 30c54df
Show file tree
Hide file tree
Showing 42 changed files with 342 additions and 329 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ if(ANDROID)
add_definitions(-D__ANDROID__)

add_library(${PROJECT_NAME} SHARED ${SOURCES})
target_link_libraries(${PROJECT_NAME} raylib zlibstatic android log)
target_link_libraries(${PROJECT_NAME} raylib zlibstatic json-c android log)
elseif(UNIX AND NOT ANDROID)
add_executable(${PROJECT_NAME} ${SOURCES})
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Expand Down
9 changes: 8 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,42 +144,49 @@
},
{
"name": "x64-release-windows",
"displayName": "x64 Release Windows",
"configurePreset": "x64-release-windows",
"inherits": ["base-build"]
},
{
"name": "x86-release-windows",
"displayName": "x86 Release Windows",
"configurePreset": "x86-release-windows",
"inherits": ["base-build"]
},
{
"name": "x64-release-linux",
"displayName": "x64 Release Linux",
"configurePreset": "x64-release-linux",
"inherits": ["base-build"]
},
{
"name": "x86-release-linux",
"displayName": "x86 Release Linux",
"configurePreset": "x86-release-linux",
"inherits": ["base-build"]
},

{
"name": "x64-debug-windows",
"displayName": "x64 Debug Windows",
"configurePreset": "x64-debug-windows",
"inherits": ["base-build"]
},
{
"name": "x86-debug-windows",
"displayName": "x86 Debug Windows",
"configurePreset": "x86-debug-windows",
"inherits": ["base-build"]
},
{
"name": "x64-debug-linux",
"displayName": "x64 Debug Linux",
"configurePreset": "x64-debug-linux",
"inherits": ["base-build"]
},
{
"name": "x86-debug-linux",
"displayName": "x86 Debug Linux",
"configurePreset": "x86-debug-linux",
"inherits": ["base-build"]
}
Expand Down
6 changes: 3 additions & 3 deletions android/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 7 additions & 24 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@ plugins {
}

android {
signingConfigs {
create("release") {
}
}
namespace = "com.julesgrc0.wispy"
compileSdk = 34

defaultConfig {
applicationId = "com.julesgrc0.wispy"
minSdk = 34
minSdk = 21
targetSdk = 34


versionCode = 1
versionName = "alpha-0.0.5"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isJniDebuggable = false
isMinifyEnabled = true
//isShrinkResources = true
//multiDexEnabled = true
isShrinkResources = true

proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
getByName("debug") {
Expand All @@ -40,23 +36,10 @@ android {
path = file("../../CMakeLists.txt")
}
}
buildFeatures {
viewBinding = true
}
ndkVersion = "26.2.11394342"
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
ndkVersion = "26.2.11394342"
buildToolsVersion = "35.0.0 rc1"
}

dependencies {

implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
3 changes: 2 additions & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
org.gradle.configuration-cache=true
44 changes: 0 additions & 44 deletions src/core/bridge.h

This file was deleted.

23 changes: 5 additions & 18 deletions src/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ w_config *load_config() {
if (cfg == NULL)
return NULL;

#ifndef __ANDROID__
char *config_path = malloc(MAX_PATH * 2);
if (config_path == NULL)
return NULL;
Expand Down Expand Up @@ -52,32 +51,21 @@ w_config *load_config() {
json_object_put(root);
free(data);
} else {
#endif // !__ANDROID__

memset(cfg, 0, sizeof(w_config));
cfg->fullscreen = 1;
cfg->vsync = 0;
cfg->msaa4x = 1;

cfg->max_fps = 0;
cfg->height = 0;
cfg->width = 0;

#if defined(_DEBUG) && !defined(__ANDROID__)
cfg->fullscreen = 0;
cfg->height = RENDER_H;
#if defined(_DEBUG) && !defined(PLATFORM_ANDROID)
cfg->width = RENDER_W;
#endif // _DEBUG

#ifndef __ANDROID__
cfg->height = RENDER_H;
cfg->fullscreen = 0;
#endif
}
free(config_path);
#endif // !__ANDROID__

return cfg;
}

void save_config(w_config *config) {
#if !defined(_DEBUG) && !defined(__ANDROID__)
char *config_path = malloc(MAX_PATH * 2);
if (config_path == NULL)
return;
Expand Down Expand Up @@ -112,5 +100,4 @@ void save_config(w_config *config) {
json_object_put(root);

free(config_path);
#endif // !_DEBUG
}
1 change: 1 addition & 0 deletions src/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef struct w_config {
unsigned int height : 12;

unsigned int max_fps : 10;

} w_config;

w_config *load_config();
Expand Down
8 changes: 4 additions & 4 deletions src/core/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void destroy_controls(w_controls *kb) {
}

void update_controls(w_controls *kb) {
#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
kb->jump = kb->is_jumping;
if (!kb->is_breaking) {
kb->left = kb->joystick.x < -0.5;
Expand All @@ -28,11 +28,11 @@ void update_controls(w_controls *kb) {
kb->jump = IsKeyDown(KEY_SPACE);
kb->inventory = IsKeyDown(KEY_RIGHT_ALT) || IsKeyDown(KEY_LEFT_SHIFT);
kb->shift = IsKeyDown(KEY_RIGHT_SHIFT) || IsKeyDown(KEY_LEFT_SHIFT);
#endif // __ANDROID__
#endif
}

void clear_controls(w_controls *kb) {
#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
kb->is_jumping = false;
kb->is_breaking = false;
kb->joystick = VEC_ZERO;
Expand All @@ -41,7 +41,7 @@ void clear_controls(w_controls *kb) {
kb->key = 0;
}

#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
bool check_collision_touch(Vector2 position, float size) {
return !Vector2Equals(get_collision_touch(position, size), VEC_ZERO);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef struct w_controls {
uint8_t key;
};

#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
Vector2 joystick;
bool is_jumping;
bool is_breaking;
Expand All @@ -31,7 +31,7 @@ void destroy_controls(w_controls *kb);
void update_controls(w_controls *kb);
void clear_controls(w_controls *kb);

#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
bool check_collision_touch(Vector2 position, float size);
Vector2 get_nearest_touch(Vector2 position);
Vector2 get_collision_touch(Vector2 position, float size);
Expand Down
2 changes: 1 addition & 1 deletion src/core/mainframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ w_state *init_mainframe() {
if (state == NULL)
return NULL;

#ifdef _DEBUG
#if defined(_DEBUG)
SetTraceLogLevel(LOG_ALL);
SetRandomSeed(0);
srand(0);
Expand Down
6 changes: 3 additions & 3 deletions src/core/mainframe.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "../screen/game.h"
#include "../screen/loading.h"
#include "../screen/menu.h"
#include "../screens/game/game.h"
#include "../screens/loading/loading.h"
#include "../screens/menu/menu.h"
#include "../stdafx.h"
#include "state.h"

Expand Down
4 changes: 2 additions & 2 deletions src/core/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ typedef struct w_state {

w_config *config;

#ifdef _WIN32
#if defined(PLATFORM_WINDOWS)
HINSTANCE hInstance;
#endif // _WIN32
#endif

} w_state;

Expand Down
1 change: 1 addition & 0 deletions src/core/utils/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

typedef struct w_camera {
float *matrix;
Vector2 target_position;
} w_camera;

w_camera *create_camera(float x, float y);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ w_guiaction *create_action(w_guicontext *ctx, Vector2 position, float size,
}

bool update_action(w_guiaction *act) {
#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
bool clicked = check_collision_touch(act->position, act->size);
#else
bool clicked =
Expand Down
4 changes: 2 additions & 2 deletions src/gui/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void move_button(w_guibutton *button, Vector2 position) {
}

bool update_button(w_guibutton *button) {
#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
bool is_hover = has_touch() && check_collision_touch_rect(button->rect);
#else
bool is_hover = CheckCollisionRecs(
Expand All @@ -46,7 +46,7 @@ bool update_button(w_guibutton *button) {
DrawText(button->text, (int)button->position.x, (int)button->position.y,
(int)button->ctx->font_size, color);

#ifdef __ANDROID__
#if defined(PLATFORM_ANDROID)
return is_hover;
#else
return IsMouseButtonDown(MOUSE_LEFT_BUTTON) && is_hover;
Expand Down
Loading

0 comments on commit 30c54df

Please sign in to comment.