Ejemplo n.º 1
0
        public IWritablePacket Packetize(IWritablePacket packet)
        {
            // Serialize all pending commands for the next frame.
            packet.WriteWithTypeInfo((ICollection <Command>)Commands);

            return(packet);
        }
Ejemplo n.º 2
0
        public IWritablePacket Packetize(IWritablePacket packet)
        {
            // Write the trailing simulation. We can reconstruct the newer ones
            // from there.
            packet.Write(_simulations[_simulations.Length - 1]);

            // Write pending object removals.
            packet.Write(_removes.Count);
            foreach (var frame in _removes)
            {
                packet.Write(frame.Key);
                packet.Write(frame.Value.Count);
                foreach (var entity in frame.Value)
                {
                    packet.Write(entity);
                }
            }

            // Write pending simulation commands.
            packet.Write(_commands.Count);
            foreach (var frame in _commands)
            {
                packet.Write(frame.Key);
                packet.WriteWithTypeInfo((ICollection <Command>)frame.Value);
            }

            return(packet);
        }
Ejemplo n.º 3
0
        public static IWritablePacket WriteWithTypeInfo <T>(this IWritablePacket packet, ICollection <T> data)
            where T : class
        {
            if (data == null)
            {
                return(packet.Write(-1));
            }

            packet.Write(data.Count);
            foreach (var item in data)
            {
                packet.WriteWithTypeInfo(item);
            }
            return(packet);
        }
Ejemplo n.º 4
0
        public IWritablePacket Packetize(IWritablePacket packet)
        {
            foreach (var id in _squadIds)
            {
                packet.Write(id);
                var data = _squads[id];
                packet.WriteWithTypeInfo(data.Formation);
                packet.Write(data.Spacing);
                packet.Write(data.Members.Count);
                foreach (var member in data.Members)
                {
                    packet.Write(member);
                }
            }

            return(packet);
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     Write a complete entity, meaning all its components, to the specified packet. Entities saved this way can be
 ///     restored using the <see cref="DepacketizeEntity"/> method. Note that this has no knowledge about components'
 ///     internal states, so if they keep references to other entities or components via their id, these ids will obviously
 ///     be wrong after depacketizing. You will have to take care of fixing these references yourself.
 ///     <para/>
 ///     This uses the components' serialization facilities.
 /// </summary>
 /// <param name="packet">The packet to write to.</param>
 /// <param name="entity">The entity to write.</param>
 /// <returns>The packet after writing the entity's components.</returns>
 public IWritablePacket PacketizeEntity(IWritablePacket packet, int entity)
 {
     return(packet.WriteWithTypeInfo((ICollection <Component>)_entities[entity].Components));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// May be overridden in subclasses which wish to add another protocol layer.
 /// In that case this should follow the pattern
 /// <code>
 /// override WrapDataForSend(...) {
 ///   packet.Write(myStuff);
 ///   return base.WrapDataForSend(...);
 /// }
 /// </code>
 /// </summary>
 /// <param name="command">The command to wrap.</param>
 /// <param name="packet">The packet to wrap into.</param>
 /// <returns>the given packet, after writing.</returns>
 protected virtual IWritablePacket WrapDataForSend(TCommand command, IWritablePacket packet)
 {
     return(packet.WriteWithTypeInfo(command));
 }