diff --git a/src/contrib/libvorbis/lib/barkmel.c b/src/contrib/libvorbis/lib/barkmel.c index 37b6c4c7ba..e7d7299601 100644 --- a/src/contrib/libvorbis/lib/barkmel.c +++ b/src/contrib/libvorbis/lib/barkmel.c @@ -15,6 +15,7 @@ ********************************************************************/ +#if 0 #include #include "scales.h" int main(){ @@ -61,4 +62,4 @@ int main(){ } return(0); } - +#endif diff --git a/src/engine/audio/CMakeLists.txt b/src/engine/audio/CMakeLists.txt index 7b1b788d1e..371e4209cf 100644 --- a/src/engine/audio/CMakeLists.txt +++ b/src/engine/audio/CMakeLists.txt @@ -59,4 +59,10 @@ else () set_source_files_properties(src/audio_mixer_avx.cpp PROPERTIES COMPILE_FLAGS -mavx) endif () +if (MSVC) + set_source_files_properties(src/audio_mixer_sse.cpp PROPERTIES COMPILE_FLAGS /arch:SSE) +else () + set_source_files_properties(src/audio_mixer_sse.cpp PROPERTIES COMPILE_FLAGS -msse) +endif () + add_library (halley-audio ${SOURCES} ${HEADERS}) diff --git a/src/engine/audio/include/halley/audio/vorbis_dec.h b/src/engine/audio/include/halley/audio/vorbis_dec.h index c9c7b05348..f8247894f7 100644 --- a/src/engine/audio/include/halley/audio/vorbis_dec.h +++ b/src/engine/audio/include/halley/audio/vorbis_dec.h @@ -30,7 +30,7 @@ struct OggVorbis_File; #if defined(_MSC_VER) || defined(__clang__) using OggOffsetType = int64_t; #else -using OggOffsetType = long int; +using OggOffsetType = long long; #endif namespace Halley { diff --git a/src/engine/core/include/halley/core/game/halley_main.h b/src/engine/core/include/halley/core/game/halley_main.h index 8e176a95d8..03449ff8a4 100644 --- a/src/engine/core/include/halley/core/game/halley_main.h +++ b/src/engine/core/include/halley/core/game/halley_main.h @@ -43,7 +43,7 @@ namespace Halley // Macro to implement program #if defined(HALLEY_EXECUTABLE) - #if defined(_WIN32) || defined(WINDOWS_STORE) + #if (defined(_WIN32) || defined(WINDOWS_STORE)) && !defined(__MINGW32__) #define HalleyGame(T) int __stdcall WinMain(void*, void*, char*, int) { return Halley::HalleyMain::winMain(); } #else #define HalleyGame(T) int main(int argc, char* argv[]) { return Halley::HalleyMain::main(argc, argv); } diff --git a/src/engine/core/include/halley/core/input/input_joystick.h b/src/engine/core/include/halley/core/input/input_joystick.h index 86e12962e0..b32e5ef18e 100644 --- a/src/engine/core/include/halley/core/input/input_joystick.h +++ b/src/engine/core/include/halley/core/input/input_joystick.h @@ -25,7 +25,7 @@ #include #include "input_button_base.h" -#if defined(_WIN32) && !defined(WINDOWS_STORE) +#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__) #define XINPUT_AVAILABLE #endif diff --git a/src/engine/core/src/game/core.cpp b/src/engine/core/src/game/core.cpp index aea394471c..9276f80539 100644 --- a/src/engine/core/src/game/core.cpp +++ b/src/engine/core/src/game/core.cpp @@ -241,7 +241,7 @@ void Core::setOutRedirect(bool appendToExisting) { #if defined(_WIN32) || defined(__APPLE__) || defined(linux) String path = (Path(environment->getDataPath()) / "log.txt").getString(); -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) auto outStream = std::make_shared(path.getUTF16().c_str(), appendToExisting ? std::ofstream::app : std::ofstream::trunc); #else auto outStream = std::make_shared(path.c_str(), appendToExisting ? std::ofstream::app : std::ofstream::trunc); diff --git a/src/engine/utils/CMakeLists.txt b/src/engine/utils/CMakeLists.txt index 5c51288a42..31d957d2cb 100644 --- a/src/engine/utils/CMakeLists.txt +++ b/src/engine/utils/CMakeLists.txt @@ -217,3 +217,7 @@ assign_source_group(${SOURCES}) assign_source_group(${HEADERS}) add_library (halley-utils ${SOURCES} ${HEADERS}) + +if (MINGW) + target_link_libraries(halley-utils shlwapi wbemuuid) +endif () diff --git a/src/engine/utils/src/file/path.cpp b/src/engine/utils/src/file/path.cpp index ed59e24d3b..9d628d32e5 100644 --- a/src/engine/utils/src/file/path.cpp +++ b/src/engine/utils/src/file/path.cpp @@ -237,7 +237,7 @@ Bytes Path::readFile(const Path& path) { Bytes result; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) std::ifstream fp(path.getString().getUTF16().c_str(), std::ios::binary | std::ios::in); #else std::ifstream fp(path.string(), std::ios::binary | std::ios::in); diff --git a/src/engine/utils/src/os/os_win32.cpp b/src/engine/utils/src/os/os_win32.cpp index 500052c1c0..5041a27658 100644 --- a/src/engine/utils/src/os/os_win32.cpp +++ b/src/engine/utils/src/os/os_win32.cpp @@ -37,10 +37,14 @@ #include #include #include -#include #include #include #include +#include + +#if defined(_WIN32) && !defined(__MINGW32__) +#include +#endif #pragma comment(lib, "wbemuuid.lib") //#pragma comment(lib, "comsupp.lib") @@ -57,6 +61,11 @@ Halley::OSWin32::OSWin32() // "Creating a WMI Application Using C++" try { +#ifdef __MINGW32__ + // Fix symbol undefined bug of MINGW + static const IID CLSID_WbemAdministrativeLocator = {0xcb8555cc, 0x9128, 0x11d1, {0xad,0x9b,0x00,0xc0,0x4f,0xd8,0xfd,0xff}}; +#endif + // Initialize COM HRESULT hr; hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); @@ -105,8 +114,13 @@ static String getCOMError(int hr) if (FAILED(hr2)) return "Failed getting COM error."; BSTR str; info->GetDescription(&str); +#ifdef __MINGW32__ + String tmp(str); + return "\"" + tmp + "\", code 0x"+ toString(hr, 16); +#else _bstr_t tmp(str); return "\"" + String(LPCSTR(tmp)) + "\", code 0x"+ toString(hr, 16); +#endif } Halley::String Halley::OSWin32::runWMIQuery(String query, String parameter) const @@ -117,6 +131,46 @@ Halley::String Halley::OSWin32::runWMIQuery(String query, String parameter) cons if (pSvc) { try { +#ifdef __MINGW32__ + HRESULT hr; + IEnumWbemClassObject* enumerator; + BSTR lang = const_cast(L"WQL"); + auto query_wchar = query.getUTF16(); + BSTR q = const_cast(query_wchar.c_str()); + hr = pSvc->ExecQuery(lang, q, WBEM_FLAG_FORWARD_ONLY, nullptr, &enumerator); + if (FAILED(hr)) { + if (enumerator) enumerator->Release(); enumerator = nullptr; + throw Exception("Error running WMI query: "+getCOMError(hr), HalleyExceptions::OS); + } + + ULONG retcnt; + IWbemClassObject* result; + hr = enumerator->Next(WBEM_INFINITE, 1L, &result, &retcnt); + if (retcnt == 0) { + if (result) result->Release(); result = nullptr; + if (enumerator) enumerator->Release(); enumerator = nullptr; + return "Unknown"; + } + if (FAILED(hr)) { + if (result) result->Release(); result = nullptr; + if (enumerator) enumerator->Release(); enumerator = nullptr; + throw Exception("Error obtaining WMI enumeration", HalleyExceptions::OS); + } + + _variant_t var_val; + hr = result->Get(parameter.getUTF16().c_str(), 0, &var_val, nullptr, nullptr); + + if (result) result->Release(); result = nullptr; + if (enumerator) enumerator->Release(); enumerator = nullptr; + + if (FAILED(hr)) throw Exception("Error retrieving name from WMI query result", HalleyExceptions::OS); + + if (var_val.vt == VT_NULL) { + return ""; + } else { + return String(var_val.bstrVal); + } +#else HRESULT hr; CComPtr enumerator; BSTR lang = CComBSTR(L"WQL"); @@ -139,6 +193,7 @@ Halley::String Halley::OSWin32::runWMIQuery(String query, String parameter) cons } else { return String(static_cast(_bstr_t(var_val))); } +#endif } catch (std::exception& e) { std::cout << "Exception running WMI query: " << e.what() << std::endl; } catch (...) { diff --git a/src/engine/utils/src/support/StackWalker/StackWalker.cpp b/src/engine/utils/src/support/StackWalker/StackWalker.cpp index 30bed9a301..47d64d8ae0 100644 --- a/src/engine/utils/src/support/StackWalker/StackWalker.cpp +++ b/src/engine/utils/src/support/StackWalker/StackWalker.cpp @@ -74,7 +74,7 @@ * **********************************************************************/ -#if defined(_WIN32) && !defined(WINDOWS_STORE) +#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__) #include #include diff --git a/src/engine/utils/src/support/StackWalker/StackWalker.h b/src/engine/utils/src/support/StackWalker/StackWalker.h index bf954ec0c8..1aadef511e 100644 --- a/src/engine/utils/src/support/StackWalker/StackWalker.h +++ b/src/engine/utils/src/support/StackWalker/StackWalker.h @@ -36,7 +36,7 @@ // so we need not to check the version (because we only support _MSC_VER >= 1100)! #pragma once -#if defined(_WIN32) && !defined(WINDOWS_STORE) +#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__) #include diff --git a/src/plugins/asio/CMakeLists.txt b/src/plugins/asio/CMakeLists.txt index 2ab58c336c..6d8e7bb32f 100644 --- a/src/plugins/asio/CMakeLists.txt +++ b/src/plugins/asio/CMakeLists.txt @@ -23,4 +23,8 @@ assign_source_group(${SOURCES}) assign_source_group(${HEADERS}) add_library (halley-asio ${SOURCES} ${HEADERS}) -target_link_libraries(halley-asio halley-core halley-net) \ No newline at end of file +target_link_libraries(halley-asio halley-core halley-net) + +if (MINGW) + target_link_libraries(halley-asio ws2_32 wsock32) +endif () diff --git a/src/plugins/dx11/CMakeLists.txt b/src/plugins/dx11/CMakeLists.txt index 441e6c2725..1399aeca38 100644 --- a/src/plugins/dx11/CMakeLists.txt +++ b/src/plugins/dx11/CMakeLists.txt @@ -35,3 +35,7 @@ assign_source_group(${HEADERS}) add_library (halley-dx11 ${SOURCES} ${HEADERS}) target_link_libraries(halley-dx11 halley-core halley-utils) + +if (MINGW) + target_link_libraries(halley-dx11 d3d11 dxgi) +endif () diff --git a/src/plugins/dx11/src/dx11_video.cpp b/src/plugins/dx11/src/dx11_video.cpp index 7be0bc03b2..9f37667c24 100644 --- a/src/plugins/dx11/src/dx11_video.cpp +++ b/src/plugins/dx11/src/dx11_video.cpp @@ -4,6 +4,8 @@ #include "dx11_texture.h" #include "dx11_render_target.h" #include "dx11_material_constant_buffer.h" +#include "dx11_blend.h" +#include "dx11_rasterizer.h" #include #include @@ -113,7 +115,11 @@ void DX11Video::initSwapChain(Window& window) #else swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; #endif +#ifdef __MINGW32__ + swapChainDesc.Scaling = static_cast(2); // DXGI_SCALING_ASPECT_RATIO_STRETCH +#else swapChainDesc.Scaling = DXGI_SCALING_ASPECT_RATIO_STRETCH; +#endif swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; IUnknown* coreWindow = reinterpret_cast(window.getNativeHandle()); diff --git a/src/plugins/mf/src/resource_data_byte_stream.cpp b/src/plugins/mf/src/resource_data_byte_stream.cpp index fc320070bb..139be98d3a 100644 --- a/src/plugins/mf/src/resource_data_byte_stream.cpp +++ b/src/plugins/mf/src/resource_data_byte_stream.cpp @@ -1,6 +1,6 @@ #include "resource_data_byte_stream.h" #include "halley/concurrency/concurrent.h" -#include +//#include using namespace Halley; class AsyncReadOp : public IUnknown diff --git a/src/plugins/opengl/src/video_opengl.cpp b/src/plugins/opengl/src/video_opengl.cpp index debcc23c1e..5237f2f80e 100644 --- a/src/plugins/opengl/src/video_opengl.cpp +++ b/src/plugins/opengl/src/video_opengl.cpp @@ -157,9 +157,18 @@ void VideoOpenGL::setupDebugCallback() glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); #endif +#ifdef __MINGW32__ + struct DebugImpl { + static void APIENTRY Callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) { + reinterpret_cast(userParam)->onGLDebugMessage(source, type, id, severity, message); + } + }; + glDebugMessageCallback(DebugImpl::Callback, this); +#else glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) { reinterpret_cast(userParam)->onGLDebugMessage(source, type, id, severity, message); }, this); +#endif glCheckError(); } else { glGetError(); diff --git a/src/plugins/sdl/src/system_sdl.cpp b/src/plugins/sdl/src/system_sdl.cpp index 434e346a74..04a48c551e 100644 --- a/src/plugins/sdl/src/system_sdl.cpp +++ b/src/plugins/sdl/src/system_sdl.cpp @@ -291,7 +291,7 @@ std::shared_ptr SystemSDL::getClipboard() const } -#if defined(_WIN32) && !defined(WINDOWS_STORE) +#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__) #pragma warning(default: 6320 6322) #include const DWORD MS_VC_EXCEPTION=0x406D1388; @@ -327,7 +327,7 @@ void SetThreadName( DWORD dwThreadID, const char* name) void SystemSDL::setThreadName(const String& name) { -#if defined(_WIN32) && !defined(WINDOWS_STORE) && defined(_DEBUG) +#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__) && defined(_DEBUG) if (name != "main") { SetThreadName(static_cast(-1), name.c_str()); } diff --git a/src/tools/editor/CMakeLists.txt b/src/tools/editor/CMakeLists.txt index 58644692b4..a5a9101e99 100644 --- a/src/tools/editor/CMakeLists.txt +++ b/src/tools/editor/CMakeLists.txt @@ -44,6 +44,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(EXTRA_LIBS bz2 z) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(EXTRA_LIBS pthread) +elseif(MINGW) + set(EXTRA_LIBS ws2_32 wsock32 d3d11 dxgi) endif() include_directories(${FREETYPE_INCLUDE_DIR} "../tools/include") diff --git a/src/tools/runner/src/dynamic_library.cpp b/src/tools/runner/src/dynamic_library.cpp index e3240c767c..379da410fe 100644 --- a/src/tools/runner/src/dynamic_library.cpp +++ b/src/tools/runner/src/dynamic_library.cpp @@ -93,7 +93,7 @@ void DynamicLibrary::unload() void* DynamicLibrary::getFunction(std::string name) const { #ifdef _WIN32 - return GetProcAddress(handle, name.c_str()); + return reinterpret_cast(GetProcAddress(handle, name.c_str())); #else return nullptr; #endif diff --git a/src/tools/tools/CMakeLists.txt b/src/tools/tools/CMakeLists.txt index 0124499d8a..2674a197ac 100644 --- a/src/tools/tools/CMakeLists.txt +++ b/src/tools/tools/CMakeLists.txt @@ -153,3 +153,7 @@ target_link_libraries (halley-tools ${YAMLCPP_LIBRARY} ${CMAKE_DL_LIBS} ) + +if (MINGW) + target_link_libraries(halley-tools d3dcompiler) +endif () diff --git a/src/tools/tools/src/assets/importers/shader_importer.cpp b/src/tools/tools/src/assets/importers/shader_importer.cpp index cceb873314..56b057e191 100644 --- a/src/tools/tools/src/assets/importers/shader_importer.cpp +++ b/src/tools/tools/src/assets/importers/shader_importer.cpp @@ -6,7 +6,7 @@ #include "halley/core/graphics/shader.h" #include "halley/support/logger.h" -#ifdef _MSC_VER +#ifdef _WIN32 #include #pragma comment(lib, "D3DCompiler.lib") #endif @@ -36,7 +36,7 @@ void ShaderImporter::import(const ImportingAsset& asset, IAssetCollector& collec Bytes ShaderImporter::compileHLSL(const String& name, ShaderType type, const Bytes& bytes) const { -#ifdef _MSC_VER +#ifdef _WIN32 String target; @@ -59,7 +59,11 @@ Bytes ShaderImporter::compileHLSL(const String& name, ShaderType type, const Byt ID3D10Blob *codeBlob = nullptr; ID3D10Blob *errorBlob = nullptr; +#ifdef __MINGW32__ + const HRESULT hResult = D3DCompile(bytes.data(), bytes.size(), name.c_str(), nullptr, nullptr, "main", target.c_str(), 0, 0, &codeBlob, &errorBlob); +#else const HRESULT hResult = D3DCompile2(bytes.data(), bytes.size(), name.c_str(), nullptr, nullptr, "main", target.c_str(), 0, 0, 0, nullptr, 0, &codeBlob, &errorBlob); +#endif if (hResult != S_OK) { const auto errorMessage = String(reinterpret_cast(errorBlob->GetBufferPointer()), errorBlob->GetBufferSize()); errorBlob->Release();