mirror of https://github.com/axmolengine/axmol.git
fixed some errors of iphone platform
This commit is contained in:
parent
e312bb4d18
commit
9a959c299f
|
@ -1 +1 @@
|
|||
78c89f5d993e6ed6fd3016a960cd1796bbcc1d39
|
||||
821f97de148b8a4f5c67bbdb7751d22f3f9217c4
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
#include "NSMutableArray.h"
|
||||
#include "CGGeometry.h"
|
||||
#include "CCXCocos2dDefine.h"
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
namespace cocos2d {
|
||||
class CCSpriteFrame;
|
||||
|
@ -41,119 +41,119 @@ namespace cocos2d {
|
|||
[sprite runAction:[CCAnimate actionWithAnimation:animation]];
|
||||
|
||||
*/
|
||||
class CCX_DLL CCAnimation : public NSObject
|
||||
{
|
||||
protected:
|
||||
std::string m_nameStr;
|
||||
float m_fDelay;
|
||||
NSMutableArray<CCSpriteFrame*> *m_pobFrames;
|
||||
|
||||
public:
|
||||
// attributes
|
||||
|
||||
/** get name of the animation */
|
||||
inline const char* getName(void) { return m_nameStr.c_str(); }
|
||||
/** set name of the animation */
|
||||
inline void setName(const char *pszName){ m_nameStr = pszName; }
|
||||
|
||||
/** get delay between frames in seconds */
|
||||
inline float getDelay(void) { return m_fDelay; }
|
||||
/** set delay between frames in seconds */
|
||||
inline void setDelay(float fDelay) { m_fDelay = fDelay; }
|
||||
|
||||
/** get array of frames */
|
||||
inline NSMutableArray<CCSpriteFrame*>* getFrames(void) { return m_pobFrames; }
|
||||
/** set array of frames, the Frames is retained */
|
||||
inline void setFrames(NSMutableArray<CCSpriteFrame*> *pFrames)
|
||||
{
|
||||
CCX_SAFE_RETAIN(pFrames);
|
||||
CCX_SAFE_RELEASE(m_pobFrames);
|
||||
m_pobFrames = pFrames;
|
||||
}
|
||||
|
||||
public:
|
||||
~CCAnimation(void);
|
||||
|
||||
class CCX_DLL CCAnimation : public NSObject
|
||||
{
|
||||
protected:
|
||||
std::string m_nameStr;
|
||||
float m_fDelay;
|
||||
NSMutableArray<CCSpriteFrame*> *m_pobFrames;
|
||||
|
||||
public:
|
||||
// attributes
|
||||
|
||||
/** get name of the animation */
|
||||
inline const char* getName(void) { return m_nameStr.c_str(); }
|
||||
/** set name of the animation */
|
||||
inline void setName(const char *pszName){ m_nameStr = pszName; }
|
||||
|
||||
/** get delay between frames in seconds */
|
||||
inline float getDelay(void) { return m_fDelay; }
|
||||
/** set delay between frames in seconds */
|
||||
inline void setDelay(float fDelay) { m_fDelay = fDelay; }
|
||||
|
||||
/** get array of frames */
|
||||
inline NSMutableArray<CCSpriteFrame*>* getFrames(void) { return m_pobFrames; }
|
||||
/** set array of frames, the Frames is retained */
|
||||
inline void setFrames(NSMutableArray<CCSpriteFrame*> *pFrames)
|
||||
{
|
||||
CCX_SAFE_RETAIN(pFrames);
|
||||
CCX_SAFE_RELEASE(m_pobFrames);
|
||||
m_pobFrames = pFrames;
|
||||
}
|
||||
|
||||
public:
|
||||
~CCAnimation(void);
|
||||
|
||||
/** Initializes a CCAnimation with frames.
|
||||
@since v0.99.5
|
||||
*/
|
||||
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
*/
|
||||
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
/** Initializes a CCAnimation with frames and a delay between frames
|
||||
@since v0.99.5
|
||||
*/
|
||||
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames, float delay);
|
||||
|
||||
*/
|
||||
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames, float delay);
|
||||
|
||||
/** Initializes a CCAnimation with a name
|
||||
@since v0.99.3
|
||||
@deprecated Will be removed in 1.0.1. Use "init" instead.
|
||||
*/
|
||||
bool initWithName(const char *pszName);
|
||||
|
||||
*/
|
||||
bool initWithName(const char *pszName);
|
||||
|
||||
/** Initializes a CCAnimation with a name and frames
|
||||
@since v0.99.3
|
||||
@deprecated Will be removed in 1.0.1. Use "initWithFrames" instead.
|
||||
*/
|
||||
bool initWithName(const char *pszName, NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
*/
|
||||
bool initWithName(const char *pszName, NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
/** Initializes a CCAnimation with a name and delay between frames.
|
||||
@deprecated Will be removed in 1.0.1. Use "initWithFrames:nil delay:delay" instead.
|
||||
*/
|
||||
bool initWithName(const char *pszName, float fDelay);
|
||||
|
||||
*/
|
||||
bool initWithName(const char *pszName, float fDelay);
|
||||
|
||||
/** Initializes a CCAnimation with a name, delay and an array of CCSpriteFrames.
|
||||
@deprecated Will be removed in 1.0.1. Use "initWithFrames:frames delay:delay" instead.
|
||||
*/
|
||||
bool initWithName(const char *pszName, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
/** adds a frame to a CCAnimation */
|
||||
void addFrame(CCSpriteFrame *pFrame);
|
||||
|
||||
*/
|
||||
bool initWithName(const char *pszName, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
/** adds a frame to a CCAnimation */
|
||||
void addFrame(CCSpriteFrame *pFrame);
|
||||
|
||||
/** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
|
||||
Added to facilitate the migration from v0.8 to v0.9.
|
||||
*/
|
||||
void addFrameWithFileName(const char *pszFileName);
|
||||
|
||||
*/
|
||||
void addFrameWithFileName(const char *pszFileName);
|
||||
|
||||
/** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it.
|
||||
Added to facilitate the migration from v0.8 to v0.9.
|
||||
*/
|
||||
void addFrameWithTexture(CCTexture2D* pobTexture, CGRect rect);
|
||||
|
||||
bool init(void);
|
||||
|
||||
public:
|
||||
*/
|
||||
void addFrameWithTexture(CCTexture2D* pobTexture, CGRect rect);
|
||||
|
||||
bool init(void);
|
||||
|
||||
public:
|
||||
/** Creates an animation
|
||||
@since v0.99.5
|
||||
*/
|
||||
static CCAnimation* animation(void);
|
||||
|
||||
*/
|
||||
static CCAnimation* animation(void);
|
||||
|
||||
/** Creates an animation with frames.
|
||||
@since v0.99.5
|
||||
*/
|
||||
static CCAnimation* animationWithFrames(NSArray<CCSpriteFrame*> *frames);
|
||||
|
||||
*/
|
||||
static CCAnimation* animationWithFrames(NSArray<CCSpriteFrame*> *frames);
|
||||
|
||||
/* Creates an animation with frames and a delay between frames.
|
||||
@since v0.99.5
|
||||
*/
|
||||
static CCAnimation* animationWithFrames(NSArray<CCSpriteFrame*> *frames, float delay);
|
||||
|
||||
*/
|
||||
static CCAnimation* animationWithFrames(NSArray<CCSpriteFrame*> *frames, float delay);
|
||||
|
||||
/** Creates a CCAnimation with a name
|
||||
@since v0.99.3
|
||||
@deprecated Will be removed in 1.0.1. Use "animation" instead.
|
||||
*/
|
||||
static CCAnimation* animationWithName(const char *pszName);
|
||||
|
||||
*/
|
||||
static CCAnimation* animationWithName(const char *pszName);
|
||||
|
||||
/** Creates a CCAnimation with a name and frames
|
||||
@since v0.99.3
|
||||
@deprecated Will be removed in 1.0.1. Use "animationWithFrames" instead.
|
||||
*/
|
||||
static CCAnimation* animationWithName(const char *pszName, NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
/** Creates a CCAnimation with a name and delay between frames. */
|
||||
static CCAnimation* animationWithName(const char *pszName, float fDelay);
|
||||
|
||||
/** Creates a CCAnimation with a name, delay and an array of CCSpriteFrames. */
|
||||
static CCAnimation* animationWithName(const char *pszName, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
||||
*/
|
||||
static CCAnimation* animationWithName(const char *pszName, NSArray<CCSpriteFrame*> *pFrames);
|
||||
|
||||
/** Creates a CCAnimation with a name and delay between frames. */
|
||||
static CCAnimation* animationWithName(const char *pszName, float fDelay);
|
||||
|
||||
/** Creates a CCAnimation with a name, delay and an array of CCSpriteFrames. */
|
||||
static CCAnimation* animationWithName(const char *pszName, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
||||
};
|
||||
} // end of name sapce cocos2d
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
|||
#ifndef __CCDIRECTOR_H__
|
||||
#define __CCDIRECTOR_H__
|
||||
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "ccConfig.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCXCocos2dDefine.h"
|
||||
|
@ -35,9 +36,8 @@ THE SOFTWARE.
|
|||
#include "CCXEGLView.h"
|
||||
#include "ccxCommon.h"
|
||||
#include "CCGL.h"
|
||||
#include "platform/CCNS.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
enum {
|
||||
|
@ -269,7 +269,7 @@ public:
|
|||
*/
|
||||
CGSize getDisplaySizeInPixels(void);
|
||||
|
||||
/** changes the projection size */
|
||||
/** changes the projection size */
|
||||
void reshapeProjection(CGSize newWindowSize);
|
||||
|
||||
/** converts a UIKit coordinate to an OpenGL coordinate
|
||||
|
@ -543,7 +543,7 @@ protected:
|
|||
/* store the fps string */
|
||||
char *m_pszFPS;
|
||||
|
||||
/* This object will be visited after the scene. Useful to hook a notification node */
|
||||
/* This object will be visited after the scene. Useful to hook a notification node */
|
||||
CCNode *m_pNotificationNode;
|
||||
|
||||
/* Projection protocol delegate */
|
||||
|
|
|
@ -25,71 +25,71 @@ THE SOFTWARE.
|
|||
#define __CCRENDER_TEXTURE_H__
|
||||
|
||||
#include "NSData.h"
|
||||
#include "CCNode.h"
|
||||
#include "CCSprite.h"
|
||||
|
||||
#include "CCNode.h"
|
||||
#include "CCSprite.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
enum eImageFormat
|
||||
{
|
||||
kCCImageFormatJPG = 0,
|
||||
kCCImageFormatPNG = 1,
|
||||
typedef enum eImageFormat
|
||||
{
|
||||
kCCImageFormatJPG = 0,
|
||||
kCCImageFormatPNG = 1,
|
||||
kCCImageFormatRawData = 2
|
||||
};
|
||||
/**
|
||||
@brief CCRenderTexture is a generic rendering target. To render things into it,
|
||||
simply construct a render target, call begin on it, call visit on any cocos
|
||||
scenes or objects to render them, and call end. For convienience, render texture
|
||||
adds a sprite as it's display child with the results, so you can simply add
|
||||
the render texture to your scene and treat it like any other CocosNode.
|
||||
There are also functions for saving the render texture to disk in PNG or JPG format.
|
||||
|
||||
@since v0.8.1
|
||||
*/
|
||||
class CCX_DLL CCRenderTexture : public CCNode
|
||||
{
|
||||
/** The CCSprite being used.
|
||||
} tImageFormat;
|
||||
/**
|
||||
@brief CCRenderTexture is a generic rendering target. To render things into it,
|
||||
simply construct a render target, call begin on it, call visit on any cocos
|
||||
scenes or objects to render them, and call end. For convienience, render texture
|
||||
adds a sprite as it's display child with the results, so you can simply add
|
||||
the render texture to your scene and treat it like any other CocosNode.
|
||||
There are also functions for saving the render texture to disk in PNG or JPG format.
|
||||
|
||||
@since v0.8.1
|
||||
*/
|
||||
class CCX_DLL CCRenderTexture : public CCNode
|
||||
{
|
||||
/** The CCSprite being used.
|
||||
The sprite, by default, will use the following blending function: GL_ONE, GL_ONE_MINUS_SRC_ALPHA.
|
||||
The blending function can be changed in runtime by calling:
|
||||
- [[renderTexture sprite] setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||
*/
|
||||
CCX_PROPERTY(CCSprite*, m_pSprite, Sprite)
|
||||
public:
|
||||
CCRenderTexture();
|
||||
virtual ~CCRenderTexture();
|
||||
/** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
|
||||
CCX_PROPERTY(CCSprite*, m_pSprite, Sprite)
|
||||
public:
|
||||
CCRenderTexture();
|
||||
virtual ~CCRenderTexture();
|
||||
/** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
|
||||
static CCRenderTexture * renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat);
|
||||
|
||||
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */
|
||||
static CCRenderTexture * renderTextureWithWidthAndHeight(int w, int h);
|
||||
|
||||
/** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
|
||||
static CCRenderTexture * renderTextureWithWidthAndHeight(int w, int h);
|
||||
|
||||
/** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
|
||||
bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat);
|
||||
|
||||
/** starts grabbing */
|
||||
void begin();
|
||||
void begin();
|
||||
|
||||
/** starts rendering to the texture while clearing the texture first.
|
||||
This is more efficient then calling -clear first and then -begin */
|
||||
void beginWithClear(float r, float g, float b, float a);
|
||||
|
||||
/** ends grabbing */
|
||||
void end();
|
||||
|
||||
/** clears the texture with a color */
|
||||
void end();
|
||||
|
||||
/** clears the texture with a color */
|
||||
void clear(float r, float g, float b, float a);
|
||||
|
||||
/** saves the texture into a file */
|
||||
bool saveBuffer(const char *name);
|
||||
/** saves the texture into a file. The format can be JPG or PNG */
|
||||
bool saveBuffer(const char *name, int format);
|
||||
|
||||
/* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */
|
||||
/** saves the texture into a file */
|
||||
bool saveBuffer(const char *name);
|
||||
/** saves the texture into a file. The format can be JPG or PNG */
|
||||
bool saveBuffer(const char *name, int format);
|
||||
|
||||
/* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */
|
||||
NSData *getUIImageAsDataFromBuffer(int format);
|
||||
protected:
|
||||
GLuint m_uFBO;
|
||||
GLint m_nOldFBO;
|
||||
CCTexture2D* m_pTexture;
|
||||
protected:
|
||||
GLuint m_uFBO;
|
||||
GLint m_nOldFBO;
|
||||
CCTexture2D* m_pTexture;
|
||||
|
||||
GLenum m_ePixelFormat;
|
||||
GLfloat m_aClearColor[4];
|
||||
|
@ -97,7 +97,7 @@ protected:
|
|||
private:
|
||||
void saveGLstate();
|
||||
void restoreGLstate();
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace cocos2d
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// build each architecture with the optimal particle system
|
||||
|
||||
// ARMv7, Mac or Simulator use "Quad" particle
|
||||
#if defined(__ARM_NEON__) || defined(CCX_PLATFORM_MAC) || defined(TARGET_IPHONE_SIMULATOR) || defined(CCX_PLATFORM_WIN32) || defined(_TRANZDA_VM_)
|
||||
#if defined(__ARM_NEON__) || defined(CCX_PLATFORM_MAC) || defined(CCX_PLATFORM_IPHONE) || defined(CCX_PLATFORM_WIN32) || defined(_TRANZDA_VM_)
|
||||
|
||||
#include "CCParticleSystemQuad.h"
|
||||
#define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemQuad
|
||||
|
|
|
@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/CCNS.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCScene.h"
|
||||
#include "NSMutableArray.h"
|
||||
|
@ -746,8 +747,8 @@ void CCDirector::showProfilers()
|
|||
#endif
|
||||
}
|
||||
|
||||
/***************************************************
|
||||
* mobile platforms specific functions
|
||||
/***************************************************
|
||||
* mobile platforms specific functions
|
||||
**************************************************/
|
||||
|
||||
// is the view currently attached
|
||||
|
@ -779,10 +780,10 @@ bool CCDirector::detach(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CCDirector::setDepthBufferFormat(tDepthBufferFormat kDepthBufferFormat)
|
||||
{
|
||||
assert(! isOpenGLAttached());
|
||||
m_eDepthBufferFormat = kDepthBufferFormat;
|
||||
void CCDirector::setDepthBufferFormat(tDepthBufferFormat kDepthBufferFormat)
|
||||
{
|
||||
assert(! isOpenGLAttached());
|
||||
m_eDepthBufferFormat = kDepthBufferFormat;
|
||||
}
|
||||
|
||||
void CCDirector::setPixelFormat(tPixelFormat kPixelFormat)
|
||||
|
@ -825,7 +826,11 @@ bool CCDirector::enableRetinaDisplay(bool enabled)
|
|||
|
||||
///@todo SD device iphone specific
|
||||
// if ([[UIScreen mainScreen] scale] == 1.0)
|
||||
// return NO;
float newScale = enabled ? 2 : 1;
setContentScaleFactor(newScale);
|
||||
// return NO;
|
||||
|
||||
float newScale = enabled ? 2 : 1;
|
||||
setContentScaleFactor(newScale);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -898,8 +903,8 @@ void CCDirector::setDeviceOrientation(ccDeviceOrientation kDeviceOrientation)
|
|||
}
|
||||
}
|
||||
|
||||
/***************************************************
|
||||
* PC platforms specific functions, such as mac
|
||||
/***************************************************
|
||||
* PC platforms specific functions, such as mac
|
||||
**************************************************/
|
||||
|
||||
CGPoint CCDirector::convertEventToGL(NSEvent *event)
|
||||
|
@ -937,8 +942,8 @@ CGPoint CCDirector::convertToLogicalCoordinates(CGPoint coordinates)
|
|||
}
|
||||
|
||||
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
||||
// should we afford 4 types of director ??
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __PLATFOMR_CCNS_H__
|
||||
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
|||
#ifdef CCX_PLATFORM_IPHONE
|
||||
|
||||
#include <Availability.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
//#include <Foundation/Foundation.h>
|
||||
|
||||
#define CCRectFromString(__r__) CGRectFromString(__r__)
|
||||
#define CCPointFromString(__p__) CGPointFromString(__p__)
|
||||
|
@ -43,15 +43,11 @@ THE SOFTWARE.
|
|||
#define CCTextAlignmentLeft UITextAlignmentLeft
|
||||
#define CCTextAlignmentRight UITextAlignmentRight
|
||||
|
||||
#define MacGLView void
|
||||
#define NSWindow void
|
||||
|
||||
|
||||
#elif defined(CCX_PLATFORM_MAC)
|
||||
|
||||
#include <Availability.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include "platform/MacGLView.h"
|
||||
|
||||
#define CCRectFromString(__r__) NSRectToCGRect( NSRectFromString(__r__) )
|
||||
#define CCPointFromString(__p__) NSPointToCGPoint( NSPointFromString(__p__) )
|
||||
|
@ -80,9 +76,6 @@ THE SOFTWARE.
|
|||
#define CCTextAlignmentLeft 0
|
||||
#define CCTextAlignmentRight 0
|
||||
|
||||
#define MacGLView void
|
||||
#define NSWindow void
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __PLATFOMR_CCNS_H__
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
#ifndef __CC_PLATFORM_MACROS_H__
|
||||
#define __CC_PLATFORM_MACROS_H__
|
||||
|
||||
/**
|
||||
* define some platform specific macros
|
||||
*/
|
||||
#include "config_platform.h"
|
||||
|
||||
#ifdef CCX_PLATFORM_MOBILE
|
||||
#define MacGLView void
|
||||
#define NSWindow void
|
||||
#elif defined(CCX_PLATFORM_PC)
|
||||
#include "platform/MacGLView.h"
|
||||
#endif
|
||||
|
||||
#endif // __CC_PLATFORM_MACROS_H__
|
|
@ -67,7 +67,7 @@ static id s_sharedDirectorCaller;
|
|||
|
||||
-(void) doCaller: (id) sender
|
||||
{
|
||||
cocos2d::CCDirector::sharedDirector()->preMainLoop();
|
||||
cocos2d::CCDirector::sharedDirector()->mainLoop();
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -81,6 +81,7 @@ public: inline varType get##funName(void){ return varName; }\
|
|||
public: inline void set##funName(varType var){ varName = var; }
|
||||
|
||||
#define CCX_SAFE_DELETE(p) if(p) { delete p; p=NULL; }
|
||||
#define CCX_SAFE_DELETE_ARRAY(p) if(p) { delete[] p; p=NULL;}
|
||||
#define CCX_SAFE_FREE(p) if(p) { free(p); p=NULL; }
|
||||
#define CCX_SAFE_RELEASE(p) if(p) { p->release(); }
|
||||
#define CCX_SAFE_RELEASE_NULL(p) if(p) { p->release(); p = NULL; }
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
|
||||
CGSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool canSetContentScaleFactor();
|
||||
void setContentScaleFactor(float contentScaleFactor);
|
||||
|
||||
// keep compatible
|
||||
void release();
|
||||
|
|
|
@ -50,6 +50,16 @@ bool CCXEGLView::isOpenGLReady()
|
|||
{
|
||||
return [EAGLView sharedEGLView] != NULL;
|
||||
}
|
||||
|
||||
bool CCXEGLView::canSetContentScaleFactor()
|
||||
{
|
||||
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
|
||||
}
|
||||
|
||||
void CCXEGLView::setContentScaleFactor(float contentScaleFactor)
|
||||
{
|
||||
[[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor];
|
||||
}
|
||||
|
||||
void CCXEGLView::release()
|
||||
{
|
||||
|
|
|
@ -62,6 +62,21 @@ public:
|
|||
@param pszResourcePath The absolute resource path
|
||||
*/
|
||||
static void setResourcePath(const char *pszResourcePath);
|
||||
|
||||
/** loads a file into memory.
|
||||
the caller should release the allocated buffer.
|
||||
|
||||
@returns the size of the allocated buffer
|
||||
@since v0.99.5
|
||||
*/
|
||||
static int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
|
||||
|
||||
/** removes the HD suffix from a path
|
||||
|
||||
@returns NSString * without the HD suffix
|
||||
@since v0.99.5
|
||||
*/
|
||||
static const char *ccRemoveHDSuffixFromFile( const char *path );
|
||||
|
||||
static const char* getResourcePath(void);
|
||||
};
|
||||
|
|
|
@ -34,226 +34,333 @@ THE SOFTWARE.
|
|||
|
||||
#define MAX_PATH 260
|
||||
|
||||
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
||||
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath )
|
||||
{
|
||||
// do not convert an absolute path (starting with '/')
|
||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||
if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/'))
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
NSString *path = [NSString stringWithUTF8String: pszPath]
|
||||
NSString *name = [path lastPathComponent];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) {
|
||||
|
||||
CCLOG(@"cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
|
||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX withString:@""];
|
||||
|
||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
return pszPath;
|
||||
}
|
||||
|
||||
static NSString* getDoubleResolutionImage(NSString* path)
|
||||
{
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||
{
|
||||
return pszRelativePath;
|
||||
|
||||
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
|
||||
NSString *name = [pathWithoutExtension lastPathComponent];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) {
|
||||
|
||||
CCLOG(@"cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
NSString *extension = [path pathExtension];
|
||||
|
||||
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
|
||||
{
|
||||
// All ccz / gz files should be in the format filename.xxx.ccz
|
||||
// so we need to pull off the .xxx part of the extension as well
|
||||
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
|
||||
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
|
||||
NSString *retinaName = [pathWithoutExtension stringByAppendingString:CC_RETINA_DISPLAY_FILENAME_SUFFIX];
|
||||
retinaName = [retinaName stringByAppendingPathExtension:extension];
|
||||
|
||||
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
|
||||
if( [fileManager fileExistsAtPath:retinaName] )
|
||||
return retinaName;
|
||||
|
||||
CCLOG(@"cocos2d: CCFileUtils: Warning HD file not found: %@", [retinaName lastPathComponent] );
|
||||
}
|
||||
|
||||
NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]];
|
||||
NSString *file = [imagePathComponents lastObject];
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
[imagePathComponents removeLastObject];
|
||||
NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents];
|
||||
return path;
|
||||
}
|
||||
|
||||
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
||||
|
||||
{
|
||||
|
||||
NSAssert(pszRelativePath != nil, @"CCFileUtils: Invalid path");
|
||||
|
||||
// do not convert an absolute path (starting with '/')
|
||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||
NSString *fullpath = nil;
|
||||
|
||||
// only if it is not an absolute path
|
||||
if( ! [relPath isAbsolutePath] )
|
||||
{
|
||||
NSString *file = [relPath lastPathComponent];
|
||||
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
|
||||
|
||||
fullpath = [[NSBundle mainBundle] pathForResource:file
|
||||
ofType:nil
|
||||
inDirectory:imageDirectory];
|
||||
}
|
||||
|
||||
NSString *fullpath = [[NSBundle mainBundle] pathForResource:file
|
||||
ofType:nil
|
||||
inDirectory:imageDirectory];
|
||||
if (fullpath == nil)
|
||||
fullpath = relPath;
|
||||
|
||||
|
||||
fullpath = getDoubleResolutionImage(fullpath);
|
||||
|
||||
return [fullpath UTF8String];
|
||||
}
|
||||
|
||||
namespace cocos2d {
|
||||
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
||||
void plist_endElement(void *ctx, const xmlChar *name);
|
||||
void plist_characters(void *ctx, const xmlChar *ch, int len);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SAX_NONE = 0,
|
||||
SAX_KEY,
|
||||
SAX_DICT,
|
||||
SAX_INT,
|
||||
SAX_REAL,
|
||||
SAX_STRING
|
||||
}CCSAXState;
|
||||
|
||||
class CCDictMaker
|
||||
{
|
||||
public:
|
||||
NSDictionary<std::string, NSObject*> *m_pRootDict;
|
||||
NSDictionary<std::string, NSObject*> *m_pCurDict;
|
||||
std::stack<NSDictionary<std::string, NSObject*>*> m_tDictStack;
|
||||
std::string m_sCurKey;///< parsed key
|
||||
CCSAXState m_tState;
|
||||
public:
|
||||
CCDictMaker()
|
||||
{
|
||||
m_pRootDict = NULL;
|
||||
m_pCurDict = NULL;
|
||||
m_tState = SAX_NONE;
|
||||
}
|
||||
~CCDictMaker()
|
||||
{
|
||||
}
|
||||
NSDictionary<std::string, NSObject*> *dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
if( !(fp = fopen(pFileName, "r")) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
fseek(fp,0,SEEK_END);
|
||||
int size = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
char *buffer = new char[size+1];
|
||||
fread(buffer,sizeof(char),size,fp);
|
||||
fclose(fp);
|
||||
/*
|
||||
* this initialize the library and check potential ABI mismatches
|
||||
* between the version it was compiled for and the actual shared
|
||||
* library used.
|
||||
*/
|
||||
LIBXML_TEST_VERSION
|
||||
xmlSAXHandler saxHandler;
|
||||
memset( &saxHandler, 0, sizeof(saxHandler) );
|
||||
// Using xmlSAXVersion( &saxHandler, 2 ) generate crash as it sets plenty of other pointers...
|
||||
saxHandler.initialized = XML_SAX2_MAGIC; // so we do this to force parsing as SAX2.
|
||||
saxHandler.startElement = &plist_startElement;
|
||||
saxHandler.endElement = &plist_endElement;
|
||||
saxHandler.characters = &plist_characters;
|
||||
|
||||
int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );
|
||||
if ( result != 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* Cleanup function for the XML library.
|
||||
*/
|
||||
xmlCleanupParser();
|
||||
/*
|
||||
* this is to debug memory for regression tests
|
||||
*/
|
||||
xmlMemoryDump();
|
||||
delete []buffer;
|
||||
return m_pRootDict;
|
||||
}
|
||||
};
|
||||
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
|
||||
{
|
||||
CCDictMaker *pMaker = (CCDictMaker*)(ctx);
|
||||
std::string sName((char*)name);
|
||||
if( sName == "dict" )
|
||||
{
|
||||
NSDictionary<std::string, NSObject*> *pNewDict = new NSDictionary<std::string, NSObject*>();
|
||||
if(! pMaker->m_pRootDict)
|
||||
{
|
||||
pMaker->m_pRootDict = pNewDict;
|
||||
pNewDict->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
NSAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
|
||||
pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
|
||||
pNewDict->release();
|
||||
pMaker->m_sCurKey.clear();
|
||||
}
|
||||
pMaker->m_pCurDict = pNewDict;
|
||||
pMaker->m_tDictStack.push(pMaker->m_pCurDict);
|
||||
pMaker->m_tState = SAX_DICT;
|
||||
}
|
||||
else if(sName == "key")
|
||||
{
|
||||
pMaker->m_tState = SAX_KEY;
|
||||
}
|
||||
else if(sName == "integer")
|
||||
{
|
||||
pMaker->m_tState = SAX_INT;
|
||||
}
|
||||
else if(sName == "real")
|
||||
{
|
||||
pMaker->m_tState = SAX_REAL;
|
||||
}
|
||||
else if(sName == "string")
|
||||
{
|
||||
pMaker->m_tState = SAX_STRING;
|
||||
}
|
||||
else
|
||||
{
|
||||
pMaker->m_tState = SAX_NONE;
|
||||
}
|
||||
}
|
||||
void plist_endElement(void *ctx, const xmlChar *name)
|
||||
{
|
||||
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
|
||||
std::string sName((char*)name);
|
||||
if( sName == "dict" )
|
||||
{
|
||||
pMaker->m_tDictStack.pop();
|
||||
if ( !pMaker->m_tDictStack.empty() )
|
||||
{
|
||||
pMaker->m_pCurDict = (NSDictionary<std::string, NSObject*>*)(pMaker->m_tDictStack.top());
|
||||
}
|
||||
}
|
||||
pMaker->m_tState = SAX_NONE;
|
||||
}
|
||||
void plist_characters(void *ctx, const xmlChar *ch, int len)
|
||||
{
|
||||
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
|
||||
if (pMaker->m_tState == SAX_NONE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NSString *pText = new NSString();
|
||||
pText->m_sString = std::string((char*)ch,0,len);
|
||||
|
||||
switch(pMaker->m_tState)
|
||||
{
|
||||
case SAX_KEY:
|
||||
pMaker->m_sCurKey = pText->m_sString;
|
||||
break;
|
||||
case SAX_INT:
|
||||
case SAX_REAL:
|
||||
case SAX_STRING:
|
||||
{
|
||||
NSAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
|
||||
pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pText->release();
|
||||
}
|
||||
|
||||
// record the resource path
|
||||
static char s_pszResourcePath[MAX_PATH] = {0};
|
||||
|
||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||
{
|
||||
NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||
NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||
|
||||
strcpy(s_pszResourcePath, pszResourcePath);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::getResourcePath()
|
||||
{
|
||||
return s_pszResourcePath;
|
||||
}
|
||||
|
||||
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
||||
void plist_endElement(void *ctx, const xmlChar *name);
|
||||
void plist_characters(void *ctx, const xmlChar *ch, int len);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SAX_NONE = 0,
|
||||
SAX_KEY,
|
||||
SAX_DICT,
|
||||
SAX_INT,
|
||||
SAX_REAL,
|
||||
SAX_STRING
|
||||
}CCSAXState;
|
||||
|
||||
class CCDictMaker
|
||||
{
|
||||
public:
|
||||
NSDictionary<std::string, NSObject*> *m_pRootDict;
|
||||
NSDictionary<std::string, NSObject*> *m_pCurDict;
|
||||
std::stack<NSDictionary<std::string, NSObject*>*> m_tDictStack;
|
||||
std::string m_sCurKey;///< parsed key
|
||||
CCSAXState m_tState;
|
||||
public:
|
||||
CCDictMaker()
|
||||
{
|
||||
m_pRootDict = NULL;
|
||||
m_pCurDict = NULL;
|
||||
m_tState = SAX_NONE;
|
||||
}
|
||||
~CCDictMaker()
|
||||
{
|
||||
}
|
||||
NSDictionary<std::string, NSObject*> *dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
if( !(fp = fopen(pFileName, "r")) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
fseek(fp,0,SEEK_END);
|
||||
int size = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
char *buffer = new char[size+1];
|
||||
fread(buffer,sizeof(char),size,fp);
|
||||
fclose(fp);
|
||||
/*
|
||||
* this initialize the library and check potential ABI mismatches
|
||||
* between the version it was compiled for and the actual shared
|
||||
* library used.
|
||||
*/
|
||||
LIBXML_TEST_VERSION
|
||||
xmlSAXHandler saxHandler;
|
||||
memset( &saxHandler, 0, sizeof(saxHandler) );
|
||||
// Using xmlSAXVersion( &saxHandler, 2 ) generate crash as it sets plenty of other pointers...
|
||||
saxHandler.initialized = XML_SAX2_MAGIC; // so we do this to force parsing as SAX2.
|
||||
saxHandler.startElement = &plist_startElement;
|
||||
saxHandler.endElement = &plist_endElement;
|
||||
saxHandler.characters = &plist_characters;
|
||||
|
||||
int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );
|
||||
if ( result != 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* Cleanup function for the XML library.
|
||||
*/
|
||||
xmlCleanupParser();
|
||||
/*
|
||||
* this is to debug memory for regression tests
|
||||
*/
|
||||
xmlMemoryDump();
|
||||
delete []buffer;
|
||||
return m_pRootDict;
|
||||
}
|
||||
};
|
||||
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
|
||||
{
|
||||
CCDictMaker *pMaker = (CCDictMaker*)(ctx);
|
||||
std::string sName((char*)name);
|
||||
if( sName == "dict" )
|
||||
{
|
||||
NSDictionary<std::string, NSObject*> *pNewDict = new NSDictionary<std::string, NSObject*>();
|
||||
if(! pMaker->m_pRootDict)
|
||||
{
|
||||
pMaker->m_pRootDict = pNewDict;
|
||||
pNewDict->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
NSAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
|
||||
pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
|
||||
pNewDict->release();
|
||||
pMaker->m_sCurKey.clear();
|
||||
}
|
||||
pMaker->m_pCurDict = pNewDict;
|
||||
pMaker->m_tDictStack.push(pMaker->m_pCurDict);
|
||||
pMaker->m_tState = SAX_DICT;
|
||||
}
|
||||
else if(sName == "key")
|
||||
{
|
||||
pMaker->m_tState = SAX_KEY;
|
||||
}
|
||||
else if(sName == "integer")
|
||||
{
|
||||
pMaker->m_tState = SAX_INT;
|
||||
}
|
||||
else if(sName == "real")
|
||||
{
|
||||
pMaker->m_tState = SAX_REAL;
|
||||
}
|
||||
else if(sName == "string")
|
||||
{
|
||||
pMaker->m_tState = SAX_STRING;
|
||||
}
|
||||
else
|
||||
{
|
||||
pMaker->m_tState = SAX_NONE;
|
||||
}
|
||||
}
|
||||
void plist_endElement(void *ctx, const xmlChar *name)
|
||||
{
|
||||
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
|
||||
std::string sName((char*)name);
|
||||
if( sName == "dict" )
|
||||
{
|
||||
pMaker->m_tDictStack.pop();
|
||||
if ( !pMaker->m_tDictStack.empty() )
|
||||
{
|
||||
pMaker->m_pCurDict = (NSDictionary<std::string, NSObject*>*)(pMaker->m_tDictStack.top());
|
||||
}
|
||||
}
|
||||
pMaker->m_tState = SAX_NONE;
|
||||
}
|
||||
void plist_characters(void *ctx, const xmlChar *ch, int len)
|
||||
{
|
||||
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
|
||||
if (pMaker->m_tState == SAX_NONE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NSString *pText = new NSString();
|
||||
pText->m_sString = std::string((char*)ch,0,len);
|
||||
|
||||
switch(pMaker->m_tState)
|
||||
{
|
||||
case SAX_KEY:
|
||||
pMaker->m_sCurKey = pText->m_sString;
|
||||
break;
|
||||
case SAX_INT:
|
||||
case SAX_REAL:
|
||||
case SAX_STRING:
|
||||
{
|
||||
NSAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
|
||||
pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pText->release();
|
||||
}
|
||||
|
||||
// record the resource path
|
||||
static char s_pszResourcePath[MAX_PATH] = {0};
|
||||
|
||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||
{
|
||||
NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||
NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||
|
||||
strcpy(s_pszResourcePath, pszResourcePath);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::getResourcePath()
|
||||
{
|
||||
return s_pszResourcePath;
|
||||
}
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
return static_fullPathFromRelativePath(pszRelativePath);
|
||||
}
|
||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||
{
|
||||
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||
NSString *pRet = new NSString();
|
||||
pRet->autorelease();
|
||||
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
|
||||
pRet->m_sString += pszFilename;
|
||||
return pRet->m_sString.c_str();
|
||||
}
|
||||
NSDictionary<std::string, NSObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
CCDictMaker tMaker;
|
||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||
}
|
||||
|
||||
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||
{
|
||||
assert( out );
|
||||
assert( &*out );
|
||||
|
||||
int size = 0;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if( !f ) {
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
*out = (unsigned char*)malloc(size);
|
||||
int read = fread(*out, 1, size, f);
|
||||
if( read != size ) {
|
||||
free(*out);
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
const char* CCFileUtils::ccRemoveHDSuffixFromFile( const char *path )
|
||||
{
|
||||
return static_ccRemoveHDSuffixFromFile(path);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
return static_fullPathFromRelativePath(pszRelativePath);
|
||||
}
|
||||
|
||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||
{
|
||||
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||
NSString *pRet = new NSString();
|
||||
pRet->autorelease();
|
||||
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
|
||||
pRet->m_sString += pszFilename;
|
||||
return pRet->m_sString.c_str();
|
||||
}
|
||||
NSDictionary<std::string, NSObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
CCDictMaker tMaker;
|
||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||
}
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
- kImageFormatJPG -> jpeg
|
||||
@return true if load correctly
|
||||
*/
|
||||
bool initWithContentsOfFile(const std::string &strPath, tImageFormat imageType = kImageFormatPNG);
|
||||
bool initWithContentsOfFile(const std::string &strPath, tImageFormat imageType = kCCImageFormatPNG);
|
||||
/**
|
||||
Load image from stream buffer.
|
||||
@param pBuffer stream buffer that hold the image data
|
||||
|
|
|
@ -319,8 +319,8 @@ bool UIImage::initWithContentsOfFile(const string &strPath, tImageFormat imageTy
|
|||
|
||||
switch (imageType)
|
||||
{
|
||||
case kImageFormatPNG:
|
||||
case kImageFormatJPG:
|
||||
case kCCImageFormatPNG:
|
||||
case kCCImageFormatJPG:
|
||||
bRet = static_initWithFile(strPath.c_str(), &m_imageInfo);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -77,7 +77,7 @@ static EAGLView *view;
|
|||
static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||
|
||||
@interface EAGLView (Private)
|
||||
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
|
||||
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
|
||||
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat;
|
||||
@end
|
||||
|
||||
|
@ -105,14 +105,14 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
|||
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format] autorelease];
|
||||
}
|
||||
|
||||
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth
|
||||
{
|
||||
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0] autorelease];
|
||||
}
|
||||
|
||||
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples
|
||||
{
|
||||
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained sharegroup:sharegroup multiSampling:multisampling numberOfSamples:samples] autorelease];
|
||||
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth
|
||||
{
|
||||
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0] autorelease];
|
||||
}
|
||||
|
||||
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)multisampling numberOfSamples:(unsigned int)samples
|
||||
{
|
||||
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained sharegroup:sharegroup multiSampling:multisampling numberOfSamples:samples] autorelease];
|
||||
}
|
||||
|
||||
+ (id) sharedEGLView
|
||||
|
@ -129,22 +129,22 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
|||
|
||||
- (id) initWithFrame:(CGRect)frame
|
||||
{
|
||||
return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
|
||||
return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
|
||||
}
|
||||
|
||||
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format
|
||||
{
|
||||
return [self initWithFrame:frame pixelFormat:format depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
|
||||
return [self initWithFrame:frame pixelFormat:format depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0];
|
||||
}
|
||||
|
||||
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained
|
||||
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples;
|
||||
{
|
||||
if((self = [super initWithFrame:frame]))
|
||||
{
|
||||
pixelformat_ = format;
|
||||
depthFormat_ = depth;
|
||||
multiSampling_ = sampling;
|
||||
requestedSamples_ = nSamples;
|
||||
multiSampling_ = sampling;
|
||||
requestedSamples_ = nSamples;
|
||||
preserveBackbuffer_ = retained;
|
||||
|
||||
if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
|
||||
|
@ -159,20 +159,20 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
|||
|
||||
-(id) initWithCoder:(NSCoder *)aDecoder
|
||||
{
|
||||
if( (self = [super initWithCoder:aDecoder]) ) {
|
||||
|
||||
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer];
|
||||
|
||||
pixelformat_ = kEAGLColorFormatRGB565;
|
||||
depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES;
|
||||
multiSampling_= NO;
|
||||
requestedSamples_ = 0;
|
||||
size_ = [eaglLayer bounds].size;
|
||||
|
||||
if( ! [self setupSurfaceWithSharegroup:nil] ) {
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
if( (self = [super initWithCoder:aDecoder]) ) {
|
||||
|
||||
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer];
|
||||
|
||||
pixelformat_ = kEAGLColorFormatRGB565;
|
||||
depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES;
|
||||
multiSampling_= NO;
|
||||
requestedSamples_ = 0;
|
||||
size_ = [eaglLayer bounds].size;
|
||||
|
||||
if( ! [self setupSurfaceWithSharegroup:nil] ) {
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
view = self;
|
||||
|
@ -220,30 +220,30 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
|||
indexBitsUsed &= temp;
|
||||
}
|
||||
|
||||
-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
|
||||
{
|
||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking,
|
||||
pixelformat_, kEAGLDrawablePropertyColorFormat, nil];
|
||||
|
||||
|
||||
renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_
|
||||
withPixelFormat:[self convertPixelFormat:pixelformat_]
|
||||
withSharegroup:sharegroup
|
||||
withMultiSampling:multiSampling_
|
||||
withNumberOfSamples:requestedSamples_];
|
||||
if (!renderer_)
|
||||
return NO;
|
||||
|
||||
context_ = [renderer_ context];
|
||||
[context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
|
||||
|
||||
//discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer];
|
||||
|
||||
return YES;
|
||||
-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
|
||||
{
|
||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking,
|
||||
pixelformat_, kEAGLDrawablePropertyColorFormat, nil];
|
||||
|
||||
|
||||
renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_
|
||||
withPixelFormat:[self convertPixelFormat:pixelformat_]
|
||||
withSharegroup:sharegroup
|
||||
withMultiSampling:multiSampling_
|
||||
withNumberOfSamples:requestedSamples_];
|
||||
if (!renderer_)
|
||||
return NO;
|
||||
|
||||
context_ = [renderer_ context];
|
||||
[context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
|
||||
|
||||
//discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -255,93 +255,93 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
|||
|
||||
- (void) layoutSubviews
|
||||
{
|
||||
[renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer];
|
||||
size_ = [renderer_ backingSize];
|
||||
|
||||
// Issue #914 #924
|
||||
[renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer];
|
||||
size_ = [renderer_ backingSize];
|
||||
|
||||
// Issue #914 #924
|
||||
// CCDirector *director = [CCDirector sharedDirector];
|
||||
// [director reshapeProjection:size_];
|
||||
cocos2d::CGSize size;
|
||||
size.width = size_.width;
|
||||
size.height = size_.height;
|
||||
cocos2d::CCDirector::sharedDirector()->reshapeProjection(size);
|
||||
|
||||
// Avoid flicker. Issue #350
|
||||
|
||||
// Avoid flicker. Issue #350
|
||||
//[director performSelectorOnMainThread:@selector(drawScene) withObject:nil waitUntilDone:YES];
|
||||
cocos2d::CCDirector::sharedDirector()->drawScene();
|
||||
}
|
||||
|
||||
- (void) swapBuffers
|
||||
{
|
||||
// IMPORTANT:
|
||||
// - preconditions
|
||||
// -> context_ MUST be the OpenGL context
|
||||
// -> renderbuffer_ must be the the RENDER BUFFER
|
||||
|
||||
#ifdef __IPHONE_4_0
|
||||
|
||||
if (multiSampling_)
|
||||
{
|
||||
/* Resolve from msaaFramebuffer to resolveFramebuffer */
|
||||
//glDisable(GL_SCISSOR_TEST);
|
||||
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]);
|
||||
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]);
|
||||
glResolveMultisampleFramebufferAPPLE();
|
||||
}
|
||||
|
||||
if( discardFramebufferSupported_)
|
||||
{
|
||||
if (multiSampling_)
|
||||
{
|
||||
if (depthFormat_)
|
||||
{
|
||||
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES};
|
||||
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES};
|
||||
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
|
||||
}
|
||||
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]);
|
||||
|
||||
}
|
||||
|
||||
// not MSAA
|
||||
else if (depthFormat_ ) {
|
||||
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES};
|
||||
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __IPHONE_4_0
|
||||
|
||||
// IMPORTANT:
|
||||
// - preconditions
|
||||
// -> context_ MUST be the OpenGL context
|
||||
// -> renderbuffer_ must be the the RENDER BUFFER
|
||||
|
||||
#ifdef __IPHONE_4_0
|
||||
|
||||
if (multiSampling_)
|
||||
{
|
||||
/* Resolve from msaaFramebuffer to resolveFramebuffer */
|
||||
//glDisable(GL_SCISSOR_TEST);
|
||||
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]);
|
||||
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]);
|
||||
glResolveMultisampleFramebufferAPPLE();
|
||||
}
|
||||
|
||||
if( discardFramebufferSupported_)
|
||||
{
|
||||
if (multiSampling_)
|
||||
{
|
||||
if (depthFormat_)
|
||||
{
|
||||
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES};
|
||||
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES};
|
||||
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
|
||||
}
|
||||
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]);
|
||||
|
||||
}
|
||||
|
||||
// not MSAA
|
||||
else if (depthFormat_ ) {
|
||||
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES};
|
||||
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __IPHONE_4_0
|
||||
|
||||
// if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
|
||||
// CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);
|
||||
|
||||
#if COCOS2D_DEBUG
|
||||
CHECK_GL_ERROR();
|
||||
#endif
|
||||
|
||||
// We can safely re-bind the framebuffer here, since this will be the
|
||||
// 1st instruction of the new main loop
|
||||
if( multiSampling_ )
|
||||
|
||||
#if COCOS2D_DEBUG
|
||||
CHECK_GL_ERROR();
|
||||
#endif
|
||||
|
||||
// We can safely re-bind the framebuffer here, since this will be the
|
||||
// 1st instruction of the new main loop
|
||||
if( multiSampling_ )
|
||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, [renderer_ msaaFrameBuffer]);
|
||||
}
|
||||
|
||||
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat
|
||||
{
|
||||
// define the pixel format
|
||||
GLenum pFormat;
|
||||
|
||||
|
||||
if([pixelFormat isEqualToString:@"EAGLColorFormat565"])
|
||||
pFormat = GL_RGB565_OES;
|
||||
else
|
||||
pFormat = GL_RGBA8_OES;
|
||||
|
||||
return pFormat;
|
||||
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat
|
||||
{
|
||||
// define the pixel format
|
||||
GLenum pFormat;
|
||||
|
||||
|
||||
if([pixelFormat isEqualToString:@"EAGLColorFormat565"])
|
||||
pFormat = GL_RGB565_OES;
|
||||
else
|
||||
pFormat = GL_RGBA8_OES;
|
||||
|
||||
return pFormat;
|
||||
}
|
||||
|
||||
#pragma mark EAGLView - Point conversion
|
||||
|
|
Loading…
Reference in New Issue