Skip to content

Commit

Permalink
issue cocos2d#1089 HelloWorld can run with modified code
Browse files Browse the repository at this point in the history
  • Loading branch information
honghui committed Mar 26, 2012
1 parent b769dca commit d30b80b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 57 deletions.
1 change: 0 additions & 1 deletion cocos2dx/label_nodes/CCLabelBMFont.cpp
Expand Up @@ -1215,7 +1215,6 @@ namespace cocos2d{

if (shift != 0)
{
int j = 0;
for (unsigned j = 0; j < line_length; j++)
{
index = i + j + lineNumber;
Expand Down
24 changes: 13 additions & 11 deletions cocos2dx/platform/ios/CCFileUtils_ios.mm
Expand Up @@ -23,6 +23,7 @@ of this software and associated documentation files (the "Software"), to deal
THE SOFTWARE.
****************************************************************************/
#import <Foundation/Foundation.h>
#import <UIKit/UIDevice.h>

#include <string>
#include <stack>
Expand All @@ -34,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
#include "CCDirector.h"
#include "CCSAXParser.h"
#include "support/zip_support/unzip.h"
#include "ccTypes.h"

#define MAX_PATH 260

Expand All @@ -45,6 +47,7 @@ of this software and associated documentation files (the "Software"), to deal
static NSString *__suffixiPhoneRetinaDisplay =@"-hd";
static NSString *__suffixiPad =@"-ipad";
static NSString *__suffixiPadRetinaDisplay =@"-ipadhd";
static NSFileManager *__localFileManager= [[NSFileManager alloc] init];

// NSString *ccRemoveSuffixFromPath( NSString *suffix, NSString *path);

Expand Down Expand Up @@ -246,10 +249,8 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,

std::string& CCFileUtils::removeSuffixFromFile(std::string& cpath )
{
path = static_ccRemoveHDSuffixFromFile(path.c_str());
return path;

NSString *ret = nil;
NSString *path = [NSString stringWithUTF8String:cpath.c_str()];

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
Expand All @@ -266,15 +267,16 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,
{
if( CC_CONTENT_SCALE_FACTOR() == 2 )
{
ret = removeSuffixFromPath(__suffixiPhoneRetinaDisplay, path);
ret = removeSuffixFromPath(__suffixiPhoneRetinaDisplay, [NSString stringWithUTF8String:cpath.c_str()]);
}
else
{
ret = path;
}
}

return [ret UTF8String];
cpath = [ret UTF8String];
return cpath;
}

void CCFileUtils::setiPhoneRetinaDisplaySuffix(const char *suffix)
Expand All @@ -295,11 +297,11 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,
__suffixiPadRetinaDisplay = [[NSString stringWithUTF8String:suffix] retain];
}

bool CCFileUtils::fileExistsAtPath(const char *cpath, const char *csuffix)
bool fileExistsAtPath(const char *cpath, const char *csuffix)
{
NSString *fullpath = nil;
NSString *relPath = [NSString stringWithUTF8String:cpath];
NSString *suffix = [NSString stringWithUTF8String:csuffix]
NSString *suffix = [NSString stringWithUTF8String:csuffix];

// only if it is not an absolute path
if( ! [relPath isAbsolutePath] ) {
Expand Down Expand Up @@ -376,12 +378,12 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,
// Retina Display ?
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
ret = getPathForSuffix(fullpath, __suffixiPadRetinaDisplay);
*resolutionType = kCCResolutioniPadRetinaDisplay;
*pResolutionType = kCCResolutioniPadRetinaDisplay;
}
else
{
ret = getPathForSuffix(fullpath, __suffixiPad);
*resolutionType = kCCResolutioniPad;
*pResolutionType = kCCResolutioniPad;
}
}
// iPhone ?
Expand All @@ -390,14 +392,14 @@ static void static_addValueToCCDict(id key, id value, CCDictionary<std::string,
// Retina Display ?
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
ret = getPathForSuffix(fullpath, __suffixiPhoneRetinaDisplay);
*resolutionType = kCCResolutioniPhoneRetinaDisplay;
*pResolutionType = kCCResolutioniPhoneRetinaDisplay;
}
}

// If it is iPhone Non RetinaDisplay, or if the previous "getPath" failed, then use iPhone images.
if( ret == nil )
{
*resolutionType = kCCResolutioniPhone;
*pResolutionType = kCCResolutioniPhone;
ret = fullpath;
}

Expand Down
14 changes: 7 additions & 7 deletions cocos2dx/platform/ios/ES1Renderer.m
Expand Up @@ -32,8 +32,8 @@
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED

#import "ES1Renderer.h"
#import "../../Support/OpenGL_Internal.h"
#import "../../ccMacros.h"
#import "OpenGL_Internal.h"
//#import "ccMacros.h"


@interface ES1Renderer (private)
Expand Down Expand Up @@ -116,13 +116,13 @@ - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer

if (![context_ renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer])
{
CCLOG(@"failed to call context");
NSLog(@"failed to call context");
}

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth_);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight_);

CCLOG(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_);
NSLog(@"cocos2d: surface size: %dx%d", (int)backingWidth_, (int)backingHeight_);

if (multiSampling_)
{
Expand All @@ -144,7 +144,7 @@ - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer

if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
}
Expand All @@ -169,7 +169,7 @@ - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer

if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
CCLOG(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}

Expand All @@ -191,7 +191,7 @@ - (NSString*) description

- (void)dealloc
{
CCLOGINFO(@"cocos2d: deallocing %@", self);
NSLog(@"cocos2d: deallocing %@", self);

// Tear down GL
if(defaultFramebuffer_)
Expand Down
10 changes: 10 additions & 0 deletions cocos2dx/textures/CCTexture2D.cpp
Expand Up @@ -134,6 +134,16 @@ GLfloat CCTexture2D::getMaxT()
{
return m_fMaxT;
}

ccResolutionType CCTexture2D::getResolutionType()
{
return m_eResolutionType;
}

void CCTexture2D::setResolutionType(ccResolutionType resolution)
{
m_eResolutionType = resolution;
}

void CCTexture2D::setMaxT(GLfloat maxT)
{
Expand Down
79 changes: 41 additions & 38 deletions cocos2dx/textures/CCTextureCache.cpp
Expand Up @@ -322,8 +322,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)

// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
std::string pathKey = path;
ccResolutionType resolution;
CCFileUtils::removeSuffixFromFile(pathKey, &resolution);
CCFileUtils::removeSuffixFromFile(pathKey);

pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
texture = m_pTextures->objectForKey(pathKey);
Expand Down Expand Up @@ -352,6 +351,8 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
unsigned char* pBuffer = data.getBuffer();
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg));

ccResolutionType resolution;
fullpath = CCFileUtils::fullPathFromRelativePath(fullpath.c_str(), &resolution);
texture = new CCTexture2D();
texture->initWithImage(&image, resolution);

Expand Down Expand Up @@ -380,6 +381,8 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
unsigned char* pBuffer = data.getBuffer();
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng));

ccResolutionType resolution;
fullpath = CCFileUtils::fullPathFromRelativePath(fullpath.c_str(), &resolution);
texture = new CCTexture2D();
texture->initWithImage(&image, resolution);

Expand Down Expand Up @@ -416,7 +419,7 @@ CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAl
CCTexture2D * texture;

std::string temp(path);
CCFileUtils::ccRemoveHDSuffixFromFile(temp);
CCFileUtils::removeSuffixFromFile(temp);

if ( (texture = m_pTextures->objectForKey(temp)) )
{
Expand Down Expand Up @@ -464,9 +467,9 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
tex = new CCTexture2D();
if( tex->initWithPVRFile(fullpath.c_str()) )
{
#if CC_ENABLE_CACHE_TEXTTURE_DATA
// cache the texture file name
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
#if CC_ENABLE_CACHE_TEXTTURE_DATA
// cache the texture file name
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
#endif
m_pTextures->setObject(tex, key);
tex->autorelease();
Expand Down Expand Up @@ -737,38 +740,38 @@ void VolatileTexture::reloadAllTextures()

switch (vt->m_eCashedImageType)
{
case kImageFile:
{
CCImage image;
std::string lowerCase(vt->m_strFileName.c_str());
for (unsigned int i = 0; i < lowerCase.length(); ++i)
{
lowerCase[i] = tolower(lowerCase[i]);
}

if (std::string::npos != lowerCase.find(".pvr"))
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);

vt->texture->initWithPVRFile(vt->m_strFileName.c_str());
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
}
else
{
CCFileData data(vt->m_strFileName.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();

if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
vt->texture->initWithImage(&image);
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
}
}
}
case kImageFile:
{
CCImage image;
std::string lowerCase(vt->m_strFileName.c_str());
for (unsigned int i = 0; i < lowerCase.length(); ++i)
{
lowerCase[i] = tolower(lowerCase[i]);
}

if (std::string::npos != lowerCase.find(".pvr"))
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);

vt->texture->initWithPVRFile(vt->m_strFileName.c_str());
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
}
else
{
CCFileData data(vt->m_strFileName.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();

if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
vt->texture->initWithImage(&image);
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
}
}
}
break;
case kImageData:
{
Expand Down

0 comments on commit d30b80b

Please sign in to comment.