Merge branch 'v3.10' of github.com:cocos2d/cocos2d-x into v3.10

This commit is contained in:
pandamicro 2015-12-15 10:45:42 +08:00
commit ca45f9f69d
86 changed files with 1092 additions and 591 deletions

View File

@ -2,6 +2,8 @@ cocos2d-x-3.10 December ? 2015
[NEW] Core: Added Application::getVersion() to get the app version. [NEW] Core: Added Application::getVersion() to get the app version.
[NEW] UI: Add PageView indicator. [NEW] UI: Add PageView indicator.
[NEW] Label: Add three Overflow type to new label, see release note for more information. [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: RichText support new line element.
[REFINE] UI: Set focus to Widget when touched. [REFINE] UI: Set focus to Widget when touched.

View File

@ -67,6 +67,7 @@ ClippingNode::~ClippingNode()
_stencil->stopAllActions(); _stencil->stopAllActions();
_stencil->release(); _stencil->release();
} }
CC_SAFE_DELETE(_stencilStateManager);
} }
ClippingNode* ClippingNode::create() ClippingNode* ClippingNode::create()

View File

@ -91,4 +91,4 @@ protected:
NS_CC_END NS_CC_END
/// @endcond /// @endcond
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_FRAMEWORK_COMPONENT_H__

View File

@ -75,4 +75,4 @@ private:
NS_CC_END NS_CC_END
/// @endcond /// @endcond
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_FRAMEWORK_COMCONTAINER_H__

View File

@ -591,9 +591,7 @@ bool Label::setBMFontFilePath(const std::string& bmfontFilePath, const Vec2& ima
FontFNT *bmFont = (FontFNT*)newAtlas->getFont(); FontFNT *bmFont = (FontFNT*)newAtlas->getFont();
if (bmFont) { if (bmFont) {
float originalFontSize = bmFont->getOriginalFontSize(); float originalFontSize = bmFont->getOriginalFontSize();
if(fabs(_bmFontSize+1) < FLT_EPSILON){ _bmFontSize = originalFontSize / CC_CONTENT_SCALE_FACTOR();
_bmFontSize = originalFontSize / CC_CONTENT_SCALE_FACTOR();
}
} }
} }

View File

@ -189,9 +189,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
idx++; idx++;
continue; continue;
} }
addChild(child, 0, idx); addChild(child, idx, idx);
child->setOrderOfArrival(idx);
child->setTag(TMXLayerTag);
// update content size with the max size // update content size with the max size
const Size& childSize = child->getContentSize(); const Size& childSize = child->getContentSize();
Size currentSize = this->getContentSize(); Size currentSize = this->getContentSize();

View File

@ -50,6 +50,7 @@ Ref::Ref()
, _scriptObject(nullptr) , _scriptObject(nullptr)
, _rooted(false) , _rooted(false)
, _scriptOwned(false) , _scriptOwned(false)
,_referenceCountAtRootTime(0)
#endif #endif
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
@ -93,11 +94,15 @@ void Ref::retain()
++_referenceCount; ++_referenceCount;
#if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS #if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS
if (!_rooted && _scriptOwned) if (_scriptOwned && !_rooted)
{ {
auto scriptMgr = ScriptEngineManager::getInstance()->getScriptEngine(); auto scriptMgr = ScriptEngineManager::getInstance()->getScriptEngine();
if (scriptMgr && scriptMgr->getScriptType() == kScriptTypeJavascript) 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); scriptMgr->rootObject(this);
_rooted = true; _rooted = true;
} }
@ -111,7 +116,7 @@ void Ref::release()
--_referenceCount; --_referenceCount;
#if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS #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(); auto scriptMgr = ScriptEngineManager::getInstance()->getScriptEngine();
if (scriptMgr && scriptMgr->getScriptType() == kScriptTypeJavascript) if (scriptMgr && scriptMgr->getScriptType() == kScriptTypeJavascript)

View File

@ -161,6 +161,7 @@ public:
When true, it means that the object was already rooted. When true, it means that the object was already rooted.
*/ */
bool _rooted; bool _rooted;
unsigned int _referenceCountAtRootTime;
/** /**
* The life of the object is scrolled by the scripting engine. * The life of the object is scrolled by the scripting engine.

View File

@ -69,4 +69,4 @@ private:
} }
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_EXTENTIONS_CCCOMATTRIBUTE_H__

View File

@ -112,4 +112,4 @@ private:
} }
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_EXTENTIONS_CCCOMAUDIO_H__

View File

@ -82,4 +82,4 @@ public:
} }
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_EXTENTIONS_CCCOMCONTROLLER_H__

View File

@ -84,4 +84,4 @@ private:
}; };
} }
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_EXTENTIONS_CCCOMRENDER_H__

View File

@ -162,4 +162,4 @@ private:
} }
#endif // __FUNDATION__CCCOMPONENT_H__ #endif // __CC_EXTENTIONS_CCINPUTDELEGATE_H__

View File

@ -427,8 +427,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
ids[i] = touch; ids[i] = touch;
xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;; xs[i] = [touch locationInView: [touch view]].x * self.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;; ys[i] = [touch locationInView: [touch view]].y * self.contentScaleFactor;;
#ifdef __IPHONE_9_0 && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0 // Use 9.0 or higher SDK to compile
// running on iOS 9.0 or higher version // running on iOS 9.0 or higher version
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0f) { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0f) {
fs[i] = touch.force; fs[i] = touch.force;

View File

@ -56,20 +56,6 @@ getDuration : function (
return 0; return 0;
}, },
/**
* @method create
* @param {String} arg0
* @param {String} arg1
* @return {cc.Animation3D}
*/
create : function (
str,
str
)
{
return cc.Animation3D;
},
/** /**
* @method Animation3D * @method Animation3D
* @constructor * @constructor

View File

@ -4903,6 +4903,32 @@ getElapsed : function (
*/ */
cc.Sequence = { 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 * @method Sequence
* @constructor * @constructor
@ -5043,6 +5069,32 @@ RepeatForever : function (
*/ */
cc.Spawn = { 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 * @method Spawn
* @constructor * @constructor

View File

@ -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); JS_ReportError(cx, "js_cocos2dx_3d_Animation3D_getDuration : wrong number of arguments: %d, was expecting %d", argc, 0);
return false; 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<cocos2d::Animation3D>(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<cocos2d::Animation3D>(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) bool js_cocos2dx_3d_Animation3D_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, 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 JS_FS_END
}; };
static JSFunctionSpec st_funcs[] = { JSFunctionSpec *st_funcs = NULL;
JS_FN("create", js_cocos2dx_3d_Animation3D_create, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
jsb_cocos2d_Animation3D_prototype = JS_InitClass( jsb_cocos2d_Animation3D_prototype = JS_InitClass(
cx, global, cx, global,

View File

@ -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_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_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_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); bool js_cocos2dx_3d_Animation3D_Animation3D(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_Animate3D_class; extern JSClass *jsb_cocos2d_Animate3D_class;

View File

@ -7635,7 +7635,7 @@ bool js_cocos2dx_Director_getInstance(JSContext *cx, uint32_t argc, jsval *vp)
auto ret = cocos2d::Director::getInstance(); auto ret = cocos2d::Director::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Director>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Director>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }
@ -12214,6 +12214,68 @@ void js_register_cocos2dx_ActionInterval(JSContext *cx, JS::HandleObject global)
JSClass *jsb_cocos2d_Sequence_class; JSClass *jsb_cocos2d_Sequence_class;
JSObject *jsb_cocos2d_Sequence_prototype; 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<cocos2d::FiniteTimeAction *> 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) bool js_cocos2dx_Sequence_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, 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[] = { 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_FN("ctor", js_cocos2dx_Sequence_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END JS_FS_END
}; };
@ -12678,6 +12742,68 @@ void js_register_cocos2dx_RepeatForever(JSContext *cx, JS::HandleObject global)
JSClass *jsb_cocos2d_Spawn_class; JSClass *jsb_cocos2d_Spawn_class;
JSObject *jsb_cocos2d_Spawn_prototype; 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<cocos2d::FiniteTimeAction *> 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) bool js_cocos2dx_Spawn_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, 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[] = { 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_FN("ctor", js_cocos2dx_Spawn_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END JS_FS_END
}; };
@ -16726,7 +16854,7 @@ bool js_cocos2dx_Configuration_getInstance(JSContext *cx, uint32_t argc, jsval *
auto ret = cocos2d::Configuration::getInstance(); auto ret = cocos2d::Configuration::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Configuration>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Configuration>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }
@ -55950,7 +56078,7 @@ bool js_cocos2dx_GLProgramCache_getInstance(JSContext *cx, uint32_t argc, jsval
auto ret = cocos2d::GLProgramCache::getInstance(); auto ret = cocos2d::GLProgramCache::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::GLProgramCache>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::GLProgramCache>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }
@ -58157,7 +58285,7 @@ bool js_cocos2dx_AnimationCache_getInstance(JSContext *cx, uint32_t argc, jsval
auto ret = cocos2d::AnimationCache::getInstance(); auto ret = cocos2d::AnimationCache::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::AnimationCache>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::AnimationCache>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }
@ -59307,7 +59435,7 @@ bool js_cocos2dx_SpriteFrameCache_getInstance(JSContext *cx, uint32_t argc, jsva
auto ret = cocos2d::SpriteFrameCache::getInstance(); auto ret = cocos2d::SpriteFrameCache::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::SpriteFrameCache>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::SpriteFrameCache>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }

View File

@ -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_cocos2dx_Sequence_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global); void js_register_cocos2dx_Sequence(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); 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); bool js_cocos2dx_Sequence_Sequence(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_Repeat_class; 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_cocos2dx_Spawn_finalize(JSContext *cx, JSObject *obj);
void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global); void js_register_cocos2dx_Spawn(JSContext *cx, JS::HandleObject global);
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); 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); bool js_cocos2dx_Spawn_Spawn(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_cocos2d_RotateTo_class; extern JSClass *jsb_cocos2d_RotateTo_class;

View File

@ -698,7 +698,7 @@ bool js_cocos2dx_studio_ActionManagerEx_getInstance(JSContext *cx, uint32_t argc
auto ret = cocostudio::ActionManagerEx::getInstance(); auto ret = cocostudio::ActionManagerEx::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocostudio::ActionManagerEx>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocostudio::ActionManagerEx>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }
@ -5172,7 +5172,7 @@ bool js_cocos2dx_studio_ArmatureDataManager_getInstance(JSContext *cx, uint32_t
auto ret = cocostudio::ArmatureDataManager::getInstance(); auto ret = cocostudio::ArmatureDataManager::getInstance();
js_type_class_t *typeClass = js_get_type_from_native<cocostudio::ArmatureDataManager>(ret); js_type_class_t *typeClass = js_get_type_from_native<cocostudio::ArmatureDataManager>(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)); args.rval().set(OBJECT_TO_JSVAL(jsret));
return true; return true;
} }

View File

