当前位置: 首页>>代码示例>>C++>>正文


C++ StateMap::insert方法代码示例

本文整理汇总了C++中StateMap::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ StateMap::insert方法的具体用法?C++ StateMap::insert怎么用?C++ StateMap::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateMap的用法示例。


在下文中一共展示了StateMap::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processStateMachineNode

bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj, const QString& nodeId, const QUrl& jsonUrl) {
    auto smNode = std::static_pointer_cast<AnimStateMachine>(node);
    assert(smNode);

    READ_STRING(currentState, jsonObj, nodeId, jsonUrl, false);

    auto statesValue = jsonObj.value("states");
    if (!statesValue.isArray()) {
        qCCritical(animation) << "AnimNodeLoader, bad array \"states\" in stateMachine node, id =" << nodeId;
        return false;
    }

    // build a map for all children by name.
    std::map<QString, int> childMap;
    buildChildMap(childMap, node);

    // first pass parse all the states and build up the state and transition map.
    using StringPair = std::pair<QString, QString>;
    using TransitionMap = std::multimap<AnimStateMachine::State::Pointer, StringPair>;
    TransitionMap transitionMap;

    using StateMap = std::map<QString, AnimStateMachine::State::Pointer>;
    StateMap stateMap;

    auto statesArray = statesValue.toArray();
    for (const auto& stateValue : statesArray) {
        if (!stateValue.isObject()) {
            qCCritical(animation) << "AnimNodeLoader, bad state object in \"states\", id =" << nodeId;
            return false;
        }
        auto stateObj = stateValue.toObject();

        READ_STRING(id, stateObj, nodeId, jsonUrl, false);
        READ_FLOAT(interpTarget, stateObj, nodeId, jsonUrl, false);
        READ_FLOAT(interpDuration, stateObj, nodeId, jsonUrl, false);
        READ_OPTIONAL_STRING(interpType, stateObj);

        READ_OPTIONAL_STRING(interpTargetVar, stateObj);
        READ_OPTIONAL_STRING(interpDurationVar, stateObj);
        READ_OPTIONAL_STRING(interpTypeVar, stateObj);

        auto iter = childMap.find(id);
        if (iter == childMap.end()) {
            qCCritical(animation) << "AnimNodeLoader, could not find stateMachine child (state) with nodeId =" << nodeId << "stateId =" << id;
            return false;
        }

        AnimStateMachine::InterpType interpTypeEnum = AnimStateMachine::InterpType::SnapshotPrev;  // default value
        if (!interpType.isEmpty()) {
            interpTypeEnum = stringToInterpType(interpType);
            if (interpTypeEnum == AnimStateMachine::InterpType::NumTypes) {
                qCCritical(animation) << "AnimNodeLoader, bad interpType on stateMachine state, nodeId = " << nodeId << "stateId =" << id;
                return false;
            }
        }

        auto statePtr = std::make_shared<AnimStateMachine::State>(id, iter->second, interpTarget, interpDuration, interpTypeEnum);
        assert(statePtr);

        if (!interpTargetVar.isEmpty()) {
            statePtr->setInterpTargetVar(interpTargetVar);
        }
        if (!interpDurationVar.isEmpty()) {
            statePtr->setInterpDurationVar(interpDurationVar);
        }
        if (!interpTypeVar.isEmpty()) {
            statePtr->setInterpTypeVar(interpTypeVar);
        }

        smNode->addState(statePtr);
        stateMap.insert(StateMap::value_type(statePtr->getID(), statePtr));

        auto transitionsValue = stateObj.value("transitions");
        if (!transitionsValue.isArray()) {
            qCritical(animation) << "AnimNodeLoader, bad array \"transitions\" in stateMachine node, stateId =" << id << "nodeId =" << nodeId;
            return false;
        }

        auto transitionsArray = transitionsValue.toArray();
        for (const auto& transitionValue : transitionsArray) {
            if (!transitionValue.isObject()) {
                qCritical(animation) << "AnimNodeLoader, bad transition object in \"transtions\", stateId =" << id << "nodeId =" << nodeId;
                return false;
            }
            auto transitionObj = transitionValue.toObject();

            READ_STRING(var, transitionObj, nodeId, jsonUrl, false);
            READ_STRING(state, transitionObj, nodeId, jsonUrl, false);

            transitionMap.insert(TransitionMap::value_type(statePtr, StringPair(var, state)));
        }
    }

    // second pass: now iterate thru all transitions and add them to the appropriate states.
    for (auto& transition : transitionMap) {
        AnimStateMachine::State::Pointer srcState = transition.first;
        auto iter = stateMap.find(transition.second.second);
        if (iter != stateMap.end()) {
            srcState->addTransition(AnimStateMachine::State::Transition(transition.second.first, iter->second));
        } else {
//.........这里部分代码省略.........
开发者ID:Nex-Pro,项目名称:hifi,代码行数:101,代码来源:AnimNodeLoader.cpp

示例2: stateFactory

 /**
  * Creates a new state. Make sure the state doesn't exist when calling this
  * function!
  * This function also inserts the state into the _states map.
  * @param id The id of the new state.
  **/
 State *createState(StateId id) {
     State *state = stateFactory(id);
     state->load();
     _states.insert(StateMapPair(id, state));
     return state;
 }
开发者ID:RenatoUtsch,项目名称:boids,代码行数:12,代码来源:StateContainer.hpp


注:本文中的StateMap::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。