Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into surith-js-tests

This commit is contained in:
James Chen 2012-10-12 15:15:12 +08:00
commit a4e41c924d
6 changed files with 633 additions and 38 deletions

View File

@ -95,11 +95,14 @@ CCLabelAtlas* CCLabelAtlas::create(const char *string, const char *fntFile)
bool CCLabelAtlas::initWithString(const char *theString, const char *fntFile)
{
CCDictionary *dict = CCDictionary::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fntFile));
std::string pathStr = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fntFile);
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
CCDictionary *dict = CCDictionary::createWithContentsOfFile(pathStr.c_str());
CCAssert(((CCString*)dict->objectForKey("version"))->intValue() == 1, "Unsupported version. Upgrade cocos2d version");
CCString *textureFilename = (CCString*)dict->objectForKey("textureFilename");
std::string texturePathStr = relPathStr + ((CCString*)dict->objectForKey("textureFilename"))->getCString();
CCString *textureFilename = CCString::create(texturePathStr);
unsigned int width = ((CCString*)dict->objectForKey("itemWidth"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int height = ((CCString*)dict->objectForKey("itemHeight"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int startChar = ((CCString*)dict->objectForKey("firstChar"))->intValue();

View File

@ -125,10 +125,10 @@ static void removeJSTouchObject(JSContext *cx, CCTouch *x, jsval &jsret) {
}
void ScriptingCore::executeJSFunctionWithThisObj(jsval thisObj, jsval callback,
jsval data) {
jsval *data) {
jsval retval;
if(callback != JSVAL_VOID || thisObj != JSVAL_VOID) {
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(thisObj), callback, 1, &data, &retval);
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(thisObj), callback, 1, data, &retval);
}
}
@ -372,6 +372,12 @@ void ScriptingCore::removeAllRoots(JSContext *cx) {
js_proxy_t *current, *tmp;
HASH_ITER(hh, _js_native_global_ht, current, tmp) {
JS_RemoveObjectRoot(cx, &current->obj);
HASH_DEL(_js_native_global_ht, current);
free(current);
}
HASH_ITER(hh, _native_js_global_ht, current, tmp) {
HASH_DEL(_native_js_global_ht, current);
free(current);
}
HASH_CLEAR(hh, _js_native_global_ht);
HASH_CLEAR(hh, _native_js_global_ht);
@ -899,6 +905,31 @@ ccColor3B jsval_to_cccolor3b(JSContext *cx, jsval v) {
return cocos2d::ccc3(r, g, b);
}
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, CCPoint **points, int *numPoints) {
// Parsing sequence
JSObject *jsobj;
JSBool ok = JS_ValueToObject( cx, v, &jsobj );
if(!jsobj || !JS_IsArrayObject( cx, jsobj)) return JS_FALSE;
uint32_t len;
JS_GetArrayLength(cx, jsobj, &len);
CCPoint *array = (CCPoint*)malloc( sizeof(CCPoint) * len);
for( uint32_t i=0; i< len;i++ ) {
jsval valarg;
JS_GetElement(cx, jsobj, i, &valarg);
array[i] = jsval_to_ccpoint(cx, valarg);
}
*numPoints = len;
*points = array;
return JS_TRUE;
}
CCArray* jsval_to_ccarray(JSContext* cx, jsval v) {
JSObject *arr;
if (JS_ValueToObject(cx, v, &arr) && JS_IsArrayObject(cx, arr)) {

View File

@ -85,7 +85,7 @@ public:
int executeFunctionWithObjectData(CCNode *self, const char *name, JSObject *obj);
int executeFunctionWithOwner(jsval owner, const char *name, jsval data);
void executeJSFunctionWithThisObj(jsval thisObj, jsval callback, jsval data);
void executeJSFunctionWithThisObj(jsval thisObj, jsval callback, jsval *data);
/**
* will eval the specified string
@ -184,6 +184,7 @@ ccGridSize jsval_to_ccgridsize(JSContext *cx, jsval v);
ccColor4B jsval_to_cccolor4b(JSContext *cx, jsval v);
ccColor4F jsval_to_cccolor4f(JSContext *cx, jsval v);
ccColor3B jsval_to_cccolor3b(JSContext *cx, jsval v);
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, CCPoint **points, int *numPoints);
CCArray* jsval_to_ccarray(JSContext* cx, jsval v);
jsval ccarray_to_jsval(JSContext* cx, CCArray *arr);
// from native

View File

@ -406,6 +406,8 @@ JSBool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp)
ret = cocos2d::CCAnimation::create(arg0, arg1, loops);
} else if (argc == 1) {
ret = cocos2d::CCAnimation::createWithSpriteFrames(arg0);
} else if (argc == 0) {
ret = cocos2d::CCAnimation::create();
}
jsval jsret;
if (ret) {
@ -828,7 +830,509 @@ JSBool js_cocos2dx_CCSet_constructor(JSContext *cx, uint32_t argc, jsval *vp)
return JS_FALSE;
}
JSBool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCNode* cobj = (cocos2d::CCNode *)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, cobj)
if (argc == 1) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cobj->setPosition(arg0);
return JS_TRUE;
} if (argc == 2) {
double x;
if( ! JS_ValueToNumber(cx, argv[0], &x ) ) {
return JS_FALSE;
}
double y;
if( ! JS_ValueToNumber(cx, argv[1], &y ) ) {
return JS_FALSE;
}
cobj->setPosition(CCPoint(x,y));
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_CCSprite_setPosition(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCSprite* cobj = (cocos2d::CCSprite *)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, cobj)
if (argc == 1) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cobj->setPosition(arg0);
return JS_TRUE;
} if (argc == 2) {
double x;
if( ! JS_ValueToNumber(cx, argv[0], &x ) ) {
return JS_FALSE;
}
double y;
if( ! JS_ValueToNumber(cx, argv[1], &y ) ) {
return JS_FALSE;
}
cobj->setPosition(CCPoint(x,y));
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
template<class T>
JSBool js_BezierActions_create(JSContext *cx, uint32_t argc, jsval *vp) {
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
double t;
if( ! JS_ValueToNumber(cx, argv[0], &t) ) {
return JS_FALSE;
}
int num;
CCPoint *arr;
jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num);
ccBezierConfig config;
config.controlPoint_1 = arr[0];
config.controlPoint_2 = arr[1];
config.endPosition = arr[2];
CCBezierBy* ret = CCBezierBy::create(t, config);
free(arr);
jsval jsret;
do {
if (ret) {
js_proxy_t *p;
JS_GET_PROXY(p, ret);
if (p) {
jsret = OBJECT_TO_JSVAL(p->obj);
} else {
// create a new js obj of that class
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCBezierBy>(cx, ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
}
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
template<class T>
JSBool js_CardinalSplineActions_create(JSContext *cx, uint32_t argc, jsval *vp) {
jsval *argv = JS_ARGV(cx, vp);
if (argc == 3) {
double dur;
if( ! JS_ValueToNumber(cx, argv[0], &dur) ) {
return JS_FALSE;
}
int num;
CCPoint *arr;
jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num);
double ten;
if( ! JS_ValueToNumber(cx, argv[2], &ten) ) {
return JS_FALSE;
}
CCPointArray *points = CCPointArray::create(num);
for( int i=0; i < num;i++) {
points->addControlPoint(arr[i]);
}
T *ret = T::create(dur, points, ten);
free(arr);
jsval jsret;
do {
if (ret) {
js_proxy_t *p;
JS_GET_PROXY(p, ret);
if (p) {
jsret = OBJECT_TO_JSVAL(p->obj);
} else {
// create a new js obj of that class
js_proxy_t *proxy = js_get_or_create_proxy<T>(cx, ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
}
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
template<class T>
JSBool js_CatmullRomActions_create(JSContext *cx, uint32_t argc, jsval *vp) {
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
double dur;
if( ! JS_ValueToNumber(cx, argv[0], &dur) ) {
return JS_FALSE;
}
int num;
CCPoint *arr;
jsval_to_ccarray_of_CCPoint(cx, argv[1], &arr, &num);
CCPointArray *points = CCPointArray::create(num);
for( int i=0; i < num;i++) {
points->addControlPoint(arr[i]);
}
T *ret = T::create(dur, points);
free(arr);
jsval jsret;
do {
if (ret) {
js_proxy_t *p;
JS_GET_PROXY(p, ret);
if (p) {
jsret = OBJECT_TO_JSVAL(p->obj);
} else {
// create a new js obj of that class
js_proxy_t *proxy = js_get_or_create_proxy<T>(cx, ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
}
} else {
jsret = JSVAL_NULL;
}
} while (0);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool JSB_CCBezierBy_actionWithDuration(JSContext *cx, uint32_t argc, jsval *vp) {
js_BezierActions_create<cocos2d::CCBezierBy>(cx, argc, vp);
}
JSBool JSB_CCBezierTo_actionWithDuration(JSContext *cx, uint32_t argc, jsval *vp) {
js_BezierActions_create<cocos2d::CCBezierTo>(cx, argc, vp);
}
JSBool JSB_CCCardinalSplineBy_actionWithDuration(JSContext *cx, uint32_t argc, jsval *vp) {
return js_CardinalSplineActions_create<cocos2d::CCCardinalSplineBy>(cx, argc, vp);
}
JSBool JSB_CCCardinalSplineTo_actionWithDuration(JSContext *cx, uint32_t argc, jsval *vp) {
return js_CardinalSplineActions_create<cocos2d::CCCardinalSplineTo>(cx, argc, vp);
}
JSBool JSB_CCCatmullRomBy_actionWithDuration(JSContext *cx, uint32_t argc, jsval *vp) {
return js_CatmullRomActions_create<cocos2d::CCCatmullRomBy>(cx, argc, vp);
}
JSBool JSB_CCCatmullRomTo_actionWithDuration(JSContext *cx, uint32_t argc, jsval *vp) {
return js_CatmullRomActions_create<cocos2d::CCCatmullRomTo>(cx, argc, vp);
}
JSBool js_cocos2dx_ccpAdd(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
CCPoint ret = ccpAdd(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpNeg(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 1) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
CCPoint ret = ccpNeg(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpSub(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
CCPoint ret = ccpSub(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpMult(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
double arg1;
if( ! JS_ValueToNumber(cx, argv[1], &arg1) ) {
return JS_FALSE;
}
CCPoint ret = ccpMult(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpMidpoint(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
CCPoint ret = ccpMidpoint(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpDot(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
float ret = ccpDot(arg0, arg1);
jsval jsret = DOUBLE_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpCross(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
float ret = ccpCross(arg0, arg1);
jsval jsret = DOUBLE_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpPerp(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 1) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
CCPoint ret = ccpPerp(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpRPerp(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 1) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
CCPoint ret = ccpRPerp(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpProject(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
CCPoint ret = ccpProject(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpRotate(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 2) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
cocos2d::CCPoint arg1;
arg1 = jsval_to_ccpoint(cx, argv[1]);
CCPoint ret = ccpRotate(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_ccpNormalize(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
if (argc == 1) {
cocos2d::CCPoint arg0;
arg0 = jsval_to_ccpoint(cx, argv[0]);
CCPoint ret = ccpNormalize(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
extern JSObject* js_cocos2dx_CCNode_prototype;
extern JSObject* js_cocos2dx_CCLayerColor_prototype;
extern JSObject* js_cocos2dx_CCSprite_prototype;
extern JSObject* js_cocos2dx_CCAction_prototype;
extern JSObject* js_cocos2dx_CCAnimation_prototype;
extern JSObject* js_cocos2dx_CCMenuItem_prototype;
@ -839,8 +1343,13 @@ extern JSObject* js_cocos2dx_CCSpriteBatchNode_prototype;
//extern JSObject* js_cocos2dx_CCMotionStreak_prototype;
extern JSObject* js_cocos2dx_CCAtlasNode_prototype;
extern JSObject* js_cocos2dx_CCParticleBatchNode_prototype;
extern JSObject* js_cocos2dx_CCLayerColor_prototype;
extern JSObject* js_cocos2dx_CCParticleSystem_prototype;
extern JSObject* js_cocos2dx_CCCatmullRomBy_prototype;
extern JSObject* js_cocos2dx_CCCatmullRomTo_prototype;
extern JSObject* js_cocos2dx_CCCardinalSplineTo_prototype;
extern JSObject* js_cocos2dx_CCCardinalSplineBy_prototype;
extern JSObject* js_cocos2dx_CCBezierTo_prototype;
extern JSObject* js_cocos2dx_CCBezierBy_prototype;
// setBlendFunc
template<class T>
@ -926,6 +1435,29 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)
JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "schedule", js_CCNode_schedule, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "scheduleOnce", js_CCNode_scheduleOnce, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "unschedule", js_CCNode_unschedule, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "setPosition", js_cocos2dx_CCNode_setPosition, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCSprite_prototype, "setPosition", js_cocos2dx_CCSprite_setPosition, 1, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.BezierBy; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCBezierBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.BezierTo; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCBezierTo_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CardinalSplineBy; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCCardinalSplineBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CardinalSplineTo; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCCardinalSplineTo_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CatmullRomBy; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCCatmullRomBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.CatmullRomTo; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCCatmullRomTo_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCNode_prototype, "release", js_cocos2dx_release, 0, JSPROP_READONLY | JSPROP_PERMANENT);
@ -964,7 +1496,7 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemFont; })()"));
JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItemFont_create, 1, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.MenuItemToggle; })()"));
JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCMenuItemToggle_create, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "_create", js_cocos2dx_CCMenuItemToggle_create, 1, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Sequence; })()"));
JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCSequence_create, 0, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.Spawn; })()"));
@ -981,6 +1513,21 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return this; })()"));
JS_DefineFunction(cx, tmpObj, "garbageCollect", js_forceGC, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pAdd", js_cocos2dx_ccpAdd, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pSub", js_cocos2dx_ccpSub, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pNeg", js_cocos2dx_ccpNeg, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pMult", js_cocos2dx_ccpMult, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pMidpoint", js_cocos2dx_ccpMidpoint, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pDot", js_cocos2dx_ccpDot, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pCross", js_cocos2dx_ccpCross, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pPerp", js_cocos2dx_ccpPerp, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pRPerp", js_cocos2dx_ccpRPerp, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pProject", js_cocos2dx_ccpProject, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pRotate", js_cocos2dx_ccpRotate, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, ns, "pNormalize", js_cocos2dx_ccpNormalize, 0, JSPROP_READONLY | JSPROP_PERMANENT);
// add constructor for CCSet
JSFunction *ccSetConstructor = JS_NewFunction(cx, js_cocos2dx_CCSet_constructor, 0, JSPROP_READONLY | JSPROP_PERMANENT, NULL, "constructor");
JSObject *ctor = JS_GetFunctionObject(ccSetConstructor);

View File

@ -66,18 +66,24 @@ public:
void callbackFunc(CCNode *node) const {
js_proxy_t *p;
JS_GET_PROXY(p, node);
jsval retObj = OBJECT_TO_JSVAL(p->obj);
jsval valArr[2];
JSContext *cx = ScriptingCore::getInstance()->getGlobalContext();
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCNode>(cx, node);
valArr[0] = OBJECT_TO_JSVAL(proxy->obj);
if(extraData != NULL) {
ScriptingCore::getInstance()->executeJSFunctionWithThisObj(jsThisObj,
jsCallback,
*extraData);
valArr[1] = *extraData;
} else {
ScriptingCore::getInstance()->executeJSFunctionWithThisObj(jsThisObj,
jsCallback,
retObj);
valArr[1] = JSVAL_NULL;
}
jsval retval;
if(jsCallback != JSVAL_VOID || jsThisObj != JSVAL_VOID) {
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(jsThisObj), jsCallback, 1, valArr, &retval);
}
}
private:
jsval jsCallback;
@ -120,14 +126,17 @@ public:
void pause();
void scheduleFunc(CCNode *node) const {
void scheduleFunc(float dt) const {
jsval retObj = JSVAL_NULL;
ScriptingCore::getInstance()->executeJSFunctionWithThisObj(jsThisObj,
jsSchedule,
retObj);
jsval retval = JSVAL_NULL, data = DOUBLE_TO_JSVAL(dt);
JSContext *cx = ScriptingCore::getInstance()->getGlobalContext();
if(jsSchedule != JSVAL_VOID || jsThisObj != JSVAL_VOID) {
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(jsThisObj), jsSchedule, 1, &data, &retval);
}
}
private:
jsval jsSchedule;

View File

@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos2dx/include/cocos2d.h %(cocosdir)s/CocosDenshion/inc
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
classes = CCSprite.* CCScene CCNode CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCSequence CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCSet SimpleAudioEngine CCScheduler CCTimer CCOrbit.*
classes = CCSprite.* CCScene CCNode CCDirector CCLayer.* CCMenu.* CCTouch CC.*Action.* CCMove.* CCRotate.* CCBlink.* CCTint.* CCSequence CCRepeat.* CCFade.* CCEase.* CCScale.* CCTransition.* CCSpawn CCSequence CCAnimat.* CCFlip.* CCDelay.* CCSkew.* CCJump.* CCPlace.* CCShow.* CCProgress.* CCPointArray CCToggleVisibility.* CCHide CCParticle.* CCLabel.* CCAtlas.* CCTextureCache.* CCTexture2D CCCardinal.* CCCatmullRom.* CCParallaxNode CCTileMap.* CCTMX.* CCCallFunc CCRenderTexture CCGridAction CCGrid3DAction CCShaky3D CCWaves3D CCFlipX3D CCFlipY3D CCSpeed CCActionManager CCSet SimpleAudioEngine CCScheduler CCTimer CCOrbit.* CCFollow.* CCBezier.* CCCardinalSpline.*
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
@ -34,8 +34,9 @@ classes = CCSprite.* CCScene CCNode CCDirector CCLayer.* CCMenu.* CCTouch CC.*Ac
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = CCNode::[.*Transform convertToWindowSpace getChildren getGrid setGLServerState description getCamera getShaderProgram getUserObject .*UserData getGLServerState],
CCSprite::[getQuad displayFrame getTexture getBlendFunc setBlendFunc getTextureAtlas setSpriteBatchNode getSpriteBatchNode],
skip = CCNode::[.*Transform convertToWindowSpace getChildren setPosition getGrid setGLServerState description getCamera getShaderProgram getUserObject .*UserData getGLServerState],
CCSprite::[getQuad displayFrame getTexture getBlendFunc setPosition setBlendFunc getTextureAtlas setSpriteBatchNode getSpriteBatchNode],
CCSpriteBatchNode::[getBlendFunc setBlendFunc],
CCMotionStreak::[getBlendFunc setBlendFunc],
CCAtlasNode::[getBlendFunc setBlendFunc],
@ -44,7 +45,7 @@ skip = CCNode::[.*Transform convertToWindowSpace getChildren getGrid setGLServer
CCParticleSystem::[getBlendFunc setBlendFunc],
CCDirector::[getAccelerometer getKeypadDispatcher getTouchDispatcher setWatcherCallbackFun getOpenGLView getScheduler getProjection],
CCLayer.*::[didAccelerate (g|s)etBlendFunc],
CCMenu.*::[.*Target getSubItems create alignItemsInColumns initWithItems alignItemsInRows],
CCMenu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns],
CCMenuItem.*::[create],
CCRGBAProtocol::[*],
CCCopying::[*],
@ -88,6 +89,9 @@ skip = CCNode::[.*Transform convertToWindowSpace getChildren getGrid setGLServer
CCParticleSystemQuad::[postStep setBatchNode draw setTexture$ setTotalParticles updateQuadWithParticle setupIndices listenBackToForeground initWithTotalParticles particleWithFile node],
CCTexture2D::[initWithPVRTCData addPVRTCImage],
CCLayerMultiplex::[*],
CCCatmullRom.*::[create actionWithDuration],
CCBezier.*::[create actionWithDuration],
CCCardinalSpline.*::[create actionWithDuration setPoints],
CCTextureCache::[addPVRTCImage],
*::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*]