Пример #1
0
void handle_signal(int signal) 
{
	static int internal_state = 0;
	ScriptingCore* sc = ScriptingCore::getInstance();
	// should start everything back
	CCDirector* director = CCDirector::sharedDirector();
	if (director->getRunningScene()) 
	{
		director->popToRootScene();
	} 
	else
	{
		CCPoolManager::sharedPoolManager()->finalize();
		if (internal_state == 0) 
		{
			//sc->dumpRoot(NULL, 0, NULL);
			sc->start();
			internal_state = 1;
		} 
		else
		{
			sc->runScript("hello.js");
			internal_state = 0;
		}
	}
}
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if(!glview) {
		glview = GLView::createWithRect("TutorialCCJSYouTube", Rect(0,0,900,640));
		director->setOpenGLView(glview);
	}

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    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_system);
    sc->addRegisterCallback(JSB_register_opengl);
    
    sc->addRegisterCallback(register_all_cocos2dx_builder);
    sc->addRegisterCallback(register_CCBuilderReader);
    
	sc->addRegisterCallback(register_all_cocos2dx_ui);
	sc->addRegisterCallback(register_all_cocos2dx_ui_manual);
	sc->addRegisterCallback(register_all_cocos2dx_studio);
	sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
    
    sc->addRegisterCallback(register_all_cocos2dx_spine);
    sc->addRegisterCallback(register_all_cocos2dx_spine_manual);
    
    sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
    sc->addRegisterCallback(register_jsb_websocket);
	sc->addRegisterCallback(register_jsb_socketio);
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif
    sc->start();    
    sc->runScript("script/jsb_boot.js");
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
	ScriptEngineManager::getInstance()->setScriptEngine(engine);
	ScriptingCore::getInstance()->runScript("main.js");

    return true;
}
Пример #3
0
bool AppDelegate::applicationDidFinishLaunching()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    sdkbox::init("68ba9af98d6f860b716fea6ef1a014a1", "4b488fa2d50b35af");
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    sdkbox::init("32e4e540cd14b5d2a536ad99493873b6", "c80ea05e3d8d1917", "googleplay");
#endif
    
    // initialize director
    auto director = Director::getInstance();

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

#if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0)

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // for getIPAddress
    extern void setActivityPathForAndroid(const std::string &path);
    setActivityPathForAndroid("org/cocos2dx/javascript/AppActivity");
#endif

    auto runtimeEngine = RuntimeEngine::getInstance();
    auto jsRuntime = RuntimeJsImpl::create();
    runtimeEngine->addRuntime(jsRuntime, kRuntimeEngineJs);
    runtimeEngine->start();
    
    // js need special debug port
    if (runtimeEngine->getProjectConfig().getDebuggerType() != kCCRuntimeDebuggerNone)
    {
        jsRuntime->startWithDebugger();
    }
#else
   js_module_register();
    ScriptingCore* sc = ScriptingCore::getInstance();
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginIAPJS);
    sc->addRegisterCallback(register_all_PluginIAPJS_helper);
#endif
   sc->start();
   sc->runScript("script/jsb_boot.js");
   ScriptEngineProtocol *engine = ScriptingCore::getInstance();
   ScriptEngineManager::getInstance()->setScriptEngine(engine);
   ScriptingCore::getInstance()->runScript("main.js");
#endif

    return true;
}
Пример #4
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

#if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0)

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // for getIPAddress
    extern void setActivityPathForAndroid(const std::string &path);
    setActivityPathForAndroid("org/cocos2dx/javascript/AppActivity");
#endif

    auto runtimeEngine = RuntimeEngine::getInstance();
    auto jsRuntime = RuntimeJsImpl::create();
    runtimeEngine->addRuntime(jsRuntime, kRuntimeEngineJs);
    runtimeEngine->start();
    
    // js need special debug port
    if (runtimeEngine->getProjectConfig().getDebuggerType() != kCCRuntimeDebuggerNone)
    {
        jsRuntime->startWithDebugger();
    }
