Merge pull request #1901 from dumganhar/iss1683-ccfileutils

issue #1683: Making some API of CCFileUtils more c++ friendly by using std::vector rather than CCArray.
This commit is contained in:
minggo 2013-01-27 18:53:20 -08:00
commit e45cc7d548
47 changed files with 833 additions and 652 deletions

View File

@ -34,6 +34,8 @@ THE SOFTWARE.
#include <vorbis/vorbisfile.h>
#include "SimpleAudioEngine.h"
#include "cocos2d.h"
USING_NS_CC;
using namespace std;
@ -257,9 +259,12 @@ namespace CocosDenshion
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
if (!s_isBackgroundInitialized || s_currentBackgroundStr != pszFilePath)
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
if (!s_isBackgroundInitialized || s_currentBackgroundStr != fullPath)
{
string path = pszFilePath;
string path = fullPath;
if (isOGGFile(path.data()))
{
@ -285,17 +290,20 @@ namespace CocosDenshion
alSourcei(s_backgroundSource, AL_BUFFER, s_backgroundBuffer);
checkALError("preloadBackgroundMusic");
s_currentBackgroundStr = pszFilePath;
s_currentBackgroundStr = fullPath;
}
s_currentBackgroundStr = pszFilePath;
s_currentBackgroundStr = fullPath;
s_isBackgroundInitialized = true;
}
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
if (!s_isBackgroundInitialized)
preloadBackgroundMusic(pszFilePath);
preloadBackgroundMusic(fullPath.c_str());
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
alSourcePlay(s_backgroundSource);
@ -383,17 +391,20 @@ namespace CocosDenshion
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
{
EffectsMap::iterator iter = s_effects.find(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
EffectsMap::iterator iter = s_effects.find(fullPath);
if (iter == s_effects.end())
{
preloadEffect(pszFilePath);
preloadEffect(fullPath.c_str());
// let's try again
iter = s_effects.find(pszFilePath);
iter = s_effects.find(fullPath);
if (iter == s_effects.end())
{
fprintf(stderr, "could not find play sound %s\n", pszFilePath);
fprintf(stderr, "could not find play sound %s\n", fullPath.c_str());
return -1;
}
}
@ -415,7 +426,10 @@ namespace CocosDenshion
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{
EffectsMap::iterator iter = s_effects.find(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
EffectsMap::iterator iter = s_effects.find(fullPath);
// check if we have this already
if (iter == s_effects.end())
@ -423,7 +437,7 @@ namespace CocosDenshion
ALuint buffer;
ALuint source;
soundData *data = new soundData;
string path = pszFilePath;
string path = fullPath;
checkALError("preloadEffect");
@ -459,13 +473,16 @@ namespace CocosDenshion
data->buffer = buffer;
data->source = source;
s_effects.insert(EffectsMap::value_type(pszFilePath, data));
s_effects.insert(EffectsMap::value_type(fullPath, data));
}
}
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
{
EffectsMap::iterator iter = s_effects.find(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
EffectsMap::iterator iter = s_effects.find(fullPath);
if (iter != s_effects.end())
{

View File

@ -1,5 +1,7 @@
#include "SimpleAudioEngine.h"
#include "FmodAudioPlayer.h"
#include "cocos2d.h"
USING_NS_CC;
namespace CocosDenshion {
@ -19,30 +21,17 @@ SimpleAudioEngine* SimpleAudioEngine::sharedEngine() {
void SimpleAudioEngine::end() {
oAudioPlayer->close();
// sharedMusic().Close();
//
// EffectList::iterator p = sharedList().begin();
// while (p != sharedList().end())
// {
// delete p->second;
// p->second = NULL;
// p++;
// }
// sharedList().clear();
// return;
}
//void SimpleAudioEngine::setResource(const char* pszZipFileName) {
//}
//////////////////////////////////////////////////////////////////////////
// BackgroundMusic
//////////////////////////////////////////////////////////////////////////
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath,
bool bLoop) {
oAudioPlayer->playBackgroundMusic(pszFilePath, bLoop);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
oAudioPlayer->playBackgroundMusic(fullPath.c_str(), bLoop);
}
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) {
@ -70,7 +59,9 @@ bool SimpleAudioEngine::isBackgroundMusicPlaying() {
}
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) {
return oAudioPlayer->preloadBackgroundMusic(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return oAudioPlayer->preloadBackgroundMusic(fullPath.c_str());
}
//////////////////////////////////////////////////////////////////////////
@ -79,7 +70,9 @@ void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath) {
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath,
bool bLoop) {
return oAudioPlayer->playEffect(pszFilePath, bLoop);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return oAudioPlayer->playEffect(fullPath.c_str(), bLoop);
}
void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {
@ -87,11 +80,15 @@ void SimpleAudioEngine::stopEffect(unsigned int nSoundId) {
}
void SimpleAudioEngine::preloadEffect(const char* pszFilePath) {
return oAudioPlayer->preloadEffect(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return oAudioPlayer->preloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::unloadEffect(const char* pszFilePath) {
return oAudioPlayer->unloadEffect(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return oAudioPlayer->unloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::pauseEffect(unsigned int uSoundId) {
@ -136,24 +133,5 @@ void SimpleAudioEngine::setEffectsVolume(float volume) {
return oAudioPlayer->setEffectsVolume(volume);
}
//////////////////////////////////////////////////////////////////////////
// static function
//////////////////////////////////////////////////////////////////////////
const char * _FullPath(const char * szPath) {
}
unsigned int _Hash(const char *key) {
// unsigned int len = strlen(key);
// const char *end=key+len;
// unsigned int hash;
//
// for (hash = 0; key < end; key++)
// {
// hash *= 16777619;
// hash ^= (unsigned int) (unsigned char) toupper(*key);
// }
// return (hash);
}
} // end of namespace CocosDenshion

View File

@ -24,6 +24,8 @@ THE SOFTWARE.
#include "SimpleAudioEngine.h"
#include "SimpleAudioEngine_objc.h"
#include "cocos2d.h"
USING_NS_CC;
static void static_end()
{
@ -174,12 +176,16 @@ void SimpleAudioEngine::end()
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
static_preloadBackgroundMusic(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_preloadBackgroundMusic(fullPath.c_str());
}
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
static_playBackgroundMusic(pszFilePath, bLoop);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_playBackgroundMusic(fullPath.c_str(), bLoop);
}
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
@ -224,32 +230,38 @@ void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
float SimpleAudioEngine::getEffectsVolume()
{
return static_getEffectsVolume();
return static_getEffectsVolume();
}
void SimpleAudioEngine::setEffectsVolume(float volume)
{
static_setEffectsVolume(volume);
static_setEffectsVolume(volume);
}
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
{
return static_playEffect(pszFilePath, bLoop);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
return static_playEffect(fullPath.c_str(), bLoop);
}
void SimpleAudioEngine::stopEffect(unsigned int nSoundId)
{
static_stopEffect(nSoundId);
static_stopEffect(nSoundId);
}
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{
static_preloadEffect(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_preloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
{
static_unloadEffect(pszFilePath);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
static_unloadEffect(fullPath.c_str());
}
void SimpleAudioEngine::pauseEffect(unsigned int uSoundId)

View File

@ -26,9 +26,10 @@ THE SOFTWARE.
#include "SimpleAudioEngine.h"
#include "s3e.h"
#include "IwUtil.h"
#include <string>
#include <map>
#include "cocos2d.h"
USING_NS_CC;
using namespace std ;
@ -103,9 +104,11 @@ namespace CocosDenshion
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb");
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
s3eFile *fileHandle = s3eFileOpen(fullPath.c_str(), "rb");
IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError()));
IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", fullPath.c_str(), s3eFileGetError()));
g_AudioFileSize = s3eFileGetSize(fileHandle);
g_AudioBuffer = (int16*)malloc(g_AudioFileSize);
@ -116,18 +119,20 @@ namespace CocosDenshion
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
s3eResult result;
result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop ? 0 : 1);
if ( result == S3E_RESULT_ERROR)
{
result = s3eAudioPlay(pszFilePath, bLoop ? 0 : 1);
result = s3eAudioPlay(fullPath.c_str(), bLoop ? 0 : 1);
}
if ( result == S3E_RESULT_ERROR)
{
IwAssert(GAME, ("Play music %s Failed. Error Code : %s", pszFilePath, s3eAudioGetErrorString()));
IwAssert(GAME, ("Play music %s Failed. Error Code : %s", fullPath.c_str(), s3eAudioGetErrorString()));
}
}
@ -191,20 +196,23 @@ namespace CocosDenshion
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
{
SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ;
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ;
int16* buff = 0 ;
if( it==g_pSoundFxMap->end() ) {
preloadEffect(pszFilePath) ;
preloadEffect(fullPath.c_str()) ;
}
buff = (*g_pSoundFxMap)[pszFilePath].data ;
buff = (*g_pSoundFxMap)[fullPath].data ;
int channel = s3eSoundGetFreeChannel();
s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[pszFilePath].size/2, (bLoop ? 0 : 1), 0);
s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[fullPath].size/2, (bLoop ? 0 : 1), 0);
if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", pszFilePath, s3eSoundGetErrorString()));
IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", fullPath.c_str(), s3eSoundGetErrorString()));
}
return channel;
@ -218,16 +226,18 @@ namespace CocosDenshion
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{
SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ;
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ;
if( it==g_pSoundFxMap->end() ) {
s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb");
s3eFile *fileHandle = s3eFileOpen(fullPath.c_str(), "rb");
IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError()));
IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", fullPath.c_str(), s3eFileGetError()));
int32 fileSize = s3eFileGetSize(fileHandle);
int16* buff = (int16*)malloc(fileSize);
(*g_pSoundFxMap)[pszFilePath] = SoundFx(buff,fileSize) ;
(*g_pSoundFxMap)[fullPath] = SoundFx(buff,fileSize) ;
memset(buff, 0, fileSize);
s3eFileRead(buff, fileSize, 1, fileHandle);
s3eFileClose(fileHandle);
@ -236,9 +246,11 @@ namespace CocosDenshion
void SimpleAudioEngine::unloadEffect(const char* pszFilePath)
{
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
// effect must not be playing!
SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ;
SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ;
if( it != g_pSoundFxMap->end() ) {
free(it->second.data) ;
g_pSoundFxMap->erase(it) ;

View File

@ -5,6 +5,8 @@ CCFLAGS = -Wall -fPIC
CXXFLAGS = -Wall -fPIC
VISIBILITY =
COCOS2DX_PATH = ../../cocos2dx
LBITS := $(shell getconf LONG_BIT)
ifeq ($(LBITS),64)
INCLUDES = -I.. \
@ -16,6 +18,16 @@ INCLUDES = -I.. \
-I../third_party/fmod/api/inc
endif
INCLUDES += -I$(COCOS2DX_PATH) \
-I$(COCOS2DX_PATH)/platform/third_party/linux \
-I$(COCOS2DX_PATH)/platform/third_party/linux/libfreetype2 \
-I$(COCOS2DX_PATH)/cocoa \
-I$(COCOS2DX_PATH)/include \
-I$(COCOS2DX_PATH)/platform \
-I$(COCOS2DX_PATH)/platform/linux \
-I$(COCOS2DX_PATH)/kazmath/include \
-I$(COCOS2DX_PATH)/platform/third_party/linux/libxml2 \
-I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg
DEFINES = -DLINUX

View File

@ -25,6 +25,7 @@ THE SOFTWARE.
#define __CC_FILEUTILS_PLATFORM_H__
#include <string>
#include <vector>
#include "CCPlatformMacros.h"
#include "ccTypes.h"
#include "ccTypeInfo.h"
@ -42,15 +43,36 @@ class CCArray;
class CC_DLL CCFileUtils : public TypeInfo
{
public:
/**
* Returns an unique ID for this class.
* @note It's only used for JSBindings now.
* @return The unique ID for this class.
*/
virtual long getClassTypeInfo() {
static const long id = cocos2d::getHashCodeByString(typeid(cocos2d::CCFileUtils).name());
return id;
}
/**
* Gets the instance of CCFileUtils.
*/
static CCFileUtils* sharedFileUtils();
/**
* Destroys the instance of CCFileUtils.
*/
static void purgeFileUtils();
/**
* Purges the file searching cache.
*
* @note It should be invoked after the resources were updated.
* For instance, in the CocosPlayer sample, every time you run application from CocosBuilder,
* All the resources will be downloaded to the writable folder, before new js app launchs,
* this method should be invokded to clean the file searching cache.
*/
void purgeCachedEntries();
/**
@brief Get resource file data
@param[in] pszFileName The resource file name which contains the path.
@ -71,14 +93,13 @@ public:
unsigned char* getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize);
/**
@brief Generate the absolute path of the file.
@param pszRelativePath The relative path of the file.
@return The absolute path of the file.
@warning We only add the ResourcePath before the relative path of the file.
@deprecated Please use fullPathForFilename instead.
If you have not set the ResourcePath, the function appends "/NEWPLUS/TDA_DATA/UserData/" by default.
You can set ResourcePath with void setResourcePath(const char *pszResourcePath);
*/
* @brief Generate the absolute path of the file.
* @param pszRelativePath The relative path of the file.
* @return The absolute path of the file.
* @warning We only add the ResourcePath before the relative path of the file.
* @deprecated Please use fullPathForFilename instead.
*
*/
CC_DEPRECATED_ATTRIBUTE const char* fullPathFromRelativePath(const char *pszRelativePath);
/** Returns the fullpath for a given filename.
@ -95,12 +116,13 @@ public:
Examples:
* In iOS: "image.png" -> "image.pvr" -> "/full/path/res_dir/image.pvr"
* In Android: "image.png" -> "image.png" -> "/full/path/res_dir/image.png"
* In iOS: "image.png" -> "image.pvr.ccz" -> "searching path/resolution dir/image.pvr.ccz"
* "gamescene/background.png" -> "gamescene/background.pvr.ccz" -> "searching path/gamescene/resolution dir/background.pvr.ccz"
* In Android: "sounds/click.wav" -> "sounds/click.ogg" -> "searching path/sounds/resolution dir/click.ogg"
@since v2.1
*/
std::string fullPathForFilename(const char* filename);
std::string fullPathForFilename(const char* pszFileName);
/**
* Loads the filenameLookup dictionary from the contents of a filename.
@ -150,39 +172,32 @@ public:
*/
CC_DEPRECATED_ATTRIBUTE void setResourceDirectory(const char *pszDirectoryName);
/** Array that contains the search order of the resources based for the device.
By default it will try to load resources in the following order until one is found:
- On iPad HD: iPad HD resources, iPad resources, resources not associated with any device
- On iPad: iPad resources, resources not associated with any device
- On iPhone 5 HD: iPhone 5 HD resources, iPhone HD resouces, iPhone 5 resources, iPhone resources, resources not associated with any device
- On iPhone HD: iPhone HD resources, iPhone resouces, resources not associated with any device
- On iPhone: iPhone resources, resources not associated with any device
- On Mac HD: Mac HD resources, Mac resources, resources not associated with any device
- On Mac: Mac resources, resources not associated with any device
If the property "enableiPhoneResourcesOniPad" is enabled, it will also search for iPhone resources if you are in an iPad.
@since v2.1
/**
* Sets the array that contains the search order of the resources based for the device.
*
* @see getSearchResolutionsOrder().
* @since v2.1
*/
void setSearchResolutionsOrder(CCArray* pSearchResolutionsOrder);
CCArray* getSearchResolutionsOrder();
/** Array of search paths.
You can use this array to modify the search path of the resources.
If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
By default it is an array with only the "" (empty string) element.
@since v2.1
*/
void setSearchPath(CCArray* pSearchPaths);
CCArray* getSearchPath();
void setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder);
const std::vector<std::string>& getSearchResolutionsOrder();
/**
@brief Get the resource directory
*/
const char* getResourceDirectory();
* Sets the array of search paths.
* You can use this array to modify the search path of the resources.
* If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
*
* By default it is an array with only the "" (empty string) element.
*
* @since v2.1
*/
void setSearchPath(const std::vector<std::string>& searchPaths);
const std::vector<std::string>& getSearchPath();
/**
* Gets the resource directory
* @deprecated Please use getSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE const char* getResourceDirectory();
/**
@brief Get the writeable path
@ -199,8 +214,6 @@ public:
protected:
CCFileUtils(void)
: m_pFilenameLookupDict(NULL)
, m_pSearchResolutionsOrderArray(NULL)
, m_pSearchPathArray(NULL)
{
}
@ -220,8 +233,8 @@ protected:
*/
CCDictionary* m_pFilenameLookupDict;
CCArray* m_pSearchResolutionsOrderArray;
CCArray* m_pSearchPathArray;
std::vector<std::string> m_searchResolutionsOrderArray;
std::vector<std::string> m_searchPathArray;
};
// end of platform group

View File

@ -387,28 +387,24 @@ std::string CCFileUtils::getNewFilename(const char* pszFileName)
return pszNewFileName;
}
void CCFileUtils::setSearchResolutionsOrder(CCArray* pSearchResolutionsOrder)
void CCFileUtils::setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder)
{
CC_SAFE_RETAIN(pSearchResolutionsOrder);
CC_SAFE_RELEASE(m_pSearchResolutionsOrderArray);
m_pSearchResolutionsOrderArray = pSearchResolutionsOrder;
m_searchResolutionsOrderArray = searchResolutionsOrder;
}
CCArray* CCFileUtils::getSearchResolutionsOrder()
const std::vector<std::string>& CCFileUtils::getSearchResolutionsOrder()
{
return m_pSearchResolutionsOrderArray;
return m_searchResolutionsOrderArray;
}
void CCFileUtils::setSearchPath(CCArray* pSearchPaths)
void CCFileUtils::setSearchPath(const std::vector<std::string>& searchPaths)
{
CC_SAFE_RETAIN(pSearchPaths);
CC_SAFE_RELEASE(m_pSearchPathArray);
m_pSearchPathArray = pSearchPaths;
m_searchPathArray = searchPaths;
}
CCArray* CCFileUtils::getSearchPath()
const std::vector<std::string>& CCFileUtils::getSearchPath()
{
return m_pSearchPathArray;
return m_searchPathArray;
}
const char* CCFileUtils::getResourceDirectory()

View File

@ -53,12 +53,8 @@ CCFileUtils* CCFileUtils::sharedFileUtils()
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create("assets/"));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("assets/");
m_searchResolutionsOrderArray.push_back("");
return true;
}
@ -68,8 +64,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pZipFile);
@ -88,10 +82,19 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
if (pszFileName == NULL || pszFileName[0] == '\0' || pszFileName[0] == '/') {
CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
// Return directly if it's an absolute path.
// On Android, there are two situations for full path.
// 1) Files in APK, e.g. assets/path/path/file.png
// 2) Files not in APK, e.g. /data/data/org.cocos2dx.hellocpp/cache/path/path/file.png, or /sdcard/path/path/file.png.
// So these two situations need to be checked on Android.
std::string strFileName = pszFileName;
if (pszFileName[0] == '/' || strFileName.find("assets/") == 0)
{
CCLOG("Return absolute path( %s ) directly.", pszFileName);
return pszFileName;
}
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end())
@ -105,20 +108,15 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
string fullpath = "";
bool bFound = false;
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
CCLOG("\n\nSEARCHING: %s, %s, %s", newFilename.c_str(), pResourceDirectory->getCString(), pSearchPath->getCString());
fullpath = this->getPathForFilename(newFilename, pResourceDirectory->getCString(), pSearchPath->getCString());
CCLOG("\n\nSEARCHING: %s, %s, %s", newFilename.c_str(), resOrderIter->c_str(), searchPathsIter->c_str());
fullpath = this->getPathForFilename(newFilename, *resOrderIter, *searchPathsIter);
// Check whether file exists in apk.
if (s_pZipFile->fileExists(fullpath))
@ -136,14 +134,16 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
}
if (bFound)
{
s_fullPathCache.insert(std::pair<std::string, std::string>(newFilename, fullpath));
// Using the filename passed in as key.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
CCLOG("Returning path: %s", fullpath.c_str());
return fullpath;
}
}
}
return newFilename;
// The file wasn't found, return the file name passed in.
return pszFileName;
}
const char* CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
@ -248,7 +248,7 @@ void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
m_obDirectory.insert(0, "assets/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
string CCFileUtils::getWriteablePath()

View File

@ -14,7 +14,6 @@ NS_CC_BEGIN;
// sharedApplication pointer
CCApplication * CCApplication::sm_pSharedApplication = 0;
long CCApplication::m_animationInterval = 1000;
static std::string s_strRootResPath = "";
// convert the timespec into milliseconds
static long time2millis(struct timespec *times)
@ -81,21 +80,22 @@ CCApplication::Orientation CCApplication::setOrientation(Orientation orientation
return orientation;
}
void CCApplication::setResourceRootPath(const char *pszRootResDir)
void CCApplication::setResourceRootPath(const std::string& rootResDir)
{
if (pszRootResDir)
{
s_strRootResPath = pszRootResDir;
if (s_strRootResPath[s_strRootResPath.length() - 1] != '/')
{
s_strRootResPath += '/';
}
}
m_resourceRootPath = rootResDir;
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
{
m_resourceRootPath += '/';
}
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = pFileUtils->getSearchPath();
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
pFileUtils->setSearchPath(searchPaths);
}
const char *CCApplication::getResourceRootPath(void)
const std::string& CCApplication::getResourceRootPath(void)
{
return s_strRootResPath.c_str();
return m_resourceRootPath;
}
TargetPlatform CCApplication::getTargetPlatform()

View File

@ -73,7 +73,7 @@ public:
protected:
static CCApplication * sm_pSharedApplication;
std::string m_resourceRootPath;
static long m_animationInterval;
};

