Ejemplo n.º 1
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.º 2
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;
}
Ejemplo n.º 3
0
/**
 * Create a new Lua engine instance.
 * Currently does no error checking (update
 * this comment if that is added).
 */
static int luaEngineCreate(lua_State *L)
{
	LuaEngine* engine = new LuaEngine();
	engine->initialize();
	lua_pushlightuserdata(L, engine);

	return 1; // Number of results
}
Ejemplo n.º 4
0
void MovieView::executeCallBack(int nHandle)
{
	LuaEngine* pEngine = LuaEngine::getInstance();
	LuaStack* pStack = pEngine->getLuaStack();

	int nRet = pStack->executeFunctionByHandler(nHandle, 0);
	pStack->clean();
}
Ejemplo n.º 5
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.º 6
0
bool BindLuaLogger(LuaEngine& lua)
{
    if(!lua.IsValid())
        return false;

    // Bind log function.
    Lua::getGlobalNamespace(lua.GetState())
        .addFunction("Log", LuaLog);

    return true;
}
Ejemplo n.º 7
0
void CNetDelegate::executeOnExceptionCaughtScriptHandler(CCSocketStatus eStatus)
{
	if (m_nExceptionCaughtScriptHandler != 0)
	{
		LuaEngine* pEngine = LuaEngine::getInstance();
		LuaStack* pStack = pEngine->getLuaStack();

		pStack->pushInt((int)eStatus);

		pStack->executeFunctionByHandler(m_nExceptionCaughtScriptHandler, 1);
		pStack->clean();
	}
}
Ejemplo n.º 8
0
void CNetDelegate::executeOnMessageReceivedScriptHandler(CBuffer *oBuffer)
{
	if (m_nMessageReceivedScriptHandler != 0)
	{
		LuaEngine* pEngine = LuaEngine::getInstance();
		LuaStack* pStack = pEngine->getLuaStack();

		pStack->pushObject(oBuffer, "CBuffer");

		pStack->executeFunctionByHandler(m_nMessageReceivedScriptHandler, 1);
		pStack->clean();
	}
}
Ejemplo n.º 9
0
void Scene::updateLua()
{
    LuaEngine* sceneLuaEngine = getLuaEngine();
    clearRenderFunctions();//Clean up last rendered stuff
    if(sceneLuaEngine)
    {
        if(sceneLuaEngine->isValid() && !sceneLuaEngine->shouldShutdown()){
            //sceneLuaEngine->runGarbageCollector();
            LuaEvent loopEvent = BindingCore_Events_Engine::createLoopEvent(sceneLuaEngine, uTickf);
            sceneLuaEngine->dispatchEvent(loopEvent);
        }
    }
}
Ejemplo n.º 10
0
void CCMsgDelegate::executeOnMessageScriptHandler(unsigned int uMsg, Ref* pMsgObj)
{
	if (m_nMessageScriptHandler != 0)
	{
		LuaEngine* pEngine = LuaEngine::getInstance();
		LuaStack* pStack = pEngine->getLuaStack();

		pStack->pushInt(uMsg);
		pStack->pushObject(pMsgObj, "Ref");

		pStack->executeFunctionByHandler(m_nMessageScriptHandler, 2);
		pStack->clean();
	}
}
Ejemplo n.º 11
0
bool AppDelegate::applicationDidFinishLaunching()
{
	auto theFileUtils = FileUtils::getInstance();
	auto paths = theFileUtils->getSearchPaths();

	auto rootDirectory = paths[0];

	// set working directory
#if defined(_WIN32)
	char buffer[512] = { 0 };
	_getcwd(buffer, sizeof(buffer));
	std::string workingDirectory = buffer;
	auto index = workingDirectory.find_last_of('\\');
	rootDirectory = workingDirectory.substr(0, index);
#endif

	paths.clear();
	paths.push_back(rootDirectory + "/data");
	paths.push_back(theFileUtils->getWritablePath());
	theFileUtils->setSearchPaths(paths);

    // register lua engine
    LuaEngine* engine = LuaEngine::getInstance();
	std::string scriptsPath = rootDirectory + "/scripts";
	engine->addSearchPath(scriptsPath.c_str());

    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    lua_State* L = engine->getLuaStack()->getLuaState();
    lua_module_register(L);

	for (auto& arg : args)
	{
		if (arg == "-debug")
		{
			engine->executeString("debugEnabled = true");
		}
	}

    engine->executeString("require 'main.lua'");

	setIcon();

    return true;
}
Ejemplo n.º 12
0
void ComponentLua::initClass()
{
    static bool run = true;
    if (run)
    {
        // LUA_REGISTRYINDEX["component"] = new table
        
        LuaEngine* engine = LuaEngine::getInstance();
        lua_State* l = engine->getLuaStack()->getLuaState();
        
        lua_pushstring(l, KEY_COMPONENT);              // stack: "component"
        lua_newtable(l);                               // stack: "component" table
        lua_rawset(l, LUA_REGISTRYINDEX);              // stack: -
        
        run = false;
    }
    
    
}
Ejemplo n.º 13
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QStackedWidget *stackedWidget = this->findChild<QStackedWidget *>(tr("stackedWidget"));
    if (stackedWidget)
    {
        stackedWidget->setCurrentIndex(0);
    }

    LuaEngine *pEngine = LuaEngine::getInstance();
    L = pEngine->getLuaStack()->getLuaState();

    tabWidget = this->findChild<QTabWidget *>(tr("tabWidget"));

    setValidator();
}
Ejemplo n.º 14
0
CSceneExtension* CSceneManager::loadScene(const char* pSceneName)
{
	CCAssert(pSceneName && strlen(pSceneName), "should not null");

	map<string, CSceneExtension*>::iterator mitr = m_mSceneCachePool.find(pSceneName);
	if( mitr != m_mSceneCachePool.end() )
	{
		return mitr->second;
	}
#if USING_LUA
	map<string,int>::iterator itr = m_mFnSceneCreateScriptFunc.find(pSceneName);
	if(itr!=m_mFnSceneCreateScriptFunc.end())
	{
		LuaEngine* pEngine = LuaEngine::getInstance();
		LuaStack* pStack = pEngine->getLuaStack();

		__Array pRetArray;
		pRetArray.initWithCapacity(1);

		int nRet = pStack->executeFunctionReturnArray(itr->second, 0, 1, pRetArray);
		CCAssert(pRetArray.count() > 0, "return num = 0");

		Ref* pReturnObject = pRetArray.getObjectAtIndex(0);
		pStack->clean();

		CSceneExtension* pSceneExt = dynamic_cast<CSceneExtension*>(pReturnObject);
		pSceneExt->setClassName(pSceneName);
		return pSceneExt;
	}
#else
	map<string, Fn_CreateSceneExtension>::iterator itr = m_mFnSceneCreatePointers.find(pSceneName);
	if( itr != m_mFnSceneCreatePointers.end() )
	{
		CSceneExtension* pScene = (*itr->second)();
		pScene->setClassName(pSceneName);
		pScene->init();
		pScene->autorelease();
		return pScene;
	}
#endif
	return NULL;
}
Ejemplo n.º 15
0
void CWidgetWindow::executeTouchCancelledAfterLongClickHandler(Ref* pSender, Touch *pTouch, float fDuration)
{
    if( m_pTouchCancelledAfterLongClickListener && m_pTouchCancelledAfterLongClickHandler )
    {
		(m_pTouchCancelledAfterLongClickListener->*m_pTouchCancelledAfterLongClickHandler)(pSender, pTouch, fDuration);
    }
#if USING_LUA
	else if( m_pTouchCancelledAfterLongClickScriptHandler != 0 )
	{
		LuaEngine* pEngine = LuaEngine::getInstance();
		LuaStack* pStack = pEngine->getLuaStack();

		pStack->pushObject(pSender, "Ref");
		pStack->pushObject(pTouch, "Touch");
		pStack->pushFloat(fDuration);

		int nRet = pStack->executeFunctionByHandler(m_pTouchCancelledAfterLongClickScriptHandler, 3);
		pStack->clean();
	}
#endif
}
static LuaStack * initExecParam(Node *node, int phase)
{
    if (!node) return nullptr;
    int  id = node->_luaID;
    if (id<1)
    {
        return nullptr;
    }
    
    LuaEngine* engine = LuaEngine::getInstance();
    auto stack = engine->getLuaStack();
    stack->clean();
    
    auto L = stack->getLuaState();
    luaL_getmetatable(L, "cc.Node");                             /* stack: mt */
    lua_pushliteral(L, "EventDispatcher");
    lua_rawget(L, -2);                                           /* stack: mt func */
    lua_pushstring(L, "tolua_ubox");                             /* stack: mt func key */
    lua_rawget(L, -3);                                           /* stack: mt func ubox */
    if (lua_isnil(L, -1))
    {
        // use global ubox
        lua_pop(L, 1);                                              /* stack: mt func */
        lua_pushstring(L, "tolua_ubox");                            /* stack: mt func key */
        lua_rawget(L, LUA_REGISTRYINDEX);                           /* stack: mt func ubox */
    };
    lua_pushlightuserdata(L, node);                                 /* stack: mt func ubox ptr */
    lua_rawget(L,-2);                                               /* stack: mt func ubox ud */
    if (lua_isnil(L, -1))
    {
        stack->clean();
        return nullptr;
    }
    
    int etype = (phase == NODE_TOUCH_CAPTURING_PHASE) ? NODE_TOUCH_CAPTURE_EVENT : NODE_TOUCH_EVENT;
    lua_pushnumber(L, etype);                                       /* stack: mt func ubox ud etype */
    lua_remove(L, -3);                                              /* stack: mt func ud etype */

    return stack;
}
Ejemplo n.º 17
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.º 18
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.º 19
0
/**
 * Evaluate Lua code.
 */
