mirror of https://github.com/axmolengine/axmol.git
fixed some errors of iphone platform
This commit is contained in:
parent
e312bb4d18
commit
9a959c299f
|
@ -1 +1 @@
|
|||
78c89f5d993e6ed6fd3016a960cd1796bbcc1d39
|
||||
821f97de148b8a4f5c67bbdb7751d22f3f9217c4
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
#include "NSMutableArray.h"
|
||||
#include "CGGeometry.h"
|
||||
#include "CCXCocos2dDefine.h"
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
namespace cocos2d {
|
||||
class CCSpriteFrame;
|
||||
|
|
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
|||
#ifndef __CCDIRECTOR_H__
|
||||
#define __CCDIRECTOR_H__
|
||||
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "ccConfig.h"
|
||||
#include "ccTypes.h"
|
||||
#include "CCXCocos2dDefine.h"
|
||||
|
@ -35,9 +36,8 @@ THE SOFTWARE.
|
|||
#include "CCXEGLView.h"
|
||||
#include "ccxCommon.h"
|
||||
#include "CCGL.h"
|
||||
#include "platform/CCNS.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
enum {
|
||||
|
|
|
@ -30,12 +30,12 @@ THE SOFTWARE.
|
|||
|
||||
namespace cocos2d {
|
||||
|
||||
enum eImageFormat
|
||||
typedef enum eImageFormat
|
||||
{
|
||||
kCCImageFormatJPG = 0,
|
||||
kCCImageFormatPNG = 1,
|
||||
kCCImageFormatRawData = 2
|
||||
};
|
||||
} tImageFormat;
|
||||
/**
|
||||
@brief CCRenderTexture is a generic rendering target. To render things into it,
|
||||
simply construct a render target, call begin on it, call visit on any cocos
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// build each architecture with the optimal particle system
|
||||
|
||||
// ARMv7, Mac or Simulator use "Quad" particle
|
||||
#if defined(__ARM_NEON__) || defined(CCX_PLATFORM_MAC) || defined(TARGET_IPHONE_SIMULATOR) || defined(CCX_PLATFORM_WIN32) || defined(_TRANZDA_VM_)
|
||||
#if defined(__ARM_NEON__) || defined(CCX_PLATFORM_MAC) || defined(CCX_PLATFORM_IPHONE) || defined(CCX_PLATFORM_WIN32) || defined(_TRANZDA_VM_)
|
||||
|
||||
#include "CCParticleSystemQuad.h"
|
||||
#define ARCH_OPTIMAL_PARTICLE_SYSTEM CCParticleSystemQuad
|
||||
|
|
|
@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/CCNS.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCScene.h"
|
||||
#include "NSMutableArray.h"
|
||||
|
@ -825,7 +826,11 @@ bool CCDirector::enableRetinaDisplay(bool enabled)
|
|||
|
||||
///@todo SD device iphone specific
|
||||
// if ([[UIScreen mainScreen] scale] == 1.0)
|
||||
// return NO;
float newScale = enabled ? 2 : 1;
setContentScaleFactor(newScale);
|
||||
// return NO;
|
||||
|
||||
float newScale = enabled ? 2 : 1;
|
||||
setContentScaleFactor(newScale);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
|||
#ifdef CCX_PLATFORM_IPHONE
|
||||
|
||||
#include <Availability.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
//#include <Foundation/Foundation.h>
|
||||
|
||||
#define CCRectFromString(__r__) CGRectFromString(__r__)
|
||||
#define CCPointFromString(__p__) CGPointFromString(__p__)
|
||||
|
@ -43,15 +43,11 @@ THE SOFTWARE.
|
|||
#define CCTextAlignmentLeft UITextAlignmentLeft
|
||||
#define CCTextAlignmentRight UITextAlignmentRight
|
||||
|
||||
#define MacGLView void
|
||||
#define NSWindow void
|
||||
|
||||
|
||||
#elif defined(CCX_PLATFORM_MAC)
|
||||
|
||||
#include <Availability.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include "platform/MacGLView.h"
|
||||
|
||||
#define CCRectFromString(__r__) NSRectToCGRect( NSRectFromString(__r__) )
|
||||
#define CCPointFromString(__p__) NSPointToCGPoint( NSPointFromString(__p__) )
|
||||
|
@ -80,9 +76,6 @@ THE SOFTWARE.
|
|||
#define CCTextAlignmentLeft 0
|
||||
#define CCTextAlignmentRight 0
|
||||
|
||||
#define MacGLView void
|
||||
#define NSWindow void
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __PLATFOMR_CCNS_H__
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#ifndef __CC_PLATFORM_MACROS_H__
|
||||
#define __CC_PLATFORM_MACROS_H__
|
||||
|
||||
/**
|
||||
* define some platform specific macros
|
||||
*/
|
||||
#include "config_platform.h"
|
||||
|
||||
#ifdef CCX_PLATFORM_MOBILE
|
||||
#define MacGLView void
|
||||
#define NSWindow void
|
||||
#elif defined(CCX_PLATFORM_PC)
|
||||
#include "platform/MacGLView.h"
|
||||
#endif
|
||||
|
||||
#endif // __CC_PLATFORM_MACROS_H__
|
|
@ -67,7 +67,7 @@ static id s_sharedDirectorCaller;
|
|||
|
||||
-(void) doCaller: (id) sender
|
||||
{
|
||||
cocos2d::CCDirector::sharedDirector()->preMainLoop();
|
||||
cocos2d::CCDirector::sharedDirector()->mainLoop();
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -81,6 +81,7 @@ public: inline varType get##funName(void){ return varName; }\
|
|||
public: inline void set##funName(varType var){ varName = var; }
|
||||
|
||||
#define CCX_SAFE_DELETE(p) if(p) { delete p; p=NULL; }
|
||||
#define CCX_SAFE_DELETE_ARRAY(p) if(p) { delete[] p; p=NULL;}
|
||||
#define CCX_SAFE_FREE(p) if(p) { free(p); p=NULL; }
|
||||
#define CCX_SAFE_RELEASE(p) if(p) { p->release(); }
|
||||
#define CCX_SAFE_RELEASE_NULL(p) if(p) { p->release(); p = NULL; }
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
|
||||
CGSize getSize();
|
||||
bool isOpenGLReady();
|
||||
bool canSetContentScaleFactor();
|
||||
void setContentScaleFactor(float contentScaleFactor);
|
||||
|
||||
// keep compatible
|
||||
void release();
|
||||
|
|
|
@ -51,6 +51,16 @@ bool CCXEGLView::isOpenGLReady()
|
|||
return [EAGLView sharedEGLView] != NULL;
|
||||
}
|
||||
|
||||
bool CCXEGLView::canSetContentScaleFactor()
|
||||
{
|
||||
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
|
||||
}
|
||||
|
||||
void CCXEGLView::setContentScaleFactor(float contentScaleFactor)
|
||||
{
|
||||
[[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor];
|
||||
}
|
||||
|
||||
void CCXEGLView::release()
|
||||
{
|
||||
[CCDirectorCaller destroy];
|
||||
|
|
|
@ -63,6 +63,21 @@ public:
|
|||
*/
|
||||
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);
|
||||
};
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -34,32 +34,105 @@ THE SOFTWARE.
|
|||
|
||||
#define MAX_PATH 260
|
||||
|
||||
static const char* static_fullPathFromRelativePath(const char *pszRelativePath)
|
||||
static const char *static_ccRemoveHDSuffixFromFile( const char *pszPath )
|
||||
{
|
||||
// do not convert an absolute path (starting with '/')
|
||||
NSString *relPath = [NSString stringWithUTF8String: pszRelativePath];
|
||||
if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/'))
|
||||
{
|
||||
return pszRelativePath;
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
|
||||
NSString *path = [NSString stringWithUTF8String: pszPath]
|
||||
NSString *name = [path lastPathComponent];
|
||||
|
||||
// check if path already has the suffix.
|
||||
if( [name rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) {
|
||||
|
||||
CCLOG(@"cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040", path, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
|
||||
|
||||
NSString *newLastname = [name stringByReplacingOccurrencesOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX withString:@""];
|
||||
|
||||
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
|
||||
return [[pathWithoutLastname stringByAppendingPathComponent:newLastname] UTF8String];
|
||||
}
|
||||
}
|
||||
|
||||
NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]];
|
||||
NSString *file = [imagePathComponents lastObject];
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
[imagePathComponents removeLastObject];
|
||||
NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents];
|
||||
return pszPath;
|
||||
}
|
||||
|
||||
NSString *fullpath = [[NSBundle mainBundle] pathForResource:file
|
||||
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];
|
||||
}
|
||||
|
||||
if (fullpath == nil)
|
||||
fullpath = relPath;
|
||||
|
||||
fullpath = getDoubleResolutionImage(fullpath);
|
||||
|
||||
return [fullpath UTF8String];
|
||||
}
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
||||
void plist_endElement(void *ctx, const xmlChar *name);
|
||||
void plist_characters(void *ctx, const xmlChar *ch, int len);
|
||||
|
@ -237,10 +310,45 @@ const char* CCFileUtils::getResourcePath()
|
|||
return s_pszResourcePath;
|
||||
}
|
||||
|
||||
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||
{
|
||||
assert( out );
|
||||
assert( &*out );
|
||||
|
||||
int size = 0;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if( !f ) {
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
*out = (unsigned char*)malloc(size);
|
||||
int read = fread(*out, 1, size, f);
|
||||
if( read != size ) {
|
||||
free(*out);
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
const char* CCFileUtils::ccRemoveHDSuffixFromFile( const char *path )
|
||||
{
|
||||
return static_ccRemoveHDSuffixFromFile(path);
|
||||
}
|
||||
|
||||
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||
{
|
||||
return static_fullPathFromRelativePath(pszRelativePath);
|
||||
}
|
||||
|
||||
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
|
||||
{
|
||||
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||
|
@ -255,5 +363,4 @@ NSDictionary<std::string, NSObject*> *CCFileUtils::dictionaryWithContentsOfFile(
|
|||
CCDictMaker tMaker;
|
||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||
}
|
||||
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
- kImageFormatJPG -> jpeg
|
||||
@return true if load correctly
|
||||
*/
|
||||
bool initWithContentsOfFile(const std::string &strPath, tImageFormat imageType = kImageFormatPNG);
|
||||
bool initWithContentsOfFile(const std::string &strPath, tImageFormat imageType = kCCImageFormatPNG);
|
||||
/**
|
||||
Load image from stream buffer.
|
||||
@param pBuffer stream buffer that hold the image data
|
||||
|
|
|
@ -319,8 +319,8 @@ bool UIImage::initWithContentsOfFile(const string &strPath, tImageFormat imageTy
|
|||
|
||||
switch (imageType)
|
||||
{
|
||||
case kImageFormatPNG:
|
||||
case kImageFormatJPG:
|
||||
case kCCImageFormatPNG:
|
||||
case kCCImageFormatJPG:
|
||||
bRet = static_initWithFile(strPath.c_str(), &m_imageInfo);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
- (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]))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue