- fixed an issue in build script. The rendersystems are now compiled three times. This is not nice but necessary at the moment (see comments in build script for further information)

- fixed some casing in AddInSystemFactory
- some minor improvements in AddInSystemFactory and AddInTypeCollection
- fixed WindowsGame sample (AddIn-Selection)
This commit is contained in:
Glatzemann 2012-09-17 09:35:16 +00:00 committed by Konstantin Koch
parent 10aea90e56
commit e51a8943aa
4 changed files with 89 additions and 29 deletions

View File

@ -26,7 +26,7 @@ namespace ANX.Framework.NonXNA
private Dictionary<string, ICreator> creators; private Dictionary<string, ICreator> creators;
private static AddInSystemFactory instance; private static AddInSystemFactory instance;
private bool initialized; private bool initialized;
private Dictionary<AddInType, AddInTypeCollection> addinSystems; private Dictionary<AddInType, AddInTypeCollection> addInSystems;
#endregion #endregion
#region Public #region Public
@ -57,10 +57,10 @@ namespace ANX.Framework.NonXNA
private AddInSystemFactory() private AddInSystemFactory()
{ {
creators = new Dictionary<string, ICreator>(); creators = new Dictionary<string, ICreator>();
addinSystems = new Dictionary<AddInType, AddInTypeCollection>(); addInSystems = new Dictionary<AddInType, AddInTypeCollection>();
foreach (AddInType type in Enum.GetValues(typeof(AddInType))) foreach (AddInType type in Enum.GetValues(typeof(AddInType)))
addinSystems.Add(type, new AddInTypeCollection()); addInSystems.Add(type, new AddInTypeCollection());
} }
#endregion #endregion
@ -89,7 +89,7 @@ namespace ANX.Framework.NonXNA
AddIn addin = new AddIn(creatorType, matchingSupportedPlatformsType); AddIn addin = new AddIn(creatorType, matchingSupportedPlatformsType);
if (addin.IsSupported) if (addin.IsSupported)
{ {
addinSystems[addin.Type].Add(addin); addInSystems[addin.Type].Add(addin);
Logger.Info("[ANX] successfully loaded AddIn (" + addin.Type + ") " + creatorType.FullName + "."); Logger.Info("[ANX] successfully loaded AddIn (" + addin.Type + ") " + creatorType.FullName + ".");
} }
else else
@ -173,20 +173,45 @@ namespace ANX.Framework.NonXNA
} }
#endregion #endregion
#region GetDefaultCreator #region GetAvailableCreators
public T GetDefaultCreator<T>() where T : class, ICreator public IEnumerable<T> GetAvailableCreators<T>() where T : class, ICreator
{
AddInType type = GetAddInType(typeof(T));
if (type != AddInType.Unknown)
{
AddInTypeCollection addIns = addInSystems[type];
foreach (AddIn addIn in addIns)
{
T instance = addIn.Instance as T;
if (instance != null && instance.IsSupported)
{
yield return instance;
}
}
}
else
{
throw new Exception("couldn't resolve AddInType of '" + typeof(T).FullName + "'");
}
}
#endregion
#region GetDefaultCreator
public T GetDefaultCreator<T>() where T : class, ICreator
{ {
Initialize(); Initialize();
AddInType addInType = GetAddInType(typeof(T)); AddInType addInType = GetAddInType(typeof(T));
return addinSystems[addInType].GetDefaultCreator<T>(addInType); return addInSystems[addInType].GetDefaultCreator<T>(addInType);
} }
#endregion #endregion
#region SortAddIns #region SortAddIns
public void SortAddIns() public void SortAddIns()
{ {
foreach (AddInTypeCollection info in addinSystems.Values) foreach (AddInTypeCollection info in addInSystems.Values)
info.Sort(); info.Sort();
creators = creators.OrderBy(x => x.Value.Priority).ToDictionary(x => x.Key, x => x.Value); creators = creators.OrderBy(x => x.Value.Priority).ToDictionary(x => x.Key, x => x.Value);
@ -196,24 +221,24 @@ namespace ANX.Framework.NonXNA
#region GetPreferredSystem #region GetPreferredSystem
public string GetPreferredSystem(AddInType addInType) public string GetPreferredSystem(AddInType addInType)
{ {
return addinSystems[addInType].PreferredName; return addInSystems[addInType].PreferredName;
} }
#endregion #endregion
#region SetPreferredSystem #region SetPreferredSystem
public void SetPreferredSystem(AddInType addInType, string preferredName) public void SetPreferredSystem(AddInType addInType, string preferredName)
{ {
if (addinSystems[addInType].PreferredLocked) if (addInSystems[addInType].PreferredLocked)
throw new AddInLoadingException(String.Format("Can't set preferred {0} because a {0} is alread in use.", addInType)); throw new AddInLoadingException(String.Format("Can't set preferred {0} because a {0} is alread in use.", addInType));
addinSystems[addInType].PreferredName = preferredName; addInSystems[addInType].PreferredName = preferredName;
} }
#endregion #endregion
#region PreventSystemChange #region PreventSystemChange
public void PreventSystemChange(AddInType addInType) public void PreventSystemChange(AddInType addInType)
{ {
addinSystems[addInType].Lock(); addInSystems[addInType].Lock();
} }
#endregion #endregion

View File

@ -7,9 +7,9 @@ using System.Collections.Generic;
namespace ANX.Framework.NonXNA namespace ANX.Framework.NonXNA
{ {
internal class AddInTypeCollection internal class AddInTypeCollection : IEnumerable<AddIn>
{ {
private List<AddIn> AvailableSystems; private List<AddIn> availableSystems;
#region Public #region Public
public string PreferredName public string PreferredName
@ -28,21 +28,21 @@ namespace ANX.Framework.NonXNA
#region Constructor #region Constructor
public AddInTypeCollection() public AddInTypeCollection()
{ {
AvailableSystems = new List<AddIn>(); availableSystems = new List<AddIn>();
} }
#endregion #endregion
#region Add #region Add
public void Add(AddIn addIn) public void Add(AddIn addIn)
{ {
AvailableSystems.Add(addIn); availableSystems.Add(addIn);
} }
#endregion #endregion
#region Sort #region Sort
public void Sort() public void Sort()
{ {
AvailableSystems.Sort(); availableSystems.Sort();
} }
#endregion #endregion
@ -56,19 +56,27 @@ namespace ANX.Framework.NonXNA
#region GetDefaultCreator #region GetDefaultCreator
public T GetDefaultCreator<T>(AddInType addInType) where T : class, ICreator public T GetDefaultCreator<T>(AddInType addInType) where T : class, ICreator
{ {
Sort();
if (String.IsNullOrEmpty(PreferredName)) if (String.IsNullOrEmpty(PreferredName))
{ {
if (AvailableSystems.Count > 0) for (int i = 0; i < availableSystems.Count; i++)
return AvailableSystems[0].Instance as T; {
T candidate = availableSystems[i].Instance as T;
if (candidate != null && candidate.IsSupported)
{
return candidate;
}
}
throw new AddInLoadingException(String.Format( throw new AddInLoadingException(String.Format(
"Couldn't get default {0} because there are no " + "Couldn't get default {0} because there are no " +
"registered {0}s available! Make sure you referenced a {0} library " + "registered and supported {0}s available! Make sure you referenced a {0} library " +
"in your project or one is laying in your output folder!", addInType)); "in your project or one is laying in your output folder!", addInType));
} }
else else
{ {
foreach (AddIn addin in AvailableSystems) foreach (AddIn addin in availableSystems)
if (addin.Name.Equals(PreferredName, StringComparison.CurrentCultureIgnoreCase)) if (addin.Name.Equals(PreferredName, StringComparison.CurrentCultureIgnoreCase))
return addin.Instance as T; return addin.Instance as T;
@ -80,5 +88,15 @@ namespace ANX.Framework.NonXNA
throw new AddInLoadingException(String.Format("Couldn't find a DefaultCreator of type '{0}'!", typeof(T).FullName)); throw new AddInLoadingException(String.Format("Couldn't find a DefaultCreator of type '{0}'!", typeof(T).FullName));
} }
#endregion #endregion
}
public IEnumerator<AddIn> GetEnumerator()
{
return availableSystems.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return availableSystems.GetEnumerator();
}
}
} }

View File

@ -24,23 +24,23 @@ namespace WindowsGame1
{ {
AddInSystemFactory.Instance.SortAddIns(); AddInSystemFactory.Instance.SortAddIns();
foreach (IRenderSystemCreator renderSystemCreator in AddInSystemFactory.Instance.GetCreators<IRenderSystemCreator>()) foreach (IRenderSystemCreator renderSystemCreator in AddInSystemFactory.Instance.GetAvailableCreators<IRenderSystemCreator>())
{ {
cbRenderSystem.Items.Add(renderSystemCreator.Name); cbRenderSystem.Items.Add(renderSystemCreator.Name);
} }
cbRenderSystem.SelectedIndex = 0; cbRenderSystem.SelectedItem = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().Name;
foreach (IInputSystemCreator inputSystemCreator in AddInSystemFactory.Instance.GetCreators<IInputSystemCreator>()) foreach (IInputSystemCreator inputSystemCreator in AddInSystemFactory.Instance.GetAvailableCreators<IInputSystemCreator>())
{ {
cbInputSystem.Items.Add(inputSystemCreator.Name); cbInputSystem.Items.Add(inputSystemCreator.Name);
} }
cbInputSystem.SelectedIndex = 0; cbInputSystem.SelectedItem = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Name;
foreach (ISoundSystemCreator soundSystemCreator in AddInSystemFactory.Instance.GetCreators<ISoundSystemCreator>()) foreach (ISoundSystemCreator soundSystemCreator in AddInSystemFactory.Instance.GetAvailableCreators<ISoundSystemCreator>())
{ {
cbAudioSystem.Items.Add(soundSystemCreator.Name); cbAudioSystem.Items.Add(soundSystemCreator.Name);
} }
cbAudioSystem.SelectedIndex = 0; cbAudioSystem.SelectedItem = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>().Name;
} }
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)

View File

@ -484,7 +484,24 @@
</target> </target>
<target name="tools" description="Build ANX.Framework tools" depends="support" unless="${target::has-executed('tools')}"> <!--
TODO: "depends rendersystem" in the tools target leads to three compilations of all the rendersystems. Currently this is necessary because we have
kind of ring dependency. To build a rendersystem we need the StockShaderCodeGenerator. This is used to embed the stock shaders into the
rendersystem. To compile a stock shader the rendersystem is needed because the compile methods are embedded into the rendersytem.
A possible solution is:
- compile render system
- compile stock shader code generator
- generate stock shaders
- compile stock shader assembly
- merge render system and stock shader assembly to one file
Another possible solution is:
- don't use sscg or remove rendersystem dependency from sscg
-->
<target name="tools" description="Build ANX.Framework tools" depends="support, rendersystem" unless="${target::has-executed('tools')}">
<foreach item="File" property="projectFile"> <foreach item="File" property="projectFile">
<in> <in>
<items basedir="../Tools/"> <items basedir="../Tools/">