void UserConnection::Send(const kNet::DataSerializer &data)
{
    if (webSocketConnection.expired())
        return;
    if (data.BytesFilled() == 0)
        return;
    
    webSocketConnection.lock()->send(static_cast<void*>(data.GetData()), static_cast<uint64_t>(data.BytesFilled()));
}
Example #2
0
void Client::SendCameraOrientation(kNet::DataSerializer ds, kNet::NetworkMessage *msg)
{
    Ptr(kNet::MessageConnection) connection = GetConnection();

    if (ds.BytesFilled() > 0)
        connection->EndAndQueueMessage(msg, ds.BytesFilled());

    else
        connection->FreeMessage(msg);
}
Example #3
0
void EC_DynamicComponent::SerializeToBinary(kNet::DataSerializer& dest) const
{
    dest.Add<u8>(attributes_.size());
    // For now, transmit all values as strings
    AttributeVector::const_iterator iter = attributes_.begin();
    while(iter != attributes_.end())
    {
        dest.AddString((*iter)->GetNameString());
        dest.AddString((*iter)->TypeName());
        dest.AddString((*iter)->ToString());
        ++iter;
    }
}
Example #4
0
File: Entity.cpp Project: A-K/naali
 void Entity::SerializeToBinary(kNet::DataSerializer &dst) const
 {
     dst.Add<u32>(GetId());
     uint num_serializable = 0;
     foreach(const ComponentPtr &comp, Components())
         if (comp->IsSerializable() && !comp->IsTemporary())
             num_serializable++;
     dst.Add<u32>(num_serializable);
     foreach(const ComponentPtr &comp, Components())
         if (comp->IsSerializable() && !comp->IsTemporary())
         {
             dst.Add<u32>(comp->TypeNameHash());
             dst.AddString(comp->Name().toStdString());
             dst.Add<u8>(comp->GetNetworkSyncEnabled() ? 1 : 0);
             
             // Write each component to a separate buffer, then write out its size first, so we can skip unknown components
             QByteArray comp_bytes;
             // Assume 64KB max per component for now
             comp_bytes.resize(64 * 1024);
             kNet::DataSerializer comp_dest(comp_bytes.data(), comp_bytes.size());
             comp->SerializeToBinary(comp_dest);
             comp_bytes.resize(comp_dest.BytesFilled());
             
             dst.Add<u32>(comp_bytes.size());
             dst.AddArray<u8>((const u8*)comp_bytes.data(), comp_bytes.size());
         }
 }
Example #5
0
void Entity::SerializeToBinary(kNet::DataSerializer &dst) const
{
    dst.Add<u32>(Id());
    dst.Add<u8>(IsReplicated() ? 1 : 0);
    uint num_serializable = 0;
    for (ComponentMap::const_iterator i = components_.begin(); i != components_.end(); ++i)
        if (!i->second->IsTemporary())
            num_serializable++;
    dst.Add<u32>(num_serializable);
    for (ComponentMap::const_iterator i = components_.begin(); i != components_.end(); ++i)
        if (!i->second->IsTemporary())
        {
            dst.Add<u32>(i->second->TypeId()); ///\todo VLE this!
            dst.AddString(i->second->Name().toStdString());
            dst.Add<u8>(i->second->IsReplicated() ? 1 : 0);
            
            // Write each component to a separate buffer, then write out its size first, so we can skip unknown components
            QByteArray comp_bytes;
            // Assume 64KB max per component for now
            comp_bytes.resize(64 * 1024);
            kNet::DataSerializer comp_dest(comp_bytes.data(), comp_bytes.size());
            i->second->SerializeToBinary(comp_dest);
            comp_bytes.resize(comp_dest.BytesFilled());
            
            dst.Add<u32>(comp_bytes.size());
            dst.AddArray<u8>((const u8*)comp_bytes.data(), comp_bytes.size());
        }
}
Example #6
0
void Entity::SerializeToBinary(kNet::DataSerializer &dst, bool serializeTemporary, bool serializeLocal, bool serializeChildren) const
{
    dst.Add<u32>(Id());
    dst.Add<u8>(IsReplicated() ? 1 : 0);
    Vector<ComponentPtr> serializable;
    Vector<EntityPtr> serializableChildren;
    for (ComponentMap::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
        if (i->second_->ShouldBeSerialized(serializeTemporary, serializeLocal))
            serializable.Push(i->second_);

    if (serializeChildren)
    {
        foreach(const EntityWeakPtr &childWeak, children_)
        {
            const EntityPtr child = childWeak.Lock();
            if (child && child->ShouldBeSerialized(serializeTemporary, serializeLocal, serializeChildren))
                serializableChildren.Push(child);
        }
    }

    /// \hack Retain binary compatibility with earlier scene format, at the cost of max. 65535 components or child entities
    if (serializable.Size() > 0xffff)
        LogError("Entity::SerializeToBinary: entity contains more than 65535 components, binary save will be erroneous");
    if (serializableChildren.Size() > 0xffff)
        LogError("Entity::SerializeToBinary: entity contains more than 65535 child entities, binary save will be erroneous");

    dst.Add<u32>(serializable.Size() | (serializableChildren.Size() << 16));
    foreach(const ComponentPtr &comp, serializable)
    {
        dst.Add<u32>(comp->TypeId()); ///\todo VLE this!
        dst.AddString(comp->Name().CString());
        dst.Add<u8>(comp->IsReplicated() ? 1 : 0);

        // Write each component to a separate buffer, then write out its size first, so we can skip unknown components
        PODVector<unsigned char> comp_bytes;
        // Assume 64KB max per component for now
        comp_bytes.Resize(64 * 1024);
        kNet::DataSerializer comp_dest((char*)&comp_bytes[0], comp_bytes.Size());
        comp->SerializeToBinary(comp_dest);
        comp_bytes.Resize(static_cast<uint>(comp_dest.BytesFilled()));
        
        dst.Add<u32>(comp_bytes.Size());
        if (comp_bytes.Size())
            dst.AddArray<u8>((const u8*)&comp_bytes[0], comp_bytes.Size());
    }
Example #7
0
template<> void TUNDRACORE_API Attribute<QVariantList>::ToBinary(kNet::DataSerializer& dest) const
{
    dest.Add<u8>(value.size());
    for(uint i = 0; i < (uint)value.size(); ++i)
        dest.AddString(value[i].toString().toStdString());
}
Example #8
0
template<> void TUNDRACORE_API Attribute<QVariant>::ToBinary(kNet::DataSerializer& dest) const
{
    std::string str = value.toString().toStdString();
    dest.AddString(str);
}
Example #9
0
template<> void TUNDRACORE_API Attribute<EntityReference>::ToBinary(kNet::DataSerializer& dest) const
{
    dest.AddString(value.ref.toStdString());
}
Example #10
0
template<> void TUNDRACORE_API Attribute<AssetReferenceList>::ToBinary(kNet::DataSerializer& dest) const
{
    dest.Add<u8>(value.Size());
    for(int i = 0; i < value.Size(); ++i)
        dest.AddString(value[i].ref.toStdString());
}