Commit Graph

178 Commits

Author SHA1 Message Date
James Chen e8c0844dd5 fixed #1617: Some improvements for JS Bindings.
1) Changed cc.REPEAT_FOREVER = - 1 to cc.REPEAT_FOREVER = 0xffffffff
[Reason]: If cc.REPEAT_FOREVER = -1, it will be a very big double value after converting it to double by JS_ValueToNumber on android.
Then cast it to unsigned int, the value will be 0. The schedule will not be able to work.
I don't know why this occurs only on android.
[Solution]: Instead of passing -1 to it, I assign it with max value of unsigned int in c++.

2) Added two helper function, cc.ArrayGetIndexOfObject and cc.ArrayContainsObject.

3) Added JSScheduleWrapper::removeTargetForNativeNode to avoid memory leaks.

4) Improvments for JSTouchDelegate. Added four functions as follows:
// Set the touch delegate to map by using the key (pJSObj).
static void setDelegateForJSObject(JSObject* pJSObj, JSTouchDelegate* pDelegate);

// Get the touch delegate by the key (pJSObj).
static JSTouchDelegate* getDelegateForJSObject(JSObject* pJSObj);

// Remove the delegate by the key (pJSObj).
static void removeDelegateForJSObject(JSObject* pJSObj);

void unregisterTouchDelegate();
And exported cc.unregisterTouchDelegate(); to js.
Fix a memory leak for JSTouchDelegate by making it as an autorelease object.

5) Don't add js callback function to the reserved slot of object.
[Reason]: The target object may execute more than one schedule.
Therefore, previous js callback function will be replaced
by the current one. For example:

this.scheduleOnce(function() { temporary function 1 }, 0.5);
this.scheduleOnce(function() { temporary function 2 }, 0.5);

In this case, the temporary function 1 will be removed from reserved slot 0.
And temporary function 2 will be set to reserved slot 0 of this object.
If gc is triggered before the JSScheduleWrapper::scheduleFunc is invoked,
crash will happen. You could simply reproduce it by adding jsc.garbageCollect(); after scheduleOnce.
[Solution] Because one schedule corresponds to one JSScheduleWrapper, we root
the js callback function in JSScheduleWrapper::setJSCallbackFunc and unroot it
at the destructor of JSScheduleWrapper.
2012-12-18 11:56:44 +08:00
CocosRobot 13b04e3ee4 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-12-17 15:26:28 +08:00
James Chen e7328cf3ba fixed #1614: DrawNodeTest crashes on JSB. 2012-12-14 10:31:31 +08:00
Nicolas Gramlich 9537389949 Added cc.DrawNode.extend. 2012-12-12 21:49:29 +08:00
dualface 268aa45d2c rename CCNode:scheduleUpdateScriptHandlerWithPriority() to CCNode::scheduleUpdateWhitPriorityLua()
remove unused functions
2012-12-10 16:09:23 +08:00
dualface c8753f72ef [scripting] add CCNode::scheduleUpdateScriptHandlerWithPriority() 2012-12-10 13:48:27 +08:00
CocosRobot f7e87f2269 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-12-07 09:51:17 +08:00
CocosRobot fe9e6ba688 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-12-06 17:22:53 +08:00
James Chen 34eb3a88c2 Commented JS_SetGCZeal. 2012-12-04 17:23:08 +08:00
James Chen b5ae1f6d2a Updated MoonWarriors/Classes/AppDelegate.cpp.
Updated the submodule reference of cocos2d-js-tests to the latest one.
Fixed duplicate define in js_bindings_ccbreader.cpp.
2012-12-04 11:36:45 +08:00
CocosRobot 545002b3a9 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-12-04 10:59:58 +08:00
minggo 4e7fca3185 merge dualface's pull request for fixing CCLayer script support and fix error for js-binding 2012-12-04 10:52:49 +08:00
James Chen 7c074d4ced issue #1550: fixed a memory leak in jsbinding. 2012-12-03 22:17:53 +08:00
James Chen 478791a472 Added CCBReader::setCCBRootPath. 2012-12-03 18:27:50 +08:00
James Chen f6185844a9 fixed #1588: Get the right js callback function in js_CCScheduler_schedule. 2012-12-03 15:59:29 +08:00
James Chen d97dfe162a fixed #1588: RescheduleCallback support for JSBinding. 2012-12-03 15:33:36 +08:00
James Chen 399fb53452 fixed #1586: Native object need to be an autorelease object. 2012-12-01 11:41:51 +08:00
James Chen e3615e2fb1 fixed #1586: Invoking removeAllRoots in ScriptingCore destructor to avoid crash when app exits. 2012-12-01 11:41:50 +08:00
James Chen 36bc0ab0bb Invoking JS_SetGCZeal only when the macros DEBUG and JS_GC_ZEAL is defined. 2012-12-01 11:41:50 +08:00
Rohan Kuruvilla 745392ad6c Changing chipmunk manual bindings to fix GC issues 2012-11-30 16:08:19 -08:00
CocosRobot 3533358049 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-11-30 22:20:22 +08:00
James Chen 07661a1e21 issue #1581: Added jsb_set_reserved_slot and jsb_get_reserved_slot, 2012-11-30 22:00:30 +08:00
James Chen 15d02e4db8 Merge branch 'iss1581-fix-jsbinding-bugs' of https://github.com/dumganhar/cocos2d-x into iss1583-js-tests
Conflicts:
	scripting/javascript/bindings/cocos2d_specifics.cpp
2012-11-30 21:43:44 +08:00
James Chen 95875112fa Merge branch 'iss1583-js-tests' of https://github.com/dumganhar/cocos2d-x into iss1583-js-tests 2012-11-30 21:19:19 +08:00
James Chen 26790eb17a issue #1583: Added some Macros as follows:
cc.MENU_STATE_WAITING = 0;
cc.MENU_STATE_TRACKING_TOUCH = 1;
cc.MENU_HANDLER_PRIORITY = -128;
cc.DEFAULT_PADDING = 5;
2012-11-30 21:15:54 +08:00
James Chen 0d93f2d651 issue #1583: Bind cc.Menu.alignItemsInRows, cc.Menu.alignItemsInColums, cc.LayerMultiplex.create 2012-11-30 21:15:01 +08:00
James Chen 96e2707f39 issue #1583: Added jsvals_variadic_to_ccarray function. 2012-11-30 21:12:14 +08:00
James Chen e8c5f5f38c Added CCTexture2D::setTexParameters binding.
Fixed pass one more argument in JSCallFuncWrapper::callbackFunc if extraData is void.
2012-11-30 18:15:29 +08:00
minggo bb6e03bd3f Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into iss1583-update-js 2012-11-30 17:42:51 +08:00
James Chen a37cc8a098 Updated jsb_constants_chipmunk.js and jsb_constants_cocosbuilder.js. 2012-11-29 15:29:58 +08:00
James Chen 494806167b Temporary commit. 2012-11-29 15:26:24 +08:00
James Chen 208132895e issue #1583: Moved the common js codes to scripting/javascript/bindings/js folder. Deleted the old js sample resources. 2012-11-29 11:27:39 +08:00
James Chen bb4b3fb4bc issue #1581: Deleted JS_AddObjectRoot when construct a JS array since JS_SetElement will not trigger a GC. 2012-11-29 11:01:32 +08:00
Rohan Kuruvilla a4b55b5217 Fixing Accelerometer crash on Android 2012-11-28 15:56:57 -08:00
James Chen a4762605b8 issue #1581: Removed some unused codes. 2012-11-28 22:24:12 +08:00
James Chen a814066601 issue #1581: JSBinding bug fixes.
Some fixes of JSBinding codes:
[1] Check whether the proxy was already added in JS_NEW_PROXY
[2] In struct schedFunc_proxy_t, JSScheduleWrapper* --> CCArray*
Reason: One js function may correspond to many targets. To debug this, you could refer to JSScheduleWrapper::dump function. It will prove that i'm right. :)
[3] In ScriptingCore::cleanupSchedulesAndActions function, we must invoke unschedule for all targets and remove the proxy both in _schedFunc_target_ht and _schedTarget_native_ht, otherwise the hash tables will grow bigger and bigger, so I added a new function JSScheduleWrapper::removeAllTargetsForNatiaveNode to make this things easier.
[4] To easily find out the bugs of binding codes, I add JS_SetGCZeal in ScriptingCore::createGlobalContext, it only works in DEBUG mode.
[5] In js_cocos2dx_CCNode_getChildren, we should add the generated array to root to avoid gc happen when invoking JS_SetElement.
[6] The JSCallFuncWrapper isn't needed since an action will be run by a cc.Node and it will be released at the CCNode::cleanup.
[7] Some improvements of JSScheduleWrapper class.
[8] Added a new function JSScheduleWrapper::setTarget, it's for js_CCNode_unschedule to find out which target need to be unscheduled.
[9] Commented JS_SetReservedSlot in js_CCNode_scheduleOnce and js_CCNode_schedule.
Reason:
For js_CCNode_scheduleOnce: Don't add the callback function to the reserved slot of this js object.Since the class of js object may be inherited from cocos class(e.g. cc.Sprite). The subclass will not contain reserved slots. It will crash if invoking this.
For js_CCNode_schedule: Don't add js callback function to the reserved slot of scheduler js object. Since the scheduler is an object always rooted.
So the callback function might not be released when gc comes.I looked inside the implementation of cc.Node.schedule, and it doesn't use JS_SetReservedSlot there.
2012-11-28 22:04:55 +08:00
CocosRobot 9e929019c3 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-11-28 11:53:56 +08:00
James Chen 0ce47db8f1 Merge pull request #1648 from CocosRobot/updategeneratedsubmodule_1353897594
cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings
2012-11-26 19:13:05 -08:00
James Chen e0948a4817 fixed #1576: Sync CCBReader to latest version, CCString* --> std::string, CocosBuilderTest crash fixes. 2012-11-26 21:51:05 +08:00
CocosRobot 0ec7f873fe cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-11-26 10:40:03 +08:00
James Chen 7c1e860d78 issue #1573: Added CocosDragonJS. Made it compiled ok on iOS,android and win32. 2012-11-23 15:09:03 +08:00
Rohan Kuruvilla 36bbd80b68 Adding changes to CCBreader 2012-11-23 15:08:55 +08:00
James Chen c32ea4486b issue #1572: WatermelonWithMe works on Android now. 2012-11-22 18:46:30 +08:00
James Chen ee97633a4f Merge pull request #1637 from dumganhar/gles20
Minor fix in ScriptingCore::log;Avoiding pointer point to a destroyed variable.
2012-11-22 01:53:57 -08:00
James Chen c0097db48c Avoiding pointer point to a destroyed variable. 2012-11-22 17:36:49 +08:00
James Chen 692d16f296 Minor fix in ScriptingCore::log. 2012-11-22 17:34:58 +08:00
CocosRobot 10ceef62dc cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-11-22 17:22:19 +08:00
CocosRobot ce19b26771 cocos2dxmatoMac-mini : updating submodule reference to latest autogenerated bindings 2012-11-22 15:38:09 +08:00
James Chen b66bc98a46 issue #1564: Made ChipmunkTest of TestJavascript works 2012-11-22 15:19:16 +08:00
James Chen 51d61ba214 issue #1564: fix the wrong order of parameters in CCScheduler::scheduleSelector.
Made MoonWarriors works.
2012-11-22 12:05:38 +08:00