issue #1683: Making some api of CCFileUtils more c++ friendly by using std::vector rather than CCArray.

This commit is contained in:
James Chen 2013-01-26 22:31:57 +08:00
parent ca9e96213f
commit 119115502d
12 changed files with 277 additions and 189 deletions

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();
void setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder);
const std::vector<std::string>& 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
/**
* 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(CCArray* pSearchPaths);
CCArray* getSearchPath();
void setSearchPath(const std::vector<std::string>& searchPaths);
const std::vector<std::string>& getSearchPath();
/**
@brief Get the resource directory
*/
const char* getResourceDirectory();
* 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);
@ -108,20 +102,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))
@ -253,7 +242,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

@ -50,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);
@ -59,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;
}
@ -133,16 +128,12 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string fullpath;
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;
fullpath = this->getPathForFilename(newFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter);
// check if file or path exist
if (access(fullpath.c_str(), F_OK) != -1)

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()
@ -298,18 +289,13 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
// in Lookup Filename dictionary ?
std::string newfilename = this->getNewFilename(pszFileName);
CCObject* pSearchObj = NULL;
CCARRAY_FOREACH(m_pSearchPathArray, pSearchObj)
{
CCString* pSearchPath = (CCString*)pSearchObj;
CCObject* pResourceDirObj = NULL;
CCARRAY_FOREACH(m_pSearchResolutionsOrderArray, pResourceDirObj)
{
CCString* pResourceDirectory = (CCString*)pResourceDirObj;
fullpath = this->getPathForFilename(newfilename, pResourceDirectory->getCString(), pSearchPath->getCString());
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)
{

View File

@ -35,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;
}
@ -50,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);
@ -121,17 +116,12 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string fullpath;
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
struct stat sts;

View File

@ -52,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;
}
@ -67,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);
@ -137,17 +132,12 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
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());
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 (s3eFileCheckExists(fullpath.c_str()) == S3E_TRUE)

View File

@ -66,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);
@ -80,11 +78,8 @@ 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;
}
@ -167,16 +162,12 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
std::string newFileName = getNewFilename(pszFileName);
std::string fullpath;
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;
fullpath = this->getPathForFilename(newFileName, pResourceDirectory->getCString(), pSearchPath->getCString());
fullpath = this->getPathForFilename(newFileName, *resOrderIter, *searchPathsIter);
if (GetFileAttributesA(fullpath.c_str()) != -1)
{

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);

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

@ -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],