Merge pull request #1276 from dumganhar/gles20

fixed #1455: Adding xcode template for cocos2dx-js. Thank rohankuruvilla.
This commit is contained in:
James Chen 2012-08-31 19:51:43 -07:00
commit 45a712e932
14 changed files with 517 additions and 18 deletions

View File

@ -94,6 +94,7 @@ copy_base_files(){
echo ...copying cocos2dx files
copy_files cocos2dx "$LIBS_DIR"
echo ...copying CocosDenshion files
copy_files CocosDenshion "$LIBS_DIR"
}
@ -101,7 +102,7 @@ copy_base_files(){
copy_cocos2d_files(){
echo ...copying cocos2d files
copy_files cocos2dx "$LIBS_DIR"
copy_files licenses/LICENSE_cocos2d-x.txt "$LIBS_DIR"
copy_files licenses/LICENSE_cocos2d-x.txt "$LIBS_DIR"
}
copy_cocosdenshion_files(){
@ -186,27 +187,47 @@ copy_xcode4_project_templates(){
LIBS_DIR="$DST_DIR""lib_box2d.xctemplate/libs/"
mkdir -p "$LIBS_DIR"
mkdir -p "$LIBS_DIR"
echo ...copying Box2D files
copy_files external/Box2D "$LIBS_DIR"
copy_files licenses/LICENSE_box2d.txt "$LIBS_DIR"
copy_files licenses/LICENSE_box2d.txt "$LIBS_DIR"
echo done!
print_template_banner "Installing Xcode 4 lua iOS template"
print_template_banner "Installing Xcode 4 lua iOS template"
LIBS_DIR="$DST_DIR""lib_lua.xctemplate/libs/"
mkdir -p "$LIBS_DIR"
echo ...copying lua files
copy_files scripting/lua "$LIBS_DIR"
copy_files licenses/LICENSE_lua.txt "$LIBS_DIR"
copy_files licenses/LICENSE_tolua++.txt "$LIBS_DIR"
echo done!
print_template_banner "Installing Xcode 4 JS iOS template"
LIBS_DIR="$DST_DIR""lib_js.xctemplate/libs/javascript"
mkdir -p "$LIBS_DIR"
echo ...copying js files
copy_files scripting/javascript/bindings "$LIBS_DIR"
copy_files licenses/LICENSE_js.txt "$LIBS_DIR"
echo done!
LIBS_DIR="$DST_DIR""lib_lua.xctemplate/libs/"
mkdir -p "$LIBS_DIR"
echo ...copying spidermonkey files
echo ...copying lua files
copy_files scripting/lua "$LIBS_DIR"
copy_files licenses/LICENSE_lua.txt "$LIBS_DIR"
copy_files licenses/LICENSE_tolua++.txt "$LIBS_DIR"
LIBS_DIR="$DST_DIR""lib_spidermonkey.xctemplate/libs/javascript"
mkdir -p "$LIBS_DIR"
copy_files scripting/javascript/spidermonkey-ios "$LIBS_DIR"
echo done!
echo done!
# Move File Templates to correct position
# DST_DIR="$HOME/Library/Developer/Xcode/Templates/File Templates/cocos2d/"

View File

@ -0,0 +1,92 @@
#include "AppDelegate.h"
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
#include "ScriptingCore.h"
#include "cocos2dx.hpp"
#include "cocos2d_specifics.hpp"
#include "js_bindings_chipmunk_manual.hpp"
#include "js_bindings_chipmunk_functions.hpp"
USING_NS_CC;
using namespace CocosDenshion;
AppDelegate::AppDelegate()
{
}
AppDelegate::~AppDelegate()
{
// SimpleAudioEngine::end();
}
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->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
CCScene * pScene = CCScene::create();
ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx);
sc->addRegisterCallback(register_cocos2dx_js_extensions);
sc->addRegisterCallback(register_chipmunk_manual);
sc->addRegisterCallback(register_CCPhysicsSprite);
sc->start();
CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
ScriptingCore::getInstance()->runScript("hello.js");
return true;
}
void handle_signal(int signal) {
static int internal_state = 0;
ScriptingCore* sc = ScriptingCore::getInstance();
// should start everything back
CCDirector* director = CCDirector::sharedDirector();
if (director->getRunningScene()) {
director->popToRootScene();
} else {
CCPoolManager::sharedPoolManager()->finalize();
if (internal_state == 0) {
//sc->dumpRoot(NULL, 0, NULL);
sc->start();
internal_state = 1;
} else {
sc->runScript("hello.js");
internal_state = 0;
}
}
}
// 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()->stopAnimation();
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->startAnimation();
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
}

