From 7ede1373f7ceb8a3dde0e65809054c5343a3bf53 Mon Sep 17 00:00:00 2001 From: Rohan Kuruvilla Date: Mon, 22 Oct 2012 14:51:35 -0700 Subject: [PATCH] Adding function to cleanup actions and schedule to ScriptingCore --- scripting/javascript/bindings/ScriptingCore.cpp | 15 ++++++++++++++- scripting/javascript/bindings/ScriptingCore.h | 8 +++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scripting/javascript/bindings/ScriptingCore.cpp b/scripting/javascript/bindings/ScriptingCore.cpp index ca06e56149..7b701c8f32 100644 --- a/scripting/javascript/bindings/ScriptingCore.cpp +++ b/scripting/javascript/bindings/ScriptingCore.cpp @@ -620,6 +620,16 @@ void ScriptingCore::resumeSchedulesAndActions(CCNode *node) { } } +void ScriptingCore::cleanupSchedulesAndActions(CCNode *node) { + + CCArray * arr = JSSchedule::getTargetForNativeNode(node); + if(! arr) return; + for(unsigned int i = 0; i < arr->count(); ++i) { + if(arr->objectAtIndex(i)) { + arr->removeObjectAtIndex(i); + } + } +} int ScriptingCore::executeNodeEvent(CCNode* pNode, int nAction) { @@ -651,6 +661,9 @@ int ScriptingCore::executeNodeEvent(CCNode* pNode, int nAction) { executeJSFunctionWithName(this->cx_, p->obj, "onExitTransitionDidStart", dataVal, retval); } + else if(nAction == kCCNodeOnCleanup) { + cleanupSchedulesAndActions(pNode); + } return 1; } @@ -1100,7 +1113,7 @@ jsval cccolor4f_to_jsval(JSContext* cx, ccColor4F& v) { return JSVAL_NULL; } -jsval cccolor3b_to_jsval(JSContext* cx, ccColor3B& v) { +jsval cccolor3b_to_jsval(JSContext* cx, const ccColor3B& v) { JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); if (!tmp) return JSVAL_NULL; JSBool ok = JS_DefineProperty(cx, tmp, "r", INT_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && diff --git a/scripting/javascript/bindings/ScriptingCore.h b/scripting/javascript/bindings/ScriptingCore.h index dddd6a0482..825a585189 100644 --- a/scripting/javascript/bindings/ScriptingCore.h +++ b/scripting/javascript/bindings/ScriptingCore.h @@ -59,7 +59,8 @@ public: virtual int executeString(const char* codes) { return 0; } void pauseSchedulesAndActions(CCNode *node); void resumeSchedulesAndActions(CCNode *node); - + void cleanupSchedulesAndActions(CCNode *node); + /** @brief Execute a script file. @param filename String object holding the filename of the script file that is to be executed @@ -197,10 +198,7 @@ jsval ccsize_to_jsval(JSContext* cx, CCSize& v); jsval ccgridsize_to_jsval(JSContext* cx, ccGridSize& v); jsval cccolor4b_to_jsval(JSContext* cx, ccColor4B& v); jsval cccolor4f_to_jsval(JSContext* cx, ccColor4F& v); -jsval cccolor3b_to_jsval(JSContext* cx, ccColor3B& v); - -JSObject* NewGlobalObject(JSContext* cx); -JSBool jsNewGlobal(JSContext* cx, unsigned argc, jsval* vp); +jsval cccolor3b_to_jsval(JSContext* cx, const ccColor3B& v); JSBool jsSocketOpen(JSContext* cx, unsigned argc, jsval* vp); JSBool jsSocketRead(JSContext* cx, unsigned argc, jsval* vp);