Source formatting, clean up.

This commit is contained in:
NathanSweet 2013-03-25 22:27:00 +01:00
parent 1f991ac234
commit ec8509b511
8 changed files with 129 additions and 172 deletions

View File

@ -9,86 +9,67 @@
USING_NS_CC; USING_NS_CC;
using namespace std; using namespace std;
AppDelegate::AppDelegate() { AppDelegate::AppDelegate () {
} }
AppDelegate::~AppDelegate() AppDelegate::~AppDelegate () {
{
} }
bool AppDelegate::applicationDidFinishLaunching() { bool AppDelegate::applicationDidFinishLaunching () {
// initialize director CCDirector* director = CCDirector::sharedDirector();
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView); CCEGLView* view = CCEGLView::sharedOpenGLView();
director->setOpenGLView(view);
// Set the design resolution view->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
CCSize frameSize = pEGLView->getFrameSize();
vector<string> searchPath;
// In this demo, we select resource according to the frame's height. // In this demo, we select resource according to the frame's height.
// If the resource size is different from design resolution size, you need to set contentScaleFactor. // If the resource size is different from design resolution size, you need to set contentScaleFactor.
// We use the ratio of resource's height to the height of design resolution, // We use the ratio of resource's height to the height of design resolution,
// this can make sure that the resource's height could fit for the height of design resolution. // this can make sure that the resource's height could fit for the height of design resolution.
vector<string> searchPath;
CCSize frameSize = view->getFrameSize();
if (frameSize.height > mediumResource.size.height) {
// if the frame's height is larger than the height of medium resource size, select large resource. // if the frame's height is larger than the height of medium resource size, select large resource.
if (frameSize.height > mediumResource.size.height)
{
searchPath.push_back(largeResource.directory); searchPath.push_back(largeResource.directory);
pDirector->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width)); director->setContentScaleFactor( //
} MIN(largeResource.size.height / designResolutionSize.height, //
largeResource.size.width / designResolutionSize.width));
} else if (frameSize.height > smallResource.size.height) {
// if the frame's height is larger than the height of small resource size, select medium resource. // if the frame's height is larger than the height of small resource size, select medium resource.
else if (frameSize.height > smallResource.size.height)
{
searchPath.push_back(mediumResource.directory); searchPath.push_back(mediumResource.directory);
pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); director->setContentScaleFactor( //
} MIN(mediumResource.size.height / designResolutionSize.height, //
mediumResource.size.width / designResolutionSize.width));
} else {
// if the frame's height is smaller than the height of medium resource size, select small resource. // if the frame's height is smaller than the height of medium resource size, select small resource.
else
{
searchPath.push_back(smallResource.directory); searchPath.push_back(smallResource.directory);
pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); director->setContentScaleFactor( //
MIN(smallResource.size.height / designResolutionSize.height, //
smallResource.size.width / designResolutionSize.width));
} }
searchPath.push_back("common"); searchPath.push_back("common");
// set searching path
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);
// turn on display FPS director->setDisplayStats(true);
pDirector->setDisplayStats(true); director->setAnimationInterval(1.0 / 60);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
CCScene *pScene = ExampleScene::scene(); CCScene *pScene = ExampleScene::scene();
director->runWithScene(pScene);
// run
pDirector->runWithScene(pScene);
return true; 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 () {
void AppDelegate::applicationDidEnterBackground() {
CCDirector::sharedDirector()->stopAnimation(); CCDirector::sharedDirector()->stopAnimation();
// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
} }
// this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground () {
void AppDelegate::applicationWillEnterForeground() {
CCDirector::sharedDirector()->startAnimation(); CCDirector::sharedDirector()->startAnimation();
// if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
} }

View File

@ -1,38 +1,16 @@
#ifndef _APP_DELEGATE_H_ #ifndef _APPDELEGATE_H_
#define _APP_DELEGATE_H_ #define _APPDELEGATE_H_
#include "cocos2d.h" #include "cocos2d.h"
/** class AppDelegate: private cocos2d::CCApplication {
@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: public:
AppDelegate(); AppDelegate ();
virtual ~AppDelegate(); virtual ~AppDelegate ();
/** virtual bool applicationDidFinishLaunching ();
@brief Implement CCDirector and CCScene init code here. virtual void applicationDidEnterBackground ();
@return true Initialize success, app continue. virtual void applicationWillEnterForeground ();
@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_ #endif // _APPDELEGATE_H_

View File

@ -1,5 +1,5 @@
#ifndef __APPMACROS_H__ #ifndef _APPMACROS_H_
#define __APPMACROS_H__ #define _APPMACROS_H_
#include "cocos2d.h" #include "cocos2d.h"
@ -31,16 +31,15 @@
/* If you want to switch design resolution, change next line */ /* If you want to switch design resolution, change next line */
#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320 #define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320
typedef struct tagResource typedef struct tagResource {
{
cocos2d::CCSize size; cocos2d::CCSize size;
char directory[100]; char directory[100];
}Resource; } Resource;
static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "iphone" }; static Resource smallResource = {cocos2d::CCSizeMake(480, 320), "iphone"};
static Resource mediumResource = { cocos2d::CCSizeMake(960, 640), "iphone-retina" }; static Resource mediumResource = {cocos2d::CCSizeMake(960, 640), "iphone-retina"};
static Resource largeResource = { cocos2d::CCSizeMake(1024, 768), "ipad" }; static Resource largeResource = {cocos2d::CCSizeMake(1024, 768), "ipad"};
static Resource extralargeResource = { cocos2d::CCSizeMake(2048, 1536), "ipadhd" }; static Resource extralargeResource = {cocos2d::CCSizeMake(2048, 1536), "ipadhd"};
#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320) #if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320); static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);
@ -57,4 +56,4 @@ static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(2048, 1536);
// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution // The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
#define TITLE_FONT_SIZE (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24) #define TITLE_FONT_SIZE (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
#endif /* __APPMACROS_H__ */ #endif /* _APPMACROS_H_ */