@ -64,8 +64,8 @@ static bool js_cocos2dx_Sprite3D_createAsync(JSContext *cx, uint32_t argc, jsval
auto lambda = [=](Sprite3D* larg0, void* larg1) -> void{ auto lambda = [=](Sprite3D* larg0, void* larg1) -> void{
jsval largv[2]; jsval largv[2];
js_proxy_t* proxy = js_get_or_create_proxy(cx, larg0); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
largv[0] = proxy ? OBJECT_TO_JSVAL(proxy->obj) : JS::UndefinedValue(); largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<Sprite3D>(cx, larg0));
JSB_HeapValueWrapper* v = (JSB_HeapValueWrapper*)larg1; JSB_HeapValueWrapper* v = (JSB_HeapValueWrapper*)larg1;
largv[1] = v->get(); 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); ret = Terrain::create(arg0, arg1);
} }
js_proxy_t *jsProxy = js_get_or_create_proxy<Terrain>(cx, (Terrain*)ret); args.rval().set(OBJECT_TO_JSVAL(js_get_or_create_jsobject<Terrain>(cx, ret)));
args.rval().set(OBJECT_TO_JSVAL(jsProxy->obj));
return true; return true;
} }
JS_ReportError(cx, "wrong number of arguments"); 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; 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<cocos2d::Animation3D>(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<cocos2d::Animation3D>(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) void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global)
{ {
JS::RootedValue tmpVal(cx); JS::RootedValue tmpVal(cx);
@ -357,6 +392,10 @@ void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global)
tmpObj.set(tmpVal.toObjectOrNull()); tmpObj.set(tmpVal.toObjectOrNull());
JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_Terrain_create, 2, JSPROP_READONLY | JSPROP_PERMANENT); 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); JS_GetProperty(cx, ccObj, "Bundle3D", &tmpVal);
tmpObj.set(tmpVal.toObjectOrNull()); tmpObj.set(tmpVal.toObjectOrNull());
JS_DefineFunction(cx, tmpObj, "getTrianglesList", js_cocos2dx_Bundle3D_getTrianglesList, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "getTrianglesList", js_cocos2dx_Bundle3D_getTrianglesList, 1, JSPROP_READONLY | JSPROP_PERMANENT);

View File

@ -430,8 +430,9 @@ void registerDefaultClasses(JSContext* cx, JS::HandleObject global) {
JS_DefineFunction(cx, global, "__isObjectValid", ScriptingCore::isObjectValid, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, global, "__isObjectValid", ScriptingCore::isObjectValid, 1, JSPROP_READONLY | JSPROP_PERMANENT);
} }
static void sc_finalize(JSFreeOp *freeOp, JSObject *obj) { static void sc_finalize(JSFreeOp *freeOp, JSObject *obj)
CCLOGINFO("jsbindings: finalizing JS object %p (global class)", obj); {
CCLOG("jsbindings: finalizing JS object %p (global class)", obj);
} }
//static JSClass global_class = { //static JSClass global_class = {
@ -499,16 +500,21 @@ 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, const char *filename, JSContext* cx, JS::HandleObject global)
{ {
if (cx == NULL)
cx = _cx;
if (global == NULL)
global = _global.ref().get();
JSAutoCompartment ac(cx, global); JSAutoCompartment ac(cx, global);
JS::RootedObject jsglobal(cx, global); return JS_EvaluateScript(cx, global, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1, outVal);
return JS_EvaluateScript(cx, jsglobal, string, (unsigned)strlen(string), "ScriptingCore::evalString", 1); }
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() void ScriptingCore::start()
@ -1181,10 +1187,17 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve
// AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray"); // AddNamedObjectRoot(this->_cx, &jsretArr, "touchArray");
int count = 0; 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<cocos2d::Touch>(touches[0]);
typeClassEvent = js_get_type_from_native<cocos2d::Event>(event);
for (const auto& touch : touches) for (const auto& touch : touches)
{ {
JS::RootedValue jsret(_cx, OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::Touch>(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)) if (!JS_SetElement(this->_cx, jsretArr, count, jsret))
{ {
break; break;
@ -1192,19 +1205,14 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve
++count; ++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]; jsval dataVal[2];
dataVal[0] = OBJECT_TO_JSVAL(jsretArr); dataVal[0] = OBJECT_TO_JSVAL(jsretArr);
dataVal[1] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::Event>(_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); ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet);
}
} while(false);
// JS_RemoveObjectRoot(this->_cx, &jsretArr); // JS_RemoveObjectRoot(this->_cx, &jsretArr);
@ -1231,37 +1239,18 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event
std::string funcName = getTouchFuncName(eventCode); std::string funcName = getTouchFuncName(eventCode);
bool ret = false; bool ret = false;
do js_proxy_t * p = jsb_get_native_proxy(nativeObj);
if (p)
{ {
js_proxy_t * p = jsb_get_native_proxy(nativeObj); js_type_class_t *typeClassTouch = js_get_type_from_native<cocos2d::Touch>(touch);
if (!p) break; js_type_class_t *typeClassEvent = js_get_type_from_native<cocos2d::Event>(event);
jsval dataVal[2]; jsval dataVal[2];
dataVal[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::Touch>(_cx, touch)); dataVal[0] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, touch, typeClassTouch, "cocos2d::Touch"));
dataVal[1] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::Event>(_cx, event)); dataVal[1] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClassEvent, "cocos2d::Event"));
// if (jsvalRet != nullptr) ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet);
// { }
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);
removeJSObject(_cx, touch); removeJSObject(_cx, touch);
removeJSObject(_cx, event); removeJSObject(_cx, event);
@ -1282,37 +1271,15 @@ bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::Mouse
std::string funcName = getMouseFuncName(eventType); std::string funcName = getMouseFuncName(eventType);
bool ret = false; 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]; jsval dataVal[1];
dataVal[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::Event>(_cx, event)); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Event>(event);
dataVal[0] = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClass, "cocos2d::Event"));
// if (jsvalRet != nullptr) ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, dataVal, jsvalRet);
// { }
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);
removeJSObject(_cx, event); removeJSObject(_cx, event);
return ret; return ret;
@ -1396,10 +1363,11 @@ bool ScriptingCore::handleKeybardEvent(void* nativeObj, cocos2d::EventKeyboard::
return false; return false;
bool ret = false; bool ret = false;
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Event>(event);
jsval args[2] = { jsval args[2] = {
int32_to_jsval(_cx, (int32_t)keyCode), int32_to_jsval(_cx, (int32_t)keyCode),
OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::Event>(_cx, event)) OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, event, typeClass, "cocos2d::Event"))
}; };
if (isPressed) if (isPressed)
@ -1425,9 +1393,11 @@ bool ScriptingCore::handleFocusEvent(void* nativeObj, cocos2d::ui::Widget* widge
if (nullptr == p) if (nullptr == p)
return false; return false;
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::ui::Widget>(widgetLoseFocus);
jsval args[2] = { jsval args[2] = {
OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::ui::Widget>(_cx, widgetLoseFocus)), OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(_cx, widgetLoseFocus, typeClass, "cocos2d::ui::Widget")),
OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::ui::Widget>(_cx, widgetGetFocus)) 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); bool ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "onFocusChanged", 2, args);
@ -1446,7 +1416,9 @@ int ScriptingCore::executeCustomTouchesEvent(EventTouch::EventCode eventType,
int count = 0; int count = 0;
for (auto& touch : touches) for (auto& touch : touches)
{ {
jsval jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject<Touch>(this->_cx, touch)); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Touch>(touch);
jsval jsret = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch"));
JS::RootedValue jsval(_cx, jsret); JS::RootedValue jsval(_cx, jsret);
if (!JS_SetElement(this->_cx, jsretArr, count, jsval)) { if (!JS_SetElement(this->_cx, jsretArr, count, jsval)) {
break; break;
@ -1467,20 +1439,20 @@ int ScriptingCore::executeCustomTouchesEvent(EventTouch::EventCode eventType,
} }
int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, Touch *touch, JSObject *obj)
Touch *pTouch, JSObject *obj)
{ {
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
JS::RootedValue retval(_cx); JS::RootedValue retval(_cx);
std::string funcName = getTouchFuncName(eventType); std::string funcName = getTouchFuncName(eventType);
jsval jsTouch = OBJECT_TO_JSVAL(js_get_or_create_jsobject<Touch>(this->_cx, pTouch)); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Touch>(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); executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, &retval);
// Remove touch object from global hash table and unroot it. // Remove touch object from global hash table and unroot it.
removeJSObject(this->_cx, pTouch); removeJSObject(this->_cx, touch);
return 1; return 1;
@ -1488,19 +1460,20 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType,
int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType,
Touch *pTouch, JSObject *obj, Touch *touch, JSObject *obj,
JS::MutableHandleValue retval) JS::MutableHandleValue retval)
{ {
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
std::string funcName = getTouchFuncName(eventType); std::string funcName = getTouchFuncName(eventType);
jsval jsTouch = OBJECT_TO_JSVAL(js_get_or_create_jsobject<Touch>(this->_cx, pTouch)); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Touch>(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); executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, retval);
// Remove touch object from global hash table and unroot it. // Remove touch object from global hash table and unroot it.
removeJSObject(this->_cx, pTouch); removeJSObject(this->_cx, touch);
return 1; return 1;
@ -1595,14 +1568,12 @@ void ScriptingCore::rootObject(Ref* ref)
nproxy = jsb_get_native_proxy(ptr); nproxy = jsb_get_native_proxy(ptr);
if (nproxy) { if (nproxy) {
JSContext *cx = getGlobalContext(); JSContext *cx = getGlobalContext();
// FIXME: Creating a RootedObject here is not needed. jsproxy = jsb_get_js_proxy(nproxy->obj);
// it is being created only because jsb_get_js_proxy() requires one JS::AddNamedObjectRoot(cx, &jsproxy->obj, typeid(*ref).name());
// but only the raw pointer is used in jsb_get_js_proxy() }
JS::RootedObject handle(cx, nproxy->obj.get()); else
jsproxy = jsb_get_js_proxy(handle); {
AddObjectRoot(cx, &jsproxy->obj); CCLOG("BUG in rootObject");
CCLOG("Rooting %p - %p: %s", ref, &jsproxy->obj, typeid(*ref).name());
} }
} }
@ -1611,17 +1582,16 @@ void ScriptingCore::unrootObject(Ref* ref)
js_proxy_t* nproxy; js_proxy_t* nproxy;
js_proxy_t* jsproxy; js_proxy_t* jsproxy;
void *ptr = (void*)ref; void *ptr = (void*)ref;
nproxy = jsb_get_native_proxy(ptr); nproxy = jsb_get_native_proxy(ptr);
if (nproxy) { if (nproxy) {
JSContext *cx = getGlobalContext(); JSContext *cx = getGlobalContext();
// FIXME: Creating a RootedObject here is not needed. jsproxy = jsb_get_js_proxy(nproxy->obj);
// it is being created only because jsb_get_js_proxy() requires one JS::RemoveObjectRoot(cx, &jsproxy->obj);
// but only the raw pointer is used in jsb_get_js_proxy() }
JS::RootedObject handle(cx, nproxy->obj.get()); else
jsproxy = jsb_get_js_proxy(handle); {
RemoveObjectRoot(cx, &jsproxy->obj); CCLOG("BUG in unrootObject");
CCLOG("Unrooting %p - %p: %s", ref, &jsproxy->obj, typeid(*ref).name());
} }
} }
@ -1900,14 +1870,14 @@ void ScriptingCore::enableDebugger(unsigned int port)
} }
} }
JS::HandleObject NewGlobalObject(JSContext* cx, bool debug) JSObject* NewGlobalObject(JSContext* cx, bool debug)
{ {
JS::CompartmentOptions options; JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST); options.setVersion(JSVERSION_LATEST);
JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, &shellTrustedPrincipals, JS::DontFireOnNewGlobalHook, options)); JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, &shellTrustedPrincipals, JS::DontFireOnNewGlobalHook, options));
if (!glob) { if (!glob) {
return JS::NullPtr(); return nullptr;
} }
JSAutoCompartment ac(cx, glob); JSAutoCompartment ac(cx, glob);
bool ok = true; bool ok = true;
@ -1917,7 +1887,7 @@ JS::HandleObject NewGlobalObject(JSContext* cx, bool debug)
if (ok && debug) if (ok && debug)
ok = JS_DefineDebuggerObject(cx, glob); ok = JS_DefineDebuggerObject(cx, glob);
if (!ok) if (!ok)
return JS::NullPtr(); return nullptr;
JS_FireOnNewGlobalObject(cx, glob); JS_FireOnNewGlobalObject(cx, glob);
@ -1980,11 +1950,10 @@ js_proxy_t* jsb_get_native_proxy(void* nativeObj)
return p; 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; js_proxy_t* p = nullptr;
JSObject* ptr = jsObj.get(); JS_GET_NATIVE_PROXY(p, jsObj);
JS_GET_NATIVE_PROXY(p, ptr);
return p; return p;
} }
@ -2018,33 +1987,38 @@ JSObject* jsb_ref_autoreleased_create_jsobject(JSContext *cx, cocos2d::Ref *ref,
return js_obj; 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 // get_or_create
JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug) JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug)
{ {
auto proxy = jsb_get_native_proxy(ref); auto proxy = jsb_get_native_proxy(ref);
if (proxy) if (proxy)
return proxy->obj; 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;
} }
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); auto proxy = jsb_get_native_proxy(ref);
if (proxy) if (proxy)
return proxy->obj; return proxy->obj;
// else // else
return jsb_ref_singleton_create_jsobject(cx, ref, typeClass, debug); return jsb_ref_autoreleased_create_jsobject(cx, ref, typeClass, debug);
} }
// ref_init // ref_init
@ -2071,34 +2045,22 @@ void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap<JSObject*> *obj, Ref* ref
(void)obj; (void)obj;
ref->_scriptOwned = true; ref->_scriptOwned = true;
// retain it, since the object is autoreleased // retain it, since the object is autoreleased
ret->retain(); ref->retain();
#else #else
// don't autorelease it, since it is already autoreleased // don't autorelease it, since it is already autoreleased
JS::AddNamedObjectRoot(cx, obj, debug); JS::AddNamedObjectRoot(cx, obj, debug);
#endif #endif
} }
void jsb_ref_singleton_init(JSContext* cx, JS::Heap<JSObject*> *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 // finalize
void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj) void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj)
{ {
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
js_proxy_t* nproxy; js_proxy_t* nproxy;
js_proxy_t* jsproxy; js_proxy_t* jsproxy;
jsproxy = jsb_get_js_proxy(obj);
JS::RootedObject jsobj(fop->runtime(), obj);
jsproxy = jsb_get_js_proxy(jsobj);
if (jsproxy) if (jsproxy)
{ {
auto ref = static_cast<cocos2d::Ref*>(jsproxy->ptr); auto ref = static_cast<cocos2d::Ref*>(jsproxy->ptr);
@ -2106,8 +2068,6 @@ void jsb_ref_finalize(JSFreeOp* fop, JSObject* obj)
if (ref) if (ref)
{ {
CCLOG("jsb_ref_finalize: JSObject address = %p (%s)", obj, typeid(*ref).name());
jsb_remove_proxy(nproxy, jsproxy); jsb_remove_proxy(nproxy, jsproxy);
ref->release(); ref->release();
} }

View File

@ -234,7 +234,22 @@ public:
* @param global @~english The js global object * @param global @~english The js global object
* @return @~english Return true if successfully invoked, otherwise return false. * @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, 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 @brief @~english Get script object for the given path
@ -517,7 +532,7 @@ public:
void restartVM(); 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_set_reserved_slot(JSObject *obj, uint32_t idx, jsval value);
bool jsb_get_reserved_slot(JSObject *obj, uint32_t idx, jsval& ret); bool jsb_get_reserved_slot(JSObject *obj, uint32_t idx, jsval& ret);
@ -549,7 +564,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_new_proxy(void* nativeObj, JS::HandleObject jsObj);
js_proxy_t* jsb_get_native_proxy(void* nativeObj); 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); void jsb_remove_proxy(js_proxy_t* nativeProxy, js_proxy_t* jsProxy);
/** /**
@ -565,12 +580,6 @@ void jsb_ref_init(JSContext* cx, JS::Heap<JSObject*> *obj, cocos2d::Ref* ref, co
*/ */
void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap<JSObject*> *obj, cocos2d::Ref* ref, const char* debug); void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap<JSObject*> *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<JSObject*> *obj, cocos2d::Ref* ref, const char* debug);
/** /**
* Generic finalize used by objects that are subclass of Ref * Generic finalize used by objects that are subclass of Ref
*/ */
@ -595,23 +604,20 @@ 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); 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. 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); 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. 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 might return an already existing copy when you create them. For example, `Animation3D::create()`;
*/ */
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); void removeJSObject(JSContext* cx, void* nativeObj);

View File

@ -70,12 +70,6 @@ JSClass* JSPROXY_CCPhysicsSprite_class = NULL;
JSObject* JSPROXY_CCPhysicsSprite_object = NULL; JSObject* JSPROXY_CCPhysicsSprite_object = NULL;
// Constructor // Constructor
// Destructor
void JSPROXY_CCPhysicsSprite_finalize(JSFreeOp *fop, JSObject *obj)
{
CCLOGINFO("jsbindings: finalizing JS object %p (PhysicsSprite)", obj);
}
// Arguments: // Arguments:
// Ret value: BOOL (b) // Ret value: BOOL (b)
bool JSPROXY_CCPhysicsSprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) { bool JSPROXY_CCPhysicsSprite_isDirty(JSContext *cx, uint32_t argc, jsval *vp) {
@ -173,12 +167,6 @@ extern JSObject *js_cocos2dx_CCDrawNode_prototype;
// Constructor // Constructor
// Destructor
void JSB_CCPhysicsDebugNode_finalize(JSFreeOp *fop, JSObject *obj)
{
CCLOGINFO("jsbindings: finalizing JS object %p (PhysicsDebugNode)", obj);
}
// Arguments: cpSpace* // Arguments: cpSpace*
// Ret value: PhysicsDebugNode* (o) // Ret value: PhysicsDebugNode* (o)
bool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t argc, jsval *vp) { 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->enumerate = JS_EnumerateStub;
JSB_CCPhysicsDebugNode_class->resolve = JS_ResolveStub; JSB_CCPhysicsDebugNode_class->resolve = JS_ResolveStub;
JSB_CCPhysicsDebugNode_class->convert = JS_ConvertStub; 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; JSB_CCPhysicsDebugNode_class->flags = 0;
static JSPropertySpec properties[] = { static JSPropertySpec properties[] = {
@ -442,7 +430,8 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrame__static(JSContext *cx, uint32
// Arguments: NSString* // Arguments: NSString*
// Ret value: PhysicsSprite* (o) // 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); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
bool ok = true; bool ok = true;
const char* arg0 = nullptr; const char* arg0 = nullptr;
@ -452,27 +441,9 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui
PhysicsSprite* ret = PhysicsSprite::createWithSpriteFrameName(arg0); PhysicsSprite* ret = PhysicsSprite::createWithSpriteFrameName(arg0);
jsval jsret; js_type_class_t *typeClass = js_get_type_from_native<cocos2d::extension::PhysicsSprite>(ret);
do { JS::RootedObject jsret(cx, jsb_ref_autoreleased_create_jsobject(cx, ret, typeClass, "cocos2d::extension::PhysicsSprite"));
if (ret) { args.rval().set(OBJECT_TO_JSVAL(jsret));
TypeTest<PhysicsSprite> 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);
return true; 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) { bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
bool ok = true; bool ok = true;
PhysicsSprite* cobj = new PhysicsSprite(); auto cobj = new (std::nothrow) cocos2d::extension::PhysicsSprite;
cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::extension::PhysicsSprite>(cobj);
if (_ccobj) {
_ccobj->autorelease();
}
TypeTest<cocos2d::extension::PhysicsSprite> 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));
// link the native object with the javascript object // link the native object with the javascript object
js_proxy_t* p = jsb_new_proxy(cobj, obj); JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::extension::PhysicsSprite"));
JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::PhysicsSprite"); args.rval().set(OBJECT_TO_JSVAL(jsobj));
if (JS_HasProperty(cx, obj, "_ctor", &ok)) if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok)
ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args);
return true; 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::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
PhysicsSprite *nobj = new PhysicsSprite(); auto nobj = new (std::nothrow) cocos2d::extension::PhysicsSprite;
if (nobj) { auto newproxy = jsb_new_proxy(nobj, obj);
nobj->autorelease(); jsb_ref_init(cx, &newproxy->obj, nobj, "cocos2d::extension::PhysicsSprite");
}
js_proxy_t* p = jsb_new_proxy(nobj, obj);
JS::AddNamedObjectRoot(cx, &p->obj, "cocos2d::extension::SpriteFrame");
bool isFound = false; 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); ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args);
args.rval().setUndefined(); args.rval().setUndefined();
return true; return true;
@ -535,7 +490,7 @@ void JSPROXY_CCPhysicsSprite_createClass(JSContext *cx, JS::HandleObject globalO
JSPROXY_CCPhysicsSprite_class->enumerate = JS_EnumerateStub; JSPROXY_CCPhysicsSprite_class->enumerate = JS_EnumerateStub;
JSPROXY_CCPhysicsSprite_class->resolve = JS_ResolveStub; JSPROXY_CCPhysicsSprite_class->resolve = JS_ResolveStub;
JSPROXY_CCPhysicsSprite_class->convert = JS_ConvertStub; 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; JSPROXY_CCPhysicsSprite_class->flags = 0;
static JSPropertySpec properties[] = { static JSPropertySpec properties[] = {

View File

@ -203,10 +203,9 @@ bool js_cocos2dx_EventTouch_getTouches(JSContext *cx, uint32_t argc, jsval *vp)
JS::RootedValue arrElement(cx); JS::RootedValue arrElement(cx);
//First, check whether object is associated with js object. //First, check whether object is associated with js object.
js_proxy_t* jsproxy = js_get_or_create_proxy<cocos2d::Touch>(cx, touchObj); auto jsobj = js_get_or_create_jsobject<cocos2d::Touch>(cx, touchObj);
if (jsproxy) { if (jsobj)
arrElement = OBJECT_TO_JSVAL(jsproxy->obj); arrElement = OBJECT_TO_JSVAL(jsobj);
}
if (!JS_SetElement(cx, jsretArr, i, arrElement)) { if (!JS_SetElement(cx, jsretArr, i, arrElement)) {
break; break;
} }
@ -4558,8 +4557,7 @@ bool js_PlistParser_getInstance(JSContext *cx, unsigned argc, JS::Value *vp)
jsret = OBJECT_TO_JSVAL(p->obj); jsret = OBJECT_TO_JSVAL(p->obj);
} else { } else {
// create a new js obj of that class // create a new js obj of that class
js_proxy_t *proxy = js_get_or_create_proxy<SAXParser>(cx, parser); jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject<SAXParser>(cx, parser));
jsret = OBJECT_TO_JSVAL(proxy->obj);
} }
} else { } else {
jsret = JSVAL_NULL; jsret = JSVAL_NULL;
@ -4878,8 +4876,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v
jsval largv[2]; jsval largv[2];
do { do {
if (larg0) { if (larg0) {
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::RenderTexture>(cx, (cocos2d::RenderTexture*)larg0); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::RenderTexture>(cx, (cocos2d::RenderTexture*)larg0));
} else { } else {
largv[0] = JSVAL_NULL; largv[0] = JSVAL_NULL;
} }
@ -4949,8 +4947,8 @@ bool js_cocos2dx_RenderTexture_saveToFile(JSContext *cx, uint32_t argc, jsval *v
jsval largv[2]; jsval largv[2];
do { do {
if (larg0) { if (larg0) {
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::RenderTexture>(cx, (cocos2d::RenderTexture*)larg0); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
largv[0] = OBJECT_TO_JSVAL(jsProxy->obj); largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::RenderTexture>(cx, (cocos2d::RenderTexture*)larg0));
} else { } else {
largv[0] = JSVAL_NULL; largv[0] = JSVAL_NULL;
} }
@ -5144,35 +5142,16 @@ bool js_cocos2dx_EventKeyboard_constructor(JSContext *cx, uint32_t argc, jsval *
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments"); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventKeyboard_constructor : Error processing arguments");
cocos2d::EventKeyboard* cobj = new (std::nothrow) cocos2d::EventKeyboard(arg0, arg1); cocos2d::EventKeyboard* cobj = new (std::nothrow) cocos2d::EventKeyboard(arg0, arg1);
cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::EventKeyboard>(cobj);
if (_ccobj) { auto jsobj = jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::EventKeyboard");
_ccobj->autorelease();
} args.rval().set(OBJECT_TO_JSVAL(jsobj));
TypeTest<cocos2d::EventKeyboard> 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");
return true; return true;
} }
extern JSObject *jsb_cocos2d_Event_prototype; 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) static bool js_is_native_obj(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -5190,7 +5169,7 @@ void js_register_cocos2dx_EventKeyboard(JSContext *cx, JS::HandleObject global)
jsb_cocos2d_EventKeyboard_class->enumerate = JS_EnumerateStub; jsb_cocos2d_EventKeyboard_class->enumerate = JS_EnumerateStub;
jsb_cocos2d_EventKeyboard_class->resolve = JS_ResolveStub; jsb_cocos2d_EventKeyboard_class->resolve = JS_ResolveStub;
jsb_cocos2d_EventKeyboard_class->convert = JS_ConvertStub; 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); jsb_cocos2d_EventKeyboard_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
static JSPropertySpec properties[] = { static JSPropertySpec properties[] = {
@ -5314,17 +5293,11 @@ bool js_cocos2dx_Scene_getPhysics3DWorld(JSContext *cx, uint32_t argc, jsval *vp
{ {
cocos2d::Physics3DWorld* ret = cobj->getPhysics3DWorld(); cocos2d::Physics3DWorld* ret = cobj->getPhysics3DWorld();
jsval jsret = JSVAL_NULL; jsval jsret = JSVAL_NULL;
do if (ret)
{ {
if (ret) js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Physics3DWorld>(ret);
{ jsret = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::Physics3DWorld"));
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::Physics3DWorld>(cx, (cocos2d::Physics3DWorld*)ret); }
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else
{
jsret = JSVAL_NULL;
}
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; return true;
} }
@ -5400,15 +5373,11 @@ bool js_cocos2dx_Scene_getNavMesh(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 0) { if (argc == 0) {
cocos2d::NavMesh* ret = cobj->getNavMesh(); cocos2d::NavMesh* ret = cobj->getNavMesh();
jsval jsret = JSVAL_NULL; jsval jsret = JSVAL_NULL;
do { if (ret)
if (ret) { {
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::NavMesh>(cx, (cocos2d::NavMesh*)ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::NavMesh>(ret);
jsret = OBJECT_TO_JSVAL(jsProxy->obj); jsret = OBJECT_TO_JSVAL(jsb_ref_get_or_create_jsobject(cx, ret, typeClass, "cocos2d::NavMesh"));
} }
else {
jsret = JSVAL_NULL;
}
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; return true;
} }
@ -5657,14 +5626,9 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments");
cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0));
jsval jsret = JSVAL_NULL; jsval jsret = JSVAL_NULL;
do { if (ret) {
if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::PolygonInfo>(cx, ret));
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::PolygonInfo>(cx, ret); }
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; return true;
} }
@ -5676,14 +5640,9 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments");
cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1));
jsval jsret = JSVAL_NULL; jsval jsret = JSVAL_NULL;
do { if (ret) {
if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::PolygonInfo>(cx, ret));
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::PolygonInfo>(cx, ret); }
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; return true;
} }
@ -5697,14 +5656,9 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments");
cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2));
jsval jsret = JSVAL_NULL; jsval jsret = JSVAL_NULL;
do { if (ret) {
if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::PolygonInfo>(cx, ret));
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::PolygonInfo>(cx, ret); }
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; return true;
} }
@ -5720,14 +5674,9 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); 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)); cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3));
jsval jsret = JSVAL_NULL; jsval jsret = JSVAL_NULL;
do { if (ret) {
if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject<cocos2d::PolygonInfo>(cx, ret));
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::PolygonInfo>(cx, ret); }
jsret = OBJECT_TO_JSVAL(jsProxy->obj);
} else {
jsret = JSVAL_NULL;
}
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; return true;
} }

View File

@ -133,11 +133,8 @@ JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if<!std:
JS::RootedObject parent(cx, typeClass->parentProto.ref().get()); JS::RootedObject parent(cx, typeClass->parentProto.ref().get());
JS::RootedObject js_obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); JS::RootedObject js_obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent));
proxy = jsb_new_proxy(native_obj, js_obj); proxy = jsb_new_proxy(native_obj, js_obj);
#ifdef DEBUG
AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name()); JS::AddNamedObjectRoot(cx, &proxy->obj, typeid(*native_obj).name());
#else
AddObjectRoot(cx, &proxy->obj);
#endif
} }
return proxy->obj; return proxy->obj;
} }
@ -150,13 +147,8 @@ JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if<!std:
template<class T> template<class T>
JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if<std::is_base_of<cocos2d::Ref,T>::value,T>::type *native_obj) JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if<std::is_base_of<cocos2d::Ref,T>::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<T>(native_obj); js_type_class_t* typeClass = js_get_type_from_native<T>(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); JS::Value anonEvaluate(JSContext *cx, JS::HandleObject thisObj, const char* string);

View File

@ -32,31 +32,31 @@ void GLNode::draw(Renderer *renderer, const Mat4& transform, uint32_t flags) {
void GLNode::onDraw(Mat4 &transform, uint32_t flags) void GLNode::onDraw(Mat4 &transform, uint32_t flags)
{ {
js_proxy_t* proxy = NULL;
JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); JSContext *cx = ScriptingCore::getInstance()->getGlobalContext();
proxy = js_get_or_create_proxy<cocos2d::Node>(cx, this);
if( proxy ) { js_type_class_t *typeClass = js_get_type_from_native<cocos2d::GLNode>(this);
// JSObject *jsObj = proxy->obj; auto j = jsb_ref_get_or_create_jsobject(cx, this, typeClass, "cocos2d::GLNode");
JS::RootedObject jsObj(cx, proxy->obj.get());
if (jsObj) {
bool found = false;
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
JS_HasProperty(cx, jsObj, "draw", &found); if (j)
if (found == true) { {
auto director = Director::getInstance(); JS::RootedObject jsObj(cx, j);
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
JS::RootedValue rval(cx); bool found = false;
JS::RootedValue fval(cx); JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
JS_GetProperty(cx, jsObj, "draw", &fval);
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) bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
if (argc == 0) { if (argc == 0) {
cocos2d::GLNode* cobj = new cocos2d::GLNode(); cocos2d::GLNode* cobj = new (std::nothrow) cocos2d::GLNode;
cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj);
if (_ccobj) {
_ccobj->autorelease();
}
TypeTest<cocos2d::GLNode> t; js_type_class_t *typeClass = js_get_type_from_native<cocos2d::GLNode>(cobj);
js_type_class_t *typeClass = nullptr; JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::GLNode"));
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::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
args.rval().set(OBJECT_TO_JSVAL(obj)); args.rval().set(OBJECT_TO_JSVAL(jsobj));
// link the native object with the javascript object
js_proxy_t *p = jsb_new_proxy(cobj, obj);
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; return true;
} }
@ -101,17 +87,16 @@ bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp)
return false; return false;
} }
void js_cocos2dx_GLNode_finalize(JSFreeOp *fop, JSObject *obj) {
}
static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
cocos2d::GLNode *nobj = new cocos2d::GLNode(); cocos2d::GLNode *nobj = new (std::nothrow) cocos2d::GLNode;
js_proxy_t* p = jsb_new_proxy(nobj, obj); auto newproxy = jsb_new_proxy(nobj, obj);
nobj->autorelease(); jsb_ref_init(cx, &newproxy->obj, nobj, "cocos2d::GLNode");
JS::AddNamedObjectRoot(cx, &p->obj, "GLNode"); bool isFound = false;
if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound)
ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args);
args.rval().setUndefined(); args.rval().setUndefined();
return true; 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) bool js_cocos2dx_GLNode_create(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
cocos2d::GLNode* ret = new cocos2d::GLNode(); cocos2d::GLNode* ret = new (std::nothrow) cocos2d::GLNode;
jsval jsret; jsval jsret = JSVAL_NULL;
do {
if (ret) { if (ret) {
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::GLNode>(cx, ret); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::GLNode>(ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
} else { auto jsobj = jsb_ref_create_jsobject(cx, ret, typeClass, "cocos2d::GLNode");
jsret = JSVAL_NULL; jsret = OBJECT_TO_JSVAL(jsobj);
} }
} while (0);
args.rval().set(jsret); args.rval().set(jsret);
return true; 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->enumerate = JS_EnumerateStub;
js_cocos2dx_GLNode_class->resolve = JS_ResolveStub; js_cocos2dx_GLNode_class->resolve = JS_ResolveStub;
js_cocos2dx_GLNode_class->convert = JS_ConvertStub; 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); js_cocos2dx_GLNode_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
static JSPropertySpec properties[] = { static JSPropertySpec properties[] = {

View File

@ -1761,9 +1761,10 @@ jsval ccarray_to_jsval(JSContext* cx, __Array *arr)
JS::RootedValue arrElement(cx); JS::RootedValue arrElement(cx);
//First, check whether object is associated with js object. //First, check whether object is associated with js object.
js_proxy_t* jsproxy = js_get_or_create_proxy<cocos2d::Ref>(cx, obj); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Ref>(obj);
if (jsproxy) { auto jsobj = jsb_ref_get_or_create_jsobject(cx, obj, typeClass, "cocos2d::Ref");
arrElement = OBJECT_TO_JSVAL(jsproxy->obj); if (jsobj) {
arrElement = OBJECT_TO_JSVAL(jsobj);
} }
else { else {
__String* strVal = NULL; __String* strVal = NULL;
@ -1812,9 +1813,10 @@ jsval ccdictionary_to_jsval(JSContext* cx, __Dictionary* dict)
JS::RootedValue dictElement(cx); JS::RootedValue dictElement(cx);
Ref* obj = pElement->getObject(); Ref* obj = pElement->getObject();
//First, check whether object is associated with js object. //First, check whether object is associated with js object.
js_proxy_t* jsproxy = js_get_or_create_proxy<cocos2d::Ref>(cx, obj); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Ref>(obj);
if (jsproxy) { auto jsobj = jsb_ref_get_or_create_jsobject(cx, obj, typeClass, "cocos2d::Ref");
dictElement = OBJECT_TO_JSVAL(jsproxy->obj); if (jsobj) {
dictElement = OBJECT_TO_JSVAL(jsobj);
} }
else { else {
__String* strVal = NULL; __String* strVal = NULL;

View File

@ -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); bool jsval_to_resourcedata(JSContext *cx, JS::HandleValue v, cocos2d::ResourceData* ret);
// forward declaration // 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 <class T> template <class T>
bool jsvals_variadic_to_ccvector( JSContext *cx, /*jsval *vp, int argc,*/const JS::CallArgs& args, cocos2d::Vector<T>* ret) bool jsvals_variadic_to_ccvector( JSContext *cx, /*jsval *vp, int argc,*/const JS::CallArgs& args, cocos2d::Vector<T>* ret)

View File

@ -46,7 +46,7 @@ JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge_evalSt
CCLOG("Cocos2dxJavascriptJavaBridge_evalString error, invalid string code"); CCLOG("Cocos2dxJavascriptJavaBridge_evalString error, invalid string code");
return 0; return 0;
} }
ScriptingCore::getInstance()->evalString(strValue.c_str(), nullptr); ScriptingCore::getInstance()->evalString(strValue.c_str());
return 1; return 1;
} }

View File

@ -175,10 +175,10 @@
BA4095C31A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */; }; 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 */; }; 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 */; }; 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 = (); }; }; BA9FD5D21BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; };
BA9FD5D31BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; settings = {ASSET_TAGS = (); }; }; BA9FD5D31BAC0A7600996C85 /* CCComponentJS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA9FD5D01BAC0A7600996C85 /* CCComponentJS.cpp */; };
BA9FD5D41BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; settings = {ASSET_TAGS = (); }; }; BA9FD5D41BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; };
BA9FD5D51BAC0A7600996C85 /* CCComponentJS.h in Headers */ = {isa = PBXBuildFile; fileRef = BA9FD5D11BAC0A7600996C85 /* CCComponentJS.h */; settings = {ASSET_TAGS = (); }; }; 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 */; }; 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 */; }; 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 */; }; BAEE4D731AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BAEE4D701AC3FFAD003BEB0F /* jsb_cocos2dx_3d_extension_auto.hpp */; };
@ -214,7 +214,6 @@
1A119E3C18BDF19200352BAA /* jsb_cocos2dx_spine_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_spine_auto.hpp; sourceTree = "<group>"; }; 1A119E3C18BDF19200352BAA /* jsb_cocos2dx_spine_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_spine_auto.hpp; sourceTree = "<group>"; };
1A119E3E18BDF19200352BAA /* jsb_cocos2dx_studio_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_studio_auto.cpp; sourceTree = "<group>"; }; 1A119E3E18BDF19200352BAA /* jsb_cocos2dx_studio_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_studio_auto.cpp; sourceTree = "<group>"; };
1A119E3F18BDF19200352BAA /* jsb_cocos2dx_studio_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_studio_auto.hpp; sourceTree = "<group>"; }; 1A119E3F18BDF19200352BAA /* jsb_cocos2dx_studio_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_studio_auto.hpp; sourceTree = "<group>"; };
1A119E4318BDF19200352BAA /* Android.mk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Android.mk; sourceTree = "<group>"; };
1A119E4418BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_chipmunk_auto_classes.cpp; sourceTree = "<group>"; }; 1A119E4418BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_chipmunk_auto_classes.cpp; sourceTree = "<group>"; };
1A119E4518BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_auto_classes.h; sourceTree = "<group>"; }; 1A119E4518BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_auto_classes.h; sourceTree = "<group>"; };
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 = "<group>"; }; 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 = "<group>"; };
@ -227,7 +226,6 @@
1A119E4D18BDF19200352BAA /* js_bindings_chipmunk_registration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_registration.h; sourceTree = "<group>"; }; 1A119E4D18BDF19200352BAA /* js_bindings_chipmunk_registration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_chipmunk_registration.h; sourceTree = "<group>"; };
1A119E4E18BDF19200352BAA /* cocos2d_specifics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cocos2d_specifics.cpp; sourceTree = "<group>"; }; 1A119E4E18BDF19200352BAA /* cocos2d_specifics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cocos2d_specifics.cpp; sourceTree = "<group>"; };
1A119E4F18BDF19200352BAA /* cocos2d_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocos2d_specifics.hpp; sourceTree = "<group>"; }; 1A119E4F18BDF19200352BAA /* cocos2d_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocos2d_specifics.hpp; sourceTree = "<group>"; };
1A119E5118BDF19200352BAA /* Android.mk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Android.mk; sourceTree = "<group>"; };
1A119E5218BDF19200352BAA /* cocosbuilder_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocosbuilder_specifics.hpp; sourceTree = "<group>"; }; 1A119E5218BDF19200352BAA /* cocosbuilder_specifics.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cocosbuilder_specifics.hpp; sourceTree = "<group>"; };
1A119E5318BDF19200352BAA /* js_bindings_ccbreader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_ccbreader.cpp; sourceTree = "<group>"; }; 1A119E5318BDF19200352BAA /* js_bindings_ccbreader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = js_bindings_ccbreader.cpp; sourceTree = "<group>"; };
1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_ccbreader.h; sourceTree = "<group>"; }; 1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = js_bindings_ccbreader.h; sourceTree = "<group>"; };
@ -437,7 +435,6 @@
1A119E4218BDF19200352BAA /* chipmunk */ = { 1A119E4218BDF19200352BAA /* chipmunk */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
1A119E4318BDF19200352BAA /* Android.mk */,
1A119E4418BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp */, 1A119E4418BDF19200352BAA /* js_bindings_chipmunk_auto_classes.cpp */,
1A119E4518BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h */, 1A119E4518BDF19200352BAA /* js_bindings_chipmunk_auto_classes.h */,
1A119E4618BDF19200352BAA /* js_bindings_chipmunk_auto_classes_registration.h */, 1A119E4618BDF19200352BAA /* js_bindings_chipmunk_auto_classes_registration.h */,
@ -455,7 +452,6 @@
1A119E5018BDF19200352BAA /* cocosbuilder */ = { 1A119E5018BDF19200352BAA /* cocosbuilder */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
1A119E5118BDF19200352BAA /* Android.mk */,
1A119E5218BDF19200352BAA /* cocosbuilder_specifics.hpp */, 1A119E5218BDF19200352BAA /* cocosbuilder_specifics.hpp */,
1A119E5318BDF19200352BAA /* js_bindings_ccbreader.cpp */, 1A119E5318BDF19200352BAA /* js_bindings_ccbreader.cpp */,
1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */, 1A119E5418BDF19200352BAA /* js_bindings_ccbreader.h */,

View File

@ -563,19 +563,13 @@ cc.ActionInterval.prototype._ctor = function(d) {
}; };
cc.Sequence.prototype._ctor = function(tempArray) { 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; var last = paramArray.length - 1;
if ((last >= 0) && (paramArray[last] == null)) if ((last >= 0) && (paramArray[last] == null))
cc.log("parameters should not be ending with null in Javascript"); cc.log("parameters should not be ending with null in Javascript");
if (last >= 0) { if (last >= 0) {
var prev = paramArray[0]; this.init(paramArray);
for (var i = 1; i < last; i++) {
if (paramArray[i]) {
prev = cc.Sequence.create(prev, paramArray[i]);
}
}
this.initWithTwoActions(prev, paramArray[last]);
} }
}; };
@ -588,19 +582,13 @@ cc.RepeatForever.prototype._ctor = function(action) {
}; };
cc.Spawn.prototype._ctor = function(tempArray) { 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; var last = paramArray.length - 1;
if ((last >= 0) && (paramArray[last] == null)) if ((last >= 0) && (paramArray[last] == null))
cc.log("parameters should not be ending with null in Javascript"); cc.log("parameters should not be ending with null in Javascript");
if (last >= 0) { if (last >= 0) {
var prev = paramArray[0]; this.init(paramArray);
for (var i = 1; i < last; i++) {
if (paramArray[i]) {
prev = cc.Spawn.create(prev, paramArray[i]);
}
}
this.initWithTwoActions(prev, paramArray[last]);
} }
}; };
@ -1208,4 +1196,4 @@ cc.Menu.create = function(menuItems) {
return cc.Menu._create.apply(null, items); return cc.Menu._create.apply(null, items);
}; };
cc.TMXLayer.prototype.tileFlagsAt = cc.TMXLayer.prototype.getTileFlagsAt; cc.TMXLayer.prototype.tileFlagsAt = cc.TMXLayer.prototype.getTileFlagsAt;

