mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
@@ -31,15 +31,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <string.h> // Resolves that memset, memcpy aren't found while APP_PLATFORM >= 22 on Android
|
||||
#include <vector>
|
||||
#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];
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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) */
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<cocos2d::GLView>(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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "v8.h"
|
||||
|
||||
#include <string>
|
||||
#include <string.h> // Resolves that memset, memcpy aren't found while APP_PLATFORM >= 22 on Android
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
@@ -1427,6 +1367,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<void*>(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 +1541,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));
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
+2
@@ -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__
|
||||
|
||||
+2
@@ -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__
|
||||
|
||||
+5
@@ -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];
|
||||
|
||||
+3
@@ -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__
|
||||
|
||||
+3
@@ -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__
|
||||
|
||||
+5
@@ -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];
|
||||
|
||||
+3
@@ -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__
|
||||
|
||||
+3
@@ -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__
|
||||
|
||||
+5
@@ -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];
|
||||
|
||||
+3
@@ -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__
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user