mirror of
https://github.com/XProger/OpenLara.git
synced 2025-01-17 21:09:00 +01:00
#15 fix android build, add content directory for audio tracks (/sdcard/OpenLara/audio/), add binary data
This commit is contained in:
parent
b06e415ee0
commit
d046c078f3
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
|
||||
versionName "0.1"
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a','x86','x86_64'
|
||||
abiFilters 'armeabi-v7a', 'x86', 'x86_64'
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
@ -29,6 +29,9 @@ android {
|
||||
path "CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
aaptOptions {
|
||||
noCompress 'psx', 'phd', 'pcx', 'mp3', 'ogg'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -9,9 +9,10 @@
|
||||
<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"
|
||||
-->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
-->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
@ -10,10 +10,12 @@
|
||||
JNIEXPORT return_type JNICALL \
|
||||
Java_org_xproger_openlara_Wrapper_##method_name
|
||||
|
||||
time_t startTime;
|
||||
|
||||
int getTime() {
|
||||
timeval time;
|
||||
gettimeofday(&time, NULL);
|
||||
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return int((t.tv_sec - startTime) * 1000 + t.tv_usec / 1000);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@ -23,25 +25,31 @@ int lastTime;
|
||||
char Stream::cacheDir[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;
|
||||
|
||||
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);
|
||||
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);
|
||||
Game::init(level);
|
||||
|
||||
level->seek(levelOffset);
|
||||
music->seek(musicOffset);
|
||||
|
||||
Game::init(level, music);
|
||||
|
||||
lastTime = getTime();
|
||||
lastTime = getTime();
|
||||
}
|
||||
|
||||
JNI_METHOD(void, nativeFree)(JNIEnv* env) {
|
||||
|
@ -66,9 +66,8 @@ public class MainActivity extends Activity implements OnTouchListener, OnKeyList
|
||||
String packName = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES).applicationInfo.sourceDir;
|
||||
// hardcoded demo level and music
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
finish();
|
||||
@ -215,9 +214,9 @@ class Sound {
|
||||
public void run() {
|
||||
while ( audioTrack.getPlayState() != AudioTrack.PLAYSTATE_STOPPED ) {
|
||||
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING && wrapper.ready) {
|
||||
synchronized (wrapper) {
|
||||
//synchronized (wrapper) {
|
||||
Wrapper.nativeSoundFill(buffer);
|
||||
}
|
||||
//}
|
||||
audioTrack.write(buffer, 0, buffer.length);
|
||||
audioTrack.flush();
|
||||
} else
|
||||
@ -270,7 +269,7 @@ class Touch {
|
||||
}
|
||||
|
||||
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 nativeReset();
|
||||
public static native void nativeResize(int w, int h);
|
||||
@ -280,18 +279,18 @@ class Wrapper implements Renderer {
|
||||
public static native void nativeSoundFill(short buffer[]);
|
||||
|
||||
Boolean ready = false;
|
||||
private String packName;
|
||||
private String contentDir;
|
||||
private String cacheDir;
|
||||
private String packName;
|
||||
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;
|
||||
void onCreate(String contentDir, String cacheDir, String packName, int levelOffset) {
|
||||
this.contentDir = contentDir;
|
||||
this.cacheDir = cacheDir;
|
||||
this.packName = packName;
|
||||
this.levelOffset = levelOffset;
|
||||
this.musicOffset = musicOffset;
|
||||
|
||||
sound = new Sound();
|
||||
sound.start(this);
|
||||
@ -325,8 +324,8 @@ class Wrapper implements Renderer {
|
||||
nativeTouch(t.id, t.state, t.x, t.y);
|
||||
}
|
||||
touch.clear();
|
||||
nativeUpdate();
|
||||
}
|
||||
nativeUpdate();
|
||||
nativeRender();
|
||||
}
|
||||
|
||||
@ -338,7 +337,7 @@ class Wrapper implements Renderer {
|
||||
@Override
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
if (!ready) {
|
||||
nativeInit(packName, cacheDir, levelOffset, musicOffset);
|
||||
nativeInit(contentDir, cacheDir, packName, levelOffset);
|
||||
sound.play();
|
||||
ready = true;
|
||||
}
|
||||
|
Binary file not shown.
@ -3,7 +3,7 @@ cls
|
||||
set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c
|
||||
set PROJ=OpenLara
|
||||
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.
|
||||
call em++ %SRC% %FLAGS% -o %PROJ%.js --preload-file %PRELOAD%
|
||||
gzip.exe -9 -f %PROJ%.data %PROJ%.js %PROJ%.js.mem
|
@ -85,16 +85,8 @@ struct Texture {
|
||||
};
|
||||
|
||||
FormatDesc desc = formats[format];
|
||||
/*
|
||||
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
|
||||
}
|
||||
*/
|
||||
#ifdef MOBILE
|
||||
|
||||
#ifdef __EMSCRIPTEN__ // fucking firefox!
|
||||
if (format == RGBA_FLOAT) {
|
||||
if (Core::support.texFloat) {
|
||||
desc.ifmt = GL_RGBA;
|
||||
@ -105,10 +97,20 @@ struct Texture {
|
||||
if (format == RGBA_HALF) {
|
||||
if (Core::support.texHalf) {
|
||||
desc.ifmt = GL_RGBA;
|
||||
desc.type = GL_HALF_FLOAT_OES;
|
||||
#ifdef MOBILE
|
||||
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++) {
|
||||
glTexImage2D(cube ? (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i) : GL_TEXTURE_2D, 0, desc.ifmt, width, height, 0, desc.fmt, desc.type, data);
|
||||
|
23
src/utils.h
23
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 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];
|
||||
path[0] = 0;
|
||||
strcat(path, contentDir);
|
||||
@ -998,16 +998,21 @@ struct Stream {
|
||||
return;
|
||||
#else
|
||||
LOG("error loading file \"%s\"\n", name);
|
||||
if (callback) {
|
||||
callback(NULL, userData);
|
||||
return;
|
||||
} else {
|
||||
ASSERT(false);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (callback)
|
||||
callback(this, userData);
|
||||
}
|
||||
ASSERT(f != NULL);
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (callback)
|
||||
callback(this, userData);
|
||||
}
|
||||
|
||||
~Stream() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user