public static TrackReader AcquireRead(ResourceSync sync, Track track, EditorGrid cells)
 {
     return(new TrackReader(sync.AcquireRead(), track)
     {
         _editorcells = cells
     });
 }
        public void Initialize(AutoArray <GameLine> lines)
        {
            Clear();
            ResourceSync initsync = new ResourceSync();

            GenericVertex[] vertices = new GenericVertex[lines.Count * wellsize];
            System.Threading.Tasks.Parallel.For(0, lines.Count, (idx) =>
            {
                var line = (StandardLine)lines[idx];
                var well = GetWell(line);
                for (int i = 0; i < wellsize; i++)
                {
                    vertices[idx * wellsize + i] = well[i];
                }
                try
                {
                    initsync.UnsafeEnterWrite();
                    _lines.Add(line.ID, idx * wellsize);
                }
                finally
                {
                    initsync.UnsafeExitWrite();
                }
            });
            _vertexcounter = vertices.Length;
            _vbo.Bind();
            EnsureVBOSize(vertices.Length, false);
            _vbo.SetData(vertices, 0, 0, vertices.Length);
            _vbo.Unbind();
        }
Example #3
0
        public void Initialize(List <RedLine> lines)
        {
            Clear();
            if (lines.Count == 0)
            {
                return;
            }
            //max size for init
            var          redshapes = new GenericVertex[lines.Count * ShapeSize * 3][];
            ResourceSync initsync  = new ResourceSync();
            int          vertcount = 0;

            System.Threading.Tasks.Parallel.For(0, lines.Count,
                                                (idx) =>
            {
                var acc        = GetAccelDecor(lines[idx]);
                redshapes[idx] = acc;
                System.Threading.Interlocked.Add(ref vertcount, acc.Length);
            });
            GenericVertex[] verts = new GenericVertex[vertcount];
            _indices.EnsureCapacity(vertcount);
            _indices.UnsafeSetCount(vertcount);
            int shapepos = 0;

            for (int idx = 0; idx < lines.Count; idx++)
            {
                var acc   = redshapes[idx];
                var entry = new accelentry()
                {
                    start  = shapepos,
                    shapes = acc.Length / ShapeSize
                };
                for (int i = 0; i < acc.Length; i++)
                {
                    verts[shapepos] = acc[i];
                    _indices.unsafe_array[shapepos] = shapepos;
                    shapepos++;
                }
                _lookup.Add(lines[idx].ID, entry);
            }


            _vertcount = verts.Length;
            _accelbuffer.Bind();
            EnsureVBOSize(verts.Length, false);
            _accelbuffer.SetData(verts, 0, 0, verts.Length);
            _accelbuffer.Unbind();
            _accelibo.Bind();
            EnsureIBOSize(_indices.Count, false);
            _accelibo.SetData(_indices.unsafe_array, 0, 0, _indices.Count);
            _accelibo.Unbind();
        }
        public TrackRenderer()
        {
            _sync                  = new ResourceSync();
            _lineactions           = new Queue <Tuple <LineActionType, GameLine> >();
            _physlines             = new Dictionary <int, int>();
            _scenerylines          = new Dictionary <int, int>();
            _decorator             = new LineDecorator();
            _physvbo               = new LineRenderer(Shaders.LineShader);
            _physvbo.OverrideColor = Constants.DefaultLineColor;

            _sceneryvbo = new LineRenderer(Shaders.LineShader);
            _sceneryvbo.OverrideColor = Color.Black;
        }
Example #5
0
 public static TrackWriter AcquireWrite(
     ResourceSync sync,
     Track track,
     SimulationRenderer renderer,
     UndoManager undo,
     Timeline timeline,
     EditorGrid cells)
 {
     return(new TrackWriter(sync.AcquireWrite(), track)
     {
         _undo = undo,
         _renderer = renderer,
         _timeline = timeline,
         _editorcells = cells
     });
 }