View File

@ -75,7 +75,7 @@
-- @return Control#Control self (return value: cc.Control) -- @return Control#Control self (return value: cc.Control)
-------------------------------- --------------------------------
-- Returns a point corresponding to the touh location converted into the<br> -- Returns a point corresponding to the touch location converted into the<br>
-- control space coordinates.<br> -- control space coordinates.<br>
-- param touch A Touch object that represents a touch. -- param touch A Touch object that represents a touch.
-- @function [parent=#Control] getTouchLocation -- @function [parent=#Control] getTouchLocation

View File

@ -145,7 +145,7 @@
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- Sets the font of the label, changes the label to a BMFont if neccessary.<br> -- Sets the font of the label, changes the label to a BMFont if necessary.<br>
-- param fntFile The name of the font to change to<br> -- param fntFile The name of the font to change to<br>
-- param state The state that uses the specified fntFile. The values are described<br> -- param state The state that uses the specified fntFile. The values are described<br>
-- in "CCControlState". -- in "CCControlState".

View File

@ -256,7 +256,7 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
} }
} }
//FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249
if (!_ignoreSize) { if (!_ignoreSize && _customSize.equals(Size::ZERO)) {
_customSize = _buttonNormalRenderer->getContentSize(); _customSize = _buttonNormalRenderer->getContentSize();
} }
this->setupNormalTexture(textureLoaded); this->setupNormalTexture(textureLoaded);

