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 "NSMutableArray.h"
|
||||||
#include "CGGeometry.h"
|
#include "CGGeometry.h"
|
||||||
#include "CCXCocos2dDefine.h"
|
#include "CCXCocos2dDefine.h"
|
||||||
#include <string.h>
|
#include <string>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
class CCSpriteFrame;
|
class CCSpriteFrame;
|
||||||
|
@ -41,119 +41,119 @@ namespace cocos2d {
|
||||||
[sprite runAction:[CCAnimate actionWithAnimation:animation]];
|
[sprite runAction:[CCAnimate actionWithAnimation:animation]];
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class CCX_DLL CCAnimation : public NSObject
|
class CCX_DLL CCAnimation : public NSObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string m_nameStr;
|
std::string m_nameStr;
|
||||||
float m_fDelay;
|
float m_fDelay;
|
||||||
NSMutableArray<CCSpriteFrame*> *m_pobFrames;
|
NSMutableArray<CCSpriteFrame*> *m_pobFrames;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// attributes
|
// attributes
|
||||||
|
|
||||||
/** get name of the animation */
|
/** get name of the animation */
|
||||||
inline const char* getName(void) { return m_nameStr.c_str(); }
|
inline const char* getName(void) { return m_nameStr.c_str(); }
|
||||||
/** set name of the animation */
|
/** set name of the animation */
|
||||||
inline void setName(const char *pszName){ m_nameStr = pszName; }
|
inline void setName(const char *pszName){ m_nameStr = pszName; }
|
||||||
|
|
||||||
/** get delay between frames in seconds */
|
/** get delay between frames in seconds */
|
||||||
inline float getDelay(void) { return m_fDelay; }
|
inline float getDelay(void) { return m_fDelay; }
|
||||||
/** set delay between frames in seconds */
|
/** set delay between frames in seconds */
|
||||||
inline void setDelay(float fDelay) { m_fDelay = fDelay; }
|
inline void setDelay(float fDelay) { m_fDelay = fDelay; }
|
||||||
|
|
||||||
/** get array of frames */
|
/** get array of frames */
|
||||||
inline NSMutableArray<CCSpriteFrame*>* getFrames(void) { return m_pobFrames; }
|
inline NSMutableArray<CCSpriteFrame*>* getFrames(void) { return m_pobFrames; }
|
||||||
/** set array of frames, the Frames is retained */
|
/** set array of frames, the Frames is retained */
|
||||||
inline void setFrames(NSMutableArray<CCSpriteFrame*> *pFrames)
|
inline void setFrames(NSMutableArray<CCSpriteFrame*> *pFrames)
|
||||||
{
|
{
|
||||||
CCX_SAFE_RETAIN(pFrames);
|
CCX_SAFE_RETAIN(pFrames);
|
||||||
CCX_SAFE_RELEASE(m_pobFrames);
|
CCX_SAFE_RELEASE(m_pobFrames);
|
||||||
m_pobFrames = pFrames;
|
m_pobFrames = pFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~CCAnimation(void);
|
~CCAnimation(void);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with frames.
|
/** Initializes a CCAnimation with frames.
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames);
|
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with frames and a delay between frames
|
/** Initializes a CCAnimation with frames and a delay between frames
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames, float delay);
|
bool initWithFrames(NSArray<CCSpriteFrame*> *pFrames, float delay);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with a name
|
/** Initializes a CCAnimation with a name
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
@deprecated Will be removed in 1.0.1. Use "init" instead.
|
@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
|
/** Initializes a CCAnimation with a name and frames
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
@deprecated Will be removed in 1.0.1. Use "initWithFrames" instead.
|
@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.
|
/** Initializes a CCAnimation with a name and delay between frames.
|
||||||
@deprecated Will be removed in 1.0.1. Use "initWithFrames:nil delay:delay" instead.
|
@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.
|
/** 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.
|
@deprecated Will be removed in 1.0.1. Use "initWithFrames:frames delay:delay" instead.
|
||||||
*/
|
*/
|
||||||
bool initWithName(const char *pszName, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
bool initWithName(const char *pszName, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
||||||
|
|
||||||
/** adds a frame to a CCAnimation */
|
/** adds a frame to a CCAnimation */
|
||||||
void addFrame(CCSpriteFrame *pFrame);
|
void addFrame(CCSpriteFrame *pFrame);
|
||||||
|
|
||||||
/** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
|
/** 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.
|
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.
|
/** 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.
|
Added to facilitate the migration from v0.8 to v0.9.
|
||||||
*/
|
*/
|
||||||
void addFrameWithTexture(CCTexture2D* pobTexture, CGRect rect);
|
void addFrameWithTexture(CCTexture2D* pobTexture, CGRect rect);
|
||||||
|
|
||||||
bool init(void);
|
bool init(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Creates an animation
|
/** Creates an animation
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animation(void);
|
static CCAnimation* animation(void);
|
||||||
|
|
||||||
/** Creates an animation with frames.
|
/** Creates an animation with frames.
|
||||||
@since v0.99.5
|
@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.
|
/* Creates an animation with frames and a delay between frames.
|
||||||
@since v0.99.5
|
@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
|
/** Creates a CCAnimation with a name
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
@deprecated Will be removed in 1.0.1. Use "animation" instead.
|
@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
|
/** Creates a CCAnimation with a name and frames
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
@deprecated Will be removed in 1.0.1. Use "animationWithFrames" instead.
|
@deprecated Will be removed in 1.0.1. Use "animationWithFrames" instead.
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithName(const char *pszName, NSArray<CCSpriteFrame*> *pFrames);
|
static CCAnimation* animationWithName(const char *pszName, NSArray<CCSpriteFrame*> *pFrames);
|
||||||
|
|
||||||
/** Creates a CCAnimation with a name and delay between frames. */
|
/** Creates a CCAnimation with a name and delay between frames. */
|
||||||
static CCAnimation* animationWithName(const char *pszName, float fDelay);
|
static CCAnimation* animationWithName(const char *pszName, float fDelay);
|
||||||
|
|
||||||
/** Creates a CCAnimation with a name, delay and an array of CCSpriteFrames. */
|
/** 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, float fDelay, NSArray<CCSpriteFrame*> *pFrames);
|
||||||
};
|
};
|
||||||
} // end of name sapce cocos2d
|
} // end of name sapce cocos2d
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
||||||
#ifndef __CCDIRECTOR_H__
|
#ifndef __CCDIRECTOR_H__
|
||||||
#define __CCDIRECTOR_H__
|
#define __CCDIRECTOR_H__
|
||||||
|
|
||||||
|
#include "platform/CCPlatformMacros.h"
|
||||||
#include "ccConfig.h"
|
#include "ccConfig.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "CCXCocos2dDefine.h"
|
#include "CCXCocos2dDefine.h"
|
||||||
|
@ -35,9 +36,8 @@ THE SOFTWARE.
|
||||||
#include "CCXEGLView.h"
|
#include "CCXEGLView.h"
|
||||||
#include "ccxCommon.h"
|
#include "ccxCommon.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "platform/CCNS.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -269,7 +269,7 @@ public:
|
||||||
*/
|
*/
|
||||||
CGSize getDisplaySizeInPixels(void);
|
CGSize getDisplaySizeInPixels(void);
|
||||||
|
|
||||||
/** changes the projection size */
|
/** changes the projection size */
|
||||||
void reshapeProjection(CGSize newWindowSize);
|
void reshapeProjection(CGSize newWindowSize);
|
||||||
|
|
||||||
/** converts a UIKit coordinate to an OpenGL coordinate
|
/** converts a UIKit coordinate to an OpenGL coordinate
|
||||||
|
@ -543,7 +543,7 @@ protected:
|
||||||
/* store the fps string */
|
/* store the fps string */
|
||||||
char *m_pszFPS;
|
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;
|
CCNode *m_pNotificationNode;
|
||||||
|
|
||||||
/* Projection protocol delegate */
|
/* Projection protocol delegate */
|
||||||
|
|
|
@ -25,71 +25,71 @@ THE SOFTWARE.
|
||||||
#define __CCRENDER_TEXTURE_H__
|
#define __CCRENDER_TEXTURE_H__
|
||||||
|
|
||||||
#include "NSData.h"
|
#include "NSData.h"
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCSprite.h"
|
#include "CCSprite.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
enum eImageFormat
|
typedef enum eImageFormat
|
||||||
{
|
{
|
||||||
kCCImageFormatJPG = 0,
|
kCCImageFormatJPG = 0,
|
||||||
kCCImageFormatPNG = 1,
|
kCCImageFormatPNG = 1,
|
||||||
kCCImageFormatRawData = 2
|
kCCImageFormatRawData = 2
|
||||||
};
|
} tImageFormat;
|
||||||
/**
|
/**
|
||||||
@brief CCRenderTexture is a generic rendering target. To render things into it,
|
@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
|
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
|
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
|
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.
|
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.
|
There are also functions for saving the render texture to disk in PNG or JPG format.
|
||||||
|
|
||||||
@since v0.8.1
|
@since v0.8.1
|
||||||
*/
|
*/
|
||||||
class CCX_DLL CCRenderTexture : public CCNode
|
class CCX_DLL CCRenderTexture : public CCNode
|
||||||
{
|
{
|
||||||
/** The CCSprite being used.
|
/** The CCSprite being used.
|
||||||
The sprite, by default, will use the following blending function: GL_ONE, GL_ONE_MINUS_SRC_ALPHA.
|
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:
|
The blending function can be changed in runtime by calling:
|
||||||
- [[renderTexture sprite] setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
- [[renderTexture sprite] setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||||
*/
|
*/
|
||||||
CCX_PROPERTY(CCSprite*, m_pSprite, Sprite)
|
CCX_PROPERTY(CCSprite*, m_pSprite, Sprite)
|
||||||
public:
|
public:
|
||||||
CCRenderTexture();
|
CCRenderTexture();
|
||||||
virtual ~CCRenderTexture();
|
virtual ~CCRenderTexture();
|
||||||
/** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
|
/** 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);
|
static CCRenderTexture * renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat);
|
||||||
|
|
||||||
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */
|
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */
|
||||||
static CCRenderTexture * renderTextureWithWidthAndHeight(int w, int h);
|
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 */
|
/** 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);
|
bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat);
|
||||||
|
|
||||||
/** starts grabbing */
|
/** starts grabbing */
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
/** starts rendering to the texture while clearing the texture first.
|
/** starts rendering to the texture while clearing the texture first.
|
||||||
This is more efficient then calling -clear first and then -begin */
|
This is more efficient then calling -clear first and then -begin */
|
||||||
void beginWithClear(float r, float g, float b, float a);
|
void beginWithClear(float r, float g, float b, float a);
|
||||||
|
|
||||||
/** ends grabbing */
|
/** ends grabbing */
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
/** clears the texture with a color */
|
/** clears the texture with a color */
|
||||||
void clear(float r, float g, float b, float a);
|
void clear(float r, float g, float b, float a);
|
||||||
|
|
||||||
/** saves the texture into a file */
|
/** saves the texture into a file */
|
||||||
bool saveBuffer(const char *name);
|
bool saveBuffer(const char *name);
|
||||||
/** saves the texture into a file. The format can be JPG or PNG */
|
/** saves the texture into a file. The format can be JPG or PNG */
|
||||||
bool saveBuffer(const char *name, int format);
|
bool saveBuffer(const char *name, int format);
|
||||||
|
|
||||||
/* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */
|
/* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */
|
||||||
NSData *getUIImageAsDataFromBuffer(int format);
|
NSData *getUIImageAsDataFromBuffer(int format);
|
||||||
protected:
|
protected:
|
||||||
GLuint m_uFBO;
|
GLuint m_uFBO;
|
||||||
GLint m_nOldFBO;
|
GLint m_nOldFBO;
|
||||||
CCTexture2D* m_pTexture;
|
CCTexture2D* m_pTexture;
|
||||||
|
|
||||||
GLenum m_ePixelFormat;
|
GLenum m_ePixelFormat;
|
||||||
GLfloat m_aClearColor[4];
|
GLfloat m_aClearColor[4];
|
||||||
|
@ -97,7 +97,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
void saveGLstate();
|
void saveGLstate();
|
||||||
void restoreGLstate();
|
void restoreGLstate();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cocos2d
|
} // namespace cocos2d
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
// build each architecture with the optimal particle system
|
// build each architecture with the optimal particle system
|
||||||
|
|
||||||
// ARMv7, Mac or Simulator use "Quad" particle
|
// 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"
|
#include "CCParticleSystemQuad.h"
|
||||||
#define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemQuad
|
#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.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "platform/CCNS.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCScene.h"
|
#include "CCScene.h"
|
||||||
#include "NSMutableArray.h"
|
#include "NSMutableArray.h"
|
||||||
|
@ -746,8 +747,8 @@ void CCDirector::showProfilers()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
* mobile platforms specific functions
|
* mobile platforms specific functions
|
||||||
**************************************************/
|
**************************************************/
|
||||||
|
|
||||||
// is the view currently attached
|
// is the view currently attached
|
||||||
|
@ -779,10 +780,10 @@ bool CCDirector::detach(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCDirector::setDepthBufferFormat(tDepthBufferFormat kDepthBufferFormat)
|
void CCDirector::setDepthBufferFormat(tDepthBufferFormat kDepthBufferFormat)
|
||||||
{
|
{
|
||||||
assert(! isOpenGLAttached());
|
assert(! isOpenGLAttached());
|
||||||
m_eDepthBufferFormat = kDepthBufferFormat;
|
m_eDepthBufferFormat = kDepthBufferFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCDirector::setPixelFormat(tPixelFormat kPixelFormat)
|
void CCDirector::setPixelFormat(tPixelFormat kPixelFormat)
|
||||||
|
@ -825,7 +826,11 @@ bool CCDirector::enableRetinaDisplay(bool enabled)
|
||||||
|
|
||||||
///@todo SD device iphone specific
|
///@todo SD device iphone specific
|
||||||
// if ([[UIScreen mainScreen] scale] == 1.0)
|
// 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;
|
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)
|
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 ??
|
// should we afford 4 types of director ??
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __PLATFOMR_CCNS_H__
|
#ifndef __PLATFOMR_CCNS_H__
|
||||||
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
#ifdef CCX_PLATFORM_IPHONE
|
#ifdef CCX_PLATFORM_IPHONE
|
||||||
|
|
||||||
#include <Availability.h>
|
#include <Availability.h>
|
||||||
#include <Foundation/Foundation.h>
|
//#include <Foundation/Foundation.h>
|
||||||
|
|
||||||
#define CCRectFromString(__r__) CGRectFromString(__r__)
|
#define CCRectFromString(__r__) CGRectFromString(__r__)
|
||||||
#define CCPointFromString(__p__) CGPointFromString(__p__)
|
#define CCPointFromString(__p__) CGPointFromString(__p__)
|
||||||
|
@ -43,15 +43,11 @@ THE SOFTWARE.
|
||||||
#define CCTextAlignmentLeft UITextAlignmentLeft
|
#define CCTextAlignmentLeft UITextAlignmentLeft
|
||||||
#define CCTextAlignmentRight UITextAlignmentRight
|
#define CCTextAlignmentRight UITextAlignmentRight
|
||||||
|
|
||||||
#define MacGLView void
|
|
||||||
#define NSWindow void
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(CCX_PLATFORM_MAC)
|
#elif defined(CCX_PLATFORM_MAC)
|
||||||
|
|
||||||
#include <Availability.h>
|
#include <Availability.h>
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include "platform/MacGLView.h"
|
|
||||||
|
|
||||||
#define CCRectFromString(__r__) NSRectToCGRect( NSRectFromString(__r__) )
|
#define CCRectFromString(__r__) NSRectToCGRect( NSRectFromString(__r__) )
|
||||||
#define CCPointFromString(__p__) NSPointToCGPoint( NSPointFromString(__p__) )
|
#define CCPointFromString(__p__) NSPointToCGPoint( NSPointFromString(__p__) )
|
||||||
|
@ -80,9 +76,6 @@ THE SOFTWARE.
|
||||||
#define CCTextAlignmentLeft 0
|
#define CCTextAlignmentLeft 0
|
||||||
#define CCTextAlignmentRight 0
|
#define CCTextAlignmentRight 0
|
||||||
|
|
||||||
#define MacGLView void
|
|
||||||
#define NSWindow void
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // __PLATFOMR_CCNS_H__
|
#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
|
-(void) doCaller: (id) sender
|
||||||
{
|
{
|
||||||
cocos2d::CCDirector::sharedDirector()->preMainLoop();
|
cocos2d::CCDirector::sharedDirector()->mainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -81,6 +81,7 @@ public: inline varType get##funName(void){ return varName; }\
|
||||||
public: inline void set##funName(varType var){ varName = var; }
|
public: inline void set##funName(varType var){ varName = var; }
|
||||||
|
|
||||||
#define CCX_SAFE_DELETE(p) if(p) { delete p; p=NULL; }
|
#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_FREE(p) if(p) { free(p); p=NULL; }
|
||||||
#define CCX_SAFE_RELEASE(p) if(p) { p->release(); }
|
#define CCX_SAFE_RELEASE(p) if(p) { p->release(); }
|
||||||
#define CCX_SAFE_RELEASE_NULL(p) if(p) { p->release(); p = NULL; }
|
#define CCX_SAFE_RELEASE_NULL(p) if(p) { p->release(); p = NULL; }
|
||||||
|
|
|
@ -42,6 +42,8 @@ public:
|
||||||
|
|
||||||
CGSize getSize();
|
CGSize getSize();
|
||||||
bool isOpenGLReady();
|
bool isOpenGLReady();
|
||||||
|
bool canSetContentScaleFactor();
|
||||||
|
void setContentScaleFactor(float contentScaleFactor);
|
||||||
|
|
||||||
// keep compatible
|
// keep compatible
|
||||||
void release();
|
void release();
|
||||||
|
|
|
@ -50,6 +50,16 @@ bool CCXEGLView::isOpenGLReady()
|
||||||
{
|
{
|
||||||
return [EAGLView sharedEGLView] != NULL;
|
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()
|
void CCXEGLView::release()
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,21 @@ public:
|
||||||
@param pszResourcePath The absolute resource path
|
@param pszResourcePath The absolute resource path
|
||||||
*/
|
*/
|
||||||
static void setResourcePath(const char *pszResourcePath);
|
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);
|
static const char* getResourcePath(void);
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,226 +34,333 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#define MAX_PATH 260
|
#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 '/')
|
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
|
||||||
if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/'))
|
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]];
|
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
NSString *file = [imagePathComponents lastObject];
|
|
||||||
|
|
||||||
[imagePathComponents removeLastObject];
|
return path;
|
||||||
NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents];
|
}
|
||||||
|
|
||||||
|
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)
|
if (fullpath == nil)
|
||||||
fullpath = relPath;
|
fullpath = relPath;
|
||||||
|
|
||||||
|
fullpath = getDoubleResolutionImage(fullpath);
|
||||||
|
|
||||||
return [fullpath UTF8String];
|
return [fullpath UTF8String];
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace cocos2d {
|
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);
|
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||||
void plist_endElement(void *ctx, const xmlChar *name);
|
{
|
||||||
void plist_characters(void *ctx, const xmlChar *ch, int len);
|
assert( out );
|
||||||
|
assert( &*out );
|
||||||
typedef enum
|
|
||||||
{
|
int size = 0;
|
||||||
SAX_NONE = 0,
|
FILE *f = fopen(filename, "rb");
|
||||||
SAX_KEY,
|
if( !f ) {
|
||||||
SAX_DICT,
|
*out = NULL;
|
||||||
SAX_INT,
|
return -1;
|
||||||
SAX_REAL,
|
}
|
||||||
SAX_STRING
|
|
||||||
}CCSAXState;
|
fseek(f, 0, SEEK_END);
|
||||||
|
size = ftell(f);
|
||||||
class CCDictMaker
|
fseek(f, 0, SEEK_SET);
|
||||||
{
|
|
||||||
public:
|
*out = (unsigned char*)malloc(size);
|
||||||
NSDictionary<std::string, NSObject*> *m_pRootDict;
|
int read = fread(*out, 1, size, f);
|
||||||
NSDictionary<std::string, NSObject*> *m_pCurDict;
|
if( read != size ) {
|
||||||
std::stack<NSDictionary<std::string, NSObject*>*> m_tDictStack;
|
free(*out);
|
||||||
std::string m_sCurKey;///< parsed key
|
*out = NULL;
|
||||||
CCSAXState m_tState;
|
return -1;
|
||||||
public:
|
}
|
||||||
CCDictMaker()
|
|
||||||
{
|
fclose(f);
|
||||||
m_pRootDict = NULL;
|
|
||||||
m_pCurDict = NULL;
|
return size;
|
||||||
m_tState = SAX_NONE;
|
}
|
||||||
}
|
|
||||||
~CCDictMaker()
|
const char* CCFileUtils::ccRemoveHDSuffixFromFile( const char *path )
|
||||||
{
|
{
|
||||||
}
|
return static_ccRemoveHDSuffixFromFile(path);
|
||||||
NSDictionary<std::string, NSObject*> *dictionaryWithContentsOfFile(const char *pFileName)
|
}
|
||||||
{
|
|
||||||
FILE *fp = NULL;
|
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||||
if( !(fp = fopen(pFileName, "r")) )
|
{
|
||||||
{
|
return static_fullPathFromRelativePath(pszRelativePath);
|
||||||
return NULL;
|
}
|
||||||
}
|
|
||||||
fseek(fp,0,SEEK_END);
|
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||||
int size = ftell(fp);
|
{
|
||||||
fseek(fp,0,SEEK_SET);
|
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||||
char *buffer = new char[size+1];
|
NSString *pRet = new NSString();
|
||||||
fread(buffer,sizeof(char),size,fp);
|
pRet->autorelease();
|
||||||
fclose(fp);
|
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
|
||||||
/*
|
pRet->m_sString += pszFilename;
|
||||||
* this initialize the library and check potential ABI mismatches
|
return pRet->m_sString.c_str();
|
||||||
* between the version it was compiled for and the actual shared
|
}
|
||||||
* library used.
|
NSDictionary<std::string, NSObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
*/
|
{
|
||||||
LIBXML_TEST_VERSION
|
CCDictMaker tMaker;
|
||||||
xmlSAXHandler saxHandler;
|
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
- kImageFormatJPG -> jpeg
|
- kImageFormatJPG -> jpeg
|
||||||
@return true if load correctly
|
@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.
|
Load image from stream buffer.
|
||||||
@param pBuffer stream buffer that hold the image data
|
@param pBuffer stream buffer that hold the image data
|
||||||
|
|
|
@ -319,8 +319,8 @@ bool UIImage::initWithContentsOfFile(const string &strPath, tImageFormat imageTy
|
||||||
|
|
||||||
switch (imageType)
|
switch (imageType)
|
||||||
{
|
{
|
||||||
case kImageFormatPNG:
|
case kCCImageFormatPNG:
|
||||||
case kImageFormatJPG:
|
case kCCImageFormatJPG:
|
||||||
bRet = static_initWithFile(strPath.c_str(), &m_imageInfo);
|
bRet = static_initWithFile(strPath.c_str(), &m_imageInfo);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -77,7 +77,7 @@ static EAGLView *view;
|
||||||
static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
|
|
||||||
@interface EAGLView (Private)
|
@interface EAGLView (Private)
|
||||||
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
|
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
|
||||||
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat;
|
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -105,14 +105,14 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format] autorelease];
|
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth
|
+ (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];
|
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
|
+ (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];
|
return [[[[self alloc] init] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained sharegroup:sharegroup multiSampling:multisampling numberOfSamples:samples] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) sharedEGLView
|
+ (id) sharedEGLView
|
||||||
|
@ -129,22 +129,22 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
|
|
||||||
- (id) initWithFrame:(CGRect)frame
|
- (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
|
- (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]))
|
if((self = [super initWithFrame:frame]))
|
||||||
{
|
{
|
||||||
pixelformat_ = format;
|
pixelformat_ = format;
|
||||||
depthFormat_ = depth;
|
depthFormat_ = depth;
|
||||||
multiSampling_ = sampling;
|
multiSampling_ = sampling;
|
||||||
requestedSamples_ = nSamples;
|
requestedSamples_ = nSamples;
|
||||||
preserveBackbuffer_ = retained;
|
preserveBackbuffer_ = retained;
|
||||||
|
|
||||||
if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
|
if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
|
||||||
|
@ -159,20 +159,20 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
|
|
||||||
-(id) initWithCoder:(NSCoder *)aDecoder
|
-(id) initWithCoder:(NSCoder *)aDecoder
|
||||||
{
|
{
|
||||||
if( (self = [super initWithCoder:aDecoder]) ) {
|
if( (self = [super initWithCoder:aDecoder]) ) {
|
||||||
|
|
||||||
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer];
|
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[self layer];
|
||||||
|
|
||||||
pixelformat_ = kEAGLColorFormatRGB565;
|
pixelformat_ = kEAGLColorFormatRGB565;
|
||||||
depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES;
|
depthFormat_ = 0; // GL_DEPTH_COMPONENT24_OES;
|
||||||
multiSampling_= NO;
|
multiSampling_= NO;
|
||||||
requestedSamples_ = 0;
|
requestedSamples_ = 0;
|
||||||
size_ = [eaglLayer bounds].size;
|
size_ = [eaglLayer bounds].size;
|
||||||
|
|
||||||
if( ! [self setupSurfaceWithSharegroup:nil] ) {
|
if( ! [self setupSurfaceWithSharegroup:nil] ) {
|
||||||
[self release];
|
[self release];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view = self;
|
view = self;
|
||||||
|
@ -220,30 +220,30 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
indexBitsUsed &= temp;
|
indexBitsUsed &= temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
|
-(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
|
||||||
{
|
{
|
||||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||||
|
|
||||||
eaglLayer.opaque = YES;
|
eaglLayer.opaque = YES;
|
||||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
[NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking,
|
[NSNumber numberWithBool:preserveBackbuffer_], kEAGLDrawablePropertyRetainedBacking,
|
||||||
pixelformat_, kEAGLDrawablePropertyColorFormat, nil];
|
pixelformat_, kEAGLDrawablePropertyColorFormat, nil];
|
||||||
|
|
||||||
|
|
||||||
renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_
|
renderer_ = [[ES1Renderer alloc] initWithDepthFormat:depthFormat_
|
||||||
withPixelFormat:[self convertPixelFormat:pixelformat_]
|
withPixelFormat:[self convertPixelFormat:pixelformat_]
|
||||||
withSharegroup:sharegroup
|
withSharegroup:sharegroup
|
||||||
withMultiSampling:multiSampling_
|
withMultiSampling:multiSampling_
|
||||||
withNumberOfSamples:requestedSamples_];
|
withNumberOfSamples:requestedSamples_];
|
||||||
if (!renderer_)
|
if (!renderer_)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
context_ = [renderer_ context];
|
context_ = [renderer_ context];
|
||||||
[context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
|
[context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer];
|
||||||
|
|
||||||
//discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer];
|
//discardFramebufferSupported_ = [[CCConfiguration sharedConfiguration] supportsDiscardFramebuffer];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
|
@ -255,93 +255,93 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
|
|
||||||
- (void) layoutSubviews
|
- (void) layoutSubviews
|
||||||
{
|
{
|
||||||
[renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer];
|
[renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer];
|
||||||
size_ = [renderer_ backingSize];
|
size_ = [renderer_ backingSize];
|
||||||
|
|
||||||
// Issue #914 #924
|
// Issue #914 #924
|
||||||
// CCDirector *director = [CCDirector sharedDirector];
|
// CCDirector *director = [CCDirector sharedDirector];
|
||||||
// [director reshapeProjection:size_];
|
// [director reshapeProjection:size_];
|
||||||
cocos2d::CGSize size;
|
cocos2d::CGSize size;
|
||||||
size.width = size_.width;
|
size.width = size_.width;
|
||||||
size.height = size_.height;
|
size.height = size_.height;
|
||||||
cocos2d::CCDirector::sharedDirector()->reshapeProjection(size);
|
cocos2d::CCDirector::sharedDirector()->reshapeProjection(size);
|
||||||
|
|
||||||
// Avoid flicker. Issue #350
|
// Avoid flicker. Issue #350
|
||||||
//[director performSelectorOnMainThread:@selector(drawScene) withObject:nil waitUntilDone:YES];
|
//[director performSelectorOnMainThread:@selector(drawScene) withObject:nil waitUntilDone:YES];
|
||||||
cocos2d::CCDirector::sharedDirector()->drawScene();
|
cocos2d::CCDirector::sharedDirector()->drawScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) swapBuffers
|
- (void) swapBuffers
|
||||||
{
|
{
|
||||||
// IMPORTANT:
|
// IMPORTANT:
|
||||||
// - preconditions
|
// - preconditions
|
||||||
// -> context_ MUST be the OpenGL context
|
// -> context_ MUST be the OpenGL context
|
||||||
// -> renderbuffer_ must be the the RENDER BUFFER
|
// -> renderbuffer_ must be the the RENDER BUFFER
|
||||||
|
|
||||||
#ifdef __IPHONE_4_0
|
#ifdef __IPHONE_4_0
|
||||||
|
|
||||||
if (multiSampling_)
|
if (multiSampling_)
|
||||||
{
|
{
|
||||||
/* Resolve from msaaFramebuffer to resolveFramebuffer */
|
/* Resolve from msaaFramebuffer to resolveFramebuffer */
|
||||||
//glDisable(GL_SCISSOR_TEST);
|
//glDisable(GL_SCISSOR_TEST);
|
||||||
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]);
|
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, [renderer_ msaaFrameBuffer]);
|
||||||
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]);
|
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, [renderer_ defaultFrameBuffer]);
|
||||||
glResolveMultisampleFramebufferAPPLE();
|
glResolveMultisampleFramebufferAPPLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( discardFramebufferSupported_)
|
if( discardFramebufferSupported_)
|
||||||
{
|
{
|
||||||
if (multiSampling_)
|
if (multiSampling_)
|
||||||
{
|
{
|
||||||
if (depthFormat_)
|
if (depthFormat_)
|
||||||
{
|
{
|
||||||
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES};
|
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES};
|
||||||
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments);
|
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES};
|
GLenum attachments[] = {GL_COLOR_ATTACHMENT0_OES};
|
||||||
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
|
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]);
|
glBindRenderbufferOES(GL_RENDERBUFFER_OES, [renderer_ colorRenderBuffer]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// not MSAA
|
// not MSAA
|
||||||
else if (depthFormat_ ) {
|
else if (depthFormat_ ) {
|
||||||
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES};
|
GLenum attachments[] = { GL_DEPTH_ATTACHMENT_OES};
|
||||||
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments);
|
glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 1, attachments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __IPHONE_4_0
|
#endif // __IPHONE_4_0
|
||||||
|
|
||||||
// if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
|
// if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
|
||||||
// CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);
|
// CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);
|
||||||
|
|
||||||
#if COCOS2D_DEBUG
|
#if COCOS2D_DEBUG
|
||||||
CHECK_GL_ERROR();
|
CHECK_GL_ERROR();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We can safely re-bind the framebuffer here, since this will be the
|
// We can safely re-bind the framebuffer here, since this will be the
|
||||||
// 1st instruction of the new main loop
|
// 1st instruction of the new main loop
|
||||||
if( multiSampling_ )
|
if( multiSampling_ )
|
||||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, [renderer_ msaaFrameBuffer]);
|
glBindFramebufferOES(GL_FRAMEBUFFER_OES, [renderer_ msaaFrameBuffer]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat
|
- (unsigned int) convertPixelFormat:(NSString*) pixelFormat
|
||||||
{
|
{
|
||||||
// define the pixel format
|
// define the pixel format
|
||||||
GLenum pFormat;
|
GLenum pFormat;
|
||||||
|
|
||||||
|
|
||||||
if([pixelFormat isEqualToString:@"EAGLColorFormat565"])
|
if([pixelFormat isEqualToString:@"EAGLColorFormat565"])
|
||||||
pFormat = GL_RGB565_OES;
|
pFormat = GL_RGB565_OES;
|
||||||
else
|
else
|
||||||
pFormat = GL_RGBA8_OES;
|
pFormat = GL_RGBA8_OES;
|
||||||
|
|
||||||
return pFormat;
|
return pFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark EAGLView - Point conversion
|
#pragma mark EAGLView - Point conversion
|
||||||
|
|
Loading…
Reference in New Issue