From 6cf513a377bedc25be9259491fba8fc1396f6e0f Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 22 Nov 2017 16:15:30 +0800 Subject: [PATCH 1/8] Adds missing binding code for Scheduler.isTargetPaused. (#1007) --- .../scripting/js-bindings/manual/jsb_node.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_node.cpp b/native/cocos/scripting/js-bindings/manual/jsb_node.cpp index 0b3514bdaf..64356c9a02 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_node.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_node.cpp @@ -1427,6 +1427,35 @@ static bool js_cocos2dx_Scheduler_resumeTarget(se::State& s) } SE_BIND_FUNC(js_cocos2dx_Scheduler_resumeTarget) +static bool js_cocos2dx_Scheduler_isTargetPaused(se::State& s) +{ + const auto& args = s.args(); + int argc = (int)args.size(); + + if (argc == 1) + { + Scheduler* cobj = (Scheduler*)s.nativeThisObject(); + se::Value targetIdVal; + if (args[0].toObject()->getProperty(SCHEDULE_TARGET_ID_KEY, &targetIdVal) && targetIdVal.isNumber()) + { + uint32_t targetId = targetIdVal.toUint32(); + if (isTargetExistInScheduler(targetId)) + { + bool isPaused = cobj->isTargetPaused(reinterpret_cast(targetId)); + s.rval().setBoolean(isPaused); + return true; + } + } + + s.rval().setBoolean(false); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +SE_BIND_FUNC(js_cocos2dx_Scheduler_isTargetPaused) + static void resumeAllSchedulesForTarget(Node* node, se::Object* jsThis) { node->getScheduler()->resumeTarget(jsThis); @@ -1572,6 +1601,7 @@ bool jsb_register_Node_manual(se::Object* global) schedulerProto->defineFunction("isScheduled", _SE(js_cocos2dx_Scheduler_isScheduled)); schedulerProto->defineFunction("pauseTarget", _SE(js_cocos2dx_Scheduler_pauseTarget)); schedulerProto->defineFunction("resumeTarget", _SE(js_cocos2dx_Scheduler_resumeTarget)); + schedulerProto->defineFunction("isTargetPaused", _SE(js_cocos2dx_Scheduler_isTargetPaused)); #if STANDALONE_TEST cls->defineFunction("addChild", _SE(Node_addChild)); From c22673d440918b051702a2674f1b42d9f89e7a0e Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 23 Nov 2017 13:39:35 +0800 Subject: [PATCH 2/8] Provides an interface for getting SafeArea (#1008) * Provides an interface for getting SafeArea * @available(iOS 11.0, *) isn't supported in Xcode8. So we use the old way. --- native/cocos/base/CCDirector.cpp | 12 ++++ native/cocos/base/CCDirector.h | 5 ++ native/cocos/platform/CCGLView.cpp | 5 ++ native/cocos/platform/CCGLView.h | 5 ++ native/cocos/platform/ios/CCGLViewImpl-ios.h | 1 + native/cocos/platform/ios/CCGLViewImpl-ios.mm | 48 ++++++++++++++ .../auto/api/jsb_cocos2dx_auto_api.js | 36 +++++++--- .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 66 +++++++++++++++---- .../js-bindings/auto/jsb_cocos2dx_auto.hpp | 6 +- 9 files changed, 160 insertions(+), 24 deletions(-) diff --git a/native/cocos/base/CCDirector.cpp b/native/cocos/base/CCDirector.cpp index e3cca89539..7f2920f2e6 100644 --- a/native/cocos/base/CCDirector.cpp +++ b/native/cocos/base/CCDirector.cpp @@ -814,6 +814,18 @@ Vec2 Director::getVisibleOrigin() const } } +Rect Director::getSafeAreaRect() const +{ + if (_openGLView) + { + return _openGLView->getSafeAreaRect(); + } + else + { + return Rect::ZERO; + } +} + // scene management void Director::runWithScene(Scene *scene) diff --git a/native/cocos/base/CCDirector.h b/native/cocos/base/CCDirector.h index ca884930db..3c881aa74f 100644 --- a/native/cocos/base/CCDirector.h +++ b/native/cocos/base/CCDirector.h @@ -246,6 +246,11 @@ public: /** Returns visible origin coordinate of the OpenGL view in points. */ Vec2 getVisibleOrigin() const; + /** + * Returns safe area rectangle of the OpenGL view in points. + */ + Rect getSafeAreaRect() const; + /** * Converts a screen coordinate to an OpenGL coordinate. * Useful to convert (multi) touch coordinates to the current layout (portrait or landscape). diff --git a/native/cocos/platform/CCGLView.cpp b/native/cocos/platform/CCGLView.cpp index dd4cfc3575..9383c0f99a 100644 --- a/native/cocos/platform/CCGLView.cpp +++ b/native/cocos/platform/CCGLView.cpp @@ -233,6 +233,11 @@ Vec2 GLView::getVisibleOrigin() const } } +Rect GLView::getSafeAreaRect() const +{ + return getVisibleRect(); +} + void GLView::setViewPortInPoints(float x , float y , float w , float h) { glViewport((GLint)(x * _scaleX + _viewPortRect.origin.x), diff --git a/native/cocos/platform/CCGLView.h b/native/cocos/platform/CCGLView.h index e22cbca28b..cc36fb706d 100644 --- a/native/cocos/platform/CCGLView.h +++ b/native/cocos/platform/CCGLView.h @@ -229,6 +229,11 @@ public: */ virtual Rect getVisibleRect() const; + /** + * Gets safe area rectangle of opengl viewport. + */ + virtual Rect getSafeAreaRect() const; + /** * Set the design resolution size. * @param width Design resolution width. diff --git a/native/cocos/platform/ios/CCGLViewImpl-ios.h b/native/cocos/platform/ios/CCGLViewImpl-ios.h index 6208f23927..9e36b73e36 100644 --- a/native/cocos/platform/ios/CCGLViewImpl-ios.h +++ b/native/cocos/platform/ios/CCGLViewImpl-ios.h @@ -74,6 +74,7 @@ public: virtual void end() override; virtual void swapBuffers() override; virtual void setIMEKeyboardState(bool bOpen) override; + virtual Rect getSafeAreaRect() const override; protected: GLViewImpl(); diff --git a/native/cocos/platform/ios/CCGLViewImpl-ios.mm b/native/cocos/platform/ios/CCGLViewImpl-ios.mm index c8a0cb814a..6a2ad47ad6 100644 --- a/native/cocos/platform/ios/CCGLViewImpl-ios.mm +++ b/native/cocos/platform/ios/CCGLViewImpl-ios.mm @@ -32,6 +32,7 @@ #include "platform/ios/CCDirectorCaller-ios.h" #include "platform/ios/CCGLViewImpl-ios.h" #include "base/CCTouch.h" +#include "base/CCDirector.h" NS_CC_BEGIN @@ -226,6 +227,53 @@ void GLViewImpl::setIMEKeyboardState(bool open) } } +Rect GLViewImpl::getSafeAreaRect() const +{ + CCEAGLView *eaglview = (CCEAGLView*) _eaglview; + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 + float version = [[UIDevice currentDevice].systemVersion floatValue]; + if (version >= 11.0f) + { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpartial-availability" + UIEdgeInsets safeAreaInsets = eaglview.safeAreaInsets; +#pragma clang diagnostic pop + + // Multiply contentScaleFactor since safeAreaInsets return points. + safeAreaInsets.left *= eaglview.contentScaleFactor; + safeAreaInsets.right *= eaglview.contentScaleFactor; + safeAreaInsets.top *= eaglview.contentScaleFactor; + safeAreaInsets.bottom *= eaglview.contentScaleFactor; + + // Get leftBottom and rightTop point in UI coordinates + Vec2 leftBottom = Vec2(safeAreaInsets.left, _screenSize.height - safeAreaInsets.bottom); + Vec2 rightTop = Vec2(_screenSize.width - safeAreaInsets.right, safeAreaInsets.top); + + // Convert a point from UI coordinates to which in design resolution coordinate. + leftBottom.x = (leftBottom.x - _viewPortRect.origin.x) / _scaleX, + leftBottom.y = (leftBottom.y - _viewPortRect.origin.y) / _scaleY; + rightTop.x = (rightTop.x - _viewPortRect.origin.x) / _scaleX, + rightTop.y = (rightTop.y - _viewPortRect.origin.y) / _scaleY; + + // Adjust points to make them inside design resolution + leftBottom.x = MAX(leftBottom.x, 0); + leftBottom.y = MIN(leftBottom.y, _designResolutionSize.height); + rightTop.x = MIN(rightTop.x, _designResolutionSize.width); + rightTop.y = MAX(rightTop.y, 0); + + // Convert to GL coordinates + leftBottom = Director::getInstance()->convertToGL(leftBottom); + rightTop = Director::getInstance()->convertToGL(rightTop); + + return Rect(leftBottom.x, leftBottom.y, rightTop.x - leftBottom.x, rightTop.y - leftBottom.y); + } +#endif + + // If running on iOS devices lower than 11.0, return visiable rect instead. + return GLView::getSafeAreaRect(); +} + NS_CC_END #endif // CC_PLATFOR_IOS diff --git a/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index c6b47601ff..c58dddef21 100644 --- a/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -2189,13 +2189,13 @@ bool }, /** - * @method isAntiAliasEnabled - * @return {bool} + * @method getSafeAreaRect + * @return {rect_object} */ -isAntiAliasEnabled : function ( +getSafeAreaRect : function ( ) { - return false; + return cc.Rect; }, /** @@ -2464,6 +2464,16 @@ pollEvents : function ( { }, +/** + * @method isAntiAliasEnabled + * @return {bool} + */ +isAntiAliasEnabled : function ( +) +{ + return false; +}, + }; /** @@ -2509,6 +2519,16 @@ float { }, +/** + * @method getDeltaTime + * @return {float} + */ +getDeltaTime : function ( +) +{ + return 0; +}, + /** * @method getContentScaleFactor * @return {float} @@ -2530,13 +2550,13 @@ getWinSizeInPixels : function ( }, /** - * @method getDeltaTime - * @return {float} + * @method getSafeAreaRect + * @return {rect_object} */ -getDeltaTime : function ( +getSafeAreaRect : function ( ) { - return 0; + return cc.Rect; }, /** diff --git a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index d2f9ac81d3..c6db4e6228 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -4931,23 +4931,23 @@ static bool js_cocos2dx_GLView_setIMEKeyboardState(se::State& s) } SE_BIND_FUNC(js_cocos2dx_GLView_setIMEKeyboardState) -static bool js_cocos2dx_GLView_isAntiAliasEnabled(se::State& s) +static bool js_cocos2dx_GLView_getSafeAreaRect(se::State& s) { cocos2d::GLView* cobj = (cocos2d::GLView*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_cocos2dx_GLView_isAntiAliasEnabled : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_cocos2dx_GLView_getSafeAreaRect : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - bool result = cobj->isAntiAliasEnabled(); - ok &= boolean_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_cocos2dx_GLView_isAntiAliasEnabled : Error processing arguments"); + cocos2d::Rect result = cobj->getSafeAreaRect(); + ok &= Rect_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_cocos2dx_GLView_getSafeAreaRect : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_cocos2dx_GLView_isAntiAliasEnabled) +SE_BIND_FUNC(js_cocos2dx_GLView_getSafeAreaRect) static bool js_cocos2dx_GLView_setScissorInPoints(se::State& s) { @@ -5422,6 +5422,24 @@ static bool js_cocos2dx_GLView_pollEvents(se::State& s) } SE_BIND_FUNC(js_cocos2dx_GLView_pollEvents) +static bool js_cocos2dx_GLView_isAntiAliasEnabled(se::State& s) +{ + cocos2d::GLView* cobj = (cocos2d::GLView*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_cocos2dx_GLView_isAntiAliasEnabled : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + bool result = cobj->isAntiAliasEnabled(); + ok &= boolean_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_cocos2dx_GLView_isAntiAliasEnabled : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_cocos2dx_GLView_isAntiAliasEnabled) + @@ -5434,7 +5452,7 @@ bool js_register_cocos2dx_GLView(se::Object* obj) cls->defineFunction("setContentScaleFactor", _SE(js_cocos2dx_GLView_setContentScaleFactor)); cls->defineFunction("getContentScaleFactor", _SE(js_cocos2dx_GLView_getContentScaleFactor)); cls->defineFunction("setIMEKeyboardState", _SE(js_cocos2dx_GLView_setIMEKeyboardState)); - cls->defineFunction("isAntiAliasEnabled", _SE(js_cocos2dx_GLView_isAntiAliasEnabled)); + cls->defineFunction("getSafeAreaRect", _SE(js_cocos2dx_GLView_getSafeAreaRect)); cls->defineFunction("setScissorInPoints", _SE(js_cocos2dx_GLView_setScissorInPoints)); cls->defineFunction("getViewName", _SE(js_cocos2dx_GLView_getViewName)); cls->defineFunction("isOpenGLReady", _SE(js_cocos2dx_GLView_isOpenGLReady)); @@ -5460,6 +5478,7 @@ bool js_register_cocos2dx_GLView(se::Object* obj) cls->defineFunction("getVisibleSize", _SE(js_cocos2dx_GLView_getVisibleSize)); cls->defineFunction("isScissorEnabled", _SE(js_cocos2dx_GLView_isScissorEnabled)); cls->defineFunction("pollEvents", _SE(js_cocos2dx_GLView_pollEvents)); + cls->defineFunction("isAntiAliasEnabled", _SE(js_cocos2dx_GLView_isAntiAliasEnabled)); cls->install(); JSBClassType::registerClass(cls); @@ -5544,6 +5563,24 @@ static bool js_cocos2dx_Director_setContentScaleFactor(se::State& s) } SE_BIND_FUNC(js_cocos2dx_Director_setContentScaleFactor) +static bool js_cocos2dx_Director_getDeltaTime(se::State& s) +{ + cocos2d::Director* cobj = (cocos2d::Director*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_cocos2dx_Director_getDeltaTime : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + float result = cobj->getDeltaTime(); + ok &= float_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_cocos2dx_Director_getDeltaTime : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_cocos2dx_Director_getDeltaTime) + static bool js_cocos2dx_Director_getContentScaleFactor(se::State& s) { cocos2d::Director* cobj = (cocos2d::Director*)s.nativeThisObject(); @@ -5580,23 +5617,23 @@ static bool js_cocos2dx_Director_getWinSizeInPixels(se::State& s) } SE_BIND_FUNC(js_cocos2dx_Director_getWinSizeInPixels) -static bool js_cocos2dx_Director_getDeltaTime(se::State& s) +static bool js_cocos2dx_Director_getSafeAreaRect(se::State& s) { cocos2d::Director* cobj = (cocos2d::Director*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_cocos2dx_Director_getDeltaTime : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_cocos2dx_Director_getSafeAreaRect : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - float result = cobj->getDeltaTime(); - ok &= float_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_cocos2dx_Director_getDeltaTime : Error processing arguments"); + cocos2d::Rect result = cobj->getSafeAreaRect(); + ok &= Rect_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_cocos2dx_Director_getSafeAreaRect : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_cocos2dx_Director_getDeltaTime) +SE_BIND_FUNC(js_cocos2dx_Director_getSafeAreaRect) static bool js_cocos2dx_Director_isCullingEnabled(se::State& s) { @@ -6715,9 +6752,10 @@ bool js_register_cocos2dx_Director(se::Object* obj) cls->defineFunction("isPurgeDirectorInNextLoop", _SE(js_cocos2dx_Director_isPurgeDirectorInNextLoop)); cls->defineFunction("setEventDispatcher", _SE(js_cocos2dx_Director_setEventDispatcher)); cls->defineFunction("setContentScaleFactor", _SE(js_cocos2dx_Director_setContentScaleFactor)); + cls->defineFunction("getDeltaTime", _SE(js_cocos2dx_Director_getDeltaTime)); cls->defineFunction("getContentScaleFactor", _SE(js_cocos2dx_Director_getContentScaleFactor)); cls->defineFunction("getWinSizeInPixels", _SE(js_cocos2dx_Director_getWinSizeInPixels)); - cls->defineFunction("getDeltaTime", _SE(js_cocos2dx_Director_getDeltaTime)); + cls->defineFunction("getSafeAreaRect", _SE(js_cocos2dx_Director_getSafeAreaRect)); cls->defineFunction("isCullingEnabled", _SE(js_cocos2dx_Director_isCullingEnabled)); cls->defineFunction("setGLDefaultValues", _SE(js_cocos2dx_Director_setGLDefaultValues)); cls->defineFunction("setActionManager", _SE(js_cocos2dx_Director_setActionManager)); diff --git a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index ccf02982fa..3647b8071e 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -266,7 +266,7 @@ SE_DECLARE_FUNC(js_cocos2dx_GLView_getViewPortRect); SE_DECLARE_FUNC(js_cocos2dx_GLView_setContentScaleFactor); SE_DECLARE_FUNC(js_cocos2dx_GLView_getContentScaleFactor); SE_DECLARE_FUNC(js_cocos2dx_GLView_setIMEKeyboardState); -SE_DECLARE_FUNC(js_cocos2dx_GLView_isAntiAliasEnabled); +SE_DECLARE_FUNC(js_cocos2dx_GLView_getSafeAreaRect); SE_DECLARE_FUNC(js_cocos2dx_GLView_setScissorInPoints); SE_DECLARE_FUNC(js_cocos2dx_GLView_getViewName); SE_DECLARE_FUNC(js_cocos2dx_GLView_isOpenGLReady); @@ -292,6 +292,7 @@ SE_DECLARE_FUNC(js_cocos2dx_GLView_getVisibleRect); SE_DECLARE_FUNC(js_cocos2dx_GLView_getVisibleSize); SE_DECLARE_FUNC(js_cocos2dx_GLView_isScissorEnabled); SE_DECLARE_FUNC(js_cocos2dx_GLView_pollEvents); +SE_DECLARE_FUNC(js_cocos2dx_GLView_isAntiAliasEnabled); extern se::Object* __jsb_cocos2d_Director_proto; extern se::Class* __jsb_cocos2d_Director_class; @@ -302,9 +303,10 @@ SE_DECLARE_FUNC(js_cocos2dx_Director_pause); SE_DECLARE_FUNC(js_cocos2dx_Director_isPurgeDirectorInNextLoop); SE_DECLARE_FUNC(js_cocos2dx_Director_setEventDispatcher); SE_DECLARE_FUNC(js_cocos2dx_Director_setContentScaleFactor); +SE_DECLARE_FUNC(js_cocos2dx_Director_getDeltaTime); SE_DECLARE_FUNC(js_cocos2dx_Director_getContentScaleFactor); SE_DECLARE_FUNC(js_cocos2dx_Director_getWinSizeInPixels); -SE_DECLARE_FUNC(js_cocos2dx_Director_getDeltaTime); +SE_DECLARE_FUNC(js_cocos2dx_Director_getSafeAreaRect); SE_DECLARE_FUNC(js_cocos2dx_Director_isCullingEnabled); SE_DECLARE_FUNC(js_cocos2dx_Director_setGLDefaultValues); SE_DECLARE_FUNC(js_cocos2dx_Director_setActionManager); From 7c4eeecdde2806016be48aba718d97fbee318118 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 23 Nov 2017 13:47:15 +0800 Subject: [PATCH 3/8] Removes the unneeded support for passing 'key' arguments to cc.Scheduer.schedule/unschedule. (#1009) * Removes the unneeded support for passing 'key' arguments to cc.Scheduler.schedule/unschedule. * cc.REPEAT_FOREVER isn't defined in lite and it isn't needed to hack cc.Scheduler.schedule in script either. --- .../scripting/js-bindings/manual/jsb_node.cpp | 114 +++++------------- .../js-bindings/script/jsb_cocos2d.js | 37 ------ 2 files changed, 27 insertions(+), 124 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_node.cpp b/native/cocos/scripting/js-bindings/manual/jsb_node.cpp index 64356c9a02..3ae43f37d4 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_node.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_node.cpp @@ -442,7 +442,7 @@ private: static uint32_t __idx = 0; -static bool Scheduler_scheduleCommon(Scheduler* scheduler, const se::Value& jsThis, const se::Value& jsFunc, float interval, unsigned int repeat, float delay, bool isPaused, const std::string& aKey, bool toRootTarget, const std::string& callFromDebug) +static bool Scheduler_scheduleCommon(Scheduler* scheduler, const se::Value& jsThis, const se::Value& jsFunc, float interval, unsigned int repeat, float delay, bool isPaused, bool toRootTarget, const std::string& callFromDebug) { assert(jsThis.isObject()); assert(jsFunc.isObject()); @@ -469,24 +469,10 @@ static bool Scheduler_scheduleCommon(Scheduler* scheduler, const se::Value& jsTh if (targetIdVal.isNumber() && funcIdVal.isNumber()) { - bool found = false; - if (!aKey.empty()) - { - key = aKey; - const ScheduleElement* scheduleElem = nullptr; - found = isScheduleExist(key, targetId, &scheduleElem); - if (found) - { - assert(scheduleElem->getFuncId() == funcId); - } - } - else - { - const ScheduleElement* scheduleElem = nullptr; - found = isScheduleExist(funcId, targetId, &scheduleElem); - if (found) - key = scheduleElem->getKey(); - } + const ScheduleElement* scheduleElem = nullptr; + bool found = isScheduleExist(funcId, targetId, &scheduleElem); + if (found) + key = scheduleElem->getKey(); if (found && !key.empty()) { @@ -519,10 +505,7 @@ static bool Scheduler_scheduleCommon(Scheduler* scheduler, const se::Value& jsTh } } - if (!aKey.empty()) - key = aKey; - else - key = StringUtils::format("__node_schedule_key:%u", __idx++); + key = StringUtils::format("__node_schedule_key:%u", __idx++); se::Object* target = jsThis.toObject(); insertSchedule(funcId, targetId, ScheduleElement(target, jsFunc.toObject(), key, targetId, funcId)); @@ -579,7 +562,6 @@ static bool Node_schedule(se::State& s) unsigned int repeat = CC_REPEAT_FOREVER; float delay = 0.0f; bool ok = false; - std::string key; if (argc >= 2) { @@ -599,21 +581,7 @@ static bool Node_schedule(se::State& s) SE_PRECONDITION2(ok, false, "Converting 'delay' argument failed"); } - if (argc >= 5 && !args[4].isNullOrUndefined()) - { - if (args[4].isString() || args[4].isNumber()) - { - key = args[4].toStringForce(); - ok = true; - } - else - { - ok = false; - } - SE_PRECONDITION2(ok, false, "Converting 'key' argument failed"); - } - - return Scheduler_scheduleCommon(thiz->getScheduler(), jsThis, jsFunc, interval, repeat, delay, !thiz->isRunning(), key, false, "cc.Node.schedule"); + return Scheduler_scheduleCommon(thiz->getScheduler(), jsThis, jsFunc, interval, repeat, delay, !thiz->isRunning(), false, "cc.Node.schedule"); } SE_REPORT_ERROR("wrong number of arguments: %d, expected: %s", argc, ">=1"); @@ -639,7 +607,6 @@ static bool Node_scheduleOnce(se::State& s) se::Value jsFunc(args[0]); float delay = 0.0f; - std::string key; bool ok = false; if (argc >= 2) @@ -648,21 +615,7 @@ static bool Node_scheduleOnce(se::State& s) SE_PRECONDITION2(ok, false, "Converting 'delay' argument failed"); } - if (argc >= 3 && !args[2].isNullOrUndefined()) - { - if (args[2].isString() || args[2].isNumber()) - { - key = args[2].toStringForce(); - ok = true; - } - else - { - ok = false; - } - SE_PRECONDITION2(ok, false, "Converting 'key' argument failed"); - } - - return Scheduler_scheduleCommon(thiz->getScheduler(), jsThis, jsFunc, 0.0f, 0, delay, !thiz->isRunning(), key, false, "cc.Node.scheduleOnce"); + return Scheduler_scheduleCommon(thiz->getScheduler(), jsThis, jsFunc, 0.0f, 0, delay, !thiz->isRunning(), false, "cc.Node.scheduleOnce"); } SE_BIND_FUNC(Node_scheduleOnce) @@ -1112,7 +1065,7 @@ static bool Node_setPosition(se::State& s) float y = 0.0f; ok &= seval_to_float(args[0], &x); ok &= seval_to_float(args[1], &y); - cobj->setPosition(cocos2d::Vec2(x, y)); + cobj->setPosition(x, y); return true; } @@ -1188,7 +1141,8 @@ static bool js_cocos2dx_Scheduler_schedule(se::State& s) SE_LOGD("-------------------------- \n"); #endif - if (argc >= 2) + // + if (argc >= 4) { Scheduler* cobj = (Scheduler*)s.nativeThisObject(); @@ -1218,47 +1172,33 @@ static bool js_cocos2dx_Scheduler_schedule(se::State& s) unsigned int repeat = CC_REPEAT_FOREVER; float delay = 0.0f; bool isPaused = false; - std::string key; - if (argc >= 3) + ok = seval_to_float(args[2], &interval); + SE_PRECONDITION2(ok, false, "Converting 'interval' argument failed"); + + if (argc == 4) { - ok = seval_to_float(args[2], &interval); -// SE_PRECONDITION2(ok, false, "Converting 'interval' argument failed"); + // callback, target, interval, paused + ok = seval_to_boolean(args[3], &isPaused); + SE_PRECONDITION2(ok, false, "Converting 'isPaused' argument failed"); } - - if (argc >= 4) + else if (argc >= 6) { + // callback, target, interval, repeat, delay, paused + // repeat ok = seval_to_uint32(args[3], &repeat); -// SE_PRECONDITION2(ok, false, "Converting 'interval' argument failed"); - } + SE_PRECONDITION2(ok, false, "Converting 'interval' argument failed"); - if (argc >= 5) - { + // delay ok = seval_to_float(args[4], &delay); -// SE_PRECONDITION2(ok, false, "Converting 'delay' argument failed"); - } + SE_PRECONDITION2(ok, false, "Converting 'delay' argument failed"); - if (argc >= 6) - { + // isPaused ok = seval_to_boolean(args[5], &isPaused); -// SE_PRECONDITION2(ok, false, "Converting 'isPaused' argument failed"); + SE_PRECONDITION2(ok, false, "Converting 'isPaused' argument failed"); } - if (argc >= 7 && !args[6].isNullOrUndefined()) - { - if (args[6].isString() || args[6].isNumber()) - { - key = args[6].toStringForce(); - ok = true; - } - else - { - ok = false; - } - SE_PRECONDITION2(ok, false, "Converting 'key' argument failed"); - } - - return Scheduler_scheduleCommon(cobj, jsThis, jsFunc, interval, repeat, delay, isPaused, key, !isBindedObject, "cc.Scheduler.schedule"); + return Scheduler_scheduleCommon(cobj, jsThis, jsFunc, interval, repeat, delay, isPaused, !isBindedObject, "cc.Scheduler.schedule"); } SE_REPORT_ERROR("wrong number of arguments: %d, expected: %s", argc, ">=2"); diff --git a/native/cocos/scripting/js-bindings/script/jsb_cocos2d.js b/native/cocos/scripting/js-bindings/script/jsb_cocos2d.js index df4ddb3347..572ae53c66 100644 --- a/native/cocos/scripting/js-bindings/script/jsb_cocos2d.js +++ b/native/cocos/scripting/js-bindings/script/jsb_cocos2d.js @@ -1032,43 +1032,6 @@ _p.enableStroke = _p.enableOutline; _p.setBoundingWidth = _p.setWidth; _p.setBoundingHeight = _p.setHeight; -// -// cc.Scheduler scheduleCallbackForTarget -// -_p = cc.Scheduler.prototype; -_p.unscheduleUpdateForTarget = _p.unscheduleUpdate; -_p.unscheduleAllCallbacksForTarget = function (target) { - this.unschedule(target.__instanceId + "", target); -}; -_p._schedule = _p.schedule; -_p.schedule = function (callback, target, interval, repeat, delay, paused, key) { - var isSelector = false; - if (typeof callback !== "function") { - var selector = callback; - isSelector = true; - } - if (isSelector === false) { - //callback, target, interval, repeat, delay, paused, key - //callback, target, interval, paused, key - if (repeat !== undefined && (delay === undefined || paused === undefined)) { - key = delay; - paused = repeat; - delay = 0; - repeat = cc.REPEAT_FOREVER; - } - } else { - //selector, target, interval, repeat, delay, paused - //selector, target, interval, paused - if (repeat !== undefined && delay === undefined) { - paused = repeat; - repeat = cc.REPEAT_FOREVER; - delay = 0; - } - } - - this._schedule(callback, target, interval, repeat, delay, paused, key); -}; - // // cc.BlendFunc // From f5f94ac8573609961843158fda45efad6b8cd31e Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 23 Nov 2017 14:26:03 +0800 Subject: [PATCH 4/8] [iOS] jsb.reflection.callStaticMethod supports to call objective-c method with `NSNumber*` and supports to pass `undefined`/`null` from JS. (#1010) --- .../scripting/js-bindings/manual/JavaScriptObjCBridge.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/native/cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm b/native/cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm index 1e063c2e5a..58d77b803d 100644 --- a/native/cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm +++ b/native/cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm @@ -163,6 +163,11 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray& argv, se::Val unsigned char val = arg.toUint8(); [invocation setArgument:&val atIndex:i]; } + else if (argumentType == "@") + { // NSNumber* + NSNumber* number = [NSNumber numberWithDouble:arg.toNumber()]; + [invocation setArgument:&number atIndex:i]; + } else { NSLog(@"Unsupported argument type: %s", argumentType.c_str()); @@ -189,6 +194,10 @@ bool JavaScriptObjCBridge::CallInfo::execute(const se::ValueArray& argv, se::Val return false; } } + else if (arg.isNullOrUndefined()) + { + // Don't call [invocation setArgument] will pass nil to relevant Objective-C argument. + } else { NSLog(@"Unsupported argument type, se::Value::Type: %d", (int)arg.getType()); From cdad6b5868a1c4c50c9e300adfd9175030387920 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 23 Nov 2017 15:13:34 +0800 Subject: [PATCH 5/8] Some Android Simulators don't support SSE instruction, so disable it for x86 arch. (#1011) --- .../runtime-src/proj.android-studio/app/jni/Application.mk | 2 ++ .../frameworks/runtime-src/proj.android/jni/Application.mk | 2 ++ .../runtime-src/proj.android-studio/app/jni/Application.mk | 3 +++ .../frameworks/runtime-src/proj.android/jni/Application.mk | 3 +++ .../runtime-src/proj.android-studio/app/jni/Application.mk | 3 +++ .../frameworks/runtime-src/proj.android/jni/Application.mk | 3 +++ .../runtime-src/proj.android-studio/app/jni/Application.mk | 3 +++ .../frameworks/runtime-src/proj.android/jni/Application.mk | 3 +++ 8 files changed, 22 insertions(+) diff --git a/native/templates/js-template-binary/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk b/native/templates/js-template-binary/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk index 3059fd0da8..028bd310bd 100755 --- a/native/templates/js-template-binary/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk +++ b/native/templates/js-template-binary/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk @@ -26,3 +26,5 @@ else APP_OPTIM := release endif +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/templates/js-template-binary/frameworks/runtime-src/proj.android/jni/Application.mk b/native/templates/js-template-binary/frameworks/runtime-src/proj.android/jni/Application.mk index 3059fd0da8..028bd310bd 100755 --- a/native/templates/js-template-binary/frameworks/runtime-src/proj.android/jni/Application.mk +++ b/native/templates/js-template-binary/frameworks/runtime-src/proj.android/jni/Application.mk @@ -26,3 +26,5 @@ else APP_OPTIM := release endif +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/templates/js-template-default/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk b/native/templates/js-template-default/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk index ca7481714b..028bd310bd 100755 --- a/native/templates/js-template-default/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk +++ b/native/templates/js-template-default/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk @@ -25,3 +25,6 @@ else APP_CFLAGS += -DNDEBUG APP_OPTIM := release endif + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/templates/js-template-default/frameworks/runtime-src/proj.android/jni/Application.mk b/native/templates/js-template-default/frameworks/runtime-src/proj.android/jni/Application.mk index ca7481714b..028bd310bd 100755 --- a/native/templates/js-template-default/frameworks/runtime-src/proj.android/jni/Application.mk +++ b/native/templates/js-template-default/frameworks/runtime-src/proj.android/jni/Application.mk @@ -25,3 +25,6 @@ else APP_CFLAGS += -DNDEBUG APP_OPTIM := release endif + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk b/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk index ca7481714b..028bd310bd 100755 --- a/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk +++ b/native/templates/js-template-link/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk @@ -25,3 +25,6 @@ else APP_CFLAGS += -DNDEBUG APP_OPTIM := release endif + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/templates/js-template-link/frameworks/runtime-src/proj.android/jni/Application.mk b/native/templates/js-template-link/frameworks/runtime-src/proj.android/jni/Application.mk index ca7481714b..028bd310bd 100755 --- a/native/templates/js-template-link/frameworks/runtime-src/proj.android/jni/Application.mk +++ b/native/templates/js-template-link/frameworks/runtime-src/proj.android/jni/Application.mk @@ -25,3 +25,6 @@ else APP_CFLAGS += -DNDEBUG APP_OPTIM := release endif + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/tools/simulator/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk b/native/tools/simulator/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk index b31b93cb0d..7daffeb60c 100755 --- a/native/tools/simulator/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk +++ b/native/tools/simulator/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk @@ -21,3 +21,6 @@ endif COCOS_SIMULATOR_BUILD := 1 USE_ARM_MODE := 1 + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/tools/simulator/frameworks/runtime-src/proj.android/jni/Application.mk b/native/tools/simulator/frameworks/runtime-src/proj.android/jni/Application.mk index fc868a3588..34de8052d7 100755 --- a/native/tools/simulator/frameworks/runtime-src/proj.android/jni/Application.mk +++ b/native/tools/simulator/frameworks/runtime-src/proj.android/jni/Application.mk @@ -18,3 +18,6 @@ endif COCOS_SIMULATOR_BUILD := 1 USE_ARM_MODE := 1 + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ From 2e3883f0975dc3ae812258d8023026482026d28a Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 23 Nov 2017 15:19:37 +0800 Subject: [PATCH 6/8] [Android] Fixed compilation error while using APP_PLATFORM >= 22. (#1012) * [Android] Fixed compilation error while using APP_PLATFORM >= 22. * Don't use deprecated createUint8TypedArray. --- native/cocos/audio/android/mp3reader.cpp | 4 +--- native/cocos/scripting/js-bindings/jswrapper/v8/Base.h | 1 + native/cocos/scripting/js-bindings/manual/jsb_conversions.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/native/cocos/audio/android/mp3reader.cpp b/native/cocos/audio/android/mp3reader.cpp index 9388d843d8..6658f604b7 100644 --- a/native/cocos/audio/android/mp3reader.cpp +++ b/native/cocos/audio/android/mp3reader.cpp @@ -31,15 +31,13 @@ #include #include #include -#include +#include // Resolves that memset, memcpy aren't found while APP_PLATFORM >= 22 on Android #include #include "audio/android/cutils/log.h" #include "pvmp3decoder_api.h" #include "audio/android/mp3reader.h" -using namespace std; - static uint32_t U32_AT(const uint8_t *ptr) { return ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3]; } diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Base.h b/native/cocos/scripting/js-bindings/jswrapper/v8/Base.h index 71126068f1..6bb36a4c93 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Base.h +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Base.h @@ -32,6 +32,7 @@ #include "v8.h" #include +#include // Resolves that memset, memcpy aren't found while APP_PLATFORM >= 22 on Android #include #include #include diff --git a/native/cocos/scripting/js-bindings/manual/jsb_conversions.cpp b/native/cocos/scripting/js-bindings/manual/jsb_conversions.cpp index 92cf987d92..55574add63 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_conversions.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_conversions.cpp @@ -1762,7 +1762,7 @@ bool Data_to_seval(const cocos2d::Data& v, se::Value* ret) { assert(ret != nullptr); assert(!v.isNull()); - se::HandleObject obj(se::Object::createUint8TypedArray(v.getBytes(), v.getSize())); + se::HandleObject obj(se::Object::createTypedArray(se::Object::TypedArrayType::UINT8, v.getBytes(), v.getSize())); ret->setObject(obj); return true; } From 901f4fa50c0c9b884b34d99f7427256cdfedbd61 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 28 Nov 2017 13:36:14 +0800 Subject: [PATCH 7/8] Auto hide home indicator for iPhoneX. (#1013) --- .../runtime-src/proj.ios_mac/ios/RootViewController.mm | 5 +++++ .../runtime-src/proj.ios_mac/ios/RootViewController.mm | 5 +++++ .../runtime-src/proj.ios_mac/ios/RootViewController.mm | 5 +++++ .../runtime-src/proj.ios_mac/ios/RootViewController.mm | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/native/templates/js-template-binary/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/native/templates/js-template-binary/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index b71b9b7c44..5298c2f175 100755 --- a/native/templates/js-template-binary/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/native/templates/js-template-binary/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -105,6 +105,11 @@ return self; return YES; } +// Controls the application's preferred home indicator auto-hiding when this view controller is shown. +- (BOOL)prefersHomeIndicatorAutoHidden { + return YES; +} + - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; diff --git a/native/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/native/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index b71b9b7c44..5298c2f175 100755 --- a/native/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/native/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -105,6 +105,11 @@ return self; return YES; } +// Controls the application's preferred home indicator auto-hiding when this view controller is shown. +- (BOOL)prefersHomeIndicatorAutoHidden { + return YES; +} + - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; diff --git a/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index b71b9b7c44..5298c2f175 100755 --- a/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/native/templates/js-template-link/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -105,6 +105,11 @@ return self; return YES; } +// Controls the application's preferred home indicator auto-hiding when this view controller is shown. +- (BOOL)prefersHomeIndicatorAutoHidden { + return YES; +} + - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; diff --git a/native/tools/simulator/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/native/tools/simulator/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index 5bc929e35f..587f45061e 100755 --- a/native/tools/simulator/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/native/tools/simulator/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -105,6 +105,11 @@ return YES; } +// Controls the application's preferred home indicator auto-hiding when this view controller is shown. +- (BOOL)prefersHomeIndicatorAutoHidden { + return YES; +} + - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; From 412f71a89b378767b091a834bdff0be6329a3f97 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 28 Nov 2017 13:42:01 +0800 Subject: [PATCH 8/8] [android] Fixes wrong timeout value is used. Should use timeout parameter per requrest instead of per client instance. (#1014) --- native/cocos/network/HttpClient-android.cpp | 6 +++--- native/cocos/network/HttpClient.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/native/cocos/network/HttpClient-android.cpp b/native/cocos/network/HttpClient-android.cpp index 382ad0df6d..57c69d69f1 100644 --- a/native/cocos/network/HttpClient-android.cpp +++ b/native/cocos/network/HttpClient-android.cpp @@ -128,7 +128,7 @@ public: bool init(HttpRequest* request) { createHttpURLConnection(request->getUrl()); - if(!configure()) + if(!configure(request)) { return false; } @@ -613,7 +613,7 @@ private: } } - bool configure() + bool configure(HttpRequest* request) { if(nullptr == _httpURLConnection) { @@ -625,7 +625,7 @@ private: return false; } - setReadAndConnectTimeout(_client->getTimeoutForRead() * 1000, _client->getTimeoutForConnect() * 1000); + setReadAndConnectTimeout(request->getTimeout() * 1000, request->getTimeout() * 1000); setVerifySSL(); diff --git a/native/cocos/network/HttpClient.cpp b/native/cocos/network/HttpClient.cpp index 9d790ca837..9521a54c09 100644 --- a/native/cocos/network/HttpClient.cpp +++ b/native/cocos/network/HttpClient.cpp @@ -162,7 +162,7 @@ void HttpClient::networkThreadAlone(HttpRequest* request, HttpResponse* response } //Configure curl's timeout property -static bool configureCURL(HttpClient* client, CURL* handle, char* errorBuffer) +static bool configureCURL(HttpClient* client, HttpRequest* request, CURL* handle, char* errorBuffer) { if (!handle) { return false; @@ -173,11 +173,11 @@ static bool configureCURL(HttpClient* client, CURL* handle, char* errorBuffer) if (code != CURLE_OK) { return false; } - code = curl_easy_setopt(handle, CURLOPT_TIMEOUT, HttpClient::getInstance()->getTimeoutForRead()); + code = curl_easy_setopt(handle, CURLOPT_TIMEOUT, request->getTimeout()); if (code != CURLE_OK) { return false; } - code = curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, HttpClient::getInstance()->getTimeoutForConnect()); + code = curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, request->getTimeout()); if (code != CURLE_OK) { return false; } @@ -239,7 +239,7 @@ public: { if (!_curl) return false; - if (!configureCURL(client, _curl, errorBuffer)) + if (!configureCURL(client, request, _curl, errorBuffer)) return false; /* get custom header data (if set) */