View File

@ -0,0 +1,45 @@
//
// GCTestAppDelegate.h
// GCTest
//
// Created by Rohan Kuruvilla on 06/08/2012.
// Copyright __MyCompanyName__ 2012. All rights reserved.
//
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_
#include "CCApplication.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 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();
};
#endif // _APP_DELEGATE_H_

View File

@ -0,0 +1,8 @@
//
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif

View File

@ -0,0 +1,29 @@
try {
cc.p = cc.p || function( x, y ) {
return {x:x, y:y};
};
cc.c4b = cc.c4 || function (r, g, b, o) {
return {r: r, g: g, b: b, a: o};
};
director = cc.Director.getInstance();
winSize = director.getWinSize();
var scene = new cc.Scene();
var layer = new cc.LayerGradient();
layer.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
var lab = "Houston we have liftoff!";
var label = cc.LabelTTF.create(lab, "Arial", 28);
layer.addChild(label, 1);
label.setPosition( cc.p(winSize.width / 2, winSize.height / 2));
scene.addChild(layer);
director.runWithScene(scene);
} catch(e) {log(e);}

Binary file not shown.

View File

@ -0,0 +1,33 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
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.
****************************************************************************/
@class RootViewController;
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
UIWindow *window;
RootViewController *viewController;
}
@end

View File

@ -0,0 +1,109 @@
//
// ___PROJECTNAMEASIDENTIFIER___AppController.mm
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppController.h"
#import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppController
#pragma mark -
#pragma mark Application lifecycle
// cocos2d application instance
static AppDelegate s_sharedApplication;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
// Use RootViewController manage EAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
viewController.view = __glView;
// Set RootViewController to window
[window addSubview: viewController.view];
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden: YES];
cocos2d::CCApplication::sharedApplication()->run();
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
cocos2d::CCDirector::sharedDirector()->pause();
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
cocos2d::CCDirector::sharedDirector()->resume();
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground();
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground();
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
cocos2d::CCDirector::sharedDirector()->purgeCachedData();
}
- (void)dealloc {
[super dealloc];
}
@end

View File

@ -0,0 +1,33 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2010 Ricardo Quesada
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.
****************************************************************************/
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController {
}
@end

View File

@ -0,0 +1,78 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2010 Ricardo Quesada
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.
****************************************************************************/
#import "RootViewController.h"
@implementation RootViewController
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end

View File

@ -0,0 +1,15 @@
//
// main.m
// HelloLua
//
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
[pool release];
return retVal;
}

View File

@ -1 +1 @@
c62c8fc39eb5a5c0b9dde4f0cffa9815d032699b
8bf975e465dbd53b0042a7d6a96c2d98240dd881

View File

