Added Summeries

This commit is contained in:
Michel Fedde 2021-03-19 20:59:02 +01:00
parent 71a22df8bd
commit 8296d9b8a9
47 changed files with 812 additions and 177 deletions

View file

@ -28,6 +28,18 @@ namespace SM.Base.Controls
/// </summary>
public static Vector2 InScreenNormalized { get; private set; }
/// <summary>
/// This returns true, if the left mouse button was pressed.
/// <para>Its pretty much: IsDown(MouseButton.Left, true)</para>
/// </summary>
public static bool LeftClick => IsDown(MouseButton.Left, true);
/// <summary>
/// This returns true, if the right mouse button was pressed.
/// <para>Its pretty much: IsDown(MouseButton.Right, true)</para>
/// </summary>
public static bool RightClick => IsDown(MouseButton.Right, true);
/// <summary>
/// The event to update the values.
/// </summary>
@ -53,11 +65,21 @@ namespace SM.Base.Controls
_mouseState = OpenTK.Input.Mouse.GetState();
}
/// <summary>
/// Checks if the mouse is pressed.
/// </summary>
/// <param name="button"></param>
/// <param name="once">If true, it will not get called, when it was pressed in the last update.</param>
public static bool IsDown(MouseButton button, bool once = false)
{
return _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
}
/// <summary>
/// Checks if the mouse is not pressed.
/// </summary>
/// <param name="button"></param>
/// <param name="once">If true, it will not get called, when it was not pressed in the last update.</param>
public static bool IsUp(MouseButton button, bool once = false)
{
return _mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));

View file

@ -55,6 +55,7 @@ namespace SM.Base.Drawing
/// </summary>
public bool Active { get; set; } = true;
/// <inheritdoc />
public bool RenderActive { get; set; } = true;
/// <inheritdoc />

View file

@ -34,19 +34,10 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="GLWpfControl, Version=3.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.GLWpfControl.3.2.3\lib\net452\GLWpfControl.dll</HintPath>
</Reference>
<Reference Include="OpenTK, Version=3.3.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.XInput, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />

View file

