bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); #if CC_64BITS FileUtils::getInstance()->addSearchPath("src/64bit"); #endif FileUtils::getInstance()->addSearchPath("src"); FileUtils::getInstance()->addSearchPath("res"); if (engine->executeScriptFile("main.lua")) { return false; } return true; }
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; }
bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); #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 auto runtimeEngine = RuntimeEngine::getInstance(); runtimeEngine->addRuntime(RuntimeLuaImpl::create(), kRuntimeEngineLua); runtimeEngine->start(); #else if (engine->executeScriptFile("src/main.lua")) { return false; } #endif return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { string title = "wt-cgame-a"; glview = cocos2d::GLViewImpl::create(title.c_str()); director->setOpenGLView(glview); director->startAnimation(); } auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); // use Quick-Cocos2d-X quick_module_register(L); LuaStack* stack = engine->getLuaStack(); #if ANYSDK_DEFINE > 0 lua_getglobal(stack->getLuaState(), "_G"); tolua_anysdk_open(stack->getLuaState()); tolua_anysdk_manual_open(stack->getLuaState()); lua_pop(stack->getLuaState(), 1); #endif //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); //FileUtils::getInstance()->setResourceEncryptKeyAndSign("test", "XXTEA"); #if 0 // use luajit bytecode package stack->setXXTEAKeyAndSign("2dxLua", "XXTEA"); #ifdef CC_TARGET_OS_IPHONE if (sizeof(long) == 4) { stack->loadChunksFromZIP("res/game.zip"); } else { stack->loadChunksFromZIP("res/game64.zip"); } #else // android, mac, win32, etc stack->loadChunksFromZIP("res/game.zip"); #endif stack->executeString("require 'main'"); #else // #if 0 // use discrete files engine->executeScriptFile("src/main.lua"); #endif return true; }
bool AppDelegate::applicationDidFinishLaunching() { #if (COCOS2D_DEBUG>0) initRuntime(); #endif if (!ConfigParser::getInstance()->isInit()) { ConfigParser::getInstance()->readConfig(); } // 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) 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); auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function auto luaState = stack->getLuaState(); lua_getglobal(luaState, "_G"); register_all_pluginx_protocols(luaState); register_all_pluginx_manual_callback(luaState); register_all_pluginx_manual_protocols(luaState); #if (COCOS2D_DEBUG>0) if (startRuntime()) return true; #endif engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); // If you want to use Quick-Cocos2d-X, please uncomment below code // register_all_quick_manual(L); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); if (L) { lua_getglobal(L, "_G"); register_all_cocos2dx_lilith(L); register_all_cocos2dx_lilith_manual(L); register_global_interface(L); luaopen_struct(L);//add luaopen_bit(L);//add luaopen_lpeg(L);//add luaopen_mycrypto(L);//add lua_settop(L, 0); } #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 RuntimeEngine::getInstance()->start(); cocos2d::log("iShow!"); #else if (engine->executeScriptFile("src/main.lua")) { return false; } #endif return true; }
bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); lua_register(L, "test_lua", test); tolua_xx_open(L); tolua_GameNetDelegate_open(L); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); #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 auto runtimeEngine = RuntimeEngine::getInstance(); runtimeEngine->addRuntime(RuntimeLuaImpl::create(), kRuntimeEngineLua); runtimeEngine->start(); #else if (engine->executeScriptFile("src/main.lua")) { return false; } #endif // CCInetAddress oAddres; // oAddres.setIp("192.168.0.188"); // oAddres.setPort(9001); // // 22222 // // auto net = GameNetDelegate::getInstance(); // net->setInetAddress(oAddres); // net->connect(); // TestLuaStruct::testToLua(); return true; }
bool AppDelegate::applicationDidFinishLaunching() { #if (COCOS2D_DEBUG > 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) 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 } auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); // If you want to use Quick-Cocos2d-X, please uncomment below code // register_all_quick_manual(L); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); #if (COCOS2D_DEBUG > 0) // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE startRuntime(); #else engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); #endif return true; }
void AppDelegate::startLoadLua(bool isfirst/*=true*/) { g_luaisLoad=false; auto engine = LuaEngine::getInstance(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); capi_lua_register(); g_luaisLoad=true; #if (COCOS2D_DEBUG>0) if (startRuntime()) return; #endif engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); director->setProjection(Director::Projection::_2D); // 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); director->startAnimation(); // register lua engine auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); luaopen_crypt(L); luaopen_protobuf_c(L); const char *wirtPathPrefix = "com.hei54.weapons"; lua_pushstring(L, wirtPathPrefix); lua_setglobal(L, "WRITABLE_PATH_PREFIX"); // If you want to use Quick-Cocos2dx-Community, please uncomment below code quick_module_register(L); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", "XXTEA"); StartupCall *call = StartupCall::create(this); call->startup(); return true; }
bool AppDelegate::applicationDidFinishLaunching() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) InitCrashReport(); #endif #if (COCOS2D_DEBUG>0) initRuntime(); #endif if (!ConfigParser::getInstance()->isInit()) { ConfigParser::getInstance()->readConfig(); } // 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) 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); //::SetWindowPos(glfwGetWin32Window(director->getOpenGLView()->getWindow()),HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); #else glview = GLView::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 #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #if (COCOS2D_DEBUG<=0) director->setAnimationInterval(1.0 / 30); #else director->setAnimationInterval(1.0 / 60); #endif #else director->setAnimationInterval(1.0 / 60); #endif auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("s3ExtaS", strlen("s3ExtaS"), "IH8wdkD", strlen("IH8wdkD")); //cocos luacompile -s G:\\mobile_arpg\\arpg\\src -d I:\\securecrt\\xxeat -e -k s3ExtaS -b IH8wdkD //register custom function CustomLuaCocos2d(engine->getLuaStack()->getLuaState()); //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); //register_all_ccarpg(stack->getLuaState()); //register_all_ccarpg_manual(stack->getLuaState()); // std::string resdirname = "res/"; std::string configdirname = "config/"; vector<string> searchPath; #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) searchPath.push_back("../../src/"); searchPath.push_back("../../"+configdirname); searchPath.push_back("../../"+resdirname); //extern std::string getCurAppPath(); //string resourcePath = getCurAppPath(); //searchPath.push_back(resourcePath+"/"); //searchPath.push_back("src/"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) searchPath.push_back("src/"); searchPath.push_back(configdirname); searchPath.push_back(resdirname); #else searchPath.push_back("src/"); //searchPath.push_back("config/"); searchPath.push_back(resdirname); #endif // std::string pathToSave = FileUtils::getInstance()->getWritablePath(); // pathToSave += "s3b6lhuxo"; // //#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) // DIR *pDir = NULL; // // pDir = opendir (pathToSave.c_str()); // if (pDir) // { // searchPath.insert(searchPath.begin(), pathToSave); // } //#else // if ((GetFileAttributesA(pathToSave.c_str())) != INVALID_FILE_ATTRIBUTES) // { // searchPath.insert(searchPath.begin(), pathToSave); // } //#endif FileUtils::getInstance()->setSearchPaths(searchPath); CcarpgNet::getInstance()->start(); #if (COCOS2D_DEBUG>0) MessageDispatcher::getInstance()->startLocalTerminal(0); #endif //if(!ReceiveThread::GetInstance()->isRunning) //{ // ReceiveThread::GetInstance()->start(); //} //FileUtils::getInstance()->printSearchPath(); #if (COCOS2D_DEBUG>0) #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(stack->getLuaState()); #endif if (ConfigParser::getInstance()->useCocosIde()){ if (startRuntime()) { #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 EventListenerKeyboard *listener = EventListenerKeyboard::create(); listener->onKeyReleased = AppDelegate::keyEventCallback; director->getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1); #endif return true; } } else { //#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(stack->getLuaState()); //#endif #ifdef USE_ANY_SDK_IN_IOS #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) LuaStack* stackios = engine->getLuaStack(); lua_getglobal(stackios->getLuaState(), "_G"); tolua_anysdk_open(stackios->getLuaState()); tolua_anysdk_manual_open(stackios->getLuaState()); lua_pop(stackios->getLuaState(), 1); #endif #endif engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); // engine->executeScriptFile("src/main.lua"); } #else #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(stack->getLuaState()); #endif //vector<string> searchPath; //searchPath.push_back("../../src"); //searchPath.push_back("../../res"); //FileUtils::getInstance()->setSearchPaths(searchPath); //CcarpgNet::getInstance()->start(); //long lasttt = getTimer(); //CcarpgMcm::getInstance()->setCurrentMapData(51001); //CCLOG("mcm need time = %d",(getTimer()-lasttt)); //SocketThread* th= SocketThread::GetInstance(); //th->start(); #ifdef USE_ANY_SDK_IN_IOS #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) LuaStack* stackios = engine->getLuaStack(); lua_getglobal(stackios->getLuaState(), "_G"); tolua_anysdk_open(stackios->getLuaState()); tolua_anysdk_manual_open(stackios->getLuaState()); lua_pop(stackios->getLuaState(), 1); #endif #endif engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) //::SetWindowPos(glfwGetWin32Window(director->getOpenGLView()->getWindow()),HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); //BringWindowToTop(glfwGetWin32Window(director->getOpenGLView()->getWindow())); //SetConsoleTitle(L"your title"); //SetWindowText(glfwGetWin32Window(director->getOpenGLView()->getWindow()), L"cllc"); // HDC hdc = GetWindowDC(glfwGetWin32Window(director->getOpenGLView()->getWindow())); //SetTextColor(hdc, 0xFFFF0000); #endif #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 EventListenerKeyboard *listener = EventListenerKeyboard::create(); listener->onKeyReleased = AppDelegate::keyEventCallback; director->getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1); #endif return true; }
bool AppDelegate::applicationDidFinishLaunching() { #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 initRuntime(); #elif (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 if (_launchMode) { initRuntime(); } #endif initResourcePath(); // 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) 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 director->startAnimation(); } auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); // use Quick-Cocos2d-X quick_module_register(L); LuaStack* stack = engine->getLuaStack(); #if ANYSDK_DEFINE > 0 lua_getglobal(stack->getLuaState(), "_G"); tolua_anysdk_open(stack->getLuaState()); tolua_anysdk_manual_open(stack->getLuaState()); lua_pop(stack->getLuaState(), 1); #endif stack->setXXTEAKeyAndSign("ilovecocos2dx", strlen("ilovecocos2dx"), "XXTEA", strlen("XXTEA")); stack->addSearchPath("src"); #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 if (_launchMode) { startRuntime(); } #endif FileUtils *utils = FileUtils::getInstance(); const char *updateFileName = "code/launcher.zip"; std::string updateFilePath = utils->fullPathForFilename(updateFileName); bool isUpdate = false; if (updateFilePath.compare(updateFileName) != 0) //check if update file exist { printf("%s\n", updateFilePath.c_str()); isUpdate = true; engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); } if (!isUpdate) //no update file { const char *zipFilename ="code/game.zip"; std::string zipFilePath = utils->fullPathForFilename(zipFilename); if (zipFilePath.compare(zipFilename) == 0) //no game zip file use default lua file { engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); } else { stack->loadChunksFromZIP(zipFilename); stack->executeString("require 'main'"); } } return true; }
bool AppDelegate::applicationDidFinishLaunching() { #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 initRuntime(); #elif (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 if (_launchMode) { initRuntime(); } #endif //------------------------------------------------- // printf( "%s", getSSID().c_str()); // CCLOG("%s", p); // 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) 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 director->startAnimation(); } auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); sqlite_register(L); //注册sqlite相关函数 toolFunction_register(L); // use Quick-Cocos2d-X quick_module_register(L); LuaStack* stack = engine->getLuaStack(); #if ANYSDK_DEFINE > 0 lua_getglobal(stack->getLuaState(), "_G"); tolua_anysdk_open(stack->getLuaState()); tolua_anysdk_manual_open(stack->getLuaState()); lua_pop(stack->getLuaState(), 1); #endif stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); #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 // if (_launchMode) // { // startRuntime(); // } // else { engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); } #else engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); #endif return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { auto title = StringUtils::format("quick-cocos2d-x (%s)", cocos2dVersion()); glview = GLViewImpl::createWithRect(title, Rect(0, 0, 640, 960)); director->setOpenGLView(glview); } director->getOpenGLView()->setDesignResolutionSize(640, 960, ResolutionPolicy::FIXED_WIDTH); // 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); FileUtils::getInstance()->addSearchPath("res"); // run director->runWithScene(MainScene::create()); return true; // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // load framework stack->loadChunksFromZIP("res/framework_precompiled.zip"); #else // load framework if (_projectConfig.isLoadPrecompiledFramework()) { const string precompiledFrameworkPath = SimulatorConfig::getInstance()->getPrecompiledFrameworkPath(); stack->loadChunksFromZIP(precompiledFrameworkPath.c_str()); } #endif FileUtils::getInstance()->setPopupNotify(false); // set script path string path = FileUtils::getInstance()->fullPathForFilename("scripts/main.lua"); 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); stack->addSearchPath(dir.c_str()); p = dir.find_last_of("/\\"); if (p != dir.npos) { stack->addSearchPath(dir.substr(0, p).c_str()); } } string env = "__LUA_STARTUP_FILE__=\""; env.append(path); env.append("\""); engine->executeString(env.c_str()); CCLOG("------------------------------------------------"); CCLOG("LOAD LUA FILE: %s", path.c_str()); CCLOG("------------------------------------------------"); engine->executeScriptFile(path.c_str()); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0f / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); LuaRegister::openLibs(L); LuaUtil::openLibs(L); LuaNetwork::openLibs(L); luaopen_bit(L); luaopen_cjson(L); luaopen_md5_core(L); luaopen_lua_timer(L); //初始化lua加载函数 TDLuaMgr::instance(); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); #ifdef WIN32 std::string result = ""; WCHAR buf[1000 + 1]; int i = 1000; GetCurrentDirectory(1000, buf); //得到当前工作路径 cocos2d::StringUtils::UTF16ToUTF8((char16_t*)buf, result); result = result + "/../../"; cocos2d::log("add path is %s", result.c_str()); FileUtils::getInstance()->addSearchPath(result); FileUtils::getInstance()->addSearchPath(result + "/src"); FileUtils::getInstance()->addSearchPath(result + "/res"); for (auto path : cocos2d::FileUtils::getInstance()->getSearchPaths()) { cocos2d::log("search paths is %s", path.c_str()); } #endif { Data data = FileUtils::getInstance()->getDataFromFile("src/config/GlobalConfig.conf"); ConfigMgr::instance()->initGlobalConfig((const char*)data.getBytes(), data.getSize()); } // 设置脚本宏 LuaMgrIns->registerLuaGlobalVariable("SERVER_TYPE", "client"); Json::Value macro = GlobalConfig.get("lua_macros", Json::objectValue); for (auto mr : macro.getMemberNames()) { LuaMgrIns->registerLuaGlobalVariable(mr.c_str(), macro[mr.c_str()].asCString()); } { Data data = FileUtils::getInstance()->getDataFromFile("src/config/protocol.txt"); NetConfig::instance()->updateMessage((const char*)data.getBytes(), data.getSize()); } //CommandLine::instance()->CreateCmdLine(); Director::getInstance()->getScheduler()->schedule(std::bind(&AppDelegate::onUpdate, this, 0.1f), (void *)this, 0.1f, false, "onUpdate"); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); #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 auto runtimeEngine = RuntimeEngine::getInstance(); runtimeEngine->addRuntime(RuntimeLuaImpl::create(), kRuntimeEngineLua); runtimeEngine->start(); #else if (engine->executeScriptFile("src/main.lua")) { return false; } #endif return true; }