View File

@ -7,14 +7,14 @@ using namespace cocos2d;
using namespace spine; using namespace spine;
using namespace std; using namespace std;
CCScene* ExampleScene::scene() { CCScene* ExampleScene::scene () {
CCScene *scene = CCScene::create(); CCScene *scene = CCScene::create();
ExampleScene *layer = ExampleScene::create(); ExampleScene *layer = ExampleScene::create();
scene->addChild(layer); scene->addChild(layer);
return scene; return scene;
} }
bool ExampleScene::init() { bool ExampleScene::init () {
if (!CCLayer::init()) return false; if (!CCLayer::init()) return false;
Atlas *atlas = new Atlas("spineboy.txt"); Atlas *atlas = new Atlas("spineboy.txt");

View File

@ -3,13 +3,13 @@
#include "cocos2d.h" #include "cocos2d.h"
class ExampleScene : public cocos2d::CCLayer { class ExampleScene: public cocos2d::CCLayer {
public: public:
static cocos2d::CCScene* scene(); static cocos2d::CCScene* scene ();
virtual bool init(); virtual bool init ();
CREATE_FUNC(ExampleScene); CREATE_FUNC (ExampleScene);
}; };
#endif // SPINE_EXAMPLESCENE_H_ #endif // _EXAMPLESCENE_H_

View File

@ -39,7 +39,7 @@ AtlasPage::~AtlasPage () {
Atlas::Atlas (const std::string &path) { Atlas::Atlas (const std::string &path) {
unsigned long size; unsigned long size;
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData( char *data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size)); CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
if (!data) throw std::runtime_error("Error reading atlas file: " + path); if (!data) throw std::runtime_error("Error reading atlas file: " + path);
load(data, data + size); load(data, data + size);

View File

@ -1,27 +1,27 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2013, Esoteric Software * Copyright (c) 2013, Esoteric Software
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/ ******************************************************************************/
#include <spine-cocos2dx/CCSkeleton.h> #include <spine-cocos2dx/CCSkeleton.h>
#include <stdexcept> #include <stdexcept>
@ -38,8 +38,7 @@ using namespace spine;
USING_NS_CC; USING_NS_CC;
CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) : CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) :
debug(false) debug(false) {
{
if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null."); if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null.");
skeleton = new Skeleton(skeletonData); skeleton = new Skeleton(skeletonData);
state = new AnimationState(stateData); state = new AnimationState(stateData);
@ -62,7 +61,7 @@ void CCSkeleton::update (float deltaTime) {
void CCSkeleton::draw () { void CCSkeleton::draw () {
CC_NODE_DRAW_SETUP(); CC_NODE_DRAW_SETUP();
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
skeleton->draw(); skeleton->draw();
if (debug) { if (debug) {

View File

@ -43,7 +43,7 @@ SkeletonJson::SkeletonJson (Atlas *atlas) :
SkeletonData* SkeletonJson::readSkeletonData (const std::string &path) const { SkeletonData* SkeletonJson::readSkeletonData (const std::string &path) const {
unsigned long size; unsigned long size;
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData( char *data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size)); CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
if (!data) throw runtime_error("Error reading skeleton file: " + path); if (!data) throw runtime_error("Error reading skeleton file: " + path);
return BaseSkeletonJson::readSkeletonData(data, data + size); return BaseSkeletonJson::readSkeletonData(data, data + size);
@ -51,7 +51,7 @@ SkeletonData* SkeletonJson::readSkeletonData (const std::string &path) const {
Animation* SkeletonJson::readAnimation (const std::string &path, const SkeletonData *skeletonData) const { Animation* SkeletonJson::readAnimation (const std::string &path, const SkeletonData *skeletonData) const {
unsigned long size; unsigned long size;
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData( char *data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size)); CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
if (!data) throw runtime_error("Error reading animation file: " + path); if (!data) throw runtime_error("Error reading animation file: " + path);
return BaseSkeletonJson::readAnimation(data, data + size, skeletonData); return BaseSkeletonJson::readAnimation(data, data + size, skeletonData);