Merge pull request #2 from chuanweizhang2013/v3luaruntime

modify luadebug and adjust code file
This commit is contained in:
cocoscodeide 2014-05-08 22:09:06 +08:00
commit 6efaa2fe8f
24 changed files with 871 additions and 679 deletions

File diff suppressed because it is too large Load Diff

View File

@ -21,21 +21,26 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching()
{
#ifdef COCOS2D_DEBUG
initRuntime();
string entryfile ="src/main.lua";
#if (COCOS2D_DEBUG>0)
initRuntime(entryfile);
#endif
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
ConfigParser::getInstance()->readConfig();
if (!ConfigParser::getInstance()->isInit()) {
ConfigParser::getInstance()->readConfig();
}
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,float frameZoomFactor = 1.0f);
createSimulator(title.c_str(),viewSize.width,viewSize.height);
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 = GLView::createWithRect(title.c_str(), Rect(0,0,viewSize.width,viewSize.height));
director->setOpenGLView(glview);
@ -48,14 +53,19 @@ bool AppDelegate::applicationDidFinishLaunching()
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
#ifdef COCOS2D_DEBUG
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
//register custom function
//LuaStack* stack = engine->getLuaStack();
//register_custom_function(stack->getLuaState());
#if (COCOS2D_DEBUG>0)
if (startRuntime())
return true;
#endif
auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);
engine->executeScriptFile("src/main.lua");
engine->executeScriptFile(entryfile.c_str());
return true;
}

View File

@ -16,36 +16,43 @@ ConfigParser *ConfigParser::getInstance(void)
return s_sharedInstance;
}
bool ConfigParser::isInit()
{
return _isInit;
}
void ConfigParser::readConfig()
{
_initViewSize.setSize(960,640);
_viewName="HelloLua";
_isInit = true;
string filecfg = "res/config.json";
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg);
FILE * pFile = fopen (fullPathFile.c_str() , "r");
if(pFile)
{
rapidjson::FileStream inputStream(pFile);
rapidjson::Document runtimecfgjson;
runtimecfgjson.ParseStream<0>(inputStream);
_docRootjson.ParseStream<0>(inputStream);
fclose(pFile);
if (runtimecfgjson.HasMember("init_view") && runtimecfgjson["init_view"].IsObject())
if (_docRootjson.HasMember("init_view") && _docRootjson["init_view"].IsObject())
{
const rapidjson::Value& objectInitView = runtimecfgjson["init_view"];
const rapidjson::Value& objectInitView = _docRootjson["init_view"];
if (objectInitView.HasMember("width") && objectInitView.HasMember("height"))
{
_initViewSize.width = objectInitView["width"].GetUint();
_initViewSize.height = objectInitView["height"].GetUint();
}
if (objectInitView.HasMember("name"))
if (objectInitView.HasMember("name") && objectInitView["name"].IsString())
{
_viewName = objectInitView["name"].GetString();
}
if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) {
_isLandscape = objectInitView["isLandscape"].GetBool();
}
}
if (runtimecfgjson.HasMember("simulator_screen_size"))
if (_docRootjson.HasMember("simulator_screen_size"))
{
const rapidjson::Value& ArrayScreenSize = runtimecfgjson["simulator_screen_size"];
const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"];
if (ArrayScreenSize.IsArray())
{
for (int i=0; i<ArrayScreenSize.Size(); i++)
@ -58,14 +65,20 @@ void ConfigParser::readConfig()
}
}
}
}
}
ConfigParser::ConfigParser(void)
ConfigParser::ConfigParser(void):_isInit(false),_isLandscape(true)
{
}
rapidjson::Document& ConfigParser::getConfigJsonRoot()
{
return _docRootjson;
}
string ConfigParser::getInitViewName()
{
return _viewName;
@ -76,6 +89,11 @@ Size ConfigParser::getInitViewSize()
return _initViewSize;
}
bool ConfigParser::isLanscape()
{
return _isLandscape;
}
int ConfigParser::getScreenSizeCount(void)
{
return (int)_screenSizeArray.size();

View File

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include "cocos2d.h"
#include "json/document.h"
using namespace std;
USING_NS_CC;
@ -32,14 +33,21 @@ public:
int getScreenSizeCount(void);
cocos2d::Size getInitViewSize();
string getInitViewName();
rapidjson::Document& getConfigJsonRoot();
const SimulatorScreenSize getScreenSize(int index);
bool isLanscape();
bool isInit();
private:
ConfigParser(void);
static ConfigParser *s_sharedInstance;
ScreenSizeArray _screenSizeArray;
cocos2d::Size _initViewSize;
string _viewName;
bool _isLandscape;
bool _isInit;
rapidjson::Document _docRootjson;
};
#endif // __CONFIG_PARSER_H__