#else
    js_module_register();
    ScriptingCore* sc = ScriptingCore::getInstance();
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginAgeCheqJS);
    sc->addRegisterCallback(register_all_PluginAgeCheqJS_helper);
#endif
    sc->start();
    sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
//    sc->enableDebugger();
#endif
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript("main.js");
#endif

    return true;
}
Пример #5
0
void TSScriptJS::GetWebConfig(std::string& Adapter_Ip, int& Adapter_Port) 
{
    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->runScript("Config/Config.js");
    JSObject* pObj;    	
	jsval obj;
    JS_GetProperty(sc->getGlobalContext(),sc->getGlobalObject(),"IP", &obj); 
    JS_ValueToObject(sc->getGlobalContext(),obj,&pObj);
    jsval AdaptServerIP;  
    JS_GetProperty(sc->getGlobalContext(),pObj,"AdaptServerIP", &AdaptServerIP);  
    JSString* pS = JS_ValueToString(sc->getGlobalContext(), AdaptServerIP);  
    JSStringWrapper pW(pS);  
	Adapter_Ip = pW.get().c_str();
    TSLog("AdapteServer Ip = %s", pW.get().c_str()); 
    jsval ip_port;  
    JS_GetProperty(sc->getGlobalContext(),pObj,"AdaptServerPort", &ip_port);  
    JSString* pS_port = JS_ValueToString(sc->getGlobalContext(), ip_port);  
    JSStringWrapper pWs(pS_port); 
    Adapter_Port = atoi(pWs.get().c_str());	
    TSLog("AdapteServer Port = %s",pWs.get().c_str());
}
Пример #6
0
void startRuntime()
{
    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_FileUtils);
    sc->start();
    sc->runScript("script/jsb_boot.js");

    int debugPort = 5086; 
#if(CC_PLATFORM_MAC == CC_TARGET_PLATFORM || CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM)
        debugPort = ConfigParser::getInstance()->getDebugPort();
#endif
    sc->enableDebugger(debugPort);
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);

    auto scene = Scene::create();
    auto connectLayer = new ConnectWaitLayer();
    connectLayer->autorelease();
    auto director = Director::getInstance();
    scene->addChild(connectLayer);
    director->runWithScene(scene);
}
Пример #7
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        glview = cocos2d::GLViewImpl::create("hello_world");
#else
        glview = cocos2d::GLViewImpl::createWithRect("hello_world", Rect(0,0,900,640));
#endif
        director->setOpenGLView(glview);
    }
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    js_module_register();
    
    ScriptingCore* sc = ScriptingCore::getInstance();
#ifdef SDKBOX_ENABLED
    sc->addRegisterCallback(register_all_PluginIAPJS);
    sc->addRegisterCallback(register_all_PluginIAPJS_helper);
    sc->addRegisterCallback(register_all_PluginFacebookJS);
    sc->addRegisterCallback(register_all_PluginFacebookJS_helper);
#endif
    sc->start();
    sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
    sc->enableDebugger();
#endif
    ScriptEngineManager::getInstance()->setScriptEngine(sc);
    ScriptingCore::getInstance()->runScript("main.js");
    
    return true;
}
Пример #8
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        glview = cocos2d::GLViewImpl::create("js-tests");
#else
        glview = cocos2d::GLViewImpl::createWithRect("js-tests", Rect(0,0,900,640));
#endif
        director->setOpenGLView(glview);
    }

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_all_cocos2dx);
    sc->addRegisterCallback(register_cocos2dx_js_core);
    sc->addRegisterCallback(jsb_register_system);
    
    sc->addRegisterCallback(register_all_cocos2dx_extension);
    sc->addRegisterCallback(register_all_cocos2dx_extension_manual);

    sc->addRegisterCallback(jsb_register_chipmunk);
    sc->addRegisterCallback(JSB_register_opengl);
    
    sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
    sc->addRegisterCallback(register_jsb_websocket);
	sc->addRegisterCallback(register_jsb_socketio);

    sc->addRegisterCallback(register_all_cocos2dx_builder);
    sc->addRegisterCallback(register_CCBuilderReader);

    sc->addRegisterCallback(register_all_cocos2dx_ui);
    sc->addRegisterCallback(register_all_cocos2dx_ui_manual);
    sc->addRegisterCallback(register_all_cocos2dx_studio);
    sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
    
    sc->addRegisterCallback(register_all_cocos2dx_spine);
    sc->addRegisterCallback(register_all_cocos2dx_spine_manual);

    sc->addRegisterCallback(register_all_cocos2dx_3d);
    sc->addRegisterCallback(register_all_cocos2dx_3d_manual);
    
    sc->addRegisterCallback(register_all_cocos2dx_3d_extension);
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif

    sc->addRegisterCallback(register_DrawNode3D_bindings);
