Example #1
0
        internal WorldRenderer(ModData mod, World world)
        {
            World     = world;
            TileSize  = World.Map.Grid.TileSize;
            TileScale = world.Map.Grid.Type == MapGridT.RectangularIsometric ? 1448 : 1024;
            ViewPort  = new GameViewPort(this, world.Map);
            createPaletteReference = CreatePaletteReference;

            var mapGrid = mod.Manifest.Get <MapGrid>();

            enableDepthBuffer = mapGrid.EnableDepthBuffer;

            foreach (var pal in world.TraitDict.ActorsWithTrait <ILoadsPalettes>())
            {
                pal.Trait.LoadPalettes(this);
            }

            foreach (var p in world.Players)
            {
                UpdatePalettesForPlayer(p.InternalName, p.Color, false);
            }

            palette.Initialize();

            Theater = new Theater(world.Map.Rules.TileSet);

            terrainRenderer = new TerrainRenderer(world, this);

            debugVis = Exts.Lazy(() => world.WorldActor.TraitOrDefault <DebugVisualizations>());
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="wr"></param>
        /// <param name="viewPort"></param>
        public void Draw(WorldRenderer wr, GameViewPort viewPort)
        {
            foreach (var kv in spriteLayers.Values)
            {
                kv.Draw(wr.ViewPort);
            }

            foreach (var r in wr.World.WorldActor.TraitsImplementing <IRenderOverlay>())
            {
                r.Render(wr);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewport"></param>
        public void Draw(GameViewPort viewport)
        {
            var cells = restrictToBounds ? viewport.VisibleCellsInsideBounds : viewport.AllVisibleCells;

            //only draw the rows that are visible
            //只绘制可见的行
            var firstRow = cells.CandidateMapCoords.TopLeft.V.Clamp(0, map.MapSize.Y);
            var lastRow  = (cells.CandidateMapCoords.BottomRight.V + 1).Clamp(firstRow, map.MapSize.Y);

            WarGame.Renderer.Flush();

            //Flush any visible changes to the GPU
            for (var row = firstRow; row <= lastRow; row++)
            {
                if (!dirtyRows.Remove(row))
                {
                    continue;
                }

                var rowOffset = rowStride * row;

                unsafe
                {
                    //The compiler / language spec won't let us calculate a pointer to an offset inside a generic array T[],
                    //and so we are forced to calculate the start-of-row pointer here to pass in to SetData.
                    fixed(Vertex *vPtr = &vertices[0])
                    {
                        vertexBuffer.SetData((IntPtr)(vPtr + rowOffset), rowOffset, rowStride);
                    }
                }
            }
            WarGame.Renderer.WorldSpriteRenderer.DrawVertexBuffer(vertexBuffer,
                                                                  rowStride * firstRow,
                                                                  rowStride * (lastRow - firstRow),
                                                                  PrimitiveType.TriangleList,
                                                                  Sheet,
                                                                  BlendMode);

            WarGame.Renderer.Flush();
        }