From a604c0aa9f9523f5e35a09fafb14e9550a785f3d Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sat, 22 Jul 2023 18:09:18 +0100 Subject: [PATCH] game-activity: Integrate GameActivity 2.0.2 --- android-activity/CHANGELOG.md | 7 ++-- android-activity/build.rs | 9 +++++- android-activity/src/game_activity/mod.rs | 39 ++++++++++++++++------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/android-activity/CHANGELOG.md b/android-activity/CHANGELOG.md index 4453871..35afefa 100644 --- a/android-activity/CHANGELOG.md +++ b/android-activity/CHANGELOG.md @@ -5,11 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- GameActivity updated to 2.0.2 (requires the corresponding 2.0.2 `.aar` release from Google) ([#88](https://github.com/rust-mobile/android-activity/pull/88)) ## [0.4.3] - 2022-07-30 ### Fixed - Fixed a deadlock in the `native-activity` backend while waiting for the native thread after getting an `onDestroy` callback from Java ([#94](https://github.com/rust-mobile/android-activity/pull/94)) - - Fixed numerous deadlocks in the `game-activity` backend with how it would wait for the native thread in various Java callbacks, after the app has returned from `android_main` ([#98](https://github.com/rust-mobile/android-activity/pull/98)) ## [0.4.2] - 2022-06-17 @@ -26,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Removed some overly-verbose logging in the `native-activity` backend ([#49](https://github.com/rust-mobile/android-activity/pull/49)) ### Removed -- Most of the examples were moved to https://github.com/rust-mobile/rust-android-examples ([#50](https://github.com/rust-mobile/android-activity/pull/50)) +- Most of the examples were moved to ([#50](https://github.com/rust-mobile/android-activity/pull/50)) ## [0.4] - 2022-11-10 ### Changed @@ -61,4 +62,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1] - 2022-07-04 ### Added -- Initial release \ No newline at end of file +- Initial release diff --git a/android-activity/build.rs b/android-activity/build.rs index 305b6ba..7fc92e7 100644 --- a/android-activity/build.rs +++ b/android-activity/build.rs @@ -1,13 +1,20 @@ #![allow(dead_code)] fn build_glue_for_game_activity() { - for f in ["GameActivity.h", "GameActivity.cpp"] { + for f in [ + "GameActivity.h", + "GameActivity.cpp", + "GameActivityEvents.h", + "GameActivityEvents.cpp", + "GameActivityLog.h", + ] { println!("cargo:rerun-if-changed=game-activity-csrc/game-activity/{f}"); } cc::Build::new() .cpp(true) .include("game-activity-csrc") .file("game-activity-csrc/game-activity/GameActivity.cpp") + .file("game-activity-csrc/game-activity/GameActivityEvents.cpp") .extra_warnings(false) .cpp_link_stdlib("c++_static") .compile("libgame_activity.a"); diff --git a/android-activity/src/game_activity/mod.rs b/android-activity/src/game_activity/mod.rs index d43dc6e..95aef1d 100644 --- a/android-activity/src/game_activity/mod.rs +++ b/android-activity/src/game_activity/mod.rs @@ -467,7 +467,17 @@ impl<'a> MotionEventsLendingIterator<'a> { } fn next(&mut self) -> Option> { if self.pos < self.count { - let ga_event = unsafe { &(*self.buffer.ptr.as_ptr()).motionEvents[self.pos] }; + // Safety: + // - This iterator currently has exclusive access to the front buffer of events + // - We know the buffer is non-null + // - `pos` is less than the number of events stored in the buffer + let ga_event = unsafe { + (*self.buffer.ptr.as_ptr()) + .motionEvents + .offset(self.pos as isize) + .as_ref() + .unwrap() + }; let event = MotionEvent::new(ga_event); self.pos += 1; Some(event) @@ -496,7 +506,17 @@ impl<'a> KeyEventsLendingIterator<'a> { } fn next(&mut self) -> Option> { if self.pos < self.count { - let ga_event = unsafe { &(*self.buffer.ptr.as_ptr()).keyEvents[self.pos] }; + // Safety: + // - This iterator currently has exclusive access to the front buffer of events + // - We know the buffer is non-null + // - `pos` is less than the number of events stored in the buffer + let ga_event = unsafe { + (*self.buffer.ptr.as_ptr()) + .keyEvents + .offset(self.pos as isize) + .as_ref() + .unwrap() + }; let event = KeyEvent::new(ga_event); self.pos += 1; Some(event) @@ -543,16 +563,15 @@ impl<'a> Drop for InputBuffer<'a> { // // https://github.com/rust-lang/rfcs/issues/2771 extern "C" { - pub fn Java_com_google_androidgamesdk_GameActivity_loadNativeCode_C( + pub fn Java_com_google_androidgamesdk_GameActivity_initializeNativeCode_C( env: *mut JNIEnv, javaGameActivity: jobject, - path: jstring, - funcName: jstring, internalDataDir: jstring, obbDir: jstring, externalDataDir: jstring, jAssetMgr: jobject, savedState: jbyteArray, + javaConfig: jobject, ) -> jlong; pub fn GameActivity_onCreate_C( @@ -563,27 +582,25 @@ extern "C" { } #[no_mangle] -pub unsafe extern "C" fn Java_com_google_androidgamesdk_GameActivity_loadNativeCode( +pub unsafe extern "C" fn Java_com_google_androidgamesdk_GameActivity_initializeNativeCode( env: *mut JNIEnv, java_game_activity: jobject, - path: jstring, - func_name: jstring, internal_data_dir: jstring, obb_dir: jstring, external_data_dir: jstring, jasset_mgr: jobject, saved_state: jbyteArray, + java_config: jobject, ) -> jni_sys::jlong { - Java_com_google_androidgamesdk_GameActivity_loadNativeCode_C( + Java_com_google_androidgamesdk_GameActivity_initializeNativeCode_C( env, java_game_activity, - path, - func_name, internal_data_dir, obb_dir, external_data_dir, jasset_mgr, saved_state, + java_config, ) }