Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dynamic theme option #16

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions .github/workflows/Android_Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ on:
- master
pull_request:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
x64:
runs-on: ubuntu-latest

strategy:
matrix:
build_type:
- release

steps:
- name: Set BUILD_TYPE variable
run: echo "BUILD_TYPE=${{ matrix.build_type }}" >> $GITHUB_ENV

- uses: actions/checkout@v2
- name: Fetch submodules
run: git submodule update --init --recursive
Expand All @@ -29,31 +33,44 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
distribution: 'zulu'
java-version: '17'

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DBUILD_HYDRA_CORE=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86_64 -DENABLE_VULKAN=0 -DENABLE_USER_BUILD=ON

- name: Build
run: |
# Apply patch for GLES compatibility
git apply ./.github/gles.patch
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
# Build the project with CMake
cmake --build ${{github.workspace}}/build --config ${{ env.BUILD_TYPE }}
# Move the generated library to the appropriate location
mv ./build/libAlber.so ./src/pandroid/app/src/main/jniLibs/x86_64/
# Build the Android app with Gradle
cd src/pandroid
./gradlew assembleDebug
./gradlew assemble${{ env.BUILD_TYPE }}
cd ../..

- name: Upload executable
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: Android APK (x86-64)
path: './src/pandroid/app/build/outputs/apk/debug/app-debug.apk'
name: Android APKs (x86-64)
path: |
./src/pandroid/app/build/outputs/apk/${{ env.BUILD_TYPE }}/app-${{ env.BUILD_TYPE }}.apk

arm64:
runs-on: ubuntu-latest

strategy:
matrix:
build_type:
- release

steps:
- name: Set BUILD_TYPE variable
run: echo "BUILD_TYPE=${{ matrix.build_type }}" >> $GITHUB_ENV

- uses: actions/checkout@v2
- name: Fetch submodules
run: git submodule update --init --recursive
Expand All @@ -68,24 +85,29 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
distribution: 'zulu'
java-version: '17'

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DBUILD_HYDRA_CORE=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DENABLE_VULKAN=0 -DENABLE_USER_BUILD=ON -DCMAKE_CXX_FLAGS="-march=armv8-a+crypto"

- name: Build
run: |
# Apply patch for GLES compatibility
git apply ./.github/gles.patch
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
# Build the project with CMake
cmake --build ${{github.workspace}}/build --config ${{ env.BUILD_TYPE }}
# Move the generated library to the appropriate location
mv ./build/libAlber.so ./src/pandroid/app/src/main/jniLibs/arm64-v8a/
# Build the Android app with Gradle
cd src/pandroid
./gradlew assembleDebug
./gradlew assemble${{ env.BUILD_TYPE }}
ls -R app/build/outputs
cd ../..

- name: Upload executable
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: Android APK (arm64)
path: './src/pandroid/app/build/outputs/apk/debug/app-debug.apk'

name: Android APKs (arm64)
path: |
./src/pandroid/app/build/outputs/apk/${{ env.BUILD_TYPE }}/app-${{ env.BUILD_TYPE }}.apk
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@
[submodule "third_party/oaknut"]
path = third_party/oaknut
url = https://github.com/merryhime/oaknut
[submodule "third_party/luv"]
path = third_party/luv
url = https://github.com/luvit/luv
[submodule "third_party/libuv"]
path = third_party/libuv
url = https://github.com/libuv/libuv
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp
third_party/xxhash/xxhash.c
)

if(ENABLE_LUAJIT AND NOT ANDROID)
# Build luv and libuv for Lua TCP server usage if we're not on Android
include_directories(third_party/luv/src)
include_directories(third_party/luv/deps/lua-compat-5.3/c-api)
include_directories(third_party/libuv/include)
set(THIRD_PARTY_SOURCE_FILES ${THIRD_PARTY_SOURCE_FILES} third_party/luv/src/luv.c)
set(LIBUV_BUILD_SHARED OFF)

add_subdirectory(third_party/libuv)
endif()

if(ENABLE_QT_GUI)
include_directories(third_party/duckstation)
Expand Down Expand Up @@ -433,6 +443,11 @@ endif()
if(ENABLE_LUAJIT)
target_compile_definitions(Alber PUBLIC "PANDA3DS_ENABLE_LUA=1")
target_link_libraries(Alber PRIVATE libluajit)

