diff --git a/OpenDiablo2.Common/Interfaces/IRenderWindow.cs b/OpenDiablo2.Common/Interfaces/IRenderWindow.cs
index 0f63c9d3..184ad56d 100644
--- a/OpenDiablo2.Common/Interfaces/IRenderWindow.cs
+++ b/OpenDiablo2.Common/Interfaces/IRenderWindow.cs
@@ -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);
}
}
diff --git a/OpenDiablo2.Core/GameEngine.cs b/OpenDiablo2.Core/GameEngine.cs
index 381168e9..7e997c51 100644
--- a/OpenDiablo2.Core/GameEngine.cs
+++ b/OpenDiablo2.Core/GameEngine.cs
@@ -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;
diff --git a/OpenDiablo2.Core/GameState/GameState.cs b/OpenDiablo2.Core/GameState/GameState.cs
index 671ca532..3427489f 100644
--- a/OpenDiablo2.Core/GameState/GameState.cs
+++ b/OpenDiablo2.Core/GameState/GameState.cs
@@ -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();
}
diff --git a/OpenDiablo2.Core/Map Engine/MapEngine.cs b/OpenDiablo2.Core/Map Engine/MapEngine.cs
index 495d0e0b..5ea231ab 100644
--- a/OpenDiablo2.Core/Map Engine/MapEngine.cs
+++ b/OpenDiablo2.Core/Map Engine/MapEngine.cs
@@ -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)
{
diff --git a/OpenDiablo2.SDL2/SDL2RenderWindow.cs b/OpenDiablo2.SDL2/SDL2RenderWindow.cs
index 9727f1d8..da8b0219 100644
--- a/OpenDiablo2.SDL2/SDL2RenderWindow.cs
+++ b/OpenDiablo2.SDL2/SDL2RenderWindow.cs
@@ -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;
+ }
}
}
}
diff --git a/OpenDiablo2.Scenes/SelectHeroClass.cs b/OpenDiablo2.Scenes/SelectHeroClass.cs
index ce58fe6a..6a7aaf64 100644
--- a/OpenDiablo2.Scenes/SelectHeroClass.cs
+++ b/OpenDiablo2.Scenes/SelectHeroClass.cs
@@ -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;
diff --git a/OpenDiablo2/OpenDiablo2.csproj b/OpenDiablo2/OpenDiablo2.csproj
index e1269f79..b89c0a8a 100644
--- a/OpenDiablo2/OpenDiablo2.csproj
+++ b/OpenDiablo2/OpenDiablo2.csproj
@@ -12,6 +12,21 @@
512
true
true
+ publish\
+ true
+ Disk
+ false
+ Foreground
+ 7
+ Days
+ false
+ false
+ true
+ 0
+ 1.0.0.%2a
+ false
+ false
+ true
AnyCPU
@@ -44,7 +59,8 @@
bin\x64\Release\
- TRACE
+
+
true
pdbonly
x64
@@ -111,5 +127,17 @@
OpenDiablo2.SDL2
+
+
+ False
+ Microsoft .NET Framework 4.6.1 %28x86 and x64%29
+ true
+
+
+ False
+ .NET Framework 3.5 SP1
+ false
+
+
\ No newline at end of file