From 0d8c9eeb19277ef992e8027f0cb343079bef8bee Mon Sep 17 00:00:00 2001 From: chuanweizhang2013 Date: Fri, 29 Aug 2014 15:05:55 +0800 Subject: [PATCH] add link resource support --- .../.settings/version.json | 4 +- templates/lua-template-runtime/config.json | 3 +- .../runtime-src/Classes/ConfigParser.cpp | 12 ++++- .../runtime-src/Classes/ConfigParser.h | 2 + .../runtime-src/Classes/runtime/Runtime.cpp | 52 ++++++++++++------- .../Classes/runtime/lua_debugger.c | 8 ++- 6 files changed, 57 insertions(+), 24 deletions(-) diff --git a/templates/lua-template-runtime/.settings/version.json b/templates/lua-template-runtime/.settings/version.json index 62ee19a364..4efc015971 100644 --- a/templates/lua-template-runtime/.settings/version.json +++ b/templates/lua-template-runtime/.settings/version.json @@ -1,4 +1,4 @@ { - "templateVersion":"1.3", - "runtimeVersion":"1.3" + "templateVersion":"1.4", + "runtimeVersion":"1.4" } \ No newline at end of file diff --git a/templates/lua-template-runtime/config.json b/templates/lua-template-runtime/config.json index c208eca175..d50247cdda 100644 --- a/templates/lua-template-runtime/config.json +++ b/templates/lua-template-runtime/config.json @@ -6,7 +6,8 @@ "width": 960, "height": 640, "entry": "src/main.lua", - "consolePort": 6010 + "consolePort": 6010, + "uploadPort": 6020 }, "simulator_screen_size": [ { diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp index eaa12d4fbc..ac8601941d 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp @@ -26,6 +26,7 @@ void ConfigParser::readConfig() _isInit = true; _isWindowTop = false; _consolePort = 6010; + _uploadPort = 6020; string filecfg = "config.json"; string fileContent; @@ -73,9 +74,14 @@ void ConfigParser::readConfig() } if (objectInitView.HasMember("consolePort")){ _consolePort = objectInitView["consolePort"].GetUint(); - if(0 == _consolePort) + if(_consolePort<=0) _consolePort = 6010; } + if (objectInitView.HasMember("uploadPort")){ + _uploadPort = objectInitView["uploadPort"].GetUint(); + if(_uploadPort<=0) + _uploadPort = 6020; + } if (objectInitView.HasMember("isWindowTop") && objectInitView["isWindowTop"].IsBool()){ _isWindowTop= objectInitView["isWindowTop"].GetBool(); } @@ -141,6 +147,10 @@ int ConfigParser::getConsolePort() { return _consolePort; } +int ConfigParser::getUploadPort() +{ + return _uploadPort; +} int ConfigParser::getScreenSizeCount(void) { return (int)_screenSizeArray.size(); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h index 4a83b386b4..a4ad886e8f 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.h @@ -37,6 +37,7 @@ public: rapidjson::Document& getConfigJsonRoot(); const SimulatorScreenSize getScreenSize(int index); int getConsolePort(); + int getUploadPort(); bool isLanscape(); bool isWindowTop(); bool isInit(); @@ -52,6 +53,7 @@ private: bool _isInit; bool _isWindowTop; int _consolePort; + int _uploadPort; rapidjson::Document _docRootjson; }; diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp index bb07bc00f9..251cd2a535 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp @@ -50,7 +50,7 @@ using namespace std; using namespace cocos2d; std::string g_resourcePath; - +static std::string g_projectPath; //1M size #define MAXPROTOLENGTH 1048576 @@ -64,7 +64,7 @@ std::string g_resourcePath; extern string getIPAddress(); const char* getRuntimeVersion() { - return "1.3"; + return "1.4"; } static string& replaceAll(string& str,const string& old_value,const string& new_value) @@ -801,11 +801,13 @@ public: _console->listenOnTCP(6010); #endif _fileserver = nullptr; -#if(CC_PLATFORM_MAC != CC_TARGET_PLATFORM && CC_PLATFORM_WIN32 != CC_TARGET_PLATFORM) _fileserver= FileServer::getShareInstance(); +#if(CC_PLATFORM_MAC == CC_TARGET_PLATFORM || CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM) + _fileserver->listenOnTCP(ConfigParser::getInstance()->getUploadPort()); +#else _fileserver->listenOnTCP(6020); - _fileserver->readResFileFinfo(); #endif + _fileserver->readResFileFinfo(); } ~ConsoleCustomCommand() @@ -998,13 +1000,17 @@ int lua_cocos2dx_runtime_addSearchPath(lua_State* tolua_S) ok &= luaval_to_std_string(tolua_S, 2,&arg0); if(!ok) return 0; - std::string argtmp = arg0; - if (!FileUtils::getInstance()->isAbsolutePath(arg0)) - arg0 = g_resourcePath+arg0; + std::string originPath = arg0; + if (!FileUtils::getInstance()->isAbsolutePath(originPath)) + arg0 = g_resourcePath+originPath; cobj->addSearchPath(arg0); +#if(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + if (!FileUtils::getInstance()->isAbsolutePath(originPath)) + cobj->addSearchPath(g_projectPath + originPath); +#endif #if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - if (!FileUtils::getInstance()->isAbsolutePath(argtmp)) - cobj->addSearchPath(argtmp); + if (!FileUtils::getInstance()->isAbsolutePath(originPath)) + cobj->addSearchPath(originPath); #endif return 0; } @@ -1052,17 +1058,22 @@ int lua_cocos2dx_runtime_setSearchPaths(lua_State* tolua_S) ok &= luaval_to_std_vector_string(tolua_S, 2,&vecPaths); if(!ok) return 0; - std::vector argtmp; + std::vector originPath; // for IOS platform. + std::vector projPath; // for Desktop platform. for (int i = 0; i < vecPaths.size(); i++) { if (!FileUtils::getInstance()->isAbsolutePath(vecPaths[i])) { - argtmp.push_back(vecPaths[i]); + originPath.push_back(vecPaths[i]); // for IOS platform. + projPath.push_back(g_projectPath+vecPaths[i]); //for Desktop platform. vecPaths[i] = g_resourcePath + vecPaths[i]; } } +#if(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + vecPaths.insert(vecPaths.end(),projPath.begin(),projPath.end()); +#endif #if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - vecPaths.insert(vecPaths.end(),argtmp.begin(),argtmp.end()); + vecPaths.insert(vecPaths.end(),originPath.begin(),originPath.end()); #endif cobj->setSearchPaths(vecPaths); return 0; @@ -1109,18 +1120,23 @@ bool initRuntime() vector searchPathArray; searchPathArray=FileUtils::getInstance()->getSearchPaths(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - if (g_resourcePath.empty()) + if (g_projectPath.empty()) { extern std::string getCurAppPath(); - string resourcePath = getCurAppPath(); + string appPath = getCurAppPath(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - resourcePath.append("/../../"); + appPath.append("/../../"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - resourcePath.append("/../../../"); + appPath.append("/../../../"); #endif - resourcePath =replaceAll(resourcePath,"\\","/"); - g_resourcePath = resourcePath; + appPath =replaceAll(appPath,"\\","/"); + g_projectPath = appPath; } + searchPathArray.insert(searchPathArray.begin(),g_projectPath); + g_resourcePath = FileUtils::getInstance()->getWritablePath(); + g_resourcePath += "debugruntime/"; + g_resourcePath += ConfigParser::getInstance()->getInitViewName(); + g_resourcePath +="/"; #else g_resourcePath = FileUtils::getInstance()->getWritablePath(); g_resourcePath += "debugruntime/"; diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/lua_debugger.c b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/lua_debugger.c index 04dae17695..cf7bf2a55a 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/lua_debugger.c +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/lua_debugger.c @@ -1,10 +1,14 @@ /* debugger.c */ - +#if __cplusplus +extern "C"{ +#endif #include "lua.h" #include "lauxlib.h" #include "lua_debugger.h" - +#if __cplusplus +} +#endif /* ldt_debugger */ static const char lua_m_ldt_debugger[] = { 0x1b,0x4c,0x4a,0x01,0x02,0x87,0x01,0x00,0x01,0x0c,0x00,0x06,0x02,0x18,0x32,0x01,