WIP Android SDL

This commit is contained in:
TheBrokenRail
2023-11-02 15:02:58 -04:00
committed by iProgramInCpp
parent 811bc7a6fa
commit 0559f66102
46 changed files with 631 additions and 276 deletions

6
.gitmodules vendored
View File

@@ -4,3 +4,9 @@
[submodule "thirdparty/gles-compatibility-layer"]
path = thirdparty/gles-compatibility-layer
url = https://github.com/TheBrokenRail/gles-compatibility-layer.git
[submodule "thirdparty/SDL-src"]
path = thirdparty/SDL-src
url = https://github.com/libsdl-org/SDL
[submodule "thirdparty/LibPNG-src"]
path = thirdparty/LibPNG-src
url = https://github.com/glennrp/libpng

View File

@@ -9,7 +9,7 @@
#define DEMO
#else
#if defined __ANDROID__ || defined TARGET_OS_IPHONE
#if defined ANDROID || defined TARGET_OS_IPHONE
#define MOBILE
#endif

View File

@@ -26,7 +26,7 @@ enum eSDLVirtualKeys
#include <Windows.h>
#endif
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
#include <android/keycodes.h>
#define AKEYCODE_ARROW_LEFT AKEYCODE_DPAD_LEFT

View File

@@ -43,20 +43,38 @@ if(EMSCRIPTEN)
else()
list(APPEND SOURCES desktop/AppPlatform_sdl.cpp)
endif()
add_executable(reminecraftpe ${SOURCES})
if(ANDROID)
add_library(reminecraftpe SHARED ${SOURCES})
set_target_properties(reminecraftpe PROPERTIES OUTPUT_NAME main)
target_link_libraries(reminecraftpe log)
else()
add_executable(reminecraftpe ${SOURCES})
endif()
# Core
add_subdirectory(../../source source)
target_link_libraries(reminecraftpe reminecraftpe-core)
# OpenAL
add_subdirectory(../openal openal)
target_link_libraries(reminecraftpe reminecraftpe-openal)
if(NOT ANDROID)
add_subdirectory(../openal openal)
target_link_libraries(reminecraftpe reminecraftpe-openal)
endif()
# LibPNG (If Needed)
if(NOT EMSCRIPTEN)
find_package(PNG REQUIRED)
target_link_libraries(reminecraftpe PNG::PNG)
if(ANDROID)
# Vendor LibPNG
add_subdirectory(../../thirdparty/LibPNG-src libpng EXCLUDE_FROM_ALL)
target_include_directories(png_static INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../thirdparty/LibPNG-src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/libpng>"
)
target_link_libraries(reminecraftpe png_static)
else()
find_package(PNG REQUIRED)
target_link_libraries(reminecraftpe PNG::PNG)
endif()
endif()
# SDL

15
platforms/sdl/android/.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

3
platforms/sdl/android/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>

20
platforms/sdl/android/.idea/gradle.xml generated Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

10
platforms/sdl/android/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

7
platforms/sdl/android/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

1
platforms/sdl/android/app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,41 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 33
defaultConfig {
applicationId 'io.github.reminecraftpe'
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName '1.0'
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_static'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
applicationVariants.all { variant ->
tasks["merge${variant.name.capitalize()}Assets"]
.dependsOn("externalNativeBuild${variant.name.capitalize()}")
}
sourceSets.main {
java.srcDir '../../../../thirdparty/SDL-src/android-project/app/src/main/java'
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
version '3.22.1'
}
}
lint {
abortOnError false
}
namespace 'io.github.reminecraftpe'
}

View File

@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in [sdk]/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# 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 *;
#}

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<!-- OpenGL ES 3.0 -->
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
<!-- Touchscreen support -->
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<!-- External mouse input events -->
<uses-feature
android:name="android.hardware.type.pc"
android:required="false" />
<!-- Internet -->
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name"
android:icon="@drawable/icon"
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:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:preferMinimalPostProcessing="true"
android:exported="true"
android:windowSoftInputMode="adjustPan"
tools:ignore="UnusedAttribute">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1 @@
../../../../../../../game/assets

