28.10.2020
SM.Core: + Particle System + scriptable system for scripts ~ Moved Texts- and Particles-namespace to SM.Base.Drawing ~ Changed how you tell the stopwatch to pause. (From method to property) ~ Fixed Randomize.GetFloat(min, max) ~ Now automaticly adds the DrawingBase.Transformation to DrawContext.ModelMatrix. No need to change DrawContext.Instances[0], anymore. SM.OGL: + "one-file-shader"-support SM2D: + DrawParticles (Control for Texture and Color not there yet) ~ Changed coordnate system to upper-right as (1,1) ~ Changed default shader to "one-file-shader"
This commit is contained in:
parent
03b3942732
commit
beb9c19081
45 changed files with 580 additions and 190 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -11,9 +13,15 @@ namespace SM.Base.Scene
|
|||
/// Contains a list of show items.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
public abstract class GenericItemCollection<TItem> : List<TItem>, IShowItem, IShowCollection<TItem>
|
||||
public abstract class GenericItemCollection<TItem> : List<TItem>, IShowItem, IShowCollection<TItem>, IScriptable
|
||||
where TItem : IShowItem
|
||||
{
|
||||
private List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||
|
||||
/// <summary>
|
||||
/// Currently active script objects.
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<IScriptable> ScriptableObjects => new ReadOnlyCollection<IScriptable>(_scriptableObjects);
|
||||
/// <inheritdoc />
|
||||
public List<TItem> Objects => this;
|
||||
|
||||
|
|
@ -24,18 +32,20 @@ namespace SM.Base.Scene
|
|||
public string Name { get; set; } = "Unnamed Item Collection";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICollection<string> Flags { get; set; } = new[] {"collection"};
|
||||
public ICollection<string> Flags { get; set; } = new List<string>() {"collection"};
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
for (var i = 0; i < Objects.Count; i++)
|
||||
this[i].Update(context);
|
||||
for (var i = 0; i < _scriptableObjects.Count; i++)
|
||||
_scriptableObjects[i].Update(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IShowCollection{TItem}.Draw" />
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
context.LastPassthough = this;
|
||||
|
||||
for (var i = 0; i < Objects.Count; i++)
|
||||
this[i].Draw(context);
|
||||
}
|
||||
|
|
@ -51,26 +61,68 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a item.
|
||||
/// Adds a item to the draw and the script collection, when applicable.
|
||||
/// </summary>
|
||||
public new void Add(TItem item)
|
||||
{
|
||||
AddObject(item);
|
||||
|
||||
if (item is IScriptable scriptable)
|
||||
AddScript(scriptable);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the object to the collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void AddObject(TItem item)
|
||||
{
|
||||
base.Add(item);
|
||||
item.Parent = this;
|
||||
item.OnAdded(this);
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds the script to the collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void AddScript(IScriptable item)
|
||||
{
|
||||
_scriptableObjects.Add(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a item.
|
||||
/// Removes a item from the draw and script collection, when applicable.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public new void Remove(TItem item)
|
||||
{
|
||||
RemoveObject(item);
|
||||
|
||||
if (item.GetType().IsAssignableFrom(typeof(IScriptable)))
|
||||
RemoveScript((IScriptable)item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the object from the draw collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void RemoveObject(TItem item)
|
||||
{
|
||||
base.Remove(item);
|
||||
item.Parent = null;
|
||||
item.OnRemoved(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the object from the script collection.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void RemoveScript(IScriptable item)
|
||||
{
|
||||
_scriptableObjects.Remove(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a object with this name or the default, if not available.
|
||||
/// <para>Not reclusive.</para>
|
||||
|
|
@ -111,6 +163,7 @@ namespace SM.Base.Scene
|
|||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
var obj = this[i];
|
||||
if (obj.Flags == null) continue;
|
||||
if (obj.Flags.Contains(flag)) list.Add(obj);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract class GenericScene
|
||||
{
|
||||
|
||||
|
||||
private IBackgroundItem _background;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -27,6 +29,9 @@ namespace SM.Base.Scene
|
|||
_background = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// If true, the scene was already initialized.
|
||||
/// </summary>
|
||||
public bool IsInitialized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -137,7 +142,6 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public override void Update(UpdateContext context)
|
||||
{
|
||||
_Background?.Update(context);
|
||||
_objectCollection.Update(context);
|
||||
_hud.Update(context);
|
||||
}
|
||||
|
|
|
|||
15
SMCode/SM.Base/Scene/IScriptable.cs
Normal file
15
SMCode/SM.Base/Scene/IScriptable.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a object as script.
|
||||
/// </summary>
|
||||
public interface IScriptable
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the object.
|
||||
/// </summary>
|
||||
void Update(UpdateContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,13 +26,7 @@ namespace SM.Base.Scene
|
|||
/// Contains specific flags for the object.
|
||||
/// </summary>
|
||||
ICollection<string> Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tells the object to update own systems.
|
||||
/// </summary>
|
||||
/// <param name="context">The update context</param>
|
||||
void Update(UpdateContext context);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tells the object to draw its object.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue