Пример #1
0
 public bool Contains(T item)
 {
     for (var i = 0; i < vals.Count; i++)
     {
         IsValid(i);
         if (vals[i].id == item.Id)
         {
             vals[i] = new __RefListRecord <T>(item);
             return(true);
         }
     }
     return(false);
 }
Пример #2
0
 public T this[int index]
 {
     get
     {
         if (IsValid(index))
         {
             return(vals[index].val);
         }
         return(null);
     }
     set
     {
         if (value == null)
         {
             throw new Exception($"null arg set as ref into ref list");
         }
         vals[index] = new __RefListRecord <T>(value);
     }
 }
Пример #3
0
        public bool IsValid(int index)
        {
            var val = vals[index];

            if (val.id <= 0)
            {
                return(false);
            }
            var cached = val.val;

            if (cached == null || val.id != cached.Id || cached.ShouldBeDestroyed)
            {
                if (root == null)
                {
                    throw new ZergRushException("there in no cached ref in non alive ref list");
                }
                var recolled = root.RecallMayBe(val.id);
                if (recolled == null)
                {
                    vals[index] = new __RefListRecord <T>(0);
                    return(false);
                }
                cached = recolled as T;
                if (cached == null)
                {
                    throw new ZergRushException("invalid object stored with id: " + val.id);
                }

                if (cached.ShouldBeDestroyed)
                {
                    vals[index] = new __RefListRecord <T>(0);
                    return(false);
                }
                // save cached value and return
                vals[index] = new __RefListRecord <T>(cached);
                return(true);
            }
            return(true);
        }