/// <summary>Reads a far value.</summary> /// <param name="packet">The packet to read from.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static FarValue ReadFarValue(this IReadablePacket packet) { var segment = packet.ReadInt32(); var offset = packet.ReadSingle(); return(new FarValue(segment, offset)); }
public void Depacketize(IReadablePacket packet) { for (var i = 0; i < N; ++i) { _mt[i] = packet.ReadUInt64(); } }
public void Depacketize(IReadablePacket packet) { if (packet.ReadBoolean()) { _start = packet.ReadFarPosition(); } }
public GameInfoReceivedEventArgs(IPEndPoint host, int playerCount, int maxPlayers, IReadablePacket data) { Host = host; PlayerCount = playerCount; MaxPlayers = maxPlayers; Data = data; }
public void PostDepacketize(IReadablePacket packet) { if (_depacketizer == null) { throw new InvalidOperationException("No deserializer specified."); } _cells.Clear(); var cellCount = packet.ReadInt32(); for (var i = 0; i < cellCount; ++i) { var cellId = packet.ReadUInt64(); var tree = new Collections.DynamicQuadTree <T>( _maxEntriesPerNode, _minNodeBounds, _boundExtension, _movingBoundMultiplier, _packetizer, _depacketizer); packet.ReadPacketizableInto(tree); _cells.Add(cellId, tree); } _entryBounds.Clear(); var entryCount = packet.ReadInt32(); for (var i = 0; i < entryCount; ++i) { var key = _depacketizer(packet); TRectangle value; packet.Read(out value); _entryBounds[key] = value; } }
public static IReadablePacket ReadPacketizableInto <T>([NotNull] this IReadablePacket packet, [NotNull] T result) where T : class { // We need something to write to. if (result == null) { throw new ArgumentNullException("result", "Cannot depacketize into null reference."); } // Make sure we can depacketize to this type. System.Diagnostics.Debug.Assert(IsPacketizable(result)); // See if we have anything at all, or if the written value was null. if (packet.ReadBoolean()) { // Perform the actual deserialization. try { GetDepacketizer(result.GetType())(packet, result); } catch (Exception ex) { throw new PacketException("Failed deserializing packetizable", ex); } return(packet); } throw new InvalidOperationException("Cannot read 'null' into existing instance."); }
/// <summary>Reads a vector value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static Vector2 ReadVector2(this IReadablePacket packet) { Vector2 result; result.X = packet.ReadSingle(); result.Y = packet.ReadSingle(); return(result); }
public void Depacketize(IReadablePacket packet) { for (var i = 0; i < Count; ++i) { Vertices[i] = packet.ReadVector2(); Normals[i] = packet.ReadVector2(); } }
/// <summary>Reads a rotation value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> private static Rotation ReadRotation(this IReadablePacket packet) { Rotation result; result.Sin = packet.ReadSingle(); result.Cos = packet.ReadSingle(); return(result); }
/// <summary>Reads a far position value.</summary> /// <param name="packet">The packet to read from.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static FarPosition ReadFarPosition(this IReadablePacket packet) { FarPosition result; result.X = packet.ReadFarValue(); result.Y = packet.ReadFarValue(); return(result); }
public void Depacketize(IReadablePacket packet) { //Targets.Clear(); //var targetCount = packet.ReadInt32(); //for (var i = 0; i < targetCount; i++) //{ // Targets.Add(packet.ReadInt32()); //} }
public void Depacketize(IReadablePacket packet) { // Read the list of commands for the next frame. Commands.Clear(); foreach (var command in packet.ReadPacketizablesWithTypeInfo <Command>()) { PushCommand(command); } }
/// <summary>Reads a ManifoldPoint value.</summary> /// <param name="packet">The packet.</param> /// <param name="result">The read value.</param> /// <returns>The packet, for call chaining.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> private static IReadablePacket Read(this IReadablePacket packet, out ManifoldPoint result) { result.Id.Feature = new ContactFeature(); return(packet .Read(out result.LocalPoint) .Read(out result.NormalImpulse) .Read(out result.TangentImpulse) .Read(out result.Id.Key)); }
/// <summary>Reads a far rectangle value.</summary> /// <param name="packet">The packet to read from.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static FarRectangle ReadFarRectangle(this IReadablePacket packet) { FarRectangle result; result.X = packet.ReadFarValue(); result.Y = packet.ReadFarValue(); result.Width = packet.ReadSingle(); result.Height = packet.ReadSingle(); return(result); }
public void Depacketize(IReadablePacket packet) { Targets.Clear(); var targetCount = packet.ReadInt32(); for (var i = 0; i < targetCount; i++) { Targets.Add(packet.ReadInt32()); } }
public static string ReadString(this IReadablePacket packet) { if (!packet.HasString()) { throw new PacketException("Cannot read string."); } var data = packet.ReadByteArray(); return(data == null ? null : Encoding.UTF8.GetString(data)); }
public void Depacketize(IReadablePacket packet) { ComponentsToDisable.Clear(); var componentCount = packet.ReadInt32(); for (var i = 0; i < componentCount; i++) { ComponentsToDisable.Add(packet.ReadInt32()); } }
public void Depacketize(IReadablePacket packet) { _reusableIds.Clear(); var reusableIdCount = packet.ReadInt32(); for (var i = 0; i < reusableIdCount; i++) { _reusableIds.Add(packet.ReadInt32()); } }
public void Depacketize(IReadablePacket packet) { Factory = FactoryLibrary.GetFactory(packet.ReadString()) as PlanetFactory; Albedo = null; Normals = null; Specular = null; Lights = null; Clouds = null; }
/// <summary>Reads a rectangle value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static Rectangle ReadRectangle(this IReadablePacket packet) { Rectangle result; result.X = packet.ReadInt32(); result.Y = packet.ReadInt32(); result.Width = packet.ReadInt32(); result.Height = packet.ReadInt32(); return(result); }
/// <summary>Reads a rectangle value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static RectangleF ReadRectangleF(this IReadablePacket packet) { RectangleF result; result.X = packet.ReadSingle(); result.Y = packet.ReadSingle(); result.Width = packet.ReadSingle(); result.Height = packet.ReadSingle(); return(result); }
/// <summary> /// Reads an entity from the specified packet, meaning all its components. This will create a new entity, with an id /// that may differ from the id the entity had when it was written. /// <para/> /// In particular, all re-created components will likely have different different ids as well, so this method is not /// suited for storing components that reference other components, even if just by their ID. /// <para/> /// This will act as though all of the written components were added, i.e. for each restored component a /// <see cref="ComponentAdded"/> message will be sent. /// <para/> /// This uses the components' serialization facilities. /// </summary> /// <param name="packet">The packet to read the entity from.</param> /// <param name="componentIdMap">A mapping of how components' ids changed due to serialization, mapping old id to new id.</param> /// <returns>The id of the read entity.</returns> public int DepacketizeEntity(IReadablePacket packet, Dictionary <int, int> componentIdMap = null) { // Keep track of what we already did, to allow unwinding if something // bad happens. Then get an entity id and try to read the components. var undo = new Stack <Action>(); var entity = AddEntity(); undo.Push(() => RemoveEntity(entity)); try { // Read all components that were written for this entity. This // does not yet mess with our internal state. var components = packet.ReadPacketizablesWithTypeInfo <Component>(); // Now we need to inject the components into our system, so we assign // an id to each one and link it to our entity id. foreach (var component in components) { // Link stuff together. var id = _componentIds.GetId(); if (componentIdMap != null) { componentIdMap.Add(component.Id, id); } component.Id = id; component.Entity = entity; component.Manager = this; _components[component.Id] = component; // Add to entity index. _entities[entity].Add(component); // Push to undo queue in case a message handler throws. undo.Push(() => RemoveComponent(id)); // Send a message to all systems. ComponentAdded message; message.Component = component; SendMessage(message); } // Yay, all went well. Return the id of the read entity. return(entity); } catch (Exception) { // Undo all we did. while (undo.Count > 0) { undo.Pop()(); } throw; } }
public void Depacketize(IReadablePacket packet) { var attributeCount = packet.ReadInt32(); for (var i = 0; i < attributeCount; i++) { var type = (AttributeType)packet.ReadByte(); var value = packet.ReadSingle(); Attributes.Add(type, value); } Projectiles = packet.ReadPacketizables <ProjectileFactory>(); }
public void Depacketize(IReadablePacket packet) { // Get actual data. var data = packet.ReadByteArray(); // Start writing from the start, overwriting everything. _stream.Position = 0; _stream.Write(data, 0, data.Length); // Reset to start for reading. _stream.Position = 0; }
/// <summary>Reads a sweep value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static Sweep ReadSweep(this IReadablePacket packet) { Sweep result; packet.Read(out result.LocalCenter); packet.Read(out result.CenterOfMass0); packet.Read(out result.CenterOfMass); packet.Read(out result.Angle0); packet.Read(out result.Angle); packet.Read(out result.Alpha0); return(result); }
public void Depacketize(IReadablePacket packet) { _cooldowns.Clear(); var cooldownsCount = packet.ReadInt32(); for (var i = 0; i < cooldownsCount; i++) { var key = packet.ReadInt32(); var value = packet.ReadInt32(); _cooldowns.Add(key, value); } }
public void Depacketize(IReadablePacket packet) { _cellInfo.Clear(); var cellCount = packet.ReadInt32(); for (var i = 0; i < cellCount; i++) { var key = packet.ReadUInt64(); var value = packet.ReadPacketizable <CellInfo>(); _cellInfo.Add(key, value); } }
/// <summary>Reads a world transform value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static WorldTransform ReadWorldTransform(this IReadablePacket packet) { WorldTransform result; #if FARMATH result.Translation = packet.ReadFarPosition(); #else result.Translation = packet.ReadVector2(); #endif result.Rotation = packet.ReadRotation(); return(result); }
public void Depacketize(IReadablePacket packet) { _cellSpawns.Clear(); var spawnCount = packet.ReadInt32(); for (var i = 0; i < spawnCount; i++) { var id = packet.ReadUInt64(); var count = packet.ReadInt32(); _cellSpawns.Add(Tuple.Create(id, count)); } }
/// <summary>Reads a Manifold value.</summary> /// <param name="packet">The packet.</param> /// <returns>The read value.</returns> /// <exception cref="PacketException">The packet has not enough available data for the read operation.</exception> public static Manifold ReadManifold(this IReadablePacket packet) { var result = new Manifold(); packet .Read(out result.Points.Item1) .Read(out result.Points.Item2) .Read(out result.LocalNormal) .Read(out result.LocalPoint); result.Type = (Manifold.ManifoldType)packet.ReadByte(); packet.Read(out result.PointCount); return(result); }