Пример #1
0
        public void ProcessEntityUpdate(int serverTick, int id, ref NetworkReader reader)
        {
            //  FSLog.Info($"ProcessEntityUpdate,serverTick:{serverTick},id:{id}!");
            var data = replicatedData[id];

            if (data.Entity == Entity.Null)
            {
                return;
            }

            GameDebug.Assert(data.LastServerTick < serverTick,
                             "Failed to apply snapshot. Wrong tick order. entityId:{0} snapshot tick:{1} last server tick:{2}", id,
                             serverTick, data.LastServerTick);
            data.LastServerTick = serverTick;

            GameDebug.Assert(data.SerializableArray != null, "Failed to apply snapshot. Serializablearray is null");

            foreach (var entry in data.SerializableArray)
            {
                entry.Deserialize(ref reader, serverTick);
            }

            foreach (var entry in data.PredictedArray)
            {
                entry.Deserialize(ref reader, serverTick);
            }

            foreach (var entry in data.InterpolatedArray)
            {
                entry.Deserialize(ref reader, serverTick);
            }

            replicatedData[id] = data;
        }
Пример #2
0
        public void GenerateEntitySnapshot(int entityId, ref NetworkWriter writer)
        {
            //   FSLog.Info($"GenerateEntitySnapshot,entityId:{entityId}!");
            var data = replicatedData[entityId];

            GameDebug.Assert(data.SerializableArray != null, "Failed to generate snapshot. Serializablearray is null");

            foreach (var entry in data.SerializableArray)
            {
                entry.Serialize(ref writer);
            }

            writer.SetFieldSection(NetworkWriter.FieldSectionType.OnlyPredicting);
            foreach (var entry in data.PredictedArray)
            {
                entry.Serialize(ref writer);
            }
            writer.ClearFieldSection();

            writer.SetFieldSection(NetworkWriter.FieldSectionType.OnlyNotPredicting);
            foreach (var entry in data.InterpolatedArray)
            {
                entry.Serialize(ref writer);
            }
            writer.ClearFieldSection();
        }
Пример #3
0
        public Entity Unregister(int entityId)
        {
            var entity = replicatedData[entityId].Entity;

            if (entity == Entity.Null)
            {
                return(Entity.Null);
            }
            GameDebug.Assert(entity != Entity.Null, "Unregister. ReplicatedData has has entity set");

            if (showInfo.IntValue > 0)
            {
                if (entityManager.HasComponent <Transform>(entity))
                {
                    GameDebug.Log("RepEntity UNREGISTER NetID:" + entityId + " Entity:" + entity + " GameObject:" +
                                  entityManager.GetComponentObject <Transform>(entity).name);
                }
                else
                {
                    GameDebug.Log("RepEntity UNREGISTER NetID:" + entityId + " Entity:" + entity);
                }
            }

            replicatedData[entityId] = new ReplicatedData();
            return(entity);
        }
Пример #4
0
 public T this[int i]
 {
     get
     {
         GameDebug.Assert(i < m_Count);
         return(m_Elements[(m_First + i) % m_Elements.Length]);
     }
     set
     {
         GameDebug.Assert(i < m_Count);
         m_Elements[(m_First + i) % m_Elements.Length] = value;
     }
 }
Пример #5
0
        public void Register(int entityId, Entity entity)
        {
            if (showInfo.IntValue > 0)
            {
                if (entityManager.HasComponent <Transform>(entity))
                {
                    GameDebug.Log("RepEntity REGISTER NetID:" + entityId + " Entity:" + entity + " GameObject:" +
                                  entityManager.GetComponentObject <Transform>(entity).name);
                }
                else
                {
                    GameDebug.Log("RepEntity REGISTER NetID:" + entityId + " Entity:" + entity);
                }
            }


            // Grow to make sure there is room for entity
            if (entityId >= replicatedData.Count)
            {
                var count     = entityId - replicatedData.Count + 1;
                var emptyData = new ReplicatedData();
                for (var i = 0; i < count; i++)
                {
                    replicatedData.Add(emptyData);
                }
            }

            GameDebug.Assert(replicatedData[entityId].Entity == Entity.Null, "ReplicatedData has entity set:{0}",
                             replicatedData[entityId].Entity);

            netSerializables.Clear();
            netPredicted.Clear();
            netInterpolated.Clear();

            //var go = entityManager.HasComponent<Transform>(entity)
            //    ? entityManager.GetComponentObject<Transform>(entity).gameObject
            //    : null;


            FindSerializers(entity);

            if (entityManager.HasComponent <EntityGroupChildren>(entity))
            {
                var buffer = entityManager.GetBuffer <EntityGroupChildren>(entity);
                for (var i = 0; i < buffer.Length; i++)
                {
                    var childEntity = buffer[i].Entity;
                    if (showInfo.IntValue > 0)
                    {
                        GameDebug.Log(" ReplicatedEntityChildren: " + i + " = " + childEntity);
                    }
                    FindSerializers(childEntity);
                }
            }

            var data = new ReplicatedData
            {
                Entity = entity,
                //      gameObject = go,
                SerializableArray = netSerializables.ToArray(),
                PredictedArray    = netPredicted.ToArray(),
                InterpolatedArray = netInterpolated.ToArray()
            };

            replicatedData[entityId] = data;
        }