コード例 #1
0
ファイル: BoidsArea.cs プロジェクト: pbostrm/showcase_u_pelle
    public void CreateBounds()
    {
        DebugOutput.Shout("Starting BoundsOctrees test");
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();

        Stopwatch stopWatch2 = new Stopwatch();
        stopWatch2.Start();

        bounds = new BoundsOctree(null, 0, BoundsName, boundsSize, transform.position, maxLevels, null);
        bounds.CheckBounds(ObstacleMask);

        stopWatch2.Stop();
        DebugOutput.Shout("created bounds in " + (stopWatch2.ElapsedMilliseconds) + ", a total of " + bounds.relatedOctrees.Count + " octrees were created");

        Stopwatch stopWatch3 = new Stopwatch();
        stopWatch3.Start();
        foreach (var relatedOctree in bounds.relatedOctrees)
        {
            relatedOctree.RefreshNeighbors();
        }
        int oldCnt = bounds.relatedOctrees.Count;
        stopWatch3.Stop();

        DebugOutput.Shout("established neighbors in " + (stopWatch3.ElapsedMilliseconds));

        Stopwatch stopWatch4 = new Stopwatch();
        stopWatch4.Start();

        Stopwatch stopWatch41 = new Stopwatch();
        stopWatch41.Start();
        BoundsOctree origoBound = bounds.GetBound(true,transform.position + startingPoint);
        if (origoBound != null)
        {
            origoBound.EstablishRelations();
        }
        else
        {
            DebugOutput.Shout("Origopoint is unreachable.");
        }
        stopWatch41.Stop();

        DebugOutput.Shout("Established Relations in" + (stopWatch41.ElapsedMilliseconds));

        if (CleanUpBounds)
        {
            Stopwatch stopWatch42 = new Stopwatch();
            stopWatch42.Start();
            bounds.CleanOutUnrelated();
            foreach (var relatedOctree in bounds.relatedOctrees)
            {
                relatedOctree.RefreshNeighbors();
            }
            stopWatch42.Stop();
            DebugOutput.Shout("cleanedoutUnrelated in" + (stopWatch42.ElapsedMilliseconds));

        }

        stopWatch4.Stop();
        DebugOutput.Shout("cleaned up octrees in" + (stopWatch4.ElapsedMilliseconds)
            + ", a total of " + (oldCnt - bounds.relatedOctrees.Count) + "were eliminated");

        int cnt = 0;
        foreach (var relatedBounds in bounds.relatedOctrees)
        {
            if (relatedBounds.Empty && relatedBounds.Related)
            {
                cnt++;
            }
        }
        stopWatch.Stop();
        DebugOutput.Shout("finished bounds in " + (stopWatch.ElapsedMilliseconds)
            + ", a total of " + bounds.relatedOctrees.Count + " octrees remains, of which "
            + cnt + " is traversable");
    }