static int luaEngineEval(lua_State *L)
{
	// First param is pointer to the engine, it must not
	// be nil and must be light user data.
	if (!lua_isnoneornil(L, 1) && lua_islightuserdata(L, 1))
	{
		LuaEngine* engine = (LuaEngine*) lua_touserdata(L, 1);
		if (NULL != engine)
		{
			const char* code = luaL_checkstring(L, 2);
			int result = engine->eval(code);
			if (0 != result)
			{
				// Return true to Lua.
				lua_pushboolean(L, 1);
				return 1; // Number of results
			}
		}
	}

	// Return false to Lua.
	lua_pushboolean(L, 0);
	return 1; // Number of results
}
Ejemplo n.º 20
0
void LevelScene::update()
{
    if(m_luaEngine.shouldShutdown())
    {
        m_fader.setFade(10, 1.0, 1.0);
        setExiting(0, LvlExit::EXIT_Error);
    }

    Scene::update();

    if(!m_isPauseMenu)
        tickAnimations(uTickf);

    if(!m_isLevelContinues)
    {
        //Level exit timeout
        m_exitLevelDelay -= uTickf;

        if(m_exitLevelDelay <= 0.0)
        {
            m_doExit = true;

            if(m_fader.isNull())
            {
                if(PGE_MusPlayer::isPlaying())
                    PGE_MusPlayer::fadeOut(500);

                m_fader.setFade(10, 1.0, 0.01);
            }
        }
    }

    if(m_doExit)
    {
        if(m_exitLevelCode == LvlExit::EXIT_Closed)
        {
            m_fader.setFull();
            m_isRunning = false;
        }
        else
        {
            if(m_fader.isFull())
                m_isRunning = false;
        }
    }
    else if(m_isPauseMenu)
        processPauseMenu();
    else
    {
        //Update physics is not pause menu
        updateLua();//Process LUA code
        m_systemEvents.processEvents(uTickf);
        m_events.processTimers(uTickf);

        //update cameras
        for(PGE_LevelCamera &cam : m_cameras)
            cam.updatePre(uTickf);

        processEffects(uTickf);

        if(!m_isTimeStopped) //if activated Time stop bonus or time disabled by special event
        {
            //Make world step
            processPhysics(uTickf);
        }

        while(!m_blockTransforms.empty())
        {
            transformTask_block x = m_blockTransforms.front();
            x.block->transformTo_x(x.id);
            m_blockTransforms.pop_front();
        }

        // Send controller states to controllable objects
        m_player1Controller->sendControls();
        m_player2Controller->sendControls();

        //update players
        for(LVL_Player *plr : m_itemsPlayers)
        {
            plr->update(uTickf);

            if(PGE_Window::showDebugInfo)
            {
                m_debug_player_jumping    = plr->m_jumpPressed;
                m_debug_player_onground   = plr->onGround();
                m_debug_player_foots      = (int)plr->l_contactB.size();
            }
        }

        for(size_t i = 0; i < m_blocksInFade.size(); i++)
        {
            if(m_blocksInFade[i]->tickFader(uTickf))
            {
                m_blocksInFade.erase(m_blocksInFade.begin() + (int)i);
                i--;
            }
        }

        //Process activated NPCs
        //for(size_t i = 0; i < m_npcActive.size(); i++)
        for(auto i = m_npcActive.begin(); i != m_npcActive.end();)
        {
            LVL_Npc *n = *i;
            n->update(uTickf);
            if(n->isKilled())
            {
                i = m_npcActive.erase(i);
                continue;
            }
            else if(n->activationTimeout <= 0)
            {
                if(!n->warpSpawing)
                    n->deActivate();
                if(n->wasDeactivated)
                {
                    if(!isVizibleOnScreen(n->m_momentum) || !n->isVisible() || !n->is_activity)
                    {
                        n->wasDeactivated = false;
                        i = m_npcActive.erase(i);
                        continue;
                    }
                }
            }
            ++i;
        }

        if(!m_isTimeStopped) //if activated Time stop bonus or time disabled by special event
        {
            //Process and resolve collisions
            processAllCollisions();
        }

        /***************Collect garbage****************/
        if(!m_npcDead.empty())
            collectGarbageNPCs();

        if(!m_playersDead.empty())
            collectGarbagePlayers();

        if(!m_blocksToDelete.empty())
            collectGarbageBlocks();

        /**********************************************/

        //update cameras
        for(PGE_LevelCamera &cam : m_cameras)
        {
            cam.updatePost(uTickf);
            //! --------------DRAW HUD--------------------------------------
            // TODO: Implement separated render queue for elements of HUD and provide render functions
            // are will draw HUD elements after world has drawn.
            LuaEngine *sceneLuaEngine = getLuaEngine();
            if(sceneLuaEngine)
            {
                if(sceneLuaEngine->isValid() && !sceneLuaEngine->shouldShutdown())
                {
                    LuaEvent drawHUDEvent = BindingCore_Events_Engine::createDrawLevelHUDEvent(sceneLuaEngine,
                                            &cam,
                                            &m_playerStates[(size_t)(cam.playerID - 1)]);
                    sceneLuaEngine->dispatchEvent(drawHUDEvent);
                }
            }
            //! ------------------------------------------------------------
        }

        //Add effects into the render table
        for(Scene_Effect &item : WorkingEffects)
        {
            renderArrayAddFunction([&item](double camPosX, double camPosY)
            {
                item.render(camPosX, camPosY);
            },  item.m_zIndex);
        }

        //Clear garbage (be careful!)
        //luaEngine.runGarbageCollector();
    }

    //Process interprocessing commands cache
    process_InterprocessCommands();
    //Process Z-sort of the render functions
    renderArrayPrepare();
    //Process message boxes
    m_messages.process();
}
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.º 22
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.º 23
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;
}