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

Xbox One/Series support #3946

Merged
merged 12 commits into from
Jan 17, 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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,10 @@ Brewfile.lock.json
# GPerf heap profile dumps
*.heap
*.mo

# UWP copied assets
uwp-project/Assets/data
uwp-project/Assets/fonts
uwp-project/Assets/gendata
uwp-project/Assets/ui_art

18 changes: 17 additions & 1 deletion 3rdParty/SDL2/CMake/FindSDL2.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# An empty find module to allow calls to `find_package(SDL2)` to succeed.
if(UWP_LIB AND NOT TARGET SDL2::SDL2-static)
set(SDL_BUILD_TYPE "Release")

if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(SDL_BUILD_TYPE "Debug")
endif()

set(SDL2_LIBRARY "${UWP_SDL2_DIR}/VisualC-WinRT/x64/${SDL_BUILD_TYPE}/SDL-UWP")
set(SDL2_INCLUDE_DIR "${UWP_SDL2_DIR}/include")
add_library(SDL2_lib STATIC IMPORTED)
set_property(TARGET SDL2_lib PROPERTY IMPORTED_LOCATION "${SDL2_LIBRARY}/SDL2.lib")
set_property(TARGET SDL2_lib PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR})
add_library(SDL2::SDL2-static ALIAS SDL2_lib)
mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY)
set(SDL2_LIBRARIES ${SDL2_LIBRARY})
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
endif()
4 changes: 0 additions & 4 deletions 3rdParty/SDL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ FetchContent_Declare(SDL2
URL_HASH MD5=3fb6d72c33434082c32d2649c35c6502
)
FetchContent_MakeAvailableExcludeFromAll(SDL2)

if(TARGET SDL2::SDL2-static)
add_library(SDL2::SDL2 ALIAS SDL2-static)
endif()
5 changes: 4 additions & 1 deletion 3rdParty/SDL_image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ target_link_libraries(SDL_image PNG::PNG)

if(USE_SDL1)
target_link_libraries(SDL_image ${SDL_LIBRARY})
else()
elseif(TARGET SDL2::SDL2)
target_link_libraries(SDL_image SDL2::SDL2)
add_library(SDL2::SDL2_image ALIAS SDL_image)
elseif(TARGET SDL2::SDL2-static)
target_link_libraries(SDL_image SDL2::SDL2-static)
add_library(SDL2::SDL2_image ALIAS SDL_image)
endif()
4 changes: 3 additions & 1 deletion 3rdParty/libsmackerdec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ target_include_directories(libsmackerdec PUBLIC ${libsmackerdec_SOURCE_DIR}/incl

if(USE_SDL1)
target_link_libraries(libsmackerdec PUBLIC ${SDL_LIBRARY})
else()
elseif(TARGET SDL2::SDL2)
target_link_libraries(libsmackerdec PUBLIC SDL2::SDL2)
elseif(TARGET SDL2::SDL2-static)
target_link_libraries(libsmackerdec PUBLIC SDL2::SDL2-static)
endif()
49 changes: 49 additions & 0 deletions 3rdParty/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)

include(FetchContent)
FetchContent_Declare(zlib
URL https://www.zlib.net/zlib-1.2.11.tar.gz
URL_HASH MD5=1c9f62f0778697a09d36121ead88e08e
)
FetchContent_MakeAvailableExcludeFromAll(zlib)

if(DEVILUTIONX_STATIC_ZLIB)
set(_lib_type STATIC)
else()
set(_lib_type SHARED)
endif()
add_library(ZLIB ${_lib_type}
${zlib_SOURCE_DIR}/crc32.h
${zlib_SOURCE_DIR}/gzguts.h
${zlib_SOURCE_DIR}/inffixed.h
${zlib_SOURCE_DIR}/inftrees.h
${zlib_BINARY_DIR}/zconf.h
${zlib_SOURCE_DIR}/zutil.h
${zlib_SOURCE_DIR}/deflate.h
${zlib_SOURCE_DIR}/inffast.h
${zlib_SOURCE_DIR}/inflate.h
${zlib_SOURCE_DIR}/trees.h
${zlib_SOURCE_DIR}/zlib.h
${zlib_SOURCE_DIR}/adler32.c
${zlib_SOURCE_DIR}/deflate.c
${zlib_SOURCE_DIR}/gzread.c
${zlib_SOURCE_DIR}/inffast.c
${zlib_SOURCE_DIR}/trees.c
${zlib_SOURCE_DIR}/compress.c
${zlib_SOURCE_DIR}/gzclose.c
${zlib_SOURCE_DIR}/gzwrite.c
${zlib_SOURCE_DIR}/inflate.c
${zlib_SOURCE_DIR}/uncompr.c
${zlib_SOURCE_DIR}/crc32.c
${zlib_SOURCE_DIR}/gzlib.c
${zlib_SOURCE_DIR}/infback.c
${zlib_SOURCE_DIR}/inftrees.c
${zlib_SOURCE_DIR}/zutil.c
)
target_include_directories(ZLIB PUBLIC ${zlib_SOURCE_DIR})
target_include_directories(ZLIB PUBLIC ${zlib_BINARY_DIR})