@ -2,32 +2,46 @@ pushd ../../
echo "generating libcocos2dx"
mkdir -p template/xcode4/lib_cocos2dx.xctemplate
python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 third_party CCImage.cpp CCThread.cpp proj.ios CCFileUtilsCommon_cpp.h CCImageCommon_cpp.h CCFileUtils.cpp Android.mk mac" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist
python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 blackberry linux third_party CCImage.cpp CCThread.cpp proj.ios CCFileUtilsCommon_cpp.h CCImageCommon_cpp.h CCFileUtils.cpp Android.mk mac" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist
echo "generating libcocosdenshion"
mkdir -p template/xcode4/lib_cocosdenshion.xctemplate
python ./tools/xcode4_template_generator/template_generator.py --directory CocosDenshion --identifier libcocosdenshion --prefix libs --exclude "android win32 third_party Android.mk mac" > ./template/xcode4/lib_cocosdenshion.xctemplate/TemplateInfo.plist
python ./tools/xcode4_template_generator/template_generator.py --directory CocosDenshion --identifier libcocosdenshion --prefix libs --exclude "android win32 blackberry linux third_party Android.mk mac" > ./template/xcode4/lib_cocosdenshion.xctemplate/TemplateInfo.plist
echo "generating libbox2d"
mkdir -p template/xcode4/lib_box2d.xctemplate
pushd external
python ../tools/xcode4_template_generator/template_generator.py --directory Box2D --identifier libbox2d --prefix libs --exclude "android win32 Android.mk" > ../template/xcode4/lib_box2d.xctemplate/TemplateInfo.plist
python ../tools/xcode4_template_generator/template_generator.py --directory Box2D --identifier libbox2d --prefix libs --exclude "android win32 blackberry linux Android.mk" > ../template/xcode4/lib_box2d.xctemplate/TemplateInfo.plist
popd
echo "generating libchipmunk"
mkdir -p template/xcode4/lib_chipmunk.xctemplate
pushd external
python ../tools/xcode4_template_generator/template_generator.py --directory chipmunk --identifier libchipmunk --prefix libs --exclude "android win32 Android.mk CMakeFiles Makefile" > ../template/xcode4/lib_chipmunk.xctemplate/TemplateInfo.plist
python ../tools/xcode4_template_generator/template_generator.py --directory chipmunk --identifier libchipmunk --prefix libs --exclude "android win32 blackberry linux Android.mk CMakeFiles Makefile" > ../template/xcode4/lib_chipmunk.xctemplate/TemplateInfo.plist
popd
echo "generating liblua"
mkdir -p template/xcode4/lib_lua.xctemplate
pushd scripting
python ../tools/xcode4_template_generator/template_generator.py --directory lua --identifier liblua --prefix libs --append ../tools/xcode4_template_generator/template_lua_patch.txt --exclude "android win32 Makefile CMakeFiles" > ../template/xcode4/lib_lua.xctemplate/TemplateInfo.plist
python ../tools/xcode4_template_generator/template_generator.py --directory lua --identifier liblua --prefix libs --append ../tools/xcode4_template_generator/template_lua_patch.txt --exclude "android win32 blackberry linux Makefile CMakeFiles" > ../template/xcode4/lib_lua.xctemplate/TemplateInfo.plist
popd
echo "generating libjs"
mkdir -p template/xcode4/lib_js.xctemplate
pushd scripting
python ../tools/xcode4_template_generator/template_generator.py --directory javascript/bindings --identifier libjs --prefix libs --append ../tools/xcode4_template_generator/template_js_patch.txt --exclude "Android.mk helper.js sample.js" > ../template/xcode4/lib_js.xctemplate/TemplateInfo.plist
popd
echo "generating libspidermonkey"
mkdir -p template/xcode4/lib_spidermonkey.xctemplate
pushd scripting
python ../tools/xcode4_template_generator/template_generator.py --directory javascript/spidermonkey-ios --identifier libspidermonkey --exclude "bin host" --prefix libs > ../template/xcode4/lib_spidermonkey.xctemplate/TemplateInfo.plist
popd
echo "generating libextensions"
python ./tools/xcode4_template_generator/template_generator.py --directory extensions --identifier libextensions --prefix libs --exclude "proj.win32 Android.mk" > ./template/xcode4/lib_extensions.xctemplate/TemplateInfo.plist
python ./tools/xcode4_template_generator/template_generator.py --directory extensions --identifier libextensions --prefix libs --exclude "proj.win32 proj.blackberry proj.linux Android.mk CCEditBoxImplAndroid.cpp CCEditBoxImplAndroid.h" > ./template/xcode4/lib_extensions.xctemplate/TemplateInfo.plist
echo "done"

View File

@ -0,0 +1,22 @@
<key>Project</key>
<dict>
<key>Configurations</key>
<dict>
<key>Debug</key>
<dict>
<key>GCC_PREPROCESSOR_DEFINITIONS</key>
<array>
<string>COCOS2D_JAVASCRIPT</string>
</array>
</dict>
<key>Release</key>
<dict>
<key>GCC_PREPROCESSOR_DEFINITIONS</key>
<array>
<string>COCOS2D_JAVASCRIPT</string>
</array>
</dict>
</dict>
</dict>