#if(CC_TARGET_PLATFORM != CC_PLATFORM_WP8)
    sc->addRegisterCallback(register_Effect3D_bindings);
#endif

    sc->start();
    sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
    sc->enableDebugger();
#endif
    
    auto pEngine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
    
    ScriptingCore::getInstance()->runScript("main.js");
    
    return true;
}
Пример #9
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        glview = cocos2d::GLViewImpl::create("js");
#else
        glview = cocos2d::GLViewImpl::createWithRect("js", Rect(0,0,900,640));
#endif
        director->setOpenGLView(glview);
}

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_all_cocos2dx);
    sc->addRegisterCallback(register_cocos2dx_js_core);
    sc->addRegisterCallback(jsb_register_system);

    // extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_extension);
    sc->addRegisterCallback(register_all_cocos2dx_extension_manual);

    // chipmunk can be commented out to reduce the package
    sc->addRegisterCallback(jsb_register_chipmunk);
    // opengl can be commented out to reduce the package
    sc->addRegisterCallback(JSB_register_opengl);
    
    // builder can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_builder);
    sc->addRegisterCallback(register_CCBuilderReader);
    
    // ui can be commented out to reduce the package, attension studio need ui module
    sc->addRegisterCallback(register_all_cocos2dx_ui);
    sc->addRegisterCallback(register_all_cocos2dx_ui_manual);

    // studio can be commented out to reduce the package, 
    sc->addRegisterCallback(register_all_cocos2dx_studio);
    sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
    
    // spine can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_spine);
    sc->addRegisterCallback(register_all_cocos2dx_spine_manual);
    
    // XmlHttpRequest can be commented out to reduce the package
    sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
    // websocket can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_websocket);
    // sokcet io can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_socketio);

    // 3d can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d);
    sc->addRegisterCallback(register_all_cocos2dx_3d_manual);
    
    // 3d extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d_extension);
    sc->addRegisterCallback(register_all_PluginGoogleAnalyticsJS);
    
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
    // Physics 3d can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_physics3d);
    sc->addRegisterCallback(register_all_cocos2dx_physics3d_manual);
#endif

