mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-10 07:06:52 +02:00
#15 fix android build, add content directory for audio tracks (/sdcard/OpenLara/audio/), add binary data
This commit is contained in:
BIN
bin/OpenLara.exe
BIN
bin/OpenLara.exe
Binary file not shown.
BIN
bin/audio/track_03.ogg
Normal file
BIN
bin/audio/track_03.ogg
Normal file
Binary file not shown.
@@ -10,7 +10,7 @@ android {
|
|||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "0.1"
|
versionName "0.1"
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters 'armeabi-v7a','x86','x86_64'
|
abiFilters 'armeabi-v7a', 'x86', 'x86_64'
|
||||||
}
|
}
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
@@ -29,6 +29,9 @@ android {
|
|||||||
path "CMakeLists.txt"
|
path "CMakeLists.txt"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
aaptOptions {
|
||||||
|
noCompress 'psx', 'phd', 'pcx', 'mp3', 'ogg'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@@ -9,9 +9,10 @@
|
|||||||
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
|
||||||
<!--
|
<!--
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="com.qti.permission.PROFILER" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
android:debuggable="true"
|
|
||||||
-->
|
-->
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
|
@@ -10,10 +10,12 @@
|
|||||||
JNIEXPORT return_type JNICALL \
|
JNIEXPORT return_type JNICALL \
|
||||||
Java_org_xproger_openlara_Wrapper_##method_name
|
Java_org_xproger_openlara_Wrapper_##method_name
|
||||||
|
|
||||||
|
time_t startTime;
|
||||||
|
|
||||||
int getTime() {
|
int getTime() {
|
||||||
timeval time;
|
timeval t;
|
||||||
gettimeofday(&time, NULL);
|
gettimeofday(&t, NULL);
|
||||||
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
|
return int((t.tv_sec - startTime) * 1000 + t.tv_usec / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -23,23 +25,29 @@ int lastTime;
|
|||||||
char Stream::cacheDir[255];
|
char Stream::cacheDir[255];
|
||||||
char Stream::contentDir[255];
|
char Stream::contentDir[255];
|
||||||
|
|
||||||
JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring packName, jstring cacheDir, jint levelOffset, jint musicOffset) {
|
JNI_METHOD(void, nativeInit)(JNIEnv* env, jobject obj, jstring contentDir, jstring cacheDir, jstring packName, jint levelOffset) {
|
||||||
|
timeval t;
|
||||||
|
gettimeofday(&t, NULL);
|
||||||
|
startTime = t.tv_sec;
|
||||||
|
|
||||||
const char* str;
|
const char* str;
|
||||||
|
|
||||||
Stream::contentDir[0] = Stream::cacheDir[0] = 0;
|
Stream::contentDir[0] = Stream::cacheDir[0] = 0;
|
||||||
|
|
||||||
|
str = env->GetStringUTFChars(packName, NULL);
|
||||||
|
Stream *level = new Stream(str);
|
||||||
|
env->ReleaseStringUTFChars(packName, str);
|
||||||
|
level->seek(levelOffset);
|
||||||
|
|
||||||
|
str = env->GetStringUTFChars(contentDir, NULL);
|
||||||
|
strcat(Stream::contentDir, str);
|
||||||
|
env->ReleaseStringUTFChars(contentDir, str);
|
||||||
|
|
||||||
str = env->GetStringUTFChars(cacheDir, NULL);
|
str = env->GetStringUTFChars(cacheDir, NULL);
|
||||||
strcat(Stream::cacheDir, str);
|
strcat(Stream::cacheDir, str);
|
||||||
env->ReleaseStringUTFChars(cacheDir, str);
|
env->ReleaseStringUTFChars(cacheDir, str);
|
||||||
|
|
||||||
str = env->GetStringUTFChars(packName, NULL);
|
Game::init(level);
|
||||||
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();
|
lastTime = getTime();
|
||||||
}
|
}
|
||||||
|
@@ -66,9 +66,8 @@ public class MainActivity extends Activity implements OnTouchListener, OnKeyList
|
|||||||
String packName = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES).applicationInfo.sourceDir;
|
String packName = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES).applicationInfo.sourceDir;
|
||||||
// hardcoded demo level and music
|
// hardcoded demo level and music
|
||||||
AssetFileDescriptor fLevel = this.getResources().openRawResourceFd(R.raw.level2);
|
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());
|
wrapper.onCreate(System.getenv("EXTERNAL_STORAGE") + "/OpenLara/", getCacheDir().getAbsolutePath() + "/", packName, (int)fLevel.getStartOffset());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
finish();
|
finish();
|
||||||
@@ -215,9 +214,9 @@ class Sound {
|
|||||||
public void run() {
|
public void run() {
|
||||||
while ( audioTrack.getPlayState() != AudioTrack.PLAYSTATE_STOPPED ) {
|
while ( audioTrack.getPlayState() != AudioTrack.PLAYSTATE_STOPPED ) {
|
||||||
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING && wrapper.ready) {
|
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING && wrapper.ready) {
|
||||||
synchronized (wrapper) {
|
//synchronized (wrapper) {
|
||||||
Wrapper.nativeSoundFill(buffer);
|
Wrapper.nativeSoundFill(buffer);
|
||||||
}
|
//}
|
||||||
audioTrack.write(buffer, 0, buffer.length);
|
audioTrack.write(buffer, 0, buffer.length);
|
||||||
audioTrack.flush();
|
audioTrack.flush();
|
||||||
} else
|
} else
|
||||||
@@ -270,7 +269,7 @@ class Touch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Wrapper implements Renderer {
|
class Wrapper implements Renderer {
|
||||||
public static native void nativeInit(String packName, String cacheDir, int levelOffset, int musicOffset);
|
public static native void nativeInit(String contentDir, String cacheDir, String packName, int levelOffset);
|
||||||
public static native void nativeFree();
|
public static native void nativeFree();
|
||||||
public static native void nativeReset();
|
public static native void nativeReset();
|
||||||
public static native void nativeResize(int w, int h);
|
public static native void nativeResize(int w, int h);
|
||||||
@@ -280,18 +279,18 @@ class Wrapper implements Renderer {
|
|||||||
public static native void nativeSoundFill(short buffer[]);
|
public static native void nativeSoundFill(short buffer[]);
|
||||||
|
|
||||||
Boolean ready = false;
|
Boolean ready = false;
|
||||||
private String packName;
|
private String contentDir;
|
||||||
private String cacheDir;
|
private String cacheDir;
|
||||||
|
private String packName;
|
||||||
private int levelOffset;
|
private int levelOffset;
|
||||||
private int musicOffset;
|
|
||||||
private ArrayList<Touch> touch = new ArrayList<>();
|
private ArrayList<Touch> touch = new ArrayList<>();
|
||||||
private Sound sound;
|
private Sound sound;
|
||||||
|
|
||||||
void onCreate(String packName, String cacheDir, int levelOffset, int musicOffset) {
|
void onCreate(String contentDir, String cacheDir, String packName, int levelOffset) {
|
||||||
this.packName = packName;
|
this.contentDir = contentDir;
|
||||||
this.cacheDir = cacheDir;
|
this.cacheDir = cacheDir;
|
||||||
|
this.packName = packName;
|
||||||
this.levelOffset = levelOffset;
|
this.levelOffset = levelOffset;
|
||||||
this.musicOffset = musicOffset;
|
|
||||||
|
|
||||||
sound = new Sound();
|
sound = new Sound();
|
||||||
sound.start(this);
|
sound.start(this);
|
||||||
@@ -325,8 +324,8 @@ class Wrapper implements Renderer {
|
|||||||
nativeTouch(t.id, t.state, t.x, t.y);
|
nativeTouch(t.id, t.state, t.x, t.y);
|
||||||
}
|
}
|
||||||
touch.clear();
|
touch.clear();
|
||||||
nativeUpdate();
|
|
||||||
}
|
}
|
||||||
|
nativeUpdate();
|
||||||
nativeRender();
|
nativeRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +337,7 @@ class Wrapper implements Renderer {
|
|||||||
@Override
|
@Override
|
||||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
nativeInit(packName, cacheDir, levelOffset, musicOffset);
|
nativeInit(contentDir, cacheDir, packName, levelOffset);
|
||||||
sound.play();
|
sound.play();
|
||||||
ready = true;
|
ready = true;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@@ -3,7 +3,7 @@ cls
|
|||||||
set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c
|
set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c
|
||||||
set PROJ=OpenLara
|
set PROJ=OpenLara
|
||||||
set FLAGS=-O3 -Wno-deprecated-register --llvm-opts 2 -fmax-type-align=2 -std=c++11 -Wall -I../../
|
set FLAGS=-O3 -Wno-deprecated-register --llvm-opts 2 -fmax-type-align=2 -std=c++11 -Wall -I../../
|
||||||
set PRELOAD=./LEVEL2.PSX
|
set PRELOAD=./level/LEVEL2.PSX
|
||||||
echo.
|
echo.
|
||||||
call em++ %SRC% %FLAGS% -o %PROJ%.js --preload-file %PRELOAD%
|
call em++ %SRC% %FLAGS% -o %PROJ%.js --preload-file %PRELOAD%
|
||||||
gzip.exe -9 -f %PROJ%.data %PROJ%.js %PROJ%.js.mem
|
gzip.exe -9 -f %PROJ%.data %PROJ%.js %PROJ%.js.mem
|
@@ -85,16 +85,8 @@ struct Texture {
|
|||||||
};
|
};
|
||||||
|
|
||||||
FormatDesc desc = formats[format];
|
FormatDesc desc = formats[format];
|
||||||
/*
|
|
||||||
if ((format == RGBA_FLOAT && !Core::support.colorFloat) || (format == RGBA_HALF && !Core::support.colorHalf)) {
|
#ifdef __EMSCRIPTEN__ // fucking firefox!
|
||||||
desc.ifmt = GL_RGBA;
|
|
||||||
#ifdef MOBILE
|
|
||||||
if (format == RGBA_HALF)
|
|
||||||
desc.type = GL_HALF_FLOAT_OES;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#ifdef MOBILE
|
|
||||||
if (format == RGBA_FLOAT) {
|
if (format == RGBA_FLOAT) {
|
||||||
if (Core::support.texFloat) {
|
if (Core::support.texFloat) {
|
||||||
desc.ifmt = GL_RGBA;
|
desc.ifmt = GL_RGBA;
|
||||||
@@ -105,10 +97,20 @@ struct Texture {
|
|||||||
if (format == RGBA_HALF) {
|
if (format == RGBA_HALF) {
|
||||||
if (Core::support.texHalf) {
|
if (Core::support.texHalf) {
|
||||||
desc.ifmt = GL_RGBA;
|
desc.ifmt = GL_RGBA;
|
||||||
|
#ifdef MOBILE
|
||||||
desc.type = GL_HALF_FLOAT_OES;
|
desc.type = GL_HALF_FLOAT_OES;
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if ((format == RGBA_FLOAT && !Core::support.colorFloat) || (format == RGBA_HALF && !Core::support.colorHalf)) {
|
||||||
|
desc.ifmt = GL_RGBA;
|
||||||
|
#ifdef MOBILE
|
||||||
|
if (format == RGBA_HALF)
|
||||||
|
desc.type = GL_HALF_FLOAT_OES;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
glTexImage2D(cube ? (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) : GL_TEXTURE_2D, 0, desc.ifmt, width, height, 0, desc.fmt, desc.type, data);
|
glTexImage2D(cube ? (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) : GL_TEXTURE_2D, 0, desc.ifmt, width, height, 0, desc.fmt, desc.type, data);
|
||||||
|
13
src/utils.h
13
src/utils.h
@@ -979,7 +979,7 @@ struct Stream {
|
|||||||
Stream(const void *data, int size) : callback(NULL), userData(NULL), f(NULL), data((char*)data), size(size), pos(0), name(NULL) {}
|
Stream(const void *data, int size) : callback(NULL), userData(NULL), f(NULL), data((char*)data), size(size), pos(0), name(NULL) {}
|
||||||
|
|
||||||
Stream(const char *name, Callback *callback = NULL, void *userData = NULL) : callback(callback), userData(userData), data(NULL), size(-1), pos(0), name(NULL) {
|
Stream(const char *name, Callback *callback = NULL, void *userData = NULL) : callback(callback), userData(userData), data(NULL), size(-1), pos(0), name(NULL) {
|
||||||
if (contentDir[0]) {
|
if (contentDir[0] && (!cacheDir[0] || !strstr(name, cacheDir))) {
|
||||||
char path[255];
|
char path[255];
|
||||||
path[0] = 0;
|
path[0] = 0;
|
||||||
strcat(path, contentDir);
|
strcat(path, contentDir);
|
||||||
@@ -998,10 +998,14 @@ struct Stream {
|
|||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
LOG("error loading file \"%s\"\n", name);
|
LOG("error loading file \"%s\"\n", name);
|
||||||
#endif
|
if (callback) {
|
||||||
|
callback(NULL, userData);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
ASSERT(f != NULL);
|
#endif
|
||||||
|
} else {
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size = ftell(f);
|
size = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
@@ -1009,6 +1013,7 @@ struct Stream {
|
|||||||
if (callback)
|
if (callback)
|
||||||
callback(this, userData);
|
callback(this, userData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~Stream() {
|
~Stream() {
|
||||||
delete[] name;
|
delete[] name;
|
||||||
|
Reference in New Issue
Block a user