diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index a1fdcc3..d26cddb 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -6,11 +6,10 @@ on: branches: ["main"] env: - BUILD_PATH: ./android/app/build/outputs/apk/release + BUILD_PATH: ./app/build/outputs/apk/release BUILD_TYPE: release BUILD_PLATFORM: android - permissions: security-events: write actions: read @@ -27,7 +26,7 @@ jobs: arch: [x64, x86] steps: - uses: actions/checkout@v4 - with: + with: submodules: true - uses: lukka/get-cmake@latest @@ -35,28 +34,23 @@ jobs: - name: Setup Java JDK uses: actions/setup-java@v3.13.0 with: - distribution: 'adopt' - java-version: '17' - + distribution: "adopt" + java-version: "17" + - name: Setup Android SDK uses: android-actions/setup-android@v2 - name: Build Application run: | - sudo apt-get update -y - sudo apt-get install -y cmake - cd ./android - chmod +x ./gradlew - ./gradlew assembleRelease - - # - name: Sign Application - # run: | - # keytool -genkey -v -keystore release-key.keystore -alias wispy -keyalg RSA -keysize 2048 -validity 10000 -storepass ${{ secrets.KEYSTORE_PASSWORD }} -keypass ${{ secrets.KEY_PASSWORD }} -dname "CN=julesgrc0, OU=Engineering, O=Wispy, L=France, S=France, C=FR" - # ${ANDROID_HOME}/build-tools/31.0.0/apksigner sign --ks release-key.keystore --ks-key-alias wispy --ks-pass pass:${{ secrets.KEYSTORE_PASSWORD }} --key-pass pass:${{ secrets.KEY_PASSWORD }} --out ${{env.BUILD_PATH}}signed-app-release.apk ${{env.BUILD_PATH}}app-release.apk - + sudo apt-get update -y + sudo apt-get install -y cmake + cd ./android + chmod +x ./gradlew + ./gradlew assembleRelease + tree + - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: wipsy-${{env.BUILD_PLATFORM}}-${{matrix.arch}}.apk path: ${{env.BUILD_PATH}}/app-release.apk - diff --git a/src/core/view.c b/src/core/view.c index b4e5f73..1bcf39e 100644 --- a/src/core/view.c +++ b/src/core/view.c @@ -38,4 +38,4 @@ Vector2 vec_block_round(Vector2 vec) { .x = round(vec.x / (float)CUBE_W) * (float)CUBE_W, .y = round(vec.y / (float)CUBE_H) * (float)CUBE_H, }; -} +} \ No newline at end of file diff --git a/src/core/view.h b/src/core/view.h index 0bc3333..cb699df 100644 --- a/src/core/view.h +++ b/src/core/view.h @@ -14,8 +14,9 @@ typedef struct w_collision { #pragma pack(pop) #define smooth_float(current, target, speed) \ - current = (current < target) ? fmin(current + speed, target) \ - : fmax(current - speed, target); + current = ((float)current < (float)target) \ + ? fmin((float)current + (float)speed, (float)target) \ + : fmax((float)current - (float)speed, (float)target); Vector2 center_camera_on_object(Camera2D *camera, Rectangle box); Vector2 center_object_on_camera(Rectangle box, Camera2D *camera); @@ -25,4 +26,4 @@ void smooth_vec(Vector2 *position, Vector2 target, float move); void smooth_rect(Rectangle *box, Rectangle target, float move); Vector2 get_mouse_block_center(Camera2D *camera); -Vector2 vec_block_round(Vector2 vec); +Vector2 vec_block_round(Vector2 vec); \ No newline at end of file diff --git a/src/gui/button.c b/src/gui/button.c index ed39cfc..4a4db81 100644 --- a/src/gui/button.c +++ b/src/gui/button.c @@ -37,10 +37,10 @@ void move_button(w_guibutton *button, Vector2 position) { } bool update_button(w_guibutton *button) { - bool is_hover = #ifdef __ANDROID__ - has_touch() && check_collision_touch_rect(button->rect); + bool is_hover = has_touch() && check_collision_touch_rect(button->rect); #else + bool is_hover = CheckCollisionRecs(button->rect, (Rectangle){ .x = FORMAT_W(GetMouseX()), .y = FORMAT_H(GetMouseY()), @@ -53,8 +53,9 @@ bool update_button(w_guibutton *button) { DrawRectangleRoundedLines(button->rect, button->ctx->border_radius, 1.f, button->ctx->border_size, color); - DrawText(button->text, button->position.x, button->position.y, - button->ctx->font_size, color); + DrawText(button->text, (int)button->position.x, (int)button->position.y, + (int)button->ctx->font_size, color); + #ifdef __ANDROID__ return is_hover; #else diff --git a/src/gui/gui.h b/src/gui/gui.h index 96858cc..454310a 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1,7 +1,6 @@ #pragma once #include "../stdafx.h" - typedef struct w_guicontext { float border_size; float margin_width; @@ -13,3 +12,53 @@ typedef struct w_guicontext { w_guicontext *create_gui(); void destroy_gui(w_guicontext *ctx); +/* +TODO: idea for a gui system + + + ... (frames) + + +typedef struct w_guiframe w_guiframe; + +typedef struct w_guiframe { + float width; + float height; + + float x; + float y; + + float border; + float border_radius; + + float padding; + + Color background_color; + Color border_color; + + char *text; + int font_size; + + Texture texture; + + size_t len; + w_guiframe *frames; +}; + + +void calculate_frame(w_guiframe* root); + + +*/ \ No newline at end of file diff --git a/src/screen/menu.c b/src/screen/menu.c index b5aefa1..e6912a7 100644 --- a/src/screen/menu.c +++ b/src/screen/menu.c @@ -53,15 +53,15 @@ void menu_screen(w_state *state) { (Vector2){0, title_text->font_size + 10}), (char *)TextFormat("made by @julesgrc0 - %s", WISPY_VERSION), 20, WHITE); - double angle = 0.0; + float angle = 0.0; while (!WindowShouldClose() && is_active) { - double speed = GetFrameTime() * 0.1; + float speed = GetFrameTime() * 0.1; angle += speed; - angle = fmod(angle, 360.0); + angle = fmodf(angle, 360.0); - camera.target.x += (float)((sin(angle) * 1000.0) * speed); - camera.target.y += (float)((cos(angle) * 1000.0) * speed); + camera.target.x += (sinf(angle) * 1000.0) * speed; + camera.target.y += (cosf(angle) * 1000.0) * speed; update_chunkview(view, grp, get_camera_view(&camera)); update_chunkview_lighting( diff --git a/src/stdafx.h b/src/stdafx.h index 0eeb6d0..e9b2fe9 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -65,26 +65,29 @@ if (x) \ free(x); -#define PHYSICS_TICK (1.0f / 120.0f) - -#define RENDER_W 1280 -#define RENDER_H 720 - #define PERCENT_W(x) RENDER_W *x #define PERCENT_H(x) RENDER_H *x #define PIXELS_W(x) RENDER_W / x #define PIXELS_H(x) RENDER_H / x -#define FORMAT_TO(x, size, target) (x / size) * target -#define FORMAT_W(x) FORMAT_TO(x, GetScreenWidth(), RENDER_W) -#define FORMAT_H(x) FORMAT_TO(x, GetScreenHeight(), RENDER_H) +#define FORMAT_TO(x, size, target) (((float)x / (float)size) * (float)target) +#define FORMAT_W(x) FORMAT_TO(x, GetRenderWidth(), RENDER_W) +#define FORMAT_H(x) FORMAT_TO(x, GetRenderHeight(), RENDER_H) +#define FORMAT_VEC(x) \ + (Vector2) { FORMAT_W(x.x), FORMAT_H(x.y) } + +#define PHYSICS_TICK (1.0f / 120.0f) + +#define RENDER_W 1280 +#define RENDER_H 720 #define RENDER_CUBE_COUNT 20 #define RENDER_CUBE_GAP 2 -#define CHUNK_MID_H 128 #define CHUNK_H 256 // 2^8 #define CHUNK_W 64 // 2^6 +#define CHUNK_MID_H 128 + #define CHUNK_GROUP_LEN 10 #define CHUNK_GROUP_UPDATE_DIST 2 #define CHUNK_GROUP_MID_LEN 5 @@ -113,38 +116,4 @@ #define LOG(...) #endif // _DEBUG -#if defined(_DEBUG) && defined(_WIN32) -#define measure(name, x) \ - do { \ - LARGE_INTEGER start, end, frequency; \ - long long elapsed_time; \ - QueryPerformanceFrequency(&frequency); \ - QueryPerformanceCounter(&start); \ - \ - x; \ - \ - QueryPerformanceCounter(&end); \ - elapsed_time = \ - (end.QuadPart - start.QuadPart) * 100000000 / frequency.QuadPart; \ - printf("[%s]: %lld ns\n", #name, elapsed_time); \ - } while (0); - -#elif defined(_DEBUG) && (defined(__linux__) || defined(__ANDROID__)) -#define measure(name, x) \ - do { \ - struct timespec start, end; \ - long long elapsed_time; \ - clock_gettime(CLOCK_MONOTONIC, &start); \ - \ - x; \ - \ - clock_gettime(CLOCK_MONOTONIC, &end); \ - elapsed_time = (end.tv_sec - start.tv_sec) * 1000000000 + \ - (end.tv_nsec - start.tv_nsec); \ - printf("[%s]: %lld ns\n", #name, elapsed_time); \ - } while (0); -#else -#define measure(name, x) -#endif // _DEBUG && _WIN32 - #endif // _STDAFX_H \ No newline at end of file diff --git a/src/terrain/chunk.c b/src/terrain/chunk.c index 679f0de..8ef0aaa 100644 --- a/src/terrain/chunk.c +++ b/src/terrain/chunk.c @@ -53,13 +53,11 @@ void *create_chunk_thread(void *arg) LOG("creating chunk"); w_chunk *chunk = arg; - Image topLayer = GenImagePerlinNoise(CHUNK_W, BLOCK_TOP_LAYER_H, - chunk->position * CHUNK_W, 0, 6.f); + Image base = GenImagePerlinNoise(CHUNK_W, BLOCK_TOP_LAYER_H, + chunk->position * CHUNK_W, 0, 6.f); Image mineral = GenImageCellular(CHUNK_W, CHUNK_MID_H - BLOCK_TOP_LAYER_H, 10); - // Image caves = GenImageCellular(CHUNK_W, mineralHeight, 10); - for (unsigned int x = 0; x < CHUNK_W; x++) { unsigned int level = 0; bool firstLayer = false; @@ -68,7 +66,7 @@ void *create_chunk_thread(void *arg) w_blocktype type = BLOCK_AIR; if (y >= CHUNK_MID_H) { if (y < CHUNK_MID_H + BLOCK_TOP_LAYER_H) { - unsigned int value = GetImageColor(topLayer, x, (y - CHUNK_MID_H)).r; + unsigned int value = GetImageColor(base, x, (y - CHUNK_MID_H)).r; if (level == 0) { if (y > CHUNK_MID_H + BLOCK_TOP_LAYER_H / 3 || (value < 105)) { @@ -112,7 +110,7 @@ void *create_chunk_thread(void *arg) } } - UnloadImage(topLayer); + UnloadImage(base); UnloadImage(mineral); #ifdef _WIN32 diff --git a/src/terrain/chunk_view.c b/src/terrain/chunk_view.c index d727ecc..9799687 100644 --- a/src/terrain/chunk_view.c +++ b/src/terrain/chunk_view.c @@ -133,6 +133,7 @@ void filter_chunkview_blocks(w_chunk *chunk, Rectangle view, Rectangle block = {.x = 0, .y = 0, .width = CUBE_W, .height = CUBE_H}; +#pragma omp parallel for for (unsigned int x = 0; x < CHUNK_W; x++) { bool noclear = false; @@ -156,12 +157,14 @@ void filter_chunkview_blocks(w_chunk *chunk, Rectangle view, block.y = y * CUBE_H; if (CheckCollisionRecs(block, view)) { - - blocks[*rendercount] = (w_renderblock){.dst = block, - .src = CUBE_SRC_RECT, - .light = WHITE, - .block = chunk->blocks[index]}; - (*rendercount)++; +#pragma omp critical + { + blocks[*rendercount] = (w_renderblock){.dst = block, + .src = CUBE_SRC_RECT, + .light = WHITE, + .block = chunk->blocks[index]}; + (*rendercount)++; + } } } } @@ -173,6 +176,7 @@ void update_chunkview_lighting(w_chunkview *chunk_view, Vector2 light, return; } +#pragma omp parallel for for (size_t i = 0; i < chunk_view->textures_len; i++) { Vector2 block_center = {chunk_view->blocks[i].dst.x + (CUBE_W / 2), chunk_view->blocks[i].dst.y + (CUBE_H / 2)};