mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-26 05:44:18 +01:00
Introduce AndroidSettings
class and use inheritance
The `Settings` class now has a pure virtual `Update` method, and uses inheritance over template specialization for platform-specific behavior override.
This commit is contained in:
parent
3905728447
commit
2840a126dd
@ -134,7 +134,6 @@ add_library(skyline SHARED
|
||||
${source_DIR}/skyline/common.cpp
|
||||
${source_DIR}/skyline/common/exception.cpp
|
||||
${source_DIR}/skyline/common/logger.cpp
|
||||
${source_DIR}/skyline/common/settings.cpp
|
||||
${source_DIR}/skyline/common/signal.cpp
|
||||
${source_DIR}/skyline/common/uuid.cpp
|
||||
${source_DIR}/skyline/common/trace.cpp
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "skyline/common.h"
|
||||
#include "skyline/common/language.h"
|
||||
#include "skyline/common/signal.h"
|
||||
#include "skyline/common/settings.h"
|
||||
#include "skyline/common/android_settings.h"
|
||||
#include "skyline/common/trace.h"
|
||||
#include "skyline/loader/loader.h"
|
||||
#include "skyline/vfs/android_asset_filesystem.h"
|
||||
@ -54,14 +54,6 @@ static std::string GetTimeZoneName() {
|
||||
return "GMT";
|
||||
}
|
||||
|
||||
template<> void skyline::Settings::Update<skyline::KtSettings>(KtSettings newSettings) {
|
||||
isDocked = newSettings.GetBool("isDocked");
|
||||
usernameValue = newSettings.GetString("usernameValue");
|
||||
systemLanguage = newSettings.GetInt<skyline::language::SystemLanguage>("systemLanguage");
|
||||
forceTripleBuffering = newSettings.GetBool("forceTripleBuffering");
|
||||
disableFrameThrottling = newSettings.GetBool("disableFrameThrottling");
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void Java_emu_skyline_SkylineApplication_initializeLog(
|
||||
JNIEnv *env,
|
||||
jobject,
|
||||
@ -93,8 +85,7 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(
|
||||
|
||||
auto jvmManager{std::make_shared<skyline::JvmManager>(env, instance)};
|
||||
|
||||
skyline::KtSettings ktSettings{env, settingsInstance};
|
||||
auto settings{std::make_shared<skyline::Settings>(ktSettings)};
|
||||
std::shared_ptr<skyline::Settings> settings{std::make_shared<skyline::AndroidSettings>(env, settingsInstance)};
|
||||
|
||||
skyline::JniString publicAppFilesPath(env, publicAppFilesPathJstring);
|
||||
skyline::Logger::EmulationContext.Initialize(publicAppFilesPath + "logs/emulation.sklog");
|
||||
@ -240,10 +231,9 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setTouchSta
|
||||
env->ReleaseIntArrayElements(pointsJni, reinterpret_cast<jint *>(points.data()), JNI_ABORT);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_SettingsValues_updateNative(JNIEnv *env, jobject settingsInstance) {
|
||||
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_SettingsValues_updateNative(JNIEnv *env, jobject) {
|
||||
auto settings{SettingsWeak.lock()};
|
||||
if (!settings)
|
||||
return; // We don't mind if we miss settings updates while settings haven't been initialized
|
||||
skyline::KtSettings ktSettings{env, settingsInstance};
|
||||
settings->Update(ktSettings);
|
||||
settings->Update();
|
||||
}
|
||||
|
41
app/src/main/cpp/skyline/common/android_settings.h
Normal file
41
app/src/main/cpp/skyline/common/android_settings.h
Normal file
@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "settings.h"
|
||||
#include "jvm.h"
|
||||
|
||||
namespace skyline {
|
||||
/**
|
||||
* @brief Handles settings on the android platform
|
||||
* @note Lifetime of this class must not exceed the one of the JNIEnv contained inside ktSettings
|
||||
*/
|
||||
class AndroidSettings final : public Settings {
|
||||
private:
|
||||
KtSettings ktSettings;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @note Will construct the underlying KtSettings object in-place
|
||||
*/
|
||||
AndroidSettings(JNIEnv *env, jobject settingsInstance) : ktSettings(env, settingsInstance) {
|
||||
Update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @note Will take ownership of the passed KtSettings object
|
||||
*/
|
||||
AndroidSettings(KtSettings &&ktSettings) : ktSettings(std::move(ktSettings)) {
|
||||
Update();
|
||||
}
|
||||
|
||||
void Update() override {
|
||||
isDocked = ktSettings.GetBool("isDocked");
|
||||
usernameValue = std::move(ktSettings.GetString("usernameValue"));
|
||||
systemLanguage = ktSettings.GetInt<skyline::language::SystemLanguage>("systemLanguage");
|
||||
forceTripleBuffering = ktSettings.GetBool("forceTripleBuffering");
|
||||
disableFrameThrottling = ktSettings.GetBool("disableFrameThrottling");
|
||||
};
|
||||
};
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
namespace skyline {
|
||||
/**
|
||||
* @note This is a placeholder implementation, it must be overridden via template specialisation for platform-specific behavior
|
||||
*/
|
||||
template<class T>
|
||||
void Settings::Update(T newSettings) {}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace skyline {
|
||||
/**
|
||||
* @brief The Settings class is used to access preferences set in the Kotlin component of Skyline
|
||||
* @brief The Settings class provides a simple interface to access user-defined settings, update values and subscribe callbacks to observe changes.
|
||||
*/
|
||||
class Settings {
|
||||
template<typename T>
|
||||
@ -60,16 +60,14 @@ namespace skyline {
|
||||
Setting<bool> forceTripleBuffering; //!< If the presentation engine should always triple buffer even if the swapchain supports double buffering
|
||||
Setting<bool> disableFrameThrottling; //!< Allow the guest to submit frames without any blocking calls
|
||||
|
||||
template<class T>
|
||||
Settings(T settings) {
|
||||
Update(settings);
|
||||
}
|
||||
Settings() = default;
|
||||
|
||||
virtual ~Settings() = default;
|
||||
|
||||
/**
|
||||
* @brief Updates settings with the given values
|
||||
* @param newSettings A platform-specific object containing the new settings' values
|
||||
* @note This method is platform-specific and must be overridden
|
||||
*/
|
||||
template<class T>
|
||||
void Update(T newSettings);
|
||||
virtual void Update() = 0;
|
||||
};
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace skyline {
|
||||
/**
|
||||
* @brief A wrapper over the `Settings` Kotlin class
|
||||
* @note The lifetime of this class must not exceed that of the JNI environment
|
||||
* @note Copy construction of this class is disallowed to avoid issues with the JNI environment lifetime
|
||||
*/
|
||||
class KtSettings {
|
||||
private:
|
||||
@ -31,6 +32,12 @@ namespace skyline {
|
||||
public:
|
||||
KtSettings(JNIEnv *env, jobject settingsInstance) : env(env), settingsInstance(settingsInstance), settingsClass(env->GetObjectClass(settingsInstance)) {}
|
||||
|
||||
KtSettings(const KtSettings &) = delete;
|
||||
|
||||
void operator=(const KtSettings &) = delete;
|
||||
|
||||
KtSettings(KtSettings &&) = default;
|
||||
|
||||
/**
|
||||
* @param key A null terminated string containing the key of the setting to get
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user