support read material files on linux

modify the name of getAliveParticleCnt function
This commit is contained in:
songchengjiang 2015-03-02 16:28:38 +08:00
parent 79d892bffc
commit a9eb4dc7f9
20 changed files with 76 additions and 50 deletions

View File

@ -181,7 +181,7 @@ void ParticleSystem3D::update(float delta)
void ParticleSystem3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
if (getAliveParticleCnt() && _render)
if (getAliveParticleCount() && _render)
{
_render->render(renderer, transform, this);
}

View File

@ -223,9 +223,9 @@ public:
return _particlePool;
}
virtual int getAliveParticleCnt() const
virtual int getAliveParticleCount() const
{
return _aliveParticlesCnt;
return 0;
}
State getState() const { return _state; }

View File

@ -31,17 +31,15 @@
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include <io.h>
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID/* || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX*/)
//#include <sys/io.h>
//#include <sys/dir.h>
//#include <sys/types.h>
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "android/CCFileUtils-android.h"
#include <android/asset_manager.h>
//#include <sys/stat.h>
//#include <dirent.h>
//#include <unistd.h>
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
#include <ftw.h>
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#endif
NS_CC_BEGIN
@ -217,6 +215,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())))
{
CCLOG("error opendir %s!!!\n",fileFolder.c_str());
return false;
}
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 + "/" + 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);
state = true;
}
}
closedir(d);
#endif
return state;

View File