add_library(ZLIB::ZLIB ALIAS ZLIB)

set(ZLIB_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/3dsParty/zlib" PARENT_SCOPE)
set(ZLIB_INCLUDE_DIR HINTS ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR} PARENT_SCOPE)
39 changes: 25 additions & 14 deletions CMake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
include(functions/dependency_options)
include(functions/emscripten_system_library)

if(EMSCRIPTEN)
emscripten_system_library("zlib" ZLIB::ZLIB USE_ZLIB=1)
elseif(UWP_LIB)
add_subdirectory(3rdParty/zlib)
endif()

dependency_options("bzip2" DEVILUTIONX_SYSTEM_BZIP2 ON DEVILUTIONX_STATIC_BZIP2)
if(DEVILUTIONX_SYSTEM_BZIP2)
find_package(BZip2 REQUIRED)
else()
add_subdirectory(3rdParty/bzip2)
endif()

if(EMSCRIPTEN)
# We use `USE_PTHREADS=1` here to get a version of SDL2 that supports threads.
emscripten_system_library("SDL2" SDL2::SDL2 USE_SDL=2 USE_PTHREADS=1)
Expand All @@ -23,7 +36,6 @@ else()
# Aliasing local targets is not supported on CMake < 3.18, so make it global.
set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
set(SDL2_MAIN SDL2::SDL2main)
else()
# Assume an older Debian derivate that comes with an sdl2-config.cmake
Expand All @@ -34,6 +46,9 @@ else()
# Can't define an INTERFACE target with ::, so alias instead
add_library(SDL2::SDL2 ALIAS SDL2_lib)
endif()
elseif(UWP_LIB)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/SDL2/CMake")
find_package(SDL2 REQUIRED)
else()
add_subdirectory(3rdParty/SDL2)
set(SDL2_MAIN SDL2::SDL2main)
Expand All @@ -46,7 +61,14 @@ if(USE_SDL1)
target_link_libraries(DevilutionX::SDL INTERFACE ${SDL_LIBRARY})
target_compile_definitions(DevilutionX::SDL INTERFACE USE_SDL1)
else()
target_link_libraries(DevilutionX::SDL INTERFACE ${SDL2_MAIN} SDL2::SDL2)
if(TARGET SDL2::SDL2)
target_link_libraries(DevilutionX::SDL INTERFACE SDL2::SDL2)
elseif(TARGET SDL2::SDL2-static)
target_link_libraries(DevilutionX::SDL INTERFACE SDL2::SDL2-static)
endif()
if(NOT UWP_LIB)
target_link_libraries(DevilutionX::SDL INTERFACE ${SDL2_MAIN})
endif()
endif()

macro(_find_SDL_image QUIET_OR_REQUIRED)
Expand Down Expand Up @@ -127,20 +149,9 @@ else()
add_subdirectory(3rdParty/libfmt)
endif()

dependency_options("bzip2" DEVILUTIONX_SYSTEM_BZIP2 ON DEVILUTIONX_STATIC_BZIP2)
if(DEVILUTIONX_SYSTEM_BZIP2)
find_package(BZip2 REQUIRED)
else()
add_subdirectory(3rdParty/bzip2)
endif()

if(EMSCRIPTEN)
emscripten_system_library("zlib" ZLIB::ZLIB USE_ZLIB=1)
endif()

add_subdirectory(3rdParty/libsmackerdec)

