From 2255cf91bafa923fb58954499ffa3c92379eb2fc Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 9 Sep 2014 12:07:33 +0400 Subject: [PATCH 01/41] openUrl function for all platform but on windows RT empty function --- cocos/platform/CCApplicationProtocol.h | 9 +++++++++ cocos/platform/android/CCApplication-android.cpp | 5 +++++ cocos/platform/android/CCApplication-android.h | 7 +++++++ .../java/src/org/cocos2dx/lib/Cocos2dxHelper.java | 14 ++++++++++++++ .../jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp | 14 ++++++++++++++ .../jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h | 1 + cocos/platform/ios/CCApplication-ios.h | 7 +++++++ cocos/platform/ios/CCApplication-ios.mm | 7 +++++++ cocos/platform/linux/CCApplication-linux.cpp | 6 ++++++ cocos/platform/linux/CCApplication-linux.h | 7 +++++++ cocos/platform/mac/CCApplication-mac.h | 7 +++++++ cocos/platform/mac/CCApplication-mac.mm | 7 +++++++ cocos/platform/win32/CCApplication-win32.cpp | 10 ++++++++++ cocos/platform/win32/CCApplication-win32.h | 7 +++++++ cocos/platform/winrt/CCApplication.cpp | 6 ++++++ cocos/platform/winrt/CCApplication.h | 7 +++++++ 16 files changed, 121 insertions(+) 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/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..8fcbf1001d 100644 --- a/cocos/platform/winrt/CCApplication.cpp +++ b/cocos/platform/winrt/CCApplication.cpp @@ -177,6 +177,12 @@ Application::Platform Application::getTargetPlatform() return Platform::OS_WP8; } +bool Application::openURL(const std::string &url) +{ + //TODO release this method + 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..2f561a20c0 100644 --- a/cocos/platform/winrt/CCApplication.h +++ b/cocos/platform/winrt/CCApplication.h @@ -62,6 +62,13 @@ 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); /** * Sets the Resource root path. From a9a0ff35f6b76c28561011853e8a2dc4b40bed6b Mon Sep 17 00:00:00 2001 From: Guy Kogus Date: Mon, 22 Sep 2014 13:40:24 +0100 Subject: [PATCH 02/41] Added method for converting from std::string to Platform::String. --- cocos/platform/winrt/CCWinRTUtils.cpp | 6 ++++++ cocos/platform/winrt/CCWinRTUtils.h | 1 + 2 files changed, 7 insertions(+) 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); From 6e91c65e749f358a5d10ad250d327783bbd65b29 Mon Sep 17 00:00:00 2001 From: Guy Kogus Date: Mon, 22 Sep 2014 13:47:58 +0100 Subject: [PATCH 03/41] Windows Phone 8 can now open URLs. --- cocos/platform/winrt/CCApplication.cpp | 14 +++++++++++--- cocos/platform/winrt/CCApplication.h | 12 ++++++++++++ cocos/platform/winrt/InputEvent.h | 1 + cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.cpp | 13 +++++++++---- cocos/platform/wp8-xaml/cpp/Cocos2dRenderer.h | 2 ++ cocos/platform/wp8-xaml/cpp/Direct3DInterop.cpp | 11 +++++++++++ cocos/platform/wp8-xaml/cpp/Direct3DInterop.h | 3 +++ cocos/platform/wp8-xaml/xaml/MainPage.xaml.cs | 9 +++++++++ .../proj.wp8-xaml/App/MainPage.xaml.cs | 9 +++++++++ .../AppComponent/src/Cocos2dRenderer.cpp | 13 +++++++++---- .../AppComponent/src/Cocos2dRenderer.h | 2 ++ .../AppComponent/src/Direct3DInterop.cpp | 11 +++++++++++ .../AppComponent/src/Direct3DInterop.h | 3 +++ 13 files changed, 92 insertions(+), 11 deletions(-) diff --git a/cocos/platform/winrt/CCApplication.cpp b/cocos/platform/winrt/CCApplication.cpp index 8fcbf1001d..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); @@ -179,8 +180,15 @@ Application::Platform Application::getTargetPlatform() bool Application::openURL(const std::string &url) { - //TODO release this method - return false; + if (m_openURLDelegate) + { + m_openURLDelegate(PlatformStringFromString(url)); + return true; + } + else + { + return false; + } } void Application::setResourceRootPath(const std::string& rootResDir) diff --git a/cocos/platform/winrt/CCApplication.h b/cocos/platform/winrt/CCApplication.h index 2f561a20c0..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 @@ -70,6 +71,15 @@ public: */ 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. * @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPaths() instead. @@ -94,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/InputEvent.h b/cocos/platform/winrt/InputEvent.h index 64f8ed64df..290fc4f744 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); 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 e14858b33d..5c2aa87c62 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 70d50eb5ee..81c80c295c 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); } } @@ -199,6 +201,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/App/MainPage.xaml.cs b/templates/cpp-template-default/proj.wp8-xaml/App/MainPage.xaml.cs index 70d50eb5ee..81c80c295c 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); } } @@ -199,6 +201,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..52b55b57f7 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 @@ -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 e14858b33d..5c2aa87c62 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; }; From 908311ff7f882cc7581a474067ff4cf22be654f2 Mon Sep 17 00:00:00 2001 From: Guy Kogus Date: Mon, 22 Sep 2014 13:48:15 +0100 Subject: [PATCH 04/41] Added tests for opening a URL. --- .../Classes/OpenURLTest/OpenURLTest.cpp | 38 +++++++++++++++++++ .../Classes/OpenURLTest/OpenURLTest.h | 24 ++++++++++++ tests/cpp-tests/Classes/controller.cpp | 3 +- tests/cpp-tests/Classes/tests.h | 2 + .../cpp-testsComponent.vcxproj | 2 + .../cpp-testsComponent.vcxproj.filters | 9 +++++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.cpp create mode 100644 tests/cpp-tests/Classes/OpenURLTest/OpenURLTest.h 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 b5864d45ac..299415ed4f 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -104,7 +104,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 0fd5748a1e..a5a68df7de 100644 --- a/tests/cpp-tests/Classes/tests.h +++ b/tests/cpp-tests/Classes/tests.h @@ -75,4 +75,6 @@ #include "Camera3DTest/Camera3DTest.h" #include "BillBoardTest/BillBoardTest.h" +#include "OpenURLTest/OpenURLTest.h" + #endif 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 + From b8b5397e4e196e0ce36537d1f40df4fe1ec3f691 Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 22 Sep 2014 17:32:20 +0400 Subject: [PATCH 05/41] Tests for Mac/iOS android Linux & Windows --- build/cocos2d_tests.xcodeproj/project.pbxproj | 16 ++++++++++++++++ tests/cpp-tests/CMakeLists.txt | 1 + tests/cpp-tests/proj.android/jni/Android.mk | 1 + tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 2 ++ .../proj.win32/cpp-tests.vcxproj.filters | 6 ++++++ 5 files changed, 26 insertions(+) diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index d86ff073b4..3452104c8d 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -934,6 +934,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 */; }; @@ -2958,6 +2960,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 = ""; }; @@ -5505,6 +5509,7 @@ 1AC35B1718CECF0C00F37B72 /* UserDefaultTest */, 1AC35B1A18CECF0C00F37B72 /* VisibleRect.cpp */, 1AC35B1B18CECF0C00F37B72 /* VisibleRect.h */, + A5030C3219D059AB000E78E7 /* OpenURLTest */, 1AC35B1C18CECF0C00F37B72 /* ZwoptexTest */, ); name = Classes; @@ -7160,6 +7165,15 @@ name = BillBoardTest; sourceTree = ""; }; + A5030C3219D059AB000E78E7 /* OpenURLTest */ = { + isa = PBXGroup; + children = ( + A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */, + A5030C3419D059DA000E78E7 /* OpenURLTest.h */, + ); + name = OpenURLTest; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -7997,6 +8011,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 */, @@ -8224,6 +8239,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 */, 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/proj.android/jni/Android.mk b/tests/cpp-tests/proj.android/jni/Android.mk index be29988826..f25c1253f2 100644 --- a/tests/cpp-tests/proj.android/jni/Android.mk +++ b/tests/cpp-tests/proj.android/jni/Android.mk @@ -186,6 +186,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 73d0325d2d..8633f180f8 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -275,6 +275,7 @@ + @@ -466,6 +467,7 @@ + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index 96bd0d11b3..9382250f22 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -444,6 +444,9 @@ Classes\PerformanceTest + + Classes\OpenURLTest + Classes\ZwoptexTest @@ -989,6 +992,9 @@ Classes\PerformanceTest + + Classes\OpenURLTest + Classes\ZwoptexTest From e74b2f31640eecde9ddc1f13808619fb29686d80 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 23 Sep 2014 18:15:26 +0800 Subject: [PATCH 06/41] add macro to enable neon on IOS --- cocos/math/MathUtil.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index acf6ab0b42..463130aa03 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -115,6 +115,10 @@ NS_CC_MATH_END #define MATRIX_SIZE ( sizeof(float) * 16) +#ifdef __ARM_NEON__ +#define USE_NEON +#endif + #ifdef USE_NEON #include "MathUtilNeon.inl" #else From 2226aa5c8abf5381645359a4027a534de71632a1 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Tue, 23 Sep 2014 10:01:42 -0700 Subject: [PATCH 07/41] need to reset the accelerometer before trying to enable it again --- cocos/platform/winrt/CCDevice.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) 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) From b9c57f7e28b54e826a6a855d45c3e9b61d109497 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Tue, 23 Sep 2014 10:39:17 -0700 Subject: [PATCH 08/41] changed background-music-aac.wav to background.wav. background-music-acc.wav does not exist --- .../ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From b18e0501fc22b70bcf86c88da7a228cb3432938b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 24 Sep 2014 10:32:29 +0800 Subject: [PATCH 09/41] move code to mathUtil.cp --- cocos/math/MathUtil.cpp | 402 ++++++++++++++++++++++++++++++++++++ cocos/math/MathUtil.h | 20 +- cocos/math/MathUtil.inl | 171 --------------- cocos/math/MathUtilNeon.inl | 225 -------------------- 4 files changed, 412 insertions(+), 406 deletions(-) diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index 3e62986cc3..c972d59943 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -44,4 +44,406 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, } } +#ifdef USE_NEON + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +void MathUtil::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" + ); +} + +#else + +void MathUtil::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; +} + +void MathUtil::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]; +} + +void MathUtil::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]; +} + +void MathUtil::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; +} + +void MathUtil::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); +} + +void MathUtil::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]; +} + +void MathUtil::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); +} + +void MathUtil::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]; +} + +void MathUtil::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; +} + +void MathUtil::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; +} + +#endif + NS_CC_MATH_END diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index 463130aa03..b40da30720 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -88,25 +88,25 @@ private: inline 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(); }; diff --git a/cocos/math/MathUtil.inl b/cocos/math/MathUtil.inl index ba19d635e7..8a78dee6d5 100644 --- a/cocos/math/MathUtil.inl +++ b/cocos/math/MathUtil.inl @@ -20,175 +20,4 @@ NS_CC_MATH_BEGIN -inline void MathUtil::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 MathUtil::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 MathUtil::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 MathUtil::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 MathUtil::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) -{ - 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 MathUtil::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 MathUtil::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) -{ - // 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) -{ - 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/MathUtilNeon.inl b/cocos/math/MathUtilNeon.inl index f9c73498fd..8a78dee6d5 100644 --- a/cocos/math/MathUtilNeon.inl +++ b/cocos/math/MathUtilNeon.inl @@ -20,229 +20,4 @@ NS_CC_MATH_BEGIN -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - -inline void MathUtil::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" - ); -} - NS_CC_MATH_END From e1d11ae5c380a18223531d40079efb263ed81f87 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 24 Sep 2014 11:06:07 +0800 Subject: [PATCH 10/41] move sse code to mathUtil.cpp --- cocos/math/MathUtil.cpp | 153 +++++++++++++++++++++++++++++++++++++ cocos/math/MathUtil.h | 25 ++---- cocos/math/MathUtilSSE.inl | 148 ----------------------------------- 3 files changed, 161 insertions(+), 165 deletions(-) diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index c972d59943..9e7138bfde 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -446,4 +446,157 @@ void MathUtil::crossVec3(const float* v1, const float* v2, float* dst) #endif +#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); + dst[1] = _mm_add_ps(m[1], s); + dst[2] = _mm_add_ps(m[2], s); + dst[3] = _mm_add_ps(m[3], s); +} + +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]); + dst[2] = _mm_add_ps(m1[2], m2[2]); + dst[3] = _mm_add_ps(m1[3], m2[3]); +} + +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]); + dst[2] = _mm_sub_ps(m1[2], m2[2]); + dst[3] = _mm_sub_ps(m1[3], m2[3]); +} + +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); + dst[1] = _mm_mul_ps(m[1], s); + dst[2] = _mm_mul_ps(m[2], s); + dst[3] = _mm_mul_ps(m[3], s); +} + +void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +{ + __m128 dst0, dst1, dst2, dst3; + { + __m128 e0 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst0 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst1 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst2 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst3 = a2; + } + dst[0] = dst0; + dst[1] = dst1; + dst[2] = dst2; + dst[3] = dst3; +} + +void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) +{ + __m128 z = _mm_setzero_ps(); + dst[0] = _mm_sub_ps(z, m[0]); + dst[1] = _mm_sub_ps(z, m[1]); + dst[2] = _mm_sub_ps(z, m[2]); + dst[3] = _mm_sub_ps(z, m[3]); +} + +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); + __m128 tmp1 = _mm_shuffle_ps(m[2], m[3], 0x44); + __m128 tmp3 = _mm_shuffle_ps(m[2], m[3], 0xEE); + + dst[0] = _mm_shuffle_ps(tmp0, tmp1, 0x88); + dst[1] = _mm_shuffle_ps(tmp0, tmp1, 0xDD); + dst[2] = _mm_shuffle_ps(tmp2, tmp3, 0x88); + dst[3] = _mm_shuffle_ps(tmp2, tmp3, 0xDD); +} + +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)); + __m128 col3 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)); + __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)) + ); +} + +#endif + NS_CC_MATH_END diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index b40da30720..2e5dab3938 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -72,21 +72,21 @@ public: 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 static void addMatrix(const float* m, float scalar, float* dst); @@ -119,13 +119,4 @@ NS_CC_MATH_END #define USE_NEON #endif -#ifdef USE_NEON -#include "MathUtilNeon.inl" -#else -#include "MathUtil.inl" -#if defined(__SSE__) -#include "MathUtilSSE.inl" -#endif -#endif - #endif diff --git a/cocos/math/MathUtilSSE.inl b/cocos/math/MathUtilSSE.inl index b701bb51ca..ebb29b663b 100644 --- a/cocos/math/MathUtilSSE.inl +++ b/cocos/math/MathUtilSSE.inl @@ -1,152 +1,4 @@ NS_CC_MATH_BEGIN -inline 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); - dst[1] = _mm_add_ps(m[1], s); - dst[2] = _mm_add_ps(m[2], s); - dst[3] = _mm_add_ps(m[3], s); -} - -inline 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]); - dst[2] = _mm_add_ps(m1[2], m2[2]); - dst[3] = _mm_add_ps(m1[3], m2[3]); -} - -inline 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]); - dst[2] = _mm_sub_ps(m1[2], m2[2]); - dst[3] = _mm_sub_ps(m1[3], m2[3]); -} - -inline 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); - dst[1] = _mm_mul_ps(m[1], s); - dst[2] = _mm_mul_ps(m[2], s); - dst[3] = _mm_mul_ps(m[3], s); -} - -inline void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) -{ - __m128 dst0, dst1, dst2, dst3; - { - __m128 e0 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst0 = a2; - } - - { - __m128 e0 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst1 = a2; - } - - { - __m128 e0 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst2 = a2; - } - - { - __m128 e0 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst3 = a2; - } - dst[0] = dst0; - dst[1] = dst1; - dst[2] = dst2; - dst[3] = dst3; -} - -inline void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) -{ - __m128 z = _mm_setzero_ps(); - dst[0] = _mm_sub_ps(z, m[0]); - dst[1] = _mm_sub_ps(z, m[1]); - dst[2] = _mm_sub_ps(z, m[2]); - dst[3] = _mm_sub_ps(z, m[3]); -} - -inline 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); - __m128 tmp1 = _mm_shuffle_ps(m[2], m[3], 0x44); - __m128 tmp3 = _mm_shuffle_ps(m[2], m[3], 0xEE); - - dst[0] = _mm_shuffle_ps(tmp0, tmp1, 0x88); - dst[1] = _mm_shuffle_ps(tmp0, tmp1, 0xDD); - dst[2] = _mm_shuffle_ps(tmp2, tmp3, 0x88); - dst[3] = _mm_shuffle_ps(tmp2, tmp3, 0xDD); -} - -inline 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)); - __m128 col3 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)); - __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)) - ); -} NS_CC_MATH_END From b513dbafb5eccde5aef41b8886ef18195530bb76 Mon Sep 17 00:00:00 2001 From: honghui Date: Wed, 24 Sep 2014 11:43:21 +0800 Subject: [PATCH 11/41] read config.json may failed caused by syntax error --- .../runtime-src/Classes/AppDelegate.cpp | 16 +- .../runtime-src/Classes/ConfigParser.cpp | 154 +++++++++--------- .../runtime-src/Classes/ConfigParser.h | 2 +- .../runtime-src/Classes/runtime/Runtime.cpp | 110 +++++-------- .../runtime-src/Classes/runtime/Runtime.h | 4 +- .../proj.android/jni/hellolua/main.cpp | 10 +- .../src/org/cocos2dx/lua/AppActivity.java | 2 +- 7 files changed, 135 insertions(+), 163 deletions(-) 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(); @@ -716,26 +716,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 +748,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 +831,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 +1171,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 +1192,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) @@ -1228,30 +1220,14 @@ bool initRuntime() 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); From 2a75b7192add9de3aa7b0d47072327d4e9759eb3 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 24 Sep 2014 16:12:47 +0800 Subject: [PATCH 12/41] enable neon on IOS and refactor code --- cocos/math/MathUtil.cpp | 570 ++++-------------------------------- cocos/math/MathUtil.h | 5 - cocos/math/MathUtil.inl | 195 ++++++++++++ cocos/math/MathUtilNeon.inl | 250 +++++++++++++++- cocos/math/MathUtilSSE.inl | 153 ++++++++++ 5 files changed, 653 insertions(+), 520 deletions(-) diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index 9e7138bfde..6a2ebb408c 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -21,12 +21,19 @@ This file was modified to fit the cocos2d-x project #include "MathUtil.h" #include "base/ccMacros.h" +#if defined (__ARM_NEON__) || ((CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) &&!defined(__SSE__)) +#include "MathUtilNeon.inl" +#endif + +#include "MathUtil.inl" +#include "MathUtilSSE.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,559 +51,94 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, } } -#ifdef USE_NEON - void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - -void MathUtil::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" - ); -} - +#ifdef __ARM_NEON__ + MathUtilNeon::addMatrix(m, scalar, dst); #else - -void MathUtil::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; + MathUtilC::addMatrix(m, scalar, dst); +#endif } void MathUtil::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]; +#ifdef __ARM_NEON__ + MathUtilNeon::addMatrix(m1, m2, dst); +#else + MathUtilC::addMatrix(m1, m2, dst); +#endif } void MathUtil::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]; +#ifdef __ARM_NEON__ + MathUtilNeon::subtractMatrix(m1, m2, dst); +#else + MathUtilC::subtractMatrix(m1, m2, dst); +#endif } void MathUtil::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; +#ifdef __ARM_NEON__ + MathUtilNeon::multiplyMatrix(m, scalar, dst); +#else + MathUtilC::multiplyMatrix(m, scalar, dst); +#endif } void MathUtil::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); +#ifdef __ARM_NEON__ + MathUtilNeon::multiplyMatrix(m1, m2, dst); +#else + MathUtilC::multiplyMatrix(m1, m2, dst); +#endif } void MathUtil::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]; +#ifdef __ARM_NEON__ + MathUtilNeon::negateMatrix(m, dst); +#else + MathUtilC::negateMatrix(m, dst); +#endif } void MathUtil::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); +#ifdef __ARM_NEON__ + MathUtilNeon::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) { - 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]; +#ifdef __ARM_NEON__ + MathUtilNeon::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) { - // 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; +#ifdef __ARM_NEON__ + MathUtilNeon::transformVec4(m, v, dst); +#else + MathUtilC::transformVec4(m, v, dst); +#endif } void MathUtil::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; -} - +#ifdef __ARM_NEON__ + MathUtilNeon::crossVec3(v1, v2, dst); +#else + MathUtilC::crossVec3(v1, v2, dst); #endif - -#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); - dst[1] = _mm_add_ps(m[1], s); - dst[2] = _mm_add_ps(m[2], s); - dst[3] = _mm_add_ps(m[3], s); } -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]); - dst[2] = _mm_add_ps(m1[2], m2[2]); - dst[3] = _mm_add_ps(m1[3], m2[3]); -} - -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]); - dst[2] = _mm_sub_ps(m1[2], m2[2]); - dst[3] = _mm_sub_ps(m1[3], m2[3]); -} - -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); - dst[1] = _mm_mul_ps(m[1], s); - dst[2] = _mm_mul_ps(m[2], s); - dst[3] = _mm_mul_ps(m[3], s); -} - -void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) -{ - __m128 dst0, dst1, dst2, dst3; - { - __m128 e0 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst0 = a2; - } - - { - __m128 e0 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst1 = a2; - } - - { - __m128 e0 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst2 = a2; - } - - { - __m128 e0 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(0, 0, 0, 0)); - __m128 e1 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(1, 1, 1, 1)); - __m128 e2 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(2, 2, 2, 2)); - __m128 e3 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(3, 3, 3, 3)); - - __m128 v0 = _mm_mul_ps(m1[0], e0); - __m128 v1 = _mm_mul_ps(m1[1], e1); - __m128 v2 = _mm_mul_ps(m1[2], e2); - __m128 v3 = _mm_mul_ps(m1[3], e3); - - __m128 a0 = _mm_add_ps(v0, v1); - __m128 a1 = _mm_add_ps(v2, v3); - __m128 a2 = _mm_add_ps(a0, a1); - - dst3 = a2; - } - dst[0] = dst0; - dst[1] = dst1; - dst[2] = dst2; - dst[3] = dst3; -} - -void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) -{ - __m128 z = _mm_setzero_ps(); - dst[0] = _mm_sub_ps(z, m[0]); - dst[1] = _mm_sub_ps(z, m[1]); - dst[2] = _mm_sub_ps(z, m[2]); - dst[3] = _mm_sub_ps(z, m[3]); -} - -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); - __m128 tmp1 = _mm_shuffle_ps(m[2], m[3], 0x44); - __m128 tmp3 = _mm_shuffle_ps(m[2], m[3], 0xEE); - - dst[0] = _mm_shuffle_ps(tmp0, tmp1, 0x88); - dst[1] = _mm_shuffle_ps(tmp0, tmp1, 0xDD); - dst[2] = _mm_shuffle_ps(tmp2, tmp3, 0x88); - dst[3] = _mm_shuffle_ps(tmp2, tmp3, 0xDD); -} - -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)); - __m128 col3 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)); - __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)) - ); -} - -#endif - NS_CC_MATH_END diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index 2e5dab3938..92f1ace3c6 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -108,15 +108,10 @@ private: static void crossVec3(const float* v1, const float* v2, float* dst); - MathUtil(); }; NS_CC_MATH_END #define MATRIX_SIZE ( sizeof(float) * 16) -#ifdef __ARM_NEON__ -#define USE_NEON -#endif - #endif diff --git a/cocos/math/MathUtil.inl b/cocos/math/MathUtil.inl index 8a78dee6d5..5148fa13d8 100644 --- a/cocos/math/MathUtil.inl +++ b/cocos/math/MathUtil.inl @@ -20,4 +20,199 @@ NS_CC_MATH_BEGIN +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; + 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 MathUtilC::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 MathUtilC::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 MathUtilC::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 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 MathUtilC::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 MathUtilC::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 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 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 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; +} + NS_CC_MATH_END diff --git a/cocos/math/MathUtilNeon.inl b/cocos/math/MathUtilNeon.inl index 8a78dee6d5..bf41e6c704 100644 --- a/cocos/math/MathUtilNeon.inl +++ b/cocos/math/MathUtilNeon.inl @@ -17,7 +17,255 @@ This file was modified to fit the cocos2d-x project */ - NS_CC_MATH_BEGIN +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + +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" + ); +} + NS_CC_MATH_END diff --git a/cocos/math/MathUtilSSE.inl b/cocos/math/MathUtilSSE.inl index ebb29b663b..3a6d5c1de0 100644 --- a/cocos/math/MathUtilSSE.inl +++ b/cocos/math/MathUtilSSE.inl @@ -1,4 +1,157 @@ NS_CC_MATH_BEGIN +#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); + dst[1] = _mm_add_ps(m[1], s); + dst[2] = _mm_add_ps(m[2], s); + dst[3] = _mm_add_ps(m[3], s); +} + +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]); + dst[2] = _mm_add_ps(m1[2], m2[2]); + dst[3] = _mm_add_ps(m1[3], m2[3]); +} + +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]); + dst[2] = _mm_sub_ps(m1[2], m2[2]); + dst[3] = _mm_sub_ps(m1[3], m2[3]); +} + +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); + dst[1] = _mm_mul_ps(m[1], s); + dst[2] = _mm_mul_ps(m[2], s); + dst[3] = _mm_mul_ps(m[3], s); +} + +void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +{ + __m128 dst0, dst1, dst2, dst3; + { + __m128 e0 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst0 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst1 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst2 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst3 = a2; + } + dst[0] = dst0; + dst[1] = dst1; + dst[2] = dst2; + dst[3] = dst3; +} + +void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) +{ + __m128 z = _mm_setzero_ps(); + dst[0] = _mm_sub_ps(z, m[0]); + dst[1] = _mm_sub_ps(z, m[1]); + dst[2] = _mm_sub_ps(z, m[2]); + dst[3] = _mm_sub_ps(z, m[3]); +} + +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); + __m128 tmp1 = _mm_shuffle_ps(m[2], m[3], 0x44); + __m128 tmp3 = _mm_shuffle_ps(m[2], m[3], 0xEE); + + dst[0] = _mm_shuffle_ps(tmp0, tmp1, 0x88); + dst[1] = _mm_shuffle_ps(tmp0, tmp1, 0xDD); + dst[2] = _mm_shuffle_ps(tmp2, tmp3, 0x88); + dst[3] = _mm_shuffle_ps(tmp2, tmp3, 0xDD); +} + +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)); + __m128 col3 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)); + __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)) + ); +} + +#endif + NS_CC_MATH_END From cc39ed288a8dcc4cfd800d911a45177081046d43 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 24 Sep 2014 17:21:38 +0800 Subject: [PATCH 13/41] android can link with neon(neon code has some bugs) --- cocos/math/MathUtil.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ cocos/math/MathUtil.h | 5 +++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index 6a2ebb408c..9f37d16cf3 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -21,7 +21,12 @@ 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 + #if defined (__ARM_NEON__) || ((CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) &&!defined(__SSE__)) +#define USE_NEON #include "MathUtilNeon.inl" #endif @@ -51,10 +56,36 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, } } +bool MathUtil::isNeonEnabled() +{ +#ifdef __ARM_NEON__ + return true; +#elif defined (USE_NEON) + if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0) + return true; + else + return false; +#else + return false; +#endif +} + +bool MathUtil::isSSEEnabled() +{ +#ifdef __SSE__ + return true; +#else + return false; +#endif +} + void MathUtil::addMatrix(const float* m, float scalar, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::addMatrix(m, scalar, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::addMatrix(m, scalar, dst); + else MathUtilC::addMatrix(m, scalar, dst); #else MathUtilC::addMatrix(m, scalar, dst); #endif @@ -64,6 +95,9 @@ void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::addMatrix(m1, m2, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::addMatrix(m1, m2, dst); + else MathUtilC::addMatrix(m1, m2, dst); #else MathUtilC::addMatrix(m1, m2, dst); #endif @@ -73,6 +107,9 @@ void MathUtil::subtractMatrix(const float* m1, const float* m2, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::subtractMatrix(m1, m2, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::subtractMatrix(m1, m2, dst); + else MathUtilC::subtractMatrix(m1, m2, dst); #else MathUtilC::subtractMatrix(m1, m2, dst); #endif @@ -82,6 +119,9 @@ void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::multiplyMatrix(m, scalar, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::multiplyMatrix(m, scalar, dst); + else MathUtilC::multiplyMatrix(m, scalar, dst); #else MathUtilC::multiplyMatrix(m, scalar, dst); #endif @@ -91,6 +131,9 @@ void MathUtil::multiplyMatrix(const float* m1, const float* m2, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::multiplyMatrix(m1, m2, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::multiplyMatrix(m1, m2, dst); + else MathUtilC::multiplyMatrix(m1, m2, dst); #else MathUtilC::multiplyMatrix(m1, m2, dst); #endif @@ -100,6 +143,9 @@ void MathUtil::negateMatrix(const float* m, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::negateMatrix(m, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::negateMatrix(m, dst); + else MathUtilC::negateMatrix(m, dst); #else MathUtilC::negateMatrix(m, dst); #endif @@ -109,6 +155,9 @@ void MathUtil::transposeMatrix(const float* m, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::transposeMatrix(m, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::transposeMatrix(m, dst); + else MathUtilC::transposeMatrix(m, dst); #else MathUtilC::transposeMatrix(m, dst); #endif @@ -118,6 +167,9 @@ void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, { #ifdef __ARM_NEON__ MathUtilNeon::transformVec4(m, x, y, z, w, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) 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 @@ -127,6 +179,9 @@ void MathUtil::transformVec4(const float* m, const float* v, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::transformVec4(m, v, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::transformVec4(m, v, dst); + else MathUtilC::transformVec4(m, v, dst); #else MathUtilC::transformVec4(m, v, dst); #endif @@ -136,6 +191,9 @@ void MathUtil::crossVec3(const float* v1, const float* v2, float* dst) { #ifdef __ARM_NEON__ MathUtilNeon::crossVec3(v1, v2, dst); +#elif defined (USE_NEON) + if(isNeonEnabled()) MathUtilNeon::crossVec3(v1, v2, dst); + else MathUtilC::crossVec3(v1, v2, dst); #else MathUtilC::crossVec3(v1, v2, dst); #endif diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index 92f1ace3c6..e08a0ba037 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -69,7 +69,10 @@ 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 isNeonEnabled(); + static bool isSSEEnabled(); private: #ifdef __SSE__ static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); From 3c434ec35428296119b6bb4b93edcce32a62ec99 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 24 Sep 2014 17:47:38 +0800 Subject: [PATCH 14/41] remove Win32InputBox.cpp/.h, move them to UIEditBoxImpl-win32.cpp --- cocos/2d/libcocos2d.vcxproj | 2 - cocos/2d/libcocos2d.vcxproj.filters | 6 - cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp | 460 ++++++++++++++++++++- cocos/ui/proj.win32/Win32InputBox.cpp | 383 ----------------- cocos/ui/proj.win32/Win32InputBox.h | 106 ----- 5 files changed, 458 insertions(+), 499 deletions(-) delete mode 100644 cocos/ui/proj.win32/Win32InputBox.cpp delete mode 100644 cocos/ui/proj.win32/Win32InputBox.h diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 3f99625b24..9e0cfa2545 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -404,7 +404,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - @@ -783,7 +782,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 10c806f590..537fe8b5bb 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 @@ -2278,9 +2275,6 @@ extension\GUI\CCControlExtensions - - ui\UIWidgets\EditBox - platform\win32 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 From 1146f1a8db6b9662cb33ee27c7a4e092c0391ec0 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Wed, 24 Sep 2014 08:38:48 -0700 Subject: [PATCH 15/41] use CCGLViewImpl.h --- .../proj.wp8-xaml/AppComponent/src/Cocos2dRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..7231d15208 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 From d1faf75b583ca4caccd30f272ef6fab41851b579 Mon Sep 17 00:00:00 2001 From: toma Date: Thu, 25 Sep 2014 01:46:17 +0900 Subject: [PATCH 16/41] [CCLabel] Apply updateContent() for getStringNumLines() when Label is dirty --- cocos/2d/CCLabel.cpp | 9 +++++++++ cocos/2d/CCLabel.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) 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; } From a897f2302333bdce7ef2dd272b4132fecd475288 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 25 Sep 2014 10:46:25 +0800 Subject: [PATCH 17/41] refactor neon code --- cocos/math/MathUtil.cpp | 112 ++++++++++++------ cocos/math/MathUtil.h | 4 +- .../platform/android/java/project.properties | 2 +- .../proj.android/project.properties | 2 +- 4 files changed, 78 insertions(+), 42 deletions(-) diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index 9f37d16cf3..b5aa1ed7dc 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -25,13 +25,49 @@ This file was modified to fit the cocos2d-x project #include #endif -#if defined (__ARM_NEON__) || ((CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) &&!defined(__SSE__)) -#define USE_NEON +//#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 (__SSE__) + //#define INCLUDE_NEON32 + #endif +#else + +#endif + +#if defined (__SSE__) +#define USE_SSE +#define INCLUDE_SSE +#endif + +#ifdef INCLUDE_NEON32 #include "MathUtilNeon.inl" #endif -#include "MathUtil.inl" +#ifdef INCLUDE_NEON64 +// TODO: add neon64 inplementation here +// #include "MathUtil.inl" +#endif + +#ifdef INCLUDE_SSE #include "MathUtilSSE.inl" +#endif + +#include "MathUtil.inl" NS_CC_MATH_BEGIN @@ -56,11 +92,11 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, } } -bool MathUtil::isNeonEnabled() +bool MathUtil::isNeon32Enabled() { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 return true; -#elif defined (USE_NEON) +#elif (defined (INCLUDE_NEON32) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) ) if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0) return true; else @@ -70,9 +106,9 @@ bool MathUtil::isNeonEnabled() #endif } -bool MathUtil::isSSEEnabled() +bool MathUtil::isNeon64Enabled() { -#ifdef __SSE__ +#ifdef USE_NEON64 return true; #else return false; @@ -81,10 +117,10 @@ bool MathUtil::isSSEEnabled() void MathUtil::addMatrix(const float* m, float scalar, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::addMatrix(m, scalar, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -93,10 +129,10 @@ void MathUtil::addMatrix(const float* m, float scalar, float* dst) void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::addMatrix(m1, m2, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -105,10 +141,10 @@ void MathUtil::addMatrix(const float* m1, const float* m2, float* dst) void MathUtil::subtractMatrix(const float* m1, const float* m2, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::subtractMatrix(m1, m2, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -117,10 +153,10 @@ void MathUtil::subtractMatrix(const float* m1, const float* m2, float* dst) void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::multiplyMatrix(m, scalar, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -129,10 +165,10 @@ void MathUtil::multiplyMatrix(const float* m, float scalar, float* dst) void MathUtil::multiplyMatrix(const float* m1, const float* m2, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::multiplyMatrix(m1, m2, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -141,10 +177,10 @@ void MathUtil::multiplyMatrix(const float* m1, const float* m2, float* dst) void MathUtil::negateMatrix(const float* m, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::negateMatrix(m, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::negateMatrix(m, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::negateMatrix(m, dst); else MathUtilC::negateMatrix(m, dst); #else MathUtilC::negateMatrix(m, dst); @@ -153,10 +189,10 @@ void MathUtil::negateMatrix(const float* m, float* dst) void MathUtil::transposeMatrix(const float* m, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::transposeMatrix(m, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::transposeMatrix(m, dst); +#elif defined (INCLUDE_NEON32) + if(isNeon32Enabled()) MathUtilNeon::transposeMatrix(m, dst); else MathUtilC::transposeMatrix(m, dst); #else MathUtilC::transposeMatrix(m, dst); @@ -165,10 +201,10 @@ void MathUtil::transposeMatrix(const float* m, float* dst) void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::transformVec4(m, x, y, z, w, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -177,10 +213,10 @@ void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, void MathUtil::transformVec4(const float* m, const float* v, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::transformVec4(m, v, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); @@ -189,10 +225,10 @@ void MathUtil::transformVec4(const float* m, const float* v, float* dst) void MathUtil::crossVec3(const float* v1, const float* v2, float* dst) { -#ifdef __ARM_NEON__ +#ifdef USE_NEON32 MathUtilNeon::crossVec3(v1, v2, dst); -#elif defined (USE_NEON) - if(isNeonEnabled()) MathUtilNeon::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); diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index e08a0ba037..64d80ad4c3 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -71,8 +71,8 @@ public: static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime); private: //Indicates that if neon is enabled - static bool isNeonEnabled(); - static bool isSSEEnabled(); + static bool isNeon32Enabled(); + static bool isNeon64Enabled(); private: #ifdef __SSE__ static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); diff --git a/cocos/platform/android/java/project.properties b/cocos/platform/android/java/project.properties index 88ca83f9d0..61afc8fe54 100644 --- a/cocos/platform/android/java/project.properties +++ b/cocos/platform/android/java/project.properties @@ -12,4 +12,4 @@ android.library=true # Project target. -target=android-10 +target=android-19 diff --git a/tests/cpp-empty-test/proj.android/project.properties b/tests/cpp-empty-test/proj.android/project.properties index 572f7c30de..b743fe7388 100644 --- a/tests/cpp-empty-test/proj.android/project.properties +++ b/tests/cpp-empty-test/proj.android/project.properties @@ -8,6 +8,6 @@ # project structure. # Project target. -target=android-10 +target=android-19 android.library.reference.1=../../../cocos/platform/android/java From 260cdd4eaa56e6683bc46fd210dd186ab78ee435 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 10:53:34 +0800 Subject: [PATCH 18/41] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 67e5e60114..3a7f68eb16 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ cocos2d-x-3.3 [NEW] UI: `WebView` support on windows [FIX] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 + [FIX] Accelerometer: will freeze app and then crash on WP8 cocos2d-x-3.3 Sep.20 2014 [NEW] 3d: added `BillBoard` From ab19c81371fad695e8cdf9ccb7f7732ae8a1ee5b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 25 Sep 2014 10:53:44 +0800 Subject: [PATCH 19/41] add neon64 implementation --- cocos/math/MathUtil.cpp | 23 +++- cocos/math/MathUtilNeon64.inl | 218 ++++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 cocos/math/MathUtilNeon64.inl diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index b5aa1ed7dc..64cce45d46 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -59,8 +59,7 @@ This file was modified to fit the cocos2d-x project #endif #ifdef INCLUDE_NEON64 -// TODO: add neon64 inplementation here -// #include "MathUtil.inl" +#include "MathUtilNeon64.inl" #endif #ifdef INCLUDE_SSE @@ -119,6 +118,8 @@ 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); @@ -131,6 +132,8 @@ 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); @@ -143,6 +146,8 @@ 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); @@ -155,6 +160,8 @@ 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); @@ -167,6 +174,8 @@ 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); @@ -179,6 +188,8 @@ 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); @@ -191,6 +202,8 @@ 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); @@ -203,6 +216,8 @@ void MathUtil::transformVec4(const float* m, float x, float y, float z, float w, { #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); @@ -215,6 +230,8 @@ 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); @@ -227,6 +244,8 @@ 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); 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 From b56b0d1eaefb99fc99a0486a55992478323d2743 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 10:55:18 +0800 Subject: [PATCH 20/41] [ci skip] --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 3a7f68eb16..6296bb0d09 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,8 +4,8 @@ cocos2d-x-3.3 [NEW] Utils: added getCascadeBoundingBox() [NEW] UI: `WebView` support on windows - [FIX] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 [FIX] Accelerometer: will freeze app and then crash on WP8 + [FIX] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 cocos2d-x-3.3 Sep.20 2014 [NEW] 3d: added `BillBoard` From 34fbca9c50c5cd469182382f4ae6e0aa70bfc4bf Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 25 Sep 2014 11:46:42 +0800 Subject: [PATCH 21/41] fix ios8 EditBox orientation problem --- cocos/platform/ios/CCEAGLView-ios.mm | 37 +++++++++++++--------------- 1 file changed, 17 insertions(+), 20 deletions(-) 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); From 206e158596112c7a9f49497ab346c66470225d5c Mon Sep 17 00:00:00 2001 From: honghui Date: Thu, 25 Sep 2014 12:01:16 +0800 Subject: [PATCH 22/41] performance improvement for lua runtime on Run mode --- .../frameworks/runtime-src/Classes/runtime/Runtime.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp index c7181cdfb6..8b07d81830 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp @@ -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()); @@ -1213,9 +1215,7 @@ void 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(); From e0d14458a5bb9b7d72e270a57204b56da50abfbf Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 25 Sep 2014 05:43:04 +0000 Subject: [PATCH 23/41] [AUTO][ci skip]: updating cocos2dx_files.json --- templates/cocos2dx_files.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 53bfe0d56f..a8b0fdc178 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -1083,8 +1083,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", From f9fb673df98a84006a26cf2c01233817aeb1e52c Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 13:43:12 +0800 Subject: [PATCH 24/41] [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index f761ab3791..f26cadbe32 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1010,6 +1010,9 @@ Developers: wohaaitinciu WebView support on windows + + guykogus + Implemented Application::openUrl for WP8 and WinRT Retired Core Developers: WenSheng Yang From ebc632fd1f25aac7e259837053327a9f88f3f8ca Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 13:45:00 +0800 Subject: [PATCH 25/41] [ci skip] --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index f26cadbe32..f7064154f4 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 From 26cbfaa29bfdcd9f55d44f9bd8dd0172a87a23b6 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 13:46:12 +0800 Subject: [PATCH 26/41] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 6296bb0d09..cb2cf32733 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ 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 From 1da8986291549cec5f7858951b98acfdc8541319 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 25 Sep 2014 05:48:32 +0000 Subject: [PATCH 27/41] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/Application.lua | 23 ++- .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 138 ++++++++++++------ .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 1 + 3 files changed, 110 insertions(+), 52 deletions(-) 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/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 9869b1cf29..8af271dbdf 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -58962,6 +58962,53 @@ int lua_register_cocos2dx_TextureCache(lua_State* tolua_S) 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 +59053,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 +59097,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 +59230,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); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index bede494edf..0cff4e3b27 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1573,6 +1573,7 @@ int register_all_cocos2dx(lua_State* tolua_S); + #endif // __cocos2dx_h__ From df7685d237d1348b30dae9b88ee68dd1c238d751 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 13:52:20 +0800 Subject: [PATCH 28/41] [ci skip] Update CHANGELOG --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index cb2cf32733..b2456ad14e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,7 +5,8 @@ cocos2d-x-3.3 [NEW] Utils: added getCascadeBoundingBox() [NEW] UI: `WebView` support on windows - [FIX] Accelerometer: will freeze app and then crash on WP8 + [FIX] Accelerometer: using Accelerometer will freeze app and then crash on WP8 + [FIX] EditBox: view rendereed in wrong position if click EditBox on iOS 8 [FIX] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 cocos2d-x-3.3 Sep.20 2014 From e281f9f6b380cee01b2cd93147eb8d40440bc905 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 14:47:03 +0800 Subject: [PATCH 29/41] [ci skip] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index b2456ad14e..5ce3373f9b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ cocos2d-x-3.3 [FIX] Accelerometer: using Accelerometer will freeze app and then crash on WP8 [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] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 cocos2d-x-3.3 Sep.20 2014 From d36e57f1294fcf4f6f1309214177e08988b82184 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 25 Sep 2014 14:49:51 +0800 Subject: [PATCH 30/41] [ci skip]Update Authors --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index f7064154f4..de1df99e53 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1014,6 +1014,9 @@ Developers: guykogus Implemented Application::openUrl for WP8 and WinRT + + tttreal + Fixed Label::getStringNumLines() Retired Core Developers: WenSheng Yang From 71926816182e57b26b96cdb147ab42ee2be6dbb3 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 25 Sep 2014 06:50:06 +0000 Subject: [PATCH 31/41] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/Application.lua | 23 ++- .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 138 ++++++++++++------ .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 1 + 3 files changed, 110 insertions(+), 52 deletions(-) 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/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 9869b1cf29..8af271dbdf 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -58962,6 +58962,53 @@ int lua_register_cocos2dx_TextureCache(lua_State* tolua_S) 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 +59053,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 +59097,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 +59230,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); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index bede494edf..0cff4e3b27 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1573,6 +1573,7 @@ int register_all_cocos2dx(lua_State* tolua_S); + #endif // __cocos2dx_h__ From 23fb2062c9c64fa3550a05042acc64b0729c1c31 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Thu, 25 Sep 2014 15:05:42 +0800 Subject: [PATCH 32/41] Fix the bug that passing the wrong stack index to luaval_to_ccvaluemap and luaval_to_ccvaluevector --- .../lua-bindings/manual/LuaBasicConversions.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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)); } From ed9848a782f9ef54320745746acdada157eabd65 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 25 Sep 2014 16:09:28 +0800 Subject: [PATCH 33/41] neon works on android(only on armeabi-v7a) --- cocos/Android.mk | 5 ++++- cocos/math/MathUtil.cpp | 27 +++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) 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/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index 64cce45d46..bb981a3255 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -42,8 +42,11 @@ This file was modified to fit the cocos2d-x project #else #endif #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - #if !defined (__SSE__) - //#define INCLUDE_NEON32 + #if defined (__arm64__) + #define INCLUDE_NEON64 + #elif defined (__ARM_NEON__) + #define INCLUDE_NEON32 + #else #endif #else @@ -96,10 +99,22 @@ bool MathUtil::isNeon32Enabled() #ifdef USE_NEON32 return true; #elif (defined (INCLUDE_NEON32) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) ) - if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0) - return true; - else - return false; + 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 From af0c9ce2fafcb031e9a7fe260264789c66d7a82e Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 25 Sep 2014 16:54:33 +0800 Subject: [PATCH 34/41] reverse target=android-10 on android --- cocos/platform/android/java/project.properties | 2 +- tests/cpp-empty-test/proj.android/project.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/platform/android/java/project.properties b/cocos/platform/android/java/project.properties index 61afc8fe54..88ca83f9d0 100644 --- a/cocos/platform/android/java/project.properties +++ b/cocos/platform/android/java/project.properties @@ -12,4 +12,4 @@ android.library=true # Project target. -target=android-19 +target=android-10 diff --git a/tests/cpp-empty-test/proj.android/project.properties b/tests/cpp-empty-test/proj.android/project.properties index b743fe7388..572f7c30de 100644 --- a/tests/cpp-empty-test/proj.android/project.properties +++ b/tests/cpp-empty-test/proj.android/project.properties @@ -8,6 +8,6 @@ # project structure. # Project target. -target=android-19 +target=android-10 android.library.reference.1=../../../cocos/platform/android/java From 1f2fc054fef3556ebb26b4de6e98636cf643d801 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 25 Sep 2014 10:05:55 +0000 Subject: [PATCH 35/41] [AUTO][ci skip]: updating cocos2dx_files.json --- templates/cocos2dx_files.json | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index a8b0fdc178..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", From ebf0562b8439e69ef986852f354cc84cd17cd7d7 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 26 Sep 2014 10:35:50 +0800 Subject: [PATCH 36/41] remove armv7s support on iOS --- build/cocos2d_libs.xcodeproj/project.pbxproj | 2 ++ build/cocos2d_tests.xcodeproj/project.pbxproj | 32 +++++++++++++------ .../HelloCpp.xcodeproj/project.pbxproj | 2 ++ .../HelloLua.xcodeproj/project.pbxproj | 2 ++ .../HelloLua.xcodeproj/project.pbxproj | 2 ++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 1f9c90a639..54f8649053 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -6834,6 +6834,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; }; @@ -6866,6 +6867,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 3bc0f55d98..213643c47d 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -7161,15 +7161,6 @@ name = Products; sourceTree = ""; }; - B609E67019C18D90003D0074 /* BillBoardTest */ = { - isa = PBXGroup; - children = ( - B609E67119C18DAD003D0074 /* BillBoardTest.cpp */, - B609E67219C18DAD003D0074 /* BillBoardTest.h */, - ); - name = BillBoardTest; - sourceTree = ""; - }; A5030C3219D059AB000E78E7 /* OpenURLTest */ = { isa = PBXGroup; children = ( @@ -7179,6 +7170,15 @@ name = OpenURLTest; sourceTree = ""; }; + B609E67019C18D90003D0074 /* BillBoardTest */ = { + isa = PBXGroup; + children = ( + B609E67119C18DAD003D0074 /* BillBoardTest.cpp */, + B609E67219C18DAD003D0074 /* BillBoardTest.h */, + ); + name = BillBoardTest; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -8593,6 +8593,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 +8620,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 +8705,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 +8723,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 +8744,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 +8766,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 +8826,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 +8848,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 +8898,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 +8918,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 +8941,7 @@ buildSettings = { COMPRESS_PNG_FILES = NO; SDKROOT = iphoneos; + VALID_ARCHS = "arm64 armv7"; }; name = Debug; }; @@ -8939,6 +8950,7 @@ buildSettings = { COMPRESS_PNG_FILES = NO; SDKROOT = iphoneos; + VALID_ARCHS = "arm64 armv7"; }; name = Release; }; @@ -8962,6 +8974,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 +8999,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/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/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/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; }; From bd56a71b1b0368d3c9c4047eb808ff5c5a1f8d7b Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 26 Sep 2014 10:44:29 +0800 Subject: [PATCH 37/41] CC_USE_MEM_LEAK_DETECTION -> CC_REF_LEAK_DETECTION --- cocos/base/CCRef.cpp | 12 ++++++------ cocos/base/CCRef.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) 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 From 995b09cb2807f2cf4e64595b276cc0753e14d70e Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 26 Sep 2014 11:01:18 +0800 Subject: [PATCH 38/41] [ci skip] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 5ce3373f9b..6f45fd66c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ cocos2d-x-3.3 [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] TextFieldTTF: will get wrong characters if using Chinese input method on WP8 From 0cbe8890306ea6ad1f979d900614eb8f9bf165e5 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 26 Sep 2014 11:51:59 +0800 Subject: [PATCH 39/41] [ci skip] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 6f45fd66c2..c64067915b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ cocos2d-x-3.3 [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 From 1c71234921bdf1ad70daaf54bdc5d70878167b56 Mon Sep 17 00:00:00 2001 From: Hong Liang Date: Fri, 26 Sep 2014 11:52:52 +0800 Subject: [PATCH 40/41] export lua function "cc.Device::getDPI()" --- tools/tolua/cocos2dx.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 8b92268f28..8583530c0e 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::[*] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], From 963c02eb3ded8eef1c5b128165ec6f5455bfec3b Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Fri, 26 Sep 2014 05:45:33 +0000 Subject: [PATCH 41/41] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/Device.lua | 31 ++++ .../auto/api/lua_cocos2dx_auto_api.lua | 5 + .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 151 ++++++++++++++++++ .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 5 + 4 files changed, 192 insertions(+) create mode 100644 cocos/scripting/lua-bindings/auto/api/Device.lua 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 8af271dbdf..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,156 @@ 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; @@ -65571,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 0cff4e3b27..758bdf6e07 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1570,6 +1570,11 @@ int register_all_cocos2dx(lua_State* tolua_S); + + + + +