Ejemplo n.º 1
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // register lua engine
    LuaEngine* pEngine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(pEngine);

    
    LuaStack* stack = pEngine->getLuaStack();
    stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA"));
    
    lua_State* L = stack->getLuaState();
    
    lua_module_register(L);

    lua_getglobal(L, "_G");
    if (lua_istable(L,-1))//stack:...,_G,
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
        register_assetsmanager_test_sample(L);
#endif
        register_test_binding(L);
    }
    lua_pop(L, 1);


    pEngine->executeScriptFile("src/controller.lua");

    return true;
}
void PlayerWin::loadLuaConfig()
{
    LuaEngine* pEngine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(pEngine);

    // load player lua core
    luaopen_PlayerLuaCore(pEngine->getLuaStack()->getLuaState());
    luaopen_PlayerLuaCore_Manual(pEngine->getLuaStack()->getLuaState());

    // set env
	string quickRootPath = _project.getQuickCocos2dxRootPath();
    quickRootPath = convertPathFormatToUnixStyle(quickRootPath);

    string env = "__G_QUICK_V3_ROOT__=\"";
    env.append(quickRootPath);
    env.append("\"");
    pEngine->executeString(env.c_str());

    // set user home dir
    lua_pushstring(pEngine->getLuaStack()->getLuaState(), getUserDocumentPath().c_str());
    lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__USER_HOME__");

    //
    // ugly: Add the opening project to the "Open Recents" list
    //
    lua_pushstring(pEngine->getLuaStack()->getLuaState(), _project.getProjectDir().c_str());
    lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__PLAYER_OPEN_TITLE__");

    lua_pushstring(pEngine->getLuaStack()->getLuaState(), _project.makeCommandLine().c_str());
    lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__PLAYER_OPEN_COMMAND__");

    // load player.lua
    string playerCoreFilePath = quickRootPath + "quick/welcome/src/player.lua";
    pEngine->executeScriptFile(playerCoreFilePath.c_str());
}
Ejemplo n.º 3
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto pDirector = Director::getInstance();
    pDirector->setOpenGLView(EGLView::getInstance());

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
    
    auto screenSize = EGLView::getInstance()->getFrameSize();
    
    auto designSize = Size(480, 320);
    
    auto pFileUtils = FileUtils::getInstance();
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        std::vector<std::string> searchPaths;
        searchPaths.push_back("hd");
        pFileUtils->setSearchPaths(searchPaths);
        pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
    }
    
    EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);
    
    // register lua engine
    LuaEngine* pEngine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    LuaStack* stack = pEngine->getLuaStack();
    register_assetsmanager_test_sample(stack->getLuaState());
#endif
    
    std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
    searchPaths.insert(searchPaths.begin(), "Images");
    searchPaths.insert(searchPaths.begin(), "cocosbuilderRes");
    if (screenSize.height > 320)
    {
        searchPaths.insert(searchPaths.begin(), "hd/scenetest/LoadSceneEdtiorFileTest");
    }
    else
    {
        searchPaths.insert(searchPaths.begin(), "scenetest/LoadSceneEdtiorFileTest");
    }

#if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
    searchPaths.push_back("TestCppResources");
    searchPaths.push_back("script");
#endif
    FileUtils::getInstance()->setSearchPaths(searchPaths);

    pEngine->executeScriptFile("luaScript/controller.lua");
    
    return true;
}
Ejemplo n.º 4
0
bool AppDelegate::applicationDidFinishLaunching() {
	// initialize director
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if (!glview) {
		glview = GLViewImpl::createWithRect("CocosWeb", Rect(0, 0, 6400, 9600));
		director->setOpenGLView(glview);
	}
#if ISTEST 
	director->getOpenGLView()->setFrameSize(320, 480);
#else
	director->getOpenGLView()->setFrameSize(glview->getVisibleRect().size.width, glview->getVisibleRect().size.height);
#endif
	director->getOpenGLView()->setDesignResolutionSize(640, 960, ResolutionPolicy::SHOW_ALL);

	// turn on display FPS
	director->setDisplayStats(true);

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


	LuaEngine* pEngine = LuaEngine::getInstance();
	ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
	lua_State* L = pEngine->getLuaStack()->getLuaState();
	lua_module_register(L);
#if ISTEST
	AllocConsole();
	HWND _hwndConsole = GetConsoleWindow();
	if (_hwndConsole != NULL)
	{
		ShowWindow(_hwndConsole, SW_SHOW);
		BringWindowToTop(_hwndConsole);
		freopen("CONOUT$", "wt", stdout);
		freopen("CONOUT$", "wt", stderr);

		HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE);
		if (hmenu != NULL)
		{
			DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
		}
	}
	pEngine->executeString("print=release_print");
	FileUtils::getInstance()->addSearchPath("../../Resources/res");
#else
	FileUtils::getInstance()->addSearchPath("res");
	FileUtils::getInstance()->addSearchPath("LuaScript");
	pEngine->getInstance()->addLuaLoader(decode_lua_loader);
