Merge branch 'develop' into console

This commit is contained in:
Ricardo Quesada 2013-11-27 14:29:27 -08:00
commit 21afd63d82
12 changed files with 136 additions and 64 deletions

View File

@ -1,7 +1,9 @@
cocos2d-x-3.0beta0 ?? 2013
[Android]
[NEW] build/android-build.sh: add supporting to generate .apk file
[FIX] XMLHttpRequest receives wrong binary array.
[NEW] Bindings-generator supports to bind 'unsigned long'.
[FIX] 'Test Frame Event' of TestJavascript/CocoStudioArmatureTest Crashes.
cocos2d-x-3.0alpha1 Nov.19 2013
[all platforms]
[DOC] Added RELEASE_NOTES and CODING_STYLE.md files

View File

@ -659,6 +659,16 @@ void Sprite::draw(void)
// Node overrides
void Sprite::addChild(Node *child)
{
Node::addChild(child);
}
void Sprite::addChild(Node *child, int zOrder)
{
Node::addChild(child, zOrder);
}
void Sprite::addChild(Node *child, int zOrder, int tag)
{
CCASSERT(child != NULL, "Argument must be non-NULL");

View File

@ -78,9 +78,6 @@ struct transformValues_;
* The default anchorPoint in Sprite is (0.5, 0.5).
*/
class CC_DLL Sprite : public NodeRGBA, public TextureProtocol
#ifdef EMSCRIPTEN
, public GLBufferedNode
#endif // EMSCRIPTEN
{
public:
@ -412,7 +409,10 @@ public:
virtual void removeChild(Node* child, bool cleanup) override;
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
virtual void reorderChild(Node *child, int zOrder) override;
using Node::addChild;
// Should also override addChild(Node*) and addChild(Node*, int), or binding generator will only
// bind addChild(Node*, int, int);
virtual void addChild(Node* child) override;
virtual void addChild(Node* child, int zOrder) override;
virtual void addChild(Node *child, int zOrder, int tag) override;
virtual void sortAllChildren() override;
virtual void setScale(float scale) override;

@ -1 +1 @@
Subproject commit 86ee6e4468b81db04dcdc286392fec41e9ec33a7
Subproject commit 3f5c6fd9082864d9dc214ce225e1515df279406d

View File

@ -102,6 +102,8 @@ void JSArmatureWrapper::addArmatureFileInfoAsyncCallbackFunc(float percent)
void JSArmatureWrapper::frameCallbackFunc(cocostudio::Bone *pBone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)
{
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
JSContext *cx = ScriptingCore::getInstance()->getGlobalContext();
JSObject *thisObj = JSVAL_IS_VOID(_jsThisObj) ? NULL : JSVAL_TO_OBJECT(_jsThisObj);
js_proxy_t *proxy = js_get_or_create_proxy(cx, pBone);
@ -120,8 +122,6 @@ void JSArmatureWrapper::frameCallbackFunc(cocostudio::Bone *pBone, const char *f
JS_AddValueRoot(cx, valArr);
JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET
JS_CallFunctionValue(cx, thisObj, _jsCallback, 4, valArr, &retval);
JS_RemoveValueRoot(cx, valArr);
}

View File

@ -93,34 +93,6 @@ JSBool jsval_to_int( JSContext *cx, jsval vp, int *ret )
return jsval_to_int32(cx, vp, (int32_t*)ret);
}
// XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???)
JSBool jsval_to_long( JSContext *cx, jsval vp, long *r )
{
#ifdef __LP64__
// compatibility check
assert( sizeof(long)==8);
JSString *jsstr = JS_ValueToString(cx, vp);
JSB_PRECONDITION2(jsstr, cx, JS_FALSE, "Error converting value to string");
char *str = JS_EncodeString(cx, jsstr);
JSB_PRECONDITION2(str, cx, JS_FALSE, "Error encoding string");
char *endptr;
long ret = strtol(str, &endptr, 10);
*r = ret;
return JS_TRUE;
#else
// compatibility check
assert( sizeof(int)==4);
long ret = JSVAL_TO_INT(vp);
#endif
*r = ret;
return JS_TRUE;
}
jsval opaque_to_jsval( JSContext *cx, void *opaque )
{
#ifdef __LP64__
@ -191,6 +163,21 @@ jsval long_to_jsval( JSContext *cx, long number )
#endif
}
jsval ulong_to_jsval( JSContext *cx, unsigned long number )
{
#ifdef __LP64__
assert( sizeof(unsigned long)==8);
char chr[128];
snprintf(chr, sizeof(chr)-1, "%lu", number);
JSString *ret_obj = JS_NewStringCopyZ(cx, chr);
return STRING_TO_JSVAL(ret_obj);
#else
CCASSERT( sizeof(int)==4, "Error!");
return UINT_TO_JSVAL(number);
#endif
}
jsval longlong_to_jsval( JSContext *cx, long long number )
{
#if JSB_REPRESENT_LONGLONG_AS_STR
@ -367,7 +354,52 @@ JSBool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval )
return ok;
}
JSBool jsval_to_long_long(JSContext *cx, jsval vp, long long* r) {
// XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???)
JSBool jsval_to_long( JSContext *cx, jsval vp, long *r )
{
#ifdef __LP64__
// compatibility check
assert( sizeof(long)==8);
JSString *jsstr = JS_ValueToString(cx, vp);
JSB_PRECONDITION2(jsstr, cx, JS_FALSE, "Error converting value to string");
char *str = JS_EncodeString(cx, jsstr);
JSB_PRECONDITION2(str, cx, JS_FALSE, "Error encoding string");
char *endptr;
long ret = strtol(str, &endptr, 10);
*r = ret;
return JS_TRUE;
#else
// compatibility check
assert( sizeof(int)==4);
long ret = JSVAL_TO_INT(vp);
#endif
*r = ret;
return JS_TRUE;
}
JSBool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out)
{
if (out == nullptr)
return JS_FALSE;
long rval = 0;
JSBool ret = JS_FALSE;
ret = jsval_to_long(cx, vp, &rval);
if (ret)
{
*out = (unsigned long)rval;
}
return ret;
}
JSBool jsval_to_long_long(JSContext *cx, jsval vp, long long* r)
{
JSObject *tmp_arg;
JSBool ok = JS_ValueToObject( cx, vp, &tmp_arg );
JSB_PRECONDITION3( ok, cx, JS_FALSE, "Error converting value to object");

View File

@ -9,29 +9,28 @@
#include "js_bindings_core.h"
#include "cocos2d.h"
extern JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **out );
extern JSBool jsval_to_int( JSContext *cx, jsval vp, int *out);
extern JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *out);
extern JSBool jsval_to_long( JSContext *cx, jsval vp, long *out);
extern JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy);
JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **out );
JSBool jsval_to_int( JSContext *cx, jsval vp, int *out);
JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *out);
JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_c_proxy_s **out_proxy);
/** converts a jsval (JS string) into a char */
extern JSBool jsval_to_charptr( JSContext *cx, jsval vp, const char **out);
JSBool jsval_to_charptr( JSContext *cx, jsval vp, const char **out);
extern jsval opaque_to_jsval( JSContext *cx, void* opaque);
extern jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass *klass, const char* class_name);
extern jsval long_to_jsval( JSContext *cx, long number );
extern jsval longlong_to_jsval( JSContext *cx, long long number );
jsval opaque_to_jsval( JSContext *cx, void* opaque);
jsval c_class_to_jsval( JSContext *cx, void* handle, JSObject* object, JSClass *klass, const char* class_name);
/* Converts a char ptr into a jsval (using JS string) */
extern jsval charptr_to_jsval( JSContext *cx, const char *str);
extern JSBool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t);
extern JSBool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data );
jsval charptr_to_jsval( JSContext *cx, const char *str);
JSBool JSB_jsval_typedarray_to_dataptr( JSContext *cx, jsval vp, GLsizei *count, void **data, JSArrayBufferViewType t);
JSBool JSB_get_arraybufferview_dataptr( JSContext *cx, jsval vp, GLsizei *count, GLvoid **data );
// some utility functions
// to native
JSBool jsval_to_int32( JSContext *cx, jsval vp, int32_t *ret );
JSBool jsval_to_uint32( JSContext *cx, jsval vp, uint32_t *ret );
JSBool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *ret );
JSBool jsval_to_long( JSContext *cx, jsval vp, long *out);
JSBool jsval_to_ulong( JSContext *cx, jsval vp, unsigned long *out);
JSBool jsval_to_long_long(JSContext *cx, jsval v, long long* ret);
JSBool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret);
JSBool jsval_to_ccpoint(JSContext *cx, jsval v, cocos2d::Point* ret);
@ -51,6 +50,8 @@ JSBool jsval_to_FontDefinition( JSContext *cx, jsval vp, cocos2d::FontDefinition
// from native
jsval int32_to_jsval( JSContext *cx, int32_t l);
jsval uint32_to_jsval( JSContext *cx, uint32_t number );
jsval long_to_jsval( JSContext *cx, long number );
jsval ulong_to_jsval(JSContext* cx, unsigned long v);
jsval long_long_to_jsval(JSContext* cx, long long v);
jsval std_string_to_jsval(JSContext* cx, const std::string& v);
jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length = -1);

