Drop SDL1 support (#7619)

This commit is contained in:
Oleg Derevenetz
2023-08-24 09:18:35 +08:00
committed by GitHub
parent 76ec8e2bb5
commit 860daa412c
49 changed files with 180 additions and 1126 deletions
+1 -1
View File
@@ -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
+2 -16
View File
@@ -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
+1 -1
View File
@@ -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) \
+3 -95
View File
@@ -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
+1 -19
View File
@@ -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
+1 -1
View File
@@ -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 \
+3 -3
View File
@@ -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
+2 -3
View File
@@ -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)
+1 -2
View File
@@ -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
+1 -2
View File
@@ -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
-17
View File
@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)packages\sdl1\include\;$(MSBuildThisFileDirectory)packages\sdl1\include\SDL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(MSBuildThisFileDirectory)packages\sdl1\lib\$(PlatformTarget);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>SDL.lib;SDL_mixer.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>xcopy /Y /Q "$(MSBuildThisFileDirectory)packages\sdl1\lib\$(PlatformTarget)\*.dll" "$(OutDir)"
xcopy /Y /Q "$(MSBuildThisFileDirectory)packages\sdl1\lib\$(PlatformTarget)\*.pdb" "$(OutDir)"
%(Command)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
</Project>
+3 -4
View File
@@ -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.
<a name="android"></a>
### Android
+7 -12
View File
@@ -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
+1 -2
View File
@@ -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
```
+6 -11
View File
@@ -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
+2 -2
View File
@@ -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.
-26
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,21 +37,11 @@
<Import Project="VisualStudio\fheroes2\common.props" />
<Import Project="VisualStudio\fheroes2\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="VisualStudio\Debug.props" />
<Import Project="VisualStudio\SDL1.props" />
<Import Project="VisualStudio\fheroes2\Debug.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="VisualStudio\Debug.props" />
<Import Project="VisualStudio\SDL2.props" />
<Import Project="VisualStudio\fheroes2\Debug.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="VisualStudio\Release.props" />
<Import Project="VisualStudio\SDL1.props" />
<Import Project="VisualStudio\fheroes2\Release.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="VisualStudio\Release.props" />
<Import Project="VisualStudio\SDL2.props" />
+1 -1
View File
@@ -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.
+24
View File
@@ -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
+24
View File
@@ -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
-4
View File
@@ -1,4 +0,0 @@
#!/bin/bash
# Install SDL 1.2
sudo apt-get install -y libsdl1.2debian libsdl-image1.2 libsdl-mixer1.2
-4
View File
@@ -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
-4
View File
@@ -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
-4
View File
@@ -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
+1 -1
View File
@@ -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.
+29
View File
@@ -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
-17
View File
@@ -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
-17
View File
@@ -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
+6 -8
View File
@@ -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}"
+1 -15
View File
@@ -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)
+1 -9
View File
@@ -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
-4
View File
@@ -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
+2 -3
View File
@@ -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
$<$<BOOL:${SDL2MAIN_FOUND}>:${SDL2MAIN_LIBRARY}>
${${USE_SDL_VERSION}MAIN_LIBRARY}
${${USE_SDL_VERSION}_LIBRARY}
${${USE_SDL_VERSION}_MIXER_LIBRARIES}
$<$<BOOL:${ENABLE_IMAGE}>:${${USE_SDL_VERSION}_IMAGE_LIBRARIES}>
-17
View File
@@ -42,7 +42,6 @@
#include <SDL_mixer.h>
#include <SDL_rwops.h>
#include <SDL_stdinc.h>
#include <SDL_version.h>
#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;
+3 -17
View File
@@ -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 <cassert>
#include <cstdint>
#include <stdexcept>
#include <SDL.h>
#include <SDL_error.h>
#include <SDL_version.h>
#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();
+42 -142
View File
@@ -29,22 +29,15 @@
#include <vector>
#include <SDL_error.h>
#include <SDL_pixels.h>
#include <SDL_stdinc.h>
#include <SDL_surface.h>
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <SDL_pixels.h>
#include <SDL_surface.h>
#else
#include <SDL_video.h>
#endif
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#if defined( WITH_IMAGE )
#define ENABLE_PNG
#include <SDL_image.h>
#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<SDL_Surface, std::function<void( SDL_Surface * )>> surface( nullptr, SDL_FreeSurface );
{
std::unique_ptr<SDL_Surface, std::function<void( SDL_Surface * )>> loadedSurface( nullptr, SDL_FreeSurface );
std::unique_ptr<SDL_Surface, std::function<void( SDL_Surface * )>> 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<SDL_PixelFormat, std::function<void( SDL_PixelFormat * )>> 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<SDL_PixelFormat, std::function<void( SDL_PixelFormat * )>> 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<uint8_t *>( surface->pixels );
uint8_t * outY = image.image();
uint8_t * transformY = image.transform();
const uint8_t * inY = reinterpret_cast<uint8_t *>( 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<uint8_t *>( 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<uint8_t *>( 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;
}
+6 -174
View File
@@ -21,6 +21,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "localevent.h"
#include <cassert>
#include <cmath>
#include <cstdlib>
@@ -30,25 +32,19 @@
#include <vector>
#include <SDL_events.h>
#include <SDL_gamecontroller.h>
#include <SDL_hints.h>
#include <SDL_joystick.h>
#include <SDL_keyboard.h>
#include <SDL_keycode.h>
#include <SDL_mouse.h>
#include <SDL_timer.h>
#include <SDL_touch.h>
#include <SDL_version.h>
#include <SDL_video.h>
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <SDL_gamecontroller.h>
#include <SDL_hints.h>
#include <SDL_keycode.h>
#include <SDL_touch.h>
#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<uint32_t> 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<uint8_t> 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<SDL_Keycode>( getSDLKey( key ) ) );
#else
return SDL_GetKeyName( static_cast<SDLKey>( 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
}
-11
View File
@@ -32,12 +32,8 @@
#include <utility>
#include <SDL_events.h>
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <SDL_gamecontroller.h>
#include <SDL_touch.h>
#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<SDL_FingerID>, std::optional<SDL_FingerID>> _fingerIds;
// Is the two-finger gesture currently being processed
bool _isTwoFingerGestureInProgress = false;
#endif
};
#endif
+3 -243
View File
@@ -29,21 +29,15 @@
#include <utility>
#include <SDL_error.h>
#include <SDL_stdinc.h>
#include <SDL_version.h>
#include <SDL_video.h>
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <SDL_events.h>
#include <SDL_hints.h>
#include <SDL_mouse.h>
#include <SDL_pixels.h>
#include <SDL_rect.h>
#include <SDL_render.h>
#include <SDL_stdinc.h>
#include <SDL_surface.h>
#else
#include <SDL_active.h>
#endif
#include <SDL_video.h>
#if defined( TARGET_PS_VITA )
#include <vita2d.h>
@@ -142,8 +136,6 @@ namespace
}
}
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
// Scaling is available only on SDL 2.
std::set<fheroes2::ResolutionInfo> 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<size_t>( 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<fheroes2::ResolutionInfo> getAvailableResolutions() const override
{
static const std::vector<fheroes2::ResolutionInfo> filteredResolutions = []() {
std::set<fheroes2::ResolutionInfo> resolutionSet;
SDL_Rect ** modes = SDL_ListModes( nullptr, SDL_FULLSCREEN | SDL_HWSURFACE );
if ( modes != nullptr && modes != reinterpret_cast<SDL_Rect **>( -1 ) ) {
for ( int i = 0; modes[i]; ++i ) {
resolutionSet.emplace( modes[i]->w, modes[i]->h );
}
}
resolutionSet = FilterResolutions( resolutionSet );
return std::vector<fheroes2::ResolutionInfo>{ 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<fheroes2::ResolutionInfo> 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<uint8_t> & 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<size_t>( 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<uint8_t *>( _surface->pixels ) );
}
}
}
}
void _syncFullScreen()
{
if ( isFullScreen() != BaseRenderEngine::isFullScreen() ) {
+1 -1
View File
@@ -59,7 +59,7 @@
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) && defined( ANDROID )
#if defined( ANDROID )
#include <SDL_error.h>
#include <SDL_system.h>
#endif
+1 -21
View File
@@ -33,17 +33,9 @@
#include <SDL_events.h>
#include <SDL_main.h> // IWYU pragma: keep
#include <SDL_mouse.h>
#include <SDL_version.h>
#if defined( _WIN32 )
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#include <cassert>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#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;
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\82m2wav\common.props" />
<Import Project="..\..\VisualStudio\tools\82m2wav\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\bin2txt\common.props" />
<Import Project="..\..\VisualStudio\tools\bin2txt\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\extractor\common.props" />
<Import Project="..\..\VisualStudio\tools\extractor\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\h2dmgr\common.props" />
<Import Project="..\..\VisualStudio\tools\h2dmgr\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\icn2img\common.props" />
<Import Project="..\..\VisualStudio\tools\icn2img\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\pal2img\common.props" />
<Import Project="..\..\VisualStudio\tools\pal2img\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\til2img\common.props" />
<Import Project="..\..\VisualStudio\tools\til2img\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
-24
View File
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-SDL1|Win32">
<Configuration>Debug-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL2|Win32">
<Configuration>Debug-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -13,18 +9,6 @@
<Configuration>Debug-SDL2</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|Win32">
<Configuration>Release-SDL1</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug-SDL1|x64">
<Configuration>Debug-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL1|x64">
<Configuration>Release-SDL1</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release-SDL2|Win32">
<Configuration>Release-SDL2</Configuration>
<Platform>Win32</Platform>
@@ -53,18 +37,10 @@
<Import Project="..\..\VisualStudio\tools\xmi2midi\common.props" />
<Import Project="..\..\VisualStudio\tools\xmi2midi\sources.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Debug-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Debug.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL1'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL1.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)'=='Release-SDL2'" Label="PropertySheets">
<Import Project="..\..\VisualStudio\Release.props" />
<Import Project="..\..\VisualStudio\SDL2.props" />