View File

@ -137,7 +137,7 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType)
break; break;
} }
//FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249
if (!_ignoreSize) { if (!_ignoreSize && _customSize.equals(Size::ZERO)) {
_customSize = _imageRenderer->getContentSize(); _customSize = _imageRenderer->getContentSize();
} }
this->setupTexture(); this->setupTexture();

View File

@ -87,6 +87,7 @@ _isFocusPassing(false)
Layout::~Layout() Layout::~Layout()
{ {
CC_SAFE_RELEASE(_clippingStencil); CC_SAFE_RELEASE(_clippingStencil);
CC_SAFE_DELETE(_stencileStateManager);
} }
void Layout::onEnter() void Layout::onEnter()

View File

@ -390,8 +390,8 @@ protected:
virtual void onItemListChanged(); virtual void onItemListChanged();
virtual void remedyLayoutParameter(Widget* item);
void updateInnerContainerSize(); void updateInnerContainerSize();
void remedyLayoutParameter(Widget* item);
void remedyVerticalLayoutParameter(LinearLayoutParameter* layoutParameter, ssize_t itemIndex); void remedyVerticalLayoutParameter(LinearLayoutParameter* layoutParameter, ssize_t itemIndex);
void remedyHorizontalLayoutParameter(LinearLayoutParameter* layoutParameter,ssize_t itemIndex); void remedyHorizontalLayoutParameter(LinearLayoutParameter* layoutParameter,ssize_t itemIndex);

View File

@ -163,7 +163,7 @@ void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
} }
//FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249
if (!_ignoreSize) { if (!_ignoreSize && _customSize.equals(Size::ZERO)) {
_customSize = _barRenderer->getContentSize(); _customSize = _barRenderer->getContentSize();
} }
this->setupTexture(); this->setupTexture();

View File

@ -427,6 +427,11 @@ const Color3B& PageView::getIndicatorSelectedIndexColor() const
return _indicator->getSelectedIndexColor(); return _indicator->getSelectedIndexColor();
} }
void PageView::remedyLayoutParameter(Widget *item)
{
item->setContentSize(this->getContentSize());
ListView::remedyLayoutParameter(item);
}
} }

View File

@ -350,6 +350,7 @@ CC_CONSTRUCTOR_ACCESS:
protected: protected:
void pageTurningEvent(); void pageTurningEvent();
virtual void remedyLayoutParameter(Widget* item)override;
virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override; virtual void moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) override;
virtual void onItemListChanged() override; virtual void onItemListChanged() override;
virtual void onSizeChanged() override; virtual void onSizeChanged() override;

View File

@ -670,7 +670,7 @@ namespace ui {
void Scale9Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) void Scale9Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{ {
if (_scale9Image) { if (_scale9Image && _scale9Enabled) {
#if CC_USE_CULLING #if CC_USE_CULLING
// Don't do calculate the culling if the transform was not updated // Don't do calculate the culling if the transform was not updated
auto visitingCamera = Camera::getVisitingCamera(); auto visitingCamera = Camera::getVisitingCamera();
@ -757,12 +757,21 @@ namespace ui {
else else
break; break;
} }
if (!_scale9Enabled && _scale9Image && _scale9Image->getLocalZOrder() < 0 )
{
_scale9Image->visit(renderer, _modelViewTransform, flags);
}
// draw self // draw self
// //
if (isVisitableByVisitingCamera()) if (isVisitableByVisitingCamera())
this->draw(renderer, _modelViewTransform, flags); 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) for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
(*it)->visit(renderer, _modelViewTransform, flags); (*it)->visit(renderer, _modelViewTransform, flags);
@ -1336,5 +1345,14 @@ namespace ui {
CC_SAFE_RELEASE_NULL(this->_scale9Image); CC_SAFE_RELEASE_NULL(this->_scale9Image);
} }
void Scale9Sprite::setGlobalZOrder(float globalZOrder)
{
Node::setGlobalZOrder(globalZOrder);
if (_scale9Image)
{
_scale9Image->setGlobalZOrder(globalZOrder);
}
}
}} }}

View File

