예제 #1
0
    public void DrawTexture()
    {
        _executor.Clear();
        var MakeMapM = new Utility.Coroutine(_ShowWeatherMap());

        _executor.Add(MakeMapM);
    }
예제 #2
0
        public void DoubleValues_SingleInputSingleExecution_SingleOutput(int input)
        {
            string[] outputs = null;

            _executor.Add(scriptName, new [] { input.ToString() }, os => outputs = os).Wait();

            Assert.NotNull(outputs);
            Assert.Single(outputs);

            Assert.True(int.TryParse(outputs[0], out int result));
            Assert.Equal(input * 2, result);
        }
예제 #3
0
 /// <summary>
 /// Regist an IResumable which update by Application
 /// </summary>
 /// <param name="c"></param>
 public void RegistApplicationExecuter(IResumable c)
 {
     if (!applicationExecutor.Contains(c))
     {
         applicationExecutor.Add(c);
     }
 }
예제 #4
0
 public void AddToUpdateExecuter(IResumable c)
 {
     if (!gamePlayUpdateExecuter.Contains(c))
     {
         gamePlayUpdateExecuter.Add(c);
     }
 }
예제 #5
0
 private void DoAddAndRemoveExecuter()
 {
     if (removeUnpauseUpdateExecuterCache.Count > 0)
     {
         foreach (IResumable re in removeUnpauseUpdateExecuterCache)
         {
             gamePlayUnpauseUpdateExecuter.Remove(re);
         }
         removeUnpauseUpdateExecuterCache.Clear();
     }
     if (addUnpauseUpdateExecuterCache.Count > 0)
     {
         foreach (IResumable re in addUnpauseUpdateExecuterCache)
         {
             gamePlayUnpauseUpdateExecuter.Add(re);
         }
         addUnpauseUpdateExecuterCache.Clear();
     }
     if (removeUpdateExecuterCache.Count > 0)
     {
         foreach (IResumable re in removeUpdateExecuterCache)
         {
             gamePlayUpdateExecuter.Remove(re);
         }
         removeUpdateExecuterCache.Clear();
     }
     if (addUpdateExecuterCache.Count > 0)
     {
         foreach (IResumable re in addUpdateExecuterCache)
         {
             gamePlayUpdateExecuter.Add(re);
         }
         addUpdateExecuterCache.Clear();
     }
 }
예제 #6
0
    private void _CreateNewWorld()
    {
        _executor.Clear();
        var monad = new BlockMonad <None>(r => _CreateNewWorldMonad());

        _executor.Add(monad.Do());
    }
예제 #7
0
        public void TestDieAndAbort()
        {
            var executor = new Executor(1)
            {
                AbortPipelineOnError = true, DieOnException = true
            };
            var collector = new EventCollector <ExecutorLifeCycleEventArgs>();

            CreatePipelineWithException(executor);

            executor.LifeCycleEvent += collector.Collect;

            executor.ExecuteBlocking(new MockFileSource(), true);

            AnalyzeCollector(collector, out int _, out int failedCount);

            // after the first pipeline, the second (which also throws an exception) should not be executed
            Assert.AreEqual(1, failedCount);

            // due to die, new sources are not accepted anymore
            Assert.IsFalse(executor.Add(new MockFileSource()));

            Assert.IsTrue(collector.WaitFor(arg => arg.EventType == ExecutorLifeCycleEventType.Stop, 5000),
                          "The executor did not stop in time (it should have died).");

            executor.LifeCycleEvent -= collector.Collect;
        }
예제 #8
0
    public IEnumerator Initialize()
    {
        var genTerrainMonad = new BlockMonad <float[]>(r =>
                                                       _terrainGen.GenerateHeightMap(
                                                           MAP_WIDTH,
                                                           MAP_HEIGHT,
                                                           Random.Range(0, 10000),
                                                           Random.Range(0, 10000),
                                                           new TerrainParameter(),
                                                           r));
        var genTemperatureMonad = new BlockMonad <float[]>(r =>
                                                           _temperatureGen.GenerateWeatherMap(
                                                               MAP_WIDTH,
                                                               MAP_HEIGHT,
                                                               Random.Range(0, 10000),
                                                               Random.Range(0, 10000),
                                                               new WeatherParameter(),
                                                               r));
        var genHumidityMonad = new BlockMonad <float[]>(r =>
                                                        _humidityGen.GenerateWeatherMap(
                                                            MAP_WIDTH,
                                                            MAP_HEIGHT,
                                                            Random.Range(0, 10000),
                                                            Random.Range(0, 10000),
                                                            new WeatherParameter(),
                                                            r));
        var genManaMonad = new BlockMonad <float[]>(r =>
                                                    _manaGen.GenerateWeatherMap(
                                                        MAP_WIDTH,
                                                        MAP_HEIGHT,
                                                        Random.Range(0, 10000),
                                                        Random.Range(0, 10000),
                                                        new WeatherParameter(),
                                                        r));

        var combineM = Monad.WhenAll(
            genTerrainMonad,
            genTemperatureMonad,
            genHumidityMonad,
            genManaMonad);

        _executor.Add(combineM.Do());
        yield return(_executor.Join());
    }