@ -15,8 +15,8 @@ namespace SM.Base.Scene
/// </summary>
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable, IFixedScriptable
{
private List<IScriptable> _scriptableObjects = new List<IScriptable>();
private List<IFixedScriptable> _fixedScriptables = new List<IFixedScriptable>();
private readonly List<IScriptable> _scriptableObjects = new List<IScriptable>();
private readonly List<IFixedScriptable> _fixedScriptables = new List<IFixedScriptable>();
/// <summary>
/// Currently active script objects.
@ -45,6 +45,7 @@ namespace SM.Base.Scene
/// <inheritdoc />
public bool RenderActive { get; set; } = true;
/// <inheritdoc />
public virtual void FixedUpdate(FixedUpdateContext context)
{
if (!Active || !UpdateActive) return;
@ -126,6 +127,11 @@ namespace SM.Base.Scene
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
}
/// <summary>
/// Removes an object from the drawing list.
/// <para>If the object is a scriptable object, it will remove the object from that list as well.</para>
/// </summary>
/// <param name="items"></param>
public void Remove(params IShowItem[] items)
{
foreach (var item in items)
@ -161,6 +167,12 @@ namespace SM.Base.Scene
if (item is IFixedScriptable fs) _fixedScriptables.Remove(fs);
}
/// <summary>
/// Returns all objects in the drawing list.
/// <para>Not reclusive.</para>
/// </summary>
/// <param name="includeCollections">If true, it will add collections as well.</param>
/// <returns></returns>
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
{
List<IShowItem> items = new List<IShowItem>();
@ -224,7 +236,6 @@ namespace SM.Base.Scene
/// <summary>
/// Contains a list of show items with transformation.
/// </summary>
/// <typeparam name="TItem">The type of show items.</typeparam>
/// <typeparam name="TTransformation">The type of transformation.</typeparam>
public abstract class GenericItemCollection<TTransformation> : GenericItemCollection,
IShowTransformItem<TTransformation>

View file

@ -213,18 +213,24 @@ namespace SM.Base.Scene
/// A generic scene that imports different functions.
/// </summary>
/// <typeparam name="TCamera">The type of cameras.</typeparam>
/// <typeparam name="TItem">The type of show items.</typeparam>
/// <typeparam name="TCollection">The type for collections</typeparam>
public abstract class GenericScene<TCamera, TCollection> : GenericScene
where TCamera : GenericCamera, new()
where TCollection : GenericItemCollection, new()
{
/// <summary>
/// Objects inside the scene, but as the collection type.
/// </summary>
public new TCollection Objects
{
get => (TCollection) base.Objects;
set => base.Objects = value;
}
/// <summary>
/// HUD-Objects inside the scene, but as the collection type.
/// </summary>
public new TCollection HUD
{
get
@ -235,18 +241,28 @@ namespace SM.Base.Scene
set => base.HUD = value;
}
/// <summary>
/// The active camera, that is used if the context doesn't force the viewport camera.
/// <para>If none set, it automaticly uses the viewport camera.</para>
/// </summary>
public new TCamera Camera
{
get => (TCamera) base.Camera;
set => base.Camera = value;
}
/// <summary>
/// A camera to control the HUD.
/// </summary>
public new TCamera HUDCamera
{
get => (TCamera) base.HUDCamera;
set => base.HUDCamera = value;
}
/// <summary>
/// A camera to control the background.
/// </summary>
public new TCamera BackgroundCamera
{
get => (TCamera) base.BackgroundCamera;

View file

@ -55,19 +55,36 @@ namespace SM.Base.Scene
void OnRemoved(object sender);
}
/// <summary>
/// Interface to implement transformation.
/// </summary>
/// <typeparam name="TTransform"></typeparam>
public interface ITransformItem<TTransform>
where TTransform : GenericTransformation
{
/// <summary>
/// Controls the transformation of the object.
/// </summary>
TTransform Transform { get; set; }
}
/// <summary>
/// Merges <see cref="IShowItem"/> and <see cref="ITransformItem{TTransform}"/>.
/// </summary>
/// <typeparam name="TTransform"></typeparam>
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
where TTransform : GenericTransformation
{
}
/// <summary>
/// Interface to implement models in the object.
/// </summary>
public interface IModelItem
{
/// <summary>
/// The mesh the rendering should use.
/// </summary>
GenericMesh Mesh { get; set; }
}
}

View file

@ -96,7 +96,6 @@ namespace SM.Base.Types
/// <summary>
/// Conversion from <see cref="float" /> to One-dimensional Vector.
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
//public static implicit operator CVector1(float f) => new CVector1(f);
protected virtual float GetLengthProcess()
@ -104,14 +103,27 @@ namespace SM.Base.Types
return X * X;
}
/// <summary>
/// Normalizes the vector.
/// </summary>
/// <param name="length"></param>
protected virtual void NormalizationProcess(float length)
{
X *= length;
}
/// <summary>
/// This triggers the <see cref="Changed"/> event.
/// </summary>
protected void TriggerChanged()
{
Changed?.Invoke();
}
/// <inheritdoc />
public override string ToString()
{
return X.ToString();
}
}
}

View file

@ -46,6 +46,12 @@ namespace SM.Base.Types
Y *= length;
}
/// <inheritdoc />
public override string ToString()
{
return "{"+X+"; "+Y+"}";
}
/// <summary>
/// Sets each component to the same value
/// </summary>
@ -58,7 +64,6 @@ namespace SM.Base.Types
/// <summary>
/// Sets each component to the <see cref="Vector2" /> counter-part.
/// </summary>
/// <param name="vector"></param>
public void Set(Vector2 vector, bool triggerChanged = true)
{
Set(vector.X, vector.Y, triggerChanged);
@ -67,8 +72,6 @@ namespace SM.Base.Types
/// <summary>
/// Sets the a own value to each component.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void Set(float x, float y, bool triggerChanged = true)
{
Y = y;

View file

@ -46,6 +46,12 @@ namespace SM.Base.Types
Z *= length;
}
/// <inheritdoc />
public override string ToString()
{
return "{" + X + "; " + Y + "}";
}
/// <inheritdoc />
public override void Set(float uniform, bool triggerChanged = true)
{

View file

@ -6,12 +6,24 @@ using SM.Base.Scene;
namespace SM.Base.Window
{
/// <summary>
/// A context that gets send when a window want to update the scene.
/// </summary>
public struct UpdateContext
{
/// <summary>
/// The window what triggered the updated.
/// </summary>
public IGenericWindow Window;
/// <summary>
/// A current update delta time. Equivalent to <see cref="SMRenderer.DefaultDeltatime"/>.
/// </summary>
public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime;
/// <summary>
/// The scene that gets updated.
/// </summary>
public GenericScene Scene;
}
}

View file

@ -18,17 +18,80 @@ using Mouse = SM.Base.Controls.Mouse;
namespace SM.Base.Window
{
/// <summary>
/// This provides the main entry, by executing the window.
/// </summary>
public class GLWindow : GameWindow, IGenericWindow
{
private Vector2 _flagWindowSize;
private Thread _fixedUpdateThread;
private WindowFlags _windowFlags;
public WindowFlags WindowFlags;
/// <inheritdoc />
public bool Loading { get; private set; } = true;
/// <inheritdoc />
public float AspectRatio { get; set; }
/// <inheritdoc />
public GenericCamera ViewportCamera { get; set; }
/// <inheritdoc />
public bool ForceViewportCamera { get; set; }
/// <inheritdoc />
public bool DrawWhileUnfocused { get; set; } = true;
/// <inheritdoc />
public bool UpdateWhileUnfocused { get; set; } = false;
/// <inheritdoc />
public Vector2 WindowSize { get; set; }
/// <inheritdoc />
public ISetup AppliedSetup { get; private set; }
/// <inheritdoc />
public new event Action<IGenericWindow> Resize;
/// <inheritdoc />
public new event Action<IGenericWindow> Load;
/// <inheritdoc />
public GenericScene CurrentScene { get; private set; }
/// <inheritdoc />
public RenderPipeline CurrentRenderPipeline { get; private set; }
/// <summary>
/// Gets/Sets the current window flag.
/// </summary>
public WindowFlags WindowFlags
{
get => _windowFlags;
set
{
if (_windowFlags != value)
{
_windowFlags = value;
ChangeWindowFlag(value);
}
}
}
/// <summary>
/// Loads the window with default values.
/// <para>Width: 1280px; Height: 720px; Title: Generic OpenGL Title; WindowFlag: Window</para>
/// </summary>
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
{
}
/// <summary>
/// Loads the window with custom values.
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="title"></param>
/// <param name="flags"></param>
/// <param name="vSync"></param>
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default,
GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion,
@ -37,39 +100,16 @@ namespace SM.Base.Window
VSync = vSync;
_flagWindowSize = new Vector2(width, height);
ChangeWindowFlag(flags);
WindowFlags = flags;
}
public bool Loading { get; private set; } = true;
public float AspectRatio { get; set; }
public GenericCamera ViewportCamera { get; set; }
public bool ForceViewportCamera { get; set; }
public bool DrawWhileUnfocused { get; set; } = true;
public bool UpdateWhileUnfocused { get; set; } = false;
public Vector2 WindowSize { get; set; }
public ISetup AppliedSetup { get; private set; }
public new event Action<IGenericWindow> Resize;
public new event Action<IGenericWindow> Load;
public GenericScene CurrentScene { get; private set; }
public RenderPipeline CurrentRenderPipeline { get; private set; }
public void TriggerLoad()
{
Load?.Invoke(this);
}
public void TriggerResize()
{
Resize?.Invoke(this);
}
/// <summary>
/// A event that gets executed when the window is done loading.
/// </summary>
public event Action<IGenericWindow> Loaded;
/// <inheritdoc />
protected override void OnLoad(EventArgs e)
{
WindowCode.Load(this);
@ -78,6 +118,7 @@ namespace SM.Base.Window
base.OnLoad(e);
}
/// <inheritdoc />
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
@ -94,6 +135,7 @@ namespace SM.Base.Window
}
}
/// <inheritdoc />
protected override void OnUpdateFrame(FrameEventArgs e)
{
if (!Focused && !UpdateWhileUnfocused) return;
@ -104,6 +146,7 @@ namespace SM.Base.Window
}
/// <inheritdoc />
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
@ -115,23 +158,40 @@ namespace SM.Base.Window
GLDebugging.CheckGLErrors();
}
/// <inheritdoc />
protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
Mouse.MouseMoveEvent(e, this);
}
/// <inheritdoc />
public void TriggerLoad()
{
Load?.Invoke(this);
}
/// <inheritdoc />
public void TriggerResize()
{
Resize?.Invoke(this);
}
/// <inheritdoc />
public void Update(UpdateContext context)
{
}
/// <inheritdoc />
public void ApplySetup(ISetup setup)
{
AppliedSetup = setup;
setup.Applied(this);
}
/// <inheritdoc />
public void SetScene(GenericScene scene)
{
if (Loading)
@ -144,6 +204,7 @@ namespace SM.Base.Window
CurrentScene = scene;
}
/// <inheritdoc />
public void SetRenderPipeline(RenderPipeline renderPipeline)
{
if (Loading)
@ -156,34 +217,12 @@ namespace SM.Base.Window
CurrentRenderPipeline = renderPipeline;
}
public void ChangeWindowFlag(WindowFlags newFlag)
{
WindowFlags = newFlag;
switch (newFlag)
{
case WindowFlags.Window:
Width = (int) _flagWindowSize.X;
Height = (int) _flagWindowSize.Y;
WindowBorder = WindowBorder.Resizable;
break;
case WindowFlags.BorderlessWindow:
WindowBorder = WindowBorder.Hidden;
X = Screen.PrimaryScreen.Bounds.Left;
Y = Screen.PrimaryScreen.Bounds.Top;
Width = Screen.PrimaryScreen.Bounds.Width;
Height = Screen.PrimaryScreen.Bounds.Height;
break;
case WindowFlags.ExclusiveFullscreen:
break;
default:
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
}
}
/// <summary>
/// Starts the fixed update loop.
/// <para>Need to get executed before <see cref="IFixedScriptable"/> can be used.</para>
/// </summary>
/// <param name="updatesPerSecond"></param>
public void RunFixedUpdate(float updatesPerSecond)
{
Deltatime.FixedUpdateDelta = 1 / (float)updatesPerSecond;
@ -208,5 +247,31 @@ namespace SM.Base.Window
Thread.Sleep(waitTime);
}
}
private void ChangeWindowFlag(WindowFlags newFlag)
{
switch (newFlag)
{
case WindowFlags.Window:
Width = (int)_flagWindowSize.X;
Height = (int)_flagWindowSize.Y;
WindowBorder = WindowBorder.Resizable;
break;
case WindowFlags.BorderlessWindow:
WindowBorder = WindowBorder.Hidden;
X = Screen.PrimaryScreen.Bounds.Left;
Y = Screen.PrimaryScreen.Bounds.Top;
Width = Screen.PrimaryScreen.Bounds.Width;
Height = Screen.PrimaryScreen.Bounds.Height;
break;
case WindowFlags.ExclusiveFullscreen:
break;
default:
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
}
}
}
}

