public void FromBytes(ByteQueue bytes) { Clear(); startStateTick = bytes.GetInt(); endStateTick = bytes.GetInt(); entityCount.value = bytes.GetIToBytes <LongValue>(entityCount.GetType()).value; spawns.AddRange(bytes.GetIToBytes <SerializableListEntity>(spawns.GetType())); despawns.AddRange(bytes.GetIToBytes <SerializableListEntity>(despawns.GetType())); foreach (var componentType in componentTypes) { for (int i = 0; i < entityCount.value; i++) { var hasChanges = bytes.GetBool(); if (hasChanges) { changes[componentType].Add(bytes.GetIToBytes <Component>(componentType)); } else { changes[componentType].Add(null); } } } }
public DeltaStateOld(byte[] bytes, State startState) { this.startState = startState; this.endState = new TransformStateCompressed.TransformState(); var byteQueue = new ByteQueue(bytes); var startTick = byteQueue.GetInt(); endState.tick = byteQueue.GetInt(); tick = endState.tick; var spawnCount = byteQueue.GetInt(); for (int i = 0; i < spawnCount; i++) { spawns.Add(new Entity(byteQueue.GetInt())); } var despawnCount = byteQueue.GetInt(); for (int i = 0; i < despawnCount; i++) { despawns.Add(startState.entities.Where(entity => entity.id == byteQueue.GetInt()).First()); } endState.entities.AddRange(startState.entities.Union(spawns).Except(despawns).OrderBy(entity => entity.id)); foreach (var componentType in types) { var currentIndex = 0; while (currentIndex < endState.entities.Count) { var skip = byteQueue.GetInt(); for (int i = 0; i < skip; i++) { changes.Add(new Change { componentType = componentType, entityId = endState.entities[currentIndex + i].id }); } currentIndex += skip; if (currentIndex >= endState.entities.Count) { break; } var entity = endState.entities[currentIndex]; var component = (Component)Activator.CreateInstance(componentType); entity.AddComponent(component); component.Deserialize(byteQueue); changes.Add(new Change { componentType = componentType, entityId = entity.id, delta = component }); currentIndex++; } } }
public void FromBytes(ByteQueue bytes) { tick = bytes.GetInt(); entities.Clear(); entities.FromBytes(bytes); foreach (var componentType in componentTypes) { foreach (var entity in entities) { var hasComponent = bytes.GetBool(); if (hasComponent) { entity.AddComponent(bytes.GetIToBytes <Component>(componentType)); } } } }
public override void Deserialize(ByteQueue byteQueue) { frame = byteQueue.GetInt(); }
public override void FromBytes(ByteQueue bytes) { frame = bytes.GetInt(); }