Esempio n. 1
0
        /// <summary>
        /// Creates entity with single component at specified EcsWorld.
        /// </summary>
        /// <param name="world">World instance.</param>
        public static Inc1 Create(EcsWorld world)
        {
            world.GetFilter <EcsFilterSingle <Inc1> > ();
            var data = world.CreateEntityWith <Inc1> ();

            world.ProcessDelayedUpdates();
            return(data);
        }
Esempio n. 2
0
        public EcsSystems(EcsWorld world)
        {
#if DEBUG
            if (world == null)
            {
                throw new ArgumentNullException();
            }
#endif
            _world = world;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
 public EcsWorld()
 {
     Active = this;
 }