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 static State GetStateFromBytes(Type type, ByteQueue bytes, int tick) { if (tick == 0) { return(bytes.GetIToBytes <State>(type)); } var currentTick = 0; while (bytes.Count > 0) { if (bytes.StartsWith(DELIMITER)) { currentTick++; } if (currentTick == tick) { bytes.GetBytes(DELIMITER.Length); return(bytes.GetIToBytes <State>(type)); } bytes.GetByte(); } return(null); }
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 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)); } } } }