From 2a806a82c641c81ffd13d6eeedabf275581ec8ed Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Wed, 9 Dec 2015 15:07:58 +0800 Subject: [PATCH 01/28] Fix #24345 TMX Iso Zorder and TMX Ortho Zorder rendering error in TestCPP. --- cocos/2d/CCTMXTiledMap.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cocos/2d/CCTMXTiledMap.cpp b/cocos/2d/CCTMXTiledMap.cpp index 93967c4504..e68717bea7 100644 --- a/cocos/2d/CCTMXTiledMap.cpp +++ b/cocos/2d/CCTMXTiledMap.cpp @@ -189,9 +189,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo) idx++; continue; } - addChild(child, 0, idx); - child->setOrderOfArrival(idx); - child->setTag(TMXLayerTag); + addChild(child, idx, idx); // update content size with the max size const Size& childSize = child->getContentSize(); Size currentSize = this->getContentSize(); From c823821a08810da1494da57b7853203bb946c8f1 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 10 Dec 2015 10:36:00 +0800 Subject: [PATCH 02/28] fix controlButton test error --- .../CCControlButtonTest/CCControlButtonTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp index 9c8ccae21e..dbe92feb24 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp @@ -277,15 +277,16 @@ ControlButton *ControlButtonTest_Styling::standardButtonWithTitle(const char *ti { /** Creates and return a button with a default background and title color. */ auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png"); - backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png"); - backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size auto titleButton = Label::createWithTTF(title, "fonts/Marker Felt.ttf", 30); titleButton->setColor(Color3B(159, 168, 176)); ControlButton *button = ControlButton::create(titleButton, backgroundButton); + backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size + backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size + button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED); button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED); From 96d391ea30751d0c3057f33ca9136dd4da64f383 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 10 Dec 2015 18:02:55 -0800 Subject: [PATCH 03/28] Squashed commit of the following: commit aff4e27200a77db60b13ea30c2457558e5f53059 Author: Ricardo Quesada Date: Thu Dec 10 17:58:41 2015 -0800 compiles with new GC model commit 1fa69cd71231d56371cd45a378e50a1888308b42 Author: Ricardo Quesada Date: Thu Dec 10 17:41:15 2015 -0800 Animation3D works Ok commit d439969caf7e6fe83a74e37d078c4361a08cb816 Author: Ricardo Quesada Date: Thu Dec 10 13:39:50 2015 -0800 Sprite3d create: converted to new API commit aabe449e4a968fad882c44df9be787eb7c3bfcec Author: Ricardo Quesada Date: Thu Dec 10 13:27:33 2015 -0800 ouch... commit 688ab610a8cb7607bc3c51b8ca01d800ef3c9794 Author: Ricardo Quesada Date: Thu Dec 10 13:12:25 2015 -0800 Spawn/Sequence init* were not bound Fixed. Now JS Scheduler Test works Ok --- .../auto/api/jsb_cocos2dx_3d_auto_api.js | 14 -- .../auto/api/jsb_cocos2dx_auto_api.js | 52 +++++++ .../js-bindings/auto/jsb_cocos2dx_3d_auto.cpp | 37 +---- .../js-bindings/auto/jsb_cocos2dx_3d_auto.hpp | 1 - .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 138 +++++++++++++++++- .../js-bindings/auto/jsb_cocos2dx_auto.hpp | 4 + .../auto/jsb_cocos2dx_studio_auto.cpp | 4 +- .../manual/3d/jsb_cocos2dx_3d_manual.cpp | 47 +++++- .../js-bindings/manual/ScriptingCore.cpp | 35 +---- .../js-bindings/manual/ScriptingCore.h | 15 +- .../js-bindings/manual/cocos2d_specifics.cpp | 98 +++++-------- .../js-bindings/script/jsb_create_apis.js | 22 +-- tools/bindings-generator | 2 +- tools/tojs/cocos2dx.ini | 4 +- tools/tojs/cocos2dx_3d.ini | 2 +- 15 files changed, 289 insertions(+), 186 deletions(-) diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js index bfc87c64f2..319d1a4b8e 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js @@ -56,20 +56,6 @@ getDuration : function ( return 0; }, -/** - * @method create - * @param {String} arg0 - * @param {String} arg1 - * @return {cc.Animation3D} - */ -create : function ( -str, -str -) -{ - return cc.Animation3D; -}, - /** * @method Animation3D * @constructor diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index 1bb76c58a2..626f1990b7 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -4903,6 +4903,32 @@ getElapsed : function ( */ cc.Sequence = { +/** + * @method init + * @param {Array} arg0 + * @return {bool} + */ +init : function ( +array +) +{ + return false; +}, + +/** + * @method initWithTwoActions + * @param {cc.FiniteTimeAction} arg0 + * @param {cc.FiniteTimeAction} arg1 + * @return {bool} + */ +initWithTwoActions : function ( +finitetimeaction, +finitetimeaction +) +{ + return false; +}, + /** * @method Sequence * @constructor @@ -5043,6 +5069,32 @@ RepeatForever : function ( */ cc.Spawn = { +/** + * @method init + * @param {Array} arg0 + * @return {bool} + */ +init : function ( +array +) +{ + return false; +}, + +/** + * @method initWithTwoActions + * @param {cc.FiniteTimeAction} arg0 + * @param {cc.FiniteTimeAction} arg1 + * @return {bool} + */ +initWithTwoActions : function ( +finitetimeaction, +finitetimeaction +) +{ + return false; +}, + /** * @method Spawn * @constructor diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp index b220ac88be..e429e644be 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp @@ -115,38 +115,6 @@ bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getDuration : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, args.get(0), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); - - auto ret = cocos2d::Animation3D::create(arg0); - js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - return true; - } - if (argc == 2) { - std::string arg0; - std::string arg1; - ok &= jsval_to_std_string(cx, args.get(0), &arg0); - ok &= jsval_to_std_string(cx, args.get(1), &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); - - auto ret = cocos2d::Animation3D::create(arg0, arg1); - js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - return true; - } - JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); - return false; -} - bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -190,10 +158,7 @@ void js_register_cocos2dx_3d_Animation3D(JSContext *cx, JS::HandleObject global) JS_FS_END }; - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_3d_Animation3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; + JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_Animation3D_prototype = JS_InitClass( cx, global, diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp index 49a39b5fa2..07ee9c6107 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp @@ -16,7 +16,6 @@ bool js_cocos2dx_3d_Animation3D_initWithFile(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_3d_Animation3D_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getBoneCurveByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_Animation3D(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Animate3D_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index 6c15a2224e..d8b66fe53e 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -7635,7 +7635,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) auto ret = cocos2d::Director::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -12214,6 +12214,68 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Sequence_class; JSObject *jsb_cocos2d_Sequence_prototype; +bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vector arg0; + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Sequence_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Invalid Native Object"); + if (argc == 2) { + cocos2d::FiniteTimeAction* arg0 = nullptr; + cocos2d::FiniteTimeAction* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Error processing arguments"); + bool ret = cobj->initWithTwoActions(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Sequence_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12266,6 +12328,8 @@ void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_Sequence_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTwoActions", js_cocos2dx_Sequence_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Sequence_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -12678,6 +12742,68 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Spawn_class; JSObject *jsb_cocos2d_Spawn_prototype; +bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vector arg0; + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Spawn_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Invalid Native Object"); + if (argc == 2) { + cocos2d::FiniteTimeAction* arg0 = nullptr; + cocos2d::FiniteTimeAction* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Error processing arguments"); + bool ret = cobj->initWithTwoActions(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Spawn_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12730,6 +12856,8 @@ void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_Spawn_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTwoActions", js_cocos2dx_Spawn_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Spawn_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -16726,7 +16854,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval * auto ret = cocos2d::Configuration::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -55950,7 +56078,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::GLProgramCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -58157,7 +58285,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::AnimationCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -59307,7 +59435,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva auto ret = cocos2d::SpriteFrameCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index 0055f1c107..fb22303582 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -648,6 +648,8 @@ bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Sequence_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sequence_Sequence(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Repeat_class; @@ -683,6 +685,8 @@ bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Spawn_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Spawn_Spawn(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_RotateTo_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp index 660f580f1a..3a425d1161 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -698,7 +698,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc auto ret = cocostudio::ActionManagerEx::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -5172,7 +5172,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t auto ret = cocostudio::ArmatureDataManager::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp index 0929d7f396..72e6fd78a9 100644 --- a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp +++ b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp @@ -64,8 +64,8 @@ static bool js_cocos2dx_Sprite3D_createAsync(JSContext *cx, uint32_t argc, jsval auto lambda = [=](Sprite3D* larg0, void* larg1) -> void{ jsval largv[2]; - js_proxy_t* proxy = js_get_or_create_proxy(cx, larg0); - largv[0] = proxy ? OBJECT_TO_JSVAL(proxy->obj) : JS::UndefinedValue(); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, larg0)); JSB_HeapValueWrapper* v = (JSB_HeapValueWrapper*)larg1; largv[1] = v->get(); @@ -280,8 +280,7 @@ bool js_cocos2dx_Terrain_create(JSContext *cx, uint32_t argc, jsval *vp) ret = Terrain::create(arg0, arg1); } - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (Terrain*)ret); - args.rval().set(OBJECT_TO_JSVAL(jsProxy->obj)); + args.rval().set(OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret))); return true; } JS_ReportError(cx, "wrong number of arguments"); @@ -342,6 +341,42 @@ bool js_cocos2dx_Terrain_getHeightData(JSContext *cx, uint32_t argc, jsval *vp) return false; } +// this code cannot be automated since it must use +// get_or_create_jsobject instead of create_jsobject +// since Animation3D::create() might return an existing copy +// since it caches them +bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + + auto ret = cocos2d::Animation3D::create(arg0); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); + return true; + } + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + + auto ret = cocos2d::Animation3D::create(arg0, arg1); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); + return false; +} + void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global) { JS::RootedValue tmpVal(cx); @@ -357,6 +392,10 @@ void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global) tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_Terrain_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_GetProperty(cx, ccObj, "Animation3D", &tmpVal); + tmpObj.set(tmpVal.toObjectOrNull()); + JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_3d_Animation3D_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); + JS_GetProperty(cx, ccObj, "Bundle3D", &tmpVal); tmpObj.set(tmpVal.toObjectOrNull()); JS_DefineFunction(cx, tmpObj, "getTrianglesList", js_cocos2dx_Bundle3D_getTrianglesList, 1, JSPROP_READONLY | JSPROP_PERMANENT); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 6a0acc472c..9c1157028d 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -2018,16 +2018,6 @@ JSObject* jsb_ref_autoreleased_create_jsobject(JSContext *cx, cocos2d::Ref *ref, return js_obj; } -JSObject* jsb_ref_singleton_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) -{ - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parent(cx, typeClass->parentProto.ref()); - JS::RootedObject js_obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); - js_proxy_t* newproxy = jsb_new_proxy(ref, js_obj); - jsb_ref_singleton_init(cx, &newproxy->obj, ref, debug); - return js_obj; -} - // get_or_create JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) { @@ -2038,13 +2028,14 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty return jsb_ref_create_jsobject(cx, ref, typeClass, debug); } -JSObject* jsb_ref_singleton_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) +// get_or_create: REf is already autoreleased (or created) +JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) { auto proxy = jsb_get_native_proxy(ref); if (proxy) return proxy->obj; // else - return jsb_ref_singleton_create_jsobject(cx, ref, typeClass, debug); + return jsb_ref_autoreleased_create_jsobject(cx, ref, typeClass, debug); } // ref_init @@ -2071,34 +2062,22 @@ void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap *obj, Ref* ref (void)obj; ref->_scriptOwned = true; // retain it, since the object is autoreleased - ret->retain(); + ref->retain(); #else // don't autorelease it, since it is already autoreleased JS::AddNamedObjectRoot(cx, obj, debug); #endif } -void jsb_ref_singleton_init(JSContext* cx, JS::Heap *obj, Ref* ref, const char* debug) -{ - // CCLOG("jsb_ref_singleton_init: JSObject address = %p. %s", obj->get(), debug); -#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS - (void)cx; - (void)obj; - ref->_scriptOwned = true; - // don't retain it: it is a singleton -#else - // don't autorelease it: it is a singleton - JS::AddNamedObjectRoot(cx, obj, debug); -#endif -} - // finalize void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) { #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS js_proxy_t* nproxy; js_proxy_t* jsproxy; - jsproxy = jsb_get_js_proxy(obj); + + JS::RootedObject jsobj(ScriptingCore::getInstance()->getGlobalContext(), obj); + jsproxy = jsb_get_js_proxy(jsobj); if (jsproxy) { auto ref = static_cast(jsproxy->ptr); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index e5f8587ad6..259ba5962d 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -565,12 +565,6 @@ void jsb_ref_init(JSContext* cx, JS::Heap *obj, cocos2d::Ref* ref, co */ void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap *obj, cocos2d::Ref* ref, const char* debug); -/** - * Generic initialization function for Singletons - * Similar to jsb_ref_init(), but call it to initialize singletons - */ -void jsb_ref_singleton_init(JSContext* cx, JS::Heap *obj, cocos2d::Ref* ref, const char* debug); - /** * Generic finalize used by objects that are subclass of Ref */ @@ -595,12 +589,6 @@ JSObject* jsb_ref_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_clas */ JSObject* jsb_ref_autoreleased_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); -/** - * Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Singleton (ref) - * Similar to jsb_ref_create_jsobject(), but call it if you know that Ref is a Singleton - */ -JSObject* jsb_ref_singleton_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); - /** It will try to get the associated JSObjct for ref. If it can't find it, it will create a new one associating it to Ref @@ -611,7 +599,8 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty It will try to get the associated JSObjct for ref. If it can't find it, it will create a new one associating it to Ref */ -JSObject* jsb_ref_singleton_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); +JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); + void removeJSObject(JSContext* cx, void* nativeObj); diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index 836aadaebe..b4489b1fa8 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -203,10 +203,9 @@ bool js_cocos2dx_EventTouch_getTouches(JSContext *cx, uint32_t argc, jsval *vp) JS::RootedValue arrElement(cx); //First, check whether object is associated with js object. - js_proxy_t* jsproxy = js_get_or_create_proxy(cx, touchObj); - if (jsproxy) { - arrElement = OBJECT_TO_JSVAL(jsproxy->obj); - } + auto jsobj = js_get_or_create_jsobject(cx, touchObj); + if (jsobj) + arrElement = OBJECT_TO_JSVAL(jsobj); if (!JS_SetElement(cx, jsretArr, i, arrElement)) { break; } @@ -4558,8 +4557,7 @@ bool js_PlistParser_getInstance(JSContext *cx, unsigned argc, JS::Value *vp) jsret = OBJECT_TO_JSVAL(p->obj); } else { // create a new js obj of that class - js_proxy_t *proxy = js_get_or_create_proxy(cx, parser); - jsret = OBJECT_TO_JSVAL(proxy->obj); + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, parser)); } } else { jsret = JSVAL_NULL; @@ -4878,8 +4876,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v jsval largv[2]; do { if (larg0) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::RenderTexture*)larg0); - largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::RenderTexture*)larg0)); } else { largv[0] = JSVAL_NULL; } @@ -4949,8 +4947,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v jsval largv[2]; do { if (larg0) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::RenderTexture*)larg0); - largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::RenderTexture*)larg0)); } else { largv[0] = JSVAL_NULL; } @@ -5314,17 +5312,10 @@ bool js_cocos2dx_Scene_getPhysics3DWorld(JSContext *cx, uint32_t argc, jsval *vp { cocos2d::Physics3DWorld* ret = cobj->getPhysics3DWorld(); jsval jsret = JSVAL_NULL; - do - { - if (ret) - { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::Physics3DWorld*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else - { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::Physics3DWorld*)ret)); + else + jsret = JSVAL_NULL; args.rval().set(jsret); return true; } @@ -5400,15 +5391,10 @@ bool js_cocos2dx_Scene_getNavMesh(JSContext *cx, uint32_t argc, jsval *vp) if (argc == 0) { cocos2d::NavMesh* ret = cobj->getNavMesh(); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, (cocos2d::NavMesh*)ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } - else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::NavMesh*)ret)); + else + jsret = JSVAL_NULL; args.rval().set(jsret); return true; } @@ -5657,14 +5643,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } @@ -5676,14 +5659,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } @@ -5697,14 +5677,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } @@ -5720,14 +5697,11 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3)); jsval jsret = JSVAL_NULL; - do { - if (ret) { - js_proxy_t *jsProxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(jsProxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); + } else { + jsret = JSVAL_NULL; + } args.rval().set(jsret); return true; } diff --git a/cocos/scripting/js-bindings/script/jsb_create_apis.js b/cocos/scripting/js-bindings/script/jsb_create_apis.js index 5fe8be19c2..b3f24c3eb8 100644 --- a/cocos/scripting/js-bindings/script/jsb_create_apis.js +++ b/cocos/scripting/js-bindings/script/jsb_create_apis.js @@ -563,19 +563,13 @@ cc.ActionInterval.prototype._ctor = function(d) { }; cc.Sequence.prototype._ctor = function(tempArray) { - var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + var paramArray = (tempArray instanceof Array) ? tempArray : Array.prototype.slice.call(arguments); var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.log("parameters should not be ending with null in Javascript"); if (last >= 0) { - var prev = paramArray[0]; - for (var i = 1; i < last; i++) { - if (paramArray[i]) { - prev = cc.Sequence.create(prev, paramArray[i]); - } - } - this.initWithTwoActions(prev, paramArray[last]); + this.init(paramArray); } }; @@ -588,19 +582,13 @@ cc.RepeatForever.prototype._ctor = function(action) { }; cc.Spawn.prototype._ctor = function(tempArray) { - var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + var paramArray = (tempArray instanceof Array) ? tempArray : Array.prototype.slice.call(arguments); var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.log("parameters should not be ending with null in Javascript"); if (last >= 0) { - var prev = paramArray[0]; - for (var i = 1; i < last; i++) { - if (paramArray[i]) { - prev = cc.Spawn.create(prev, paramArray[i]); - } - } - this.initWithTwoActions(prev, paramArray[last]); + this.init(paramArray); } }; @@ -1208,4 +1196,4 @@ cc.Menu.create = function(menuItems) { return cc.Menu._create.apply(null, items); }; -cc.TMXLayer.prototype.tileFlagsAt = cc.TMXLayer.prototype.getTileFlagsAt; \ No newline at end of file +cc.TMXLayer.prototype.tileFlagsAt = cc.TMXLayer.prototype.getTileFlagsAt; diff --git a/tools/bindings-generator b/tools/bindings-generator index b940871c1d..522eff18a6 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit b940871c1dfff94c0220364539dd9d0583995719 +Subproject commit 522eff18a6c87ee8473d0d9cd05959e374a6d602 diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index fb01f08d91..411003cd71 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -87,8 +87,8 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat Range::[*], NotificationObserver::[*], Image::[initWithString initWithImageData], - Sequence::[create init], - Spawn::[create init], + Sequence::[create], + Spawn::[create], RotateTo::[calculateAngles], GLProgram::[getProgram setUniformLocationWith(1|2|3|4)fv setUniformLocationWith(2|3|4)iv setUniformLocationWithMatrix(2|3|4)fv], GLProgramState::[setUniformVec4 setVertexAttribPointer], diff --git a/tools/tojs/cocos2dx_3d.ini b/tools/tojs/cocos2dx_3d.ini index da874c86c8..a39fbc4829 100644 --- a/tools/tojs/cocos2dx_3d.ini +++ b/tools/tojs/cocos2dx_3d.ini @@ -43,7 +43,7 @@ skip = Skeleton3D::[create], Sprite3D::[getAABB getMeshArrayByName createAsync], Mesh::[create getMeshCommand getAABB getDefaultGLProgram getMeshVertexAttribute draw setTexture getTexture], Sprite3DCache::[addSprite3DData getSpriteData], - Animation3D::[getBoneCurves], + Animation3D::[create getBoneCurves], Animate3D::[getKeyFrameUserInfo], TextureCube::[setTexParameters], Terrain::[getAABB getQuadTree create getHeightData], From c034303ad8f37ca01b1694e4a03e87191d1f7352 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 10 Dec 2015 18:22:10 -0800 Subject: [PATCH 04/28] Adds MemoryModelTest --- tests/js-tests/project.json | 1 + .../src/MemoryModelTest/MemoryModelTest.js | 234 ++++++++++++++++++ tests/js-tests/src/tests-main.js | 9 + 3 files changed, 244 insertions(+) create mode 100644 tests/js-tests/src/MemoryModelTest/MemoryModelTest.js diff --git a/tests/js-tests/project.json b/tests/js-tests/project.json index 33dec07096..e93a597ba4 100644 --- a/tests/js-tests/project.json +++ b/tests/js-tests/project.json @@ -33,6 +33,7 @@ "src/TouchesTest/TouchesTest.js", "src/SchedulerTest/SchedulerTest.js", "src/MenuTest/MenuTest.js", + "src/MemoryModelTest/MemoryModelTest.js", "src/ActionsTest/ActionsTest.js", "src/TileMapTest/TileMapTest.js", "src/TransitionsTest/TransitionsTest.js", diff --git a/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js b/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js new file mode 100644 index 0000000000..a0973d8318 --- /dev/null +++ b/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js @@ -0,0 +1,234 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +var memoryModelTestSceneIdx = -1; + +//------------------------------------------------------------------ +// +// MemoryModelTestBase +// +//------------------------------------------------------------------ +var MemoryModelTestBase = BaseTestLayer.extend({ + _title:"", + _subtitle:"", + + onRestartCallback:function (sender) { + var s = new MemoryModelTestScene(); + s.addChild(restartMemoryModelTest()); + director.runScene(s); + }, + onNextCallback:function (sender) { + var s = new MemoryModelTestScene(); + s.addChild(nextMemoryModelTest()); + director.runScene(s); + }, + onBackCallback:function (sender) { + var s = new MemoryModelTestScene(); + s.addChild(previousMemoryModelTest()); + director.runScene(s); + }, + + // automation + numberOfPendingTests:function() { + return ( (arrayOfMemoryModelTest.length-1) - memoryModelTestSceneIdx ); + }, + + getTestNumber:function() { + return memoryModelTestSceneIdx; + } + +}); + +//------------------------------------------------------------------ +// +// Set property on sprite +// +//------------------------------------------------------------------ +var SetPropertyMemoryModelTest = MemoryModelTestBase.extend({ + _title:"Set Property Test", + _subtitle:"See console for possible errors", + + ctor:function () { + this._super(); + var sprite = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + var tag = 10; + this.addChild(sprite, 0, tag); + var x = winSize.width / 2; + var y = winSize.height / 2; + sprite.setPosition(x, y); + + // add random property + sprite.randomProperty = "hello world"; + + sprite = this.getChildByTag(tag); + + // should print "hello world" + this.log(sprite.randomProperty); + }, +}); + +//------------------------------------------------------------------ +// +// Using Ivar 1: from ctor to onEnter +// +//------------------------------------------------------------------ +var Ivar1MemoryModelTest = MemoryModelTestBase.extend({ + _title:"Using ivars to hold C++ objects", + _subtitle:"From ctor to onEnter", + + ctor:function () { + this._super(); + this.sprite = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + }, + onEnter:function() { + this._super(); + this.addChild(this.sprite); + var x = winSize.width / 2; + var y = winSize.height / 2; + this.sprite.setPosition(x, y); + }, +}); + +//------------------------------------------------------------------ +// +// Using Ivar 2: from ctor to update +// +//------------------------------------------------------------------ +var Ivar2MemoryModelTest = MemoryModelTestBase.extend({ + _title:"Using ivars to hold C++ objects", + _subtitle:"From ctor to update", + + ctor:function () { + this._super(); + this.sprite = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + this.scheduleOnce(this.showSprite, 0.5); + }, + showSprite:function() { + this.addChild(this.sprite); + var x = winSize.width / 2; + var y = winSize.height / 2; + this.sprite.setPosition(x, y); + }, +}); + +var MemoryModelTestScene = TestScene.extend({ + runThisTest:function (num) { + memoryModelTestSceneIdx = (num || num == 0) ? (num - 1) : -1; + var layer = nextMemoryModelTest(); + this.addChild(layer); + + director.runScene(this); + } +}); + +//------------------------------------------------------------------ +// +// Using Local vars +// +//------------------------------------------------------------------ +var LocalVarMemoryModelTest = MemoryModelTestBase.extend({ + _title:"Using local vars + GC", + _subtitle:"native objects should get destroyed", + + ctor:function () { + this._super(); + var sprite1 = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + var sprite2 = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + var sprite3 = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + var a = 10; + //cc.sys.dumpRoot(); + cc.sys.garbageCollect(); + cc.log(sprite1); + cc.log(sprite2); + cc.log(sprite3); + cc.log(a); + }, +}); + +//------------------------------------------------------------------ +// +// Using Local vars +// +//------------------------------------------------------------------ +var RetainRootsMemoryModelTest = MemoryModelTestBase.extend({ + _title:"retain must root", + _subtitle:"native objects should not get destroyed", + + ctor:function () { + this._super(); + var sprite = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + // addChild should root the sprite + this.addChild(sprite); + cc.sys.garbageCollect(); + + var x = winSize.width / 2; + var y = winSize.height / 2; + sprite.setPosition(x, y); + }, +}); + + +// +// Entry point +// +var MemoryModelTestScene = TestScene.extend({ + runThisTest:function (num) { + memoryModelTestSceneIdx = (num || num == 0) ? (num - 1) : -1; + var layer = nextMemoryModelTest(); + this.addChild(layer); + + director.runScene(this); + } +}); + + +// +// Flow control +// + +var arrayOfMemoryModelTest = [ + SetPropertyMemoryModelTest, + Ivar1MemoryModelTest, + Ivar2MemoryModelTest, + LocalVarMemoryModelTest, + RetainRootsMemoryModelTest, +]; + +var nextMemoryModelTest = function () { + memoryModelTestSceneIdx++; + memoryModelTestSceneIdx = memoryModelTestSceneIdx % arrayOfMemoryModelTest.length; + + return new arrayOfMemoryModelTest[memoryModelTestSceneIdx](); +}; +var previousMemoryModelTest = function () { + memoryModelTestSceneIdx--; + if (memoryModelTestSceneIdx < 0) + memoryModelTestSceneIdx += arrayOfMemoryModelTest.length; + + return new arrayOfMemoryModelTest[memoryModelTestSceneIdx](); +}; +var restartMemoryModelTest = function () { + return new arrayOfMemoryModelTest[memoryModelTestSceneIdx](); +}; + diff --git a/tests/js-tests/src/tests-main.js b/tests/js-tests/src/tests-main.js index ef40036ae2..19a13434c8 100644 --- a/tests/js-tests/src/tests-main.js +++ b/tests/js-tests/src/tests-main.js @@ -479,6 +479,15 @@ var testNames = [ return new MaterialSystemTestScene(); } }, + { + title:"Memory Model Test", + resource:g_menu, + platforms: PLATFORM_JSB, + linksrc:"src/MemoryModelTest/MemoryModelTest.js", + testScene:function () { + return new MemoryModelTestScene(); + } + }, { title:"Menu Test", resource:g_menu, From f877f26bd22abeb131c7949e26cbf03656e102e9 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 11 Dec 2015 11:56:58 +0800 Subject: [PATCH 05/28] update for controlButton --- .../CCControlExtension/CCControlButton.cpp | 22 +++++++++---------- .../GUI/CCControlExtension/CCControlButton.h | 8 +++---- .../CCControlButtonTest.cpp | 9 ++++---- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCControlButton.cpp b/extensions/GUI/CCControlExtension/CCControlButton.cpp index 9a69de517e..94035a91a4 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -63,10 +63,10 @@ ControlButton::~ControlButton() bool ControlButton::init() { - return this->initWithLabelAndBackgroundSprite(Label::createWithSystemFont("", "Helvetica", 12), cocos2d::ui::Scale9Sprite::create()); + return this->initWithLabelAndBackgroundSprite(Label::createWithSystemFont("", "Helvetica", 12), cocos2d::ui::Scale9Sprite::create(),true); } -bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprite* backgroundSprite) +bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize) { if (Control::init()) { @@ -79,9 +79,9 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprit _isPushed = false; - // Adjust the background image by default - setAdjustBackgroundImage(true); + // Adjust the background image by adjustBackGroundSize setPreferredSize(Size::ZERO); + setAdjustBackgroundImage(adjustBackGroundSize); // Zooming button by default _zoomOnTouchDown = true; _scaleRatio = 1.1f; @@ -120,17 +120,17 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprit } } -ControlButton* ControlButton::create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite) +ControlButton* ControlButton::create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize) { ControlButton *pRet = new (std::nothrow) ControlButton(); - pRet->initWithLabelAndBackgroundSprite(label, backgroundSprite); + pRet->initWithLabelAndBackgroundSprite(label, backgroundSprite, adjustBackGroundSize); pRet->autorelease(); return pRet; } bool ControlButton::initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize) { - return initWithLabelAndBackgroundSprite(Label::createWithSystemFont(title, fontName, fontSize), cocos2d::ui::Scale9Sprite::create()); + return initWithLabelAndBackgroundSprite(Label::createWithSystemFont(title, fontName, fontSize), cocos2d::ui::Scale9Sprite::create(),true); } ControlButton* ControlButton::create(const std::string& title, const std::string& fontName, float fontSize) @@ -141,16 +141,16 @@ ControlButton* ControlButton::create(const std::string& title, const std::string return pRet; } -bool ControlButton::initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite) +bool ControlButton::initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize) { Label *label = Label::createWithSystemFont("", "Arial", 30);// - return initWithLabelAndBackgroundSprite(label, sprite); + return initWithLabelAndBackgroundSprite(label, sprite,adjustBackGroundSize); } -ControlButton* ControlButton::create(cocos2d::ui::Scale9Sprite* sprite) +ControlButton* ControlButton::create(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize) { ControlButton *pRet = new (std::nothrow) ControlButton(); - pRet->initWithBackgroundSprite(sprite); + pRet->initWithBackgroundSprite(sprite,adjustBackGroundSize); pRet->autorelease(); return pRet; } diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 302b8c8ec9..279ccce292 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -55,8 +55,8 @@ class CC_EX_DLL ControlButton : public Control { public: static ControlButton* create(); - static ControlButton* create(cocos2d::ui::Scale9Sprite* sprite); - static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite); + static ControlButton* create(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize = true); + static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize = true); static ControlButton* create(const std::string& title, const std::string& fontName, float fontSize); virtual void needsLayout(void) override; @@ -202,8 +202,8 @@ CC_CONSTRUCTOR_ACCESS: virtual ~ControlButton(); virtual bool init() override; - virtual bool initWithLabelAndBackgroundSprite(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite); - virtual bool initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite); + virtual bool initWithLabelAndBackgroundSprite(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize); + virtual bool initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize); virtual bool initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize); protected: diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp index dbe92feb24..e5b50557dd 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp @@ -277,16 +277,15 @@ ControlButton *ControlButtonTest_Styling::standardButtonWithTitle(const char *ti { /** Creates and return a button with a default background and title color. */ auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png"); + backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png"); - + backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size + auto titleButton = Label::createWithTTF(title, "fonts/Marker Felt.ttf", 30); titleButton->setColor(Color3B(159, 168, 176)); - ControlButton *button = ControlButton::create(titleButton, backgroundButton); - backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size - backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size - + ControlButton *button = ControlButton::create(titleButton, backgroundButton,false); button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED); button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED); From a9f404c200352dd4c5aa8afac29c0cc791219f39 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Fri, 11 Dec 2015 13:56:29 +0800 Subject: [PATCH 06/28] Update CHANGELOG --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5046e3c79b..725848627c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ cocos2d-x-3.10 December ? 2015 [NEW] Core: Added Application::getVersion() to get the app version. [NEW] UI: Add PageView indicator. [NEW] Label: Add three Overflow type to new label, see release note for more information. +[NEW] UI: UIText::clone supports clone the text effect. +[NEW] Label: Add methods to query label effect state. [REFINE] UI: RichText support new line element. [REFINE] UI: Set focus to Widget when touched. From 8b2dfb1a4bc47945f10c3eb25122f384ed71de0a Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 10 Dec 2015 22:15:44 -0800 Subject: [PATCH 07/28] Mooooores fixes but GC memory model doesn't work yet... somewhere someone is still retaining a reference that prevents the whole thing from releasing --- .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 10 +- .../auto/jsb_cocos2dx_studio_auto.cpp | 4 +- .../js-bindings/manual/ScriptingCore.cpp | 161 ++++++++---------- .../js-bindings/manual/ScriptingCore.h | 4 +- .../js-bindings/manual/cocos2d_specifics.cpp | 22 +-- .../js-bindings/manual/cocos2d_specifics.hpp | 7 +- .../manual/js_manual_conversions.cpp | 14 +- .../src/MemoryModelTest/MemoryModelTest.js | 22 +++ tools/bindings-generator | 2 +- 9 files changed, 123 insertions(+), 123 deletions(-) diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index d8b66fe53e..12771ed9b7 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -7635,7 +7635,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) auto ret = cocos2d::Director::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -16854,7 +16854,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval * auto ret = cocos2d::Configuration::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -56078,7 +56078,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::GLProgramCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -58285,7 +58285,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::AnimationCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -59435,7 +59435,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva auto ret = cocos2d::SpriteFrameCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp index 3a425d1161..f26ef41787 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -698,7 +698,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc auto ret = cocostudio::ActionManagerEx::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -5172,7 +5172,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t auto ret = cocostudio::ArmatureDataManager::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 9c1157028d..19354fa161 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -430,8 +430,9 @@ void registerDefaultClasses(JSContext* cx, JS::HandleObject global) { JS_DefineFunction(cx, global, "__isObjectValid", ScriptingCore::isObjectValid, 1, JSPROP_READONLY | JSPROP_PERMANENT); } -static void sc_finalize(JSFreeOp *freeOp, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (global class)", obj); +static void sc_finalize(JSFreeOp *freeOp, JSObject *obj) +{ + CCLOG("jsbindings: finalizing JS object %p (global class)", obj); } //static JSClass global_class = { @@ -1181,10 +1182,17 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve // AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray"); int count = 0; - + + js_type_class_t *typeClassEvent = nullptr; + js_type_class_t *typeClassTouch = nullptr; + + if (touches.size()>0) + typeClassTouch = js_get_type_from_native(touches[0]); + typeClassEvent = js_get_type_from_native(event); + for (const auto& touch : touches) { - JS::RootedValue jsret(_cx, OBJECT_TO_JSVAL(js_get_or_create_jsobject(this->_cx, touch))); + JS::RootedValue jsret(_cx, OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, touch, typeClassTouch, "cocos2d::Touch"))); if (!JS_SetElement(this->_cx, jsretArr, count, jsret)) { break; @@ -1192,19 +1200,14 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve ++count; } - do + js_proxy_t* p = jsb_get_native_proxy(nativeObj); + if (p) { - js_proxy_t * p = jsb_get_native_proxy(nativeObj); - if (!p) break; - jsval dataVal[2]; dataVal[0] = OBJECT_TO_JSVAL(jsretArr); - dataVal[1] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, event)); - + dataVal[1] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClassEvent, "cocos2d::Event")); ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet); - - - } while(false); + } // JS_RemoveObjectRoot(this->_cx, &jsretArr); @@ -1231,37 +1234,18 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event std::string funcName = getTouchFuncName(eventCode); bool ret = false; - do + js_proxy_t * p = jsb_get_native_proxy(nativeObj); + if (p) { - js_proxy_t * p = jsb_get_native_proxy(nativeObj); - if (!p) break; - + js_type_class_t *typeClassTouch = js_get_type_from_native(touch); + js_type_class_t *typeClassEvent = js_get_type_from_native(event); + jsval dataVal[2]; - dataVal[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, touch)); - dataVal[1] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, event)); - -// if (jsvalRet != nullptr) -// { - ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet); -// } -// else -// { -// JS::RootedValue retval(_cx); -// executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, &retval); -// if(retval.isNull()) -// { -// ret = false; -// } -// else if(retval.isBoolean()) -// { -// ret = retval.toBoolean(); -// } -// else -// { -// ret = false; -// } -// } - } while(false); + dataVal[0] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, touch, typeClassTouch, "cocos2d::Touch")); + dataVal[1] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClassEvent, "cocos2d::Event")); + + ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet); + } removeJSObject(_cx, touch); removeJSObject(_cx, event); @@ -1282,37 +1266,15 @@ bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::Mouse std::string funcName = getMouseFuncName(eventType); bool ret = false; - do + js_proxy_t * p = jsb_get_native_proxy(nativeObj); + if (p) { - js_proxy_t * p = jsb_get_native_proxy(nativeObj); - if (!p) break; - jsval dataVal[1]; - dataVal[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, event)); - -// if (jsvalRet != nullptr) -// { - ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, jsvalRet); -// } -// else -// { -// JS::RootedValue retval(_cx); -// executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, &retval); -// if(retval.isNull()) -// { -// ret = false; -// } -// else if(retval.isBoolean()) -// { -// ret = retval.toBoolean(); -// } -// else -// { -// ret = false; -// } -// } - } while(false); - + js_type_class_t *typeClass = js_get_type_from_native(event); + dataVal[0] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClass, "cocos2d::Event")); + ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, jsvalRet); + } + removeJSObject(_cx, event); return ret; @@ -1396,10 +1358,11 @@ bool ScriptingCore::handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard:: return false; bool ret = false; - + + js_type_class_t *typeClass = js_get_type_from_native(event); jsval args[2] = { int32_to_jsval(_cx, (int32_t)keyCode), - OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, event)) + OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClass, "cocos2d::Event")) }; if (isPressed) @@ -1425,9 +1388,11 @@ bool ScriptingCore::handleFocusEvent(void* nativeObj, cocos2d::ui::Widget* widge if (nullptr == p) return false; + js_type_class_t *typeClass = js_get_type_from_native(widgetLoseFocus); + jsval args[2] = { - OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, widgetLoseFocus)), - OBJECT_TO_JSVAL(js_get_or_create_jsobject(_cx, widgetGetFocus)) + OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, widgetLoseFocus, typeClass, "cocos2d::ui::Widget")), + OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, widgetGetFocus, typeClass, "cocos2d::ui::Widget")) }; bool ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onFocusChanged", 2, args); @@ -1446,7 +1411,9 @@ int ScriptingCore::executeCustomTouchesEvent(EventTouch::EventCode eventType, int count = 0; for (auto& touch : touches) { - jsval jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(this->_cx, touch)); + js_type_class_t *typeClass = js_get_type_from_native(touch); + + jsval jsret = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch")); JS::RootedValue jsval(_cx, jsret); if (!JS_SetElement(this->_cx, jsretArr, count, jsval)) { break; @@ -1467,20 +1434,20 @@ int ScriptingCore::executeCustomTouchesEvent(EventTouch::EventCode eventType, } -int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, - Touch *pTouch, JSObject *obj) +int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, Touch *touch, JSObject *obj) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS::RootedValue retval(_cx); std::string funcName = getTouchFuncName(eventType); - jsval jsTouch = OBJECT_TO_JSVAL(js_get_or_create_jsobject(this->_cx, pTouch)); + js_type_class_t *typeClass = js_get_type_from_native(touch); + jsval jsTouch = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch")); executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, &retval); // Remove touch object from global hash table and unroot it. - removeJSObject(this->_cx, pTouch); + removeJSObject(this->_cx, touch); return 1; @@ -1488,19 +1455,20 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, - Touch *pTouch, JSObject *obj, + Touch *touch, JSObject *obj, JS::MutableHandleValue retval) { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET std::string funcName = getTouchFuncName(eventType); - jsval jsTouch = OBJECT_TO_JSVAL(js_get_or_create_jsobject(this->_cx, pTouch)); + js_type_class_t *typeClass = js_get_type_from_native(touch); + jsval jsTouch = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch")); executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, retval); // Remove touch object from global hash table and unroot it. - removeJSObject(this->_cx, pTouch); + removeJSObject(this->_cx, touch); return 1; @@ -1611,6 +1579,7 @@ void ScriptingCore::unrootObject(Ref* ref) js_proxy_t* nproxy; js_proxy_t* jsproxy; void *ptr = (void*)ref; + nproxy = jsb_get_native_proxy(ptr); if (nproxy) { JSContext *cx = getGlobalContext(); @@ -1621,7 +1590,7 @@ void ScriptingCore::unrootObject(Ref* ref) jsproxy = jsb_get_js_proxy(handle); RemoveObjectRoot(cx, &jsproxy->obj); - CCLOG("Unrooting %p - %p: %s", ref, &jsproxy->obj, typeid(*ref).name()); + CCLOG("Unrooting #2 %p - %p: %s", ref, &jsproxy->obj, typeid(*ref).name()); } } @@ -2024,8 +1993,22 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty auto proxy = jsb_get_native_proxy(ref); if (proxy) return proxy->obj; - // else - return jsb_ref_create_jsobject(cx, ref, typeClass, debug); + + // don't auto-release, don't retain. + JS::RootedObject proto(cx, typeClass->proto.ref()); + JS::RootedObject parent(cx, typeClass->parentProto.ref()); + JS::RootedObject js_obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); + js_proxy_t* newproxy = jsb_new_proxy(ref, js_obj); +#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS + CC_UNUSED_PARAM(newproxy); + // don't retain it. + ref->_scriptOwned = true; +#else + // don't autorelease it + JS::AddNamedObjectRoot(cx, &newproxy->obj, debug); +#endif + + return js_obj; } // get_or_create: REf is already autoreleased (or created) @@ -2076,7 +2059,9 @@ void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) js_proxy_t* nproxy; js_proxy_t* jsproxy; - JS::RootedObject jsobj(ScriptingCore::getInstance()->getGlobalContext(), obj); + CCLOG("jsb_ref_finalize #1: JSObject address = %p", obj); + + JS::RootedObject jsobj(fop->runtime(), obj); jsproxy = jsb_get_js_proxy(jsobj); if (jsproxy) { @@ -2085,7 +2070,7 @@ void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) if (ref) { - CCLOG("jsb_ref_finalize: JSObject address = %p (%s)", obj, typeid(*ref).name()); + CCLOG("jsb_ref_finalize #2: JSObject address = %p (%s)", obj, typeid(*ref).name()); jsb_remove_proxy(nproxy, jsproxy); ref->release(); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index 259ba5962d..b9ac8b295c 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -591,13 +591,15 @@ JSObject* jsb_ref_autoreleased_create_jsobject(JSContext *cx, cocos2d::Ref *ref, /** It will try to get the associated JSObjct for ref. - If it can't find it, it will create a new one associating it to Ref + If it can't find it, it will create a new one associating it to Ref. + Call this function for objects that were already created and initialized, when returning `getChild()` */ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); /** It will try to get the associated JSObjct for ref. If it can't find it, it will create a new one associating it to Ref + Call this function for objects that might return an already existing copy when you create them. For example, `Animation3D::create()`; */ JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug); diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index b4489b1fa8..0f4c728ab2 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -5313,9 +5313,10 @@ bool js_cocos2dx_Scene_getPhysics3DWorld(JSContext *cx, uint32_t argc, jsval *vp cocos2d::Physics3DWorld* ret = cobj->getPhysics3DWorld(); jsval jsret = JSVAL_NULL; if (ret) - jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::Physics3DWorld*)ret)); - else - jsret = JSVAL_NULL; + { + js_type_class_t *typeClass = js_get_type_from_native(ret); + jsret = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Physics3DWorld")); + } args.rval().set(jsret); return true; } @@ -5392,9 +5393,10 @@ bool js_cocos2dx_Scene_getNavMesh(JSContext *cx, uint32_t argc, jsval *vp) cocos2d::NavMesh* ret = cobj->getNavMesh(); jsval jsret = JSVAL_NULL; if (ret) - jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (cocos2d::NavMesh*)ret)); - else - jsret = JSVAL_NULL; + { + js_type_class_t *typeClass = js_get_type_from_native(ret); + jsret = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::NavMesh")); + } args.rval().set(jsret); return true; } @@ -5645,8 +5647,6 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); - } else { - jsret = JSVAL_NULL; } args.rval().set(jsret); return true; @@ -5661,8 +5661,6 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); - } else { - jsret = JSVAL_NULL; } args.rval().set(jsret); return true; @@ -5679,8 +5677,6 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); - } else { - jsret = JSVAL_NULL; } args.rval().set(jsret); return true; @@ -5699,8 +5695,6 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); - } else { - jsret = JSVAL_NULL; } args.rval().set(jsret); return true; diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp index e9eb1e91e0..1c6dc8ff2c 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp @@ -150,13 +150,8 @@ JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if::value,T>::type *native_obj) { - js_proxy_t *proxy = jsb_get_native_proxy(native_obj); - if (proxy) - return proxy->obj; - - // else js_type_class_t* typeClass = js_get_type_from_native(native_obj); - return jsb_ref_autoreleased_create_jsobject(cx, native_obj, typeClass, typeid(*native_obj).name()); + return jsb_ref_get_or_create_jsobject(cx, native_obj, typeClass, typeid(*native_obj).name()); } JS::Value anonEvaluate(JSContext *cx, JS::HandleObject thisObj, const char* string); diff --git a/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp b/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp index 95da599c43..9a41cf9eea 100644 --- a/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp +++ b/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp @@ -1761,9 +1761,10 @@ jsval ccarray_to_jsval(JSContext* cx, __Array *arr) JS::RootedValue arrElement(cx); //First, check whether object is associated with js object. - js_proxy_t* jsproxy = js_get_or_create_proxy(cx, obj); - if (jsproxy) { - arrElement = OBJECT_TO_JSVAL(jsproxy->obj); + js_type_class_t *typeClass = js_get_type_from_native(obj); + auto jsobj = jsb_ref_get_or_create_jsobject(cx, obj, typeClass, "cocos2d::Ref"); + if (jsobj) { + arrElement = OBJECT_TO_JSVAL(jsobj); } else { __String* strVal = NULL; @@ -1812,9 +1813,10 @@ jsval ccdictionary_to_jsval(JSContext* cx, __Dictionary* dict) JS::RootedValue dictElement(cx); Ref* obj = pElement->getObject(); //First, check whether object is associated with js object. - js_proxy_t* jsproxy = js_get_or_create_proxy(cx, obj); - if (jsproxy) { - dictElement = OBJECT_TO_JSVAL(jsproxy->obj); + js_type_class_t *typeClass = js_get_type_from_native(obj); + auto jsobj = jsb_ref_get_or_create_jsobject(cx, obj, typeClass, "cocos2d::Ref"); + if (jsobj) { + dictElement = OBJECT_TO_JSVAL(jsobj); } else { __String* strVal = NULL; diff --git a/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js b/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js index a0973d8318..a38d14f122 100644 --- a/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js +++ b/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js @@ -188,6 +188,27 @@ var RetainRootsMemoryModelTest = MemoryModelTestBase.extend({ }, }); +//------------------------------------------------------------------ +// +// Testing Root/Unroot +// +//------------------------------------------------------------------ +var RootUnrootMemoryModelTest = MemoryModelTestBase.extend({ + _title:"root/unroot", + _subtitle:"rooting/unrooting with GC memory model", + + ctor:function () { + this._super(); + var sprite = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); + // addChild should root the sprite + this.addChild(sprite); + + // should unroot the sprite + this.removeChild(sprite) + cc.sys.garbageCollect(); + }, +}); + // // Entry point @@ -213,6 +234,7 @@ var arrayOfMemoryModelTest = [ Ivar2MemoryModelTest, LocalVarMemoryModelTest, RetainRootsMemoryModelTest, + RootUnrootMemoryModelTest, ]; var nextMemoryModelTest = function () { diff --git a/tools/bindings-generator b/tools/bindings-generator index 522eff18a6..26b56a42b7 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 522eff18a6c87ee8473d0d9cd05959e374a6d602 +Subproject commit 26b56a42b7ea74ca7acb4003c7f98fe149741503 From fd321530e512d07e675ff9a1e9dd63defbaab1e9 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 11 Dec 2015 08:59:35 -0800 Subject: [PATCH 08/28] restores autobindings --- .../auto/api/jsb_cocos2dx_3d_auto_api.js | 14 ++ .../auto/api/jsb_cocos2dx_auto_api.js | 52 ------- .../js-bindings/auto/jsb_cocos2dx_3d_auto.cpp | 37 ++++- .../js-bindings/auto/jsb_cocos2dx_3d_auto.hpp | 1 + .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 138 +----------------- .../js-bindings/auto/jsb_cocos2dx_auto.hpp | 4 - .../auto/jsb_cocos2dx_studio_auto.cpp | 4 +- 7 files changed, 58 insertions(+), 192 deletions(-) diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js index 319d1a4b8e..bfc87c64f2 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js @@ -56,6 +56,20 @@ getDuration : function ( return 0; }, +/** + * @method create + * @param {String} arg0 + * @param {String} arg1 + * @return {cc.Animation3D} + */ +create : function ( +str, +str +) +{ + return cc.Animation3D; +}, + /** * @method Animation3D * @constructor diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index 626f1990b7..1bb76c58a2 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -4903,32 +4903,6 @@ getElapsed : function ( */ cc.Sequence = { -/** - * @method init - * @param {Array} arg0 - * @return {bool} - */ -init : function ( -array -) -{ - return false; -}, - -/** - * @method initWithTwoActions - * @param {cc.FiniteTimeAction} arg0 - * @param {cc.FiniteTimeAction} arg1 - * @return {bool} - */ -initWithTwoActions : function ( -finitetimeaction, -finitetimeaction -) -{ - return false; -}, - /** * @method Sequence * @constructor @@ -5069,32 +5043,6 @@ RepeatForever : function ( */ cc.Spawn = { -/** - * @method init - * @param {Array} arg0 - * @return {bool} - */ -init : function ( -array -) -{ - return false; -}, - -/** - * @method initWithTwoActions - * @param {cc.FiniteTimeAction} arg0 - * @param {cc.FiniteTimeAction} arg1 - * @return {bool} - */ -initWithTwoActions : function ( -finitetimeaction, -finitetimeaction -) -{ - return false; -}, - /** * @method Spawn * @constructor diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp index e429e644be..b220ac88be 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp @@ -115,6 +115,38 @@ bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getDuration : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + + auto ret = cocos2d::Animation3D::create(arg0); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); + return true; + } + if (argc == 2) { + std::string arg0; + std::string arg1; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); + + auto ret = cocos2d::Animation3D::create(arg0, arg1); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); + return true; + } + JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); + return false; +} + bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -158,7 +190,10 @@ void js_register_cocos2dx_3d_Animation3D(JSContext *cx, JS::HandleObject global) JS_FS_END }; - JSFunctionSpec *st_funcs = NULL; + static JSFunctionSpec st_funcs[] = { + JS_FN("create", js_cocos2dx_3d_Animation3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; jsb_cocos2d_Animation3D_prototype = JS_InitClass( cx, global, diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp index 07ee9c6107..49a39b5fa2 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp @@ -16,6 +16,7 @@ bool js_cocos2dx_3d_Animation3D_initWithFile(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_3d_Animation3D_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getBoneCurveByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_Animation3D(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Animate3D_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index 12771ed9b7..6c15a2224e 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -7635,7 +7635,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) auto ret = cocos2d::Director::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -12214,68 +12214,6 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Sequence_class; JSObject *jsb_cocos2d_Sequence_prototype; -bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_init : Invalid Native Object"); - if (argc == 1) { - cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, args.get(0), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_init : Error processing arguments"); - bool ret = cobj->init(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - args.rval().set(jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Sequence_init : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Invalid Native Object"); - if (argc == 2) { - cocos2d::FiniteTimeAction* arg0 = nullptr; - cocos2d::FiniteTimeAction* arg1 = nullptr; - do { - if (args.get(0).isNull()) { arg0 = nullptr; break; } - if (!args.get(0).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - do { - if (args.get(1).isNull()) { arg1 = nullptr; break; } - if (!args.get(1).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Error processing arguments"); - bool ret = cobj->initWithTwoActions(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - args.rval().set(jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Sequence_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12328,8 +12266,6 @@ void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_Sequence_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithTwoActions", js_cocos2dx_Sequence_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Sequence_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -12742,68 +12678,6 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Spawn_class; JSObject *jsb_cocos2d_Spawn_prototype; -bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_init : Invalid Native Object"); - if (argc == 1) { - cocos2d::Vector arg0; - ok &= jsval_to_ccvector(cx, args.get(0), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_init : Error processing arguments"); - bool ret = cobj->init(arg0); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - args.rval().set(jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Spawn_init : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Invalid Native Object"); - if (argc == 2) { - cocos2d::FiniteTimeAction* arg0 = nullptr; - cocos2d::FiniteTimeAction* arg1 = nullptr; - do { - if (args.get(0).isNull()) { arg0 = nullptr; break; } - if (!args.get(0).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - do { - if (args.get(1).isNull()) { arg1 = nullptr; break; } - if (!args.get(1).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Error processing arguments"); - bool ret = cobj->initWithTwoActions(arg0, arg1); - jsval jsret = JSVAL_NULL; - jsret = BOOLEAN_TO_JSVAL(ret); - args.rval().set(jsret); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_Spawn_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12856,8 +12730,6 @@ void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { - JS_FN("init", js_cocos2dx_Spawn_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("initWithTwoActions", js_cocos2dx_Spawn_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Spawn_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -16854,7 +16726,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval * auto ret = cocos2d::Configuration::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -56078,7 +55950,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::GLProgramCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -58285,7 +58157,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::AnimationCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -59435,7 +59307,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva auto ret = cocos2d::SpriteFrameCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index fb22303582..0055f1c107 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -648,8 +648,6 @@ bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Sequence_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); -bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sequence_Sequence(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Repeat_class; @@ -685,8 +683,6 @@ bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Spawn_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); -bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Spawn_Spawn(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_RotateTo_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp index f26ef41787..660f580f1a 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -698,7 +698,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc auto ret = cocostudio::ActionManagerEx::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -5172,7 +5172,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t auto ret = cocostudio::ArmatureDataManager::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); + JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } From 71f9ead9818933be0b67d51f01e0a9f59e960477 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Fri, 11 Dec 2015 17:52:29 +0000 Subject: [PATCH 09/28] [ci skip][AUTO]: updating luabinding & jsbinding automatically --- .../auto/api/jsb_cocos2dx_3d_auto_api.js | 14 -- .../auto/api/jsb_cocos2dx_auto_api.js | 52 +++++++ .../js-bindings/auto/jsb_cocos2dx_3d_auto.cpp | 37 +---- .../js-bindings/auto/jsb_cocos2dx_3d_auto.hpp | 1 - .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 138 +++++++++++++++++- .../js-bindings/auto/jsb_cocos2dx_auto.hpp | 4 + .../auto/jsb_cocos2dx_studio_auto.cpp | 4 +- 7 files changed, 192 insertions(+), 58 deletions(-) diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js index bfc87c64f2..319d1a4b8e 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_3d_auto_api.js @@ -56,20 +56,6 @@ getDuration : function ( return 0; }, -/** - * @method create - * @param {String} arg0 - * @param {String} arg1 - * @return {cc.Animation3D} - */ -create : function ( -str, -str -) -{ - return cc.Animation3D; -}, - /** * @method Animation3D * @constructor diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index 1bb76c58a2..626f1990b7 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -4903,6 +4903,32 @@ getElapsed : function ( */ cc.Sequence = { +/** + * @method init + * @param {Array} arg0 + * @return {bool} + */ +init : function ( +array +) +{ + return false; +}, + +/** + * @method initWithTwoActions + * @param {cc.FiniteTimeAction} arg0 + * @param {cc.FiniteTimeAction} arg1 + * @return {bool} + */ +initWithTwoActions : function ( +finitetimeaction, +finitetimeaction +) +{ + return false; +}, + /** * @method Sequence * @constructor @@ -5043,6 +5069,32 @@ RepeatForever : function ( */ cc.Spawn = { +/** + * @method init + * @param {Array} arg0 + * @return {bool} + */ +init : function ( +array +) +{ + return false; +}, + +/** + * @method initWithTwoActions + * @param {cc.FiniteTimeAction} arg0 + * @param {cc.FiniteTimeAction} arg1 + * @return {bool} + */ +initWithTwoActions : function ( +finitetimeaction, +finitetimeaction +) +{ + return false; +}, + /** * @method Spawn * @constructor diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp index b220ac88be..e429e644be 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.cpp @@ -115,38 +115,6 @@ bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getDuration : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, args.get(0), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); - - auto ret = cocos2d::Animation3D::create(arg0); - js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - return true; - } - if (argc == 2) { - std::string arg0; - std::string arg1; - ok &= jsval_to_std_string(cx, args.get(0), &arg0); - ok &= jsval_to_std_string(cx, args.get(1), &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_3d_Animation3D_create : Error processing arguments"); - - auto ret = cocos2d::Animation3D::create(arg0, arg1); - js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::Animation3D")); - args.rval().set(OBJECT_TO_JSVAL(jsret)); - return true; - } - JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_create : wrong number of arguments"); - return false; -} - bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -190,10 +158,7 @@ void js_register_cocos2dx_3d_Animation3D(JSContext *cx, JS::HandleObject global) JS_FS_END }; - static JSFunctionSpec st_funcs[] = { - JS_FN("create", js_cocos2dx_3d_Animation3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FS_END - }; + JSFunctionSpec *st_funcs = NULL; jsb_cocos2d_Animation3D_prototype = JS_InitClass( cx, global, diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp index 49a39b5fa2..07ee9c6107 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_3d_auto.hpp @@ -16,7 +16,6 @@ bool js_cocos2dx_3d_Animation3D_initWithFile(JSContext *cx, uint32_t argc, jsval bool js_cocos2dx_3d_Animation3D_init(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getBoneCurveByName(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_getDuration(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_3d_Animation3D_create(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_3d_Animation3D_Animation3D(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Animate3D_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index 6c15a2224e..12771ed9b7 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -7635,7 +7635,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp) auto ret = cocos2d::Director::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Director")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -12214,6 +12214,68 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Sequence_class; JSObject *jsb_cocos2d_Sequence_prototype; +bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vector arg0; + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Sequence_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Sequence* cobj = (cocos2d::Sequence *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Invalid Native Object"); + if (argc == 2) { + cocos2d::FiniteTimeAction* arg0 = nullptr; + cocos2d::FiniteTimeAction* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Sequence_initWithTwoActions : Error processing arguments"); + bool ret = cobj->initWithTwoActions(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Sequence_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12266,6 +12328,8 @@ void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_Sequence_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTwoActions", js_cocos2dx_Sequence_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Sequence_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -12678,6 +12742,68 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global) JSClass *jsb_cocos2d_Spawn_class; JSObject *jsb_cocos2d_Spawn_prototype; +bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_init : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vector arg0; + ok &= jsval_to_ccvector(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_init : Error processing arguments"); + bool ret = cobj->init(arg0); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Spawn_init : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Spawn* cobj = (cocos2d::Spawn *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Invalid Native Object"); + if (argc == 2) { + cocos2d::FiniteTimeAction* arg0 = nullptr; + cocos2d::FiniteTimeAction* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (cocos2d::FiniteTimeAction*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Spawn_initWithTwoActions : Error processing arguments"); + bool ret = cobj->initWithTwoActions(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Spawn_initWithTwoActions : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -12730,6 +12856,8 @@ void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec funcs[] = { + JS_FN("init", js_cocos2dx_Spawn_init, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("initWithTwoActions", js_cocos2dx_Spawn_initWithTwoActions, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2dx_Spawn_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -16726,7 +16854,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval * auto ret = cocos2d::Configuration::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Configuration")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -55950,7 +56078,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::GLProgramCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::GLProgramCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -58157,7 +58285,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval auto ret = cocos2d::AnimationCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::AnimationCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -59307,7 +59435,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva auto ret = cocos2d::SpriteFrameCache::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::SpriteFrameCache")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index 0055f1c107..fb22303582 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -648,6 +648,8 @@ bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Sequence_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Sequence_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Sequence_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Sequence_Sequence(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_Repeat_class; @@ -683,6 +685,8 @@ bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp); void js_cocos2dx_Spawn_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); +bool js_cocos2dx_Spawn_init(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Spawn_initWithTwoActions(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Spawn_Spawn(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_RotateTo_class; diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp index 660f580f1a..f26ef41787 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_studio_auto.cpp @@ -698,7 +698,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc auto ret = cocostudio::ActionManagerEx::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ActionManagerEx")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -5172,7 +5172,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t auto ret = cocostudio::ArmatureDataManager::getInstance(); js_type_class_t *typeClass = js_get_type_from_native(ret); - JS::RootedObject jsret(cx, jsb_ref_singleton_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); + JS::RootedObject jsret(cx, jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocostudio::ArmatureDataManager")); args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } From 47911e0c249ae366a6dae63ea3aede56e44d480e Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 11 Dec 2015 15:18:09 -0800 Subject: [PATCH 10/28] more js fixes fixes in how ref count is measured opengl bindings converted to new API --- cocos/base/CCRef.cpp | 9 +- cocos/base/CCRef.h | 1 + .../js-bindings/manual/ScriptingCore.cpp | 37 +++---- .../js-bindings/manual/ScriptingCore.h | 2 +- .../js-bindings/manual/cocos2d_specifics.cpp | 23 +--- .../js-bindings/manual/js_bindings_opengl.cpp | 101 ++++++++---------- .../manual/js_manual_conversions.h | 2 +- .../src/MemoryModelTest/MemoryModelTest.js | 7 ++ 8 files changed, 78 insertions(+), 104 deletions(-) diff --git a/cocos/base/CCRef.cpp b/cocos/base/CCRef.cpp index 59215c5738..4c4ce17674 100644 --- a/cocos/base/CCRef.cpp +++ b/cocos/base/CCRef.cpp @@ -50,6 +50,7 @@ Ref::Ref() , _scriptObject(nullptr) , _rooted(false) , _scriptOwned(false) +,_referenceCountAtRootTime(0) #endif { #if CC_ENABLE_SCRIPT_BINDING @@ -93,11 +94,15 @@ void Ref::retain() ++_referenceCount; #if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS - if (!_rooted && _scriptOwned) + if (_scriptOwned && !_rooted) { auto scriptMgr = ScriptEngineManager::getInstance()->getScriptEngine(); if (scriptMgr && scriptMgr->getScriptType() == kScriptTypeJavascript) { + _referenceCountAtRootTime = _referenceCount-1; + + CCLOG("retain + root: %p (%s) rc=%d rcrt=%d", this, typeid(*this).name(), _referenceCount, _referenceCountAtRootTime); + scriptMgr->rootObject(this); _rooted = true; } @@ -111,7 +116,7 @@ void Ref::release() --_referenceCount; #if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS - if (_scriptOwned && _referenceCount==1 && _rooted) + if (_scriptOwned && _rooted && _referenceCount==_referenceCountAtRootTime) { auto scriptMgr = ScriptEngineManager::getInstance()->getScriptEngine(); if (scriptMgr && scriptMgr->getScriptType() == kScriptTypeJavascript) diff --git a/cocos/base/CCRef.h b/cocos/base/CCRef.h index 5ca40a0c9e..4451243ae1 100644 --- a/cocos/base/CCRef.h +++ b/cocos/base/CCRef.h @@ -161,6 +161,7 @@ public: When true, it means that the object was already rooted. */ bool _rooted; + unsigned int _referenceCountAtRootTime; /** * The life of the object is scrolled by the scripting engine. diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 19354fa161..91ff3b53e9 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -1563,14 +1563,12 @@ void ScriptingCore::rootObject(Ref* ref) nproxy = jsb_get_native_proxy(ptr); if (nproxy) { JSContext *cx = getGlobalContext(); - // FIXME: Creating a RootedObject here is not needed. - // it is being created only because jsb_get_js_proxy() requires one - // but only the raw pointer is used in jsb_get_js_proxy() - JS::RootedObject handle(cx, nproxy->obj.get()); - jsproxy = jsb_get_js_proxy(handle); - AddObjectRoot(cx, &jsproxy->obj); - - CCLOG("Rooting %p - %p: %s", ref, &jsproxy->obj, typeid(*ref).name()); + jsproxy = jsb_get_js_proxy(nproxy->obj); + JS::AddNamedObjectRoot(cx, &jsproxy->obj, typeid(*ref).name()); + } + else + { + CCLOG("BUG in rootObject"); } } @@ -1583,14 +1581,12 @@ void ScriptingCore::unrootObject(Ref* ref) nproxy = jsb_get_native_proxy(ptr); if (nproxy) { JSContext *cx = getGlobalContext(); - // FIXME: Creating a RootedObject here is not needed. - // it is being created only because jsb_get_js_proxy() requires one - // but only the raw pointer is used in jsb_get_js_proxy() - JS::RootedObject handle(cx, nproxy->obj.get()); - jsproxy = jsb_get_js_proxy(handle); - RemoveObjectRoot(cx, &jsproxy->obj); - - CCLOG("Unrooting #2 %p - %p: %s", ref, &jsproxy->obj, typeid(*ref).name()); + jsproxy = jsb_get_js_proxy(nproxy->obj); + JS::RemoveObjectRoot(cx, &jsproxy->obj); + } + else + { + CCLOG("BUG in unrootObject"); } } @@ -1949,11 +1945,10 @@ js_proxy_t* jsb_get_native_proxy(void* nativeObj) return p; } -js_proxy_t* jsb_get_js_proxy(JS::HandleObject jsObj) +js_proxy_t* jsb_get_js_proxy(JSObject* jsObj) { js_proxy_t* p = nullptr; - JSObject* ptr = jsObj.get(); - JS_GET_NATIVE_PROXY(p, ptr); + JS_GET_NATIVE_PROXY(p, jsObj); return p; } @@ -2059,8 +2054,6 @@ void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) js_proxy_t* nproxy; js_proxy_t* jsproxy; - CCLOG("jsb_ref_finalize #1: JSObject address = %p", obj); - JS::RootedObject jsobj(fop->runtime(), obj); jsproxy = jsb_get_js_proxy(jsobj); if (jsproxy) @@ -2070,8 +2063,6 @@ void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) if (ref) { - CCLOG("jsb_ref_finalize #2: JSObject address = %p (%s)", obj, typeid(*ref).name()); - jsb_remove_proxy(nproxy, jsproxy); ref->release(); } diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index b9ac8b295c..820553bfc3 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -549,7 +549,7 @@ js_type_class_t *jsb_register_class(JSContext *cx, JSClass *jsClass, JS::HandleO js_proxy_t* jsb_new_proxy(void* nativeObj, JS::HandleObject jsObj); js_proxy_t* jsb_get_native_proxy(void* nativeObj); -js_proxy_t* jsb_get_js_proxy(JS::HandleObject jsObj); +js_proxy_t* jsb_get_js_proxy(JSObject* jsObj); void jsb_remove_proxy(js_proxy_t* nativeProxy, js_proxy_t* jsProxy); /** diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index 0f4c728ab2..99a761f32c 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -5142,25 +5142,10 @@ bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval * JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments"); cocos2d::EventKeyboard* cobj = new (std::nothrow) cocos2d::EventKeyboard(arg0, arg1); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); - } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); - JS::RootedValue objVal(cx, OBJECT_TO_JSVAL(obj)); - args.rval().set(objVal); - // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::EventKeyboard"); + js_type_class_t *typeClass = js_get_type_from_native(cobj); + auto jsobj = jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::EventKeyboard"); + + args.rval().set(OBJECT_TO_JSVAL(jsobj)); return true; } diff --git a/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp b/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp index 605bc616fd..bb69e13000 100644 --- a/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp +++ b/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp @@ -32,31 +32,31 @@ void GLNode::draw(Renderer *renderer, const Mat4& transform, uint32_t flags) { void GLNode::onDraw(Mat4 &transform, uint32_t flags) { - js_proxy_t* proxy = NULL; JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - proxy = js_get_or_create_proxy(cx, this); - if( proxy ) { -// JSObject *jsObj = proxy->obj; - JS::RootedObject jsObj(cx, proxy->obj.get()); - if (jsObj) { - bool found = false; - JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + js_type_class_t *typeClass = js_get_type_from_native(this); + auto j = jsb_ref_get_or_create_jsobject(cx, this, typeClass, "cocos2d::GLNode"); - JS_HasProperty(cx, jsObj, "draw", &found); - if (found == true) { - auto director = Director::getInstance(); - director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); + if (j) + { + JS::RootedObject jsObj(cx, j); - JS::RootedValue rval(cx); - JS::RootedValue fval(cx); - JS_GetProperty(cx, jsObj, "draw", &fval); + bool found = false; + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - JS_CallFunctionValue(cx, jsObj, fval, JS::HandleValueArray::empty(), &rval); + JS_HasProperty(cx, jsObj, "draw", &found); + if (found) { + auto director = Director::getInstance(); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); - director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - } + JS::RootedValue rval(cx); + JS::RootedValue fval(cx); + JS_GetProperty(cx, jsObj, "draw", &fval); + + JS_CallFunctionValue(cx, jsObj, fval, JS::HandleValueArray::empty(), &rval); + + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } } } @@ -68,32 +68,18 @@ JSObject *js_cocos2dx_GLNode_prototype; bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { - if (argc == 0) { - cocos2d::GLNode* cobj = new cocos2d::GLNode(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); - } + cocos2d::GLNode* cobj = new (std::nothrow) cocos2d::GLNode; - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); + js_type_class_t *typeClass = js_get_type_from_native(cobj); + JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::GLNode")); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - args.rval().set(OBJECT_TO_JSVAL(obj)); - // link the native object with the javascript object - js_proxy_t *p = jsb_new_proxy(cobj, obj); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); - JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); + bool ok=false; + if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); return true; } @@ -101,17 +87,16 @@ bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) return false; } -void js_cocos2dx_GLNode_finalize(JSFreeOp *fop, JSObject *obj) { -} - static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - cocos2d::GLNode *nobj = new cocos2d::GLNode(); - js_proxy_t* p = jsb_new_proxy(nobj, obj); - nobj->autorelease(); - JS::AddNamedObjectRoot(cx, &p->obj, "GLNode"); + cocos2d::GLNode *nobj = new (std::nothrow) cocos2d::GLNode; + auto newproxy = jsb_new_proxy(nobj, obj); + jsb_ref_init(cx, &newproxy->obj, nobj, "cocos2d::GLNode"); + bool isFound = false; + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); args.rval().setUndefined(); return true; } @@ -119,16 +104,16 @@ static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_GLNode_create(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - cocos2d::GLNode* ret = new cocos2d::GLNode(); - jsval jsret; - do { - if (ret) { - js_proxy_t *proxy = js_get_or_create_proxy(cx, ret); - jsret = OBJECT_TO_JSVAL(proxy->obj); - } else { - jsret = JSVAL_NULL; - } - } while (0); + cocos2d::GLNode* ret = new (std::nothrow) cocos2d::GLNode; + jsval jsret = JSVAL_NULL; + + if (ret) { + js_type_class_t *typeClass = js_get_type_from_native(ret); + + auto jsobj = jsb_ref_create_jsobject(cx, ret, typeClass, "cocos2d::GLNode"); + jsret = OBJECT_TO_JSVAL(jsobj); + } + args.rval().set(jsret); return true; } @@ -145,7 +130,7 @@ void js_register_cocos2dx_GLNode(JSContext *cx, JS::HandleObject global) { js_cocos2dx_GLNode_class->enumerate = JS_EnumerateStub; js_cocos2dx_GLNode_class->resolve = JS_ResolveStub; js_cocos2dx_GLNode_class->convert = JS_ConvertStub; - js_cocos2dx_GLNode_class->finalize = js_cocos2dx_GLNode_finalize; + js_cocos2dx_GLNode_class->finalize = jsb_ref_finalize; js_cocos2dx_GLNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { diff --git a/cocos/scripting/js-bindings/manual/js_manual_conversions.h b/cocos/scripting/js-bindings/manual/js_manual_conversions.h index ce64a45310..e2d2f538f0 100644 --- a/cocos/scripting/js-bindings/manual/js_manual_conversions.h +++ b/cocos/scripting/js-bindings/manual/js_manual_conversions.h @@ -119,7 +119,7 @@ bool jsval_to_ray(JSContext *cx, JS::HandleValue vp, cocos2d::Ray* ret); bool jsval_to_resourcedata(JSContext *cx, JS::HandleValue v, cocos2d::ResourceData* ret); // forward declaration -CC_JS_DLL js_proxy_t* jsb_get_js_proxy(JS::HandleObject jsObj); +CC_JS_DLL js_proxy_t* jsb_get_js_proxy(JSObject* jsObj); template bool jsvals_variadic_to_ccvector( JSContext *cx, /*jsval *vp, int argc,*/const JS::CallArgs& args, cocos2d::Vector* ret) diff --git a/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js b/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js index a38d14f122..ea0e8a245d 100644 --- a/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js +++ b/tests/js-tests/src/MemoryModelTest/MemoryModelTest.js @@ -70,6 +70,7 @@ var SetPropertyMemoryModelTest = MemoryModelTestBase.extend({ _subtitle:"See console for possible errors", ctor:function () { + cc.sys.garbageCollect(); this._super(); var sprite = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); var tag = 10; @@ -157,6 +158,12 @@ var LocalVarMemoryModelTest = MemoryModelTestBase.extend({ var sprite2 = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); var sprite3 = new cc.Sprite(s_grossini_dance_atlas, cc.rect(0, 0, 85, 121)); var a = 10; + this.addChild(sprite1); + this.removeChild(sprite1); +// this.addChild(sprite2); +// this.removeChild(sprite2); + this.addChild(sprite3); + this.removeChild(sprite3); //cc.sys.dumpRoot(); cc.sys.garbageCollect(); cc.log(sprite1); From c5058aa2f963ce41a6317781dfcc2709806c99eb Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 11 Dec 2015 17:18:20 -0800 Subject: [PATCH 11/28] more conversions --- .../chipmunk/js_bindings_chipmunk_manual.cpp | 81 +++++-------------- .../js-bindings/manual/cocos2d_specifics.cpp | 6 +- .../js-bindings/manual/cocos2d_specifics.hpp | 7 +- .../project.pbxproj | 12 +-- .../Classes/js_DrawNode3D_bindings.cpp | 33 ++------ 5 files changed, 33 insertions(+), 106 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp index 936430eff6..34e4d42722 100644 --- a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp +++ b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp @@ -70,12 +70,6 @@ JSClass* JSPROXY_CCPhysicsSprite_class = NULL; JSObject* JSPROXY_CCPhysicsSprite_object = NULL; // Constructor -// Destructor -void JSPROXY_CCPhysicsSprite_finalize(JSFreeOp *fop, JSObject *obj) -{ - CCLOGINFO("jsbindings: finalizing JS object %p (PhysicsSprite)", obj); -} - // Arguments: // Ret value: BOOL (b) bool JSPROXY_CCPhysicsSprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) { @@ -173,12 +167,6 @@ extern JSObject *js_cocos2dx_CCDrawNode_prototype; // Constructor -// Destructor -void JSB_CCPhysicsDebugNode_finalize(JSFreeOp *fop, JSObject *obj) -{ - CCLOGINFO("jsbindings: finalizing JS object %p (PhysicsDebugNode)", obj); -} - // Arguments: cpSpace* // Ret value: PhysicsDebugNode* (o) bool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t argc, jsval *vp) { @@ -295,7 +283,7 @@ void JSB_CCPhysicsDebugNode_createClass(JSContext *cx, JS::HandleObject globalOb JSB_CCPhysicsDebugNode_class->enumerate = JS_EnumerateStub; JSB_CCPhysicsDebugNode_class->resolve = JS_ResolveStub; JSB_CCPhysicsDebugNode_class->convert = JS_ConvertStub; - JSB_CCPhysicsDebugNode_class->finalize = JSB_CCPhysicsDebugNode_finalize; + JSB_CCPhysicsDebugNode_class->finalize = jsb_ref_finalize; JSB_CCPhysicsDebugNode_class->flags = 0; static JSPropertySpec properties[] = { @@ -442,7 +430,8 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrame__static(JSContext *cx, uint32 // Arguments: NSString* // Ret value: PhysicsSprite* (o) -bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, uint32_t argc, jsval *vp) { +bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, uint32_t argc, jsval *vp) +{ JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; const char* arg0 = nullptr; @@ -452,27 +441,9 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui PhysicsSprite* ret = PhysicsSprite::createWithSpriteFrameName(arg0); - jsval jsret; - do { - if (ret) { - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); - jsret = OBJECT_TO_JSVAL(obj); - js_proxy_t *p = jsb_new_proxy(ret, obj); - JS::AddNamedObjectRoot(cx, &p->obj, "CCPhysicsSprite"); - } else { - jsret = JSVAL_NULL; - } - } while (0); - args.rval().set(jsret); + js_type_class_t *typeClass = js_get_type_from_native(ret); + JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::extension::PhysicsSprite")); + args.rval().set(OBJECT_TO_JSVAL(jsret)); return true; } @@ -483,27 +454,14 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - PhysicsSprite* cobj = new PhysicsSprite(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); - } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parentProto(cx, typeClass->parentProto.ref()); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parentProto)); - args.rval().set(OBJECT_TO_JSVAL(obj)); + auto cobj = new (std::nothrow) cocos2d::extension::PhysicsSprite; + js_type_class_t *typeClass = js_get_type_from_native(cobj); + // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::PhysicsSprite"); - if (JS_HasProperty(cx, obj, "_ctor", &ok)) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::extension::PhysicsSprite")); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); + if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); return true; } @@ -511,14 +469,11 @@ static bool JSPROXY_CCPhysicsSprite_ctor(JSContext *cx, uint32_t argc, jsval *vp { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - PhysicsSprite *nobj = new PhysicsSprite(); - if (nobj) { - nobj->autorelease(); - } - js_proxy_t* p = jsb_new_proxy(nobj, obj); - JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::SpriteFrame"); + auto nobj = new (std::nothrow) cocos2d::extension::PhysicsSprite; + auto newproxy = jsb_new_proxy(nobj, obj); + jsb_ref_init(cx, &newproxy->obj, nobj, "cocos2d::extension::PhysicsSprite"); bool isFound = false; - if (JS_HasProperty(cx, obj, "_ctor", &isFound)) + if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); args.rval().setUndefined(); return true; @@ -535,7 +490,7 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JS::HandleObject globalO JSPROXY_CCPhysicsSprite_class->enumerate = JS_EnumerateStub; JSPROXY_CCPhysicsSprite_class->resolve = JS_ResolveStub; JSPROXY_CCPhysicsSprite_class->convert = JS_ConvertStub; - JSPROXY_CCPhysicsSprite_class->finalize = JSPROXY_CCPhysicsSprite_finalize; + JSPROXY_CCPhysicsSprite_class->finalize = jsb_ref_finalize; JSPROXY_CCPhysicsSprite_class->flags = 0; static JSPropertySpec properties[] = { diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index 99a761f32c..025b0ed24f 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -5152,10 +5152,6 @@ bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval * extern JSObject *jsb_cocos2d_Event_prototype; -void js_cocos2d_EventKeyboard_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (EventKeyboard)", obj); -} - static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -5173,7 +5169,7 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JS::HandleObject global) jsb_cocos2d_EventKeyboard_class->enumerate = JS_EnumerateStub; jsb_cocos2d_EventKeyboard_class->resolve = JS_ResolveStub; jsb_cocos2d_EventKeyboard_class->convert = JS_ConvertStub; - jsb_cocos2d_EventKeyboard_class->finalize = js_cocos2d_EventKeyboard_finalize; + jsb_cocos2d_EventKeyboard_class->finalize = jsb_ref_finalize; jsb_cocos2d_EventKeyboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp index 1c6dc8ff2c..30a096d314 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp @@ -133,11 +133,8 @@ JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_ifparentProto.ref().get()); JS::RootedObject js_obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); proxy = jsb_new_proxy(native_obj, js_obj); -#ifdef DEBUG - AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); -#else - AddObjectRoot(cx, &proxy->obj); -#endif + + JS::AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); } return proxy->obj; } diff --git a/cocos/scripting/js-bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj b/cocos/scripting/js-bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj index ab0bc1f418..9e61293b30 100644 --- a/cocos/scripting/js-bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/js-bindings/proj.ios_mac/cocos2d_js_bindings.xcodeproj/project.pbxproj @@ -172,10 +172,10 @@ BA4095C31A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */; }; BA4095C41A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */; }; BA4095C51A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */; }; - BA9FD5D21BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; settings = {ASSET_TAGS = (); }; }; - BA9FD5D31BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; settings = {ASSET_TAGS = (); }; }; - BA9FD5D41BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; settings = {ASSET_TAGS = (); }; }; - BA9FD5D51BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; settings = {ASSET_TAGS = (); }; }; + BA9FD5D21BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; }; + BA9FD5D31BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; }; + BA9FD5D41BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; }; + BA9FD5D51BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; }; BAEE4D711AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BAEE4D6F1AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp */; }; BAEE4D721AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BAEE4D6F1AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.cpp */; }; BAEE4D731AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BAEE4D701AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp */; }; @@ -211,7 +211,6 @@ 1A119E3C18BDF19200352BAA /* jsb_cocos2dx_spine_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_spine_auto.hpp; sourceTree = ""; }; 1A119E3E18BDF19200352BAA /* jsb_cocos2dx_studio_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_studio_auto.cpp; sourceTree = ""; }; 1A119E3F18BDF19200352BAA /* jsb_cocos2dx_studio_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_studio_auto.hpp; sourceTree = ""; }; - 1A119E4318BDF19200352BAA /* Android.mk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Android.mk; sourceTree = ""; }; 1A119E4418BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_chipmunk_auto_classes.cpp; sourceTree = ""; }; 1A119E4518BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_auto_classes.h; sourceTree = ""; }; 1A119E4618BDF19200352BAA /* js_bindings_chipmunk_auto_classes_registration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_auto_classes_registration.h; sourceTree = ""; }; @@ -224,7 +223,6 @@ 1A119E4D18BDF19200352BAA /* js_bindings_chipmunk_registration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_registration.h; sourceTree = ""; }; 1A119E4E18BDF19200352BAA /* cocos2d_specifics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cocos2d_specifics.cpp; sourceTree = ""; }; 1A119E4F18BDF19200352BAA /* cocos2d_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocos2d_specifics.hpp; sourceTree = ""; }; - 1A119E5118BDF19200352BAA /* Android.mk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Android.mk; sourceTree = ""; }; 1A119E5218BDF19200352BAA /* cocosbuilder_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocosbuilder_specifics.hpp; sourceTree = ""; }; 1A119E5318BDF19200352BAA /* js_bindings_ccbreader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_ccbreader.cpp; sourceTree = ""; }; 1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_ccbreader.h; sourceTree = ""; }; @@ -428,7 +426,6 @@ 1A119E4218BDF19200352BAA /* chipmunk */ = { isa = PBXGroup; children = ( - 1A119E4318BDF19200352BAA /* Android.mk */, 1A119E4418BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp */, 1A119E4518BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h */, 1A119E4618BDF19200352BAA /* js_bindings_chipmunk_auto_classes_registration.h */, @@ -446,7 +443,6 @@ 1A119E5018BDF19200352BAA /* cocosbuilder */ = { isa = PBXGroup; children = ( - 1A119E5118BDF19200352BAA /* Android.mk */, 1A119E5218BDF19200352BAA /* cocosbuilder_specifics.hpp */, 1A119E5318BDF19200352BAA /* js_bindings_ccbreader.cpp */, 1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */, diff --git a/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp b/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp index cc1bb7a1f0..e3d0dc14fb 100644 --- a/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp +++ b/tests/js-tests/project/Classes/js_DrawNode3D_bindings.cpp @@ -485,29 +485,15 @@ bool js_cocos2dx_DrawNode3D_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - cocos2d::DrawNode3D* cobj = new (std::nothrow) cocos2d::DrawNode3D(); + cocos2d::DrawNode3D* cobj = new (std::nothrow) cocos2d::DrawNode3D; cobj->init(); - cocos2d::Ref *_ccobj = dynamic_cast(cobj); - if (_ccobj) { - _ccobj->autorelease(); - } - TypeTest t; - js_type_class_t *typeClass = nullptr; - std::string typeName = t.s_name(); - auto typeMapIter = _js_global_type_map.find(typeName); - CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); - typeClass = typeMapIter->second; - CCASSERT(typeClass, "The value is null."); - // JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); - JS::RootedObject proto(cx, typeClass->proto.ref()); - JS::RootedObject parent(cx, typeClass->parentProto.ref()); - JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); - args.rval().set(OBJECT_TO_JSVAL(obj)); + js_type_class_t *typeClass = js_get_type_from_native(cobj); + // link the native object with the javascript object - js_proxy_t* p = jsb_new_proxy(cobj, obj); - AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode3D"); - if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) - ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); + JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::DrawNode3D")); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); + if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); return true; } @@ -520,9 +506,6 @@ static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp) extern JSObject *jsb_cocos2d_Node_prototype; -void js_cocos2d_DrawNode3D_finalize(JSFreeOp *fop, JSObject *obj) { - CCLOGINFO("jsbindings: finalizing JS object %p (DrawNode3D)", obj); -} void js_register_cocos2dx_DrawNode3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_DrawNode3D_class = (JSClass *)calloc(1, sizeof(JSClass)); @@ -534,7 +517,7 @@ void js_register_cocos2dx_DrawNode3D(JSContext *cx, JS::HandleObject global) { jsb_cocos2d_DrawNode3D_class->enumerate = JS_EnumerateStub; jsb_cocos2d_DrawNode3D_class->resolve = JS_ResolveStub; jsb_cocos2d_DrawNode3D_class->convert = JS_ConvertStub; - jsb_cocos2d_DrawNode3D_class->finalize = js_cocos2d_DrawNode3D_finalize; + jsb_cocos2d_DrawNode3D_class->finalize = jsb_ref_finalize; jsb_cocos2d_DrawNode3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); static JSPropertySpec properties[] = { From 3bb9a37393247b665cc49906a1314468059a5107 Mon Sep 17 00:00:00 2001 From: mogemimi Date: Fri, 4 Dec 2015 14:29:41 +0900 Subject: [PATCH 12/28] Fix deprecation warnings in PU --- extensions/Particle3D/PU/CCPUBillboardChain.cpp | 4 ++-- extensions/Particle3D/PU/CCPURender.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/Particle3D/PU/CCPUBillboardChain.cpp b/extensions/Particle3D/PU/CCPUBillboardChain.cpp index 56a6860ebf..c023d108fc 100644 --- a/extensions/Particle3D/PU/CCPUBillboardChain.cpp +++ b/extensions/Particle3D/PU/CCPUBillboardChain.cpp @@ -734,9 +734,9 @@ void PUBillboardChain::setBlendFunc(const BlendFunc& blendFunc) GLuint PUBillboardChain::getTextureName() { - if (TextureCache::getInstance()->isDirty()) + if (Director::getInstance()->getTextureCache()->isDirty()) { - if (TextureCache::getInstance()->getTextureForKey(_texFile) == nullptr) + if (Director::getInstance()->getTextureCache()->getTextureForKey(_texFile) == nullptr) { _texture = nullptr; this->init(""); diff --git a/extensions/Particle3D/PU/CCPURender.cpp b/extensions/Particle3D/PU/CCPURender.cpp index 51dd172f83..6f7b2e8413 100644 --- a/extensions/Particle3D/PU/CCPURender.cpp +++ b/extensions/Particle3D/PU/CCPURender.cpp @@ -589,9 +589,9 @@ bool PUParticle3DEntityRender::initRender( const std::string &texFile ) GLuint PUParticle3DEntityRender::getTextureName() { - if (TextureCache::getInstance()->isDirty()) + if (Director::getInstance()->getTextureCache()->isDirty()) { - if (TextureCache::getInstance()->getTextureForKey(_texFile) == nullptr) + if (Director::getInstance()->getTextureCache()->getTextureForKey(_texFile) == nullptr) { _texture = nullptr; this->initRender(""); From d27f50aaf27cf572b7b0b18b919de88270dead31 Mon Sep 17 00:00:00 2001 From: mogemimi Date: Sat, 12 Dec 2015 00:37:58 +0900 Subject: [PATCH 13/28] Fix typos in documentation and comments --- extensions/GUI/CCControlExtension/CCControl.cpp | 8 ++++---- extensions/GUI/CCControlExtension/CCControl.h | 8 ++++---- extensions/GUI/CCControlExtension/CCControlButton.h | 2 +- extensions/GUI/CCControlExtension/CCControlHuePicker.h | 2 +- extensions/GUI/CCControlExtension/CCControlSlider.h | 2 +- extensions/GUI/CCScrollView/CCScrollView.h | 2 +- extensions/Particle3D/PU/CCPUAffectorTranslator.cpp | 2 +- .../Particle3D/PU/CCPUDoPlacementParticleEventHandler.h | 2 +- extensions/Particle3D/PU/CCPUDynamicAttribute.h | 2 +- extensions/Particle3D/PU/CCPUEmitterTranslator.cpp | 2 +- extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h | 2 +- extensions/Particle3D/PU/CCPUObserver.cpp | 2 +- extensions/Particle3D/PU/CCPUObserver.h | 2 +- extensions/Particle3D/PU/CCPURandomiserTranslator.cpp | 2 +- extensions/Particle3D/PU/CCPUTechniqueTranslator.cpp | 2 +- extensions/Particle3D/PU/CCPUTextureRotator.h | 2 +- extensions/Particle3D/PU/CCPUVertexEmitter.h | 4 ++-- extensions/assets-manager/AssetsManager.cpp | 6 +++--- extensions/assets-manager/AssetsManager.h | 2 +- extensions/assets-manager/AssetsManagerEx.cpp | 2 +- extensions/assets-manager/AssetsManagerEx.h | 2 +- 21 files changed, 30 insertions(+), 30 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCControl.cpp b/extensions/GUI/CCControlExtension/CCControl.cpp index 417627191d..66f81aa9b7 100644 --- a/extensions/GUI/CCControlExtension/CCControl.cpp +++ b/extensions/GUI/CCControlExtension/CCControl.cpp @@ -107,7 +107,7 @@ void Control::sendActionsForControlEvents(EventType controlEvents) // For each control events for (int i = 0; i < kControlEventTotalNumber; i++) { - // If the given controlEvents bitmask contains the curent event + // If the given controlEvents bitmask contains the current event if (((int)controlEvents & (1 << i))) { // Call invocations @@ -135,7 +135,7 @@ void Control::addTargetWithActionForControlEvents(Ref* target, Handler action, E // For each control events for (int i = 0; i < kControlEventTotalNumber; i++) { - // If the given controlEvents bitmask contains the curent event + // If the given controlEvents bitmask contains the current event if (((int)controlEvents & (1 << i))) { this->addTargetWithActionForControlEvent(target, action, (EventType)(1<removeTargetWithActionForControlEvent(target, action, (EventType)(1 << i)); diff --git a/extensions/GUI/CCControlExtension/CCControl.h b/extensions/GUI/CCControlExtension/CCControl.h index e4842d047a..8b89a693fa 100644 --- a/extensions/GUI/CCControlExtension/CCControl.h +++ b/extensions/GUI/CCControlExtension/CCControl.h @@ -122,7 +122,7 @@ public: /** * Adds a target and action for a particular event (or events) to an internal * dispatch table. - * The action message may optionnaly include the sender and the event as + * The action message may optionally include the sender and the event as * parameters, in that order. * When you call this method, target is not retained. * @@ -149,7 +149,7 @@ public: virtual void removeTargetWithActionForControlEvents(Ref* target, Handler action, EventType controlEvents); /** - * Returns a point corresponding to the touh location converted into the + * Returns a point corresponding to the touch location converted into the * control space coordinates. * @param touch A Touch object that represents a touch. */ @@ -190,7 +190,7 @@ CC_CONSTRUCTOR_ACCESS: protected: /** * Returns an Invocation object able to construct messages using a given - * target-action pair. (The invocation may optionnaly include the sender and + * target-action pair. (The invocation may optionally include the sender and * the event as parameters, in that order) * * @param target The target object. @@ -217,7 +217,7 @@ protected: /** * Adds a target and action for a particular event to an internal dispatch * table. - * The action message may optionnaly include the sender and the event as + * The action message may optionally include the sender and the event as * parameters, in that order. * When you call this method, target is not retained. * diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 302b8c8ec9..4c7dc27511 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -134,7 +134,7 @@ public: virtual float getTitleTTFSizeForState(State state); /** - * Sets the font of the label, changes the label to a BMFont if neccessary. + * Sets the font of the label, changes the label to a BMFont if necessary. * @param fntFile The name of the font to change to * @param state The state that uses the specified fntFile. The values are described * in "CCControlState". diff --git a/extensions/GUI/CCControlExtension/CCControlHuePicker.h b/extensions/GUI/CCControlExtension/CCControlHuePicker.h index bca41ba1c6..b2bb21dbd9 100644 --- a/extensions/GUI/CCControlExtension/CCControlHuePicker.h +++ b/extensions/GUI/CCControlExtension/CCControlHuePicker.h @@ -71,7 +71,7 @@ protected: void updateSliderPosition(Vec2 location); bool checkSliderPosition(Vec2 location); - //maunally put in the setters + //manually put in the setters CC_SYNTHESIZE_READONLY(float, _hue, Hue); virtual void setHue(float val); CC_SYNTHESIZE_READONLY(float, _huePercentage, HuePercentage); diff --git a/extensions/GUI/CCControlExtension/CCControlSlider.h b/extensions/GUI/CCControlExtension/CCControlSlider.h index e2196c6b8f..fec34ca07c 100644 --- a/extensions/GUI/CCControlExtension/CCControlSlider.h +++ b/extensions/GUI/CCControlExtension/CCControlSlider.h @@ -129,7 +129,7 @@ protected: /** Returns the value for the given location. */ float valueForLocation(Vec2 location); - //maunally put in the setters + //manually put in the setters /** Contains the receiver's current value. */ CC_SYNTHESIZE_READONLY(float, _value, Value); diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index f621169493..47dc14b235 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -323,7 +323,7 @@ protected: */ Node* _container; /** - * Determiens whether user touch is moved after begin phase. + * Determines whether user touch is moved after begin phase. */ bool _touchMoved; /** diff --git a/extensions/Particle3D/PU/CCPUAffectorTranslator.cpp b/extensions/Particle3D/PU/CCPUAffectorTranslator.cpp index 687019adb0..49b5397694 100644 --- a/extensions/Particle3D/PU/CCPUAffectorTranslator.cpp +++ b/extensions/Particle3D/PU/CCPUAffectorTranslator.cpp @@ -104,7 +104,7 @@ void PUAffectorTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode } else if (prop->name == token[TOKEN_POSITION]) { - // Property: positon + // Property: position if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) { Vec3 val; diff --git a/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h b/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h index 03a97973ff..82bf9a3597 100644 --- a/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h +++ b/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h @@ -107,7 +107,7 @@ public: bool alwaysUsePosition(void) const {return _alwaysUsePosition;}; /** Set the boolean to indicate whether the position of the particle that is handled must be used for emission of - the new particle or whether the contact point of the physics actor must be used. This only applies if a physics angine + the new particle or whether the contact point of the physics actor must be used. This only applies if a physics engine is used, otherwise the default is used. */ void setAlwaysUsePosition(bool alwaysUsePosition) {_alwaysUsePosition = alwaysUsePosition;}; diff --git a/extensions/Particle3D/PU/CCPUDynamicAttribute.h b/extensions/Particle3D/PU/CCPUDynamicAttribute.h index 2a235756f3..70dc447305 100644 --- a/extensions/Particle3D/PU/CCPUDynamicAttribute.h +++ b/extensions/Particle3D/PU/CCPUDynamicAttribute.h @@ -258,7 +258,7 @@ class CC_DLL PUDynamicAttributeCurved : public PUDynamicAttribute inline ControlPointList::iterator getLastValidIterator(void); }; -/* This class generates values based on an oscillating functione (i.e. Sine). +/* This class generates values based on an oscillating function (i.e. Sine). */ class CC_DLL PUDynamicAttributeOscillate : public PUDynamicAttribute { diff --git a/extensions/Particle3D/PU/CCPUEmitterTranslator.cpp b/extensions/Particle3D/PU/CCPUEmitterTranslator.cpp index e760b5e51b..0cfa89f37f 100644 --- a/extensions/Particle3D/PU/CCPUEmitterTranslator.cpp +++ b/extensions/Particle3D/PU/CCPUEmitterTranslator.cpp @@ -108,7 +108,7 @@ void PUEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode * } else if (prop->name == token[TOKEN_POSITION]) { - // Property: positon + // Property: position if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) { Vec3 val; diff --git a/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h b/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h index cb153007d7..f58224edfd 100644 --- a/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h +++ b/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h @@ -196,7 +196,7 @@ public: /** Returns the type op distribution. @remarks There are several ways to emit particles on the surface of a mesh. This attribute indicates - the type of distrubution on the surface. + the type of distribution on the surface. */ const MeshInfo::MeshSurfaceDistribution getDistribution (void) const; diff --git a/extensions/Particle3D/PU/CCPUObserver.cpp b/extensions/Particle3D/PU/CCPUObserver.cpp index 9920da403a..ca2111b9aa 100644 --- a/extensions/Particle3D/PU/CCPUObserver.cpp +++ b/extensions/Particle3D/PU/CCPUObserver.cpp @@ -198,7 +198,7 @@ void PUObserver::destroyEventHandler(PUEventHandler* eventHandler) { if (*it == eventHandler) { - // Detroy it + // Destroy it //ParticleSystemManager::getSingletonPtr()->destroyEventHandler(*it); (*it)->release(); _eventHandlers.erase(it); diff --git a/extensions/Particle3D/PU/CCPUObserver.h b/extensions/Particle3D/PU/CCPUObserver.h index 06afd0e012..8103d157b9 100644 --- a/extensions/Particle3D/PU/CCPUObserver.h +++ b/extensions/Particle3D/PU/CCPUObserver.h @@ -159,7 +159,7 @@ public: bool getObserveUntilEvent(void) const; /** Sets the value of mObserveUntilEvent. This value determines whether observation must be continued - after an event ocurred and the event handlers are called. + after an event occurred and the event handlers are called. */ void setObserveUntilEvent(bool observeUntilEvent); diff --git a/extensions/Particle3D/PU/CCPURandomiserTranslator.cpp b/extensions/Particle3D/PU/CCPURandomiserTranslator.cpp index 1c734cc23d..27d4162237 100644 --- a/extensions/Particle3D/PU/CCPURandomiserTranslator.cpp +++ b/extensions/Particle3D/PU/CCPURandomiserTranslator.cpp @@ -55,7 +55,7 @@ bool PURandomiserTranslator::translateChildProperty( PUScriptCompiler* compiler, } else if (prop->name == token[TOKEN_RND_MAX_DEVIATION_X]) { - // Property: rand_aff_max_deviation_x (depreacted and replaced by 'max_deviation_x') + // Property: rand_aff_max_deviation_x (deprecated and replaced by 'max_deviation_x') if (passValidateProperty(compiler, prop, token[TOKEN_RND_MAX_DEVIATION_X], VAL_REAL)) { float val = 0.0f; diff --git a/extensions/Particle3D/PU/CCPUTechniqueTranslator.cpp b/extensions/Particle3D/PU/CCPUTechniqueTranslator.cpp index 4425a63518..0c2149173f 100644 --- a/extensions/Particle3D/PU/CCPUTechniqueTranslator.cpp +++ b/extensions/Particle3D/PU/CCPUTechniqueTranslator.cpp @@ -89,7 +89,7 @@ void PUTechniqueTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode } else if (prop->name == token[TOKEN_POSITION]) { - // Property: positon + // Property: position if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) { Vec3 val; diff --git a/extensions/Particle3D/PU/CCPUTextureRotator.h b/extensions/Particle3D/PU/CCPUTextureRotator.h index ec9504c5a7..3dc1b71f9f 100644 --- a/extensions/Particle3D/PU/CCPUTextureRotator.h +++ b/extensions/Particle3D/PU/CCPUTextureRotator.h @@ -62,7 +62,7 @@ public: */ void setRotationSpeed(PUDynamicAttribute* dynRotationSpeed); - /** Returns the rotation defined in the the affector. + /** Returns the rotation defined in the affector. */ PUDynamicAttribute* getRotation(void) const; diff --git a/extensions/Particle3D/PU/CCPUVertexEmitter.h b/extensions/Particle3D/PU/CCPUVertexEmitter.h index 4945d66047..7940d36082 100644 --- a/extensions/Particle3D/PU/CCPUVertexEmitter.h +++ b/extensions/Particle3D/PU/CCPUVertexEmitter.h @@ -62,9 +62,9 @@ NS_CC_BEGIN // /** Defines the speed of generating spawnpoints. In each Particle Technique update // 'mIterations' vertices are traversed. // @remarks -// Setting this attribute to a higher value is needed if the emssion rate of the emitter +// Setting this attribute to a higher value is needed if the emission rate of the emitter // is high. On slower computers, emitting the particles may exceed generating the -// spawnpoints (because this is not done at once, but per Particle Tehcnique update). +// spawnpoints (because this is not done at once, but per Particle Technique update). // */ // unsigned short mIterations; // diff --git a/extensions/assets-manager/AssetsManager.cpp b/extensions/assets-manager/AssetsManager.cpp index 50b71da88b..962019fcee 100644 --- a/extensions/assets-manager/AssetsManager.cpp +++ b/extensions/assets-manager/AssetsManager.cpp @@ -253,7 +253,7 @@ void AssetsManager::downloadAndUncompress() void AssetsManager::update() { // all operation in checkUpdate, nothing need to do - // keep this function for compatiblity + // keep this function for compatibility } bool AssetsManager::uncompress() @@ -308,8 +308,8 @@ bool AssetsManager::uncompress() const size_t filenameLength = strlen(fileName); if (fileName[filenameLength-1] == '/') { - // Entry is a direcotry, so create it. - // If the directory exists, it will failed scilently. + // Entry is a directory, so create it. + // If the directory exists, it will failed silently. if (!FileUtils::getInstance()->createDirectory(fullPath)) { CCLOG("can not create directory %s", fullPath.c_str()); diff --git a/extensions/assets-manager/AssetsManager.h b/extensions/assets-manager/AssetsManager.h index 23d55ac7ce..f3452650b2 100644 --- a/extensions/assets-manager/AssetsManager.h +++ b/extensions/assets-manager/AssetsManager.h @@ -55,7 +55,7 @@ public: // Error caused by creating a file to store downloaded data CREATE_FILE, /** Error caused by network - -- network unavaivable + -- network unavailable -- timeout -- ... */ diff --git a/extensions/assets-manager/AssetsManagerEx.cpp b/extensions/assets-manager/AssetsManagerEx.cpp index 58e8e82ae1..936dcf0b96 100644 --- a/extensions/assets-manager/AssetsManagerEx.cpp +++ b/extensions/assets-manager/AssetsManagerEx.cpp @@ -833,7 +833,7 @@ void AssetsManagerEx::onError(const network::DownloadTask& task, int errorCodeInternal, const std::string& errorStr) { - // Skip version error occured + // Skip version error occurred if (task.identifier == VERSION_ID) { CCLOG("AssetsManagerEx : Fail to download version file, step skipped\n"); diff --git a/extensions/assets-manager/AssetsManagerEx.h b/extensions/assets-manager/AssetsManagerEx.h index 1fd166d26b..4dbfec62fc 100644 --- a/extensions/assets-manager/AssetsManagerEx.h +++ b/extensions/assets-manager/AssetsManagerEx.h @@ -149,7 +149,7 @@ protected: */ const DownloadUnits& getFailedAssets() const; - /** @brief Function for destorying the downloaded version file and manifest file + /** @brief Function for destroying the downloaded version file and manifest file */ void destroyDownloadedVersion(); From 8df13ad6f9866b6bdb31da1b113a76e002b8364a Mon Sep 17 00:00:00 2001 From: mogemimi Date: Sat, 12 Dec 2015 00:43:19 +0900 Subject: [PATCH 14/28] Replace non-ASCII characters in comments --- extensions/GUI/CCControlExtension/CCControl.h | 8 ++++---- extensions/Particle3D/PU/CCPUAffector.h | 2 +- .../Particle3D/PU/CCPUDoPlacementParticleEventHandler.h | 4 ++-- extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h | 2 +- extensions/Particle3D/PU/CCPUObserver.h | 4 ++-- extensions/Particle3D/PU/CCPUOnClearObserver.h | 6 +++--- extensions/Particle3D/PU/CCPUParticleSystem3D.cpp | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCControl.h b/extensions/GUI/CCControlExtension/CCControl.h index 8b89a693fa..7c25caec6b 100644 --- a/extensions/GUI/CCControlExtension/CCControl.h +++ b/extensions/GUI/CCControlExtension/CCControl.h @@ -84,7 +84,7 @@ public: /** The possible state for a control. */ enum class State { - NORMAL = 1 << 0, // The normal, or default state of a control¡ªthat is, enabled but neither selected nor highlighted. + NORMAL = 1 << 0, // The normal, or default state of a control that is, enabled but neither selected nor highlighted. HIGH_LIGHTED = 1 << 1, // Highlighted state of a control. A control enters this state when a touch down, drag inside or drag enter is performed. You can retrieve and set this value through the highlighted property. DISABLED = 1 << 2, // Disabled state of a control. This state indicates that the control is currently disabled. You can retrieve and set this value through the enabled property. SELECTED = 1 << 3 // Selected state of a control. This state indicates that the control is currently selected. You can retrieve and set this value through the selected property. @@ -138,7 +138,7 @@ public: * Removes a target and action for a particular event (or events) from an * internal dispatch table. * - * @param target The target object—that is, the object to which the action + * @param target The target object that is, the object to which the action * message is sent. Pass nil to remove all targets paired with action and the * specified control events. * @param action A selector identifying an action message. Pass NULL to remove @@ -221,7 +221,7 @@ protected: * parameters, in that order. * When you call this method, target is not retained. * - * @param target The target object¡ªthat is, the object to which the action + * @param target The target object that is, the object to which the action * message is sent. It cannot be nil. The target is not retained. * @param action A selector identifying an action message. It cannot be NULL. * @param controlEvent A control event for which the action message is sent. @@ -233,7 +233,7 @@ protected: * Removes a target and action for a particular event from an internal dispatch * table. * - * @param target The target object¡ªthat is, the object to which the action + * @param target The target object that is, the object to which the action * message is sent. Pass nil to remove all targets paired with action and the * specified control events. * @param action A selector identifying an action message. Pass NULL to remove diff --git a/extensions/Particle3D/PU/CCPUAffector.h b/extensions/Particle3D/PU/CCPUAffector.h index 87d9bf3f1d..e1c564fd90 100644 --- a/extensions/Particle3D/PU/CCPUAffector.h +++ b/extensions/Particle3D/PU/CCPUAffector.h @@ -119,7 +119,7 @@ protected: /** Although the scale is on a Particle System level, the affector can also be scaled. */ Vec3 _affectorScale; - /** Because the public attribute ´position?is sometimes used for both localspace and worldspace + /** Because the public attribute position is sometimes used for both localspace and worldspace position, the mDerivedPosition attribute is introduced. */ Vec3 _derivedPosition; diff --git a/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h b/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h index 82bf9a3597..d3bded8a11 100644 --- a/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h +++ b/extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h @@ -143,14 +143,14 @@ protected: /** Store the technique value to keep up to speed. @remarks - If the ParticleTechnique has been destroyed, the DoPlacementParticleEventHandler isn´t automatically + If the ParticleTechnique has been destroyed, the DoPlacementParticleEventHandler isn't automatically notified. Using the pointer causes an exception. */ PUParticleSystem3D* _system; /** Store the emitter value to keep up to speed. @remarks - If the ParticleEmitter has been destroyed, the DoPlacementParticleEventHandler isn´t automatically + If the ParticleEmitter has been destroyed, the DoPlacementParticleEventHandler isn't automatically notified. Using the pointer causes an exception. */ PUEmitter* _emitter; diff --git a/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h b/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h index f58224edfd..a779fa174b 100644 --- a/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h +++ b/extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h @@ -133,7 +133,7 @@ public: /** Destructor **/ ~MeshInfo (void); - /** Generate a random number. The ´high?argument determines that numbers are + /** Generate a random number. The high argument determines that numbers are returned between [0..high] **/ float getGaussianRandom (float high, float cutoff = 4); diff --git a/extensions/Particle3D/PU/CCPUObserver.h b/extensions/Particle3D/PU/CCPUObserver.h index 8103d157b9..1939254d2e 100644 --- a/extensions/Particle3D/PU/CCPUObserver.h +++ b/extensions/Particle3D/PU/CCPUObserver.h @@ -213,8 +213,8 @@ protected: // Particle type to be observed. Default is that all particles are observed. PUParticle3D::ParticleType _particleTypeToObserve; - /** Determines whether mParticleTypeToObserve is set. If ´true? only that particles of the specified type - are observed. If ´false?(= default), all particles are observed. + /** Determines whether mParticleTypeToObserve is set. If true only that particles of the specified type + are observed. If false (= default), all particles are observed. */ bool _particleTypeToObserveSet; diff --git a/extensions/Particle3D/PU/CCPUOnClearObserver.h b/extensions/Particle3D/PU/CCPUOnClearObserver.h index b54ffc97bd..be06b9cbff 100644 --- a/extensions/Particle3D/PU/CCPUOnClearObserver.h +++ b/extensions/Particle3D/PU/CCPUOnClearObserver.h @@ -50,13 +50,13 @@ public: */ virtual bool observe (PUParticle3D* particle, float timeElapsed) override; - /** The _processParticle() function is overridden, because we don´t observe an individual particle. - even if there isn´t a particle left anymore (and that is the situation we want to validate). + /** The _processParticle() function is overridden, because we don't observe an individual particle. + even if there isn't a particle left anymore (and that is the situation we want to validate). */ virtual void updateObserver(PUParticle3D* particle, float timeElapsed, bool firstParticle) override; /** Instead of the _processParticle(), the _postProcessParticles() is used because it is called - even if there isn´t a particle left anymore (and that is the situation we want to validate). + even if there isn't a particle left anymore (and that is the situation we want to validate). */ virtual void postUpdateObserver(float timeElapsed) override; diff --git a/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp b/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp index 13542a0609..5281b66a1c 100755 --- a/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp +++ b/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp @@ -1011,7 +1011,7 @@ void PUParticleSystem3D::initParticleForExpiration( PUParticle3D* particle, floa it->particleExpired(this, particle); } ///** Externs are also called to perform expiration activities. If needed, affectors and emitters may be added, but at the moment - // there is no reason for (and we don´t want to waste cpu resources). + // there is no reason for (and we don't want to waste cpu resources). //*/ //if (!mExterns.empty()) //{ From 07673f71cd5c108aff0c28cb705fc505b0100089 Mon Sep 17 00:00:00 2001 From: mogemimi Date: Wed, 18 Nov 2015 01:39:43 +0900 Subject: [PATCH 15/28] Fix inconsistent header include guards --- cocos/2d/CCComponent.h | 2 +- cocos/2d/CCComponentContainer.h | 2 +- cocos/editor-support/cocostudio/CCComAttribute.h | 2 +- cocos/editor-support/cocostudio/CCComAudio.h | 2 +- cocos/editor-support/cocostudio/CCComController.h | 2 +- cocos/editor-support/cocostudio/CCComRender.h | 2 +- cocos/editor-support/cocostudio/CCInputDelegate.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cocos/2d/CCComponent.h b/cocos/2d/CCComponent.h index 89f8d8801a..7a247f8b8b 100644 --- a/cocos/2d/CCComponent.h +++ b/cocos/2d/CCComponent.h @@ -91,4 +91,4 @@ protected: NS_CC_END /// @endcond -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_FRAMEWORK_COMPONENT_H__ diff --git a/cocos/2d/CCComponentContainer.h b/cocos/2d/CCComponentContainer.h index 89380f4749..ac6ee19100 100644 --- a/cocos/2d/CCComponentContainer.h +++ b/cocos/2d/CCComponentContainer.h @@ -75,4 +75,4 @@ private: NS_CC_END /// @endcond -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_FRAMEWORK_COMCONTAINER_H__ diff --git a/cocos/editor-support/cocostudio/CCComAttribute.h b/cocos/editor-support/cocostudio/CCComAttribute.h index 48fc113fa8..a49a50b73b 100644 --- a/cocos/editor-support/cocostudio/CCComAttribute.h +++ b/cocos/editor-support/cocostudio/CCComAttribute.h @@ -69,4 +69,4 @@ private: } -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_EXTENTIONS_CCCOMATTRIBUTE_H__ diff --git a/cocos/editor-support/cocostudio/CCComAudio.h b/cocos/editor-support/cocostudio/CCComAudio.h index 4bbd190780..65b4016903 100644 --- a/cocos/editor-support/cocostudio/CCComAudio.h +++ b/cocos/editor-support/cocostudio/CCComAudio.h @@ -112,4 +112,4 @@ private: } -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_EXTENTIONS_CCCOMAUDIO_H__ diff --git a/cocos/editor-support/cocostudio/CCComController.h b/cocos/editor-support/cocostudio/CCComController.h index 2c92345f93..957191508e 100644 --- a/cocos/editor-support/cocostudio/CCComController.h +++ b/cocos/editor-support/cocostudio/CCComController.h @@ -82,4 +82,4 @@ public: } -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_EXTENTIONS_CCCOMCONTROLLER_H__ diff --git a/cocos/editor-support/cocostudio/CCComRender.h b/cocos/editor-support/cocostudio/CCComRender.h index 1e1a048391..1048e3742d 100644 --- a/cocos/editor-support/cocostudio/CCComRender.h +++ b/cocos/editor-support/cocostudio/CCComRender.h @@ -84,4 +84,4 @@ private: }; } -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_EXTENTIONS_CCCOMRENDER_H__ diff --git a/cocos/editor-support/cocostudio/CCInputDelegate.h b/cocos/editor-support/cocostudio/CCInputDelegate.h index 13dbd2df92..53e9cf5873 100644 --- a/cocos/editor-support/cocostudio/CCInputDelegate.h +++ b/cocos/editor-support/cocostudio/CCInputDelegate.h @@ -162,4 +162,4 @@ private: } -#endif // __FUNDATION__CCCOMPONENT_H__ +#endif // __CC_EXTENTIONS_CCINPUTDELEGATE_H__ From 0473dd88fc07429b597ad041cf926986492531c0 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Sun, 13 Dec 2015 03:12:14 +0000 Subject: [PATCH 16/28] [ci skip][AUTO]: updating luabinding & jsbinding automatically --- cocos/scripting/lua-bindings/auto/api/Control.lua | 2 +- cocos/scripting/lua-bindings/auto/api/ControlButton.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/scripting/lua-bindings/auto/api/Control.lua b/cocos/scripting/lua-bindings/auto/api/Control.lua index 33b609aa68..d9d0567921 100644 --- a/cocos/scripting/lua-bindings/auto/api/Control.lua +++ b/cocos/scripting/lua-bindings/auto/api/Control.lua @@ -75,7 +75,7 @@ -- @return Control#Control self (return value: cc.Control) -------------------------------- --- Returns a point corresponding to the touh location converted into the
+-- Returns a point corresponding to the touch location converted into the
-- control space coordinates.
-- param touch A Touch object that represents a touch. -- @function [parent=#Control] getTouchLocation diff --git a/cocos/scripting/lua-bindings/auto/api/ControlButton.lua b/cocos/scripting/lua-bindings/auto/api/ControlButton.lua index f39bb2ef25..9da8d10e83 100644 --- a/cocos/scripting/lua-bindings/auto/api/ControlButton.lua +++ b/cocos/scripting/lua-bindings/auto/api/ControlButton.lua @@ -145,7 +145,7 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- Sets the font of the label, changes the label to a BMFont if neccessary.
+-- Sets the font of the label, changes the label to a BMFont if necessary.
-- param fntFile The name of the font to change to
-- param state The state that uses the specified fntFile. The values are described
-- in "CCControlState". From b1d700ad33f882a7b99e8e5a00160fab47a36d22 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Sun, 13 Dec 2015 13:59:42 +0800 Subject: [PATCH 17/28] fix bmfont size error --- cocos/2d/CCLabel.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index ccf3e09c54..cfcbd019dc 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -591,9 +591,7 @@ bool Label::setBMFontFilePath(const std::string& bmfontFilePath, const Vec2& ima FontFNT *bmFont = (FontFNT*)newAtlas->getFont(); if (bmFont) { float originalFontSize = bmFont->getOriginalFontSize(); - if(fabs(_bmFontSize+1) < FLT_EPSILON){ - _bmFontSize = originalFontSize / CC_CONTENT_SCALE_FACTOR(); - } + _bmFontSize = originalFontSize / CC_CONTENT_SCALE_FACTOR(); } } From 8c9b03112e5880723797d5a0d10fd2abe6ce10b6 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 14 Dec 2015 10:09:06 +0800 Subject: [PATCH 18/28] fix scale9sprite global zorder issue. 1. it also fix the positiong issue when call setScale9Enabled(false) --- cocos/ui/UIScale9Sprite.cpp | 20 ++++- cocos/ui/UIScale9Sprite.h | 5 +- .../CocoStudioGUITest/UIScale9SpriteTest.cpp | 82 +++++++++++++++++++ .../CocoStudioGUITest/UIScale9SpriteTest.h | 16 ++++ 4 files changed, 121 insertions(+), 2 deletions(-) diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 91454b8058..aef00adf7a 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -670,7 +670,7 @@ namespace ui { void Scale9Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { - if (_scale9Image) { + if (_scale9Image && _scale9Enabled) { #if CC_USE_CULLING // Don't do calculate the culling if the transform was not updated auto visitingCamera = Camera::getVisitingCamera(); @@ -757,12 +757,21 @@ namespace ui { else break; } + + if (!_scale9Enabled && _scale9Image && _scale9Image->getLocalZOrder() < 0 ) + { + _scale9Image->visit(renderer, _modelViewTransform, flags); + } // draw self // if (isVisitableByVisitingCamera()) this->draw(renderer, _modelViewTransform, flags); + if (!_scale9Enabled && _scale9Image && _scale9Image->getLocalZOrder() >= 0 ) + { + _scale9Image->visit(renderer, _modelViewTransform, flags); + } for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); @@ -1336,5 +1345,14 @@ namespace ui { CC_SAFE_RELEASE_NULL(this->_scale9Image); } + + void Scale9Sprite::setGlobalZOrder(float globalZOrder) + { + Node::setGlobalZOrder(globalZOrder); + if (_scale9Image) + { + _scale9Image->setGlobalZOrder(globalZOrder); + } + } }} diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index 7a36a5f1de..0908c5f93f 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -577,6 +577,8 @@ namespace ui { /** * @brief Toggle 9-slice feature. * If Scale9Sprite is 9-slice disabled, the Scale9Sprite will rendered as a normal sprite. + * @waring: Don't use setScale9Enabled(false), use setRenderingType(RenderingType::SIMPLE) instead. + * The setScale9Enabled(false) is kept only for back back compatibility. * @param enabled True to enable 9-slice, false otherwise. * @js NA */ @@ -657,7 +659,8 @@ namespace ui { virtual float getScale() const override; using Node::getScaleZ; virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; - + virtual void setGlobalZOrder(float globalZOrder) override; + /** * Set the slice sprite rendering type. * When setting to SIMPLE, only 4 vertexes is used to rendering. diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp index 408c61f91b..4357efc8ef 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp @@ -55,6 +55,8 @@ UIScale9SpriteTests::UIScale9SpriteTests() ADD_TEST_CASE(UIS9NinePatchTest); ADD_TEST_CASE(UIS9BatchTest); ADD_TEST_CASE(UIS9ToggleRenderingTypeTest); + ADD_TEST_CASE(UIS9GlobalZOrderTest); + ADD_TEST_CASE(UIS9EnableScale9FalseTest); } // UIScale9SpriteTest @@ -92,6 +94,7 @@ bool UIScale9SpriteTest::init() normalSprite2->setPosition(120, 270); normalSprite2->setScale9Enabled(false); normalSprite2->setOpacity(100); + normalSprite2->setContentSize(normalSprite2->getContentSize() * 2); this->addChild(normalSprite2); normalSprite2->setColor(Color3B::GREEN); normalSprite2->runAction(action); @@ -994,3 +997,82 @@ bool UIS9ToggleRenderingTypeTest::init() return false; } + +bool UIS9GlobalZOrderTest::init() +{ + if (UIScene::init()) { + + auto winSize = Director::getInstance()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2 - 20); + + auto label = Label::createWithSystemFont("The green scale9sprite is in the back.", "Arial", 15); + label->setPosition(Vec2(winSize.width/2, winSize.height - 60)); + this->addChild(label); + + auto blocks = ui::Scale9Sprite::create("Images/blocks9.png"); + + blocks->setPosition(Vec2(x, y)); + blocks->setPreferredSize(Size(96*2, 96*1.5)); + blocks->setColor(Color3B::RED); + blocks->setGlobalZOrder(1); + this->addChild(blocks); + + + auto blocks2 = ui::Scale9Sprite::create("Images/blocks9.png"); + blocks2->setPosition(Vec2(x, y)); + blocks2->setPreferredSize(Size(96*3, 96)); + blocks2->setGlobalZOrder(0); + blocks2->setColor(Color3B::GREEN); + this->addChild(blocks2); + + + return true; + } + return false; +} + + +bool UIS9EnableScale9FalseTest::init() +{ + if (UIScene::init()) { + + auto winSize = Director::getInstance()->getWinSize(); + float x = winSize.width / 2 + 50; + float y = 0 + (winSize.height / 2 + 10); + + auto label = Label::createWithSystemFont("Only the yellow block intersect with the green one.", "Arial", 15); + label->setPosition(Vec2(winSize.width/2, winSize.height - 60)); + this->addChild(label); + + auto blocks = ui::Scale9Sprite::create("Images/blocks9.png"); + blocks->setScale9Enabled(false); + blocks->setPosition(Vec2(x, y)); + blocks->setPreferredSize(Size(96*2, 96)); + blocks->setColor(Color3B::RED); + blocks->setGlobalZOrder(1); + this->addChild(blocks); + + + auto blocks2 = ui::Scale9Sprite::create("Images/blocks9.png"); + blocks2->setScale9Enabled(false); + blocks2->setPosition(Vec2(0, 0)); + blocks2->setPreferredSize(Size(96*1.5, 96)); + blocks2->setGlobalZOrder(0); + blocks2->setColor(Color3B::GREEN); + blocks->addChild(blocks2); + + auto blocks3 = ui::Scale9Sprite::create("Images/blocks9.png"); + blocks3->setScale9Enabled(false); + blocks3->setPosition(Vec2(0, 0)); + blocks3->setPreferredSize(Size(96, 96)); + blocks3->setGlobalZOrder(2); + blocks3->setColor(Color3B::YELLOW); + blocks2->addChild(blocks3); + + + return true; + } + return false; +} + diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h index 87b328bf9c..66e6d238df 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.h @@ -274,4 +274,20 @@ public: virtual bool init() override; }; +class UIS9GlobalZOrderTest: public UIScene +{ +public: + CREATE_FUNC(UIS9GlobalZOrderTest); + + virtual bool init() override; +}; + +class UIS9EnableScale9FalseTest: public UIScene +{ +public: + CREATE_FUNC(UIS9EnableScale9FalseTest); + + virtual bool init() override; +}; + #endif /* defined(__cocos2d_tests__UIScale9SpriteTest__) */ From 0f5aac57549209012b3cf71ca4ec2e1346934f67 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 14 Dec 2015 10:14:39 +0800 Subject: [PATCH 19/28] fix typo --- cocos/ui/UIScale9Sprite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index 0908c5f93f..4404ac9a64 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -577,7 +577,7 @@ namespace ui { /** * @brief Toggle 9-slice feature. * If Scale9Sprite is 9-slice disabled, the Scale9Sprite will rendered as a normal sprite. - * @waring: Don't use setScale9Enabled(false), use setRenderingType(RenderingType::SIMPLE) instead. + * @warning: Don't use setScale9Enabled(false), use setRenderingType(RenderingType::SIMPLE) instead. * The setScale9Enabled(false) is kept only for back back compatibility. * @param enabled True to enable 9-slice, false otherwise. * @js NA From 445442c964297a9970e268b06b7ecf25e5c93610 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 14 Dec 2015 10:27:11 +0800 Subject: [PATCH 20/28] Upgrade spider monkey to solve win32 js project crash issue --- cocos/scripting/js-bindings/manual/ScriptingCore.cpp | 6 +++--- cocos/scripting/js-bindings/manual/ScriptingCore.h | 2 +- external/config.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 19354fa161..ae2481d067 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -1869,14 +1869,14 @@ void ScriptingCore::enableDebugger(unsigned int port) } } -JS::HandleObject NewGlobalObject(JSContext* cx, bool debug) +JSObject* NewGlobalObject(JSContext* cx, bool debug) { JS::CompartmentOptions options; options.setVersion(JSVERSION_LATEST); JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, &shellTrustedPrincipals, JS::DontFireOnNewGlobalHook, options)); if (!glob) { - return JS::NullPtr(); + return nullptr; } JSAutoCompartment ac(cx, glob); bool ok = true; @@ -1886,7 +1886,7 @@ JS::HandleObject NewGlobalObject(JSContext* cx, bool debug) if (ok && debug) ok = JS_DefineDebuggerObject(cx, glob); if (!ok) - return JS::NullPtr(); + return nullptr; JS_FireOnNewGlobalObject(cx, glob); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index b9ac8b295c..336909455c 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -517,7 +517,7 @@ public: void restartVM(); }; -JS::HandleObject NewGlobalObject(JSContext* cx, bool debug = false); +JSObject* NewGlobalObject(JSContext* cx, bool debug = false); bool jsb_set_reserved_slot(JSObject *obj, uint32_t idx, jsval value); bool jsb_get_reserved_slot(JSObject *obj, uint32_t idx, jsval& ret); diff --git a/external/config.json b/external/config.json index 4c7cebe515..0739cd1c10 100644 --- a/external/config.json +++ b/external/config.json @@ -1,6 +1,6 @@ { - "version":"v3-deps-78", - "zip_file_size":"119277304", + "version":"v3-deps-79", + "zip_file_size":"124402591", "repo_name":"cocos2d-x-3rd-party-libs-bin", "repo_parent":"https://github.com/cocos2d/", "move_dirs":{ From 3e64e09e6934a35f5559c44c1edd73879cd5271d Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 14 Dec 2015 10:40:09 +0800 Subject: [PATCH 21/28] fix memory leaks of stencileStateManager --- cocos/2d/CCClippingNode.cpp | 1 + cocos/ui/UILayout.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 8557203765..2f7db66030 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -67,6 +67,7 @@ ClippingNode::~ClippingNode() _stencil->stopAllActions(); _stencil->release(); } + CC_SAFE_DELETE(_stencilStateManager); } ClippingNode* ClippingNode::create() diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index b1643eff7e..81ae344ed5 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -87,6 +87,7 @@ _isFocusPassing(false) Layout::~Layout() { CC_SAFE_RELEASE(_clippingStencil); + CC_SAFE_DELETE(_stencileStateManager); } void Layout::onEnter() From 436db6e9325541b6cc9cb6d8dc074e0f3e111d74 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Mon, 14 Dec 2015 11:20:26 +0800 Subject: [PATCH 22/28] Fix #24347 JSTest(web)-->UI Test-->UIFocus-->UIFocusTestVertical displays focus first. --- tests/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js b/tests/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js index 5b172dae05..27ea0e2164 100644 --- a/tests/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js +++ b/tests/js-tests/src/GUITest/UIFocusTest/UIFocusTest.js @@ -188,8 +188,6 @@ var UIFocusTestVertical = UIFocusTestBase.extend({ w.setTag(i); w.addTouchEventListener(this.onImageViewClicked, this); this._verticalLayout.addChild(w); - if (i == 2) - w.requestFocus(); } this._loopText = new ccui.Text("loop enabled", "Arial", 20); From 838bd242ce54595461e3480a8f451e276de5798b Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 14 Dec 2015 11:53:09 +0800 Subject: [PATCH 23/28] fix #12249 --- cocos/ui/UIButton.cpp | 2 +- cocos/ui/UIImageView.cpp | 2 +- cocos/ui/UILoadingBar.cpp | 2 +- cocos/ui/UISlider.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index c877a70eac..ab034d18b4 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -256,7 +256,7 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType) } } //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize) { + if (!_ignoreSize && _customSize.equals(Size::ZERO)) { _customSize = _buttonNormalRenderer->getContentSize(); } this->setupNormalTexture(textureLoaded); diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 79c12adf36..d9af32b8a9 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -137,7 +137,7 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType) break; } //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize) { + if (!_ignoreSize && _customSize.equals(Size::ZERO)) { _customSize = _imageRenderer->getContentSize(); } this->setupTexture(); diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index dd1d040947..d96f141369 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -163,7 +163,7 @@ void LoadingBar::loadTexture(const std::string& texture,TextureResType texType) } //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize) { + if (!_ignoreSize && _customSize.equals(Size::ZERO)) { _customSize = _barRenderer->getContentSize(); } this->setupTexture(); diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp index 20909e73ca..07ca7c3077 100644 --- a/cocos/ui/UISlider.cpp +++ b/cocos/ui/UISlider.cpp @@ -172,7 +172,7 @@ void Slider::loadBarTexture(const std::string& fileName, TextureResType texType) } } //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize) { + if (!_ignoreSize && _customSize.equals(Size::ZERO)) { _customSize = _barRenderer->getContentSize(); } this->setupBarTexture(); From 330b588215da65b04ee430528151bc212d5fc877 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 14 Dec 2015 13:13:54 +0800 Subject: [PATCH 24/28] Fix evalString doesn't return result issue --- cocos/scripting/js-bindings/manual/ScriptingCore.cpp | 10 ++-------- cocos/scripting/js-bindings/manual/ScriptingCore.h | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index ae2481d067..85fb7e0c9d 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -500,16 +500,10 @@ void ScriptingCore::string_report(JS::HandleValue val) { } } -bool ScriptingCore::evalString(const char *string, jsval *outVal, const char *filename, JSContext* cx, JSObject* global) +bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal, JSContext* cx, JS::HandleObject global, const char *filename) { - if (cx == NULL) - cx = _cx; - if (global == NULL) - global = _global.ref().get(); - JSAutoCompartment ac(cx, global); - JS::RootedObject jsglobal(cx, global); - return JS_EvaluateScript(cx, jsglobal, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1); + return JS_EvaluateScript(cx, global, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1, outVal); } void ScriptingCore::start() diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index 336909455c..e167569cb8 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -234,7 +234,7 @@ public: * @param global @~english The js global object * @return @~english Return true if successfully invoked, otherwise return false. */ - bool evalString(const char *string, jsval *outVal, const char *filename = NULL, JSContext* cx = NULL, JSObject* global = NULL); + bool evalString(const char *string, JS::MutableHandleValue outVal, JSContext* cx, JS::HandleObject global, const char *filename = NULL); /** @brief @~english Get script object for the given path From 662c7fbec50e7a6802cb6febe8db5cc05a255ca2 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 14 Dec 2015 13:55:17 +0800 Subject: [PATCH 25/28] Made API consistent with old version --- .../js-bindings/manual/ScriptingCore.cpp | 13 ++++++++++++- .../js-bindings/manual/ScriptingCore.h | 17 ++++++++++++++++- .../platform/android/CCJavascriptJavaBridge.cpp | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 85fb7e0c9d..aab6456212 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -500,12 +500,23 @@ void ScriptingCore::string_report(JS::HandleValue val) { } } -bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal, JSContext* cx, JS::HandleObject global, const char *filename) +bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal, const char *filename, JSContext* cx, JS::HandleObject global) { JSAutoCompartment ac(cx, global); return JS_EvaluateScript(cx, global, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1, outVal); } +bool ScriptingCore::evalString(const char *string, JS::MutableHandleValue outVal) +{ + return evalString(string, outVal, nullptr, _cx, _global.ref()); +} + +bool ScriptingCore::evalString(const char *string) +{ + JS::RootedValue retVal(_cx); + return evalString(string, &retVal); +} + void ScriptingCore::start() { // for now just this diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.h b/cocos/scripting/js-bindings/manual/ScriptingCore.h index e167569cb8..748694e518 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.h +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.h @@ -234,7 +234,22 @@ public: * @param global @~english The js global object * @return @~english Return true if successfully invoked, otherwise return false. */ - bool evalString(const char *string, JS::MutableHandleValue outVal, JSContext* cx, JS::HandleObject global, const char *filename = NULL); + bool evalString(const char *string, JS::MutableHandleValue outVal, const char *filename, JSContext* cx, JS::HandleObject global); + + /**@~english + * Evaluate the specified js code string + * @param string @~english The string with the javascript code to be evaluated + * @param outVal @~english The jsval that will hold the return value of the evaluation. + * @return @~english Return true if successfully invoked, otherwise return false. + */ + bool evalString(const char *string, JS::MutableHandleValue outVal); + + /**@~english + * Evaluate the specified js code string + * @param string @~english The string with the javascript code to be evaluated + * @return @~english Return true if successfully invoked, otherwise return false. + */ + bool evalString(const char *string); /** @brief @~english Get script object for the given path diff --git a/cocos/scripting/js-bindings/manual/platform/android/CCJavascriptJavaBridge.cpp b/cocos/scripting/js-bindings/manual/platform/android/CCJavascriptJavaBridge.cpp index 8b65563ebf..419dc4b603 100644 --- a/cocos/scripting/js-bindings/manual/platform/android/CCJavascriptJavaBridge.cpp +++ b/cocos/scripting/js-bindings/manual/platform/android/CCJavascriptJavaBridge.cpp @@ -46,7 +46,7 @@ JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge_evalSt CCLOG("Cocos2dxJavascriptJavaBridge_evalString error, invalid string code"); return 0; } - ScriptingCore::getInstance()->evalString(strValue.c_str(), nullptr); + ScriptingCore::getInstance()->evalString(strValue.c_str()); return 1; } From 23bf815cfab7cf5274ab87fdc7146be5b060bfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E5=B3=B0?= Date: Mon, 14 Dec 2015 14:26:52 +0800 Subject: [PATCH 26/28] Fix 3d touch compile error in lower version Xcode --- cocos/platform/ios/CCEAGLView-ios.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cocos/platform/ios/CCEAGLView-ios.mm b/cocos/platform/ios/CCEAGLView-ios.mm index eb4947bd5f..89894b21c9 100644 --- a/cocos/platform/ios/CCEAGLView-ios.mm +++ b/cocos/platform/ios/CCEAGLView-ios.mm @@ -427,8 +427,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. ids[i] = touch; xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;; - -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0 // Use 9.0 or higher SDK to compile +#ifdef __IPHONE_9_0 && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0 // running on iOS 9.0 or higher version if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0f) { fs[i] = touch.force; From 508d54ec3c2c8e12a23ad8dc600508d70f72840d Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 14 Dec 2015 15:29:02 +0800 Subject: [PATCH 27/28] fix pageview child size --- cocos/ui/UIListView.h | 2 +- cocos/ui/UIPageView.cpp | 5 ++ cocos/ui/UIPageView.h | 1 + .../UIPageViewTest/UIPageViewTest.cpp | 86 +++++++++++++++++++ .../UIPageViewTest/UIPageViewTest.h | 16 ++++ 5 files changed, 109 insertions(+), 1 deletion(-) diff --git a/cocos/ui/UIListView.h b/cocos/ui/UIListView.h index 0112cf585a..66e48efcf1 100644 --- a/cocos/ui/UIListView.h +++ b/cocos/ui/UIListView.h @@ -390,8 +390,8 @@ protected: virtual void onItemListChanged(); + virtual void remedyLayoutParameter(Widget* item); void updateInnerContainerSize(); - void remedyLayoutParameter(Widget* item); void remedyVerticalLayoutParameter(LinearLayoutParameter* layoutParameter, ssize_t itemIndex); void remedyHorizontalLayoutParameter(LinearLayoutParameter* layoutParameter,ssize_t itemIndex); diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index 17904d2c38..3fb95e8093 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -427,6 +427,11 @@ const Color3B& PageView::getIndicatorSelectedIndexColor() const return _indicator->getSelectedIndexColor(); } +void PageView::remedyLayoutParameter(Widget *item) +{ + item->setContentSize(this->getContentSize()); + ListView::remedyLayoutParameter(item); +} } diff --git a/cocos/ui/UIPageView.h b/cocos/ui/UIPageView.h index c2129ccdda..926eb936c4 100644 --- a/cocos/ui/UIPageView.h +++ b/cocos/ui/UIPageView.h @@ -350,6 +350,7 @@ CC_CONSTRUCTOR_ACCESS: protected: void pageTurningEvent(); + virtual void remedyLayoutParameter(Widget* item)override; virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override; virtual void onItemListChanged() override; virtual void onSizeChanged() override; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 20040dfdb2..7306c0d9a8 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -13,6 +13,7 @@ UIPageViewTests::UIPageViewTests() ADD_TEST_CASE(UIPageViewJumpToPageTest); ADD_TEST_CASE(UIPageViewVerticalTest); ADD_TEST_CASE(UIPageViewDisableTouchTest); + ADD_TEST_CASE(UIPageViewChildSizeTest); } // UIPageViewTest @@ -876,3 +877,88 @@ bool UIPageViewDisableTouchTest::init() return false; } +// UIPageViewTest +UIPageViewChildSizeTest::UIPageViewChildSizeTest() + : _displayValueLabel(nullptr) +{ + +} + +UIPageViewChildSizeTest::~UIPageViewChildSizeTest() +{ +} + +bool UIPageViewChildSizeTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the dragpanel events will be displayed + _displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + + _displayValueLabel->getContentSize().height * 1.5)); + _uiLayer->addChild(_displayValueLabel); + + // Add the black background + Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color3B(159, 168, 176)); + alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + Layout* root = static_cast(_uiLayer->getChildByTag(81)); + + Layout* background = dynamic_cast(root->getChildByName("background_Panel")); + + // Create the page view + Size size(240, 130); + PageView* pageView = PageView::create(); + pageView->setDirection(PageView::Direction::HORIZONTAL); + pageView->setContentSize(size); + Size backgroundSize = background->getContentSize(); + pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f); + pageView->removeAllItems(); + pageView->setIndicatorEnabled(true); + + int pageCount = 4; + for (int i = 0; i < pageCount; ++i) + { + ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png"); + imageView->setScale9Enabled(true); + + Text* label = Text::create(StringUtils::format("page %d", (i + 1)), "fonts/Marker Felt.ttf", 30); + label->setColor(Color3B(192, 192, 192)); + label->setAnchorPoint(Vec2::ZERO); + imageView->addChild(label); + + pageView->insertCustomItem(imageView, i); + } + + pageView->addEventListener(CC_CALLBACK_2(UIPageViewChildSizeTest::pageViewEvent, this)); + + _uiLayer->addChild(pageView); + + return true; + } + return false; +} + +void UIPageViewChildSizeTest::pageViewEvent(Ref *pSender, PageView::EventType type) +{ + switch (type) + { + case PageView::EventType::TURNING: + { + PageView* pageView = dynamic_cast(pSender); + + _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + } + break; + + default: + break; + } +} + diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h index 466b95673a..bc17231970 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h @@ -139,4 +139,20 @@ protected: cocos2d::ui::Text* _displayValueLabel; }; +class UIPageViewChildSizeTest : public UIScene +{ +public: + CREATE_FUNC(UIPageViewChildSizeTest); + + UIPageViewChildSizeTest(); + ~UIPageViewChildSizeTest(); + virtual bool init() override; + + void pageViewEvent(cocos2d::Ref* sender, cocos2d::ui::PageView::EventType type); + +protected: + + cocos2d::ui::Text* _displayValueLabel; +}; + #endif /* defined(__TestCpp__UIPageViewTest__) */ From 4d89508377d5c412e0e0a692dd35b119cc7f5921 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 14 Dec 2015 17:38:52 +0800 Subject: [PATCH 28/28] update for controlButton size --- .../GUI/CCControlExtension/CCControlButton.cpp | 16 ++++++++++++---- .../GUI/CCControlExtension/CCControlButton.h | 7 ++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCControlButton.cpp b/extensions/GUI/CCControlExtension/CCControlButton.cpp index 94035a91a4..99e371183a 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -120,6 +120,14 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprit } } +ControlButton* ControlButton::create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite) +{ + ControlButton *pRet = new (std::nothrow) ControlButton(); + pRet->initWithLabelAndBackgroundSprite(label, backgroundSprite, true); + pRet->autorelease(); + return pRet; +} + ControlButton* ControlButton::create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize) { ControlButton *pRet = new (std::nothrow) ControlButton(); @@ -141,16 +149,16 @@ ControlButton* ControlButton::create(const std::string& title, const std::string return pRet; } -bool ControlButton::initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize) +bool ControlButton::initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite) { Label *label = Label::createWithSystemFont("", "Arial", 30);// - return initWithLabelAndBackgroundSprite(label, sprite,adjustBackGroundSize); + return initWithLabelAndBackgroundSprite(label, sprite,false); } -ControlButton* ControlButton::create(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize) +ControlButton* ControlButton::create(cocos2d::ui::Scale9Sprite* sprite) { ControlButton *pRet = new (std::nothrow) ControlButton(); - pRet->initWithBackgroundSprite(sprite,adjustBackGroundSize); + pRet->initWithBackgroundSprite(sprite); pRet->autorelease(); return pRet; } diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 279ccce292..4f0abd14e6 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -55,9 +55,10 @@ class CC_EX_DLL ControlButton : public Control { public: static ControlButton* create(); - static ControlButton* create(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize = true); - static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize = true); + static ControlButton* create(cocos2d::ui::Scale9Sprite* sprite); + static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite); static ControlButton* create(const std::string& title, const std::string& fontName, float fontSize); + static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize); virtual void needsLayout(void) override; @@ -203,7 +204,7 @@ CC_CONSTRUCTOR_ACCESS: virtual bool init() override; virtual bool initWithLabelAndBackgroundSprite(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize); - virtual bool initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite, bool adjustBackGroundSize); + virtual bool initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite); virtual bool initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize); protected: