예제 #1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        CheckDisposeTempData();

        // Compute index
        positionsMap        = new NativeHashMap <int, int>(m_PowderGroup.Length, Allocator.Temp);
        toDeleteEntities    = new NativeHashMap <int, int>(Mathf.Max(m_PowderGroup.Length / 10, 64), Allocator.Temp);
        m_TempDataAllocated = true;

        var computeHashJob = new HashCoordJob()
        {
            powders = m_PowderGroup.powders,
            hashMap = positionsMap
        };
        var previousJobHandle = computeHashJob.Schedule(m_PowderGroup.Length, 64, inputDeps);

        if ((Input.GetMouseButtonDown(0) || Input.GetMouseButton(0)) && PowderGame.IsInWorld(Input.mousePosition))
        {
            var coord    = PowderGame.ScreenToCoord(Input.mousePosition);
            var spawnJob = new SpawnJob()
            {
                hashMap    = positionsMap,
                coord      = coord,
                cmdBuffer  = m_Barrier.CreateCommandBuffer(),
                type       = PowderGame.currentPowder,
                isPainting = !Input.GetMouseButtonDown(0)
            };
            previousJobHandle = spawnJob.Schedule(previousJobHandle);
        }

        // Simulate
        if (PowderGame.simulate)
        {
            var simulateJob = new SimulateJob()
            {
                powders          = m_PowderGroup.powders,
                positions        = m_PowderGroup.positions,
                hashMap          = positionsMap,
                rand             = Rand.Create(),
                entities         = m_PowderGroup.entities,
                cmdBuffer        = m_Barrier.CreateCommandBuffer(),
                toDeleteEntities = toDeleteEntities
            };
            previousJobHandle = simulateJob.Schedule(m_PowderGroup.Length, 64, previousJobHandle);
        }

        var deleteEntitiesJob = new DeleteEntitiesJob()
        {
            entities         = m_PowderGroup.entities,
            cmdBuffer        = m_Barrier.CreateCommandBuffer(),
            toDeleteEntities = toDeleteEntities
        };

        previousJobHandle = deleteEntitiesJob.Schedule(m_PowderGroup.Length, 64, previousJobHandle);

        inputDeps = previousJobHandle;

        return(inputDeps);
    }
예제 #2
0
 // Update is called once per frame and is needed here to check if the job is finished
 void Update()
 {
     if (myJob != null)
     {
         if (myJob.Update())
         {
             // Alternative to the OnFinished callback
             finishJob();
             myJob = null;
         }
     }
 }
예제 #3
0
    //Doing the work. Creates a new job and runs it.
    void prepareAndStartJob()
    {
        //Showing Loading Indicator
        LoadingIndicator.SetActive(true);

        //First create a new simulatejob to run this on a seperate thread
        myJob = new SimulateJob();
        //Now set the "simulator" to the QiskitSimulator. (If UseReal is set to true, a real backend is used, and your Token needs to be provided).
        myJob.Simulator = new QiskitSimulator(1000, UseReal, Token);
        //Creating a circuit from the red channel of the provided texture (for black and white image any of the 3 color channels is ok).
        myJob.Circuit = QuantumImageCreator.GetCircuitDirect(Input, ColorChannel.R);
        //applying additional manipulation to the circuit
        applyPartialQ(myJob.Circuit, Rotation);
        //run the job, meaning start the simulation (or the call to the backend)
        myJob.Start();
    }
예제 #4
0
    void SimulateJobs()
    {
        NativeArray <Vector3> vertsNative = new NativeArray <Vector3>(verts, Allocator.TempJob);
        var job = new SimulateJob
        {
            nativeVerts = vertsNative,
            multiplier  = multiplier,
            scale       = scale,
            flowSpeed   = flowSpeed,
            time        = Time.time
        };
        var jobHandle = job.Schedule(vertsNative.Length, 250);

        jobHandle.Complete();

        vertsNative.CopyTo(verts);
        GetComponent <MeshFilter>().mesh.vertices = verts;
        vertsNative.Dispose();
    }
예제 #5
0
    //Doing the work. Creates a new job and runs it.
    void prepareAndStartJob()
    {
        if (DeviceName.Length < 5)
        {
            DeviceName = "ibmq_16_melbourne";
        }

        //Showing Loading Indicator
        LoadingIndicator.SetActive(true);

        //First create a new simulatejob to run this on a seperate thread
        myJob = new SimulateJob();
        //Now set the "simulator" to the QiskitSimulator. (If UseReal is set to true, a real backend is used, and your Token needs to be provided).
        myJob.Simulator = new QiskitSimulator(NumberOfShots, UseReal, Token, DeviceName, DontStartPython, UseInternalDevice);
        //Creating a circuit from the red channel of the provided texture (for black and white image any of the 3 color channels is ok).
        myJob.Circuit = QuantumImageCreator.GetCircuitDirect(Input, ColorChannel.R);
        //applying additional manipulation to the circuit
        applyPartialQ(myJob.Circuit, QuantumBlurRotation);
        //run the job, meaning start the simulation (or the call to the backend)
        myJob.Start();
    }