#endif
	pEngine->executeScriptFile("main.lua");

	new GameInitiali();

	SceneManager::instance()->showScene("mainScene");
	return true;
}
Ejemplo n.º 5
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    Director *director = Director::getInstance();
    director->setOpenGLView(EGLView::getInstance());


    // turn on display FPS
    director->setDisplayStats(false);

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

    // register lua engine
    LuaEngine* engine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    
    std::string path = FileUtils::getInstance()->fullPathForFilename("Script/main.lua");
    engine->executeScriptFile(path.c_str());

    return true;
}
Ejemplo n.º 6
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    Director *pDirector = Director::sharedDirector();
    pDirector->setOpenGLView(EGLView::sharedOpenGLView());
    
    EGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder);

    // turn on display FPS
    pDirector->setDisplayStats(true);

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

    // register lua engine
    LuaEngine* pEngine = LuaEngine::defaultEngine();
    ScriptEngineManager::sharedManager()->setScriptEngine(pEngine);

    std::string path = FileUtils::sharedFileUtils()->fullPathForFilename("hello.lua");
    pEngine->executeScriptFile(path.c_str());

    return true;
}
Ejemplo n.º 7
0
bool AppDelegate::applicationDidFinishLaunching()
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
    if (_projectConfig.getDebuggerType() == kCCLuaDebuggerCodeIDE)
    {
        initRuntime(_projectConfig.getProjectDir());
        if (!ConfigParser::getInstance()->isInit())
        {
            ConfigParser::getInstance()->readConfig();
        }
    }
#endif //CC_TARGET_PLATFORM == CC_PLATFORM_MAC
    
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#else
        Size viewSize = _projectConfig.getFrameSize();
        glview = GLView::createWithRect("simpleui", Rect(0,0,viewSize.width,viewSize.height));
        director->setOpenGLView(glview);
#endif
    }
    
    // turn on display FPS
    director->setDisplayStats(true);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    // register lua engine
    LuaEngine* pEngine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
    
    LuaStack *pStack = pEngine->getLuaStack();
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // load framework
    pStack->loadChunksFromZIP("res/framework_precompiled.zip");
    
    // set script path
    string path = FileUtils::getInstance()->fullPathForFilename("src/main.lua");

#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    // load framework
    pStack->loadChunksFromZIP("res/framework_precompiled_wp8.zip");
    
    // set script path
    string path = FileUtils::getInstance()->fullPathForFilename("src/main.lua");
    
#else
    // load framework
    if (_projectConfig.isLoadPrecompiledFramework())
    {
        const string precompiledFrameworkPath = SimulatorConfig::getInstance()->getPrecompiledFrameworkPath();
        pStack->loadChunksFromZIP(precompiledFrameworkPath.c_str());
    }
    
    // set script path
    string path = FileUtils::getInstance()->fullPathForFilename(_projectConfig.getScriptFileRealPath().c_str());
#endif
    
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
    // Code IDE
    if (_projectConfig.getDebuggerType() == kCCLuaDebuggerCodeIDE)
    {
        if (startRuntime()) return true;
    }
#endif //CC_TARGET_PLATFORM == CC_PLATFORM_MAC
    
    size_t pos;
    while ((pos = path.find_first_of("\\")) != std::string::npos)
    {
        path.replace(pos, 1, "/");
    }
    size_t p = path.find_last_of("/\\");
    if (p != path.npos)
    {
        const string dir = path.substr(0, p);
        pStack->addSearchPath(dir.c_str());
        
        p = dir.find_last_of("/\\");
        if (p != dir.npos)
        {
            pStack->addSearchPath(dir.substr(0, p).c_str());
        }
    }
    
    string env = "__LUA_STARTUP_FILE__=\"";
    env.append(path);
    env.append("\"");
    pEngine->executeString(env.c_str());
    
    CCLOG("------------------------------------------------");
    CCLOG("LOAD LUA FILE: %s", path.c_str());
    CCLOG("------------------------------------------------");
    pEngine->executeScriptFile(path.c_str());

    return true;
}
Ejemplo n.º 8
0
bool AppDelegate::applicationDidFinishLaunching()
{
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::createWithRect("Test Lua", Rect(0,0,900,640));
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    auto screenSize = glview->getFrameSize();
    
    auto designSize = Size(480, 320);
    
    auto pFileUtils = FileUtils::getInstance();
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        std::vector<std::string> searchPaths;
        searchPaths.push_back("hd");
        pFileUtils->setSearchPaths(searchPaths);
        director->setContentScaleFactor(resourceSize.height/designSize.height);
    }
    
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);
    
    // register lua engine
    LuaEngine* pEngine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    LuaStack* stack = pEngine->getLuaStack();
    register_assetsmanager_test_sample(stack->getLuaState());
#endif
    
    std::string resPrefix("res/");
    
    std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
    searchPaths.insert(searchPaths.begin(), resPrefix);
    searchPaths.insert(searchPaths.begin(), resPrefix + "Images");
    searchPaths.insert(searchPaths.begin(), resPrefix + "cocosbuilderRes");
    if (screenSize.height > 320)
    {
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/Images");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/ArmatureComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/AttributeComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/BackgroundComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/EffectComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/ParticleComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/SpriteComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/TmxMapComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/UIComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/TriggerTest");
    }
    else
    {
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/ArmatureComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/AttributeComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/BackgroundComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/EffectComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/LoadSceneEdtiorFileTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/ParticleComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/SpriteComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/TmxMapComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/UIComponentTest");
        searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/TriggerTest");
    }


    FileUtils::getInstance()->setSearchPaths(searchPaths);

    pEngine->executeScriptFile("src/controller.lua");
    
    return true;
}