changed skin element lookup to dictionary (was linear search)

This commit is contained in:
Benjamin Hess authored and Alexander Eckart committed 2012-03-30 23:25:16 +08:00
1 parent d7e474d774
commit 269dd38402
1 file changed
+16 -21
+16 -21
View File
@@ -45,7 +45,7 @@ namespace Vocaluxe.Base
public string Path;
public string FileName;
public List<SkinElement> SkinList;
public Dictionary<string, SkinElement> SkinList;
public List<SkinElement> VideoList;
public SColors ThemeColors;
@@ -163,16 +163,18 @@ namespace Vocaluxe.Base
{
string value = String.Empty;
// load skins/textures
for (int i = 0; i < _Skins[index].SkinList.Count; i++)
List<string> keys = new List<string>(_Skins[index].SkinList.Keys);
foreach (string name in keys)
{
CHelper.GetValueFromXML("//root/Skins/" + _Skins[index].SkinList[i].Name, navigator, ref value, String.Empty);
SkinElement sk = new SkinElement();
sk.Name = _Skins[index].SkinList[i].Name;
CHelper.GetValueFromXML("//root/Skins/" + name, navigator, ref value, String.Empty);
SkinElement sk = _Skins[index].SkinList[name];
sk.Value = value;
sk.VideoIndex = -1;
sk.Texture = CDraw.AddTexture(Path.Combine(_Skins[index].Path, sk.Value));
_Skins[index].SkinList[i] = sk;
_Skins[index].SkinList[name] = sk;
}
// load videos
@@ -199,9 +201,9 @@ namespace Vocaluxe.Base
{
for (int i = 0; i < _Skins.Count; i++)
{
for (int j = 0; j < _Skins[i].SkinList.Count; j++)
foreach (SkinElement sk in _Skins[i].SkinList.Values)
{
STexture Texture = _Skins[i].SkinList[j].Texture;
STexture Texture = sk.Texture;
CDraw.RemoveTexture(ref Texture);
}
@@ -335,7 +337,7 @@ namespace Vocaluxe.Base
#region Skins
writer.WriteStartElement("Skins");
foreach (SkinElement element in _Skins[SkinIndex].SkinList)
foreach (SkinElement element in _Skins[SkinIndex].SkinList.Values)
{
writer.WriteElementString(element.Name, element.Value);
}
@@ -489,14 +491,14 @@ namespace Vocaluxe.Base
skin.Path = path;
skin.FileName = file;
skin.SkinList = new List<SkinElement>();
skin.SkinList = new Dictionary<string, SkinElement>();
List<string> names = CHelper.GetValuesFromXML("Skins", navigator);
foreach (string str in names)
{
SkinElement sk = new SkinElement();
sk.Name = str;
sk.Value = String.Empty;
skin.SkinList.Add(sk);
skin.SkinList[str] = sk;
}
skin.VideoList = new List<SkinElement>();
@@ -573,16 +575,9 @@ namespace Vocaluxe.Base
public static STexture GetSkinTexture(string TextureName)
{
int SkinIndex = GetSkinIndex();
if (SkinIndex != -1)
if (SkinIndex != -1 && TextureName != null && _Skins[SkinIndex].SkinList.ContainsKey(TextureName))
{
for (int i = 0; i < _Skins[SkinIndex].SkinList.Count; i++)
{
SkinElement sk = _Skins[SkinIndex].SkinList[i];
if (sk.Name == TextureName)
{
return sk.Texture;
}
}
return _Skins[SkinIndex].SkinList[TextureName].Texture;
}
return new STexture(-1);
}
@@ -599,7 +594,7 @@ namespace Vocaluxe.Base
private static string GetSkinFileName(string SkinName, int SkinIndex, bool ReturnPath)
{
foreach (SkinElement sk in _Skins[SkinIndex].SkinList)
foreach (SkinElement sk in _Skins[SkinIndex].SkinList.Values)
{
if (sk.Name == SkinName)
{