(upbeat music)
Hello. I’m Victor Repetskyi,
the technical leader of Android Games team in London.
And in this talk, I’m covering new C/C++ libraries
designed to help you build your game and game engines.
AGDK is a new initiative.
It’s a set of tools and libraries from Google to help game development.
Firstly, it contains workflow tools to make our Android development efficient.
Next it includes our C/C++ development libraries
to make games easier to build, debug and maintain.
And some of these libraries I'm covering today.
And lastly it contains a set of tools
to optimize your game quality and performance.
So how are C/C++ libraries distributed?
You can get them from AAR packages which I’ll be talking about later.
You can get both static and dynamic libraries from AGDK's file.
And for advanced integration you can get the source code
from Android Open Source project.
First library is Game Activity.
So what is Game Activity?
As you know, Activity class is a starting point of any Android app.
It allows accessing rendering surface, and handling life cycle and input events.
However, high-performance game engines are developed in C/C++,
and developers need a way to handle
all aspect of Activity class in their C/C++ code.
To pass control from activity to C/C++ code developers use JNI,
but it is complicated and error prone.
So Game Activity is designed to simplify plumbing between the activity and C/C++.
So what is Game Activity exactly?
So, game activities are an activity specifically designed for games
and game engines developed in C/C++.
It inherits from AppCompatActivity,
allowing you to use the Jetpack components architecture
and still use some of their newer features of the platform on old Android devices.
It renders into a SurfaceView
which allows you to interface with any Android UI element.
It handles events, like Activity class does, allowing your Android UI elements
such as textbox, webview, or an ad or form, to work as usual.
It expose the events to your game using the C interface
and makes them easier to consume in your game loop.
It offers C API similar to NativeActivity.
So how Game Activity here is designed?
It contains two parts.
One is Java part, a Game Activity class,
which is intended to interact with any existing UI toolkits
such as Antd or any other Android libraries which are available only in Java.
It’s has a second part, a C/C++ part,
because there is the native glue code,
which helps you to handle events in your C/C++ code
and interacts with your C/C++ code.
So how you implement our Game Activity?
First thing you need to extend the class Game Activity.
You can override any necessary methods to the game activity here.
Don’t forget to load your native part, using the system load library methods.
The android_native_app_glue library calls
the following function and passing it a preferred state structure.
It also serves as a wrapper that simplifies handling of Game Activity callbacks.
android_main function is the analog of activity in C/C++ code,
and it takes our android_app struct as a parameter.
Next topic is our Game Text Input API.
So why we need a game text input API?
In general, it’s complicated to write full-screen Android app in C/C++,
that uses the software keyboard for text input.
The typical workaround involves showing and hiding an EditText box.
However, this requires you to handle many edge cases
and ensure that it works across different devices,
different IMEs and platform changes.
The Text Input API hides this complexity of IME
and provides you easy-to-use C interface.
So Game Text Input API provides functions to show and hide software keyboard,
set and get the currently editing text & receive notification when the text changes.
It supports the following features:
Text input, text selection, composing regions,
spell-checking, completion, and multi-key characters.
So how are the Game Text Input APIs designed?
Serves as a middleman between Android platform,
which has Input Methods Manager,
specific IMEs, such as Gboard or Swift and your game.
A sample use case of Text Input API includes:
first, you need to init the library using GameInput_init.
Then, check that the InputConnection is passed
to the C library using setInputConnection method.
Then check a listener for State changes to the InputConnection.
Then check that processEvent is called.
Then use showIme and hideIme functions to show and hide IME.
And you can pass a callback using the method setEventCallback.
The steps two and four are not necessary if you're using Game Activity.
Next topic is a Game Controller API.
So why so we need Game Controller API?
Implementing game controller support in C/C++ Android applications
has always involves a fair bit of work for developers.
Events from controller devices can be accessed in C/C++ code
through the input functionality of the NDK.
But enumeration of relevant input devices,
retrieving capabilities of those input devices,
and receiving notification of device connection
and removal are not available through this current NDK API.
Applications must implement this functionality using JNI code,
that uses Input Manager API.
Game Controller API hides this complexity
and allows you to handle controller event in your C/C++ code.
What features are supported by Game Controller API?
It supports callbacks for detecting controller connections and disconnections.
It supports getting controller device information,
including button style and layout.
It supports controller input data
standardized around modern dual-stick controller designs.
It supports extended features for controllers,
including vibration, lights, motion axis data, and beta status.
Reading input from virtual and physical mouse devices,
and ability to specify custom control mapping data for particular devices.
A typical use case of the library includes,
first, call the Init functions.
Then, implement lifecycle event with onPause and onResume functions.
Then reading controller information
using getControllerinfo and getControllerData functions.
Then, call in update function once per game frame.
And then, process events using the processGameActivityInputEvent function,
and closing the library with destroy function.
So how can you use C and C++ libraries delivered as AAR functions?
Android AAR is a file format for Android libraries.
You can include it as a dependency for an Android app.
Unlike JAR files, AAR files contain extra Android information,
and also can contain C and C++ libraries for the use by game C/C++ code.
Google Jetpack offers many Android libraries distributed through Maven repository.
So, to use our C/C++ AAR in your project,
you need to do the following changes to your root Gradle file.
You need to include the repository.
A Google repository means that you can download the Jetpack libraries,
but you can include a local repository issue if you are using AAR files locally.
You need to include dependencies on the latest Android Gradle plugin.
Next, in your app build.gradle file, you include the following settings:
set the prefab to true
and include the libraries you need in dependencies.
Next, you include in the gradle.properties files
the following properties: AndroidX=true,
and Android.prefabVersion, you specify as 1.1.2 or more recent.
Now you can add the libraries to your CMake file.
This will allow linking the libraries to your project.
And in this example, you can see how to include game activity.
After this step, you can include header and source files into your project.
So, this is all.
Thank you all for your attention.
If you’re interested, download AGDK by following the link.
You can find all of the source code and samples there.
(upbeat music)