Пример #1
0
        public GamePadInputDeviceManager()
        {
            gamePadState    = new RingBuffer <GamePadState> [maxDevices];
            deviceConnected = new bool[maxDevices];

            _taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumerator(GamePadStateEnqueue());

            if (InputManager.XInputUpdateRate == 0)
            {
                timeStep = Mathf.floorToInt(Time.deltaTime * 1000.0f);
            }
            else
            {
                timeStep = Mathf.floorToInt(1.0f / InputManager.XInputUpdateRate * 1000.0f);
            }

            bufferSize = (int)Math.Max(InputManager.XInputBufferSize, 1);

            for (int deviceIndex = 0; deviceIndex < maxDevices; deviceIndex++)
            {
                gamePadState[deviceIndex] = new RingBuffer <GamePadState>(bufferSize);
            }

            for (int deviceIndex = 0; deviceIndex < maxDevices; deviceIndex++)
            {
                GamePadInputDevice gamePad = new GamePadInputDevice(deviceIndex, this);
                devices.Add(gamePad);
            }

            _taskRoutine.Start();
        }
Пример #2
0
 public CameraFollowTargetEngine(ITime time)
 {
     _time        = time;
     _taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumerator(PhysicUpdate())
                    .SetScheduler(StandardSchedulers.physicScheduler);
     _taskRoutine.Start();
 }
        public MultiThreadedParallelTaskCollection(int numberOfThreads = MAX_CONCURRENT_TASKS, bool relaxed = false)
        {
            _runners       = new MultiThreadRunner[numberOfThreads];
            _taskRoutines  = new ITaskRoutine[numberOfThreads];
            _parallelTasks = new ParallelTaskCollection[numberOfThreads];

            //prepare a single multithread runner for each group of fiber like task collections
            //number of threads can be less than the number of tasks to run
            for (int i = 0; i < numberOfThreads; i++)
            {
                _runners[i] = new MultiThreadRunner("MultiThreadedParallelTask:".FastConcat(i), relaxed);
            }

            //prepare the fiber-like paralleltasks
            for (int i = 0; i < numberOfThreads; i++)
            {
                var ptask = TaskRunner.Instance.AllocateNewTaskRoutine();
                var ptc   = new ParallelTaskCollection();
                ptc.onComplete += DecrementConcurrentOperationsCounter;

                ptask.SetEnumerator(ptc).SetScheduler(_runners[i]);

                _parallelTasks[i] = ptc;
                _taskRoutines[i]  = ptask;
                //once they are all done, the process will be completed
            }
        }
Пример #4
0
    public IEnumerator TestUnityWait()
    {
        var coroutineMonoRunner = new CoroutineMonoRunner("test1");
        ITaskRoutine <IEnumerator> taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(coroutineMonoRunner);

        taskRoutine.SetEnumeratorProvider(new WaitForSecondsUnity().GetEnumerator);


        taskRoutine.Start();
        DateTime then = DateTime.Now;

        while (taskRoutine.isRunning == true)
        {
            yield return(null);
        }
        coroutineMonoRunner.Dispose();
        var totalSeconds = (DateTime.Now - then).TotalSeconds;

        Assert.That(totalSeconds, Is.InRange(0.9, 1.1));
    }
Пример #5
0
    public IEnumerator TestUnityWaitInParallel()
    {
        var updateMonoRunner = new UpdateMonoRunner("test1");
        ITaskRoutine <IEnumerator> taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(updateMonoRunner);
        ParallelTaskCollection     pt          = new ParallelTaskCollection();

        pt.Add(new WaitForSecondsUnity().GetEnumerator());
        pt.Add(new WaitForSecondsUnity().GetEnumerator());
        taskRoutine.SetEnumerator(pt);
        taskRoutine.Start();
        DateTime then = DateTime.Now;

        while (taskRoutine.isRunning == true)
        {
            yield return(null);
        }
        updateMonoRunner.Dispose();
        var totalSeconds = (DateTime.Now - then).TotalSeconds;

        Assert.That(totalSeconds, Is.InRange(0.9, 1.1));
    }
        void InitializeThreadsAndData(uint numberOfThreads, bool tightTasks)
        {
            _decrementRunningThread = DecrementRunningThread;

            _runners       = new MultiThreadRunner[numberOfThreads];
            _taskRoutines  = new ITaskRoutine <IEnumerator> [numberOfThreads];
            _parallelTasks = new ParallelTaskCollection[numberOfThreads];

            //prepare a single multithread runner for each group of fiber like task collections
            //number of threads can be less than the number of tasks to run
            for (int i = 0; i < numberOfThreads; i++)
            {
                _runners[i] = new MultiThreadRunner("MultiThreadedParallelRunner ".FastConcat(_name, " #").FastConcat(i),
                                                    false, tightTasks);
            }

            Func <Exception, bool> ptcOnOnException = (e) => {
                DecrementConcurrentOperationsCounter();
                return(false);
            };

            Action ptcOnOnComplete = DecrementConcurrentOperationsCounter;

            //prepare the fiber-like paralleltasks
            for (int i = 0; i < numberOfThreads; i++)
            {
                var ptask = TaskRunner.Instance.AllocateNewTaskRoutine(_runners[i]);
                var ptc   = new ParallelTaskCollection("MultiThreaded ParallelTaskCollection ".FastConcat(_name, " #").FastConcat(i));

                ptc.onComplete  += ptcOnOnComplete;
                ptc.onException += ptcOnOnException;

                ptask.SetEnumerator(ptc);

                _parallelTasks[i] = ptc;
                _taskRoutines[i]  = ptask;
            }
        }
Пример #7
0
 // Use this for initialization
 void Start()
 {
     _taskRountine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumeratorProvider(ResetTaskAndRun); //The Task routine is pooled! You could have used Start directly, but you need to use SetEnumeratorProvider if you want restart the TaskRoutine later
     _taskRountine.Start();
 }
Пример #8
0
 public void Ready()
 {
     _taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumeratorProvider(PhysicsTick);
 }
Пример #9
0
 public PlayerActionLeftStickUpdateEngine(ISequencer sequencer)
 {
     _sequencer   = sequencer;
     _taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumerator(UpdateLeftStickAction());
 }
Пример #10
0
 public PlayerActionSetUpdateEngine()
 {
     _taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumerator(UpdateActionSet());
 }
Пример #11
0
 public TurnResolutionEngine()
 {
     _taskRoutine         = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumeratorProvider(WaitToEnableButtons);
     _waitToEnableButtons = new WaitForSeconds(ReadGlobalData().AlphaDurationOnTextResult);
 }
Пример #12
0
 public PlayerInputEngine(HexGrid mapManager)
 {
     _mapManager  = mapManager;
     _taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine().SetEnumeratorProvider(ReadInput);
 }
 void Start()
 {
     taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(StandardSchedulers.updateScheduler);
     CalculateAndShowNumber().RunOnScheduler(StandardSchedulers.multiThreadScheduler);
     direction = new Vector2(Mathf.Cos(Random.Range(0, 3.14f)) / 1000, Mathf.Sin(Random.Range(0, 3.14f) / 1000));
 }