android: jni: native: Tighten up emulation start/stop signaling.
This commit is contained in:
parent
1e94d16dad
commit
9ba67eab4f
1 changed files with 75 additions and 69 deletions
|
@ -61,7 +61,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsRunning() const {
|
bool IsRunning() const {
|
||||||
return system.IsPoweredOn();
|
return is_running.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Core::PerfStatsResults& PerfStats() const {
|
const Core::PerfStatsResults& PerfStats() const {
|
||||||
|
@ -95,7 +95,8 @@ public:
|
||||||
system.GetFileSystemController().CreateFactories(*system.GetFilesystem());
|
system.GetFileSystemController().CreateFactories(*system.GetFilesystem());
|
||||||
|
|
||||||
// Load the ROM.
|
// Load the ROM.
|
||||||
const Core::SystemResultStatus load_result{system.Load(EmulationSession::GetInstance().Window(), filepath)};
|
const Core::SystemResultStatus load_result{
|
||||||
|
system.Load(EmulationSession::GetInstance().Window(), filepath)};
|
||||||
if (load_result != Core::SystemResultStatus::Success) {
|
if (load_result != Core::SystemResultStatus::Success) {
|
||||||
return load_result;
|
return load_result;
|
||||||
}
|
}
|
||||||
|
@ -124,19 +125,23 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void HaltEmulation() {
|
void HaltEmulation() {
|
||||||
|
is_running.store(false, std::memory_order_relaxed);
|
||||||
cv.notify_one();
|
cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunEmulation() {
|
void RunEmulation() {
|
||||||
std::unique_lock lock(mutex);
|
std::unique_lock lock(mutex);
|
||||||
|
|
||||||
|
is_running.store(true, std::memory_order_relaxed);
|
||||||
|
|
||||||
void(system.Run());
|
void(system.Run());
|
||||||
|
|
||||||
if (system.DebuggerEnabled()) {
|
if (system.DebuggerEnabled()) {
|
||||||
system.InitializeDebugger();
|
system.InitializeDebugger();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (cv.wait_for(lock, std::chrono::seconds (1)) == std::cv_status::timeout) {
|
while (!cv.wait_for(lock, std::chrono::seconds(1),
|
||||||
|
[&]() { return !is_running.load(std::memory_order_relaxed); })) {
|
||||||
std::scoped_lock perf_stats_lock(perf_stats_mutex);
|
std::scoped_lock perf_stats_lock(perf_stats_mutex);
|
||||||
perf_stats = system.GetAndResetPerfStats();
|
perf_stats = system.GetAndResetPerfStats();
|
||||||
}
|
}
|
||||||
|
@ -157,6 +162,7 @@ private:
|
||||||
std::unique_ptr<EmuWindow_Android> window;
|
std::unique_ptr<EmuWindow_Android> window;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
std::condition_variable_any cv;
|
std::condition_variable_any cv;
|
||||||
|
std::atomic_bool is_running{};
|
||||||
};
|
};
|
||||||
|
|
||||||
/*static*/ EmulationSession EmulationSession::s_instance;
|
/*static*/ EmulationSession EmulationSession::s_instance;
|
||||||
|
@ -231,8 +237,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_NotifyOrientationChange(JNIEnv* env,
|
||||||
jint layout_option,
|
jint layout_option,
|
||||||
jint rotation) {}
|
jint rotation) {}
|
||||||
|
|
||||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_SetUserDirectory(
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_SetUserDirectory([[maybe_unused]] JNIEnv* env,
|
||||||
[[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz,
|
[[maybe_unused]] jclass clazz,
|
||||||
[[maybe_unused]] jstring j_directory) {}
|
[[maybe_unused]] jstring j_directory) {}
|
||||||
|
|
||||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_UnPauseEmulation([[maybe_unused]] JNIEnv* env,
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_UnPauseEmulation([[maybe_unused]] JNIEnv* env,
|
||||||
|
@ -291,11 +297,11 @@ jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_onGamePadAxisEvent([[maybe_unused
|
||||||
}
|
}
|
||||||
|
|
||||||
jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_onTouchEvent([[maybe_unused]] JNIEnv* env,
|
jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_onTouchEvent([[maybe_unused]] JNIEnv* env,
|
||||||
[[maybe_unused]] jclass clazz,
|
[[maybe_unused]] jclass clazz, jfloat x,
|
||||||
jfloat x, jfloat y,
|
jfloat y, jboolean pressed) {
|
||||||
jboolean pressed) {
|
|
||||||
if (EmulationSession::GetInstance().IsRunning()) {
|
if (EmulationSession::GetInstance().IsRunning()) {
|
||||||
return static_cast<jboolean>(EmulationSession::GetInstance().Window().OnTouchEvent(x, y, pressed));
|
return static_cast<jboolean>(
|
||||||
|
EmulationSession::GetInstance().Window().OnTouchEvent(x, y, pressed));
|
||||||
}
|
}
|
||||||
return static_cast<jboolean>(false);
|
return static_cast<jboolean>(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue