AnimationStateMachineBehaviour* AnimationStateMachine::addBehaviour( const char* from, const char* to, izanagi::CAnimationInterp::E_INTERP_TYPE interpType/*= izanagi::CAnimationInterp::E_INTERP_TYPE::E_INTERP_TYPE_SMOOTH*/) { IZ_ASSERT(from || to); AnimationStateMachineNode* fromNode = nullptr; AnimationStateMachineNode* toNode = nullptr; if (from) { IZ_ASSERT(strlen(from) > 0); if (m_entry.getName() != from) { fromNode = getNode(from); } } if (to) { IZ_ASSERT(strlen(to) > 0); if (m_exit.getName() != to) { toNode = getNode(to); } } auto ret = addBehaviour( fromNode, toNode, interpType); return ret; }
void ActionPattern::xmlInit(const QDomNode& _node, const ActionPatternMap& _apMap) { ArbiterRepository * ar = ArbiterRepository::instance(); BehaviourRepository * br = BehaviourRepository::instance(); // first pass // retrieve arbiter // we need it to register the behaviours there QDomNode n = _node.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); // try to convert the node to an element. if( !e.isNull() ) { // the node was really an element. QDomAttr attribute = e.attributeNode("name"); // retrieve arbiter if (e.tagName()=="arbiter") { if (arbiter_ == NULL) { if (!attribute.isNull() && !attribute.value().isEmpty()) { string name(attribute.value()); Arbiter* a; if ((a = ar->getArbiter(name)) != 0) { ArbiterParameters * params = a->getParametersInstance(); arbiter(a, params); } else { std::string error("Arbiter not registered: " + name); throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup(error.c_str())); } } else { throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup("Arbiter without name.")); } } else { throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup("Multiple arbiters specified.")); } } // syntax checking else if (e.tagName() != "behaviour" && e.tagName() != "transition") { std::string error("Unknown tag name: " + string(e.tagName())); throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup(error.c_str())); } } n = n.nextSibling(); } // There has to be exact one arbiter if (arbiter_ == NULL) { std::string error("ActionPattern without an arbiter: " + actionPatternName_); throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup(error.c_str())); } // second pass // retrieve behaviours and transitions n = _node.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); // try to convert the node to an element. if( !e.isNull() ) { // the node was really an element. QDomAttr attribute = e.attributeNode("name"); // retrieve behaviours if (e.tagName() == "behaviour") { if (!attribute.isNull() && !attribute.value().isEmpty()) { string name(attribute.value()); Behaviour * behaviour; BehaviourParameters * parameters; if ((behaviour = br->getBehaviour(name)) != 0) { parameters = behaviour->getParametersInstance(); KeyValueList params; params <<= n; *parameters <<= params; addBehaviour(behaviour, parameters); } else { std::string error("Behaviour not registered: " + name); throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup(error.c_str())); } } else { throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup("Behaviour without name.")); } } // retrieve transitions else if (e.tagName() == "transition") { QDomAttr attrMessage = e.attributeNode("message"); string message; if (!attrMessage.isNull() && !attrMessage.value().isEmpty()) { message = string(attrMessage.value()); } else { throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup("Transition without message.")); } QDomAttr attrPattern = e.attributeNode("target"); if (!attrPattern.isNull() && !attrPattern.value().isEmpty()) { string patternname = string(attrPattern.value()); ActionPatternMap::const_iterator iter = _apMap.find(patternname); if (iter != _apMap.end()) addTransition(message, iter->second); else { std::string error("ActionPattern for transition not registered: " + message + " --> " + patternname + "."); throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup(error.c_str())); } } else throw BehaviourEngine::EMalformedPolicy(CORBA::string_dup("Transition without target.")); } } n = n.nextSibling(); } }