mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 23:47:16 -05:00
More rendering optimizations
This commit is contained in:
parent
3e1c52449b
commit
8c4646d57a
@ -29,6 +29,6 @@ namespace OpenDiablo2.Common.Interfaces
|
|||||||
void Draw(ISprite sprite, int frame);
|
void Draw(ISprite sprite, int frame);
|
||||||
void Draw(ISprite sprite, int xSegments, int ySegments, int offset);
|
void Draw(ISprite sprite, int xSegments, int ySegments, int offset);
|
||||||
void Draw(ILabel label);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ namespace OpenDiablo2.Core
|
|||||||
sw.Start();
|
sw.Start();
|
||||||
while (getRenderWindow().IsRunning)
|
while (getRenderWindow().IsRunning)
|
||||||
{
|
{
|
||||||
while (sw.ElapsedMilliseconds < 16)
|
while (sw.ElapsedMilliseconds < 40)
|
||||||
Thread.Sleep(1); // Oh yes we did
|
Thread.Sleep((int)Math.Min(1, 40 -sw.ElapsedMilliseconds)); // The original runs at about 25 fps.
|
||||||
|
|
||||||
var ms = sw.ElapsedMilliseconds;
|
var ms = sw.ElapsedMilliseconds;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ namespace OpenDiablo2.Core.GameState_
|
|||||||
public void Initialize(string characterName, eHero hero)
|
public void Initialize(string characterName, eHero hero)
|
||||||
{
|
{
|
||||||
sceneManager.ChangeScene("Game");
|
sceneManager.ChangeScene("Game");
|
||||||
ChangeMap(eLevelId.Act5_Baal_Entrance);
|
ChangeMap(eLevelId.Act1_Town);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeMap(eLevelId levelId)
|
public void ChangeMap(eLevelId levelId)
|
||||||
@ -62,7 +62,7 @@ namespace OpenDiablo2.Core.GameState_
|
|||||||
var random = new Random();
|
var random = new Random();
|
||||||
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
||||||
MapName = level.Name;
|
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);
|
MapData = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
|
||||||
getMapEngine().NotifyMapChanged();
|
getMapEngine().NotifyMapChanged();
|
||||||
}
|
}
|
||||||
|
@ -97,19 +97,23 @@ namespace OpenDiablo2.Core.Map_Engine
|
|||||||
if (visualX < -160 || visualX > 800 || visualY < -80 || visualY > 600)
|
if (visualX < -160 || visualX > 800 || visualY < -80 || visualY > 600)
|
||||||
continue;
|
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)
|
public void Update(long ms)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -277,17 +277,8 @@ namespace OpenDiablo2.SDL2_
|
|||||||
SDL.SDL_RenderCopy(renderer, lbl.texture, IntPtr.Zero, ref destRect);
|
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;
|
MPQDT1Tile tile = null;
|
||||||
for (int i = 0; i < mapData.DT1s.Count(); i++)
|
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 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 srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = frameSize.Width, h = frameSize.Height };
|
||||||
var frameSizeMax = frameSize.Width * 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
|
try
|
||||||
{
|
{
|
||||||
UInt32* data = (UInt32*)pixels;
|
UInt32* data = (UInt32*)pixels;
|
||||||
@ -318,24 +313,27 @@ namespace OpenDiablo2.SDL2_
|
|||||||
|
|
||||||
foreach (var block in tile.Blocks)
|
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);
|
try
|
||||||
|
|
||||||
for (int xx = 0; xx < 32; xx++)
|
|
||||||
{
|
{
|
||||||
index++;
|
var color = palette.Colors[colorIndex];
|
||||||
|
|
||||||
if (index > frameSizeMax)
|
|
||||||
continue;
|
|
||||||
if (index < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var color = palette.Colors[block.PixelData[xx + (yy * 32)]];
|
|
||||||
|
|
||||||
if ((color & 0xFFFFFF) > 0)
|
if ((color & 0xFFFFFF) > 0)
|
||||||
data[index] = color;
|
data[index] = color;
|
||||||
|
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
xx++;
|
||||||
|
if (xx == 32)
|
||||||
|
{
|
||||||
|
index -= 32;
|
||||||
|
index += pitchChange;
|
||||||
|
xx = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ namespace OpenDiablo2.Scenes
|
|||||||
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalk, Palettes.Fechar, new Point(300, 335)),
|
BackWalkSprite = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalk, Palettes.Fechar, new Point(300, 335)),
|
||||||
BackWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalkOverlay, Palettes.Fechar, new Point(300, 335)),
|
BackWalkSpriteOverlay = renderWindow.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalkOverlay, Palettes.Fechar, new Point(300, 335)),
|
||||||
SelectionBounds = new Rectangle(265, 220, 55, 175),
|
SelectionBounds = new Rectangle(265, 220, 55, 175),
|
||||||
ForwardWalkTimeMs = 3000,
|
ForwardWalkTimeMs = 2000,
|
||||||
BackWalkTimeMs = 1500,
|
BackWalkTimeMs = 1500,
|
||||||
};
|
};
|
||||||
heroRenderInfo[eHero.Necromancer].ForwardWalkSpriteOverlay.Blend = true;
|
heroRenderInfo[eHero.Necromancer].ForwardWalkSpriteOverlay.Blend = true;
|
||||||
|
@ -12,6 +12,21 @@
|
|||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<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>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@ -44,7 +59,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<OutputPath>bin\x64\Release\</OutputPath>
|
<OutputPath>bin\x64\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>
|
||||||
|
</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
@ -111,5 +127,17 @@
|
|||||||
<Name>OpenDiablo2.SDL2</Name>
|
<Name>OpenDiablo2.SDL2</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</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" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user