1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-13 11:10:43 +00:00

Prevented re-generation of textures. Fixed button on hero class screen.

This commit is contained in:
Tim Sarbin 2018-11-22 23:44:01 -05:00
parent 245eabe4c2
commit 63dbe3f6eb
8 changed files with 42 additions and 44 deletions

View File

@ -3,6 +3,7 @@
public enum eButtonType
{
Wide,
Medium,
Cancel
}
}

View File

@ -16,6 +16,7 @@ namespace OpenDiablo2.Common.Models
public static Dictionary<eButtonType, ButtonLayout> Values = new Dictionary<eButtonType, ButtonLayout>
{
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Medium, new ButtonLayout{ XSegments = 1, ResourceName=ResourcePaths.MediumButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Cancel, new ButtonLayout {XSegments = 1,ResourceName = ResourcePaths.CancelButton,PaletteName = Palettes.Units } }
};
}

View File

@ -19,16 +19,16 @@ namespace OpenDiablo2.Common.Models
public UInt32 Unknown;
public UInt32 NextBlock;
public UInt32 Length;
public Int16[,] ImageData;
public Int16[] ImageData;
public void Dispose()
{
ImageData = new Int16[0, 0];
ImageData = new Int16[0];
}
public Color GetColor(int x, int y, Palette palette)
{
var index = ImageData[x, y];
var index = ImageData[x + (y * Width)];
if (index == -1)
return Color.Transparent;
@ -86,10 +86,10 @@ namespace OpenDiablo2.Common.Models
Length = br.ReadUInt32()
};
result.Frames[i].ImageData = new Int16[result.Frames[i].Width, result.Frames[i].Height];
result.Frames[i].ImageData = new Int16[result.Frames[i].Width * result.Frames[i].Height];
for (int ty = 0; ty < result.Frames[i].Height; ty++)
for (int tx = 0; tx < result.Frames[i].Width; tx++)
result.Frames[i].ImageData[tx, ty] = -1;
result.Frames[i].ImageData[tx + (ty * result.Frames[i].Width)] = -1;
int x = 0;
@ -110,17 +110,19 @@ namespace OpenDiablo2.Common.Models
if ((b & 0x80) > 0)
{
var transparentPixelsToWrite = b & 0x7F;
for (int p = 0; p < transparentPixelsToWrite; p++)
{
result.Frames[i].ImageData[x++, y] = -1;
}
Enumerable.Repeat<Int16>(-1, transparentPixelsToWrite).ToArray()
.CopyTo(result.Frames[i].ImageData, x + (y * result.Frames[i].Width));
x += transparentPixelsToWrite;
continue;
}
for (int p = 0; p < b; p++)
{
result.Frames[i].ImageData[x++, y] = br.ReadByte();
}
br.ReadBytes(b).CopyTo(result.Frames[i].ImageData, x + (y * result.Frames[i].Width));
x += b;
}
}

View File

@ -40,6 +40,7 @@ namespace OpenDiablo2.Common
// --- UI ---
public static string WideButtonBlank = "data\\global\\ui\\FrontEnd\\WideButtonBlank.dc6";
public static string MediumButtonBlank = "data\\global\\ui\\FrontEnd\\MediumButtonBlank.dc6";
public static string CancelButton = "data\\global\\ui\\FrontEnd\\CancelButtonBlank.dc6";
}

View File

@ -49,6 +49,7 @@
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=4.8.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">

View File

@ -67,17 +67,13 @@ namespace OpenDiablo2.SDL2_
public Size LocalFrameSize => new Size((int)source.Frames[Frame].Width, (int)source.Frames[Frame].Height);
// TODO: This is slow. Make fix.
private void UpdateTextureData()
{
foreach (var texture in textures)
{
SDL.SDL_DestroyTexture(texture);
}
textures = new IntPtr[TotalFrames];
for (var i = 0; i < source.Frames.Count(); i++)
textures[i] = LoadFrame(source.Frames[i], renderer);
LoadFrame(i, renderer);
}
@ -91,32 +87,40 @@ namespace OpenDiablo2.SDL2_
(byte)Math.Min((float)source.B * 1.2, 255)
);
private IntPtr LoadFrame(ImageFrame frame, IntPtr renderer)
object bob = new object();
private void LoadFrame(int index, IntPtr renderer)
{
var texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, Pow2(FrameSize.Width), Pow2(FrameSize.Height));
var frame = source.Frames[index];
if (texture == IntPtr.Zero)
if (textures[index] == IntPtr.Zero)
textures[index] = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, Pow2(FrameSize.Width), Pow2(FrameSize.Height));
if (textures[index] == IntPtr.Zero)
throw new ApplicationException("Unaple to initialize texture.");
SDL.SDL_SetTextureBlendMode(texture, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
SDL.SDL_SetRenderTarget(renderer, texture);
SDL.SDL_SetTextureBlendMode(textures[index], SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
SDL.SDL_SetRenderTarget(renderer, textures[index]);
SDL.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL.SDL_RenderFillRect(renderer, IntPtr.Zero);
SDL.SDL_SetRenderTarget(renderer, IntPtr.Zero);
var binaryData = new UInt32[frame.Width * frame.Height];
for (int y = 0; y < frame.Height; y++)
for (var y = 0; y < frame.Height; y++)
{
for (int x = 0; x < frame.Width; x++)
{
var col = AdjustColor(frame.GetColor(x, y, CurrentPalette));
binaryData[x + y * frame.Width] = (uint)col.ToArgb();
var palColor = frame.GetColor(x, (int)y, CurrentPalette);
//var col = AdjustColor(palColor);
binaryData[x + y * frame.Width] = (uint)palColor.ToArgb();
}
}
var rect = new SDL.SDL_Rect { x = 0, y = FrameSize.Height - (int)frame.Height, w = (int)frame.Width, h = (int)frame.Height };
GCHandle pinnedArray = GCHandle.Alloc(binaryData, GCHandleType.Pinned);
SDL.SDL_UpdateTexture(texture, ref rect, pinnedArray.AddrOfPinnedObject(), (int)frame.Width * 4);
SDL.SDL_UpdateTexture(textures[index], ref rect, pinnedArray.AddrOfPinnedObject(), (int)frame.Width * 4);
pinnedArray.Free();
return texture;
}

View File

@ -85,18 +85,6 @@ namespace OpenDiablo2.Scenes
/*
musicProvider.LoadSong(mpqProvider.GetStream("data\\global\\music\\introedit.wav"));
// TODO: Fake loading for now, this should be in its own scene as we start loading real stuff
var r = new Random();
for (int i = 1; i < 10; i++)
{
renderWindow.Clear();
loadingSprite.Frame = i;
renderWindow.Draw(loadingSprite);
renderWindow.Sync();
Thread.Sleep(r.Next(150));
}
musicProvider.PlaySong();
*/
}

View File

@ -51,11 +51,11 @@ namespace OpenDiablo2.Scenes
headingFont = renderWindow.LoadFont(ResourcePaths.Font30, Palettes.Units);
headingLabel = renderWindow.CreateLabel(headingFont);
headingLabel.Text = "Select Hero Class";
headingLabel.Location = new System.Drawing.Point(400 - (headingLabel.TextArea.Width / 2), 20);
headingLabel.Location = new System.Drawing.Point(400 - (headingLabel.TextArea.Width / 2), 17);
exitButton = createButton(eButtonType.Cancel);
exitButton = createButton(eButtonType.Medium);
exitButton.Text = "EXIT";
exitButton.Location = new System.Drawing.Point(30, 550);
exitButton.Location = new System.Drawing.Point(30, 540);
exitButton.OnActivate = OnExitClicked;
}