2013-01-25 10:29:39 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
#include "PlayerStatus.h"
|
2013-03-20 14:27:46 +08:00
|
|
|
#include "MainSceneHelper.h"
|
2013-01-25 10:29:39 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "SimpleAudioEngine.h"
|
|
|
|
#include "ScriptingCore.h"
|
2013-03-13 05:18:45 +08:00
|
|
|
#include "generated/jsb_cocos2dx_auto.hpp"
|
2013-03-20 14:27:46 +08:00
|
|
|
#include "generated/jsb_cocos2dx_extension_auto.hpp"
|
|
|
|
#include "jsb_cocos2dx_extension_manual.h"
|
2013-01-25 10:29:39 +08:00
|
|
|
#include "cocos2d_specifics.hpp"
|
|
|
|
#include "js_bindings_chipmunk_registration.h"
|
|
|
|
#include "js_bindings_ccbreader.h"
|
2013-03-20 14:27:46 +08:00
|
|
|
#include "js_bindings_system_registration.h"
|
2013-04-10 06:29:35 +08:00
|
|
|
#include "jsb_opengl_registration.h"
|
2013-04-24 09:03:54 +08:00
|
|
|
#include "platform/CCDevice.h"
|
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
|
|
|
|
|
2013-04-24 07:47:14 +08:00
|
|
|
static bool firstTime = true;
|
2013-01-25 10:29:39 +08:00
|
|
|
|
2013-04-26 02:36:25 +08:00
|
|
|
static bool isPortraitApp = true;
|
2013-04-26 09:13:03 +08:00
|
|
|
char *_cocosplayer_log_buf = NULL;
|
|
|
|
|
2013-04-26 02:36:25 +08:00
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace CocosDenshion;
|
2013-04-18 08:24:59 +08:00
|
|
|
CCScene *mainScene;
|
2013-01-25 10:29:39 +08:00
|
|
|
|
2013-04-18 08:24:59 +08:00
|
|
|
AppDelegate::AppDelegate(): isRetina(false), isIPhone(false)
|
2013-01-25 10:29:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
CCScriptEngineManager::sharedManager()->purgeSharedManager();
|
|
|
|
}
|
|
|
|
|
2013-04-18 08:24:59 +08:00
|
|
|
|
|
|
|
bool runMainScene() {
|
|
|
|
/* Push the new scene with a fancy transition. */
|
|
|
|
ccColor3B transitionColor;
|
|
|
|
transitionColor.r = 0;
|
|
|
|
transitionColor.g = 0;
|
|
|
|
transitionColor.b = 0;
|
|
|
|
|
|
|
|
mainScene = PlayerStatus::loadMainScene("StatusLayer.ccbi");
|
2013-04-24 07:47:14 +08:00
|
|
|
|
|
|
|
if(CCDirector::sharedDirector()->getRunningScene() != NULL && CCDirector::sharedDirector()->getRunningScene() != mainScene) {
|
2013-04-18 08:24:59 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5f, mainScene, transitionColor));
|
2013-04-24 07:47:14 +08:00
|
|
|
} else if(CCDirector::sharedDirector()->getRunningScene() != NULL) {
|
|
|
|
|
|
|
|
}else {
|
2013-04-18 08:24:59 +08:00
|
|
|
CCDirector::sharedDirector()->runWithScene(CCTransitionFade::create(0.5f, mainScene, transitionColor));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
void handle_ccb_run() {
|
2013-01-25 21:52:35 +08:00
|
|
|
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
|
2013-04-26 02:36:25 +08:00
|
|
|
SimpleAudioEngine::sharedEngine()->end();
|
2013-04-23 15:58:25 +08:00
|
|
|
CCFileUtils::sharedFileUtils()->loadFilenameLookupDictionaryFromFile("fileLookup.plist");
|
2013-01-25 21:52:35 +08:00
|
|
|
ScriptingCore::getInstance()->runScript("main.js");
|
2013-01-25 10:29:39 +08:00
|
|
|
}
|
|
|
|
|
2013-04-27 04:40:49 +08:00
|
|
|
bool handle_eval_script(const char *script, jsval *out) {
|
|
|
|
ScriptingCore::getInstance()->evalString(script, out);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
void handle_connected() {
|
2013-04-24 09:03:54 +08:00
|
|
|
CCBHelper::setStatusMessage("Connected!");
|
2013-01-25 10:29:39 +08:00
|
|
|
}
|
|
|
|
|
2013-04-24 07:47:14 +08:00
|
|
|
void resetCocosApp();
|
|
|
|
|
|
|
|
void initViews(CCSize designSize) {
|
|
|
|
(CCScriptEngineManager::sharedManager())->removeScriptEngine();
|
|
|
|
resetCocosApp();
|
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
|
|
|
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
|
|
|
|
pDirector->setProjection(kCCDirectorProjection2D);
|
|
|
|
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setViewValues(CCEGLView *pView, CCSize frameSize, CCSize designSize) {
|
2013-04-26 09:15:11 +08:00
|
|
|
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
|
|
|
|
((AppDelegate *)CCApplication::sharedApplication())->initGameView();
|
2013-04-24 07:47:14 +08:00
|
|
|
}
|
|
|
|
|
2013-04-10 06:29:35 +08:00
|
|
|
void handle_set_orient(bool isPortrait) {
|
2013-04-24 09:03:54 +08:00
|
|
|
cocos2d::CCEGLView* pView = CCEGLView::sharedOpenGLView();
|
2013-04-24 07:47:14 +08:00
|
|
|
if (pView != NULL)
|
|
|
|
{
|
|
|
|
CCSize frameSize = pView->getFrameSize();
|
|
|
|
CCSize designSize = pView->getDesignResolutionSize();
|
|
|
|
if (((frameSize.width > frameSize.height && isPortrait))
|
|
|
|
|| (frameSize.width < frameSize.height && !isPortrait)) {
|
2013-04-26 09:15:11 +08:00
|
|
|
isPortraitApp = isPortrait;
|
|
|
|
pView->setFrameSize(frameSize.height, frameSize.width);
|
2013-04-24 07:47:14 +08:00
|
|
|
setViewValues(pView, frameSize, designSize);
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 06:29:35 +08:00
|
|
|
}
|
|
|
|
|
2013-04-26 09:17:29 +08:00
|
|
|
void openEditBox();
|
|
|
|
void updatePairingLabel(const char * label) {
|
|
|
|
if(!label) {
|
|
|
|
PlayerStatus::pairingLabel = "";
|
|
|
|
} else {
|
|
|
|
PlayerStatus::pairingLabel = label;
|
2013-04-26 02:36:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-18 08:24:59 +08:00
|
|
|
void handle_set_message(const char* msg) {
|
|
|
|
CCBHelper::setInstructionsMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_set_status(const char* msg) {
|
|
|
|
CCBHelper::setStatusMessage(msg);
|
|
|
|
}
|
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
void handle_disconnected() {
|
2013-04-24 09:03:54 +08:00
|
|
|
CCBHelper::setStatusMessage("Disconnected");
|
2013-01-25 10:29:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_ccb_stop() {
|
2013-04-26 02:36:25 +08:00
|
|
|
SimpleAudioEngine::sharedEngine()->end();
|
2013-04-18 08:24:59 +08:00
|
|
|
runMainScene();
|
2013-01-25 10:29:39 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 15:58:25 +08:00
|
|
|
void sendLogMsg(const char *msg);
|
|
|
|
|
|
|
|
|
2013-04-26 09:13:03 +08:00
|
|
|
void cocosPlayerNetworkLog(const char * pszFormat, ...)
|
2013-04-23 15:58:25 +08:00
|
|
|
{
|
|
|
|
printf("Cocos2d: ");
|
|
|
|
char szBuf[kMaxLogLen+1] = {0};
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, pszFormat);
|
|
|
|
vsnprintf(szBuf, kMaxLogLen, pszFormat, ap);
|
|
|
|
va_end(ap);
|
|
|
|
printf("%s", szBuf);
|
|
|
|
printf("\n");
|
|
|
|
sendLogMsg(szBuf);
|
|
|
|
}
|
2013-04-26 09:13:03 +08:00
|
|
|
|
|
|
|
void cocosplayer_js_log(const char *format, ...) {
|
|
|
|
if (_cocosplayer_log_buf == NULL) {
|
|
|
|
_cocosplayer_log_buf = (char *)calloc(sizeof(char), kMaxLogLen+1);
|
|
|
|
}
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, format);
|
|
|
|
int len = vsnprintf(_cocosplayer_log_buf, kMaxLogLen, format, vl);
|
|
|
|
va_end(vl);
|
|
|
|
if (len) {
|
|
|
|
cocosPlayerNetworkLog("CocosPlayer: %s\n", _cocosplayer_log_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool JS_cocosPlayerLog(JSContext* cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
|
|
|
if (argc > 0) {
|
|
|
|
JSString *string = NULL;
|
|
|
|
JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string);
|
|
|
|
if (string) {
|
|
|
|
JSStringWrapper wrapper(string);
|
|
|
|
cocosplayer_js_log((char *)wrapper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void register_CocosPlayer(JSContext* cx, JSObject* obj) {
|
|
|
|
// first, try to get the ns
|
|
|
|
jsval nsval;
|
|
|
|
JSObject *ns;
|
|
|
|
JS_GetProperty(cx, obj, "cc", &nsval);
|
|
|
|
if (nsval == JSVAL_VOID) {
|
|
|
|
ns = JS_NewObject(cx, NULL, NULL, NULL);
|
|
|
|
nsval = OBJECT_TO_JSVAL(ns);
|
|
|
|
JS_SetProperty(cx, obj, "cc", &nsval);
|
|
|
|
} else {
|
|
|
|
JS_ValueToObject(cx, nsval, &ns);
|
|
|
|
}
|
|
|
|
obj = ns;
|
|
|
|
|
|
|
|
JS_DefineFunction(cx, obj, "_cocosplayerLog", JS_cocosPlayerLog, 2, JSPROP_READONLY | JSPROP_PERMANENT);
|
|
|
|
}
|
2013-01-25 10:29:39 +08:00
|
|
|
|
2013-04-18 08:24:59 +08:00
|
|
|
extern "C" {
|
|
|
|
|
2013-04-24 07:47:14 +08:00
|
|
|
|
2013-04-24 09:03:54 +08:00
|
|
|
const char * getCCBDirectoryPath();
|
2013-04-18 08:24:59 +08:00
|
|
|
|
|
|
|
|
2013-04-24 09:03:54 +08:00
|
|
|
static void setResolutionSizes(bool isTablet, bool isRetina, bool isPortrait) {
|
|
|
|
CCSize designSize, resourceSize;
|
|
|
|
if(isTablet && isPortrait) {
|
2013-04-23 15:58:25 +08:00
|
|
|
designSize = CCSizeMake(768, 1024);
|
2013-04-24 09:03:54 +08:00
|
|
|
if(isRetina) resourceSize = CCSizeMake(1536, 2048);
|
|
|
|
else resourceSize = CCSizeMake(768, 1024);
|
|
|
|
} else if(isTablet) {
|
|
|
|
designSize = CCSizeMake(1024, 768);
|
|
|
|
if(isRetina) resourceSize = CCSizeMake(2048, 1536);
|
|
|
|
else resourceSize = CCSizeMake(1024, 768);
|
|
|
|
} else if(isPortrait) {
|
|
|
|
designSize = CCSizeMake(320, 480);
|
|
|
|
if(isRetina) resourceSize = CCSizeMake(640, 960);
|
|
|
|
else resourceSize = CCSizeMake(320, 480);
|
|
|
|
} else {
|
|
|
|
designSize = CCSizeMake(480, 320);
|
|
|
|
if(isRetina) resourceSize = CCSizeMake(960, 640);
|
|
|
|
else resourceSize = CCSizeMake(480, 320);
|
2013-04-18 08:24:59 +08:00
|
|
|
}
|
|
|
|
|
2013-04-24 09:03:54 +08:00
|
|
|
CCDirector::sharedDirector()->setContentScaleFactor(resourceSize.width/designSize.width);
|
|
|
|
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);
|
2013-04-18 08:24:59 +08:00
|
|
|
}
|
2013-04-24 09:03:54 +08:00
|
|
|
|
2013-04-26 09:15:11 +08:00
|
|
|
void AppDelegate::initGameView() {
|
|
|
|
|
|
|
|
// initialize director
|
2013-04-24 09:03:54 +08:00
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
2013-04-26 09:15:11 +08:00
|
|
|
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
|
|
|
|
pDirector->setProjection(kCCDirectorProjection2D);
|
|
|
|
|
|
|
|
|
|
|
|
CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
|
|
|
|
if(!isPortraitApp) {
|
|
|
|
screenSize = CCSizeMake(screenSize.height, screenSize.width);
|
|
|
|
}
|
2013-04-24 09:03:54 +08:00
|
|
|
|
2013-04-26 09:15:11 +08:00
|
|
|
std::vector<std::string> resDirOrders;
|
|
|
|
std::string res;
|
|
|
|
TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();
|
|
|
|
|
|
|
|
|
|
|
|
if (platform == kTargetIphone || platform == kTargetIpad)
|
|
|
|
{
|
|
|
|
std::vector<std::string> searchPaths = CCFileUtils::sharedFileUtils()->getSearchPaths();
|
|
|
|
searchPaths.insert(searchPaths.begin(), "Published files iOS");
|
|
|
|
searchPaths.insert(searchPaths.begin(), getCCBDirectoryPath());
|
2013-04-24 09:03:54 +08:00
|
|
|
|
2013-04-26 09:15:11 +08:00
|
|
|
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
|
|
|
|
if (screenSize.height > 1136)
|
2013-04-18 08:24:59 +08:00
|
|
|
{
|
2013-04-26 09:15:11 +08:00
|
|
|
res = "iPad";
|
|
|
|
setResolutionSizes(true, true, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-ipadhd");
|
|
|
|
resDirOrders.push_back("resources-ipad");
|
|
|
|
resDirOrders.push_back("resources-iphonehd");
|
|
|
|
isIPhone = false;
|
|
|
|
isRetina = true;
|
|
|
|
cocos2d::extension::CCBReader::setResolutionScale(2);
|
|
|
|
} else if(screenSize.height > 1024) {
|
|
|
|
res = "iPhone";
|
|
|
|
setResolutionSizes(false, true, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-iphonehd");
|
|
|
|
resDirOrders.push_back("resources-iphone");
|
|
|
|
isIPhone = true;
|
|
|
|
isRetina = true;
|
|
|
|
}
|
|
|
|
else if (screenSize.height > 960)
|
|
|
|
{
|
|
|
|
res = "iPad";
|
|
|
|
setResolutionSizes(true, false, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-ipad");
|
|
|
|
resDirOrders.push_back("resources-iphonehd");
|
|
|
|
isIPhone = false;
|
|
|
|
isRetina = false;
|
|
|
|
cocos2d::extension::CCBReader::setResolutionScale(2);
|
2013-04-24 09:03:54 +08:00
|
|
|
|
2013-04-26 09:15:11 +08:00
|
|
|
}
|
|
|
|
else if (screenSize.height > 480)
|
|
|
|
{
|
|
|
|
res = "iPhone";
|
|
|
|
setResolutionSizes(false, true, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-iphonehd");
|
|
|
|
resDirOrders.push_back("resources-iphone");
|
|
|
|
isIPhone = true;
|
|
|
|
isRetina = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = "iPhone";
|
|
|
|
setResolutionSizes(false, false, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-iphone");
|
|
|
|
isIPhone = true;
|
|
|
|
isRetina = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (platform == kTargetAndroid || platform == kTargetWindows)
|
|
|
|
{
|
|
|
|
int dpi = -1;
|
|
|
|
dpi = CCDevice::getDPI();
|
|
|
|
|
|
|
|
if(dpi > 300) { // retina
|
|
|
|
if (screenSize.height > 1920) {
|
|
|
|
res = "xlarge";
|
2013-04-26 02:36:25 +08:00
|
|
|
setResolutionSizes(true, true, isPortraitApp);
|
2013-04-26 09:15:11 +08:00
|
|
|
resDirOrders.push_back("resources-xlarge");
|
|
|
|
resDirOrders.push_back("resources-large");
|
|
|
|
resDirOrders.push_back("resources-medium");
|
|
|
|
resDirOrders.push_back("resources-small");
|
|
|
|
} else {
|
|
|
|
res = "large";
|
2013-04-26 02:36:25 +08:00
|
|
|
setResolutionSizes(false, true, isPortraitApp);
|
2013-04-26 09:15:11 +08:00
|
|
|
resDirOrders.push_back("resources-large");
|
|
|
|
resDirOrders.push_back("resources-medium");
|
|
|
|
resDirOrders.push_back("resources-small");
|
2013-04-24 09:03:54 +08:00
|
|
|
}
|
2013-04-26 09:15:11 +08:00
|
|
|
} else { // non retina
|
|
|
|
if (screenSize.height > 960)
|
2013-04-24 09:03:54 +08:00
|
|
|
{
|
2013-04-26 09:15:11 +08:00
|
|
|
res = "large";
|
2013-04-26 02:36:25 +08:00
|
|
|
setResolutionSizes(true, false, isPortraitApp);
|
2013-04-26 09:15:11 +08:00
|
|
|
resDirOrders.push_back("resources-large");
|
|
|
|
resDirOrders.push_back("resources-medium");
|
|
|
|
resDirOrders.push_back("resources-small");
|
2013-04-24 09:03:54 +08:00
|
|
|
cocos2d::extension::CCBReader::setResolutionScale(2);
|
2013-04-26 09:15:11 +08:00
|
|
|
}
|
|
|
|
else if (screenSize.height > 768)
|
|
|
|
{
|
|
|
|
res = "medium";
|
|
|
|
setResolutionSizes(true, false, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-medium");
|
|
|
|
resDirOrders.push_back("resources-small");
|
2013-04-24 09:03:54 +08:00
|
|
|
}
|
|
|
|
else if (screenSize.height > 480)
|
|
|
|
{
|
2013-04-26 09:15:11 +08:00
|
|
|
res = "small";
|
|
|
|
setResolutionSizes(false, false, isPortraitApp);
|
|
|
|
resDirOrders.push_back("resources-small");
|
2013-04-24 09:03:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-26 02:36:25 +08:00
|
|
|
setResolutionSizes(false, false, isPortraitApp);
|
2013-04-26 09:15:11 +08:00
|
|
|
res = "xsmall";
|
|
|
|
resDirOrders.push_back("resources-xsmall");
|
2013-04-24 09:03:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-18 08:24:59 +08:00
|
|
|
}
|
2013-04-26 09:15:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
|
|
|
|
pFileUtils->setSearchResolutionsOrder(resDirOrders);
|
|
|
|
|
|
|
|
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
|
|
|
searchPaths.insert(searchPaths.begin(), pFileUtils->getWritablePath());
|
|
|
|
pFileUtils->setSearchPaths(searchPaths);
|
|
|
|
|
|
|
|
PlayerStatus::setDeviceResolution(res);
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2013-04-24 09:03:54 +08:00
|
|
|
|
2013-04-26 09:15:11 +08:00
|
|
|
initGameView();
|
2013-04-24 09:03:54 +08:00
|
|
|
ScriptingCore* sc = ScriptingCore::getInstance();
|
|
|
|
sc->addRegisterCallback(register_all_cocos2dx);
|
|
|
|
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
|
|
|
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
|
|
|
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
|
|
|
sc->addRegisterCallback(register_CCBuilderReader);
|
|
|
|
sc->addRegisterCallback(jsb_register_system);
|
|
|
|
sc->addRegisterCallback(jsb_register_chipmunk);
|
|
|
|
sc->addRegisterCallback(JSB_register_opengl);
|
2013-04-26 09:13:03 +08:00
|
|
|
sc->addRegisterCallback(register_CocosPlayer);
|
2013-04-24 09:03:54 +08:00
|
|
|
sc->start();
|
|
|
|
|
|
|
|
CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
|
|
|
|
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
|
|
|
|
if(firstTime) {
|
|
|
|
runMainScene();
|
|
|
|
firstTime = false;
|
|
|
|
} else {
|
|
|
|
handle_ccb_run();
|
2013-04-18 08:24:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
|
2013-03-20 14:27:46 +08:00
|
|
|
|
2013-04-24 09:03:54 +08:00
|
|
|
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();
|
2013-01-25 10:29:39 +08:00
|
|
|
} else {
|
2013-04-24 09:03:54 +08:00
|
|
|
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;
|
|
|
|
}
|
2013-01-25 10:29:39 +08:00
|
|
|
}
|
|
|
|
}
|
2013-04-24 09:03:54 +08:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2013-01-25 10:29:39 +08:00
|
|
|
}
|