예제 #9
0
        /// <summary>
        /// Return a iterator block that executes the monad. See <see cref="IMonad{T}.Do"/>.
        /// </summary>
        public IEnumerator Do()
        {
            Executor executor = new Executor();

            using (var defer = new Defer())
            {
                defer.Add(() =>
                {
                    foreach (Coroutine c in executor)
                    {
                        c.Dispose();
                    }
                    executor.Clear();
                });

                for (int i = 0; i < _ms.Length; ++i)
                {
                    executor.Add(_Do(_ms[i]));
                }

                executor.Resume(Coroutine.Delta);
                while (!executor.Finished)
                {
                    if (Error != null)
                    {
                        yield break;
                    }
                    yield return(null);

                    executor.Resume(Coroutine.Delta);
                }

                if (Error != null)
                {
                    yield break;
                }
                Result = System.Array.ConvertAll(_ms, m => m.Result);
            }
        }
예제 #10
0
        /// <summary>
        /// This method processes all queued sources. If a source becomes available it will be removed
        /// from the queued sources and added to the executor.
        /// </summary>
        protected virtual void ProcessQueuedSources()
        {
            foreach (var queuedSource in QueuedSources)
            {
                bool abort = false;
                try
                {
                    if (!queuedSource.Value(queuedSource.Key))
                    {
                        continue;                                                            // skip if not ready
                    }
                }
                catch (Exception e)
                {
                    Log.Debug(e);
                    abort = true;
                }

                if (QueuedSources.TryRemove(queuedSource.Key, out _))
                {
                    Log.InfoFormat("Source has become ready, executing {0} pipelineOrBuilder(s).",
                                   InternalPipelines.Count);

                    if (!abort)
                    {
                        abort = !Executor.Add(queuedSource.Key);
                    }

                    Log.DebugFormat("{0} has been added to executor. Failed={1}", queuedSource.Key, abort);

                    ExecuteEvent(abort
                                                ? SchedulerLifeCycleEventType.SourceDiscarded
                                                : SchedulerLifeCycleEventType.SourceReady, queuedSource.Key);
                }
            }
        }
예제 #11
0
        public void Init()
        {
            if (IsInit)
            {
                return;
            }
            OnApplicationInit?.Invoke();
            gamePlayController  = new GamePlayController(this, GetDefaultGameplayData());
            applicationExecutor = new Executor();

            //Prepare Instance
            foreach (var item in scriptableObjectLifeCycle)
            {
                var temp = Instantiate(item);
                scriptableObjectLifeCycleInstances.Add(temp);
            }
            monoBehaviourLifeCycleInstance =
                Resources.FindObjectsOfTypeAll <MonoBehaviourLifeCycle>()
                .Where((m) =>
                       m.gameObject != null &&
                       m.gameObject.scene.IsValid())
                .ToArray();

            resolveTargetInstance = GenerateResolveTargetInstance(GetAllRegisterType().ToArray());

            //Inject Dependency
            foreach (var item in gamePlayDatas)
            {
                InjectByClass(item);
            }

            foreach (var item in scriptableObjectLifeCycleInstances)
            {
                InjectByClass(item);
            }

            foreach (var item in monoBehaviourLifeCycleInstance)
            {
                InjectByClass(item);
            }

            foreach (var item in resolveTargetInstance)
            {
                InjectByClass(item);
            }

            //Init
            gamePlayController.Init();

            foreach (var item in scriptableObjectLifeCycleInstances)
            {
                item.Init();
                allApplicationLifeCycles.Add(item.GetType(), item);
            }

            foreach (var item in monoBehaviourLifeCycleInstance)
            {
                item.Init();
                allApplicationLifeCycles.Add(item.GetType(), item);
            }

            foreach (var item in gamePlayDatas)
            {
                item.Init();
            }

            foreach (var item in resolveTargetInstance)
            {
                if (item is IApplicationLifeCycle applicationLifeCycle)
                {
                    applicationLifeCycle.Init();
                    allApplicationLifeCycles.Add(item.GetType(), applicationLifeCycle);
                }
            }

            applicationExecutor.Add(ApplicationTask());
            applicationExecutor.Add(ApplicationUpdateRunner());
            IsInit = true;
        }
예제 #12
0
 private void Start()
 => _mainExecutor.Add(_Main());
예제 #13
0
 public override void Execute()
 {
     Executor.Add(_addingEntity);
 }