Better ID management
This commit is contained in:
1 parent
d251329791
commit
3804810545
1 file changed
+34
-30
@@ -35,8 +35,9 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
private Size _SizeBeforeMinimize;
|
private Size _SizeBeforeMinimize;
|
||||||
|
|
||||||
private Dictionary<int, STexture> _Textures;
|
private Dictionary<int, STexture> _Textures;
|
||||||
private List<Texture> _D3DTextures;
|
private Dictionary<int, Texture> _D3DTextures;
|
||||||
private List<STextureQueque> _Queque;
|
private List<STextureQueque> _Queque;
|
||||||
|
private Queue<int> _IDs;
|
||||||
|
|
||||||
private Object MutexTexture = new Object();
|
private Object MutexTexture = new Object();
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
private int y = 0;
|
private int y = 0;
|
||||||
private int x = 0;
|
private int x = 0;
|
||||||
|
|
||||||
private STexture blankTexture;
|
private STexture _BlankTexture;
|
||||||
|
|
||||||
private Queue<TexturedColoredVertex> _Vertices;
|
private Queue<TexturedColoredVertex> _Vertices;
|
||||||
private Queue<Texture> _VerticesTextures;
|
private Queue<Texture> _VerticesTextures;
|
||||||
@@ -63,8 +64,13 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));
|
this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));
|
||||||
_Textures = new Dictionary<int, STexture>();
|
_Textures = new Dictionary<int, STexture>();
|
||||||
_D3DTextures = new List<Texture>();
|
_D3DTextures = new Dictionary<int, Texture>();
|
||||||
_Queque = new List<STextureQueque>();
|
_Queque = new List<STextureQueque>();
|
||||||
|
_IDs = new Queue<int>();
|
||||||
|
|
||||||
|
//Fill Queue with 100000 IDs
|
||||||
|
for (int i = 0; i < 100000; i++)
|
||||||
|
_IDs.Enqueue(i);
|
||||||
|
|
||||||
_Vertices = new Queue<TexturedColoredVertex>();
|
_Vertices = new Queue<TexturedColoredVertex>();
|
||||||
_VerticesTextures = new Queue<Texture>();
|
_VerticesTextures = new Queue<Texture>();
|
||||||
@@ -270,6 +276,8 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
y = 0;
|
y = 0;
|
||||||
x = 0;
|
x = 0;
|
||||||
|
|
||||||
|
if ((float)w / (float)h == CSettings.GetRenderAspect())
|
||||||
|
return;
|
||||||
if ((float)w / (float)h > CSettings.GetRenderAspect())
|
if ((float)w / (float)h > CSettings.GetRenderAspect())
|
||||||
{
|
{
|
||||||
//The windows's width is too big
|
//The windows's width is too big
|
||||||
@@ -482,7 +490,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
Graphics g = Graphics.FromImage(blankMap);
|
Graphics g = Graphics.FromImage(blankMap);
|
||||||
g.Clear(Color.White);
|
g.Clear(Color.White);
|
||||||
g.Dispose();
|
g.Dispose();
|
||||||
blankTexture = AddTexture(blankMap);
|
_BlankTexture = AddTexture(blankMap);
|
||||||
|
|
||||||
blankMap.Dispose();
|
blankMap.Dispose();
|
||||||
return true;
|
return true;
|
||||||
@@ -583,11 +591,11 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
public bool Unload()
|
public bool Unload()
|
||||||
{
|
{
|
||||||
//Dispose all textures
|
//Dispose all textures
|
||||||
for (int i = 0; i < _D3DTextures.Count; i++)
|
foreach (KeyValuePair<int, Texture> p in _D3DTextures)
|
||||||
{
|
{
|
||||||
if (_D3DTextures[i] != null)
|
p.Value.Dispose();
|
||||||
_D3DTextures[i].Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TexturedColoredVertex.GetDeclaration(_Device).Dispose();
|
TexturedColoredVertex.GetDeclaration(_Device).Dispose();
|
||||||
_VertexBuffer.Dispose();
|
_VertexBuffer.Dispose();
|
||||||
_IndexBuffer.Dispose();
|
_IndexBuffer.Dispose();
|
||||||
@@ -713,7 +721,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
Surface textureSurface = tex.GetSurfaceLevel(0);
|
Surface textureSurface = tex.GetSurfaceLevel(0);
|
||||||
Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0);
|
Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0);
|
||||||
backbufferSurface.Dispose();
|
backbufferSurface.Dispose();
|
||||||
_D3DTextures.Add(tex);
|
_D3DTextures.Add(_IDs.Peek(), tex);
|
||||||
|
|
||||||
texture.color = new SColorF(1f, 1f, 1f, 1f);
|
texture.color = new SColorF(1f, 1f, 1f, 1f);
|
||||||
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
|
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
|
||||||
@@ -721,7 +729,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
texture.height = h;
|
texture.height = h;
|
||||||
texture.w2 = NextPowerOfTwo(texture.width);
|
texture.w2 = NextPowerOfTwo(texture.width);
|
||||||
texture.h2 = NextPowerOfTwo(texture.height);
|
texture.h2 = NextPowerOfTwo(texture.height);
|
||||||
texture.index = _D3DTextures.Count - 1;
|
texture.index = _IDs.Dequeue();
|
||||||
|
|
||||||
lock (MutexTexture)
|
lock (MutexTexture)
|
||||||
{
|
{
|
||||||
@@ -787,7 +795,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2)
|
public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2)
|
||||||
{
|
{
|
||||||
SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255);
|
SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255);
|
||||||
DrawTexture(blankTexture, new SRectF(x1, y1, x2, y2, 1), color);
|
DrawTexture(_BlankTexture, new SRectF(x1, y1, x2, y2, 1), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -822,7 +830,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="rect">The coordinates in a SRectF struct</param>
|
/// <param name="rect">The coordinates in a SRectF struct</param>
|
||||||
public void DrawColor(SColorF color, SRectF rect)
|
public void DrawColor(SColorF color, SRectF rect)
|
||||||
{
|
{
|
||||||
DrawTexture(blankTexture, rect, color);
|
DrawTexture(_BlankTexture, rect, color);
|
||||||
}
|
}
|
||||||
#endregion Basic Draw Methods
|
#endregion Basic Draw Methods
|
||||||
#region Textures
|
#region Textures
|
||||||
@@ -951,8 +959,8 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
texture.TexturePath = String.Empty;
|
texture.TexturePath = String.Empty;
|
||||||
lock (MutexTexture)
|
lock (MutexTexture)
|
||||||
{
|
{
|
||||||
_D3DTextures.Add(t);
|
_D3DTextures.Add(_IDs.Peek(), t);
|
||||||
texture.index = _D3DTextures.Count - 1;
|
texture.index = _IDs.Dequeue();
|
||||||
_Textures[texture.index] = texture;
|
_Textures[texture.index] = texture;
|
||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
@@ -988,8 +996,8 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
|
|
||||||
lock (MutexTexture)
|
lock (MutexTexture)
|
||||||
{
|
{
|
||||||
_D3DTextures.Add(null);
|
_D3DTextures.Add(_IDs.Peek(), null);
|
||||||
texture.index = _D3DTextures.Count - 1;
|
texture.index = _IDs.Dequeue();
|
||||||
queque.ID = texture.index;
|
queque.ID = texture.index;
|
||||||
_Queque.Add(queque);
|
_Queque.Add(queque);
|
||||||
_Textures[texture.index] = texture;
|
_Textures[texture.index] = texture;
|
||||||
@@ -1024,8 +1032,8 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
|
|
||||||
lock (MutexTexture)
|
lock (MutexTexture)
|
||||||
{
|
{
|
||||||
_D3DTextures.Add(t);
|
_D3DTextures.Add(_IDs.Peek(), t);
|
||||||
texture.index = _D3DTextures.Count - 1;
|
texture.index = _IDs.Dequeue();
|
||||||
_Textures[texture.index] = texture;
|
_Textures[texture.index] = texture;
|
||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
@@ -1055,7 +1063,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <returns>True if succeeded</returns>
|
/// <returns>True if succeeded</returns>
|
||||||
public bool UpdateTexture(ref STexture Texture, ref byte[] Data)
|
public bool UpdateTexture(ref STexture Texture, ref byte[] Data)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture))
|
if ((Texture.index >= 0) && (_Textures.Count > 0) && _TextureExists(ref Texture))
|
||||||
{
|
{
|
||||||
DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None);
|
DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None);
|
||||||
for (int i = 0; i < Data.Length; )
|
for (int i = 0; i < Data.Length; )
|
||||||
@@ -1108,8 +1116,9 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
if ((Texture.index >= 0) && (_Textures.Count > 0))
|
if ((Texture.index >= 0) && (_Textures.Count > 0))
|
||||||
{
|
{
|
||||||
_D3DTextures[Texture.index].Dispose();
|
_D3DTextures[Texture.index].Dispose();
|
||||||
_D3DTextures[Texture.index] = null;
|
_D3DTextures.Remove(Texture.index);
|
||||||
_Textures.Remove(Texture.index);
|
_Textures.Remove(Texture.index);
|
||||||
|
_IDs.Enqueue(Texture.index);
|
||||||
Texture.index = -1;
|
Texture.index = -1;
|
||||||
Texture.ID = -1;
|
Texture.ID = -1;
|
||||||
}
|
}
|
||||||
@@ -1123,8 +1132,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="Texture">The texture to be drawn</param>
|
/// <param name="Texture">The texture to be drawn</param>
|
||||||
public void DrawTexture(STexture Texture)
|
public void DrawTexture(STexture Texture)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
|
DrawTexture(Texture, Texture.rect, Texture.color);
|
||||||
DrawTexture(Texture, Texture.rect, Texture.color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1134,8 +1142,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
|
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
|
||||||
public void DrawTexture(STexture Texture, SRectF rect)
|
public void DrawTexture(STexture Texture, SRectF rect)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
|
DrawTexture(Texture, rect, Texture.color, false);
|
||||||
DrawTexture(Texture, rect, Texture.color, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1146,8 +1153,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
|
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
|
||||||
public void DrawTexture(STexture Texture, SRectF rect, SColorF color)
|
public void DrawTexture(STexture Texture, SRectF rect, SColorF color)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
|
DrawTexture(Texture, rect, color, false);
|
||||||
DrawTexture(Texture, rect, color, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1159,8 +1165,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
|
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
|
||||||
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds)
|
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
|
DrawTexture(Texture, rect, color, bounds, false);
|
||||||
DrawTexture(Texture, rect, color, bounds, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1172,8 +1177,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="mirrored">True if the texture should be mirrored</param>
|
/// <param name="mirrored">True if the texture should be mirrored</param>
|
||||||
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored)
|
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
|
DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored);
|
||||||
DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1186,7 +1190,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
/// <param name="mirrored">True if the texture should be mirrored</param>
|
/// <param name="mirrored">True if the texture should be mirrored</param>
|
||||||
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored)
|
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored)
|
||||||
{
|
{
|
||||||
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture))
|
if (_TextureExists(ref Texture))
|
||||||
{
|
{
|
||||||
if (_D3DTextures[Texture.index] == null)
|
if (_D3DTextures[Texture.index] == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user