Merge branch 'yangws-439'

This commit is contained in:
walzer 2011-03-30 11:47:10 +08:00
commit 70eb85e6df
23 changed files with 284 additions and 336 deletions

View File

@ -46,9 +46,9 @@ CCData::~CCData(void)
CCData* CCData::dataWithContentsOfFile(const string &strPath)
{
FileData data;
unsigned long nSize = 0;
unsigned char* pBuffer = data.getFileData(strPath.c_str(), "rb", &nSize);
CCFileData data(strPath.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
if (! pBuffer)
{

View File

@ -125,9 +125,9 @@ namespace cocos2d{
{
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
FileData data;
unsigned long nBufSize = 0;
char* pBuffer = (char*) data.getFileData(fullpath.c_str(), "r", &nBufSize);
CCFileData data(controlFile, "rb");
unsigned long nBufSize = data.getSize();
char* pBuffer = (char*) data.getBuffer();
CCAssert(pBuffer, "CCBMFontConfiguration::parseConfigFile | Open file error.");

View File

@ -262,12 +262,12 @@ bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *
if (strlen(textureName) > 0)
{
// set not pop-up message box when load image failed
bool bNotify = CCImage::getIsPopupNotify();
CCImage::setIsPopupNotify(false);
bool bNotify = CCFileUtils::getIsPopupNotify();
CCFileUtils::setIsPopupNotify(false);
this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str());
// reset the value of UIImage notify
CCImage::setIsPopupNotify(bNotify);
CCFileUtils::setIsPopupNotify(bNotify);
}
// if it fails, try to get it from the base64-gzipped data

View File

@ -48,6 +48,11 @@ void CCLog(const char * pszFormat, ...)
OutputDebugStringA("\n");
}
void CCMessageBox(const char * pszMsg, const char * pszTitle)
{
MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
}
NS_CC_END;
#endif // CC_PLATFORM_WIN32
@ -94,6 +99,16 @@ void CCLog(const char * pszFormat, ...)
#endif
}
void CCMessageBox(const char * pszMsg, const char * pszTitle)
{
TUChar tszMsg[MAX_LEN] = { 0 };
TUChar tszTitle[MAX_LEN] = { 0 };
TUString::StrUtf8ToStrUnicode(tszMsg,(Char*)pszMsg);
TUString::StrUtf8ToStrUnicode(tszTitle,(Char*)pszTitle);
TMessageBox box(tszMsg, tszTitle, WMB_OK);
box.Show();
}
NS_CC_END;
#endif // CC_PLATFORM_WOPHONE
@ -121,6 +136,12 @@ void CCLog(const char * pszFormat, ...)
printf("\n");
}
// ios no MessageBox, use CCLog instead
void CCMessageBox(const char * pszMsg, const char * pszTitle)
{
CCLog("%s: %s", pszTitle, pszMsg);
}
NS_CC_END;
#endif // CC_PLATFORM_IOS
@ -147,6 +168,12 @@ void CCLog(const char * pszFormat, ...)
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf);
}
// android no MessageBox, use CCLog instead
void CCMessageBox(const char * pszMsg, const char * pszTitle)
{
CCLog("%s: %s", pszTitle, pszMsg);
}
NS_CC_END;
#endif // CC_PLATFORM_ANDROID
@ -174,8 +201,13 @@ void CCLog(const char * pszFormat, ...)
IwTrace(GAME, (buf));
}
// airplay no MessageBox, use CCLog instead
void CCMessageBox(const char * pszMsg, const char * pszTitle)
{
CCLog("%s: %s", pszTitle, pszMsg);
}
NS_CC_END;
#endif // CC_PLATFORM_AIRPLAY

View File

@ -36,6 +36,7 @@ static const int kMaxLogLen = 255;
@brief Output Debug message.
*/
void CC_DLL CCLog(const char * pszFormat, ...);
void CC_DLL CCMessageBox(const char * pszMsg, const char * pszTitle);
NS_CC_END;

View File

@ -287,6 +287,21 @@ unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const
return pBuffer;
}
//////////////////////////////////////////////////////////////////////////
// Notification support when getFileData from invalid file path.
//////////////////////////////////////////////////////////////////////////
static bool s_bPopupNotify = true;
void CCFileUtils::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool CCFileUtils::getIsPopupNotify()
{
return s_bPopupNotify;
}
NS_CC_END;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
@ -301,4 +316,4 @@ NS_CC_END;
#include "android/CCFileUtils_android.cpp"
#endif
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)

View File