View File

@ -200,18 +200,18 @@ void MinXmlHttpRequest::handle_requestResponse(network::HttpClient *sender, netw
/** get the response data **/
std::vector<char> *buffer = response->getResponseData();
char* concatenated = (char*) malloc(buffer->size() + 1);
std::string s2(buffer->begin(), buffer->end());
strcpy(concatenated, s2.c_str());
if (statusCode == 200)
{
//Succeeded
_status = 200;
_readyState = DONE;
_data << concatenated;
_dataSize = buffer->size();
CC_SAFE_FREE(_data);
_data = (char*) malloc(_dataSize + 1);
_data[_dataSize] = '\0';
memcpy((void*)_data, (const void*)buffer->data(), _dataSize);
}
else
{
@ -219,7 +219,6 @@ void MinXmlHttpRequest::handle_requestResponse(network::HttpClient *sender, netw
}
// Free Memory.
free((void*) concatHeader);
free((void*) concatenated);
js_proxy_t * p;
void* ptr = (void*)this;
@ -256,7 +255,10 @@ void MinXmlHttpRequest::_sendRequest(JSContext *cx)
* @brief Constructor initializes cchttprequest and stuff
*
*/
MinXmlHttpRequest::MinXmlHttpRequest() : _onreadystateCallback(NULL), _isNetwork(true)
MinXmlHttpRequest::MinXmlHttpRequest()
: _onreadystateCallback(nullptr)
, _isNetwork(true)
, _data(nullptr)
{
_httpHeader.clear();
_requestHeader.clear();
@ -285,6 +287,7 @@ MinXmlHttpRequest::~MinXmlHttpRequest()
// _httpRequest->release();
}
CC_SAFE_FREE(_data);
}
/**
@ -543,7 +546,7 @@ JS_BINDED_PROP_SET_IMPL(MinXmlHttpRequest, withCredentials)
*/
JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, responseText)
{
jsval strVal = std_string_to_jsval(cx, _data.str());
jsval strVal = std_string_to_jsval(cx, _data);
if (strVal != JSVAL_NULL)
{
@ -567,7 +570,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response)
{
JS::RootedValue outVal(cx);
jsval strVal = std_string_to_jsval(cx, _data.str());
jsval strVal = std_string_to_jsval(cx, _data);
if (JS_ParseJSON(cx, JS_GetStringCharsZ(cx, JSVAL_TO_STRING(strVal)), _dataSize, &outVal))
{
vp.set(outVal);
@ -578,7 +581,7 @@ JS_BINDED_PROP_GET_IMPL(MinXmlHttpRequest, response)
{
JSObject* tmp = JS_NewArrayBuffer(cx, _dataSize);
uint8_t* tmpData = JS_GetArrayBufferData(tmp);
_data.read((char*)tmpData, _dataSize);
memcpy((void*)tmpData, (const void*)_data, _dataSize);
jsval outVal = OBJECT_TO_JSVAL(tmp);
vp.set(outVal);

View File

@ -93,8 +93,8 @@ private:
JSContext* _cx;
std::string _meth;
std::string _type;
std::stringstream _data;
size_t _dataSize;
char* _data;
uint32_t _dataSize;
JSObject* _onreadystateCallback;
int _readyState;
int _status;

View File

@ -307,6 +307,30 @@ bool luaval_to_long(lua_State* L,int lo, long* outValue)
return ok;
}
bool luaval_to_ulong(lua_State* L,int lo, unsigned long* outValue)
{
if (NULL == L || NULL == outValue)
return false;
bool ok = true;
tolua_Error tolua_err;
if (!tolua_isnumber(L,lo,0,&tolua_err))
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err);
#endif
ok = false;
}
if (ok)
{
*outValue = (unsigned long)tolua_tonumber(L, lo, 0);
}
return ok;
}
bool luaval_to_size(lua_State* L,int lo,Size* outValue)
{
if (NULL == L || NULL == outValue)

View File

@ -1 +1 @@
44e542ea244df0150ae90190bf59a34356ac2c25
0121559669b9a084d0677116b0cfa09c617b4cd7

@ -1 +1 @@
Subproject commit e6c7016f83c9d02e0b8e784c65043369a1745680
Subproject commit 3e215fc4865a75e25db6f45115350ef2d7a256ca