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 void PostDepacketize(IReadablePacket packet) { // Restore entity objects (which we use for faster lookup of components // on an entity). This in particular re-creates empty entities, i.e. // entities with no components. foreach (var entityId in _entityIds) { _entities[entityId] = AllocateEntity(); } // Read back all components. var componentCount = packet.ReadInt32(); for (var i = 0; i < componentCount; ++i) { var type = packet.ReadType(); var component = AllocateComponent(type); packet.ReadPacketizableInto(component); component.Manager = this; _components[component.Id] = component; _entities[component.Entity].Add(component); } // Read back all systems. var systemCount = packet.ReadInt32(); for (var i = 0; i < systemCount; ++i) { var type = packet.ReadType(); var instance = _systemsByTypeId[GetSystemTypeId(type)]; Debug.Assert(instance != null); packet.ReadPacketizableInto(instance); } // All done, send message to allow post-processing, e.g. for fetching // their components again, which is why this has to come last. Initialize message; SendMessage(message); }
public void Depacketize(IReadablePacket packet) { _currentBehaviors.Clear(); var behaviorCount = packet.ReadInt32(); for (var i = 0; i < behaviorCount; i++) { _currentBehaviors.Push((BehaviorType)packet.ReadByte()); } foreach (var behaviorType in _behaviors.Keys) { var behavior = _behaviors[behaviorType]; packet.ReadPacketizableInto(behavior); } }
public void Depacketize(IReadablePacket packet) { // Unwrap the trailing state and mirror it to all the newer ones. packet.ReadPacketizableInto(_simulations[_simulations.Length - 1]); MirrorSimulation(_simulations[_simulations.Length - 1], _simulations.Length - 2); // Find adds / removes / commands that our out of date now, but keep // newer ones (that might be locally generated). PrunePastEvents(); // Continue with reading the list of removes. var removeCount = packet.ReadInt32(); for (var removeIndex = 0; removeIndex < removeCount; ++removeIndex) { var key = packet.ReadInt64(); if (!_removes.ContainsKey(key)) { _removes.Add(key, new List <int>()); } var valueCount = packet.ReadInt32(); for (var valueIndex = 0; valueIndex < valueCount; ++valueIndex) { _removes[key].Add(packet.ReadInt32()); } } // And finally the commands. var commandCount = packet.ReadInt32(); for (var commandIndex = 0; commandIndex < commandCount; ++commandIndex) { var key = packet.ReadInt64(); if (!_commands.ContainsKey(key)) { _commands.Add(key, new List <Command>()); } _commands[key].AddRange(packet.ReadPacketizablesWithTypeInfo <Command>()); } // Got a valid state. WaitingForSynchronization = false; }
public void Depacketize(IReadablePacket packet) { foreach (var tree in _trees.Where(tree => tree != null)) { tree.Clear(); } foreach (var changed in _changed.Where(changed => changed != null)) { changed.Clear(); } var indexCount = packet.ReadInt32(); for (var i = 0; i < indexCount; ++i) { var index = packet.ReadInt32(); if (_trees[index] == null) { #if FARMATH _trees[index] = new FarCollections.SpatialHashedQuadTree <int>(_maxEntriesPerNode, _minNodeBounds, 0.1f, 2f, (p, v) => p.Write(v), p => p.ReadInt32()); #else _trees[index] = new DynamicQuadTree <int>(_maxEntriesPerNode, _minNodeBounds, 0.1f, 2f, (p, v) => p.Write(v), p => p.ReadInt32()); #endif } if (_changed[index] == null) { _changed[index] = new HashSet <int>(); } packet.ReadPacketizableInto(_trees[index]); var changedCount = packet.ReadInt32(); for (var j = 0; j < changedCount; ++j) { _changed[index].Add(packet.ReadInt32()); } } }