public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_livingCells.Count); foreach (var cellId in _livingCells) { packet.Write(cellId); } packet.Write(_pendingCells.Count); foreach (var pending in _pendingCells) { packet.Write(pending.Key); packet.Write(pending.Value); } packet.Write(_livingSubCells.Count); foreach (var cellId in _livingSubCells) { packet.Write(cellId); } packet.Write(_pendingSubCells.Count); foreach (var pending in _pendingSubCells) { packet.Write(pending.Key); packet.Write(pending.Value); } return(packet); }
public static IWritablePacket Write <T>([NotNull] this IWritablePacket packet, T data) where T : class { // Check whether we have something. if (data != null) { // Check its underlying type. var type = data.GetType(); if (!IsPacketizable(type)) { return(packet); } // Flag that we have something. packet.Write(true); // Packetize all fields, then give the object a chance to do manual // serialization, e.g. of collections and such. try { GetPacketizer(type)(packet, data); } catch (Exception ex) { throw new PacketException("Failed serializing " + type.Name, ex); } return(packet); } // Flag that we have nothing. return(packet.Write(false)); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_reusableIds.Count); foreach (var reusableId in _reusableIds) { packet.Write(reusableId); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(ComponentsToDisable.Count); foreach (var componentType in ComponentsToDisable) { packet.Write(componentType); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_cellSpawns.Count); foreach (var entry in _cellSpawns) { packet.Write(entry.Item1); packet.Write(entry.Item2); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { for (var i = 0; i < Count; ++i) { packet.Write(Vertices[i]); packet.Write(Normals[i]); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_start.HasValue); if (_start.HasValue) { packet.Write(_start.Value); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(Targets.Count); foreach (var item in Targets) { packet.Write(item); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_cooldowns.Count); foreach (var kv in _cooldowns) { packet.Write(kv.Key); packet.Write(kv.Value); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_cellInfo.Count); foreach (var item in _cellInfo) { packet.Write(item.Key); packet.Write(item.Value); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(Attributes.Count); foreach (var attribute in Attributes) { packet.Write((byte)attribute.Key); packet.Write(attribute.Value); } packet.Write((ICollection <ProjectileFactory>)Projectiles); return(packet); }
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); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_changedShape.Count); foreach (var entity in _changedShape) { packet.Write(entity); } packet.Write(_changedMass.Count); foreach (var entity in _changedMass) { packet.Write(entity); } return(packet); }
/// <summary>Writes the specified matrix value.</summary> /// <param name="packet">The packet.</param> /// <param name="data">The value to write.</param> /// <returns>This packet, for call chaining.</returns> public static IWritablePacket Write(this IWritablePacket packet, Matrix data) { return(packet.Write(data.M11).Write(data.M12).Write(data.M13).Write(data.M14). Write(data.M21).Write(data.M22).Write(data.M23).Write(data.M24). Write(data.M31).Write(data.M32).Write(data.M33).Write(data.M34). Write(data.M41).Write(data.M42).Write(data.M43).Write(data.M44)); }
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); }
public IWritablePacket Packetize(IWritablePacket packet) { for (var i = 0; i < N; ++i) { packet.Write(_mt[i]); } return(packet); }
/// <summary>Writes the specified manifold point value.</summary> /// <param name="packet">The packet.</param> /// <param name="data">The value to write.</param> /// <returns>This packet, for call chaining.</returns> private static IWritablePacket Write(this IWritablePacket packet, ManifoldPoint data) { return(packet .Write(data.LocalPoint) .Write(data.NormalImpulse) .Write(data.TangentImpulse) .Write(data.Id.Key)); }
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); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_currentBehaviors.Count); var behaviorTypes = _currentBehaviors.ToArray(); // Stacks iterators work backwards (first is the last pushed element), // so we need to iterate backwards. for (var i = behaviorTypes.Length; i > 0; --i) { packet.Write((byte)behaviorTypes[i - 1]); } foreach (var behavior in _behaviors.Values) { packet.Write(behavior); } return(packet); }
/// <summary>Writes the specified manifold value.</summary> /// <param name="packet">The packet.</param> /// <param name="data">The value to write.</param> /// <returns>This packet, for call chaining.</returns> public static IWritablePacket Write(this IWritablePacket packet, Manifold data) { return(packet .Write(data.Points.Item1) .Write(data.Points.Item2) .Write(data.LocalNormal) .Write(data.LocalPoint) .Write((byte)data.Type) .Write(data.PointCount)); }
/// <summary>Writes the specified sweep value.</summary> /// <param name="packet">The packet.</param> /// <param name="data">The value to write.</param> /// <returns>This packet, for call chaining.</returns> public static IWritablePacket Write(this IWritablePacket packet, Sweep data) { return(packet .Write(data.LocalCenter) .Write(data.CenterOfMass0) .Write(data.CenterOfMass) .Write(data.Angle0) .Write(data.Angle) .Write(data.Alpha0)); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(Capacity); packet.Write(Count); // Write actual item ids with their positions. for (var i = 0; i < _items.Count; i++) { var itemEntry = _items[i]; if (itemEntry <= 0) { continue; } packet.Write(i); packet.Write(itemEntry); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { // Write the components, which are enough to implicitly restore the // entity to component mapping as well, so we don't need to write // the entity mapping. Entities without any components are already // known via the entity ids. packet.Write(_componentIds.Count); foreach (var component in Components) { // Store type manually to allow going through object pool on // deserialization. packet.Write(component.GetType()); packet.Write(component); } // Write systems, with their types, as these will only be read back // via ReadPacketizableInto() to keep some variables that can only // passed in the constructor (in particular for presentation systems). packet.Write(_systems.Count(Packetizable.IsPacketizable)); foreach (var system in _systems.Where(Packetizable.IsPacketizable)) { packet.Write(system.GetType()); packet.Write(system); } return(packet); }
public static IWritablePacket WriteWithTypeInfo <T>([NotNull] this IWritablePacket packet, T data) where T : class { // Check whether we have something. if (data != null) { // Check its underlying type. var type = data.GetType(); if (!IsPacketizable(type)) { return(packet); } // Flag that we have something. packet.Write(true); // Make sure we have a parameterless public constructor for deserialization. System.Diagnostics.Debug.Assert(type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) != null); // Store the type, which also tells us the value us not null. packet.Write(type); // Packetize all fields, then give the object a chance to do manual // serialization, e.g. of collections and such. try { GetPacketizer(type)(packet, data); } catch (Exception ex) { throw new PacketException("Failed serializing " + type.Name, ex); } return(packet); } // Flag that we have nothing. return(packet.Write(false)); }
public IWritablePacket Packetize(IWritablePacket packet) { if (_packetizer == null) { throw new InvalidOperationException("No serializer specified."); } packet.Write(_cells.Count); foreach (var entry in _cells) { packet.Write(entry.Key); packet.Write(entry.Value); } packet.Write(_entryBounds.Count); foreach (var entry in _entryBounds) { _packetizer(packet, entry.Key); packet.Write(entry.Value); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(IndexCount); for (var index = 0; index < _nextIndexId; ++index) { // Skip non-existing and empty trees. if (_trees[index] == null || _trees[index].Count == 0) { System.Diagnostics.Debug.Assert(_changed[index] == null || _changed[index].Count == 0); continue; } packet.Write(index); packet.Write(_trees[index]); packet.Write(_changed[index].Count); foreach (var component in _changed[index]) { packet.Write(component); } } return(packet); }
/// <summary>Special purpose packetize method, only writing own data, not that of the base class. Used for saving.</summary> /// <param name="packet">The packet to write to.</param> /// <returns>The written to packet.</returns> public IWritablePacket PacketizeLocal(IWritablePacket packet) { packet.Write(_baseAttributes.Count); foreach (var attribute in _baseAttributes) { packet.Write(Enum.GetName(typeof(TAttribute), attribute.Key)); packet.Write(attribute.Value); } packet.Write(_modifiedAttributes.Count); foreach (var attribute in _modifiedAttributes) { packet.Write(Enum.GetName(typeof(TAttribute), attribute.Key)); packet.Write(attribute.Value[0]); packet.Write(attribute.Value[1]); } return(packet); }
public IWritablePacket Packetize(IWritablePacket packet) { packet.Write(_newCollisions.Count); foreach (var info in _newCollisions) { packet.Write(info.Key); packet.Write(info.Value); } packet.Write(_activeCollisions.Count); foreach (var info in _activeCollisions) { packet.Write(info.Key); packet.Write(info.Value); } return(packet); }
public static IWritablePacket Write(this IWritablePacket packet, Type data) { return(data == null?packet.Write((string)null) : packet.Write(data.AssemblyQualifiedName)); }
public static IWritablePacket Write(this IWritablePacket packet, string data) { return(data == null?packet.Write((byte[])null) : packet.Write(Encoding.UTF8.GetBytes(data))); }