Example #1
0
 Node* Particle3DReader::createNodeWithFlatBuffers(const flatbuffers::Table *particle3DOptions)
 {
     auto options = (Particle3DOptions*)particle3DOptions;
     
     auto fileData = options->fileData();
     std::string path = fileData->path()->c_str();
     
     PUParticleSystem3D* ret = PUParticleSystem3D::create();
     if (FileUtils::getInstance()->isFileExist(path))
     {
         ret->initWithFilePath(path);
     }
     
     setPropsWithFlatBuffers(ret, particle3DOptions);
     
     if(ret)
     {
         ret->startParticleSystem();
     }
     
     return ret;
 }
void PUParticleSystem3D::startParticleSystem()
{
    stopParticleSystem();

    if (_state != State::RUNNING)
    {
        forceStopParticleSystem();
        if (_render)
            _render->notifyStart();

        for (auto &it : _observers){
            it->notifyStart();
        }

        for (auto& it : _emitters) {
            auto emitter = static_cast<PUEmitter*>(it);
            emitter->notifyStart();
        }

        for (auto& it : _affectors) {
            auto affector = static_cast<PUAffector*>(it);
            affector->notifyStart();
        }

        scheduleUpdate();
        _state = State::RUNNING;
        _latestPosition = getDerivedPosition(); // V1.3.1
    }

    for (auto iter : _children)
    {
        PUParticleSystem3D *system = dynamic_cast<PUParticleSystem3D *>(iter);
        if (system){
            system->_parentParticleSystem = this;
            system->startParticleSystem();
        }
    }
}