From b100a8d2de5a5196e2177bfbca03b855b053e34a Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:30:09 -0300 Subject: [PATCH 1/8] allegro: adjust for mingw build --- libsrc/allegro/CMakeLists.txt | 3 ++- libsrc/allegro/include/allegro/internal/alconfig.h | 5 ++++- libsrc/allegro/include/allegro/platform/almsvc.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libsrc/allegro/CMakeLists.txt b/libsrc/allegro/CMakeLists.txt index eefc944a1a5..4ffe8ecfd79 100644 --- a/libsrc/allegro/CMakeLists.txt +++ b/libsrc/allegro/CMakeLists.txt @@ -162,6 +162,7 @@ endif() if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") # WIN32 is set by CMake for any Windows platform + set(ALLEGRO_WINDOWS TRUE) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(ALLEGRO_UNIX TRUE) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android") @@ -238,7 +239,7 @@ set(ALLEGRO_NO_ASM 1) set(PLATFORM_SOURCES) -if(ALLEGRO_MSVC) +if(ALLEGRO_WINDOWS) list(APPEND PLATFORM_SOURCES ${ALLEGRO_SRC_WIN_FILES}) else() # non-windows platforms are use unixy/posix file handling and have no gdi diff --git a/libsrc/allegro/include/allegro/internal/alconfig.h b/libsrc/allegro/include/allegro/internal/alconfig.h index 3a66a3f5324..594adc62df2 100644 --- a/libsrc/allegro/include/allegro/internal/alconfig.h +++ b/libsrc/allegro/include/allegro/internal/alconfig.h @@ -55,12 +55,15 @@ #define ALLEGRO_UNIX #elif defined(__FreeBSD__) #define ALLEGRO_UNIX +#elif defined(__MINGW32__) + #define ALLEGRO_MINGW + #define ALLEGRO_WINDOWS #endif /* include platform-specific stuff */ #ifndef SCAN_EXPORT - #if defined ALLEGRO_MSVC + #if defined ALLEGRO_MSVC || defined(ALLEGRO_MINGW) #include "allegro/platform/almsvc.h" #elif defined ALLEGRO_MACOSX #include "allegro/platform/alosxcfg.h" diff --git a/libsrc/allegro/include/allegro/platform/almsvc.h b/libsrc/allegro/include/allegro/platform/almsvc.h index 0e865d9c93b..7347abdce23 100644 --- a/libsrc/allegro/include/allegro/platform/almsvc.h +++ b/libsrc/allegro/include/allegro/platform/almsvc.h @@ -71,7 +71,7 @@ #define INLINE __inline #define LONG_LONG __int64 -#if (_MSC_VER >= 1600) +#if defined(ALLEGRO_MINGW) || (_MSC_VER >= 1600) #define ALLEGRO_HAVE_STDINT_H #else #define int64_t signed __int64 From 92f6ff3b6cc2afe849e2d9af82abf8b724c20c30 Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:34:07 -0300 Subject: [PATCH 2/8] Plugins: fix AGSBlend min/max conflict in Windows.h in MinGW --- Plugins/agsblend/AGSBlend.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/Plugins/agsblend/AGSBlend.cpp b/Plugins/agsblend/AGSBlend.cpp index 8a7417185dc..dfb9e14afeb 100644 --- a/Plugins/agsblend/AGSBlend.cpp +++ b/Plugins/agsblend/AGSBlend.cpp @@ -16,14 +16,11 @@ #define MIN_EDITOR_VERSION 1 #define MIN_ENGINE_VERSION 3 -#if AGS_PLATFORM_OS_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include -#endif #include #include #include +#include #if !defined(BUILTIN_PLUGINS) #define THIS_IS_THE_PLUGIN @@ -42,18 +39,13 @@ typedef unsigned char uint8; #define DEFAULT_RGB_B_SHIFT_32 0 #define DEFAULT_RGB_A_SHIFT_32 24 -#if !AGS_PLATFORM_OS_WINDOWS -#define min(x,y) (((x) < (y)) ? (x) : (y)) -#define max(x,y) (((x) > (y)) ? (x) : (y)) -#endif - #define abs(a) ((a)<0 ? -(a) : (a)) #define ChannelBlend_Normal(B,L) ((uint8)(B)) #define ChannelBlend_Lighten(B,L) ((uint8)((L > B) ? L:B)) #define ChannelBlend_Darken(B,L) ((uint8)((L > B) ? B:L)) #define ChannelBlend_Multiply(B,L) ((uint8)((B * L) / 255)) #define ChannelBlend_Average(B,L) ((uint8)((B + L) / 2)) -#define ChannelBlend_Add(B,L) ((uint8)(min(255, (B + L)))) +#define ChannelBlend_Add(B,L) ((uint8)(std::min(255, (B + L)))) #define ChannelBlend_Subtract(B,L) ((uint8)((B + L < 255) ? 0:(B + L - 255))) #define ChannelBlend_Difference(B,L) ((uint8)(abs(B - L))) #define ChannelBlend_Negation(B,L) ((uint8)(255 - abs(255 - B - L))) @@ -62,17 +54,17 @@ typedef unsigned char uint8; #define ChannelBlend_Overlay(B,L) ((uint8)((L < 128) ? (2 * B * L / 255):(255 - 2 * (255 - B) * (255 - L) / 255))) #define ChannelBlend_SoftLight(B,L) ((uint8)((L < 128)?(2*((B>>1)+64))*((float)L/255):(255-(2*(255-((B>>1)+64))*(float)(255-L)/255)))) #define ChannelBlend_HardLight(B,L) (ChannelBlend_Overlay(L,B)) -#define ChannelBlend_ColorDodge(B,L) ((uint8)((L == 255) ? L:min(255, ((B << 8 ) / (255 - L))))) -#define ChannelBlend_ColorBurn(B,L) ((uint8)((L == 0) ? L:max(0, (255 - ((255 - B) << 8 ) / L)))) +#define ChannelBlend_ColorDodge(B,L) ((uint8)((L == 255) ? L:std::min(255, ((B << 8 ) / (255 - L))))) +#define ChannelBlend_ColorBurn(B,L) ((uint8)((L == 0) ? L:std::max(0, (255 - ((255 - B) << 8 ) / L)))) #define ChannelBlend_LinearDodge(B,L)(ChannelBlend_Add(B,L)) #define ChannelBlend_LinearBurn(B,L) (ChannelBlend_Subtract(B,L)) #define ChannelBlend_LinearLight(B,L)((uint8)(L < 128)?ChannelBlend_LinearBurn(B,(2 * L)):ChannelBlend_LinearDodge(B,(2 * (L - 128)))) #define ChannelBlend_VividLight(B,L) ((uint8)(L < 128)?ChannelBlend_ColorBurn(B,(2 * L)):ChannelBlend_ColorDodge(B,(2 * (L - 128)))) #define ChannelBlend_PinLight(B,L) ((uint8)(L < 128)?ChannelBlend_Darken(B,(2 * L)):ChannelBlend_Lighten(B,(2 * (L - 128)))) #define ChannelBlend_HardMix(B,L) ((uint8)((ChannelBlend_VividLight(B,L) < 128) ? 0:255)) -#define ChannelBlend_Reflect(B,L) ((uint8)((L == 255) ? L:min(255, (B * B / (255 - L))))) +#define ChannelBlend_Reflect(B,L) ((uint8)((L == 255) ? L:std::min(255, (B * B / (255 - L))))) #define ChannelBlend_Glow(B,L) (ChannelBlend_Reflect(L,B)) -#define ChannelBlend_Phoenix(B,L) ((uint8)(min(B,L) - max(B,L) + 255)) +#define ChannelBlend_Phoenix(B,L) ((uint8)(std::min(B,L) - std::max(B,L) + 255)) #define ChannelBlend_Alpha(B,L,O) ((uint8)(O * B + (1 - O) * L)) #define ChannelBlend_AlphaF(B,L,F,O) (ChannelBlend_Alpha(F(B,L),B,O)) @@ -80,6 +72,10 @@ typedef unsigned char uint8; #pragma endregion #if AGS_PLATFORM_OS_WINDOWS && !defined(BUILTIN_PLUGINS) +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include + // The standard Windows DLL entry point BOOL APIENTRY DllMain( HANDLE hModule, @@ -238,10 +234,10 @@ int HighPass(int sprite, int threshold){ int srcr = getb32(srclongbuffer[y][x]); int srcg = getg32(srclongbuffer[y][x]); int srcb = getr32(srclongbuffer[y][x]); - int tempmaxim = max(srcr, srcg); - int maxim = max(tempmaxim, srcb); - int tempmin = min( srcr, srcg); - int minim = min( srcb, tempmin); + int tempmaxim = std::max(srcr, srcg); + int maxim = std::max(tempmaxim, srcb); + int tempmin = std::min( srcr, srcg); + int minim = std::min( srcb, tempmin); int light = (maxim + minim) /2 ; if (light < threshold) srclongbuffer[y][x] = makeacol32(0,0,0,0); @@ -874,7 +870,7 @@ int DrawAlpha(int destination, int sprite, int x, int y, int trans) } -#if AGS_PLATFORM_OS_WINDOWS +#if AGS_PLATFORM_OS_WINDOWS && !defined(BUILTIN_PLUGINS) //============================================================================== From e4440d804984313d858e10c68a76e07caaeae11a Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:34:29 -0300 Subject: [PATCH 3/8] Common: add AGS_PLATFORM_WINDOWS_MINGW --- Common/core/platform.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Common/core/platform.h b/Common/core/platform.h index a5545c091ad..73158d72af2 100644 --- a/Common/core/platform.h +++ b/Common/core/platform.h @@ -123,6 +123,12 @@ #error "Unknown platform" #endif +#if defined(__MINGW32__) +#define AGS_PLATFORM_WINDOWS_MINGW (1) +#else +#define AGS_PLATFORM_WINDOWS_MINGW (0) +#endif + #if defined(_DEBUG) #define AGS_PLATFORM_DEBUG (1) #elif ! defined(NDEBUG) From bd71a5eac7c5a1b8a4ad764fd9f87eb2dac5e68d Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:35:26 -0300 Subject: [PATCH 4/8] Engine: remove unused gameux.h from acplwin.cpp --- Engine/platform/windows/acplwin.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Engine/platform/windows/acplwin.cpp b/Engine/platform/windows/acplwin.cpp index 56b2f1ae136..6092797af32 100644 --- a/Engine/platform/windows/acplwin.cpp +++ b/Engine/platform/windows/acplwin.cpp @@ -20,7 +20,6 @@ #include "platform/windows/windows.h" #include #include -#include #include #include "platform/base/agsplatformdriver.h" From 5a6be85a27793993ed6c960922ec7f10b35e19be Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:37:04 -0300 Subject: [PATCH 5/8] Engine: fix winsetup build error in MinGW using cast --- Engine/platform/windows/setup/winsetup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/platform/windows/setup/winsetup.cpp b/Engine/platform/windows/setup/winsetup.cpp index 97bbeee7101..2962f7a5c82 100644 --- a/Engine/platform/windows/setup/winsetup.cpp +++ b/Engine/platform/windows/setup/winsetup.cpp @@ -882,9 +882,9 @@ void WinSetupDialog::OnGfxModeUpdate() DWORD_PTR sel = GetCurItemData(_hGfxModeList); switch (sel) { - case kGfxMode_Desktop: + case static_cast(kGfxMode_Desktop): _winCfg.FsSetup = WindowSetup(_desktopSize, kWnd_Fullscreen); break; - case kGfxMode_GameRes: + case static_cast(kGfxMode_GameRes): _winCfg.FsSetup = WindowSetup(_winCfg.GameResolution, kWnd_Fullscreen); break; default: { From 9884cabbbb1cf09e9828e53647fc9c5f255e86e9 Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:41:31 -0300 Subject: [PATCH 6/8] Engine: fix util/library MinGW build error on void* cast this cast is not required on MSVC. --- Engine/util/library_windows.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Engine/util/library_windows.h b/Engine/util/library_windows.h index bf648ed6d79..3fed79ca9f0 100644 --- a/Engine/util/library_windows.h +++ b/Engine/util/library_windows.h @@ -15,6 +15,7 @@ #define __AGS_EE_UTIL__LIBRARY_WINDOWS_H #include +#include "core/platform.h" #include "debug/out.h" #include "platform/windows/winapi_exclusive.h" #include "util/path.h" @@ -103,7 +104,7 @@ class WindowsLibrary final : public BaseLibrary { if (!_library) return nullptr; - return GetProcAddress(_library, fn_name.GetCStr()); + return reinterpret_cast(GetProcAddress(_library, fn_name.GetCStr())); } private: From 3e6752d82758fa283e12bab00cccbbbc705b284e Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:45:23 -0300 Subject: [PATCH 7/8] Engine: disable custom exception handling in MinGW `__except` is not supported on mingw and will require a different code for exception handling. I found working code but it used an undocumented nt api, so this is better to research with calm. --- Engine/main/main.cpp | 4 ++-- Engine/platform/windows/win_ex_handling.cpp | 3 ++- Engine/platform/windows/win_ex_handling.h | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Engine/main/main.cpp b/Engine/main/main.cpp index ec20b7c1f9a..d42e9b0cdb8 100644 --- a/Engine/main/main.cpp +++ b/Engine/main/main.cpp @@ -43,7 +43,7 @@ #include "platform/windows/win_ex_handling.h" #endif -#if AGS_PLATFORM_OS_WINDOWS && !AGS_PLATFORM_DEBUG +#if AGS_PLATFORM_OS_WINDOWS && (!AGS_PLATFORM_DEBUG) && !AGS_PLATFORM_WINDOWS_MINGW #define USE_CUSTOM_EXCEPTION_HANDLER #endif @@ -366,7 +366,7 @@ static int main_process_cmdline(ConfigTree &cfg, int argc, char *argv[]) int ags_entry_point(int argc, char *argv[]) { main_init(argc, argv); -#if AGS_PLATFORM_OS_WINDOWS +#if AGS_PLATFORM_OS_WINDOWS && !AGS_PLATFORM_WINDOWS_MINGW setup_malloc_handling(); #endif debug_flags=0; diff --git a/Engine/platform/windows/win_ex_handling.cpp b/Engine/platform/windows/win_ex_handling.cpp index 3ed36df889b..688ce8829aa 100644 --- a/Engine/platform/windows/win_ex_handling.cpp +++ b/Engine/platform/windows/win_ex_handling.cpp @@ -13,7 +13,8 @@ //============================================================================= #include "core/platform.h" -#if AGS_PLATFORM_OS_WINDOWS +// TODO: port exception handling to mingw +#if AGS_PLATFORM_OS_WINDOWS && !AGS_PLATFORM_WINDOWS_MINGW #include #include #include diff --git a/Engine/platform/windows/win_ex_handling.h b/Engine/platform/windows/win_ex_handling.h index 30f458945d2..c7a862df111 100644 --- a/Engine/platform/windows/win_ex_handling.h +++ b/Engine/platform/windows/win_ex_handling.h @@ -16,9 +16,11 @@ #include "util/ini_util.h" +#if !AGS_PLATFORM_WINDOWS_MINGW void setup_malloc_handling(); int initialize_engine_with_exception_handling( int (initialize_engine)(const AGS::Common::ConfigTree &startup_opts), const AGS::Common::ConfigTree &startup_opts); +#endif #endif // __AGS_EE_PLATFORM__WIN_EXCEPTION_HANDLING_H From e644cee96a052015dbfb02b8ecbd35892db63954 Mon Sep 17 00:00:00 2001 From: e Date: Sat, 21 Oct 2023 21:46:08 -0300 Subject: [PATCH 8/8] CMake: make sure MinGW builds statically by default this is to avoid manually copying mingw dlls, and ensures a portable binary the same as traditional acwin.exe --- CMake/c_flag_overrides.cmake | 4 ++++ CMake/cxx_flag_overrides.cmake | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMake/c_flag_overrides.cmake b/CMake/c_flag_overrides.cmake index 56dcd2c4578..37b96f616d8 100644 --- a/CMake/c_flag_overrides.cmake +++ b/CMake/c_flag_overrides.cmake @@ -6,3 +6,7 @@ if(MSVC) set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /DNDEBUG") set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /DNDEBUG") endif() + +if(MINGW) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") +endif () \ No newline at end of file diff --git a/CMake/cxx_flag_overrides.cmake b/CMake/cxx_flag_overrides.cmake index 2893692651f..0230c008836 100644 --- a/CMake/cxx_flag_overrides.cmake +++ b/CMake/cxx_flag_overrides.cmake @@ -5,4 +5,8 @@ if(MSVC) set(CMAKE_CXX_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /DNDEBUG") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /DNDEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /DNDEBUG") -endif() \ No newline at end of file +endif() + +if(MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") +endif () \ No newline at end of file