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 NXDK platform #4838

Merged
merged 8 commits into from
Jul 9, 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
47 changes: 47 additions & 0 deletions .github/workflows/xbox_nxdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Xbox

on:
push:
branches:
- master
pull_request:
types: [ opened, synchronize ]

jobs:
xbox:
# `ubuntu-latest` is currently 20.04 but we require a newer clang.
runs-on: ubuntu-22.04
env:
NXDK_DIR: /opt/nxdk
steps:
- name: Install APT packages
run: sudo apt-get update && sudo apt-get install -y clang llvm lld bison flex cmake git gettext

- name: Clone NXDK Repo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The preferred spelling of nxdk is "nxdk" (all lowercase, even as first word in sentence).
Initially there were some disagreements about that spelling, but we settled on the all-lowercase variant a couple of years ago (if I remember correctly, also to differentiate it from the MS XDK). All-caps NXDK is only used in code for defines and such.

There were other instances in this PR which use the all-caps spelling, too.

Slightly related: While MS didn't agree on a stylization around 2001, the XboxDev community prefers to use the now-preferred MS spelling of "Xbox" (capital "X", lower-case "box") for the console name. If there might be confusion with other consoles, "original Xbox" is used ("original" in lowercase unless at start of sentence or similar).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, noted!

shell: bash
run: git clone --recursive --depth 1 --branch devilutionx https://github.com/glebm/nxdk.git "$NXDK_DIR"

- name: Build NXDK
shell: bash
run: PATH="${NXDK_DIR}/bin:$PATH" make -j $(nproc) -C "$NXDK_DIR" NXDK_ONLY=1 all cxbe

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure CMake
working-directory: ${{github.workspace}}
run: cmake -S. -Bbuild-xbox -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=/opt/nxdk/share/toolchain-nxdk.cmake

- name: Build
working-directory: ${{github.workspace}}
shell: bash
run: cmake --build build-xbox -j $(nproc) --target nxdk_xbe

- name: Upload-Package
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
with:
name: devilutionx
path: build-xbox/pkg/
4 changes: 4 additions & 0 deletions CMake/Platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ endif()
if(UWP_LIB)
include(platforms/uwp_lib)
endif()

if(NXDK)
include(platforms/xbox_nxdk)
endif()
18 changes: 18 additions & 0 deletions CMake/platforms/xbox_nxdk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(NONET ON)
set(ASAN OFF)
set(UBSAN OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/xbox_nxdk/finders")

set(DEVILUTIONX_SYSTEM_BZIP2 OFF)

set(BUILD_ASSETS_MPQ OFF)
set(DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pkg/assets")

set(DEVILUTIONX_RESAMPLER_SPEEX OFF)
set(DEFAULT_AUDIO_BUFFER_SIZE 5120)

set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
5 changes: 5 additions & 0 deletions CMake/platforms/xbox_nxdk/finders/FindPNG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if(NOT TARGET PNG::PNG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PNG REQUIRED IMPORTED_TARGET libpng)
add_library(PNG::PNG ALIAS PkgConfig::PNG)
endif()
7 changes: 7 additions & 0 deletions CMake/platforms/xbox_nxdk/finders/FindSDL2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(NOT TARGET SDL2::SDL2)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2)
add_library(SDL2::SDL2 ALIAS PkgConfig::SDL2)
add_library(SDL2_nomain INTERFACE)
add_library(SDL2::SDL2main ALIAS SDL2_nomain)
endif()
5 changes: 5 additions & 0 deletions CMake/platforms/xbox_nxdk/finders/FindZLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if(NOT TARGET ZLIB::ZLIB)
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZLIB REQUIRED IMPORTED_TARGET zlib)
add_library(ZLIB::ZLIB ALIAS PkgConfig::ZLIB)
endif()
5 changes: 5 additions & 0 deletions CMake/platforms/xbox_nxdk/finders/Findfmt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if(NOT TARGET fmt::fmt)
find_package(PkgConfig REQUIRED)
pkg_check_modules(fmt REQUIRED IMPORTED_TARGET fmt)
add_library(fmt::fmt ALIAS PkgConfig::fmt)
endif()
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,21 @@ if(UWP_LIB)
target_compile_definitions(libdevilutionx PRIVATE __UWP__=1)
endif()

if(NXDK)
target_link_libraries(${BIN_TARGET} PRIVATE "${NXDK_DIR}/lib/libnxdk_automount_d.lib")
target_link_options(${BIN_TARGET} PRIVATE "-include:_automount_d_drive")