#if CC_USE_NAVMESH
    sc->addRegisterCallback(register_all_cocos2dx_navmesh);
    sc->addRegisterCallback(register_all_cocos2dx_navmesh_manual);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    sc->addRegisterCallback(register_all_cocos2dx_experimental_video);
    sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual);
    sc->addRegisterCallback(register_all_cocos2dx_experimental_webView);
    sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif
    sc->start();    
    sc->runScript("script/jsb_boot.js");
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript("main.js");

    return true;
}
Пример #10
0
static void register_js()
{
	ScriptingCore* sc = ScriptingCore::getInstance();
	sc->addRegisterCallback(register_all_cocos2dx);
	sc->addRegisterCallback(register_cocos2dx_js_core);
	sc->addRegisterCallback(jsb_register_system);

	// extension can be commented out to reduce the package
	sc->addRegisterCallback(register_all_cocos2dx_extension);
	sc->addRegisterCallback(register_all_cocos2dx_extension_manual);

	// chipmunk can be commented out to reduce the package
	/*sc->addRegisterCallback(jsb_register_chipmunk);
	// opengl can be commented out to reduce the package
	sc->addRegisterCallback(JSB_register_opengl);

	// builder can be commented out to reduce the package
	sc->addRegisterCallback(register_all_cocos2dx_builder);
	sc->addRegisterCallback(register_CCBuilderReader);*/

	// ui can be commented out to reduce the package, attension studio need ui module
	sc->addRegisterCallback(register_all_cocos2dx_ui);
	sc->addRegisterCallback(register_all_cocos2dx_ui_manual);
	
	// studio can be commented out to reduce the package,
	sc->addRegisterCallback(register_all_cocos2dx_studio);
	sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
	/*
	// spine can be commented out to reduce the package
	sc->addRegisterCallback(register_all_cocos2dx_spine);
	sc->addRegisterCallback(register_all_cocos2dx_spine_manual);
	/*
	// XmlHttpRequest can be commented out to reduce the package
	sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
	// websocket can be commented out to reduce the package
	sc->addRegisterCallback(register_jsb_websocket);
	// sokcet io can be commented out to reduce the package
	sc->addRegisterCallback(register_jsb_socketio);

	// 3d can be commented out to reduce the package
	sc->addRegisterCallback(register_all_cocos2dx_3d);
	sc->addRegisterCallback(register_all_cocos2dx_3d_manual);

	// 3d extension can be commented out to reduce the package
	sc->addRegisterCallback(register_all_cocos2dx_3d_extension);
	
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION
	// Physics 3d can be commented out to reduce the package
	sc->addRegisterCallback(register_all_cocos2dx_physics3d);
	sc->addRegisterCallback(register_all_cocos2dx_physics3d_manual);
#endif

#if CC_USE_NAVMESH
	sc->addRegisterCallback(register_all_cocos2dx_navmesh);
	sc->addRegisterCallback(register_all_cocos2dx_navmesh_manual);
#endif
	*/
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	sc->addRegisterCallback(register_all_cocos2dx_experimental_video);
	sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual);
	sc->addRegisterCallback(register_all_cocos2dx_experimental_webView);
	sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	sc->addRegisterCallback(register_all_cocos2dx_audioengine);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
	sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif

	// my api
	sc->addRegisterCallback(register_all_app);

	sc->start();
	sc->runScript("res/script/ccs/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
	sc->enableDebugger();
#endif
	

}
Пример #11
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    std::string writeAblePath=FileUtils::getInstance()->getWritablePath();
    FileUtils::getInstance()->addSearchPath(writeAblePath+"res",true);
    FileUtils::getInstance()->addSearchPath("res");
    
    CommonLib::initCommonLib();
    
    cocos2d::ui::Button::setDefaultSoundEffectFile("sound/ui/button_touch.mp3");
    cocos2d::ui::Button::setSoundEffectFunc([](const char* effectFile){
        CommonLib::playEffectSound(effectFile);
    });

    
#if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0)

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // for getIPAddress
    extern void setActivityPathForAndroid(const std::string &path);
    setActivityPathForAndroid("org/cocos2dx/javascript/AppActivity");
#endif
    
    auto runtimeEngine = RuntimeEngine::getInstance();
    auto jsRuntime = RuntimeJsImpl::create();
    runtimeEngine->addRuntime(jsRuntime, kRuntimeEngineJs);
    runtimeEngine->start();
    
    // js need special debug port
    if (runtimeEngine->getProjectConfig().getDebuggerType() != kCCRuntimeDebuggerNone)
    {
        jsRuntime->startWithDebugger();
    }
#else
    js_module_register();
    ScriptingCore* sc = ScriptingCore::getInstance();
//    CUpdateManager::getInstance();
    
    sc->exterScriptFunc=[](const char* scriptFile)->Data*{
        return getFileDataFromScriptZip(scriptFile);
    };
    
    auto enterGameFun=[=](int updateCBType){
        CCLOG("enterGameFun==========>>0");
        _isInit=true;
        _lastDayInteger=CommonLib::getTodayInteger();

        initJSBZip();
        
        sc->start();
        sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
        sc->enableDebugger();
#endif
        ScriptEngineProtocol *engine = ScriptingCore::getInstance();
        ScriptEngineManager::getInstance()->setScriptEngine(engine);
        ScriptingCore::getInstance()->runScript("src/main.js");
    };
    if(_lastDayInteger>0)
    {
        EntitySprite::clearAllRes();
        enterGameFun(0);
        return true;
    }
    
    auto glview = director->getOpenGLView();
    glview->setDesignResolutionSize(960,640, ResolutionPolicy::NO_BORDER);
    
    WelcomeScene* welcomeScene=WelcomeScene::create();
    Director::getInstance()->pushScene(welcomeScene);

    welcomeScene->addEventListener([=](){
        UpdateScene* updateScene=UpdateScene::create();
        Director::getInstance()->replaceScene(updateScene);
        updateScene->addEventListener(enterGameFun);
    });