@ -115,7 +115,7 @@ void PUParticle3DMaterialTranslator::translate(PUScriptCompiler* compiler, PUAbs
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
//PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
_material = new PUParticle3DMaterial();
_material = new (std::nothrow) PUParticle3DMaterial();
_material->fileName = obj->file;
_material->name = obj->name;
_material->autorelease();

View File

@ -409,7 +409,7 @@ void PUParticleSystem3D::update(float delta)
if (_state != State::RUNNING){
if (_state == State::PAUSE)
return;
else if (_state == State::STOP && getAliveParticleCnt() <= 0){
else if (_state == State::STOP && getAliveParticleCount() <= 0){
if (!_emitters.empty()){
if (_render)
_render->notifyStop();
@ -1156,7 +1156,7 @@ void PUParticleSystem3D::removeAllListener()
void PUParticleSystem3D::draw( Renderer *renderer, const Mat4 &transform, uint32_t flags )
{
if (getAliveParticleCnt() <= 0) return;
if (getAliveParticleCount() <= 0) return;
if (_render)
_render->render(renderer, transform, this);
@ -1360,7 +1360,7 @@ void PUParticleSystem3D::calulateRotationOffset( void )
_rotationOffset = getDerivedOrientation() * latestOrientationInverse;
}
int PUParticleSystem3D::getAliveParticleCnt() const
int PUParticleSystem3D::getAliveParticleCount() const
{
int sz = 0;
sz += _particlePool.getActiveDataList().size();
@ -1380,7 +1380,7 @@ int PUParticleSystem3D::getAliveParticleCnt() const
PUParticle3D *particle = static_cast<PUParticle3D *>(pool.getFirst());
while (particle)
{
sz += static_cast<PUParticleSystem3D*>(particle->particleEntityPtr)->getAliveParticleCnt();
sz += static_cast<PUParticleSystem3D*>(particle->particleEntityPtr)->getAliveParticleCount();
particle = static_cast<PUParticle3D *>(pool.getNext());
}
}

View File

@ -254,7 +254,7 @@ public:
*/
virtual void resumeParticleSystem() override;
virtual int getAliveParticleCnt() const override;
virtual int getAliveParticleCount() const override;
/** Returns the velocity scale, defined in the particle system, but passed to the technique for convenience.
*/

View File

@ -74,7 +74,7 @@ bool PUParticle3DGeometryRotatorTranslator::translateChildProperty( PUScriptComp
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotationSpeed(dynamicAttributeFixed);
return true;
@ -89,7 +89,7 @@ bool PUParticle3DGeometryRotatorTranslator::translateChildProperty( PUScriptComp
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotationSpeed(dynamicAttributeFixed);
return true;

View File

@ -48,7 +48,7 @@ bool PUParticle3DJetAffectorTranslator::translateChildProperty( PUScriptCompiler
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynAcceleration(dynamicAttributeFixed);
return true;
@ -63,7 +63,7 @@ bool PUParticle3DJetAffectorTranslator::translateChildProperty( PUScriptCompiler
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynAcceleration(dynamicAttributeFixed);
return true;

View File

@ -103,7 +103,7 @@ void PUParticle3DLineAffector::notifyRescaled(const Vec3& scale)
//-----------------------------------------------------------------------
void PUParticle3DLineAffector::preUpdateAffector(float deltaTime)
{
if (/*technique->getNumberOfEmittedParticles()*/static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCnt() > 0)
if (/*technique->getNumberOfEmittedParticles()*/static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCount() > 0)
{
_timeSinceLastUpdate += deltaTime;
while (_timeSinceLastUpdate > _timeStep)

View File

@ -103,7 +103,7 @@ void PUParticle3DRandomiser::setRandomDirection(bool randomDirection)
//-----------------------------------------------------------------------
void PUParticle3DRandomiser::preUpdateAffector(float deltaTime)
{
if (/*technique->getNumberOfEmittedParticles()*/static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCnt() > 0)
if (/*technique->getNumberOfEmittedParticles()*/static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCount() > 0)
{
_timeSinceLastUpdate += deltaTime;
if (_timeSinceLastUpdate > _timeStep)

View File

@ -48,7 +48,7 @@ bool PUParticle3DScaleAffectorTranslator::translateChildProperty( PUScriptCompil
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynScaleXYZ(dynamicAttributeFixed);
return true;
@ -63,7 +63,7 @@ bool PUParticle3DScaleAffectorTranslator::translateChildProperty( PUScriptCompil
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynScaleX(dynamicAttributeFixed);
return true;
@ -78,7 +78,7 @@ bool PUParticle3DScaleAffectorTranslator::translateChildProperty( PUScriptCompil
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynScaleY(dynamicAttributeFixed);
return true;
@ -93,7 +93,7 @@ bool PUParticle3DScaleAffectorTranslator::translateChildProperty( PUScriptCompil
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynScaleZ(dynamicAttributeFixed);
return true;

View File

@ -47,7 +47,7 @@ bool PUParticle3DScaleVelocityAffectorTranslator::translateChildProperty( PUScri
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setDynScaleVelocity(dynamicAttributeFixed);
return true;

View File

@ -74,7 +74,7 @@ bool PUParticle3DTextureRotatorTranslator::translateChildProperty( PUScriptCompi
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotationSpeed(dynamicAttributeFixed);
return true;
@ -89,7 +89,7 @@ bool PUParticle3DTextureRotatorTranslator::translateChildProperty( PUScriptCompi
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotationSpeed(dynamicAttributeFixed);
return true;
@ -104,7 +104,7 @@ bool PUParticle3DTextureRotatorTranslator::translateChildProperty( PUScriptCompi
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotation(dynamicAttributeFixed);
return true;
@ -119,7 +119,7 @@ bool PUParticle3DTextureRotatorTranslator::translateChildProperty( PUScriptCompi
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotation(dynamicAttributeFixed);
return true;

View File

@ -74,7 +74,7 @@ bool PUParticle3DVortexAffectorTranslator::translateChildProperty( PUScriptCompi
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotationSpeed(dynamicAttributeFixed);
return true;
@ -89,7 +89,7 @@ bool PUParticle3DVortexAffectorTranslator::translateChildProperty( PUScriptCompi
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
affector->setRotationSpeed(dynamicAttributeFixed);
return true;

View File

@ -201,7 +201,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynEmissionRate(dynamicAttributeFixed);
}
@ -216,7 +216,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynTotalTimeToLive(dynamicAttributeFixed);
}
@ -231,7 +231,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleMass(dynamicAttributeFixed);
}
@ -342,7 +342,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynVelocity(dynamicAttributeFixed);
}
@ -357,7 +357,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynDuration(dynamicAttributeFixed);
}
@ -372,7 +372,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynRepeatDelay(dynamicAttributeFixed);
}
@ -425,7 +425,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynAngle(dynamicAttributeFixed);
}
@ -440,7 +440,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleAllDimensions(dynamicAttributeFixed);
}
@ -455,7 +455,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleWidth(dynamicAttributeFixed);
}
@ -470,7 +470,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleHeight(dynamicAttributeFixed);
}
@ -485,7 +485,7 @@ void PUParticle3DEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbst
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleDepth(dynamicAttributeFixed);
}

View File

@ -56,7 +56,7 @@ void PUParticle3DOnClearObserver::postUpdateObserver(float timeElapsed)
{
if (_continue)
{
if (static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCnt() <= 0)
if (static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCount() <= 0)
{
/** Handle the event. Use 0 as the particle pointer. This means that not all eventhandlers
are suitable. If they expect a particle (and most eventhandlers do), it could

View File

@ -63,7 +63,7 @@ void PUParticle3DOnQuotaObserver::postUpdateObserver(float deltaTime)
}
//_result = particleTechnique->getNumberOfEmittedParticles(_particleTypeToObserve) >= quota;
_result = static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCnt() >= quota;
_result = static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCount() >= quota;
}
else
{
@ -77,7 +77,7 @@ void PUParticle3DOnQuotaObserver::postUpdateObserver(float deltaTime)
+ static_cast<PUParticleSystem3D *>(_particleSystem)->getEmittedEmitterQuota()
+ static_cast<PUParticleSystem3D *>(_particleSystem)->getEmittedSystemQuota();
//_result = particleTechnique->getNumberOfEmittedParticles() >= quota;
_result = static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCnt() >= quota;
_result = static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCount() >= quota;
}
}

View File

@ -52,7 +52,7 @@ void PUParticle3DOnTimeObserver::preUpdateObserver(float deltaTime)
// Also observe if there are no particles emitted, because some of the event handlers do not only
// perform an action on a particle.
if (static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCnt() <= 0)
if (static_cast<PUParticleSystem3D *>(_particleSystem)->getAliveParticleCount() <= 0)
{
handleObserve(0, deltaTime);
}

View File

@ -470,7 +470,9 @@ PUParticle3DModelRender::PUParticle3DModelRender()
PUParticle3DModelRender::~PUParticle3DModelRender()
{
for (auto iter : _spriteList){
iter->release();
}
}
void PUParticle3DModelRender::copyAttributesTo( PUParticle3DRender *render )

View File

@ -198,7 +198,7 @@ void Particle3DTestDemo::update( float delta )
for (auto iter : children){
ParticleSystem3D *child = dynamic_cast<ParticleSystem3D *>(iter);
if (child){
count += child->getAliveParticleCnt();
count += child->getAliveParticleCount();
}
}