Initial support for updating settings during emulation + observing settings changes

This commit is contained in:
lynxnb 2022-01-10 18:45:37 +01:00 committed by ◱ Mark
parent c5dde5953a
commit 69cf25b1a7
4 changed files with 39 additions and 0 deletions

View File

@ -60,6 +60,8 @@ template<> void skyline::Settings::Update<skyline::KtSettings>(KtSettings newSet
systemLanguage = newSettings.GetInt<skyline::language::SystemLanguage>("systemLanguage");
forceTripleBuffering = newSettings.GetBool("forceTripleBuffering");
disableFrameThrottling = newSettings.GetBool("disableFrameThrottling");
OnSettingsChanged();
}
extern "C" JNIEXPORT void Java_emu_skyline_SkylineApplication_initializeLog(
@ -239,3 +241,11 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setTouchSta
input->touch.SetState(points);
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) {
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);
}

View File

@ -4,6 +4,16 @@
#include "settings.h"
namespace skyline {
void Settings::Subscribe(Callback callback) {
callbacks.push_back(std::move(callback));
}
void Settings::OnSettingsChanged() {
std::for_each(callbacks.begin(), callbacks.end(), [&](const Callback& listener) {
listener(*this);
});
}
/**
* @note This is a placeholder implementation, it must be overridden via template specialisation for platform-specific behavior
*/

View File

@ -27,9 +27,23 @@ namespace skyline {
/**
* @brief Updates settings with the given values
* @note The implementations of this method must call OnSettingsChanged
* @param newSettings A platform-specific object containing the new settings' values
*/
template<class T>
void Update(T newSettings);
using Callback = std::function<void(const Settings &)>;
/**
* @brief Subscribe to settings changes
* @param callback The function to be called when settings change
*/
void Subscribe(Callback callback);
private:
std::vector<Callback> callbacks; //!< Callbacks to be called when settings change
void OnSettingsChanged();
};
}

View File

@ -13,4 +13,9 @@ class SettingsValues(pref: Settings) : Serializable {
var systemLanguage : Int = pref.systemLanguage
var forceTripleBuffering : Boolean = pref.forceTripleBuffering
var disableFrameThrottling : Boolean = pref.disableFrameThrottling
/**
* Updates settings in libskyline during emulation
*/
external fun updateNative()
}