Remove cleanup from auto bindings add made it support override in JS

This commit is contained in:
pandamicro 2015-07-16 14:09:26 +08:00
parent 04fd171e77
commit 490d5a3747
7 changed files with 53 additions and 11 deletions

View File

@ -221,20 +221,22 @@ bool Node::init()
void Node::cleanup() void Node::cleanup()
{ {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnCleanup))
return;
}
else if (_scriptType == kScriptTypeLua)
{
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnCleanup);
}
#endif // #if CC_ENABLE_SCRIPT_BINDING
// actions // actions
this->stopAllActions(); this->stopAllActions();
this->unscheduleAllCallbacks(); this->unscheduleAllCallbacks();
#if CC_ENABLE_SCRIPT_BINDING
if ( _scriptType != kScriptTypeNone)
{
int action = kNodeOnCleanup;
BasicScriptData data(this,(void*)&action);
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
}
#endif // #if CC_ENABLE_SCRIPT_BINDING
// timers // timers
for( const auto &child: _children) for( const auto &child: _children)
child->cleanup(); child->cleanup();

View File

@ -63,6 +63,14 @@ ProtectedNode * ProtectedNode::create(void)
void ProtectedNode::cleanup() void ProtectedNode::cleanup()
{ {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnCleanup))
return;
}
#endif // #if CC_ENABLE_SCRIPT_BINDING
Node::cleanup(); Node::cleanup();
// timers // timers
for( const auto &child: _protectedChildren) for( const auto &child: _protectedChildren)

View File

@ -191,6 +191,14 @@ void TransitionScene::onExit()
// custom cleanup // custom cleanup
void TransitionScene::cleanup() void TransitionScene::cleanup()
{ {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnCleanup))
return;
}
#endif // #if CC_ENABLE_SCRIPT_BINDING
Scene::cleanup(); Scene::cleanup();
if( _isSendCleanupToScene ) if( _isSendCleanupToScene )

View File

@ -2456,6 +2456,20 @@ bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsv
return false; return false;
} }
bool js_cocos2dx_Node_cleanup(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_cleanup : Invalid Native Object");
ScriptingCore::getInstance()->setCalledFromScript(true);
cobj->cleanup();
args.rval().setUndefined();
return true;
}
bool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -6145,6 +6159,7 @@ void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global)
JS_DefineFunction(cx, tmpObj, "onExit", js_cocos2dx_Node_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "onExit", js_cocos2dx_Node_onExit, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "onEnterTransitionDidFinish", js_cocos2dx_Node_onEnterTransitionDidFinish, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "onExitTransitionDidStart", js_cocos2dx_Node_onExitTransitionDidStart, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "cleanup", js_cocos2dx_Node_cleanup, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "schedule", js_CCNode_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "schedule", js_CCNode_schedule, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "scheduleUpdateWithPriority", js_cocos2dx_CCNode_scheduleUpdateWithPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "scheduleUpdateWithPriority", js_cocos2dx_CCNode_scheduleUpdateWithPriority, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);

View File

@ -262,6 +262,7 @@ bool js_cocos2dx_Node_onEnter(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_onExit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_onExit(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_onEnterTransitionDidFinish(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_onEnterTransitionDidFinish(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Node_cleanup(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_onEnter(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_onEnter(JSContext *cx, uint32_t argc, jsval *vp);
bool js_cocos2dx_Component_onExit(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_onExit(JSContext *cx, uint32_t argc, jsval *vp);

View File

@ -1385,6 +1385,14 @@ namespace ui {
void Scale9Sprite::cleanup() void Scale9Sprite::cleanup()
{ {
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnCleanup))
return;
}
#endif // #if CC_ENABLE_SCRIPT_BINDING
Node::cleanup(); Node::cleanup();
// timers // timers
for( const auto &child: _protectedChildren) for( const auto &child: _protectedChildren)

View File

@ -103,7 +103,7 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat
CardinalSpline.*::[create actionWithDuration setPoints initWithDuration], CardinalSpline.*::[create actionWithDuration setPoints initWithDuration],
Scheduler::[pause resume ^unschedule$ unscheduleUpdate unscheduleAllForTarget schedule isTargetPaused isScheduled], Scheduler::[pause resume ^unschedule$ unscheduleUpdate unscheduleAllForTarget schedule isTargetPaused isScheduled],
TextureCache::[addPVRTCImage], TextureCache::[addPVRTCImage],
*::[copyWith.* onEnter.* onExit.* ^description$ getObjectType onTouch.* onAcc.* onKey.* onRegisterTouchListener operator.+], *::[copyWith.* ^cleanup$ onEnter.* onExit.* ^description$ getObjectType onTouch.* onAcc.* onKey.* onRegisterTouchListener operator.+],
FileUtils::[getFileData getDataFromFile setFilenameLookupDictionary destroyInstance getFullPathCache], FileUtils::[getFileData getDataFromFile setFilenameLookupDictionary destroyInstance getFullPathCache],
Application::[^application.* ^run$ getCurrentLanguageCode setAnimationInterval], Application::[^application.* ^run$ getCurrentLanguageCode setAnimationInterval],
Camera::[getEyeXYZ getCenterXYZ getUpXYZ], Camera::[getEyeXYZ getCenterXYZ getUpXYZ],