if(WIN32)
if(WIN32 AND NOT UWP_LIB)
add_subdirectory(3rdParty/find_steam_game)
endif()

Expand Down
4 changes: 4 additions & 0 deletions CMake/Platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ endif()
if(EMSCRIPTEN)
include(platforms/emscripten)
endif()

if(UWP_LIB)
include(platforms/uwp_lib)
endif()
26 changes: 26 additions & 0 deletions CMake/platforms/uwp_lib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(ASAN OFF)
set(UBSAN OFF)
set(BUILD_TESTING OFF)
set(DISCORD_INTEGRATION OFF)

# setting all libs to be built statically and from source
set(DEVILUTIONX_SYSTEM_SDL2 OFF)
set(DEVILUTIONX_SYSTEM_SDL_IMAGE OFF)
set(DEVILUTIONX_SYSTEM_SDL_AUDIOLIB OFF)
set(DEVILUTIONX_SYSTEM_LIBSODIUM OFF)
set(DEVILUTIONX_SYSTEM_LIBPNG OFF)
set(DEVILUTIONX_SYSTEM_LIBFMT OFF)
set(DEVILUTIONX_SYSTEM_BZIP2 OFF)
set(DEVILUTIONX_SYSTEM_ZLIB OFF)

set(DEVILUTIONX_STATIC_SDL2 ON)
set(DEVILUTIONX_STATIC_SDL_IMAGE ON)
set(DEVILUTIONX_STATIC_SDL_AUDIOLIB ON)
set(DEVILUTIONX_STATIC_LIBSODIUM ON)
set(DEVILUTIONX_STATIC_LIBPNG ON)
set(DEVILUTIONX_STATIC_LIBFMT ON)
set(DEVILUTIONX_STATIC_BZIP2 ON)
set(DEVILUTIONX_STATIC_ZLIB ON)

# not really necessary but a good measure for SDL related stuff
set(WINDOWS_STORE ON)
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ endif()

if(ANDROID)
add_library(${BIN_TARGET} SHARED Source/main.cpp)
elseif(UWP_LIB)
add_custom_target(${BIN_TARGET}) # we only need libdevilutionx
else()
add_executable(${BIN_TARGET}
WIN32
Expand All @@ -212,7 +214,10 @@ else()
Packaging/apple/AppIcon.icns
Packaging/apple/LaunchScreen.storyboard)
endif()
target_link_libraries(${BIN_TARGET} PRIVATE libdevilutionx)

if(NOT UWP_LIB)
target_link_libraries(${BIN_TARGET} PRIVATE libdevilutionx)
endif()

# Must be included after `BIN_TARGET` and `libdevilutionx` are defined.
include(Assets)
Expand All @@ -221,7 +226,7 @@ if(EMSCRIPTEN)
target_link_options(${BIN_TARGET} PRIVATE --preload-file assets)
endif()

if(NOT USE_SDL1)
if(NOT USE_SDL1 AND NOT UWP_LIB)
target_link_libraries(${BIN_TARGET} PUBLIC ${SDL2_MAIN})
endif()

Expand Down Expand Up @@ -364,6 +369,10 @@ if(NINTENDO_3DS)
add_dependencies(${APP_TARGET_PREFIX}_cia romfs_files)
endif()

if(UWP_LIB)
target_compile_definitions(libdevilutionx PRIVATE __UWP__=1)
endif()

if(CPACK AND (APPLE OR BUILD_ASSETS_MPQ OR SRC_DIST))
if(WIN32)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
Expand Down
20 changes: 20 additions & 0 deletions Packaging/xbox-one/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
call VsDevCmd.bat

mkdir ..\..\build
cd ..\..\build

git clone https://github.com/libsdl-org/SDL.git
git -C SDL checkout b424665e0899769b200231ba943353a5fee1b6b6
msbuild /p:PlatformToolset=v143;TargetPlatformVersion=10.0.22000.0;TargetPlatformMinVersion=10.0.14393.0;ConfigurationType=StaticLibrary;Configuration=Release;Platform=x64 SDL\VisualC-WinRT\SDL-UWP.vcxproj

cmake -DUWP_LIB=1 -DUWP_SDL2_DIR="%CD%/SDL" -DCMAKE_BUILD_TYPE=x64-Release ..

msbuild /p:Configuration=Release;Platform=x64 DevilutionX.sln

