1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-20 22:25:24 +00:00

More rendering optimizations

This commit is contained in:
Tim Sarbin 2018-11-25 09:42:39 -05:00
parent 3e1c52449b
commit 8c4646d57a
7 changed files with 70 additions and 40 deletions

View File

@ -29,6 +29,6 @@ namespace OpenDiablo2.Common.Interfaces
void Draw(ISprite sprite, int frame);
void Draw(ISprite sprite, int xSegments, int ySegments, int offset);
void Draw(ILabel label);
void DrawMapCell(int xCell, int yCell, int xPixel, int yPixel, MPQDS1 mapData);
void DrawMapCell(int xCell, int yCell, int xPixel, int yPixel, MPQDS1 mapData, int main_index, int sub_index, Palette palette);
}
}

View File

@ -90,8 +90,8 @@ namespace OpenDiablo2.Core
sw.Start();
while (getRenderWindow().IsRunning)
{
while (sw.ElapsedMilliseconds < 16)
Thread.Sleep(1); // Oh yes we did
while (sw.ElapsedMilliseconds < 40)
Thread.Sleep((int)Math.Min(1, 40 -sw.ElapsedMilliseconds)); // The original runs at about 25 fps.
var ms = sw.ElapsedMilliseconds;

View File

@ -41,7 +41,7 @@ namespace OpenDiablo2.Core.GameState_
public void Initialize(string characterName, eHero hero)
{
sceneManager.ChangeScene("Game");
ChangeMap(eLevelId.Act5_Baal_Entrance);
ChangeMap(eLevelId.Act1_Town);
}
public void ChangeMap(eLevelId levelId)
@ -62,7 +62,7 @@ namespace OpenDiablo2.Core.GameState_
var random = new Random();
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
MapName = level.Name;
Act = Convert.ToInt32(mapNames.First().ElementAt(3));
Act = Convert.ToInt32(mapNames.First().Substring(3, 1));
MapData = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
getMapEngine().NotifyMapChanged();
}

View File

@ -97,19 +97,23 @@ namespace OpenDiablo2.Core.Map_Engine
if (visualX < -160 || visualX > 800 || visualY < -80 || visualY > 600)
continue;
RenderFloorCell(x, y, ((x - y) * 80) - cOffX, ((x + y) * 40) - cOffY);
var floorLayer = gameState.MapData.FloorLayers[0];
var floor = floorLayer.Props[x + (y * gameState.MapData.Width)];
if (floor.Prop1 == 0)
return;
var sub_index = floor.Prop2;
var main_index = (floor.Prop3 >> 4) + ((floor.Prop4 & 0x03) << 4);
if (x < 0 || y < 0 || x >= gameState.MapData.Width || y >= gameState.MapData.Height)
continue;
renderWindow.DrawMapCell(x, y, ((x - y) * 80) - cOffX, ((x + y) * 40) - cOffY, gameState.MapData, main_index, sub_index, gameState.CurrentPalette);
}
}
private void RenderFloorCell(int x, int y, int xp, int yp)
{
if (x < 0 || y < 0 || x >= gameState.MapData.Width || y >= gameState.MapData.Height)
return;
renderWindow.DrawMapCell(x, y, xp, yp, gameState.MapData);
}
public void Update(long ms)
{

View File

@ -277,17 +277,8 @@ namespace OpenDiablo2.SDL2_
SDL.SDL_RenderCopy(renderer, lbl.texture, IntPtr.Zero, ref destRect);
}
public unsafe void DrawMapCell(int xCell, int yCell, int xPixel, int yPixel, MPQDS1 mapData)
public unsafe void DrawMapCell(int xCell, int yCell, int xPixel, int yPixel, MPQDS1 mapData, int main_index, int sub_index, Palette palette)
{
var floorLayer = mapData.FloorLayers.First();
var floor = floorLayer.Props[xCell + (yCell * mapData.Width)];
if (floor.Prop1 == 0)
return;
var palette = paletteProvider.PaletteTable[$"ACT{mapData.Act}"];
var sub_index = floor.Prop2;
var main_index = (floor.Prop3 >> 4) + ((floor.Prop4 & 0x03) << 4);
MPQDT1Tile tile = null;
for (int i = 0; i < mapData.DT1s.Count(); i++)
@ -307,7 +298,11 @@ namespace OpenDiablo2.SDL2_
var frameSize = new Size(tile.Width, Math.Abs(tile.Height));
var srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = frameSize.Width, h = frameSize.Height };
var frameSizeMax = frameSize.Width * frameSize.Height;
SDL.SDL_LockTexture(cellTexture, ref srcRect, out IntPtr pixels, out int pitch);
if (SDL.SDL_LockTexture(cellTexture, IntPtr.Zero, out IntPtr pixels, out int pitch) != 0)
{
log.Error("Could not lock texture for map rendering");
return;
}
try
{
UInt32* data = (UInt32*)pixels;
@ -318,24 +313,27 @@ namespace OpenDiablo2.SDL2_
foreach (var block in tile.Blocks)
{
for (int yy = 0; yy < 32; yy++)
var index = block.PositionX + ((block.PositionY) * pitchChange);
var xx = 0;
foreach (var colorIndex in block.PixelData)
{
var index = block.PositionX + ((block.PositionY + yy) * pitchChange);
for (int xx = 0; xx < 32; xx++)
try
{
index++;
if (index > frameSizeMax)
continue;
if (index < 0)
continue;
var color = palette.Colors[block.PixelData[xx + (yy * 32)]];
var color = palette.Colors[colorIndex];
if ((color & 0xFFFFFF) > 0)
data[index] = color;
} finally
{
index++;
xx++;
if (xx == 32)
{
index -= 32;
index += pitchChange;
xx = 0;
}
}
}
}

View File

@ -130,7 +130,7 @@ namespace OpenDiablo2.Scenes
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalk, Palettes.Fechar, new Point(300, 335)),
BackWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalkOverlay, Palettes.Fechar, new Point(300, 335)),
SelectionBounds = new Rectangle(265, 220, 55, 175),
ForwardWalkTimeMs = 3000,
ForwardWalkTimeMs = 2000,
BackWalkTimeMs = 1500,
};
heroRenderInfo[eHero.Necromancer].ForwardWalkSpriteOverlay.Blend = true;

View File

@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -44,7 +59,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>
</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
@ -111,5 +127,17 @@
<Name>OpenDiablo2.SDL2</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>