예제 #1
0
 public void Remove(IReleasable r)
 {
     if (releasables != null)
     {
         releasables.Remove(r);
     }
 }
예제 #2
0
 public void Add(IReleasable r)
 {
     if (releasables == null)
     {
         releasables = new List <IReleasable>();
     }
     releasables.Add(r);
 }
예제 #3
0
        LayeredDisposable(IDisposable underlying)
        {
            if (underlying == null)
            {
                throw new ArgumentNullException();
            }

            _underlying = new OriginalReleasable(underlying);
        }
예제 #4
0
 public static void FindAndRemove(IReleasable r)
 {
     foreach (var p in pools)
     {
         p.Remove(r);
     }
     if (def != null)
     {
         def.Remove(r);
     }
 }
예제 #5
0
 public static void FindAndAdd(IReleasable r)
 {
     foreach (var p in pools)
     {
         if (r.transform.IsChildOf(p.transform))
         {
             p.Add(r);
             return;
         }
     }
     def.Add(r);
 }
예제 #6
0
        public void Add(IReleasable item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            WeakReference reference = new WeakReference(item, false);

            lock (this._items.SyncRoot)
            {
                this._items.Add(reference);
            }
        }
예제 #7
0
    public static void HotFileDBReg(IReleasable r)
    {
        if (!IsIntanceInScene)
        {
            GameObject go = new GameObject("HotFileDBIOReleaser");
            go.AddComponent<HotFileDBIOReleaser>();
            IsIntanceInScene = true;
        }

        if (HotFileDBs == null)
            HotFileDBs = new List<IReleasable>();

        HotFileDBs.Add(r);
    }
예제 #8
0
 protected virtual void Check()
 {
     if (!this._checking)
     {
         try
         {
             lock (this)
             {
                 if (this._checking)
                 {
                     return;
                 }
                 this._checking = true;
             }
             int index = 0;
             lock (this._items.SyncRoot)
             {
                 while (index < this._items.Count)
                 {
                     if (this._items[index] == null)
                     {
                         this._items.RemoveAt(index);
                     }
                     else
                     {
                         WeakReference state = this._items[index] as WeakReference;
                         if ((state == null) || !state.IsAlive)
                         {
                             this._items.RemoveAt(index);
                             continue;
                         }
                         IReleasable target = state.Target as IReleasable;
                         if ((target == null) || target.IsExpired)
                         {
                             this._items.RemoveAt(index);
                             WorkThread.QueueItem(new WaitCallback(this.ReleaseItem), state);
                             continue;
                         }
                         index++;
                     }
                 }
             }
         }
         finally
         {
             this._checking = false;
         }
     }
 }
    public static void HotFileDBReg(IReleasable r)
    {
        if (!IsIntanceInScene)
        {
            GameObject go = new GameObject("HotFileDBIOReleaser");
            go.AddComponent <HotFileDBIOReleaser>();
            IsIntanceInScene = true;
        }


        if (HotFileDBs == null)
        {
            HotFileDBs = new List <IReleasable>();
        }



        HotFileDBs.Add(r);
    }
예제 #10
0
 protected virtual void ReleaseItem(object state)
 {
     if (state != null)
     {
         WeakReference reference = state as WeakReference;
         if (reference != null)
         {
             if (reference.IsAlive)
             {
                 IReleasable target = reference.Target as IReleasable;
                 if (target != null)
                 {
                     target.Release();
                 }
             }
             reference = null;
         }
     }
 }
예제 #11
0
        public void RemoveComponent <TComponent>(Entity <TEntity> entity, ComponentID <TEntity, TComponent> id) where TComponent : class
        {
            _threadAffinity.Validate();
            Assert.Debug(IsValid(entity), $"Invalid entity: Index: {entity.Index} CreationID: {entity.CreationIDCheck}");

            Assert.Debug((ushort)id.ComponentIndex < _maxComponentsPerEntity, "Component index out of range");

            int entityIndex    = entity.Index;
            int componentIndex = id.ComponentIndex;
            int offset         = entityIndex * _maxComponentsPerEntity + componentIndex;

            object      component           = _components[offset];
            IReleasable releasableComponent = component as IReleasable;

            if (releasableComponent != null)
            {
                releasableComponent.Release();
            }

            _components[offset] = null;

            componentFlags[entityIndex][componentIndex] = false;
        }
예제 #12
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");
            if (offset < 0 || offset >= buffer.Length)
                throw new ArgumentOutOfRangeException("offset");
            if (count < 0 || offset + count > buffer.Length)
                throw new ArgumentOutOfRangeException("count");
            if (dataAvailable == null)
                throw new ObjectDisposedException(GetType().Name);

            if (count == 0)
                return 0;

            while (true)
            {
                int handleIndex = WaitHandle.WaitAny(events);
                lock (lockForRead)
                {
                    lock (lockForAll)
                    {
                        if (currentChunk == null)
                        {
                            if (chunks.Count == 0)
                            {
                                if (handleIndex == doneWritingHandleIndex)
                                    return 0;
                                else
                                    continue;
                            }
                            currentChunk = chunks.Dequeue();
                            currentChunk.Value.Position = 0; //bad
                        }
                    }
                }

                int bytesAvailable = (int)currentChunk.Value.Length - (int)currentChunk.Value.Position;
                int bytesToCopy;
                if (bytesAvailable > count)
                {
                    bytesToCopy = count;
                    currentChunk.Value.Read(buffer, offset, bytesToCopy);
                }
                else
                {
                    bytesToCopy = bytesAvailable;
                    currentChunk.Value.Read(buffer, offset, bytesToCopy);
                    currentChunk.Release();
                    currentChunk = null;
                    lock (lockForAll)
                    {
                        if (chunks.Count == 0)
                            dataAvailable.Reset();
                    }
                }
                return bytesToCopy;
            }
        }
예제 #13
0
 public ReleasableWrapper(IReleasable wrapped)
 {
     _wrapped = wrapped;
 }
예제 #14
0
 static IReleasable Wrap(IReleasable underlying)
 {
     return(new ReleasableWrapper(underlying));
 }
예제 #15
0
 public void Add(IReleasable r)
 {
     releasables.Add(r);
 }
        public override bool Tick()
        {
            switch (State)
            {
            case RobotLoadTruckTask.TaskState.Init:
                _targetEntity.SetPathfindingTarget(_item.Position, _targetEntity.GetPathfindingGraph());
                _state = TaskState.MoveToItem;
                break;

            case RobotLoadTruckTask.TaskState.MoveToItem:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }
                _state = TaskState.PickupCargo;
                break;

            case RobotLoadTruckTask.TaskState.PickupCargo:
                if (!_targetEntity.TryAddCargo(_item))
                {
                    break;
                }
                _state = TaskState.MoveToQueue;
                _targetEntity.SetPathfindingTarget(Constants.RobotEnterTruck, _targetEntity.GetPathfindingGraph());
                break;

            case RobotLoadTruckTask.TaskState.MoveToQueue:
                if (_targetEntity.IsAtDestination())
                {
                    _state = TaskState.AwaitTruckAvailable;
                }
                break;

            case RobotLoadTruckTask.TaskState.AwaitTruckAvailable:
                if (_truck.IsOccupied)
                {
                    break;
                }
                _lock = _truck.Occupy(_targetEntity);
                _targetEntity.SetTarget(_destination.PositionAbsolute);
                _state = TaskState.DropOffDestination;
                break;

            case RobotLoadTruckTask.TaskState.DropOffDestination:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }
                _destination.SetCargo(_targetEntity.CargoSlots[0].ReleaseCargo());
                _targetEntity.SetTarget(Constants.RobotExitTruck);
                _state = TaskState.LeaveTruck;
                break;

            case RobotLoadTruckTask.TaskState.LeaveTruck:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }

                _targetEntity.SetPathfindingTarget(_targetEntity.IdlePos, _targetEntity.GetPathfindingGraph());
                _lock.Release();
                _state           = TaskState.Finished;
                this._isFinished = true;
                break;

            case RobotLoadTruckTask.TaskState.Finished:
                break;
            }
            return(base.Tick());
        }
예제 #17
0
 public static void Register(IReleasable rel)
 {
     m_release.Add(rel);
 }
예제 #18
0
 public void Remove(IReleasable r)
 {
     releasables.Remove(r);
 }