View File

@ -32,6 +32,7 @@ NS_CC_BEGIN;
#define MAX_PATH 256
static CCFileUtils *s_pFileUtils = 0;
static std::map<std::string, std::string> s_fullPathCache;
CCFileUtils *CCFileUtils::sharedFileUtils()
{
@ -49,8 +50,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pFileUtils);
@ -58,11 +57,8 @@ void CCFileUtils::purgeFileUtils()
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create(""));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("");
m_searchResolutionsOrderArray.push_back("");
return true;
}
@ -70,15 +66,13 @@ bool CCFileUtils::init()
void CCFileUtils::purgeCachedEntries()
{
s_fullPathCache.clear();
}
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
{
std::string ret;
const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath();
std::string ret = CCApplication::sharedApplication()->getResourceRootPath();;
ret = resourceRootPath;
if (ret[ret.length()-1] != '\\' && ret[ret.length()-1] != '/')
{
ret += "/";
@ -112,60 +106,52 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
return ret;
}
const char* CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
if (pszFileName && pszFileName[0] == '/')
CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
// Return directly if it's absolute path.
if (pszFileName[0] == '/')
{
return pszFileName;
}
bool bFound = false;
CCString* pRet = CCString::create("");
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
do
{
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
// Search in subdirectories
fullpath = this->getPathForFilename(newFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
// check if file or path exist
if (access(fullpath.c_str(), F_OK) != -1)
{
pRet->m_sString = fullpath;
bFound = true;
break;
}
}
if (bFound)
{
break;
}
}
}while(false);
if (!bFound)
{ // Can't find the file, return the relative path.
pRet->m_sString = newFileName;
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end()) {
CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
return cacheIter->second;
}
return pRet->getCString();
// in Lookup Filename dictionary ?
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter);
// check if file or path exist
if (access(fullpath.c_str(), F_OK) != -1)
{
// Adding the full path to cache if the file was found.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
return fullpath;
}
}
}
// The file wasn't found, return the file name passed in.
return pszFileName;
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return fullPathForFilename(pszRelativePath);
return CCString::create(fullPathForFilename(pszRelativePath))->getCString();
}
@ -178,27 +164,6 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
return pRet->m_sString.c_str();
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
{
const char* pFullPath = this->fullPathForFilename(filename);
if (pFullPath)
{
CCDictionary* pDict = CCDictionary::createWithContentsOfFile(filename);
if (pDict)
{
CCDictionary* pMetadata = (CCDictionary*)pDict->objectForKey("metadata");
int version = ((CCString*)pMetadata->objectForKey("version"))->intValue();
if (version != 1)
{
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename);
return;
}
setFilenameLookupDictionary((CCDictionary*)pDict->objectForKey("filenames"));
}
}
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char *buffer = 0;
@ -247,7 +212,7 @@ void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
{
m_obDirectory.append("/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
std::string CCFileUtils::getWriteablePath()

View File

@ -162,8 +162,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pFileUtils);
@ -176,37 +174,30 @@ void CCFileUtils::purgeCachedEntries()
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create(""));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("");
m_searchResolutionsOrderArray.push_back("");
return true;
}
void CCFileUtils::setSearchResolutionsOrder(CCArray* pSearchResolutionsOrder)
void CCFileUtils::setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder)
{
CC_SAFE_RETAIN(pSearchResolutionsOrder);
CC_SAFE_RELEASE(m_pSearchResolutionsOrderArray);
m_pSearchResolutionsOrderArray = pSearchResolutionsOrder;
m_searchResolutionsOrderArray = searchResolutionsOrder;
}
CCArray* CCFileUtils::getSearchResolutionsOrder()
const std::vector<std::string>& CCFileUtils::getSearchResolutionsOrder()
{
return m_pSearchResolutionsOrderArray;
return m_searchResolutionsOrderArray;
}
void CCFileUtils::setSearchPath(CCArray* pSearchPaths)
void CCFileUtils::setSearchPath(const std::vector<std::string>& searchPaths)
{
CC_SAFE_RETAIN(pSearchPaths);
CC_SAFE_RELEASE(m_pSearchPathArray);
m_pSearchPathArray = pSearchPaths;
m_searchPathArray = searchPaths;
}
CCArray* CCFileUtils::getSearchPath()
const std::vector<std::string>& CCFileUtils::getSearchPath()
{
return m_pSearchPathArray;
return m_searchPathArray;
}
void CCFileUtils::setResourceDirectory(const char *pszDirectoryName)
@ -216,7 +207,7 @@ void CCFileUtils::setResourceDirectory(const char *pszDirectoryName)
{
m_obDirectory.append("/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
const char* CCFileUtils::getResourceDirectory()
@ -245,8 +236,6 @@ std::string CCFileUtils::getNewFilename(const char* pszFileName)
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
{
std::string ret = "";
std::string file = filename;
std::string file_path = "";
size_t pos = filename.find_last_of("/");
@ -270,56 +259,55 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
inDirectory:[NSString stringWithUTF8String:path.c_str()]];
if (fullpath != nil)
{
ret = [fullpath UTF8String];
if (fullpath != nil) {
return [fullpath UTF8String];
}
return ret;
// Return empty string when file wasn't found.
return "";
}
std::string CCFileUtils::fullPathForFilename(const char* filename)
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
CCAssert(filename != NULL, "CCFileUtils: Invalid path");
CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
NSString *relPath = [NSString stringWithUTF8String:pszFileName];
// Return directly if it's an absolute path.
if ([relPath isAbsolutePath]) {
return pszFileName;
}
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(filename);
if (cacheIter != s_fullPathCache.end())
{
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end()) {
//CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
return cacheIter->second;
}
std::string fullpath = "";
NSString *relPath = [NSString stringWithUTF8String:filename];
// only if it is not an absolute path
if( ! [relPath isAbsolutePath] ) {
// in Lookup Filename dictionary ?
std::string newfilename = this->getNewFilename(pszFileName);
std::string newfilename = this->getNewFilename(filename);
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
fullpath = this->getPathForFilename(newfilename, *resOrderIter, *searchPathsIter);
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
if (fullpath.length() > 0)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
fullpath = this->getPathForFilename(newfilename, pResourceDirectory->getCString(), pSearchPath->getCString());
if (fullpath.length() > 0)
{
s_fullPathCache.insert(std::pair<std::string, std::string>(filename, fullpath));
return fullpath;
}
// Adding the full path to cache if the file was found.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
return fullpath;
}
}
}
return filename;
// The file wasn't found, return the file name passed in.
return pszFileName;
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
@ -350,11 +338,10 @@ void CCFileUtils::setFilenameLookupDictionary(CCDictionary* pFilenameLookupDict)
CC_SAFE_RETAIN(m_pFilenameLookupDict);
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
const char* CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
std::string relativeFile = fullPathForFilename(pszRelativeFile);
CCString *pRet = new CCString();
pRet->autorelease();
CCString *pRet = CCString::create("");
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += getNewFilename(pszFilename);
return pRet->m_sString.c_str();

