32 |
33 | //#pragma mark - Helpful Macros
34 |
35 | #define JS_BINDED_CLASS_GLUE(klass) \
36 | static JSClass js_class; \
37 | static JSObject* js_proto; \
38 | static JSObject* js_parent; \
39 | static void _js_register(JSContext* cx, JS::HandleObject global);
40 |
41 | #define JS_BINDED_CLASS_GLUE_IMPL(klass) \
42 | JSClass klass::js_class = {}; \
43 | JSObject* klass::js_proto = NULL; \
44 | JSObject* klass::js_parent = NULL; \
45 |
46 | #define JS_BINDED_FUNC(klass, name) \
47 | bool name(JSContext *cx, unsigned argc, jsval *vp)
48 |
49 | #define JS_BINDED_CONSTRUCTOR(klass) \
50 | static bool _js_constructor(JSContext *cx, unsigned argc, jsval *vp)
51 |
52 | #define JS_BINDED_CONSTRUCTOR_IMPL(klass) \
53 | bool klass::_js_constructor(JSContext *cx, unsigned argc, jsval *vp)
54 |
55 | #define JS_BINDED_FUNC_IMPL(klass, name) \
56 | static bool klass##_func_##name(JSContext *cx, unsigned argc, jsval *vp) { \
57 | JSObject* thisObj = JS_THIS_OBJECT(cx, vp); \
58 | klass* obj = (klass*)JS_GetPrivate(thisObj); \
59 | if (obj) { \
60 | return obj->name(cx, argc, vp); \
61 | } \
62 | JS_ReportError(cx, "Invalid object call for function %s", #name); \
63 | return false; \
64 | } \
65 | bool klass::name(JSContext *cx, unsigned argc, jsval *vp)
66 |
67 | #define JS_WRAP_OBJECT_IN_VAL(klass, cobj, out) \
68 | do { \
69 | JSObject *obj = JS_NewObject(cx, &klass::js_class, klass::js_proto, klass::js_parent); \
70 | if (obj) { \
71 | JS_SetPrivate(obj, cobj); \
72 | out = OBJECT_TO_JSVAL(obj); \
73 | } \
74 | } while(0) \
75 |
76 | #define JS_BINDED_FUNC_FOR_DEF(klass, name) \
77 | JS_FN(#name, klass##_func_##name, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT)
78 |
79 | #define JS_BINDED_PROP_GET(klass, propName) \
80 | bool _js_get_##propName(JSContext *cx, const JS::CallArgs& args)
81 |
82 | #define JS_BINDED_PROP_GET_IMPL(klass, propName) \
83 | static bool _js_get_##klass##_##propName(JSContext *cx, unsigned argc, jsval *vp) { \
84 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \
85 | JSObject* obj = args.thisv().toObjectOrNull(); \
86 | klass* cobj = (klass*)JS_GetPrivate(obj); \
87 | if (cobj) { \
88 | return cobj->_js_get_##propName(cx, args); \
89 | } \
90 | JS_ReportError(cx, "Invalid getter call for property %s", #propName); \
91 | return false; \
92 | } \
93 | bool klass::_js_get_##propName(JSContext *cx, const JS::CallArgs& args)
94 |
95 | #define JS_BINDED_PROP_SET(klass, propName) \
96 | bool _js_set_##propName(JSContext *cx, const JS::CallArgs& args)
97 |
98 | #define JS_BINDED_PROP_SET_IMPL(klass, propName) \
99 | static bool _js_set_##klass##_##propName(JSContext *cx, unsigned argc, jsval *vp) { \
100 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \
101 | JSObject* obj = args.thisv().toObjectOrNull(); \
102 | klass* cobj = (klass*)JS_GetPrivate(obj); \
103 | if (cobj) { \
104 | return cobj->_js_set_##propName(cx, args); \
105 | } \
106 | JS_ReportError(cx, "Invalid setter call for property %s", #propName); \
107 | return false; \
108 | } \
109 | bool klass::_js_set_##propName(JSContext *cx, const JS::CallArgs& args)
110 |
111 | #define JS_BINDED_PROP_ACCESSOR(klass, propName) \
112 | JS_BINDED_PROP_GET(klass, propName); \
113 | JS_BINDED_PROP_SET(klass, propName);
114 |
115 | #define JS_BINDED_PROP_DEF_GETTER(klass, propName) \
116 | JS_PSG(#propName, _js_get_##klass##_##propName, JSPROP_ENUMERATE | JSPROP_PERMANENT)
117 |
118 | #define JS_BINDED_PROP_DEF_ACCESSOR(klass, propName) \
119 | JS_PSGS(#propName, _js_get_##klass##_##propName, _js_set_##klass##_##propName, JSPROP_ENUMERATE | JSPROP_PERMANENT)
120 |
121 | #define JS_CREATE_UINT_WRAPPED(valOut, propName, val) \
122 | do { \
123 | JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); \
124 | jsval propVal = UINT_TO_JSVAL(val); \
125 | JS_SetProperty(cx, jsobj, "__" propName, &propVal); \
126 | valOut = OBJECT_TO_JSVAL(jsobj); \
127 | } while(0)
128 |
129 | #define JS_GET_UINT_WRAPPED(inVal, propName, out) \
130 | do { \
131 | if (inVal.isObject()) {\
132 | JSObject* jsobj = JSVAL_TO_OBJECT(inVal); \
133 | jsval outVal; \
134 | JS_GetProperty(cx, jsobj, "__" propName, &outVal); \
135 | JS_ValueToECMAUint32(cx, outVal, &out); \
136 | } else { \
137 | int32_t tmp; \
138 | JS_ValueToInt32(cx, inVal, &tmp); \
139 | out = (uint32_t)tmp; \
140 | } \
141 | } while (0)
142 |
143 | #endif /* __XMLHTTPHELPER_H__ */
144 |
--------------------------------------------------------------------------------
/script/jsb_pool.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | *
29 | * cc.pool is a singleton object serves as an object cache pool.
30 | * It can helps you to improve your game performance for objects which need frequent release and recreate operations
31 | * Some common use case is :
32 | * 1. Bullets in game (die very soon, massive creation and recreation, no side effect on other objects)
33 | * 2. Blocks in candy crash (massive creation and recreation)
34 | * etc...
35 | *
36 | *
37 | * @example
38 | * var sp = new cc.Sprite("a.png");
39 | * this.addChild(sp);
40 | * cc.pool.putInPool(sp);
41 | *
42 | * cc.pool.getFromPool(cc.Sprite, "a.png");
43 | * @class
44 | * @name cc.pool
45 | */
46 | cc.pool = /** @lends cc.pool# */{
47 | _pool: {},
48 |
49 | _releaseCB: function () {
50 | this.release();
51 | },
52 |
53 | _autoRelease: function (obj) {
54 | var running = obj._running === undefined ? false : !obj._running;
55 | cc.director.getScheduler().scheduleCallbackForTarget(obj, this._releaseCB, 0, 0, 0, running)
56 | },
57 |
58 | /**
59 | * Put the obj in pool
60 | * @param obj
61 | */
62 | putInPool: function (obj) {
63 | var pid = obj.constructor.prototype.__pid;
64 | if (!pid) {
65 | var desc = { writable: true, enumerable: false, configurable: true };
66 | desc.value = ClassManager.getNewID();
67 | Object.defineProperty(obj.constructor.prototype, '__pid', desc);
68 | }
69 | if (!this._pool[pid]) {
70 | this._pool[pid] = [];
71 | }
72 | // JSB retain to avoid being auto released
73 | obj.retain && obj.retain();
74 | // User implementation for disable the object
75 | obj.unuse && obj.unuse();
76 | this._pool[pid].push(obj);
77 | },
78 |
79 | /**
80 | * Check if this kind of obj has already in pool
81 | * @param objClass
82 | * @returns {boolean} if this kind of obj is already in pool return true,else return false;
83 | */
84 | hasObject: function (objClass) {
85 | var pid = objClass.prototype.__pid;
86 | var list = this._pool[pid];
87 | if (!list || list.length == 0) {
88 | return false;
89 | }
90 | return true;
91 | },
92 |
93 | /**
94 | * Remove the obj if you want to delete it;
95 | * @param obj
96 | */
97 | removeObject: function (obj) {
98 | var pid = obj.constructor.prototype.__pid;
99 | if (pid) {
100 | var list = this._pool[pid];
101 | if (list) {
102 | for (var i = 0; i < list.length; i++) {
103 | if (obj === list[i]) {
104 | // JSB release to avoid memory leak
105 | obj.release && obj.release();
106 | list.splice(i, 1);
107 | }
108 | }
109 | }
110 | }
111 | },
112 |
113 | /**
114 | * Get the obj from pool
115 | * @param args
116 | * @returns {*} call the reuse function an return the obj
117 | */
118 | getFromPool: function (objClass/*,args*/) {
119 | if (this.hasObject(objClass)) {
120 | var pid = objClass.prototype.__pid;
121 | var list = this._pool[pid];
122 | var args = Array.prototype.slice.call(arguments);
123 | args.shift();
124 | var obj = list.pop();
125 | // User implementation for re-enable the object
126 | obj.reuse && obj.reuse.apply(obj, args);
127 | // JSB release to avoid memory leak
128 | cc.sys.isNative && obj.release && this._autoRelease(obj);
129 | return obj;
130 | }
131 | },
132 |
133 | /**
134 | * remove all objs in pool and reset the pool
135 | */
136 | drainAllPools: function () {
137 | for (var i in this._pool) {
138 | for (var j = 0; j < this._pool[i].length; j++) {
139 | var obj = this._pool[i][j];
140 | // JSB release to avoid memory leak
141 | obj.release && obj.release();
142 | }
143 | }
144 | this._pool = {};
145 | }
146 | };
--------------------------------------------------------------------------------
/manual/chipmunk/js_bindings_chipmunk_manual.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012 Zynga Inc.
3 | * Copyright (c) 2013-2014 Chukong Technologies Inc.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 |
24 |
25 | #ifndef __js_bindings_chipmunk_manual
26 | #define __js_bindings_chipmunk_manual
27 |
28 | #include "jsapi.h"
29 | #include "js_bindings_config.h"
30 | #include "js_manual_conversions.h"
31 | #include "ScriptingCore.h"
32 | #ifdef JSB_INCLUDE_CHIPMUNK
33 |
34 | #include "chipmunk_private.h"
35 | #include "js_bindings_chipmunk_auto_classes.h"
36 |
37 | // Free Functions
38 | bool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp);
39 | bool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp);
40 |
41 | bool JSB_cpArbiterGetBodies(JSContext *cx, uint32_t argc, jsval *vp);
42 | bool JSB_cpArbiterGetShapes(JSContext *cx, uint32_t argc, jsval *vp);
43 |
44 | bool JSB_cpBodyGetUserData(JSContext *cx, uint32_t argc, jsval *vp);
45 | bool JSB_cpBodySetUserData(JSContext *cx, uint32_t argc, jsval *vp);
46 |
47 | // poly related
48 | bool JSB_cpAreaForPoly(JSContext *cx, uint32_t argc, jsval *vp);
49 | bool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp);
50 | bool JSB_cpCentroidForPoly(JSContext *cx, uint32_t argc, jsval *vp);
51 | bool JSB_cpRecenterPoly(JSContext *cx, uint32_t argc, jsval *vp);
52 |
53 | // "Methods" from the OO API
54 | bool JSB_cpSpace_setDefaultCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp);
55 | bool JSB_cpSpace_addCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp);
56 | bool JSB_cpSpace_removeCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp);
57 |
58 | // manually wrapped for rooting/unrooting purposes
59 | bool JSB_cpSpace_addBody(JSContext *cx, uint32_t argc, jsval *vp);
60 | bool JSB_cpSpace_addConstraint(JSContext *cx, uint32_t argc, jsval *vp);
61 | bool JSB_cpSpace_addShape(JSContext *cx, uint32_t argc, jsval *vp);
62 | bool JSB_cpSpace_addStaticShape(JSContext *cx, uint32_t argc, jsval *vp);
63 | bool JSB_cpSpace_removeBody(JSContext *cx, uint32_t argc, jsval *vp);
64 | bool JSB_cpSpace_removeConstraint(JSContext *cx, uint32_t argc, jsval *vp);
65 | bool JSB_cpSpace_removeShape(JSContext *cx, uint32_t argc, jsval *vp);
66 | bool JSB_cpSpace_removeStaticShape(JSContext *cx, uint32_t argc, jsval *vp);
67 | bool JSB_cpSpace_segmentQueryFirst(JSContext *cx, uint32_t argc, jsval *vp);
68 | bool JSB_cpSpace_nearestPointQueryNearest(JSContext *cx, uint32_t argc, jsval *vp);
69 | bool JSB_cpSpace_eachShape(JSContext *cx, uint32_t argc, jsval *vp);
70 | bool JSB_cpSpace_eachBody(JSContext *cx, uint32_t argc, jsval *vp);
71 | bool JSB_cpSpace_eachConstraint(JSContext *cx, uint32_t argc, jsval *vp);
72 | bool JSB_cpSpace_pointQuery(JSContext *cx, uint32_t argc, jsval *vp);
73 | bool JSB_cpSpace_nearestPointQuery(JSContext *cx, uint32_t argc, jsval *vp);
74 | bool JSB_cpSpace_segmentQuery(JSContext *cx, uint32_t argc, jsval *vp);
75 | bool JSB_cpSpace_bbQuery(JSContext *cx, uint32_t argc, jsval *vp);
76 | bool JSB_cpSpace_addPostStepCallback(JSContext *cx, uint32_t argc, jsval *vp);
77 |
78 | bool JSB_cpArbiter_getBodies(JSContext *cx, uint32_t argc, jsval *vp);
79 | bool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp);
80 |
81 | bool JSB_cpBody_constructor(JSContext *cx, uint32_t argc, jsval *vp);
82 | bool JSB_cpBody_getUserData(JSContext *cx, uint32_t argc, jsval *vp);
83 | bool JSB_cpBody_setUserData(JSContext *cx, uint32_t argc, jsval *vp);
84 |
85 | bool JSB_cpBody_eachShape(JSContext *cx, uint32_t argc, jsval *vp);
86 | bool JSB_cpBody_eachConstraint(JSContext *cx, uint32_t argc, jsval *vp);
87 | bool JSB_cpBody_eachArbiter(JSContext *cx, uint32_t argc, jsval *vp);
88 |
89 |
90 | // convertions
91 |
92 | jsval cpBB_to_jsval(JSContext *cx, cpBB bb );
93 | bool jsval_to_cpBB( JSContext *cx, jsval vp, cpBB *ret );
94 | bool jsval_to_array_of_cpvect( JSContext *cx, jsval vp, cpVect**verts, int *numVerts);
95 | bool jsval_to_cpVect( JSContext *cx, jsval vp, cpVect *out );
96 | jsval cpVect_to_jsval( JSContext *cx, cpVect p );
97 |
98 | // Object Oriented Chipmunk
99 | void JSB_cpBase_createClass(JSContext* cx, JS::HandleObject globalObj, const char * name );
100 | extern JSObject* JSB_cpBase_object;
101 | extern JSClass* JSB_cpBase_class;
102 | extern void register_CCPhysicsSprite(JSContext *cx, JS::HandleObject obj);
103 | extern void register_CCPhysicsDebugNode(JSContext *cx, JS::HandleObject obj);
104 |
105 | // Manual constructor / destructors
106 | bool JSB_cpPolyShape_constructor(JSContext *cx, uint32_t argc, jsval *vp);
107 | void JSB_cpSpace_finalize(JSFreeOp *fop, JSObject *obj);
108 |
109 | #endif // JSB_INCLUDE_CHIPMUNK
110 |
111 | #endif // __js_bindings_chipmunk_manual
112 |
--------------------------------------------------------------------------------
/script/physicsSprite/jsb_physicsSprite.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-2014 Chukong Technologies Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 |
23 | // move from extension
24 | // start
25 | //PhysicsDebugNode
26 | cc.PhysicsDebugNode.create = function( space ) {
27 | var s = space;
28 | if( space.handle !== undefined )
29 | s = space.handle;
30 | return cc.PhysicsDebugNode._create( s );
31 | };
32 |
33 | cc.PhysicsDebugNode.prototype._ctor = function(space){
34 | this.init();
35 | var s = space;
36 | if( space.handle !== undefined )
37 | s = space.handle;
38 | this.setSpace(s);
39 | };
40 |
41 | cc.PhysicsDebugNode.prototype.setSpace = function( space ) {
42 | var s = space;
43 | if( space.handle !== undefined )
44 | s = space.handle;
45 | return this._setSpace( s );
46 | };
47 |
48 | // physicsSprite
49 | cc.PhysicsSprite.prototype.setBody = function( body ) {
50 | var b = body;
51 | if( body.handle !== undefined )
52 | b = body.handle;
53 | return this._setCPBody( b );
54 | };
55 |
56 | cc.PhysicsSprite.prototype.getBody = function() {
57 | return this.getCPBody();
58 | };
59 | // end
60 |
61 | // move from property_impls
62 | // start
63 | _safeExtend(cc.PhysicsSprite.prototype, {
64 | setPositionX: function(x) {
65 | this.setPosition( cc.p(x, this.getPositionY()) );
66 | },
67 | setPositionY: function(y) {
68 | this.setPosition( cc.p(this.getPositionX(), y) );
69 | }
70 | });
71 | // end
72 |
73 | // move from property_apis
74 | // start
75 | var _proto = cc.PhysicsSprite.prototype;
76 | cc.defineGetterSetter(_proto, "body", _proto.getBody, _proto.setBody);
77 | cc.defineGetterSetter(_proto, "x", _proto.getPositionX, _proto.setPositionX);
78 | cc.defineGetterSetter(_proto, "y", _proto.getPositionY, _proto.setPositionY);
79 | cc.defineGetterSetter(_proto, "rotation", _proto.getRotation, _proto.setRotation);
80 | cc.defineGetterSetter(_proto, "dirty", _proto.isDirty, _proto.setDirty);
81 | // end
82 |
83 | // move from create_apis
84 | // start
85 | /************************ PhysicsSprite *************************/
86 | var _p = cc.PhysicsSprite.prototype;
87 | _p._ctor = function(fileName, rect){
88 | if (fileName === undefined) {
89 | cc.PhysicsSprite.prototype.init.call(this);
90 | }else if (typeof(fileName) === "string") {
91 | if (fileName[0] === "#") {
92 | //init with a sprite frame name
93 | var frameName = fileName.substr(1, fileName.length - 1);
94 | var spriteFrame = cc.spriteFrameCache.getSpriteFrame(frameName);
95 | this.initWithSpriteFrame(spriteFrame);
96 | } else {
97 | //init with filename and rect
98 | if(rect)
99 | this.initWithFile(fileName, rect);
100 | else
101 | this.initWithFile(fileName);
102 | }
103 | }else if (typeof(fileName) === "object") {
104 | if (fileName instanceof cc.Texture2D) {
105 | //init with texture and rect
106 | this.initWithTexture(fileName, rect);
107 | } else if (fileName instanceof cc.SpriteFrame) {
108 | //init with a sprite frame
109 | this.initWithSpriteFrame(fileName);
110 | }
111 | }
112 | };
113 |
114 | cc.PhysicsSprite._create = cc.PhysicsSprite.create;
115 | cc.PhysicsSprite.create = function (fileName, rect) {
116 | var sprite;
117 |
118 | if (arguments.length == 0) {
119 | sprite = cc.PhysicsSprite._create();
120 | return sprite;
121 | }
122 |
123 | if (typeof(fileName) === "string") {
124 | if (fileName[0] === "#") {
125 | //init with a sprite frame name
126 | var frameName = fileName.substr(1, fileName.length - 1);
127 | var spriteFrame = cc.spriteFrameCache.getSpriteFrame(frameName);
128 | sprite = cc.PhysicsSprite.createWithSpriteFrame(spriteFrame);
129 | } else {
130 | // Create with filename and rect
131 | sprite = rect ? cc.PhysicsSprite._create(fileName, rect) : cc.PhysicsSprite._create(fileName);
132 | }
133 | if (sprite)
134 | return sprite;
135 | else return null;
136 | }
137 |
138 | if (typeof(fileName) === "object") {
139 | if (fileName instanceof cc.Texture2D) {
140 | //init with texture and rect
141 | sprite = rect ? cc.PhysicsSprite.createWithTexture(fileName, rect) : cc.PhysicsSprite.createWithTexture(fileName);
142 | } else if (fileName instanceof cc.SpriteFrame) {
143 | //init with a sprite frame
144 | sprite = cc.PhysicsSprite.createWithSpriteFrame(fileName)
145 | }
146 | if (sprite)
147 | return sprite;
148 | else return null;
149 | }
150 |
151 | return null;
152 | };
153 | // end
154 |
155 |
--------------------------------------------------------------------------------
/manual/network/XMLHTTPRequest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by Rolando Abarca 2012.
3 | * Copyright (c) 2012 Rolando Abarca. All rights reserved.
4 | * Copyright (c) 2013 Zynga Inc. All rights reserved.
5 | * Copyright (c) 2013-2014 Chukong Technologies Inc.
6 | *
7 | * Heavy based on: https://github.com/funkaster/FakeWebGL/blob/master/FakeWebGL/WebGL/XMLHTTPRequest.h
8 | *
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy
10 | * of this software and associated documentation files (the "Software"), to deal
11 | * in the Software without restriction, including without limitation the rights
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the Software is
14 | * furnished to do so, subject to the following conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be included in
17 | * all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | * THE SOFTWARE.
26 | */
27 |
28 |
29 | #ifndef __FAKE_XMLHTTPREQUEST_H__
30 | #define __FAKE_XMLHTTPREQUEST_H__
31 |
32 | #include "jsapi.h"
33 | #include "jsfriendapi.h"
34 | #include "network/HttpClient.h"
35 | #include "js_bindings_config.h"
36 | #include "ScriptingCore.h"
37 | #include "jsb_helper.h"
38 |
39 | class MinXmlHttpRequest : public cocos2d::Ref
40 | {
41 | public:
42 | enum class ResponseType
43 | {
44 | STRING,
45 | ARRAY_BUFFER,
46 | BLOB,
47 | DOCUMENT,
48 | JSON
49 | };
50 |
51 | // Ready States (http://www.w3.org/TR/XMLHttpRequest/#interface-xmlhttprequest)
52 | static const unsigned short UNSENT = 0;
53 | static const unsigned short OPENED = 1;
54 | static const unsigned short HEADERS_RECEIVED = 2;
55 | static const unsigned short LOADING = 3;
56 | static const unsigned short DONE = 4;
57 |
58 | MinXmlHttpRequest();
59 | ~MinXmlHttpRequest();
60 |
61 | JS_BINDED_CLASS_GLUE(MinXmlHttpRequest);
62 | JS_BINDED_CONSTRUCTOR(MinXmlHttpRequest);
63 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onloadstart);
64 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onreadystatechange);
65 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onabort);
66 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onerror);
67 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onload);
68 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, onloadend);
69 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, ontimeout);
70 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, withCredentials);
71 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, upload);
72 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, timeout);
73 | JS_BINDED_PROP_ACCESSOR(MinXmlHttpRequest, responseType);
74 | JS_BINDED_PROP_GET(MinXmlHttpRequest, readyState);
75 | JS_BINDED_PROP_GET(MinXmlHttpRequest, status);
76 | JS_BINDED_PROP_GET(MinXmlHttpRequest, statusText);
77 | JS_BINDED_PROP_GET(MinXmlHttpRequest, responseText);
78 | JS_BINDED_PROP_GET(MinXmlHttpRequest, response);
79 | JS_BINDED_PROP_GET(MinXmlHttpRequest, responseXML);
80 | JS_BINDED_FUNC(MinXmlHttpRequest, open);
81 | JS_BINDED_FUNC(MinXmlHttpRequest, send);
82 | JS_BINDED_FUNC(MinXmlHttpRequest, abort);
83 | JS_BINDED_FUNC(MinXmlHttpRequest, getAllResponseHeaders);
84 | JS_BINDED_FUNC(MinXmlHttpRequest, getResponseHeader);
85 | JS_BINDED_FUNC(MinXmlHttpRequest, setRequestHeader);
86 | JS_BINDED_FUNC(MinXmlHttpRequest, overrideMimeType);
87 |
88 | void handle_requestResponse(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response);
89 |
90 | void update(float dt);
91 | private:
92 | void _gotHeader(std::string header);
93 | void _setRequestHeader(const char* field, const char* value);
94 | void _setHttpRequestHeader();
95 | void _setHttpRequestData(const char *data, size_t len);
96 | void _sendRequest(JSContext *cx);
97 | void _notify(JSObject * callback);
98 |
99 | std::string _url;
100 | JSContext* _cx;
101 | std::string _meth;
102 | std::string _type;
103 | char* _data;
104 | uint32_t _dataSize;
105 | JS::Heap _onloadstartCallback;
106 | JS::Heap _onabortCallback;
107 | JS::Heap _onerrorCallback;
108 | JS::Heap _onloadCallback;
109 | JS::Heap _onloadendCallback;
110 | JS::Heap _ontimeoutCallback;
111 | JS::Heap _onreadystateCallback;
112 | int _readyState;
113 | int _status;
114 | std::string _statusText;
115 | ResponseType _responseType;
116 | unsigned long long _timeout;
117 | float _elapsedTime;
118 | bool _isAsync;
119 | cocos2d::network::HttpRequest* _httpRequest;
120 | bool _isNetwork;
121 | bool _withCredentialsValue;
122 | bool _errorFlag;
123 | std::unordered_map _httpHeader;
124 | std::unordered_map _requestHeader;
125 | bool _isAborted;
126 | cocos2d::Scheduler* _scheduler;
127 | };
128 |
129 | #endif
130 |
--------------------------------------------------------------------------------
/auto/jsb_cocos2dx_3d_extension_auto.hpp:
--------------------------------------------------------------------------------
1 | #ifndef __cocos2dx_3d_extension_h__
2 | #define __cocos2dx_3d_extension_h__
3 |
4 | #include "jsapi.h"
5 | #include "jsfriendapi.h"
6 |
7 |
8 | extern JSClass *jsb_cocos2d_ParticleSystem3D_class;
9 | extern JSObject *jsb_cocos2d_ParticleSystem3D_prototype;
10 |
11 | bool js_cocos2dx_3d_extension_ParticleSystem3D_constructor(JSContext *cx, uint32_t argc, jsval *vp);
12 | void js_cocos2dx_3d_extension_ParticleSystem3D_finalize(JSContext *cx, JSObject *obj);
13 | void js_register_cocos2dx_3d_extension_ParticleSystem3D(JSContext *cx, JS::HandleObject global);
14 | void register_all_cocos2dx_3d_extension(JSContext* cx, JS::HandleObject obj);
15 | bool js_cocos2dx_3d_extension_ParticleSystem3D_resumeParticleSystem(JSContext *cx, uint32_t argc, jsval *vp);
16 | bool js_cocos2dx_3d_extension_ParticleSystem3D_startParticleSystem(JSContext *cx, uint32_t argc, jsval *vp);
17 | bool js_cocos2dx_3d_extension_ParticleSystem3D_isEnabled(JSContext *cx, uint32_t argc, jsval *vp);
18 | bool js_cocos2dx_3d_extension_ParticleSystem3D_isKeepLocal(JSContext *cx, uint32_t argc, jsval *vp);
19 | bool js_cocos2dx_3d_extension_ParticleSystem3D_setEnabled(JSContext *cx, uint32_t argc, jsval *vp);
20 | bool js_cocos2dx_3d_extension_ParticleSystem3D_getParticleQuota(JSContext *cx, uint32_t argc, jsval *vp);
21 | bool js_cocos2dx_3d_extension_ParticleSystem3D_getBlendFunc(JSContext *cx, uint32_t argc, jsval *vp);
22 | bool js_cocos2dx_3d_extension_ParticleSystem3D_pauseParticleSystem(JSContext *cx, uint32_t argc, jsval *vp);
23 | bool js_cocos2dx_3d_extension_ParticleSystem3D_getState(JSContext *cx, uint32_t argc, jsval *vp);
24 | bool js_cocos2dx_3d_extension_ParticleSystem3D_getAliveParticleCount(JSContext *cx, uint32_t argc, jsval *vp);
25 | bool js_cocos2dx_3d_extension_ParticleSystem3D_setParticleQuota(JSContext *cx, uint32_t argc, jsval *vp);
26 | bool js_cocos2dx_3d_extension_ParticleSystem3D_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp);
27 | bool js_cocos2dx_3d_extension_ParticleSystem3D_stopParticleSystem(JSContext *cx, uint32_t argc, jsval *vp);
28 | bool js_cocos2dx_3d_extension_ParticleSystem3D_setKeepLocal(JSContext *cx, uint32_t argc, jsval *vp);
29 | bool js_cocos2dx_3d_extension_ParticleSystem3D_ParticleSystem3D(JSContext *cx, uint32_t argc, jsval *vp);
30 |
31 | extern JSClass *jsb_cocos2d_PUParticleSystem3D_class;
32 | extern JSObject *jsb_cocos2d_PUParticleSystem3D_prototype;
33 |
34 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_constructor(JSContext *cx, uint32_t argc, jsval *vp);
35 | void js_cocos2dx_3d_extension_PUParticleSystem3D_finalize(JSContext *cx, JSObject *obj);
36 | void js_register_cocos2dx_3d_extension_PUParticleSystem3D(JSContext *cx, JS::HandleObject global);
37 | void register_all_cocos2dx_3d_extension(JSContext* cx, JS::HandleObject obj);
38 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getParticleSystemScaleVelocity(JSContext *cx, uint32_t argc, jsval *vp);
39 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedSystemQuota(JSContext *cx, uint32_t argc, jsval *vp);
40 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultDepth(JSContext *cx, uint32_t argc, jsval *vp);
41 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedSystemQuota(JSContext *cx, uint32_t argc, jsval *vp);
42 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_clearAllParticles(JSContext *cx, uint32_t argc, jsval *vp);
43 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getMaterialName(JSContext *cx, uint32_t argc, jsval *vp);
44 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_calulateRotationOffset(JSContext *cx, uint32_t argc, jsval *vp);
45 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getMaxVelocity(JSContext *cx, uint32_t argc, jsval *vp);
46 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_forceUpdate(JSContext *cx, uint32_t argc, jsval *vp);
47 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getTimeElapsedSinceStart(JSContext *cx, uint32_t argc, jsval *vp);
48 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getEmittedEmitterQuota(JSContext *cx, uint32_t argc, jsval *vp);
49 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_isMarkedForEmission(JSContext *cx, uint32_t argc, jsval *vp);
50 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultWidth(JSContext *cx, uint32_t argc, jsval *vp);
51 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setEmittedEmitterQuota(JSContext *cx, uint32_t argc, jsval *vp);
52 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMarkedForEmission(JSContext *cx, uint32_t argc, jsval *vp);
53 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_clone(JSContext *cx, uint32_t argc, jsval *vp);
54 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultWidth(JSContext *cx, uint32_t argc, jsval *vp);
55 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_copyAttributesTo(JSContext *cx, uint32_t argc, jsval *vp);
56 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMaterialName(JSContext *cx, uint32_t argc, jsval *vp);
57 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getParentParticleSystem(JSContext *cx, uint32_t argc, jsval *vp);
58 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setMaxVelocity(JSContext *cx, uint32_t argc, jsval *vp);
59 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDefaultHeight(JSContext *cx, uint32_t argc, jsval *vp);
60 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedPosition(JSContext *cx, uint32_t argc, jsval *vp);
61 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_rotationOffset(JSContext *cx, uint32_t argc, jsval *vp);
62 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedOrientation(JSContext *cx, uint32_t argc, jsval *vp);
63 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllEmitter(JSContext *cx, uint32_t argc, jsval *vp);
64 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setParticleSystemScaleVelocity(JSContext *cx, uint32_t argc, jsval *vp);
65 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_getDerivedScale(JSContext *cx, uint32_t argc, jsval *vp);
66 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultHeight(JSContext *cx, uint32_t argc, jsval *vp);
67 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_removeAllListener(JSContext *cx, uint32_t argc, jsval *vp);
68 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_setDefaultDepth(JSContext *cx, uint32_t argc, jsval *vp);
69 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_create(JSContext *cx, uint32_t argc, jsval *vp);
70 | bool js_cocos2dx_3d_extension_PUParticleSystem3D_PUParticleSystem3D(JSContext *cx, uint32_t argc, jsval *vp);
71 | #endif
72 |
73 |
--------------------------------------------------------------------------------
/script/extension/jsb_ext_property_apis.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Chukong Technologies Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 |
23 | var _proto = cc.Control.prototype;
24 | cc.defineGetterSetter(_proto, "opacityModifyRGB", _proto.isOpacityModifyRGB, _proto.setOpacityModifyRGB);
25 | cc.defineGetterSetter(_proto, "state", _proto.getState);
26 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
27 | cc.defineGetterSetter(_proto, "selected", _proto.isSelected, _proto.setSelected);
28 | cc.defineGetterSetter(_proto, "highlighted", _proto.isHighlighted, _proto.setHighlighted);
29 |
30 | _proto = cc.ControlButton.prototype;
31 | cc.defineGetterSetter(_proto, "color", _proto.getColor, _proto.setColor);
32 | cc.defineGetterSetter(_proto, "opacity", _proto.getOpacity, _proto.setOpacity);
33 | cc.defineGetterSetter(_proto, "adjustBackgroundImage", _proto.getAdjustBackgroundImage, _proto.setAdjustBackgroundImage);
34 | cc.defineGetterSetter(_proto, "zoomOnTouchDown", _proto.getZoomOnTouchDown, _proto.setZoomOnTouchDown);
35 | cc.defineGetterSetter(_proto, "preferredSize", _proto.getPreferredSize, _proto.setPreferredSize);
36 | cc.defineGetterSetter(_proto, "labelAnchor", _proto.getLabelAnchorPoint, _proto.setLabelAnchorPoint);
37 |
38 | _proto = cc.ControlColourPicker.prototype;
39 | cc.defineGetterSetter(_proto, "color", _proto.getColor, _proto.setColor);
40 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
41 | cc.defineGetterSetter(_proto, "background", _proto.getBackground);
42 |
43 | _proto = cc.ControlHuePicker.prototype;
44 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
45 | cc.defineGetterSetter(_proto, "hue", _proto.getHue, _proto.setHue);
46 | cc.defineGetterSetter(_proto, "huePercent", _proto.getHuePercentage, _proto.setHuePercentage);
47 | cc.defineGetterSetter(_proto, "background", _proto.getBackground);
48 | cc.defineGetterSetter(_proto, "slider", _proto.getSlider);
49 | cc.defineGetterSetter(_proto, "startPos", _proto.getStartPos);
50 |
51 | _proto = cc.ControlPotentiometer.prototype;
52 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
53 | cc.defineGetterSetter(_proto, "value", _proto.getValue, _proto.setValue);
54 | cc.defineGetterSetter(_proto, "minValue", _proto.getMinimumValue, _proto.setMinimumValue);
55 | cc.defineGetterSetter(_proto, "maxValue", _proto.getMaximumValue, _proto.setMaximumValue);
56 | cc.defineGetterSetter(_proto, "progressTimer", _proto.getProgressTimer, _proto.setProgressTimer);
57 | cc.defineGetterSetter(_proto, "thumbSprite", _proto.getThumbSprite, _proto.setThumbSprite);
58 | cc.defineGetterSetter(_proto, "prevLocation", _proto.getPreviousLocation, _proto.setPreviousLocation);
59 |
60 | _proto = cc.ControlSaturationBrightnessPicker.prototype;
61 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
62 | cc.defineGetterSetter(_proto, "saturation", _proto.getSaturation);
63 | cc.defineGetterSetter(_proto, "brightness", _proto.getBrightness);
64 | cc.defineGetterSetter(_proto, "background", _proto.getBackground);
65 | cc.defineGetterSetter(_proto, "overlay", _proto.getOverlay);
66 | cc.defineGetterSetter(_proto, "shadow", _proto.getShadow);
67 | cc.defineGetterSetter(_proto, "slider", _proto.getSlider);
68 | cc.defineGetterSetter(_proto, "startPos", _proto.getStartPos);
69 |
70 | _proto = cc.ControlSlider.prototype;
71 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
72 | cc.defineGetterSetter(_proto, "value", _proto.getValue, _proto.setValue);
73 | cc.defineGetterSetter(_proto, "minValue", _proto.getMinimumValue, _proto.setMinimumValue);
74 | cc.defineGetterSetter(_proto, "maxValue", _proto.getMaximumValue, _proto.setMaximumValue);
75 | cc.defineGetterSetter(_proto, "minAllowedValue", _proto.getMinimumAllowedValue, _proto.setMinimumAllowedValue);
76 | cc.defineGetterSetter(_proto, "maxAllowedValue", _proto.getMaximumAllowedValue, _proto.setMaximumAllowedValue);
77 | cc.defineGetterSetter(_proto, "thumbSprite", _proto.getThumbSprite);
78 | cc.defineGetterSetter(_proto, "progressSprite", _proto.getProgressSprite);
79 | cc.defineGetterSetter(_proto, "backgroundSprite", _proto.getBackgroundSprite);
80 |
81 | _proto = cc.ControlSwitch.prototype;
82 | cc.defineGetterSetter(_proto, "enabled", _proto.isEnabled, _proto.setEnabled);
83 |
84 | _proto = cc.ScrollView.prototype;
85 | cc.defineGetterSetter(_proto, "width", _proto._getWidth, _proto._setWidth);
86 | cc.defineGetterSetter(_proto, "height", _proto._getHeight, _proto._setHeight);
87 | cc.defineGetterSetter(_proto, "direction", _proto.getDirection, _proto.setDirection);
88 |
89 | _proto = cc.ControlStepper.prototype;
90 | cc.defineGetterSetter(_proto, "wraps", _proto.getWraps, _proto.setWraps);
91 | cc.defineGetterSetter(_proto, "value", _proto.getValue, _proto.setValue);
92 | cc.defineGetterSetter(_proto, "minValue", _proto.getMinimumValue, _proto.setMinimumValue);
93 | cc.defineGetterSetter(_proto, "maxValue", _proto.getMaximumValue, _proto.setMaximumValue);
94 | cc.defineGetterSetter(_proto, "stepValue", _proto.getStepValue, _proto.setStepValue);
95 | cc.defineGetterSetter(_proto, "continuous", _proto.isContinuous);
96 | cc.defineGetterSetter(_proto, "minusSprite", _proto.getMinusSprite, _proto.setMinusSprite);
97 | cc.defineGetterSetter(_proto, "plusSprite", _proto.getPlusSprite, _proto.setPlusSprite);
98 | cc.defineGetterSetter(_proto, "minusLabel", _proto.getMinusLabel, _proto.setMinusLabel);
99 | cc.defineGetterSetter(_proto, "plusSLabel", _proto.getPlusSLabel, _proto.setPlusSLabel);
100 |
101 | _proto = cc.TableViewCell.prototype;
102 | cc.defineGetterSetter(_proto, "objectId", _proto.getObjectID, _proto.setObjectID);
103 |
--------------------------------------------------------------------------------
/script/ccui/jsb_ccui_create_apis.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Chukong Technologies Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 |
23 | ccui.Widget.prototype.init = ccui.Widget.prototype._init;
24 | ccui.RichText.prototype.init = function(){
25 | ccui.Widget.prototype.init.call(this);
26 | };
27 | ccui.Slider.prototype.init = function(){
28 | ccui.Widget.prototype.init.call(this);
29 | this.setTouchEnabled(true);
30 | };
31 |
32 | ccui.Widget.prototype._ctor
33 | = ccui.RichText.prototype._ctor
34 | = ccui.Slider.prototype._ctor
35 | = ccui.Layout.prototype._ctor
36 | = ccui.ListView.prototype._ctor
37 | = ccui.PageView.prototype._ctor
38 | = ccui.ScrollView.prototype._ctor
39 | = function(){
40 | this.init();
41 | }
42 |
43 | ccui.Button.prototype._ctor = function (normalImage, selectedImage, disableImage, texType) {
44 | if(texType !== undefined)
45 | ccui.Button.prototype.init.call(this, normalImage, selectedImage, disableImage, texType);
46 | else if(disableImage !== undefined)
47 | ccui.Button.prototype.init.call(this, normalImage, selectedImage, disableImage);
48 | else if(selectedImage !== undefined)
49 | ccui.Button.prototype.init.call(this, normalImage, selectedImage);
50 | else if(normalImage !== undefined)
51 | ccui.Button.prototype.init.call(this, normalImage);
52 | else
53 | ccui.Widget.prototype.init.call(this);
54 |
55 | this.setTouchEnabled(true);
56 | };
57 |
58 | ccui.CheckBox.prototype._ctor = function (backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType) {
59 | if (frontCrossDisabled !== undefined) {
60 | texType = texType || ccui.Widget.LOCAL_TEXTURE;
61 | ccui.CheckBox.prototype.init.call(this, backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType);
62 | }else if(backGroundSelected !== undefined){
63 | texType = ccui.Widget.LOCAL_TEXTURE;
64 | cross = backGroundSelected;
65 | backGroundSelected = backGroundDisabled = frontCrossDisabled = backGround;
66 | ccui.CheckBox.prototype.init.call(this, backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType);
67 | }
68 | else {
69 | ccui.Widget.prototype.init.call(this);
70 | }
71 |
72 | this.setSelected(false);
73 | this.setTouchEnabled(true);
74 | };
75 |
76 | ccui.ImageView.prototype._ctor = function(imageFileName, texType){
77 | if(imageFileName !== undefined){
78 | texType = texType || ccui.Widget.LOCAL_TEXTURE;
79 | ccui.ImageView.prototype._init.call(this, imageFileName, texType);
80 | }
81 | else
82 | ccui.Widget.prototype.init.call(this);
83 | }
84 |
85 | ccui.LoadingBar.prototype._ctor = function(textureName, percentage){
86 | ccui.Widget.prototype.init.call(this);
87 |
88 | if(textureName !== undefined)
89 | this.loadTexture(textureName);
90 | if(percentage !== undefined)
91 | this.setPercent(percentage);
92 | };
93 |
94 | ccui.TextAtlas.prototype._ctor = function(stringValue, charMapFile, itemWidth, itemHeight, startCharMap){
95 | ccui.Widget.prototype.init.call(this);
96 | startCharMap !== undefined && this.setProperty(stringValue, charMapFile, itemWidth, itemHeight, startCharMap);
97 | };
98 |
99 | ccui.Text.prototype._ctor = function(textContent, fontName, fontSize){
100 | if(fontSize !== undefined)
101 | ccui.Text.prototype.init.call(this, textContent, fontName, fontSize);
102 | else
103 | ccui.Widget.prototype.init.call(this);
104 | };
105 |
106 | ccui.TextBMFont.prototype._ctor = function(text, filename){
107 | ccui.Widget.prototype.init.call(this);
108 |
109 | if(filename !== undefined){
110 | this.setFntFile(filename);
111 | this.setString(text);
112 | }
113 | };
114 |
115 | ccui.TextField.prototype._ctor = function(placeholder, fontName, fontSize){
116 | ccui.Widget.prototype.init.call(this);
117 | this.setTouchEnabled(true);
118 |
119 | if (placeholder !== undefined)
120 | this.setPlaceHolder(placeholder);
121 | if (fontName !== undefined)
122 | this.setFontName(fontName);
123 | if (fontSize !== undefined)
124 | this.setFontSize(fontSize);
125 | };
126 |
127 | ccui.RichElementText.prototype._ctor = function(tag, color, opacity, text, fontName, fontSize){
128 | fontSize !== undefined && this.init(tag, color, opacity, text, fontName, fontSize);
129 | };
130 |
131 | ccui.RichElementImage.prototype._ctor = function(tag, color, opacity, filePath){
132 | filePath !== undefined && this.init(tag, color, opacity, filePath);
133 | };
134 |
135 | ccui.RichElementCustomNode.prototype._ctor = function(tag, color, opacity, customNode){
136 | customNode !== undefined && this.init(tag, color, opacity, customNode);
137 | };
138 |
139 | cc.Scale9Sprite.prototype._ctor = function(file, rect, capInsets){
140 | rect = rect || cc.rect(0, 0, 0, 0);
141 | capInsets = capInsets || cc.rect(0, 0, 0, 0);
142 | if(file != undefined){
143 | if(file instanceof cc.SpriteFrame)
144 | this.initWithSpriteFrame(file, rect);
145 | else{
146 | var frame = cc.spriteFrameCache.getSpriteFrame(file);
147 | if(frame != null)
148 | this.initWithSpriteFrame(frame, rect);
149 | else
150 | this.initWithFile(file, rect, capInsets);
151 | }
152 | }else{
153 | this.init();
154 | }
155 | };
156 |
157 | cc.EditBox.prototype._ctor = function(size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg){
158 | normal9SpriteBg && this.initWithSizeAndBackgroundSprite(size, normal9SpriteBg);
159 | };
160 |
--------------------------------------------------------------------------------
/manual/js_bindings_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012 Zynga Inc.
3 | * Copyright (c) 2013-2014 Chukong Technologies Inc.
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 |
24 |
25 | #ifndef __JS_BINDINGS_CONFIG_H
26 | #define __JS_BINDINGS_CONFIG_H
27 |
28 |
29 | /** @def JSB_ASSERT_ON_FAIL
30 | Whether or not to assert when the arguments or conversions are incorrect.
31 | It is recommened to turn it off in Release mode.
32 | */
33 | #ifndef JSB_ASSERT_ON_FAIL
34 | #define JSB_ASSERT_ON_FAIL 0
35 | #endif
36 |
37 |
38 | #if JSB_ASSERT_ON_FAIL
39 | #define JSB_PRECONDITION( condition, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
40 | #define JSB_PRECONDITION2( condition, context, ret_value, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
41 | #define ASSERT( condition, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
42 |
43 | #else
44 | #define JSB_PRECONDITION( condition, ...) do { \
45 | if( ! (condition) ) { \
46 | cocos2d::log("jsb: ERROR: File %s: Line: %d, Function: %s", __FILE__, __LINE__, __FUNCTION__ ); \
47 | cocos2d::log(__VA_ARGS__); \
48 | JSContext* globalContext = ScriptingCore::getInstance()->getGlobalContext(); \
49 | if( ! JS_IsExceptionPending( globalContext ) ) { \
50 | JS_ReportError( globalContext, __VA_ARGS__ ); \
51 | } \
52 | return false; \
53 | } \
54 | } while(0)
55 | #define JSB_PRECONDITION2( condition, context, ret_value, ...) do { \
56 | if( ! (condition) ) { \
57 | cocos2d::log("jsb: ERROR: File %s: Line: %d, Function: %s", __FILE__, __LINE__, __FUNCTION__ ); \
58 | cocos2d::log(__VA_ARGS__); \
59 | if( ! JS_IsExceptionPending( context ) ) { \
60 | JS_ReportError( context, __VA_ARGS__ ); \
61 | } \
62 | return ret_value; \
63 | } \
64 | } while(0)
65 | #define ASSERT( condition, error_msg) do { \
66 | if( ! (condition) ) { \
67 | CCLOG("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \
68 | return false; \
69 | } \
70 | } while(0)
71 | #endif
72 |
73 | #define JSB_PRECONDITION3( condition, context, ret_value, ...) do { \
74 | if( ! (condition) ) return (ret_value); \
75 | } while(0)
76 |
77 |
78 | /** @def JSB_REPRESENT_LONGLONG_AS_STR
79 | When JSB_REPRESENT_LONGLONG_AS_STR is defined, the long long will be represented as JS strings.
80 | Otherwise they will be represented as an array of two intengers.
81 | It is needed to to use an special representation since there are no 64-bit integers in JS.
82 | Representing the long long as string could be a bit slower, but it is easier to debug from JS.
83 | Enabled by default.
84 | */
85 | #ifndef JSB_REPRESENT_LONGLONG_AS_STR
86 | #define JSB_REPRESENT_LONGLONG_AS_STR 1
87 | #endif // JSB_REPRESENT_LONGLONG_AS_STR
88 |
89 |
90 | /** @def JSB_INCLUDE_CHIPMUNK
91 | Whether or not it should include JS bindings for Chipmunk
92 | */
93 | #ifndef JSB_INCLUDE_CHIPMUNK
94 | #define JSB_INCLUDE_CHIPMUNK 1
95 | #endif // JSB_INCLUDE_CHIPMUNK
96 |
97 |
98 | /** @def JSB_INCLUDE_COCOSBUILDERREADER
99 | Whether or not it should include JS bindings for CocosBuilder Reader
100 | */
101 | #ifndef JSB_INCLUDE_COCOSBUILDERREADER
102 | #define JSB_INCLUDE_COCOSBUILDERREADER 1
103 | #endif // JSB_INCLUDE_COCOSBUILDERREADER
104 |
105 | /** @def JSB_INCLUDE_COCOSDENSHION
106 | Whether or not it should include bindings for CocosDenshion (sound engine)
107 | */
108 | #ifndef JSB_INCLUDE_COCOSDENSHION
109 | #define JSB_INCLUDE_COCOSDENSHION 1
110 | #endif // JSB_INCLUDE_COCOSDENSHION
111 |
112 | #if JSB_ENABLE_DEBUGGER
113 | #define JSB_ENSURE_AUTOCOMPARTMENT(cx, obj) \
114 | JSAutoCompartment ac(cx, obj)
115 | #else
116 | #define JSB_ENSURE_AUTOCOMPARTMENT(cx, obj)
117 | #endif
118 |
119 | #define JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET \
120 | JSAutoCompartment __jsb_ac(ScriptingCore::getInstance()->getGlobalContext(), ScriptingCore::getInstance()->getGlobalObject());
121 |
122 |
123 | /** @def JSB_INCLUDE_SYSTEM
124 | Whether or not it should include bindings for system components like LocalStorage
125 | */
126 | #ifndef JSB_INCLUDE_SYSTEM
127 | #define JSB_INCLUDE_SYSTEM 1
128 | #endif // JSB_INCLUDE_SYSTEM
129 |
130 | /** @def JSB_INCLUDE_OPENGL
131 | Whether or not it should include bindings for WebGL / OpenGL ES 2.0
132 | */
133 | #ifndef JSB_INCLUDE_OPENGL
134 | #define JSB_INCLUDE_OPENGL 1
135 | #endif // JSB_INCLUDE_OPENGL
136 |
137 | /** @def JSB_INCLUDE_XMLHTTP
138 | Whether or not it should include bindings for XmlHttpRequest
139 | */
140 | #ifndef JSB_INCLUDE_XMLHTTP
141 | #define JSB_INCLUDE_XMLHTTP 1
142 | #endif // JSB_INCLUDE_XMLHTTP
143 |
144 | #ifndef JSB_MAX_STACK_QUOTA
145 | #define JSB_MAX_STACK_QUOTA 500000
146 | #endif // JSB_MAX_STACK_QUOTA
147 |
148 | #endif // __JS_BINDINGS_CONFIG_H
149 |
--------------------------------------------------------------------------------
/script/jsb_loaders.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Chukong Technologies Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 |
23 | //
24 | // cocos2d loader plugins.
25 | //
26 | // This helper file should be required after jsb_cocos2d.js
27 | //
28 |
29 | cc._emptyLoader = {
30 | load : function(realUrl, url){
31 | return null;
32 | }
33 | };
34 |
35 | cc.loader.register([
36 | "mp3", "ogg", "wav", "mp4", "m4a",
37 | "font", "eot", "ttf", "woff", "svg"
38 | ],
39 | cc._emptyLoader);
40 |
41 | cc._txtLoader = {
42 | load : function(realUrl, url){
43 | return jsb.fileUtils.getStringFromFile(realUrl);
44 | }
45 | };
46 | cc.loader.register(["txt", "xml", "vsh", "fsh", "tmx", "tsx"], cc._txtLoader);
47 |
48 | cc._jsonLoader = {
49 | load : function(realUrl, url){
50 | var data = jsb.fileUtils.getStringFromFile(realUrl);
51 | try{
52 | return JSON.parse(data);
53 | }catch(e){
54 | cc.error(e);
55 | return null;
56 | }
57 | }
58 | };
59 | cc.loader.register(["json", "ExportJson"], cc._jsonLoader);
60 |
61 | cc._imgLoader = {
62 | load : function(realUrl, url, res, cb){
63 | cc.loader.loadImg(realUrl, function(err, img){
64 | if(err) {
65 | cb && cb(err);
66 | return;
67 | }
68 | cc.loader.cache[url] = img;
69 | cb && cb(null, img);
70 | });
71 | }
72 | };
73 | cc.loader.register(["png", "jpg", "bmp","jpeg","gif"], cc._imgLoader);
74 |
75 | cc._plistLoader = {
76 | load : function(realUrl, url){
77 | var content = jsb.fileUtils.getStringFromFile(realUrl);
78 | return cc.plistParser.parse(content);
79 | }
80 | };
81 | cc.loader.register(["plist"], cc._plistLoader);
82 |
83 | cc._binaryLoader = {
84 | load : function(realUrl, url){
85 | return cc.loader.loadBinarySync(realUrl);
86 | }
87 | };
88 | cc.loader.register(["ccbi"], cc._binaryLoader);
89 |
90 |
91 | cc._fntLoader = {
92 | INFO_EXP : /info [^\n]*(\n|$)/gi,
93 | COMMON_EXP : /common [^\n]*(\n|$)/gi,
94 | PAGE_EXP : /page [^\n]*(\n|$)/gi,
95 | CHAR_EXP : /char [^\n]*(\n|$)/gi,
96 | KERNING_EXP : /kerning [^\n]*(\n|$)/gi,
97 | ITEM_EXP : /\w+=[^ \r\n]+/gi,
98 | INT_EXP : /^[\-]?\d+$/,
99 |
100 | _parseStrToObj : function(str){
101 | var arr = str.match(this.ITEM_EXP);
102 | var obj = {};
103 | if(arr){
104 | for(var i = 0, li = arr.length; i < li; i++){
105 | var tempStr = arr[i];
106 | var index = tempStr.indexOf("=");
107 | var key = tempStr.substring(0, index);
108 | var value = tempStr.substring(index + 1);
109 | if(value.match(this.INT_EXP)) value = parseInt(value);
110 | else if(value[0] == '"') value = value.substring(1, value.length - 1);
111 | obj[key] = value;
112 | }
113 | }
114 | return obj;
115 | },
116 | parseFnt : function(fntStr, url){
117 | var self = this, fnt = {};
118 | //padding
119 | var infoObj = self._parseStrToObj(fntStr.match(self.INFO_EXP)[0]);
120 | var paddingArr = infoObj["padding"].split(",");
121 | var padding = {
122 | left : parseInt(paddingArr[0]),
123 | top : parseInt(paddingArr[1]),
124 | right : parseInt(paddingArr[2]),
125 | bottom : parseInt(paddingArr[3])
126 | };
127 |
128 | //common
129 | var commonObj = self._parseStrToObj(fntStr.match(self.COMMON_EXP)[0]);
130 | fnt.commonHeight = commonObj["lineHeight"];
131 | if (cc._renderType === cc._RENDER_TYPE_WEBGL) {
132 | var texSize = cc.configuration.getMaxTextureSize();
133 | if(commonObj["scaleW"] > texSize.width || commonObj["scaleH"] > texSize.height)
134 | cc.log("cc.LabelBMFont._parseCommonArguments(): page can't be larger than supported");
135 | }
136 | if(commonObj["pages"] !== 1) cc.log("cc.LabelBMFont._parseCommonArguments(): only supports 1 page");
137 |
138 | //page
139 | var pageObj = self._parseStrToObj(fntStr.match(self.PAGE_EXP)[0]);
140 | if(pageObj["id"] !== 0) cc.log("cc.LabelBMFont._parseImageFileName() : file could not be found");
141 | fnt.atlasName = cc.path.changeBasename(url, pageObj["file"]);
142 |
143 | //char
144 | var charLines = fntStr.match(self.CHAR_EXP);
145 | var fontDefDictionary = fnt.fontDefDictionary = {};
146 | for(var i = 0, li = charLines.length; i < li; i++){
147 | var charObj = self._parseStrToObj(charLines[i]);
148 | var charId = charObj["id"];
149 | fontDefDictionary[charId] = {
150 | rect : {x : charObj["x"], y : charObj["y"], width : charObj["width"], height : charObj["height"]},
151 | xOffset : charObj["xoffset"],
152 | yOffset : charObj["yoffset"],
153 | xAdvance : charObj["xadvance"]
154 | };
155 | }
156 |
157 | //kerning
158 | var kerningDict = fnt.kerningDict = {};
159 | var kerningLines = fntStr.match(self.KERNING_EXP);
160 | if(kerningLines){
161 | for(var i = 0, li = kerningLines.length; i < li; i++){
162 | var kerningObj = self._parseStrToObj(kerningLines[i]);
163 | kerningDict[(kerningObj["first"] << 16) | (kerningObj["second"] & 0xffff)] = kerningObj["amount"];
164 | }
165 | }
166 | return fnt;
167 | },
168 |
169 | load : function(realUrl, url){
170 | var data = jsb.fileUtils.getStringFromFile(realUrl);
171 | return this.parseFnt(data, url);
172 | }
173 | };
174 | cc.loader.register(["fnt"], cc._fntLoader);
175 |
--------------------------------------------------------------------------------
/script/jsb_debugger.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-2014 Chukong Technologies Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 |
23 | let promise = null;
24 | var globalDebuggee = null;
25 |
26 | var gTestGlobals = [];
27 |
28 |
29 | // A mock tab list, for use by tests. This simply presents each global in
30 | // gTestGlobals as a tab, and the list is fixed: it never calls its
31 | // onListChanged handler.
32 | //
33 | // As implemented now, we consult gTestGlobals when we're constructed, not
34 | // when we're iterated over, so tests have to add their globals before the
35 | // root actor is created.
36 | function TestTabList(aConnection) {
37 | this.conn = aConnection;
38 |
39 | // An array of actors for each global added with
40 | // DebuggerServer.addTestGlobal.
41 | this._tabActors = [];
42 |
43 | // A pool mapping those actors' names to the actors.
44 | this._tabActorPool = new ActorPool(aConnection);
45 |
46 | for (let global of gTestGlobals) {
47 | let actor = new TestTabActor(aConnection, global);
48 | actor.selected = false;
49 | this._tabActors.push(actor);
50 | this._tabActorPool.addActor(actor);
51 | }
52 | if (this._tabActors.length > 0) {
53 | this._tabActors[0].selected = true;
54 | }
55 |
56 | aConnection.addActorPool(this._tabActorPool);
57 | }
58 |
59 | TestTabList.prototype = {
60 | constructor: TestTabList,
61 | getList: function () {
62 | return promise.resolve([tabActor for (tabActor of this._tabActors)]);
63 | }
64 | };
65 |
66 | function createRootActor(aConnection)
67 | {
68 | let root = new RootActor(aConnection,
69 | { tabList: new TestTabList(aConnection) });
70 | root.applicationType = "xpcshell-tests";
71 | return root;
72 | }
73 |
74 | function TestTabActor(aConnection, aGlobal)
75 | {
76 | this.conn = aConnection;
77 | this._global = aGlobal;
78 | this._threadActor = new ThreadActor(this, this._global);
79 | this.conn.addActor(this._threadActor);
80 | this._attached = false;
81 | this._extraActors = {};
82 | }
83 |
84 | TestTabActor.prototype = {
85 | constructor: TestTabActor,
86 | actorPrefix: "TestTabActor",
87 |
88 | get window() {
89 | return { wrappedJSObject: this._global };
90 | },
91 |
92 | form: function() {
93 | let response = { actor: this.actorID, title: "Hello Cocos2d-X JSB", url: "http://cocos2d-x.org" };
94 |
95 | // Walk over tab actors added by extensions and add them to a new ActorPool.
96 | let actorPool = new ActorPool(this.conn);
97 | // this._createExtraActors(DebuggerServer.tabActorFactories, actorPool);
98 | if (!actorPool.isEmpty()) {
99 | this._tabActorPool = actorPool;
100 | this.conn.addActorPool(this._tabActorPool);
101 | }
102 |
103 | // this._appendExtraActors(response);
104 |
105 | return response;
106 | },
107 |
108 | onAttach: function(aRequest) {
109 | this._attached = true;
110 |
111 | let response = { type: "tabAttached", threadActor: this._threadActor.actorID };
112 | // this._appendExtraActors(response);
113 |
114 | return response;
115 | },
116 |
117 | onDetach: function(aRequest) {
118 | if (!this._attached) {
119 | return { "error":"wrongState" };
120 | }
121 | return { type: "detached" };
122 | },
123 |
124 | /* Support for DebuggerServer.addTabActor. */
125 | // _createExtraActors: CommonCreateExtraActors,
126 | // _appendExtraActors: CommonAppendExtraActors,
127 |
128 | // Hooks for use by TestTabActors.
129 | addToParentPool: function(aActor) {
130 | this.conn.addActor(aActor);
131 | },
132 |
133 | removeFromParentPool: function(aActor) {
134 | this.conn.removeActor(aActor);
135 | }
136 | };
137 |
138 | TestTabActor.prototype.requestTypes = {
139 | "attach": TestTabActor.prototype.onAttach,
140 | "detach": TestTabActor.prototype.onDetach
141 | };
142 |
143 | this.processInput = function (inputstr) {
144 | if (!inputstr) {
145 | return;
146 | }
147 |
148 | if (inputstr === "connected")
149 | {
150 | DebuggerServer.createRootActor = (conn => {
151 | return new RootActor(conn, { tabList: new TestTabList(conn) });
152 | });
153 | DebuggerServer.init(() => true);
154 | DebuggerServer.openListener(5086);
155 | if (debuggerServer && debuggerServer.onSocketAccepted)
156 | {
157 | var aTransport = {
158 | host: "127.0.0.1",
159 | port: 5086,
160 | openInputStream: function() {
161 | return {
162 | close: function(){}
163 | };
164 | },
165 | openOutputStream: function() {
166 | return {
167 | close: function(){},
168 | write: function(){},
169 | asyncWait: function(){}
170 | };
171 | },
172 | };
173 | debuggerServer.onSocketAccepted(null, aTransport);
174 | }
175 | return;
176 | }
177 |
178 | if (DebuggerServer && DebuggerServer._transport && DebuggerServer._transport.onDataAvailable)
179 | {
180 | DebuggerServer._transport.onDataAvailable(inputstr);
181 | }
182 | };
183 |
184 | this._prepareDebugger = function (global) {
185 |
186 | globalDebuggee = global;
187 | require = global.require;
188 | cc = global.cc;
189 |
190 | require('script/debugger/DevToolsUtils.js', "debug");
191 | require('script/debugger/core/promise.js', "debug");
192 | require('script/debugger/transport.js', "debug");
193 | require('script/debugger/actors/root.js', "debug");
194 | require('script/debugger/actors/script.js', "debug");
195 | require('script/debugger/main.js', "debug");
196 |
197 | promise = exports;
198 | //DebuggerServer.addTestGlobal = function(aGlobal) {
199 | gTestGlobals.push(global);
200 | //};
201 |
202 | };
203 |
204 |
--------------------------------------------------------------------------------
/script/debugger/DevToolsUtils.js:
--------------------------------------------------------------------------------
1 | /* This Source Code Form is subject to the terms of the Mozilla Public
2 | * License, v. 2.0. If a copy of the MPL was not distributed with this
3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 |
5 | "use strict";
6 |
7 | function utf16to8(str) {
8 | var out, i, len, c;
9 |
10 | out = "";
11 | len = str.length;
12 | for(i = 0; i < len; i++)
13 | {
14 | c = str.charCodeAt(i);
15 | if ((c >= 0x0001) && (c <= 0x007F))
16 | {
17 | out += str.charAt(i);
18 | }
19 | else if (c > 0x07FF)
20 | {
21 | out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
22 | out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
23 | out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
24 | }
25 | else
26 | {
27 | out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
28 | out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
29 | }
30 | }
31 | return out;
32 | }
33 |
34 | function utf8to16(str) {
35 | var out, i, len, c;
36 | var char2, char3;
37 |
38 | out = "";
39 | len = str.length;
40 | i = 0;
41 | while(i < len) { c = str.charCodeAt(i++); switch(c >> 4)
42 | {
43 | case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
44 | // 0xxxxxxx
45 | out += str.charAt(i-1);
46 | break;
47 | case 12: case 13:
48 | // 110x xxxx 10xx xxxx
49 | char2 = str.charCodeAt(i++);
50 | out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
51 | break;
52 | case 14:
53 | // 1110 xxxx 10xx xxxx 10xx xxxx
54 | char2 = str.charCodeAt(i++);
55 | char3 = str.charCodeAt(i++);
56 | out += String.fromCharCode(((c & 0x0F) << 12) |
57 | ((char2 & 0x3F) << 6) |
58 | ((char3 & 0x3F) << 0));
59 | break;
60 | }
61 | }
62 |
63 | return out;
64 | }
65 |
66 | var dump = function(msg) {
67 | log(msg);
68 | };
69 |
70 | /* General utilities used throughout devtools. */
71 |
72 | /**
73 | * Turn the error |aError| into a string, without fail.
74 | */
75 | this.safeErrorString = function safeErrorString(aError) {
76 | try {
77 | let errorString = aError.toString();
78 | if (typeof errorString === "string") {
79 | // Attempt to attach a stack to |errorString|. If it throws an error, or
80 | // isn't a string, don't use it.
81 | try {
82 | if (aError.stack) {
83 | let stack = aError.stack.toString();
84 | if (typeof stack === "string") {
85 | errorString += "\nStack: " + stack;
86 | }
87 | }
88 | } catch (ee) { }
89 |
90 | return errorString;
91 | }
92 | } catch (ee) { }
93 |
94 | return "";
95 | }
96 |
97 |
98 | /**
99 | * Report that |aWho| threw an exception, |aException|.
100 | */
101 | this.reportException = function reportException(aWho, aException) {
102 | let msg = aWho + " threw an exception: " + safeErrorString(aException);
103 |
104 | dump(msg + "\n");
105 |
106 | // if (Components.utils.reportError) {
107 | // /*
108 | // * Note that the xpcshell test harness registers an observer for
109 | // * console messages, so when we're running tests, this will cause
110 | // * the test to quit.
111 | // */
112 | // Components.utils.reportError(msg);
113 | // }
114 | }
115 |
116 | /**
117 | * Given a handler function that may throw, return an infallible handler
118 | * function that calls the fallible handler, and logs any exceptions it
119 | * throws.
120 | *
121 | * @param aHandler function
122 | * A handler function, which may throw.
123 | * @param aName string
124 | * A name for aHandler, for use in error messages. If omitted, we use
125 | * aHandler.name.
126 | *
127 | * (SpiderMonkey does generate good names for anonymous functions, but we
128 | * don't have a way to get at them from JavaScript at the moment.)
129 | */
130 | this.makeInfallible = function makeInfallible(aHandler, aName) {
131 | if (!aName)
132 | aName = aHandler.name;
133 |
134 | return function (/* arguments */) {
135 | try {
136 | return aHandler.apply(this, arguments);
137 | } catch (ex) {
138 | let who = "Handler function";
139 | if (aName) {
140 | who += " " + aName;
141 | }
142 | reportException(who, ex);
143 | }
144 | }
145 | }
146 |
147 | const executeSoon = aFn => {
148 | Services.tm.mainThread.dispatch({
149 | run: this.makeInfallible(aFn)
150 | }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
151 | }
152 |
153 | /**
154 | * Like Array.prototype.forEach, but doesn't cause jankiness when iterating over
155 | * very large arrays by yielding to the browser and continuing execution on the
156 | * next tick.
157 | *
158 | * @param Array aArray
159 | * The array being iterated over.
160 | * @param Function aFn
161 | * The function called on each item in the array.
162 | * @returns Promise
163 | * A promise that is resolved once the whole array has been iterated
164 | * over.
165 | */
166 | this.yieldingEach = function yieldingEach(aArray, aFn) {
167 | const deferred = promise.defer();
168 |
169 | let i = 0;
170 | let len = aArray.length;
171 |
172 | (function loop() {
173 | const start = Date.now();
174 |
175 | while (i < len) {
176 | // Don't block the main thread for longer than 16 ms at a time. To
177 | // maintain 60fps, you have to render every frame in at least 16ms; we
178 | // aren't including time spent in non-JS here, but this is Good
179 | // Enough(tm).
180 | if (Date.now() - start > 16) {
181 | executeSoon(loop);
182 | return;
183 | }
184 |
185 | try {
186 | aFn(aArray[i++]);
187 | } catch (e) {
188 | deferred.reject(e);
189 | return;
190 | }
191 | }
192 |
193 | deferred.resolve();
194 | }());
195 |
196 | return deferred.promise;
197 | }
198 |
199 |
200 | /**
201 | * Like XPCOMUtils.defineLazyGetter, but with a |this| sensitive getter that
202 | * allows the lazy getter to be defined on a prototype and work correctly with
203 | * instances.
204 | *
205 | * @param Object aObject
206 | * The prototype object to define the lazy getter on.
207 | * @param String aKey
208 | * The key to define the lazy getter on.
209 | * @param Function aCallback
210 | * The callback that will be called to determine the value. Will be
211 | * called with the |this| value of the current instance.
212 | */
213 | this.defineLazyPrototypeGetter =
214 | function defineLazyPrototypeGetter(aObject, aKey, aCallback) {
215 | Object.defineProperty(aObject, aKey, {
216 | configurable: true,
217 | get: function() {
218 | const value = aCallback.call(this);
219 |
220 | Object.defineProperty(this, aKey, {
221 | configurable: true,
222 | writable: true,
223 | value: value
224 | });
225 |
226 | return value;
227 | }
228 | });
229 | }
230 |
231 |
--------------------------------------------------------------------------------
/auto/jsb_cocos2dx_builder_auto.hpp:
--------------------------------------------------------------------------------
1 | #ifndef __cocos2dx_builder_h__
2 | #define __cocos2dx_builder_h__
3 |
4 | #include "jsapi.h"
5 | #include "jsfriendapi.h"
6 |
7 |
8 | extern JSClass *jsb_cocosbuilder_CCBAnimationManager_class;
9 | extern JSObject *jsb_cocosbuilder_CCBAnimationManager_prototype;
10 |
11 | bool js_cocos2dx_builder_CCBAnimationManager_constructor(JSContext *cx, uint32_t argc, jsval *vp);
12 | void js_cocos2dx_builder_CCBAnimationManager_finalize(JSContext *cx, JSObject *obj);
13 | void js_register_cocos2dx_builder_CCBAnimationManager(JSContext *cx, JS::HandleObject global);
14 | void register_all_cocos2dx_builder(JSContext* cx, JS::HandleObject obj);
15 | bool js_cocos2dx_builder_CCBAnimationManager_moveAnimationsFromNode(JSContext *cx, uint32_t argc, jsval *vp);
16 | bool js_cocos2dx_builder_CCBAnimationManager_setAutoPlaySequenceId(JSContext *cx, uint32_t argc, jsval *vp);
17 | bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNames(JSContext *cx, uint32_t argc, jsval *vp);
18 | bool js_cocos2dx_builder_CCBAnimationManager_actionForSoundChannel(JSContext *cx, uint32_t argc, jsval *vp);
19 | bool js_cocos2dx_builder_CCBAnimationManager_setBaseValue(JSContext *cx, uint32_t argc, jsval *vp);
20 | bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNodes(JSContext *cx, uint32_t argc, jsval *vp);
21 | bool js_cocos2dx_builder_CCBAnimationManager_getLastCompletedSequenceName(JSContext *cx, uint32_t argc, jsval *vp);
22 | bool js_cocos2dx_builder_CCBAnimationManager_setRootNode(JSContext *cx, uint32_t argc, jsval *vp);
23 | bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamedTweenDuration(JSContext *cx, uint32_t argc, jsval *vp);
24 | bool js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletName(JSContext *cx, uint32_t argc, jsval *vp);
25 | bool js_cocos2dx_builder_CCBAnimationManager_getRootContainerSize(JSContext *cx, uint32_t argc, jsval *vp);
26 | bool js_cocos2dx_builder_CCBAnimationManager_setDocumentControllerName(JSContext *cx, uint32_t argc, jsval *vp);
27 | bool js_cocos2dx_builder_CCBAnimationManager_setObject(JSContext *cx, uint32_t argc, jsval *vp);
28 | bool js_cocos2dx_builder_CCBAnimationManager_getContainerSize(JSContext *cx, uint32_t argc, jsval *vp);
29 | bool js_cocos2dx_builder_CCBAnimationManager_actionForCallbackChannel(JSContext *cx, uint32_t argc, jsval *vp);
30 | bool js_cocos2dx_builder_CCBAnimationManager_getDocumentOutletNames(JSContext *cx, uint32_t argc, jsval *vp);
31 | bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp);
32 | bool js_cocos2dx_builder_CCBAnimationManager_init(JSContext *cx, uint32_t argc, jsval *vp);
33 | bool js_cocos2dx_builder_CCBAnimationManager_getKeyframeCallbacks(JSContext *cx, uint32_t argc, jsval *vp);
34 | bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp);
35 | bool js_cocos2dx_builder_CCBAnimationManager_setRootContainerSize(JSContext *cx, uint32_t argc, jsval *vp);
36 | bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceIdTweenDuration(JSContext *cx, uint32_t argc, jsval *vp);
37 | bool js_cocos2dx_builder_CCBAnimationManager_getRunningSequenceName(JSContext *cx, uint32_t argc, jsval *vp);
38 | bool js_cocos2dx_builder_CCBAnimationManager_getAutoPlaySequenceId(JSContext *cx, uint32_t argc, jsval *vp);
39 | bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackName(JSContext *cx, uint32_t argc, jsval *vp);
40 | bool js_cocos2dx_builder_CCBAnimationManager_getRootNode(JSContext *cx, uint32_t argc, jsval *vp);
41 | bool js_cocos2dx_builder_CCBAnimationManager_addDocumentOutletNode(JSContext *cx, uint32_t argc, jsval *vp);
42 | bool js_cocos2dx_builder_CCBAnimationManager_setDelegate(JSContext *cx, uint32_t argc, jsval *vp);
43 | bool js_cocos2dx_builder_CCBAnimationManager_getSequenceDuration(JSContext *cx, uint32_t argc, jsval *vp);
44 | bool js_cocos2dx_builder_CCBAnimationManager_addDocumentCallbackNode(JSContext *cx, uint32_t argc, jsval *vp);
45 | bool js_cocos2dx_builder_CCBAnimationManager_runAnimationsForSequenceNamed(JSContext *cx, uint32_t argc, jsval *vp);
46 | bool js_cocos2dx_builder_CCBAnimationManager_getSequenceId(JSContext *cx, uint32_t argc, jsval *vp);
47 | bool js_cocos2dx_builder_CCBAnimationManager_setCallFunc(JSContext *cx, uint32_t argc, jsval *vp);
48 | bool js_cocos2dx_builder_CCBAnimationManager_getDocumentCallbackNodes(JSContext *cx, uint32_t argc, jsval *vp);
49 | bool js_cocos2dx_builder_CCBAnimationManager_setSequences(JSContext *cx, uint32_t argc, jsval *vp);
50 | bool js_cocos2dx_builder_CCBAnimationManager_debug(JSContext *cx, uint32_t argc, jsval *vp);
51 | bool js_cocos2dx_builder_CCBAnimationManager_getDocumentControllerName(JSContext *cx, uint32_t argc, jsval *vp);
52 | bool js_cocos2dx_builder_CCBAnimationManager_CCBAnimationManager(JSContext *cx, uint32_t argc, jsval *vp);
53 |
54 | extern JSClass *jsb_cocosbuilder_CCBReader_class;
55 | extern JSObject *jsb_cocosbuilder_CCBReader_prototype;
56 |
57 | bool js_cocos2dx_builder_CCBReader_constructor(JSContext *cx, uint32_t argc, jsval *vp);
58 | void js_cocos2dx_builder_CCBReader_finalize(JSContext *cx, JSObject *obj);
59 | void js_register_cocos2dx_builder_CCBReader(JSContext *cx, JS::HandleObject global);
60 | void register_all_cocos2dx_builder(JSContext* cx, JS::HandleObject obj);
61 | bool js_cocos2dx_builder_CCBReader_getAnimationManager(JSContext *cx, uint32_t argc, jsval *vp);
62 | bool js_cocos2dx_builder_CCBReader_setAnimationManager(JSContext *cx, uint32_t argc, jsval *vp);
63 | bool js_cocos2dx_builder_CCBReader_addOwnerOutletName(JSContext *cx, uint32_t argc, jsval *vp);
64 | bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNames(JSContext *cx, uint32_t argc, jsval *vp);
65 | bool js_cocos2dx_builder_CCBReader_addDocumentCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp);
66 | bool js_cocos2dx_builder_CCBReader_setCCBRootPath(JSContext *cx, uint32_t argc, jsval *vp);
67 | bool js_cocos2dx_builder_CCBReader_addOwnerOutletNode(JSContext *cx, uint32_t argc, jsval *vp);
68 | bool js_cocos2dx_builder_CCBReader_getOwnerCallbackNodes(JSContext *cx, uint32_t argc, jsval *vp);
69 | bool js_cocos2dx_builder_CCBReader_readSoundKeyframesForSeq(JSContext *cx, uint32_t argc, jsval *vp);
70 | bool js_cocos2dx_builder_CCBReader_getCCBRootPath(JSContext *cx, uint32_t argc, jsval *vp);
71 | bool js_cocos2dx_builder_CCBReader_getOwnerCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp);
72 | bool js_cocos2dx_builder_CCBReader_getOwnerOutletNodes(JSContext *cx, uint32_t argc, jsval *vp);
73 | bool js_cocos2dx_builder_CCBReader_readUTF8(JSContext *cx, uint32_t argc, jsval *vp);
74 | bool js_cocos2dx_builder_CCBReader_addOwnerCallbackControlEvents(JSContext *cx, uint32_t argc, jsval *vp);
75 | bool js_cocos2dx_builder_CCBReader_getOwnerOutletNames(JSContext *cx, uint32_t argc, jsval *vp);
76 | bool js_cocos2dx_builder_CCBReader_readCallbackKeyframesForSeq(JSContext *cx, uint32_t argc, jsval *vp);
77 | bool js_cocos2dx_builder_CCBReader_getAnimationManagersForNodes(JSContext *cx, uint32_t argc, jsval *vp);
78 | bool js_cocos2dx_builder_CCBReader_getNodesWithAnimationManagers(JSContext *cx, uint32_t argc, jsval *vp);
79 | bool js_cocos2dx_builder_CCBReader_setResolutionScale(JSContext *cx, uint32_t argc, jsval *vp);
80 | bool js_cocos2dx_builder_CCBReader_CCBReader(JSContext *cx, uint32_t argc, jsval *vp);
81 | #endif
82 |
83 |
--------------------------------------------------------------------------------