#endif
    
    return true;
}
Пример #12
0
void TestLayer::testLogic(int testIndex)
{
    if (testIndex == 1)
    {
		if (m_bSpiderMonkeyInited) 
		{
			c_addLogToCLI(3, "[C++] %s", "Spidermonkey already inited!!!");
			return;
		}
        // init spidermonkey
        ScriptingCore* sc = ScriptingCore::getInstance();
        CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
        CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
        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_system);
        sc->addRegisterCallback(JSB_register_opengl);
        sc->start();
        if (!JS_DefineFunctions(sc->getGlobalContext(), sc->getGlobalObject(), myjs_global_functions)) {
            c_addLogToCLI(4, "[C++] JS_DefineFunctions Failed!!!");
            return;
        }
        sc->runScript("GlobalFuncTest.js");
        sc->runScript("SpriteFuncTest.js");
        m_bSpiderMonkeyInited = true;
		//c_addLogToCLI(1, "[C++] %s", "Spidermonkey init success");
        return;
    }
    if (!m_bSpiderMonkeyInited)
    {
		//c_addLogToCLI(4, "[C++] %s", "Init SpiderMonkey First!!!");
        return;
    }
    if (testIndex == 2)
    {
        // call JS function - 0 param, 0 return
        ScriptingCore* sc = ScriptingCore::getInstance();
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "MyLogFunc");
        c_addLogToCLI(1, "[C++] MyLogFunc called");
    }
    else if (testIndex == 3)
    {
        // call JS function - 1 param(Basic Type) , 1 return(Basic Type)
        ScriptingCore* sc = ScriptingCore::getInstance();
        jsval dataVal = INT_TO_JSVAL(10);
        jsval ret;
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "DubleIntFunc", 1, &dataVal, &ret);
        c_addLogToCLI(1, "[C++] DubleIntFunc called with result: %d", JSVAL_TO_INT(ret));
    }
    else if (testIndex == 4)
    {
        // call JS function - 0 param , 1 return(cocos2d Object)
        ScriptingCore* sc = ScriptingCore::getInstance();
        jsval ret;
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "SpawnIconSprite", 0, NULL, &ret);
		c_addLogToCLI(1, "[C++] SpawnIconSprite called");
        if(!JSVAL_IS_NULL(ret)) {
            JSObject *obj = JSVAL_TO_OBJECT(ret);
            js_proxy_t *proxy = jsb_get_js_proxy(obj);
            CCSprite *sprite = (CCSprite *)(proxy ? proxy->ptr : NULL);
            if (sprite) {
                this->addChild(sprite);
				c_addLogToCLI(1, "[C++] Add sprite from js to c++ layer");
            }
        }
    }
    else if (testIndex == 5 )
    {
        // call JS function - 1 param(cocos2d Object) , 0 return
        ScriptingCore* sc = ScriptingCore::getInstance();
        CCSprite *sprite = CCSprite::create("Icon.png");
        sprite->setPosition(ccp(CCRANDOM_0_1() * 1000, CCRANDOM_0_1() * 1000));
        this->addChild(sprite);
        js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCSprite>(sc->getGlobalContext(), sprite);
        jsval dataVal = OBJECT_TO_JSVAL(p->obj);
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "DoubleSpriteSize", 1, &dataVal, NULL);
		c_addLogToCLI(1, "[C++] Add sprite from js to layer");
    }
    else if (testIndex == 6)
    {
        // Bind Simple UI component to c++ CCScene
        ScriptingCore* sc = ScriptingCore::getInstance();
        sc->runScript("CircleLabelTTFTest.js");
		c_addLogToCLI(1, "[C++] %s", "Run CircleLabelTTFTest script");
		c_addLogToCLI(1, "[C++] %s", "Bind UI Component to CCSCene");
    }
    else if (testIndex == 7)
    {
        // Bind Complex UI component to c++ CCScene
        ScriptingCore* sc = ScriptingCore::getInstance();
        sc->runScript("CalendarTest.js");
		c_addLogToCLI(1, "[C++] %s", "Run CalendarTest script");
		c_addLogToCLI(1, "[C++] %s", "Bind UI Component to CCSCene");
    }
    else if (testIndex == 8)
    {
        // call JS function - N param(Mix) , 0 return
        ScriptingCore* sc = ScriptingCore::getInstance();
        js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCLayer>(sc->getGlobalContext(), this);
        jsval layerVal = OBJECT_TO_JSVAL(p->obj);
        
        jsval nowStringVal = c_string_to_jsval(sc->getGlobalContext(), "2013-7-27");
        jsval minYearVal = INT_TO_JSVAL(2010);
        jsval maxYearVal = INT_TO_JSVAL(2016);
        jsval args[4];
        args[0] = layerVal;
        args[1] = minYearVal;
        args[2] = maxYearVal;
        args[3] = nowStringVal;
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "AddCalendarToLayer", 4, args, NULL);
		c_addLogToCLI(1, "[C++] %s", "Bind Calendar UI to speicfied layer");
    }
    else if (testIndex == 9)
    {
        // call JS object function
        ScriptingCore* sc = ScriptingCore::getInstance();
        js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCLayer>(sc->getGlobalContext(), this);
        jsval layerVal = OBJECT_TO_JSVAL(p->obj);
        
        jsval stringVal = c_string_to_jsval(sc->getGlobalContext(), "center");
        
        CCArray *array = CCArray::create();
        array->addObject(CCInteger::create(111));
        array->addObject(CCInteger::create(222));
        array->addObject(CCInteger::create(333));
        array->addObject(CCInteger::create(444));
        array->addObject(CCInteger::create(555));
        array->addObject(CCInteger::create(666));
        array->addObject(CCInteger::create(777));
        array->addObject(CCInteger::create(888));
        jsval arrayVal = ccarray_to_jsval(sc->getGlobalContext(), array);
        jsval radiusVal = INT_TO_JSVAL(200);
        jsval args[4];
        args[0] = layerVal;
        args[1] = stringVal;
        args[2] = arrayVal;
        args[3] = radiusVal;
        jsval ret;
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "AddCircleTTFSpriteToLayer", 4, args, &ret);
		c_addLogToCLI(1, "[C++] %s", "Bind CircleTTF UI to speicfied layer");
        if(!JSVAL_IS_NULL(ret)) {
            sc->executeFunctionWithOwner(ret, "expandTTF", 0, NULL, NULL);
			c_addLogToCLI(1, "[C++] %s", "Call CircleTTF function expandTTF");
        }
    }
    else if (testIndex == 10)
    {
        // Bind UI Component (CLI)
        ScriptingCore* sc = ScriptingCore::getInstance();
        js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCLayer>(sc->getGlobalContext(), this);
        jsval layerVal = OBJECT_TO_JSVAL(p->obj);
        sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "BindCLILayerTo", 1, &layerVal, &g_cliJSValue);
		c_addLogToCLI(1, "[C++] %s", "Bind CLI Layer to current layer");
        m_bCLIBound = true;
    }
    else
    {
		c_addLogToCLI(4, "[C++] TEST NOT FOUND!!!");
    }
}
Пример #13
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        glview = cocos2d::GLViewImpl::create("ZjhMobile");
#else
        glview = cocos2d::GLViewImpl::createWithRect("ZjhMobile", Rect(0,0,900,640));
#endif
        director->setOpenGLView(glview);
}

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_all_cocos2dx);
    sc->addRegisterCallback(register_cocos2dx_js_core);
    sc->addRegisterCallback(jsb_register_system);

    // extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_extension);
    sc->addRegisterCallback(register_all_cocos2dx_extension_manual);

    // chipmunk can be commented out to reduce the package
    sc->addRegisterCallback(jsb_register_chipmunk);
    // opengl can be commented out to reduce the package
    sc->addRegisterCallback(JSB_register_opengl);
    
    // builder can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_builder);
    sc->addRegisterCallback(register_CCBuilderReader);
    
    // ui can be commented out to reduce the package, attension studio need ui module
    sc->addRegisterCallback(register_all_cocos2dx_ui);
    sc->addRegisterCallback(register_all_cocos2dx_ui_manual);

    // studio can be commented out to reduce the package, 
    sc->addRegisterCallback(register_all_cocos2dx_studio);
    sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
    
    // spine can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_spine);
    sc->addRegisterCallback(register_all_cocos2dx_spine_manual);
    
    // XmlHttpRequest can be commented out to reduce the package
    sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
    // websocket can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_websocket);
    // sokcet io can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_socketio);

    // 3d can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d);
    sc->addRegisterCallback(register_all_cocos2dx_3d_manual);
    
    // 3d extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d_extension);
    
    //my
    sc->addRegisterCallback(register_all_cocos2dx_nativehelper);
    
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif
    sc->start();    
    sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
    sc->enableDebugger();