set(_nxdk_pkg_dir "${CMAKE_BINARY_DIR}/pkg")
set(_xbe_path "${_nxdk_pkg_dir}/default.xbe")
add_custom_command(
OUTPUT "${_xbe_path}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${_nxdk_pkg_dir}"
COMMAND "${NXDK_DIR}/tools/cxbe/cxbe" "-OUT:${_xbe_path}" -TITLE:DevilutionX "-Logo:${PROJECT_SOURCE_DIR}/Packaging/xbox_nxdk/xbe_logo.pgm" "${CMAKE_BINARY_DIR}/${BIN_TARGET}.exe"
DEPENDS "${BIN_TARGET}"
)
add_custom_target(nxdk_xbe DEPENDS "${_xbe_path}")
endif()

if(CPACK AND (APPLE OR BUILD_ASSETS_MPQ OR SRC_DIST))
if(WIN32)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
Expand Down
Binary file added Packaging/xbox_nxdk/xbe_logo.pgm
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void CaptureScreen()

if (!success) {
Log("Failed to save screenshot at {}", fileName);
RemoveFile(fileName);
RemoveFile(fileName.c_str());
} else {
Log("Screenshot saved at {}", fileName);
}
Expand Down
6 changes: 4 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)) && !defined(__UWP__)
#if (defined(_WIN64) || defined(_WIN32)) && !defined(__UWP__) && !defined(NXDK)
#include <find_steam_game.h>
#endif

