Browse Source

Port engine to Android

Set the font path for Android

Do not check for FileExists on CharisSILB.ttf for Android, FileExists
will always fail as it doesn't detect files located in the APK

port
pull/2165/head
Anders Jenbo 5 years ago
parent
commit
e2ead2cc5e
  1. 31
      CMakeLists.txt
  2. 2
      Source/DiabloUI/fonts.cpp
  3. 14
      Source/init.cpp
  4. 4
      Source/main.cpp
  5. 2
      Source/storm/storm_file_wrapper.h
  6. 2
      android-project/.gitignore
  7. 0
      android-project/app/src/main/assets/.gitkeep

31
CMakeLists.txt

@ -187,6 +187,17 @@ if(NINTENDO_3DS)
include(n3ds_defs)
endif()
if(ANDROID)
set(ASAN OFF)
set(UBSAN OFF)
set(NONET ON)
set(TTF_FONT_DIR \"\")
file(
COPY "${DevilutionX_SOURCE_DIR}/Packaging/resources/CharisSILB.ttf"
DESTINATION "${DevilutionX_SOURCE_DIR}/android-project/app/src/main/assets")
endif()
if(PIE)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
@ -426,13 +437,6 @@ set(libdevilutionx_SRCS
Source/storm/storm_svid.cpp
Source/miniwin/misc_msg.cpp)
set(devilutionxbin_SRCS
Source/main.cpp
Source/devilutionx.exe.manifest
Packaging/macOS/AppIcon.icns
Packaging/resources/CharisSILB.ttf
Packaging/windows/devilutionx.rc)
if(USE_SDL1)
list(APPEND libdevilutionx_SRCS Source/utils/sdl2_to_1_2_backports.cpp)
endif()
@ -515,7 +519,18 @@ if(RUN_TESTS)
endif()
add_library(libdevilutionx OBJECT ${libdevilutionx_SRCS})
add_executable(${BIN_TARGET} WIN32 MACOSX_BUNDLE ${devilutionxbin_SRCS})
if (ANDROID)
add_library(${BIN_TARGET} SHARED Source/main.cpp)
else()
add_executable(${BIN_TARGET}
WIN32
MACOSX_BUNDLE
Source/main.cpp
Source/devilutionx.exe.manifest
Packaging/macOS/AppIcon.icns
Packaging/resources/CharisSILB.ttf
Packaging/windows/devilutionx.rc)
endif()
target_link_libraries(${BIN_TARGET} PRIVATE libdevilutionx)
# Copy the font and devilutionx.mpq to the build directory to it works from the build directory

2
Source/DiabloUI/fonts.cpp

@ -63,7 +63,7 @@ void LoadTtfFont()
}
std::string ttfFontPath = paths::TtfPath() + paths::TtfName();
#ifdef __linux__
#if defined(__linux__) && !defined(__ANDROID__)
if (!FileExists(ttfFontPath.c_str())) {
ttfFontPath = "/usr/share/fonts/truetype/" + paths::TtfName();
}

14
Source/init.cpp

@ -139,16 +139,24 @@ void init_archives()
{
std::vector<std::string> paths;
paths.reserve(5);
#ifdef __ANDROID__
paths.push_back(std::string(getenv("EXTERNAL_STORAGE")) + "/devilutionx/");
#else
paths.push_back(paths::BasePath());
#endif
paths.push_back(paths::PrefPath());
if (paths[0] == paths[1])
paths.pop_back();
#ifdef __linux__
#ifdef __ANDROID__
if (getenv("SECONDARY_STORAGE") != nullptr)
paths.emplace_back(std::string(getenv("SECONDARY_STORAGE")) + "/devilutionx/");
if (getenv("EXTERNAL_SDCARD_STORAGE") != nullptr)
paths.emplace_back(std::string(getenv("EXTERNAL_SDCARD_STORAGE")) + "/devilutionx/");
#elif defined(__linux__)
paths.emplace_back("/usr/share/diasurgical/devilutionx/");
paths.emplace_back("/usr/local/share/diasurgical/devilutionx/");
#endif
#ifdef __3DS__
#elif defined(__3DS__)
paths.emplace_back("romfs:/");
#endif

4
Source/main.cpp

@ -18,7 +18,11 @@ extern "C" const char *__asan_default_options()
}
#endif
#ifdef __ANDROID__
int SDL_main(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
#ifdef __SWITCH__
switch_enable_network();

2
Source/storm/storm_file_wrapper.h

@ -1,6 +1,6 @@
/** A pointer to a Storm file as a `FILE *`. Only available on some platforms. */
#pragma once
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
#if (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__) || defined(__DragonFly__)
#include <cstdio>
#include "miniwin/miniwin.h"

2
android-project/.gitignore vendored

@ -10,3 +10,5 @@ build/
# Local configuration file (sdk path, etc)
/local.properties
/app/src/main/assets/CharisSILB.ttf

0
android-project/app/src/main/assets/.gitkeep

Loading…
Cancel
Save