2021-19-03

SM.Base:
~ Improved Keyboard.AreSpecificKeysPressed(int, int)
~ Made GenericTransformation.LastMaster's set public
~ Made the fixed update use the property "IsExiting" to determent if it should stop.
~ The MainFramebuffer of each RenderPipeline now has always a name.

SM2D:
~ Moved the checking code of Mouse2D.MouseOver into a own method.
This commit is contained in:
Michel Fedde 2021-03-19 09:31:36 +01:00
parent c8db1ce8bc
commit 71a22df8bd
7 changed files with 31 additions and 18 deletions

View file

@ -82,7 +82,7 @@ namespace SM.Base.Controls
throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex)); throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex));
int length = endIndex - startIndex; int length = endIndex - startIndex;
for (int i = 0; i < length; i++) for (int i = 0; i < length + 1; i++)
{ {
int actualIndex = i + startIndex; int actualIndex = i + startIndex;
Key key = (Key) actualIndex; Key key = (Key) actualIndex;
@ -136,7 +136,7 @@ namespace SM.Base.Controls
bool success = false; bool success = false;
List<Key> keys = new List<Key>(); List<Key> keys = new List<Key>();
for (int i = 0; i < length; i++) for (int i = 0; i < length + 1; i++)
{ {
int actualIndex = i + startIndex; int actualIndex = i + startIndex;
Key key = (Key) actualIndex; Key key = (Key) actualIndex;

View file

@ -19,7 +19,7 @@ namespace SM.Base.Drawing
/// <summary> /// <summary>
/// The last matrix that was used to calculate the real world matrix. /// The last matrix that was used to calculate the real world matrix.
/// </summary> /// </summary>
public Matrix4 LastMaster { get; internal set; } public Matrix4 LastMaster { get; set; }
/// <summary> /// <summary>
/// The transformation in world space. /// The transformation in world space.

View file

@ -121,12 +121,6 @@ namespace SM.Base.Window
Mouse.MouseMoveEvent(e, this); Mouse.MouseMoveEvent(e, this);
} }
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
_fixedUpdateThread?.Abort();
}
public void Update(UpdateContext context) public void Update(UpdateContext context)
{ {
@ -201,7 +195,7 @@ namespace SM.Base.Window
private void ExecuteFixedUpdate() private void ExecuteFixedUpdate()
{ {
Stopwatch deltaStop = new Stopwatch(); Stopwatch deltaStop = new Stopwatch();
while (Thread.CurrentThread.ThreadState != System.Threading.ThreadState.AbortRequested) while (!IsExiting)
{ {
deltaStop.Restart(); deltaStop.Restart();
@ -210,7 +204,8 @@ namespace SM.Base.Window
CurrentScene?.FixedUpdate(context); CurrentScene?.FixedUpdate(context);
long delta = deltaStop.ElapsedMilliseconds; long delta = deltaStop.ElapsedMilliseconds;
Thread.Sleep(Math.Max((int)(Deltatime.FixedUpdateDelta * 1000) - (int)delta, 0)); int waitTime = Math.Max((int)(Deltatime.FixedUpdateDelta * 1000) - (int)delta, 0);
Thread.Sleep(waitTime);
} }
} }
} }

View file

@ -36,7 +36,7 @@ namespace SM.Base.Window
/// This contains the default shader. /// This contains the default shader.
/// <para>Default: <see cref="SMRenderer.DefaultMaterialShader"/></para> /// <para>Default: <see cref="SMRenderer.DefaultMaterialShader"/></para>
/// </summary> /// </summary>
public virtual MaterialShader DefaultShader { get; protected set; } = SMRenderer.DefaultMaterialShader; public virtual MaterialShader DefaultShader { get; protected set; }
/// <summary> /// <summary>
/// Here you can set a default material. /// Here you can set a default material.
/// </summary> /// </summary>
@ -53,6 +53,8 @@ namespace SM.Base.Window
/// <inheritdoc/> /// <inheritdoc/>
public virtual void Initialization() public virtual void Initialization()
{ {
MainFramebuffer.Name = GetType().Name + ".MainFramebuffer";
if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer); if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer);
DefaultShader ??= SMRenderer.DefaultMaterialShader; DefaultShader ??= SMRenderer.DefaultMaterialShader;
} }

View file

@ -2,6 +2,7 @@
using OpenTK; using OpenTK;
using SM.Base.Controls; using SM.Base.Controls;
using SM.Base.Scene; using SM.Base.Scene;
using SM.OGL.Mesh;
using SM2D.Scene; using SM2D.Scene;
using SM2D.Types; using SM2D.Types;
@ -48,12 +49,11 @@ namespace SM2D.Controls
foreach (TObject item in checkingObjects) foreach (TObject item in checkingObjects)
{ {
Matrix4 worldPos = item.Transform.InWorldSpace;
item.Mesh.BoundingBox.GetBounds(worldPos, out Vector3 min, out Vector3 max); if (MouseOver(mousePos, item.Mesh.BoundingBox, item.Transform))
if (mousePos.X > min.X && mousePos.X < max.X &&
mousePos.Y > min.Y && mousePos.Y < max.Y)
{ {
Matrix4 worldPos = item.Transform.InWorldSpace;
// if z is greater than distance // if z is greater than distance
if (worldPos[3, 2] > distance) if (worldPos[3, 2] > distance)
{ {
@ -63,9 +63,24 @@ namespace SM2D.Controls
success = true; success = true;
} }
} }
return success; return success;
} }
public static bool MouseOver(Vector2 mousePos, BoundingBox boundingBox, Transformation transform)
{
Matrix4 worldPos = transform.InWorldSpace;
boundingBox.GetBounds(worldPos, out Vector3 min, out Vector3 max);
if (mousePos.X > min.X && mousePos.X < max.X &&
mousePos.Y > min.Y && mousePos.Y < max.Y)
{
return true;
}
return false;
}
} }
} }

View file

@ -30,6 +30,7 @@ namespace SM_TEST
window.ApplySetup(new Window2DSetup() {WorldScale = new Vector2(0,1000)}); window.ApplySetup(new Window2DSetup() {WorldScale = new Vector2(0,1000)});
window.SetRenderPipeline(new TestRenderPipeline()); window.SetRenderPipeline(new TestRenderPipeline());
window.SetScene(scene = new Scene()); window.SetScene(scene = new Scene());
window.RunFixedUpdate(60);
window.Load += WindowOnLoad; window.Load += WindowOnLoad;
window.RenderFrame += WindowOnUpdateFrame; window.RenderFrame += WindowOnUpdateFrame;
window.Run(); window.Run();

View file

@ -13,7 +13,7 @@ namespace SM_TEST
public override void Initialization() public override void Initialization()
{ {
MainFramebuffer = CreateWindowFramebuffer(0); MainFramebuffer = CreateWindowFramebuffer(16);
_postBuffer = CreateWindowFramebuffer(); _postBuffer = CreateWindowFramebuffer();
Framebuffers.Add(_postBuffer); Framebuffers.Add(_postBuffer);