From d3a718d8f689a0d753f7235d8d2dd9219a59aef3 Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Sat, 24 Nov 2018 20:34:21 -0500 Subject: [PATCH] Cleaned up the rendering some. --- OpenDiablo2.SDL2/SDL2Sprite.cs | 23 ++++------------------- OpenDiablo2.Scenes/Game.cs | 2 +- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/OpenDiablo2.SDL2/SDL2Sprite.cs b/OpenDiablo2.SDL2/SDL2Sprite.cs index d973de05..4d56642c 100644 --- a/OpenDiablo2.SDL2/SDL2Sprite.cs +++ b/OpenDiablo2.SDL2/SDL2Sprite.cs @@ -20,7 +20,6 @@ namespace OpenDiablo2.SDL2_ public Point Location { get; set; } = new Point(); public Size FrameSize { get; set; } = new Size(); - private Point mapTileOffset = new Point(); private bool darken; public bool Darken @@ -83,14 +82,9 @@ namespace OpenDiablo2.SDL2_ FrameSize = new Size(Pow2((int)source.Frames.Max(x => x.Width)), Pow2((int)source.Frames.Max(x => x.Height))); } - private int[] idxtable = new int[] { 20, 21, 22, 23, 24, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4 }; public unsafe SDL2Sprite(IntPtr renderer, Palette palette, MPQDS1 mapData, int x, int y, eRenderCellType cellType) { this.renderer = renderer; - // TODO: Cell types - - // Floor cell types - // Todo: multiple floor layers var floorLayer = mapData.FloorLayers.First(); var floor = floorLayer.Props[x + (y * mapData.Width)]; @@ -118,23 +112,14 @@ namespace OpenDiablo2.SDL2_ throw new ApplicationException("Could not locate tile!"); - //FrameSize = new Size(tile.Width, Math.Abs(tile.Height)); + FrameSize = new Size(tile.Width, Math.Abs(tile.Height)); TotalFrames = 1; frame = 0; IntPtr pixels; int pitch; - var maxX = tile.Blocks.Max(z => z.PositionX + 32); - var maxY = tile.Blocks.Max(z => z.PositionY + 32); - var minX = tile.Blocks.Min(z => z.PositionX); - var minY = tile.Blocks.Min(z => z.PositionY); - FrameSize = new Size(Pow2(maxX - minX), Pow2(maxY - minY)); - var yDiff = Math.Abs(minY); - var xDiff = Math.Abs(maxY); - - mapTileOffset = new Point(minX, minY); texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, FrameSize.Width, FrameSize.Height); SDL.SDL_SetTextureBlendMode(texture, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); @@ -151,8 +136,8 @@ namespace OpenDiablo2.SDL2_ foreach(var block in tile.Blocks) { - var px = block.PositionX + xDiff; - var py = block.PositionY + yDiff; + var px = block.PositionX; + var py = block.PositionY; //var px = 0; //var py = 0; @@ -181,7 +166,7 @@ namespace OpenDiablo2.SDL2_ internal Point GetRenderPoint() { return source == null - ? new Point(Location.X + mapTileOffset.X, (Location.Y - FrameSize.Height) + mapTileOffset.Y) + ? Location : new Point(Location.X + source.Frames[Frame].OffsetX, (Location.Y - FrameSize.Height) + source.Frames[Frame].OffsetY); } diff --git a/OpenDiablo2.Scenes/Game.cs b/OpenDiablo2.Scenes/Game.cs index 7d87df85..ea4f628f 100644 --- a/OpenDiablo2.Scenes/Game.cs +++ b/OpenDiablo2.Scenes/Game.cs @@ -87,7 +87,7 @@ namespace OpenDiablo2.Scenes for (int x = 0; x < gameState.MapData.Width; x++) { testSprite[idx] = renderWindow.GenerateMapCell(gameState.MapData, x, y, eRenderCellType.Floor, gameState.CurrentPalette); - testSprite[idx].Location = new Point(((x - y) * 80) - 900, ((x + y) * 40) - 900); + testSprite[idx].Location = new Point(((x - y) * 80) - 2900, ((x + y) * 40) - 1900); idx++; } }