@ -577,6 +577,8 @@ namespace ui {
/** /**
* @brief Toggle 9-slice feature. * @brief Toggle 9-slice feature.
* If Scale9Sprite is 9-slice disabled, the Scale9Sprite will rendered as a normal sprite. * If Scale9Sprite is 9-slice disabled, the Scale9Sprite will rendered as a normal sprite.
* @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. * @param enabled True to enable 9-slice, false otherwise.
* @js NA * @js NA
*/ */
@ -657,7 +659,8 @@ namespace ui {
virtual float getScale() const override; virtual float getScale() const override;
using Node::getScaleZ; using Node::getScaleZ;
virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
virtual void setGlobalZOrder(float globalZOrder) override;
/** /**
* Set the slice sprite rendering type. * Set the slice sprite rendering type.
* When setting to SIMPLE, only 4 vertexes is used to rendering. * When setting to SIMPLE, only 4 vertexes is used to rendering.

View File

@ -172,7 +172,7 @@ void Slider::loadBarTexture(const std::string& fileName, TextureResType texType)
} }
} }
//FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249
if (!_ignoreSize) { if (!_ignoreSize && _customSize.equals(Size::ZERO)) {
_customSize = _barRenderer->getContentSize(); _customSize = _barRenderer->getContentSize();
} }
this->setupBarTexture(); this->setupBarTexture();

View File

@ -107,7 +107,7 @@ void Control::sendActionsForControlEvents(EventType controlEvents)
// For each control events // For each control events
for (int i = 0; i < kControlEventTotalNumber; i++) 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))) if (((int)controlEvents & (1 << i)))
{ {
// Call invocations // Call invocations
@ -135,7 +135,7 @@ void Control::addTargetWithActionForControlEvents(Ref* target, Handler action, E
// For each control events // For each control events
for (int i = 0; i < kControlEventTotalNumber; i++) 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))) if (((int)controlEvents & (1 << i)))
{ {
this->addTargetWithActionForControlEvent(target, action, (EventType)(1<<i)); this->addTargetWithActionForControlEvent(target, action, (EventType)(1<<i));
@ -148,7 +148,7 @@ void Control::addTargetWithActionForControlEvents(Ref* target, Handler action, E
/** /**
* Adds a target and action for a particular event to an internal dispatch * Adds a target and action for a particular event to an internal dispatch
* table. * 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. * parameters, in that order.
* When you call this method, target is not retained. * When you call this method, target is not retained.
* *
@ -173,7 +173,7 @@ void Control::removeTargetWithActionForControlEvents(Ref* target, Handler action
// For each control events // For each control events
for (int i = 0; i < kControlEventTotalNumber; i++) 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))) if (((int)controlEvents & (1 << i)))
{ {
this->removeTargetWithActionForControlEvent(target, action, (EventType)(1 << i)); this->removeTargetWithActionForControlEvent(target, action, (EventType)(1 << i));

View File

@ -84,7 +84,7 @@ public:
/** The possible state for a control. */ /** The possible state for a control. */
enum class State 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. 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. 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. 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.
@ -122,7 +122,7 @@ public:
/** /**
* Adds a target and action for a particular event (or events) to an internal * Adds a target and action for a particular event (or events) to an internal
* dispatch table. * 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. * parameters, in that order.
* When you call this method, target is not retained. * When you call this method, target is not retained.
* *
@ -138,7 +138,7 @@ public:
* Removes a target and action for a particular event (or events) from an * Removes a target and action for a particular event (or events) from an
* internal dispatch table. * internal dispatch table.
* *
* @param target The target objectthat 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 * message is sent. Pass nil to remove all targets paired with action and the
* specified control events. * specified control events.
* @param action A selector identifying an action message. Pass NULL to remove * @param action A selector identifying an action message. Pass NULL to remove
@ -149,7 +149,7 @@ public:
virtual void removeTargetWithActionForControlEvents(Ref* target, Handler action, EventType controlEvents); 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. * control space coordinates.
* @param touch A Touch object that represents a touch. * @param touch A Touch object that represents a touch.
*/ */
@ -190,7 +190,7 @@ CC_CONSTRUCTOR_ACCESS:
protected: protected:
/** /**
* Returns an Invocation object able to construct messages using a given * 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) * the event as parameters, in that order)
* *
* @param target The target object. * @param target The target object.
@ -217,11 +217,11 @@ protected:
/** /**
* Adds a target and action for a particular event to an internal dispatch * Adds a target and action for a particular event to an internal dispatch
* table. * 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. * parameters, in that order.
* When you call this method, target is not retained. * 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. * 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 action A selector identifying an action message. It cannot be NULL.
* @param controlEvent A control event for which the action message is sent. * @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 * Removes a target and action for a particular event from an internal dispatch
* table. * 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 * message is sent. Pass nil to remove all targets paired with action and the
* specified control events. * specified control events.
* @param action A selector identifying an action message. Pass NULL to remove * @param action A selector identifying an action message. Pass NULL to remove

View File

@ -63,10 +63,10 @@ ControlButton::~ControlButton()
bool ControlButton::init() 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()) if (Control::init())
{ {
@ -79,9 +79,9 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprit
_isPushed = false; _isPushed = false;
// Adjust the background image by default // Adjust the background image by adjustBackGroundSize
setAdjustBackgroundImage(true);
setPreferredSize(Size::ZERO); setPreferredSize(Size::ZERO);
setAdjustBackgroundImage(adjustBackGroundSize);
// Zooming button by default // Zooming button by default
_zoomOnTouchDown = true; _zoomOnTouchDown = true;
_scaleRatio = 1.1f; _scaleRatio = 1.1f;
@ -123,14 +123,22 @@ 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)
{ {
ControlButton *pRet = new (std::nothrow) ControlButton(); ControlButton *pRet = new (std::nothrow) ControlButton();
pRet->initWithLabelAndBackgroundSprite(label, backgroundSprite); 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();
pRet->initWithLabelAndBackgroundSprite(label, backgroundSprite, adjustBackGroundSize);
pRet->autorelease(); pRet->autorelease();
return pRet; return pRet;
} }
bool ControlButton::initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize) 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) ControlButton* ControlButton::create(const std::string& title, const std::string& fontName, float fontSize)
@ -144,7 +152,7 @@ ControlButton* ControlButton::create(const std::string& title, const std::string
bool ControlButton::initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite) bool ControlButton::initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite)
{ {
Label *label = Label::createWithSystemFont("", "Arial", 30);// Label *label = Label::createWithSystemFont("", "Arial", 30);//
return initWithLabelAndBackgroundSprite(label, sprite); return initWithLabelAndBackgroundSprite(label, sprite,false);
} }
ControlButton* ControlButton::create(cocos2d::ui::Scale9Sprite* sprite) ControlButton* ControlButton::create(cocos2d::ui::Scale9Sprite* sprite)

View File

@ -58,6 +58,7 @@ public:
static ControlButton* create(cocos2d::ui::Scale9Sprite* sprite); static ControlButton* create(cocos2d::ui::Scale9Sprite* sprite);
static ControlButton* create(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite); 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(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; virtual void needsLayout(void) override;
@ -134,7 +135,7 @@ public:
virtual float getTitleTTFSizeForState(State state); 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 fntFile The name of the font to change to
* @param state The state that uses the specified fntFile. The values are described * @param state The state that uses the specified fntFile. The values are described
* in "CCControlState". * in "CCControlState".
@ -202,7 +203,7 @@ CC_CONSTRUCTOR_ACCESS:
virtual ~ControlButton(); virtual ~ControlButton();
virtual bool init() override; virtual bool init() override;
virtual bool initWithLabelAndBackgroundSprite(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite); virtual bool initWithLabelAndBackgroundSprite(Node* label, cocos2d::ui::Scale9Sprite* backgroundSprite, bool adjustBackGroundSize);
virtual bool initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite); virtual bool initWithBackgroundSprite(cocos2d::ui::Scale9Sprite* sprite);
virtual bool initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize); virtual bool initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize);

View File

@ -71,7 +71,7 @@ protected:
void updateSliderPosition(Vec2 location); void updateSliderPosition(Vec2 location);
bool checkSliderPosition(Vec2 location); bool checkSliderPosition(Vec2 location);
//maunally put in the setters //manually put in the setters
CC_SYNTHESIZE_READONLY(float, _hue, Hue); CC_SYNTHESIZE_READONLY(float, _hue, Hue);
virtual void setHue(float val); virtual void setHue(float val);
CC_SYNTHESIZE_READONLY(float, _huePercentage, HuePercentage); CC_SYNTHESIZE_READONLY(float, _huePercentage, HuePercentage);

View File

@ -129,7 +129,7 @@ protected:
/** Returns the value for the given location. */ /** Returns the value for the given location. */
float valueForLocation(Vec2 location); float valueForLocation(Vec2 location);
//maunally put in the setters //manually put in the setters
/** Contains the receiver's current value. */ /** Contains the receiver's current value. */
CC_SYNTHESIZE_READONLY(float, _value, Value); CC_SYNTHESIZE_READONLY(float, _value, Value);

View File

@ -323,7 +323,7 @@ protected:
*/ */
Node* _container; Node* _container;
/** /**
* Determiens whether user touch is moved after begin phase. * Determines whether user touch is moved after begin phase.
*/ */
bool _touchMoved; bool _touchMoved;
/** /**

View File

@ -119,7 +119,7 @@ protected:
/** Although the scale is on a Particle System level, the affector can also be scaled. /** Although the scale is on a Particle System level, the affector can also be scaled.
*/ */
Vec3 _affectorScale; 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. position, the mDerivedPosition attribute is introduced.
*/ */
Vec3 _derivedPosition; Vec3 _derivedPosition;

View File

@ -104,7 +104,7 @@ void PUAffectorTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode
} }
else if (prop->name == token[TOKEN_POSITION]) else if (prop->name == token[TOKEN_POSITION])
{ {
// Property: positon // Property: position
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
{ {
Vec3 val; Vec3 val;

View File

@ -734,9 +734,9 @@ void PUBillboardChain::setBlendFunc(const BlendFunc& blendFunc)
GLuint PUBillboardChain::getTextureName() 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; _texture = nullptr;
this->init(""); this->init("");

View File

@ -107,7 +107,7 @@ public:
bool alwaysUsePosition(void) const {return _alwaysUsePosition;}; 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 /** 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. is used, otherwise the default is used.
*/ */
void setAlwaysUsePosition(bool alwaysUsePosition) {_alwaysUsePosition = alwaysUsePosition;}; void setAlwaysUsePosition(bool alwaysUsePosition) {_alwaysUsePosition = alwaysUsePosition;};
@ -143,14 +143,14 @@ protected:
/** Store the technique value to keep up to speed. /** Store the technique value to keep up to speed.
@remarks @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. notified. Using the pointer causes an exception.
*/ */
PUParticleSystem3D* _system; PUParticleSystem3D* _system;
/** Store the emitter value to keep up to speed. /** Store the emitter value to keep up to speed.
@remarks @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. notified. Using the pointer causes an exception.
*/ */
PUEmitter* _emitter; PUEmitter* _emitter;

View File

@ -258,7 +258,7 @@ class CC_DLL PUDynamicAttributeCurved : public PUDynamicAttribute
inline ControlPointList::iterator getLastValidIterator(void); 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 class CC_DLL PUDynamicAttributeOscillate : public PUDynamicAttribute
{ {

View File

@ -108,7 +108,7 @@ void PUEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *
} }
else if (prop->name == token[TOKEN_POSITION]) else if (prop->name == token[TOKEN_POSITION])
{ {
// Property: positon // Property: position
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
{ {
Vec3 val; Vec3 val;

View File

@ -133,7 +133,7 @@ public:
/** Destructor **/ /** Destructor **/
~MeshInfo (void); ~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] **/ returned between [0..high] **/
float getGaussianRandom (float high, float cutoff = 4); float getGaussianRandom (float high, float cutoff = 4);
@ -196,7 +196,7 @@ public:
/** Returns the type op distribution. /** Returns the type op distribution.
@remarks @remarks
There are several ways to emit particles on the surface of a mesh. This attribute indicates 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; const MeshInfo::MeshSurfaceDistribution getDistribution (void) const;

View File

@ -198,7 +198,7 @@ void PUObserver::destroyEventHandler(PUEventHandler* eventHandler)
{ {
if (*it == eventHandler) if (*it == eventHandler)
{ {
// Detroy it // Destroy it
//ParticleSystemManager::getSingletonPtr()->destroyEventHandler(*it); //ParticleSystemManager::getSingletonPtr()->destroyEventHandler(*it);
(*it)->release(); (*it)->release();
_eventHandlers.erase(it); _eventHandlers.erase(it);

View File

@ -159,7 +159,7 @@ public:
bool getObserveUntilEvent(void) const; bool getObserveUntilEvent(void) const;
/** Sets the value of mObserveUntilEvent. This value determines whether observation must be continued /** 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); void setObserveUntilEvent(bool observeUntilEvent);
@ -213,8 +213,8 @@ protected:
// Particle type to be observed. Default is that all particles are observed. // Particle type to be observed. Default is that all particles are observed.
PUParticle3D::ParticleType _particleTypeToObserve; PUParticle3D::ParticleType _particleTypeToObserve;
/** Determines whether mParticleTypeToObserve is set. If ´true? only that particles of the specified type /** Determines whether mParticleTypeToObserve is set. If true only that particles of the specified type
are observed. If ´false?(= default), all particles are observed. are observed. If false (= default), all particles are observed.
*/ */
bool _particleTypeToObserveSet; bool _particleTypeToObserveSet;

View File

@ -50,13 +50,13 @@ public:
*/ */
virtual bool observe (PUParticle3D* particle, float timeElapsed) override; virtual bool observe (PUParticle3D* particle, float timeElapsed) override;
/** The _processParticle() function is overridden, because we don´t observe an individual particle. /** 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). 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; virtual void updateObserver(PUParticle3D* particle, float timeElapsed, bool firstParticle) override;
/** Instead of the _processParticle(), the _postProcessParticles() is used because it is called /** 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; virtual void postUpdateObserver(float timeElapsed) override;

View File

@ -1011,7 +1011,7 @@ void PUParticleSystem3D::initParticleForExpiration( PUParticle3D* particle, floa
it->particleExpired(this, particle); it->particleExpired(this, particle);
} }
///** Externs are also called to perform expiration activities. If needed, affectors and emitters may be added, but at the moment ///** 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()) //if (!mExterns.empty())
//{ //{

View File

@ -55,7 +55,7 @@ bool PURandomiserTranslator::translateChildProperty( PUScriptCompiler* compiler,
} }
else if (prop->name == token[TOKEN_RND_MAX_DEVIATION_X]) 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)) if (passValidateProperty(compiler, prop, token[TOKEN_RND_MAX_DEVIATION_X], VAL_REAL))
{ {
float val = 0.0f; float val = 0.0f;

View File

@ -589,9 +589,9 @@ bool PUParticle3DEntityRender::initRender( const std::string &texFile )
GLuint PUParticle3DEntityRender::getTextureName() 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; _texture = nullptr;
this->initRender(""); this->initRender("");

View File

@ -89,7 +89,7 @@ void PUTechniqueTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode
} }
else if (prop->name == token[TOKEN_POSITION]) else if (prop->name == token[TOKEN_POSITION])
{ {
// Property: positon // Property: position
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
{ {
Vec3 val; Vec3 val;

View File

@ -62,7 +62,7 @@ public:
*/ */
void setRotationSpeed(PUDynamicAttribute* dynRotationSpeed); void setRotationSpeed(PUDynamicAttribute* dynRotationSpeed);
/** Returns the rotation defined in the the affector. /** Returns the rotation defined in the affector.
*/ */
PUDynamicAttribute* getRotation(void) const; PUDynamicAttribute* getRotation(void) const;

View File

@ -62,9 +62,9 @@ NS_CC_BEGIN
// /** Defines the speed of generating spawnpoints. In each Particle Technique update // /** Defines the speed of generating spawnpoints. In each Particle Technique update
// 'mIterations' vertices are traversed. // 'mIterations' vertices are traversed.
// @remarks // @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 // 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; // unsigned short mIterations;
// //

View File

@ -253,7 +253,7 @@ void AssetsManager::downloadAndUncompress()
void AssetsManager::update() void AssetsManager::update()
{ {
// all operation in checkUpdate, nothing need to do // all operation in checkUpdate, nothing need to do
// keep this function for compatiblity // keep this function for compatibility
} }
bool AssetsManager::uncompress() bool AssetsManager::uncompress()
@ -308,8 +308,8 @@ bool AssetsManager::uncompress()
const size_t filenameLength = strlen(fileName); const size_t filenameLength = strlen(fileName);
if (fileName[filenameLength-1] == '/') if (fileName[filenameLength-1] == '/')
{ {
// Entry is a direcotry, so create it. // Entry is a directory, so create it.
// If the directory exists, it will failed scilently. // If the directory exists, it will failed silently.
if (!FileUtils::getInstance()->createDirectory(fullPath)) if (!FileUtils::getInstance()->createDirectory(fullPath))
{ {
CCLOG("can not create directory %s", fullPath.c_str()); CCLOG("can not create directory %s", fullPath.c_str());

View File

@ -55,7 +55,7 @@ public:
// Error caused by creating a file to store downloaded data // Error caused by creating a file to store downloaded data
CREATE_FILE, CREATE_FILE,
/** Error caused by network /** Error caused by network
-- network unavaivable -- network unavailable
-- timeout -- timeout
-- ... -- ...
*/ */

View File

@ -833,7 +833,7 @@ void AssetsManagerEx::onError(const network::DownloadTask& task,
int errorCodeInternal, int errorCodeInternal,
const std::string& errorStr) const std::string& errorStr)
{ {
// Skip version error occured // Skip version error occurred
if (task.identifier == VERSION_ID) if (task.identifier == VERSION_ID)
{ {
CCLOG("AssetsManagerEx : Fail to download version file, step skipped\n"); CCLOG("AssetsManagerEx : Fail to download version file, step skipped\n");

View File

@ -149,7 +149,7 @@ protected:
*/ */
const DownloadUnits& getFailedAssets() const; 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(); void destroyDownloadedVersion();

View File

@ -1,6 +1,6 @@
{ {
"version":"v3-deps-78", "version":"v3-deps-79",
"zip_file_size":"119277304", "zip_file_size":"124402591",
"repo_name":"cocos2d-x-3rd-party-libs-bin", "repo_name":"cocos2d-x-3rd-party-libs-bin",
"repo_parent":"https://github.com/cocos2d/", "repo_parent":"https://github.com/cocos2d/",
"move_dirs":{ "move_dirs":{

View File

@ -280,12 +280,12 @@ ControlButton *ControlButtonTest_Styling::standardButtonWithTitle(const char *ti
backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size backgroundButton->setPreferredSize(Size(45, 45)); // Set the prefered size
auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png"); auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png");
backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size backgroundHighlightedButton->setPreferredSize(Size(45, 45)); // Set the prefered size
auto titleButton = Label::createWithTTF(title, "fonts/Marker Felt.ttf", 30); auto titleButton = Label::createWithTTF(title, "fonts/Marker Felt.ttf", 30);
titleButton->setColor(Color3B(159, 168, 176)); titleButton->setColor(Color3B(159, 168, 176));
ControlButton *button = ControlButton::create(titleButton, backgroundButton); ControlButton *button = ControlButton::create(titleButton, backgroundButton,false);
button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED); button->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED);
button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED); button->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED);

View File

@ -13,6 +13,7 @@ UIPageViewTests::UIPageViewTests()
ADD_TEST_CASE(UIPageViewJumpToPageTest); ADD_TEST_CASE(UIPageViewJumpToPageTest);
ADD_TEST_CASE(UIPageViewVerticalTest); ADD_TEST_CASE(UIPageViewVerticalTest);
ADD_TEST_CASE(UIPageViewDisableTouchTest); ADD_TEST_CASE(UIPageViewDisableTouchTest);
ADD_TEST_CASE(UIPageViewChildSizeTest);
} }
// UIPageViewTest // UIPageViewTest
@ -876,3 +877,88 @@ bool UIPageViewDisableTouchTest::init()
return false; 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<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(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<PageView*>(pSender);
_displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1));
}
break;
default:
break;
}
}

View File

@ -139,4 +139,20 @@ protected:
cocos2d::ui::Text* _displayValueLabel; 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__) */ #endif /* defined(__TestCpp__UIPageViewTest__) */

View File

@ -55,6 +55,8 @@ UIScale9SpriteTests::UIScale9SpriteTests()
ADD_TEST_CASE(UIS9NinePatchTest); ADD_TEST_CASE(UIS9NinePatchTest);
ADD_TEST_CASE(UIS9BatchTest); ADD_TEST_CASE(UIS9BatchTest);
ADD_TEST_CASE(UIS9ToggleRenderingTypeTest); ADD_TEST_CASE(UIS9ToggleRenderingTypeTest);
ADD_TEST_CASE(UIS9GlobalZOrderTest);
ADD_TEST_CASE(UIS9EnableScale9FalseTest);
} }
// UIScale9SpriteTest // UIScale9SpriteTest
@ -92,6 +94,7 @@ bool UIScale9SpriteTest::init()
normalSprite2->setPosition(120, 270); normalSprite2->setPosition(120, 270);
normalSprite2->setScale9Enabled(false); normalSprite2->setScale9Enabled(false);
normalSprite2->setOpacity(100); normalSprite2->setOpacity(100);
normalSprite2->setContentSize(normalSprite2->getContentSize() * 2);
this->addChild(normalSprite2); this->addChild(normalSprite2);
normalSprite2->setColor(Color3B::GREEN); normalSprite2->setColor(Color3B::GREEN);
normalSprite2->runAction(action); normalSprite2->runAction(action);
@ -994,3 +997,82 @@ bool UIS9ToggleRenderingTypeTest::init()
return false; 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;
}

View File

@ -274,4 +274,20 @@ public:
virtual bool init() override; 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__) */ #endif /* defined(__cocos2d_tests__UIScale9SpriteTest__) */

View File

@ -33,6 +33,7 @@
"src/TouchesTest/TouchesTest.js", "src/TouchesTest/TouchesTest.js",
"src/SchedulerTest/SchedulerTest.js", "src/SchedulerTest/SchedulerTest.js",
"src/MenuTest/MenuTest.js", "src/MenuTest/MenuTest.js",
"src/MemoryModelTest/MemoryModelTest.js",
"src/ActionsTest/ActionsTest.js", "src/ActionsTest/ActionsTest.js",
"src/TileMapTest/TileMapTest.js", "src/TileMapTest/TileMapTest.js",
"src/TransitionsTest/TransitionsTest.js", "src/TransitionsTest/TransitionsTest.js",

View File

@ -485,29 +485,15 @@ bool js_cocos2dx_DrawNode3D_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
bool ok = true; bool ok = true;
cocos2d::DrawNode3D* cobj = new (std::nothrow) cocos2d::DrawNode3D(); cocos2d::DrawNode3D* cobj = new (std::nothrow) cocos2d::DrawNode3D;
cobj->init(); cobj->init();
cocos2d::Ref *_ccobj = dynamic_cast<cocos2d::Ref *>(cobj); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::DrawNode3D>(cobj);
if (_ccobj) {
_ccobj->autorelease();
}
TypeTest<cocos2d::DrawNode3D> 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));
// link the native object with the javascript object // link the native object with the javascript object
js_proxy_t* p = jsb_new_proxy(cobj, obj); JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "cocos2d::DrawNode3D"));
AddNamedObjectRoot(cx, &p->obj, "cocos2d::DrawNode3D"); args.rval().set(OBJECT_TO_JSVAL(jsobj));
if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok)
ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args);
return true; 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; 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) { void js_register_cocos2dx_DrawNode3D(JSContext *cx, JS::HandleObject global) {
jsb_cocos2d_DrawNode3D_class = (JSClass *)calloc(1, sizeof(JSClass)); 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->enumerate = JS_EnumerateStub;
jsb_cocos2d_DrawNode3D_class->resolve = JS_ResolveStub; jsb_cocos2d_DrawNode3D_class->resolve = JS_ResolveStub;
jsb_cocos2d_DrawNode3D_class->convert = JS_ConvertStub; 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); jsb_cocos2d_DrawNode3D_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
static JSPropertySpec properties[] = { static JSPropertySpec properties[] = {

View File

@ -188,8 +188,6 @@ var UIFocusTestVertical = UIFocusTestBase.extend({
w.setTag(i); w.setTag(i);
w.addTouchEventListener(this.onImageViewClicked, this); w.addTouchEventListener(this.onImageViewClicked, this);
this._verticalLayout.addChild(w); this._verticalLayout.addChild(w);
if (i == 2)
w.requestFocus();
} }
this._loopText = new ccui.Text("loop enabled", "Arial", 20); this._loopText = new ccui.Text("loop enabled", "Arial", 20);

View File

@ -0,0 +1,263 @@
/****************************************************************************
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 () {
cc.sys.garbageCollect();
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;
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);
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);
},
});
//------------------------------------------------------------------
//
// 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
//
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,
RootUnrootMemoryModelTest,
];
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]();
};

View File

@ -479,6 +479,15 @@ var testNames = [
return new MaterialSystemTestScene(); 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", title:"Menu Test",
resource:g_menu, resource:g_menu,

@ -1 +1 @@
Subproject commit b940871c1dfff94c0220364539dd9d0583995719 Subproject commit 26b56a42b7ea74ca7acb4003c7f98fe149741503

View File

@ -87,8 +87,8 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat
Range::[*], Range::[*],
NotificationObserver::[*], NotificationObserver::[*],
Image::[initWithString initWithImageData], Image::[initWithString initWithImageData],
Sequence::[create init], Sequence::[create],
Spawn::[create init], Spawn::[create],
RotateTo::[calculateAngles], RotateTo::[calculateAngles],
GLProgram::[getProgram setUniformLocationWith(1|2|3|4)fv setUniformLocationWith(2|3|4)iv setUniformLocationWithMatrix(2|3|4)fv], GLProgram::[getProgram setUniformLocationWith(1|2|3|4)fv setUniformLocationWith(2|3|4)iv setUniformLocationWithMatrix(2|3|4)fv],
GLProgramState::[setUniformVec4 setVertexAttribPointer], GLProgramState::[setUniformVec4 setVertexAttribPointer],

View File

@ -43,7 +43,7 @@ skip = Skeleton3D::[create],
Sprite3D::[getAABB getMeshArrayByName createAsync], Sprite3D::[getAABB getMeshArrayByName createAsync],
Mesh::[create getMeshCommand getAABB getDefaultGLProgram getMeshVertexAttribute draw setTexture getTexture], Mesh::[create getMeshCommand getAABB getDefaultGLProgram getMeshVertexAttribute draw setTexture getTexture],
Sprite3DCache::[addSprite3DData getSpriteData], Sprite3DCache::[addSprite3DData getSpriteData],
Animation3D::[getBoneCurves], Animation3D::[create getBoneCurves],
Animate3D::[getKeyFrameUserInfo], Animate3D::[getKeyFrameUserInfo],
TextureCube::[setTexParameters], TextureCube::[setTexParameters],
Terrain::[getAABB getQuadTree create getHeightData], Terrain::[getAABB getQuadTree create getHeightData],