From e5ada6f3774922558666ee549d3daa43b8564e56 Mon Sep 17 00:00:00 2001 From: martell Date: Thu, 5 Dec 2013 03:37:27 +0000 Subject: [PATCH 1/3] added support for msys2 mingwtoolchains and fix x64 cocos/audio on windows platform for MSVC and Mingw. Also fixed a few very bad type casts very important for future Arm64 bit processors --- CMakeLists.txt | 25 +++++++++++++ build/build-mingw32-gcc-make.sh | 62 ++++++++++++++++++++++++++++++++ cocos/2d/CCSprite.cpp | 2 +- cocos/2d/ZipUtils.cpp | 2 +- cocos/2d/platform/win32/CCStdC.h | 10 +++++- cocos/audio/win32/MciPlayer.cpp | 22 ++++++------ cocos/base/CCPlatformConfig.h | 4 ++- 7 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 build/build-mingw32-gcc-make.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 08c2eddb1f..dfa9ac305e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,28 @@ +#/**************************************************************************** +# Copyright (c) 2013 cocos2d-x.org +# Copyright (c) 2012-2013 martell malone +# +# http://www.cocos2d-x.org +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# ****************************************************************************/ + cmake_minimum_required(VERSION 2.8) project (Cocos2dx) diff --git a/build/build-mingw32-gcc-make.sh b/build/build-mingw32-gcc-make.sh new file mode 100644 index 0000000000..c7f45347f8 --- /dev/null +++ b/build/build-mingw32-gcc-make.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# msys2 Pacman Manager for cocos2d-x + +#/**************************************************************************** +# Copyright (c) 2012-2013 Martell Malone +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# ****************************************************************************/ + +set -e + +THISDIR="$(dirname $0)" +test "$THISDIR" = "." && THISDIR=${PWD} +OSTYPE=${OSTYPE//[0-9.]/} +HOST_ARCH=$(uname -m) + +if [ "${HOST_ARCH}" = "i686" ]; then + BITS=32 +elif [ "${HOST_ARCH}" = "x86_64" ]; then + BITS=64 +fi + +if [ "${OSTYPE}" = "msys" ]; then + + CC=${HOST_ARCH}-w64-mingw32-gcc + CXX=${HOST_ARCH}-w64-mingw32-g++ + PP=mingw-w64-${HOST_ARCH} + + MINGW_PACKAGES=(glfw glew libwebp libjpeg-turbo libpng freetype libiconv zlib curl + make gcc binutils headers cmake libxml2) + + MINGW_PACKAGES=(${MINGW_PACKAGES[@]/#/${PP}-}) + + pacman -S --force --noconfirm --needed ${MINGW_PACKAGES[@]} + + mkdir -p mingw${BITS} && cd mingw${BITS} + + export PATH=/mingw${BITS}/bin:${PATH} + + cmake -G"MinGW Makefiles" -DCMAKE_MAKE_PROGRAM="mingw32-make" \ + -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" ../.. + + mingw32-make +fi diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 36577238b0..d0ec167bcc 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -613,7 +613,7 @@ void Sprite::draw(void) long offset = 0; setGLBufferData(&_quad, 4 * kQuadSize, 0); #else - long offset = (long)&_quad; + size_t offset = (size_t)&_quad; #endif // EMSCRIPTEN // vertex diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index ebde2f9963..5c47939152 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -439,7 +439,7 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, long bufferLen, unsi } unsigned long destlen = len; - unsigned long source = (unsigned long) buffer + sizeof(*header); + size_t source = (size_t) buffer + sizeof(*header); int ret = uncompress(*out, &destlen, (Bytef*)source, bufferLen - sizeof(*header) ); if( ret != Z_OK ) diff --git a/cocos/2d/platform/win32/CCStdC.h b/cocos/2d/platform/win32/CCStdC.h index 4716dc6524..1090404d89 100644 --- a/cocos/2d/platform/win32/CCStdC.h +++ b/cocos/2d/platform/win32/CCStdC.h @@ -52,6 +52,12 @@ THE SOFTWARE. #include #include +#ifndef M_PI + #define M_PI 3.14159265358 +#endif +#ifndef M_PI_2 + #define M_PI_2 1.57079632679 +#endif // for MIN MAX and sys/time.h on win32 platform #ifdef __MINGW32__ #include @@ -73,7 +79,9 @@ THE SOFTWARE. #endif #define _WINSOCKAPI_ -#define NOMINMAX +#ifndef NOMINMAX + #define NOMINMAX +#endif // Structure timeval has define in winsock.h, include windows.h for it. #include diff --git a/cocos/audio/win32/MciPlayer.cpp b/cocos/audio/win32/MciPlayer.cpp index 25520cb9b9..a01dbddb1e 100644 --- a/cocos/audio/win32/MciPlayer.cpp +++ b/cocos/audio/win32/MciPlayer.cpp @@ -8,11 +8,11 @@ namespace CocosDenshion { static HINSTANCE s_hInstance; static MCIERROR s_mciError; -static LRESULT WINAPI _SoundPlayProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +LRESULT WINAPI _SoundPlayProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); MciPlayer::MciPlayer() : _wnd(NULL) -, _dev(NULL) +, _dev(0L) , _soundID(0) , _times(0) , _playing(false) @@ -56,7 +56,7 @@ MciPlayer::MciPlayer() NULL ); if (_wnd) { - SetWindowLong(_wnd, GWL_USERDATA, (LONG)this); + SetWindowLongPtr(_wnd, GWLP_USERDATA, (LONG_PTR)this); } } @@ -85,7 +85,7 @@ void MciPlayer::Open(const char* pFileName, UINT uId) mciOpen.lpstrDeviceType = (LPCTSTR)MCI_ALL_DEVICE_ID; mciOpen.lpstrElementName = pFileName; - mciError = mciSendCommand(0,MCI_OPEN, MCI_OPEN_ELEMENT, (DWORD)&mciOpen); + mciError = mciSendCommand(0,MCI_OPEN, MCI_OPEN_ELEMENT, reinterpret_cast(&mciOpen)); BREAK_IF(mciError); _dev = mciOpen.wDeviceID; @@ -101,8 +101,8 @@ void MciPlayer::Play(UINT uTimes /* = 1 */) return; } MCI_PLAY_PARMS mciPlay = {0}; - mciPlay.dwCallback = (DWORD_PTR)_wnd; - s_mciError = mciSendCommand(_dev,MCI_PLAY, MCI_FROM|MCI_NOTIFY,(DWORD)&mciPlay); + mciPlay.dwCallback = reinterpret_cast(_wnd); + s_mciError = mciSendCommand(_dev,MCI_PLAY, MCI_FROM|MCI_NOTIFY,reinterpret_cast(&mciPlay)); if (! s_mciError) { _playing = true; @@ -149,8 +149,8 @@ void MciPlayer::Rewind() mciSendCommand(_dev, MCI_SEEK, MCI_SEEK_TO_START, 0); MCI_PLAY_PARMS mciPlay = {0}; - mciPlay.dwCallback = (DWORD)_wnd; - _playing = mciSendCommand(_dev, MCI_PLAY, MCI_NOTIFY,(DWORD)&mciPlay) ? false : true; + mciPlay.dwCallback = reinterpret_cast(_wnd); + _playing = mciSendCommand(_dev, MCI_PLAY, MCI_NOTIFY,reinterpret_cast(&mciPlay)) ? false : true; } bool MciPlayer::IsPlaying() @@ -185,7 +185,7 @@ LRESULT WINAPI _SoundPlayProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) MciPlayer * pPlayer = NULL; if (MM_MCINOTIFY == Msg && MCI_NOTIFY_SUCCESSFUL == wParam - &&(pPlayer = (MciPlayer *)GetWindowLong(hWnd, GWL_USERDATA))) + &&(pPlayer = (MciPlayer *)GetWindowLongPtr(hWnd, GWLP_USERDATA))) { if (pPlayer->_times) { @@ -197,8 +197,8 @@ LRESULT WINAPI _SoundPlayProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) mciSendCommand(lParam, MCI_SEEK, MCI_SEEK_TO_START, 0); MCI_PLAY_PARMS mciPlay = {0}; - mciPlay.dwCallback = (DWORD)hWnd; - mciSendCommand(lParam, MCI_PLAY, MCI_NOTIFY,(DWORD)&mciPlay); + mciPlay.dwCallback = reinterpret_cast(hWnd); + mciSendCommand(lParam, MCI_PLAY, MCI_NOTIFY,reinterpret_cast(&mciPlay)); } else { diff --git a/cocos/base/CCPlatformConfig.h b/cocos/base/CCPlatformConfig.h index 5ba0757dac..3a74498d1a 100644 --- a/cocos/base/CCPlatformConfig.h +++ b/cocos/base/CCPlatformConfig.h @@ -133,7 +133,9 @@ Config of cocos2d-x project, per target platform. #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) -#pragma warning (disable:4127) +#ifndef __MINGW32__ +#pragma warning (disable:4127) +#endif #endif // CC_PLATFORM_WIN32 #endif // __CC_PLATFORM_CONFIG_H__ From e0523c73f52968c48284e3afccb1d87f066d3546 Mon Sep 17 00:00:00 2001 From: martell Date: Thu, 5 Dec 2013 03:53:25 +0000 Subject: [PATCH 2/3] fixed CCImage for MSVC someone added std:tolower which broke it --- cocos/2d/platform/win32/CCImage.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos/2d/platform/win32/CCImage.cpp b/cocos/2d/platform/win32/CCImage.cpp index a5d4d68a21..dd6d64742a 100644 --- a/cocos/2d/platform/win32/CCImage.cpp +++ b/cocos/2d/platform/win32/CCImage.cpp @@ -22,6 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #define __CC_PLATFORM_IMAGE_CPP__ +#if _MSC_VER +#include +#endif #include "platform/CCImageCommon_cpp.h" NS_CC_BEGIN From 8f574272ee8f189cd95e88e68b6b00b40cf6c390 Mon Sep 17 00:00:00 2001 From: martell Date: Thu, 5 Dec 2013 03:54:44 +0000 Subject: [PATCH 3/3] removed unneeded directories for Mingw cmake --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfa9ac305e..c68536b314 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,12 +195,6 @@ if(WIN32) ) endif() - link_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/gles/prebuilt - ) - elseif(APPLE) else()