From 92e08265cd9d8a15abb31f8e414289a9954c39f5 Mon Sep 17 00:00:00 2001 From: mannewalis Date: Thu, 3 Jul 2014 08:42:06 -0700 Subject: [PATCH] changes needed for swift bindings to work --- cocos/2d/CCNode.cpp | 12 ++++++++++++ cocos/2d/CCNode.h | 9 +++++++++ cocos/base/CCConsole.h | 2 ++ cocos/base/CCRef.cpp | 1 + cocos/base/CCRef.h | 2 ++ cocos/base/ccTypes.h | 2 ++ 6 files changed, 28 insertions(+) diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index a0905817e1..4ac671aa64 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -1310,6 +1310,9 @@ Mat4 Node::transform(const Mat4& parentTransform) void Node::onEnter() { + if (onEnterCallback) + onEnterCallback(); + #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { @@ -1337,6 +1340,9 @@ void Node::onEnter() void Node::onEnterTransitionDidFinish() { + if (onEnterTransitionDidFinishCallback) + onEnterTransitionDidFinishCallback(); + #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { @@ -1359,6 +1365,9 @@ void Node::onEnterTransitionDidFinish() void Node::onExitTransitionDidStart() { + if (onExitTransitionDidStartCallback) + onExitTransitionDidStartCallback(); + #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { @@ -1380,6 +1389,9 @@ void Node::onExitTransitionDidStart() void Node::onExit() { + if (onExitCallback) + onExitCallback(); + #if CC_ENABLE_SCRIPT_BINDING if (_scriptType == kScriptTypeJavascript) { diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 55a26ec113..57fd0279f2 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1464,6 +1464,15 @@ public: virtual void setOpacityModifyRGB(bool value) {CC_UNUSED_PARAM(value);} virtual bool isOpacityModifyRGB() const { return false; }; + /* + * Public pointers to various callbacks on this class. They can be treated as properties and + * set to call any method or lambda function. + */ + std::function onEnterCallback; + std::function onExitCallback; + std::function onEnterTransitionDidFinishCallback; + std::function onExitTransitionDidStartCallback; + CC_CONSTRUCTOR_ACCESS: // Nodes should be created using create(); Node(); diff --git a/cocos/base/CCConsole.h b/cocos/base/CCConsole.h index 7db9d397b3..9ab18ff443 100644 --- a/cocos/base/CCConsole.h +++ b/cocos/base/CCConsole.h @@ -47,6 +47,7 @@ typedef SSIZE_T ssize_t; #include #include +#include "base/CCRef.h" #include "base/ccMacros.h" #include "base/CCPlatformMacros.h" @@ -73,6 +74,7 @@ void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) class CC_DLL Console + : public Ref { public: struct Command { diff --git a/cocos/base/CCRef.cpp b/cocos/base/CCRef.cpp index 1f2c3a4ce7..140bde422b 100644 --- a/cocos/base/CCRef.cpp +++ b/cocos/base/CCRef.cpp @@ -46,6 +46,7 @@ Ref::Ref() static unsigned int uObjectCount = 0; _luaID = 0; _ID = ++uObjectCount; + _scriptObject = nullptr; #endif #if CC_USE_MEM_LEAK_DETECTION diff --git a/cocos/base/CCRef.h b/cocos/base/CCRef.h index 50f8c8b05c..283fd1cae7 100644 --- a/cocos/base/CCRef.h +++ b/cocos/base/CCRef.h @@ -142,6 +142,8 @@ public: unsigned int _ID; /// Lua reference id int _luaID; + /// scriptObject, support for swift + void* _scriptObject; #endif // Memory leak diagnostic data (only included when CC_USE_MEM_LEAK_DETECTION is defined and its value isn't zero) diff --git a/cocos/base/ccTypes.h b/cocos/base/ccTypes.h index 2c25850967..7911e37f22 100644 --- a/cocos/base/ccTypes.h +++ b/cocos/base/ccTypes.h @@ -33,6 +33,7 @@ THE SOFTWARE. #include "math/CCGeometry.h" #include "math/CCMath.h" #include "CCGL.h" +#include "CCRef.h" NS_CC_BEGIN @@ -484,6 +485,7 @@ public: @brief The device accelerometer reports values for each axis in units of g-force */ class Acceleration + : public Ref { public: double x;