View File

@ -13,8 +13,6 @@
NS_CC_BEGIN
static std::string s_strRootResPath = "";
// sharedApplication pointer
CCApplication * CCApplication::sm_pSharedApplication = 0;
@ -67,21 +65,22 @@ void CCApplication::setAnimationInterval(double interval)
m_nAnimationInterval = interval*1000.0f;
}
void CCApplication::setResourceRootPath(const char* pszRootResDir)
void CCApplication::setResourceRootPath(const std::string& rootResDir)
{
if (pszRootResDir)
{
s_strRootResPath = pszRootResDir;
if (s_strRootResPath[s_strRootResPath.length()-1] != '/')
{
s_strRootResPath += '/';
}
}
m_resourceRootPath = rootResDir;
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
{
m_resourceRootPath += '/';
}
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = pFileUtils->getSearchPath();
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
pFileUtils->setSearchPath(searchPaths);
}
const char* CCApplication::getResourceRootPath(void)
const std::string& CCApplication::getResourceRootPath(void)
{
return s_strRootResPath.c_str();
return m_resourceRootPath;
}
TargetPlatform CCApplication::getTargetPlatform()

View File

@ -40,11 +40,17 @@ public:
/* override functions */
virtual ccLanguageType getCurrentLanguage();
/* set the Resource root path */
void setResourceRootPath(const char* pszRootResDir);
/**
* Sets the Resource root path.
* @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE void setResourceRootPath(const char* pszRootResDir);
/* get the Resource root path */
const char* getResourceRootPath(void);
/**
* Gets the Resource root path.
* @deprecated Please use CCFileUtils::sharedFileUtils()->getSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE const char* getResourceRootPath(void);
/**
@brief Get target platform
@ -52,6 +58,7 @@ public:
virtual TargetPlatform getTargetPlatform();
protected:
long m_nAnimationInterval; //micro second
std::string m_resourceRootPath;
static CCApplication * sm_pSharedApplication;
};

View File

@ -21,6 +21,7 @@ using namespace std;
NS_CC_BEGIN
static CCFileUtils* s_pFileUtils = NULL;
static std::map<std::string, std::string> s_fullPathCache;
CCFileUtils* CCFileUtils::sharedFileUtils()
{
@ -34,11 +35,8 @@ CCFileUtils* CCFileUtils::sharedFileUtils()
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create(""));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("");
m_searchResolutionsOrderArray.push_back("");
return true;
}
@ -49,8 +47,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pFileUtils);
@ -58,15 +54,13 @@ void CCFileUtils::purgeFileUtils()
void CCFileUtils::purgeCachedEntries()
{
s_fullPathCache.clear();
}
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
{
std::string ret;
const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath();
std::string ret = CCApplication::sharedApplication()->getResourceRootPath();
ret = resourceRootPath;
if (ret[ret.length()-1] != '\\' && ret[ret.length()-1] != '/')
{
ret += "/";
@ -100,61 +94,54 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
return ret;
}
const char* CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
if (pszFileName && pszFileName[0] == '/')
CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
// Return directly if it's an absolute path.
if (pszFileName[0] == '/')
{
//CCLOG("return absolute path directly: %s ", pszFileName);
return pszFileName;
}
bool bFound = false;
CCString* pRet = CCString::create("");
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
do
{
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
// Search in subdirectories
fullpath = this->getPathForFilename(newFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
// check if file or path exist
struct stat sts;
if (stat(fullpath.c_str(), &sts) != -1)
{
pRet->m_sString = fullpath;
bFound = true;
break;
}
}
if (bFound)
{
break;
}
}
}while(false);
if (!bFound)
{ // Can't find the file, return the relative path.
pRet->m_sString = newFileName;
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end()) {
//CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
return cacheIter->second;
}
return pRet->getCString();
// in Lookup Filename dictionary ?
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter);
// check if file or path exist
struct stat sts;
if (stat(fullpath.c_str(), &sts) != -1)
{
// Adding the full path to cache if the file was found.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
return fullpath;
}
}
}
// The file wasn't found, return the file name passed in.
return pszFileName;
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return fullPathForFilename(pszRelativePath);
return CCString::create(fullPathForFilename(pszRelativePath))->getCString();
}
@ -167,27 +154,6 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
return pRet->m_sString.c_str();
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
{
const char* pFullPath = this->fullPathForFilename(filename);
if (pFullPath)
{
CCDictionary* pDict = CCDictionary::createWithContentsOfFile(filename);
if (pDict)
{
CCDictionary* pMetadata = (CCDictionary*)pDict->objectForKey("metadata");
int version = ((CCString*)pMetadata->objectForKey("version"))->intValue();
if (version != 1)
{
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename);
return;
}
setFilenameLookupDictionary((CCDictionary*)pDict->objectForKey("filenames"));
}
}
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char * pData = 0;
@ -229,7 +195,7 @@ void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
{
m_obDirectory.append("/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
string CCFileUtils::getWriteablePath()

View File

@ -69,11 +69,17 @@ public:
*/
virtual TargetPlatform getTargetPlatform();
/* set the Resource root path */
void setResourceRootPath(const std::string& rootResDir);
/**
* Sets the Resource root path.
* @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE void setResourceRootPath(const std::string& rootResDir);
/* get the Resource root path */
const std::string& getResourceRootPath(void);
/**
* Gets the Resource root path.
* @deprecated Please use CCFileUtils::sharedFileUtils()->getSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE const std::string& getResourceRootPath(void);
void setStartupScriptFilename(const std::string& startupScriptFile);

View File

@ -25,7 +25,7 @@
#import "CCApplication.h"
#import <Cocoa/Cocoa.h>
#include <algorithm>
#include "platform/CCFileUtils.h"
#include "CCGeometry.h"
#include "CCDirector.h"
#import "CCDirectorCaller.h"
@ -126,11 +126,14 @@ ccLanguageType CCApplication::getCurrentLanguage()
void CCApplication::setResourceRootPath(const std::string& rootResDir)
{
m_resourceRootPath = rootResDir;
std::replace(m_resourceRootPath.begin(), m_resourceRootPath.end(), '\\', '/');
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
{
m_resourceRootPath += '/';
}
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = pFileUtils->getSearchPath();
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
pFileUtils->setSearchPath(searchPaths);
}
const std::string& CCApplication::getResourceRootPath(void)

View File

@ -44,8 +44,6 @@ USING_NS_CC;
static void static_addValueToCCDict(id key, id value, CCDictionary* pDict);
static void static_addItemToCCArray(id item, CCArray* pArray);
static NSFileManager *__localFileManager= [NSFileManager defaultManager];
static void static_addItemToCCArray(id item, CCArray *pArray)
{
// add string value into array
@ -148,12 +146,14 @@ CCDictionary* ccFileUtils_dictionaryWithContentsOfFileThreadSafe(const char *pFi
CCArray* ccFileUtils_arrayWithContentsOfFileThreadSafe(const char* pFileName);
static CCFileUtils* s_pFileUtils = NULL;
static std::map<std::string, std::string> s_fullPathCache;
CCFileUtils* CCFileUtils::sharedFileUtils()
{
if (s_pFileUtils == NULL)
{
s_pFileUtils = new CCFileUtils();
s_pFileUtils->init();
}
return s_pFileUtils;
}
@ -164,8 +164,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pFileUtils);
@ -173,20 +171,37 @@ void CCFileUtils::purgeFileUtils()
void CCFileUtils::purgeCachedEntries()
{
s_fullPathCache.clear();
}
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create(""));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("");
m_searchResolutionsOrderArray.push_back("");
return true;
}
void CCFileUtils::setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder)
{
m_searchResolutionsOrderArray = searchResolutionsOrder;
}
const std::vector<std::string>& CCFileUtils::getSearchResolutionsOrder()
{
return m_searchResolutionsOrderArray;
}
void CCFileUtils::setSearchPath(const std::vector<std::string>& searchPaths)
{
m_searchPathArray = searchPaths;
}
const std::vector<std::string>& CCFileUtils::getSearchPath()
{
return m_searchPathArray;
}
void CCFileUtils::setResourceDirectory(const char *pszDirectoryName)
{
m_obDirectory = pszDirectoryName;
@ -194,92 +209,151 @@ void CCFileUtils::setResourceDirectory(const char *pszDirectoryName)
{
m_obDirectory.append("/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
void CCFileUtils::setSearchResolutionsOrder(CCArray* pSearchResolutionsOrder)
const char* CCFileUtils::getResourceDirectory()
{
CC_SAFE_RETAIN(pSearchResolutionsOrder);
CC_SAFE_RELEASE(m_pSearchResolutionsOrderArray);
m_pSearchResolutionsOrderArray = pSearchResolutionsOrder;
}
CCArray* CCFileUtils::getSearchResolutionsOrder()
{
return m_pSearchResolutionsOrderArray;
}
void CCFileUtils::setSearchPath(CCArray* pSearchPaths)
{
CC_SAFE_RETAIN(pSearchPaths);
CC_SAFE_RELEASE(m_pSearchPathArray);
m_pSearchPathArray = pSearchPaths;
}
CCArray* CCFileUtils::getSearchPath()
{
return m_pSearchPathArray;
return m_obDirectory.c_str();
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
CCAssert(pszRelativePath != NULL, "CCFileUtils: Invalid path");
NSString *fullpath = nil;
NSString *relPath = [NSString stringWithUTF8String:pszRelativePath];
// only if it is not an absolute path
if( ! [relPath isAbsolutePath] ) {
// pathForResource also searches in .lproj directories. issue #1230
NSString *lastPathComponent = [relPath lastPathComponent];
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
NSMutableString *imageDirectoryByAppendDirectory = [NSMutableString stringWithUTF8String:m_obDirectory.c_str()];
[imageDirectoryByAppendDirectory appendString:imageDirectory];
const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath();
if (resourceRootPath.length() == 0)
{
// search path from directory set by setResourceDirectory
fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent
ofType:nil
inDirectory:imageDirectoryByAppendDirectory];
if (fullpath == nil)
{
// search from root directory
fullpath = [[NSBundle mainBundle] pathForResource:lastPathComponent
ofType:nil
inDirectory:imageDirectory];
}
}
else
{
fullpath = [NSString stringWithFormat:@"%s%s%@", resourceRootPath.c_str(), m_obDirectory.c_str(), relPath];
}
}
if (fullpath == nil)
{
fullpath = relPath;
}
return [fullpath UTF8String];
return CCString::create(fullPathForFilename(pszRelativePath))->getCString();
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
std::string CCFileUtils::getNewFilename(const char* pszFileName)
{
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
CCString *pRet = new CCString();
pRet->autorelease();
const char* pszNewFileName = NULL;
// in Lookup Filename dictionary ?
CCString* fileNameFound = m_pFilenameLookupDict ? (CCString*)m_pFilenameLookupDict->objectForKey(pszFileName) : NULL;
if( NULL == fileNameFound || fileNameFound->length() == 0) {
pszNewFileName = pszFileName;
}
else {
pszNewFileName = fileNameFound->getCString();
}
return pszNewFileName;
}
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
{
std::string file = filename;
std::string file_path = "";
size_t pos = filename.find_last_of("/");
if (pos != std::string::npos)
{
file_path = filename.substr(0, pos+1);
file = filename.substr(pos+1);
}
// searchPath + file_path + resourceDirectory
std::string path = searchPath;
if (path[path.length()-1] != '/')
{
path += "/";
}
path += file_path;
path += resourceDirectory;
NSString* fullpath = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:file.c_str()]
ofType:nil
inDirectory:[NSString stringWithUTF8String:path.c_str()]];
if (fullpath != nil) {
return [fullpath UTF8String];
}
// Return empty string when file wasn't found.
return "";
}
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
NSString *relPath = [NSString stringWithUTF8String:pszFileName];
// Return directly if it's an absolute path.
if ([relPath isAbsolutePath]) {
return pszFileName;
}
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end()) {
//CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
return cacheIter->second;
}
std::string fullpath = "";
// in Lookup Filename dictionary ?
std::string newfilename = this->getNewFilename(pszFileName);
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
fullpath = this->getPathForFilename(newfilename, *resOrderIter, *searchPathsIter);
if (fullpath.length() > 0)
{
// Adding the full path to cache if the file was found.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
return fullpath;
}
}
}
// The file wasn't found, return the file name passed in.
return pszFileName;
}
void CCFileUtils::loadFilenameLookupDictionaryFromFile(const char* filename)
{
std::string pFullPath = this->fullPathForFilename(filename);
if (pFullPath.length() > 0)
{
CCDictionary* pDict = CCDictionary::createWithContentsOfFile(filename);
if (pDict)
{
CCDictionary* pMetadata = (CCDictionary*)pDict->objectForKey("metadata");
int version = ((CCString*)pMetadata->objectForKey("version"))->intValue();
if (version != 1)
{
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename);
return;
}
setFilenameLookupDictionary((CCDictionary*)pDict->objectForKey("filenames"));
}
}
}
void CCFileUtils::setFilenameLookupDictionary(CCDictionary* pFilenameLookupDict)
{
CC_SAFE_RELEASE(m_pFilenameLookupDict);
m_pFilenameLookupDict = pFilenameLookupDict;
CC_SAFE_RETAIN(m_pFilenameLookupDict);
}
const char* CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
std::string relativeFile = fullPathForFilename(pszRelativeFile);
CCString *pRet = CCString::create("");
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += pszFilename;
pRet->m_sString += getNewFilename(pszFilename);
return pRet->m_sString.c_str();
}
CCDictionary* ccFileUtils_dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
{
const char* pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pFileName);
NSString* pPath = [NSString stringWithUTF8String:pszFullPath];
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pFileName);
NSString* pPath = [NSString stringWithUTF8String:fullPath.c_str()];
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
CCDictionary* pRet = new CCDictionary();

View File

@ -168,11 +168,11 @@ static EAGLView *view;
[self lockOpenGLContext];
NSRect rect = [self bounds];
// NSRect rect = [self bounds];
cocos2d::CCDirector *director = cocos2d::CCDirector::sharedDirector();
CGSize size = NSSizeToCGSize(rect.size);
cocos2d::CCSize ccsize = cocos2d::CCSizeMake(size.width, size.height);
// CGSize size = NSSizeToCGSize(rect.size);
// cocos2d::CCSize ccsize = cocos2d::CCSizeMake(size.width, size.height);
//director->reshapeProjection(ccsize);
// avoid flicker

View File

@ -38,6 +38,7 @@ NS_CC_BEGIN;
static CCFileUtils* s_pFileUtils = NULL;
static std::map<std::string, std::string> s_fullPathCache;
CCFileUtils* CCFileUtils::sharedFileUtils()
{
@ -51,11 +52,8 @@ CCFileUtils* CCFileUtils::sharedFileUtils()
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create(""));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("");
m_searchResolutionsOrderArray.push_back("");
return true;
}
@ -66,8 +64,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pFileUtils);
@ -75,7 +71,7 @@ void CCFileUtils::purgeFileUtils()
void CCFileUtils::purgeCachedEntries()
{
s_fullPathCache.clear();
}
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
@ -115,63 +111,51 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
return ret;
}
const char* CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
// TODO HOW ARE WE SUPPOSED TO WRITE BACK TO THE "ignore" REFERENCE?
IwAssert(GAME, pszFileName);
if (pszFileName && pszFileName[0] == '/')
// Return directly if it's an absolute path.
if (pszFileName[0] == '/')
{
return pszFileName;
}
bool bFound = false;
CCString* pRet = CCString::create("");
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end()) {
CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
return cacheIter->second;
}
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
do
{
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
// Search in subdirectories
fullpath = this->getPathForFilename(newFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter);
// check if file or path exist
if (s3eFileCheckExists(fullpath.c_str()) == S3E_TRUE)
{
pRet->m_sString = fullpath;
bFound = true;
break;
}
}
if (bFound)
// check if file or path exist
if (s3eFileCheckExists(fullpath.c_str()) == S3E_TRUE)
{
break;
// Adding the full path to cache if the file was found.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
return fullpath;
}
}
}while(false);
if (!bFound)
{ // Can't find the file, return the relative path.
pRet->m_sString = newFileName;
}
return pRet->getCString();
// The file wasn't found, return the file name passed in.
return pszFileName;
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return fullPathForFilename(pszRelativePath);
return CCString::create(fullPathForFilename(pszRelativePath))->getCString();
}
@ -219,7 +203,7 @@ void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
{
m_obDirectory.append("/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
std::string CCFileUtils::getWriteablePath()

View File

@ -163,6 +163,15 @@ void CCApplication::setResourceRootPath(const std::string& rootResDir)
{
m_resourceRootPath += '/';
}
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = pFileUtils->getSearchPath();
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
pFileUtils->setSearchPath(searchPaths);
}
const std::string& CCApplication::getResourceRootPath(void)
{
return m_resourceRootPath;
}
void CCApplication::setStartupScriptFilename(const std::string& startupScriptFile)

View File

@ -36,14 +36,17 @@ public:
*/
virtual TargetPlatform getTargetPlatform();
/* set the Resource root path */
void setResourceRootPath(const std::string& rootResDir);
/**
* Sets the Resource root path.
* @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE void setResourceRootPath(const std::string& rootResDir);
/* get the Resource root path */
const std::string& getResourceRootPath(void)
{
return m_resourceRootPath;
}
/**
* Gets the Resource root path.
* @deprecated Please use CCFileUtils::sharedFileUtils()->getSearchPath() instead.
*/
CC_DEPRECATED_ATTRIBUTE const std::string& getResourceRootPath(void);
void setStartupScriptFilename(const std::string& startupScriptFile);

View File

@ -33,6 +33,7 @@ NS_CC_BEGIN
// record the resource path
static char s_pszResourcePath[MAX_PATH] = {0};
static std::map<std::string, std::string> s_fullPathCache;
static void _CheckPath()
{
@ -65,8 +66,6 @@ void CCFileUtils::purgeFileUtils()
{
s_pFileUtils->purgeCachedEntries();
CC_SAFE_RELEASE(s_pFileUtils->m_pFilenameLookupDict);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchPathArray);
CC_SAFE_RELEASE(s_pFileUtils->m_pSearchResolutionsOrderArray);
}
CC_SAFE_DELETE(s_pFileUtils);
@ -74,16 +73,13 @@ void CCFileUtils::purgeFileUtils()
void CCFileUtils::purgeCachedEntries()
{
s_fullPathCache.clear();
}
bool CCFileUtils::init()
{
m_pSearchPathArray = new CCArray();
m_pSearchPathArray->addObject(CCString::create(""));
m_pSearchResolutionsOrderArray = new CCArray();
m_pSearchResolutionsOrderArray->addObject(CCString::create(""));
m_searchPathArray.push_back("");
m_searchResolutionsOrderArray.push_back("");
return true;
}
@ -96,17 +92,10 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
{
std::string ret;
const std::string& resourceRootPath = CCApplication::sharedApplication()->getResourceRootPath();
if (filename.length() > 0
&& ('/' == filename[0] || '\\' == filename[0]))
{
// path start with '/' or '\', is absolute path without driver name
char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0};
ret = szDriver;
ret += "/";
}
else if (resourceRootPath.length() > 0)
if (resourceRootPath.length() > 0)
{
ret = resourceRootPath;
if (ret[ret.length()-1] != '\\' && ret[ret.length()-1] != '/')
@ -149,46 +138,48 @@ std::string CCFileUtils::getPathForFilename(const std::string& filename, const s
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
bool bFound = false;
CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
// Return directly if it's an absolute path.
if (strlen(pszFileName) > 3
&& pszFileName[0] >= 'a' && pszFileName[0] <= 'z'
&& pszFileName[0] >= 'A' && pszFileName[0] <= 'Z'
&& (pszFileName[1] == ':')
&& (pszFileName[2] == '\\' || pszFileName[2] == '/')
)
{
CCLOG("Probably invoking fullPathForFilename recursively, return the full path: %s", pszFileName);
return pszFileName;
}
// Already Cached ?
std::map<std::string, std::string>::iterator cacheIter = s_fullPathCache.find(pszFileName);
if (cacheIter != s_fullPathCache.end()) {
// CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
return cacheIter->second;
}
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
do
{
if ((newFileName.length() > 1 && newFileName[1] == ':'))
{
// path start with "x:", is absolute path, return directly
return newFileName;
}
for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArray.begin();
searchPathsIter != m_searchPathArray.end(); ++searchPathsIter) {
for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter);
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
if (GetFileAttributesA(fullpath.c_str()) != -1)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
// Search in subdirectories
fullpath = this->getPathForFilename(newFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
if (GetFileAttributesA(fullpath.c_str()) != -1)
{
bFound = true;
break;
}
}
if (bFound)
{
break;
// Adding the full path to cache if the file was found.
s_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
return fullpath;
}
}
}
}while(false);
return bFound ? fullpath : newFileName;
// The file wasn't found, return the file name passed in.
return pszFileName;
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
@ -238,7 +229,7 @@ void CCFileUtils::setResourceDirectory(const char* pszResourceDirectory)
m_obDirectory.append("/");
}
m_pSearchPathArray->insertObject(CCString::create(m_obDirectory.c_str()), 0);
m_searchPathArray.insert(m_searchPathArray.begin(), m_obDirectory);
}
string CCFileUtils::getWriteablePath()