View File

@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-android)
add_subdirectory(../../../../../ sdl)

View File

@@ -0,0 +1,42 @@
package io.github.reminecraftpe;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager;
import org.libsdl.app.SDLActivity;
public class MainActivity extends SDLActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fullscreen
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
}
@Override
@SuppressWarnings("deprecation")
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
// Fullscreen
if (hasFocus) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
WindowInsetsController controller = getWindow().getInsetsController();
if (controller != null) {
controller.hide(WindowInsets.Type.systemBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
} else {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">ReMinecraftPE</string>
</resources>

View File

@@ -0,0 +1,25 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@@ -0,0 +1,17 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#Thu Nov 11 18:20:34 PST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

160
platforms/sdl/android/gradlew vendored Executable file
View File

@@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
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"
which java >/dev/null 2>&1 || 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
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
platforms/sdl/android/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,90 @@
@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
@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=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
: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 %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="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!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -0,0 +1 @@
include ':app'

View File

@@ -12,7 +12,9 @@
#include "common/Utils.hpp"
#ifndef ANDROID
#include "SoundSystemAL.hpp"
#endif
void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)
{
@@ -35,7 +37,11 @@ void AppPlatform_sdl_base::initSoundSystem()
{
if (!m_pSoundSystem)
{
#ifndef ANDROID
m_pSoundSystem = new SoundSystemAL();
#else
m_pSoundSystem = new SoundSystem();
#endif
LOG_I("Initializing OpenAL SoundSystem...");
}
else

View File

@@ -380,6 +380,8 @@ int main(int argc, char *argv[])
storagePath = getenv("APPDATA");
#elif defined(__EMSCRIPTEN__)
storagePath = "";
#elif defined(ANDROID)
storagePath = SDL_AndroidGetInternalStoragePath();
#else
storagePath = getenv("HOME");
#endif

View File

@@ -1,12 +1,6 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-core)
if(NOT ANDROID)
set(INCLUDES . .. ../thirdparty/zlib)
else()
set(INCLUDES . ..)
endif()
# Build
add_library(reminecraftpe-core STATIC
common/Random.cpp
@@ -275,21 +269,23 @@ add_library(reminecraftpe-core STATIC
renderer/GL/GL.cpp
)
target_include_directories(reminecraftpe-core PUBLIC ${INCLUDES})
target_include_directories(reminecraftpe-core PUBLIC . .. ../thirdparty/zlib)
# RakNet
add_subdirectory(../thirdparty/raknet raknet)
target_link_libraries(reminecraftpe-core PUBLIC raknet)
# zlib - Android builds with its own version
# Hack - If we're not building for Android, surely we're building with SDL
# zlib
add_subdirectory(../thirdparty/zlib zlib)
target_link_libraries(reminecraftpe-core PUBLIC zlib)
# SDL
if(USE_SDL)
add_subdirectory(../thirdparty/zlib zlib)
target_link_libraries(reminecraftpe-core PUBLIC zlib)
# SDL
add_library(SDL INTERFACE)
if(EMSCRIPTEN)
if(ANDROID)
add_subdirectory(../thirdparty/SDL-src SDL EXCLUDE_FROM_ALL)
target_link_libraries(SDL INTERFACE SDL2::SDL2)
elseif(EMSCRIPTEN)
set(SDL_FLAG -sUSE_SDL=2)
target_compile_options(SDL INTERFACE "${SDL_FLAG}")
target_link_options(SDL INTERFACE "${SDL_FLAG}")
@@ -298,7 +294,7 @@ if(USE_SDL)
target_link_libraries(SDL INTERFACE SDL2::SDL2)
endif()
target_link_libraries(reminecraftpe-core PUBLIC SDL)
# OpenGL
if(NOT EMSCRIPTEN)
option(USE_GLES1_COMPATIBILITY_LAYER "Whether To Enable The GLESv1_CM Compatibility Layer" TRUE)
@@ -318,8 +314,6 @@ if(USE_SDL)
find_package(OpenGL REQUIRED)
target_link_libraries(reminecraftpe-core PUBLIC OpenGL::OpenGL OpenGL::GLU)
endif()
elseif(ANDROID)
# Add Android related stuff here.
endif()
# Sound Data

View File

@@ -10,7 +10,7 @@
#include "client/app/Minecraft.hpp"
#ifndef ORIGINAL_CODE
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
#define HANDLE_CHARS_SEPARATELY // faked though, see platforms/android/minecraftcpp/minecraftcpp.NativeActivity/main.cpp
#endif

View File

@@ -149,7 +149,7 @@ void Options::_initDefaultValues()
KM(KM_FLY_DOWN, SDLVK_x);
KM(KM_CHAT_CMD, SDLVK_SLASH);
#endif
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
// -- Original xperia play controls
//KM(KM_FORWARD, AKEYCODE_DPAD_UP);
//KM(KM_LEFT, AKEYCODE_DPAD_LEFT);

View File

@@ -13,7 +13,7 @@ bool Controller::isTouchedValues[2];
float Controller::stickValuesX[2];
float Controller::stickValuesY[2];
#ifndef __ANDROID__
#if !defined(ANDROID) || defined(USE_SDL)
const float Controller_unk_1[3] = { 0.0f, 0.64f, -0.64f };
#endif
@@ -52,7 +52,7 @@ void Controller::feed(int stickNo, int touched, float x, float y)
if (!isValidStick(stickNo))
return;
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
int index = stickNo - 1;
#else
int index = (x >= 0.0f) ? 1 : 0;
@@ -61,7 +61,7 @@ void Controller::feed(int stickNo, int touched, float x, float y)
// maybe the 2 'touch sticks' are actually internally 1 single surface??
isTouchedValues[index] = touched != 0;
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
stickValuesX[index] = x;
#else
stickValuesX[index] = linearTransform(x + Controller_unk_1[index + 1], 0.0f, 2.78f, true);

View File

@@ -22,7 +22,7 @@ ControllerTurnInput::ControllerTurnInput()
TurnDelta ControllerTurnInput::getTurnDelta()
{
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
return TurnDelta(Controller::getX(m_stickNo) * 50.f, Controller::getY(m_stickNo) * 60.f);
#endif

View File

@@ -326,7 +326,7 @@ void GameRenderer::setupFog(int i)
if (m_pMinecraft->m_pMobPersp->isUnderLiquid(Material::water))
{
#if defined(ORIGINAL_CODE) || defined(__ANDROID__)
#if defined(ORIGINAL_CODE) || defined(ANDROID)
glFogx(GL_FOG_MODE, GL_EXP);
#else
glFogi(GL_FOG_MODE, GL_EXP);
@@ -336,7 +336,7 @@ void GameRenderer::setupFog(int i)
}
else if (m_pMinecraft->m_pMobPersp->isUnderLiquid(Material::lava))
{
#if defined(ORIGINAL_CODE) || defined(__ANDROID__)
#if defined(ORIGINAL_CODE) || defined(ANDROID)
glFogx(GL_FOG_MODE, GL_EXP);
#else
glFogi(GL_FOG_MODE, GL_EXP);
@@ -346,7 +346,7 @@ void GameRenderer::setupFog(int i)
}
else
{
#if defined(ORIGINAL_CODE) || defined(__ANDROID__)
#if defined(ORIGINAL_CODE) || defined(ANDROID)
glFogx(GL_FOG_MODE, GL_LINEAR);
#else
glFogi(GL_FOG_MODE, GL_LINEAR);

View File

@@ -2,12 +2,23 @@
#include <string>
#ifdef ANDROID
#include <android/log.h>
enum eLogLevel
{
LOG_INFO = ANDROID_LOG_INFO,
LOG_WARN = ANDROID_LOG_WARN,
LOG_ERR = ANDROID_LOG_ERROR,
};
#else
enum eLogLevel
{
LOG_INFO,
LOG_WARN,
LOG_ERR,
};
#endif
class Logger
{
@@ -26,39 +37,19 @@ public:
virtual void printf(eLogLevel, const char* const fmt, ...);
};
// TODO: For now
#ifdef __ANDROID__
#ifndef NDEBUG
#define _DEBUG
#endif
#endif
#if defined(_DEBUG) || !defined(NDEBUG)
#ifdef _DEBUG
#define LOG(level, ...) Logger::singleton()->printf(level, __VA_ARGS__)
#ifdef __ANDROID__
#undef LOG
#define LOG_INFO ANDROID_LOG_INFO
#define LOG_ERR ANDROID_LOG_ERROR
#define LOG_WARN ANDROID_LOG_WARN
#include <android/log.h>
#ifdef ANDROID
// TODO: Add a LoggerAndroid
#define LOG(level, ...) __android_log_print(level, "ReMinecraftPE", __VA_ARGS__)
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, "ReMinecraftPE", __VA_ARGS__)
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, "ReMinecraftPE", __VA_ARGS__)
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, "ReMinecraftPE", __VA_ARGS__)
#define LOG(level, ...) __android_log_print(level, "ReMinecraftPE", __VA_ARGS__)
#else
#define LOG(level, ...) Logger::singleton()->printf(level, __VA_ARGS__)
#endif
#define LOG_I(...) LOG(LOG_INFO, __VA_ARGS__)
#define LOG_W(...) LOG(LOG_WARN, __VA_ARGS__)
#define LOG_E(...) LOG(LOG_ERR, __VA_ARGS__)
#endif
#else
#define LOG(...) ((void)0)

View File

@@ -1,46 +0,0 @@
#include <iostream>
#include <stdarg.h>
#ifdef _WIN32
#include <windows.h>
#endif
#include "StandardOut.hpp"
#include "Util.hpp"
StandardOut* const StandardOut::singleton()
{
// This is automatically allocated when accessed for the first time,
// and automatically deallocated when runtime concludes.
static StandardOut standardOut = StandardOut();
return &standardOut;
}
void StandardOut::print(const char* const str)
{
std::cout << str << std::endl;
#ifdef _WIN32
OutputDebugStringA(str);
OutputDebugStringA("\n");
#endif
}
void StandardOut::print(std::string str)
{
print(str.c_str());
}
void StandardOut::vprintf(const char* const fmt, va_list argPtr)
{
print(Util::vformat(fmt, argPtr));
}
void StandardOut::printf(const char* const fmt, ...)
{
va_list argList;
va_start(argList, fmt);
vprintf(fmt, argList);
va_end(argList);
}

View File

@@ -1,37 +0,0 @@
#pragma once
#include <string>
class StandardOut
{
public:
static StandardOut* const singleton();
void print(const char* const str);
void print(std::string str);
void vprintf(const char* const fmt, va_list argPtr);
void printf(const char* const fmt, ...);
};
#ifdef _DEBUG
#define LOG(...) StandardOut::singleton()->printf(__VA_ARGS__)
#ifdef PLATFORM_ANDROID
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, "MinecraftPE", __VA_ARGS__)
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, "MinecraftPE", __VA_ARGS__)
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, "MinecraftPE", __VA_ARGS__)
#else
#define LOG_I(...) LOG("[Info]: " __VA_ARGS__)
#define LOG_W(...) LOG("[WARN]: " __VA_ARGS__)
#define LOG_E(...) LOG("[ERROR]: " __VA_ARGS__)
#endif
#else
#define LOG(...)
#define LOG_I(...)
#define LOG_W(...)
#define LOG_E(...)
#endif