View file

@ -10,39 +10,106 @@ using SM.OGL.Framebuffer;
namespace SM.Base.Window
{
/// <summary>
/// This interface sets ground functions for windows.
/// </summary>
public interface IGenericWindow : IFramebufferWindow
{
/// <summary>
/// If true, the window is currently loading.
/// </summary>
bool Loading { get; }
/// <summary>
/// Holds the aspect ratio of the window.
/// </summary>
float AspectRatio { get; set; }
/// <summary>
/// The viewport camera is used, when no camera is found in the scene.
/// </summary>
GenericCamera ViewportCamera { get; set; }
/// <summary>
/// Turning this to true, will force the window to render in the viewport camera.
/// </summary>
bool ForceViewportCamera { get; set; }
/// <summary>
/// Turning this to false will not allow drawing while the window is not in focus.
/// </summary>
bool DrawWhileUnfocused { get; set; }
/// <summary>
/// Turning this to false will not allow updating while the window is not in focus.
/// </summary>
bool UpdateWhileUnfocused { get; set; }
/// <summary>
/// Contains the window size.
/// </summary>
Vector2 WindowSize { get; set; }
/// <summary>
/// The rectangle the window is using.
/// </summary>
Rectangle ClientRectangle { get; }
/// <summary>
/// The setup that was applied to the window.
/// </summary>
ISetup AppliedSetup { get; }
/// <summary>
/// The scene that is currently used.
/// </summary>
GenericScene CurrentScene { get; }
/// <summary>
/// The render pipeline that is currently used.
/// </summary>
RenderPipeline CurrentRenderPipeline { get; }
/// <summary>
/// An event, when the window resizes.
/// </summary>
event Action<IGenericWindow> Resize;
/// <summary>
/// An event, when the window is loading.
/// </summary>
event Action<IGenericWindow> Load;
/// <summary>
/// This gets executed, when the window should update something.
/// </summary>
/// <param name="context">The context of the update.</param>
void Update(UpdateContext context);
/// <summary>
/// This applies a setup to the window.
/// </summary>
/// <param name="setup"></param>
void ApplySetup(ISetup setup);
/// <summary>
/// This sets a scene for the window to use.
/// </summary>
/// <param name="scene"></param>
void SetScene(GenericScene scene);
/// <summary>
/// This sets a render pipeline, from where the scene gets rendered.
/// </summary>
/// <param name="renderPipeline"></param>
void SetRenderPipeline(RenderPipeline renderPipeline);
/// <summary>
/// This triggeres the <see cref="Load"/> event.
/// </summary>
void TriggerLoad();
/// <summary>
/// This triggeres the <see cref="Resize"/> event.
/// </summary>
void TriggerResize();
/// <summary>
/// This closes the window.
/// </summary>
void Close();
}
}

View file

@ -1,8 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
</packages>