Example #1
0
PODVector<unsigned char> CustomGeometry::GetGeometryDataAttr() const
{
    VectorBuffer ret;

    ret.WriteVLE(geometries_.Size());
    ret.WriteUInt(elementMask_);

    for (unsigned i = 0; i < geometries_.Size(); ++i)
    {
        unsigned numVertices = vertices_[i].Size();
        ret.WriteVLE(numVertices);
        ret.WriteUByte(primitiveTypes_[i]);

        for (unsigned j = 0; j < numVertices; ++j)
        {
             if (elementMask_ & MASK_POSITION)
                ret.WriteVector3(vertices_[i][j].position_);
             if (elementMask_ & MASK_NORMAL)
                ret.WriteVector3(vertices_[i][j].normal_);
             if (elementMask_ & MASK_COLOR)
                ret.WriteUInt(vertices_[i][j].color_);
             if (elementMask_ & MASK_TEXCOORD1)
                ret.WriteVector2(vertices_[i][j].texCoord_);
             if (elementMask_ & MASK_TANGENT)
                ret.WriteVector4(vertices_[i][j].tangent_);
        }
    }

    return ret.GetBuffer();
}
//
// write_node
//
void ClientSidePrediction::write_node(VectorBuffer& message, Node& node)
{
    // Write node ID
    message.WriteUInt(node.GetID());

    // Write attributes
    write_network_attributes(node, message);

    // Write user variables
    const auto& vars = node.GetVars();
    message.WriteVLE(vars.Size());
    for (auto i = vars.Begin(); i != vars.End(); ++i)
    {
        message.WriteStringHash(i->first_);
        message.WriteVariant(i->second_);
    }

    // Write number of components
    message.WriteVLE(node.GetNumComponents());

    // Write components
    const auto& components = node.GetComponents();
    for (unsigned i = 0; i < components.Size(); ++i)
    {
        auto component = components[i];
        write_component(message, *component);
    }
}
Example #3
0
PODVector<unsigned char> DecalSet::GetDecalsAttr() const
{
    VectorBuffer ret;

    ret.WriteBool(skinned_);
    ret.WriteVLE(decals_.Size());

    for (List<Decal>::ConstIterator i = decals_.Begin(); i != decals_.End(); ++i)
    {
        ret.WriteFloat(i->timer_);
        ret.WriteFloat(i->timeToLive_);
        ret.WriteVLE(i->vertices_.Size());
        ret.WriteVLE(i->indices_.Size());

        for (PODVector<DecalVertex>::ConstIterator j = i->vertices_.Begin(); j != i->vertices_.End(); ++j)
        {
            ret.WriteVector3(j->position_);
            ret.WriteVector3(j->normal_);
            ret.WriteVector2(j->texCoord_);
            ret.WriteVector4(j->tangent_);
            if (skinned_)
            {
                for (unsigned k = 0; k < 4; ++k)
                    ret.WriteFloat(j->blendWeights_[k]);
                for (unsigned k = 0; k < 4; ++k)
                    ret.WriteUByte(j->blendIndices_[k]);
            }
        }

        for (PODVector<unsigned short>::ConstIterator j = i->indices_.Begin(); j != i->indices_.End(); ++j)
            ret.WriteUShort(*j);
    }

    if (skinned_)
    {
        ret.WriteVLE(bones_.Size());

        for (Vector<Bone>::ConstIterator i = bones_.Begin(); i != bones_.End(); ++i)
        {
            ret.WriteString(i->name_);
            ret.WriteUByte(i->collisionMask_);
            if (i->collisionMask_ & BONECOLLISION_SPHERE)
                ret.WriteFloat(i->radius_);
            if (i->collisionMask_ & BONECOLLISION_BOX)
                ret.WriteBoundingBox(i->boundingBox_);
            ret.Write(i->offsetMatrix_.Data(), sizeof(Matrix3x4));
        }
    }

    return ret.GetBuffer();
}
Example #4
0
PODVector<unsigned char> ScriptInstance::GetDelayedMethodCallsAttr() const
{
    VectorBuffer buf;
    buf.WriteVLE(delayedMethodCalls_.Size());
    for (Vector<DelayedMethodCall>::ConstIterator i = delayedMethodCalls_.Begin(); i != delayedMethodCalls_.End(); ++i)
    {
        buf.WriteFloat(i->period_);
        buf.WriteFloat(i->delay_);
        buf.WriteBool(i->repeat_);
        buf.WriteString(i->declaration_);
        buf.WriteVariantVector(i->parameters_);
    }
    return buf.GetBuffer();
}
//
// write_scene_state
//
void ClientSidePrediction::write_scene_state(VectorBuffer& message, Scene* scene)
{
    // Write placeholder last input ID, which will be set per connection before sending
    message.WriteUInt(0);

    auto& nodes = scene_nodes[scene];

    // Write number of nodes
    message.WriteVLE(nodes.size());

    // Write nodes
    for (auto node : nodes)
        write_node(message, *node);
}