blob: b7859cefda2c04e6c074247e0872f5e637e188ba [file] [log] [blame]
Don Turnerf7923ae2018-04-03 22:43:27 +01001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Don Turner0db81a42018-03-29 17:48:12 +010016#include <jni.h>
Don Turner0db81a42018-03-29 17:48:12 +010017#include <memory>
18
Don Turnerf7923ae2018-04-03 22:43:27 +010019#include <android/asset_manager_jni.h>
20
21#include "utils/logging.h"
Don Turner0db81a42018-03-29 17:48:12 +010022#include "Game.h"
23
Don Turner495af0e2018-05-25 17:09:54 +010024
Don Turner0db81a42018-03-29 17:48:12 +010025extern "C" {
26
Don Turnerf7923ae2018-04-03 22:43:27 +010027std::unique_ptr<Game> game;
Don Turner0db81a42018-03-29 17:48:12 +010028
29JNIEXPORT void JNICALL
Don Turnerf7923ae2018-04-03 22:43:27 +010030Java_com_google_oboe_sample_rhythmgame_MainActivity_native_1onCreate(JNIEnv *env, jobject instance,
Don Turner0db81a42018-03-29 17:48:12 +010031 jobject jAssetManager) {
32
33 AAssetManager *assetManager = AAssetManager_fromJava(env, jAssetManager);
Don Turnerf7923ae2018-04-03 22:43:27 +010034 game = std::make_unique<Game>(assetManager);
Don Turner0db81a42018-03-29 17:48:12 +010035 game->start();
36}
37
38JNIEXPORT void JNICALL
Don Turnerf7923ae2018-04-03 22:43:27 +010039Java_com_google_oboe_sample_rhythmgame_RendererWrapper_native_1onSurfaceCreated(JNIEnv *env, jobject instance) {
Don Turner0db81a42018-03-29 17:48:12 +010040 game->onSurfaceCreated();
41}
42
43JNIEXPORT void JNICALL
Don Turnerf7923ae2018-04-03 22:43:27 +010044Java_com_google_oboe_sample_rhythmgame_RendererWrapper_native_1onSurfaceChanged(JNIEnv *env, jclass type,
Don Turner0db81a42018-03-29 17:48:12 +010045 jint width, jint height) {
46 game->onSurfaceChanged(width, height);
47}
48
49JNIEXPORT void JNICALL
Don Turnerf7923ae2018-04-03 22:43:27 +010050Java_com_google_oboe_sample_rhythmgame_RendererWrapper_native_1onDrawFrame(JNIEnv *env, jclass type) {
Don Turner0db81a42018-03-29 17:48:12 +010051 game->tick();
52}
53
54JNIEXPORT void JNICALL
Don Turnerf7923ae2018-04-03 22:43:27 +010055Java_com_google_oboe_sample_rhythmgame_GameSurfaceView_native_1onTouchInput(JNIEnv *env, jclass type,
Don Turner0db81a42018-03-29 17:48:12 +010056 jint event_type,
57 jlong time_since_boot_ms,
58 jint pixel_x, jint pixel_y) {
59 game->tap(time_since_boot_ms);
60}
61
62JNIEXPORT void JNICALL
Don Turnerf7923ae2018-04-03 22:43:27 +010063Java_com_google_oboe_sample_rhythmgame_GameSurfaceView_native_1surfaceDestroyed__(JNIEnv *env, jclass type) {
Don Turner0db81a42018-03-29 17:48:12 +010064 game->onSurfaceDestroyed();
65}
66
67}