Exemplo n.º 1
0
 public bool IsCompatible(EcsFilter filter)
 {
     if (BitsCount > 0 && filter.IncludeMask.BitsCount <= BitsCount)
     {
         int i    = filter.IncludeMask.BitsCount - 1;
         var maxJ = BitsCount - 1;
         for (; i >= 0; i--)
         {
             var j   = maxJ;
             var bit = filter.IncludeMask.Bits[i];
             for (; j >= 0; j--)
             {
                 if (Bits[j] == bit)
                 {
                     break;
                 }
             }
             if (j == -1)
             {
                 break;
             }
         }
         if (i == -1)
         {
             return(!IsIntersects(filter.ExcludeMask));
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        public virtual void Initialize()
        {
            _world          = GetWorld();
            _filter         = GetFilter();
            _worker         = GetWorker();
            _minJobSize     = GetMinJobSize();
            _threadsCount   = GetThreadsCount();
            _forceSyncState = GetForceSyncState();
#if DEBUG
            if (_world == null)
            {
                throw new Exception("Invalid EcsWorld");
            }
            if (_filter == null)
            {
                throw new Exception("Invalid EcsFilter");
            }
            if (_minJobSize < 1)
            {
                throw new Exception("Invalid JobSize");
            }
            if (_threadsCount < 1)
            {
                throw new Exception("Invalid ThreadsCount");
            }
#endif
#if !UNITY_WEBGL
            _descs = new WorkerDesc[_threadsCount];
            _syncs = new ManualResetEvent[_threadsCount];
            EcsMultiThreadJob job;
            for (var i = 0; i < _descs.Length; i++)
            {
                job       = new EcsMultiThreadJob();
                job.World = _world;
                var desc = new WorkerDesc();
                desc.Job    = job;
                desc.Thread = new Thread(ThreadProc);
                desc.Thread.IsBackground = true;
#if DEBUG
                desc.Thread.Name = string.Format("ECS-{0:X}-{1}", this.GetHashCode(), i);
#endif
                desc.HasWork  = new ManualResetEvent(false);
                desc.WorkDone = new ManualResetEvent(true);
                desc.Worker   = _worker;
                _descs[i]     = desc;
                _syncs[i]     = desc.WorkDone;
                desc.Thread.Start(desc);
            }
#endif
            _localJob       = new EcsMultiThreadJob();
            _localJob.World = _world;
        }
Exemplo n.º 3
0
        public virtual void Destroy()
        {
#if !UNITY_WEBGL
            for (var i = 0; i < _descs.Length; i++)
            {
                var desc = _descs[i];
                _descs[i] = null;
                desc.Thread.Interrupt();
                desc.Thread.Join(10);
                _syncs[i].Close();
                _syncs[i] = null;
            }
#endif
            _world  = null;
            _filter = null;
            _worker = null;
        }