# If we're not on Android, link libuv too
if (NOT ANDROID)
target_link_libraries(Alber PRIVATE uv_a)
endif()
endif()

if(ENABLE_OPENGL)
Expand Down
10 changes: 9 additions & 1 deletion include/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <cstdarg>
#include <fstream>

#ifdef __ANDROID__
#include <android/log.h>
#endif

namespace Log {
// Our logger class
template <bool enabled>
Expand All @@ -12,7 +16,11 @@ namespace Log {

std::va_list args;
va_start(args, fmt);
#ifdef __ANDROID__
__android_log_vprint(ANDROID_LOG_DEFAULT, "Panda3DS", fmt, args);
#else
std::vprintf(fmt, args);
#endif
va_end(args);
}
};
Expand Down Expand Up @@ -81,4 +89,4 @@ namespace Log {
#else
#define MAKE_LOG_FUNCTION(functionName, logger) MAKE_LOG_FUNCTION_USER(functionName, logger)
#endif
}
}
10 changes: 10 additions & 0 deletions include/panda_qt/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class MainWindow : public QMainWindow {
SetCirclePadY,
LoadLuaScript,
EditCheat,
PressTouchscreen,
ReleaseTouchscreen,
};

// Tagged union representing our message queue messages
Expand All @@ -68,6 +70,11 @@ class MainWindow : public QMainWindow {
struct {
CheatMessage* c;
} cheat;

struct {
u16 x;
u16 y;
} touchscreen;
};
};