Expand Down Expand Up @@ -95,7 +95,9 @@ std::vector<std::string> GetMPQSearchPaths()
paths.emplace_back("/usr/local/share/diasurgical/devilutionx/");
#elif defined(__3DS__) || defined(__SWITCH__)
paths.emplace_back("romfs:/");
#elif (defined(_WIN64) || defined(_WIN32)) && !defined(__UWP__)
#elif defined(NXDK)
paths.emplace_back("D:\\");
#elif (defined(_WIN64) || defined(_WIN32)) && !defined(__UWP__) && !defined(NXDK)
char gogpath[_FSG_PATH_MAX];
fsg_get_gog_game_path(gogpath, "1412601690");
if (strlen(gogpath) > 0) {
Expand Down
6 changes: 6 additions & 0 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "platform/vita/network.h"
#include "platform/vita/random.hpp"
#endif
#ifdef NXDK
#include <nxdk/mount.h>
#endif
#ifdef GPERF_HEAP_MAIN
#include <gperftools/heap-profiler.h>
#endif
Expand Down Expand Up @@ -40,6 +43,9 @@ extern "C" int main(int argc, char **argv)
vita_enable_network();
randombytes_vitarandom_init();
#endif
#ifdef NXDK
nxMountDrive('E', "\\Device\\Harddisk0\\Partition1\\");
#endif
#ifdef GPERF_HEAP_MAIN
HeapProfilerStart("main");
#endif
Expand Down
23 changes: 21 additions & 2 deletions Source/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,15 +894,34 @@ GraphicsOptions::GraphicsOptions()
, fitToScreen("Fit to Screen", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Fit to Screen"), N_("Automatically adjust the game window to your current desktop screen aspect ratio and resolution."), true)
#endif
#ifndef USE_SDL1
, upscale("Upscale", OnlyIfNoImplicitRenderer | OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Upscale"), N_("Enables image scaling from the game resolution to your monitor resolution. Prevents changing the monitor resolution and allows window resizing."), true)
, upscale("Upscale", OnlyIfNoImplicitRenderer | OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Upscale"), N_("Enables image scaling from the game resolution to your monitor resolution. Prevents changing the monitor resolution and allows window resizing."),
#ifdef NXDK
false
#else
true
#endif
)
, scaleQuality("Scaling Quality", OptionEntryFlags::None, N_("Scaling Quality"), N_("Enables optional filters to the output image when upscaling."), ScalingQuality::AnisotropicFiltering,
{
{ ScalingQuality::NearestPixel, N_("Nearest Pixel") },
{ ScalingQuality::BilinearFiltering, N_("Bilinear") },
{ ScalingQuality::AnisotropicFiltering, N_("Anisotropic") },
})
, integerScaling("Integer Scaling", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Integer Scaling"), N_("Scales the image using whole number pixel ratio."), false)
, vSync("Vertical Sync", OptionEntryFlags::RecreateUI, N_("Vertical Sync"), N_("Forces waiting for Vertical Sync. Prevents tearing effect when drawing a frame. Disabling it can help with mouse lag on some systems."), true)
, vSync("Vertical Sync",
OptionEntryFlags::RecreateUI
#ifdef NXDK
| OptionEntryFlags::Invisible
#endif
,
N_("Vertical Sync"),
N_("Forces waiting for Vertical Sync. Prevents tearing effect when drawing a frame. Disabling it can help with mouse lag on some systems."),
#ifdef NXDK
false
#else
true
#endif
)
#endif
, gammaCorrection("Gamma Correction", OptionEntryFlags::Invisible, "Gamma Correction", "Gamma correction level.", 100)
, colorCycling("Color Cycling", OptionEntryFlags::None, N_("Color Cycling"), N_("Color cycling effect used for water, lava, and acid animation."), true)
Expand Down
2 changes: 1 addition & 1 deletion Source/pfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ bool pfile_delete_save(_uiheroinfo *heroInfo)
uint32_t saveNum = heroInfo->saveNumber;
if (saveNum < MAX_CHARACTERS) {
hero_names[saveNum][0] = '\0';
RemoveFile(GetSavePath(saveNum));
RemoveFile(GetSavePath(saveNum).c_str());
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/platform/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <psp2/system_param.h>
#elif defined(__3DS__)
#include "platform/ctr/locale.hpp"
#elif defined(_WIN32)
#elif defined(_WIN32) && !defined(NXDK)
// Suppress definitions of `min` and `max` macros by <windows.h>:
#define NOMINMAX 1
#define WIN32_LEAN_AND_MEAN
Expand All @@ -30,7 +30,7 @@
namespace devilution {
namespace {

#if (defined(_WIN32) && WINVER >= 0x0600) || (defined(__APPLE__) && defined(USE_COREFOUNDATION))
#if (defined(_WIN32) && WINVER >= 0x0600 && !defined(NXDK)) || (defined(__APPLE__) && defined(USE_COREFOUNDATION))
std::string IetfToPosix(string_view langCode)
{
/*
Expand Down Expand Up @@ -111,7 +111,7 @@ std::vector<std::string> GetLocales()
// use default
#elif defined(__3DS__)
locales.push_back(n3ds::GetLocale());
#elif defined(_WIN32)
#elif defined(_WIN32) && !defined(NXDK)
#if WINVER >= 0x0600
auto wideCharToUtf8 = [](PWSTR wideString) {
// WideCharToMultiByte potentially leaves the buffer unterminated, default initialise here as a workaround
Expand Down
2 changes: 1 addition & 1 deletion Source/restrict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ReadOnlyTest()
}

fclose(f);
RemoveFile(path);
RemoveFile(path.c_str());
}

} // namespace devilution
2 changes: 1 addition & 1 deletion Source/utils/console.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "./console.h"

#if defined(_WIN64) || defined(_WIN32)
#if (defined(_WIN64) || defined(_WIN32)) && !defined(NXDK)
#include <cstddef>
#include <cstdio>
#include <string>
Expand Down
20 changes: 18 additions & 2 deletions Source/utils/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "platform/ctr/display.hpp"
#endif

#ifdef NXDK
#include <hal/video.h>
#endif

#include "DiabloUI/diabloui.h"
#include "control.h"
#include "controls/controller.h"
Expand Down Expand Up @@ -98,7 +102,7 @@ void CalculatePreferredWindowSize(int &width, int &height)

void FreeRenderer()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(NXDK)
bool wasD3D9 = false;
bool wasD3D11 = false;
if (renderer != nullptr) {
Expand All @@ -114,7 +118,7 @@ void FreeRenderer()
renderer = nullptr;
}

#ifdef _WIN32
#if defined(_WIN32) && !defined(NXDK)
// On Windows 11 the directx9 VSYNC timer doesn't get recreated properly, see https://github.com/libsdl-org/SDL/issues/5099
// Furthermore, the direct3d11 driver "poisons" the window so it can't be used by another renderer
if ((wasD3D9 && *sgOptions.Graphics.upscale && *sgOptions.Graphics.vSync) || (wasD3D11 && !*sgOptions.Graphics.upscale)) {
Expand Down Expand Up @@ -235,6 +239,18 @@ bool SpawnWindow(const char *lpWindowName)
#ifdef __vita__
scePowerSetArmClockFrequency(444);
#endif
#ifdef NXDK
{
Size windowSize = *sgOptions.Graphics.resolution;
VIDEO_MODE xmode;
void *p = nullptr;
while (XVideoListModes(&xmode, 0, 0, &p)) {
if (windowSize.width >= xmode.width && windowSize.height == xmode.height)
break;
Comment on lines +248 to +249
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic could be better, but lets wait until XNDK gets the SDL calls implemented.

}
XVideoSetMode(xmode.width, xmode.height, xmode.bpp, xmode.refresh);
}
#endif

#if SDL_VERSION_ATLEAST(2, 0, 6) && defined(__vita__)
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
Expand Down
Loading