summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 040fb4a)
raw | patch | inline | side by side (parent: 040fb4a)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 13 May 2018 20:57:07 +0000 (23:57 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 13 May 2018 20:57:52 +0000 (23:57 +0300) |
android/README | patch | blob | history | |
android/src/org/d2df/app/CopyAssets.java | [new file with mode: 0644] | patch | blob |
android/src/org/d2df/app/Doom2DF.java | patch | blob | history | |
src/game/Doom2DF.lpr | patch | blob | history | |
src/lib/sdl2/sdlsystem.inc | patch | blob | history |
diff --git a/android/README b/android/README
index e99a2f6342225d6ecd78920a7b44c8ef31af4453..de9cb1bab91ac03abe7e57b9357b7afb63e6385e 100644 (file)
--- a/android/README
+++ b/android/README
D2DF uses special version of nanoGL ( https://github.com/DeaDDooMER/nanogl ) with some added functions.
Build all shared libraries using NDK toolchain and put into directory ./ass/lib/armeabi-v7a/.
Also you need to build FPC crosscompiler ( http://wiki.freepascal.org/Android ).
+Put game resources into direcotor resources/ (or install it manually into external/internal storage).
Generate keys:
```
Build APK and sign it:
```
rm -rf bin obj gen
-mkdir -p bin obj gen
+mkdir -p bin obj gen resources
aapt package -f -m -S res -J gen -M AndroidManifest.xml -I ${ANDROID_JAR}
javac -source 1.6 -target 1.6 -d obj -bootclasspath ${ANDROID_JAR} -sourcepath src `find src -name '*.java'`
dx --dex --output=bin/classes.dex obj
-J gen \
-I ${ANDROID_JAR} \
-F bin/d2df.unsigned.apk \
+ -A resources
bin ass
jarsigner -sigalg SHA1withRSA -digestalg SHA1 \
-keystore d2df.keystore \
diff --git a/android/src/org/d2df/app/CopyAssets.java b/android/src/org/d2df/app/CopyAssets.java
--- /dev/null
@@ -0,0 +1,71 @@
+package org.d2df.app;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import android.util.Log;
+
+public class CopyAssets {
+
+ public static void copyAssets(Context context, String prefix) {
+ AssetManager assetManager = context.getAssets();
+ String[] files = null;
+ try {
+ files = assetManager.list(prefix);
+ } catch (IOException e) {
+ Log.e("tag", "Failed to get asset file list.", e);
+ }
+ if (files != null) for (String filename : files) {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ File f = new File(context.getExternalFilesDir(null), prefix);
+ if (!f.exists()) {
+ f.mkdirs();
+ }
+ File outFile = new File(context.getExternalFilesDir(null), prefix + "/" + filename);
+ if (!outFile.exists()) {
+ in = assetManager.open(prefix + "/" + filename);
+ out = new FileOutputStream(outFile);
+ copyFile(in, out);
+ }
+ } catch(IOException e) {
+ Log.e("tag", "Failed to copy asset file: " + filename, e);
+ }
+ finally {
+ if (in != null) {
+ try {
+ in.close();
+ in = null;
+ } catch (IOException e) {
+
+ }
+ }
+ if (out != null) {
+ try {
+ out.flush();
+ out.close();
+ out = null;
+ } catch (IOException e) {
+
+ }
+ }
+ }
+ }
+ }
+
+ public static void copyFile(InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[1024];
+ int read;
+ while((read = in.read(buffer)) != -1){
+ out.write(buffer, 0, read);
+ }
+ }
+
+}
index 175f4e48925150adb5fdc4e8857d9957dea6a556..ca1766609ac4b4a689bca384dba7db7d0a530ff8 100644 (file)
import android.app.Activity;
import android.os.Bundle;
+import org.libsdl.app.SDL;
import org.libsdl.app.SDLActivity;
public class Doom2DF extends SDLActivity {
"Doom2DF"
};
}
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ CopyAssets.copyAssets(SDL.getContext(), "");
+ CopyAssets.copyAssets(SDL.getContext(), "data");
+ CopyAssets.copyAssets(SDL.getContext(), "data/models");
+ CopyAssets.copyAssets(SDL.getContext(), "maps");
+ CopyAssets.copyAssets(SDL.getContext(), "maps/megawads");
+ CopyAssets.copyAssets(SDL.getContext(), "wads");
+ }
}
diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr
index 8808d633f3181c3460a7b15b64ce27e2e613e13f..0b62430ad3d7c369f4dcf485b6f4fbb65f8e1f67 100644 (file)
--- a/src/game/Doom2DF.lpr
+++ b/src/game/Doom2DF.lpr
{$IFDEF ANDROID}
{$I-}
e_SetSafeSlowLog(true);
- Chdir('/sdcard/D2DF');
+ Chdir(SDL_AndroidGetExternalStoragePath());
if IOresult <> 0 then
begin
- Mkdir('/sdcard/D2DF');
- Chdir('/sdcard/D2DF');
+ Chdir(SDL_AndroidGetInternalStoragePath());
if IOresult <> 0 then
begin
- e_WriteLog('Fail: cant chdir /sdcard/D2DF', TMsgType.Fatal);
+ e_WriteLog('Fuck! Cant chdir to any game directory :(', TMsgType.Fatal);
result := 1;
exit;
end;
index 1e06d9f0ed7c28fec74703d5fb3e675c90101f04..8f5c6e252eb2df7261bca677f197e145312c14c4 100644 (file)
cdecl; external SDL_LibName;
{$ENDIF}
+
+{$IF DEFINED(ANDROID)}
+
+Function SDL_AndroidGetExternalStoragePath:PChar;
+ cdecl; external SDL_LibName;
+
+Function SDL_AndroidGetInternalStoragePath:PChar;
+ cdecl; external SDL_LibName;
+
+{$ENDIF}