呼叫大量的 addRegisterCallback 函式,向 SpiderMonkey 註冊 Cocos2d-x 引擎的函式。
ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx);
sc->addRegisterCallback(register_all_cocos2dx_extension);
sc->addRegisterCallback(register_cocos2dx_js_extensions);
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
sc->addRegisterCallback(jsb_register_chipmunk);
sc->addRegisterCallback(JSB_register_opengl);
sc->addRegisterCallback(jsb_register_system);
sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
sc->addRegisterCallback(register_jsb_websocket);
sc->addRegisterCallback(register_all_cocos2dx_builder);
sc->addRegisterCallback(register_CCBuilderReader);
sc->addRegisterCallback(register_all_cocos2dx_gui);
sc->addRegisterCallback(register_all_cocos2dx_gui_manual);
sc->addRegisterCallback(register_all_cocos2dx_studio);
sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
sc->addRegisterCallback(register_all_cocos2dx_spine);
sc->start();
以 register_all_cocos2dx 註冊函式為例,跳轉到實現程式碼:
void register_all_cocos2dx(JSContext* cx, JSObject* obj) {
// first, try to get the ns
JS::RootedValue nsval(cx);
JSObject *ns;
JS_GetProperty(cx, obj, "cc", &nsval);
if (nsval == JSVAL_VOID) {
ns = JS_NewObject(cx, NULL, NULL, NULL);
nsval = OBJECT_TO_JSVAL(ns);
JS_SetProperty(cx, obj, "cc", nsval);
} else {
JS_ValueToObject(cx, nsval, &ns);
}
obj = ns;
js_register_cocos2dx_Action(cx, obj);
js_register_cocos2dx_FiniteTimeAction(cx, obj);
js_register_cocos2dx_ActionInstant(cx, obj);
js_register_cocos2dx_Hide(cx, obj);
js_register_cocos2dx_Node(cx, obj);
js_register_cocos2dx_Scene(cx, obj);
js_register_cocos2dx_TransitionScene(cx, obj);
js_register_cocos2dx_TransitionEaseScene(cx, obj);
js_register_cocos2dx_TransitionMoveInL(cx, obj);
js_register_cocos2dx_TransitionMoveInB(cx, obj);
js_register_cocos2dx_Layer(cx, obj);
js_register_cocos2dx___LayerRGBA(cx, obj);
js_register_cocos2dx_AtlasNode(cx, obj);
js_register_cocos2dx_TileMapAtlas(cx, obj);
js_register_cocos2dx_TransitionMoveInT(cx, obj);
js_register_cocos2dx_TransitionMoveInR(cx, obj);
js_register_cocos2dx_ParticleSystem(cx, obj);
js_register_cocos2dx_ParticleSystemQuad(cx, obj);
js_register_cocos2dx_ParticleSnow(cx, obj);
js_register_cocos2dx_ActionInterval(cx, obj);
js_register_cocos2dx_ActionCamera(cx, obj);
js_register_cocos2dx_ProgressFromTo(cx, obj);
js_register_cocos2dx_MoveBy(cx, obj);
js_register_cocos2dx_MoveTo(cx, obj);
js_register_cocos2dx_JumpBy(cx, obj);
js_register_cocos2dx_ActionEase(cx, obj);
js_register_cocos2dx_EaseBounce(cx, obj);
js_register_cocos2dx_EaseBounceIn(cx, obj);
js_register_cocos2dx_TransitionRotoZoom(cx, obj);
js_register_cocos2dx_Director(cx, obj);
js_register_cocos2dx_Texture2D(cx, obj);
js_register_cocos2dx_EaseElastic(cx, obj);
js_register_cocos2dx_EaseElasticOut(cx, obj);
js_register_cocos2dx_EaseBackOut(cx, obj);
js_register_cocos2dx_TransitionSceneOriented(cx, obj);
js_register_cocos2dx_TransitionFlipX(cx, obj);
js_register_cocos2dx_Spawn(cx, obj);
js_register_cocos2dx_SimpleAudioEngine(cx, obj);
js_register_cocos2dx_SkewTo(cx, obj);
js_register_cocos2dx_SkewBy(cx, obj);
js_register_cocos2dx_TransitionProgress(cx, obj);
js_register_cocos2dx_TransitionProgressVertical(cx, obj);
js_register_cocos2dx_TMXTiledMap(cx, obj);
js_register_cocos2dx_GridAction(cx, obj);
js_register_cocos2dx_Grid3DAction(cx, obj);
js_register_cocos2dx_FadeIn(cx, obj);
js_register_cocos2dx_AnimationCache(cx, obj);
js_register_cocos2dx_FlipX3D(cx, obj);
js_register_cocos2dx_FlipY3D(cx, obj);
js_register_cocos2dx_EaseSineInOut(cx, obj);
js_register_cocos2dx_TransitionFlipAngular(cx, obj);
js_register_cocos2dx_EGLViewProtocol(cx, obj);
js_register_cocos2dx_EGLView(cx, obj);
js_register_cocos2dx_EaseElasticInOut(cx, obj);
js_register_cocos2dx_Show(cx, obj);
js_register_cocos2dx_FadeOut(cx, obj);
js_register_cocos2dx_CallFunc(cx, obj);
js_register_cocos2dx_Waves3D(cx, obj);
js_register_cocos2dx_ParticleFireworks(cx, obj);
js_register_cocos2dx_MenuItem(cx, obj);
呼叫大量的 addRegisterCallback 函式,向 SpiderMonkey 註冊 Cocos2d-x 引擎的函式。
ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx);
sc->addRegisterCallback(register_all_cocos2dx_extension);
sc->addRegisterCallback(register_cocos2dx_js_extensions);
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
sc->addRegisterCallback(jsb_register_chipmunk);
sc->addRegisterCallback(JSB_register_opengl);
sc->addRegisterCallback(jsb_register_system);
sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
sc->addRegisterCallback(register_jsb_websocket);
sc->addRegisterCallback(register_all_cocos2dx_builder);
sc->addRegisterCallback(register_CCBuilderReader);
sc->addRegisterCallback(register_all_cocos2dx_gui);
sc->addRegisterCallback(register_all_cocos2dx_gui_manual);
sc->addRegisterCallback(register_all_cocos2dx_studio);
sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
sc->addRegisterCallback(register_all_cocos2dx_spine);
sc->start();
以 register_all_cocos2dx 註冊函式為例,跳轉到實現程式碼:
void register_all_cocos2dx(JSContext* cx, JSObject* obj) {
// first, try to get the ns
JS::RootedValue nsval(cx);
JSObject *ns;
JS_GetProperty(cx, obj, "cc", &nsval);
if (nsval == JSVAL_VOID) {
ns = JS_NewObject(cx, NULL, NULL, NULL);
nsval = OBJECT_TO_JSVAL(ns);
JS_SetProperty(cx, obj, "cc", nsval);
} else {
JS_ValueToObject(cx, nsval, &ns);
}
obj = ns;
js_register_cocos2dx_Action(cx, obj);
js_register_cocos2dx_FiniteTimeAction(cx, obj);
js_register_cocos2dx_ActionInstant(cx, obj);
js_register_cocos2dx_Hide(cx, obj);
js_register_cocos2dx_Node(cx, obj);
js_register_cocos2dx_Scene(cx, obj);
js_register_cocos2dx_TransitionScene(cx, obj);
js_register_cocos2dx_TransitionEaseScene(cx, obj);
js_register_cocos2dx_TransitionMoveInL(cx, obj);
js_register_cocos2dx_TransitionMoveInB(cx, obj);
js_register_cocos2dx_Layer(cx, obj);
js_register_cocos2dx___LayerRGBA(cx, obj);
js_register_cocos2dx_AtlasNode(cx, obj);
js_register_cocos2dx_TileMapAtlas(cx, obj);
js_register_cocos2dx_TransitionMoveInT(cx, obj);
js_register_cocos2dx_TransitionMoveInR(cx, obj);
js_register_cocos2dx_ParticleSystem(cx, obj);
js_register_cocos2dx_ParticleSystemQuad(cx, obj);
js_register_cocos2dx_ParticleSnow(cx, obj);
js_register_cocos2dx_ActionInterval(cx, obj);
js_register_cocos2dx_ActionCamera(cx, obj);
js_register_cocos2dx_ProgressFromTo(cx, obj);
js_register_cocos2dx_MoveBy(cx, obj);
js_register_cocos2dx_MoveTo(cx, obj);
js_register_cocos2dx_JumpBy(cx, obj);
js_register_cocos2dx_ActionEase(cx, obj);
js_register_cocos2dx_EaseBounce(cx, obj);
js_register_cocos2dx_EaseBounceIn(cx, obj);
js_register_cocos2dx_TransitionRotoZoom(cx, obj);
js_register_cocos2dx_Director(cx, obj);
js_register_cocos2dx_Texture2D(cx, obj);
js_register_cocos2dx_EaseElastic(cx, obj);
js_register_cocos2dx_EaseElasticOut(cx, obj);
js_register_cocos2dx_EaseBackOut(cx, obj);
js_register_cocos2dx_TransitionSceneOriented(cx, obj);
js_register_cocos2dx_TransitionFlipX(cx, obj);
js_register_cocos2dx_Spawn(cx, obj);
js_register_cocos2dx_SimpleAudioEngine(cx, obj);
js_register_cocos2dx_SkewTo(cx, obj);
js_register_cocos2dx_SkewBy(cx, obj);
js_register_cocos2dx_TransitionProgress(cx, obj);
js_register_cocos2dx_TransitionProgressVertical(cx, obj);
js_register_cocos2dx_TMXTiledMap(cx, obj);
js_register_cocos2dx_GridAction(cx, obj);
js_register_cocos2dx_Grid3DAction(cx, obj);
js_register_cocos2dx_FadeIn(cx, obj);
js_register_cocos2dx_AnimationCache(cx, obj);
js_register_cocos2dx_FlipX3D(cx, obj);
js_register_cocos2dx_FlipY3D(cx, obj);
js_register_cocos2dx_EaseSineInOut(cx, obj);
js_register_cocos2dx_TransitionFlipAngular(cx, obj);
js_register_cocos2dx_EGLViewProtocol(cx, obj);
js_register_cocos2dx_EGLView(cx, obj);
js_register_cocos2dx_EaseElasticInOut(cx, obj);
js_register_cocos2dx_Show(cx, obj);
js_register_cocos2dx_FadeOut(cx, obj);
js_register_cocos2dx_CallFunc(cx, obj);
js_register_cocos2dx_Waves3D(cx, obj);
js_register_cocos2dx_ParticleFireworks(cx, obj);
js_register_cocos2dx_MenuItem(cx, obj);