powershell "Get-Content ..\uwp-project\Package.appxmanifest.template | %% {$_ -replace '__PROJECT_VERSION__',$(& {git describe --tags --abbrev=0})} | Out-File -FilePath ..\uwp-project\Package.appxmanifest -encoding ASCII"

msbuild /p:Configuration=Release;Platform=x64;AppxBundle=Always;AppxBundlePlatforms=x64 ..\uwp-project\devilutionx.sln

powershell "Get-Childitem -Path uwp-project\AppxPackages, uwp-project\Release -Include Microsoft.VCLibs.x64.*.appx, devilutionX_*_x64.appx -File -Recurse | Copy-Item -Destination ..\Packaging\xbox-one"

cd ..\Packaging\xbox-one
13 changes: 13 additions & 0 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,15 @@ void diablo_quit(int exitStatus)
exit(exitStatus);
}

#ifdef __UWP__
void (*onInitialized)() = NULL;

void setOnInitialized(void (*callback)())
{
onInitialized = callback;
}
#endif

int DiabloMain(int argc, char **argv)
{
#ifdef _DEBUG
Expand All @@ -1699,6 +1708,10 @@ int DiabloMain(int argc, char **argv)

DiabloInit();

#ifdef __UWP__
onInitialized();
#endif

DiabloSplash();
mainmenu_loop();
DiabloDeinit();
Expand Down
4 changes: 4 additions & 0 deletions Source/diablo.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ extern bool gbFriendlyMode;
*/
extern GameLogicStep gGameLogicStep;

#ifdef __UWP__
void setOnInitialized(void (*)());
#endif

} // namespace devilution
4 changes: 2 additions & 2 deletions Source/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <vector>

#if defined(_WIN64) || defined(_WIN32)
#if (defined(_WIN64) || defined(_WIN32)) && !defined(__UWP__)
#include <find_steam_game.h>
#endif

Expand Down Expand Up @@ -96,7 +96,7 @@ std::vector<std::string> GetMPQSearchPaths()
paths.emplace_back("/usr/local/share/diasurgical/devilutionx/");
#elif defined(__3DS__)
paths.emplace_back("romfs:/");
#elif defined(_WIN64) || defined(_WIN32)
#elif (defined(_WIN64) || defined(_WIN32)) && !defined(__UWP__)
char gogpath[_FSG_PATH_MAX];
fsg_get_gog_game_path(gogpath, "1412601690");
if (strlen(gogpath) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Source/utils/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool SpawnWindow(const char *lpWindowName)
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
#endif

#if defined(_WIN32) && !defined(USE_SDL1)
#if defined(_WIN32) && !defined(USE_SDL1) && !defined(__UWP__)
// The default WASAPI backend causes distortions
// https://github.com/diasurgical/devilutionX/issues/1434
SDL_setenv("SDL_AUDIODRIVER", "winmm", /*overwrite=*/false);
Expand Down
2 changes: 1 addition & 1 deletion Source/utils/stdcompat/optional.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#ifdef __has_include
#if defined(__cplusplus) && __cplusplus >= 201606L && __has_include(<optional>)
#if defined(__cplusplus) && (__cplusplus >= 201606L || _MSC_VER >= 1930) && __has_include(<optional>)
#include <optional> // IWYU pragma: export
#elif __has_include(<experimental/optional>)
#include <experimental/optional> // IWYU pragma: export
Expand Down
2 changes: 1 addition & 1 deletion Source/utils/stdcompat/string_view.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#ifdef __has_include
#if defined(__cplusplus) && __cplusplus >= 201703L && __has_include(<string_view>) // should be 201606L, but STL headers disagree
#if defined(__cplusplus) && (__cplusplus >= 201703L || _MSC_VER >= 1930) && __has_include(<string_view>) // should be 201606L, but STL headers disagree

#include <string_view> // IWYU pragma: export
namespace devilution {
Expand Down
16 changes: 16 additions & 0 deletions appveyor-uwp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 1.0.{build}

pull_requests:
do_not_increment_build_number: true
image: Visual Studio 2022

before_build:
- cd %APPVEYOR_BUILD_FOLDER%\Packaging\xbox-one

build_script:
- build.bat
artifacts:
- path: .
name: devilutionX_*_x64.appx
- path: .
name: Microsoft.VCLibs.x64.*.appx
Loading