diff --git a/AUTHORS b/AUTHORS index f761ab3791..de1df99e53 100644 --- a/AUTHORS +++ b/AUTHORS @@ -811,6 +811,7 @@ Developers: Added Node::stopAllActionsByTag && ActionManager::removeAllActionsByTag Added getAllTouches() in GLViewProtocol Precompiled headers improvements + Added Application::openUrl for all supported platforms ecept WP8 and WinRT youknowone Adds iOS-like elastic bounceback support for cocos2d::extension::ScrollView @@ -1010,6 +1011,12 @@ Developers: wohaaitinciu WebView support on windows + + guykogus + Implemented Application::openUrl for WP8 and WinRT + + tttreal + Fixed Label::getStringNumLines() Retired Core Developers: WenSheng Yang diff --git a/CHANGELOG b/CHANGELOG index 67e5e60114..c64067915b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,15 @@ cocos2d-x-3.3 [NEW] Audio: new audio supports Mac OS X + [NEW] Application: added openUrl() [NEW] Rect: added merge() [NEW] Utils: added getCascadeBoundingBox() [NEW] UI: `WebView` support on windows + [FIX] Accelerometer: using Accelerometer will freeze app and then crash on WP8 + [FIX] C++: remove armv7s in VALID_ARCHS for Xcode projects + [FIX] EditBox: view rendereed in wrong position if click EditBox on iOS 8 + [FIX] Label: getStringNumLines() may returns wrong result if label is dirty + [FIX] Lua-binding: may crash if passing two-dimensional table from lua to c++ [FIX] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 cocos2d-x-3.3 Sep.20 2014 diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 7c92ea00ad..ca5efb5ebd 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -6852,6 +6852,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../external/freetype2/include/ios $(SRCROOT)/../external/curl/include/ios $(SRCROOT)/../external/webp/include/ios $(SRCROOT)/../external/tiff/include/ios $(SRCROOT)/../external/jpeg/include/ios $(SRCROOT)/../external/png/include/ios $(SRCROOT)/../external/websockets/include/ios $(SRCROOT)/../external/chipmunk/include/chipmunk"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -6884,6 +6885,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../external/freetype2/include/ios $(SRCROOT)/../external/curl/include/ios $(SRCROOT)/../external/webp/include/ios $(SRCROOT)/../external/tiff/include/ios $(SRCROOT)/../external/jpeg/include/ios $(SRCROOT)/../external/png/include/ios $(SRCROOT)/../external/websockets/include/ios $(SRCROOT)/../external/chipmunk/include/chipmunk"; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 7730dda38d..6f4389d5bc 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -939,6 +939,8 @@ A07A52BF1783AF210073F6A7 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A07A52B91783AE900073F6A7 /* OpenGLES.framework */; }; A07A52C01783AF250073F6A7 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A07A52B71783AE6D0073F6A7 /* UIKit.framework */; }; A07A52C31783B02C0073F6A7 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A07A52C11783B01F0073F6A7 /* AVFoundation.framework */; }; + A5030C3519D059DA000E78E7 /* OpenURLTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */; }; + A5030C3619D059DA000E78E7 /* OpenURLTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */; }; B2507B6B192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; B2507B6C192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; B609E67319C18DAD003D0074 /* BillBoardTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B609E67119C18DAD003D0074 /* BillBoardTest.cpp */; }; @@ -2965,6 +2967,8 @@ A07A52B91783AE900073F6A7 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/OpenGLES.framework; sourceTree = DEVELOPER_DIR; }; A07A52BB1783AEB80073F6A7 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; }; A07A52C11783B01F0073F6A7 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/AVFoundation.framework; sourceTree = DEVELOPER_DIR; }; + A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenURLTest.cpp; path = OpenURLTest/OpenURLTest.cpp; sourceTree = ""; }; + A5030C3419D059DA000E78E7 /* OpenURLTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenURLTest.h; path = OpenURLTest/OpenURLTest.h; sourceTree = ""; }; B2507B6A192589AF00FA4972 /* Shaders3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Shaders3D; path = "../tests/cpp-tests/Resources/Shaders3D"; sourceTree = ""; }; B609E67119C18DAD003D0074 /* BillBoardTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BillBoardTest.cpp; path = BillBoardTest/BillBoardTest.cpp; sourceTree = ""; }; B609E67219C18DAD003D0074 /* BillBoardTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BillBoardTest.h; path = BillBoardTest/BillBoardTest.h; sourceTree = ""; }; @@ -5515,6 +5519,7 @@ 1AC35B1718CECF0C00F37B72 /* UserDefaultTest */, 1AC35B1A18CECF0C00F37B72 /* VisibleRect.cpp */, 1AC35B1B18CECF0C00F37B72 /* VisibleRect.h */, + A5030C3219D059AB000E78E7 /* OpenURLTest */, 1AC35B1C18CECF0C00F37B72 /* ZwoptexTest */, ); name = Classes; @@ -7161,6 +7166,15 @@ name = Products; sourceTree = ""; }; + A5030C3219D059AB000E78E7 /* OpenURLTest */ = { + isa = PBXGroup; + children = ( + A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */, + A5030C3419D059DA000E78E7 /* OpenURLTest.h */, + ); + name = OpenURLTest; + sourceTree = ""; + }; B609E67019C18D90003D0074 /* BillBoardTest */ = { isa = PBXGroup; children = ( @@ -8020,6 +8034,7 @@ 1AC35B2918CECF0C00F37B72 /* AppDelegate.cpp in Sources */, 29080DA1191B595E0066F8DF /* GUIEditorTest.cpp in Sources */, 1AC35B3718CECF0C00F37B72 /* Bug-1159.cpp in Sources */, + A5030C3519D059DA000E78E7 /* OpenURLTest.cpp in Sources */, 29080D1C191B574B0066F8DF /* UITest.cpp in Sources */, 1AC35C3118CECF0C00F37B72 /* PerformanceRendererTest.cpp in Sources */, 1AC35C4518CECF0C00F37B72 /* SceneTest.cpp in Sources */, @@ -8249,6 +8264,7 @@ 1AC35C6018CECF0C00F37B72 /* Paddle.cpp in Sources */, 29080DBE191B595E0066F8DF /* UIPageViewTest.cpp in Sources */, 1AC35BDC18CECF0C00F37B72 /* SceneEditorTest.cpp in Sources */, + A5030C3619D059DA000E78E7 /* OpenURLTest.cpp in Sources */, 1AC35B4C18CECF0C00F37B72 /* BugsTest.cpp in Sources */, 1AC35C5218CECF0C00F37B72 /* testBasic.cpp in Sources */, 1AC35B7A18CECF0C00F37B72 /* EnemyController.cpp in Sources */, @@ -8593,6 +8609,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/.. $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../external $(SRCROOT)/../external/lua/luajit/include $(SRCROOT)/../external/lua/tolua $(SRCROOT)/../cocos/scripting/lua-bindings/manual $(SRCROOT)/../cocos/scripting/lua-bindings/auto $(SRCROOT)/../cocos/base"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8619,6 +8636,7 @@ TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/.. $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../external $(SRCROOT)/../external/lua/luajit/include $(SRCROOT)/../external/lua/tolua $(SRCROOT)/../cocos/scripting/lua-bindings/manual $(SRCROOT)/../cocos/scripting/lua-bindings/auto $(SRCROOT)/../cocos/base"; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8703,6 +8721,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../cocos/platform/ios/Simulation $(SRCROOT)/../external/curl/include/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8720,6 +8739,7 @@ TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../cocos/platform/ios/Simulation $(SRCROOT)/../external/curl/include/ios"; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8740,6 +8760,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/.. $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../external $(SRCROOT)/../external/lua/luajit/include $(SRCROOT)/../external/lua/tolua $(SRCROOT)/../cocos/scripting/lua-bindings/manual $(SRCROOT)/../cocos/scripting/lua-bindings/auto"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8761,6 +8782,7 @@ TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/.. $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../external $(SRCROOT)/../external/lua/luajit/include $(SRCROOT)/../external/lua/tolua $(SRCROOT)/../cocos/scripting/lua-bindings/manual $(SRCROOT)/../cocos/scripting/lua-bindings/auto"; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8820,6 +8842,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/.. $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../external $(SRCROOT)/../external/lua/luajit/include $(SRCROOT)/../external/lua/tolua $(SRCROOT)/../cocos/scripting/lua-bindings/manual $(SRCROOT)/../cocos/scripting/lua-bindings/auto"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8841,6 +8864,7 @@ TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/.. $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../external $(SRCROOT)/../external/lua/luajit/include $(SRCROOT)/../external/lua/tolua $(SRCROOT)/../cocos/scripting/lua-bindings/manual $(SRCROOT)/../cocos/scripting/lua-bindings/auto"; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8890,6 +8914,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../cocos/platform/ios/Simulation $(SRCROOT)/../external/curl/include/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8909,6 +8934,7 @@ TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../cocos/platform/ios/Simulation $(SRCROOT)/../external/curl/include/ios"; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8931,6 +8957,7 @@ buildSettings = { COMPRESS_PNG_FILES = NO; SDKROOT = iphoneos; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8939,6 +8966,7 @@ buildSettings = { COMPRESS_PNG_FILES = NO; SDKROOT = iphoneos; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8962,6 +8990,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../cocos/platform/ios/Simulation $(SRCROOT)/../external/curl/include/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8986,6 +9015,7 @@ TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../cocos/platform/ios $(SRCROOT)/../cocos/platform/ios/Simulation $(SRCROOT)/../external/curl/include/ios"; VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 39aaa8860c..980ed7a8c2 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -1226,6 +1226,15 @@ void Label::computeStringNumLines() _currNumLines = quantityOfLines; } +int Label::getStringNumLines() const { + if (_contentDirty) + { + const_cast(this)->updateContent(); + } + + return _currNumLines; +} + int Label::getStringLength() const { return static_cast(_currentUTF16String.length()); diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index c41f5c0da8..59e9288ab6 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -235,7 +235,7 @@ public: float getAdditionalKerning() const; // string related stuff - int getStringNumLines() const { return _currNumLines;} + int getStringNumLines() const; int getStringLength() const; FontAtlas* getFontAtlas() { return _fontAtlas; } diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 64c644f775..6e602df3e0 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -405,7 +405,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - @@ -785,7 +784,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index c1df455476..428eef5951 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -1144,9 +1144,6 @@ extension\GUI\CCControlExtensions - - ui\UIWidgets\EditBox - platform\win32 @@ -2281,9 +2278,6 @@ extension\GUI\CCControlExtensions - - ui\UIWidgets\EditBox - platform\win32 diff --git a/cocos/Android.mk b/cocos/Android.mk index 4b9ded3248..7c4c2475ba 100644 --- a/cocos/Android.mk +++ b/cocos/Android.mk @@ -227,6 +227,10 @@ LOCAL_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat LOCAL_EXPORT_CFLAGS := -DUSE_FILE32API LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat +ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) +LOCAL_ARM_NEON := true +endif + include $(BUILD_STATIC_LIBRARY) #============================================================== @@ -234,7 +238,6 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := cocos2dx_static - LOCAL_MODULE_FILENAME := libcocos2d LOCAL_STATIC_LIBRARIES := cocostudio_static diff --git a/cocos/base/CCRef.cpp b/cocos/base/CCRef.cpp index 747b08ccdf..59478a4eec 100644 --- a/cocos/base/CCRef.cpp +++ b/cocos/base/CCRef.cpp @@ -28,13 +28,13 @@ THE SOFTWARE. #include "base/ccMacros.h" #include "base/CCScriptSupport.h" -#if CC_USE_MEM_LEAK_DETECTION +#if CC_REF_LEAK_DETECTION #include // std::find #endif NS_CC_BEGIN -#if CC_USE_MEM_LEAK_DETECTION +#if CC_REF_LEAK_DETECTION static void trackRef(Ref* ref); static void untrackRef(Ref* ref); #endif @@ -49,7 +49,7 @@ Ref::Ref() _scriptObject = nullptr; #endif -#if CC_USE_MEM_LEAK_DETECTION +#if CC_REF_LEAK_DETECTION trackRef(this); #endif } @@ -73,7 +73,7 @@ Ref::~Ref() #endif -#if CC_USE_MEM_LEAK_DETECTION +#if CC_REF_LEAK_DETECTION if (_referenceCount != 0) untrackRef(this); #endif @@ -127,7 +127,7 @@ void Ref::release() } #endif -#if CC_USE_MEM_LEAK_DETECTION +#if CC_REF_LEAK_DETECTION untrackRef(this); #endif delete this; @@ -145,7 +145,7 @@ unsigned int Ref::getReferenceCount() const return _referenceCount; } -#if CC_USE_MEM_LEAK_DETECTION +#if CC_REF_LEAK_DETECTION static std::list __refAllocationList; diff --git a/cocos/base/CCRef.h b/cocos/base/CCRef.h index 5246f4feae..34dc42adba 100644 --- a/cocos/base/CCRef.h +++ b/cocos/base/CCRef.h @@ -29,7 +29,7 @@ THE SOFTWARE. #include "platform/CCPlatformMacros.h" #include "base/ccConfig.h" -#define CC_USE_MEM_LEAK_DETECTION 0 +#define CC_REF_LEAK_DETECTION 0 NS_CC_BEGIN diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index 3e62986cc3..bb981a3255 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -21,12 +21,62 @@ This file was modified to fit the cocos2d-x project #include "MathUtil.h" #include "base/ccMacros.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) +#include +#endif + +//#define USE_NEON32 : neon 32 code will be used +//#define USE_NEON64 : neon 64 code will be used +//#define INCLUDE_NEON32 : neon 32 code included +//#define INCLUDE_NEON64 : neon 64 code included +//#define USE_SSE : SSE code used +//#define INCLUDE_SSE : SSE code included + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + #if defined (__arm64__) + #define USE_NEON64 + #define INCLUDE_NEON64 + #elif defined (__ARM_NEON__) + #define USE_NEON32 + #define INCLUDE_NEON32 + #else + #endif +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + #if defined (__arm64__) + #define INCLUDE_NEON64 + #elif defined (__ARM_NEON__) + #define INCLUDE_NEON32 + #else + #endif +#else + +#endif + +#if defined (__SSE__) +#define USE_SSE +#define INCLUDE_SSE +#endif + +#ifdef INCLUDE_NEON32 +#include "MathUtilNeon.inl" +#endif + +#ifdef INCLUDE_NEON64 +#include "MathUtilNeon64.inl" +#endif + +#ifdef INCLUDE_SSE +#include "MathUtilSSE.inl" +#endif + +#include "MathUtil.inl" + NS_CC_MATH_BEGIN void MathUtil::smooth(float* x, float target, float elapsedTime, float responseTime) { GP_ASSERT(x); - + if (elapsedTime > 0) { *x += (target - *x) * elapsedTime / (elapsedTime + responseTime); @@ -44,4 +94,179 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, } } +bool MathUtil::isNeon32Enabled() +{ +#ifdef USE_NEON32 + return true; +#elif (defined (INCLUDE_NEON32) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) ) + class AnrdoidNeonChecker + { + public: + AnrdoidNeonChecker() + { + if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0) + _isNeonEnabled = true; + else + _isNeonEnabled = false; + } + bool isNeonEnabled() const { return _isNeonEnabled; } + private: + bool _isNeonEnabled; + }; + static AnrdoidNeonChecker checker; + return checker.isNeonEnabled(); +#else + return false; +#endif +} + +bool MathUtil::isNeon64Enabled() +{ +#ifdef USE_NEON64 + return true; +#else + return false; +#endif +} + +void MathUtil::addMatrix(const float* m, float scalar, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::addMatrix(m, scalar, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::addMatrix(m, scalar, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::addMatrix(m, scalar, dst); + else MathUtilC::addMatrix(m, scalar, dst); +#else + MathUtilC::addMatrix(m, scalar, dst); +#endif +} + +void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::addMatrix(m1, m2, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::addMatrix(m1, m2, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::addMatrix(m1, m2, dst); + else MathUtilC::addMatrix(m1, m2, dst); +#else + MathUtilC::addMatrix(m1, m2, dst); +#endif +} + +void MathUtil::subtractMatrix(const float* m1, const float* m2, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::subtractMatrix(m1, m2, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::subtractMatrix(m1, m2, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::subtractMatrix(m1, m2, dst); + else MathUtilC::subtractMatrix(m1, m2, dst); +#else + MathUtilC::subtractMatrix(m1, m2, dst); +#endif +} + +void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::multiplyMatrix(m, scalar, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::multiplyMatrix(m, scalar, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::multiplyMatrix(m, scalar, dst); + else MathUtilC::multiplyMatrix(m, scalar, dst); +#else + MathUtilC::multiplyMatrix(m, scalar, dst); +#endif +} + +void MathUtil::multiplyMatrix(const float* m1, const float* m2, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::multiplyMatrix(m1, m2, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::multiplyMatrix(m1, m2, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::multiplyMatrix(m1, m2, dst); + else MathUtilC::multiplyMatrix(m1, m2, dst); +#else + MathUtilC::multiplyMatrix(m1, m2, dst); +#endif +} + +void MathUtil::negateMatrix(const float* m, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::negateMatrix(m, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::negateMatrix(m, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::negateMatrix(m, dst); + else MathUtilC::negateMatrix(m, dst); +#else + MathUtilC::negateMatrix(m, dst); +#endif +} + +void MathUtil::transposeMatrix(const float* m, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::transposeMatrix(m, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::transposeMatrix(m, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::transposeMatrix(m, dst); + else MathUtilC::transposeMatrix(m, dst); +#else + MathUtilC::transposeMatrix(m, dst); +#endif +} + +void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::transformVec4(m, x, y, z, w, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::transformVec4(m, x, y, z, w, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::transformVec4(m, x, y, z, w, dst); + else MathUtilC::transformVec4(m, x, y, z, w, dst); +#else + MathUtilC::transformVec4(m, x, y, z, w, dst); +#endif +} + +void MathUtil::transformVec4(const float* m, const float* v, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::transformVec4(m, v, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::transformVec4(m, v, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::transformVec4(m, v, dst); + else MathUtilC::transformVec4(m, v, dst); +#else + MathUtilC::transformVec4(m, v, dst); +#endif +} + +void MathUtil::crossVec3(const float* v1, const float* v2, float* dst) +{ +#ifdef USE_NEON32 + MathUtilNeon::crossVec3(v1, v2, dst); +#elif defined (USE_NEON64) + MathUtilNeon64::crossVec3(v1, v2, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::crossVec3(v1, v2, dst); + else MathUtilC::crossVec3(v1, v2, dst); +#else + MathUtilC::crossVec3(v1, v2, dst); +#endif +} + NS_CC_MATH_END diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index acf6ab0b42..64d80ad4c3 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -69,59 +69,52 @@ public: * @param fallTime response time for falling slope (in the same units as elapsedTime). */ static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime); - +private: + //Indicates that if neon is enabled + static bool isNeon32Enabled(); + static bool isNeon64Enabled(); private: #ifdef __SSE__ - inline static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); + static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); - inline static void addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); + static void addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); - inline static void subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); + static void subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); - inline static void multiplyMatrix(const __m128 m[4], float scalar, __m128 dst[4]); + static void multiplyMatrix(const __m128 m[4], float scalar, __m128 dst[4]); - inline static void multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); + static void multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); - inline static void negateMatrix(const __m128 m[4], __m128 dst[4]); + static void negateMatrix(const __m128 m[4], __m128 dst[4]); - inline static void transposeMatrix(const __m128 m[4], __m128 dst[4]); + static void transposeMatrix(const __m128 m[4], __m128 dst[4]); - inline static void transformVec4(const __m128 m[4], const __m128& v, __m128& dst); + static void transformVec4(const __m128 m[4], const __m128& v, __m128& dst); #endif - inline static void addMatrix(const float* m, float scalar, float* dst); + static void addMatrix(const float* m, float scalar, float* dst); - inline static void addMatrix(const float* m1, const float* m2, float* dst); + static void addMatrix(const float* m1, const float* m2, float* dst); - inline static void subtractMatrix(const float* m1, const float* m2, float* dst); + static void subtractMatrix(const float* m1, const float* m2, float* dst); - inline static void multiplyMatrix(const float* m, float scalar, float* dst); + static void multiplyMatrix(const float* m, float scalar, float* dst); - inline static void multiplyMatrix(const float* m1, const float* m2, float* dst); + static void multiplyMatrix(const float* m1, const float* m2, float* dst); - inline static void negateMatrix(const float* m, float* dst); + static void negateMatrix(const float* m, float* dst); - inline static void transposeMatrix(const float* m, float* dst); + static void transposeMatrix(const float* m, float* dst); - inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst); + static void transformVec4(const float* m, float x, float y, float z, float w, float* dst); - inline static void transformVec4(const float* m, const float* v, float* dst); + static void transformVec4(const float* m, const float* v, float* dst); - inline static void crossVec3(const float* v1, const float* v2, float* dst); + static void crossVec3(const float* v1, const float* v2, float* dst); - MathUtil(); }; NS_CC_MATH_END #define MATRIX_SIZE ( sizeof(float) * 16) -#ifdef USE_NEON -#include "MathUtilNeon.inl" -#else -#include "MathUtil.inl" -#if defined(__SSE__) -#include "MathUtilSSE.inl" -#endif -#endif - #endif diff --git a/cocos/math/MathUtil.inl b/cocos/math/MathUtil.inl index ba19d635e7..5148fa13d8 100644 --- a/cocos/math/MathUtil.inl +++ b/cocos/math/MathUtil.inl @@ -20,7 +20,31 @@ NS_CC_MATH_BEGIN -inline void MathUtil::addMatrix(const float* m, float scalar, float* dst) +class MathUtilC +{ +public: + inline static void addMatrix(const float* m, float scalar, float* dst); + + inline static void addMatrix(const float* m1, const float* m2, float* dst); + + inline static void subtractMatrix(const float* m1, const float* m2, float* dst); + + inline static void multiplyMatrix(const float* m, float scalar, float* dst); + + inline static void multiplyMatrix(const float* m1, const float* m2, float* dst); + + inline static void negateMatrix(const float* m, float* dst); + + inline static void transposeMatrix(const float* m, float* dst); + + inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst); + + inline static void transformVec4(const float* m, const float* v, float* dst); + + inline static void crossVec3(const float* v1, const float* v2, float* dst); +}; + +inline void MathUtilC::addMatrix(const float* m, float scalar, float* dst) { dst[0] = m[0] + scalar; dst[1] = m[1] + scalar; @@ -40,7 +64,7 @@ inline void MathUtil::addMatrix(const float* m, float scalar, float* dst) dst[15] = m[15] + scalar; } -inline void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) +inline void MathUtilC::addMatrix(const float* m1, const float* m2, float* dst) { dst[0] = m1[0] + m2[0]; dst[1] = m1[1] + m2[1]; @@ -60,7 +84,7 @@ inline void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) dst[15] = m1[15] + m2[15]; } -inline void MathUtil::subtractMatrix(const float* m1, const float* m2, float* dst) +inline void MathUtilC::subtractMatrix(const float* m1, const float* m2, float* dst) { dst[0] = m1[0] - m2[0]; dst[1] = m1[1] - m2[1]; @@ -80,7 +104,7 @@ inline void MathUtil::subtractMatrix(const float* m1, const float* m2, float* ds dst[15] = m1[15] - m2[15]; } -inline void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) +inline void MathUtilC::multiplyMatrix(const float* m, float scalar, float* dst) { dst[0] = m[0] * scalar; dst[1] = m[1] * scalar; @@ -100,35 +124,35 @@ inline void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) dst[15] = m[15] * scalar; } -inline void MathUtil::multiplyMatrix(const float* m1, const float* m2, float* dst) +inline void MathUtilC::multiplyMatrix(const float* m1, const float* m2, float* dst) { // Support the case where m1 or m2 is the same array as dst. float product[16]; - + product[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; product[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]; product[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]; product[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]; - + product[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]; product[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]; product[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]; product[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]; - + product[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]; product[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]; product[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]; product[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]; - + product[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]; product[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]; product[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]; product[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]; - + memcpy(dst, product, MATRIX_SIZE); } -inline void MathUtil::negateMatrix(const float* m, float* dst) +inline void MathUtilC::negateMatrix(const float* m, float* dst) { dst[0] = -m[0]; dst[1] = -m[1]; @@ -148,7 +172,7 @@ inline void MathUtil::negateMatrix(const float* m, float* dst) dst[15] = -m[15]; } -inline void MathUtil::transposeMatrix(const float* m, float* dst) +inline void MathUtilC::transposeMatrix(const float* m, float* dst) { float t[16] = { m[0], m[4], m[8], m[12], @@ -159,33 +183,33 @@ inline void MathUtil::transposeMatrix(const float* m, float* dst) memcpy(dst, t, MATRIX_SIZE); } -inline void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, float* dst) +inline void MathUtilC::transformVec4(const float* m, float x, float y, float z, float w, float* dst) { dst[0] = x * m[0] + y * m[4] + z * m[8] + w * m[12]; dst[1] = x * m[1] + y * m[5] + z * m[9] + w * m[13]; dst[2] = x * m[2] + y * m[6] + z * m[10] + w * m[14]; } -inline void MathUtil::transformVec4(const float* m, const float* v, float* dst) +inline void MathUtilC::transformVec4(const float* m, const float* v, float* dst) { // Handle case where v == dst. float x = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12]; float y = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13]; float z = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14]; float w = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15]; - + dst[0] = x; dst[1] = y; dst[2] = z; dst[3] = w; } -inline void MathUtil::crossVec3(const float* v1, const float* v2, float* dst) +inline void MathUtilC::crossVec3(const float* v1, const float* v2, float* dst) { float x = (v1[1] * v2[2]) - (v1[2] * v2[1]); float y = (v1[2] * v2[0]) - (v1[0] * v2[2]); float z = (v1[0] * v2[1]) - (v1[1] * v2[0]); - + dst[0] = x; dst[1] = y; dst[2] = z; diff --git a/cocos/math/MathUtilNeon.inl b/cocos/math/MathUtilNeon.inl index f9c73498fd..bf41e6c704 100644 --- a/cocos/math/MathUtilNeon.inl +++ b/cocos/math/MathUtilNeon.inl @@ -17,232 +17,255 @@ This file was modified to fit the cocos2d-x project */ - NS_CC_MATH_BEGIN -inline void MathUtil::addMatrix(const float* m, float scalar, float* dst) +class MathUtilNeon +{ +public: + inline static void addMatrix(const float* m, float scalar, float* dst); + + inline static void addMatrix(const float* m1, const float* m2, float* dst); + + inline static void subtractMatrix(const float* m1, const float* m2, float* dst); + + inline static void multiplyMatrix(const float* m, float scalar, float* dst); + + inline static void multiplyMatrix(const float* m1, const float* m2, float* dst); + + inline static void negateMatrix(const float* m, float* dst); + + inline static void transposeMatrix(const float* m, float* dst); + + inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst); + + inline static void transformVec4(const float* m, const float* v, float* dst); + + inline static void crossVec3(const float* v1, const float* v2, float* dst); +}; + +inline void MathUtilNeon::addMatrix(const float* m, float scalar, float* dst) { asm volatile( - "vld1.32 {q0, q1}, [%1]! \n\t" // M[m0-m7] - "vld1.32 {q2, q3}, [%1] \n\t" // M[m8-m15] - "vld1.32 {d8[0]}, [%2] \n\t" // s - "vmov.f32 s17, s16 \n\t" // s - "vmov.f32 s18, s16 \n\t" // s - "vmov.f32 s19, s16 \n\t" // s - - "vadd.f32 q8, q0, q4 \n\t" // DST->M[m0-m3] = M[m0-m3] + s - "vadd.f32 q9, q1, q4 \n\t" // DST->M[m4-m7] = M[m4-m7] + s - "vadd.f32 q10, q2, q4 \n\t" // DST->M[m8-m11] = M[m8-m11] + s - "vadd.f32 q11, q3, q4 \n\t" // DST->M[m12-m15] = M[m12-m15] + s - - "vst1.32 {q8, q9}, [%0]! \n\t" // DST->M[m0-m7] - "vst1.32 {q10, q11}, [%0] \n\t" // DST->M[m8-m15] - : - : "r"(dst), "r"(m), "r"(&scalar) - : "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", "memory" - ); + "vld1.32 {q0, q1}, [%1]! \n\t" // M[m0-m7] + "vld1.32 {q2, q3}, [%1] \n\t" // M[m8-m15] + "vld1.32 {d8[0]}, [%2] \n\t" // s + "vmov.f32 s17, s16 \n\t" // s + "vmov.f32 s18, s16 \n\t" // s + "vmov.f32 s19, s16 \n\t" // s + + "vadd.f32 q8, q0, q4 \n\t" // DST->M[m0-m3] = M[m0-m3] + s + "vadd.f32 q9, q1, q4 \n\t" // DST->M[m4-m7] = M[m4-m7] + s + "vadd.f32 q10, q2, q4 \n\t" // DST->M[m8-m11] = M[m8-m11] + s + "vadd.f32 q11, q3, q4 \n\t" // DST->M[m12-m15] = M[m12-m15] + s + + "vst1.32 {q8, q9}, [%0]! \n\t" // DST->M[m0-m7] + "vst1.32 {q10, q11}, [%0] \n\t" // DST->M[m8-m15] + : + : "r"(dst), "r"(m), "r"(&scalar) + : "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", "memory" + ); } -inline void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) +inline void MathUtilNeon::addMatrix(const float* m1, const float* m2, float* dst) { asm volatile( - "vld1.32 {q0, q1}, [%1]! \n\t" // M1[m0-m7] - "vld1.32 {q2, q3}, [%1] \n\t" // M1[m8-m15] - "vld1.32 {q8, q9}, [%2]! \n\t" // M2[m0-m7] - "vld1.32 {q10, q11}, [%2] \n\t" // M2[m8-m15] - - "vadd.f32 q12, q0, q8 \n\t" // DST->M[m0-m3] = M1[m0-m3] + M2[m0-m3] - "vadd.f32 q13, q1, q9 \n\t" // DST->M[m4-m7] = M1[m4-m7] + M2[m4-m7] - "vadd.f32 q14, q2, q10 \n\t" // DST->M[m8-m11] = M1[m8-m11] + M2[m8-m11] - "vadd.f32 q15, q3, q11 \n\t" // DST->M[m12-m15] = M1[m12-m15] + M2[m12-m15] - - "vst1.32 {q12, q13}, [%0]! \n\t" // DST->M[m0-m7] - "vst1.32 {q14, q15}, [%0] \n\t" // DST->M[m8-m15] - : - : "r"(dst), "r"(m1), "r"(m2) - : "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "memory" - ); + "vld1.32 {q0, q1}, [%1]! \n\t" // M1[m0-m7] + "vld1.32 {q2, q3}, [%1] \n\t" // M1[m8-m15] + "vld1.32 {q8, q9}, [%2]! \n\t" // M2[m0-m7] + "vld1.32 {q10, q11}, [%2] \n\t" // M2[m8-m15] + + "vadd.f32 q12, q0, q8 \n\t" // DST->M[m0-m3] = M1[m0-m3] + M2[m0-m3] + "vadd.f32 q13, q1, q9 \n\t" // DST->M[m4-m7] = M1[m4-m7] + M2[m4-m7] + "vadd.f32 q14, q2, q10 \n\t" // DST->M[m8-m11] = M1[m8-m11] + M2[m8-m11] + "vadd.f32 q15, q3, q11 \n\t" // DST->M[m12-m15] = M1[m12-m15] + M2[m12-m15] + + "vst1.32 {q12, q13}, [%0]! \n\t" // DST->M[m0-m7] + "vst1.32 {q14, q15}, [%0] \n\t" // DST->M[m8-m15] + : + : "r"(dst), "r"(m1), "r"(m2) + : "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "memory" + ); } -inline void MathUtil::subtractMatrix(const float* m1, const float* m2, float* dst) +inline void MathUtilNeon::subtractMatrix(const float* m1, const float* m2, float* dst) { asm volatile( - "vld1.32 {q0, q1}, [%1]! \n\t" // M1[m0-m7] - "vld1.32 {q2, q3}, [%1] \n\t" // M1[m8-m15] - "vld1.32 {q8, q9}, [%2]! \n\t" // M2[m0-m7] - "vld1.32 {q10, q11}, [%2] \n\t" // M2[m8-m15] - - "vsub.f32 q12, q0, q8 \n\t" // DST->M[m0-m3] = M1[m0-m3] - M2[m0-m3] - "vsub.f32 q13, q1, q9 \n\t" // DST->M[m4-m7] = M1[m4-m7] - M2[m4-m7] - "vsub.f32 q14, q2, q10 \n\t" // DST->M[m8-m11] = M1[m8-m11] - M2[m8-m11] - "vsub.f32 q15, q3, q11 \n\t" // DST->M[m12-m15] = M1[m12-m15] - M2[m12-m15] - - "vst1.32 {q12, q13}, [%0]! \n\t" // DST->M[m0-m7] - "vst1.32 {q14, q15}, [%0] \n\t" // DST->M[m8-m15] - : - : "r"(dst), "r"(m1), "r"(m2) - : "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "memory" - ); + "vld1.32 {q0, q1}, [%1]! \n\t" // M1[m0-m7] + "vld1.32 {q2, q3}, [%1] \n\t" // M1[m8-m15] + "vld1.32 {q8, q9}, [%2]! \n\t" // M2[m0-m7] + "vld1.32 {q10, q11}, [%2] \n\t" // M2[m8-m15] + + "vsub.f32 q12, q0, q8 \n\t" // DST->M[m0-m3] = M1[m0-m3] - M2[m0-m3] + "vsub.f32 q13, q1, q9 \n\t" // DST->M[m4-m7] = M1[m4-m7] - M2[m4-m7] + "vsub.f32 q14, q2, q10 \n\t" // DST->M[m8-m11] = M1[m8-m11] - M2[m8-m11] + "vsub.f32 q15, q3, q11 \n\t" // DST->M[m12-m15] = M1[m12-m15] - M2[m12-m15] + + "vst1.32 {q12, q13}, [%0]! \n\t" // DST->M[m0-m7] + "vst1.32 {q14, q15}, [%0] \n\t" // DST->M[m8-m15] + : + : "r"(dst), "r"(m1), "r"(m2) + : "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "memory" + ); } -inline void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) +inline void MathUtilNeon::multiplyMatrix(const float* m, float scalar, float* dst) { asm volatile( - "vld1.32 {d0[0]}, [%2] \n\t" // M[m0-m7] - "vld1.32 {q4-q5}, [%1]! \n\t" // M[m8-m15] - "vld1.32 {q6-q7}, [%1] \n\t" // s - - "vmul.f32 q8, q4, d0[0] \n\t" // DST->M[m0-m3] = M[m0-m3] * s - "vmul.f32 q9, q5, d0[0] \n\t" // DST->M[m4-m7] = M[m4-m7] * s - "vmul.f32 q10, q6, d0[0] \n\t" // DST->M[m8-m11] = M[m8-m11] * s - "vmul.f32 q11, q7, d0[0] \n\t" // DST->M[m12-m15] = M[m12-m15] * s - - "vst1.32 {q8-q9}, [%0]! \n\t" // DST->M[m0-m7] - "vst1.32 {q10-q11}, [%0] \n\t" // DST->M[m8-m15] - : - : "r"(dst), "r"(m), "r"(&scalar) - : "q0", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "memory" - ); + "vld1.32 {d0[0]}, [%2] \n\t" // M[m0-m7] + "vld1.32 {q4-q5}, [%1]! \n\t" // M[m8-m15] + "vld1.32 {q6-q7}, [%1] \n\t" // s + + "vmul.f32 q8, q4, d0[0] \n\t" // DST->M[m0-m3] = M[m0-m3] * s + "vmul.f32 q9, q5, d0[0] \n\t" // DST->M[m4-m7] = M[m4-m7] * s + "vmul.f32 q10, q6, d0[0] \n\t" // DST->M[m8-m11] = M[m8-m11] * s + "vmul.f32 q11, q7, d0[0] \n\t" // DST->M[m12-m15] = M[m12-m15] * s + + "vst1.32 {q8-q9}, [%0]! \n\t" // DST->M[m0-m7] + "vst1.32 {q10-q11}, [%0] \n\t" // DST->M[m8-m15] + : + : "r"(dst), "r"(m), "r"(&scalar) + : "q0", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "memory" + ); } -inline void MathUtil::multiplyMatrix(const float* m1, const float* m2, float* dst) +inline void MathUtilNeon::multiplyMatrix(const float* m1, const float* m2, float* dst) { asm volatile( - "vld1.32 {d16 - d19}, [%1]! \n\t" // M1[m0-m7] - "vld1.32 {d20 - d23}, [%1] \n\t" // M1[m8-m15] - "vld1.32 {d0 - d3}, [%2]! \n\t" // M2[m0-m7] - "vld1.32 {d4 - d7}, [%2] \n\t" // M2[m8-m15] - - "vmul.f32 q12, q8, d0[0] \n\t" // DST->M[m0-m3] = M1[m0-m3] * M2[m0] - "vmul.f32 q13, q8, d2[0] \n\t" // DST->M[m4-m7] = M1[m4-m7] * M2[m4] - "vmul.f32 q14, q8, d4[0] \n\t" // DST->M[m8-m11] = M1[m8-m11] * M2[m8] - "vmul.f32 q15, q8, d6[0] \n\t" // DST->M[m12-m15] = M1[m12-m15] * M2[m12] - - "vmla.f32 q12, q9, d0[1] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m1] - "vmla.f32 q13, q9, d2[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m5] - "vmla.f32 q14, q9, d4[1] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m9] - "vmla.f32 q15, q9, d6[1] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m13] - - "vmla.f32 q12, q10, d1[0] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m2] - "vmla.f32 q13, q10, d3[0] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m6] - "vmla.f32 q14, q10, d5[0] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m10] - "vmla.f32 q15, q10, d7[0] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m14] - - "vmla.f32 q12, q11, d1[1] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m3] - "vmla.f32 q13, q11, d3[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m7] - "vmla.f32 q14, q11, d5[1] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m11] - "vmla.f32 q15, q11, d7[1] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m15] - - "vst1.32 {d24 - d27}, [%0]! \n\t" // DST->M[m0-m7] - "vst1.32 {d28 - d31}, [%0] \n\t" // DST->M[m8-m15] - - : // output - : "r"(dst), "r"(m1), "r"(m2) // input - note *value* of pointer doesn't change. - : "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" - ); + "vld1.32 {d16 - d19}, [%1]! \n\t" // M1[m0-m7] + "vld1.32 {d20 - d23}, [%1] \n\t" // M1[m8-m15] + "vld1.32 {d0 - d3}, [%2]! \n\t" // M2[m0-m7] + "vld1.32 {d4 - d7}, [%2] \n\t" // M2[m8-m15] + + "vmul.f32 q12, q8, d0[0] \n\t" // DST->M[m0-m3] = M1[m0-m3] * M2[m0] + "vmul.f32 q13, q8, d2[0] \n\t" // DST->M[m4-m7] = M1[m4-m7] * M2[m4] + "vmul.f32 q14, q8, d4[0] \n\t" // DST->M[m8-m11] = M1[m8-m11] * M2[m8] + "vmul.f32 q15, q8, d6[0] \n\t" // DST->M[m12-m15] = M1[m12-m15] * M2[m12] + + "vmla.f32 q12, q9, d0[1] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m1] + "vmla.f32 q13, q9, d2[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m5] + "vmla.f32 q14, q9, d4[1] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m9] + "vmla.f32 q15, q9, d6[1] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m13] + + "vmla.f32 q12, q10, d1[0] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m2] + "vmla.f32 q13, q10, d3[0] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m6] + "vmla.f32 q14, q10, d5[0] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m10] + "vmla.f32 q15, q10, d7[0] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m14] + + "vmla.f32 q12, q11, d1[1] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m3] + "vmla.f32 q13, q11, d3[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m7] + "vmla.f32 q14, q11, d5[1] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m11] + "vmla.f32 q15, q11, d7[1] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m15] + + "vst1.32 {d24 - d27}, [%0]! \n\t" // DST->M[m0-m7] + "vst1.32 {d28 - d31}, [%0] \n\t" // DST->M[m8-m15] + + : // output + : "r"(dst), "r"(m1), "r"(m2) // input - note *value* of pointer doesn't change. + : "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" + ); } -inline void MathUtil::negateMatrix(const float* m, float* dst) +inline void MathUtilNeon::negateMatrix(const float* m, float* dst) { asm volatile( - "vld1.32 {q0-q1}, [%1]! \n\t" // load m0-m7 - "vld1.32 {q2-q3}, [%1] \n\t" // load m8-m15 - - "vneg.f32 q4, q0 \n\t" // negate m0-m3 - "vneg.f32 q5, q1 \n\t" // negate m4-m7 - "vneg.f32 q6, q2 \n\t" // negate m8-m15 - "vneg.f32 q7, q3 \n\t" // negate m8-m15 - - "vst1.32 {q4-q5}, [%0]! \n\t" // store m0-m7 - "vst1.32 {q6-q7}, [%0] \n\t" // store m8-m15 - : - : "r"(dst), "r"(m) - : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "memory" - ); + "vld1.32 {q0-q1}, [%1]! \n\t" // load m0-m7 + "vld1.32 {q2-q3}, [%1] \n\t" // load m8-m15 + + "vneg.f32 q4, q0 \n\t" // negate m0-m3 + "vneg.f32 q5, q1 \n\t" // negate m4-m7 + "vneg.f32 q6, q2 \n\t" // negate m8-m15 + "vneg.f32 q7, q3 \n\t" // negate m8-m15 + + "vst1.32 {q4-q5}, [%0]! \n\t" // store m0-m7 + "vst1.32 {q6-q7}, [%0] \n\t" // store m8-m15 + : + : "r"(dst), "r"(m) + : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "memory" + ); } -inline void MathUtil::transposeMatrix(const float* m, float* dst) +inline void MathUtilNeon::transposeMatrix(const float* m, float* dst) { asm volatile( - "vld4.32 {d0[0], d2[0], d4[0], d6[0]}, [%1]! \n\t" // DST->M[m0, m4, m8, m12] = M[m0-m3] - "vld4.32 {d0[1], d2[1], d4[1], d6[1]}, [%1]! \n\t" // DST->M[m1, m5, m9, m12] = M[m4-m7] - "vld4.32 {d1[0], d3[0], d5[0], d7[0]}, [%1]! \n\t" // DST->M[m2, m6, m10, m12] = M[m8-m11] - "vld4.32 {d1[1], d3[1], d5[1], d7[1]}, [%1] \n\t" // DST->M[m3, m7, m11, m12] = M[m12-m15] - - "vst1.32 {q0-q1}, [%0]! \n\t" // DST->M[m0-m7] - "vst1.32 {q2-q3}, [%0] \n\t" // DST->M[m8-m15] - : - : "r"(dst), "r"(m) - : "q0", "q1", "q2", "q3", "memory" - ); + "vld4.32 {d0[0], d2[0], d4[0], d6[0]}, [%1]! \n\t" // DST->M[m0, m4, m8, m12] = M[m0-m3] + "vld4.32 {d0[1], d2[1], d4[1], d6[1]}, [%1]! \n\t" // DST->M[m1, m5, m9, m12] = M[m4-m7] + "vld4.32 {d1[0], d3[0], d5[0], d7[0]}, [%1]! \n\t" // DST->M[m2, m6, m10, m12] = M[m8-m11] + "vld4.32 {d1[1], d3[1], d5[1], d7[1]}, [%1] \n\t" // DST->M[m3, m7, m11, m12] = M[m12-m15] + + "vst1.32 {q0-q1}, [%0]! \n\t" // DST->M[m0-m7] + "vst1.32 {q2-q3}, [%0] \n\t" // DST->M[m8-m15] + : + : "r"(dst), "r"(m) + : "q0", "q1", "q2", "q3", "memory" + ); } -inline void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, float* dst) +inline void MathUtilNeon::transformVec4(const float* m, float x, float y, float z, float w, float* dst) { asm volatile( - "vld1.32 {d0[0]}, [%1] \n\t" // V[x] - "vld1.32 {d0[1]}, [%2] \n\t" // V[y] - "vld1.32 {d1[0]}, [%3] \n\t" // V[z] - "vld1.32 {d1[1]}, [%4] \n\t" // V[w] - "vld1.32 {d18 - d21}, [%5]! \n\t" // M[m0-m7] - "vld1.32 {d22 - d25}, [%5] \n\t" // M[m8-m15] - - "vmul.f32 q13, q9, d0[0] \n\t" // DST->V = M[m0-m3] * V[x] - "vmla.f32 q13, q10, d0[1] \n\t" // DST->V += M[m4-m7] * V[y] - "vmla.f32 q13, q11, d1[0] \n\t" // DST->V += M[m8-m11] * V[z] - "vmla.f32 q13, q12, d1[1] \n\t" // DST->V += M[m12-m15] * V[w] - - "vst1.32 {d26}, [%0]! \n\t" // DST->V[x, y] - "vst1.32 {d27[0]}, [%0] \n\t" // DST->V[z] - : - : "r"(dst), "r"(&x), "r"(&y), "r"(&z), "r"(&w), "r"(m) - : "q0", "q9", "q10","q11", "q12", "q13", "memory" - ); + "vld1.32 {d0[0]}, [%1] \n\t" // V[x] + "vld1.32 {d0[1]}, [%2] \n\t" // V[y] + "vld1.32 {d1[0]}, [%3] \n\t" // V[z] + "vld1.32 {d1[1]}, [%4] \n\t" // V[w] + "vld1.32 {d18 - d21}, [%5]! \n\t" // M[m0-m7] + "vld1.32 {d22 - d25}, [%5] \n\t" // M[m8-m15] + + "vmul.f32 q13, q9, d0[0] \n\t" // DST->V = M[m0-m3] * V[x] + "vmla.f32 q13, q10, d0[1] \n\t" // DST->V += M[m4-m7] * V[y] + "vmla.f32 q13, q11, d1[0] \n\t" // DST->V += M[m8-m11] * V[z] + "vmla.f32 q13, q12, d1[1] \n\t" // DST->V += M[m12-m15] * V[w] + + "vst1.32 {d26}, [%0]! \n\t" // DST->V[x, y] + "vst1.32 {d27[0]}, [%0] \n\t" // DST->V[z] + : + : "r"(dst), "r"(&x), "r"(&y), "r"(&z), "r"(&w), "r"(m) + : "q0", "q9", "q10","q11", "q12", "q13", "memory" + ); } -inline void MathUtil::transformVec4(const float* m, const float* v, float* dst) +inline void MathUtilNeon::transformVec4(const float* m, const float* v, float* dst) { asm volatile ( - "vld1.32 {d0, d1}, [%1] \n\t" // V[x, y, z, w] - "vld1.32 {d18 - d21}, [%2]! \n\t" // M[m0-m7] - "vld1.32 {d22 - d25}, [%2] \n\t" // M[m8-m15] - - "vmul.f32 q13, q9, d0[0] \n\t" // DST->V = M[m0-m3] * V[x] - "vmla.f32 q13, q10, d0[1] \n\t" // DST->V = M[m4-m7] * V[y] - "vmla.f32 q13, q11, d1[0] \n\t" // DST->V = M[m8-m11] * V[z] - "vmla.f32 q13, q12, d1[1] \n\t" // DST->V = M[m12-m15] * V[w] - - "vst1.32 {d26, d27}, [%0] \n\t" // DST->V - : - : "r"(dst), "r"(v), "r"(m) - : "q0", "q9", "q10","q11", "q12", "q13", "memory" - ); + "vld1.32 {d0, d1}, [%1] \n\t" // V[x, y, z, w] + "vld1.32 {d18 - d21}, [%2]! \n\t" // M[m0-m7] + "vld1.32 {d22 - d25}, [%2] \n\t" // M[m8-m15] + + "vmul.f32 q13, q9, d0[0] \n\t" // DST->V = M[m0-m3] * V[x] + "vmla.f32 q13, q10, d0[1] \n\t" // DST->V = M[m4-m7] * V[y] + "vmla.f32 q13, q11, d1[0] \n\t" // DST->V = M[m8-m11] * V[z] + "vmla.f32 q13, q12, d1[1] \n\t" // DST->V = M[m12-m15] * V[w] + + "vst1.32 {d26, d27}, [%0] \n\t" // DST->V + : + : "r"(dst), "r"(v), "r"(m) + : "q0", "q9", "q10","q11", "q12", "q13", "memory" + ); } -inline void MathUtil::crossVec3(const float* v1, const float* v2, float* dst) +inline void MathUtilNeon::crossVec3(const float* v1, const float* v2, float* dst) { asm volatile( - "vld1.32 {d1[1]}, [%1] \n\t" // - "vld1.32 {d0}, [%2] \n\t" // - "vmov.f32 s2, s1 \n\t" // q0 = (v1y, v1z, v1z, v1x) - - "vld1.32 {d2[1]}, [%3] \n\t" // - "vld1.32 {d3}, [%4] \n\t" // - "vmov.f32 s4, s7 \n\t" // q1 = (v2z, v2x, v2y, v2z) - - "vmul.f32 d4, d0, d2 \n\t" // x = v1y * v2z, y = v1z * v2x - "vmls.f32 d4, d1, d3 \n\t" // x -= v1z * v2y, y-= v1x - v2z - - "vmul.f32 d5, d3, d1[1] \n\t" // z = v1x * v2y - "vmls.f32 d5, d0, d2[1] \n\t" // z-= v1y * vx - - "vst1.32 {d4}, [%0]! \n\t" // V[x, y] - "vst1.32 {d5[0]}, [%0] \n\t" // V[z] - : - : "r"(dst), "r"(v1), "r"((v1+1)), "r"(v2), "r"((v2+1)) - : "q0", "q1", "q2", "memory" - ); + "vld1.32 {d1[1]}, [%1] \n\t" // + "vld1.32 {d0}, [%2] \n\t" // + "vmov.f32 s2, s1 \n\t" // q0 = (v1y, v1z, v1z, v1x) + + "vld1.32 {d2[1]}, [%3] \n\t" // + "vld1.32 {d3}, [%4] \n\t" // + "vmov.f32 s4, s7 \n\t" // q1 = (v2z, v2x, v2y, v2z) + + "vmul.f32 d4, d0, d2 \n\t" // x = v1y * v2z, y = v1z * v2x + "vmls.f32 d4, d1, d3 \n\t" // x -= v1z * v2y, y-= v1x - v2z + + "vmul.f32 d5, d3, d1[1] \n\t" // z = v1x * v2y + "vmls.f32 d5, d0, d2[1] \n\t" // z-= v1y * vx + + "vst1.32 {d4}, [%0]! \n\t" // V[x, y] + "vst1.32 {d5[0]}, [%0] \n\t" // V[z] + : + : "r"(dst), "r"(v1), "r"((v1+1)), "r"(v2), "r"((v2+1)) + : "q0", "q1", "q2", "memory" + ); } NS_CC_MATH_END diff --git a/cocos/math/MathUtilNeon64.inl b/cocos/math/MathUtilNeon64.inl new file mode 100644 index 0000000000..8e868798ef --- /dev/null +++ b/cocos/math/MathUtilNeon64.inl @@ -0,0 +1,218 @@ +/** + Copyright 2013 BlackBerry Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Original file from GamePlay3D: http://gameplay3d.org + + This file was modified to fit the cocos2d-x project + */ + +NS_CC_MATH_BEGIN + +class MathUtilNeon64 +{ +public: + inline static void addMatrix(const float* m, float scalar, float* dst); + + inline static void addMatrix(const float* m1, const float* m2, float* dst); + + inline static void subtractMatrix(const float* m1, const float* m2, float* dst); + + inline static void multiplyMatrix(const float* m, float scalar, float* dst); + + inline static void multiplyMatrix(const float* m1, const float* m2, float* dst); + + inline static void negateMatrix(const float* m, float* dst); + + inline static void transposeMatrix(const float* m, float* dst); + + inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst); + + inline static void transformVec4(const float* m, const float* v, float* dst); + + inline static void crossVec3(const float* v1, const float* v2, float* dst); +}; + +inline void MathUtilNeon64::addMatrix(const float* m, float scalar, float* dst) +{ + dst[0] = m[0] + scalar; + dst[1] = m[1] + scalar; + dst[2] = m[2] + scalar; + dst[3] = m[3] + scalar; + dst[4] = m[4] + scalar; + dst[5] = m[5] + scalar; + dst[6] = m[6] + scalar; + dst[7] = m[7] + scalar; + dst[8] = m[8] + scalar; + dst[9] = m[9] + scalar; + dst[10] = m[10] + scalar; + dst[11] = m[11] + scalar; + dst[12] = m[12] + scalar; + dst[13] = m[13] + scalar; + dst[14] = m[14] + scalar; + dst[15] = m[15] + scalar; +} + +inline void MathUtilNeon64::addMatrix(const float* m1, const float* m2, float* dst) +{ + dst[0] = m1[0] + m2[0]; + dst[1] = m1[1] + m2[1]; + dst[2] = m1[2] + m2[2]; + dst[3] = m1[3] + m2[3]; + dst[4] = m1[4] + m2[4]; + dst[5] = m1[5] + m2[5]; + dst[6] = m1[6] + m2[6]; + dst[7] = m1[7] + m2[7]; + dst[8] = m1[8] + m2[8]; + dst[9] = m1[9] + m2[9]; + dst[10] = m1[10] + m2[10]; + dst[11] = m1[11] + m2[11]; + dst[12] = m1[12] + m2[12]; + dst[13] = m1[13] + m2[13]; + dst[14] = m1[14] + m2[14]; + dst[15] = m1[15] + m2[15]; +} + +inline void MathUtilNeon64::subtractMatrix(const float* m1, const float* m2, float* dst) +{ + dst[0] = m1[0] - m2[0]; + dst[1] = m1[1] - m2[1]; + dst[2] = m1[2] - m2[2]; + dst[3] = m1[3] - m2[3]; + dst[4] = m1[4] - m2[4]; + dst[5] = m1[5] - m2[5]; + dst[6] = m1[6] - m2[6]; + dst[7] = m1[7] - m2[7]; + dst[8] = m1[8] - m2[8]; + dst[9] = m1[9] - m2[9]; + dst[10] = m1[10] - m2[10]; + dst[11] = m1[11] - m2[11]; + dst[12] = m1[12] - m2[12]; + dst[13] = m1[13] - m2[13]; + dst[14] = m1[14] - m2[14]; + dst[15] = m1[15] - m2[15]; +} + +inline void MathUtilNeon64::multiplyMatrix(const float* m, float scalar, float* dst) +{ + dst[0] = m[0] * scalar; + dst[1] = m[1] * scalar; + dst[2] = m[2] * scalar; + dst[3] = m[3] * scalar; + dst[4] = m[4] * scalar; + dst[5] = m[5] * scalar; + dst[6] = m[6] * scalar; + dst[7] = m[7] * scalar; + dst[8] = m[8] * scalar; + dst[9] = m[9] * scalar; + dst[10] = m[10] * scalar; + dst[11] = m[11] * scalar; + dst[12] = m[12] * scalar; + dst[13] = m[13] * scalar; + dst[14] = m[14] * scalar; + dst[15] = m[15] * scalar; +} + +inline void MathUtilNeon64::multiplyMatrix(const float* m1, const float* m2, float* dst) +{ + // Support the case where m1 or m2 is the same array as dst. + float product[16]; + + product[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; + product[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]; + product[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]; + product[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]; + + product[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]; + product[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]; + product[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]; + product[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]; + + product[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]; + product[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]; + product[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]; + product[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]; + + product[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]; + product[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]; + product[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]; + product[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]; + + memcpy(dst, product, MATRIX_SIZE); +} + +inline void MathUtilNeon64::negateMatrix(const float* m, float* dst) +{ + dst[0] = -m[0]; + dst[1] = -m[1]; + dst[2] = -m[2]; + dst[3] = -m[3]; + dst[4] = -m[4]; + dst[5] = -m[5]; + dst[6] = -m[6]; + dst[7] = -m[7]; + dst[8] = -m[8]; + dst[9] = -m[9]; + dst[10] = -m[10]; + dst[11] = -m[11]; + dst[12] = -m[12]; + dst[13] = -m[13]; + dst[14] = -m[14]; + dst[15] = -m[15]; +} + +inline void MathUtilNeon64::transposeMatrix(const float* m, float* dst) +{ + float t[16] = { + m[0], m[4], m[8], m[12], + m[1], m[5], m[9], m[13], + m[2], m[6], m[10], m[14], + m[3], m[7], m[11], m[15] + }; + memcpy(dst, t, MATRIX_SIZE); +} + +inline void MathUtilNeon64::transformVec4(const float* m, float x, float y, float z, float w, float* dst) +{ + dst[0] = x * m[0] + y * m[4] + z * m[8] + w * m[12]; + dst[1] = x * m[1] + y * m[5] + z * m[9] + w * m[13]; + dst[2] = x * m[2] + y * m[6] + z * m[10] + w * m[14]; +} + +inline void MathUtilNeon64::transformVec4(const float* m, const float* v, float* dst) +{ + // Handle case where v == dst. + float x = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12]; + float y = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13]; + float z = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14]; + float w = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15]; + + dst[0] = x; + dst[1] = y; + dst[2] = z; + dst[3] = w; +} + +inline void MathUtilNeon64::crossVec3(const float* v1, const float* v2, float* dst) +{ + float x = (v1[1] * v2[2]) - (v1[2] * v2[1]); + float y = (v1[2] * v2[0]) - (v1[0] * v2[2]); + float z = (v1[0] * v2[1]) - (v1[1] * v2[0]); + + dst[0] = x; + dst[1] = y; + dst[2] = z; +} + +NS_CC_MATH_END diff --git a/cocos/math/MathUtilSSE.inl b/cocos/math/MathUtilSSE.inl index b701bb51ca..3a6d5c1de0 100644 --- a/cocos/math/MathUtilSSE.inl +++ b/cocos/math/MathUtilSSE.inl @@ -1,6 +1,8 @@ NS_CC_MATH_BEGIN -inline void MathUtil::addMatrix(const __m128 m[4], float scalar, __m128 dst[4]) +#ifdef __SSE__ + +void MathUtil::addMatrix(const __m128 m[4], float scalar, __m128 dst[4]) { __m128 s = _mm_set1_ps(scalar); dst[0] = _mm_add_ps(m[0], s); @@ -9,7 +11,7 @@ inline void MathUtil::addMatrix(const __m128 m[4], float scalar, __m128 dst[4]) dst[3] = _mm_add_ps(m[3], s); } -inline void MathUtil::addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +void MathUtil::addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) { dst[0] = _mm_add_ps(m1[0], m2[0]); dst[1] = _mm_add_ps(m1[1], m2[1]); @@ -17,7 +19,7 @@ inline void MathUtil::addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 d dst[3] = _mm_add_ps(m1[3], m2[3]); } -inline void MathUtil::subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +void MathUtil::subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) { dst[0] = _mm_sub_ps(m1[0], m2[0]); dst[1] = _mm_sub_ps(m1[1], m2[1]); @@ -25,7 +27,7 @@ inline void MathUtil::subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m dst[3] = _mm_sub_ps(m1[3], m2[3]); } -inline void MathUtil::multiplyMatrix(const __m128 m[4], float scalar, __m128 dst[4]) +void MathUtil::multiplyMatrix(const __m128 m[4], float scalar, __m128 dst[4]) { __m128 s = _mm_set1_ps(scalar); dst[0] = _mm_mul_ps(m[0], s); @@ -34,7 +36,7 @@ inline void MathUtil::multiplyMatrix(const __m128 m[4], float scalar, __m128 dst dst[3] = _mm_mul_ps(m[3], s); } -inline void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) { __m128 dst0, dst1, dst2, dst3; { @@ -114,7 +116,7 @@ inline void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m dst[3] = dst3; } -inline void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) +void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) { __m128 z = _mm_setzero_ps(); dst[0] = _mm_sub_ps(z, m[0]); @@ -123,7 +125,7 @@ inline void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) dst[3] = _mm_sub_ps(z, m[3]); } -inline void MathUtil::transposeMatrix(const __m128 m[4], __m128 dst[4]) +void MathUtil::transposeMatrix(const __m128 m[4], __m128 dst[4]) { __m128 tmp0 = _mm_shuffle_ps(m[0], m[1], 0x44); __m128 tmp2 = _mm_shuffle_ps(m[0], m[1], 0xEE); @@ -136,7 +138,7 @@ inline void MathUtil::transposeMatrix(const __m128 m[4], __m128 dst[4]) dst[3] = _mm_shuffle_ps(tmp2, tmp3, 0xDD); } -inline void MathUtil::transformVec4(const __m128 m[4], const __m128& v, __m128& dst) +void MathUtil::transformVec4(const __m128 m[4], const __m128& v, __m128& dst) { __m128 col1 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0)); __m128 col2 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1)); @@ -144,9 +146,12 @@ inline void MathUtil::transformVec4(const __m128 m[4], const __m128& v, __m128& __m128 col4 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(3, 3, 3, 3)); dst = _mm_add_ps( - _mm_add_ps(_mm_mul_ps(m[0], col1), _mm_mul_ps(m[1], col2)), - _mm_add_ps(_mm_mul_ps(m[2], col3), _mm_mul_ps(m[3], col4)) - ); + _mm_add_ps(_mm_mul_ps(m[0], col1), _mm_mul_ps(m[1], col2)), + _mm_add_ps(_mm_mul_ps(m[2], col3), _mm_mul_ps(m[3], col4)) + ); } +#endif + + NS_CC_MATH_END diff --git a/cocos/platform/CCApplicationProtocol.h b/cocos/platform/CCApplicationProtocol.h index 6d9697fdb6..9993973d0c 100644 --- a/cocos/platform/CCApplicationProtocol.h +++ b/cocos/platform/CCApplicationProtocol.h @@ -133,6 +133,15 @@ public: * @lua NA */ virtual Platform getTargetPlatform() = 0; + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + * @js NA + * @lua NA + */ + virtual bool openURL(const std::string &url) = 0; }; // end of platform group diff --git a/cocos/platform/android/CCApplication-android.cpp b/cocos/platform/android/CCApplication-android.cpp index e542fcf0b5..f91c22cbac 100644 --- a/cocos/platform/android/CCApplication-android.cpp +++ b/cocos/platform/android/CCApplication-android.cpp @@ -176,6 +176,11 @@ Application::Platform Application::getTargetPlatform() return Platform::OS_ANDROID; } +bool Application::openURL(const std::string &url) +{ + return openURLJNI(url.c_str()); +} + void Application::applicationScreenSizeChanged(int newWidth, int newHeight) { } diff --git a/cocos/platform/android/CCApplication-android.h b/cocos/platform/android/CCApplication-android.h index e0a3975824..9b11b87a3e 100644 --- a/cocos/platform/android/CCApplication-android.h +++ b/cocos/platform/android/CCApplication-android.h @@ -83,6 +83,13 @@ public: @brief Get target platform */ virtual Platform getTargetPlatform(); + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + */ + virtual bool openURL(const std::string &url); /** @brief This function will be called when the application screen size is changed. diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index ebbc5bdc75..2c6168ac59 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -32,9 +32,11 @@ import java.lang.Runnable; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.res.AssetManager; +import android.net.Uri; import android.os.Build; import android.preference.PreferenceManager.OnActivityResultListener; import android.util.DisplayMetrics; @@ -170,6 +172,18 @@ public class Cocos2dxHelper { public static void setKeepScreenOn(boolean value) { ((Cocos2dxActivity)sActivity).setKeepScreenOn(value); } + + public static boolean openURL(String url) { + boolean ret = false; + try { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + sActivity.startActivity(i); + ret = true; + } catch (Exception e) { + } + return ret; + } public static void preloadBackgroundMusic(final String pPath) { Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath); diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp index b7b25a937d..677432216c 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp @@ -219,6 +219,20 @@ void setKeepScreenOnJni(bool value) { } } +extern bool openURLJNI(const char* url) { + JniMethodInfo t; + + bool ret = false; + if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "openURL", "(Ljava/lang/String;)Z")) { + jstring stringArg = t.env->NewStringUTF(url); + ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg); + + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(stringArg); + } + return ret; +} + // functions for UserDefault bool getBoolForKeyJNI(const char* key, bool defaultValue) { diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h index 7044a4e5e4..eda006b94f 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h @@ -40,6 +40,7 @@ extern void enableAccelerometerJni(); extern void disableAccelerometerJni(); extern void setAccelerometerIntervalJni(float interval); extern void setKeepScreenOnJni(bool value); +extern bool openURLJNI(const char* url); // functions for UserDefault extern bool getBoolForKeyJNI(const char* key, bool defaultValue); extern int getIntegerForKeyJNI(const char* key, int defaultValue); diff --git a/cocos/platform/ios/CCApplication-ios.h b/cocos/platform/ios/CCApplication-ios.h index 88c6a4f486..e88cc667c1 100644 --- a/cocos/platform/ios/CCApplication-ios.h +++ b/cocos/platform/ios/CCApplication-ios.h @@ -85,6 +85,13 @@ public: @brief Get target platform */ virtual Platform getTargetPlatform(); + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + */ + virtual bool openURL(const std::string &url); /** @brief This function will be called when the application screen size is changed. diff --git a/cocos/platform/ios/CCApplication-ios.mm b/cocos/platform/ios/CCApplication-ios.mm index cbacf107e9..d1c69ff83c 100644 --- a/cocos/platform/ios/CCApplication-ios.mm +++ b/cocos/platform/ios/CCApplication-ios.mm @@ -167,6 +167,13 @@ Application::Platform Application::getTargetPlatform() } } +bool Application::openURL(const std::string &url) +{ + NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; + NSURL* nsUrl = [NSURL URLWithString:msg]; + return [[UIApplication sharedApplication] openURL:nsUrl]; +} + void Application::applicationScreenSizeChanged(int newWidth, int newHeight) { } diff --git a/cocos/platform/ios/CCEAGLView-ios.mm b/cocos/platform/ios/CCEAGLView-ios.mm index 338b3907a2..b3d5fc4100 100644 --- a/cocos/platform/ios/CCEAGLView-ios.mm +++ b/cocos/platform/ios/CCEAGLView-ios.mm @@ -731,7 +731,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. CGSize viewSize = self.frame.size; CGFloat tmp; - switch ([[UIApplication sharedApplication] statusBarOrientation]) + switch (getFixedOrientation([[UIApplication sharedApplication] statusBarOrientation])) { case UIInterfaceOrientationPortrait: begin.origin.y = viewSize.height - begin.origin.y - begin.size.height; @@ -744,15 +744,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. break; case UIInterfaceOrientationLandscapeLeft: - tmp = begin.size.width; - begin.size.width = begin.size.height; - begin.size.height = tmp; - tmp = end.size.width; - end.size.width = end.size.height; - end.size.height = tmp; - tmp = viewSize.width; - viewSize.width = viewSize.height; - viewSize.height = tmp; + std::swap(begin.size.width, begin.size.height); + std::swap(end.size.width, end.size.height); + std::swap(viewSize.width, viewSize.height); tmp = begin.origin.x; begin.origin.x = begin.origin.y; @@ -763,15 +757,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. break; case UIInterfaceOrientationLandscapeRight: - tmp = begin.size.width; - begin.size.width = begin.size.height; - begin.size.height = tmp; - tmp = end.size.width; - end.size.width = end.size.height; - end.size.height = tmp; - tmp = viewSize.width; - viewSize.width = viewSize.height; - viewSize.height = tmp; + std::swap(begin.size.width, begin.size.height); + std::swap(end.size.width, end.size.height); + std::swap(viewSize.width, viewSize.height); tmp = begin.origin.x; begin.origin.x = begin.origin.y; @@ -850,6 +838,15 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. } } +UIInterfaceOrientation getFixedOrientation(UIInterfaceOrientation statusBarOrientation) +{ + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) + { + statusBarOrientation = UIInterfaceOrientationPortrait; + } + return statusBarOrientation; +} + -(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)dis { [UIView beginAnimations:nil context:nullptr]; @@ -869,7 +866,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. dis /= 2.0f; } - switch ([[UIApplication sharedApplication] statusBarOrientation]) + switch (getFixedOrientation([[UIApplication sharedApplication] statusBarOrientation])) { case UIInterfaceOrientationPortrait: self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y - dis, originalRect_.size.width, originalRect_.size.height); diff --git a/cocos/platform/linux/CCApplication-linux.cpp b/cocos/platform/linux/CCApplication-linux.cpp index 65310a9b0c..d3571aef03 100644 --- a/cocos/platform/linux/CCApplication-linux.cpp +++ b/cocos/platform/linux/CCApplication-linux.cpp @@ -136,6 +136,12 @@ Application::Platform Application::getTargetPlatform() return Platform::OS_LINUX; } +bool Application::openURL(const std::string &url) +{ + std::string op = std::string("open ").append(url); + return system(op.c_str())!=-1; +} + ////////////////////////////////////////////////////////////////////////// // static member function ////////////////////////////////////////////////////////////////////////// diff --git a/cocos/platform/linux/CCApplication-linux.h b/cocos/platform/linux/CCApplication-linux.h index 5c7163fc6e..e7334b50c9 100644 --- a/cocos/platform/linux/CCApplication-linux.h +++ b/cocos/platform/linux/CCApplication-linux.h @@ -77,6 +77,13 @@ public: @return Current language iso 639-1 code */ virtual const char * getCurrentLanguageCode(); + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + */ + virtual bool openURL(const std::string &url); /** diff --git a/cocos/platform/mac/CCApplication-mac.h b/cocos/platform/mac/CCApplication-mac.h index 8ff4c7e166..f75c1d08d9 100644 --- a/cocos/platform/mac/CCApplication-mac.h +++ b/cocos/platform/mac/CCApplication-mac.h @@ -90,6 +90,13 @@ public: @brief Get target platform */ virtual Platform getTargetPlatform(); + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + */ + virtual bool openURL(const std::string &url); /** * Sets the Resource root path. diff --git a/cocos/platform/mac/CCApplication-mac.mm b/cocos/platform/mac/CCApplication-mac.mm index ca72c23883..c767948e09 100644 --- a/cocos/platform/mac/CCApplication-mac.mm +++ b/cocos/platform/mac/CCApplication-mac.mm @@ -213,6 +213,13 @@ LanguageType Application::getCurrentLanguage() return ret; } +bool Application::openURL(const std::string &url) +{ + NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; + NSURL* nsUrl = [NSURL URLWithString:msg]; + return [[NSWorkspace sharedWorkspace] openURL:nsUrl]; +} + void Application::setResourceRootPath(const std::string& rootResDir) { _resourceRootPath = rootResDir; diff --git a/cocos/platform/win32/CCApplication-win32.cpp b/cocos/platform/win32/CCApplication-win32.cpp index b419c69e33..ab3fb7f150 100644 --- a/cocos/platform/win32/CCApplication-win32.cpp +++ b/cocos/platform/win32/CCApplication-win32.cpp @@ -30,6 +30,7 @@ THE SOFTWARE. #include "base/CCDirector.h" #include #include "platform/CCFileUtils.h" +#include /** @brief This function change the PVRFrame show/hide setting in register. @param bEnable If true show the PVRFrame window, otherwise hide. @@ -206,6 +207,15 @@ Application::Platform Application::getTargetPlatform() return Platform::OS_WINDOWS; } +bool Application::openURL(const std::string &url) +{ + WCHAR *temp = new WCHAR[url.size() + 1]; + int wchars_num = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.size() + 1, temp, url.size() + 1); + HINSTANCE r = ShellExecuteW(NULL, L"open", temp, NULL, NULL, SW_SHOWNORMAL); + delete[] temp; + return (int)r>32; +} + void Application::setResourceRootPath(const std::string& rootResDir) { _resourceRootPath = rootResDir; diff --git a/cocos/platform/win32/CCApplication-win32.h b/cocos/platform/win32/CCApplication-win32.h index bd4afd7a3d..c30a697d74 100644 --- a/cocos/platform/win32/CCApplication-win32.h +++ b/cocos/platform/win32/CCApplication-win32.h @@ -74,6 +74,13 @@ public: @brief Get target platform */ virtual Platform getTargetPlatform(); + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + */ + virtual bool openURL(const std::string &url); /** * Sets the Resource root path. diff --git a/cocos/platform/winrt/CCApplication.cpp b/cocos/platform/winrt/CCApplication.cpp index c039b4a8f7..009e1a06b9 100644 --- a/cocos/platform/winrt/CCApplication.cpp +++ b/cocos/platform/winrt/CCApplication.cpp @@ -54,7 +54,8 @@ Application * Application::sm_pSharedApplication = 0; // sharedApplication pointer Application * s_pSharedApplication = 0; -Application::Application() +Application::Application() : +m_openURLDelegate(nullptr) { m_nAnimationInterval.QuadPart = 0; CC_ASSERT(! sm_pSharedApplication); @@ -177,6 +178,19 @@ Application::Platform Application::getTargetPlatform() return Platform::OS_WP8; } +bool Application::openURL(const std::string &url) +{ + if (m_openURLDelegate) + { + m_openURLDelegate(PlatformStringFromString(url)); + return true; + } + else + { + return false; + } +} + void Application::setResourceRootPath(const std::string& rootResDir) { m_resourceRootPath = rootResDir; diff --git a/cocos/platform/winrt/CCApplication.h b/cocos/platform/winrt/CCApplication.h index ac6435527e..f97c4896f3 100644 --- a/cocos/platform/winrt/CCApplication.h +++ b/cocos/platform/winrt/CCApplication.h @@ -31,6 +31,7 @@ THE SOFTWARE. #include "platform/CCStdC.h" #include "platform/CCCommon.h" #include "platform/CCApplicationProtocol.h" +#include "platform/winrt/InputEvent.h" #include NS_CC_BEGIN @@ -62,6 +63,22 @@ public: @brief Get target platform */ virtual Platform getTargetPlatform() override; + + /** + @brief Open url in default browser + @param String with url to open. + @return true if the resource located by the URL was successfully opened; otherwise false. + */ + virtual bool openURL(const std::string &url); + + /** + @brief Set the callback responsible for opening a URL. + @param del The delegate that will handle opening a URL. We can't pass back a Platform::String due to name clash. + */ + void SetXamlOpenURLDelegate(const std::function& del) + { + m_openURLDelegate = del; + } /** * Sets the Resource root path. @@ -87,6 +104,8 @@ protected: std::string m_resourceRootPath; std::string m_startupScriptFilename; + std::function m_openURLDelegate; + static Application * sm_pSharedApplication; }; diff --git a/cocos/platform/winrt/CCDevice.cpp b/cocos/platform/winrt/CCDevice.cpp index bc2b9ac6a5..253d838fd0 100644 --- a/cocos/platform/winrt/CCDevice.cpp +++ b/cocos/platform/winrt/CCDevice.cpp @@ -54,6 +54,14 @@ void Device::setAccelerometerEnabled(bool isEnabled) static Windows::Foundation::EventRegistrationToken sToken; static bool sEnabled = false; + // we always need to reset the accelerometer + if (sAccelerometer) + { + sAccelerometer->ReadingChanged -= sToken; + sAccelerometer = nullptr; + sEnabled = false; + } + if (isEnabled) { sAccelerometer = Accelerometer::GetDefault(); @@ -118,17 +126,6 @@ void Device::setAccelerometerEnabled(bool isEnabled) cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(event); }); } - else - { - if (sAccelerometer) - { - sAccelerometer->ReadingChanged -= sToken; - sAccelerometer = nullptr; - } - - sEnabled = false; - } - } void Device::setAccelerometerInterval(float interval) diff --git a/cocos/platform/winrt/CCWinRTUtils.cpp b/cocos/platform/winrt/CCWinRTUtils.cpp index c874cc0b1d..c025fbb9ef 100644 --- a/cocos/platform/winrt/CCWinRTUtils.cpp +++ b/cocos/platform/winrt/CCWinRTUtils.cpp @@ -95,6 +95,12 @@ std::string PlatformStringToString(Platform::String^ s) { return std::string(t.begin(),t.end()); } +Platform::String^ PlatformStringFromString(const std::string& s) +{ + std::wstring ws(CCUtf8ToUnicode(s.c_str())); + return ref new Platform::String(ws.data(), ws.length()); +} + // Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels. float ConvertDipsToPixels(float dips) { diff --git a/cocos/platform/winrt/CCWinRTUtils.h b/cocos/platform/winrt/CCWinRTUtils.h index 5671e352cf..75b4225bda 100644 --- a/cocos/platform/winrt/CCWinRTUtils.h +++ b/cocos/platform/winrt/CCWinRTUtils.h @@ -41,6 +41,7 @@ NS_CC_BEGIN std::wstring CC_DLL CCUtf8ToUnicode(const char * pszUtf8Str, unsigned len = -1); std::string CC_DLL CCUnicodeToUtf8(const wchar_t* pwszStr); std::string PlatformStringToString(Platform::String^ s); +Platform::String^ PlatformStringFromString(const std::string& s); // Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels. float ConvertDipsToPixels(float dips); diff --git a/cocos/platform/winrt/InputEvent.h b/cocos/platform/winrt/InputEvent.h index 4ca3f3cb25..5c2dd39f2a 100644 --- a/cocos/platform/winrt/InputEvent.h +++ b/cocos/platform/winrt/InputEvent.h @@ -36,6 +36,7 @@ namespace PhoneDirect3DXamlAppComponent public delegate void Cocos2dEventDelegate(Cocos2dEvent event, Platform::String^ text); public delegate void Cocos2dMessageBoxDelegate(Platform::String^ title, Platform::String^ text); public delegate void Cocos2dEditBoxDelegate(Platform::String^ strPlaceHolder, Platform::String^ strText, int maxLength, int inputMode, int inputFlag, Windows::Foundation::EventHandler^ receiveHandler); + public delegate void Cocos2dOpenURLDelegate(Platform::String^ url); } NS_CC_BEGIN diff --git a/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.cpp b/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.cpp index 7231d15208..608cc6f828 100644 --- a/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.cpp +++ b/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.cpp @@ -181,7 +181,12 @@ void Cocos2dRenderer::SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Coco } } - - - - +void Cocos2dRenderer::SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate) +{ + m_openURLDelegate = delegate; + Application* app = Application::getInstance(); + if (app) + { + app->SetXamlOpenURLDelegate(delegate); + } +} diff --git a/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.h b/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.h index 41c3ddd144..55e84b12cb 100644 --- a/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.h +++ b/cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.h @@ -45,6 +45,7 @@ public: void SetXamlEventDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ delegate); void SetXamlMessageBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ delegate); void SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ delegate); + void SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate); Windows::Foundation::IAsyncAction^ OnSuspending(); void Connect(); @@ -61,6 +62,7 @@ private: PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ m_delegate; PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ m_messageBoxDelegate; PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ m_editBoxDelegate; + PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ m_openURLDelegate; // The AppDelegate for the Cocos2D app AppDelegate* mApp; diff --git a/cocos/platform/wp8-xaml/cpp/Direct3DInterop.cpp b/cocos/platform/wp8-xaml/cpp/Direct3DInterop.cpp index 7fbefac3e5..daf87f8f2d 100644 --- a/cocos/platform/wp8-xaml/cpp/Direct3DInterop.cpp +++ b/cocos/platform/wp8-xaml/cpp/Direct3DInterop.cpp @@ -129,6 +129,11 @@ void Direct3DInterop::OnCocos2dEditboxEvent(Object^ sender, Platform::String^ ar cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(e); } +void Direct3DInterop::OnCocos2dOpenURL(Platform::String^ url) +{ + m_openURLDelegate->Invoke(url); +} + @@ -174,6 +179,12 @@ void Direct3DInterop::SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegat m_renderer->SetXamlEditBoxDelegate(delegate); } +void Direct3DInterop::SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate) +{ + m_openURLDelegate = delegate; + m_renderer->SetXamlOpenURLDelegate(delegate); +} + bool Direct3DInterop::SendCocos2dEvent(Cocos2dEvent event) { diff --git a/cocos/platform/wp8-xaml/cpp/Direct3DInterop.h b/cocos/platform/wp8-xaml/cpp/Direct3DInterop.h index acda488448..0c8ef6fcab 100644 --- a/cocos/platform/wp8-xaml/cpp/Direct3DInterop.h +++ b/cocos/platform/wp8-xaml/cpp/Direct3DInterop.h @@ -60,6 +60,7 @@ public: void OnCocos2dKeyEvent(Cocos2dKeyEvent key); void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text); void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler^ handler); + void OnCocos2dOpenURL(Platform::String^ url); property Windows::Graphics::Display::DisplayOrientations WindowOrientation; property Windows::Foundation::Size WindowBounds; @@ -67,6 +68,7 @@ public: void SetCocos2dEventDelegate(Cocos2dEventDelegate^ delegate); void SetCocos2dMessageBoxDelegate(Cocos2dMessageBoxDelegate ^ delegate); void SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegate); + void SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate); protected: @@ -90,6 +92,7 @@ private: Cocos2dEventDelegate^ m_delegate; Cocos2dMessageBoxDelegate^ m_messageBoxDelegate; Cocos2dEditBoxDelegate^ m_editBoxDelegate; + Cocos2dOpenURLDelegate^ m_openURLDelegate; }; diff --git a/cocos/platform/wp8-xaml/xaml/MainPage.xaml.cs b/cocos/platform/wp8-xaml/xaml/MainPage.xaml.cs index 4610a773e3..56740b260c 100644 --- a/cocos/platform/wp8-xaml/xaml/MainPage.xaml.cs +++ b/cocos/platform/wp8-xaml/xaml/MainPage.xaml.cs @@ -25,6 +25,7 @@ using Windows.UI.Input; using System.Windows.Threading; using Microsoft.Phone.Info; using Windows.Graphics.Display; +using Microsoft.Phone.Tasks; namespace PhoneDirect3DXamlAppInterop { @@ -93,6 +94,7 @@ namespace PhoneDirect3DXamlAppInterop m_d3dInterop.SetCocos2dEventDelegate(OnCocos2dEvent); m_d3dInterop.SetCocos2dMessageBoxDelegate(OnCocos2dMessageBoxEvent); m_d3dInterop.SetCocos2dEditBoxDelegate(OpenEditBox); + m_d3dInterop.SetCocos2dOpenURLDelegate(OpenURL); } } @@ -206,6 +208,13 @@ namespace PhoneDirect3DXamlAppInterop } } + public void OpenURL(String url) + { + WebBrowserTask webBrowserTask = new WebBrowserTask(); + webBrowserTask.Uri = new Uri(url, UriKind.Absolute); + webBrowserTask.Show(); + } + private void StartTimer() { m_timer = new DispatcherTimer(); diff --git a/cocos/scripting/lua-bindings/auto/api/Application.lua b/cocos/scripting/lua-bindings/auto/api/Application.lua index f458be4bee..83892352a4 100644 --- a/cocos/scripting/lua-bindings/auto/api/Application.lua +++ b/cocos/scripting/lua-bindings/auto/api/Application.lua @@ -3,12 +3,28 @@ -- @module Application -- @parent_module cc +-------------------------------- +-- brief Open url in default browser
+-- param String with url to open.
+-- return true if the resource located by the URL was successfully opened; otherwise false. +-- @function [parent=#Application] openURL +-- @param self +-- @param #string url +-- @return bool#bool ret (return value: bool) + -------------------------------- -- brief Get target platform -- @function [parent=#Application] getTargetPlatform -- @param self -- @return int#int ret (return value: int) +-------------------------------- +-- brief Get current language config
+-- return Current language config +-- @function [parent=#Application] getCurrentLanguage +-- @param self +-- @return int#int ret (return value: int) + -------------------------------- -- brief Get current language iso 639-1 code
-- return Current language iso 639-1 code @@ -16,13 +32,6 @@ -- @param self -- @return char#char ret (return value: char) --------------------------------- --- brief Get current language config
--- return Current language config --- @function [parent=#Application] getCurrentLanguage --- @param self --- @return int#int ret (return value: int) - -------------------------------- -- brief Callback by Director to limit FPS.
-- param interval The time, expressed in seconds, between current frame and next. diff --git a/cocos/scripting/lua-bindings/auto/api/Device.lua b/cocos/scripting/lua-bindings/auto/api/Device.lua new file mode 100644 index 0000000000..a12863331a --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/api/Device.lua @@ -0,0 +1,31 @@ + +-------------------------------- +-- @module Device +-- @parent_module cc + +-------------------------------- +-- To enable or disable accelerometer. +-- @function [parent=#Device] setAccelerometerEnabled +-- @param self +-- @param #bool isEnabled + +-------------------------------- +-- +-- @function [parent=#Device] setKeepScreenOn +-- @param self +-- @param #bool value + +-------------------------------- +-- Sets the interval of accelerometer. +-- @function [parent=#Device] setAccelerometerInterval +-- @param self +-- @param #float interval + +-------------------------------- +-- Gets the DPI of device
+-- return The DPI of device. +-- @function [parent=#Device] getDPI +-- @param self +-- @return int#int ret (return value: int) + +return nil diff --git a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_auto_api.lua b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_auto_api.lua index d1de791a11..b1455b5ffc 100644 --- a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_auto_api.lua +++ b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_auto_api.lua @@ -1146,6 +1146,11 @@ -- @field [parent=#cc] TextureCache#TextureCache TextureCache preloaded module +-------------------------------------------------------- +-- the cc Device +-- @field [parent=#cc] Device#Device Device preloaded module + + -------------------------------------------------------- -- the cc Application -- @field [parent=#cc] Application#Application Application preloaded module diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 9869b1cf29..7a48471525 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -58962,6 +58962,203 @@ int lua_register_cocos2dx_TextureCache(lua_State* tolua_S) return 1; } +int lua_cocos2dx_Device_setAccelerometerEnabled(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"cc.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 1) + { + bool arg0; + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "cc.Device:setAccelerometerEnabled"); + if(!ok) + return 0; + cocos2d::Device::setAccelerometerEnabled(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Device:setAccelerometerEnabled",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Device_setAccelerometerEnabled'.",&tolua_err); +#endif + return 0; +} +int lua_cocos2dx_Device_setKeepScreenOn(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"cc.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 1) + { + bool arg0; + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "cc.Device:setKeepScreenOn"); + if(!ok) + return 0; + cocos2d::Device::setKeepScreenOn(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Device:setKeepScreenOn",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Device_setKeepScreenOn'.",&tolua_err); +#endif + return 0; +} +int lua_cocos2dx_Device_setAccelerometerInterval(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"cc.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 1) + { + double arg0; + ok &= luaval_to_number(tolua_S, 2,&arg0, "cc.Device:setAccelerometerInterval"); + if(!ok) + return 0; + cocos2d::Device::setAccelerometerInterval(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Device:setAccelerometerInterval",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Device_setAccelerometerInterval'.",&tolua_err); +#endif + return 0; +} +int lua_cocos2dx_Device_getDPI(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"cc.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + if(!ok) + return 0; + int ret = cocos2d::Device::getDPI(); + tolua_pushnumber(tolua_S,(lua_Number)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Device:getDPI",argc, 0); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Device_getDPI'.",&tolua_err); +#endif + return 0; +} +static int lua_cocos2dx_Device_finalize(lua_State* tolua_S) +{ + printf("luabindings: finalizing LUA object (Device)"); + return 0; +} + +int lua_register_cocos2dx_Device(lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"cc.Device"); + tolua_cclass(tolua_S,"Device","cc.Device","",nullptr); + + tolua_beginmodule(tolua_S,"Device"); + tolua_function(tolua_S,"setAccelerometerEnabled", lua_cocos2dx_Device_setAccelerometerEnabled); + tolua_function(tolua_S,"setKeepScreenOn", lua_cocos2dx_Device_setKeepScreenOn); + tolua_function(tolua_S,"setAccelerometerInterval", lua_cocos2dx_Device_setAccelerometerInterval); + tolua_function(tolua_S,"getDPI", lua_cocos2dx_Device_getDPI); + tolua_endmodule(tolua_S); + std::string typeName = typeid(cocos2d::Device).name(); + g_luaType[typeName] = "cc.Device"; + g_typeCast["Device"] = "cc.Device"; + return 1; +} + +int lua_cocos2dx_Application_openURL(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Application* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Application",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Application*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Application_openURL'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.Application:openURL"); + if(!ok) + return 0; + bool ret = cobj->openURL(arg0); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Application:openURL",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Application_openURL'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_Application_getTargetPlatform(lua_State* tolua_S) { int argc = 0; @@ -59006,50 +59203,6 @@ int lua_cocos2dx_Application_getTargetPlatform(lua_State* tolua_S) return 0; } -int lua_cocos2dx_Application_getCurrentLanguageCode(lua_State* tolua_S) -{ - int argc = 0; - cocos2d::Application* cobj = nullptr; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"cc.Application",0,&tolua_err)) goto tolua_lerror; -#endif - - cobj = (cocos2d::Application*)tolua_tousertype(tolua_S,1,0); - -#if COCOS2D_DEBUG >= 1 - if (!cobj) - { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Application_getCurrentLanguageCode'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - return 0; - const char* ret = cobj->getCurrentLanguageCode(); - tolua_pushstring(tolua_S,(const char*)ret); - return 1; - } - CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Application:getCurrentLanguageCode",argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Application_getCurrentLanguageCode'.",&tolua_err); -#endif - - return 0; -} int lua_cocos2dx_Application_getCurrentLanguage(lua_State* tolua_S) { int argc = 0; @@ -59094,6 +59247,50 @@ int lua_cocos2dx_Application_getCurrentLanguage(lua_State* tolua_S) return 0; } +int lua_cocos2dx_Application_getCurrentLanguageCode(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Application* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Application",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Application*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Application_getCurrentLanguageCode'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + return 0; + const char* ret = cobj->getCurrentLanguageCode(); + tolua_pushstring(tolua_S,(const char*)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Application:getCurrentLanguageCode",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Application_getCurrentLanguageCode'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_Application_setAnimationInterval(lua_State* tolua_S) { int argc = 0; @@ -59183,9 +59380,10 @@ int lua_register_cocos2dx_Application(lua_State* tolua_S) tolua_cclass(tolua_S,"Application","cc.Application","",nullptr); tolua_beginmodule(tolua_S,"Application"); + tolua_function(tolua_S,"openURL",lua_cocos2dx_Application_openURL); tolua_function(tolua_S,"getTargetPlatform",lua_cocos2dx_Application_getTargetPlatform); - tolua_function(tolua_S,"getCurrentLanguageCode",lua_cocos2dx_Application_getCurrentLanguageCode); tolua_function(tolua_S,"getCurrentLanguage",lua_cocos2dx_Application_getCurrentLanguage); + tolua_function(tolua_S,"getCurrentLanguageCode",lua_cocos2dx_Application_getCurrentLanguageCode); tolua_function(tolua_S,"setAnimationInterval",lua_cocos2dx_Application_setAnimationInterval); tolua_function(tolua_S,"getInstance", lua_cocos2dx_Application_getInstance); tolua_endmodule(tolua_S); @@ -65523,6 +65721,7 @@ TOLUA_API int register_all_cocos2dx(lua_State* tolua_S) lua_register_cocos2dx_TransitionTurnOffTiles(tolua_S); lua_register_cocos2dx_RotateTo(tolua_S); lua_register_cocos2dx_TransitionSplitRows(tolua_S); + lua_register_cocos2dx_Device(tolua_S); lua_register_cocos2dx_TransitionProgressRadialCCW(tolua_S); lua_register_cocos2dx_EventListenerFocus(tolua_S); lua_register_cocos2dx_TransitionPageTurn(tolua_S); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index bede494edf..758bdf6e07 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1568,6 +1568,12 @@ int register_all_cocos2dx(lua_State* tolua_S); + + + + + + diff --git a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp index e8da5290ee..0aba7331d5 100644 --- a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp +++ b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp @@ -1534,7 +1534,7 @@ bool luaval_to_ccvaluemap(lua_State* L, int lo, cocos2d::ValueMap* ret, const ch { lua_pop(L,1); ValueMap dictVal; - if (luaval_to_ccvaluemap(L, -1, &dictVal)) + if (luaval_to_ccvaluemap(L, lua_gettop(L), &dictVal)) { dict[stringKey] = Value(dictVal); } @@ -1543,7 +1543,7 @@ bool luaval_to_ccvaluemap(lua_State* L, int lo, cocos2d::ValueMap* ret, const ch { lua_pop(L,1); ValueVector arrVal; - if (luaval_to_ccvaluevector(L, -1, &arrVal)) + if (luaval_to_ccvaluevector(L, lua_gettop(L), &arrVal)) { dict[stringKey] = Value(arrVal); } @@ -1622,7 +1622,7 @@ bool luaval_to_ccvaluemapintkey(lua_State* L, int lo, cocos2d::ValueMapIntKey* r { lua_pop(L,1); ValueMap dictVal; - if (luaval_to_ccvaluemap(L, -1, &dictVal)) + if (luaval_to_ccvaluemap(L, lua_gettop(L), &dictVal)) { dict[intKey] = Value(dictVal); } @@ -1631,7 +1631,7 @@ bool luaval_to_ccvaluemapintkey(lua_State* L, int lo, cocos2d::ValueMapIntKey* r { lua_pop(L,1); ValueVector arrVal; - if (luaval_to_ccvaluevector(L, -1, &arrVal)) + if (luaval_to_ccvaluevector(L, lua_gettop(L), &arrVal)) { dict[intKey] = Value(arrVal); } @@ -1703,7 +1703,7 @@ bool luaval_to_ccvaluevector(lua_State* L, int lo, cocos2d::ValueVector* ret, co { lua_pop(L,1); ValueMap dictVal; - if (luaval_to_ccvaluemap(L, -1, &dictVal)) + if (luaval_to_ccvaluemap(L, lua_gettop(L), &dictVal)) { ret->push_back(Value(dictVal)); } @@ -1712,7 +1712,7 @@ bool luaval_to_ccvaluevector(lua_State* L, int lo, cocos2d::ValueVector* ret, co { lua_pop(L,1); ValueVector arrVal; - if(luaval_to_ccvaluevector(L, -1, &arrVal)) + if(luaval_to_ccvaluevector(L, lua_gettop(L), &arrVal)) { ret->push_back(Value(arrVal)); } diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp index de46c4b2cc..2c60aa56cc 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp @@ -28,7 +28,463 @@ #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #include "UIEditBox.h" -#include "ui/proj.win32/Win32InputBox.h" +#include +#include +#include +#include "2d/CCLabel.h" +#include "base/CCDirector.h" +#include "base/ccUTF8.h" + +#pragma warning (disable: 4312) + +class CWin32InputBox; + +// Structure used to orient the inputbox behavior +struct WIN32INPUTBOX_PARAM +{ + friend class CWin32InputBox; + + // + IN OPTIONAL bool bMultiline; + + // Pass this as none zero so to use this memory dlg template + IN OPTIONAL LPVOID DlgTemplateData; + + // Pass this as none ZERO so to load DLGTEMPLATE from resources + IN OPTIONAL LPCSTR DlgTemplateName; + + // passing both "DlgTemplateName" and "DlgTemplateData" ZERO will cause + // the dialog to use his default embedded resource + + // Center on monitor or owner window? + IN OPTIONAL bool bCenter; + + // Want to add more styles to the dialog? + IN OPTIONAL DWORD dwStylesPlus, dwStylesMinus; + IN OPTIONAL DWORD dwExStylesPlus, dwExStylesMinus; + + IN LPCSTR szTitle, szPrompt; + + // Return buffer + OUT LPSTR szResult; + IN DWORD nResultSize; + + // Owner window + HWND hwndOwner; + HINSTANCE hInstance; + + short xPos, yPos; + + WIN32INPUTBOX_PARAM(); +private: + HWND hDlg; +}; + +class CWin32InputBox +{ +private: + WIN32INPUTBOX_PARAM *_param; + static LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); + HWND _hwndEditCtrl; + + void InitDialog(); + void SetParam(WIN32INPUTBOX_PARAM *); + WIN32INPUTBOX_PARAM * GetParam(); + +public: + + CWin32InputBox(WIN32INPUTBOX_PARAM *); + ~CWin32InputBox(); + + static INT_PTR InputBoxEx(WIN32INPUTBOX_PARAM *); + static INT_PTR InputBox( + LPCSTR szTitle, + LPCSTR szPrompt, + LPSTR szResult, + DWORD nResultSize, + bool bMultiLine = false, + HWND hwndParent = 0); + + static std::string AnsiToUtf8(std::string strAnsi); + static std::string Utf8ToAnsi(std::string strUTF8); +}; + + + + +typedef struct _MSDN_DLGTEMPLATEEX +{ + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; + BYTE _rest[1]; // rest of structure +} MSDN_DLGTEMPLATEEX; + +static bool IsDlgTemplateExtended(DLGTEMPLATE *dlgTemplate) +{ + MSDN_DLGTEMPLATEEX *dgExTemplate = (MSDN_DLGTEMPLATEEX *)dlgTemplate; + + // MSDN excerpt: + //* dlgVer + // Specifies the version number of the extended dialog box template. This member must be 1. + //* signature + // Indicates whether a template is an extended dialog box template. + // If signature is 0xFFFF, this is an extended dialog box template. + // In this case, the dlgVer member specifies the template version number. + // If signature is any value other than 0xFFFF, this is a standard dialog box template that uses the DLGTEMPLATE and DLGITEMTEMPLATE structures. + + return (dgExTemplate->dlgVer == 1) && (dgExTemplate->signature == 0xFFFF); +} + +// Use alignment if supported by the compiler +#ifdef _MSC_VER +#if _MSC_VER > 1200 +__declspec(align(4)) +#endif +#endif + +// per the MSDN, the DLGTEMPLATE must be DWORD aligned +// this was generated by the DlgResToDlgTemplate tool +static unsigned char definputbox_dlg[] = +{ + 0x01, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0xc8, 0x00, 0x06, + 0x00, 0x16, 0x00, 0x11, 0x00, 0xe7, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x00, 0x69, + 0x00, 0x6e, 0x00, 0x33, 0x00, 0x32, 0x00, 0x49, 0x00, 0x6e, 0x00, 0x70, 0x00, 0x75, 0x00, 0x74, + 0x00, 0x42, 0x00, 0x6f, 0x00, 0x78, 0x00, 0x00, 0x00, 0x08, 0x00, 0xbc, 0x02, 0x00, 0x00, 0x4d, + 0x00, 0x53, 0x00, 0x20, 0x00, 0x53, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x20, + 0x00, 0x44, 0x00, 0x6c, 0x00, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x00, 0x02, 0x50, 0x06, 0x00, 0x04, 0x00, 0x9d, 0x00, 0x21, 0x00, 0xe8, + 0x03, 0x00, 0x00, 0xff, 0xff, 0x82, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x70, + 0x00, 0x74, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x00, 0x81, 0x50, 0x06, 0x00, 0x25, 0x00, 0xd8, 0x00, 0x0e, 0x00, 0xe9, + 0x03, 0x00, 0x00, 0xff, 0xff, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x84, 0x10, 0xa1, 0x50, 0x06, 0x00, 0x37, 0x00, 0xd8, 0x00, 0x31, 0x00, 0xea, + 0x03, 0x00, 0x00, 0xff, 0xff, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x50, 0xab, 0x00, 0x04, 0x00, 0x33, 0x00, 0x0e, 0x00, 0x01, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x4f, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x50, 0xab, 0x00, 0x15, 0x00, 0x33, + 0x00, 0x0e, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x43, 0x00, 0x41, 0x00, 0x4e, + 0x00, 0x43, 0x00, 0x45, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x27, 0x00, 0x08, 0x00, 0x08, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static LPCTSTR definputbox_buttonnames[] = { _T("OK"), _T("CANCEL") }; +static const INT_PTR definputbox_buttonids[] = { IDOK, IDCANCEL }; + +static const INT +definputbox_id_prompt = 1000, +definputbox_id_edit1 = 1001, +definputbox_id_edit2 = 1002; + +WIN32INPUTBOX_PARAM::WIN32INPUTBOX_PARAM() +{ + bMultiline = false; + hwndOwner = 0; + DlgTemplateName = 0; + hInstance = (HINSTANCE) ::GetModuleHandle(0); + DlgTemplateData = definputbox_dlg; + + bCenter = true; + + dwStylesPlus = 0; + dwExStylesPlus = 0; + dwStylesMinus = 0xFFFFFFFF; + dwExStylesMinus = 0xFFFFFFFF; + + xPos = yPos = -1; + + szResult = 0; + nResultSize = 0; +} + +CWin32InputBox::CWin32InputBox(WIN32INPUTBOX_PARAM *param) +{ + _param = param; +} + +CWin32InputBox::~CWin32InputBox() +{ + +} + +void CWin32InputBox::SetParam(WIN32INPUTBOX_PARAM *param) +{ + _param = param; +} + +WIN32INPUTBOX_PARAM *CWin32InputBox::GetParam() +{ + return _param; +} + +INT_PTR CWin32InputBox::InputBoxEx(WIN32INPUTBOX_PARAM *param) +{ + // Check mandatory parameters + if (param->szResult == 0) + { + ::SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + LPDLGTEMPLATE dlgTemplate; + + if (param->DlgTemplateName != 0) + { + HMODULE hModule = (HMODULE)param->hInstance; +#ifdef __MINGW32__ + HRSRC rcDlg = ::FindResource(hModule, (LPWSTR)(ULONG_PTR)(size_t)(param->DlgTemplateName), RT_DIALOG); +#else + HRSRC rcDlg = ::FindResource(hModule, MAKEINTRESOURCE(param->DlgTemplateName), RT_DIALOG); +#endif + if (rcDlg == nullptr) + return 0; + + HGLOBAL hglobalDlg = ::LoadResource(hModule, rcDlg); + if (hglobalDlg == nullptr) + return 0; + + dlgTemplate = (LPDLGTEMPLATE)hglobalDlg; + } + else if (param->DlgTemplateData != 0) + { + dlgTemplate = (LPDLGTEMPLATE)param->DlgTemplateData; + } + + MSDN_DLGTEMPLATEEX *dlgTemplateEx = + IsDlgTemplateExtended((LPDLGTEMPLATE)dlgTemplate) ? (MSDN_DLGTEMPLATEEX *)dlgTemplate : 0; + + if (dlgTemplateEx != 0) + { + dlgTemplateEx->exStyle |= param->dwExStylesPlus; + dlgTemplateEx->style |= param->dwStylesPlus; + dlgTemplateEx->exStyle &= param->dwExStylesMinus; + dlgTemplateEx->style &= param->dwStylesMinus; + + if (param->bCenter) + dlgTemplateEx->style |= DS_CENTER; + + if (param->xPos != -1) + dlgTemplateEx->x = param->xPos; + if (param->yPos != -1) + dlgTemplateEx->y = param->yPos; + } + else + { + dlgTemplate->dwExtendedStyle |= param->dwExStylesPlus; + dlgTemplate->style |= param->dwStylesPlus; + dlgTemplate->dwExtendedStyle &= param->dwExStylesMinus; + dlgTemplate->style &= param->dwStylesMinus; + + if (param->bCenter) + dlgTemplate->style |= DS_CENTER; + + if (param->xPos != -1) + dlgTemplate->x = param->xPos; + + if (param->yPos != -1) + dlgTemplate->y = param->yPos; + } + + CWin32InputBox inputbox(param); + + // Resize dialog and SHOW or HIDE multiline + INT_PTR r = ::DialogBoxIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)&inputbox); + + return r; +} + +INT_PTR CWin32InputBox::InputBox( + LPCSTR szTitle, + LPCSTR szPrompt, + LPSTR szResult, + DWORD nResultSize, + bool bMultiLine, + HWND hwndParent) +{ + WIN32INPUTBOX_PARAM param; + + param.szTitle = szTitle; + param.szPrompt = szPrompt; + param.szResult = szResult; + param.nResultSize = nResultSize; + param.bMultiline = bMultiLine; + param.hwndOwner = hwndParent; + return InputBoxEx(¶m); +} + +void CWin32InputBox::InitDialog() +{ + // Set the button captions + for (size_t i = 0; ihDlg, (int)definputbox_buttonids[i], definputbox_buttonnames[i]); + + // Set other controls + ::SetWindowTextA(_param->hDlg, Utf8ToAnsi(_param->szTitle).c_str()); + ::SetDlgItemTextA(_param->hDlg, definputbox_id_prompt, Utf8ToAnsi(_param->szPrompt).c_str()); + + HWND hwndEdit1 = ::GetDlgItem(_param->hDlg, definputbox_id_edit1); + HWND hwndEdit2 = ::GetDlgItem(_param->hDlg, definputbox_id_edit2); + + if (_param->bMultiline) + _hwndEditCtrl = hwndEdit2; + else + _hwndEditCtrl = hwndEdit1; + + ::SetWindowTextA(_hwndEditCtrl, Utf8ToAnsi(_param->szResult).c_str()); + + RECT rectDlg, rectEdit1, rectEdit2; + + ::GetWindowRect(_param->hDlg, &rectDlg); + ::GetWindowRect(hwndEdit1, &rectEdit1); + ::GetWindowRect(hwndEdit2, &rectEdit2); + + if (_param->bMultiline) + { + ::ShowWindow(hwndEdit1, SW_HIDE); + ::SetWindowPos( + hwndEdit2, + HWND_NOTOPMOST, + rectEdit1.left - rectDlg.left, + (rectEdit1.top - rectDlg.top) - (rectEdit1.bottom - rectEdit1.top), + 0, + 0, + SWP_NOSIZE | SWP_NOZORDER); + + ::SetWindowPos( + _param->hDlg, + HWND_NOTOPMOST, + 0, + 0, + rectDlg.right - rectDlg.left, + rectDlg.bottom - rectDlg.top - (rectEdit1.bottom - rectEdit1.top), + SWP_NOMOVE); + + } + else + { + ::SetWindowPos( + _param->hDlg, + HWND_NOTOPMOST, + 0, + 0, + rectDlg.right - rectDlg.left, + rectEdit1.bottom - rectDlg.top + 5, + SWP_NOMOVE); + + ::ShowWindow(hwndEdit2, SW_HIDE); + } +} + +// Message handler for about box. +LRESULT CALLBACK CWin32InputBox::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLongPtr(hDlg, GWLP_USERDATA); + WIN32INPUTBOX_PARAM *param = _this ? _this->GetParam() : 0; + + switch (message) + { + case WM_INITDIALOG: + { + SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)lParam); + + _this = (CWin32InputBox *)lParam; + _this->_param->hDlg = hDlg; + _this->InitDialog(); + return TRUE; + } + + case WM_COMMAND: + { +#ifdef _MY_DEBUG + CHAR buf[1024]; + static int i = 0; + sprintf(buf, "WM_COMMAND: %09d wParam=%08X lParam=%08X\n", i++, wParam, lParam); + OutputDebugString(buf); +#endif + INT_PTR buttonId = LOWORD(wParam); + for (size_t i = 0; + i_hwndEditCtrl, + _this->_param->szResult, + _this->_param->nResultSize); + + std::string strUtf8 = AnsiToUtf8(_this->_param->szResult); + + memset(_this->_param->szResult, 0, _this->_param->nResultSize); + strncpy(_this->_param->szResult, strUtf8.c_str(), _this->_param->nResultSize - 1); + + ::EndDialog(hDlg, buttonId); + return TRUE; + } + } + } + break; + } + return FALSE; +} + + +std::string CWin32InputBox::AnsiToUtf8(std::string strAnsi) +{ + std::string ret; + if (strAnsi.length() > 0) + { + int nWideStrLength = MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, nullptr, 0); + WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength + 1)*sizeof(WCHAR)); + memset(pwszBuf, 0, (nWideStrLength + 1)*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, pwszBuf, (nWideStrLength + 1)*sizeof(WCHAR)); + + int nUtf8Length = WideCharToMultiByte(CP_UTF8, 0, pwszBuf, -1, nullptr, 0, nullptr, FALSE); + char* pszUtf8Buf = (char*)malloc((nUtf8Length + 1)*sizeof(char)); + memset(pszUtf8Buf, 0, (nUtf8Length + 1)*sizeof(char)); + + WideCharToMultiByte(CP_UTF8, 0, pwszBuf, -1, pszUtf8Buf, (nUtf8Length + 1)*sizeof(char), nullptr, FALSE); + ret = pszUtf8Buf; + + free(pszUtf8Buf); + free(pwszBuf); + } + return ret; +} + +std::string CWin32InputBox::Utf8ToAnsi(std::string strUTF8) +{ + std::string ret; + if (strUTF8.length() > 0) + { + int nWideStrLength = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, nullptr, 0); + WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength + 1)*sizeof(WCHAR)); + memset(pwszBuf, 0, (nWideStrLength + 1)*sizeof(WCHAR)); + MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, pwszBuf, (nWideStrLength + 1)*sizeof(WCHAR)); + + int nAnsiStrLength = WideCharToMultiByte(CP_ACP, 0, pwszBuf, -1, nullptr, 0, nullptr, FALSE); + char* pszAnsiBuf = (char*)malloc((nAnsiStrLength + 1)*sizeof(char)); + memset(pszAnsiBuf, 0, (nAnsiStrLength + 1)*sizeof(char)); + + WideCharToMultiByte(CP_ACP, 0, pwszBuf, -1, pszAnsiBuf, (nAnsiStrLength + 1)*sizeof(char), nullptr, FALSE); + ret = pszAnsiBuf; + + free(pszAnsiBuf); + free(pwszBuf); + } + + return ret; +} + + NS_CC_BEGIN @@ -162,7 +618,7 @@ void EditBoxImplWin::setText(const char* pText) if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) { - long length = cc_utf8_strlen(_text.c_str(), -1); + long length = StringUtils::getCharacterCountInUTF8String(_text); for (long i = 0; i < length; i++) { strToShow.append("*"); diff --git a/cocos/ui/proj.win32/Win32InputBox.cpp b/cocos/ui/proj.win32/Win32InputBox.cpp deleted file mode 100644 index da1cb12301..0000000000 --- a/cocos/ui/proj.win32/Win32InputBox.cpp +++ /dev/null @@ -1,383 +0,0 @@ -#include "Win32InputBox.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - -#include - -#pragma warning (disable: 4312) - -typedef struct _MSDN_DLGTEMPLATEEX -{ - WORD dlgVer; - WORD signature; - DWORD helpID; - DWORD exStyle; - DWORD style; - WORD cDlgItems; - short x; - short y; - short cx; - short cy; - BYTE _rest[1]; // rest of structure -} MSDN_DLGTEMPLATEEX; - -static bool IsDlgTemplateExtended(DLGTEMPLATE *dlgTemplate) -{ - MSDN_DLGTEMPLATEEX *dgExTemplate = (MSDN_DLGTEMPLATEEX *) dlgTemplate; - - // MSDN excerpt: - //* dlgVer - // Specifies the version number of the extended dialog box template. This member must be 1. - //* signature - // Indicates whether a template is an extended dialog box template. - // If signature is 0xFFFF, this is an extended dialog box template. - // In this case, the dlgVer member specifies the template version number. - // If signature is any value other than 0xFFFF, this is a standard dialog box template that uses the DLGTEMPLATE and DLGITEMTEMPLATE structures. - - return (dgExTemplate->dlgVer == 1) && (dgExTemplate->signature == 0xFFFF); -} - -// Use alignment if supported by the compiler -#ifdef _MSC_VER - #if _MSC_VER > 1200 - __declspec(align(4)) - #endif -#endif - -// per the MSDN, the DLGTEMPLATE must be DWORD aligned -// this was generated by the DlgResToDlgTemplate tool -static unsigned char definputbox_dlg[] = -{ - 0x01,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc8,0x00,0xc8,0x00,0x06, - 0x00,0x16,0x00,0x11,0x00,0xe7,0x00,0x6d,0x00,0x00,0x00,0x00,0x00,0x57,0x00,0x69, - 0x00,0x6e,0x00,0x33,0x00,0x32,0x00,0x49,0x00,0x6e,0x00,0x70,0x00,0x75,0x00,0x74, - 0x00,0x42,0x00,0x6f,0x00,0x78,0x00,0x00,0x00,0x08,0x00,0xbc,0x02,0x00,0x00,0x4d, - 0x00,0x53,0x00,0x20,0x00,0x53,0x00,0x68,0x00,0x65,0x00,0x6c,0x00,0x6c,0x00,0x20, - 0x00,0x44,0x00,0x6c,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x80,0x00,0x02,0x50,0x06,0x00,0x04,0x00,0x9d,0x00,0x21,0x00,0xe8, - 0x03,0x00,0x00,0xff,0xff,0x82,0x00,0x50,0x00,0x72,0x00,0x6f,0x00,0x6d,0x00,0x70, - 0x00,0x74,0x00,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x80,0x00,0x81,0x50,0x06,0x00,0x25,0x00,0xd8,0x00,0x0e,0x00,0xe9, - 0x03,0x00,0x00,0xff,0xff,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x84,0x10,0xa1,0x50,0x06,0x00,0x37,0x00,0xd8,0x00,0x31,0x00,0xea, - 0x03,0x00,0x00,0xff,0xff,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x01,0x00,0x03,0x50,0xab,0x00,0x04,0x00,0x33,0x00,0x0e,0x00,0x01, - 0x00,0x00,0x00,0xff,0xff,0x80,0x00,0x4f,0x00,0x4b,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x50,0xab,0x00,0x15,0x00,0x33, - 0x00,0x0e,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0x80,0x00,0x43,0x00,0x41,0x00,0x4e, - 0x00,0x43,0x00,0x45,0x00,0x4c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x27,0x00,0x08,0x00,0x08,0x00,0xff, - 0xff,0xff,0xff,0xff,0xff,0x82,0x00,0x00,0x00,0x00,0x00 -}; - -static LPCTSTR definputbox_buttonnames[] = { _T("OK"), _T("CANCEL") }; -static const INT_PTR definputbox_buttonids[] = { IDOK, IDCANCEL }; - -static const INT - definputbox_id_prompt = 1000, - definputbox_id_edit1 = 1001, - definputbox_id_edit2 = 1002; - -WIN32INPUTBOX_PARAM::WIN32INPUTBOX_PARAM() -{ - bMultiline = false; - hwndOwner = 0; - DlgTemplateName = 0; - hInstance = (HINSTANCE) ::GetModuleHandle(0); - DlgTemplateData = definputbox_dlg; - - bCenter = true; - - dwStylesPlus = 0; - dwExStylesPlus = 0; - dwStylesMinus = 0xFFFFFFFF; - dwExStylesMinus = 0xFFFFFFFF; - - xPos = yPos = -1; - - szResult = 0; - nResultSize = 0; -} - -CWin32InputBox::CWin32InputBox(WIN32INPUTBOX_PARAM *param) -{ - _param = param; -} - -CWin32InputBox::~CWin32InputBox() -{ - -} - -void CWin32InputBox::SetParam(WIN32INPUTBOX_PARAM *param) -{ - _param = param; -} - -WIN32INPUTBOX_PARAM *CWin32InputBox::GetParam() -{ - return _param; -} - -INT_PTR CWin32InputBox::InputBoxEx(WIN32INPUTBOX_PARAM *param) -{ - // Check mandatory parameters - if (param->szResult == 0) - { - ::SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - - LPDLGTEMPLATE dlgTemplate; - - if (param->DlgTemplateName != 0) - { - HMODULE hModule = (HMODULE)param->hInstance; -#ifdef __MINGW32__ - HRSRC rcDlg = ::FindResource(hModule, (LPWSTR)(ULONG_PTR)(size_t)(param->DlgTemplateName), RT_DIALOG); -#else - HRSRC rcDlg = ::FindResource(hModule, MAKEINTRESOURCE(param->DlgTemplateName), RT_DIALOG); -#endif - if (rcDlg == nullptr) - return 0; - - HGLOBAL hglobalDlg = ::LoadResource(hModule, rcDlg); - if (hglobalDlg == nullptr) - return 0; - - dlgTemplate = (LPDLGTEMPLATE) hglobalDlg; - } - else if (param->DlgTemplateData != 0) - { - dlgTemplate = (LPDLGTEMPLATE) param->DlgTemplateData; - } - - MSDN_DLGTEMPLATEEX *dlgTemplateEx = - IsDlgTemplateExtended((LPDLGTEMPLATE) dlgTemplate) ? (MSDN_DLGTEMPLATEEX *) dlgTemplate : 0; - - if (dlgTemplateEx != 0) - { - dlgTemplateEx->exStyle |= param->dwExStylesPlus; - dlgTemplateEx->style |= param->dwStylesPlus; - dlgTemplateEx->exStyle &= param->dwExStylesMinus; - dlgTemplateEx->style &= param->dwStylesMinus; - - if (param->bCenter) - dlgTemplateEx->style |= DS_CENTER; - - if (param->xPos != -1) - dlgTemplateEx->x = param->xPos; - if (param->yPos != -1) - dlgTemplateEx->y = param->yPos; - } - else - { - dlgTemplate->dwExtendedStyle |= param->dwExStylesPlus; - dlgTemplate->style |= param->dwStylesPlus; - dlgTemplate->dwExtendedStyle &= param->dwExStylesMinus; - dlgTemplate->style &= param->dwStylesMinus; - - if (param->bCenter) - dlgTemplate->style |= DS_CENTER; - - if (param->xPos != -1) - dlgTemplate->x = param->xPos; - - if (param->yPos != -1) - dlgTemplate->y = param->yPos; - } - - CWin32InputBox inputbox(param); - - // Resize dialog and SHOW or HIDE multiline - INT_PTR r = ::DialogBoxIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)&inputbox); - - return r; -} - -INT_PTR CWin32InputBox::InputBox( - LPCSTR szTitle, - LPCSTR szPrompt, - LPSTR szResult, - DWORD nResultSize, - bool bMultiLine, - HWND hwndParent) -{ - WIN32INPUTBOX_PARAM param; - - param.szTitle = szTitle; - param.szPrompt = szPrompt; - param.szResult = szResult; - param.nResultSize = nResultSize; - param.bMultiline = bMultiLine; - param.hwndOwner = hwndParent; - return InputBoxEx(¶m); -} - -void CWin32InputBox::InitDialog() -{ - // Set the button captions - for (size_t i=0;ihDlg, (int) definputbox_buttonids[i], definputbox_buttonnames[i]); - - // Set other controls - ::SetWindowTextA(_param->hDlg, Utf8ToAnsi(_param->szTitle).c_str()); - ::SetDlgItemTextA(_param->hDlg, definputbox_id_prompt, Utf8ToAnsi(_param->szPrompt).c_str()); - - HWND hwndEdit1 = ::GetDlgItem(_param->hDlg, definputbox_id_edit1); - HWND hwndEdit2 = ::GetDlgItem(_param->hDlg, definputbox_id_edit2); - - if (_param->bMultiline) - _hwndEditCtrl = hwndEdit2; - else - _hwndEditCtrl = hwndEdit1; - - ::SetWindowTextA(_hwndEditCtrl, Utf8ToAnsi(_param->szResult).c_str()); - - RECT rectDlg, rectEdit1, rectEdit2; - - ::GetWindowRect(_param->hDlg, &rectDlg); - ::GetWindowRect(hwndEdit1, &rectEdit1); - ::GetWindowRect(hwndEdit2, &rectEdit2); - - if (_param->bMultiline) - { - ::ShowWindow(hwndEdit1, SW_HIDE); - ::SetWindowPos( - hwndEdit2, - HWND_NOTOPMOST, - rectEdit1.left - rectDlg.left, - (rectEdit1.top - rectDlg.top) - (rectEdit1.bottom - rectEdit1.top), - 0, - 0, - SWP_NOSIZE | SWP_NOZORDER); - - ::SetWindowPos( - _param->hDlg, - HWND_NOTOPMOST, - 0, - 0, - rectDlg.right - rectDlg.left, - rectDlg.bottom - rectDlg.top - (rectEdit1.bottom - rectEdit1.top), - SWP_NOMOVE); - - } - else - { - ::SetWindowPos( - _param->hDlg, - HWND_NOTOPMOST, - 0, - 0, - rectDlg.right - rectDlg.left, - rectEdit1.bottom - rectDlg.top + 5, - SWP_NOMOVE); - - ::ShowWindow(hwndEdit2, SW_HIDE); - } -} - -// Message handler for about box. -LRESULT CALLBACK CWin32InputBox::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLongPtr(hDlg, GWLP_USERDATA); - WIN32INPUTBOX_PARAM *param = _this ? _this->GetParam() : 0; - - switch (message) - { - case WM_INITDIALOG: - { - SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR) lParam); - - _this = (CWin32InputBox *) lParam; - _this->_param->hDlg = hDlg; - _this->InitDialog(); - return TRUE; - } - - case WM_COMMAND: - { -#ifdef _MY_DEBUG - CHAR buf[1024]; - static int i=0; - sprintf(buf, "WM_COMMAND: %09d wParam=%08X lParam=%08X\n", i++, wParam, lParam); - OutputDebugString(buf); -#endif - INT_PTR buttonId = LOWORD(wParam); - for (size_t i=0; - i_hwndEditCtrl, - _this->_param->szResult, - _this->_param->nResultSize); - - std::string strUtf8 = AnsiToUtf8(_this->_param->szResult); - - memset(_this->_param->szResult, 0, _this->_param->nResultSize); - strncpy(_this->_param->szResult, strUtf8.c_str(), _this->_param->nResultSize-1); - - ::EndDialog(hDlg, buttonId); - return TRUE; - } - } - } - break; - } - return FALSE; -} - - -std::string CWin32InputBox::AnsiToUtf8(std::string strAnsi) -{ - std::string ret; - if (strAnsi.length() > 0) - { - int nWideStrLength = MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, nullptr, 0); - WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength+1)*sizeof(WCHAR)); - memset(pwszBuf, 0, (nWideStrLength+1)*sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, pwszBuf, (nWideStrLength+1)*sizeof(WCHAR)); - - int nUtf8Length = WideCharToMultiByte( CP_UTF8,0,pwszBuf,-1,nullptr,0,nullptr,FALSE ); - char* pszUtf8Buf = (char*)malloc((nUtf8Length+1)*sizeof(char)); - memset(pszUtf8Buf, 0, (nUtf8Length+1)*sizeof(char)); - - WideCharToMultiByte(CP_UTF8, 0, pwszBuf, -1, pszUtf8Buf, (nUtf8Length+1)*sizeof(char), nullptr, FALSE); - ret = pszUtf8Buf; - - free(pszUtf8Buf); - free(pwszBuf); - } - return ret; -} - -std::string CWin32InputBox::Utf8ToAnsi(std::string strUTF8) -{ - std::string ret; - if (strUTF8.length() > 0) - { - int nWideStrLength = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, nullptr, 0); - WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength+1)*sizeof(WCHAR)); - memset(pwszBuf, 0, (nWideStrLength+1)*sizeof(WCHAR)); - MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, pwszBuf, (nWideStrLength+1)*sizeof(WCHAR)); - - int nAnsiStrLength = WideCharToMultiByte( CP_ACP,0,pwszBuf,-1,nullptr,0,nullptr,FALSE ); - char* pszAnsiBuf = (char*)malloc((nAnsiStrLength+1)*sizeof(char)); - memset(pszAnsiBuf, 0, (nAnsiStrLength+1)*sizeof(char)); - - WideCharToMultiByte(CP_ACP, 0, pwszBuf, -1, pszAnsiBuf, (nAnsiStrLength+1)*sizeof(char), nullptr, FALSE); - ret = pszAnsiBuf; - - free(pszAnsiBuf); - free(pwszBuf); - } - - return ret; -} - - - -#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ diff --git a/cocos/ui/proj.win32/Win32InputBox.h b/cocos/ui/proj.win32/Win32InputBox.h deleted file mode 100644 index 1fd46a5593..0000000000 --- a/cocos/ui/proj.win32/Win32InputBox.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef __03022006__WIN32INPUTBOX__ -#define __03022006__WIN32INPUTBOX__ - -#include "cocos2d.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) -/* - -This library is (c) Elias Bachaalany aka lallous -You may use this library under the following license agreement: - -The zlib/libpng License. ---------------------------- -This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, including commercial applications, -and to alter it and redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; - you must not claim that you wrote the original software. - If you use this software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, - and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. - -*/ - -#include -#include - -class CWin32InputBox; - -// Structure used to orient the inputbox behavior -struct WIN32INPUTBOX_PARAM -{ - friend class CWin32InputBox; - - // - IN OPTIONAL bool bMultiline; - - // Pass this as none zero so to use this memory dlg template - IN OPTIONAL LPVOID DlgTemplateData; - - // Pass this as none ZERO so to load DLGTEMPLATE from resources - IN OPTIONAL LPCSTR DlgTemplateName; - - // passing both "DlgTemplateName" and "DlgTemplateData" ZERO will cause - // the dialog to use his default embedded resource - - // Center on monitor or owner window? - IN OPTIONAL bool bCenter; - - // Want to add more styles to the dialog? - IN OPTIONAL DWORD dwStylesPlus, dwStylesMinus; - IN OPTIONAL DWORD dwExStylesPlus, dwExStylesMinus; - - IN LPCSTR szTitle, szPrompt; - - // Return buffer - OUT LPSTR szResult; - IN DWORD nResultSize; - - // Owner window - HWND hwndOwner; - HINSTANCE hInstance; - - short xPos, yPos; - - WIN32INPUTBOX_PARAM(); -private: - HWND hDlg; -}; - -class CWin32InputBox -{ -private: - WIN32INPUTBOX_PARAM *_param; - static LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); - HWND _hwndEditCtrl; - - void InitDialog(); - void SetParam(WIN32INPUTBOX_PARAM *); - WIN32INPUTBOX_PARAM * GetParam(); - -public: - - CWin32InputBox(WIN32INPUTBOX_PARAM *); - ~CWin32InputBox(); - - static INT_PTR InputBoxEx(WIN32INPUTBOX_PARAM *); - static INT_PTR InputBox( - LPCSTR szTitle, - LPCSTR szPrompt, - LPSTR szResult, - DWORD nResultSize, - bool bMultiLine = false, - HWND hwndParent = 0); - - static std::string AnsiToUtf8(std::string strAnsi); - static std::string Utf8ToAnsi(std::string strUTF8); -}; - -#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ - -#endif diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 53bfe0d56f..eef8e80084 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -673,6 +673,7 @@ "cocos/math/MathUtil.h", "cocos/math/MathUtil.inl", "cocos/math/MathUtilNeon.inl", + "cocos/math/MathUtilNeon64.inl", "cocos/math/MathUtilSSE.inl", "cocos/math/Quaternion.cpp", "cocos/math/Quaternion.h", @@ -1083,8 +1084,6 @@ "cocos/ui/UIWebViewImpl-win32.h", "cocos/ui/UIWidget.cpp", "cocos/ui/UIWidget.h", - "cocos/ui/proj.win32/Win32InputBox.cpp", - "cocos/ui/proj.win32/Win32InputBox.h", "cocos/ui/proj.win32/libui.vcxproj", "cocos/ui/proj.win32/libui.vcxproj.filters", "cocos/ui/proj.wp8/libGUI.vcxproj", diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj index 34641010c9..3ca78d1be6 100644 --- a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj +++ b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj @@ -541,6 +541,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = ""; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -570,6 +571,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = ""; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; diff --git a/templates/cpp-template-default/proj.wp8-xaml/App/MainPage.xaml.cs b/templates/cpp-template-default/proj.wp8-xaml/App/MainPage.xaml.cs index 4610a773e3..56740b260c 100644 --- a/templates/cpp-template-default/proj.wp8-xaml/App/MainPage.xaml.cs +++ b/templates/cpp-template-default/proj.wp8-xaml/App/MainPage.xaml.cs @@ -25,6 +25,7 @@ using Windows.UI.Input; using System.Windows.Threading; using Microsoft.Phone.Info; using Windows.Graphics.Display; +using Microsoft.Phone.Tasks; namespace PhoneDirect3DXamlAppInterop { @@ -93,6 +94,7 @@ namespace PhoneDirect3DXamlAppInterop m_d3dInterop.SetCocos2dEventDelegate(OnCocos2dEvent); m_d3dInterop.SetCocos2dMessageBoxDelegate(OnCocos2dMessageBoxEvent); m_d3dInterop.SetCocos2dEditBoxDelegate(OpenEditBox); + m_d3dInterop.SetCocos2dOpenURLDelegate(OpenURL); } } @@ -206,6 +208,13 @@ namespace PhoneDirect3DXamlAppInterop } } + public void OpenURL(String url) + { + WebBrowserTask webBrowserTask = new WebBrowserTask(); + webBrowserTask.Uri = new Uri(url, UriKind.Absolute); + webBrowserTask.Show(); + } + private void StartTimer() { m_timer = new DispatcherTimer(); diff --git a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.cpp b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.cpp index d70ac5c2fb..608cc6f828 100644 --- a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.cpp +++ b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.cpp @@ -26,7 +26,7 @@ THE SOFTWARE. #include "Cocos2dRenderer.h" #include "cocos2d.h" #include "CCApplication.h" -#include "CCGLView.h" +#include "CCGLViewImpl.h" #include "AppDelegate.h" #include @@ -181,7 +181,12 @@ void Cocos2dRenderer::SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Coco } } - - - - +void Cocos2dRenderer::SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate) +{ + m_openURLDelegate = delegate; + Application* app = Application::getInstance(); + if (app) + { + app->SetXamlOpenURLDelegate(delegate); + } +} diff --git a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.h b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.h index 41c3ddd144..55e84b12cb 100644 --- a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.h +++ b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.h @@ -45,6 +45,7 @@ public: void SetXamlEventDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ delegate); void SetXamlMessageBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ delegate); void SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ delegate); + void SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate); Windows::Foundation::IAsyncAction^ OnSuspending(); void Connect(); @@ -61,6 +62,7 @@ private: PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ m_delegate; PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ m_messageBoxDelegate; PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ m_editBoxDelegate; + PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ m_openURLDelegate; // The AppDelegate for the Cocos2D app AppDelegate* mApp; diff --git a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.cpp b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.cpp index 3f3797078a..421b71db67 100644 --- a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.cpp +++ b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.cpp @@ -129,6 +129,11 @@ void Direct3DInterop::OnCocos2dEditboxEvent(Object^ sender, Platform::String^ ar cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(e); } +void Direct3DInterop::OnCocos2dOpenURL(Platform::String^ url) +{ + m_openURLDelegate->Invoke(url); +} + @@ -174,6 +179,12 @@ void Direct3DInterop::SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegat m_renderer->SetXamlEditBoxDelegate(delegate); } +void Direct3DInterop::SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate) +{ + m_openURLDelegate = delegate; + m_renderer->SetXamlOpenURLDelegate(delegate); +} + bool Direct3DInterop::SendCocos2dEvent(Cocos2dEvent event) { diff --git a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.h b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.h index acda488448..0c8ef6fcab 100644 --- a/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.h +++ b/templates/cpp-template-default/proj.wp8-xaml/AppComponent/src/Direct3DInterop.h @@ -60,6 +60,7 @@ public: void OnCocos2dKeyEvent(Cocos2dKeyEvent key); void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text); void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler^ handler); + void OnCocos2dOpenURL(Platform::String^ url); property Windows::Graphics::Display::DisplayOrientations WindowOrientation; property Windows::Foundation::Size WindowBounds; @@ -67,6 +68,7 @@ public: void SetCocos2dEventDelegate(Cocos2dEventDelegate^ delegate); void SetCocos2dMessageBoxDelegate(Cocos2dMessageBoxDelegate ^ delegate); void SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegate); + void SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate); protected: @@ -90,6 +92,7 @@ private: Cocos2dEventDelegate^ m_delegate; Cocos2dMessageBoxDelegate^ m_messageBoxDelegate; Cocos2dEditBoxDelegate^ m_editBoxDelegate; + Cocos2dOpenURLDelegate^ m_openURLDelegate; }; diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index a297560317..98383bf5e2 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -925,6 +925,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../../cocos2d-x/cocos/platform/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -947,6 +948,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../../cocos2d-x/cocos/platform/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp index fa5cdb091b..a004abcd4e 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -13,6 +13,10 @@ using namespace std; AppDelegate::AppDelegate() { +#if (COCOS2D_DEBUG > 0) + // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE + initRuntime(); +#endif } AppDelegate::~AppDelegate() @@ -33,11 +37,6 @@ void AppDelegate::initGLContextAttrs() bool AppDelegate::applicationDidFinishLaunching() { - -#if (COCOS2D_DEBUG > 0) - initRuntime(); -#endif - // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); @@ -67,11 +66,12 @@ bool AppDelegate::applicationDidFinishLaunching() //register_custom_function(stack->getLuaState()); #if (COCOS2D_DEBUG > 0) - if (startRuntime()) - return true; + // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE + startRuntime(); +#else + engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); #endif - engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); return true; } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp index b61f0a0308..93026ab0f3 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp @@ -5,6 +5,12 @@ #include "json/writer.h" #include "ConfigParser.h" +#define CONFIG_FILE "config.json" +#define CONSOLE_PORT 6010 +#define UPLOAD_PORT 6020 +#define WIN_WIDTH 960 +#define WIN_HEIGHT 640 + // ConfigParser ConfigParser *ConfigParser::s_sharedInstance = NULL; ConfigParser *ConfigParser::getInstance(void) @@ -19,100 +25,90 @@ ConfigParser *ConfigParser::getInstance(void) void ConfigParser::readConfig() { - _isWindowTop = false; - _consolePort = 6010; - _uploadPort = 6020; - string filecfg = "config.json"; + string fullPathFile = FileUtils::getInstance()->fullPathForFilename(CONFIG_FILE); + string fileContent = FileUtils::getInstance()->getStringFromFile(fullPathFile); + + if(fileContent.empty()) + return; - string fileContent; -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID && !defined(NDEBUG)) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS && defined(COCOS2D_DEBUG)) - string fullPathFile = FileUtils::getInstance()->getWritablePath(); - fullPathFile.append("debugruntime/"); - fullPathFile.append(filecfg.c_str()); - fileContent=FileUtils::getInstance()->getStringFromFile(fullPathFile.c_str()); -#endif - - if (fileContent.empty()) - { - filecfg=FileUtils::getInstance()->fullPathForFilename(filecfg.c_str()); - fileContent=FileUtils::getInstance()->getStringFromFile(filecfg.c_str()); + if (_docRootjson.Parse<0>(fileContent.c_str()).HasParseError()) { + cocos2d::log("read json file %s failed because of %s", fullPathFile.c_str(), _docRootjson.GetParseError()); + return; } - - if(!fileContent.empty()) + + if (_docRootjson.HasMember("init_cfg")) { - _docRootjson.Parse<0>(fileContent.c_str()); - if (_docRootjson.HasMember("init_cfg")) + if(_docRootjson["init_cfg"].IsObject()) { - if(_docRootjson["init_cfg"].IsObject()) + const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; + if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) { - const rapidjson::Value& objectInitView = _docRootjson["init_cfg"]; - if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) + _initViewSize.width = objectInitView["width"].GetUint(); + _initViewSize.height = objectInitView["height"].GetUint(); + if (_initViewSize.height>_initViewSize.width) { - _initViewSize.width = objectInitView["width"].GetUint(); - _initViewSize.height = objectInitView["height"].GetUint(); - if (_initViewSize.height>_initViewSize.width) - { - float tmpvalue = _initViewSize.height; - _initViewSize.height = _initViewSize.width; - _initViewSize.width = tmpvalue; - } - + float tmpvalue = _initViewSize.height; + _initViewSize.height = _initViewSize.width; + _initViewSize.width = tmpvalue; } - if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) + + } + if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) + { + _viewName = objectInitView["name"].GetString(); + } + if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) + { + _isLandscape = objectInitView["isLandscape"].GetBool(); + } + if (objectInitView.HasMember("entry") && objectInitView["entry"].IsString()) + { + _entryfile = objectInitView["entry"].GetString(); + } + if (objectInitView.HasMember("consolePort")) + { + _consolePort = objectInitView["consolePort"].GetUint(); + if(_consolePort <= 0) + _consolePort = CONSOLE_PORT; + } + if (objectInitView.HasMember("uploadPort")) + { + _uploadPort = objectInitView["uploadPort"].GetUint(); + if(_uploadPort <= 0) + _uploadPort = UPLOAD_PORT; + } + if (objectInitView.HasMember("isWindowTop") && objectInitView["isWindowTop"].IsBool()) + { + _isWindowTop= objectInitView["isWindowTop"].GetBool(); + } + } + } + if (_docRootjson.HasMember("simulator_screen_size")) + { + const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"]; + if (ArrayScreenSize.IsArray()) + { + for (int i = 0; i #endif extern string getIPAddress(); @@ -92,6 +92,8 @@ void startScript(string strDebugArg) auto engine = LuaEngine::getInstance(); if (!strDebugArg.empty()) { + // open debugger.lua module + luaopen_debugger(engine->getLuaStack()->getLuaState()); engine->executeString(strDebugArg.c_str()); } cocos2d::log("debug args = %s", strDebugArg.c_str()); @@ -716,26 +718,28 @@ class ConnectWaitLayer: public Layer { private: Label* _labelUploadFile; - string _transferTip; public: ConnectWaitLayer() { #include "ResData.h" int designWidth = 1280; int designHeight = 800; - Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designWidth,designHeight,ResolutionPolicy::EXACT_FIT); Image* imagebg = new Image(); - imagebg->initWithImageData(__landscapePngData, sizeof(__landscapePngData)); - if (!ConfigParser::getInstance()->isLanscape()) + + if (ConfigParser::getInstance()->isLanscape()) + { + imagebg->initWithImageData(__landscapePngData, sizeof(__landscapePngData)); + Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designWidth, designHeight, ResolutionPolicy::EXACT_FIT); + } else { imagebg->initWithImageData(__portraitPngData, sizeof(__portraitPngData)); - Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designHeight,designWidth,ResolutionPolicy::EXACT_FIT); + Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designHeight, designWidth, ResolutionPolicy::EXACT_FIT); } Texture2D* texturebg = Director::getInstance()->getTextureCache()->addImage(imagebg, "play_background"); auto background = Sprite::createWithTexture(texturebg); - background->setAnchorPoint(Vec2(0,0)); - addChild(background,9000); - + background->setAnchorPoint(Vec2(0.5, 0.5)); + background->setPosition(VisibleRect::center()); + addChild(background, 9000); // variable of below is"play" button position. int portraitX = 400; @@ -746,60 +750,62 @@ public: imageplay->initWithImageData(__playEnablePngData, sizeof(__playEnablePngData)); Texture2D* textureplay = Director::getInstance()->getTextureCache()->addImage(imageplay, "play_enable"); auto playSprite = Sprite::createWithTexture(textureplay); - playSprite->setPosition(Vec2(lanscaptX,lanscaptY)); - addChild(playSprite,9999); + addChild(playSprite, 9999); Image* imageShine = new Image(); imageShine->initWithImageData(__shinePngData, sizeof(__shinePngData)); - Texture2D* textureShine = Director::getInstance()->getTextureCache()->addImage(imageShine, "Shine"); + Texture2D* textureShine = Director::getInstance()->getTextureCache()->addImage(imageShine, "shine"); auto shineSprite = Sprite::createWithTexture(textureShine); shineSprite->setOpacity(0); - shineSprite->setPosition(Vec2(lanscaptX, lanscaptY)); Vector arrayOfActions; arrayOfActions.pushBack(DelayTime::create(0.4f)); - arrayOfActions.pushBack(FadeTo::create(0.8f,200)); - arrayOfActions.pushBack(FadeTo::create(0.8f,255)); - arrayOfActions.pushBack(FadeTo::create(0.8f,200)); - arrayOfActions.pushBack(FadeTo::create(0.8f,0)); + arrayOfActions.pushBack(FadeTo::create(0.8f, 200)); + arrayOfActions.pushBack(FadeTo::create(0.8f, 255)); + arrayOfActions.pushBack(FadeTo::create(0.8f, 200)); + arrayOfActions.pushBack(FadeTo::create(0.8f, 0)); arrayOfActions.pushBack(DelayTime::create(0.4f)); shineSprite->runAction(RepeatForever::create(Sequence::create(arrayOfActions))); - addChild(shineSprite,9998); + addChild(shineSprite, 9998); string strip = getIPAddress(); - char szIPAddress[512]={0}; + char szIPAddress[64] = {0}; sprintf(szIPAddress, "IP: %s", strip.c_str()); auto IPlabel = Label::createWithSystemFont(szIPAddress, "", 72); - IPlabel->setAnchorPoint(Vec2(0,0)); + IPlabel->setAnchorPoint(Vec2(0, 0)); int spaceSizex = 72; int spaceSizey = 200; IPlabel->setPosition(Point(VisibleRect::leftTop().x + spaceSizex, VisibleRect::top().y - spaceSizey)); addChild(IPlabel, 9001); - _transferTip = "waiting for file transfer ..."; + string transferTip = "waiting for file transfer ..."; if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM) { - _transferTip = "waiting for debugger to connect ..."; + transferTip = "waiting for debugger to connect ..."; } - char szVersion[1024] = {0}; - sprintf(szVersion,"runtimeVersion:%s \nengineVersion:%s", getRuntimeVersion(), cocos2dVersion()); + char szVersion[256] = {0}; + sprintf(szVersion, "runtimeVersion:%s \nengineVersion:%s", getRuntimeVersion(), cocos2dVersion()); Label* verLable = Label::createWithSystemFont(szVersion, "", 24); verLable->setAnchorPoint(Vec2(0, 0)); int width = verLable->getBoundingBox().size.width; - verLable->setPosition(Point(VisibleRect::right().x-width, VisibleRect::rightBottom().y)); + verLable->setPosition(Point(VisibleRect::right().x - width, VisibleRect::rightBottom().y)); verLable->setAlignment(TextHAlignment::LEFT); addChild(verLable, 9002); - _labelUploadFile = Label::createWithSystemFont(_transferTip, "", 36); + _labelUploadFile = Label::createWithSystemFont(transferTip, "", 36); _labelUploadFile->setAnchorPoint(Vec2(0, 0)); _labelUploadFile->setPosition(Point(VisibleRect::leftTop().x + spaceSizex, IPlabel->getPositionY()- spaceSizex)); _labelUploadFile->setAlignment(TextHAlignment::LEFT); addChild(_labelUploadFile, 9003); - if (!ConfigParser::getInstance()->isLanscape()) + if (ConfigParser::getInstance()->isLanscape()) { - if (playSprite) playSprite->setPosition(portraitX,portraitY); - if (shineSprite) shineSprite->setPosition(portraitX,portraitY); - _labelUploadFile->setAlignment(TextHAlignment::LEFT); + playSprite->setPosition(lanscaptX, lanscaptY); + shineSprite->setPosition(lanscaptX, lanscaptY); + } + else + { + playSprite->setPosition(portraitX, portraitY); + shineSprite->setPosition(portraitX, portraitY); } auto listener = EventListenerTouchOneByOne::create(); @@ -827,11 +833,11 @@ public: // clean up: ignore stdin, stdout and stderr void update(float fDelta) { - _transferTip = FileServer::getShareInstance()->getTransingFileName(); - if (_transferTip.empty()){ + string transferTip = FileServer::getShareInstance()->getTransingFileName(); + if (transferTip.empty()){ return; } - _labelUploadFile->setString(_transferTip); + _labelUploadFile->setString(transferTip); } }; @@ -1167,25 +1173,12 @@ static void register_runtime_override_function(lua_State* tolua_S) lua_pop(tolua_S, 1); } -bool initRuntime() +void initRuntime() { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) -#ifndef _DEBUG - return false; -#endif -#elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#ifdef NDEBUG - return false; -#endif -#elif(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#ifndef COCOS2D_DEBUG - return false; -#endif -#endif - - vector searchPathArray; - searchPathArray=FileUtils::getInstance()->getSearchPaths(); + vector searchPathArray = FileUtils::getInstance()->getSearchPaths(); + #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + // add peoject's root directory to search path if (g_projectPath.empty()) { extern std::string getCurAppPath(); @@ -1201,6 +1194,7 @@ bool initRuntime() searchPathArray.insert(searchPathArray.begin(), g_projectPath); #endif + // add writable path to search path g_resourcePath = FileUtils::getInstance()->getWritablePath(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) @@ -1221,37 +1215,19 @@ bool initRuntime() auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); - LuaStack* stack = engine->getLuaStack(); - register_runtime_override_function(stack->getLuaState()); - luaopen_debugger(engine->getLuaStack()->getLuaState()); + register_runtime_override_function(engine->getLuaStack()->getLuaState()); static ConsoleCustomCommand *g_customCommand; g_customCommand = new ConsoleCustomCommand(); g_customCommand->init(); - return true; } -bool startRuntime() +void startRuntime() { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) -#ifndef _DEBUG - return false; -#endif -#elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#ifdef NDEBUG - return false; -#endif -#elif(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#ifndef COCOS2D_DEBUG - return false; -#endif -#endif - auto scene = Scene::create(); auto connectLayer = new ConnectWaitLayer(); connectLayer->autorelease(); auto director = Director::getInstance(); scene->addChild(connectLayer); director->runWithScene(scene); - return true; } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h index 6a7b9eb7c0..68e715d632 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.h @@ -25,8 +25,8 @@ THE SOFTWARE. #ifndef _RUNTIME__H_ #define _RUNTIME__H_ -bool initRuntime(); -bool startRuntime(); +void initRuntime(); +void startRuntime(); #endif // _RUNTIME__H_ diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/hellolua/main.cpp b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/hellolua/main.cpp index 2122669df2..a3de54f9b2 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/hellolua/main.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/hellolua/main.cpp @@ -24,11 +24,11 @@ extern "C" bool Java_org_cocos2dx_lua_AppActivity_nativeIsDebug(JNIEnv *env, jobject thisz) { - #ifdef NDEBUG - return false; - #else - return true; - #endif +#if (COCOS2D_DEBUG > 0) + return true; +#else + return false; +#endif } } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java index 704c69af9d..e678b3ce41 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/src/org/cocos2dx/lua/AppActivity.java @@ -54,7 +54,7 @@ import android.widget.Toast; public class AppActivity extends Cocos2dxActivity{ - static String hostIPAdress="0.0.0.0"; + static String hostIPAdress = "0.0.0.0"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index 36cda4b14c..202de49bb3 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -1260,6 +1260,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../../cocos2d-x/cocos/platform/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -1282,6 +1283,7 @@ SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../../cocos2d-x/cocos/platform/ios"; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index f3afd9c824..5ea40ae743 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -140,6 +140,7 @@ set(TESTS_SRC Classes/MotionStreakTest/MotionStreakTest.cpp Classes/MutiTouchTest/MutiTouchTest.cpp Classes/NodeTest/NodeTest.cpp + Classes/OpenURLTest/OpenURLTest.cpp Classes/ParallaxTest/ParallaxTest.cpp Classes/ParticleTest/ParticleTest.cpp Classes/PerformanceTest/PerformanceAllocTest.cpp diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp index f2dde3384a..04d5560473 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp @@ -29,7 +29,7 @@ void SceneController::onEnter() ComController::onEnter(); _fAddTargetTime = 1.0f; - static_cast(_owner->getComponent("Audio"))->playBackgroundMusic("background-music-aac.wav", true); + static_cast(_owner->getComponent("Audio"))->playBackgroundMusic("background.wav", true); static_cast(_owner->getComponent("CCComAttribute"))->setInt("KillCount", 0); } diff --git a/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp new file mode 100644 index 0000000000..69aa50444f --- /dev/null +++ b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp @@ -0,0 +1,38 @@ +#include "OpenURLTest.h" + +OpenURLTest::OpenURLTest() +{ + auto label = Label::createWithTTF("Open URL Test", "fonts/arial.ttf", 28); + addChild(label, 0); + label->setPosition(VisibleRect::center().x, VisibleRect::top().y - 50); + + auto listener = EventListenerTouchAllAtOnce::create(); + listener->onTouchesEnded = CC_CALLBACK_2(OpenURLTest::onTouchesEnded, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + + // create a label to display the tip string + _label = Label::createWithTTF("Touch the screen to open\nthe cocos2d-x home page", "fonts/arial.ttf", 22); + _label->setPosition(VisibleRect::center()); + addChild(_label, 0); + + _label->retain(); +} + +void OpenURLTest::onTouchesEnded(const std::vector& touches, Event *event) +{ + Application::getInstance()->openURL("http://www.cocos2d-x.org/"); +} + +OpenURLTest::~OpenURLTest() +{ + _label->release(); +} + +void OpenURLTestScene::runThisTest() +{ + auto layer = new (std::nothrow) OpenURLTest(); + addChild(layer); + + Director::getInstance()->replaceScene(this); + layer->release(); +} diff --git a/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h new file mode 100644 index 0000000000..96e79c9a4b --- /dev/null +++ b/tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h @@ -0,0 +1,24 @@ +#ifndef _OPEN_URL_TEST_H_ +#define _OPEN_URL_TEST_H_ + +#include "cocos2d.h" +#include "../testBasic.h" + +class OpenURLTest : public Layer +{ +public: + OpenURLTest(); + ~OpenURLTest(); + + void onTouchesEnded(const std::vector& touches, cocos2d::Event *event); +private: + cocos2d::Label* _label; +}; + +class OpenURLTestScene : public TestScene +{ +public: + virtual void runThisTest(); +}; + +#endif // _OPEN_URL_TEST_H_ diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index 398cdab08f..a50744b181 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -105,7 +105,8 @@ Controller g_aTestNames[] = { { "Touches", [](){return new PongScene();} }, { "Transitions", [](){return new TransitionsTestScene();} }, { "Unit Test", []() { return new UnitTestScene(); }}, - { "UserDefault", []() { return new UserDefaultTestScene(); } }, + { "URL Open Test", []() { return new OpenURLTestScene(); } }, + { "UserDefault", []() { return new UserDefaultTestScene(); } }, { "Zwoptex", []() { return new ZwoptexTestScene(); } }, }; diff --git a/tests/cpp-tests/Classes/tests.h b/tests/cpp-tests/Classes/tests.h index b401d40394..b46ee09f4d 100644 --- a/tests/cpp-tests/Classes/tests.h +++ b/tests/cpp-tests/Classes/tests.h @@ -76,4 +76,6 @@ #include "BillBoardTest/BillBoardTest.h" #include "LightTest/LightTest.h" +#include "OpenURLTest/OpenURLTest.h" + #endif diff --git a/tests/cpp-tests/proj.android/jni/Android.mk b/tests/cpp-tests/proj.android/jni/Android.mk index 35d516a9ff..566aec556f 100644 --- a/tests/cpp-tests/proj.android/jni/Android.mk +++ b/tests/cpp-tests/proj.android/jni/Android.mk @@ -187,6 +187,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../Classes/UnitTest/UnitTest.cpp \ ../../Classes/UITest/UITest.cpp \ ../../Classes/UserDefaultTest/UserDefaultTest.cpp \ +../../Classes/OpenURLTest/OpenURLTest.cpp \ ../../Classes/ZwoptexTest/ZwoptexTest.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index 82b252c3f9..bdc272a917 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -276,6 +276,7 @@ + @@ -468,6 +469,7 @@ + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index 9cc8a2e80c..d37e26974d 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -447,6 +447,9 @@ Classes\PerformanceTest + + Classes\OpenURLTest + Classes\ZwoptexTest @@ -995,6 +998,9 @@ Classes\PerformanceTest + + Classes\OpenURLTest + Classes\ZwoptexTest diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj index 44cadcb0c3..cc20217330 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj @@ -218,6 +218,7 @@ + @@ -421,6 +422,7 @@ + diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters index 06e1b9e7d3..80ff889bae 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters @@ -325,6 +325,9 @@ {4dadf399-3bf1-4d35-85d1-d8def766fe0f} + + {f3b97ed6-a90e-4abc-b916-f91da5de888d} + @@ -862,6 +865,9 @@ Classes\BillBoardTest + + Classes\OpenURLTest + @@ -1598,6 +1604,9 @@ Classes\BillBoardTest + + Classes\OpenURLTest + diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index ffc36fba3f..6c971d29b6 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console GLProgramCache GLProgramState Camera +classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console GLProgramCache GLProgramState Camera Device # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -137,6 +137,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Sprite3DMaterialCache::[*], Sprite3DCache::[*], Bone3D::[*], + Device::[getTextureDataForText], BillBoard::[*], BaseLight3D::[*], DirectionLight3D::[*],