Exemple #1
0
        private void EntityListWrapperOnEntityAdded(Entity entity)
        {
            if (_gameController.Settings.CoreSettings.AddedMultiThread && _multiThreadManager.ThreadsCount > 0)
            {
                var listJob = new List <Job>();

                Plugins.WhereF(x => x.IsEnable).Batch(_multiThreadManager.ThreadsCount)
                .ForEach(wrappers =>
                         listJob.Add(_multiThreadManager.AddJob(() => wrappers.ForEach(x => x.EntityAdded(entity)),
                                                                "Entity added")));

                _multiThreadManager.Process(this);
                SpinWait.SpinUntil(() => listJob.AllF(x => x.IsCompleted), 500);
            }
            else
            {
                foreach (var plugin in Plugins)
                {
                    if (plugin.IsEnable)
                    {
                        plugin.EntityAdded(entity);
                    }
                }
            }
        }
Exemple #2
0
        public void ParallelUpdate()
        {
            if (MultiThreadManager == null || MultiThreadManager.ThreadsCount < 1)
            {
                Update();
                return;
            }

            if (Coroutines.Count <= 0)
            {
                return;
            }
            jobs.Clear();

            for (var i = 0; i < Coroutines.Count; i++)
            {
                var coroutine = Coroutines[i];

                if (!coroutine.IsDone)
                {
                    if (!coroutine.Running)
                    {
                        continue;
                    }

                    if (coroutine.NextIterRealWork && !coroutine.SyncModWork)
                    {
                        var addJob = MultiThreadManager.AddJob(() =>
                        {
                            var moveNext = coroutine.MoveNext();
                            if (!moveNext)
                            {
                                coroutine.Done();
                            }
                        }, coroutine.Name);

                        jobs.Add(addJob);
                    }
                    else
                    {
                        time = sw.Elapsed.TotalMilliseconds;
                        double delta = 0;

                        var moveNext = coroutine.MoveNext();
                        if (!moveNext)
                        {
                            coroutine.Done();
                        }
                        delta = sw.Elapsed.TotalMilliseconds - time;
                        CoroutinePerformance[coroutine.Name] += delta;

                        if (delta > CriticalTimeWork)
                        {
                            Console.WriteLine(
                                $"Coroutine {coroutine.Name} ({coroutine.OwnerName}) [{Name}] {delta} $Performance coroutine");
                        }
                    }
                }
                else
                {
                    _finishedCoroutines.Add(new CoroutineDetails(coroutine.Name, coroutine.OwnerName, coroutine.Ticks, coroutine.Started,
                                                                 DateTime.Now));

                    FinishedCoroutineCount++;
                    Coroutines.Remove(coroutine);
                }
            }

            MultiThreadManager.Process(this);
            SpinWait.SpinUntil(() => jobs.AllF(job => job.IsCompleted), 500);

            foreach (var job in jobs)
            {
                CoroutinePerformance[job.Name] += job.ElapsedMs;
            }
        }