Beispiel #1
0
    public void Update()
    {
        if (!working)
        {
            return;
        }

        if (!retrievedData)
        {
            AsyncTextureReader.Status status = AsyncTextureReader.RetrieveBufferData(appendBuffer, data);
            if (status == AsyncTextureReader.Status.Succeeded)
            {
                retrievedData = true;
            }
        }
        if (!retrievedCount)
        {
            AsyncTextureReader.Status status = AsyncTextureReader.RetrieveBufferData(argBuffer, count);
            if (status == AsyncTextureReader.Status.Succeeded)
            {
                retrievedCount = true;
            }
        }
        if (retrievedData && retrievedCount)
        {
            MeshData data = BuildMeshData(1.0f);
            Mesh     mesh = data.CreateMesh();
            mf.mesh = mesh;
            working = false;
        }
    }
Beispiel #2
0
    public void PathCompute()
    {
        float startTime = Time.realtimeSinceStartup;

        unfulfilledData[0] = 0;
        unfulfilledBuffer.SetData(unfulfilledData);

        int runsThisPass = 0;

        do
        {
            if (AtoB)
            {
                shader.SetBuffer(PathSolverHandle, "pathBufferFrom", pathBufferA);
                shader.SetBuffer(PathSolverHandle, "pathBufferTo", pathBufferB);
            }
            else
            {
                shader.SetBuffer(PathSolverHandle, "pathBufferFrom", pathBufferB);
                shader.SetBuffer(PathSolverHandle, "pathBufferTo", pathBufferA);
            }

            shader.Dispatch(PathSolverHandle, flowWidth / 8, flowHeight / 8, 1);
            currentRuns++;
            runsThisPass++;

            AtoB = !AtoB;
        } while (Time.realtimeSinceStartup - startTime < pathshare && runsThisPass < MaxRunsPerPass);

        if (currentRuns > runsBeforeCheck)
        {
            if (!waitingForRetrieval)
            {
                AsyncTextureReader.RequestBufferData(unfulfilledBuffer);
                waitingForRetrieval = true;
            }
            else
            {
                AsyncTextureReader.Status status = AsyncTextureReader.RetrieveBufferData(unfulfilledBuffer, unfulfilledData);
                if (status == AsyncTextureReader.Status.Succeeded)
                {
                    waitingForRetrieval = false;
                    if (unfulfilledData[0] == 0)
                    {
                        fulfilled = true;
                    }
                }
            }
        }
    }
Beispiel #3
0
    private void GetData()
    {
#if UNITY_5_5_OR_NEWER
        if (_floats == null)
        {
            return;
        }

        AsyncTextureReader.Status status = AsyncTextureReader.RetrieveBufferData(_buffer, _floats);
        //Debug.LogFormat("Frame: {0}; Retrieve Buffer Status: {1}", Time.frameCount, status);
        if (status == AsyncTextureReader.Status.Succeeded)
        {
            Debug.LogFormat("Buffer Data: {0}; {1}; {2}; {3}", _floats[0], _floats[1], _floats[2], _floats[3]);
            _floats = null;
        }
#endif
    }
    public void Update()
    {
        if (free)
        {
            return;
        }


#if UNITY_ASYNC
        if (!retrievedData)
        {
            if (appendRequest.hasError)
            {
                Debug.Log("Append Request Error");
            }
            else if (appendRequest.done)
            {
                data          = appendRequest.GetData <float>();
                retrievedData = true;
            }
        }

        if (!retrievedCount)
        {
            if (argRequest.hasError)
            {
                Debug.Log("Arg Request Error");
            }
            else if (argRequest.done)
            {
                count          = argRequest.GetData <int>();
                retrievedCount = true;
            }
        }
#else
        if (!retrievedData)
        {
            AsyncTextureReader.Status status = AsyncTextureReader.RetrieveBufferData(appendBuffer, data);
            if (status == AsyncTextureReader.Status.Succeeded)
            {
                retrievedData = true;
            }
        }
        if (!retrievedCount)
        {
            AsyncTextureReader.Status status = AsyncTextureReader.RetrieveBufferData(argBuffer, count);
            if (status == AsyncTextureReader.Status.Succeeded)
            {
                retrievedCount = true;
            }
        }
#endif

        if (retrievedData && retrievedCount)
        {
            bool lastCheck = cur.lastCheck();
            if (!forgetNextResult && lastCheck)
            {
                cur.callback(BuildMeshData(), cur.id);
            }
            if (forgetNextResult)
            {
                Debug.Log("forgot last");
            }
            if (!lastCheck)
            {
                //Debug.Log("last check fail post");
            }

            free = true;
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (operating)
        {
            if (!fulfilled)
            {
                PathCompute();
            }
            else if (!pathreturn)
            {
                if (!waitingForRetrieval)
                {
                    if (AtoB)
                    {
                        AsyncTextureReader.RequestBufferData(pathBufferB);
                    }
                    else
                    {
                        AsyncTextureReader.RequestBufferData(pathBufferA);
                    }
                    waitingForRetrieval = true;
                }
                else
                {
                    AsyncTextureReader.Status status;

                    if (AtoB)
                    {
                        status = AsyncTextureReader.RetrieveBufferData(pathBufferB, pathDataRaw);
                    }
                    else
                    {
                        status = AsyncTextureReader.RetrieveBufferData(pathBufferA, pathDataRaw);
                    }

                    if (status == AsyncTextureReader.Status.Succeeded)
                    {
                        Debug.Log(Time.realtimeSinceStartup - computestarttime);
                        waitingForRetrieval = false;
                        pathreturn          = true;

                        for (int i = 0; i < pathData.Length; i++)
                        {
                            pathData[i] = new pathInfo(System.BitConverter.ToUInt32(pathDataRaw, i * 16), System.BitConverter.ToInt32(pathDataRaw, i * 16 + 4), System.BitConverter.ToInt32(pathDataRaw, i * 16 + 8), System.BitConverter.ToUInt32(pathDataRaw, i * 16 + 12));
                            //debugArray[i].transform.localScale = new Vector3(1.0f, 1.0f, pathData[i].cost / 10.0f);
                        }

                        if (activePath == 1)
                        {
                            activePath = 0;
                        }
                        else
                        {
                            activePath = 1;
                        }

                        shader.SetInt("activePath", activePath);

                        operating = false;
                        //Debug.Log("hey now");
                    }
                }
            }
        }
        else
        {
            //edit
            if (edits.Count > 0)
            {
                while (edits.Count > 0)
                {
                    for (int i = 0; i < edits[0].blocks.Count; i++)
                    {
                        if (edits[0].blocks[i].x > 0 && edits[0].blocks[i].x < flowWidth && edits[0].blocks[i].y > 0 && edits[0].blocks[i].y < flowHeight)
                        {
                            difficultyData[edits[0].blocks[i].x + edits[0].blocks[i].y * flowWidth] = edits[0].newVal;
                            obstacles[edits[0].blocks[i].x, edits[0].blocks[i].y].SetActive(edits[0].newVal == 0u);
                        }
                    }
                    edits.RemoveAt(0);
                }

                difficultyBuffer.SetData(difficultyData);

                NewDest(lastTarget.x, lastTarget.y);
            }
        }
    }