Skip to content

Commit 684d943

Browse files
authored
Add Android support (#92)
1 parent 23d3762 commit 684d943

29 files changed

+6012
-1
lines changed

.github/workflows/Build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,40 @@ jobs:
3838
- name: cppcheck
3939
run: cppcheck --std=c++17 src/
4040

41+
android:
42+
name: Android
43+
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- name: Clone
48+
uses: actions/checkout@v3
49+
50+
- name: Setup Java
51+
uses: actions/setup-java@v2
52+
with:
53+
distribution: temurin
54+
java-version: 11
55+
cache: gradle
56+
57+
- name: Cache cmake build
58+
uses: actions/cache@v3
59+
with:
60+
path: os/android/app/.cxx
61+
key: android-cmake-v1
62+
63+
- name: Build
64+
run: |
65+
cd os/android
66+
./gradlew assembleDebug
67+
68+
- name: Upload
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: fallout2-ce-debug.apk
72+
path: os/android/app/build/outputs/apk/debug/app-debug.apk
73+
retention-days: 7
74+
4175
linux:
4276
name: Linux (${{ matrix.arch }})
4377

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ set(CMAKE_CXX_STANDARD 17)
1515
set(CMAKE_CXX_STANDARD_REQUIRED YES)
1616
set(CMAKE_CXX_EXTENSIONS NO)
1717

18-
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE
18+
if (ANDROID)
19+
add_library(${EXECUTABLE_NAME} SHARED)
20+
else()
21+
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE)
22+
endif()
23+
24+
target_sources(${EXECUTABLE_NAME} PUBLIC
1925
"src/actions.cc"
2026
"src/actions.h"
2127
"src/animation.cc"

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ $ sudo apt install libsdl2-2.0-0
3434

3535
- Run `fallout2-ce.app`.
3636

37+
### Android
38+
39+
> **NOTE**: Android support should be considered as a technical preview. Controls are not adapted for touch screens yet. Don't expect the gameplay to be enjoyable.
40+
41+
- Download `fallout2-ce.apk` and copy it to your device. Open it with file explorer, follow instructions (install from unknown source).
42+
43+
- Run the game once, it will say `Couldn't find/load text fonts` and create a folder for data assets.
44+
45+
- Open file explorer, navigate to `Android/data/com.alexbatalov.fallout2ce/files`, delete junk folders inside (they will be named as game files, just delete them).
46+
47+
- Use Windows installation as a base - it contains data assets needed to play. Copy `master.dat`, `critter.dat`, `patch000.dat` and `data` folder to the folder above.
48+
49+
- Run the game again.
50+
3751
## Contributing
3852

3953
Integrating Sfall goodies is the top priority. Quality of life updates are OK too. Please no large scale refactorings at this time as we need to reconcile changes from Reference Edition, which will make this process slow and error-prone. In any case open up an issue with your suggestion or to notify other people that something is being worked on.

os/android/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/.idea/assetWizardSettings.xml
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/navEditor.xml
8+
/.idea/workspace.xml
9+
/local.properties

os/android/app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.cxx
2+
/build

os/android/app/build.gradle

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdk 32
7+
8+
defaultConfig {
9+
applicationId 'com.alexbatalov.fallout2ce'
10+
minSdk 21
11+
targetSdk 32
12+
versionCode 1
13+
versionName '1.0'
14+
externalNativeBuild {
15+
cmake {
16+
arguments '-DANDROID_STL=c++_static'
17+
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
18+
19+
// TODO: Remove once format issues are resolved.
20+
cppFlags '-Wno-format-security'
21+
22+
// Specify target library explicitly as there is a shared zlib,
23+
// that we don't need to be linked in.
24+
targets 'fallout2-ce'
25+
}
26+
}
27+
}
28+
29+
buildTypes {
30+
release {
31+
minifyEnabled false
32+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
33+
}
34+
}
35+
36+
compileOptions {
37+
sourceCompatibility JavaVersion.VERSION_1_8
38+
targetCompatibility JavaVersion.VERSION_1_8
39+
}
40+
41+
applicationVariants.all { variant ->
42+
tasks["merge${variant.name.capitalize()}Assets"]
43+
.dependsOn("externalNativeBuild${variant.name.capitalize()}")
44+
}
45+
46+
if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
47+
sourceSets.main {
48+
jniLibs.srcDir 'libs'
49+
}
50+
externalNativeBuild {
51+
cmake {
52+
path '../../../CMakeLists.txt'
53+
}
54+
}
55+
}
56+
}
57+
58+
dependencies {
59+
implementation fileTree(include: ['*.jar'], dir: 'libs')
60+
}

os/android/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.alexbatalov.fallout2ce"
4+
android:versionCode="1"
5+
android:versionName="1.0.0"
6+
android:installLocation="auto">
7+
8+
<!-- OpenGL ES 2.0 -->
9+
<uses-feature android:glEsVersion="0x00020000" />
10+
11+
<!-- Touchscreen support -->
12+
<uses-feature
13+
android:name="android.hardware.touchscreen"
14+
android:required="false" />
15+
16+
<!-- Game controller support -->
17+
<uses-feature
18+
android:name="android.hardware.bluetooth"
19+
android:required="false" />
20+
<uses-feature
21+
android:name="android.hardware.gamepad"
22+
android:required="false" />
23+
<uses-feature
24+
android:name="android.hardware.usb.host"
25+
android:required="false" />
26+
27+
<!-- External mouse input events -->
28+
<uses-feature
29+
android:name="android.hardware.type.pc"
30+
android:required="false" />
31+
32+
<!-- Audio recording support -->
33+
<!-- if you want to capture audio, uncomment this. -->
34+
<!-- <uses-feature
35+
android:name="android.hardware.microphone"
36+
android:required="false" /> -->
37+
38+
<!-- Allow downloading to the external storage on Android 5.1 and older -->
39+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="22" />
40+
41+
<!-- Allow access to Bluetooth devices -->
42+
<!-- Currently this is just for Steam Controller support and requires setting SDL_HINT_JOYSTICK_HIDAPI_STEAM -->
43+
<!-- <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> -->
44+
<!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> -->
45+
46+
<!-- Allow access to the vibrator -->
47+
<uses-permission android:name="android.permission.VIBRATE" />
48+
49+
<!-- if you want to capture audio, uncomment this. -->
50+
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->
51+
52+
<!-- Create a Java class extending SDLActivity and place it in a
53+
directory under app/src/main/java matching the package, e.g. app/src/main/java/com/gamemaker/game/MyGame.java
54+
55+
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
56+
in the XML below.
57+
58+
An example Java class can be found in README-android.md
59+
-->
60+
<application android:label="@string/app_name"
61+
android:allowBackup="true"
62+
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
63+
android:hardwareAccelerated="true" >
64+
65+
<!-- Example of setting SDL hints from AndroidManifest.xml:
66+
<meta-data android:name="SDL_ENV.SDL_ACCELEROMETER_AS_JOYSTICK" android:value="0"/>
67+
-->
68+
69+
<activity android:name=".MainActivity"
70+
android:label="@string/app_name"
71+
android:alwaysRetainTaskState="true"
72+
android:launchMode="singleInstance"
73+
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
74+
android:preferMinimalPostProcessing="true"
75+
android:exported="true"
76+
android:screenOrientation="landscape"
77+
>
78+
<intent-filter>
79+
<action android:name="android.intent.action.MAIN" />
80+
<category android:name="android.intent.category.LAUNCHER" />
81+
</intent-filter>
82+
<!-- Let Android know that we can handle some USB devices and should receive this event -->
83+
<intent-filter>
84+
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
85+
</intent-filter>
86+
<!-- Drop file event -->
87+
<!--
88+
<intent-filter>
89+
<action android:name="android.intent.action.VIEW" />
90+
<category android:name="android.intent.category.DEFAULT" />
91+
<data android:mimeType="*/*" />
92+
</intent-filter>
93+
-->
94+
</activity>
95+
</application>
96+
97+
</manifest>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.alexbatalov.fallout2ce;
2+
3+
import android.os.Bundle;
4+
5+
import org.libsdl.app.SDLActivity;
6+
7+
public class MainActivity extends SDLActivity {
8+
protected void onCreate(Bundle savedInstanceState) {
9+
// Needed to initialize `files` folder (and make it publicly accessible
10+
// for file managers) for user to upload assets.
11+
getExternalFilesDir(null);
12+
13+
super.onCreate(savedInstanceState);
14+
}
15+
16+
protected String[] getLibraries() {
17+
return new String[]{
18+
"fallout2-ce",
19+
};
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.libsdl.app;
2+
3+
import android.hardware.usb.UsbDevice;
4+
5+
interface HIDDevice
6+
{
7+
public int getId();
8+
public int getVendorId();
9+
public int getProductId();
10+
public String getSerialNumber();
11+
public int getVersion();
12+
public String getManufacturerName();
13+
public String getProductName();
14+
public UsbDevice getDevice();
15+
public boolean open();
16+
public int sendFeatureReport(byte[] report);
17+
public int sendOutputReport(byte[] report);
18+
public boolean getFeatureReport(byte[] report);
19+
public void setFrozen(boolean frozen);
20+
public void close();
21+
public void shutdown();
22+
}

0 commit comments

Comments
 (0)