Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 1 | /* |
| 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 Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 16 | #include <jni.h> |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 17 | #include <memory> |
| 18 | |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 19 | #include <android/asset_manager_jni.h> |
| 20 | |
| 21 | #include "utils/logging.h" |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 22 | #include "Game.h" |
| 23 | |
Don Turner | 495af0e | 2018-05-25 17:09:54 +0100 | [diff] [blame] | 24 | |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 25 | extern "C" { |
| 26 | |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 27 | std::unique_ptr<Game> game; |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 28 | |
| 29 | JNIEXPORT void JNICALL |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 30 | Java_com_google_oboe_sample_rhythmgame_MainActivity_native_1onCreate(JNIEnv *env, jobject instance, |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 31 | jobject jAssetManager) { |
| 32 | |
| 33 | AAssetManager *assetManager = AAssetManager_fromJava(env, jAssetManager); |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 34 | game = std::make_unique<Game>(assetManager); |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 35 | game->start(); |
| 36 | } |
| 37 | |
| 38 | JNIEXPORT void JNICALL |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 39 | Java_com_google_oboe_sample_rhythmgame_RendererWrapper_native_1onSurfaceCreated(JNIEnv *env, jobject instance) { |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 40 | game->onSurfaceCreated(); |
| 41 | } |
| 42 | |
| 43 | JNIEXPORT void JNICALL |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 44 | Java_com_google_oboe_sample_rhythmgame_RendererWrapper_native_1onSurfaceChanged(JNIEnv *env, jclass type, |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 45 | jint width, jint height) { |
| 46 | game->onSurfaceChanged(width, height); |
| 47 | } |
| 48 | |
| 49 | JNIEXPORT void JNICALL |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 50 | Java_com_google_oboe_sample_rhythmgame_RendererWrapper_native_1onDrawFrame(JNIEnv *env, jclass type) { |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 51 | game->tick(); |
| 52 | } |
| 53 | |
| 54 | JNIEXPORT void JNICALL |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 55 | Java_com_google_oboe_sample_rhythmgame_GameSurfaceView_native_1onTouchInput(JNIEnv *env, jclass type, |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 56 | 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 | |
| 62 | JNIEXPORT void JNICALL |
Don Turner | f7923ae | 2018-04-03 22:43:27 +0100 | [diff] [blame] | 63 | Java_com_google_oboe_sample_rhythmgame_GameSurfaceView_native_1surfaceDestroyed__(JNIEnv *env, jclass type) { |
Don Turner | 0db81a4 | 2018-03-29 17:48:12 +0100 | [diff] [blame] | 64 | game->onSurfaceDestroyed(); |
| 65 | } |
| 66 | |
| 67 | } |