From 5c8fbcedabdeca1751280863c9069f91e293eb54 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 16 Feb 2015 10:03:58 +0800 Subject: [PATCH 1/4] load all materials linux routine --- .../CCPUParticle3DMaterialManager.cpp | 88 +++++++------------ 1 file changed, 30 insertions(+), 58 deletions(-) diff --git a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp index 1adc555053..b5374d8167 100644 --- a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp +++ b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp @@ -30,17 +30,14 @@ #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #include -#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID/* || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX*/) -//#include -//#include -//#include +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "android/CCFileUtils-android.h" #include -//#include -//#include -//#include #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) #include +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) +#include +#include #endif NS_CC_BEGIN @@ -147,57 +144,6 @@ bool PUParticle3DMaterialCache::loadMaterialsFromSearchPaths( const std::string _findclose(handle); // } #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID/* || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX*/) - //TODO: - //for (auto iter : FileUtils::getInstance()->getSearchPaths()){ - //std::string fullPath = fileFolder + std::string("*.material"); - //struct ffblk data; - //int done = findfirst(fullPath.c_str(), &data, 512); - //while (!done) - //{ - // loadMaterials(fileFolder + std::string(data.name)); - // done = findnext(&data); - // state = true; - //} - //} - - //struct dirent* ent = NULL; - //DIR* pDir; - //pDir = opendir(fileFolder.c_str()); - //while(NULL != (ent = readdir(pDir))) - //{ - // //std::string fullpath = fileFolder + "/" + ent->d_name; - // //CCLOG("%s", fullpath.c_str()); - // //if(8 == ent->d_type) //在nfs或xfs下,有的文件d_type也是0 - // //if(IsFile(fullpath)) - // //{ - // // if(strstr(ent->d_name, "material")!=NULL) - // // { - // // loadMaterials(fullpath); - // // //files.push_back(ent->d_name); - // // } - // //} - //} - //closedir(pDir); - - //DIR *dp; - //struct dirent *entry; - //struct stat statbuf; - //int count = 0; - - //dp=opendir(fileFolder.c_str()); - //chdir(fileFolder.c_str()); - //while((entry = readdir(dp)) != nullptr && count < 255) - //{ - // //++count; - // //stat(entry->d_name,&statbuf); - // //if(!S_ISREG(statbuf.st_mode)) - // // continue; - - // //std::string fullpath = fileFolder + std::string(entry->d_name); - // //loadMaterials(fullpath); - // //CCLOG("%s",entry->d_name); - //} - //closedir(dp); std::string::size_type pos = fileFolder.find("assets/"); std::string relativePath = fileFolder; if (pos != std::string::npos) { @@ -216,6 +162,32 @@ bool PUParticle3DMaterialCache::loadMaterialsFromSearchPaths( const std::string #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) ftw(fileFolder.c_str(), iterPath, 500); +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) + DIR *d; //dir handle + struct dirent *file; //readdir + struct stat statbuf; + + if(!(d = opendir(fileFolder.c_str()))) + { + printf("error opendir %s!!!\n",path); + return -1; + } + while((file = readdir(d)) != NULL) + { + if(strncmp(file->d_name, ".", 1) == 0 || (stat(file->d_name, &statbuf) >= 0 && S_ISDIR(statbuf.st_mode))) + { + continue; + } + + std::string fullpath = fileFolder + "/" + ent->d_name; + if (strlen(ent->d_name) > 9 && strcmp(".material", ent->d_name + strlen(ent->d_name) - 9)) + { + CCLOG("%s", fullpath.c_str()); + loadMaterials(fullpath); + state = true; + } + } + closedir(d); #endif return state; From 6c73e22a32fbdee59be0f2545843995d7c0c7352 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 16 Feb 2015 11:18:54 +0800 Subject: [PATCH 2/4] variable name error --- .../ParticleUniverse/CCPUParticle3DMaterialManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp index b5374d8167..11a0777e30 100644 --- a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp +++ b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp @@ -179,8 +179,8 @@ bool PUParticle3DMaterialCache::loadMaterialsFromSearchPaths( const std::string continue; } - std::string fullpath = fileFolder + "/" + ent->d_name; - if (strlen(ent->d_name) > 9 && strcmp(".material", ent->d_name + strlen(ent->d_name) - 9)) + std::string fullpath = fileFolder + "/" + file->d_name; + if (strlen(file->d_name) > 9 && strcmp(".material", file->d_name + strlen(file->d_name) - 9)) { CCLOG("%s", fullpath.c_str()); loadMaterials(fullpath); From bdd7da89a12be9a5b3b6976ac422b008927e683f Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 16 Feb 2015 11:26:06 +0800 Subject: [PATCH 3/4] add header --- .../ParticleUniverse/CCPUParticle3DMaterialManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp index 11a0777e30..2bd7b6a672 100644 --- a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp +++ b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp @@ -37,6 +37,7 @@ #include #elif (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) #include +#include #include #endif NS_CC_BEGIN From a50efe998f7c8d3ee633944ac13508fce002b892 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 16 Feb 2015 11:57:07 +0800 Subject: [PATCH 4/4] fix compile --- .../ParticleUniverse/CCPUParticle3DMaterialManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp index 2bd7b6a672..3a26d64597 100644 --- a/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp +++ b/extensions/Particle3D/ParticleUniverse/CCPUParticle3DMaterialManager.cpp @@ -170,8 +170,8 @@ bool PUParticle3DMaterialCache::loadMaterialsFromSearchPaths( const std::string if(!(d = opendir(fileFolder.c_str()))) { - printf("error opendir %s!!!\n",path); - return -1; + CCLOG("error opendir %s!!!\n",fileFolder.c_str()); + return false; } while((file = readdir(d)) != NULL) {