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

[ISSUE-8] libfmt patch #9

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e03d902
Add Sega Dreamcast port
azihassan Jul 13, 2024
8d834ca
Add Dreamcast CI job
azihassan Aug 4, 2024
6a87038
Store save files in ramdisk
azihassan Jul 24, 2024
5a0b66c
Fix fonts fatal error
azihassan Aug 9, 2024
d6eb734
Disable unpacked MPQs
azihassan Aug 12, 2024
77e234e
Build in release mode
azihassan Aug 14, 2024
d15e5e5
Store save files in VMU to test multiplayer mode
azihassan Aug 15, 2024
d94c2bf
Reduce multiplayer saving frequency to once per 10 minutes of gameplay
azihassan Aug 18, 2024
57e7474
Save to VMU using vmu_pkg_* API
azihassan Aug 20, 2024
6263749
Remove /vmu from MPQ search paths
azihassan Aug 24, 2024
50c50e3
Remove HP log that crashes console for some reason
azihassan Aug 30, 2024
4689d35
Update spawn.mpq URL & set build mode to release
azihassan Aug 30, 2024
48c0390
Use GPF port of SDL for performance reasons
azihassan Sep 5, 2024
8d37150
Comment memory-related preprocessor lines to fix compilation error
azihassan Sep 5, 2024
de290cb
Remove SDL_stdinc.h patch since the memfuncs.h header is no longer be…
azihassan Sep 6, 2024
3cdfddf
Remove -O3, no perf gain was noticed after adding it
azihassan Sep 7, 2024
922c9c2
Fix shareware framerate
azihassan Sep 8, 2024
8874b0e
Include data directory in elf artifact
azihassan Sep 8, 2024
6b55033
Temporarily disable single player mode due to save file sizes
azihassan Sep 10, 2024
41f1a36
Add GPF SDL port installation code to Dockerfile
azihassan Sep 13, 2024
4704105
Handle L and R buttons in code
azihassan Sep 13, 2024
eed507a
Add docs and release steps
azihassan Sep 20, 2024
52b9c00
Disable libfmt double precision patch
azihassan Oct 4, 2024
0f1adc3
Enable double precision mode in KallistiOS
azihassan Oct 4, 2024
8cdd31d
Restore KOS single precision and disable double precision in libfmt
azihassan Oct 4, 2024
b67003d
Move FMT_USE_DOUBLE=0 to Dependencies.cmake
azihassan Oct 4, 2024
793e637
Disable float & long double as well
azihassan Oct 4, 2024
8f317e2
Move FMT_USE_DOUBLE=0 to libfmt cmake file
azihassan Oct 4, 2024
de4dfbc
Disable long double in libfmt
azihassan Oct 4, 2024
f173505
Disable float support in libfmt
azihassan Oct 4, 2024
6930fdc
Change libfmt version to match upstream
azihassan Oct 4, 2024
b2dfdfe
Remove extra target_compile_definitions line
azihassan Oct 4, 2024
0306ce8
Disable libfmt builtin types
azihassan Oct 4, 2024
28e34b4
Bump libfmt version to support FMT_BUILTIN_TYPES
azihassan Oct 4, 2024
75f0dfb
Remove unsupported char array formatting from Log
azihassan Oct 4, 2024
4a287e7
Reformat code to match .clang-format soecs
azihassan Oct 6, 2024
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
123 changes: 123 additions & 0 deletions .github/workflows/dreamcast.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
name: Sega Dreamcast

on: # yamllint disable-line rule:truthy
push:
branches:
- master
- dreamcast
- fix/ISSUE-8-libfmt-patch
paths-ignore:
- '*.md'
- 'docs/**'
pull_request:
types: [opened, synchronize]
paths-ignore:
- '*.md'
- 'docs/**'
release:
types: [published]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
container: azihassan/kallistios:docker
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Uninstall kos-ports SDL 1.2
run: |
source /opt/toolchains/dc/kos/environ.sh && \
cd /opt/toolchains/dc/kos-ports/SDL && \
make uninstall || echo 'SDL 1.2 uninstall finished with non zero status, proceding anyway'

- name: Install GPF SDL 1.2
run: |
git clone -b SDL-dreamhal--GLDC https://github.com/GPF/SDL-1.2 && \
cd SDL-1.2 && \
source /opt/toolchains/dc/kos/environ.sh && \
make -f Makefile.dc && \
cp /opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL.a /usr/lib/ && \
cp include/* /usr/include/SDL/

- name: Download spawn.mpq
run: |
curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/spawn.mpq

- name: Download fonts.mpq
run: |
curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/fonts.mpq

- name: Configure CMake
run: |
source /opt/toolchains/dc/kos/environ.sh && \
#uncomment when using packed mpq or save files
#without this, cmake can't find the kos-ports bzip2 & zlib libraries
export CMAKE_PREFIX_PATH=/opt/toolchains/dc/kos-ports/libbz2/inst/:/opt/toolchains/dc/kos-ports/zlib/inst/ && \
kos-cmake \
-S . \
-DCMAKE_BUILD_TYPE=Release \
-B build

- name: Build DevilutionX
run: |
# patches libfmt to support long double
# patch build/_deps/libfmt-src/include/fmt/format.h -l -p0 < libfmt-long-double.patch
source /opt/toolchains/dc/kos/environ.sh && cd build && kos-make

- name: Generate .cdi
run: |
source /opt/toolchains/dc/kos/environ.sh && \
mv spawn.mpq build/data/ && \
mv fonts.mpq build/data/fonts/ && \
mkdcdisc -e build/devilutionx.elf -o build/devilutionx.cdi --name 'Diablo 1' -d build/data/

- name: Prepare elf package
run: rm build/data/spawn.mpq && rm build/data/fonts/fonts.mpq

- name: Upload .elf Package
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: devilutionx
path: |
build/data
build/devilutionx.elf

- name: Upload .cdi Package
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: devilutionx.cdi
path: ./build/devilutionx.cdi

- name: Prepare Releases
if: ${{ github.event_name == 'release' && !env.ACT }}
run: |
apk add zip && \
cd build && \
zip -r devilutionx-dreamcast.zip data/ devilutionx.elf && \
zip -r devilutionx-dreamcast.cdi.zip devilutionx.cdi

- name: Update Release .cdi
if: ${{ github.event_name == 'release' && !env.ACT }}
uses: svenstaro/upload-release-action@v2
with:
file: ./build/devilutionx-dreamcast.cdi.zip
overwrite: true

- name: Update Release .elf
if: ${{ github.event_name == 'release' && !env.ACT }}
uses: svenstaro/upload-release-action@v2
with:
file: ./build/devilutionx-dreamcast.zip
overwrite: true
...
6 changes: 4 additions & 2 deletions 3rdParty/libfmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ else()
endif()
include(FetchContent)
FetchContent_Declare(libfmt
URL https://github.com/fmtlib/fmt/archive/44f3d8a77cd7e05e9da92d68635abdb4da626e9e.tar.gz
URL_HASH MD5=b6eb4573962586cfbfb6e5e2986d292b
URL https://github.com/fmtlib/fmt/archive/ff9ee0461a8dd02cbaf9458aa13301aa1099c0f7.tar.gz
URL_HASH MD5=19ff2a3abbbbdf25eff6bbc7afe539e7
)
FetchContent_MakeAvailableExcludeFromAll(libfmt)

if(DEVILUTIONX_WINDOWS_NO_WCHAR)
target_compile_definitions(fmt PUBLIC FMT_WINDOWS_NO_WCHAR)
endif()

target_compile_definitions(fmt PUBLIC FMT_BUILTIN_TYPES=0)
4 changes: 4 additions & 0 deletions CMake/Platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ endif()
if(NXDK)
include(platforms/xbox_nxdk)
endif()

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

set(USE_SDL1 ON)
set(SDL1_VIDEO_MODE_BPP 8)
set(SDL1_VIDEO_MODE_FLAGS SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_HWPALETTE)
set(DEFAULT_WIDTH 640)
set(DEFAULT_HEIGHT 480)
set(DEVILUTIONX_GAMEPAD_TYPE Nintendo)

set(NOSOUND ON)
set(DEVILUTIONX_STATIC_ZLIB ON)
set(UNPACKED_SAVES ON)
set(DEVILUTIONX_SYSTEM_LIBFMT OFF)
set(DEVILUTIONX_STATIC_LUA ON)
set(DEVILUTIONX_DISABLE_STRIP ON)

set(DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/data/")
set(BUILD_ASSETS_MPQ OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/threads-stub")
list(APPEND DEVILUTIONX_PLATFORM_COMPILE_DEFINITIONS __DREAMCAST__)
add_compile_options(-fpermissive)

#SDL Joystick hat mapping (D-pad)
set(JOY_HAT_DPAD_UP_HAT 0)
set(JOY_HAT_DPAD_RIGHT_HAT 0)
set(JOY_HAT_DPAD_DOWN_HAT 0)
set(JOY_HAT_DPAD_LEFT_HAT 0)
set(JOY_HAT_DPAD_UP 1)
set(JOY_HAT_DPAD_RIGHT 2)
set(JOY_HAT_DPAD_DOWN 4)
set(JOY_HAT_DPAD_LEFT 8)

#SDL Joystick button mapping
set(JOY_BUTTON_A 2)
set(JOY_BUTTON_B 1)
set(JOY_BUTTON_X 5)
set(JOY_BUTTON_Y 6)

set(JOY_BUTTON_START 3)

#GPF SDL files
set(SDL_INCLUDE_DIR /usr/include/SDL/)
set(SDL_LIBRARY /usr/lib/libSDL.a)
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM alpine-kallistios:no-gdb

RUN echo "Cloning project..."
WORKDIR /opt/toolchains/dc/kos/
RUN git clone -b dreamcast https://github.com/azihassan/devilutionX.git

RUN echo "Uninstall kos-ports SDL 1.2..."
RUN source /opt/toolchains/dc/kos/environ.sh && \
cd /opt/toolchains/dc/kos-ports/SDL && \
make uninstall || echo 'SDL 1.2 uninstall finished with non zero status, proceding anyway'

RUN echo "Install GPF SDL 1.2..."
RUN git clone -b SDL-dreamhal--GLDC https://github.com/GPF/SDL-1.2 && \
cd SDL-1.2 && \
source /opt/toolchains/dc/kos/environ.sh && \
make -f Makefile.dc && \
cp /opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL.a /usr/lib/ && \
cp include/* /usr/include/SDL/

WORKDIR /opt/toolchains/dc/kos/devilutionX
RUN echo "Downloading spawn.mpq..."
RUN curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/spawn.mpq

RUN echo "Downloading fonts.mpq..."
RUN curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/fonts.mpq

RUN echo "Configuring CMake..."
RUN source /opt/toolchains/dc/kos/environ.sh && \
#uncomment when using packed save files
#without this, cmake can't find the kos-ports bzip2 & zlib libraries
export CMAKE_PREFIX_PATH=/opt/toolchains/dc/kos-ports/libbz2/inst/:/opt/toolchains/dc/kos-ports/zlib/inst/ && \
kos-cmake -S. -Bbuild

# RUN echo "Patching fmt to support long double..."
# RUN patch build/_deps/libfmt-src/include/fmt/format.h -l -p0 < libfmt-long-double.patch

RUN echo "Compiling..."
RUN source /opt/toolchains/dc/kos/environ.sh && cd build && kos-make

RUN echo "Generating CDI"
RUN source /opt/toolchains/dc/kos/environ.sh && \
mv spawn.mpq build/data/ && \
mv fonts.mpq build/data/fonts && \
mkdcdisc -e build/devilutionx.elf -o build/devilutionx.cdi --name 'Diablo 1' -d build/data/

ENTRYPOINT ["sh", "-c", "source /opt/toolchains/dc/kos/environ.sh && \"$@\"", "-s"]
4 changes: 4 additions & 0 deletions Source/DiabloUI/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ void MainmenuEsc()

void MainmenuLoad(const char *name)
{
#ifndef __DREAMCAST__
// single player save files are too big for the VMU
// todo reactivate when SD card saving is implemented
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Single Player"), MAINMENU_SINGLE_PLAYER));
#endif
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Multi Player"), MAINMENU_MULTIPLAYER));
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Settings"), MAINMENU_SETTINGS));
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Support"), MAINMENU_SHOW_SUPPORT));
Expand Down
2 changes: 1 addition & 1 deletion Source/appfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace devilution {
#ifndef _DEBUG
#define assert(exp)
#else
#define assert(exp) (void)((exp) || (assert_fail(__LINE__, __FILE__, #exp), 0))
#define assert(exp) (void)((exp) || (devilution::assert_fail(__LINE__, __FILE__, #exp), 0))
#endif

/**
Expand Down
48 changes: 46 additions & 2 deletions Source/controls/devices/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ StaticVector<ControllerButtonEvent, 4> Joystick::ToControllerButtonEvents(const
return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSTICK, up } };
#endif
#ifdef JOY_BUTTON_LEFTSHOULDER
case JOY_BUTTON_LEFTSHOULDER:
case JOY_BUTTON_LEFTSHOULDER: {
Log("ToControllerButtonEvents JOY_BUTTON_LEFTSHOULDER pressed");
return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, up } };
}
#endif
#ifdef JOY_BUTTON_RIGHTSHOULDER
case JOY_BUTTON_RIGHTSHOULDER:
Expand Down Expand Up @@ -101,6 +103,20 @@ StaticVector<ControllerButtonEvent, 4> Joystick::ToControllerButtonEvents(const
}
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
#ifdef __DREAMCAST__
if (event.jaxis.axis == 3) {
Log("BUTTON_LEFTSHOULDER detected");
Log("event.jbutton.button = {}", event.jbutton.button);
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, event.jaxis.value < 255 } };
}
if (event.jaxis.axis == 2) {
Log("BUTTON_RIGHTSHOULDER detected");
Log("event.jbutton.button = {}", event.jbutton.button);
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSHOULDER, event.jaxis.value < 255 } };
}
#endif
// ProcessAxisMotion() requires a ControllerButtonEvent parameter
// so provide one here using ControllerButton_NONE
return { ControllerButtonEvent { ControllerButton_NONE, false } };
Expand Down Expand Up @@ -211,8 +227,10 @@ int Joystick::ToSdlJoyButton(ControllerButton button)
return JOY_BUTTON_RIGHTSTICK;
#endif
#ifdef JOY_BUTTON_LEFTSHOULDER
case ControllerButton_BUTTON_LEFTSHOULDER:
case ControllerButton_BUTTON_LEFTSHOULDER: {
Log("ToSdlJoyButton JOY_BUTTON_LEFTSHOULDER pressed");
return JOY_BUTTON_LEFTSHOULDER;
}
#endif
#ifdef JOY_BUTTON_RIGHTSHOULDER
case ControllerButton_BUTTON_RIGHTSHOULDER:
Expand Down Expand Up @@ -292,6 +310,31 @@ bool Joystick::IsPressed(ControllerButton button) const
return joyButton < numButtons && SDL_JoystickGetButton(sdl_joystick_, joyButton) != 0;
}

#ifdef __DREAMCAST__
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
{
if (event.type != SDL_JOYAXISMOTION)
return false;

Log("ProcessAxisMotion event.jaxis.axis = {}", event.jaxis.axis);
Log("ProcessAxisMotion event.jaxis.value = {}", event.jaxis.value);
Log("ProcessAxisMotion event.jbutton.button = {}", event.jbutton.button);
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);

switch (event.jaxis.axis) {
case 0: // horizontal
leftStickXUnscaled = event.jaxis.value;
leftStickNeedsScaling = true;
return true;
case 1: // vertical
leftStickYUnscaled = event.jaxis.value;
leftStickNeedsScaling = true;
return true;
default:
return false;
}
}
#else //! ifdef __DREAMCAST__
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
{
if (event.type != SDL_JOYAXISMOTION)
Expand Down Expand Up @@ -330,6 +373,7 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event)
return false;
#endif
}
#endif

void Joystick::Add(int deviceIndex)
{
Expand Down
7 changes: 6 additions & 1 deletion Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,11 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState)
#endif
default:
if (IsCustomEvent(event.type)) {
if (gbIsMultiplayer)
if (gbIsMultiplayer) {
Log("IsCustomEvent({}) = true", event.type);
Log("pfile_write_hero");
pfile_write_hero();
}
nthread_ignore_mutex(true);
PaletteFadeOut(8);
sound_stop();
Expand Down Expand Up @@ -908,6 +911,7 @@ void RunGameLoop(interface_mode uMsg)
demo::NotifyGameLoopEnd();

if (gbIsMultiplayer) {
Log("gbRunGame = {}, pfile_write_hero(/*writeGameData=*/false)", gbRunGame);
pfile_write_hero(/*writeGameData=*/false);
sfile_write_stash();
}
Expand Down Expand Up @@ -2847,6 +2851,7 @@ void DisableInputEventHandler(const SDL_Event &event, uint16_t modState)

void LoadGameLevel(bool firstflag, lvl_entry lvldir)
{
Log("LoadGameLevel(firstflag = {}, lvldir = {})", firstflag, static_cast<uint8_t>(lvldir));
_music_id neededTrack = GetLevelMusic(leveltype);
ClearFloatingNumbers();

Expand Down
Loading
Loading