mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-14 09:04:31 +02:00
#15 migrating from Eclipse to Android Studio
This commit is contained in:
14
src/platform/android/app/CMakeLists.txt
Normal file
14
src/platform/android/app/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANDROID -std=c++11 -fno-rtti -fno-exceptions -fvisibility=hidden -Wall")
|
||||
|
||||
add_library( game SHARED
|
||||
src/main/cpp/main.cpp
|
||||
../../../libs/stb_vorbis/stb_vorbis.c
|
||||
../../../libs/minimp3/minimp3.cpp
|
||||
)
|
||||
|
||||
include_directories(../../../)
|
||||
|
||||
target_link_libraries( game GLESv2 log )
|
36
src/platform/android/app/build.gradle
Normal file
36
src/platform/android/app/build.gradle
Normal file
@@ -0,0 +1,36 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
defaultConfig {
|
||||
applicationId "com.xproger.openlara"
|
||||
minSdkVersion 18
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a'
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments '-DANDROID_TOOLCHAIN=clang'
|
||||
}
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
25
src/platform/android/app/proguard-rules.pro
vendored
Normal file
25
src/platform/android/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\XProger\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
30
src/platform/android/app/src/main/AndroidManifest.xml
Normal file
30
src/platform/android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.xproger.openlara"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.1" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18" />
|
||||
<supports-screens android:smallScreens="true" android:largeScreens="true" android:normalScreens="true" android:xlargeScreens="true" />
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
||||
<!--
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="com.qti.permission.PROFILER" />
|
||||
android:debuggable="true"
|
||||
-->
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="sensorLandscape">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
162
src/platform/android/app/src/main/cpp/main.cpp
Normal file
162
src/platform/android/app/src/main/cpp/main.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
//#include "vr/gvr/capi/include/gvr.h"
|
||||
#include <sys/time.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "game.h"
|
||||
|
||||
#define JNI_METHOD(return_type, method_name) \
|
||||
JNIEXPORT return_type JNICALL \
|
||||
Java_org_xproger_openlara_Wrapper_##method_name
|
||||
|
||||
int getTime() {
|
||||
timeval time;
|
||||
gettimeofday(&time, NULL);
|
||||
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
int lastTime, fpsTime, fps;
|
||||
|
||||
char Stream::cacheDir[255];
|
||||
char Stream::contentDir[255];
|
||||
|
||||
JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring packName, jstring cacheDir, jint levelOffset, jint musicOffset) {
|
||||
const char* str;
|
||||
|
||||
Stream::contentDir[0] = Stream::cacheDir[0] = 0;
|
||||
str = env->GetStringUTFChars(cacheDir, NULL);
|
||||
strcat(Stream::cacheDir, str);
|
||||
env->ReleaseStringUTFChars(cacheDir, str);
|
||||
|
||||
str = env->GetStringUTFChars(packName, NULL);
|
||||
Stream *level = new Stream(str);
|
||||
Stream *music = new Stream(str);
|
||||
env->ReleaseStringUTFChars(packName, str);
|
||||
|
||||
level->seek(levelOffset);
|
||||
music->seek(musicOffset);
|
||||
|
||||
Game::init(level, music);
|
||||
|
||||
lastTime = getTime();
|
||||
fpsTime = lastTime + 1000;
|
||||
fps = 0;
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeFree)(JNIEnv* env) {
|
||||
Game::free();
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeReset)(JNIEnv* env) {
|
||||
// core->reset();
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeUpdate)(JNIEnv* env) {
|
||||
int time = getTime();
|
||||
if (time == lastTime)
|
||||
return;
|
||||
Game::update((time - lastTime) * 0.001f);
|
||||
lastTime = time;
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeRender)(JNIEnv* env) {
|
||||
Core::stats.dips = 0;
|
||||
Core::stats.tris = 0;
|
||||
Game::render();
|
||||
if (fpsTime < getTime()) {
|
||||
LOG("FPS: %d DIP: %d TRI: %d\n", fps, Core::stats.dips, Core::stats.tris);
|
||||
fps = 0;
|
||||
fpsTime = getTime() + 1000;
|
||||
} else
|
||||
fps++;
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeResize)(JNIEnv* env, jobject obj, jint w, jint h) {
|
||||
Core::width = w;
|
||||
Core::height = h;
|
||||
}
|
||||
|
||||
float DeadZone(float x) {
|
||||
return x = fabsf(x) < 0.2f ? 0.0f : x;
|
||||
}
|
||||
|
||||
int getPOV(int x, int y) {
|
||||
switch (x) {
|
||||
case -1 : {
|
||||
if (y == -1) return 8;
|
||||
if (y == 0) return 7;
|
||||
if (y == +1) return 6;
|
||||
}
|
||||
case 0 : {
|
||||
if (y == -1) return 1;
|
||||
if (y == 0) return 0;
|
||||
if (y == +1) return 5;
|
||||
}
|
||||
case +1 : {
|
||||
if (y == -1) return 2;
|
||||
if (y == 0) return 3;
|
||||
if (y == +1) return 4;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
InputKey keyToInputKey(int code) {
|
||||
int codes[] = {
|
||||
21, 22, 19, 20, 62, 66, 111, 59, 113, 57,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
|
||||
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
|
||||
};
|
||||
|
||||
for (int i = 0; i < sizeof(codes) / sizeof(codes[0]); i++)
|
||||
if (codes[i] == code)
|
||||
return (InputKey)(ikLeft + i);
|
||||
return ikNone;
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeTouch)(JNIEnv* env, jobject obj, jint id, jint state, jfloat x, jfloat y) {
|
||||
// gamepad / keyboard
|
||||
if (state < 0) {
|
||||
switch (state) {
|
||||
case -3 : Input::setPos(ikJoyL, vec2(DeadZone(x), DeadZone(y))); break;
|
||||
case -4 : Input::setPos(ikJoyR, vec2(DeadZone(x), DeadZone(y))); break;
|
||||
case -5 : Input::setPos(ikJoyPOV, vec2(float(getPOV(sign(x), sign(y))), 0.0f)); break;
|
||||
default : {
|
||||
int btn = int(x);
|
||||
InputKey key = btn <= 0 ? InputKey(ikJoyA - btn) : keyToInputKey(btn);
|
||||
Input::setDown(key, state != -1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == -100) {
|
||||
switch (state) {
|
||||
case 0 : Input::head.basis.rot.x = x; Input::head.basis.rot.y = y; break;
|
||||
case 1 : Input::head.basis.rot.z = x; Input::head.basis.rot.w = y; Input::head.set(); break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// touch
|
||||
InputKey key = Input::getTouch(id);
|
||||
if (key == ikNone) return;
|
||||
Input::setPos(key, vec2(x, y));
|
||||
if (state == 1 || state == 2)
|
||||
Input::setDown(key, state == 2);
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeSoundFill)(JNIEnv* env, jobject obj, jshortArray buffer) {
|
||||
jshort *frames = env->GetShortArrayElements(buffer, NULL);
|
||||
jsize count = env->GetArrayLength(buffer) / 2;
|
||||
Sound::fill((Sound::Frame*)frames, count);
|
||||
env->ReleaseShortArrayElements(buffer, frames, 0);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,322 @@
|
||||
package org.xproger.openlara;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioTrack;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.opengl.GLSurfaceView.Renderer;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnGenericMotionListener;
|
||||
import android.view.View.OnKeyListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
//import android.util.Log;
|
||||
|
||||
public class MainActivity extends Activity implements OnTouchListener, OnKeyListener, OnGenericMotionListener, SensorEventListener {
|
||||
private Wrapper wrapper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
|
||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
|
||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
GLSurfaceView view = new GLSurfaceView(this);
|
||||
view.setEGLContextClientVersion(2);
|
||||
view.setEGLConfigChooser(8, 8, 8, 8, 16, 8);
|
||||
view.setPreserveEGLContextOnPause(true);
|
||||
view.setRenderer(wrapper = new Wrapper());
|
||||
|
||||
view.setFocusable(true);
|
||||
view.setFocusableInTouchMode(true);
|
||||
|
||||
view.setOnTouchListener(this);
|
||||
view.setOnGenericMotionListener(this);
|
||||
view.setOnKeyListener(this);
|
||||
//setAsyncReprojectionEnabled(true);
|
||||
//setSustainedPerformanceMode(this, true);
|
||||
setContentView(view);
|
||||
|
||||
SensorManager sm = (SensorManager)getSystemService(SENSOR_SERVICE);
|
||||
sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_GAME_ROTATION_VECTOR), SensorManager.SENSOR_DELAY_FASTEST);
|
||||
|
||||
try {
|
||||
String packName = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES).applicationInfo.sourceDir;
|
||||
AssetFileDescriptor fLevel = this.getResources().openRawResourceFd(R.raw.level2);
|
||||
AssetFileDescriptor fMusic = this.getResources().openRawResourceFd(R.raw.music);
|
||||
|
||||
wrapper.onCreate(packName, getCacheDir().getAbsolutePath() + "/", (int)fLevel.getStartOffset(), (int)fMusic.getStartOffset());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
wrapper.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
wrapper.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
wrapper.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
int action = event.getAction();
|
||||
int type = action & MotionEvent.ACTION_MASK;
|
||||
int state;
|
||||
|
||||
switch (type) {
|
||||
case MotionEvent.ACTION_DOWN :
|
||||
case MotionEvent.ACTION_UP :
|
||||
case MotionEvent.ACTION_MOVE :
|
||||
state = type == MotionEvent.ACTION_MOVE ? 3 : (type == MotionEvent.ACTION_DOWN ? 2 : 1);
|
||||
for (int i = 0; i < event.getPointerCount(); i++)
|
||||
wrapper.onTouch(event.getPointerId(i), state, event.getX(i), event.getY(i));
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_DOWN :
|
||||
case MotionEvent.ACTION_POINTER_UP :
|
||||
int i = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
||||
state = type == MotionEvent.ACTION_POINTER_DOWN ? 2 : 1;
|
||||
wrapper.onTouch(event.getPointerId(i), state, event.getX(i), event.getY(i));
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor arg0, int arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// wrapper.onTouch(-100, 0, event.values[0], event.values[1]);
|
||||
// wrapper.onTouch(-100, 1, event.values[2], event.values[3]);
|
||||
wrapper.onTouch(-100, 0, -event.values[1], event.values[0]);
|
||||
wrapper.onTouch(-100, 1, event.values[2], event.values[3]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotion(View v, MotionEvent event) {
|
||||
int src = event.getDevice().getSources();
|
||||
|
||||
boolean isMouse = (src & (InputDevice.SOURCE_MOUSE)) != 0;
|
||||
boolean isJoy = (src & (InputDevice.SOURCE_GAMEPAD | InputDevice.SOURCE_JOYSTICK)) != 0;
|
||||
|
||||
if (isMouse) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isJoy) {
|
||||
wrapper.onTouch(0, -3, event.getAxisValue(MotionEvent.AXIS_X),
|
||||
event.getAxisValue(MotionEvent.AXIS_Y));
|
||||
|
||||
wrapper.onTouch(0, -4, event.getAxisValue(MotionEvent.AXIS_Z),
|
||||
event.getAxisValue(MotionEvent.AXIS_RZ));
|
||||
|
||||
wrapper.onTouch(0, -5, event.getAxisValue(MotionEvent.AXIS_HAT_X),
|
||||
event.getAxisValue(MotionEvent.AXIS_HAT_Y));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
int btn;
|
||||
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BUTTON_A : btn = -0; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_B : btn = -1; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_X : btn = -2; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_Y : btn = -3; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_L1 : btn = -4; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_R1 : btn = -5; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_SELECT : btn = -6; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_START : btn = -7; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBL : btn = -8; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBR : btn = -9; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_L2 : btn = -10; break;
|
||||
case KeyEvent.KEYCODE_BUTTON_R2 : btn = -11; break;
|
||||
case KeyEvent.KEYCODE_BACK : btn = KeyEvent.KEYCODE_ESCAPE; break;
|
||||
default : btn = keyCode;
|
||||
}
|
||||
|
||||
boolean isDown = event.getAction() == KeyEvent.ACTION_DOWN;
|
||||
wrapper.onTouch(0, isDown ? -2 : -1, btn, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("game");
|
||||
// System.loadLibrary("gvr");
|
||||
// System.load("/storage/emulated/0/libMGD.so");
|
||||
}
|
||||
}
|
||||
|
||||
class Sound {
|
||||
private short buffer[];
|
||||
private static AudioTrack audioTrack;
|
||||
|
||||
void start(final Wrapper wrapper) {
|
||||
int rate = 44100;
|
||||
int size = AudioTrack.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
//System.out.println(String.format("sound buffer size: %d", bufSize));
|
||||
buffer = new short [size / 2];
|
||||
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO,
|
||||
AudioFormat.ENCODING_PCM_16BIT, size, AudioTrack.MODE_STREAM);
|
||||
audioTrack.play();
|
||||
|
||||
new Thread( new Runnable() {
|
||||
public void run() {
|
||||
while ( audioTrack.getPlayState() != AudioTrack.PLAYSTATE_STOPPED ) {
|
||||
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING && wrapper.ready) {
|
||||
synchronized (wrapper) {
|
||||
Wrapper.nativeSoundFill(buffer);
|
||||
}
|
||||
audioTrack.write(buffer, 0, buffer.length);
|
||||
audioTrack.flush();
|
||||
} else
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch(Exception e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
} ).start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
audioTrack.flush();
|
||||
audioTrack.stop();
|
||||
audioTrack.release();
|
||||
}
|
||||
|
||||
void play() {
|
||||
audioTrack.play();
|
||||
}
|
||||
|
||||
void pause() {
|
||||
audioTrack.pause();
|
||||
}
|
||||
}
|
||||
|
||||
class Touch {
|
||||
int id, state;
|
||||
float x, y;
|
||||
Touch(int _id, int _state, float _x, float _y) {
|
||||
id = _id;
|
||||
state = _state;
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
}
|
||||
|
||||
class Wrapper implements Renderer {
|
||||
public static native void nativeInit(String packName, String cacheDir, int levelOffset, int musicOffset);
|
||||
public static native void nativeFree();
|
||||
public static native void nativeReset();
|
||||
public static native void nativeResize(int w, int h);
|
||||
public static native void nativeUpdate();
|
||||
public static native void nativeRender();
|
||||
public static native void nativeTouch(int id, int state, float x, float y);
|
||||
public static native void nativeSoundFill(short buffer[]);
|
||||
|
||||
Boolean ready = false;
|
||||
private String packName;
|
||||
private String cacheDir;
|
||||
private int levelOffset;
|
||||
private int musicOffset;
|
||||
private ArrayList<Touch> touch = new ArrayList<>();
|
||||
private Sound sound;
|
||||
|
||||
void onCreate(String packName, String cacheDir, int levelOffset, int musicOffset) {
|
||||
this.packName = packName;
|
||||
this.cacheDir = cacheDir;
|
||||
this.levelOffset = levelOffset;
|
||||
this.musicOffset = musicOffset;
|
||||
|
||||
sound = new Sound();
|
||||
sound.start(this);
|
||||
}
|
||||
|
||||
void onDestroy() {
|
||||
sound.stop();
|
||||
nativeFree();
|
||||
}
|
||||
|
||||
void onPause() {
|
||||
sound.pause();
|
||||
}
|
||||
|
||||
void onResume() {
|
||||
sound.play();
|
||||
if (ready) nativeReset();
|
||||
}
|
||||
|
||||
void onTouch(int id, int state, float x, float y) {
|
||||
synchronized (this) {
|
||||
touch.add(new Touch(id, state, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < touch.size(); i++) {
|
||||
Touch t = touch.get(i);
|
||||
nativeTouch(t.id, t.state, t.x, t.y);
|
||||
}
|
||||
touch.clear();
|
||||
nativeUpdate();
|
||||
}
|
||||
nativeRender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
nativeResize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
if (!ready) {
|
||||
nativeInit(packName, cacheDir, levelOffset, musicOffset);
|
||||
sound.play();
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/platform/android/app/src/main/res/drawable/ic_launcher.png
Normal file
BIN
src/platform/android/app/src/main/res/drawable/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
3
src/platform/android/app/src/main/res/values/strings.xml
Normal file
3
src/platform/android/app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">OpenLara</string>
|
||||
</resources>
|
23
src/platform/android/build.gradle
Normal file
23
src/platform/android/build.gradle
Normal file
@@ -0,0 +1,23 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
17
src/platform/android/gradle.properties
Normal file
17
src/platform/android/gradle.properties
Normal file
@@ -0,0 +1,17 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
BIN
src/platform/android/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
src/platform/android/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
src/platform/android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
src/platform/android/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
160
src/platform/android/gradlew
vendored
Normal file
160
src/platform/android/gradlew
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
90
src/platform/android/gradlew.bat
vendored
Normal file
90
src/platform/android/gradlew.bat
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
1
src/platform/android/settings.gradle
Normal file
1
src/platform/android/settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
include ':app'
|
Reference in New Issue
Block a user