From 70786f4963d08df41d69a54a718094a7c8cd6714 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 2 Feb 2023 22:46:31 +0300 Subject: [PATCH 1/4] lib: remove unused header This an unused header with empty class. Just remove it. --- cmake_modules/VCMI_lib.cmake | 2 -- lib/VCMI_lib.cbp | 1 - lib/abilities/Ability.h | 23 ----------------------- 3 files changed, 26 deletions(-) delete mode 100644 lib/abilities/Ability.h diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index dfdb844f6..fd3e66a38 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -239,8 +239,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/../include/vcmi/Environment.h ${MAIN_LIB_DIR}/../include/vcmi/Services.h - ${MAIN_LIB_DIR}/abilities/Ability.h - ${MAIN_LIB_DIR}/battle/AccessibilityInfo.h ${MAIN_LIB_DIR}/battle/BattleAction.h ${MAIN_LIB_DIR}/battle/BattleAttackInfo.h diff --git a/lib/VCMI_lib.cbp b/lib/VCMI_lib.cbp index 97d17da8d..bb73fdb73 100644 --- a/lib/VCMI_lib.cbp +++ b/lib/VCMI_lib.cbp @@ -281,7 +281,6 @@ - diff --git a/lib/abilities/Ability.h b/lib/abilities/Ability.h deleted file mode 100644 index 14bf3d54e..000000000 --- a/lib/abilities/Ability.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Ability.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -VCMI_LIB_NAMESPACE_BEGIN - -namespace abilities -{ - -class DLL_LINKAGE Ability -{ - -}; - -} - -VCMI_LIB_NAMESPACE_END From cffdabf48ee0d6cc2fbdb0428067364b5690d97e Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 2 Feb 2023 23:40:00 +0300 Subject: [PATCH 2/4] lib: replace SDL usage to Boost one It is safer and header-only, and can be removed after C++23 is accepted. There is no need for SDL in non-GUI. --- CMakeLists.txt | 12 ++++++++++++ cmake_modules/VCMI_lib.cmake | 1 - lib/filesystem/CBinaryReader.cpp | 4 +--- lib/vcmi_endian.h | 11 +++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aec633ff8..423f47817 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,18 @@ set(CMAKE_XCODE_ATTRIBUTE_MARKETING_VERSION ${APP_SHORT_VERSION}) set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO) set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] YES) +#Check for endian +if(${CMAKE_VERSION} VERSION_LESS "3.20.0") + include(TestBigEndian) + test_big_endian(VCMI_ENDIAN_BIG) + if(VCMI_ENDIAN_BIG) + add_definitions(-DVCMI_ENDIAN_BIG) + endif() +elseif(${CMAKE_CXX_BYTE_ORDER} EQUAL "BIG_ENDIAN") + add_definitions(-DVCMI_ENDIAN_BIG) +endif() + + if(ENABLE_LAUNCHER) add_definitions(-DENABLE_LAUNCHER) endif() diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index fd3e66a38..d9306edab 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -475,7 +475,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) PUBLIC ${MAIN_LIB_DIR}/.. PUBLIC ${MAIN_LIB_DIR}/../include PUBLIC ${MAIN_LIB_DIR} - PRIVATE ${SDL2_INCLUDE_DIR} ) if(WIN32) diff --git a/lib/filesystem/CBinaryReader.cpp b/lib/filesystem/CBinaryReader.cpp index a3c7fc706..7385a903d 100644 --- a/lib/filesystem/CBinaryReader.cpp +++ b/lib/filesystem/CBinaryReader.cpp @@ -10,14 +10,12 @@ #include "StdInc.h" #include "CBinaryReader.h" -//FIXME:library file depends on SDL - make cause troubles -#include #include "CInputStream.h" #include "../CGeneralTextHandler.h" VCMI_LIB_NAMESPACE_BEGIN -#if SDL_BYTEORDER == SDL_BIG_ENDIAN +#ifdef VCMI_ENDIAN_BIG template CData readLE(CData data) { diff --git a/lib/vcmi_endian.h b/lib/vcmi_endian.h index 2686261f8..e270b8eec 100644 --- a/lib/vcmi_endian.h +++ b/lib/vcmi_endian.h @@ -9,8 +9,7 @@ */ #pragma once -//FIXME:library file depends on SDL - may cause troubles -#include +#include //FIXME: use std::byteswap in C++23 VCMI_LIB_NAMESPACE_BEGIN @@ -45,15 +44,15 @@ static inline ui32 read_unaligned_u32(const void *p) return v->val; } -#define read_le_u16(p) (SDL_SwapLE16(read_unaligned_u16(p))) -#define read_le_u32(p) (SDL_SwapLE32(read_unaligned_u32(p))) +#define read_le_u16(p) (boost::endian::native_to_little(read_unaligned_u16(p))) +#define read_le_u32(p) (boost::endian::native_to_little(read_unaligned_u32(p))) #else #warning UB: unaligned memory access -#define read_le_u16(p) (SDL_SwapLE16(* reinterpret_cast(p))) -#define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast(p))) +#define read_le_u16(p) (boost::endian::native_to_little(* reinterpret_cast(p))) +#define read_le_u32(p) (boost::endian::native_to_little(* reinterpret_cast(p))) #define PACKED_STRUCT_BEGIN #define PACKED_STRUCT_END From 88ef83db530bfb0277335f7cd95ce64e3edb3c8b Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 3 Feb 2023 00:32:44 +0300 Subject: [PATCH 3/4] client: remove SDL_BYTEORDER usage Make use of CMake endian checking in this places too. --- client/CMT.cpp | 2 +- client/render/CBitmapHandler.cpp | 2 +- client/renderSDL/SDL_PixelAccess.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index a7566075e..e11c76b17 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -839,7 +839,7 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen, int displayIn } - #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + #ifdef VCMI_ENDIAN_BIG int bmask = 0xff000000; int gmask = 0x00ff0000; int rmask = 0x0000ff00; diff --git a/client/render/CBitmapHandler.cpp b/client/render/CBitmapHandler.cpp index 1d096fe08..c18612e8f 100644 --- a/client/render/CBitmapHandler.cpp +++ b/client/render/CBitmapHandler.cpp @@ -81,7 +81,7 @@ SDL_Surface * BitmapHandler::loadH3PCX(ui8 * pcx, size_t size) } else { -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) +#ifdef VCMI_ENDIAN_BIG int bmask = 0xff0000; int gmask = 0x00ff00; int rmask = 0x0000ff; diff --git a/client/renderSDL/SDL_PixelAccess.h b/client/renderSDL/SDL_PixelAccess.h index 6ddfc2e83..f61946ba9 100644 --- a/client/renderSDL/SDL_PixelAccess.h +++ b/client/renderSDL/SDL_PixelAccess.h @@ -68,7 +68,7 @@ namespace Channels static channel_empty a; }; -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) +#ifdef VCMI_ENDIAN_BIG template<> struct px<4> From 4feab6986754c639b4dea4e4c06e088940f1b155 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 3 Feb 2023 00:39:44 +0300 Subject: [PATCH 4/4] mapeditor: use vcmi_endian.h There is no need to redefine this functions, let's use shared implementation --- mapeditor/Animation.cpp | 1 + mapeditor/BitmapHandler.cpp | 1 + mapeditor/BitmapHandler.h | 4 ---- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mapeditor/Animation.cpp b/mapeditor/Animation.cpp index b62415cdc..20632c9d0 100644 --- a/mapeditor/Animation.cpp +++ b/mapeditor/Animation.cpp @@ -15,6 +15,7 @@ #include "BitmapHandler.h" +#include "../lib/vcmi_endian.h" #include "../lib/filesystem/Filesystem.h" #include "../lib/filesystem/ISimpleResourceLoader.h" #include "../lib/JsonNode.h" diff --git a/mapeditor/BitmapHandler.cpp b/mapeditor/BitmapHandler.cpp index d1b9dd5ce..a3cecee14 100644 --- a/mapeditor/BitmapHandler.cpp +++ b/mapeditor/BitmapHandler.cpp @@ -14,6 +14,7 @@ #include "BitmapHandler.h" #include "../lib/filesystem/Filesystem.h" +#include "../lib/vcmi_endian.h" #include #include diff --git a/mapeditor/BitmapHandler.h b/mapeditor/BitmapHandler.h index ee2967e8a..48badd4a0 100644 --- a/mapeditor/BitmapHandler.h +++ b/mapeditor/BitmapHandler.h @@ -8,10 +8,6 @@ * */ #pragma once -//code is copied from vcmiclient/CBitmapHandler.h with minimal changes - -#define read_le_u16(p) (* reinterpret_cast(p)) -#define read_le_u32(p) (* reinterpret_cast(p)) #include