From 4877dfde6db41a3460cf2dc98b5e39979d0270f7 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sat, 4 Nov 2023 15:01:40 +0200 Subject: [PATCH] * Fix options and screenshot saving. --- platforms/android/AppPlatform_android.cpp | 23 +++++++++++++++++++++++ platforms/android/AppPlatform_android.hpp | 4 ++++ platforms/android/main.cpp | 11 +++++++++++ 3 files changed, 38 insertions(+) diff --git a/platforms/android/AppPlatform_android.cpp b/platforms/android/AppPlatform_android.cpp index b74cfe0..b059ded 100644 --- a/platforms/android/AppPlatform_android.cpp +++ b/platforms/android/AppPlatform_android.cpp @@ -55,8 +55,31 @@ void AppPlatform_android::buyGame() { } +bool AppPlatform_android::hasFileSystemAccess() +{ + return true; +} + +void AppPlatform_android::setExternalStoragePath(const std::string& path) +{ + m_storageDir = path; +} + void AppPlatform_android::saveScreenshot(const std::string& fileName, int width, int height) { + std::string saveName = m_storageDir + "/" + fileName; + + LOG_I("Saving in %s", saveName.c_str()); + + int npixels = width * height; + uint32_t* pixels = new uint32_t[npixels]; + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + stbi_flip_vertically_on_write(true); + + stbi_write_png(saveName.c_str(), width, height, 4, pixels, width * 4); + + delete[] pixels; } int AppPlatform_android::getScreenWidth() const diff --git a/platforms/android/AppPlatform_android.hpp b/platforms/android/AppPlatform_android.hpp index 78e2aa1..29e32de 100644 --- a/platforms/android/AppPlatform_android.hpp +++ b/platforms/android/AppPlatform_android.hpp @@ -52,6 +52,7 @@ public: // Also add these to allow saving options. //void setOptionStrings(const std::vector & str) override; + bool hasFileSystemAccess() override; SoundSystem* const getSoundSystem() const override; void initSoundSystem() override; @@ -59,6 +60,7 @@ public: void setScreenSize(int width, int height); void initAndroidApp(android_app* ptr); + void setExternalStoragePath(const std::string& path); private: int m_ScreenWidth; @@ -81,5 +83,7 @@ private: android_app* m_app; SoundSystem* m_pSoundSystem; + + std::string m_storageDir; }; diff --git a/platforms/android/main.cpp b/platforms/android/main.cpp index 09d6a8f..85a6462 100644 --- a/platforms/android/main.cpp +++ b/platforms/android/main.cpp @@ -1,3 +1,11 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + #include #include #include "android_native_app_glue.h" @@ -334,6 +342,7 @@ static void initWindow(struct engine* engine, struct android_app* app) if (!engine->initted) { engine->ninecraftApp->m_externalStorageDir = getExternalStorageDir(engine); + g_AppPlatform.setExternalStoragePath(engine->ninecraftApp->m_externalStorageDir); engine->ninecraftApp->init(); } else @@ -366,6 +375,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { case APP_CMD_TERM_WINDOW: LOG_I("APP_CMD_TERM_WINDOW"); + engine->ninecraftApp->saveOptions(); if (engine->display) { eglMakeCurrent(engine->display, 0, 0, 0); @@ -382,6 +392,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { break; case APP_CMD_LOST_FOCUS: engine->animating = 0; + engine->ninecraftApp->saveOptions(); break; } }