public void FromBytes(ByteQueue bytes) { states.Clear(); states.Add(bytes.GetIToBytes <T>(typeof(T))); while (bytes.StartsWith(DELIMITER)) { bytes.GetBytes(DELIMITER.Length); states.Add(bytes.GetIToBytes <T>(typeof(T))); } }
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 ByteQueue ToBytes() { var bytes = new ByteQueue(); for (int i = 0; i < states.Count; i++) { if (i > 0) { bytes.Enqueue(DELIMITER); } bytes.Enqueue(states[i]); } return(bytes); }
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 static int GetCountFromBytes(ByteQueue bytes) { if (bytes.Count == 0) { return(0); } var count = 1; while (bytes.Count > 0) { if (bytes.StartsWith(DELIMITER)) { count++; } bytes.GetByte(); } return(count); }
public ByteQueue ToBytes() { var bytes = new ByteQueue(); bytes.Enqueue(tick); bytes.Enqueue(entities); foreach (var componentType in componentTypes) { foreach (var entity in entities) { var hasComponent = entity.HasComponent(componentType); bytes.Enqueue(hasComponent); if (hasComponent) { bytes.Enqueue(entity.GetComponent(componentType)); } } } return(bytes); }
public ByteQueue ToBytes() { var bytes = new ByteQueue(); bytes.Enqueue(startStateTick); bytes.Enqueue(endStateTick); bytes.Enqueue(entityCount); bytes.Enqueue(spawns); bytes.Enqueue(despawns); foreach (var componentType in componentTypes) { foreach (var change in changes[componentType]) { var hasChanges = change != null; bytes.Enqueue(hasChanges); if (hasChanges) { bytes.Enqueue(change); } } } return(bytes); }
public abstract void FromBytes(ByteQueue bytes);
public abstract void Deserialize(ByteQueue byteQueue);
public static T GetLatestStateFromBytes(ByteQueue bytes) { return(GetStateFromBytes(bytes, GetCountFromBytes(new ByteQueue(bytes)))); }
public static T GetStateFromBytes(ByteQueue bytes, int tick) => (T)GetStateFromBytes(typeof(T), bytes, tick);
public override void Deserialize(ByteQueue byteQueue) { frame = byteQueue.GetInt(); }
public override void FromBytes(ByteQueue bytes) { frame = bytes.GetInt(); }
public static T GetDeltaStateFromBytes(ByteQueue bytes, int startStateTick) => (T)GetStateFromBytes(typeof(T), bytes, startStateTick);
public override void Deserialize(ByteQueue byteQueue) { spriteName = byteQueue.GetString(); }
public override void FromBytes(ByteQueue bytes) { spriteName = bytes.GetString(); }