Przeglądaj źródła

Source formatting, clean up.

NathanSweet 12 lat temu
rodzic
commit
ec8509b511

+ 54 - 73
spine-cocos2dx/example/Classes/AppDelegate.cpp

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

+ 10 - 32
spine-cocos2dx/example/Classes/AppDelegate.h

@@ -1,38 +1,16 @@
-#ifndef  _APP_DELEGATE_H_
-#define  _APP_DELEGATE_H_
+#ifndef  _APPDELEGATE_H_
+#define  _APPDELEGATE_H_
 
 #include "cocos2d.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
-{
+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();
-};
+	AppDelegate ();
+	virtual ~AppDelegate ();
 
-#endif // _APP_DELEGATE_H_
+	virtual bool applicationDidFinishLaunching ();
+	virtual void applicationDidEnterBackground ();
+	virtual void applicationWillEnterForeground ();
+};
 
+#endif // _APPDELEGATE_H_

+ 28 - 29
spine-cocos2dx/example/Classes/AppMacros.h

@@ -1,26 +1,26 @@
-#ifndef __APPMACROS_H__
-#define __APPMACROS_H__
+#ifndef _APPMACROS_H_
+#define _APPMACROS_H_
 
 #include "cocos2d.h"
 
 /* For demonstrating using one design resolution to match different resources,
-   or one resource to match different design resolutions.
-
-   [Situation 1] Using one design resolution to match different resources.
-     Please look into Appdelegate::applicationDidFinishLaunching.
-     We check current device frame size to decide which resource need to be selected.
-     So if you want to test this situation which said in title '[Situation 1]',
-     you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina),
-     or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform
-     and modify "proj.mac/AppController.mm" by changing the window rectangle.
-
-   [Situation 2] Using one resource to match different design resolutions.
-     The coordinates in your codes is based on your current design resolution rather than resource size.
-     Therefore, your design resolution could be very large and your resource size could be small.
-     To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536'
-     and open iphone simulator or create a window of 480x320 size.
-
-   [Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources.
+ or one resource to match different design resolutions.
+
+ [Situation 1] Using one design resolution to match different resources.
+ Please look into Appdelegate::applicationDidFinishLaunching.
+ We check current device frame size to decide which resource need to be selected.
+ So if you want to test this situation which said in title '[Situation 1]',
+ you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina),
+ or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform
+ and modify "proj.mac/AppController.mm" by changing the window rectangle.
+
+ [Situation 2] Using one resource to match different design resolutions.
+ The coordinates in your codes is based on your current design resolution rather than resource size.
+ Therefore, your design resolution could be very large and your resource size could be small.
+ To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536'
+ and open iphone simulator or create a window of 480x320 size.
+
+ [Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources.
  */
 
 #define DESIGN_RESOLUTION_480X320    0
@@ -31,16 +31,15 @@
 /* If you want to switch design resolution, change next line */
 #define TARGET_DESIGN_RESOLUTION_SIZE  DESIGN_RESOLUTION_480X320
 
-typedef struct tagResource
-{
-    cocos2d::CCSize size;
-    char directory[100];
-}Resource;
+typedef struct tagResource {
+	cocos2d::CCSize size;
+	char directory[100];
+} Resource;
 
-static Resource smallResource  =  { cocos2d::CCSizeMake(480, 320),   "iphone" };
-static Resource mediumResource  =  { cocos2d::CCSizeMake(960, 640),   "iphone-retina" };
-static Resource largeResource =  { cocos2d::CCSizeMake(1024, 768),  "ipad"   };
-static Resource extralargeResource  =  { cocos2d::CCSizeMake(2048, 1536), "ipadhd" };
+static Resource smallResource = {cocos2d::CCSizeMake(480, 320), "iphone"};
+static Resource mediumResource = {cocos2d::CCSizeMake(960, 640), "iphone-retina"};
+static Resource largeResource = {cocos2d::CCSizeMake(1024, 768), "ipad"};
+static Resource extralargeResource = {cocos2d::CCSizeMake(2048, 1536), "ipadhd"};
 
 #if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
 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
 #define TITLE_FONT_SIZE  (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
 
-#endif /* __APPMACROS_H__ */
+#endif /* _APPMACROS_H_ */

+ 3 - 3
spine-cocos2dx/example/Classes/ExampleScene.cpp

@@ -7,19 +7,19 @@ using namespace cocos2d;
 using namespace spine;
 using namespace std;
 
-CCScene* ExampleScene::scene() {
+CCScene* ExampleScene::scene () {
 	CCScene *scene = CCScene::create();
 	ExampleScene *layer = ExampleScene::create();
 	scene->addChild(layer);
 	return scene;
 }
 
-bool ExampleScene::init() {
+bool ExampleScene::init () {
 	if (!CCLayer::init()) return false;
 
 	Atlas *atlas = new Atlas("spineboy.txt");
 	SkeletonJson json(atlas);
-  json.scale = 0.5;
+	json.scale = 0.5;
 	SkeletonData *skeletonData = json.readSkeletonData("spineboy-skeleton.json");
 	Animation *animation = json.readAnimation("spineboy-walk.json", skeletonData);
 

+ 5 - 5
spine-cocos2dx/example/Classes/ExampleScene.h

@@ -3,13 +3,13 @@
 
 #include "cocos2d.h"
 
-class ExampleScene : public cocos2d::CCLayer {
+class ExampleScene: public cocos2d::CCLayer {
 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_

+ 2 - 2
spine-cocos2dx/src/spine-cocos2dx/Atlas.cpp

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

+ 26 - 27
spine-cocos2dx/src/spine-cocos2dx/CCSkeleton.cpp

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

+ 4 - 4
spine-cocos2dx/src/spine-cocos2dx/SkeletonJson.cpp

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