@ -86,6 +86,12 @@ public:
*/
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
/**
@brief Set/Get whether pop-up a message box when the image load failed
*/
static void setIsPopupNotify(bool bNotify);
static bool getIsPopupNotify();
///////////////////////////////////////////////////
// interfaces on wophone
///////////////////////////////////////////////////
@ -108,33 +114,30 @@ public:
int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
};
class FileData
class CCFileData
{
public:
FileData() : m_pBuffer(NULL) {}
~FileData()
CCFileData(const char* pszFileName, const char* pszMode)
: m_pBuffer(0)
, m_uSize(0)
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
}
~CCFileData()
{
CC_SAFE_DELETE_ARRAY(m_pBuffer);
}
unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
bool reset(const char* pszFileName, const char* pszMode)
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
CC_SAFE_DELETE_ARRAY(m_pBuffer);
m_uSize = 0;
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, &m_uSize);
return (m_pBuffer) ? true : false;
}
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, pSize);
return m_pBuffer;
}
protected:
unsigned char* m_pBuffer;
CC_SYNTHESIZE_READONLY(unsigned char *, m_pBuffer, Buffer);
CC_SYNTHESIZE_READONLY(unsigned long , m_uSize, Size);
};
NS_CC_END;

View File

@ -26,6 +26,7 @@ THE SOFTWARE.
#include "CCCommon.h"
#include "CCStdC.h"
#include "CCFileUtils.h"
#include "png.h"
#include <string>
@ -63,8 +64,6 @@ static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t leng
NS_CC_BEGIN;
static void CCMessageBox(const std::string& msg, const std::string& title);
//////////////////////////////////////////////////////////////////////////
// Impliment CCImage
//////////////////////////////////////////////////////////////////////////
@ -87,51 +86,8 @@ CCImage::~CCImage()
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
{
bool bRet = false;
FILE *fp = 0;
unsigned char *buffer = NULL;
do
{
// open file
fp = fopen(strPath, "rb");
CC_BREAK_IF(! fp);
// compute the length of file
fseek(fp,0,SEEK_END);
int size = ftell(fp);
fseek(fp,0,SEEK_SET);
// allocate enough memory to save the data of file
buffer = new unsigned char[size];
CC_BREAK_IF(! buffer);
// read data
size = fread(buffer, sizeof(unsigned char), size, fp);
if (kFmtJpg == eImgFmt)
{
bRet = _initWithJpgData(buffer, size);
}
else
{
bRet = _initWithPngData(buffer, size);
}
} while (0);
CC_SAFE_DELETE_ARRAY(buffer);
if (fp)
{
fclose(fp);
}
if (! bRet && CCImage::getIsPopupNotify())
{
std::string title = "cocos2d-x error!";
std::string msg = "Load ";
msg.append(strPath).append(" failed!");
CCMessageBox(msg, title);
}
return bRet;
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
return initWithImageData(data.getBuffer(), data.getSize());
}
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
@ -155,18 +111,6 @@ bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/*
return bRet;
}
static bool s_bPopupNotify = true;
void CCImage::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool CCImage::getIsPopupNotify()
{
return s_bPopupNotify;
}
bool CCImage::_initWithJpgData(void * data, int nSize)
{
/* these are standard libjpeg structures for reading(decompression) */

View File

@ -107,13 +107,6 @@ public:
CC_SYNTHESIZE_READONLY(short, m_nHeight, Height);
CC_SYNTHESIZE_READONLY(int, m_nBitsPerComponent, BitsPerComponent);
public:
/**
@brief Set/Get whether pop-up a message box when the image load failed
*/
static void setIsPopupNotify(bool bNotify);
static bool getIsPopupNotify();
protected:
bool _initWithJpgData(void * pData, int nDatalen);
bool _initWithPngData(void * pData, int nDatalen);

View File

@ -49,9 +49,9 @@ bool CCSAXParser::init(const char *pszEncoding)
bool CCSAXParser::parse(const char *pszFile)
{
FileData data;
unsigned long size = 0;
char *pBuffer = (char*) data.getFileData(pszFile, "r", &size);
CCFileData data(pszFile, "rt");
unsigned long size = data.getSize();
char *pBuffer = (char*) data.getBuffer();
if (!pBuffer)
{

View File

@ -281,9 +281,15 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
if (! pFile && getIsPopupNotify())
{
IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError()));
}
if (! pFile)
{
*pSize = 0;
return 0;
}
int32 fileSize = s3eFileGetSize(pFile);
*pSize=fileSize;
@ -319,5 +325,20 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
return path;
}
///////////////////////////////////////////////////////////////////////////////
// Notification support when getFileData from a invalid file
///////////////////////////////////////////////////////////////////////////////
static bool s_bPopupNotify = true;
void CCFileUtils::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool CCFileUtils::getIsPopupNotify()
{
return s_bPopupNotify;
}
NS_CC_END;

View File

@ -24,6 +24,7 @@
#include "CCImage.h"
#include "CCCommon.h"
#include "CCStdC.h"
#include "CCFileUtils.h"
#include "s3eFile.h"
#include "IwImage.h"
#include "IwUtil.h"
@ -61,52 +62,8 @@ CCImage::~CCImage()
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
{
IW_CALLSTACK("UIImage::initWithImageFile");
bool bRet = false;
FILE *fp = 0;
unsigned char *buffer = NULL;
do
{
// open file
fp = fopen(strPath, "rb");
CC_BREAK_IF(! fp);
// compute the length of file
fseek(fp,0,SEEK_END);
int size = ftell(fp);
fseek(fp,0,SEEK_SET);
// allocate enough memory to save the data of file
buffer = new unsigned char[size];
CC_BREAK_IF(! buffer);
// read data
size = fread(buffer, sizeof(unsigned char), size, fp);
if (kFmtJpg == eImgFmt)
{
bRet = _initWithJpgData(buffer, size);
}
else
{
bRet = _initWithPngData(buffer, size);
}
} while (0);
CC_SAFE_DELETE_ARRAY(buffer);
if (fp)
{
fclose(fp);
}
if (! bRet && CCImage::getIsPopupNotify())
{
std::string title = "cocos2d-x error!";
std::string msg = "Load ";
msg.append(strPath).append(" failed!");
IwError(("cocos2d-x error! Load %s failed", strPath));
}
return bRet;
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
}
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
@ -129,16 +86,6 @@ bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/*
} while (0);
return bRet;
}
static bool s_bPopupNotify = true;
void CCImage::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool CCImage::getIsPopupNotify()
{
return s_bPopupNotify;
}
bool CCImage::_initWithJpgData(void * data, int nSize)
{

View File

@ -82,7 +82,15 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
string fullPath = s_strRelativePath + pszFileName;
return CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize);
unsigned char * pData = CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize);
if (! pData && getIsPopupNotify())
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(pszFileName).append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}
return pData;
}
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)

View File

@ -42,12 +42,6 @@ static int sk_atomic_dec(int *value)
NS_CC_BEGIN;
// android not support
void CCMessageBox(const std::string& msg, const std::string& title)
{
}
class BitmapDC
{
public:

View File

@ -389,7 +389,7 @@ public:
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char * Buffer = NULL;
unsigned char * pBuffer = NULL;
do
{
@ -400,12 +400,20 @@ public:
fseek(fp,0,SEEK_END);
*pSize = ftell(fp);
fseek(fp,0,SEEK_SET);
Buffer = new unsigned char[*pSize];
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
pBuffer = new unsigned char[*pSize];
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
fclose(fp);
} while (0);
return Buffer;
if (! pBuffer && getIsPopupNotify())
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(pszFileName).append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}
return pBuffer;
}
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
{
@ -415,4 +423,19 @@ public:
{
CCAssert(0, "Have not implement!");
}
// notification support when getFileData from a invalid file
static bool s_bPopupNotify = true;
void CCFileUtils::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool CCFileUtils::getIsPopupNotify()
{
return s_bPopupNotify;
}
}//namespace cocos2d

View File

@ -24,6 +24,7 @@ THE SOFTWARE.
#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>
#include "CCImage.h"
#include "CCFileUtils.h"
#include <string>
typedef struct
@ -448,13 +449,6 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl
NS_CC_BEGIN;
static bool s_bPopupNotify = true;
void CCMessageBox(const std::string& msg, const std::string& title)
{
}
CCImage::CCImage()
: m_nWidth(0)
, m_nHeight(0)
@ -473,30 +467,8 @@ CCImage::~CCImage()
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
{
bool bRet = false;
tImageInfo info = {0};
switch (eImgFmt)
{
case kFmtPng:
case kFmtJpg:
bRet = _initWithFile(strPath, &info);
break;
default:
// unsupported image type
bRet = false;
break;
}
if (bRet)
{
m_nHeight = (short)info.height;
m_nWidth = (short)info.width;
m_nBitsPerComponent = info.bitsPerComponent;
m_bHasAlpha = info.hasAlpha;
m_bPreMulti = info.isPremultipliedAlpha;
m_pData = info.data;
}
return bRet;
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
}
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
@ -546,15 +518,5 @@ bool CCImage::initWithString(
return true;
}
void CCImage::setIsPopupNotify(bool bNotify)
{
s_bPopupNotify = bNotify;
}
bool CCImage::getIsPopupNotify()
{
return s_bPopupNotify;
}
NS_CC_END;

View File

@ -115,7 +115,7 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char * Buffer = NULL;
unsigned char * pBuffer = NULL;
do
{
@ -126,12 +126,20 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
fseek(fp,0,SEEK_END);
*pSize = ftell(fp);
fseek(fp,0,SEEK_SET);
Buffer = new unsigned char[*pSize];
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
pBuffer = new unsigned char[*pSize];
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
fclose(fp);
} while (0);
return Buffer;
if (! pBuffer && getIsPopupNotify())
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(pszFileName).append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}
return pBuffer;
}
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)

View File

@ -24,11 +24,6 @@ THE SOFTWARE.
NS_CC_BEGIN;
void CCMessageBox(const std::string& msg, const std::string& title)
{
MessageBoxA(NULL, msg.c_str(), title.c_str(), MB_OK);
}
/**
@brief A memory DC which uses to draw text on bitmap.
*/

View File

@ -277,7 +277,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
do
{
if (strlen(s_pszZipFilePath) != 0)
if (0 != s_pszZipFilePath[0])
{
// if specify the zip file,load from it first
pBuffer = getFileDataFromZip(s_pszZipFilePath, pszFileName, pSize);
@ -292,10 +292,24 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
*pSize = ftell(fp);
fseek(fp,0,SEEK_SET);
pBuffer = new unsigned char[*pSize];
fread(pBuffer,sizeof(unsigned char), *pSize,fp);
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
fclose(fp);
} while (0);
if (! pBuffer && getIsPopupNotify())
{
std::string title = "Notification";
std::string msg = "Get data from file(";
msg.append(pszFileName);
if (0 != s_pszZipFilePath[0])
{
msg.append(") in zip archive(").append(s_pszZipFilePath);
}
msg.append(") failed!");
CCMessageBox(msg.c_str(), title.c_str());
}
return pBuffer;
}

View File

@ -29,14 +29,6 @@ NS_CC_BEGIN
typedef std::basic_string<TUChar> stdTUString;
void CCMessageBox(const std::string& msg, const std::string& title)
{
TUChar szText[256] = { 0 };
TUString::StrUtf8ToStrUnicode(szText,(Char*)msg.c_str());
TMessageBox box(szText, NULL, WMB_OK);
box.Show();
}
class BitmapDC
{
public:

View File

@ -1065,11 +1065,15 @@
Name="makefile"
>
<File
RelativePath="..\Lib_Cocos2d_Arm_Wophone.TMK3"
RelativePath=".\cocos2d-wophone.TMK3"
>
</File>
<File
RelativePath="..\Makefile.ARM"
RelativePath=".\Makefile-dynamic.ARM"
>
</File>
<File
RelativePath=".\Makefile.ARM"
>
</File>
</Filter>

View File

@ -194,9 +194,9 @@ tImageTGA * tgaLoad(const char *pszFilename)
{
int mode,total;
tImageTGA *info = NULL;
FileData data;
unsigned long nSize = 0;
unsigned char* pBuffer = data.getFileData(pszFilename, "rb", &nSize);
CCFileData data(pszFilename, "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
do
{

View File

@ -208,18 +208,14 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
else if (std::string::npos != lowerCase.find(".jpg") || std::string::npos != lowerCase.find(".jpeg"))
{
CCImage * image = new CCImage();
FileData data;
unsigned long nSize = 0;
unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize);
if(! image->initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg))
{
delete image;
break;
}
CCImage image;
CCFileData data(fullpath.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtJpg));
texture = new CCTexture2D();
texture->initWithImage(image);
CC_SAFE_DELETE(image);// image->release();
texture->initWithImage(&image);
if( texture )
{
@ -239,18 +235,14 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
tex = [ [CCTexture2D alloc] initWithImage: image ];
#else
// prevents overloading the autorelease pool
CCImage * image = new CCImage();
FileData data;
unsigned long nSize = 0;
unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize);
if(! image->initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng))
{
delete image;
break;
}
CCImage image;
CCFileData data(fullpath.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
CC_BREAK_IF(! image.initWithImageData((void*)pBuffer, nSize, CCImage::kFmtPng));
texture = new CCTexture2D();
texture->initWithImage(image);
CC_SAFE_DELETE(image);// image->release();
texture->initWithImage(&image);
#endif
if( texture )
{