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


C++ PropertyDescriptor::Deserialize方法代码示例

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


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

示例1: Deserialize

void BaseEntity::Deserialize(SerializableNodeObject* parentNode, EngineContext* engineContext)
{
    if (!parentNode)
    {
        LOG("Cannot deserialize Entity: Node is null.");
        return;
    }

    // Position.
    /*SerializableProperty* positionProp = (SerializableProperty*)parentNode->FindNodeByName("position");
    if (positionProp)
    	this->SetPosition(positionProp->Value.toVec3f());

    // Pose.
    SerializableProperty* poseProp = (SerializableProperty*)parentNode->FindNodeByName("pose");
    if (poseProp)
    	this->SetPose(poseProp->Value.toMat4f());

    // Direction.
    SerializableProperty* directionProp = (SerializableProperty*)parentNode->FindNodeByName("direction");
    if (directionProp)
    	this->SetDirection(directionProp->Value.toVec3f());

    // Scale.
    SerializableProperty* scaleProp = (SerializableProperty*)parentNode->FindNodeByName("scale");
    if (scaleProp)
    	this->SetScale(scaleProp->Value.toVec3f());*/

    auto nbNodes = parentNode->GetChildNodesCount();
    auto nodes = parentNode->GetChildNodes();

    for (size_t i = 0; i < nbNodes; ++i)
    {
        auto node = nodes[i];

        if (node->GetType() == SerializableNodeType::ARRAY && node->Name.toLower() == "properties")
        {
            auto nbProperties = node->GetChildNodesCount();
            auto properties = node->GetChildNodes();

            for (size_t p = 0; p < nbProperties; ++p)
            {
                if (properties[p]->GetType() != SerializableNodeType::OBJECT)
                    continue;

                PropertyDescriptor pDesc;
                pDesc.Deserialize((SerializableNodeObject*)properties[p], engineContext);

                Property* prop = this->AddProperty(pDesc);

                // Look for the value node.
                SerializableProperty* valueNode = (SerializableProperty*)properties[p]->FindNodeByName("value");

                if (valueNode)
                    prop->Set(valueNode->Value);
            }
        }
        else if (node->GetType() == SerializableNodeType::ARRAY && node->Name.toLower() == "components")
        {
            auto nbComponents = node->GetChildNodesCount();
            auto components = node->GetChildNodes();

            for (size_t c = 0; c < nbComponents; ++c)
            {
                if (components[c]->GetType() != SerializableNodeType::OBJECT)
                    continue;

                SerializableNodeObject* nodeInfo = (SerializableNodeObject*)components[c];

                BaseComponent* component = BaseComponent::DeserializeComponent(nodeInfo, engineContext, this);

                if (!component)
                {
                    LOG("Unable to deserialize component. Skipping.");
                    continue;
                }

                this->AddComponent(component);

                //component->Deserialize(nodeInfo);
            }
        }
        else if (node->GetType() == SerializableNodeType::PROPERTY)
        {
            if (node->Name.toLower() == "class")
            {
                this->SetClass(node->Value.c_str());
            }
        }
    }
}
开发者ID:qpHalcy0n,项目名称:Quad2012,代码行数:91,代码来源:qentity.cpp


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