Added FixedUpdates
This commit is contained in:
parent
777c2f6256
commit
21eaaa4900
8 changed files with 124 additions and 24 deletions
|
|
@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
|
|||
using OpenTK;
|
||||
using SM.Base;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Window.Contexts;
|
||||
using SM.Base.Windows;
|
||||
|
||||
#endregion
|
||||
|
|
@ -14,9 +15,10 @@ namespace SM.Base.Scene
|
|||
/// <summary>
|
||||
/// Contains a list of show items.
|
||||
/// </summary>
|
||||
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable
|
||||
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable, IFixedScriptable
|
||||
{
|
||||
private List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||
private List<IFixedScriptable> _fixedScriptables = new List<IFixedScriptable>();
|
||||
|
||||
/// <summary>
|
||||
/// Currently active script objects.
|
||||
|
|
@ -50,6 +52,16 @@ namespace SM.Base.Scene
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void FixedUpdate(FixedUpdateContext context)
|
||||
{
|
||||
if (!Active || !UpdateActive) return;
|
||||
|
||||
for (int i = 0; i < _fixedScriptables.Count; i++)
|
||||
{
|
||||
_fixedScriptables[i].FixedUpdate(context);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IShowCollection.Draw" />
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
|
|
@ -83,6 +95,8 @@ namespace SM.Base.Scene
|
|||
|
||||
if (item is IScriptable scriptable)
|
||||
AddScript(scriptable);
|
||||
|
||||
if (item is IFixedScriptable fixedScriptable) _fixedScriptables.Add(fixedScriptable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,6 +117,7 @@ namespace SM.Base.Scene
|
|||
public void AddScript(IScriptable item)
|
||||
{
|
||||
_scriptableObjects.Add(item);
|
||||
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
||||
}
|
||||
|
||||
public new void Remove(params IShowItem[] items)
|
||||
|
|
@ -113,6 +128,9 @@ namespace SM.Base.Scene
|
|||
|
||||
if (item is IScriptable scriptable)
|
||||
RemoveScript(scriptable);
|
||||
|
||||
if (item is IFixedScriptable fixedScriptable)
|
||||
_fixedScriptables.Remove(fixedScriptable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +152,7 @@ namespace SM.Base.Scene
|
|||
public void RemoveScript(IScriptable item)
|
||||
{
|
||||
_scriptableObjects.Remove(item);
|
||||
if (item is IFixedScriptable fs) _fixedScriptables.Remove(fs);
|
||||
}
|
||||
|
||||
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue