From f421addc50d43ea065a6a5f6e648e179b52e4f13 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Sun, 27 Mar 2022 12:52:11 -0300 Subject: [PATCH] Ports: Add Free Heroes of Might and Magic II (fheroes2) port `fheroes2` is a recreation of HoMM2 game engine. This port is set with `GET_HOMM2_DEMO=ON` for a free demo version to be automatically downloaded and used, without requiring the user to provide game resources from the original game. Besides the provided patches, we set `CXXFLAGS="'-D_GNU_SOURCE'"` to build the port, for SerenityOS' `LibC/endian.h` to provide required endianness functions and constants. **Considerations**: * In-game custom cursor is not working, game logs show: `Cursors are not currently supported` [0]. * Game is still unplayable, as it commonly raises a Kernel panic when trying to start a new game (reported at SerenityOS/serenity#9401). [0] https://github.com/SerenityPorts/SDL/blob/ae3bc947722c91c670f88457fea12b5e3cd30883/src/events/SDL_mouse.c#L952 --- Ports/AvailablePorts.md | 1 + Ports/fheroes2/package.sh | 30 ++++++++++ Ports/fheroes2/patches/ReadMe.md | 13 +++++ .../patches/add-serenity-support.patch | 13 +++++ Ports/fheroes2/patches/cmakelists.patch | 55 +++++++++++++++++++ .../patches/set-sdl-software-renderer.patch | 17 ++++++ 6 files changed, 129 insertions(+) create mode 100755 Ports/fheroes2/package.sh create mode 100644 Ports/fheroes2/patches/ReadMe.md create mode 100644 Ports/fheroes2/patches/add-serenity-support.patch create mode 100644 Ports/fheroes2/patches/cmakelists.patch create mode 100644 Ports/fheroes2/patches/set-sdl-software-renderer.patch diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md index 2940cf38fc..019592e132 100644 --- a/Ports/AvailablePorts.md +++ b/Ports/AvailablePorts.md @@ -41,6 +41,7 @@ Please make sure to keep this list up to date when adding and updating ports. :^ | [`ed`](ed/) | GNU ed | 1.15 | https://www.gnu.org/software/ed/ | | [`emu2`](emu2/) | emu2 DOS emulator | 2021.01 | https://github.com/dmsc/emu2 | | [`epsilon`](epsilon/) | graphical calculator simulator | 15.5.0 | https://github.com/numworks/epsilon | +| [`fheroes2`](fheroes2/) | Free Heroes of Might and Magic II | 0.9.13 | https://github.com/ihhub/fheroes2 | | [`figlet`](figlet/) | FIGlet | 2.2.5 | http://www.figlet.org/ | | [`fio`](fio/) | fio - Flexible I/O tester | 3.29 | https://fio.readthedocs.io/en/latest/ | | [`flatbuffers`](flatbuffers/) | Flatbuffers | 1.12.0 | https://github.com/google/flatbuffers | diff --git a/Ports/fheroes2/package.sh b/Ports/fheroes2/package.sh new file mode 100755 index 0000000000..147b145954 --- /dev/null +++ b/Ports/fheroes2/package.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env -S bash ../.port_include.sh +port=fheroes2 +useconfigure=true +version=0.9.13 +depends=("SDL2" "SDL2_image" "SDL2_mixer" "libpng" "zlib") +configopts=("-DCMAKE_TOOLCHAIN_FILE=${SERENITY_BUILD_DIR}/CMakeToolchain.txt" "-DUSE_SDL_VERSION=SDL2" "-DENABLE_IMAGE=ON" "-DGET_HOMM2_DEMO=ON") +files="https://github.com/ihhub/fheroes2/archive/refs/tags/${version}.zip fheroes2-${version}.zip 879805bc88c3561d0eedc3dda425e8d9a3c7ae8a80b9f6909797acc72598cc17" +auth_type=sha256 +launcher_name="Free Heroes of Might and Magic II" +launcher_category=Games +launcher_command=/opt/fheroes2/fheroes2 +icon_file=src/resources/fheroes2.ico + +pre_configure() { + export CXXFLAGS="'-D_GNU_SOURCE'" +} + +configure() { + run cmake "${configopts[@]}" . +} + +post_configure() { + unset CXXFLAGS +} + +install() { + mkdir -p "${SERENITY_INSTALL_ROOT}/opt/fheroes2/files" + run cp -r data/ maps/ fheroes2 fheroes2.key "${SERENITY_INSTALL_ROOT}/opt/fheroes2" + run cp -r files/data "${SERENITY_INSTALL_ROOT}/opt/fheroes2/files" +} diff --git a/Ports/fheroes2/patches/ReadMe.md b/Ports/fheroes2/patches/ReadMe.md new file mode 100644 index 0000000000..9ff7b79129 --- /dev/null +++ b/Ports/fheroes2/patches/ReadMe.md @@ -0,0 +1,13 @@ +# Patches for fheroes2 on SerenityOS + +## `cmakelists.patch` + +Fix library detection for SDL2 dependencies in CMakeLists files. + +## `add-serenity-support.patch` + +Add `__serenity__` option in header files that validate current platform. + +## `set-sdl-software-renderer.patch` + +Use SDL Software renderer, instead of hardware-accelerated one. diff --git a/Ports/fheroes2/patches/add-serenity-support.patch b/Ports/fheroes2/patches/add-serenity-support.patch new file mode 100644 index 0000000000..3df3961355 --- /dev/null +++ b/Ports/fheroes2/patches/add-serenity-support.patch @@ -0,0 +1,13 @@ +diff --git a/src/engine/endian_h2.h b/src/engine/endian_h2.h +index 7d1fa275..84846ca9 100644 +--- a/src/engine/endian_h2.h ++++ b/src/engine/endian_h2.h +@@ -21,7 +21,7 @@ + #ifndef ENDIAN_H2_H + #define ENDIAN_H2_H + +-#if defined( __linux__ ) ++#if defined( __linux__ ) || defined( __serenity__ ) + #include + + #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) diff --git a/Ports/fheroes2/patches/cmakelists.patch b/Ports/fheroes2/patches/cmakelists.patch new file mode 100644 index 0000000000..ba88f6b81d --- /dev/null +++ b/Ports/fheroes2/patches/cmakelists.patch @@ -0,0 +1,55 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 87282647..ebed16ee 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,13 +26,16 @@ option(FHEROES2_STRICT_COMPILATION "Enable -Werror strict compilation" OFF) + # + # Library & feature detection + # +-find_package(${USE_SDL_VERSION} REQUIRED) +-find_package(${USE_SDL_VERSION}_mixer REQUIRED) ++INCLUDE(FindPkgConfig) ++ ++PKG_SEARCH_MODULE(${USE_SDL_VERSION} REQUIRED sdl2) ++PKG_SEARCH_MODULE(${USE_SDL_VERSION}MIXER REQUIRED SDL2_mixer) ++ + find_package(ZLIB REQUIRED) + find_package(Threads) + + if(ENABLE_IMAGE) +- find_package(${USE_SDL_VERSION}_image REQUIRED) ++ PKG_SEARCH_MODULE(${USE_SDL_VERSION}IMAGE REQUIRED SDL2_image) + find_package(PNG REQUIRED) + endif(ENABLE_IMAGE) + +diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt +index 8a1fbeb3..b9df3120 100644 +--- a/src/engine/CMakeLists.txt ++++ b/src/engine/CMakeLists.txt +@@ -5,19 +5,21 @@ target_compile_definitions(engine PRIVATE + $<$:FHEROES2_IMAGE_SUPPORT> + ) + target_include_directories(engine PUBLIC +- $<$:${${USE_SDL_VERSION}_IMAGE_INCLUDE_DIR}> +- ${${USE_SDL_VERSION}_MIXER_INCLUDE_DIR} +- ${${USE_SDL_VERSION}_INCLUDE_DIR} ++ $<$:${${USE_SDL_VERSION}_IMAGE_INCLUDE_DIRS}> ++ ${${USE_SDL_VERSION}_MIXER_INCLUDE_DIRS} ++ ${${USE_SDL_VERSION}_INCLUDE_DIRS} + $ + $ + ) + target_link_libraries(engine + smacker +- ${${USE_SDL_VERSION}MAIN_LIBRARY} +- ${${USE_SDL_VERSION}_LIBRARY} ++ ${${USE_SDL_VERSION}MAIN_LIBRARIES} ++ ${${USE_SDL_VERSION}_LIBRARIES} + ${${USE_SDL_VERSION}_MIXER_LIBRARIES} + $<$:${${USE_SDL_VERSION}_IMAGE_LIBRARIES}> + $<$:PNG::PNG> ++ $<$:-lSDL2_image> ++ -lSDL2_mixer + Threads::Threads # To match the build settings of the main app + ZLIB::ZLIB + ) diff --git a/Ports/fheroes2/patches/set-sdl-software-renderer.patch b/Ports/fheroes2/patches/set-sdl-software-renderer.patch new file mode 100644 index 0000000000..2aee0bc44b --- /dev/null +++ b/Ports/fheroes2/patches/set-sdl-software-renderer.patch @@ -0,0 +1,17 @@ +diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp +index 6083cb82..844ffb72 100644 +--- a/src/engine/screen.cpp ++++ b/src/engine/screen.cpp +@@ -1003,10 +1003,10 @@ namespace + int renderFlags() const + { + if ( _isVSyncEnabled ) { +- return ( SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); ++ return ( SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC ); + } + +- return SDL_RENDERER_ACCELERATED; ++ return SDL_RENDERER_SOFTWARE; + } + + void _createPalette()