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


C++ MemoryBuffer::ReadStringHash方法代码示例

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


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

示例1: read_component

//
// read_component
//
void ClientSidePrediction::read_component(MemoryBuffer& message, Node* node)
{
    auto network = GetSubsystem<Network>();
    auto scene = network->GetServerConnection()->GetScene();

    // Read component ID
    auto componentID = message.ReadUInt();
    // Read component type
    auto type = message.ReadStringHash();

    // Check if the component by this ID and type already exists in this node
    auto component = scene->GetComponent(componentID);
    if (!component || component->GetType() != type || component->GetNode() != node)
    {
        if (component)
            component->Remove();
        component = node->CreateComponent(type, LOCAL, componentID);
    }

    // If was unable to create the component, would desync the message and therefore have to abort
    if (!component)
    {
        LOGERROR("CreateNode message parsing aborted due to unknown component");
        return;
    }

    // Read attributes and apply
    read_network_attributes(*component, message);
    component->ApplyAttributes();
}
开发者ID:rasteron,项目名称:Urho3D-CSP,代码行数:33,代码来源:ClientSidePrediction.cpp

示例2: read_node

//
// read_node
//
void ClientSidePrediction::read_node(MemoryBuffer& message)
{
    auto network = GetSubsystem<Network>();
    auto scene = network->GetServerConnection()->GetScene();

    auto node_id = message.ReadUInt();
    auto node = scene->GetNode(node_id);
    bool new_node = false;

    // Create the node if it doesn't exist
    if (!node)
    {
        new_node = true;
        // Add initially to the root level. May be moved as we receive the parent attribute
        node = scene->CreateChild(node_id, LOCAL);
        // Create smoothed transform component
        node->CreateComponent<SmoothedTransform>(LOCAL);
    }
    else
    {
        // Remove the node from the unused nodes list
        unused_nodes.erase(node);
    }

    // Read attributes
    read_network_attributes(*node, message);
    // ApplyAttributes() is deliberately skipped, as Node has no attributes that require late applying.
    // Furthermore it would propagate to components and child nodes, which is not desired in this case

    if (new_node)
    {
        // Snap the motion smoothing immediately to the end
        auto transform = node->GetComponent<SmoothedTransform>();
        if (transform)
            transform->Update(1.0f, 0.0f);
    }

    // Read user variables
    unsigned num_vars = message.ReadVLE();
    for (; num_vars > 0; --num_vars)
    {
        auto key = message.ReadStringHash();
        node->SetVar(key, message.ReadVariant());
    }

    // Read components
    unsigned num_components = message.ReadVLE();
    for (; num_components > 0; --num_components)
        read_component(message, node);
}
开发者ID:rasteron,项目名称:Urho3D-CSP,代码行数:53,代码来源:ClientSidePrediction.cpp


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