Add import-games-sdk.sh and import some APP_CMD_ changes for 4.0.0

This replaces `copy-files` + `file_list.txt` (subjective simplification)

This imports the SDK from commit 1b544f896646b29e798c5be0a151a488906797f7, from:
https://github.com/rust-mobile/android-games-sdk/commits/android-activity-4.0.0
This commit is contained in:
Robert Bragg
2025-03-31 20:38:10 +01:00
parent 88714f0b6a
commit 36832feacf
15 changed files with 109 additions and 81 deletions
@@ -1,61 +0,0 @@
#!/usr/bin/env bash
# Copies files from android-games-sdk-rs so that we don't have to use
# it has a submodule (see https://github.com/rust-mobile/android-activity/issues/190)
# Usage: ./copy_files source_dir dest_dir file_list.txt
# file_list.txt should contain one filename or path pattern per line
# Check if correct number of arguments
if [ $# -ne 1 ]; then
echo "Usage: $0 <android-games-sdk-rs dir>"
exit 1
fi
SOURCE_DIR="$1"
DEST_DIR="${2:-.}"
FILE_LIST="${3:-file_list.txt}"
# Check if source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory '$SOURCE_DIR' does not exist."
exit 1
fi
# Check if file list exists
if [ ! -f "$FILE_LIST" ]; then
echo "Error: File list '$FILE_LIST' does not exist."
exit 1
fi
# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"
# Read file list and copy each file
while IFS= read -r file || [ -n "$file" ]; do
# Skip empty lines and comments
if [ -z "$file" ] || [[ "$file" =~ ^# ]]; then
continue
fi
fpath="$(find "$SOURCE_DIR" -name "$file" -type f)"
# Find matching files
if [ -f "$fpath" ]; then
# Get the relative path
rel_path="${fpath#$SOURCE_DIR/}"
dest_file="$DEST_DIR/$rel_path"
dest_dir=$(dirname "$dest_file")
# Create destination directory structure
mkdir -p "$dest_dir"
# Copy the file
cp "$fpath" "$dest_file"
echo "Copied: $rel_path"
else
echo "ERROR: '$file' not found"
fi
done < "$FILE_LIST"
echo "Copy operation completed."
@@ -1,13 +0,0 @@
android_native_app_glue.c
android_native_app_glue.h
GameActivity.cpp
GameActivityEvents.cpp
GameActivityEvents.h
GameActivityEvents_internal.h
GameActivity.h
GameActivityLog.h
gamesdk_common.h
gametextinput.cpp
gametextinput.h
system_utils.cpp
system_utils.h
@@ -0,0 +1 @@
../../../../../include/common/
@@ -217,6 +217,13 @@ struct android_app {
/**
* Last editor action. Valid within APP_CMD_SOFTWARE_KB_VIS_CHANGED handler.
*
* Note: the upstream comment above isn't accurate.
* - `APP_CMD_SOFTWARE_KB_VIS_CHANGED` is associated with `softwareKeyboardVisible`
* changes, not `editorAction`.
* - `APP_CMD_EDITOR_ACTION` is associated with this state but unlike for
* `window` state there's no synchonization that blocks the Java main
* thread, so we can't say that this is only valid within the `APP_CMD_` handler.
*/
int editorAction;
@@ -441,17 +448,17 @@ enum NativeAppGlueAppCmd : int8_t {
/**
* Command from main thread: an editor action has been triggered.
*/
APP_CMD_EDITOR_ACTION,
//APP_CMD_EDITOR_ACTION,
/**
* Command from main thread: a keyboard event has been received.
*/
APP_CMD_KEY_EVENT,
//APP_CMD_KEY_EVENT,
/**
* Command from main thread: a touch event has been received.
*/
APP_CMD_TOUCH_EVENT,
//APP_CMD_TOUCH_EVENT,
};
@@ -0,0 +1 @@
../../../../../../game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h
@@ -0,0 +1,8 @@
{
"export_libraries": [],
"library_name": null,
"android": {
"export_libraries": ["-landroid", "-llog"],
"library_name": null
}
}
@@ -0,0 +1 @@
../../../../../../src/common/system_utils.cpp
@@ -579,7 +579,7 @@ static bool onTouchEvent(GameActivity* activity,
++inputBuffer->motionEventsCount;
notifyInput(android_app);
android_app_write_cmd(android_app, APP_CMD_TOUCH_EVENT);
//android_app_write_cmd(android_app, APP_CMD_TOUCH_EVENT);
pthread_mutex_unlock(&android_app->mutex);
return true;
}
@@ -665,7 +665,7 @@ static bool onKey(GameActivity* activity, const GameActivityKeyEvent* event) {
++inputBuffer->keyEventsCount;
notifyInput(android_app);
android_app_write_cmd(android_app, APP_CMD_KEY_EVENT);
//android_app_write_cmd(android_app, APP_CMD_KEY_EVENT);
pthread_mutex_unlock(&android_app->mutex);
return true;
}
@@ -722,9 +722,15 @@ static bool onEditorAction(GameActivity* activity, int action) {
struct android_app* android_app = ToApp(activity);
pthread_mutex_lock(&android_app->mutex);
android_app->editorAction = action;
android_app_write_cmd(android_app, APP_CMD_EDITOR_ACTION);
// XXX: this is a racy design that could lose InputConnection actions if the
// application doesn't manage to look at app->editorAction before another
// action is delivered.
android_app->editorAction = action;
// TODO: buffer these actions like other input events
//notifyInput(android_app);
//android_app_write_cmd(android_app, APP_CMD_EDITOR_ACTION);
pthread_mutex_unlock(&android_app->mutex);
return true;
}
@@ -0,0 +1 @@
../../../../../../game-text-input/prefab-src/modules/game-text-input/src/game-text-input/gametextinput.cpp
@@ -0,0 +1 @@
../../../../../../game-text-input/prefab-src/modules/game-text-input/include/game-text-input/gametextinput.h
@@ -0,0 +1,13 @@
{
"name": "game-activity",
"schema_version": 1,
"dependencies": [],
"version": "0.0.1",
"cpp_files": [
"src/common/system_utils.cpp",
"src/game-activity/GameActivity.cpp",
"src/game-activity/native_app_glue/android_native_app_glue.c",
"src/game-activity/GameActivityEvents.cpp",
"src/game-text-input/gametextinput.cpp"
]
}
@@ -0,0 +1 @@
../../../../../include/common/
@@ -0,0 +1,8 @@
{
"export_libraries": [],
"library_name": null,
"android": {
"export_libraries": null,
"library_name": null
}
}
@@ -0,0 +1,9 @@
{
"name": "game-text-input",
"schema_version": 1,
"dependencies": [],
"version": "0.0.1",
"cpp_files": [
"src/game-text-input/gametextinput.cpp"
]
}
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
set -xe
# Copies the native, prefab-src for GameActivity + GameTextInput from the
# upstream, android-games-sdk, including our android-activity integration
# changes.
#
# This code is maintained out-of-tree, based on a fork of Google's AGDK repo, so
# it's more practical to try and upstream changes we make, or to rebase on new
# versions.
if [ $# -ne 1 ]; then
echo "Usage: $0 <android-games-sdk dir>"
exit 1
fi
SOURCE_DIR="$1"
TOP_DIR=$(git rev-parse --show-toplevel)
DEST_DIR="$TOP_DIR/android-activity/android-games-sdk"
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory '$SOURCE_DIR' does not exist."
exit 1
fi
if [ ! -d "$DEST_DIR" ]; then
echo "Error: expected find destination directory $DEST_DIR"
exit 1
fi
rm -fr "$DEST_DIR/game-activity"
rm -fr "$DEST_DIR/game-text-input"
rm -fr "$DEST_DIR/src/common"
rm -fr "$DEST_DIR/include/common"
mkdir -p "$DEST_DIR/game-activity"
mkdir -p "$DEST_DIR/game-text-input"
mkdir -p "$DEST_DIR/include/common"
mkdir -p "$DEST_DIR/src/common"
cp -av "$SOURCE_DIR/game-activity/prefab-src" "$DEST_DIR/game-activity"
cp -av "$SOURCE_DIR/game-text-input/prefab-src" "$DEST_DIR/game-text-input"
cp -av "$SOURCE_DIR/include/common/gamesdk_common.h" "$DEST_DIR/include/common"
cp -av "$SOURCE_DIR/src/common/system_utils.h" "$DEST_DIR/src/common"
cp -av "$SOURCE_DIR/src/common/system_utils.cpp" "$DEST_DIR/src/common"