Skip to content

Commit

Permalink
Merge pull request #321 from minggo/iss538
Browse files Browse the repository at this point in the history
[iOS] fixed #538: add template of lua for xcode3
  • Loading branch information
minggo committed Jun 24, 2011
2 parents 42ce3c2 + 5677e74 commit ea0bf7c
Show file tree
Hide file tree
Showing 15 changed files with 545 additions and 9 deletions.
51 changes: 42 additions & 9 deletions install-templates-xcode.sh
Expand Up @@ -2,7 +2,7 @@

echo 'cocos2d-x template installer'

COCOS2D_VER='cocos2d-0.99.5-x-0.8.4'
COCOS2D_VER='cocos2d-0.99.5-x-0.8.5'
BASE_TEMPLATE_DIR="/Library/Application Support/Developer/Shared/Xcode"
BASE_TEMPLATE_USER_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode"

Expand Down Expand Up @@ -141,7 +141,7 @@ print_template_banner(){

# copies project-based templates
copy_xcode3_project_templates(){
if [[ $user_dir ]]; then
if [[ $user_dir ]]; then
TEMPLATE_DIR="${BASE_TEMPLATE_USER_DIR}/Project Templates/${COCOS2D_VER}/"
else
TEMPLATE_DIR="${BASE_TEMPLATE_DIR}/Project Templates/${COCOS2D_VER}/"
Expand Down Expand Up @@ -175,7 +175,7 @@ copy_xcode3_project_templates(){
check_dst_dir

echo ...copying template files
copy_files template/xcode3/cocos2d-x_box2d_app/ "$DST_DIR"
copy_files template/xcode3/cocos2d-x_box2d_app/ "$DST_DIR"

copy_base_files

Expand All @@ -192,12 +192,27 @@ copy_xcode3_project_templates(){
check_dst_dir

echo ...copying template files
copy_files template/xcode3/cocos2d-x_chipmunk_app/ "$DST_DIR"
copy_files template/xcode3/cocos2d-x_chipmunk_app/ "$DST_DIR"

copy_base_files

echo ...coping chipmunk files
copy_files chipmunk "$LIBS_DIR"

print_template_banner "Installing cocos2d-x iOS + lua template"

DST_DIR="$TEMPLATE_DIR""cocos2d-x lua Application/"
LIBS_DIR="$DST_DIR"libs

check_dst_dir

echo ...copying template files
copy_files template/xcode3/cocos2d-x_lua_app/ "$DST_DIR"

copy_base_files

echo ...coping lua files
copy_files lua "$LIBS_DIR"

echo done!
}
Expand Down Expand Up @@ -314,9 +329,27 @@ copy_xcode4_project_templates(){

}

# copy Xcode4 templates
copy_xcode4_project_templates
select_template_version(){
echo "select the template version to install"
echo "3 for xcode3"
echo "4 for xcode4"
echo "input nothing for all"

read select

if [[ "$select" == 3 ]]; then
copy_xcode3_project_templates
fi

if [[ "$select" == 4 ]]; then
copy_xcode4_project_templates
fi

if [[ "$select""aaaa" == "aaaa" ]]; then
copy_xcode3_project_templates
copy_xcode4_project_templates
fi

}

# copy Xcode3 templates
copy_xcode3_project_templates
# copy_xcode3_file_templates
select_template_version
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,160 @@
#include "___PROJECTNAMEASIDENTIFIER___AppDelegate.h"

#include "cocos2d.h"

USING_NS_CC;

AppDelegate::AppDelegate()
:m_pLuaEngine(NULL)
{
}

AppDelegate::~AppDelegate()
{
CCScriptEngineManager::sharedScriptEngineManager()->removeScriptEngine();
CC_SAFE_DELETE(m_pLuaEngine);
}

bool AppDelegate::initInstance()
{
bool bRet = false;
do
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)

// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));

#endif // CC_PLATFORM_WIN32

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.

#endif // CC_PLATFORM_IOS

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
// the default setting is to create a fullscreen view
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp

#endif // CC_PLATFORM_ANDROID

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)

// Initialize OpenGLView instance, that release by CCDirector when application terminate.
// The HelloWorld is designed as HVGA.
CCEGLView* pMainWnd = new CCEGLView(this);
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));

#ifndef _TRANZDA_VM_
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
#endif

#endif // CC_PLATFORM_WOPHONE

#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
bRet = true;
} while (0);
return bRet;
}

bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
// pDirector->enableRetinaDisplay(true);

// turn on display FPS
pDirector->setDisplayFPS(true);

// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);

// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);

// register lua engine
m_pLuaEngine = new LuaEngine;
CCScriptEngineManager::sharedScriptEngineManager()->setScriptEngine(m_pLuaEngine);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
unsigned long size;
char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);

if (pFileContent)
{
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
char *pCodes = new char[size + 1];
pCodes[size] = '\0';
memcpy(pCodes, pFileContent, size);
delete[] pFileContent;

CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
delete []pCodes;
}
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
// CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile("./../../HelloLua/Resource/hello.lua");
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile("./../../HelloLua/Resource/hello.lua");

/*
* Another way to run lua script.
* Load the file into memory and run it.
*
unsigned long size;
char *pFileContent = (char*)CCFileUtils::getFileData("./../../HelloLua/Resource/hello.lua", "r", &size);
if (pFileContent)
{
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
char *pTmp = new char[size + 1];
pTmp[size] = '\0';
memcpy(pTmp, pFileContent, size);
delete[] pFileContent;
string code(pTmp);
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteScriptFile(code);
delete []pTmp;
}
*/

#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
printf("%s", path.c_str());
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile(path.c_str());
#endif

return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->pause();

// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->resume();

// if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
@@ -0,0 +1,47 @@
#ifndef ___PROJECTNAMEASIDENTIFIER___AppDelegate_H__
#define ___PROJECTNAMEASIDENTIFIER___AppDelegate_H__

#include "CCApplication.h"
#include "LuaEngine.h"

/**
@brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class AppDelegate : private cocos2d::CCApplication
{
public:
AppDelegate();
virtual ~AppDelegate();

/**
@brief Implement for initialize OpenGL instance, set source path, etc...
*/
virtual bool initInstance();

/**
@brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching();

/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground();

/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground();

private:
LuaEngine* m_pLuaEngine;
};

#endif // ___PROJECTNAMEASIDENTIFIER___AppDelegate_H__

22 changes: 22 additions & 0 deletions template/xcode3/cocos2d-x_lua_app/LICENSE.cocos2d-x
@@ -0,0 +1,22 @@
cocos2d-x http://www.cocos2d-x.org

Copyright (c) 2008-2010 - (see each file to see the different copyright owners)


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.
10 changes: 10 additions & 0 deletions template/xcode3/cocos2d-x_lua_app/LICENSE.lua
@@ -0,0 +1,10 @@
License for Lua 5.0 and later versions
http://www.lua.org/license.html

Copyright © 1994Ð2011 Lua.org, PUC-Rio.

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.
@@ -0,0 +1 @@
d7290c34702d1c6bdb368acb060d93b42d5deff8

0 comments on commit ea0bf7c

Please sign in to comment.