View File

@ -31,6 +31,7 @@ THE SOFTWARE.
#include "json/stringbuffer.h"
#include "json/writer.h"
#include "LuaBasicConversions.h"
#include "VisibleRect.h"
#ifdef _WIN32
#include <direct.h>
@ -46,12 +47,13 @@ using namespace cocos2d;
std::string g_resourcePath;
static rapidjson::Document g_filecfgjson;
static string g_entryfile;
extern string getIPAddress();
const char* getRuntimeVersion()
{
return "1.1";
}
void startScript(string strDebugArg)
{
// register lua engine
@ -61,7 +63,7 @@ void startScript(string strDebugArg)
engine->executeString(strDebugArg.c_str());
}
cocos2d::log("debug args = %s",strDebugArg.c_str());
engine->executeScriptFile("src/main.lua");
engine->executeScriptFile(g_entryfile.c_str());
}
bool reloadScript(const string& modulefile)
@ -69,7 +71,7 @@ bool reloadScript(const string& modulefile)
string strfile = modulefile;
if (strfile.empty())
{
strfile = "src/main.lua";
strfile = g_entryfile;
}
auto director = Director::getInstance();
@ -87,95 +89,6 @@ bool reloadScript(const string& modulefile)
return (LuaEngine::getInstance()->reload(strfile.c_str())==0);
}
class VisibleRect
{
public:
static Rect getVisibleRect();
static Point left();
static Point right();
static Point top();
static Point bottom();
static Point center();
static Point leftTop();
static Point rightTop();
static Point leftBottom();
static Point rightBottom();
private:
static void lazyInit();
static Rect s_visibleRect;
};
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
// no lazy init
// Useful if we change the resolution in runtime
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return s_visibleRect;
}
Point VisibleRect::left()
{
lazyInit();
return Point(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::right()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::top()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::bottom()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
}
Point VisibleRect::center()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::leftTop()
{
lazyInit();
return Point(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::rightTop()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::leftBottom()
{
lazyInit();
return s_visibleRect.origin;
}
Point VisibleRect::rightBottom()
{
lazyInit();
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
}
class ConnectWaitLayer: public Layer
{
public:
@ -811,8 +724,23 @@ static void register_runtime_override_function(lua_State* tolua_S)
lua_pop(tolua_S, 1);
}
bool initRuntime()
bool initRuntime(string& entryfile)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#ifndef _DEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#ifdef NDEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#ifndef COCOS2D_DEBUG
return false;
#endif
#endif
g_entryfile = entryfile;
vector<string> searchPathArray;
searchPathArray=FileUtils::getInstance()->getSearchPaths();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
@ -835,6 +763,11 @@ bool initRuntime()
#endif
g_resourcePath=replaceAll(g_resourcePath,"\\","/");
if (g_resourcePath.at(g_resourcePath.length()-1) != '/')
{
g_resourcePath.append("/");
}
searchPathArray.insert(searchPathArray.begin(),g_resourcePath);
FileUtils::getInstance()->setSearchPaths(searchPathArray);
@ -843,17 +776,17 @@ bool initRuntime()
bool startRuntime()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#ifndef _DEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#ifdef NDEBUG
return false;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#ifndef _DEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#ifdef NDEBUG
return false;
#endif
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#ifndef COCOS2D_DEBUG
return false;
#ifndef COCOS2D_DEBUG
return false;
#endif
#endif

View File

@ -28,7 +28,7 @@ THE SOFTWARE.
#include <string>
using namespace std;
bool initRuntime();
bool initRuntime(string& entryfile);
bool startRuntime();
bool reloadScript(const string& modulefile);

View File

@ -0,0 +1,96 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "VisibleRect.h"
USING_NS_CC;
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
// no lazy init
// Useful if we change the resolution in runtime
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return s_visibleRect;
}
Vector2 VisibleRect::left()
{
lazyInit();
return Vector2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vector2 VisibleRect::right()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vector2 VisibleRect::top()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vector2 VisibleRect::bottom()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
}
Vector2 VisibleRect::center()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Vector2 VisibleRect::leftTop()
{
lazyInit();
return Vector2(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vector2 VisibleRect::rightTop()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Vector2 VisibleRect::leftBottom()
{
lazyInit();
return s_visibleRect.origin;
}
Vector2 VisibleRect::rightBottom()
{
lazyInit();
return Vector2(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
}

View File

@ -0,0 +1,25 @@
#ifndef __VISIBLERECT_H__
#define __VISIBLERECT_H__
#include "cocos2d.h"
class VisibleRect
{
public:
static cocos2d::Rect getVisibleRect();
static cocos2d::Vector2 left();
static cocos2d::Vector2 right();
static cocos2d::Vector2 top();
static cocos2d::Vector2 bottom();
static cocos2d::Vector2 center();
static cocos2d::Vector2 leftTop();
static cocos2d::Vector2 rightTop();
static cocos2d::Vector2 leftBottom();
static cocos2d::Vector2 rightBottom();
private:
static void lazyInit();
static cocos2d::Rect s_visibleRect;
};
#endif /* __VISIBLERECT_H__ */

View File

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

View File

@ -8,6 +8,7 @@ LOCAL_MODULE_FILENAME := libcocos2dlua
LOCAL_SRC_FILES := lua/main.cpp \
lua/Runtime_android.cpp \
../../Classes/VisibleRect.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/ConfigParser.cpp \
../../Classes/Runtime.cpp

View File

@ -50,6 +50,8 @@
50D7C96C17EBBEDF005D0B91 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D7C96B17EBBEDF005D0B91 /* OpenGL.framework */; };
50D7C96E17EBBEE6005D0B91 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D7C96D17EBBEE6005D0B91 /* AppKit.framework */; };
50D7C97017EBBEEC005D0B91 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D7C96F17EBBEEC005D0B91 /* IOKit.framework */; };
C033B51C191B337200D06937 /* VisibleRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C033B51A191B337200D06937 /* VisibleRect.cpp */; };
C033B51D191B337200D06937 /* VisibleRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C033B51A191B337200D06937 /* VisibleRect.cpp */; };
C03781B918BF655400FE4F13 /* res in Resources */ = {isa = PBXBuildFile; fileRef = C03781B718BF655400FE4F13 /* res */; };
C03781BA18BF655400FE4F13 /* res in Resources */ = {isa = PBXBuildFile; fileRef = C03781B718BF655400FE4F13 /* res */; };
C03781BB18BF655400FE4F13 /* src in Resources */ = {isa = PBXBuildFile; fileRef = C03781B818BF655400FE4F13 /* src */; };
@ -94,6 +96,8 @@
C03781F618BF65B100FE4F13 /* libluabindings iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B618BF654500FE4F13 /* libluabindings iOS.a */; };
C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; };
C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; };
C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; };
C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; };
C07828F818B4D72E00BD2287 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C07828F418B4D72E00BD2287 /* main.m */; };
C07828F918B4D72E00BD2287 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C07828F518B4D72E00BD2287 /* MainMenu.xib */; };
C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07828F718B4D72E00BD2287 /* SimulatorApp.mm */; };
@ -340,6 +344,8 @@
50D7C96B17EBBEDF005D0B91 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
50D7C96D17EBBEE6005D0B91 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
50D7C96F17EBBEEC005D0B91 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
C033B51A191B337200D06937 /* VisibleRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VisibleRect.cpp; path = ../Classes/VisibleRect.cpp; sourceTree = "<group>"; };
C033B51B191B337200D06937 /* VisibleRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VisibleRect.h; path = ../Classes/VisibleRect.h; sourceTree = "<group>"; };
C03781AE18BF654500FE4F13 /* cocos2d_lua_bindings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2d_lua_bindings.xcodeproj; path = "../../cocos2d-x/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj"; sourceTree = "<group>"; };
C03781B718BF655400FE4F13 /* res */ = {isa = PBXFileReference; lastKnownFileType = folder; name = res; path = ../../../res; sourceTree = "<group>"; };
C03781B818BF655400FE4F13 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = ../../../src; sourceTree = "<group>"; };
@ -362,6 +368,8 @@
C03781CD18BF656A00FE4F13 /* OpenglConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = OpenglConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/OpenglConstants.lua"; sourceTree = "<group>"; };
C03781CE18BF656A00FE4F13 /* StudioConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = StudioConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/StudioConstants.lua"; sourceTree = "<group>"; };
C0619CD61896894800872C26 /* Runtime_ios-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "Runtime_ios-mac.mm"; sourceTree = "<group>"; };
C06C3794191A1D1E00617BED /* ConfigParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConfigParser.cpp; path = ../Classes/ConfigParser.cpp; sourceTree = "<group>"; };
C06C3795191A1D1E00617BED /* ConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConfigParser.h; path = ../Classes/ConfigParser.h; sourceTree = "<group>"; };
C07828F418B4D72E00BD2287 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
C07828F518B4D72E00BD2287 /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
C07828F618B4D72E00BD2287 /* SimulatorApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimulatorApp.h; sourceTree = "<group>"; };
@ -615,6 +623,10 @@
F293BB7C15EB830F00256477 /* Classes */ = {
isa = PBXGroup;
children = (
C033B51A191B337200D06937 /* VisibleRect.cpp */,
C033B51B191B337200D06937 /* VisibleRect.h */,
C06C3794191A1D1E00617BED /* ConfigParser.cpp */,
C06C3795191A1D1E00617BED /* ConfigParser.h */,
C07828FB18B4DC6F00BD2287 /* Runtime.cpp */,
C07828FC18B4DC6F00BD2287 /* Runtime.h */,
C0619CD61896894800872C26 /* Runtime_ios-mac.mm */,
@ -914,8 +926,10 @@
files = (
C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */,
5023813317EBBCE400990C9B /* AppDelegate.cpp in Sources */,
C033B51D191B337200D06937 /* VisibleRect.cpp in Sources */,
C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */,
C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */,
C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */,
C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */,
C07828F818B4D72E00BD2287 /* main.m in Sources */,
C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */,
@ -928,7 +942,9 @@
files = (
5023812517EBBCAC00990C9B /* RootViewController.mm in Sources */,
F293BB9C15EB831F00256477 /* AppDelegate.cpp in Sources */,
C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */,
5023812417EBBCAC00990C9B /* main.m in Sources */,
C033B51C191B337200D06937 /* VisibleRect.cpp in Sources */,
C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */,
C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */,
5023811817EBBCAC00990C9B /* AppController.mm in Sources */,

View File

@ -30,6 +30,7 @@
#import "AppDelegate.h"
#import "RootViewController.h"
#import "CCEAGLView.h"
#include "ConfigParser.h"
@implementation AppController
@ -43,7 +44,9 @@ 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

@ -64,8 +64,9 @@
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@ -26,6 +26,7 @@
#import "RootViewController.h"
#import "cocos2d.h"
#import "CCEAGLView.h"
#include "ConfigParser.h"
@implementation RootViewController
@ -55,18 +56,32 @@
// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
if (ConfigParser::getInstance()->isLanscape()) {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}else{
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskAllButUpsideDown;
if (ConfigParser::getInstance()->isLanscape()) {
return UIInterfaceOrientationMaskLandscape;
}else{
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
#endif
}
- (BOOL) shouldAutorotate {
return YES;
if (ConfigParser::getInstance()->isLanscape()) {
return YES;
}else{
return NO;
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

View File

@ -1,9 +1,4 @@
//
// main.m
// HelloLua
//
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import <UIKit/UIKit.h>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1060" defaultVersion="1090" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<deployment version="1060" defaultVersion="1070" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AppController">
@ -121,10 +121,9 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Control" id="ysx-9J-ekz">
<items>
<menuItem title="Reload" id="hfu-OP-8X3">
<modifierMask key="keyEquivalentModifierMask"/>
<menuItem title="Relaunch" keyEquivalent="r" id="hfu-OP-8X3">
<connections>
<action selector="onReloadScript:" target="-1" id="ar6-Pq-fmZ"/>
<action selector="onRelaunch:" target="-1" id="XXg-eJ-YSn"/>
</connections>
</menuItem>
</items>
@ -143,4 +142,4 @@
</connections>
</customObject>
</objects>
</document>
</document>

View File

@ -26,7 +26,7 @@
#include <string>
#include "AppDelegate.h"
void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f);
void createSimulator(const char* viewName, float width, float height,bool isLandscape = true,float frameZoomFactor = 1.0f);
@interface AppController : NSObject <NSApplicationDelegate, NSWindowDelegate>
{
@ -46,7 +46,7 @@ void createSimulator(const char* viewName, float width, float height,float frame
- (IBAction) onScreenPortait:(id)sender;
- (IBAction) onScreenLandscape:(id)sender;
- (IBAction) onScreenZoomOut:(id)sender;
- (IBAction) onReloadScript:(id)sender;
- (IBAction) onRelaunch:(id)sender;
@end

View File

@ -117,10 +117,17 @@ std::string getCurAppPath(void)
[window makeKeyAndOrderFront:self];
}
void createSimulator(const char* viewName, float width, float height,float frameZoomFactor)
void createSimulator(const char* viewName, float width, float height,bool isLandscape,float frameZoomFactor)
{
if(g_nsAppDelegate)
{
if((isLandscape && height > width) || (!isLandscape && width > height))
{
float tmpvalue =width;
width = height;
height = width;
}
[g_nsAppDelegate createSimulator:[NSString stringWithUTF8String:viewName] viewWidth:width viewHeight:height factor:frameZoomFactor];
}
@ -281,9 +288,26 @@ void createSimulator(const char* viewName, float width, float height,float frame
[self updateView];
}
- (IBAction) onReloadScript:(id)sender
- (void) launch:(NSArray*)args
{
reloadScript("");
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithObject:args forKey:NSWorkspaceLaunchConfigurationArguments];
NSError *error = [[[NSError alloc] init] autorelease];
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
options:NSWorkspaceLaunchNewInstance
configuration:configuration error:&error];
}
- (void) relaunch:(NSArray*)args
{
[self launch:args];
[[NSApplication sharedApplication] terminate:self];
}
- (IBAction) onRelaunch:(id)sender
{
NSArray* args=[[NSArray alloc] initWithObjects:@" ", nil];
[self relaunch:args];
}

View File

@ -179,6 +179,7 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)"</C
<ClInclude Include="..\Classes\AppDelegate.h" />
<ClInclude Include="..\Classes\ConfigParser.h" />
<ClInclude Include="..\Classes\Runtime.h" />
<ClInclude Include="..\Classes\VisibleRect.h" />
<ClInclude Include="main.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="SimulatorWindow.h" />
@ -187,6 +188,7 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)"</C
<ClCompile Include="..\Classes\AppDelegate.cpp" />
<ClCompile Include="..\Classes\ConfigParser.cpp" />
<ClCompile Include="..\Classes\Runtime.cpp" />
<ClCompile Include="..\Classes\VisibleRect.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Runtime_win32.cpp" />
<ClCompile Include="SimulatorWindow.cpp" />

View File

@ -28,6 +28,9 @@
<ClInclude Include="..\Classes\ConfigParser.h">
<Filter>Classes</Filter>
</ClInclude>
<ClInclude Include="..\Classes\VisibleRect.h">
<Filter>Classes</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Classes\AppDelegate.cpp">
@ -48,6 +51,9 @@
<ClCompile Include="..\Classes\ConfigParser.cpp">
<Filter>Classes</Filter>
</ClCompile>
<ClCompile Include="..\Classes\VisibleRect.cpp">
<Filter>Classes</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="game.rc">

View File

@ -301,13 +301,20 @@ INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
return (INT_PTR)FALSE;
}
void createSimulator(const char* viewName, float width, float height, float frameZoomFactor)
void createSimulator(const char* viewName, float width, float height, bool isLandscape, float frameZoomFactor)
{
if (g_eglView)
{
return;
}
if((isLandscape && height > width) || (!isLandscape && width > height))
{
float tmpvalue =width;
width = height;
height = width;
}
g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor);
auto director = Director::getInstance();
director->setOpenGLView(g_eglView);

View File

@ -28,6 +28,6 @@ THE SOFTWARE.
/************************
@brief create Simulator
*********************************/
void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f);
void createSimulator(const char* viewName, float width, float height,bool isLandscape = true,float frameZoomFactor = 1.0f);
#endif /* __PROJECT_CONFIG_H_ */

View File

@ -28,7 +28,7 @@ def setAndroidOrientation(orientation):
except Exception:
print("parser %s file failure" % filePath)
def setConfigJson(name,viewWith,viewHeight):
def setConfigJson(name,viewWith,viewHeight,orientation):
dir_path = os.path.dirname(__file__)
filePath = os.path.join(dir_path,"res/config.json")
try:
@ -42,6 +42,10 @@ def setConfigJson(name,viewWith,viewHeight):
cfg_content["init_view"]["width"] = viewWith
if viewHeight:
cfg_content["init_view"]["height"] = viewHeight
if orientation:
cfg_content["init_view"]["isLandscape"] = True
else:
cfg_content["init_view"]["isLandscape"] = False
else:
initViewObject={}
if name:
@ -50,6 +54,11 @@ def setConfigJson(name,viewWith,viewHeight):
initViewObject["width"] = viewWith
if viewHeight:
initViewObject["height"] = viewHeight
if orientation:
initViewObject["isLandscape"] = True
else:
initViewObject["isLandscape"] = False
cfg_content["init_view"] = initViewObject
f = open(filePath,"w")
json.dump(cfg_content,f,indent=4)

View File

@ -1,5 +1,6 @@
{
"init_view":{
"isLandscape": true,
"name": "HelloLua",
"width": 960,
"height": 640