Skip to content

Commit

Permalink
Merge pull request #2196 from ericoporto/add-mingw-basic-support
Browse files Browse the repository at this point in the history
Add mingw basic support
  • Loading branch information
ivan-mogilko authored Oct 27, 2023
2 parents 4bbc422 + e644cee commit 3517286
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CMake/c_flag_overrides.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
6 changes: 5 additions & 1 deletion CMake/cxx_flag_overrides.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
endif()

if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
endif ()
6 changes: 6 additions & 0 deletions Common/core/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Engine/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Engine/platform/windows/acplwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "platform/windows/windows.h"
#include <shlobj.h>
#include <shlwapi.h>
#include <gameux.h>
#include <libcda.h>

#include "platform/base/agsplatformdriver.h"
Expand Down
4 changes: 2 additions & 2 deletions Engine/platform/windows/setup/winsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@ void WinSetupDialog::OnGfxModeUpdate()
DWORD_PTR sel = GetCurItemData(_hGfxModeList);
switch (sel)
{
case kGfxMode_Desktop:
case static_cast<DWORD_PTR>(kGfxMode_Desktop):
_winCfg.FsSetup = WindowSetup(_desktopSize, kWnd_Fullscreen); break;
case kGfxMode_GameRes:
case static_cast<DWORD_PTR>(kGfxMode_GameRes):
_winCfg.FsSetup = WindowSetup(_winCfg.GameResolution, kWnd_Fullscreen); break;
default:
{
Expand Down
3 changes: 2 additions & 1 deletion Engine/platform/windows/win_ex_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <new.h>
#include <cinttypes>
#include <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions Engine/platform/windows/win_ex_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion Engine/util/library_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define __AGS_EE_UTIL__LIBRARY_WINDOWS_H

#include <utility>
#include "core/platform.h"
#include "debug/out.h"
#include "platform/windows/winapi_exclusive.h"
#include "util/path.h"
Expand Down Expand Up @@ -103,7 +104,7 @@ class WindowsLibrary final : public BaseLibrary
{
if (!_library)
return nullptr;
return GetProcAddress(_library, fn_name.GetCStr());
return reinterpret_cast<void *>(GetProcAddress(_library, fn_name.GetCStr()));
}

private:
Expand Down
34 changes: 15 additions & 19 deletions Plugins/agsblend/AGSBlend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>

#if !defined(BUILTIN_PLUGINS)
#define THIS_IS_THE_PLUGIN
Expand All @@ -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)))
Expand All @@ -62,24 +54,28 @@ 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))


#pragma endregion

#if AGS_PLATFORM_OS_WINDOWS && !defined(BUILTIN_PLUGINS)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>

// The standard Windows DLL entry point

BOOL APIENTRY DllMain( HANDLE hModule,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)

//==============================================================================

Expand Down
3 changes: 2 additions & 1 deletion libsrc/allegro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libsrc/allegro/include/allegro/internal/alconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libsrc/allegro/include/allegro/platform/almsvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3517286

Please sign in to comment.