From 2c961bdfbfb8009e0fb0f9d45ded72e618a78a0f Mon Sep 17 00:00:00 2001 From: ucchen Date: Thu, 13 Feb 2014 11:01:54 +0800 Subject: [PATCH 1/9] add spine manual binding; --- .../project.pbxproj.REMOVED.git-id | 2 +- .../spine/jsb_cocos2dx_spine_manual.cpp | 552 ++++++++++++++++++ .../spine/jsb_cocos2dx_spine_manual.h | 18 + tests/test-javascript/Classes/AppDelegate.cpp | 2 + tools/tojs/cocos2dx_spine.ini | 2 +- 5 files changed, 574 insertions(+), 2 deletions(-) create mode 100644 cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.cpp create mode 100644 cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 3f9d30954c..5bb349ed36 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -c21329d05da45cbbfe3b7e668528ee0a1efe6043 \ No newline at end of file +5b5678e65a97b741b722874869cff95d5628e00c \ No newline at end of file diff --git a/cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.cpp b/cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.cpp new file mode 100644 index 0000000000..24491f92bb --- /dev/null +++ b/cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.cpp @@ -0,0 +1,552 @@ +// +// jsb_cocos2dx_spine_manual.cpp +// cocos2d_libs +// +// Created by ucchen on 2/12/14. +// +// + +#include "jsb_cocos2dx_spine_manual.h" +#include "ScriptingCore.h" +#include "cocos2d_specifics.hpp" +#include "spine/spine-cocos2dx.h" + +using namespace spine; + +jsval speventdata_to_jsval(JSContext* cx, spEventData& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "intValue", INT_TO_JSVAL(v.intValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "floatValue", DOUBLE_TO_JSVAL(v.floatValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "stringValue", c_string_to_jsval(cx, v.stringValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + return JSVAL_NULL; +} + +jsval spevent_to_jsval(JSContext* cx, spEvent& v) +{ + JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "data", speventdata_to_jsval(cx, *v.data), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "intValue", INT_TO_JSVAL(v.intValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "floatValue", DOUBLE_TO_JSVAL(v.floatValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "stringValue", c_string_to_jsval(cx, v.stringValue), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spbonedata_to_jsval(JSContext* cx, const spBoneData* v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + // root haven't parent + jsval parentVal = JSVAL_NULL; + if (strcmp(v->name, "root")) + parentVal = spbonedata_to_jsval(cx, v->parent); + + bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v->name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "parent", parentVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "length", DOUBLE_TO_JSVAL(v->length), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v->x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v->y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "rotation", DOUBLE_TO_JSVAL(v->rotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleX", DOUBLE_TO_JSVAL(v->scaleX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleY", DOUBLE_TO_JSVAL(v->scaleY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "inheritScale", INT_TO_JSVAL(v->inheritScale), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "inheritRotation", INT_TO_JSVAL(v->inheritRotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spbone_to_jsval(JSContext* cx, spBone& v) +{ + JSObject* tmp =JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + // root haven't parent + jsval parentVal = JSVAL_NULL; + if (strcmp(v.data->name, "root")) + parentVal = spbone_to_jsval(cx, *v.parent); + + bool ok = JS_DefineProperty(cx, tmp, "data", spbonedata_to_jsval(cx, v.data), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "parent", parentVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "rotation", DOUBLE_TO_JSVAL(v.rotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleX", DOUBLE_TO_JSVAL(v.scaleX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "scaleY", DOUBLE_TO_JSVAL(v.scaleY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m00", DOUBLE_TO_JSVAL(v.m00), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m01", DOUBLE_TO_JSVAL(v.m01), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldX", DOUBLE_TO_JSVAL(v.worldX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m10", DOUBLE_TO_JSVAL(v.m10), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "m11", DOUBLE_TO_JSVAL(v.m11), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldY", DOUBLE_TO_JSVAL(v.worldY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldRotation", DOUBLE_TO_JSVAL(v.worldRotation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldScaleX", DOUBLE_TO_JSVAL(v.worldScaleX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "worldScaleY", DOUBLE_TO_JSVAL(v.worldScaleY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spSkeleton_to_jsval(JSContext* cx, spSkeleton& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(v.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(v.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "flipX", DOUBLE_TO_JSVAL(v.flipX), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "flipY", DOUBLE_TO_JSVAL(v.flipY), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "time", DOUBLE_TO_JSVAL(v.time), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "boneCount", INT_TO_JSVAL(v.boneCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "slotCount", INT_TO_JSVAL(v.slotCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spattachment_to_jsval(JSContext* cx, spAttachment& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "r", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "type", INT_TO_JSVAL(v.type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT);/* && + JS_DefineProperty(cx, tmp, "vtable", OBJECT_TO_JSVAL(v.vtable), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT)*/ + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spslotdata_to_jsval(JSContext* cx, spSlotData& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "attachmentName", c_string_to_jsval(cx, v.attachmentName), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "r", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "a", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "additiveBlending", INT_TO_JSVAL(v.additiveBlending), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "boneData", spbonedata_to_jsval(cx, v.boneData), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spslot_to_jsval(JSContext* cx, spSlot& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "r", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "g", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "b", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "a", DOUBLE_TO_JSVAL(v.r), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "bone", spbone_to_jsval(cx, *v.bone), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "skeleton", spSkeleton_to_jsval(cx, *v.skeleton), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "attachment", spattachment_to_jsval(cx, *v.attachment), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "data", spslotdata_to_jsval(cx, *v.data), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spTimeline_to_jsval(JSContext* cx, spTimeline& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + // i have no idea to transition void* to jsval + bool ok = JS_DefineProperty(cx, tmp, "type", int32_to_jsval(cx, v.type), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT);/* && + JS_DefineProperty(cx, tmp, "vtable", OBJECT_TO_JSVAL(v.vtable), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT);*/ + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spAnimationState_to_jsval(JSContext* cx, spAnimationState& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "timeScale", DOUBLE_TO_JSVAL(v.timeScale), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "trackCount", DOUBLE_TO_JSVAL(v.trackCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spAnimation_to_jsval(JSContext* cx, spAnimation& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + bool ok = JS_DefineProperty(cx, tmp, "duration", DOUBLE_TO_JSVAL(v.duration), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timelineCount", INT_TO_JSVAL(v.timelineCount), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "name", c_string_to_jsval(cx, v.name), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timelines", spTimeline_to_jsval(cx, **v.timelines), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +jsval spTrackEntry_to_jsval(JSContext* cx, spTrackEntry& v) +{ + JSObject* tmp = JS_NewObject(cx, NULL, NULL, NULL); + if (!tmp) return JSVAL_NULL; + + jsval nextVal = JSVAL_NULL; + if (v.next) + nextVal = spTrackEntry_to_jsval(cx, *v.next); + + jsval previousVal = JSVAL_NULL; + if (v.previous) + previousVal = spTrackEntry_to_jsval(cx, *v.previous); + + bool ok = JS_DefineProperty(cx, tmp, "delay", DOUBLE_TO_JSVAL(v.delay), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "time", DOUBLE_TO_JSVAL(v.time), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "lastTime", DOUBLE_TO_JSVAL(v.lastTime), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "endTime", DOUBLE_TO_JSVAL(v.endTime), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "timeScale", DOUBLE_TO_JSVAL(v.timeScale), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "mixTime", DOUBLE_TO_JSVAL(v.mixTime), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "mixDuration", DOUBLE_TO_JSVAL(v.mixDuration), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "animation", spAnimation_to_jsval(cx, *v.animation), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "next", nextVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) && + JS_DefineProperty(cx, tmp, "previous", previousVal, NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT); + + if (ok) + { + return OBJECT_TO_JSVAL(tmp); + } + + return JSVAL_NULL; +} + +bool jsb_cocos2dx_spine_findBone(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); + if (argc == 1) { + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + spBone* ret = cobj->findBone(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) + { + jsret = spbone_to_jsval(cx, *ret); + } + } while (0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool jsb_cocos2dx_spine_findSlot(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); + if (argc == 1) { + const char* arg0; + std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + spSlot* ret = cobj->findSlot(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) + { + + } + } while (0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + spTrackEntry* ret = cobj->getCurrent(arg0); + jsval jsret = JSVAL_NULL; + do { + if (ret) + { + jsret = spTrackEntry_to_jsval(cx, *ret); + } + } while (0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } + else if (argc == 0) { + spTrackEntry* ret = cobj->getCurrent(); + jsval jsret = JSVAL_NULL; + do { + if (ret) + { + jsret = spTrackEntry_to_jsval(cx, *ret); + } + } while (0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); + if (argc == 3) { + int arg0; + ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + + const char* arg1; + std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + + bool arg2; + ok &= JS_ValueToBoolean(cx, argv[2], &arg2); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + spTrackEntry* ret = cobj->setAnimation(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + + do { + if (ret) + { + jsret = spTrackEntry_to_jsval(cx, *ret); + } + } while(0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + +bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); + if (argc == 3) { + int arg0; + ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + + const char* arg1; + std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + + bool arg2; + ok &= JS_ValueToBoolean(cx, argv[2], &arg2); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + spTrackEntry* ret = cobj->addAnimation(arg0, arg1, arg2); + jsval jsret = JSVAL_NULL; + + do { + if (ret) + { + jsret = spTrackEntry_to_jsval(cx, *ret); + } + } while(0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } else if (argc == 4) { + int arg0; + ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + + const char* arg1; + std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); + + bool arg2; + ok &= JS_ValueToBoolean(cx, argv[2], &arg2); + + double arg3; + ok &= JS::ToNumber(cx, JS::RootedValue(cx, argv[3]), &arg3); + JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); + + spTrackEntry* ret = cobj->addAnimation(arg0, arg1, arg2, arg3); + jsval jsret = JSVAL_NULL; + + do { + if (ret) + { + jsret = spTrackEntry_to_jsval(cx, *ret); + } + } while(0); + + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} + + +class JSSkeletonAnimationWrapper: public JSCallbackWrapper +{ +public: + JSSkeletonAnimationWrapper() {} + virtual ~JSSkeletonAnimationWrapper() {} + + void animationCallbackFunc(spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) const { + 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, node); + jsval retval; + if (_jsCallback != JSVAL_VOID) + { + jsval nodeVal = OBJECT_TO_JSVAL(proxy->obj); + jsval trackIndexVal = INT_TO_JSVAL(trackIndex); + int tmpType = (int)type; + jsval typeVal = INT_TO_JSVAL(tmpType); + jsval eventVal = JSVAL_NULL; + if (event) + eventVal = spevent_to_jsval(cx, *event); + jsval loopCountVal = INT_TO_JSVAL(loopCount); + + jsval valArr[5]; + valArr[0] = nodeVal; + valArr[1] = trackIndexVal; + valArr[2] = typeVal; + valArr[3] = eventVal; + valArr[4] = loopCountVal; + + JS_AddValueRoot(cx, valArr); + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JS_CallFunctionValue(cx, thisObj, _jsCallback, 5, valArr, &retval); + JS_RemoveValueRoot(cx, valArr); + } + } +}; + +static bool jsb_cocos2dx_spine_setAnimationListener(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + + spine::SkeletonAnimation* node = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( node, cx, false, "Invalid Native Object"); + if (argc == 2) { + JSSkeletonAnimationWrapper *tmpCobj = new JSSkeletonAnimationWrapper(); + jsval *argv = JS_ARGV(cx, vp); + + tmpCobj->setJSCallbackFunc(argv[1]); + tmpCobj->setJSCallbackThis(argv[0]); + + node->setAnimationListener(tmpCobj, animationStateEvent_selector(JSSkeletonAnimationWrapper::animationCallbackFunc)); + + JS_SET_RVAL(cx, vp, JSVAL_VOID); + + return true; + } + JS_ReportError(cx, "Invalid number of arguments"); + return false; +} + +extern JSObject* jsb_spine_SkeletonAnimation_prototype; + +void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global) +{ + JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "findBone", jsb_cocos2dx_spine_findBone, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "findSlot", jsb_cocos2dx_spine_findSlot, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "getCurrent", jsb_cocos2dx_spine_getCurrent, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "setAnimation", jsb_cocos2dx_spine_setAnimation, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "addAnimation", jsb_cocos2dx_spine_addAnimation, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "setAnimationListener", jsb_cocos2dx_spine_setAnimationListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT); +} diff --git a/cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.h b/cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.h new file mode 100644 index 0000000000..2a588473d2 --- /dev/null +++ b/cocos/scripting/javascript/bindings/spine/jsb_cocos2dx_spine_manual.h @@ -0,0 +1,18 @@ +// +// jsb_cocos2dx_spine_manual.h +// cocos2d_libs +// +// Created by ucchen on 2/12/14. +// +// + +#ifndef __jsb_cocos2dx_spine_manual__ +#define __jsb_cocos2dx_spine_manual__ + + +#include "jsapi.h" +#include "jsfriendapi.h" + +void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global); + +#endif /* defined(__jsb_cocos2dx_spine_manual__) */ diff --git a/tests/test-javascript/Classes/AppDelegate.cpp b/tests/test-javascript/Classes/AppDelegate.cpp index ffe11134d4..89575feafe 100644 --- a/tests/test-javascript/Classes/AppDelegate.cpp +++ b/tests/test-javascript/Classes/AppDelegate.cpp @@ -12,6 +12,7 @@ #include "extension/jsb_cocos2dx_extension_manual.h" #include "cocostudio/jsb_cocos2dx_studio_manual.h" #include "gui/jsb_cocos2dx_gui_manual.h" +#include "spine/jsb_cocos2dx_spine_manual.h" #include "cocos2d_specifics.hpp" #include "cocosbuilder/cocosbuilder_specifics.hpp" #include "chipmunk/js_bindings_chipmunk_registration.h" @@ -108,6 +109,7 @@ bool AppDelegate::applicationDidFinishLaunching() sc->addRegisterCallback(register_all_cocos2dx_studio_manual); sc->addRegisterCallback(register_all_cocos2dx_spine); + sc->addRegisterCallback(register_all_cocos2dx_spine_manual); sc->start(); diff --git a/tools/tojs/cocos2dx_spine.ini b/tools/tojs/cocos2dx_spine.ini index 9a6507072e..2fa794740e 100644 --- a/tools/tojs/cocos2dx_spine.ini +++ b/tools/tojs/cocos2dx_spine.ini @@ -21,7 +21,7 @@ extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h skip = Skeleton::[createWithData], - SkeletonAnimation::[createWithData] + SkeletonAnimation::[createWithData findBone findSlot getCurrent setAnimation addAnimation setAnimationListener] classes = Skeleton SkeletonAnimation From 6e742077c275283f4ec71cc1c2abfac73ddf83d4 Mon Sep 17 00:00:00 2001 From: ucchen Date: Thu, 13 Feb 2014 11:58:54 +0800 Subject: [PATCH 2/9] add spine setAnimationListener test; --- tests/test-javascript/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-javascript/tests b/tests/test-javascript/tests index 7a9a69a414..6bd64f94db 160000 --- a/tests/test-javascript/tests +++ b/tests/test-javascript/tests @@ -1 +1 @@ -Subproject commit 7a9a69a41480127a1572a4983eb9b5f1cbf2e186 +Subproject commit 6bd64f94dbfe0769110650424ccff2a3223767e4 From 17dab13502d5c4ebe40a63046498a34c2ae00074 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 09:36:27 +0800 Subject: [PATCH 3/9] Resets JS-Tests. --- tests/test-javascript/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-javascript/tests b/tests/test-javascript/tests index 6bd64f94db..7a9a69a414 160000 --- a/tests/test-javascript/tests +++ b/tests/test-javascript/tests @@ -1 +1 @@ -Subproject commit 6bd64f94dbfe0769110650424ccff2a3223767e4 +Subproject commit 7a9a69a41480127a1572a4983eb9b5f1cbf2e186 From ea7a27fdf7bb9869a3a0d769afda8b314129dc33 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 09:59:54 +0800 Subject: [PATCH 4/9] Updates JS-Tests. --- tests/test-javascript/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-javascript/tests b/tests/test-javascript/tests index 7a9a69a414..107a8f418d 160000 --- a/tests/test-javascript/tests +++ b/tests/test-javascript/tests @@ -1 +1 @@ -Subproject commit 7a9a69a41480127a1572a4983eb9b5f1cbf2e186 +Subproject commit 107a8f418d8dc87898f26d614855677f6c9c33c7 From 9d764718f9c0b6e71b2a76709ec3061bebbd28f3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 10:26:27 +0800 Subject: [PATCH 5/9] issue #4037: Removes unused files from Xcode setting. --- build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 03b9d8a5de..283d017ac8 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -62b321cb604eb543a6df3d89ab8d53c0c2a8b458 \ No newline at end of file +5bde2def1fece71a2464526c90939b9999ed05f3 \ No newline at end of file From f04e604a5168731779909a8309dd1e668e590615 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 10:27:19 +0800 Subject: [PATCH 6/9] Updates JS-Tests. --- tests/test-javascript/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-javascript/tests b/tests/test-javascript/tests index 107a8f418d..1589d7f727 160000 --- a/tests/test-javascript/tests +++ b/tests/test-javascript/tests @@ -1 +1 @@ -Subproject commit 107a8f418d8dc87898f26d614855677f6c9c33c7 +Subproject commit 1589d7f7273143e5c3250623a9efedad4e224518 From 2078f6de57ecfa0d66b5198793306f8b99638440 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 10:34:28 +0800 Subject: [PATCH 7/9] Updates CMakeLists. --- cocos/scripting/javascript/CMakeLists.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cocos/scripting/javascript/CMakeLists.txt b/cocos/scripting/javascript/CMakeLists.txt index 53efec15b6..253efc15df 100644 --- a/cocos/scripting/javascript/CMakeLists.txt +++ b/cocos/scripting/javascript/CMakeLists.txt @@ -5,26 +5,27 @@ set(JSBINDING_SRC ../auto-generated/js-bindings/jsb_cocos2dx_spine_auto.cpp ../auto-generated/js-bindings/jsb_cocos2dx_extension_auto.cpp ../auto-generated/js-bindings/jsb_cocos2dx_studio_auto.cpp - bindings/cocos2d_specifics.cpp - bindings/jsb_opengl_functions.cpp - bindings/js_manual_conversions.cpp - bindings/js_bindings_core.cpp - bindings/jsb_opengl_manual.cpp bindings/ScriptingCore.cpp + bindings/cocos2d_specifics.cpp + bindings/js_bindings_core.cpp bindings/js_bindings_opengl.cpp + bindings/js_manual_conversions.cpp + bindings/jsb_opengl_functions.cpp + bindings/jsb_opengl_manual.cpp bindings/jsb_opengl_registration.cpp bindings/chipmunk/js_bindings_chipmunk_auto_classes.cpp - bindings/extension/jsb_cocos2dx_extension_manual.cpp bindings/chipmunk/js_bindings_chipmunk_functions.cpp - bindings/gui/jsb_cocos2dx_gui_manual.cpp bindings/chipmunk/js_bindings_chipmunk_manual.cpp - bindings/localstorage/js_bindings_system_functions.cpp bindings/chipmunk/js_bindings_chipmunk_registration.cpp - bindings/localstorage/js_bindings_system_registration.cpp bindings/cocosbuilder/js_bindings_ccbreader.cpp - bindings/network/jsb_websocket.cpp bindings/cocostudio/jsb_cocos2dx_studio_manual.cpp + bindings/extension/jsb_cocos2dx_extension_manual.cpp + bindings/gui/jsb_cocos2dx_gui_manual.cpp + bindings/localstorage/js_bindings_system_functions.cpp + bindings/localstorage/js_bindings_system_registration.cpp bindings/network/XMLHTTPRequest.cpp + bindings/network/jsb_websocket.cpp + bindings/spine/jsb_cocos2dx_spine_manual.cpp ) include_directories( From 79e7d218cbead3aab4e54aca9512ab0243c8e474 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 10:37:50 +0800 Subject: [PATCH 8/9] Updates Android.mk --- cocos/scripting/javascript/bindings/spine/Android.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/javascript/bindings/spine/Android.mk b/cocos/scripting/javascript/bindings/spine/Android.mk index 033e557db2..4b376ec60d 100644 --- a/cocos/scripting/javascript/bindings/spine/Android.mk +++ b/cocos/scripting/javascript/bindings/spine/Android.mk @@ -6,7 +6,8 @@ LOCAL_MODULE := jsb_spine_static LOCAL_MODULE_FILENAME := libcocos2dxjsbspine -LOCAL_SRC_FILES := ../../../auto-generated/js-bindings/jsb_cocos2dx_spine_auto.cpp +LOCAL_SRC_FILES := ../../../auto-generated/js-bindings/jsb_cocos2dx_spine_auto.cpp \ + jsb_cocos2dx_spine_manual.cpp LOCAL_CFLAGS := -DCOCOS2D_JAVASCRIPT From 32012ee72ae3dee1b22d0b2229b9cfe7592e7e87 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Feb 2014 10:53:30 +0800 Subject: [PATCH 9/9] Adds missing files for vs. --- .../javascript/bindings/spine/libJSBindingForSpine.vcxproj | 2 ++ .../bindings/spine/libJSBindingForSpine.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj b/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj index 09e521c09d..f4e7b21ff3 100644 --- a/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj +++ b/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj @@ -12,9 +12,11 @@ + + diff --git a/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj.filters b/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj.filters index 5f6eb93a21..8eef0f01dd 100644 --- a/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj.filters +++ b/cocos/scripting/javascript/bindings/spine/libJSBindingForSpine.vcxproj.filters @@ -14,11 +14,17 @@ generated + + manual + generated + + manual +