From 860daa412c4aef0bee801bf8863e66614f7c9aaa Mon Sep 17 00:00:00 2001 From: Oleg Derevenetz Date: Thu, 24 Aug 2023 04:18:35 +0300 Subject: [PATCH] Drop SDL1 support (#7619) --- .github/workflows/clang_tidy.yml | 2 +- .github/workflows/cmake.yml | 18 +-- .github/workflows/iwyu.yml | 2 +- .github/workflows/make.yml | 98 +----------- .github/workflows/msvc.yml | 20 +-- .github/workflows/sonarcloud.yml | 2 +- CMakeLists.txt | 6 +- Makefile | 5 +- Makefile.switch | 3 +- Makefile.vita | 3 +- VisualStudio/SDL1.props | 17 -- docs/DEVELOPMENT.md | 7 +- docs/INSTALL.md | 19 +-- docs/README_PSV.md | 3 +- docs/README_cmake.md | 17 +- docs/README_switch.md | 4 +- fheroes2-vs2019.vcxproj | 26 --- script/linux/README.md | 2 +- script/linux/install_sdl2.sh | 24 +++ script/linux/install_sdl2_dev.sh | 24 +++ script/linux/install_sdl_1.sh | 4 - script/linux/install_sdl_1_dev.sh | 4 - script/linux/install_sdl_2.sh | 4 - script/linux/install_sdl_2_dev.sh | 4 - script/macos/README.md | 2 +- script/macos/install_sdl2.sh | 29 ++++ script/macos/install_sdl_1.sh | 17 -- script/macos/install_sdl_2.sh | 17 -- script/windows/fheroes2.iss | 14 +- src/Makefile | 16 +- src/Makefile.switch | 10 +- src/Makefile.vita | 4 - src/engine/CMakeLists.txt | 5 +- src/engine/audio.cpp | 17 -- src/engine/core.cpp | 20 +-- src/engine/image_tool.cpp | 184 +++++---------------- src/engine/localevent.cpp | 180 +-------------------- src/engine/localevent.h | 11 -- src/engine/screen.cpp | 246 +---------------------------- src/engine/system.cpp | 2 +- src/fheroes2/game/fheroes2.cpp | 22 +-- src/tools/82m2wav-vs2019.vcxproj | 24 --- src/tools/bin2txt-vs2019.vcxproj | 24 --- src/tools/extractor-vs2019.vcxproj | 24 --- src/tools/h2dmgr-vs2019.vcxproj | 24 --- src/tools/icn2img-vs2019.vcxproj | 24 --- src/tools/pal2img-vs2019.vcxproj | 24 --- src/tools/til2img-vs2019.vcxproj | 24 --- src/tools/xmi2midi-vs2019.vcxproj | 24 --- 49 files changed, 180 insertions(+), 1126 deletions(-) delete mode 100644 VisualStudio/SDL1.props create mode 100644 script/linux/install_sdl2.sh create mode 100644 script/linux/install_sdl2_dev.sh delete mode 100755 script/linux/install_sdl_1.sh delete mode 100755 script/linux/install_sdl_1_dev.sh delete mode 100755 script/linux/install_sdl_2.sh delete mode 100755 script/linux/install_sdl_2_dev.sh create mode 100644 script/macos/install_sdl2.sh delete mode 100755 script/macos/install_sdl_1.sh delete mode 100755 script/macos/install_sdl_2.sh diff --git a/.github/workflows/clang_tidy.yml b/.github/workflows/clang_tidy.yml index 14598e180..4f91de7db 100644 --- a/.github/workflows/clang_tidy.yml +++ b/.github/workflows/clang_tidy.yml @@ -31,7 +31,7 @@ jobs: sudo update-alternatives --install /usr/bin/clang-tidy-diff clang-tidy-diff /usr/bin/clang-tidy-diff-15.py 100 - name: Prepare compile_commands.json run: | - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON -DENABLE_TOOLS=ON -DUSE_SDL_VERSION=SDL2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON -DENABLE_TOOLS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Create results directory run: | mkdir clang-tidy-result diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 7fe55518d..d615d30d5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -8,30 +8,16 @@ jobs: strategy: matrix: config: - - name: Linux SDL1 - os: ubuntu-latest - dependencies: libsdl1.2-dev libsdl-mixer1.2-dev libsdl-image1.2-dev gettext ninja-build - options: -DUSE_SDL_VERSION=SDL - name: Linux SDL2 os: ubuntu-latest dependencies: libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev gettext ninja-build - options: -DUSE_SDL_VERSION=SDL2 - - name: macOS SDL1 - os: macos-latest - dependencies: sdl sdl_mixer sdl_image ninja - options: -DUSE_SDL_VERSION=SDL - - name: macOS SDL1 App Bundle - os: macos-latest - dependencies: sdl sdl_mixer sdl_image ninja dylibbundler - options: -DUSE_SDL_VERSION=SDL -DMACOS_APP_BUNDLE=ON - name: macOS SDL2 os: macos-latest dependencies: sdl2 sdl2_mixer sdl2_image ninja - options: -DUSE_SDL_VERSION=SDL2 - name: macOS SDL2 App Bundle os: macos-latest dependencies: sdl2 sdl2_mixer sdl2_image ninja dylibbundler - options: -DUSE_SDL_VERSION=SDL2 -DMACOS_APP_BUNDLE=ON + options: -DMACOS_APP_BUNDLE=ON name: CMake (${{ matrix.config.name }}) runs-on: ${{ matrix.config.os }} timeout-minutes: 30 @@ -82,7 +68,7 @@ jobs: - name: Build run: | cmake.exe -B build -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON \ - -DENABLE_TOOLS=ON -DUSE_SDL_VERSION=SDL2 -DCMAKE_TOOLCHAIN_FILE="C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake" \ + -DENABLE_TOOLS=ON -DCMAKE_TOOLCHAIN_FILE="C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake" \ -DVCPKG_TARGET_TRIPLET=x64-windows cmake.exe --build build --config Debug - name: Install diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 47173d6bc..1a828fe41 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -19,7 +19,7 @@ jobs: sudo apt-get -y install libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev gettext iwyu - name: Prepare compile_commands.json run: | - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON -DENABLE_TOOLS=ON -DUSE_SDL_VERSION=SDL2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON -DENABLE_TOOLS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Analyze run: | iwyu_tool -p build -j 2 -- -Xiwyu --cxx17ns -Xiwyu --mapping_file="$GITHUB_WORKSPACE/iwyu.map" | (grep -E -v "^$|has correct #includes/fwd-decls" || true) \ diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 02c3fa417..da1a85089 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -8,35 +8,6 @@ jobs: strategy: matrix: config: - - name: Linux x86-64 SDL1 Release - os: ubuntu-20.04 - dependencies: libsdl1.2-dev libsdl-mixer1.2-dev gettext - env: - FHEROES2_STRICT_COMPILATION: ON - FHEROES2_WITH_TOOLS: ON - FHEROES2_WITH_SDL1: ON - package_name: fheroes2_ubuntu_x86-64_SDL1.zip - package_files: >- - LICENSE - changelog.txt - fheroes2 - ./docs/README.txt - files/data/*.h2d - files/lang/*.mo - ./script/demo/download_demo_version.sh - ./script/homm2/extract_homm2_resources.sh - script/linux/install_sdl_1.sh - release_name: Ubuntu x86-64 (Linux) build with SDL1 (latest commit) - release_tag: fheroes2-linux-sdl1_dev - - name: Linux x86-64 SDL1 Debug - os: ubuntu-latest - dependencies: libsdl1.2-dev libsdl-mixer1.2-dev gettext - env: - FHEROES2_STRICT_COMPILATION: ON - FHEROES2_WITH_TOOLS: ON - FHEROES2_WITH_SDL1: ON - FHEROES2_WITH_DEBUG: ON - FHEROES2_WITH_ASAN: ON - name: Linux x86-64 SDL2 Release os: ubuntu-20.04 dependencies: libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev gettext @@ -54,7 +25,7 @@ jobs: files/lang/*.mo ./script/demo/download_demo_version.sh ./script/homm2/extract_homm2_resources.sh - script/linux/install_sdl_2.sh + script/linux/install_sdl2.sh tools_package_name: fheroes2_tools_ubuntu_x86-64_SDL2.zip tools_package_files: >- LICENSE @@ -78,42 +49,7 @@ jobs: FHEROES2_WITH_TOOLS: ON FHEROES2_WITH_IMAGE: ON FHEROES2_WITH_DEBUG: ON - FHEROES2_WITH_TSAN: ON - - name: Linux ARM64 SDL1 Release - os: ubuntu-22.04 - dependencies: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libsdl1.2-dev:arm64 libsdl-mixer1.2-dev:arm64 gettext - env: - FHEROES2_STRICT_COMPILATION: ON - FHEROES2_WITH_TOOLS: ON - FHEROES2_WITH_SDL1: ON - CC: aarch64-linux-gnu-gcc - CXX: aarch64-linux-gnu-g++ - AR: aarch64-linux-gnu-ar - package_name: fheroes2_ubuntu_arm64_SDL1.zip - package_files: >- - LICENSE - changelog.txt - fheroes2 - ./docs/README.txt - files/data/*.h2d - files/lang/*.mo - ./script/demo/download_demo_version.sh - ./script/homm2/extract_homm2_resources.sh - script/linux/install_sdl_1.sh - release_name: Ubuntu ARM64 (Linux) build with SDL1 (latest commit) - release_tag: fheroes2-linux-arm-sdl1_dev - - name: Linux ARM64 SDL1 Debug - os: ubuntu-latest - dependencies: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libsdl1.2-dev:arm64 libsdl-mixer1.2-dev:arm64 gettext - env: - FHEROES2_STRICT_COMPILATION: ON - FHEROES2_WITH_TOOLS: ON - FHEROES2_WITH_SDL1: ON - FHEROES2_WITH_DEBUG: ON FHEROES2_WITH_ASAN: ON - CC: aarch64-linux-gnu-gcc - CXX: aarch64-linux-gnu-g++ - AR: aarch64-linux-gnu-ar - name: Linux ARM64 SDL2 Release os: ubuntu-22.04 dependencies: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libsdl2-dev:arm64 libsdl2-mixer-dev:arm64 libsdl2-image-dev:arm64 libpng-dev:arm64 gettext @@ -134,7 +70,7 @@ jobs: files/lang/*.mo ./script/demo/download_demo_version.sh ./script/homm2/extract_homm2_resources.sh - script/linux/install_sdl_2.sh + script/linux/install_sdl2.sh tools_package_name: fheroes2_tools_ubuntu_arm64_SDL2.zip tools_package_files: >- LICENSE @@ -162,34 +98,6 @@ jobs: CC: aarch64-linux-gnu-gcc CXX: aarch64-linux-gnu-g++ AR: aarch64-linux-gnu-ar - - name: macOS SDL1 - os: macos-11 - dependencies: sdl sdl_mixer - env: - FHEROES2_STRICT_COMPILATION: ON - FHEROES2_WITH_TOOLS: ON - FHEROES2_WITH_SDL1: ON - package_name: fheroes2_macos_x86-64_SDL1.zip - package_files: >- - LICENSE - changelog.txt - fheroes2 - ./docs/README.txt - files/data/*.h2d - files/lang/*.mo - ./script/demo/download_demo_version.sh - ./script/homm2/extract_homm2_resources.sh - script/macos/install_sdl_1.sh - release_name: macOS x86-64 build with SDL1 (latest commit) - release_tag: fheroes2-osx-sdl1_dev - - name: macOS SDL1 App Bundle - os: macos-latest - dependencies: sdl sdl_mixer dylibbundler - env: - FHEROES2_STRICT_COMPILATION: ON - FHEROES2_WITH_TOOLS: ON - FHEROES2_WITH_SDL1: ON - FHEROES2_MACOS_APP_BUNDLE: ON - name: macOS SDL2 os: macos-11 dependencies: sdl2 sdl2_mixer sdl2_image @@ -207,7 +115,7 @@ jobs: files/lang/*.mo ./script/demo/download_demo_version.sh ./script/homm2/extract_homm2_resources.sh - script/macos/install_sdl_2.sh + script/macos/install_sdl2.sh tools_package_name: fheroes2_tools_macos_x86-64_SDL2.zip tools_package_files: >- LICENSE diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml index 7a6a93a85..0159107f9 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc.yml @@ -8,22 +8,6 @@ jobs: strategy: matrix: config: - - name: SDL1 x86 - platform: x86 - build_config: Release-SDL1 - deploy_config: SDL1 - installer_package_name: fheroes2_windows_x86_SDL1_installer.exe - zip_package_name: fheroes2_windows_x86_SDL1.zip - release_name: Windows x86 build with SDL1 (latest commit) - release_tag: fheroes2-windows-x86-SDL1 - - name: SDL1 x64 - platform: x64 - build_config: Release-SDL1 - deploy_config: SDL1 - installer_package_name: fheroes2_windows_x64_SDL1_installer.exe - zip_package_name: fheroes2_windows_x64_SDL1.zip - release_name: Windows x64 build with SDL1 (latest commit) - release_tag: fheroes2-windows-x64-SDL1 - name: SDL2 x86 platform: x86 build_config: Release-SDL2 @@ -111,13 +95,11 @@ jobs: .\\docs\\README.txt \ files\\data\\*.h2d \ files\\lang\\*.mo \ + files\\soundfonts\\* \ .\\script\\demo\\*.bat \ .\\script\\demo\\*.ps1 \ .\\script\\homm2\\*.bat \ .\\script\\homm2\\*.ps1 - if [[ ${{ matrix.config.deploy_config }} == SDL2 ]]; then - 7z.exe a -bb1 -tzip -- "$BUILD_DIR"\\${{ matrix.config.zip_package_name }} files\\soundfonts\\* - fi env: BUILD_DIR: build\${{ matrix.config.platform }}\${{ matrix.config.build_config }} - name: Create tools package diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index fdd03a2ba..405a1805b 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -45,7 +45,7 @@ jobs: ./gradlew compileDebugJavaWithJavac - name: Prepare compile_commands.json run: | - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON -DENABLE_TOOLS=ON -DUSE_SDL_VERSION=SDL2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_STRICT_COMPILATION=ON -DENABLE_IMAGE=ON -DENABLE_TOOLS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Analyze run: | sonar-scanner -Dsonar.cfamily.compile-commands=build/compile_commands.json \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e506cd84..564fba912 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -37,7 +37,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # option(USE_SYSTEM_LIBSMACKER "Use system libsmacker instead of the bundled version" OFF) option(ENABLE_STRICT_COMPILATION "Enable strict compilation mode (turns warnings into errors)" OFF) -option(ENABLE_IMAGE "Enable SDL2 Image support (requires libpng)" ON) +option(ENABLE_IMAGE "Enable SDL_image support (requires libpng)" ON) option(ENABLE_TOOLS "Enable additional tools" OFF) # Available only on macOS @@ -50,7 +50,7 @@ set(USE_SDL_VERSION SDL2 CACHE STRING "Version of the SDL library used") set(FHEROES2_DATA ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} CACHE STRING "Path to the fheroes2 data directory (relative to CMAKE_INSTALL_PREFIX)") # For ComboBox in CMake GUI -set_property(CACHE USE_SDL_VERSION PROPERTY STRINGS SDL SDL2) +set_property(CACHE USE_SDL_VERSION PROPERTY STRINGS SDL2) # # Library & feature detection diff --git a/Makefile b/Makefile index 2dea0b6f6..9a67fa044 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2022 # +# Copyright (C) 2021 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -21,11 +21,10 @@ # Options: # # FHEROES2_STRICT_COMPILATION: build in strict compilation mode (turns warnings into errors) -# FHEROES2_WITH_SDL1: build with SDL1 instead of SDL2 (which is used by default) # FHEROES2_WITH_DEBUG: build in debug mode # FHEROES2_WITH_ASAN: build with UB Sanitizer and Address Sanitizer (small runtime overhead, incompatible with FHEROES2_WITH_TSAN) # FHEROES2_WITH_TSAN: build with UB Sanitizer and Thread Sanitizer (large runtime overhead, incompatible with FHEROES2_WITH_ASAN) -# FHEROES2_WITH_IMAGE: build with SDL2 Image support (requires libpng) +# FHEROES2_WITH_IMAGE: build with SDL_image support (requires libpng) # FHEROES2_WITH_TOOLS: build additional tools # FHEROES2_MACOS_APP_BUNDLE: create a Mac app bundle (only valid when building on macOS) # FHEROES2_DATA: set the built-in path to the fheroes2 data directory (e.g. /usr/share/fheroes2) diff --git a/Makefile.switch b/Makefile.switch index 1b80c59d0..1dcf96ca3 100644 --- a/Makefile.switch +++ b/Makefile.switch @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2022 # +# Copyright (C) 2021 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -22,7 +22,6 @@ # # FHEROES2_STRICT_COMPILATION: build in strict compilation mode (turns warnings into errors) # FHEROES2_WITH_DEBUG: build in debug mode -# FHEROES2_WITH_IMAGE: build with SDL2 Image support (requires libpng, libjpeg and libwebp) # FHEROES2_DATA: set the built-in path to the fheroes2 data directory (e.g. /usr/share/fheroes2) TARGET := fheroes2 diff --git a/Makefile.vita b/Makefile.vita index a98fec717..24a4a9dd1 100644 --- a/Makefile.vita +++ b/Makefile.vita @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2022 # +# Copyright (C) 2021 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -22,7 +22,6 @@ # # FHEROES2_STRICT_COMPILATION: build in strict compilation mode (turns warnings into errors) # FHEROES2_WITH_DEBUG: build in debug mode -# FHEROES2_WITH_IMAGE: build with SDL2 Image support (requires libpng, libjpeg and libwebp) # FHEROES2_DATA: set the built-in path to the fheroes2 data directory (e.g. /usr/share/fheroes2) TARGET := fheroes2 diff --git a/VisualStudio/SDL1.props b/VisualStudio/SDL1.props deleted file mode 100644 index 9247ee0a0..000000000 --- a/VisualStudio/SDL1.props +++ /dev/null @@ -1,17 +0,0 @@ - - - - - $(MSBuildThisFileDirectory)packages\sdl1\include\;$(MSBuildThisFileDirectory)packages\sdl1\include\SDL;%(AdditionalIncludeDirectories) - - - $(MSBuildThisFileDirectory)packages\sdl1\lib\$(PlatformTarget);%(AdditionalLibraryDirectories) - SDL.lib;SDL_mixer.lib;zlib.lib;%(AdditionalDependencies) - - - xcopy /Y /Q "$(MSBuildThisFileDirectory)packages\sdl1\lib\$(PlatformTarget)\*.dll" "$(OutDir)" -xcopy /Y /Q "$(MSBuildThisFileDirectory)packages\sdl1\lib\$(PlatformTarget)\*.pdb" "$(OutDir)" -%(Command) - - - diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 9b54200d7..ffe36621f 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -20,14 +20,13 @@ Please follow the instructions below to be able to build the project from source ### macOS and Linux * Depending on your OS, run the following scripts to install the dependencies required for the build: - * macOS: go to the directory `script/macos` and run the file `install_sdl_2.sh` (default setup) or `install_sdl_1.sh`. - * Linux: go to the directory `script/linux` and run the file `install_sdl_2_dev.sh` (default setup) or `install_sdl_1_dev.sh`. + * macOS: go to the directory `script/macos` and run the file `install_sdl2.sh`. + * Linux: go to the directory `script/linux` and run the file `install_sdl2_dev.sh`. * If you have the original game, then copy the subdirectories `ANIM`, `DATA`, `MAPS` and `MUSIC` (some of them may be missing depending on the version of the original game) to the project root directory. * Alternatively, go to the directory `script/demo` and run the file `download_demo_version.sh`. This script will download a demo version of the original game, which is the minimum required for development. -* Run the `make` command in the root directory of the project to build it with **SDL2** or `make FHEROES2_WITH_SDL1="ON"` - to build it with **SDL1**. +* Run the `make` command in the root directory of the project to build it. ### Android diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 76385b233..523b2483c 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -117,7 +117,7 @@ Follow the [**instructions below**](#macos-resources) to gather resources necess method (using [**MacPorts**](#macports) or [**Homebrew**](#homebrew-mac)), or [**build the project from source**](DEVELOPMENT.md#macos-and-linux). -* After downloading the ZIP archive, extract it to a suitable directory of your choice and then run the script `install_sdl_2.sh` from +* After downloading the ZIP archive, extract it to a suitable directory of your choice and then run the script `install_sdl2.sh` from the `script/macos` subdirectory. This will install the SDL libraries required to run the game. Follow the [**instructions below**](#macos-resources) to gather resources necessary for fheroes2 to function as expected. @@ -278,7 +278,7 @@ makepkg -si * After downloading the ZIP archive, extract it to a suitable directory of your choice. Then you will need to install the SDL libraries required to run the game. The installation procedure depends on the Linux distribution you are using: - * **Debian-based**: run the script `install_sdl_2.sh` from the `script/linux` subdirectory. + * **Debian-based**: run the script `install_sdl2.sh` from the `script/linux` subdirectory. * **Pacman-based (e.g. Arch Linux)**: run the following command: `sudo pacman -S sdl2 sdl2_mixer`. @@ -329,20 +329,15 @@ makepkg -si You can download the precompiled binaries of the latest commit (snapshot) for **Windows** ( -[**x64 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-windows-x64-SDL2), -[**x64 SDL1**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-windows-x64-SDL1), -[**x86 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-windows-x86-SDL2) and -[**x86 SDL1**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-windows-x86-SDL1) +[**x64 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-windows-x64-SDL2) and +[**x86 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-windows-x86-SDL2) ), **macOS x86-64** ( -[**SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-osx-sdl2_dev) and -[**SDL1**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-osx-sdl1_dev) +[**SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-osx-sdl2_dev) ), **Ubuntu** ( -[**x86-64 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-linux-sdl2_dev), -[**x86-64 SDL1**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-linux-sdl1_dev), -[**ARM64 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-linux-arm-sdl2_dev) and -[**ARM64 SDL1**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-linux-arm-sdl1_dev) +[**x86-64 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-linux-sdl2_dev) and +[**ARM64 SDL2**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-linux-arm-sdl2_dev) ), [**Android**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-android), [**PlayStation Vita**](https://github.com/ihhub/fheroes2/releases/tag/fheroes2-psv-sdl2_dev) and diff --git a/docs/README_PSV.md b/docs/README_PSV.md index be1d6d353..7826d662f 100644 --- a/docs/README_PSV.md +++ b/docs/README_PSV.md @@ -20,8 +20,7 @@ is required for proper suspend/resume support (only use one at a time). ### Prerequisites - VitaSDK - libSDL2 -- libSDL2-mixer (optional) -- libSDL2-image (optional) +- libSDL2-mixer To build the game just run ``` diff --git a/docs/README_cmake.md b/docs/README_cmake.md index 1c30af159..e871262be 100644 --- a/docs/README_cmake.md +++ b/docs/README_cmake.md @@ -5,17 +5,13 @@ Building with CMake [**fheroes2**](README.md) can be built with CMake buildsystem. First, you need to install dependencies. For Linux and macOS follow to instructions as described above. -Next, you can build project with following commands: +Next, you can configure the project with following commands: ```shell -# SDL1 -cmake -B build -DUSE_SDL_VERSION=SDL -DENABLE_IMAGE=ON -# OR -# SDL2 -cmake -B build -DUSE_SDL_VERSION=SDL2 -DENABLE_IMAGE=ON +cmake -B build ``` -After configuration let's build project: +After configuration let's build the project: ```shell cmake --build build @@ -49,15 +45,14 @@ After following command Visual Studio automagically will find all required depen .\vcpkg\vcpkg integrate install ``` -Now you ready to compile project. cd to fheroes2 directory and run `cmake` command (note for `-DCMAKE_TOOLCHAIN_FILE` and +Now you are ready to configure the project. cd to fheroes2 directory and run `cmake` command (note for `-DCMAKE_TOOLCHAIN_FILE` and `-DVCPKG_TARGET_TRIPLET` options): ```shell -# SDL2 -cmake -B build -DCMAKE_TOOLCHAIN_FILE="C:\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows -DUSE_SDL_VERSION=SDL2 -DENABLE_IMAGE=ON -DENABLE_MIXER=ON +cmake -B build -DCMAKE_TOOLCHAIN_FILE="C:\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows ``` -After configuration let's build project: +After configuration let's build the project: ```shell cmake --build build --config Release diff --git a/docs/README_switch.md b/docs/README_switch.md index 087b48597..f8d174bea 100644 --- a/docs/README_switch.md +++ b/docs/README_switch.md @@ -3,9 +3,9 @@ It's a homebrew app, so you need to be running custom firmware for it to work. ## BUILDING -You will need to install the [devkitPro](https://devkitpro.org/) toolchain. Make sure to include the following packages: +You will need to install the [devkitPro](https://devkitpro.org/) toolchain. Make sure to include the following package: ``` -libnx switch-sdl2_image switch-sdl2_mixer +libnx switch-sdl2_mixer ``` After installation run `make -f Makefile.switch -j 2` command to build the package. diff --git a/fheroes2-vs2019.vcxproj b/fheroes2-vs2019.vcxproj index a8b4986d5..c5b35a0ad 100644 --- a/fheroes2-vs2019.vcxproj +++ b/fheroes2-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,21 +37,11 @@ - - - - - - - - - - diff --git a/script/linux/README.md b/script/linux/README.md index fd99e0bf6..56e4f64f1 100644 --- a/script/linux/README.md +++ b/script/linux/README.md @@ -1,4 +1,4 @@ Linux ====== -This directory contains helper scripts to install SDL 1.2 or SDL 2.0. +This directory contains helper scripts to install SDL. diff --git a/script/linux/install_sdl2.sh b/script/linux/install_sdl2.sh new file mode 100644 index 000000000..e96bec632 --- /dev/null +++ b/script/linux/install_sdl2.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +########################################################################### +# fheroes2: https://github.com/ihhub/fheroes2 # +# Copyright (C) 2021 - 2023 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the # +# Free Software Foundation, Inc., # +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # +########################################################################### + +# Install SDL2 +sudo apt-get install -y libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-mixer-2.0-0 diff --git a/script/linux/install_sdl2_dev.sh b/script/linux/install_sdl2_dev.sh new file mode 100644 index 000000000..7660740b1 --- /dev/null +++ b/script/linux/install_sdl2_dev.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +########################################################################### +# fheroes2: https://github.com/ihhub/fheroes2 # +# Copyright (C) 2021 - 2023 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the # +# Free Software Foundation, Inc., # +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # +########################################################################### + +# Install development dependencies targeting SDL2 +sudo apt-get install -y gettext libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev diff --git a/script/linux/install_sdl_1.sh b/script/linux/install_sdl_1.sh deleted file mode 100755 index 7566761d7..000000000 --- a/script/linux/install_sdl_1.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -# Install SDL 1.2 -sudo apt-get install -y libsdl1.2debian libsdl-image1.2 libsdl-mixer1.2 diff --git a/script/linux/install_sdl_1_dev.sh b/script/linux/install_sdl_1_dev.sh deleted file mode 100755 index e7695bc12..000000000 --- a/script/linux/install_sdl_1_dev.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -# Install development dependencies targeting SDL 1.2 -sudo apt-get install -y gettext libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev diff --git a/script/linux/install_sdl_2.sh b/script/linux/install_sdl_2.sh deleted file mode 100755 index 4ebfc203f..000000000 --- a/script/linux/install_sdl_2.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -# Install SDL 2 -sudo apt-get install -y libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-mixer-2.0-0 diff --git a/script/linux/install_sdl_2_dev.sh b/script/linux/install_sdl_2_dev.sh deleted file mode 100755 index f911d5af1..000000000 --- a/script/linux/install_sdl_2_dev.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -# Install development dependencies targeting SDL 2 -sudo apt-get install -y gettext libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev diff --git a/script/macos/README.md b/script/macos/README.md index fe5e160ca..384c31a11 100644 --- a/script/macos/README.md +++ b/script/macos/README.md @@ -1,4 +1,4 @@ macOS ====== -This directory contains helper scripts to install SDL 1.2 or SDL 2.0. +This directory contains helper scripts to install SDL. diff --git a/script/macos/install_sdl2.sh b/script/macos/install_sdl2.sh new file mode 100644 index 000000000..de09c34de --- /dev/null +++ b/script/macos/install_sdl2.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +########################################################################### +# fheroes2: https://github.com/ihhub/fheroes2 # +# Copyright (C) 2021 - 2023 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the # +# Free Software Foundation, Inc., # +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # +########################################################################### + +# Install dev tools +brew install gettext + +# Install SDL2 +brew install sdl2 +brew install sdl2_mixer +brew install sdl2_image diff --git a/script/macos/install_sdl_1.sh b/script/macos/install_sdl_1.sh deleted file mode 100755 index 82ba17be3..000000000 --- a/script/macos/install_sdl_1.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Uninstall dev tools -brew remove gettext - -# Install dev tools -brew install gettext - -# Uninstall SDL 2 -brew remove sdl2_image -brew remove sdl2_mixer -brew remove sdl2 - -# Install SDL 1.2 -brew install sdl -brew install sdl_mixer -brew install sdl_image diff --git a/script/macos/install_sdl_2.sh b/script/macos/install_sdl_2.sh deleted file mode 100755 index c575ac479..000000000 --- a/script/macos/install_sdl_2.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Uninstall dev tools -brew remove gettext - -# Install dev tools -brew install gettext - -# Uninstall SDL 1.2 -brew remove sdl_image -brew remove sdl_mixer -brew remove sdl - -# Install SDL 2 -brew install sdl2 -brew install sdl2_mixer -brew install sdl2_image diff --git a/script/windows/fheroes2.iss b/script/windows/fheroes2.iss index 11b286e73..1dd294391 100644 --- a/script/windows/fheroes2.iss +++ b/script/windows/fheroes2.iss @@ -24,19 +24,17 @@ RestartIfNeededByRun=no [Files] Source: "{#BuildDir}\{#AppName}.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "{#BuildDir}\*.dll"; DestDir: "{app}" +Source: "..\..\.vcredist\vcredist.exe"; DestDir: "{tmp}" +Source: "..\..\LICENSE"; DestDir: "{app}" +Source: "..\..\changelog.txt"; DestDir: "{app}" Source: "..\..\docs\README.txt"; DestDir: "{app}" +Source: "..\..\files\data\*.h2d"; DestDir: "{app}\files\data" +Source: "..\..\files\lang\*.mo"; DestDir: "{app}\files\lang" +Source: "..\..\files\soundfonts\*.*"; DestDir: "{app}\files\soundfonts" Source: "..\demo\*.bat"; DestDir: "{app}" Source: "..\demo\*.ps1"; DestDir: "{app}" Source: "..\homm2\*.bat"; DestDir: "{app}" Source: "..\homm2\*.ps1"; DestDir: "{app}" -Source: "..\..\changelog.txt"; DestDir: "{app}" -Source: "..\..\LICENSE"; DestDir: "{app}" -Source: "..\..\files\lang\*.mo"; DestDir: "{app}\files\lang" -Source: "..\..\files\data\*.h2d"; DestDir: "{app}\files\data" -#if DeployConfName == 'SDL2' -Source: "..\..\files\soundfonts\*.*"; DestDir: "{app}\files\soundfonts" -#endif -Source: "..\..\.vcredist\vcredist.exe"; DestDir: "{tmp}" [Tasks] Name: desktopicon; Description: "{cm:DesktopIconTaskDescription}" diff --git a/src/Makefile b/src/Makefile index f0698f341..340596ebd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2022 # +# Copyright (C) 2021 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -133,11 +133,7 @@ endif # SDL_FLAGS can already be defined in a platform-specific Makefile ifeq ($(origin SDL_FLAGS),undefined) -ifdef FHEROES2_WITH_SDL1 -SDL_FLAGS := $(shell sdl-config --cflags) -else SDL_FLAGS := $(shell sdl2-config --cflags) -endif ifdef FHEROES2_WITH_IMAGE SDL_FLAGS := $(SDL_FLAGS) $(shell libpng-config --cflags) @@ -146,15 +142,6 @@ endif # SDL_LIBS can already be defined in a platform-specific Makefile ifeq ($(origin SDL_LIBS),undefined) -ifdef FHEROES2_WITH_SDL1 -SDL_LIBS := $(shell sdl-config --libs) -# Insert -lSDL_mixer before -lSDL, but after any previous -L/path/to/lib entries -SDL_LIBS := $(subst $(firstword $(filter -l%,$(SDL_LIBS))),-lSDL_mixer $(firstword $(filter -l%,$(SDL_LIBS))),$(SDL_LIBS)) - -ifdef FHEROES2_WITH_IMAGE -SDL_LIBS := $(SDL_LIBS) -lSDL_image $(shell libpng-config --libs) -endif -else SDL_LIBS := $(shell sdl2-config --libs) # Insert -lSDL2_mixer before -lSDL2, but after any previous -L/path/to/lib entries SDL_LIBS := $(subst $(firstword $(filter -l%,$(SDL_LIBS))),-lSDL2_mixer $(firstword $(filter -l%,$(SDL_LIBS))),$(SDL_LIBS)) @@ -163,7 +150,6 @@ ifdef FHEROES2_WITH_IMAGE SDL_LIBS := $(SDL_LIBS) -lSDL2_image $(shell libpng-config --libs) endif endif -endif CCFLAGS := $(CCFLAGS) $(SDL_FLAGS) LIBS := $(SDL_LIBS) $(LIBS) diff --git a/src/Makefile.switch b/src/Makefile.switch index 293f3b270..97cad378f 100644 --- a/src/Makefile.switch +++ b/src/Makefile.switch @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -28,13 +28,5 @@ CCFLAGS_FH2 := -DTARGET_NINTENDO_SWITCH LIBS := $(LIBS) -lvorbisidec -lmodplug -lmpg123 -lopusfile -lopus -logg -ifdef FHEROES2_WITH_IMAGE -LIBS := $(LIBS) -ljpeg -lwebp -endif - # Prevent sdl2-config --cflags from running once again in the main Makefile SDL_FLAGS := - -ifdef FHEROES2_WITH_IMAGE -SDL_FLAGS := $(SDL_FLAGS) $(shell libpng-config --cflags) -endif diff --git a/src/Makefile.vita b/src/Makefile.vita index 6379d79b4..71dd617ed 100644 --- a/src/Makefile.vita +++ b/src/Makefile.vita @@ -32,7 +32,3 @@ SDL_FLAGS := -I$(VITASDK)/arm-vita-eabi/include/SDL2 SDL_LIBS := -L$(VITASDK)/arm-vita-eabi/lib -lSDL2_mixer -lSDL2 -lvita2d -lScePower_stub -lSceAudioIn_stub -lSceAudio_stub -lSceCtrl_stub -lSceHid_stub -lSceTouch_stub \ -lSceDisplay_stub -lSceGxm_stub -lSceAppMgr_stub -lSceSysmodule_stub -lSceCommonDialog_stub -lSceMotion_stub -lFLAC -lmikmod \ -lmodplug -lmpg123 -lvorbisfile -lvorbis -lopusfile -lopus -logg -lxmp - -ifdef FHEROES2_WITH_IMAGE -SDL_LIBS := $(SDL_LIBS) -lSDL2_image -lpng -ljpeg -lwebp -endif diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index a52f686f1..dd3c1cef1 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2023 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -54,8 +54,7 @@ target_include_directories( target_link_libraries( engine smacker - # In the case of SDL1, SDL_LIBRARY contains both SDLmain and SDL libraries - $<$:${SDL2MAIN_LIBRARY}> + ${${USE_SDL_VERSION}MAIN_LIBRARY} ${${USE_SDL_VERSION}_LIBRARY} ${${USE_SDL_VERSION}_MIXER_LIBRARIES} $<$:${${USE_SDL_VERSION}_IMAGE_LIBRARIES}> diff --git a/src/engine/audio.cpp b/src/engine/audio.cpp index 766f99243..689132b1b 100644 --- a/src/engine/audio.cpp +++ b/src/engine/audio.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include "core.h" #include "dir.h" @@ -181,11 +180,7 @@ namespace // This is the callback function set by Mix_ChannelFinished(). As a rule, it is called from // a SDL_Mixer internal thread. Calls of any SDL_Mixer functions are not allowed in callbacks. -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) void SDLCALL channelFinished( const int channelId ) -#else - void channelFinished( const int channelId ) -#endif { // This callback function should never be called if audio is not initialized assert( isInitialized ); @@ -273,11 +268,7 @@ namespace ERROR_LOG( "Failed to create a music track from memory. The error: " << SDL_GetError() ) } else { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) result = Mix_LoadMUS_RW( rwops, 0 ); -#else - result = Mix_LoadMUS_RW( rwops ); -#endif if ( result == nullptr ) { ERROR_LOG( "Failed to create a music track from memory. The error: " << Mix_GetError() ) } @@ -507,11 +498,7 @@ namespace // This is the callback function set by Mix_HookMusicFinished(). As a rule, it is called from // a SDL_Mixer internal thread. Calls of any SDL_Mixer functions are not allowed in callbacks. -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) void SDLCALL musicFinished() -#else - void musicFinished() -#endif { // This callback function should never be called if audio is not initialized assert( isInitialized ); @@ -646,7 +633,6 @@ void Audio::Init() return; } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) const int initializationFlags = MIX_INIT_FLAC | MIX_INIT_MP3 | MIX_INIT_OGG | MIX_INIT_MID; const int initializedFlags = Mix_Init( initializationFlags ); if ( ( initializedFlags & initializationFlags ) != initializationFlags ) { @@ -669,7 +655,6 @@ void Audio::Init() DEBUG_LOG( DBG_ENGINE, DBG_WARN, "MID module failed to be initialized" ) } } -#endif const AudioSpec audioSpec; @@ -746,9 +731,7 @@ void Audio::Quit() musicTrackManager.clearMusicDB(); Mix_CloseAudio(); -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) Mix_Quit(); -#endif mixerChannelCount = 0; diff --git a/src/engine/core.cpp b/src/engine/core.cpp index 6c14c4891..a3d4014aa 100644 --- a/src/engine/core.cpp +++ b/src/engine/core.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2021 - 2022 * + * Copyright (C) 2021 - 2023 * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -18,16 +18,16 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "core.h" + #include #include #include #include #include -#include #include "audio.h" -#include "core.h" #include "localevent.h" #include "logging.h" @@ -78,11 +78,7 @@ namespace case fheroes2::SystemInitializationComponent::Video: return SDL_INIT_VIDEO; case fheroes2::SystemInitializationComponent::GameController: -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) return SDL_INIT_GAMECONTROLLER; -#else - return 0; -#endif default: // Did you add a new component? assert( 0 ); @@ -115,19 +111,11 @@ namespace Audio::Init(); } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) if ( components.count( fheroes2::SystemInitializationComponent::GameController ) > 0 ) { LocalEvent::Get().OpenController(); } LocalEvent::Get().OpenTouchpad(); -#endif - -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) -#else - SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); -#endif - LocalEvent::setEventProcessingStates(); return true; @@ -135,11 +123,9 @@ namespace void freeCoreInternally() { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) if ( fheroes2::isComponentInitialized( fheroes2::SystemInitializationComponent::GameController ) ) { LocalEvent::Get().CloseController(); } -#endif if ( fheroes2::isComponentInitialized( fheroes2::SystemInitializationComponent::Audio ) ) { Audio::Quit(); diff --git a/src/engine/image_tool.cpp b/src/engine/image_tool.cpp index 020f67e1e..9349a5b15 100644 --- a/src/engine/image_tool.cpp +++ b/src/engine/image_tool.cpp @@ -29,22 +29,15 @@ #include #include +#include #include +#include #include -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) -#include -#include -#else -#include -#endif - -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #if defined( WITH_IMAGE ) #define ENABLE_PNG #include #endif -#endif #include "image_palette.h" #include "image_tool.h" @@ -82,11 +75,7 @@ namespace const int32_t width = image.width(); const int32_t height = image.height(); -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) SDL_Surface * surface = SDL_CreateRGBSurface( 0, width, height, 8, 0, 0, 0, 0 ); -#else - SDL_Surface * surface = SDL_CreateRGBSurface( SDL_SWSURFACE, width, height, 8, 0xFF, 0xFF00, 0xFF0000, 0xFF000000 ); -#endif if ( surface == nullptr ) { ERROR_LOG( "Error while creating a SDL surface for an image to be saved under " << path << ". Error " << SDL_GetError() ) return false; @@ -103,16 +92,10 @@ namespace col.r = *value; col.g = *( value + 1 ); col.b = *( value + 2 ); -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) col.a = 255; -#endif } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) SDL_SetPaletteColors( surface->format->palette, paletteSDL.data(), 0, 256 ); -#else - SDL_SetPalette( surface, SDL_LOGPAL | SDL_PHYSPAL, paletteSDL.data(), 0, 256 ); -#endif if ( surface->pitch != width ) { const uint8_t * imageIn = image.image(); @@ -173,156 +156,73 @@ namespace fheroes2 bool Load( const std::string & path, Image & image ) { std::unique_ptr> surface( nullptr, SDL_FreeSurface ); - - { - std::unique_ptr> loadedSurface( nullptr, SDL_FreeSurface ); + std::unique_ptr> loadedSurface( nullptr, SDL_FreeSurface ); #if defined( ENABLE_PNG ) - loadedSurface.reset( IMG_Load( path.c_str() ) ); + loadedSurface.reset( IMG_Load( path.c_str() ) ); #else - loadedSurface.reset( SDL_LoadBMP( path.c_str() ) ); + loadedSurface.reset( SDL_LoadBMP( path.c_str() ) ); #endif - if ( !loadedSurface ) { - return false; - } + if ( !loadedSurface ) { + return false; + } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) // SDL_PIXELFORMAT_BGRA32 and other RGBA color variants are only supported starting with SDL 2.0.5 #if !SDL_VERSION_ATLEAST( 2, 0, 5 ) #error Minimal supported SDL version is 2.0.5. #endif - // Image loading functions can theoretically return SDL_Surface in any supported color format, so we will convert it to a specific format for subsequent - // processing - const std::unique_ptr> pixelFormat( SDL_AllocFormat( SDL_PIXELFORMAT_BGRA32 ), SDL_FreeFormat ); - if ( !pixelFormat ) { - return false; - } - - surface.reset( SDL_ConvertSurface( loadedSurface.get(), pixelFormat.get(), 0 ) ); - if ( !surface ) { - return false; - } - - assert( SDL_MUSTLOCK( surface.get() ) == SDL_FALSE && surface->format->BytesPerPixel == 4 ); -#else - // With SDL1, we just use the loaded SDL_Surface as is and hope for the best - surface = std::move( loadedSurface ); -#endif + // Image loading functions can theoretically return SDL_Surface in any supported color format, so we will convert it to a specific format for subsequent + // processing + const std::unique_ptr> pixelFormat( SDL_AllocFormat( SDL_PIXELFORMAT_BGRA32 ), SDL_FreeFormat ); + if ( !pixelFormat ) { + return false; } - assert( surface && SDL_MUSTLOCK( surface.get() ) == SDL_FALSE ); + surface.reset( SDL_ConvertSurface( loadedSurface.get(), pixelFormat.get(), 0 ) ); + if ( !surface ) { + return false; + } - // TODO: with SDL2 we can use specific color format of SDL_Surface, therefore, most of this code will not be needed - if ( surface->format->BytesPerPixel == 1 ) { - const SDL_Palette * palette = surface->format->palette; - assert( palette != nullptr ); + assert( SDL_MUSTLOCK( surface.get() ) == SDL_FALSE && surface->format->BytesPerPixel == 4 ); - image.resize( surface->w, surface->h ); + image.resize( surface->w, surface->h ); + image.reset(); - const uint8_t * inY = reinterpret_cast( surface->pixels ); - uint8_t * outY = image.image(); - uint8_t * transformY = image.transform(); + const uint8_t * inY = reinterpret_cast( surface->pixels ); + uint8_t * outY = image.image(); + uint8_t * transformY = image.transform(); - const uint8_t * inYEnd = inY + surface->h * surface->pitch; + const uint8_t * inYEnd = inY + surface->h * surface->pitch; - for ( ; inY != inYEnd; inY += surface->pitch, outY += surface->w, transformY += surface->w ) { - const uint8_t * inX = inY; - uint8_t * outX = outY; - uint8_t * transformX = transformY; - const uint8_t * inXEnd = inX + surface->w; + for ( ; inY != inYEnd; inY += surface->pitch, outY += surface->w, transformY += surface->w ) { + const uint8_t * inX = inY; + uint8_t * outX = outY; + uint8_t * transformX = transformY; + const uint8_t * inXEnd = inX + surface->w * 4; - for ( ; inX != inXEnd; ++inX, ++outX, ++transformX ) { - assert( *inX < palette->ncolors ); - const SDL_Color * color = palette->colors + *inX; -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) - if ( color->a < 255 ) { - if ( color->a == 0 ) { - *outX = 0; - *transformX = 1; - } - else if ( color->r == 0 && color->g == 0 && color->b == 0 ) { - *outX = 0; - *transformX = 2; - } - else { - *outX = GetColorId( *( inX + 2 ), *( inX + 1 ), *inX ); - *transformX = 0; - } + for ( ; inX != inXEnd; inX += 4, ++outX, ++transformX ) { + const uint8_t alpha = *( inX + 3 ); + if ( alpha < 255 ) { + if ( alpha == 0 ) { + *outX = 0; + *transformX = 1; } - else { - *outX = GetColorId( color->r, color->g, color->b ); - *transformX = 0; - } -#else - // SDL 1 doesn't support RGBA colors. - *outX = GetColorId( color->r, color->g, color->b ); - *transformX = 0; -#endif - } - } - } - else if ( surface->format->BytesPerPixel == 3 ) { - image.resize( surface->w, surface->h ); - memset( image.transform(), 0, surface->w * surface->h ); - - const uint8_t * inY = reinterpret_cast( surface->pixels ); - uint8_t * outY = image.image(); - - const uint8_t * inYEnd = inY + surface->h * surface->pitch; - - for ( ; inY != inYEnd; inY += surface->pitch, outY += surface->w ) { - const uint8_t * inX = inY; - uint8_t * outX = outY; - const uint8_t * inXEnd = inX + surface->w * 3; - - for ( ; inX != inXEnd; inX += 3, ++outX ) { - *outX = GetColorId( *( inX + 2 ), *( inX + 1 ), *inX ); - } - } - } - else if ( surface->format->BytesPerPixel == 4 ) { - image.resize( surface->w, surface->h ); - image.reset(); - - const uint8_t * inY = reinterpret_cast( surface->pixels ); - uint8_t * outY = image.image(); - uint8_t * transformY = image.transform(); - - const uint8_t * inYEnd = inY + surface->h * surface->pitch; - - for ( ; inY != inYEnd; inY += surface->pitch, outY += surface->w, transformY += surface->w ) { - const uint8_t * inX = inY; - uint8_t * outX = outY; - uint8_t * transformX = transformY; - const uint8_t * inXEnd = inX + surface->w * 4; - - for ( ; inX != inXEnd; inX += 4, ++outX, ++transformX ) { - const uint8_t alpha = *( inX + 3 ); - if ( alpha < 255 ) { - if ( alpha == 0 ) { - *outX = 0; - *transformX = 1; - } - else if ( *inX == 0 && *( inX + 1 ) == 0 && *( inX + 2 ) == 0 ) { - *outX = 0; - *transformX = 2; - } - else { - *outX = GetColorId( *( inX + 2 ), *( inX + 1 ), *inX ); - *transformX = 0; - } + else if ( *inX == 0 && *( inX + 1 ) == 0 && *( inX + 2 ) == 0 ) { + *outX = 0; + *transformX = 2; } else { *outX = GetColorId( *( inX + 2 ), *( inX + 1 ), *inX ); *transformX = 0; } } + else { + *outX = GetColorId( *( inX + 2 ), *( inX + 1 ), *inX ); + *transformX = 0; + } } } - else { - return false; - } return true; } diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index 1947b7344..9a5c14c59 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -21,6 +21,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "localevent.h" + #include #include #include @@ -30,25 +32,19 @@ #include #include +#include +#include #include #include +#include #include #include +#include #include #include -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) - -#include -#include -#include -#include - -#endif - #include "audio.h" #include "image.h" -#include "localevent.h" #include "pal.h" #include "screen.h" #include "tools.h" @@ -241,7 +237,6 @@ namespace return SDLK_y; case fheroes2::Key::KEY_Z: return SDLK_z; -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) case fheroes2::Key::KEY_PRINT: return SDLK_PRINTSCREEN; case fheroes2::Key::KEY_KP_0: @@ -264,30 +259,6 @@ namespace return SDLK_KP_8; case fheroes2::Key::KEY_KP_9: return SDLK_KP_9; -#else - case fheroes2::Key::KEY_PRINT: - return SDLK_PRINT; - case fheroes2::Key::KEY_KP_0: - return SDLK_KP0; - case fheroes2::Key::KEY_KP_1: - return SDLK_KP1; - case fheroes2::Key::KEY_KP_2: - return SDLK_KP2; - case fheroes2::Key::KEY_KP_3: - return SDLK_KP3; - case fheroes2::Key::KEY_KP_4: - return SDLK_KP4; - case fheroes2::Key::KEY_KP_5: - return SDLK_KP5; - case fheroes2::Key::KEY_KP_6: - return SDLK_KP6; - case fheroes2::Key::KEY_KP_7: - return SDLK_KP7; - case fheroes2::Key::KEY_KP_8: - return SDLK_KP8; - case fheroes2::Key::KEY_KP_9: - return SDLK_KP9; -#endif case fheroes2::Key::KEY_KP_PERIOD: return SDLK_KP_PERIOD; case fheroes2::Key::KEY_KP_DIVIDE: @@ -537,7 +508,6 @@ namespace return 0; } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) std::set eventTypeStatus; void setEventProcessingState( const uint32_t eventType, const bool enable ) @@ -545,15 +515,6 @@ namespace eventTypeStatus.emplace( eventType ); SDL_EventState( eventType, ( enable ? SDL_ENABLE : SDL_IGNORE ) ); } -#else - std::set eventTypeStatus; - - void setEventProcessingState( const uint8_t eventType, const bool enable ) - { - eventTypeStatus.emplace( eventType ); - SDL_EventState( eventType, ( enable ? SDL_ENABLE : SDL_IGNORE ) ); - } -#endif } // Custom button mapping for Nintendo Switch @@ -587,11 +548,7 @@ namespace fheroes2 { const char * KeySymGetName( const Key key ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) return SDL_GetKeyName( static_cast( getSDLKey( key ) ) ); -#else - return SDL_GetKeyName( static_cast( getSDLKey( key ) ) ); -#endif } bool PressIntKey( uint32_t max, uint32_t & result ) @@ -699,7 +656,6 @@ LocalEvent::LocalEvent() , mouse_button( 0 ) {} -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) void LocalEvent::OpenController() { for ( int i = 0; i < SDL_NumJoysticks(); ++i ) { @@ -732,22 +688,6 @@ void LocalEvent::OpenTouchpad() } } -#else -void LocalEvent::OpenController() -{ - // Do nothing. -} -void LocalEvent::CloseController() -{ - // Do nothing. -} - -void OpenTouchpad() -{ - // Do nothing. -} -#endif - namespace { class ColorCycling @@ -895,7 +835,6 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool ResetModes( MOUSE_CLICKED ); ResetModes( MOUSE_WHEEL ); -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_WINDOWEVENT: @@ -994,49 +933,10 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool break; } } -#else - while ( SDL_PollEvent( &event ) ) { - switch ( event.type ) { - case SDL_ACTIVEEVENT: - if ( HandleActiveEvent( event.active ) ) { - renderRoi = { 0, 0, display.width(), display.height() }; - } - break; - case SDL_KEYDOWN: - case SDL_KEYUP: - HandleKeyboardEvent( event.key ); - break; - case SDL_MOUSEMOTION: - HandleMouseMotionEvent( event.motion ); - break; - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - HandleMouseButtonEvent( event.button ); - break; - case SDL_QUIT: - if ( allowExit ) { - // Try to perform clear exit to catch all memory leaks, for example. - return false; - } - break; - default: - // If this assertion blows up then we included an event type but we didn't add logic for it. - assert( eventTypeStatus.count( event.type ) == 0 ); - // This is a new event type which we do not handle. It might have been added in a newer version of SDL. - break; - } - - if ( SDL_BUTTON_WHEELDOWN == event.button.button || SDL_BUTTON_WHEELUP == event.button.button ) - break; - } -#endif - -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) if ( _gameController != nullptr ) { ProcessControllerAxisMotion(); } -#endif renderRoi = fheroes2::getBoundaryRect( renderRoi, _mouseCursorRenderArea ); @@ -1071,7 +971,6 @@ void LocalEvent::ResumeSounds() Audio::Unmute(); } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) void LocalEvent::HandleMouseWheelEvent( const SDL_MouseWheelEvent & wheel ) { SetModes( MOUSE_WHEEL ); @@ -1411,23 +1310,6 @@ void LocalEvent::HandleRenderDeviceResetEvent() display.resize( temp.width(), temp.height() ); fheroes2::Copy( temp, display ); } -#else -bool LocalEvent::HandleActiveEvent( const SDL_ActiveEvent & event ) -{ - if ( event.state & SDL_APPINPUTFOCUS ) { - if ( 0 == event.gain ) { - StopSounds(); - } - else { - ResumeSounds(); - - return true; - } - } - - return false; -} -#endif bool LocalEvent::MousePressLeft() const { @@ -1500,13 +1382,6 @@ void LocalEvent::HandleMouseButtonEvent( const SDL_MouseButtonEvent & button ) if ( modes & MOUSE_PRESSED ) switch ( button.button ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) -#else - case SDL_BUTTON_WHEELDOWN: - case SDL_BUTTON_WHEELUP: - mouse_pm = mouse_cu; - break; -#endif case SDL_BUTTON_LEFT: mouse_pl = mouse_cu; break; @@ -1524,14 +1399,6 @@ void LocalEvent::HandleMouseButtonEvent( const SDL_MouseButtonEvent & button ) } else // mouse button released switch ( button.button ) { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) -#else - case SDL_BUTTON_WHEELDOWN: - case SDL_BUTTON_WHEELUP: - mouse_rm = mouse_cu; - break; -#endif - case SDL_BUTTON_LEFT: mouse_rl = mouse_cu; break; @@ -1611,20 +1478,12 @@ bool LocalEvent::MouseClickRight( const fheroes2::Rect & rt ) bool LocalEvent::MouseWheelUp() const { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) return ( modes & MOUSE_WHEEL ) && mouse_wm.y > 0; -#else - return ( modes & MOUSE_PRESSED ) && SDL_BUTTON_WHEELUP == mouse_button; -#endif } bool LocalEvent::MouseWheelDn() const { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) return ( modes & MOUSE_WHEEL ) && mouse_wm.y < 0; -#else - return ( modes & MOUSE_PRESSED ) && SDL_BUTTON_WHEELDOWN == mouse_button; -#endif } int32_t LocalEvent::getCurrentKeyModifiers() @@ -1634,7 +1493,6 @@ int32_t LocalEvent::getCurrentKeyModifiers() void LocalEvent::setEventProcessingStates() { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) // The list below is based on event types which require >= SDL 2.0.5. Is there a reason why you want to compile with an older SDL version? #if !SDL_VERSION_ATLEAST( 2, 0, 5 ) #error Minimal supported SDL version is 2.0.5. @@ -1716,30 +1574,4 @@ void LocalEvent::setEventProcessingStates() // SDL_POLLSENTINEL is supported from SDL 2.0.? // We do not support custom user events as of now. setEventProcessingState( SDL_USEREVENT, false ); -#else - setEventProcessingState( SDL_ACTIVEEVENT, true ); - setEventProcessingState( SDL_KEYDOWN, true ); - setEventProcessingState( SDL_KEYUP, true ); - setEventProcessingState( SDL_MOUSEMOTION, true ); - setEventProcessingState( SDL_MOUSEBUTTONDOWN, true ); - setEventProcessingState( SDL_MOUSEBUTTONUP, true ); - // SDL 1 does not support joysticks and controllers. - setEventProcessingState( SDL_JOYAXISMOTION, false ); - setEventProcessingState( SDL_JOYBALLMOTION, false ); - setEventProcessingState( SDL_JOYHATMOTION, false ); - setEventProcessingState( SDL_JOYBUTTONDOWN, false ); - setEventProcessingState( SDL_JOYBUTTONUP, false ); - setEventProcessingState( SDL_QUIT, true ); - // TODO: verify why disabled processing of this event. - setEventProcessingState( SDL_SYSWMEVENT, false ); - // SDL_EVENT_RESERVEDA is not in use. - // SDL_EVENT_RESERVEDB is not in use. - // TODO: verify why disabled processing of this event. - setEventProcessingState( SDL_VIDEORESIZE, false ); - // TODO: verify why disabled processing of this event. - setEventProcessingState( SDL_VIDEOEXPOSE, false ); - // SDL_EVENT_RESERVED2 - SDL_EVENT_RESERVED7 are not in use. - // We do not support custom user events as of now. - setEventProcessingState( SDL_USEREVENT, false ); -#endif } diff --git a/src/engine/localevent.h b/src/engine/localevent.h index b8798758b..54ff38a09 100644 --- a/src/engine/localevent.h +++ b/src/engine/localevent.h @@ -32,12 +32,8 @@ #include #include -#include - -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #include #include -#endif #include "math_base.h" #include "timing.h" @@ -313,7 +309,6 @@ private: static void StopSounds(); static void ResumeSounds(); -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) void HandleMouseWheelEvent( const SDL_MouseWheelEvent & ); void HandleControllerAxisEvent( const SDL_ControllerAxisEvent & motion ); void HandleControllerButtonEvent( const SDL_ControllerButtonEvent & button ); @@ -324,10 +319,6 @@ private: static void HandleRenderDeviceResetEvent(); void ProcessControllerAxisMotion(); -#else - // Returns true if frame rendering is required. - static bool HandleActiveEvent( const SDL_ActiveEvent & event ); -#endif enum flag_t { @@ -383,7 +374,6 @@ private: double _emulatedPointerPosX = 0; double _emulatedPointerPosY = 0; -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) // bigger value corresponds to faster pointer movement speed with bigger stick axis values const double CONTROLLER_AXIS_SPEEDUP = 1.03; const double CONTROLLER_TRIGGER_CURSOR_SPEEDUP = 2.0; @@ -400,7 +390,6 @@ private: std::pair, std::optional> _fingerIds; // Is the two-finger gesture currently being processed bool _isTwoFingerGestureInProgress = false; -#endif }; #endif diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 2296b3f90..57effec94 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -29,21 +29,15 @@ #include #include -#include -#include -#include - -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #include #include #include #include #include #include +#include #include -#else -#include -#endif +#include #if defined( TARGET_PS_VITA ) #include @@ -142,8 +136,6 @@ namespace } } -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) - // Scaling is available only on SDL 2. std::set scaledResolutions; { @@ -179,7 +171,6 @@ namespace } resolutions.merge( scaledResolutions ); -#endif return resolutions; } @@ -414,7 +405,6 @@ namespace namespace { -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) class RenderCursor final : public fheroes2::Cursor { public: @@ -553,7 +543,6 @@ namespace RenderCursor() : _cursor( nullptr ) { - // SDL 2 handles mouse properly without any emulation. _emulation = false; const int returnCode = SDL_ShowCursor( _show ? SDL_ENABLE : SDL_DISABLE ); @@ -573,23 +562,6 @@ namespace } } }; -#else - // SDL 1 doesn't support hardware level cursor. - class RenderCursor final : public fheroes2::Cursor - { - public: - RenderCursor() = default; - - RenderCursor( const RenderCursor & ) = delete; - - RenderCursor & operator=( const RenderCursor & ) = delete; - - static RenderCursor * create() - { - return new RenderCursor; - } - }; -#endif } namespace @@ -806,7 +778,7 @@ namespace } } }; -#elif SDL_VERSION_ATLEAST( 2, 0, 0 ) +#else class RenderEngine final : public fheroes2::BaseRenderEngine, public BaseSDLRenderer { public: @@ -1319,218 +1291,6 @@ namespace return true; } - void _syncFullScreen() - { - if ( isFullScreen() != BaseRenderEngine::isFullScreen() ) { - BaseRenderEngine::toggleFullScreen(); - - assert( isFullScreen() == BaseRenderEngine::isFullScreen() ); - } - } - }; -#else - class RenderEngine final : public fheroes2::BaseRenderEngine, public BaseSDLRenderer - { - public: - RenderEngine( const RenderEngine & ) = delete; - - ~RenderEngine() override - { - clear(); - } - - RenderEngine & operator=( const RenderEngine & ) = delete; - - void toggleFullScreen() override - { - if ( _surface == nullptr ) { // nothing to render - BaseRenderEngine::toggleFullScreen(); - return; - } - - fheroes2::Display & display = fheroes2::Display::instance(); - if ( _surface->format->BitsPerPixel == 8 && _surface->pixels == display.image() ) { - if ( display.width() == _surface->w && display.height() == _surface->h ) { - linkRenderSurface( nullptr ); - memcpy( display.image(), _surface->pixels, static_cast( display.width() * display.height() ) ); - } - } - - const uint32_t flags = _surface->flags; - clear(); - - _surface = SDL_SetVideoMode( 0, 0, _bitDepth, flags ^ SDL_FULLSCREEN ); - if ( _surface == nullptr ) { - _surface = SDL_SetVideoMode( 0, 0, _bitDepth, flags ); - } - - _syncFullScreen(); - _createPalette(); - } - - bool isFullScreen() const override - { - if ( _surface == nullptr ) - return BaseRenderEngine::isFullScreen(); - - return ( ( _surface->flags & SDL_FULLSCREEN ) != 0 ); - } - - std::vector getAvailableResolutions() const override - { - static const std::vector filteredResolutions = []() { - std::set resolutionSet; - SDL_Rect ** modes = SDL_ListModes( nullptr, SDL_FULLSCREEN | SDL_HWSURFACE ); - if ( modes != nullptr && modes != reinterpret_cast( -1 ) ) { - for ( int i = 0; modes[i]; ++i ) { - resolutionSet.emplace( modes[i]->w, modes[i]->h ); - } - } - - resolutionSet = FilterResolutions( resolutionSet ); - - return std::vector{ resolutionSet.rbegin(), resolutionSet.rend() }; - }(); - - return filteredResolutions; - } - - void setTitle( const std::string & title ) override - { - SDL_WM_SetCaption( title.c_str(), nullptr ); - } - - void setIcon( const fheroes2::Image & icon ) override - { - SDL_Surface * surface = generateIconSurface( icon ); - if ( surface == nullptr ) - return; - - SDL_WM_SetIcon( surface, nullptr ); - - SDL_FreeSurface( surface ); - } - - static RenderEngine * create() - { - return new RenderEngine; - } - - protected: - RenderEngine() - : _surface( nullptr ) - , _bitDepth( 8 ) - { - // Do nothing. - } - - void render( const fheroes2::Display & display, const fheroes2::Rect & roi ) override - { - if ( _surface == nullptr ) // nothing to render on - return; - - copyImageToSurface( display, _surface, roi ); - - // Logically we should call SDL_UpdateRect but some systems have flickering effect with this function. - SDL_Flip( _surface ); - } - - void clear() override - { - linkRenderSurface( nullptr ); - - if ( _surface != nullptr ) { - SDL_FreeSurface( _surface ); - _surface = nullptr; - } - - _palette32Bit.clear(); - _palette8Bit.clear(); - } - - bool allocate( fheroes2::ResolutionInfo & resolutionInfo, bool isFullScreen ) override - { - clear(); - - const std::vector resolutions = getAvailableResolutions(); - assert( !resolutions.empty() ); - if ( !resolutions.empty() ) { - resolutionInfo = GetNearestResolution( resolutionInfo, resolutions ); - } - - uint32_t flags = renderFlags(); - if ( isFullScreen ) - flags |= SDL_FULLSCREEN; - - _surface = SDL_SetVideoMode( resolutionInfo.gameWidth, resolutionInfo.gameHeight, _bitDepth, flags ); - if ( _surface == nullptr ) { - return false; - } - - _syncFullScreen(); - - if ( _surface->w <= 0 || _surface->h <= 0 || _surface->w != resolutionInfo.gameWidth || _surface->h != resolutionInfo.gameHeight ) { - clear(); - return false; - } - - _createPalette(); - - return true; - } - - void updatePalette( const std::vector & colorIds ) override - { - if ( _surface == nullptr || colorIds.size() != 256 ) - return; - - generatePalette( colorIds, _surface ); - if ( _surface->format->BitsPerPixel == 8 ) { - SDL_SetPalette( _surface, SDL_LOGPAL | SDL_PHYSPAL, _palette8Bit.data(), 0, 256 ); - } - } - - bool isMouseCursorActive() const override - { - return ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == SDL_APPMOUSEFOCUS; - } - - private: - SDL_Surface * _surface; - int _bitDepth; - - uint32_t renderFlags() const - { -#if defined( _WIN32 ) - return SDL_HWSURFACE | SDL_HWPALETTE; -#else - return SDL_SWSURFACE; -#endif - } - - void _createPalette() - { - if ( _surface == nullptr ) - return; - - updatePalette( StandardPaletteIndexes() ); - - if ( _surface->format->BitsPerPixel == 8 ) { - if ( !SDL_MUSTLOCK( _surface ) ) { - // Copy the image from display buffer to SDL surface in case of fullscreen toggling - fheroes2::Display & display = fheroes2::Display::instance(); - if ( _surface->w == display.width() && _surface->h == display.height() ) { - memcpy( _surface->pixels, display.image(), static_cast( display.width() * display.height() ) ); - } - - // Display class doesn't have support for image pitch so we mustn't link display to surface if width is not divisible by 4. - if ( _surface->w % 4 == 0 ) { - linkRenderSurface( static_cast( _surface->pixels ) ); - } - } - } - } - void _syncFullScreen() { if ( isFullScreen() != BaseRenderEngine::isFullScreen() ) { diff --git a/src/engine/system.cpp b/src/engine/system.cpp index c30664985..5c0e4e4b1 100644 --- a/src/engine/system.cpp +++ b/src/engine/system.cpp @@ -59,7 +59,7 @@ #include -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) && defined( ANDROID ) +#if defined( ANDROID ) #include #include #endif diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index 045dfe03d..8b6b8c400 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -33,17 +33,9 @@ #include #include // IWYU pragma: keep #include -#include #if defined( _WIN32 ) - -#if SDL_VERSION_ATLEAST( 2, 0, 0 ) #include -#else -#define WIN32_LEAN_AND_MEAN -#include -#endif - #endif #include "agg.h" @@ -235,22 +227,10 @@ namespace }; } -// SDL1: this app is not linked against the SDLmain.lib, implement our own WinMain -#if defined( _WIN32 ) && !SDL_VERSION_ATLEAST( 2, 0, 0 ) -#undef main - -int main( int argc, char ** argv ); - -int WINAPI WinMain( HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, LPSTR /* pCmdLine */, int /* nCmdShow */ ) -{ - return main( __argc, __argv ); -} -#endif - int main( int argc, char ** argv ) { // SDL2main.lib converts argv to UTF-8, but this application expects ANSI, use the original argv -#if defined( _WIN32 ) && SDL_VERSION_ATLEAST( 2, 0, 0 ) +#if defined( _WIN32 ) assert( argc == __argc ); argv = __argv; diff --git a/src/tools/82m2wav-vs2019.vcxproj b/src/tools/82m2wav-vs2019.vcxproj index 046cdebbd..8968a7c2e 100644 --- a/src/tools/82m2wav-vs2019.vcxproj +++ b/src/tools/82m2wav-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/bin2txt-vs2019.vcxproj b/src/tools/bin2txt-vs2019.vcxproj index f75f3fdba..e358cfb88 100644 --- a/src/tools/bin2txt-vs2019.vcxproj +++ b/src/tools/bin2txt-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/extractor-vs2019.vcxproj b/src/tools/extractor-vs2019.vcxproj index c72625a5b..507d94bf3 100644 --- a/src/tools/extractor-vs2019.vcxproj +++ b/src/tools/extractor-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/h2dmgr-vs2019.vcxproj b/src/tools/h2dmgr-vs2019.vcxproj index 93bc629b7..ca6e4b280 100644 --- a/src/tools/h2dmgr-vs2019.vcxproj +++ b/src/tools/h2dmgr-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/icn2img-vs2019.vcxproj b/src/tools/icn2img-vs2019.vcxproj index 955d830fb..ce5bc8fb6 100644 --- a/src/tools/icn2img-vs2019.vcxproj +++ b/src/tools/icn2img-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/pal2img-vs2019.vcxproj b/src/tools/pal2img-vs2019.vcxproj index 1557dd3f6..9808aeaa9 100644 --- a/src/tools/pal2img-vs2019.vcxproj +++ b/src/tools/pal2img-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/til2img-vs2019.vcxproj b/src/tools/til2img-vs2019.vcxproj index 8075d5271..6b9554e93 100644 --- a/src/tools/til2img-vs2019.vcxproj +++ b/src/tools/til2img-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - - diff --git a/src/tools/xmi2midi-vs2019.vcxproj b/src/tools/xmi2midi-vs2019.vcxproj index b8febdd12..2894a1465 100644 --- a/src/tools/xmi2midi-vs2019.vcxproj +++ b/src/tools/xmi2midi-vs2019.vcxproj @@ -1,10 +1,6 @@  - - Debug-SDL1 - Win32 - Debug-SDL2 Win32 @@ -13,18 +9,6 @@ Debug-SDL2 x64 - - Release-SDL1 - Win32 - - - Debug-SDL1 - x64 - - - Release-SDL1 - x64 - Release-SDL2 Win32 @@ -53,18 +37,10 @@ - - - - - - - -