- 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:
parent
10aea90e56
commit
e51a8943aa
@ -26,7 +26,7 @@ namespace ANX.Framework.NonXNA
|
||||
private Dictionary<string, ICreator> creators;
|
||||
private static AddInSystemFactory instance;
|
||||
private bool initialized;
|
||||
private Dictionary<AddInType, AddInTypeCollection> addinSystems;
|
||||
private Dictionary<AddInType, AddInTypeCollection> addInSystems;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
@ -57,10 +57,10 @@ namespace ANX.Framework.NonXNA
|
||||
private AddInSystemFactory()
|
||||
{
|
||||
creators = new Dictionary<string, ICreator>();
|
||||
addinSystems = new Dictionary<AddInType, AddInTypeCollection>();
|
||||
addInSystems = new Dictionary<AddInType, AddInTypeCollection>();
|
||||
|
||||
foreach (AddInType type in Enum.GetValues(typeof(AddInType)))
|
||||
addinSystems.Add(type, new AddInTypeCollection());
|
||||
addInSystems.Add(type, new AddInTypeCollection());
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -89,7 +89,7 @@ namespace ANX.Framework.NonXNA
|
||||
AddIn addin = new AddIn(creatorType, matchingSupportedPlatformsType);
|
||||
if (addin.IsSupported)
|
||||
{
|
||||
addinSystems[addin.Type].Add(addin);
|
||||
addInSystems[addin.Type].Add(addin);
|
||||
Logger.Info("[ANX] successfully loaded AddIn (" + addin.Type + ") " + creatorType.FullName + ".");
|
||||
}
|
||||
else
|
||||
@ -173,20 +173,45 @@ namespace ANX.Framework.NonXNA
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetDefaultCreator
|
||||
public T GetDefaultCreator<T>() where T : class, ICreator
|
||||
#region GetAvailableCreators
|
||||
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();
|
||||
|
||||
AddInType addInType = GetAddInType(typeof(T));
|
||||
return addinSystems[addInType].GetDefaultCreator<T>(addInType);
|
||||
return addInSystems[addInType].GetDefaultCreator<T>(addInType);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SortAddIns
|
||||
public void SortAddIns()
|
||||
{
|
||||
foreach (AddInTypeCollection info in addinSystems.Values)
|
||||
foreach (AddInTypeCollection info in addInSystems.Values)
|
||||
info.Sort();
|
||||
|
||||
creators = creators.OrderBy(x => x.Value.Priority).ToDictionary(x => x.Key, x => x.Value);
|
||||
@ -196,24 +221,24 @@ namespace ANX.Framework.NonXNA
|
||||
#region GetPreferredSystem
|
||||
public string GetPreferredSystem(AddInType addInType)
|
||||
{
|
||||
return addinSystems[addInType].PreferredName;
|
||||
return addInSystems[addInType].PreferredName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetPreferredSystem
|
||||
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));
|
||||
|
||||
addinSystems[addInType].PreferredName = preferredName;
|
||||
addInSystems[addInType].PreferredName = preferredName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PreventSystemChange
|
||||
public void PreventSystemChange(AddInType addInType)
|
||||
{
|
||||
addinSystems[addInType].Lock();
|
||||
addInSystems[addInType].Lock();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -7,9 +7,9 @@ using System.Collections.Generic;
|
||||
|
||||
namespace ANX.Framework.NonXNA
|
||||
{
|
||||
internal class AddInTypeCollection
|
||||
internal class AddInTypeCollection : IEnumerable<AddIn>
|
||||
{
|
||||
private List<AddIn> AvailableSystems;
|
||||
private List<AddIn> availableSystems;
|
||||
|
||||
#region Public
|
||||
public string PreferredName
|
||||
@ -28,21 +28,21 @@ namespace ANX.Framework.NonXNA
|
||||
#region Constructor
|
||||
public AddInTypeCollection()
|
||||
{
|
||||
AvailableSystems = new List<AddIn>();
|
||||
availableSystems = new List<AddIn>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
public void Add(AddIn addIn)
|
||||
{
|
||||
AvailableSystems.Add(addIn);
|
||||
availableSystems.Add(addIn);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Sort
|
||||
public void Sort()
|
||||
{
|
||||
AvailableSystems.Sort();
|
||||
availableSystems.Sort();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -56,19 +56,27 @@ namespace ANX.Framework.NonXNA
|
||||
#region GetDefaultCreator
|
||||
public T GetDefaultCreator<T>(AddInType addInType) where T : class, ICreator
|
||||
{
|
||||
Sort();
|
||||
|
||||
if (String.IsNullOrEmpty(PreferredName))
|
||||
{
|
||||
if (AvailableSystems.Count > 0)
|
||||
return AvailableSystems[0].Instance as T;
|
||||
for (int i = 0; i < availableSystems.Count; i++)
|
||||
{
|
||||
T candidate = availableSystems[i].Instance as T;
|
||||
if (candidate != null && candidate.IsSupported)
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
throw new AddInLoadingException(String.Format(
|
||||
"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));
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (AddIn addin in AvailableSystems)
|
||||
foreach (AddIn addin in availableSystems)
|
||||
if (addin.Name.Equals(PreferredName, StringComparison.CurrentCultureIgnoreCase))
|
||||
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));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public IEnumerator<AddIn> GetEnumerator()
|
||||
{
|
||||
return availableSystems.GetEnumerator();
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return availableSystems.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,23 +24,23 @@ namespace WindowsGame1
|
||||
{
|
||||
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.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.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.SelectedIndex = 0;
|
||||
cbAudioSystem.SelectedItem = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>().Name;
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
|
@ -484,7 +484,24 @@
|
||||
|
||||
</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">
|
||||
<in>
|
||||
<items basedir="../Tools/">
|
||||
|
Loading…
x
Reference in New Issue
Block a user