View File

@ -603,7 +603,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
{
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
// option 1: subdata
glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
//glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
// option 2: data
// glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW);
@ -619,7 +619,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
m_bDirty = false;
}
glBindVertexArray(m_uVAOname);
ccGLBindVAO(m_uVAOname);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
@ -635,7 +635,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
glBindVertexArray(0);
// glBindVertexArray(0);
#else // ! CC_TEXTURE_ATLAS_USE_VAO

View File

@ -1,2 +1,2 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1

View File

@ -17,7 +17,7 @@ INCLUDES = -I../ \
-I$(COCOS2DX_PATH)/platform/linux \
-I$(COCOS2DX_PATH)/kazmath/include \
-I$(COCOS2DX_PATH)/platform/third_party/linux/libxml2 \
-I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg \
-I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg
DEFINES = -DLINUX

View File

@ -110,7 +110,7 @@ bool HelloWorld::init()
// see http://www.cocos2d-x.org/boards/6/topics/1478
this->schedule( schedule_selector(HelloWorld::updateGame) );
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("background-music-aac.wav"), true);
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music-aac.wav", true);
bRet = true;
} while (0);
@ -237,7 +237,7 @@ void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
projectile->setTag(2);
_projectiles->addObject(projectile);
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("pew-pew-lei.wav"));
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew-lei.wav");
}
void HelloWorld::updateGame(float dt)

