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 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) 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/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" diff --git a/Engine/platform/windows/setup/winsetup.cpp b/Engine/platform/windows/setup/winsetup.cpp index 31e18d772fa..fdc7da53178 100644 --- a/Engine/platform/windows/setup/winsetup.cpp +++ b/Engine/platform/windows/setup/winsetup.cpp @@ -880,9 +880,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: { 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 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: 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) //============================================================================== 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