public void Render( ViewRenderArguments args )
        {
            var device = args.Device;

            foreach ( var entry in Texture ) {
                if ( entry.Value.IB.Count == 0 ) return;

                if ( entry.Value.RealVB==null || entry.Value.RealVB.Description.SizeInBytes < Vertex.Size * entry.Value.VB.Count ) {
                    using ( entry.Value.RealVB ) {}
                    using ( entry.Value.RealIB ) {}
                    entry.Value.RealVB = new VertexBuffer( device, Vertex.Size * entry.Value.VB.Count, Usage.None, Vertex.FVF, Pool.Managed );
                    entry.Value.RealIB = new IndexBuffer(  device, sizeof(uint)* entry.Value.IB.Count, Usage.None, Pool.Managed, false );
                }

                var vb = entry.Value.RealVB.Lock(0,0,LockFlags.None);
                vb.WriteRange(entry.Value.VB.ToArray());
                entry.Value.RealVB.Unlock();

                var ib = entry.Value.RealIB.Lock(0,0,LockFlags.None);
                ib.WriteRange(entry.Value.IB.ToArray());
                entry.Value.RealIB.Unlock();

                device.SetTexture( 0, entry.Key.Texture );
                device.VertexFormat = entry.Value.RealVB.Description.FVF;
                device.SetStreamSource( 0, entry.Value.RealVB, 0, Vertex.Size );
                device.Indices = entry.Value.RealIB;
                device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, entry.Value.VB.Count, 0, entry.Value.VB.Count/2 );

                entry.Value.IB.Clear();
                entry.Value.VB.Clear();
            }
        }
        public void Render( ViewRenderArguments args )
        {
            if ( Indicies.Count == 0 ) return;

            var device = args.Device;

            if ( VB==null || VB.Description.SizeInBytes < Vertex.Size * Verticies.Count ) {
                using ( VB ) {}
                using ( IB ) {}
                VB = new VertexBuffer( device, Vertex.Size * Verticies.Count, Usage.None, Vertex.FVF, Pool.Managed );
                IB = new IndexBuffer(  device, sizeof(uint)* Indicies .Count, Usage.None, Pool.Managed, false );
            }

            var vb = VB.Lock(0,0,LockFlags.None);
            vb.WriteRange(Verticies.ToArray());
            VB.Unlock();

            var ib = IB.Lock(0,0,LockFlags.None);
            ib.WriteRange(Indicies.ToArray());
            IB.Unlock();

            device.SetTexture(0,null);
            device.Indices = IB;
            device.VertexFormat = Vertex.FVF;
            device.SetStreamSource(0,VB,0,Vertex.Size);
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,Verticies.Count,0,Verticies.Count/2);

            Indicies.Clear();
            Verticies.Clear();
        }
Пример #3
0
        public void Render( ViewRenderArguments args )
        {
            var device = args.Device;
            device.SetTransform( TransformState.View, Matrix.Scaling(Zoom,Zoom,1) * Matrix.Translation( args.Form.ClientSize.Width/2, args.Form.ClientSize.Height/2, 0 ) );

            int z = CameraFocusPosition.Z;

            // TODO: Better view range calcs.
            // These are inclusve.
            int ymin = Math.Max(0,CameraFocusPosition.Y-50);
            int xmin = Math.Max(0,CameraFocusPosition.X-50);
            int xmax = Math.Min(LocalMap.Width -1,CameraFocusPosition.X+50);
            int ymax = Math.Min(LocalMap.Height-1,CameraFocusPosition.Y+50);

            for ( int tile_y=ymin ; tile_y<=ymax ; ++tile_y )
            {
                for ( int tile_x=xmin ; tile_x<=xmax ; ++tile_x )
                {
                    // relative coordinates (still in tiles):
                    var ex = tile_x-CameraFocusPosition.X;
                    var ey = tile_y-CameraFocusPosition.Y;

                    // render location:
                    var rect = new Rectangle(TileSize.Width*ex,TileSize.Height*ey,TileSize.Width,TileSize.Height);

                    var tt = GetTileType(new IVector3(tile_x,tile_y,z));

                    int ground_z = z;
                    while ( ground_z>=0 && GetTileType(new IVector3(tile_x,tile_y,ground_z)) == TileType.Air ) --ground_z;
                    if ( ground_z < 0 ) ground_z -= 9001;

                    if ( z!=ground_z ) {
                        int atmos_i = Math.Min(z-ground_z-1,AtmosphericLayers.Count-1);
                        AtmosphereRenderer2D.Add( rect, AtmosphericLayers[atmos_i] );
                    }

                    Assets assets = args.Assets;
                    if (ground_z >= 0)
                    {
                        Tile tile = LocalMap[tile_x, tile_y, ground_z];
                        if (assets.TextureForMaterial(tile.Declaration.Material) != null)
                        {
                            BatchSpriteRenderer.Add(assets.TextureForMaterial(tile.Declaration.Material), rect);
                        }
                    }
                }
            }

            foreach ( var entity in GetVisibleEntities() ) {
                // relative coordinates (still in tiles):
                var ex = entity.Position.X-CameraFocusPosition.X;
                var ey = entity.Position.Y-CameraFocusPosition.Y;

                // render location:
                var rect = new Rectangle(TileSize.Width*ex,TileSize.Height*ey,TileSize.Width,TileSize.Height);

                if ( entity.Position.Z <= CameraFocusPosition.Z ) switch ( entity.EntityType ) {
                case EntityType.Guy:
                    BatchSpriteRenderer.Add( args.Assets.OrxyCaveMan  , rect );
                    break;
                case EntityType.Gal:
                    BatchSpriteRenderer.Add( args.Assets.OrxyCaveWoman, rect );
                    break;
                }
            }

            BatchSpriteRenderer.Render(args);
            AtmosphereRenderer2D.Render(args);
        }