1.0.10
+ Added property "CalculatedWorldScale", what always updates the world scale if required. ~ Changed how items can be inserted to a item collection. ~ AddObject(), AddScript(), RemoveObject(), RemoveScript() are now obsolte. ~ Fixed a issue, where the background was using the default mesh, what caused some visual errors if changed.
This commit is contained in:
parent
6cb1fea19a
commit
35c433fa85
7 changed files with 70 additions and 16 deletions
|
|
@ -66,6 +66,7 @@
|
||||||
<Compile Include="Drawing\TextureTransformation.cs" />
|
<Compile Include="Drawing\TextureTransformation.cs" />
|
||||||
<Compile Include="Drawing\Text\Font.cs" />
|
<Compile Include="Drawing\Text\Font.cs" />
|
||||||
<Compile Include="PostEffects\PostProcessUtility.cs" />
|
<Compile Include="PostEffects\PostProcessUtility.cs" />
|
||||||
|
<Compile Include="Scene\ICollectionItem.cs" />
|
||||||
<Compile Include="Scene\IFixedScriptable.cs" />
|
<Compile Include="Scene\IFixedScriptable.cs" />
|
||||||
<Compile Include="Shaders\MaterialShader.cs" />
|
<Compile Include="Shaders\MaterialShader.cs" />
|
||||||
<Compile Include="Drawing\Particles\ParticleContext.cs" />
|
<Compile Include="Drawing\Particles\ParticleContext.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
|
|
@ -91,13 +92,14 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a item to the draw and the script collection, when applicable.
|
/// Adds items to the draw and the script collection, when applicable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Add(params IShowItem[] items)
|
public void Add(params ICollectionItem[] items)
|
||||||
{
|
{
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
AddObject(item);
|
if (item is IShowItem show)
|
||||||
|
addObject(show);
|
||||||
|
|
||||||
if (item is IScriptable scriptable)
|
if (item is IScriptable scriptable)
|
||||||
AddScript(scriptable);
|
AddScript(scriptable);
|
||||||
|
|
@ -106,11 +108,33 @@ namespace SM.Base.Scene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the object to the collection.
|
/// Adds the object to the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
[Obsolete("Please use Add()")]
|
||||||
public void AddObject(IShowItem item)
|
public void AddObject(IShowItem item)
|
||||||
|
{
|
||||||
|
addObject(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the script to the collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
[Obsolete("Please use Add()")]
|
||||||
|
public void AddScript(IScriptable item)
|
||||||
|
{
|
||||||
|
addScript(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the object to the collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
private void addObject(IShowItem item)
|
||||||
{
|
{
|
||||||
base.Add(item);
|
base.Add(item);
|
||||||
item.Parent = this;
|
item.Parent = this;
|
||||||
|
|
@ -121,7 +145,8 @@ namespace SM.Base.Scene
|
||||||
/// Adds the script to the collection.
|
/// Adds the script to the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
public void AddScript(IScriptable item)
|
[Obsolete("Please use Add()")]
|
||||||
|
public void addScript(IScriptable item)
|
||||||
{
|
{
|
||||||
_scriptableObjects.Add(item);
|
_scriptableObjects.Add(item);
|
||||||
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
||||||
|
|
@ -132,11 +157,12 @@ namespace SM.Base.Scene
|
||||||
/// <para>If the object is a scriptable object, it will remove the object from that list as well.</para>
|
/// <para>If the object is a scriptable object, it will remove the object from that list as well.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public void Remove(params IShowItem[] items)
|
public void Remove(params ICollectionItem[] items)
|
||||||
{
|
{
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
RemoveObject(item);
|
if (item is IShowItem show)
|
||||||
|
RemoveObject(show);
|
||||||
|
|
||||||
if (item is IScriptable scriptable)
|
if (item is IScriptable scriptable)
|
||||||
RemoveScript(scriptable);
|
RemoveScript(scriptable);
|
||||||
|
|
@ -150,6 +176,7 @@ namespace SM.Base.Scene
|
||||||
/// Remove the object from the draw collection.
|
/// Remove the object from the draw collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
[Obsolete("Please use Remove()")]
|
||||||
public void RemoveObject(IShowItem item)
|
public void RemoveObject(IShowItem item)
|
||||||
{
|
{
|
||||||
base.Remove(item);
|
base.Remove(item);
|
||||||
|
|
@ -161,6 +188,7 @@ namespace SM.Base.Scene
|
||||||
/// Remove the object from the script collection.
|
/// Remove the object from the script collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
[Obsolete("Please use Remove()")]
|
||||||
public void RemoveScript(IScriptable item)
|
public void RemoveScript(IScriptable item)
|
||||||
{
|
{
|
||||||
_scriptableObjects.Remove(item);
|
_scriptableObjects.Remove(item);
|
||||||
|
|
|
||||||
10
SMCode/SM.Base/Scene/ICollectionItem.cs
Normal file
10
SMCode/SM.Base/Scene/ICollectionItem.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
namespace SM.Base.Scene
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Dummy interface for adding items.
|
||||||
|
/// </summary>
|
||||||
|
public interface ICollectionItem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ namespace SM.Base.Scene
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds requirements to object, to be properly used as a update and/or draw item.
|
/// Adds requirements to object, to be properly used as a update and/or draw item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IShowItem
|
public interface IShowItem : ICollectionItem
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parent of the object.
|
/// Parent of the object.
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Drawing;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
|
using SM.Base.Objects.Static;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Textures;
|
using SM.Base.Textures;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
|
|
@ -53,6 +54,7 @@ namespace SM2D.Drawing
|
||||||
public DrawBackground(Color4 color)
|
public DrawBackground(Color4 color)
|
||||||
{
|
{
|
||||||
Color = color;
|
Color = color;
|
||||||
|
Mesh = Plate.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -62,6 +64,7 @@ namespace SM2D.Drawing
|
||||||
public DrawBackground(Bitmap texture)
|
public DrawBackground(Bitmap texture)
|
||||||
{
|
{
|
||||||
Texture = (Texture) texture;
|
Texture = (Texture) texture;
|
||||||
|
Mesh = Plate.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -73,6 +76,7 @@ namespace SM2D.Drawing
|
||||||
{
|
{
|
||||||
Color = tint;
|
Color = tint;
|
||||||
Texture = (Texture) texture;
|
Texture = (Texture) texture;
|
||||||
|
Mesh = Plate.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using SM.Base;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
|
|
@ -38,6 +39,22 @@ namespace SM2D.Scene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Will always return a updated version of the world scale.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2 CalculatedWorldScale
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (ResizeCounter != _resizeCounter || _updateWorldScale)
|
||||||
|
{
|
||||||
|
CalculateWorldScale(SMRenderer.CurrentWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WorldScale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The world scale that got calculated.
|
/// The world scale that got calculated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using OpenTK.Graphics;
|
||||||
using SM.Base.Animation;
|
using SM.Base.Animation;
|
||||||
using SM.Base.Controls;
|
using SM.Base.Controls;
|
||||||
using SM.Base.Drawing.Text;
|
using SM.Base.Drawing.Text;
|
||||||
|
|
@ -32,17 +33,10 @@ namespace SM_TEST
|
||||||
|
|
||||||
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
||||||
window.ApplySetup(new Window2DSetup());
|
window.ApplySetup(new Window2DSetup());
|
||||||
window.SetRenderPipeline(new TestRenderPipeline());
|
|
||||||
|
|
||||||
window.SetScene(scene = new Scene());
|
window.SetScene(scene = new Scene());
|
||||||
|
|
||||||
DrawParticles particles = new DrawParticles(TimeSpan.FromSeconds(5))
|
scene.Background.Color = Color4.Blue;
|
||||||
{
|
|
||||||
Direction = new Vector2(0, 1),
|
|
||||||
DirectionRadius = 10
|
|
||||||
};
|
|
||||||
particles.Trigger();
|
|
||||||
scene.Objects.Add(particles);
|
|
||||||
|
|
||||||
window.UpdateFrame += WindowOnUpdateFrame;
|
window.UpdateFrame += WindowOnUpdateFrame;
|
||||||
window.RenderFrame += Window_RenderFrame;
|
window.RenderFrame += Window_RenderFrame;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue