Skip to content

Commit a604c0a

Browse files
committed
game-activity: Integrate GameActivity 2.0.2
1 parent b09526a commit a604c0a

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

android-activity/CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- 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))
810

911
## [0.4.3] - 2022-07-30
1012
### Fixed
1113
- 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))
12-
1314
- 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))
1415

1516
## [0.4.2] - 2022-06-17
@@ -26,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2627
### Changed
2728
- Removed some overly-verbose logging in the `native-activity` backend ([#49](https://github.com/rust-mobile/android-activity/pull/49))
2829
### Removed
29-
- 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))
30+
- 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))
3031

3132
## [0.4] - 2022-11-10
3233
### Changed
@@ -61,4 +62,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6162

6263
## [0.1] - 2022-07-04
6364
### Added
64-
- Initial release
65+
- Initial release

android-activity/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#![allow(dead_code)]
22

33
fn build_glue_for_game_activity() {
4-
for f in ["GameActivity.h", "GameActivity.cpp"] {
4+
for f in [
5+
"GameActivity.h",
6+
"GameActivity.cpp",
7+
"GameActivityEvents.h",
8+
"GameActivityEvents.cpp",
9+
"GameActivityLog.h",
10+
] {
511
println!("cargo:rerun-if-changed=game-activity-csrc/game-activity/{f}");
612
}
713
cc::Build::new()
814
.cpp(true)
915
.include("game-activity-csrc")
1016
.file("game-activity-csrc/game-activity/GameActivity.cpp")
17+
.file("game-activity-csrc/game-activity/GameActivityEvents.cpp")
1118
.extra_warnings(false)
1219
.cpp_link_stdlib("c++_static")
1320
.compile("libgame_activity.a");

android-activity/src/game_activity/mod.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,17 @@ impl<'a> MotionEventsLendingIterator<'a> {
467467
}
468468
fn next(&mut self) -> Option<MotionEvent<'a>> {
469469
if self.pos < self.count {
470-
let ga_event = unsafe { &(*self.buffer.ptr.as_ptr()).motionEvents[self.pos] };
470+
// Safety:
471+
// - This iterator currently has exclusive access to the front buffer of events
472+
// - We know the buffer is non-null
473+
// - `pos` is less than the number of events stored in the buffer
474+
let ga_event = unsafe {
475+
(*self.buffer.ptr.as_ptr())
476+
.motionEvents
477+
.offset(self.pos as isize)
478+
.as_ref()
479+
.unwrap()
480+
};
471481
let event = MotionEvent::new(ga_event);
472482
self.pos += 1;
473483
Some(event)
@@ -496,7 +506,17 @@ impl<'a> KeyEventsLendingIterator<'a> {
496506
}
497507
fn next(&mut self) -> Option<KeyEvent<'a>> {
498508
if self.pos < self.count {
499-
let ga_event = unsafe { &(*self.buffer.ptr.as_ptr()).keyEvents[self.pos] };
509+
// Safety:
510+
// - This iterator currently has exclusive access to the front buffer of events
511+
// - We know the buffer is non-null
512+
// - `pos` is less than the number of events stored in the buffer
513+
let ga_event = unsafe {
514+
(*self.buffer.ptr.as_ptr())
515+
.keyEvents
516+
.offset(self.pos as isize)
517+
.as_ref()
518+
.unwrap()
519+
};
500520
let event = KeyEvent::new(ga_event);
501521
self.pos += 1;
502522
Some(event)
@@ -543,16 +563,15 @@ impl<'a> Drop for InputBuffer<'a> {
543563
//
544564
// https://github.com/rust-lang/rfcs/issues/2771
545565
extern "C" {
546-
pub fn Java_com_google_androidgamesdk_GameActivity_loadNativeCode_C(
566+
pub fn Java_com_google_androidgamesdk_GameActivity_initializeNativeCode_C(
547567
env: *mut JNIEnv,
548568
javaGameActivity: jobject,
549-
path: jstring,
550-
funcName: jstring,
551569
internalDataDir: jstring,
552570
obbDir: jstring,
553571
externalDataDir: jstring,
554572
jAssetMgr: jobject,
555573
savedState: jbyteArray,
574+
javaConfig: jobject,
556575
) -> jlong;
557576

558577
pub fn GameActivity_onCreate_C(
@@ -563,27 +582,25 @@ extern "C" {
563582
}
564583

565584
#[no_mangle]
566-
pub unsafe extern "C" fn Java_com_google_androidgamesdk_GameActivity_loadNativeCode(
585+
pub unsafe extern "C" fn Java_com_google_androidgamesdk_GameActivity_initializeNativeCode(
567586
env: *mut JNIEnv,
568587
java_game_activity: jobject,
569-
path: jstring,
570-
func_name: jstring,
571588
internal_data_dir: jstring,
572589
obb_dir: jstring,
573590
external_data_dir: jstring,
574591
jasset_mgr: jobject,
575592
saved_state: jbyteArray,
593+
java_config: jobject,
576594
) -> jni_sys::jlong {
577-
Java_com_google_androidgamesdk_GameActivity_loadNativeCode_C(
595+
Java_com_google_androidgamesdk_GameActivity_initializeNativeCode_C(
578596
env,
579597
java_game_activity,
580-
path,
581-
func_name,
582598
internal_data_dir,
583599
obb_dir,
584600
external_data_dir,
585601
jasset_mgr,
586602
saved_state,
603+
java_config,
587604
)
588605
}
589606

0 commit comments

Comments
 (0)