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 Path;
public string FileName; public string FileName;
public List<SkinElement> SkinList; public Dictionary<string, SkinElement> SkinList;
public List<SkinElement> VideoList; public List<SkinElement> VideoList;
public SColors ThemeColors; public SColors ThemeColors;
@@ -163,16 +163,18 @@ namespace Vocaluxe.Base
{ {
string value = String.Empty; string value = String.Empty;
// load skins/textures // 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); CHelper.GetValueFromXML("//root/Skins/" + name, navigator, ref value, String.Empty);
SkinElement sk = new SkinElement(); SkinElement sk = _Skins[index].SkinList[name];
sk.Name = _Skins[index].SkinList[i].Name;
sk.Value = value; sk.Value = value;
sk.VideoIndex = -1; sk.VideoIndex = -1;
sk.Texture = CDraw.AddTexture(Path.Combine(_Skins[index].Path, sk.Value)); sk.Texture = CDraw.AddTexture(Path.Combine(_Skins[index].Path, sk.Value));
_Skins[index].SkinList[i] = sk; _Skins[index].SkinList[name] = sk;
} }
// load videos // load videos
@@ -199,9 +201,9 @@ namespace Vocaluxe.Base
{ {
for (int i = 0; i < _Skins.Count; i++) 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); CDraw.RemoveTexture(ref Texture);
} }
@@ -335,7 +337,7 @@ namespace Vocaluxe.Base
#region Skins #region Skins
writer.WriteStartElement("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); writer.WriteElementString(element.Name, element.Value);
} }
@@ -489,14 +491,14 @@ namespace Vocaluxe.Base
skin.Path = path; skin.Path = path;
skin.FileName = file; skin.FileName = file;
skin.SkinList = new List<SkinElement>(); skin.SkinList = new Dictionary<string, SkinElement>();
List<string> names = CHelper.GetValuesFromXML("Skins", navigator); List<string> names = CHelper.GetValuesFromXML("Skins", navigator);
foreach (string str in names) foreach (string str in names)
{ {
SkinElement sk = new SkinElement(); SkinElement sk = new SkinElement();
sk.Name = str; sk.Name = str;
sk.Value = String.Empty; sk.Value = String.Empty;
skin.SkinList.Add(sk); skin.SkinList[str] = sk;
} }
skin.VideoList = new List<SkinElement>(); skin.VideoList = new List<SkinElement>();
@@ -573,16 +575,9 @@ namespace Vocaluxe.Base
public static STexture GetSkinTexture(string TextureName) public static STexture GetSkinTexture(string TextureName)
{ {
int SkinIndex = GetSkinIndex(); 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++) return _Skins[SkinIndex].SkinList[TextureName].Texture;
{
SkinElement sk = _Skins[SkinIndex].SkinList[i];
if (sk.Name == TextureName)
{
return sk.Texture;
}
}
} }
return new STexture(-1); return new STexture(-1);
} }
@@ -599,7 +594,7 @@ namespace Vocaluxe.Base
private static string GetSkinFileName(string SkinName, int SkinIndex, bool ReturnPath) 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) if (sk.Name == SkinName)
{ {