Ejemplo n.º 1
0
    public void DiscoverPointsWork()
    {
        discoveredPoints = new List<Vector3>();
        discoveredValues = new List<sbyte>();
        List<Vector3> openList = new List<Vector3>();
        openList.AddRange(pendingDiscoveryWork);
        pendingDiscoveryWork.Clear();

        TerrainGenerator tgen = new TerrainGenerator(Mathf.Pow(2, worldSize));

        Vector3 offset;
        int jindex;
        sbyte value;
        Stopwatch stopwatch1 = new Stopwatch();
        stopwatch1.Start();
        for (int i = openList.Count - 1; i >= 0; i--)
        {
            //jindex = discoveryWorkTree.GetIndexAtWorldPoint(openList[i]);
            value = discoveryWorkTree.GetValueAt(openList[i]);

            if (value == 1)
            {
                openList.RemoveAt(i);
            }
            else
            {
                //discoveryWorkTree.SetValueAt(jindex, 1);
            }
        }
        stopwatch1.Stop();
        int index = 0;

        int debugCounter = 0;
        int discoveredNonVoid = 0;

        int faultychecks = 0;
        Stopwatch stopwatch2 = new Stopwatch();
        Stopwatch stopwatch3generation = new Stopwatch();
        Stopwatch stopwatch4setvalue = new Stopwatch();
        while (index < openList.Count)
        {

            for (int i = 0; i < 6; i++)
            {
                offset = openList[index];
                offset[(int)(i / 2)] += -1 + ((i % 2) * 2);  //sixaxis
                stopwatch2.Start();

               // jindex = discoveryWorkTree.GetIndexAtWorldPointSimple(offset);
                value = discoveryWorkTree.GetValueAt(offset);
                stopwatch2.Stop();
                if (value < 1)
                {
                    stopwatch3generation.Start();
                    value = tgen.GetPointValue(offset);
                    stopwatch3generation.Stop();
                    //discoveryWorkTree.SetValueAt(jindex, value);
                    if (value > 1)
                    {
                        discoveredPoints.Add(offset);
                        discoveredValues.Add(value);
                    }

                    if (value == 1)
                    {
                        if (!openList.Contains(offset))
                        {
                            openList.Add(offset);
                        }
                    }
                    else
                    {
                        discoveredNonVoid++;
                        stopwatch4setvalue.Start();
                        discoveryWorkTree.SetValueAtPoint(offset, value);
                        stopwatch4setvalue.Stop();

                    }

                }
                else
                {
                    faultychecks++;
                }

                /*//int jindex = discoveryWorkTree.GetIndexAtWorldPointSimple(offset);
                //sbyte value = discoveryWorkTree.GetValueAt(jindex);
                if (value <= 0)
                {
                    if(!openList.Contains(offset))
                    {
                        value = tgen.GetPointValue(offset);
                        discoveredPoints.Add(offset);
                        discoveredValues.Add(value);
                        if (value == 1)
                        {
                            openList.Add(offset);
                        }
                    }
                }*/
            }
            stopwatch4setvalue.Start();

            discoveryWorkTree.SetValueAtPoint(openList[index], 1);
            stopwatch4setvalue.Stop();

            index++;

            if (discoveredNonVoid >= 40)
            {/*
                DebugOutput.Shout(openList.Count.ToString() + " and faulty checks " + faultychecks.ToString() + "indiceCount = " + discoveryWorkTree.GetIndiceCount().ToString());
                DebugOutput.Shout("cleanup: " + stopwatch1.ElapsedMilliseconds.ToString() +
                    "  getindex: " + stopwatch2.ElapsedMilliseconds.ToString() +
                "  generation: " + stopwatch3generation.ElapsedMilliseconds.ToString() +
               "  setvalue: " + stopwatch4setvalue.ElapsedMilliseconds.ToString());*/
                for (int k = index; k < openList.Count; k++)
                {
                    pendingDiscoveryWork.Add(openList[k]);
                }
                break;
            }

        }
    }