Merge pull request #8087 from cocoscodeide/v3

fix runtime build error for 3.3
This commit is contained in:
minggo 2014-09-17 15:37:54 +08:00
commit 431064bc45
21 changed files with 2825 additions and 2794 deletions

View File

@ -1,4 +1,4 @@
{
"templateVersion":"1.3",
"runtimeVersion":"1.3"
"templateVersion":"1.4",
"runtimeVersion":"1.4"
}

View File

@ -1,11 +1,13 @@
{
"init_cfg":{
"isLandscape": true,
"isWindowTop": false,
"name": "HelloLua",
"width": 960,
"height": 640,
"entry": "src/main.lua",
"consolePort": 6010
"consolePort": 6010,
"uploadPort": 6020
},
"simulator_screen_size": [
{

View File

@ -38,10 +38,6 @@ bool AppDelegate::applicationDidFinishLaunching()
initRuntime();
#endif
if (!ConfigParser::getInstance()->isInit()) {
ConfigParser::getInstance()->readConfig();
}
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
@ -58,10 +54,6 @@ bool AppDelegate::applicationDidFinishLaunching()
#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);
lua_State* L = engine->getLuaStack()->getLuaState();
@ -98,4 +90,3 @@ void AppDelegate::applicationWillEnterForeground()
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}

View File

@ -1,7 +1,8 @@
#ifndef __APP_DELEGATE_H__
#define __APP_DELEGATE_H__
#include "CCApplication.h"
#include "cocos2d.h"
/**
@brief The cocos2d Application.

View File

@ -12,19 +12,16 @@ ConfigParser *ConfigParser::getInstance(void)
if (!s_sharedInstance)
{
s_sharedInstance = new ConfigParser();
s_sharedInstance->readConfig();
}
return s_sharedInstance;
}
bool ConfigParser::isInit()
{
return _isInit;
}
void ConfigParser::readConfig()
{
_isInit = true;
_isWindowTop = false;
_consolePort = 6010;
_uploadPort = 6020;
string filecfg = "config.json";
string fileContent;
@ -72,6 +69,16 @@ void ConfigParser::readConfig()
}
if (objectInitView.HasMember("consolePort")){
_consolePort = objectInitView["consolePort"].GetUint();
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();
}
}
}
@ -95,7 +102,7 @@ void ConfigParser::readConfig()
}
ConfigParser::ConfigParser(void):_isInit(false),_isLandscape(true)
ConfigParser::ConfigParser(void):_isLandscape(true)
{
_initViewSize.setSize(960,640);
_viewName = "HelloLua";
@ -127,10 +134,18 @@ bool ConfigParser::isLanscape()
return _isLandscape;
}
bool ConfigParser::isWindowTop()
{
return _isWindowTop;
}
int ConfigParser::getConsolePort()
{
return _consolePort;
}
int ConfigParser::getUploadPort()
{
return _uploadPort;
}
int ConfigParser::getScreenSizeCount(void)
{
return (int)_screenSizeArray.size();

View File

@ -37,8 +37,9 @@ public:
rapidjson::Document& getConfigJsonRoot();
const SimulatorScreenSize getScreenSize(int index);
int getConsolePort();
int getUploadPort();
bool isLanscape();
bool isInit();
bool isWindowTop();
private:
ConfigParser(void);
@ -48,8 +49,9 @@ private:
string _viewName;
string _entryfile;
bool _isLandscape;
bool _isInit;
bool _isWindowTop;
int _consolePort;
int _uploadPort;
rapidjson::Document _docRootjson;
};

View File

@ -1,27 +1,30 @@
#ifndef __LUA_TEMPLATE_RUNTIME_FRAMEWORKS_RUNTIME_SRC_CLASSES_LUA_MODULE_REGISTER_H__
#define __LUA_TEMPLATE_RUNTIME_FRAMEWORKS_RUNTIME_SRC_CLASSES_LUA_MODULE_REGISTER_H__
#include "network/lua_cocos2dx_network_manual.h"
#include "cocosdenshion/lua_cocos2dx_cocosdenshion_manual.h"
#include "network/lua_cocos2dx_network_manual.h"
#include "cocosbuilder/lua_cocos2dx_cocosbuilder_manual.h"
#include "cocostudio/lua_cocos2dx_coco_studio_manual.hpp"
#include "extension/lua_cocos2dx_extension_manual.h"
#include "ui/lua_cocos2dx_ui_manual.hpp"
#include "spine/lua_cocos2dx_spine_manual.hpp"
#include "3d/lua_cocos2dx_3d_manual.h"
#include "audioengine/lua_cocos2dx_audioengine_manual.h"
int lua_module_register(lua_State* L)
{
//Dont' change the module register order unless you know what your are doing
register_network_module(L);
register_cocosdenshion_module(L);
register_network_module(L);
register_cocosbuilder_module(L);
register_cocostudio_module(L);
register_ui_moudle(L);
register_extension_module(L);
register_spine_module(L);
register_cocos3d_module(L);
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS
register_audioengine_module(L);
#endif
return 1;
}

View File

@ -50,10 +50,7 @@ using namespace std;
using namespace cocos2d;
std::string g_resourcePath;
namespace cocos2d {
extern const char* cocos2dVersion();
};
static std::string g_projectPath;
//1M size
#define MAXPROTOLENGTH 1048576
@ -67,7 +64,7 @@ namespace cocos2d {
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)
@ -76,7 +73,7 @@ static string& replaceAll(string& str,const string& old_value,const string& new_
while(true)
{
int pos=0;
if((pos=str.find(old_value,start))!=string::npos) {
if((pos=str.find(old_value, start)) != string::npos) {
str.replace(pos,old_value.length(),new_value);
start = pos + new_value.length();
}
@ -84,6 +81,7 @@ static string& replaceAll(string& str,const string& old_value,const string& new_
}
return str;
}
static bool resetLuaModule(string fileName)
{
if (fileName.empty())
@ -154,9 +152,6 @@ void startScript(string strDebugArg)
engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str());
}
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <io.h>
#include <WS2tcpip.h>
@ -739,8 +734,7 @@ public:
}
char szVersion[1024]={0};
sprintf(szVersion,"runtimeVersion:%s \ncocos2dVersion:%s",getRuntimeVersion(),cocos2dVersion());
sprintf(szVersion,"runtimeVersion:%s \nengineVersion:%s",getRuntimeVersion(),cocos2dVersion());
Label* verLable = Label::createWithSystemFont(szVersion,"",24);
verLable->setAnchorPoint(Vec2(0,0));
int width = verLable->getBoundingBox().size.width;
@ -811,11 +805,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()
@ -931,6 +927,32 @@ public:
#else
exit(0);
#endif
}else if(strcmp(strcmd.c_str(),"shutdownapp")==0)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
extern void shutDownApp();
shutDownApp();
#else
exit(0);
#endif
}else if (strcmp(strcmd.c_str(),"getplatform")==0)
{
string platform="UNKNOW";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
platform = "WIN32";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
platform = "MAC";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
platform = "IOS";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
platform = "ANDROID";
#endif
rapidjson::Value bodyvalue(rapidjson::kObjectType);
rapidjson::Value platformValue(rapidjson::kStringType);
platformValue.SetString(platform.c_str(),dReplyParse.GetAllocator());
bodyvalue.AddMember("platform",platformValue,dReplyParse.GetAllocator());
dReplyParse.AddMember("body",bodyvalue,dReplyParse.GetAllocator());
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
}
rapidjson::StringBuffer buffer;
@ -982,13 +1004,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;
}
@ -1036,17 +1062,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<std::string> argtmp;
std::vector<std::string> originPath; // for IOS platform.
std::vector<std::string> 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;
@ -1093,24 +1124,29 @@ bool initRuntime()
vector<string> 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;
}
#else
g_resourcePath = FileUtils::getInstance()->getWritablePath();
g_resourcePath += "debugruntime/";
searchPathArray.insert(searchPathArray.begin(),g_projectPath);
#endif
g_resourcePath = FileUtils::getInstance()->getWritablePath();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
std::string getCurAppName(void);
g_resourcePath += getCurAppName();
g_resourcePath +="/";
#endif
g_resourcePath += "debugruntime/";
g_resourcePath=replaceAll(g_resourcePath,"\\","/");
if (g_resourcePath.at(g_resourcePath.length()-1) != '/'){
g_resourcePath.append("/");
@ -1124,6 +1160,10 @@ bool initRuntime()
LuaStack* stack = engine->getLuaStack();
register_runtime_override_function(stack->getLuaState());
luaopen_debugger(engine->getLuaStack()->getLuaState());
static ConsoleCustomCommand *g_customCommand;
g_customCommand = new ConsoleCustomCommand();
g_customCommand->init();
return true;
}
@ -1145,17 +1185,11 @@ bool startRuntime()
// turn on display FPS
Director::getInstance()->setDisplayStats(true);
static ConsoleCustomCommand *g_customCommand;
g_customCommand = new ConsoleCustomCommand();
g_customCommand->init();
auto scene = Scene::create();
auto connectLayer = new ConnectWaitLayer();
connectLayer->autorelease();
auto director = Director::getInstance();
scene->addChild(connectLayer);
director->runWithScene(scene);
return true;
}

View File

@ -31,7 +31,5 @@ using namespace std;
bool initRuntime();
bool startRuntime();
bool reloadScript(string modulefile);
#endif // _RUNTIME__H_

View File

@ -8,17 +8,11 @@
"copy_resources": [
{
"from": "../../../src",
"to": "src",
"exclude": [
"*.gz"
]
"to": "src"
},
{
"from": "../../../res",
"to": "res",
"exclude": [
"*.gz"
]
"to": "res"
}
],
"must_copy_resources": [

View File

@ -6,7 +6,8 @@ LOCAL_MODULE := cocos2dlua_shared
LOCAL_MODULE_FILENAME := libcocos2dlua
LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := hellolua/main.cpp \
hellolua/Runtime_android.cpp \
../../Classes/protobuf-lite/google/protobuf/io/coded_stream.cc \
../../Classes/protobuf-lite/google/protobuf/stubs/common.cc \
../../Classes/protobuf-lite/google/protobuf/extension_set.cc \
@ -29,9 +30,7 @@ LOCAL_SRC_FILES := \
../../Classes/runtime/lua_debugger.c \
../../Classes/VisibleRect.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/ConfigParser.cpp \
lua/Runtime_android.cpp \
lua/main.cpp
../../Classes/ConfigParser.cpp
LOCAL_C_INCLUDES := \
@ -45,4 +44,3 @@ LOCAL_STATIC_LIBRARIES := cocos2d_lua_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,scripting/lua-bindings/proj.android)

View File

@ -6,21 +6,6 @@
using namespace std;
using namespace cocos2d;
string getSDCardPath()
{
JniMethodInfo t;
string sdcardPath("");
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lua/AppActivity", "getSDCardPath", "()Ljava/lang/String;")) {
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
sdcardPath = JniHelper::jstring2string(str);
t.env->DeleteLocalRef(str);
}
return sdcardPath;
}
string getIPAddress()
{
JniMethodInfo t;

View File

@ -19,10 +19,6 @@ extern "C"
{
bool Java_org_cocos2dx_lua_AppActivity_nativeIsLandScape(JNIEnv *env, jobject thisz)
{
if (!ConfigParser::getInstance()->isInit())
{
ConfigParser::getInstance()->readConfig();
}
return ConfigParser::getInstance()->isLanscape();
}

View File

@ -45,22 +45,18 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.text.format.Formatter;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;
// The name of .so is specified in AndroidMenifest.xml. NativityActivity will load it automatically for you.
// You can use "System.loadLibrary()" to load other .so files.
public class AppActivity extends Cocos2dxActivity{
static String hostIPAdress="0.0.0.0";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(nativeIsLandScape()) {
@ -79,7 +75,7 @@ public class AppActivity extends Cocos2dxActivity{
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Warning");
builder.setMessage("Open Wifi for debuging...");
builder.setMessage("Please open WIFI for debuging...");
builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
@ -89,7 +85,9 @@ public class AppActivity extends Cocos2dxActivity{
System.exit(0);
}
});
builder.setCancelable(false);
builder.setNegativeButton("Cancel", null);
builder.setCancelable(true);
builder.show();
}
}
@ -126,14 +124,6 @@ public class AppActivity extends Cocos2dxActivity{
return hostIPAdress;
}
public static String getSDCardPath() {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
String strSDCardPathString = Environment.getExternalStorageDirectory().getPath();
return strSDCardPathString;
}
return null;
}
private static native boolean nativeIsLandScape();
private static native boolean nativeIsDebug();

View File

@ -30,7 +30,6 @@
#import "AppDelegate.h"
#import "RootViewController.h"
#import "platform/ios/CCEAGLView-ios.h"
#include "ConfigParser.h"
@implementation AppController
@ -49,8 +48,6 @@ static AppDelegate s_sharedApplication;
// Override point for customization after application launch.
ConfigParser::getInstance()->readConfig();
// Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]

View File

@ -25,7 +25,7 @@
#import "RootViewController.h"
#import "cocos2d.h"
#import "CCEAGLView.h"
#import "platform/ios/CCEAGLView-ios.h"
#include "ConfigParser.h"
@implementation RootViewController

View File

@ -40,9 +40,9 @@
using namespace cocos2d;
bool g_landscape = false;
bool g_windTop = true;
bool g_windTop = false;
cocos2d::Size g_screenSize;
GLView* g_eglView = nullptr;
GLViewImpl* g_eglView = nullptr;
static AppController* g_nsAppDelegate=nullptr;
@ -58,6 +58,16 @@ std::string getCurAppPath(void)
return [[[NSBundle mainBundle] bundlePath] UTF8String];
}
std::string getCurAppName(void)
{
string appName = [[[NSProcessInfo processInfo] processName] UTF8String];
int found = appName.find(" ");
if (found!=std::string::npos)
appName = appName.substr(0,found);
return appName;
}
-(void) dealloc
{
Director::getInstance()->end();
@ -102,12 +112,12 @@ std::string getCurAppPath(void)
width = height;
height = tmpvalue;
}
g_windTop = true;
g_eglView = cocos2d::GLViewImpl::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor);
g_windTop = ConfigParser::getInstance()->isWindowTop();
g_eglView = GLViewImpl::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor);
auto director = Director::getInstance();
director->setOpenGLView(g_eglView);
window = g_eglView->getCocoaWindow();
window = glfwGetCocoaWindow(g_eglView->getWindow());
[NSApp setDelegate: self];
[self createViewMenu];
@ -336,7 +346,7 @@ void createSimulator(const char* viewName, float width, float height,bool isLand
{
if ([sender state] == NSOnState) return;
float scale = (float)[sender tag] / 100.0f;
(dynamic_cast<GLViewImpl*>(g_eglView))->setFrameZoomFactor(scale);
g_eglView->setFrameZoomFactor(scale);
[self updateView];
}

View File

@ -39,7 +39,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance
AppDelegate app;
int ret = Application::getInstance()->run();
#ifdef USE_WIN32_CONSOLE

View File

@ -22,6 +22,15 @@ local function main()
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)
-- initialize director
local director = cc.Director:getInstance()
--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)
cc.FileUtils:getInstance():addSearchPath("src")
cc.FileUtils:getInstance():addSearchPath("res")
cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 0)