View File

@@ -36,7 +36,7 @@
int g_TimeSecondsOnInit = 0;
#if (!defined(USE_SDL) || defined(_WIN32)) && !defined(__ANDROID__)
#if (!defined(USE_SDL) || defined(_WIN32)) && !defined(ANDROID)
DIR* opendir(const char* name)
{

136
thirdparty/GL/GL.hpp vendored
View File

@@ -10,9 +10,8 @@
#include <common/Utils.hpp> // it includes GL/gl.h
#ifdef __ANDROID__
#if defined(ANDROID) && !defined(USE_SDL)
#define USE_GLES
#include <EGL/egl.h>
#endif
@@ -23,12 +22,12 @@
#ifdef USE_GLES
#include <GLES/gl.h>
#define GL_QUADS 0x7
#define USE_OPENGL_2_FEATURES
#include <cmath>
// https://cgit.freedesktop.org/mesa/glu/tree/src/libutil/project.c
// https://cgit.freedesktop.org/mesa/glu/tree/src/libutil/project.c
static inline void __gluMakeIdentityf(GLfloat m[16]) {
m[0 + 4 * 0] = 1; m[0 + 4 * 1] = 0; m[0 + 4 * 2] = 0; m[0 + 4 * 3] = 0;
m[1 + 4 * 0] = 0; m[1 + 4 * 1] = 1; m[1 + 4 * 2] = 0; m[1 + 4 * 3] = 0;
@@ -56,13 +55,13 @@
m[3][3] = 0;
glMultMatrixf(&m[0][0]);
}
#define USE_GL_ORTHO_F
#else
#include <GL/gl.h>
#include <GL/glu.h>
#ifdef _WIN32
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
@@ -73,13 +72,13 @@
#else
#include <GL/glu.h>
#endif
#ifdef USE_SDL
#define USE_OPENGL_2_FEATURES
#define GL_GLEXT_PROTOTYPES
#include "thirdparty/SDL2/SDL_opengl.h"
#ifndef _WIN32
#include <SDL2/SDL_opengl_glext.h>
#endif
@@ -134,122 +133,3 @@ void xglDrawArrays(GLenum mode, GLint first, GLsizei count);
#else
#define xglOrthof(left, right, bottom, top, nearpl, farpl) glOrtho((GLdouble) (left), (GLdouble) (right), (GLdouble) (bottom), (GLdouble) (top), (GLdouble) (nearpl), (GLdouble) (farpl))
#endif
#if 0
#ifdef __ANDROID__
#include <EGL/egl.h>
#endif
#if defined(USE_SDL) || defined(__ANDROID__)
#if defined(USE_GLES1_COMPATIBILITY_LAYER) || defined(__ANDROID__)
#include <GLES/gl.h>
#define GL_QUADS 0x7
#include <cmath>
// https://cgit.freedesktop.org/mesa/glu/tree/src/libutil/project.c
static inline void __gluMakeIdentityf(GLfloat m[16]) {
m[0 + 4 * 0] = 1; m[0 + 4 * 1] = 0; m[0 + 4 * 2] = 0; m[0 + 4 * 3] = 0;
m[1 + 4 * 0] = 0; m[1 + 4 * 1] = 1; m[1 + 4 * 2] = 0; m[1 + 4 * 3] = 0;
m[2 + 4 * 0] = 0; m[2 + 4 * 1] = 0; m[2 + 4 * 2] = 1; m[2 + 4 * 3] = 0;
m[3 + 4 * 0] = 0; m[3 + 4 * 1] = 0; m[3 + 4 * 2] = 0; m[3 + 4 * 3] = 1;
}
static inline void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) {
GLfloat m[4][4];
float sine, cotangent, deltaZ;
float radians = fovy / 2 * M_PI / 180;
deltaZ = zFar - zNear;
sine = sin(radians);
if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
return;
}
cotangent = cosf(radians) / sine;
__gluMakeIdentityf(&m[0][0]);
m[0][0] = cotangent / aspect;
m[1][1] = cotangent;
m[2][2] = -(zFar + zNear) / deltaZ;
m[2][3] = -1;
m[3][2] = -2 * zNear * zFar / deltaZ;
m[3][3] = 0;
glMultMatrixf(&m[0][0]);
}
#else
#ifdef _WIN32
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#endif
#ifdef __APPLE__
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif
#ifdef USE_SDL
#define USE_OPENGL_2
#if defined(USE_GLES) || defined(__ANDROID__)
#define xglOrthof glOrthof
#else
#define xglOrthof(left, right, bottom, top, nearpl, farpl) glOrtho((GLdouble) (left), (GLdouble) (right), (GLdouble) (bottom), (GLdouble) (top), (GLdouble) (nearpl), (GLdouble) (farpl))
#endif
#else
#ifndef __APPLE__
#include <GL/glext.h> // it'll include from a different dir, namely thirdparty/GL/glext.h
#endif
#endif
#endif
#ifdef _WIN32
void xglInit();
bool xglInitted();
void xglBindBuffer(GLenum target, GLuint buffer);
void xglBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
void xglGenBuffers(GLsizei num, GLuint* buffers);
void xglDeleteBuffers(GLsizei num, GLuint* buffers);
void xglOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearpl, GLfloat farpl);
void xglSwapIntervalEXT(int interval);
void xglEnableClientState(GLenum _array);
void xglDisableClientState(GLenum _array);
void xglTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
void xglColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
void xglVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
void xglDrawArrays(GLenum mode, GLint first, GLsizei count);
#else
#define xglBindBuffer glBindBuffer
#define xglBufferData glBufferData
#define xglGenBuffers glGenBuffers
#define xglDeleteBuffers glDeleteBuffers
#define xglEnableClientState glEnableClientState
#define xglDisableClientState glDisableClientState
#define xglTexCoordPointer glTexCoordPointer
#define xglColorPointer glColorPointer
#define xglVertexPointer glVertexPointer
#define xglDrawArrays glDrawArrays
#ifdef USE_GLES
#define xglOrthof glOrthof
#else
#define xglOrthof(left, right, bottom, top, nearpl, farpl) glOrtho((GLdouble) (left), (GLdouble) (right), (GLdouble) (bottom), (GLdouble) (top), (GLdouble) (nearpl), (GLdouble) (farpl))
#endif
#endif
#endif
#endif

1
thirdparty/LibPNG-src vendored Submodule

Submodule thirdparty/LibPNG-src added at f135775ad4

1
thirdparty/SDL-src vendored Submodule

Submodule thirdparty/SDL-src added at cc016b0046

View File

@@ -14,13 +14,10 @@
#include <stdio.h> // RAKNET_DEBUG_PRINTF
#include "RakAssert.h"
#if defined(ANDROID)
//#include <sys/io.h>
#elif defined(_WIN32) || defined(__CYGWIN__)
#if defined(_WIN32) || defined(__CYGWIN__)
#include <io.h>
#elif !defined ( __APPLE__ ) && !defined ( __APPLE_CC__ ) && !defined ( __PPC__ ) && !defined ( __FreeBSD__ ) && !defined ( __S3E__ ) && !defined ( __EMSCRIPTEN__ ) && !defined ( __ANDROID__ ) && !defined ( __HAIKU__ )
#elif !defined ( __APPLE__ ) && !defined ( __APPLE_CC__ ) && !defined ( __PPC__ ) && !defined ( __FreeBSD__ ) && !defined ( __S3E__ ) && !defined ( __EMSCRIPTEN__ ) && !defined ( ANDROID ) && !defined ( __HAIKU__ )
#include <sys/io.h>
#endif