View File

@ -1,2 +1,2 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1

View File

@ -76,8 +76,8 @@ m_nSoundId(0)
setTouchEnabled(true);
// preload background music and effect
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE) );
SimpleAudioEngine::sharedEngine()->preloadEffect( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE) );
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( MUSIC_FILE );
SimpleAudioEngine::sharedEngine()->preloadEffect( EFFECT_FILE );
// set default volume
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
@ -106,7 +106,7 @@ void CocosDenshionTest::menuCallback(CCObject * pSender)
// play background music
case 0:
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE)).c_str(), true);
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_FILE, true);
break;
// stop background music
case 1:
@ -137,11 +137,11 @@ void CocosDenshionTest::menuCallback(CCObject * pSender)
break;
// play effect
case 6:
m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str());
m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(EFFECT_FILE);
break;
// play effect
case 7:
m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str(), true);
m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(EFFECT_FILE, true);
break;
// stop effect
case 8:
@ -149,7 +149,7 @@ void CocosDenshionTest::menuCallback(CCObject * pSender)
break;
// unload effect
case 9:
SimpleAudioEngine::sharedEngine()->unloadEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str());
SimpleAudioEngine::sharedEngine()->unloadEffect(EFFECT_FILE);
break;
// add bakcground music volume
case 10:

View File

@ -524,7 +524,7 @@ bool SpriteBlur::initWithTexture(CCTexture2D* texture, const CCRect& rect)
void SpriteBlur::initProgram()
{
GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile(
CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_Blur.fsh"))->getCString();
CCFileUtils::sharedFileUtils()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString();
CCGLProgram* pProgram = new CCGLProgram();
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource);
setShaderProgram(pProgram);
@ -674,7 +674,7 @@ bool ShaderRetroEffect::init()
{
if( ShaderTestDemo::init() ) {
GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_HorizontalColor.fsh"))->getCString();
GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathForFilename("Shaders/example_HorizontalColor.fsh").c_str())->getCString();
CCGLProgram *p = new CCGLProgram();
p->initWithVertexShaderByteArray(ccPositionTexture_vert, fragSource);

View File

@ -1254,7 +1254,7 @@ TMXOrthoFromXMLTest::TMXOrthoFromXMLTest()
string resources = "TileMaps"; // partial paths are OK as resource paths.
string file = resources + "/orthogonal-test1.tmx";
CCString* str = CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(file.c_str()));
CCString* str = CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(file.c_str()).c_str());
CCAssert(str != NULL, "Unable to open file");
CCTMXTiledMap *map = CCTMXTiledMap::createWithXML(str->getCString() ,resources.c_str());

View File

@ -1,2 +1,2 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1

View File

@ -66,39 +66,43 @@ bool AppDelegate::applicationDidFinishLaunching()
CCSize designSize = CCSizeMake(320, 480);
CCSize resourceSize = CCSizeMake(320, 480);
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchResOrder = pFileUtils->getSearchResolutionsOrder();
string res = "xlarge";
// if (screenSize.height > 1024)
// {
// resourceSize = CCSizeMake(1280, 1920);
// CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create(""), NULL));
// res = "xlarge";
// }
// else
// if (screenSize.height > 1024)
// {
// resourceSize = CCSizeMake(1280, 1920);
// searchResOrder.insert(searchResOrder.begin(), "resources-xlarge");
// res = "xlarge";
// }
// else
if (screenSize.height > 960)
{
resourceSize = CCSizeMake(640, 960);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-large"), CCString::create(""), NULL));
res = "large";
resourceSize = CCSizeMake(640, 960);
searchResOrder.insert(searchResOrder.begin(), "resources-large");
res = "large";
}
else if (screenSize.height > 480)
{
resourceSize = CCSizeMake(480, 720);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-medium"), CCString::create(""), NULL));
res = "medium";
resourceSize = CCSizeMake(480, 720);
searchResOrder.insert(searchResOrder.begin(), "resources-medium");
res = "medium";
}
else
{
resourceSize = CCSizeMake(320, 568);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-small"), CCString::create(""), NULL));
res = "small";
resourceSize = CCSizeMake(320, 568);
searchResOrder.insert(searchResOrder.begin(), "resources-small");
res = "small";
}
pFileUtils->setSearchResolutionsOrder(searchResOrder);
pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
CCFileUtils::sharedFileUtils()->setSearchPath(CCArray::create(CCString::create(CCFileUtils::sharedFileUtils()->getWriteablePath()),
CCString::create("assets/"), CCString::create(""), NULL));
std::vector<std::string> searchPaths = pFileUtils->getSearchPath();
searchPaths.insert(searchPaths.begin(), pFileUtils->getWriteablePath());
pFileUtils->setSearchPath(searchPaths);
PlayerStatus::setDeviceResolution(res);
// turn on display FPS

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CocosDragonJS</name>
<name>CocosPlayer</name>
<comment></comment>
<projects>
</projects>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CocosDragonJS</string>
<string name="app_name">CocosPlayer</string>
</resources>

View File

@ -33,45 +33,62 @@ bool AppDelegate::applicationDidFinishLaunching()
CCSize designSize = CCSizeMake(320, 480);
CCSize resourceSize = CCSizeMake(320, 480);
std::vector<std::string> searchPaths;
std::vector<std::string> resDirOrders;
TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();
if (platform == kTargetIphone || platform == kTargetIpad)
{
CCFileUtils::sharedFileUtils()->setSearchPath(CCArray::create(CCString::create("Published-iOS"), CCString::create(""), NULL));
searchPaths.push_back("Published-iOS"); // Resources/Published-iOS
searchPaths.push_back(""); // Resources/, we added this searching path since some files such as jsb_cocos2d.js were placed at the root folder.
CCFileUtils::sharedFileUtils()->setSearchPath(searchPaths);
if (screenSize.height > 480)
{
resourceSize = CCSizeMake(640, 960);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-iphonehd"), CCString::create(""), NULL));
resDirOrders.push_back("resources-iphonehd");
resDirOrders.push_back("");
}
else
{
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-iphone"), CCString::create(""), NULL));
resDirOrders.push_back("resources-iphone");
resDirOrders.push_back("");
}
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
}
else if (platform == kTargetAndroid || platform == kTargetWindows)
{
// Comments it since opengles2.0 only supports texture size within 2048x2048.
// if (screenSize.height > 1024)
// {
// resourceSize = CCSizeMake(1280, 1920);
// CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create("resources-large"), CCString::create(""), NULL));
// }
// else
// if (screenSize.height > 1024)
// {
// resourceSize = CCSizeMake(1280, 1920);
// resDirOrders.push_back("resources-xlarge");
// resDirOrders.push_back("");
// }
// else
if (screenSize.height > 960)
{
resourceSize = CCSizeMake(640, 960);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-large"), CCString::create("resources-medium"), CCString::create(""), NULL));
resDirOrders.push_back("resources-large");
resDirOrders.push_back("");
}
else if (screenSize.height > 480)
{
resourceSize = CCSizeMake(480, 720);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-medium"), CCString::create(""), NULL));
resDirOrders.push_back("resources-medium");
resDirOrders.push_back("");
}
else
{
resourceSize = CCSizeMake(320, 568);
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-small"), CCString::create(""), NULL));
resDirOrders.push_back("resources-small");
resDirOrders.push_back("");
}
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);
}
pDirector->setContentScaleFactor(resourceSize.width/designSize.width);

@ -1 +1 @@
Subproject commit 781803f41e2b68a25cd7ad993c9cd70da8b9c05e
Subproject commit b744bb4009bdd74d428587ba51d991294b549be4

View File

@ -45,7 +45,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pEngine->executeString(pstrFileContent->getCString());
}
#else
std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("hello.lua");
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("hello.lua");
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
pEngine->executeScriptFile(path.c_str());
#endif

View File

@ -157,7 +157,7 @@ local function main()
local function menuCallbackOpenPopup()
-- loop test sound effect
local effectPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("effect1.wav")
local effectPath = CCFileUtils:sharedFileUtils():fullPathForFilename("effect1.wav")
effectID = SimpleAudioEngine:sharedEngine():playEffect(effectPath)
menuPopup:setVisible(true)
end
@ -187,10 +187,10 @@ local function main()
-- play background music, preload effect
-- uncomment below for the BlackBerry version
-- local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("background.ogg")
local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("background.mp3")
-- local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathForFilename("background.ogg")
local bgMusicPath = CCFileUtils:sharedFileUtils():fullPathForFilename("background.mp3")
SimpleAudioEngine:sharedEngine():playBackgroundMusic(bgMusicPath, true)
local effectPath = CCFileUtils:sharedFileUtils():fullPathFromRelativePath("effect1.wav")
local effectPath = CCFileUtils:sharedFileUtils():fullPathForFilename("effect1.wav")
SimpleAudioEngine:sharedEngine():preloadEffect(effectPath)
-- run

View File

@ -1,3 +1,3 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1
APP_CPPFLAGS += -fexceptions

View File

@ -41,7 +41,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pEngine->executeString(pstrFileContent->getCString());
}
#else
std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath((dirPath + "/controller.lua").c_str());
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename((dirPath + "/controller.lua").c_str());
pEngine->addSearchPath(path.substr(0, path.find_last_of("/") - dirPath.length()).c_str());
pEngine->executeScriptFile(path.c_str());
#endif

View File

@ -1,3 +1,3 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1
APP_CPPFLAGS += -fexceptions

View File

@ -2276,6 +2276,7 @@ extern JSObject* js_cocos2dx_CCScheduler_prototype;
extern JSObject* js_cocos2dx_CCDrawNode_prototype;
extern JSObject* js_cocos2dx_CCTexture2D_prototype;
extern JSObject* js_cocos2dx_CCMenu_prototype;
extern JSObject* js_cocos2dx_CCFileUtils_prototype;
// setBlendFunc
template<class T>
@ -2506,6 +2507,122 @@ JSBool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *v
return JS_FALSE;
}
static JSBool jsval_to_string_vector(JSContext* cx, jsval v, std::vector<std::string>& ret) {
JSObject *jsobj;
JSBool ok = JS_ValueToObject( cx, v, &jsobj );
JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error converting value to object");
JSB_PRECONDITION2( jsobj && JS_IsArrayObject( cx, jsobj), cx, JS_FALSE, "Object must be an array");
uint32_t len = 0;
JS_GetArrayLength(cx, jsobj, &len);
for (uint32_t i=0; i < len; i++) {
jsval elt;
if (JS_GetElement(cx, jsobj, i, &elt)) {
if (JSVAL_IS_STRING(elt))
{
JSStringWrapper str(JSVAL_TO_STRING(elt));
ret.push_back(str.get());
}
}
}
return JS_TRUE;
}
static jsval string_vector_to_jsval(JSContext* cx, const std::vector<std::string>& arr) {
JSObject *jsretArr = JS_NewArrayObject(cx, 0, NULL);
int i = 0;
for(std::vector<std::string>::const_iterator iter = arr.begin(); iter != arr.end(); ++iter, ++i) {
jsval arrElement = c_string_to_jsval(cx, iter->c_str());
if(!JS_SetElement(cx, jsretArr, i, &arrElement)) {
break;
}
}
return OBJECT_TO_JSVAL(jsretArr);
}
JSBool js_cocos2dx_CCFileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCFileUtils* cobj = (cocos2d::CCFileUtils *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
std::vector<std::string> arg0;
ok &= jsval_to_string_vector(cx, argv[0], arg0);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->setSearchResolutionsOrder(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_CCFileUtils_setSearchPath(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCFileUtils* cobj = (cocos2d::CCFileUtils *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
std::vector<std::string> arg0;
ok &= jsval_to_string_vector(cx, argv[0], arg0);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->setSearchPath(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_cocos2dx_CCFileUtils_getSearchPath(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCFileUtils* cobj = (cocos2d::CCFileUtils *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
std::vector<std::string> ret = cobj->getSearchPath();
jsval jsret;
jsret = string_vector_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_cocos2dx_CCFileUtils_getSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCFileUtils* cobj = (cocos2d::CCFileUtils *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
std::vector<std::string> ret = cobj->getSearchResolutionsOrder();
jsval jsret;
jsret = string_vector_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)
{
// first, try to get the ns
@ -2557,6 +2674,12 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)
JS_DefineFunction(cx, js_cocos2dx_CCMenu_prototype, "alignItemsInRows", js_cocos2dx_CCMenu_alignItemsInRows, 1, JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCMenu_prototype, "alignItemsInColumns", js_cocos2dx_CCMenu_alignItemsInColumns, 1, JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_PERMANENT);
JS_DefineFunction(cx, js_cocos2dx_CCFileUtils_prototype, "setSearchResolutionsOrder", js_cocos2dx_CCFileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_SHARED);
JS_DefineFunction(cx, js_cocos2dx_CCFileUtils_prototype, "setSearchPath", js_cocos2dx_CCFileUtils_setSearchPath, 1, JSPROP_PERMANENT | JSPROP_SHARED);
JS_DefineFunction(cx, js_cocos2dx_CCFileUtils_prototype, "getSearchPath", js_cocos2dx_CCFileUtils_getSearchPath, 0, JSPROP_PERMANENT | JSPROP_SHARED);
JS_DefineFunction(cx, js_cocos2dx_CCFileUtils_prototype, "getSearchResolutionsOrder", js_cocos2dx_CCFileUtils_getSearchResolutionsOrder, 0, JSPROP_PERMANENT | JSPROP_SHARED);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return cc.BezierBy; })()"));
JS_DefineFunction(cx, tmpObj, "create", JSB_CCBezierBy_actionWithDuration, 2, JSPROP_READONLY | JSPROP_PERMANENT);

View File

@ -1 +1 @@
d1aa4e4054d8cc8ad0f63b2099fba0187800fbc0
0a9aee772453f2a08adc51ea81f4798de45a2bca

View File

@ -95,7 +95,8 @@ skip = CCNode::[.*Transform convertToWindowSpace getChildren ^setPosition$ getGr
CCTextureCache::[addPVRTCImage],
CCTimer::[getSelector],
CC.*Loader$::[*],
*::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*]
*::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*],
CCFileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPath$]
rename_functions = CCDirector::[sharedDirector=getInstance],
CCSpriteFrameCache::[sharedSpriteFrameCache=getInstance addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame isFlipX=isFlippedX isFlipY=isFlippedY],

View File

@ -98,7 +98,8 @@ skip = CCNode::[.*Transform convertToWindowSpace getChildren ^setPosition$ getGr
CCTextureCache::[addPVRTCImage],
CCTimer::[getSelector],
CC.*Loader$::[*],
*::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*]
*::[copyWith.* onEnter.* onExit.* description getObjectType .*RGB.* .*HSV.*],
CCFileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPath$]
rename_functions = CCDirector::[sharedDirector=getInstance],
CCSpriteFrameCache::[sharedSpriteFrameCache=getInstance addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame isFlipX=isFlippedX isFlipY=isFlippedY],

View File

@ -6,4 +6,5 @@ class CCFileUtils
void setResourceDirectory(const char *pszDirectoryName);
const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile);
const char* fullPathFromRelativePath(const char *pszRelativePath);
std::string fullPathForFilename(const char *pszFileName);
};