Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android support #92

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ jobs:
- name: cppcheck
run: cppcheck --std=c++17 src/

android:
name: Android

runs-on: ubuntu-latest

steps:
- name: Clone
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11
cache: gradle

- name: Cache cmake build
uses: actions/cache@v3
with:
path: os/android/app/.cxx
key: android-cmake-v1

- name: Build
run: |
cd os/android
./gradlew assembleDebug

- name: Upload
uses: actions/upload-artifact@v3
with:
name: fallout2-ce-debug.apk
path: os/android/app/build/outputs/apk/debug/app-debug.apk
retention-days: 7

linux:
name: Linux (${{ matrix.arch }})

Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE
if (ANDROID)
add_library(${EXECUTABLE_NAME} SHARED)
else()
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE)
endif()

target_sources(${EXECUTABLE_NAME} PUBLIC
"src/actions.cc"
"src/actions.h"
"src/animation.cc"
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ $ sudo apt install libsdl2-2.0-0

- Run `fallout2-ce.app`.

### Android

> **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.

- Download `fallout2-ce.apk` and copy it to your device. Open it with file explorer, follow instructions (install from unknown source).

- Run the game once, it will say `Couldn't find/load text fonts` and create a folder for data assets.

- 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).

- 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.

- Run the game again.

## Contributing

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.
Expand Down
9 changes: 9 additions & 0 deletions os/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/.idea/assetWizardSettings.xml
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/navEditor.xml
/.idea/workspace.xml
/local.properties
2 changes: 2 additions & 0 deletions os/android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.cxx
/build
60 changes: 60 additions & 0 deletions os/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 32

defaultConfig {
applicationId 'com.alexbatalov.fallout2ce'
minSdk 21
targetSdk 32
versionCode 1
versionName '1.0'
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_static'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'

// TODO: Remove once format issues are resolved.
cppFlags '-Wno-format-security'

// Specify target library explicitly as there is a shared zlib,
// that we don't need to be linked in.
targets 'fallout2-ce'
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

applicationVariants.all { variant ->
tasks["merge${variant.name.capitalize()}Assets"]
.dependsOn("externalNativeBuild${variant.name.capitalize()}")
}

if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
sourceSets.main {
jniLibs.srcDir 'libs'
}
externalNativeBuild {
cmake {
path '../../../CMakeLists.txt'
}
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
21 changes: 21 additions & 0 deletions os/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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
97 changes: 97 additions & 0 deletions os/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alexbatalov.fallout2ce"
android:versionCode="1"
android:versionName="1.0.0"
android:installLocation="auto">

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />

<!-- Touchscreen support -->
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />

<!-- Game controller support -->
<uses-feature
android:name="android.hardware.bluetooth"
android:required="false" />
<uses-feature
android:name="android.hardware.gamepad"
android:required="false" />
<uses-feature
android:name="android.hardware.usb.host"
android:required="false" />

<!-- External mouse input events -->
<uses-feature
android:name="android.hardware.type.pc"
android:required="false" />

<!-- Audio recording support -->
<!-- if you want to capture audio, uncomment this. -->
<!-- <uses-feature
android:name="android.hardware.microphone"
android:required="false" /> -->

<!-- Allow downloading to the external storage on Android 5.1 and older -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="22" />

<!-- Allow access to Bluetooth devices -->
<!-- Currently this is just for Steam Controller support and requires setting SDL_HINT_JOYSTICK_HIDAPI_STEAM -->
<!-- <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> -->
<!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> -->

<!-- Allow access to the vibrator -->
<uses-permission android:name="android.permission.VIBRATE" />

<!-- if you want to capture audio, uncomment this. -->
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->

<!-- Create a Java class extending SDLActivity and place it in a
directory under app/src/main/java matching the package, e.g. app/src/main/java/com/gamemaker/game/MyGame.java

then replace "SDLActivity" with the name of your class (e.g. "MyGame")
in the XML below.

An example Java class can be found in README-android.md
-->
<application android:label="@string/app_name"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" >

<!-- Example of setting SDL hints from AndroidManifest.xml:
<meta-data android:name="SDL_ENV.SDL_ACCELEROMETER_AS_JOYSTICK" android:value="0"/>
-->

<activity android:name=".MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:preferMinimalPostProcessing="true"
android:exported="true"
android:screenOrientation="landscape"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Let Android know that we can handle some USB devices and should receive this event -->
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<!-- Drop file event -->
<!--
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
-->
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.alexbatalov.fallout2ce;

import android.os.Bundle;

import org.libsdl.app.SDLActivity;

public class MainActivity extends SDLActivity {
protected void onCreate(Bundle savedInstanceState) {
// Needed to initialize `files` folder (and make it publicly accessible
// for file managers) for user to upload assets.
getExternalFilesDir(null);

super.onCreate(savedInstanceState);
}

protected String[] getLibraries() {
return new String[]{
"fallout2-ce",
};
}
}
22 changes: 22 additions & 0 deletions os/android/app/src/main/java/org/libsdl/app/HIDDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.libsdl.app;

import android.hardware.usb.UsbDevice;

interface HIDDevice
{
public int getId();
public int getVendorId();
public int getProductId();
public String getSerialNumber();
public int getVersion();
public String getManufacturerName();
public String getProductName();
public UsbDevice getDevice();
public boolean open();
public int sendFeatureReport(byte[] report);
public int sendOutputReport(byte[] report);
public boolean getFeatureReport(byte[] report);
public void setFrozen(boolean frozen);
public void close();
public void shutdown();
}
Loading