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;
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -30,12 +30,12 @@ THE SOFTWARE.
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -51,6 +51,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()
|
||||||
{
|
{
|
||||||
[CCDirectorCaller destroy];
|
[CCDirectorCaller destroy];
|
||||||
|
|
|
@ -63,6 +63,21 @@ public:
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
};
|
};
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
|
@ -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]
|
||||||
return pszRelativePath;
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]];
|
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
NSString *file = [imagePathComponents lastObject];
|
|
||||||
|
|
||||||
[imagePathComponents removeLastObject];
|
return pszPath;
|
||||||
NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents];
|
}
|
||||||
|
|
||||||
|
static NSString* getDoubleResolutionImage(NSString* path)
|
||||||
|
{
|
||||||
|
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
|
|
||||||
|
if( CC_CONTENT_SCALE_FACTOR() == 2 )
|
||||||
|
{
|
||||||
|
|
||||||
|
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] );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||||
|
|
||||||
|
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)
|
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);
|
||||||
|
|
||||||
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
typedef enum
|
||||||
void plist_endElement(void *ctx, const xmlChar *name);
|
{
|
||||||
void plist_characters(void *ctx, const xmlChar *ch, int len);
|
SAX_NONE = 0,
|
||||||
|
SAX_KEY,
|
||||||
|
SAX_DICT,
|
||||||
|
SAX_INT,
|
||||||
|
SAX_REAL,
|
||||||
|
SAX_STRING
|
||||||
|
}CCSAXState;
|
||||||
|
|
||||||
typedef enum
|
class CCDictMaker
|
||||||
{
|
{
|
||||||
SAX_NONE = 0,
|
public:
|
||||||
SAX_KEY,
|
NSDictionary<std::string, NSObject*> *m_pRootDict;
|
||||||
SAX_DICT,
|
NSDictionary<std::string, NSObject*> *m_pCurDict;
|
||||||
SAX_INT,
|
std::stack<NSDictionary<std::string, NSObject*>*> m_tDictStack;
|
||||||
SAX_REAL,
|
std::string m_sCurKey;///< parsed key
|
||||||
SAX_STRING
|
CCSAXState m_tState;
|
||||||
}CCSAXState;
|
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;
|
||||||
|
|
||||||
class CCDictMaker
|
int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );
|
||||||
{
|
if ( result != 0 )
|
||||||
public:
|
{
|
||||||
NSDictionary<std::string, NSObject*> *m_pRootDict;
|
return NULL;
|
||||||
NSDictionary<std::string, NSObject*> *m_pCurDict;
|
}
|
||||||
std::stack<NSDictionary<std::string, NSObject*>*> m_tDictStack;
|
/*
|
||||||
std::string m_sCurKey;///< parsed key
|
* Cleanup function for the XML library.
|
||||||
CCSAXState m_tState;
|
*/
|
||||||
public:
|
xmlCleanupParser();
|
||||||
CCDictMaker()
|
/*
|
||||||
{
|
* this is to debug memory for regression tests
|
||||||
m_pRootDict = NULL;
|
*/
|
||||||
m_pCurDict = NULL;
|
xmlMemoryDump();
|
||||||
m_tState = SAX_NONE;
|
delete []buffer;
|
||||||
}
|
return m_pRootDict;
|
||||||
~CCDictMaker()
|
}
|
||||||
{
|
};
|
||||||
}
|
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
|
||||||
NSDictionary<std::string, NSObject*> *dictionaryWithContentsOfFile(const char *pFileName)
|
{
|
||||||
{
|
CCDictMaker *pMaker = (CCDictMaker*)(ctx);
|
||||||
FILE *fp = NULL;
|
std::string sName((char*)name);
|
||||||
if( !(fp = fopen(pFileName, "r")) )
|
if( sName == "dict" )
|
||||||
{
|
{
|
||||||
return NULL;
|
NSDictionary<std::string, NSObject*> *pNewDict = new NSDictionary<std::string, NSObject*>();
|
||||||
}
|
if(! pMaker->m_pRootDict)
|
||||||
fseek(fp,0,SEEK_END);
|
{
|
||||||
int size = ftell(fp);
|
pMaker->m_pRootDict = pNewDict;
|
||||||
fseek(fp,0,SEEK_SET);
|
pNewDict->autorelease();
|
||||||
char *buffer = new char[size+1];
|
}
|
||||||
fread(buffer,sizeof(char),size,fp);
|
else
|
||||||
fclose(fp);
|
{
|
||||||
/*
|
NSAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
|
||||||
* this initialize the library and check potential ABI mismatches
|
pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
|
||||||
* between the version it was compiled for and the actual shared
|
pNewDict->release();
|
||||||
* library used.
|
pMaker->m_sCurKey.clear();
|
||||||
*/
|
}
|
||||||
LIBXML_TEST_VERSION
|
pMaker->m_pCurDict = pNewDict;
|
||||||
xmlSAXHandler saxHandler;
|
pMaker->m_tDictStack.push(pMaker->m_pCurDict);
|
||||||
memset( &saxHandler, 0, sizeof(saxHandler) );
|
pMaker->m_tState = SAX_DICT;
|
||||||
// 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.
|
else if(sName == "key")
|
||||||
saxHandler.startElement = &plist_startElement;
|
{
|
||||||
saxHandler.endElement = &plist_endElement;
|
pMaker->m_tState = SAX_KEY;
|
||||||
saxHandler.characters = &plist_characters;
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );
|
switch(pMaker->m_tState)
|
||||||
if ( result != 0 )
|
{
|
||||||
{
|
case SAX_KEY:
|
||||||
return NULL;
|
pMaker->m_sCurKey = pText->m_sString;
|
||||||
}
|
break;
|
||||||
/*
|
case SAX_INT:
|
||||||
* Cleanup function for the XML library.
|
case SAX_REAL:
|
||||||
*/
|
case SAX_STRING:
|
||||||
xmlCleanupParser();
|
{
|
||||||
/*
|
NSAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
|
||||||
* this is to debug memory for regression tests
|
pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
|
||||||
*/
|
break;
|
||||||
xmlMemoryDump();
|
}
|
||||||
delete []buffer;
|
}
|
||||||
return m_pRootDict;
|
pText->release();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
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)
|
// record the resource path
|
||||||
{
|
static char s_pszResourcePath[MAX_PATH] = {0};
|
||||||
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
|
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||||
static char s_pszResourcePath[MAX_PATH] = {0};
|
{
|
||||||
|
NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||||
|
NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
|
||||||
|
|
||||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
strcpy(s_pszResourcePath, 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::getResourcePath()
|
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||||
{
|
{
|
||||||
return s_pszResourcePath;
|
assert( out );
|
||||||
}
|
assert( &*out );
|
||||||
|
|
||||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
int size = 0;
|
||||||
{
|
FILE *f = fopen(filename, "rb");
|
||||||
return static_fullPathFromRelativePath(pszRelativePath);
|
if( !f ) {
|
||||||
}
|
*out = NULL;
|
||||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
return -1;
|
||||||
{
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
}//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:
|
||||||
|
|
|
@ -137,7 +137,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
|
||||||
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]))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue