void PUScriptTranslator::processNode( PUScriptCompiler *compiler, PUAbstractNode *node ) { if(node->type != ANT_OBJECT) return; // Abstract objects are completely skipped if((reinterpret_cast<PUObjectAbstractNode*>(node))->abstract) return; // Retrieve the translator to use PUScriptTranslator *translator = PUParticle3DTranslateManager::Instance()->getTranslator(node); if(translator) translator->translate(compiler, node); }
//------------------------------------------------------------------------- void PUAffectorTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node) { PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node); PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0; // The name of the obj is the type of the affector // Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later std::string type; if(!obj->name.empty()) { type = obj->name; } //// Get the factory //ParticleAffectorFactory* particleAffectorFactory = ParticleSystemManager::getSingletonPtr()->getAffectorFactory(type); //if (!particleAffectorFactory) //{ // compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); // return; //} PUScriptTranslator *particleAffectorTranlator = PUAffectorManager::Instance()->getTranslator(type); if (!particleAffectorTranlator) return; //// Create the affector //mAffector = ParticleSystemManager::getSingletonPtr()->createAffector(type); //if (!mAffector) //{ // compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); // return; //} _affector = PUAffectorManager::Instance()->createAffector(type); if (!_affector) return; _affector->setAffectorType(type); if (parent && parent->context) { PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context); system->addAffector(_affector); } // The first value is the (optional) name std::string name; if(!obj->values.empty()) { getString(*obj->values.front(), &name); _affector->setName(name); } // Set it in the context obj->context = _affector; // Run through properties for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i) { if((*i)->type == ANT_PROPERTY) { PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i)); if (prop->name == token[TOKEN_ENABLED]) { // Property: enabled if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL)) { bool val; if(getBoolean(*prop->values.front(), &val)) { _affector->setEnabled(val); } } } else if (prop->name == token[TOKEN_POSITION]) { // Property: position if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3)) { Vec3 val; if(getVector3(prop->values.begin(), prop->values.end(), &val)) { //mAffector->position = val; //mAffector->originalPosition = val; _affector->setLocalPosition(val); } } } else if (prop->name == token[TOKEN_AFFECTOR_MASS]) { if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_MASS], VAL_REAL)) { float val = 0.0f; if(getFloat(*prop->values.front(), &val)) { _affector->setMass(val); } } } else if (prop->name == token[TOKEN_AFFECTOR_SPECIALISATION]) { if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_SPECIALISATION], VAL_STRING)) { std::string val; if(getString(*prop->values.front(), &val)) { if (val == token[TOKEN_AFFECTOR_SPEC_DEFAULT]) { _affector->setAffectSpecialisation(PUAffector::AFSP_DEFAULT); } else if (val == token[TOKEN_AFFECTOR_SPEC_TTL_INCREASE]) { _affector->setAffectSpecialisation(PUAffector::AFSP_TTL_INCREASE); } else if (val == token[TOKEN_AFFECTOR_SPEC_TTL_DECREASE]) { _affector->setAffectSpecialisation(PUAffector::AFSP_TTL_DECREASE); } } } } else if (prop->name == token[TOKEN_AFFECTOR_EXCLUDE_EMITTER]) { if (passValidatePropertyNoValues(compiler, prop, token[TOKEN_AFFECTOR_EXCLUDE_EMITTER])) { for(PUAbstractNodeList::iterator j = prop->values.begin(); j != prop->values.end(); ++j) { std::string val; if(getString(**j, &val)) { _affector->addEmitterToExclude(val); } } } } else if (particleAffectorTranlator->translateChildProperty(compiler, *i)) { // Parsed the property by another translator; do nothing } else { errorUnexpectedProperty(compiler, prop); } } else if((*i)->type == ANT_OBJECT) { if (particleAffectorTranlator->translateChildObject(compiler, *i)) { // Parsed the object by another translator; do nothing } else { processNode(compiler, *i); } } else { errorUnexpectedToken(compiler, *i); } } }
//------------------------------------------------------------------------- void PUBehaviourTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node) { PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node); PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0; // The name of the obj is the type of the Behaviour std::string type; if(!obj->name.empty()) { type = obj->name; } else { //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); return; } //// Get the factory //ParticleBehaviourFactory* behaviourFactory = ParticleSystemManager::getSingletonPtr()->getBehaviourFactory(type); //if (!behaviourFactory) //{ // //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); // return; //} PUScriptTranslator *particleBehaviourTranlator = PUBehaviourManager::Instance()->getTranslator(type); if (!particleBehaviourTranlator) return; // Create the Behaviour _behaviour = PUBehaviourManager::Instance()->createBehaviour(type); if (!_behaviour) { //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); return; } _behaviour->setBehaviourType(type); if (parent && parent->context) { PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context); system->addBehaviourTemplate(_behaviour); } else { //// It is an alias //_behaviour->setAliasName(parent->name); //ParticleSystemManager::getSingletonPtr()->addAlias(mBehaviour); } // Set it in the context obj->context = _behaviour; // Run through properties for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i) { // No properties of its own if((*i)->type == ANT_PROPERTY) { PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i)); if (particleBehaviourTranlator->translateChildProperty(compiler, *i)) { // Parsed the property by another translator; do nothing } else { errorUnexpectedProperty(compiler, prop); } } else if((*i)->type == ANT_OBJECT) { if (particleBehaviourTranlator->translateChildObject(compiler, *i)) { // Parsed the object by another translator; do nothing } else { processNode(compiler, *i); } } else { errorUnexpectedToken(compiler, *i); } } }
//------------------------------------------------------------------------- void PUObserverTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node) { PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node); PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0; // The name of the obj is the type of the Observer // Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later std::string type; if(!obj->name.empty()) { type = obj->name; } else { //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); return; } // Get the factory //ParticleObserverFactory* particleObserverFactory = ParticleSystemManager::getSingletonPtr()->getObserverFactory(type); //if (!particleObserverFactory) //{ // //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); // return; //} PUScriptTranslator *particleObserverTranlator = PUObserverManager::Instance()->getTranslator(type); if (!particleObserverTranlator) return; // Create the Observer _observer = PUObserverManager::Instance()->createObserver(type); if (!_observer) { //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line); return; } _observer->setObserverType(type); if (parent && parent->context) { PUParticleSystem3D* system = static_cast<PUParticleSystem3D *>(parent->context); system->addObserver(_observer); } else { //// It is an alias //mObserver->setAliasName(parent->name); //ParticleSystemManager::getSingletonPtr()->addAlias(mObserver); } // The first value is the (optional) name std::string name; if(!obj->values.empty()) { getString(*obj->values.front(), &name); _observer->setName(name); } // Set it in the context obj->context = _observer; // Run through properties for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i) { if((*i)->type == ANT_PROPERTY) { PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i)); if (prop->name == token[TOKEN_ENABLED]) { // Property: enabled if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL)) { bool val; if(getBoolean(*prop->values.front(), &val)) { _observer->setEnabled(val); } } } else if (prop->name == token[TOKEN_OBSERVE_PARTICLE_TYPE]) { // Property: observe_particle_type if (passValidateProperty(compiler, prop, token[TOKEN_OBSERVE_PARTICLE_TYPE], VAL_STRING)) { std::string val; if(getString(*prop->values.front(), &val)) { if (val == token[TOKEN_VISUAL_PARTICLE]) { _observer->setParticleTypeToObserve(PUParticle3D::PT_VISUAL); } else if (val == token[TOKEN_EMITTER_PARTICLE]) { _observer->setParticleTypeToObserve(PUParticle3D::PT_EMITTER); } else if (val == token[TOKEN_AFFECTOR_PARTICLE]) { _observer->setParticleTypeToObserve(PUParticle3D::PT_AFFECTOR); } else if (val == token[TOKEN_TECHNIQUE_PARTICLE]) { _observer->setParticleTypeToObserve(PUParticle3D::PT_TECHNIQUE); } else if (val == token[TOKEN_SYSTEM_PARTICLE]) { _observer->setParticleTypeToObserve(PUParticle3D::PT_SYSTEM); } } } } else if (prop->name == token[TOKEN_OBSERVE_INTERVAL]) { // Property: observe_interval if (passValidateProperty(compiler, prop, token[TOKEN_OBSERVE_INTERVAL], VAL_REAL)) { float val; if(getFloat(*prop->values.front(), &val)) { _observer->setObserverInterval(val); } } } else if (prop->name == token[TOKEN_OBSERVE_UNTIL_EVENT]) { // Property: observe_until_event if (passValidateProperty(compiler, prop, token[TOKEN_OBSERVE_UNTIL_EVENT], VAL_BOOL)) { bool val; if(getBoolean(*prop->values.front(), &val)) { _observer->setObserveUntilEvent(val); } } } else if (particleObserverTranlator->translateChildProperty(compiler, *i)) { // Parsed the property by another translator; do nothing } else { errorUnexpectedProperty(compiler, prop); } } else if((*i)->type == ANT_OBJECT) { if (particleObserverTranlator->translateChildObject(compiler, *i)) { // Parsed the object by another translator; do nothing } else { processNode(compiler, *i); } } else { errorUnexpectedToken(compiler, *i); } } }