Ejemplo n.º 1
0
    //----------------------------------------------------
    // run the physics for all the particles
    //----------------------------------------------------
    private void simulateParticlesCPU(float deltaTime)
    {
        if (_useMultithreading)
        {
            if (_parallelForeach == null)
            {
                _parallelForeach = new ParallelForeach((a, b) => particleSimulationLogic(a, b, deltaTime));
            }

            _parallelForeach.Dispatch(NUM_PARTICLES);
            _parallelForeach.Wait();
        }
        else
        {
            particleSimulationLogic(0, NUM_PARTICLES, deltaTime);
        }

        //----------------------------
        // swap back and front buffer
        //----------------------------
        var temp = _backBuffer;

        _backBuffer = _particles;
        _particles  = temp;
    }
Ejemplo n.º 2
0
        public Worker(ParallelForeach parent)
        {
            _parent = parent;

            thread              = new Thread(Run);
            thread.Priority     = System.Threading.ThreadPriority.Highest;
            thread.IsBackground = true;
            thread.Start();
        }
Ejemplo n.º 3
0
    protected virtual void Awake()
    {
        _stopwatch.Start();

        int cores = SystemInfo.processorCount;

        _integrationForeach       = new ParallelForeach(integrateParticles, cores);
        _resolveCollisionsForeach = new ParallelForeach(resolveCollisionsNaive, cores);

        _integrationForeach.OnComplete += () => {
            System.Array.Copy(_particlesFront, _particlesBack, _aliveParticles);
            _resolveCollisionsForeach.Dispatch(_aliveParticles);
        };

        ResetSimulation();

        _randomColors = new Color[maxParticles];
        for (int i = 0; i < maxParticles; i++)
        {
            _randomColors[i] = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
        }
    }