#endif
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript("main.js");

    return true;
}
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        glview = cocos2d::GLViewImpl::create("CocosProtobuf");
#else
        glview = cocos2d::GLViewImpl::createWithRect("CocosProtobuf", Rect(0,0,960,640));
#endif
        director->setOpenGLView(glview);
}

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_all_cocos2dx);
    sc->addRegisterCallback(register_cocos2dx_js_core);
    
    sc->start();    
    sc->runScript("script/jsb_boot.js");
    
    ScriptEngineProtocol *engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript("main.js");
    
    
    // test send protobuf message from C++
    JSObject* pGlobalObject = ScriptingCore::getInstance()->getGlobalObject();
    JSContext* pGlobalContext = ScriptingCore::getInstance()->getGlobalContext();

    // Create a GameInfo object first
    game::info::GameInfo gameInfo;
    
    // add RoleInfo object to repeated field
    game::info::RoleInfo *pRoleInfo1 = gameInfo.add_roleinfo();
    pRoleInfo1->set_name("cpp_name1");
    pRoleInfo1->set_type(game::enumeration::FIGHTER);
    
    // add another RoleInfo object to repeated field
    game::info::RoleInfo *pRoleInfo2 = gameInfo.add_roleinfo();
    pRoleInfo2->set_name("cpp_name2");
    pRoleInfo2->set_type(game::enumeration::BOWMAN);
    
    // add ItemInfo object to repeated field
    game::info::ItemInfo *pItemInfo1 = gameInfo.add_iteminfo();
    pItemInfo1->set_name("cpp_item1");
    pItemInfo1->set_price(100);
    
    // add another ItemInfo object to repeated field
    game::info::ItemInfo *pItemInfo2 = gameInfo.add_iteminfo();
    pItemInfo2->set_name("cpp_item2");
    pItemInfo2->set_price(200);
    
    std::string gameInfoString;
    gameInfo.SerializeToString(&gameInfoString);
    
    // need this before JS_NewArrayBuffer
    JSAutoCompartment ac(pGlobalContext, pGlobalObject);
    int length = gameInfoString.length();
    JSObject* pMessageJSObject = JS_NewArrayBuffer(pGlobalContext, length);
    uint8_t* pMessageData = JS_GetArrayBufferData(pMessageJSObject);
    memcpy((void*)pMessageData, (const void*)gameInfoString.c_str(), gameInfoString.length());
    
    JS::RootedValue ret(pGlobalContext);
    jsval arg = OBJECT_TO_JSVAL(pMessageJSObject);
    ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(pGlobalObject), "test_protobuf", 1, &arg, &ret);
    
    //
    game::info::GameInfo* pGameInfo = new game::info::GameInfo;
    JSObject* pRetJSObject = ret.toObjectOrNull();
    if(pRetJSObject && JS_IsArrayBufferObject(pRetJSObject)) {
        uint8_t* pDataBuffer = nullptr;
        int dataBufferCount = 0;
        pDataBuffer = JS_GetArrayBufferData(pRetJSObject);
        dataBufferCount = JS_GetArrayBufferByteLength(pRetJSObject);
        pGameInfo->ParseFromArray(pDataBuffer, dataBufferCount);
        
        // RoleInfo Array
        for (int i = 0; i < pGameInfo->roleinfo_size(); i++) {
            // role info
            game::info::RoleInfo roleInfo = pGameInfo->roleinfo(i);
            CCLOG("roleInfo: \n%s\n", roleInfo.Utf8DebugString().c_str());
        }
        
        // ItemInfo Array
        for (int i = 0; i < pGameInfo->iteminfo_size(); i++) {
            // role info
            game::info::ItemInfo itemInfo = pGameInfo->iteminfo(i);
            CCLOG("itemInfo: \n%s\n", itemInfo.Utf8DebugString().c_str());
        }
    }
    return true;
}
Пример #15
0
bool AppDelegate::applicationDidFinishLaunching()
{
#if (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
    // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
    initRuntime();
#endif
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();    
    if(!glview) {
        Size viewSize = ConfigParser::getInstance()->getInitViewSize();
        string title = ConfigParser::getInstance()->getInitViewName();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) && (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
        extern void createSimulator(const char* viewName, float width, float height,bool isLandscape = true, float frameZoomFactor = 1.0f);
        bool isLanscape = ConfigParser::getInstance()->isLanscape();
        createSimulator(title.c_str(), viewSize.width,viewSize.height, isLanscape);
#else
        glview = cocos2d::GLViewImpl::createWithRect(title.c_str(), Rect(0, 0, viewSize.width, viewSize.height));
        director->setOpenGLView(glview);
#endif
    }

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    ScriptingCore* sc = ScriptingCore::getInstance();
    sc->addRegisterCallback(register_all_cocos2dx);
    sc->addRegisterCallback(register_cocos2dx_js_core);
    sc->addRegisterCallback(jsb_register_system);

    // extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_extension);
    sc->addRegisterCallback(register_all_cocos2dx_extension_manual);

    // chipmunk can be commented out to reduce the package
    sc->addRegisterCallback(jsb_register_chipmunk);
    // opengl can be commented out to reduce the package
    sc->addRegisterCallback(JSB_register_opengl);
    
    // builder can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_builder);
    sc->addRegisterCallback(register_CCBuilderReader);
    
    // ui can be commented out to reduce the package, attension studio need ui module
    sc->addRegisterCallback(register_all_cocos2dx_ui);
    sc->addRegisterCallback(register_all_cocos2dx_ui_manual);

    // studio can be commented out to reduce the package, 
    sc->addRegisterCallback(register_all_cocos2dx_studio);
    sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
    
    // spine can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_spine);
    sc->addRegisterCallback(register_all_cocos2dx_spine_manual);
    
    // XmlHttpRequest can be commented out to reduce the package
    sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
    // websocket can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_websocket);
    // sokcet io can be commented out to reduce the package
    sc->addRegisterCallback(register_jsb_socketio);
    
    // 3d can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d);
    sc->addRegisterCallback(register_all_cocos2dx_3d_manual);
    
    // 3d extension can be commented out to reduce the package
    sc->addRegisterCallback(register_all_cocos2dx_3d_extension);
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    sc->addRegisterCallback(JavascriptJavaBridge::_js_register);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS|| CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    sc->addRegisterCallback(JavaScriptObjCBridge::_js_register);
#endif
    
#if (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
    // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
    startRuntime();
#else
    sc->start();
    sc->runScript("script/jsb_boot.js");
    auto engine = ScriptingCore::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    ScriptingCore::getInstance()->runScript(ConfigParser::getInstance()->getEntryFile().c_str());
#endif
    
    return true;
}