diff --git a/.gitignore b/.gitignore
index 3d967251..b97eeb99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,9 +3,16 @@
/wipeout/
/build/
+/.cxx/
+/android/app/.cxx/
+/android/.gradle/
+/android/app/build/
+/android/gradle-home/
+/android/local.properties
+/android/gradle/wrapper/gradle-wrapper.jar
+/third_party/
/wipegame
/wipegame.exe
/save.dat
.DS_STORE
-gamecontrollerdb.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a8f0470..67a5322c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,67 +47,10 @@ find_package(OpenGL)
find_package(GLEW)
find_package(SDL2)
-set(common_src
- src/wipeout/camera.c
- src/wipeout/camera.h
- src/wipeout/droid.c
- src/wipeout/droid.h
- src/wipeout/game.c
- src/wipeout/game.h
- src/wipeout/hud.c
- src/wipeout/hud.h
- src/wipeout/image.c
- src/wipeout/image.h
- src/wipeout/ingame_menus.c
- src/wipeout/ingame_menus.h
- src/wipeout/intro.c
- src/wipeout/intro.h
- src/wipeout/main_menu.c
- src/wipeout/main_menu.h
- src/wipeout/menu.c
- src/wipeout/menu.h
- src/wipeout/object.c
- src/wipeout/object.h
- src/wipeout/particle.c
- src/wipeout/particle.h
- src/wipeout/race.c
- src/wipeout/race.h
- src/wipeout/scene.c
- src/wipeout/scene.h
- src/wipeout/sfx.c
- src/wipeout/sfx.h
- src/wipeout/ship.c
- src/wipeout/ship.h
- src/wipeout/ship_ai.c
- src/wipeout/ship_ai.h
- src/wipeout/ship_player.c
- src/wipeout/ship_player.h
- src/wipeout/title.c
- src/wipeout/title.h
- src/wipeout/track.c
- src/wipeout/track.h
- src/wipeout/ui.c
- src/wipeout/ui.h
- src/wipeout/weapon.c
- src/wipeout/weapon.h
- src/input.c
- src/input.h
- src/mem.c
- src/mem.h
- src/platform.h
- src/render.h
- src/system.c
- src/system.h
- src/types.c
- src/types.h
- src/utils.c
- src/utils.h
-
- packaging/windows/wipeout.exe.manifest
- packaging/windows/wipeout.rc
-)
+set(WIPEOUT_ROOT "${CMAKE_SOURCE_DIR}")
+include("${CMAKE_SOURCE_DIR}/cmake/wipeout_sources.cmake")
-add_executable(wipeout WIN32 ${common_src})
+add_executable(wipeout WIN32 ${WIPEOUT_COMMON_SRC})
set_property(TARGET wipeout PROPERTY C_STANDARD 11)
target_include_directories(wipeout PRIVATE src)
target_include_directories(wipeout SYSTEM PRIVATE src/libs)
diff --git a/README.md b/README.md
index 4a6b2177..836aac4e 100644
--- a/README.md
+++ b/README.md
@@ -216,6 +216,11 @@ emcmake cmake -S path/to/wipeout-rewrite -B path/to/build-dir -DPLATFORM=SOKOL
cmake --build path/to/build-dir
```
+## Android
+
+See `android/README.md` for the Android Studio/NDK build, SDL2 setup, and asset
+packing instructions.
+
## Build Flags for cmake
The following is a table for project specific build flags using CMake:
diff --git a/android/README.md b/android/README.md
new file mode 100644
index 00000000..8cca4055
--- /dev/null
+++ b/android/README.md
@@ -0,0 +1,34 @@
+# Android build
+
+This project uses the SDL2 Android Java layer plus a native shared library built
+with the NDK.
+
+## Prereqs
+- Android Studio with SDK Platform **36** installed.
+- NDK **r29+** installed.
+- CMake **3.22+** (Android Studio can install this).
+
+If your local NDK revision isn't `29.0.0`, pass `-PndkVersion=29.x.y` to Gradle
+or edit `android/app/build.gradle`.
+
+## SDL2 source
+SDL2 is fetched by CMake on first build (tag `release-2.32.10`) into
+`third_party/SDL`. If you want to use a local checkout instead, populate that
+folder ahead of time.
+
+## Assets
+Place the game data under `android/app/src/main/assets/wipeout/` so paths like
+`wipeout/textures/` and `wipeout/music/` resolve inside the APK.
+
+```
+android/app/src/main/assets/wipeout/
+ textures/
+ sound/
+ music/
+ intro.mpeg
+```
+
+## Build
+Open the `android/` folder in Android Studio and run the app. If you prefer a
+CLI build, generate a Gradle wrapper in `android/` or use a local Gradle
+install to run `assembleDebug`.
diff --git a/android/app/build.gradle b/android/app/build.gradle
new file mode 100644
index 00000000..a35461aa
--- /dev/null
+++ b/android/app/build.gradle
@@ -0,0 +1,92 @@
+plugins {
+ id 'com.android.application'
+ id 'org.jetbrains.kotlin.android'
+}
+
+def sdlDir = file("${rootDir}/../third_party/SDL")
+def sdlDirPath = sdlDir.absolutePath.replace('\\', '/')
+def ndkVer = project.findProperty("ndkVersion") ?: "29.0.0"
+
+android {
+ namespace "com.phoboslab.wipeout"
+ compileSdk 36
+ ndkVersion "29.0.14206865"
+ buildToolsVersion "36.1.0"
+
+ defaultConfig {
+ applicationId "com.phoboslab.wipeout"
+ minSdk 26
+ targetSdk 36
+ versionCode 1
+ versionName "0.1"
+
+ externalNativeBuild {
+ cmake {
+ arguments "-DSDL2_SOURCE_DIR=${sdlDirPath}"
+ }
+ }
+
+ ndk {
+ abiFilters "arm64-v8a"
+ }
+ }
+
+ externalNativeBuild {
+ cmake {
+ path "src/main/cpp/CMakeLists.txt"
+ version "3.22.1"
+ }
+ }
+
+ sourceSets {
+ main {
+ java.srcDirs += [
+ "src/main/java",
+ "src/main/kotlin",
+ "${sdlDir}/android-project/app/src/main/java"
+ ]
+ res.srcDirs += [
+ "${sdlDir}/android-project/app/src/main/res",
+ "src/main/res"
+ ]
+ assets.srcDirs += ["src/main/assets"]
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ signingConfig signingConfigs.debug
+ proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+
+ kotlinOptions {
+ jvmTarget = "17"
+ }
+}
+
+afterEvaluate {
+ android.applicationVariants.all { variant ->
+ def cap = variant.name.capitalize()
+ def nativeTask = tasks.findByName("externalNativeBuild${cap}")
+ if (nativeTask != null) {
+ def kotlinTask = tasks.findByName("compile${cap}Kotlin")
+ if (kotlinTask != null) {
+ kotlinTask.dependsOn(nativeTask)
+ }
+ def javaTask = tasks.findByName("compile${cap}JavaWithJavac")
+ if (javaTask != null) {
+ javaTask.dependsOn(nativeTask)
+ }
+ }
+ }
+}
+
+dependencies {
+}
diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro
new file mode 100644
index 00000000..86b48c8a
--- /dev/null
+++ b/android/app/proguard-rules.pro
@@ -0,0 +1 @@
+# Placeholder for custom ProGuard rules.
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..83e304f9
--- /dev/null
+++ b/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/assets/wipeout/game_data_goes_here.txt b/android/app/src/main/assets/wipeout/game_data_goes_here.txt
new file mode 100644
index 00000000..41047e17
--- /dev/null
+++ b/android/app/src/main/assets/wipeout/game_data_goes_here.txt
@@ -0,0 +1,2 @@
+replace this directory with the one from the wipeout NTSC version and copy
+the common/ models from the PC version in.
diff --git a/android/app/src/main/cpp/CMakeLists.txt b/android/app/src/main/cpp/CMakeLists.txt
new file mode 100644
index 00000000..5eadbaa4
--- /dev/null
+++ b/android/app/src/main/cpp/CMakeLists.txt
@@ -0,0 +1,60 @@
+cmake_minimum_required(VERSION 3.22)
+project(wipeout_android LANGUAGES C CXX)
+
+set(WIPEOUT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../../..")
+get_filename_component(WIPEOUT_ROOT "${WIPEOUT_ROOT}" ABSOLUTE)
+
+set(SDL2_SOURCE_DIR "${WIPEOUT_ROOT}/third_party/SDL" CACHE PATH "Path to SDL2 source")
+set(SDL2_GIT_TAG "release-2.32.10" CACHE STRING "SDL2 git tag")
+
+set(SDL_SHARED ON CACHE BOOL "" FORCE)
+set(SDL_STATIC OFF CACHE BOOL "" FORCE)
+set(SDL_TEST OFF CACHE BOOL "" FORCE)
+
+if(EXISTS "${SDL2_SOURCE_DIR}/CMakeLists.txt")
+ add_subdirectory("${SDL2_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/sdl2")
+else()
+ include(FetchContent)
+ FetchContent_Declare(SDL2
+ GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
+ GIT_TAG ${SDL2_GIT_TAG}
+ GIT_SHALLOW TRUE
+ SOURCE_DIR "${SDL2_SOURCE_DIR}"
+ BINARY_DIR "${CMAKE_BINARY_DIR}/sdl2"
+ )
+ FetchContent_MakeAvailable(SDL2)
+endif()
+
+include("${WIPEOUT_ROOT}/cmake/wipeout_sources.cmake")
+
+add_library(main SHARED ${WIPEOUT_COMMON_SRC})
+set_property(TARGET main PROPERTY C_STANDARD 11)
+
+target_sources(main PRIVATE
+ "${WIPEOUT_ROOT}/src/platform_sdl.c"
+ "${WIPEOUT_ROOT}/src/render_gl.c"
+)
+
+target_include_directories(main PRIVATE "${WIPEOUT_ROOT}/src")
+target_include_directories(main SYSTEM PRIVATE "${WIPEOUT_ROOT}/src/libs")
+
+target_compile_definitions(main PRIVATE RENDERER_GL USE_GLES2 PLM_USE_SDL_RWOPS)
+
+find_library(log-lib log)
+find_library(android-lib android)
+find_library(egl-lib EGL)
+find_library(gles-lib GLESv2)
+
+if(TARGET SDL2::SDL2)
+ target_link_libraries(main SDL2::SDL2)
+elseif(TARGET SDL2)
+ target_link_libraries(main SDL2)
+endif()
+
+target_link_libraries(main
+ ${log-lib}
+ ${android-lib}
+ ${egl-lib}
+ ${gles-lib}
+ m
+)
diff --git a/android/app/src/main/java/com/phoboslab/wipeout/MainActivity.kt b/android/app/src/main/java/com/phoboslab/wipeout/MainActivity.kt
new file mode 100644
index 00000000..c12a4ff0
--- /dev/null
+++ b/android/app/src/main/java/com/phoboslab/wipeout/MainActivity.kt
@@ -0,0 +1,5 @@
+package com.phoboslab.wipeout
+
+import org.libsdl.app.SDLActivity
+
+class MainActivity : SDLActivity()
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
new file mode 100644
index 00000000..555a78b2
--- /dev/null
+++ b/android/app/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ wipEout
+
diff --git a/android/build.gradle b/android/build.gradle
new file mode 100644
index 00000000..854dbf80
--- /dev/null
+++ b/android/build.gradle
@@ -0,0 +1,4 @@
+plugins {
+ id 'com.android.application' version '8.5.2' apply false
+ id 'org.jetbrains.kotlin.android' version '1.9.24' apply false
+}
diff --git a/android/buildapks.bat b/android/buildapks.bat
new file mode 100644
index 00000000..407ebcb6
--- /dev/null
+++ b/android/buildapks.bat
@@ -0,0 +1,15 @@
+@echo off
+setlocal
+set "SCRIPT_DIR=%~dp0"
+set "GRADLE_USER_HOME=%SCRIPT_DIR%gradle-home"
+call "%SCRIPT_DIR%gradlew.bat" --no-daemon --console=plain assembleDebug
+if errorlevel 1 exit /b 1
+taskkill /im ninja.exe /f >nul 2>&1
+taskkill /im cmake.exe /f >nul 2>&1
+rmdir /s /q "%SCRIPT_DIR%app\\.cxx\\RelWithDebInfo" >nul 2>&1
+call "%SCRIPT_DIR%gradlew.bat" --no-daemon --console=plain assembleRelease
+if errorlevel 1 exit /b 1
+
+echo.
+echo APKs written to app\build\outputs\apk
+endlocal
diff --git a/android/gradle.properties b/android/gradle.properties
new file mode 100644
index 00000000..2435416c
--- /dev/null
+++ b/android/gradle.properties
@@ -0,0 +1,5 @@
+org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8
+android.useAndroidX=true
+kotlin.code.style=official
+ndkVersion=29.0.14206865
+android.suppressUnsupportedCompileSdk=36
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..b82aa23a
--- /dev/null
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/android/gradlew b/android/gradlew
new file mode 100644
index 00000000..1aa94a42
--- /dev/null
+++ b/android/gradlew
@@ -0,0 +1,249 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/android/gradlew.bat b/android/gradlew.bat
new file mode 100644
index 00000000..25da30db
--- /dev/null
+++ b/android/gradlew.bat
@@ -0,0 +1,92 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/android/settings.gradle b/android/settings.gradle
new file mode 100644
index 00000000..5cd90da4
--- /dev/null
+++ b/android/settings.gradle
@@ -0,0 +1,18 @@
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ google()
+ mavenCentral()
+ }
+}
+
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+rootProject.name = "wipeout"
+include(":app")
diff --git a/cmake/wipeout_sources.cmake b/cmake/wipeout_sources.cmake
new file mode 100644
index 00000000..e1ae1bfb
--- /dev/null
+++ b/cmake/wipeout_sources.cmake
@@ -0,0 +1,68 @@
+# Shared source list for Wipeout targets.
+if(NOT DEFINED WIPEOUT_ROOT)
+ set(WIPEOUT_ROOT "${CMAKE_SOURCE_DIR}")
+endif()
+
+set(WIPEOUT_COMMON_SRC
+ "${WIPEOUT_ROOT}/src/wipeout/camera.c"
+ "${WIPEOUT_ROOT}/src/wipeout/camera.h"
+ "${WIPEOUT_ROOT}/src/wipeout/droid.c"
+ "${WIPEOUT_ROOT}/src/wipeout/droid.h"
+ "${WIPEOUT_ROOT}/src/wipeout/game.c"
+ "${WIPEOUT_ROOT}/src/wipeout/game.h"
+ "${WIPEOUT_ROOT}/src/wipeout/hud.c"
+ "${WIPEOUT_ROOT}/src/wipeout/hud.h"
+ "${WIPEOUT_ROOT}/src/wipeout/image.c"
+ "${WIPEOUT_ROOT}/src/wipeout/image.h"
+ "${WIPEOUT_ROOT}/src/wipeout/ingame_menus.c"
+ "${WIPEOUT_ROOT}/src/wipeout/ingame_menus.h"
+ "${WIPEOUT_ROOT}/src/wipeout/intro.c"
+ "${WIPEOUT_ROOT}/src/wipeout/intro.h"
+ "${WIPEOUT_ROOT}/src/wipeout/main_menu.c"
+ "${WIPEOUT_ROOT}/src/wipeout/main_menu.h"
+ "${WIPEOUT_ROOT}/src/wipeout/menu.c"
+ "${WIPEOUT_ROOT}/src/wipeout/menu.h"
+ "${WIPEOUT_ROOT}/src/wipeout/object.c"
+ "${WIPEOUT_ROOT}/src/wipeout/object.h"
+ "${WIPEOUT_ROOT}/src/wipeout/particle.c"
+ "${WIPEOUT_ROOT}/src/wipeout/particle.h"
+ "${WIPEOUT_ROOT}/src/wipeout/race.c"
+ "${WIPEOUT_ROOT}/src/wipeout/race.h"
+ "${WIPEOUT_ROOT}/src/wipeout/scene.c"
+ "${WIPEOUT_ROOT}/src/wipeout/scene.h"
+ "${WIPEOUT_ROOT}/src/wipeout/sfx.c"
+ "${WIPEOUT_ROOT}/src/wipeout/sfx.h"
+ "${WIPEOUT_ROOT}/src/wipeout/ship.c"
+ "${WIPEOUT_ROOT}/src/wipeout/ship.h"
+ "${WIPEOUT_ROOT}/src/wipeout/ship_ai.c"
+ "${WIPEOUT_ROOT}/src/wipeout/ship_ai.h"
+ "${WIPEOUT_ROOT}/src/wipeout/ship_player.c"
+ "${WIPEOUT_ROOT}/src/wipeout/ship_player.h"
+ "${WIPEOUT_ROOT}/src/wipeout/title.c"
+ "${WIPEOUT_ROOT}/src/wipeout/title.h"
+ "${WIPEOUT_ROOT}/src/wipeout/track.c"
+ "${WIPEOUT_ROOT}/src/wipeout/track.h"
+ "${WIPEOUT_ROOT}/src/wipeout/ui.c"
+ "${WIPEOUT_ROOT}/src/wipeout/ui.h"
+ "${WIPEOUT_ROOT}/src/wipeout/weapon.c"
+ "${WIPEOUT_ROOT}/src/wipeout/weapon.h"
+ "${WIPEOUT_ROOT}/src/input.c"
+ "${WIPEOUT_ROOT}/src/input.h"
+ "${WIPEOUT_ROOT}/src/mem.c"
+ "${WIPEOUT_ROOT}/src/mem.h"
+ "${WIPEOUT_ROOT}/src/platform.h"
+ "${WIPEOUT_ROOT}/src/render.h"
+ "${WIPEOUT_ROOT}/src/system.c"
+ "${WIPEOUT_ROOT}/src/system.h"
+ "${WIPEOUT_ROOT}/src/types.c"
+ "${WIPEOUT_ROOT}/src/types.h"
+ "${WIPEOUT_ROOT}/src/utils.c"
+ "${WIPEOUT_ROOT}/src/utils.h"
+)
+
+if(WIN32)
+ list(APPEND WIPEOUT_COMMON_SRC
+ "${WIPEOUT_ROOT}/packaging/windows/wipeout.exe.manifest"
+ "${WIPEOUT_ROOT}/packaging/windows/wipeout.rc"
+ )
+endif()
diff --git a/src/libs/pl_mpeg.h b/src/libs/pl_mpeg.h
index 0016211b..f36b7b97 100644
--- a/src/libs/pl_mpeg.h
+++ b/src/libs/pl_mpeg.h
@@ -168,6 +168,10 @@ See below for detailed the API documentation.
#include
#include
+#ifdef PLM_USE_SDL_RWOPS
+ #include
+#endif
+
#ifdef __cplusplus
extern "C" {
@@ -286,6 +290,12 @@ plm_t *plm_create_with_filename(const char *filename);
plm_t *plm_create_with_file(FILE *fh, int close_when_done);
+#ifdef PLM_USE_SDL_RWOPS
+// Create a plmpeg instance with an SDL_RWops handle. Pass TRUE to close_when_done
+// to let plmpeg call SDL_RWclose() on the handle when plm_destroy() is called.
+plm_t *plm_create_with_rwops(SDL_RWops *rwops, int close_when_done);
+#endif
+
// Create a plmpeg instance with a pointer to memory as source. This assumes the
// whole file is in memory. The memory is not copied. Pass TRUE to
@@ -482,6 +492,12 @@ plm_buffer_t *plm_buffer_create_with_filename(const char *filename);
plm_buffer_t *plm_buffer_create_with_file(FILE *fh, int close_when_done);
+#ifdef PLM_USE_SDL_RWOPS
+// Create a buffer instance with an SDL_RWops handle. Pass TRUE to close_when_done
+// to let plmpeg call SDL_RWclose() on the handle when plm_destroy() is called.
+plm_buffer_t *plm_buffer_create_with_rwops(SDL_RWops *rwops, int close_when_done);
+#endif
+
// Create a buffer instance with a pointer to memory as source. This assumes
// the whole file is in memory. The bytes are not copied. Pass 1 to
@@ -861,6 +877,13 @@ plm_t *plm_create_with_file(FILE *fh, int close_when_done) {
return plm_create_with_buffer(buffer, TRUE);
}
+#ifdef PLM_USE_SDL_RWOPS
+plm_t *plm_create_with_rwops(SDL_RWops *rwops, int close_when_done) {
+ plm_buffer_t *buffer = plm_buffer_create_with_rwops(rwops, close_when_done);
+ return plm_create_with_buffer(buffer, TRUE);
+}
+#endif
+
plm_t *plm_create_with_memory(uint8_t *bytes, size_t length, int free_when_done) {
plm_buffer_t *buffer = plm_buffer_create_with_memory(bytes, length, free_when_done);
return plm_create_with_buffer(buffer, TRUE);
@@ -1320,6 +1343,9 @@ int plm_seek(plm_t *self, double time, int seek_exact) {
enum plm_buffer_mode {
PLM_BUFFER_MODE_FILE,
+#ifdef PLM_USE_SDL_RWOPS
+ PLM_BUFFER_MODE_RWOPS,
+#endif
PLM_BUFFER_MODE_FIXED_MEM,
PLM_BUFFER_MODE_RING,
PLM_BUFFER_MODE_APPEND
@@ -1335,6 +1361,9 @@ struct plm_buffer_t {
int free_when_done;
int close_when_done;
FILE *fh;
+#ifdef PLM_USE_SDL_RWOPS
+ SDL_RWops *rwops;
+#endif
plm_buffer_load_callback load_callback;
void *load_callback_user_data;
uint8_t *bytes;
@@ -1356,6 +1385,9 @@ void plm_buffer_seek(plm_buffer_t *self, size_t pos);
size_t plm_buffer_tell(plm_buffer_t *self);
void plm_buffer_discard_read_bytes(plm_buffer_t *self);
void plm_buffer_load_file_callback(plm_buffer_t *self, void *user);
+#ifdef PLM_USE_SDL_RWOPS
+void plm_buffer_load_rwops_callback(plm_buffer_t *self, void *user);
+#endif
int plm_buffer_has(plm_buffer_t *self, size_t count);
int plm_buffer_read(plm_buffer_t *self, int count);
@@ -1391,6 +1423,23 @@ plm_buffer_t *plm_buffer_create_with_file(FILE *fh, int close_when_done) {
return self;
}
+#ifdef PLM_USE_SDL_RWOPS
+plm_buffer_t *plm_buffer_create_with_rwops(SDL_RWops *rwops, int close_when_done) {
+ plm_buffer_t *self = plm_buffer_create_with_capacity(PLM_BUFFER_DEFAULT_SIZE);
+ self->rwops = rwops;
+ self->close_when_done = close_when_done;
+ self->mode = PLM_BUFFER_MODE_RWOPS;
+ self->discard_read_bytes = TRUE;
+
+ Sint64 size = SDL_RWsize(self->rwops);
+ self->total_size = size > 0 ? (size_t)size : 0;
+ plm_buffer_seek(self, 0);
+
+ plm_buffer_set_load_callback(self, plm_buffer_load_rwops_callback, NULL);
+ return self;
+}
+#endif
+
plm_buffer_t *plm_buffer_create_with_memory(uint8_t *bytes, size_t length, int free_when_done) {
plm_buffer_t *self = (plm_buffer_t *)PLM_MALLOC(sizeof(plm_buffer_t));
memset(self, 0, sizeof(plm_buffer_t));
@@ -1423,9 +1472,14 @@ plm_buffer_t *plm_buffer_create_for_appending(size_t initial_capacity) {
}
void plm_buffer_destroy(plm_buffer_t *self) {
- if (self->fh && self->close_when_done) {
+ if (self->mode == PLM_BUFFER_MODE_FILE && self->fh && self->close_when_done) {
fclose(self->fh);
}
+#ifdef PLM_USE_SDL_RWOPS
+ if (self->mode == PLM_BUFFER_MODE_RWOPS && self->rwops && self->close_when_done) {
+ SDL_RWclose(self->rwops);
+ }
+#endif
if (self->free_when_done) {
PLM_FREE(self->bytes);
}
@@ -1433,7 +1487,11 @@ void plm_buffer_destroy(plm_buffer_t *self) {
}
size_t plm_buffer_get_size(plm_buffer_t *self) {
- return (self->mode == PLM_BUFFER_MODE_FILE)
+ return (self->mode == PLM_BUFFER_MODE_FILE
+#ifdef PLM_USE_SDL_RWOPS
+ || self->mode == PLM_BUFFER_MODE_RWOPS
+#endif
+ )
? self->total_size
: self->length;
}
@@ -1496,6 +1554,13 @@ void plm_buffer_seek(plm_buffer_t *self, size_t pos) {
self->bit_index = 0;
self->length = 0;
}
+#ifdef PLM_USE_SDL_RWOPS
+ else if (self->mode == PLM_BUFFER_MODE_RWOPS) {
+ SDL_RWseek(self->rwops, pos, RW_SEEK_SET);
+ self->bit_index = 0;
+ self->length = 0;
+ }
+#endif
else if (self->mode == PLM_BUFFER_MODE_RING) {
if (pos != 0) {
// Seeking to non-0 is forbidden for dynamic-mem buffers
@@ -1511,9 +1576,15 @@ void plm_buffer_seek(plm_buffer_t *self, size_t pos) {
}
size_t plm_buffer_tell(plm_buffer_t *self) {
- return self->mode == PLM_BUFFER_MODE_FILE
- ? ftell(self->fh) + (self->bit_index >> 3) - self->length
- : self->bit_index >> 3;
+ if (self->mode == PLM_BUFFER_MODE_FILE) {
+ return ftell(self->fh) + (self->bit_index >> 3) - self->length;
+ }
+#ifdef PLM_USE_SDL_RWOPS
+ if (self->mode == PLM_BUFFER_MODE_RWOPS) {
+ return SDL_RWtell(self->rwops) + (self->bit_index >> 3) - self->length;
+ }
+#endif
+ return self->bit_index >> 3;
}
void plm_buffer_discard_read_bytes(plm_buffer_t *self) {
@@ -1545,6 +1616,24 @@ void plm_buffer_load_file_callback(plm_buffer_t *self, void *user) {
}
}
+#ifdef PLM_USE_SDL_RWOPS
+void plm_buffer_load_rwops_callback(plm_buffer_t *self, void *user) {
+ PLM_UNUSED(user);
+
+ if (self->discard_read_bytes) {
+ plm_buffer_discard_read_bytes(self);
+ }
+
+ size_t bytes_available = self->capacity - self->length;
+ size_t bytes_read = SDL_RWread(self->rwops, self->bytes + self->length, 1, bytes_available);
+ self->length += bytes_read;
+
+ if (bytes_read == 0) {
+ self->has_ended = TRUE;
+ }
+}
+#endif
+
int plm_buffer_has_ended(plm_buffer_t *self) {
return self->has_ended;
}
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
index c8816181..edb0dff9 100755
--- a/src/platform_sdl.c
+++ b/src/platform_sdl.c
@@ -1,4 +1,9 @@
#include "SDL.h"
+#include
+#if defined(__ANDROID__)
+ #include "SDL_system.h"
+ #include
+#endif
#include "platform.h"
#include "input.h"
@@ -16,6 +21,31 @@ static char *path_assets = "";
static char *path_userdata = "";
static char *temp_path = NULL;
+#if defined(__ANDROID__)
+static char android_assets_path[1024];
+static char android_userdata_path[1024];
+
+static void platform_ensure_dir(const char *path) {
+ if (!path || !path[0]) {
+ return;
+ }
+ size_t len = strlen(path);
+ if (len >= sizeof(android_assets_path)) {
+ return;
+ }
+ char buf[1024];
+ memcpy(buf, path, len + 1);
+ for (char *p = buf + 1; *p; p++) {
+ if (*p == '/') {
+ *p = '\0';
+ mkdir(buf, 0777);
+ *p = '/';
+ }
+ }
+ mkdir(buf, 0777);
+}
+#endif
+
uint8_t platform_sdl_gamepad_map[] = {
[SDL_CONTROLLER_BUTTON_A] = INPUT_GAMEPAD_A,
@@ -229,13 +259,51 @@ void platform_set_audio_mix_cb(void (*cb)(float *buffer, uint32_t len)) {
FILE *platform_open_asset(const char *name, const char *mode) {
+#if defined(__ANDROID__)
+ (void)name;
+ (void)mode;
+ return NULL;
+#else
char *path = strcat(strcpy(temp_path, path_assets), name);
return fopen(path, mode);
+#endif
}
uint8_t *platform_load_asset(const char *name, uint32_t *bytes_read) {
+#if defined(__ANDROID__)
+ SDL_RWops *rw = SDL_RWFromFile(name, "rb");
+ if (!rw) {
+ // Try external storage path first when available
+ if (path_assets && path_assets[0]) {
+ char *path = strcat(strcpy(temp_path, path_assets), name);
+ rw = SDL_RWFromFile(path, "rb");
+ }
+ }
+ if (!rw) {
+ *bytes_read = 0;
+ error_if(true, "Could not open asset: %s", name);
+ return NULL;
+ }
+
+ Sint64 size = SDL_RWsize(rw);
+ if (size <= 0) {
+ SDL_RWclose(rw);
+ *bytes_read = 0;
+ error_if(true, "Empty asset: %s", name);
+ return NULL;
+ }
+
+ uint8_t *bytes = mem_temp_alloc((uint32_t)size);
+ size_t read = SDL_RWread(rw, bytes, 1, (size_t)size);
+ SDL_RWclose(rw);
+
+ *bytes_read = (uint32_t)read;
+ error_if(read != (size_t)size, "Could not read asset: %s", name);
+ return bytes;
+#else
char *path = strcat(strcpy(temp_path, path_assets), name);
return file_load(path, bytes_read);
+#endif
}
uint8_t *platform_load_userdata(const char *name, uint32_t *bytes_read) {
@@ -248,6 +316,9 @@ uint8_t *platform_load_userdata(const char *name, uint32_t *bytes_read) {
}
uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) {
+#if defined(__ANDROID__)
+ platform_ensure_dir(path_userdata);
+#endif
char *path = strcat(strcpy(temp_path, path_userdata), name);
return file_store(path, bytes, len);
}
@@ -257,11 +328,15 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) {
SDL_GLContext platform_gl;
void platform_video_init(void) {
- #if defined(USE_GLES2)
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ #if defined(USE_GLES2)
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ #if defined(__ANDROID__)
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ #else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#endif
+ #endif
platform_gl = SDL_GL_CreateContext(window);
SDL_GL_SetSwapInterval(1);
@@ -345,6 +420,9 @@ uint32_t platform_store_userdata(const char *name, void *bytes, int32_t len) {
#endif
int main(int argc, char *argv[]) {
+#if defined(__ANDROID__)
+ SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight");
+#endif
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
// Figure out the absolute asset and userdata paths. These may either be
@@ -353,23 +431,56 @@ int main(int argc, char *argv[]) {
// We fall back to the current directory (i.e. just "") in this case.
char *sdl_path_assets = NULL;
- #ifdef PATH_ASSETS
- path_assets = TOSTRING(PATH_ASSETS);
- #else
- sdl_path_assets = SDL_GetBasePath();
- if (sdl_path_assets) {
- path_assets = sdl_path_assets;
- }
- #endif
-
char *sdl_path_userdata = NULL;
- #ifdef PATH_USERDATA
- path_userdata = TOSTRING(PATH_USERDATA);
- #else
- sdl_path_userdata = SDL_GetPrefPath("phoboslab", "wipeout");
- if (sdl_path_userdata) {
- path_userdata = sdl_path_userdata;
+
+ #if defined(__ANDROID__)
+ const char *ext_path = SDL_AndroidGetExternalStoragePath();
+ if (ext_path && ext_path[0]) {
+ size_t ext_len = strlen(ext_path);
+ const char *slash = (ext_len > 0 && ext_path[ext_len - 1] == '/') ? "" : "/";
+ snprintf(android_assets_path, sizeof(android_assets_path), "%s%s", ext_path, slash);
+ snprintf(android_userdata_path, sizeof(android_userdata_path), "%swipeout/", android_assets_path);
+ path_assets = android_assets_path;
+ path_userdata = android_userdata_path;
+ platform_ensure_dir(path_userdata);
+ }
+ else {
+ #ifdef PATH_ASSETS
+ path_assets = TOSTRING(PATH_ASSETS);
+ #else
+ sdl_path_assets = SDL_GetBasePath();
+ if (sdl_path_assets) {
+ path_assets = sdl_path_assets;
+ }
+ #endif
+
+ #ifdef PATH_USERDATA
+ path_userdata = TOSTRING(PATH_USERDATA);
+ #else
+ sdl_path_userdata = SDL_GetPrefPath("phoboslab", "wipeout");
+ if (sdl_path_userdata) {
+ path_userdata = sdl_path_userdata;
+ }
+ #endif
}
+ #else
+ #ifdef PATH_ASSETS
+ path_assets = TOSTRING(PATH_ASSETS);
+ #else
+ sdl_path_assets = SDL_GetBasePath();
+ if (sdl_path_assets) {
+ path_assets = sdl_path_assets;
+ }
+ #endif
+
+ #ifdef PATH_USERDATA
+ path_userdata = TOSTRING(PATH_USERDATA);
+ #else
+ sdl_path_userdata = SDL_GetPrefPath("phoboslab", "wipeout");
+ if (sdl_path_userdata) {
+ path_userdata = sdl_path_userdata;
+ }
+ #endif
#endif
// Reserve some space for concatenating the asset and userdata paths with
@@ -378,6 +489,19 @@ int main(int argc, char *argv[]) {
// Load gamecontrollerdb.txt if present.
// FIXME: Should this load from userdata instead?
+#if defined(__ANDROID__)
+ int gcdb_res = -1;
+ SDL_RWops *gcdb_rw = SDL_RWFromFile("gamecontrollerdb.txt", "rb");
+ if (gcdb_rw) {
+ gcdb_res = SDL_GameControllerAddMappingsFromRW(gcdb_rw, 1);
+ }
+ if (gcdb_res < 0) {
+ printf("Failed to load gamecontrollerdb.txt\n");
+ }
+ else {
+ printf("load gamecontrollerdb.txt\n");
+ }
+#else
char *gcdb_path = strcat(strcpy(temp_path, path_assets), "gamecontrollerdb.txt");
int gcdb_res = SDL_GameControllerAddMappingsFromFile(gcdb_path);
if (gcdb_res < 0) {
@@ -386,6 +510,7 @@ int main(int argc, char *argv[]) {
else {
printf("load gamecontrollerdb.txt\n");
}
+#endif
diff --git a/src/render_gl.c b/src/render_gl.c
index f09b49b2..3e15553a 100644
--- a/src/render_gl.c
+++ b/src/render_gl.c
@@ -8,6 +8,25 @@
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
+// Android (GLES2)
+#elif defined(__ANDROID__)
+ #define GL_GLEXT_PROTOTYPES
+ #include
+ #include
+
+ #define glGenVertexArrays glGenVertexArraysOES
+ #define glBindVertexArray glBindVertexArrayOES
+ #define glDeleteVertexArrays glDeleteVertexArraysOES
+
+ #ifndef GL_OES_vertex_array_object
+ #undef glGenVertexArrays
+ #undef glBindVertexArray
+ #undef glDeleteVertexArrays
+ #define glGenVertexArrays(n, arrays) ((void)0)
+ #define glBindVertexArray(array) ((void)0)
+ #define glDeleteVertexArrays(n, arrays) ((void)0)
+ #endif
+
// Linux
#elif defined(__unix__)
#include
@@ -390,6 +409,8 @@ void render_init(vec2i_t screen_size) {
#if defined(__APPLE__) && defined(__MACH__)
// OSX
// (nothing to do here)
+ #elif defined(__ANDROID__)
+ // GLES uses system-provided symbols.
#else
// Windows, Linux
glewExperimental = GL_TRUE;
@@ -988,6 +1009,7 @@ void render_textures_reset(uint16_t len) {
}
}
+#if !defined(USE_GLES2)
void render_textures_dump(const char *path) {
int width = ATLAS_SIZE * ATLAS_GRID;
int height = ATLAS_SIZE * ATLAS_GRID;
@@ -996,3 +1018,8 @@ void render_textures_dump(const char *path) {
stbi_write_png(path, width, height, 4, pixels, 0);
free(pixels);
}
+#else
+void render_textures_dump(const char *path) {
+ (void)path;
+}
+#endif
diff --git a/src/wipeout/image.c b/src/wipeout/image.c
index 99712d60..579583af 100755
--- a/src/wipeout/image.c
+++ b/src/wipeout/image.c
@@ -229,6 +229,7 @@ cmp_t *image_load_compressed(char *name) {
printf("load cmp %s\n", name);
uint32_t compressed_size;
uint8_t *compressed_bytes = platform_load_asset(name, &compressed_size);
+ error_if(!compressed_bytes || compressed_size == 0, "Missing asset: %s", name);
uint32_t p = 0;
int32_t decompressed_size = 0;
@@ -263,6 +264,7 @@ uint16_t image_get_texture(char *name) {
printf("load: %s\n", name);
uint32_t size;
uint8_t *bytes = platform_load_asset(name, &size);
+ error_if(!bytes || size == 0, "Missing asset: %s", name);
image_t *image = image_load_from_bytes(bytes, false);
uint32_t texture_index = render_texture_create(image->width, image->height, image->pixels);
mem_temp_free(image);
@@ -275,6 +277,7 @@ uint16_t image_get_texture_semi_trans(char *name) {
printf("load: %s\n", name);
uint32_t size;
uint8_t *bytes = platform_load_asset(name, &size);
+ error_if(!bytes || size == 0, "Missing asset: %s", name);
image_t *image = image_load_from_bytes(bytes, true);
uint32_t texture_index = render_texture_create(image->width, image->height, image->pixels);
mem_temp_free(image);
diff --git a/src/wipeout/intro.c b/src/wipeout/intro.c
index 0de5c983..0f9b50ad 100644
--- a/src/wipeout/intro.c
+++ b/src/wipeout/intro.c
@@ -5,6 +5,10 @@
#include "../mem.h"
#include "../platform.h"
+#if defined(__ANDROID__)
+ #include "SDL.h"
+#endif
+
#include "intro.h"
#include "ui.h"
#include "image.h"
@@ -37,13 +41,23 @@ static void audio_mix(float *samples, uint32_t len);
static void intro_end(void);
void intro_init(void) {
- FILE *file = platform_open_asset("wipeout/intro.mpeg", "rb");
- if (!file) {
- intro_end();
- return;
- }
-
- plm = plm_create_with_file(file, true);
+ #if defined(__ANDROID__)
+ SDL_RWops *rwops = SDL_RWFromFile("wipeout/intro.mpeg", "rb");
+ if (!rwops) {
+ intro_end();
+ return;
+ }
+
+ plm = plm_create_with_rwops(rwops, true);
+ #else
+ FILE *file = platform_open_asset("wipeout/intro.mpeg", "rb");
+ if (!file) {
+ intro_end();
+ return;
+ }
+
+ plm = plm_create_with_file(file, true);
+ #endif
if (!plm) {
intro_end();
return;
diff --git a/src/wipeout/sfx.c b/src/wipeout/sfx.c
index 2d4d3197..20024647 100644
--- a/src/wipeout/sfx.c
+++ b/src/wipeout/sfx.c
@@ -2,6 +2,10 @@
#include "../mem.h"
#include "../platform.h"
+#if defined(__ANDROID__)
+ #include "SDL.h"
+#endif
+
#include "sfx.h"
#include "game.h"
@@ -16,7 +20,11 @@ typedef struct {
typedef struct {
qoa_desc qoa;
+#if defined(__ANDROID__)
+ SDL_RWops *rwops;
+#else
FILE *file;
+#endif
uint32_t track_index;
uint32_t first_frame_pos;
@@ -58,7 +66,11 @@ void sfx_load(void) {
music->sample_data = mem_bump(channels * QOA_FRAME_LEN * sizeof(short) * 2);
music->qoa.channels = channels;
music->mode = SFX_MUSIC_RANDOM;
+#if defined(__ANDROID__)
+ music->rwops = NULL;
+#else
music->file = NULL;
+#endif
music->track_index = -1;
@@ -228,10 +240,21 @@ void sfx_set_position(sfx_t *sfx, vec3_t pos, vec3_t vel, float volume) {
// Music
uint32_t sfx_music_decode_frame(void) {
- if (!music->file) {
- return 0;
- }
- music->buffer_len = fread(music->buffer, 1, qoa_max_frame_size(&music->qoa), music->file);
+ #if defined(__ANDROID__)
+ if (!music->rwops) {
+ return 0;
+ }
+ size_t read = SDL_RWread(music->rwops, music->buffer, 1, qoa_max_frame_size(&music->qoa));
+ music->buffer_len = (uint32_t)read;
+ if (music->buffer_len == 0) {
+ return 0;
+ }
+ #else
+ if (!music->file) {
+ return 0;
+ }
+ music->buffer_len = fread(music->buffer, 1, qoa_max_frame_size(&music->qoa), music->file);
+ #endif
uint32_t frame_len;
qoa_decode_frame(music->buffer, music->buffer_len, &music->qoa, music->sample_data, &frame_len);
@@ -241,47 +264,94 @@ uint32_t sfx_music_decode_frame(void) {
}
void sfx_music_rewind(void) {
- fseek(music->file, music->first_frame_pos, SEEK_SET);
+ #if defined(__ANDROID__)
+ if (music->rwops) {
+ SDL_RWseek(music->rwops, music->first_frame_pos, RW_SEEK_SET);
+ }
+ #else
+ fseek(music->file, music->first_frame_pos, SEEK_SET);
+ #endif
music->sample_data_len = 0;
music->sample_data_pos = 0;
}
void sfx_music_open(char *path) {
- if (music->file) {
- fclose(music->file);
- music->file = NULL;
- }
-
- FILE *file = platform_open_asset(path, "rb");
- if (!file) {
- return;
- }
+ #if defined(__ANDROID__)
+ if (music->rwops) {
+ SDL_RWclose(music->rwops);
+ music->rwops = NULL;
+ }
- uint8_t header[QOA_MIN_FILESIZE];
- int read = fread(header, QOA_MIN_FILESIZE, 1, file);
- if (!read) {
- fclose(file);
- return;
- }
+ SDL_RWops *rwops = SDL_RWFromFile(path, "rb");
+ if (!rwops) {
+ return;
+ }
- qoa_desc qoa;
- uint32_t first_frame_pos = qoa_decode_header(header, QOA_MIN_FILESIZE, &qoa);
- if (!first_frame_pos) {
- fclose(file);
- return;
- }
+ uint8_t header[QOA_MIN_FILESIZE];
+ size_t read = SDL_RWread(rwops, header, 1, QOA_MIN_FILESIZE);
+ if (read != QOA_MIN_FILESIZE) {
+ SDL_RWclose(rwops);
+ return;
+ }
- fseek(file, first_frame_pos, SEEK_SET);
+ qoa_desc qoa;
+ uint32_t first_frame_pos = qoa_decode_header(header, QOA_MIN_FILESIZE, &qoa);
+ if (!first_frame_pos) {
+ SDL_RWclose(rwops);
+ return;
+ }
- if (qoa.channels != music->qoa.channels) {
- fclose(file);
- return;
- }
- music->qoa = qoa;
- music->first_frame_pos = first_frame_pos;
- music->file = file;
- music->sample_data_len = 0;
- music->sample_data_pos = 0;
+ if (SDL_RWseek(rwops, first_frame_pos, RW_SEEK_SET) < 0) {
+ SDL_RWclose(rwops);
+ return;
+ }
+
+ if (qoa.channels != music->qoa.channels) {
+ SDL_RWclose(rwops);
+ return;
+ }
+ music->qoa = qoa;
+ music->first_frame_pos = first_frame_pos;
+ music->rwops = rwops;
+ music->sample_data_len = 0;
+ music->sample_data_pos = 0;
+ #else
+ if (music->file) {
+ fclose(music->file);
+ music->file = NULL;
+ }
+
+ FILE *file = platform_open_asset(path, "rb");
+ if (!file) {
+ return;
+ }
+
+ uint8_t header[QOA_MIN_FILESIZE];
+ int read = fread(header, QOA_MIN_FILESIZE, 1, file);
+ if (!read) {
+ fclose(file);
+ return;
+ }
+
+ qoa_desc qoa;
+ uint32_t first_frame_pos = qoa_decode_header(header, QOA_MIN_FILESIZE, &qoa);
+ if (!first_frame_pos) {
+ fclose(file);
+ return;
+ }
+
+ fseek(file, first_frame_pos, SEEK_SET);
+
+ if (qoa.channels != music->qoa.channels) {
+ fclose(file);
+ return;
+ }
+ music->qoa = qoa;
+ music->first_frame_pos = first_frame_pos;
+ music->file = file;
+ music->sample_data_len = 0;
+ music->sample_data_pos = 0;
+ #endif
}
void sfx_music_play(uint32_t index) {
@@ -366,7 +436,11 @@ void sfx_stero_mix(float *buffer, uint32_t len) {
right *= save.sfx_volume;
// Mix in music
+ #if defined(__ANDROID__)
+ if (music->mode != SFX_MUSIC_PAUSED && music->rwops) {
+ #else
if (music->mode != SFX_MUSIC_PAUSED && music->file) {
+ #endif
if (music->sample_data_len - music->sample_data_pos == 0) {
if (!sfx_music_decode_frame()) {
if (music->mode == SFX_MUSIC_RANDOM) {