public void Initialize(List <GameLine> lines)
        {
            Clear();
            LineVertex[] vertices = new LineVertex[lines.Count * linesize];
            var          redverts = new AutoArray <GenericVertex>((lines.Count / 2) * 3);

            System.Threading.Tasks.Parallel.For(0, lines.Count, (idx) =>
            {
                var line      = (StandardLine)lines[idx];
                var lineverts = CreateDecorationLine(line, line.Color);
                for (int i = 0; i < lineverts.Length; i++)
                {
                    vertices[idx * 6 + i] = lineverts[i];
                }
            });
            var dict = _linebuffer.AddLines(lines, vertices);

            _lines = dict;
        }
        /// <summary>
        /// Clears the renderer and initializes it with new lines.
        /// </summary>
        public void InitializeTrack(Track track)
        {
            List <GameLine> scenery = new List <GameLine>(track.SceneryLines);
            List <GameLine> phys    = new List <GameLine>(track.BlueLines + track.RedLines);
            var             sorted  = track.GetSortedLines();

            using (_sync.AcquireWrite())
            {
                _lineactions.Clear();
                _physvbo.Clear();
                _sceneryvbo.Clear();
                _decorator.Clear();
                _physlines.Clear();
                _scenerylines.Clear();
                _physlines.Clear();
                RequiresUpdate = true;

                for (int i = 0; i < sorted.Length; i++)
                {
                    var line = sorted[i];
                    if (line.Type == LineType.Scenery)
                    {
                        scenery.Add(line);
                    }
                    else
                    {
                        phys.Add(line);
                    }
                }
                if (scenery.Count != 0)
                {
                    LineVertex[] sceneryverts = new LineVertex[scenery.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, scenery.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(scenery[index], false));
                        foreach (var vert in verts)
                        {
                            sceneryverts[index * linesize + counter++] = vert;
                        }
                    });
                    _scenerylines = _sceneryvbo.AddLines(
                        scenery,
                        sceneryverts);
                }
                if (phys.Count != 0)
                {
                    LineVertex[] physverts = new LineVertex[phys.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, phys.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(phys[index], false));
                        foreach (var vert in verts)
                        {
                            physverts[index * linesize + counter++] = vert;
                        }
                    });
                    _physlines = _physvbo.AddLines(
                        phys,
                        physverts);
                    _decorator.Initialize(phys);
                }
                RequiresUpdate = true;
            }
        }
Пример #3
0
        /// <summary>
        /// Clears the renderer and initializes it with new lines.
        /// </summary>
        public void InitializeTrack(Track track)
        {
            AutoArray <GameLine> scenery = new AutoArray <GameLine>(track.SceneryLines);

            scenery.UnsafeSetCount(track.SceneryLines);
            AutoArray <GameLine> phys  = new AutoArray <GameLine>(track.BlueLines);
            AutoArray <GameLine> accel = new AutoArray <GameLine>(track.RedLines);
            var sorted = track.GetSortedLines();

            using (_sync.AcquireWrite())
            {
                _lineactions.Clear();
                _physvbo.Clear();
                _sceneryvbo.Clear();
                _accelvbo.Clear();
                _bluedecorator.Clear();
                _acceldecorator.Clear();
                _physlines.Clear();
                _scenerylines.Clear();
                _accellines.Clear();
                RequiresUpdate = true;

                int scenerycount = 0;
                for (int i = 0; i < sorted.Length; i++)
                {
                    var line = sorted[i];

                    switch (line.Type)
                    {
                    case LineType.Scenery:
                        scenery.unsafe_array[scenery.Count - (1 + scenerycount++)] = line;
                        break;

                    case LineType.Blue:
                        phys.Add(line);
                        break;

                    case LineType.Red:
                        accel.Add(line);
                        break;
                    }
                }

                Debug.Assert(scenerycount == scenery.Count,
                             "Predicted scenery count was not accurate");
                if (scenery.Count != 0)
                {
                    LineVertex[] sceneryverts = new LineVertex[scenery.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, scenery.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(scenery[index], false));
                        foreach (var vert in verts)
                        {
                            sceneryverts[index * linesize + counter++] = vert;
                        }
                    });
                    _scenerylines = _sceneryvbo.AddLines(
                        scenery,
                        sceneryverts);
                }
                if (phys.Count != 0)
                {
                    LineVertex[] physverts = new LineVertex[phys.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, phys.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(phys[index], false));
                        foreach (var vert in verts)
                        {
                            physverts[index * linesize + counter++] = vert;
                        }
                    });
                    _physlines = _physvbo.AddLines(
                        phys,
                        physverts);
                    _bluedecorator.Initialize(phys);
                }
                if (accel.Count != 0)
                {
                    LineVertex[] accelverts = new LineVertex[accel.Count * linesize];
                    System.Threading.Tasks.Parallel.For(0, accel.Count, (index) =>
                    {
                        int counter = 0;
                        var verts   = (GenerateLine(accel[index], false));
                        foreach (var vert in verts)
                        {
                            accelverts[index * linesize + counter++] = vert;
                        }
                    });
                    _accellines = _accelvbo.AddLines(
                        accel,
                        accelverts);
                    _acceldecorator.Initialize(accel);
                }
                RequiresUpdate = true;
            }
        }