Ejemplo n.º 1
0
 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++;
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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));
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 public abstract void FromBytes(ByteQueue bytes);
Ejemplo n.º 9
0
 public abstract void Deserialize(ByteQueue byteQueue);
Ejemplo n.º 10
0
 public static T GetLatestStateFromBytes(ByteQueue bytes)
 {
     return(GetStateFromBytes(bytes, GetCountFromBytes(new ByteQueue(bytes))));
 }
Ejemplo n.º 11
0
 public static T GetStateFromBytes(ByteQueue bytes, int tick)
 => (T)GetStateFromBytes(typeof(T), bytes, tick);
Ejemplo n.º 12
0
 public override void Deserialize(ByteQueue byteQueue)
 {
     frame = byteQueue.GetInt();
 }
Ejemplo n.º 13
0
 public override void FromBytes(ByteQueue bytes)
 {
     frame = bytes.GetInt();
 }
 public static T GetDeltaStateFromBytes(ByteQueue bytes, int startStateTick)
 => (T)GetStateFromBytes(typeof(T), bytes, startStateTick);
Ejemplo n.º 15
0
 public override void Deserialize(ByteQueue byteQueue)
 {
     spriteName = byteQueue.GetString();
 }
Ejemplo n.º 16
0
 public override void FromBytes(ByteQueue bytes)
 {
     spriteName = bytes.GetString();
 }