mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Merge branch 'develop' into native-modules
# Conflicts: # cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp # cocos/scripting/js-bindings/manual/jsb_creator_physics_manual.cpp
This commit is contained in:
@@ -31,6 +31,13 @@
|
||||
#include <spine/spine-cocos2dx.h>
|
||||
#include <spine/extension.h>
|
||||
|
||||
namespace spine {
|
||||
static CustomTextureLoader _customTextureLoader = nullptr;
|
||||
void spAtlasPage_setCustomTextureLoader (CustomTextureLoader texLoader) {
|
||||
_customTextureLoader = texLoader;
|
||||
}
|
||||
}
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
GLuint wrap (spAtlasWrap wrap) {
|
||||
@@ -60,7 +67,13 @@ GLuint filter (spAtlasFilter filter) {
|
||||
}
|
||||
|
||||
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) {
|
||||
Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(path);
|
||||
Texture2D* texture = nullptr;
|
||||
if (spine::_customTextureLoader) {
|
||||
texture = spine::_customTextureLoader(path);
|
||||
}
|
||||
if (!texture) {
|
||||
texture = Director::getInstance()->getTextureCache()->addImage(path);
|
||||
}
|
||||
CCASSERT(texture != nullptr, "Invalid image");
|
||||
texture->retain();
|
||||
|
||||
|
||||
@@ -38,4 +38,10 @@
|
||||
#include <spine/SkeletonAnimation.h>
|
||||
#include <spine/SkeletonBatch.h>
|
||||
|
||||
namespace spine {
|
||||
typedef cocos2d::Texture2D* (*CustomTextureLoader)(const char* path);
|
||||
// set custom texture loader for _spAtlasPage_createTexture
|
||||
void spAtlasPage_setCustomTextureLoader(CustomTextureLoader texLoader);
|
||||
}
|
||||
|
||||
#endif /* SPINE_COCOS2DX_H_ */
|
||||
|
||||
@@ -613,13 +613,18 @@ WebSocketImpl::WebSocketImpl(cocos2d::network::WebSocket* ws)
|
||||
}
|
||||
|
||||
__websocketInstances->push_back(this);
|
||||
|
||||
std::shared_ptr<std::atomic<bool>> isDestroyed = _isDestroyed;
|
||||
_resetDirectorListener = cocos2d::Director::getInstance()->getEventDispatcher()->addCustomEventListener(cocos2d::Director::EVENT_RESET, [this, isDestroyed](cocos2d::EventCustom*){
|
||||
if (*isDestroyed)
|
||||
return;
|
||||
close();
|
||||
});
|
||||
|
||||
// NOTE: !!! Be careful while merging cocos2d-x-lite back to cocos2d-x. !!!
|
||||
// 'close' is a synchronous operation which may wait some seconds to make sure connection is closed.
|
||||
// But JSB doesn't need to listen on EVENT_RESET event to close connection,
|
||||
// since finalize callback (refer to 'WebSocket_finalize' function in jsb_websocket.cpp) will invoke 'closeAsync'.
|
||||
//
|
||||
// std::shared_ptr<std::atomic<bool>> isDestroyed = _isDestroyed;
|
||||
// _resetDirectorListener = cocos2d::Director::getInstance()->getEventDispatcher()->addCustomEventListener(cocos2d::Director::EVENT_RESET, [this, isDestroyed](cocos2d::EventCustom*){
|
||||
// if (*isDestroyed)
|
||||
// return;
|
||||
// close();
|
||||
// });
|
||||
}
|
||||
|
||||
WebSocketImpl::~WebSocketImpl()
|
||||
@@ -651,8 +656,9 @@ WebSocketImpl::~WebSocketImpl()
|
||||
CC_SAFE_DELETE(__wsHelper);
|
||||
}
|
||||
|
||||
cocos2d::Director::getInstance()->getEventDispatcher()->removeEventListener(_resetDirectorListener);
|
||||
|
||||
// NOTE: Refer to the comment in constructor!!!
|
||||
// cocos2d::Director::getInstance()->getEventDispatcher()->removeEventListener(_resetDirectorListener);
|
||||
|
||||
*_isDestroyed = true;
|
||||
}
|
||||
|
||||
|
||||
+21
-16
@@ -55,6 +55,7 @@ import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
public class Cocos2dxHttpURLConnection
|
||||
{
|
||||
private static String TAG = "Cocos2dxHttpURLConnection";
|
||||
private static final String POST_METHOD = "POST" ;
|
||||
private static final String PUT_METHOD = "PUT" ;
|
||||
|
||||
@@ -68,7 +69,8 @@ public class Cocos2dxHttpURLConnection
|
||||
urlConnection.setRequestProperty("Accept-Encoding", "identity");
|
||||
urlConnection.setDoInput(true);
|
||||
} catch (Exception e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "createHttpURLConnection:" + e.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ public class Cocos2dxHttpURLConnection
|
||||
urlConnection.setDoOutput(true);
|
||||
}
|
||||
} catch (ProtocolException e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
Log.e(TAG, "setRequestMethod:" + e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -132,7 +134,8 @@ public class Cocos2dxHttpURLConnection
|
||||
|
||||
httpsURLConnection.setSSLSocketFactory(context.getSocketFactory());
|
||||
} catch (Exception e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "setVerifySSL:" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,12 +149,9 @@ public class Cocos2dxHttpURLConnection
|
||||
|
||||
try {
|
||||
http.connect();
|
||||
} catch (IOException e) {
|
||||
Log.e("cocos2d-x debug info", "come in connect");
|
||||
Log.e("cocos2d-x debug info", e.toString());
|
||||
suc = 1;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "connect" + e.toString());
|
||||
suc = 1;
|
||||
}
|
||||
|
||||
@@ -170,8 +170,9 @@ public class Cocos2dxHttpURLConnection
|
||||
out.flush();
|
||||
}
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "sendRequest:" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +273,8 @@ public class Cocos2dxHttpURLConnection
|
||||
} catch (IOException e) {
|
||||
in = http.getErrorStream();
|
||||
} catch (Exception e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "1 getResponseContent: " + e.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -288,7 +290,8 @@ public class Cocos2dxHttpURLConnection
|
||||
bytestream.close();
|
||||
return retbuffer;
|
||||
} catch (Exception e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "2 getResponseContent:" + e.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -298,8 +301,9 @@ public class Cocos2dxHttpURLConnection
|
||||
int code = 0;
|
||||
try {
|
||||
code = http.getResponseCode();
|
||||
} catch (IOException e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "getResponseCode:" + e.toString());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
@@ -308,9 +312,10 @@ public class Cocos2dxHttpURLConnection
|
||||
String msg;
|
||||
try {
|
||||
msg = http.getResponseMessage();
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
msg = e.toString();
|
||||
Log.e("URLConnection exception", msg);
|
||||
Log.e(TAG, "getResponseMessage: " + msg);
|
||||
}
|
||||
|
||||
return msg;
|
||||
@@ -399,7 +404,7 @@ public class Cocos2dxHttpURLConnection
|
||||
c.setTime(new SimpleDateFormat("EEE, dd-MMM-yy hh:mm:ss zzz", Locale.US).parse(strTime));
|
||||
milliseconds = c.getTimeInMillis() / 1000;
|
||||
} catch (ParseException e) {
|
||||
Log.e("URLConnection exception", e.toString());
|
||||
Log.e(TAG, "str2Seconds: " + e.toString());
|
||||
}
|
||||
|
||||
return Long.toString(milliseconds);
|
||||
|
||||
@@ -694,7 +694,7 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
|
||||
static bool js_b2CircleShape_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2CircleShape)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2CircleShape)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
@@ -912,7 +912,7 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
|
||||
static bool js_b2EdgeShape_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2EdgeShape)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2EdgeShape)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
@@ -1180,7 +1180,7 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
|
||||
static bool js_b2ChainShape_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2ChainShape)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2ChainShape)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
@@ -1434,7 +1434,7 @@ extern se::Object* __jsb_b2Shape_proto;
|
||||
|
||||
static bool js_b2PolygonShape_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2PolygonShape)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2PolygonShape)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
@@ -2475,7 +2475,7 @@ SE_BIND_FUNC(js_box2dclasses_b2Body_GetPosition)
|
||||
|
||||
static bool js_b2Body_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2Body)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2Body)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2Body_finalize)
|
||||
@@ -2969,7 +2969,7 @@ SE_BIND_FUNC(js_box2dclasses_b2Fixture_GetDensity)
|
||||
|
||||
static bool js_b2Fixture_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2Fixture)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2Fixture)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2Fixture_finalize)
|
||||
@@ -3918,7 +3918,7 @@ SE_BIND_CTOR(js_box2dclasses_b2World_constructor, __jsb_b2World_class, js_b2Worl
|
||||
|
||||
static bool js_b2World_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2World)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2World)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
@@ -4386,7 +4386,7 @@ SE_BIND_FUNC(js_box2dclasses_b2Contact_ResetRestitution)
|
||||
|
||||
static bool js_b2Contact_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2Contact)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2Contact)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2Contact_finalize)
|
||||
@@ -4664,7 +4664,7 @@ SE_BIND_FUNC(js_box2dclasses_b2Joint_IsActive)
|
||||
|
||||
static bool js_b2Joint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2Joint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2Joint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2Joint_finalize)
|
||||
@@ -4944,7 +4944,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2DistanceJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2DistanceJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2DistanceJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2DistanceJoint_finalize)
|
||||
@@ -5188,7 +5188,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2FrictionJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2FrictionJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2FrictionJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2FrictionJoint_finalize)
|
||||
@@ -5393,7 +5393,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2GearJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2GearJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2GearJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2GearJoint_finalize)
|
||||
@@ -5708,7 +5708,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2MotorJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2MotorJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2MotorJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2MotorJoint_finalize)
|
||||
@@ -6011,7 +6011,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2MouseJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2MouseJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2MouseJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2MouseJoint_finalize)
|
||||
@@ -6480,7 +6480,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2PrismaticJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2PrismaticJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2PrismaticJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2PrismaticJoint_finalize)
|
||||
@@ -6769,7 +6769,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2PulleyJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2PulleyJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2PulleyJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2PulleyJoint_finalize)
|
||||
@@ -7219,7 +7219,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2RevoluteJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2RevoluteJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2RevoluteJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2RevoluteJoint_finalize)
|
||||
@@ -7453,7 +7453,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2RopeJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2RopeJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2RopeJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2RopeJoint_finalize)
|
||||
@@ -7712,7 +7712,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2WeldJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2WeldJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2WeldJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2WeldJoint_finalize)
|
||||
@@ -8141,7 +8141,7 @@ extern se::Object* __jsb_b2Joint_proto;
|
||||
|
||||
static bool js_b2WheelJoint_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (b2WheelJoint)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (b2WheelJoint)", s.nativeThisObject());
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_b2WheelJoint_finalize)
|
||||
|
||||
@@ -107,7 +107,7 @@ SE_BIND_CTOR(js_cocos2dx_audioengine_AudioProfile_constructor, __jsb_cocos2d_exp
|
||||
|
||||
static bool js_cocos2d_experimental_AudioProfile_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::experimental::AudioProfile)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::experimental::AudioProfile)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4562,7 +4562,7 @@ extern se::Object* __jsb_cocos2d_Node_proto;
|
||||
|
||||
static bool js_dragonBones_CCArmatureDisplay_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (dragonBones::CCArmatureDisplay)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (dragonBones::CCArmatureDisplay)", s.nativeThisObject());
|
||||
dragonBones::CCArmatureDisplay* cobj = (dragonBones::CCArmatureDisplay*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -4623,7 +4623,7 @@ extern se::Object* __jsb_cocos2d_Sprite_proto;
|
||||
|
||||
static bool js_dragonBones_DBCCSprite_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (dragonBones::DBCCSprite)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (dragonBones::DBCCSprite)", s.nativeThisObject());
|
||||
dragonBones::DBCCSprite* cobj = (dragonBones::DBCCSprite*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -4872,7 +4872,7 @@ extern se::Object* __jsb_dragonBones_BaseFactory_proto;
|
||||
|
||||
static bool js_dragonBones_CCFactory_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (dragonBones::CCFactory)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (dragonBones::CCFactory)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
|
||||
@@ -360,7 +360,7 @@ extern se::Object* __jsb_cocos2d_ui_Widget_proto;
|
||||
|
||||
static bool js_cocos2d_experimental_ui_VideoPlayer_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::experimental::ui::VideoPlayer)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::experimental::ui::VideoPlayer)", s.nativeThisObject());
|
||||
cocos2d::experimental::ui::VideoPlayer* cobj = (cocos2d::experimental::ui::VideoPlayer*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
|
||||
@@ -576,7 +576,7 @@ extern se::Object* __jsb_cocos2d_ui_Widget_proto;
|
||||
|
||||
static bool js_cocos2d_experimental_ui_WebView_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::experimental::ui::WebView)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::experimental::ui::WebView)", s.nativeThisObject());
|
||||
cocos2d::experimental::ui::WebView* cobj = (cocos2d::experimental::ui::WebView*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
|
||||
@@ -265,7 +265,7 @@ extern se::Object* __jsb_cocos2d_EventCustom_proto;
|
||||
|
||||
static bool js_cocos2d_extension_EventAssetsManagerEx_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::extension::EventAssetsManagerEx)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::extension::EventAssetsManagerEx)", s.nativeThisObject());
|
||||
cocos2d::extension::EventAssetsManagerEx* cobj = (cocos2d::extension::EventAssetsManagerEx*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -574,7 +574,7 @@ SE_BIND_CTOR(js_cocos2dx_extension_Manifest_constructor, __jsb_cocos2d_extension
|
||||
|
||||
static bool js_cocos2d_extension_Manifest_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::extension::Manifest)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::extension::Manifest)", s.nativeThisObject());
|
||||
cocos2d::extension::Manifest* cobj = (cocos2d::extension::Manifest*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -1142,7 +1142,7 @@ SE_BIND_CTOR(js_cocos2dx_extension_AssetsManagerEx_constructor, __jsb_cocos2d_ex
|
||||
|
||||
static bool js_cocos2d_extension_AssetsManagerEx_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::extension::AssetsManagerEx)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::extension::AssetsManagerEx)", s.nativeThisObject());
|
||||
cocos2d::extension::AssetsManagerEx* cobj = (cocos2d::extension::AssetsManagerEx*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -1310,7 +1310,7 @@ extern se::Object* __jsb_cocos2d_EventListenerCustom_proto;
|
||||
|
||||
static bool js_cocos2d_extension_EventListenerAssetsManagerEx_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::extension::EventListenerAssetsManagerEx)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::extension::EventListenerAssetsManagerEx)", s.nativeThisObject());
|
||||
cocos2d::extension::EventListenerAssetsManagerEx* cobj = (cocos2d::extension::EventListenerAssetsManagerEx*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
|
||||
@@ -228,7 +228,7 @@ SE_BIND_CTOR(js_cocos2dx_network_Downloader_constructor, __jsb_cocos2d_network_D
|
||||
|
||||
static bool js_cocos2d_network_Downloader_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::network::Downloader)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::network::Downloader)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
|
||||
@@ -749,7 +749,7 @@ extern se::Object* __jsb_cocos2d_Node_proto;
|
||||
|
||||
static bool js_spine_SkeletonRenderer_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (spine::SkeletonRenderer)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (spine::SkeletonRenderer)", s.nativeThisObject());
|
||||
spine::SkeletonRenderer* cobj = (spine::SkeletonRenderer*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -1682,7 +1682,7 @@ extern se::Object* __jsb_spine_SkeletonRenderer_proto;
|
||||
|
||||
static bool js_spine_SkeletonAnimation_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (spine::SkeletonAnimation)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (spine::SkeletonAnimation)", s.nativeThisObject());
|
||||
spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
|
||||
@@ -1338,7 +1338,7 @@ extern se::Object* __jsb_cocos2d_ProtectedNode_proto;
|
||||
|
||||
static bool js_cocos2d_ui_Widget_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::ui::Widget)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::ui::Widget)", s.nativeThisObject());
|
||||
cocos2d::ui::Widget* cobj = (cocos2d::ui::Widget*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -2630,7 +2630,7 @@ extern se::Object* __jsb_cocos2d_Node_proto;
|
||||
|
||||
static bool js_cocos2d_ui_Scale9Sprite_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::ui::Scale9Sprite)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::ui::Scale9Sprite)", s.nativeThisObject());
|
||||
cocos2d::ui::Scale9Sprite* cobj = (cocos2d::ui::Scale9Sprite*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
@@ -3244,7 +3244,7 @@ extern se::Object* __jsb_cocos2d_ui_Widget_proto;
|
||||
|
||||
static bool js_cocos2d_ui_EditBox_finalize(se::State& s)
|
||||
{
|
||||
CCLOG("jsbindings: finalizing JS object %p (cocos2d::ui::EditBox)", s.nativeThisObject());
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::ui::EditBox)", s.nativeThisObject());
|
||||
cocos2d::ui::EditBox* cobj = (cocos2d::ui::EditBox*)s.nativeThisObject();
|
||||
if (cobj->getReferenceCount() == 1)
|
||||
cobj->autorelease();
|
||||
|
||||
@@ -714,7 +714,185 @@ Delegate obj, onCallback: 6, this.myVar: 105
|
||||
setCallback(nullptr)
|
||||
```
|
||||
|
||||
###
|
||||
### 如何使用cocos2d-x bindings这层的类型转换辅助函数?
|
||||
|
||||
类型转换辅助函数位于`cocos/scripting/js-bindings/manual/jsb_conversions.hpp/.cpp`中,其包含:
|
||||
|
||||
#### se::Value转换为C++类型
|
||||
```
|
||||
bool seval_to_int32(const se::Value& v, int32_t* ret);
|
||||
bool seval_to_uint32(const se::Value& v, uint32_t* ret);
|
||||
bool seval_to_int8(const se::Value& v, int8_t* ret);
|
||||
bool seval_to_uint8(const se::Value& v, uint8_t* ret);
|
||||
bool seval_to_int16(const se::Value& v, int16_t* ret);
|
||||
bool seval_to_uint16(const se::Value& v, uint16_t* ret);
|
||||
bool seval_to_boolean(const se::Value& v, bool* ret);
|
||||
bool seval_to_float(const se::Value& v, float* ret);
|
||||
bool seval_to_double(const se::Value& v, double* ret);
|
||||
bool seval_to_long(const se::Value& v, long* ret);
|
||||
bool seval_to_ulong(const se::Value& v, unsigned long* ret);
|
||||
bool seval_to_longlong(const se::Value& v, long long* ret);
|
||||
bool seval_to_ssize(const se::Value& v, ssize_t* ret);
|
||||
bool seval_to_std_string(const se::Value& v, std::string* ret);
|
||||
bool seval_to_Vec2(const se::Value& v, cocos2d::Vec2* pt);
|
||||
bool seval_to_Vec3(const se::Value& v, cocos2d::Vec3* pt);
|
||||
bool seval_to_Vec4(const se::Value& v, cocos2d::Vec4* pt);
|
||||
bool seval_to_Mat4(const se::Value& v, cocos2d::Mat4* mat);
|
||||
bool seval_to_Size(const se::Value& v, cocos2d::Size* size);
|
||||
bool seval_to_Rect(const se::Value& v, cocos2d::Rect* rect);
|
||||
bool seval_to_Color3B(const se::Value& v, cocos2d::Color3B* color);
|
||||
bool seval_to_Color4B(const se::Value& v, cocos2d::Color4B* color);
|
||||
bool seval_to_Color4F(const se::Value& v, cocos2d::Color4F* color);
|
||||
bool seval_to_ccvalue(const se::Value& v, cocos2d::Value* ret);
|
||||
bool seval_to_ccvaluemap(const se::Value& v, cocos2d::ValueMap* ret);
|
||||
bool seval_to_ccvaluemapintkey(const se::Value& v, cocos2d::ValueMapIntKey* ret);
|
||||
bool seval_to_ccvaluevector(const se::Value& v, cocos2d::ValueVector* ret);
|
||||
bool sevals_variadic_to_ccvaluevector(const se::ValueArray& args, cocos2d::ValueVector* ret);
|
||||
bool seval_to_blendfunc(const se::Value& v, cocos2d::BlendFunc* ret);
|
||||
bool seval_to_std_vector_string(const se::Value& v, std::vector<std::string>* ret);
|
||||
bool seval_to_std_vector_int(const se::Value& v, std::vector<int>* ret);
|
||||
bool seval_to_std_vector_float(const se::Value& v, std::vector<float>* ret);
|
||||
bool seval_to_std_vector_Vec2(const se::Value& v, std::vector<cocos2d::Vec2>* ret);
|
||||
bool seval_to_std_vector_Touch(const se::Value& v, std::vector<cocos2d::Touch*>* ret);
|
||||
bool seval_to_std_map_string_string(const se::Value& v, std::map<std::string, std::string>* ret);
|
||||
bool seval_to_FontDefinition(const se::Value& v, cocos2d::FontDefinition* ret);
|
||||
bool seval_to_Acceleration(const se::Value& v, cocos2d::Acceleration* ret);
|
||||
bool seval_to_Quaternion(const se::Value& v, cocos2d::Quaternion* ret);
|
||||
bool seval_to_AffineTransform(const se::Value& v, cocos2d::AffineTransform* ret);
|
||||
//bool seval_to_Viewport(const se::Value& v, cocos2d::experimental::Viewport* ret);
|
||||
bool seval_to_Data(const se::Value& v, cocos2d::Data* ret);
|
||||
bool seval_to_DownloaderHints(const se::Value& v, cocos2d::network::DownloaderHints* ret);
|
||||
bool seval_to_TTFConfig(const se::Value& v, cocos2d::TTFConfig* ret);
|
||||
|
||||
//box2d seval to native convertion
|
||||
bool seval_to_b2Vec2(const se::Value& v, b2Vec2* ret);
|
||||
bool seval_to_b2AABB(const se::Value& v, b2AABB* ret);
|
||||
|
||||
template<typename T>
|
||||
bool seval_to_native_ptr(const se::Value& v, T* ret);
|
||||
|
||||
template<typename T>
|
||||
bool seval_to_Vector(const se::Value& v, cocos2d::Vector<T>* ret);
|
||||
|
||||
template<typename T>
|
||||
bool seval_to_Map_string_key(const se::Value& v, cocos2d::Map<std::string, T>* ret)
|
||||
|
||||
```
|
||||
|
||||
#### C++类型转换为se::Value
|
||||
|
||||
```c++
|
||||
bool int8_to_seval(int8_t v, se::Value* ret);
|
||||
bool uint8_to_seval(uint8_t v, se::Value* ret);
|
||||
bool int32_to_seval(int32_t v, se::Value* ret);
|
||||
bool uint32_to_seval(uint32_t v, se::Value* ret);
|
||||
bool int16_to_seval(uint16_t v, se::Value* ret);
|
||||
bool uint16_to_seval(uint16_t v, se::Value* ret);
|
||||
bool boolean_to_seval(bool v, se::Value* ret);
|
||||
bool float_to_seval(float v, se::Value* ret);
|
||||
bool double_to_seval(double v, se::Value* ret);
|
||||
bool long_to_seval(long v, se::Value* ret);
|
||||
bool ulong_to_seval(unsigned long v, se::Value* ret);
|
||||
bool longlong_to_seval(long long v, se::Value* ret);
|
||||
bool ssize_to_seval(ssize_t v, se::Value* ret);
|
||||
bool std_string_to_seval(const std::string& v, se::Value* ret);
|
||||
|
||||
bool Vec2_to_seval(const cocos2d::Vec2& v, se::Value* ret);
|
||||
bool Vec3_to_seval(const cocos2d::Vec3& v, se::Value* ret);
|
||||
bool Vec4_to_seval(const cocos2d::Vec4& v, se::Value* ret);
|
||||
bool Mat4_to_seval(const cocos2d::Mat4& v, se::Value* ret);
|
||||
bool Size_to_seval(const cocos2d::Size& v, se::Value* ret);
|
||||
bool Rect_to_seval(const cocos2d::Rect& v, se::Value* ret);
|
||||
bool Color3B_to_seval(const cocos2d::Color3B& v, se::Value* ret);
|
||||
bool Color4B_to_seval(const cocos2d::Color4B& v, se::Value* ret);
|
||||
bool Color4F_to_seval(const cocos2d::Color4F& v, se::Value* ret);
|
||||
bool ccvalue_to_seval(const cocos2d::Value& v, se::Value* ret);
|
||||
bool ccvaluemap_to_seval(const cocos2d::ValueMap& v, se::Value* ret);
|
||||
bool ccvaluemapintkey_to_seval(const cocos2d::ValueMapIntKey& v, se::Value* ret);
|
||||
bool ccvaluevector_to_seval(const cocos2d::ValueVector& v, se::Value* ret);
|
||||
bool blendfunc_to_seval(const cocos2d::BlendFunc& v, se::Value* ret);
|
||||
bool std_vector_string_to_seval(const std::vector<std::string>& v, se::Value* ret);
|
||||
bool std_vector_int_to_seval(const std::vector<int>& v, se::Value* ret);
|
||||
bool std_vector_float_to_seval(const std::vector<float>& v, se::Value* ret);
|
||||
bool std_vector_Touch_to_seval(const std::vector<cocos2d::Touch*>& v, se::Value* ret);
|
||||
bool std_map_string_string_to_seval(const std::map<std::string, std::string>& v, se::Value* ret);
|
||||
bool uniform_to_seval(const cocos2d::Uniform* v, se::Value* ret);
|
||||
bool FontDefinition_to_seval(const cocos2d::FontDefinition& v, se::Value* ret);
|
||||
bool Acceleration_to_seval(const cocos2d::Acceleration* v, se::Value* ret);
|
||||
bool Quaternion_to_seval(const cocos2d::Quaternion& v, se::Value* ret);
|
||||
bool ManifestAsset_to_seval(const cocos2d::extension::ManifestAsset& v, se::Value* ret);
|
||||
bool AffineTransform_to_seval(const cocos2d::AffineTransform& v, se::Value* ret);
|
||||
bool Data_to_seval(const cocos2d::Data& v, se::Value* ret);
|
||||
bool DownloadTask_to_seval(const cocos2d::network::DownloadTask& v, se::Value* ret);
|
||||
|
||||
template<typename T>
|
||||
bool Vector_to_seval(const cocos2d::Vector<T*>& v, se::Value* ret);
|
||||
|
||||
template<typename T>
|
||||
bool Map_string_key_to_seval(const cocos2d::Map<std::string, T*>& v, se::Value* ret);
|
||||
|
||||
template<typename T>
|
||||
bool native_ptr_to_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Value* ret, bool* isReturnCachedValue = nullptr);
|
||||
|
||||
template<typename T>
|
||||
bool native_ptr_to_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Class* cls, se::Value* ret, bool* isReturnCachedValue = nullptr)
|
||||
|
||||
template<typename T>
|
||||
bool native_ptr_to_seval(typename std::enable_if<std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Value* ret, bool* isReturnCachedValue = nullptr);
|
||||
|
||||
template<typename T>
|
||||
bool native_ptr_to_seval(typename std::enable_if<std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Class* cls, se::Value* ret, bool* isReturnCachedValue = nullptr);
|
||||
|
||||
template<typename T>
|
||||
bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Value* ret, bool* isReturnCachedValue = nullptr);
|
||||
|
||||
template<typename T>
|
||||
bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d::Ref,T>::value,T>::type* v, se::Class* cls, se::Value* ret, bool* isReturnCachedValue = nullptr);
|
||||
|
||||
|
||||
// Spine conversions
|
||||
bool speventdata_to_seval(const spEventData& v, se::Value* ret);
|
||||
bool spevent_to_seval(const spEvent& v, se::Value* ret);
|
||||
bool spbonedata_to_seval(const spBoneData& v, se::Value* ret);
|
||||
bool spbone_to_seval(const spBone& v, se::Value* ret);
|
||||
bool spskeleton_to_seval(const spSkeleton& v, se::Value* ret);
|
||||
bool spattachment_to_seval(const spAttachment& v, se::Value* ret);
|
||||
bool spslotdata_to_seval(const spSlotData& v, se::Value* ret);
|
||||
bool spslot_to_seval(const spSlot& v, se::Value* ret);
|
||||
bool sptimeline_to_seval(const spTimeline& v, se::Value* ret);
|
||||
bool spanimationstate_to_seval(const spAnimationState& v, se::Value* ret);
|
||||
bool spanimation_to_seval(const spAnimation& v, se::Value* ret);
|
||||
bool sptrackentry_to_seval(const spTrackEntry& v, se::Value* ret);
|
||||
|
||||
// Box2d
|
||||
bool b2Vec2_to_seval(const b2Vec2& v, se::Value* ret);
|
||||
bool b2Manifold_to_seval(const b2Manifold* v, se::Value* ret);
|
||||
bool b2AABB_to_seval(const b2AABB& v, se::Value* ret);
|
||||
|
||||
```
|
||||
|
||||
辅助转换函数不属于`Script Engine Wrapper`抽象层,属于cocos2d-x绑定层,封装这些函数是为了在绑定代码中更加方便的转换。
|
||||
每个转换函数都返回`bool`类型,表示转换是否成功,开发者如果调用这些接口,需要去判断这个返回值。
|
||||
|
||||
以上接口,直接根据接口名称即可知道具体的用法,接口中第一个参数为输入,第二个参数为输出参数。用法如下:
|
||||
|
||||
```c++
|
||||
se::Value v;
|
||||
bool ok = int32_to_seval(100, &v); // 第二个参数为输出参数,传入输出参数的地址
|
||||
```
|
||||
|
||||
```c++
|
||||
int32_t v;
|
||||
bool ok = seval_to_int32(args[0], &v); // 第二个参数为输出参数,传入输出参数的地址
|
||||
```
|
||||
|
||||
#### (IMPORTANT)理解native\_ptr\_to\_seval与native\_ptr\_to\_rooted\_seval的区别
|
||||
|
||||
**开发者一定要理解清楚这二者的区别,才不会因为误用导致JS层内存泄露这种比较难查的bug。**
|
||||
|
||||
* `native_ptr_to_seval`用于`JS控制CPP对象生命周期`的模式。当在绑定层需要根据一个CPP对象指针获取一个se::Value的时候,可调用此方法。引擎内大部分继承于`cocos2d::Ref`的子类都采取这种方式去获取se::Value。记住一点,当你管理的绑定对象是由JS控制生命周期,需要转换为seval的时候,请用此方法,否则考虑用`native_ptr_to_rooted_seval`。
|
||||
* `native_ptr_to_rooted_seval`用于`CPP控制JS对象生命周期`的模式。一般而言,第三方库中的对象绑定都会用到此方法。此方法会根据传入的CPP对象指针查找cache住的se::Object,如果不存在,则创建一个rooted的se::Object,即这个创建出来的JS对象将不受GC控制,并永远在内存中。开发者需要监听CPP对象的释放,并在释放的时候去做se::Object的unroot操作,具体可参照前面章节中描述的spTrackEntry_setDisposeCallback中的内容。
|
||||
|
||||
|
||||
## 自动绑定
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge_evalSt
|
||||
#define JSJ_ERR_EXCEPTION_OCCURRED (-4)
|
||||
#define JSJ_ERR_VM_THREAD_DETACHED (-5)
|
||||
#define JSJ_ERR_VM_FAILURE (-6)
|
||||
#define JSJ_ERR_CLASS_NOT_FOUND (-7)
|
||||
|
||||
class JavaScriptJavaBridge
|
||||
{
|
||||
@@ -374,6 +375,9 @@ bool JavaScriptJavaBridge::CallInfo::getMethodInfo()
|
||||
|
||||
if (NULL == m_classID) {
|
||||
LOGD("Classloader failed to find class of %s", m_className.c_str());
|
||||
m_env->ExceptionClear();
|
||||
m_error = JSJ_ERR_CLASS_NOT_FOUND;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_env->DeleteLocalRef(_jstrClassName);
|
||||
|
||||
@@ -214,6 +214,8 @@ static bool JSB_localStorageGetItem(se::State& s)
|
||||
ok = localStorageGetItem(key, &value);
|
||||
if (ok)
|
||||
s.rval().setString(value);
|
||||
else
|
||||
s.rval().setNull(); // Should return null to make JSB behavior same as Browser since returning undefined will make JSON.parse(undefined) trigger exception.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "jsb_creator_physics_manual.hpp"
|
||||
#include "jsb_creator_manual.hpp"
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
|
||||
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "cocos/scripting/js-bindings/manual/jsb_box2d_manual.hpp"
|
||||
#include "cocos/scripting/js-bindings/auto/jsb_creator_physics_auto.hpp"
|
||||
#include "cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp"
|
||||
#include "cocos/scripting/js-bindings/auto/jsb_box2d_auto.hpp"
|
||||
|
||||
#include "editor-support/creator/physics/CCPhysicsContactListener.h"
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "editor-support/creator/physics/CCPhysicsRayCastCallback.h"
|
||||
#include "editor-support/creator/physics/CCPhysicsContactImpulse.h"
|
||||
|
||||
#include "editor-support/spine/spine-cocos2dx.h"
|
||||
|
||||
static bool js_creator_PhysicsContactListener_setPreSolve(se::State& s)
|
||||
{
|
||||
creator::PhysicsContactListener* cobj = (creator::PhysicsContactListener*)s.nativeThisObject();
|
||||
@@ -253,8 +255,70 @@ static bool js_creator_PhysicsRayCastCallback_getNormals(se::State& s)
|
||||
}
|
||||
SE_BIND_FUNC(js_creator_PhysicsRayCastCallback_getNormals)
|
||||
|
||||
bool register_all_creator_physics_manual(se::Object* obj)
|
||||
|
||||
static cocos2d::Map<std::string, cocos2d::Texture2D*>* _preloadedAtlasTextures = nullptr;
|
||||
static cocos2d::Texture2D* _getPreloadedAtlasTexture(const char* path)
|
||||
{
|
||||
assert(_preloadedAtlasTextures);
|
||||
auto it = _preloadedAtlasTextures->find(path);
|
||||
return it != _preloadedAtlasTextures->end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
static bool js_creator_sp_initSkeletonRenderer(se::State& s)
|
||||
{
|
||||
// renderer, jsonPath, atlasText, textures, scale
|
||||
const auto& args = s.args();
|
||||
int argc = (int)args.size();
|
||||
if (argc != 5) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", argc, 5);
|
||||
return false;
|
||||
}
|
||||
bool ok = false;
|
||||
|
||||
spine::SkeletonRenderer* node = nullptr;
|
||||
ok = seval_to_native_ptr(args[0], &node);
|
||||
SE_PRECONDITION2(ok, false, "js_creator_sp_initSkeletonRenderer: Converting 'sgNode' failed!");
|
||||
|
||||
std::string jsonPath;
|
||||
ok = seval_to_std_string(args[1], &jsonPath);
|
||||
SE_PRECONDITION2(ok, false, "js_creator_sp_initSkeletonRenderer: Invalid json path!");
|
||||
|
||||
std::string atlasText;
|
||||
ok = seval_to_std_string(args[2], &atlasText);
|
||||
SE_PRECONDITION2(ok, false, "js_creator_sp_initSkeletonRenderer: Invalid atlas content!");
|
||||
|
||||
cocos2d::Map<std::string, cocos2d::Texture2D*> textures;
|
||||
ok = seval_to_Map_string_key(args[3], &textures);
|
||||
SE_PRECONDITION2(ok, false, "js_creator_sp_initSkeletonRenderer: Invalid textures!");
|
||||
|
||||
float scale = 1.0f;
|
||||
ok = seval_to_float(args[4], &scale);
|
||||
SE_PRECONDITION2(ok, false, "js_creator_sp_initSkeletonRenderer: Invalid scale!");
|
||||
|
||||
// create atlas from preloaded texture
|
||||
|
||||
_preloadedAtlasTextures = &textures;
|
||||
spine::spAtlasPage_setCustomTextureLoader(_getPreloadedAtlasTexture);
|
||||
|
||||
spAtlas* atlas = spAtlas_create(atlasText.c_str(), (int)atlasText.size(), "", nullptr);
|
||||
CCASSERT(atlas, "Error creating atlas.");
|
||||
|
||||
_preloadedAtlasTextures = nullptr;
|
||||
spine::spAtlasPage_setCustomTextureLoader(nullptr);
|
||||
|
||||
// init node
|
||||
node->initWithJsonFile(jsonPath, atlas, scale);
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_creator_sp_initSkeletonRenderer)
|
||||
|
||||
|
||||
bool register_all_creator_manual(se::Object* obj)
|
||||
{
|
||||
|
||||
// Physics
|
||||
|
||||
__jsb_creator_PhysicsContactListener_proto->defineFunction("setPreSolve", _SE(js_creator_PhysicsContactListener_setPreSolve));
|
||||
__jsb_creator_PhysicsContactListener_proto->defineFunction("setPostSolve", _SE(js_creator_PhysicsContactListener_setPostSolve));
|
||||
__jsb_creator_PhysicsContactListener_proto->defineFunction("setBeginContact", _SE(js_creator_PhysicsContactListener_setBeginContact));
|
||||
@@ -266,6 +330,15 @@ bool register_all_creator_physics_manual(se::Object* obj)
|
||||
__jsb_creator_PhysicsRayCastCallback_proto->defineFunction("getPoints", _SE(js_creator_PhysicsRayCastCallback_getPoints));
|
||||
__jsb_creator_PhysicsRayCastCallback_proto->defineFunction("getNormals", _SE(js_creator_PhysicsRayCastCallback_getNormals));
|
||||
|
||||
// Spine
|
||||
|
||||
se::Value nsVal;
|
||||
assert(obj->getProperty("sp", &nsVal));
|
||||
se::Object* ns = nsVal.toObject();
|
||||
|
||||
ns->defineFunction("_initSkeletonRenderer", _SE(js_creator_sp_initSkeletonRenderer));
|
||||
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
|
||||
se::Value func;
|
||||
bool ok = _JSDelegate.toObject()->getProperty("onopen", &func);
|
||||
if (ok)
|
||||
if (ok && func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(jsObj));
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
se::Value func;
|
||||
bool ok = _JSDelegate.toObject()->getProperty("onmessage", &func);
|
||||
if (ok)
|
||||
if (ok && func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(jsObj));
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
|
||||
se::Value func;
|
||||
bool ok = _JSDelegate.toObject()->getProperty("onclose", &func);
|
||||
if (ok)
|
||||
if (ok && func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(jsObj));
|
||||
@@ -215,7 +215,7 @@ public:
|
||||
|
||||
se::Value func;
|
||||
bool ok = _JSDelegate.toObject()->getProperty("onerror", &func);
|
||||
if (ok)
|
||||
if (ok && func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(jsObj));
|
||||
|
||||
@@ -330,7 +330,7 @@ void XMLHttpRequest::onResponse(HttpClient* client, HttpResponse* response)
|
||||
std::string tag = response->getHttpRequest()->getTag();
|
||||
if (!tag.empty())
|
||||
{
|
||||
CCLOG("%s completed", tag.c_str());
|
||||
LOGD("XMLHttpRequest::onResponse, %s completed\n", tag.c_str());
|
||||
}
|
||||
|
||||
long statusCode = response->getResponseCode();
|
||||
@@ -343,7 +343,7 @@ void XMLHttpRequest::onResponse(HttpClient* client, HttpResponse* response)
|
||||
if (!response->isSucceed())
|
||||
{
|
||||
std::string errorBuffer = response->getErrorBuffer();
|
||||
LOGD("Response failed, error buffer: %s", errorBuffer.c_str());
|
||||
LOGD("Response failed, error buffer: %s\n", errorBuffer.c_str());
|
||||
if (statusCode == 0 || statusCode == -1)
|
||||
{
|
||||
_errorFlag = true;
|
||||
@@ -606,8 +606,13 @@ static bool XMLHttpRequest_open(se::State& s)
|
||||
if (argc >= 2)
|
||||
{
|
||||
XMLHttpRequest* request = (XMLHttpRequest*)s.nativeThisObject();
|
||||
const std::string& method = args[0].toString();
|
||||
const std::string& url = args[1].toString();
|
||||
bool ok = false;
|
||||
std::string method;
|
||||
ok = seval_to_std_string(args[0], &method);
|
||||
SE_PRECONDITION2(ok, false, "args[0] isn't a string.");
|
||||
std::string url;
|
||||
ok = seval_to_std_string(args[1], &url);
|
||||
SE_PRECONDITION2(ok, false, "args[1] isn't a string.");
|
||||
bool ret = request->open(method, url);
|
||||
s.rval().setBoolean(ret);
|
||||
return true;
|
||||
@@ -658,7 +663,7 @@ static bool XMLHttpRequest_send(se::State& s)
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
SE_PRECONDITION2(false, false, "args[0] isn't a typed array");
|
||||
}
|
||||
}
|
||||
else if (obj->isArrayBuffer())
|
||||
@@ -673,12 +678,12 @@ static bool XMLHttpRequest_send(se::State& s)
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
SE_PRECONDITION2(false, false, "args[0] isn't an array buffer");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
SE_PRECONDITION2(false, false, "args[0] isn't a typed array or an array buffer");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -695,9 +700,13 @@ static bool XMLHttpRequest_setRequestHeader(se::State& s)
|
||||
if (argc >= 2)
|
||||
{
|
||||
XMLHttpRequest* xhr = (XMLHttpRequest*)s.nativeThisObject();
|
||||
|
||||
assert(args[0].isString() && args[1].isString());
|
||||
xhr->setRequestHeader(args[0].toString(), args[1].toString());
|
||||
std::string key;
|
||||
bool ok = seval_to_std_string(args[0], &key);
|
||||
SE_PRECONDITION2(ok, false, "args[0] couldn't be converted to string.");
|
||||
std::string value;
|
||||
ok = seval_to_std_string(args[1], &value);
|
||||
SE_PRECONDITION2(ok, false, "args[1] couldn't be converted to string.");
|
||||
xhr->setRequestHeader(key, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -719,18 +728,25 @@ static bool XMLHttpRequest_getResonpseHeader(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
XMLHttpRequest* xhr = (XMLHttpRequest*)s.nativeThisObject();
|
||||
assert(argc > 0);
|
||||
assert(args[0].isString());
|
||||
std::string header = xhr->getResonpseHeader(args[0].toString());
|
||||
s.rval().setString(header);
|
||||
return true;
|
||||
if (argc > 0)
|
||||
{
|
||||
XMLHttpRequest* xhr = (XMLHttpRequest*)s.nativeThisObject();
|
||||
std::string key;
|
||||
bool ok = seval_to_std_string(args[0], &key);
|
||||
SE_PRECONDITION2(ok, false, "args[0] couldn't be converted to string.");
|
||||
std::string header = xhr->getResonpseHeader(key);
|
||||
s.rval().setString(header);
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting > 0", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(XMLHttpRequest_getResonpseHeader)
|
||||
|
||||
static bool XMLHttpRequest_overrideMimeType(se::State& s)
|
||||
{
|
||||
assert(false); //FIXME:
|
||||
LOGD("XMLHttpRequest.overrideMimeType isn't implemented on JSB!");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(XMLHttpRequest_overrideMimeType)
|
||||
@@ -769,7 +785,6 @@ static bool XMLHttpRequest_getResponseText(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(XMLHttpRequest_getResponseText)
|
||||
|
||||
|
||||
static bool XMLHttpRequest_getResponseXML(se::State& s)
|
||||
{
|
||||
s.rval().setNull();
|
||||
@@ -821,7 +836,7 @@ static bool XMLHttpRequest_getResponse(se::State& s)
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false); // FIXME:
|
||||
SE_PRECONDITION2(false, false, "Invalid response type: %d", (int)xhr->getResponseType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -839,9 +854,24 @@ SE_BIND_PROP_GET(XMLHttpRequest_getTimeout)
|
||||
|
||||
static bool XMLHttpRequest_setTimeout(se::State& s)
|
||||
{
|
||||
XMLHttpRequest* cobj = (XMLHttpRequest*)s.nativeThisObject();
|
||||
cobj->setTimeout(s.args()[0].toUlong());
|
||||
return true;
|
||||
const auto& args = s.args();
|
||||
int argc = (int)args.size();
|
||||
if (argc > 0)
|
||||
{
|
||||
XMLHttpRequest* cobj = (XMLHttpRequest*)s.nativeThisObject();
|
||||
unsigned long timeoutInMilliseconds = 0;
|
||||
bool ok = seval_to_ulong(args[0], &timeoutInMilliseconds);
|
||||
SE_PRECONDITION2(ok, false, "args[0] isn't a number");
|
||||
if (timeoutInMilliseconds < 50)
|
||||
{
|
||||
LOGE("The timeout value (%lu ms) is too small, please note that timeout unit is milliseconds!", timeoutInMilliseconds);
|
||||
}
|
||||
cobj->setTimeout(timeoutInMilliseconds);
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting > 0", argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_SET(XMLHttpRequest_setTimeout)
|
||||
|
||||
@@ -871,13 +901,13 @@ static bool XMLHttpRequest_setResponseType(se::State& s)
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
|
||||
if (argc == 1)
|
||||
if (argc > 0)
|
||||
{
|
||||
assert(args[0].isString());
|
||||
std::string type;
|
||||
bool ok = seval_to_std_string(args[0], &type);
|
||||
SE_PRECONDITION2(ok, false, "args[0] couldn't be converted to string!");
|
||||
|
||||
XMLHttpRequest* xhr = (XMLHttpRequest*)s.nativeThisObject();
|
||||
|
||||
const std::string& type = args[0].toString();
|
||||
if (type == "text")
|
||||
{
|
||||
xhr->setResponseType(XMLHttpRequest::ResponseType::STRING);
|
||||
@@ -892,24 +922,23 @@ static bool XMLHttpRequest_setResponseType(se::State& s)
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
SE_PRECONDITION2(false, false, "The response type (%s) isn't supported!", type.c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting > 0", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_SET(XMLHttpRequest_setResponseType)
|
||||
|
||||
static bool XMLHttpRequest_getWithCredentials(se::State& s)
|
||||
{
|
||||
assert(false);
|
||||
LOGD("XMLHttpRequest.withCredentials isn't implemented on JSB!");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(XMLHttpRequest_getWithCredentials)
|
||||
|
||||
|
||||
bool register_all_xmlhttprequest(se::Object* global)
|
||||
{
|
||||
se::Class* cls = se::Class::create("XMLHttpRequest", global, nullptr, _SE(XMLHttpRequest_constructor));
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// CCConfig.js
|
||||
//
|
||||
cc.ENGINE_VERSION = "Cocos2d-x-lite v1.6.0";
|
||||
cc.ENGINE_VERSION = "Cocos2d-x-lite v1.7.0";
|
||||
|
||||
// Resolution policies
|
||||
|
||||
|
||||
@@ -78,4 +78,4 @@ sp.SkeletonAnimation.prototype.setAnimationListener = function (target, callback
|
||||
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.EVENT, event, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user