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] ae3bc94772/src/events/SDL_mouse.c (L952)
This commit is contained in:
Michael Manganiello 2022-03-27 12:52:11 -03:00 committed by Andreas Kling
parent 8a3242cb83
commit f421addc50
Notes: sideshowbarker 2024-07-17 17:06:59 +09:00
6 changed files with 129 additions and 0 deletions

View file

@ -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 |

30
Ports/fheroes2/package.sh Executable file
View file

@ -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"
}

View file

@ -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.

View file

@ -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 <endian.h>
#elif defined( __FreeBSD__ ) || defined( __OpenBSD__ )

View file

@ -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
$<$<BOOL:${ENABLE_IMAGE}>:FHEROES2_IMAGE_SUPPORT>
)
target_include_directories(engine PUBLIC
- $<$<BOOL:${ENABLE_IMAGE}>:${${USE_SDL_VERSION}_IMAGE_INCLUDE_DIR}>
- ${${USE_SDL_VERSION}_MIXER_INCLUDE_DIR}
- ${${USE_SDL_VERSION}_INCLUDE_DIR}
+ $<$<BOOL:${ENABLE_IMAGE}>:${${USE_SDL_VERSION}_IMAGE_INCLUDE_DIRS}>
+ ${${USE_SDL_VERSION}_MIXER_INCLUDE_DIRS}
+ ${${USE_SDL_VERSION}_INCLUDE_DIRS}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
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}
$<$<BOOL:${ENABLE_IMAGE}>:${${USE_SDL_VERSION}_IMAGE_LIBRARIES}>
$<$<BOOL:${ENABLE_IMAGE}>:PNG::PNG>
+ $<$<BOOL:${ENABLE_IMAGE}>:-lSDL2_image>
+ -lSDL2_mixer
Threads::Threads # To match the build settings of the main app
ZLIB::ZLIB
)

View file

@ -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()