Expand Down Expand Up @@ -108,6 +115,9 @@ class MainWindow : public QMainWindow {

void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;

void loadLuaScript(const std::string& code);
void editCheat(u32 handle, const std::vector<uint8_t>& cheat, const std::function<void(u32)>& callback);
};
3 changes: 1 addition & 2 deletions src/core/applets/mii_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Result::HorizonResult MiiSelectorApplet::start(const MemoryBlock* sharedMem, con
// Thanks to Citra devs as always for the default mii data and other applet help
output = getDefaultMii();
output.returnCode = 0; // Success
// output.selectedMiiData = miiData;
output.selectedGuestMiiIndex = std::numeric_limits<u32>::max();
output.miiChecksum = boost::crc<16, 0x1021, 0, 0, false, false>(&output.selectedMiiData, sizeof(MiiData) + sizeof(output.unknown1));

Expand Down Expand Up @@ -84,4 +83,4 @@ MiiResult MiiSelectorApplet::getDefaultMii() {
result.guestMiiName.fill(0x0);

return result;
}
}
4 changes: 2 additions & 2 deletions src/core/services/apt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void APTService::appletUtility(u32 messagePointer) {
u32 outputSize = mem.read32(messagePointer + 12);
u32 inputPointer = mem.read32(messagePointer + 20);

log("APT::AppletUtility(utility = %d, input size = %x, output size = %x, inputPointer = %08X) (Stubbed)\n", utility, inputSize, outputSize,
log("APT::AppletUtility(utility = %d, input size = %x, output size = %x, inputPointer = %08X)\n", utility, inputSize, outputSize,
inputPointer);

std::vector<u8> out(outputSize);
Expand Down Expand Up @@ -218,7 +218,7 @@ void APTService::initialize(u32 messagePointer) {
}

void APTService::inquireNotification(u32 messagePointer) {
log("APT::InquireNotification (STUBBED TO RETURN NONE)\n");
log("APT::InquireNotification\n");

mem.write32(messagePointer, IPC::responseHeader(0xB, 2, 0));
mem.write32(messagePointer + 4, Result::Success);
Expand Down
7 changes: 7 additions & 0 deletions src/jni_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ JNIEnv* jniEnv() {

extern "C" {

#define MAKE_SETTING(functionName, type, settingName) \
AlberFunction(void, functionName) (JNIEnv* env, jobject obj, type value) { emulator->getConfig().settingName = value; }

MAKE_SETTING(setShaderJitEnabled, jboolean, shaderJitEnabled)

#undef MAKE_SETTING

AlberFunction(void, Setup)(JNIEnv* env, jobject obj) { env->GetJavaVM(&jvm); }
AlberFunction(void, Pause)(JNIEnv* env, jobject obj) { emulator->pause(); }
AlberFunction(void, Resume)(JNIEnv* env, jobject obj) { emulator->resume(); }
Expand Down
15 changes: 13 additions & 2 deletions src/lua.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifdef PANDA3DS_ENABLE_LUA
#include "lua_manager.hpp"

#ifndef __ANDROID__
extern "C" {
#include "luv.h"
}
#endif

void LuaManager::initialize() {
L = luaL_newstate(); // Open Lua

Expand All @@ -9,10 +15,15 @@ void LuaManager::initialize() {
initialized = false;
return;
}

luaL_openlibs(L);
initializeThunks();

#ifndef __ANDROID__
lua_pushstring(L, "luv");
luaopen_luv(L);
lua_settable(L, LUA_GLOBALSINDEX);
#endif

initializeThunks();
initialized = true;
haveScript = false;
}
Expand Down
39 changes: 39 additions & 0 deletions src/panda_qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QDesktopServices>
#include <QFileDialog>
#include <QString>
#include <cmath>
#include <cstdio>
#include <fstream>

Expand Down Expand Up @@ -277,6 +278,10 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
case MessageType::ReleaseKey: emu->getServiceManager().getHID().releaseKey(message.key.key); break;
case MessageType::SetCirclePadX: emu->getServiceManager().getHID().setCirclepadX(message.circlepad.value); break;
case MessageType::SetCirclePadY: emu->getServiceManager().getHID().setCirclepadY(message.circlepad.value); break;
case MessageType::PressTouchscreen:
emu->getServiceManager().getHID().setTouchScreenPress(message.touchscreen.x, message.touchscreen.y);
break;
case MessageType::ReleaseTouchscreen: emu->getServiceManager().getHID().releaseTouchScreen(); break;
}
}

Expand Down Expand Up @@ -357,6 +362,40 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) {
}
}

void MainWindow::mousePressEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton) {
const QPointF clickPos = event->globalPosition();
const QPointF widgetPos = screen.mapFromGlobal(clickPos);

// Press is inside the screen area
if (widgetPos.x() >= 0 && widgetPos.x() < screen.width() && widgetPos.y() >= 0 && widgetPos.y() < screen.height()) {
// Go from widget positions to [0, 400) for x and [0, 480) for y
uint x = (uint)std::round(widgetPos.x() / screen.width() * 400.f);
uint y = (uint)std::round(widgetPos.y() / screen.height() * 480.f);

// Check if touch falls in the touch screen area
if (y >= 240 && y <= 480 && x >= 40 && x < 40 + 320) {
// Convert to 3DS coordinates
u16 x_converted = static_cast<u16>(x) - 40;
u16 y_converted = static_cast<u16>(y) - 240;

EmulatorMessage message{.type = MessageType::PressTouchscreen};
message.touchscreen.x = x_converted;
message.touchscreen.y = y_converted;
sendMessage(message);
} else {
sendMessage(EmulatorMessage{.type = MessageType::ReleaseTouchscreen});
}
}
}
}

void MainWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton) {
sendMessage(EmulatorMessage{.type = MessageType::ReleaseTouchscreen});
}
}

void MainWindow::loadLuaScript(const std::string& code) {
EmulatorMessage message{.type = MessageType::LoadLuaScript};

Expand Down
16 changes: 14 additions & 2 deletions src/pandroid/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@ android {
}

buildTypes {
release {
getByName("release") {
isMinifyEnabled = false
isShrinkResources = false
isDebuggable = false
signingConfig = signingConfigs.getByName("debug")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
isDebuggable = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand All @@ -41,4 +53,4 @@ dependencies {
implementation("androidx.preference:preference:1.2.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.code.gson:gson:2.10.1")
}
}
4 changes: 4 additions & 0 deletions src/pandroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:isGame="true"
android:hardwareAccelerated="true"
android:theme="@style/Theme.Pandroid"
tools:targetApi="31">
<activity
Expand All @@ -46,5 +48,7 @@

<activity android:name=".app.preferences.InputMapActivity"
android:configChanges="density|orientation|screenSize"/>

<service android:name=".app.services.LoggerService" android:process=":logger_service"/>
</application>
</manifest>
Loading
Loading