01.10.2020
+ Time controls (Stopwatch, Timers, Intervals) + Added smmeries to everything in SM.Base ~ Renamed Vectors to CVectors.
This commit is contained in:
parent
7acdba92f8
commit
97e638d9d9
44 changed files with 1092 additions and 289 deletions
|
|
@ -7,25 +7,36 @@ using OpenTK.Input;
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Time;
|
||||
using SM.OGL;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
public abstract class GenericWindow : GameWindow
|
||||
{
|
||||
private bool _loading = false;
|
||||
|
||||
public bool ForceViewportCamera { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This tells you the current world scale.
|
||||
/// </summary>
|
||||
protected Vector2 _worldScale = Vector2.Zero;
|
||||
/// <summary>
|
||||
/// This tells you the current aspect ratio of this window.
|
||||
/// </summary>
|
||||
public float Aspect { get; private set; } = 0f;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow() : base(1280, 720, GraphicsMode.Default, "Generic OGL Title", GameWindowFlags.Default,
|
||||
DisplayDevice.Default, 0, 0, GraphicsContextFlags.Default, null, true)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
GLSystem.INIT_SYSTEM();
|
||||
|
|
@ -42,6 +53,8 @@ namespace SM.Base
|
|||
base.OnLoad(e);
|
||||
_loading = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
|
@ -58,25 +71,47 @@ namespace SM.Base
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is triggered after all the window-loading has been done.
|
||||
/// </summary>
|
||||
protected virtual void OnLoaded()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the world scale.
|
||||
/// </summary>
|
||||
protected virtual void SetWorldScale() { }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
Deltatime.UpdateDelta = (float)e.Time;
|
||||
UpdateContext context = new UpdateContext()
|
||||
{
|
||||
KeyboardState = Keyboard.GetState(),
|
||||
MouseState = Mouse.GetState()
|
||||
};
|
||||
|
||||
Stopwatch.PerformTicks(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs the cursor and make sure it doesn't leave the window.
|
||||
/// </summary>
|
||||
/// <param name="makeItInvisible">If true, it makes the cursor invisible.</param>
|
||||
public void GrabCursor(bool makeItInvisible = true)
|
||||
{
|
||||
CursorGrabbed = true;
|
||||
CursorVisible = !makeItInvisible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ungrabs the cursor.
|
||||
/// </summary>
|
||||
public void UngrabCursor()
|
||||
{
|
||||
CursorGrabbed = false;
|
||||
|
|
@ -84,20 +119,38 @@ namespace SM.Base
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScene">The scene type</typeparam>
|
||||
/// <typeparam name="TItem">The base item type</typeparam>
|
||||
/// <typeparam name="TCamera">The camera type</typeparam>
|
||||
public abstract class GenericWindow<TScene, TItem, TCamera> : GenericWindow
|
||||
where TScene : GenericScene<TCamera, TItem>, new()
|
||||
where TItem : IShowItem
|
||||
where TCamera : GenericCamera, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// The viewport camera.
|
||||
/// </summary>
|
||||
public TCamera ViewportCamera { get; }
|
||||
/// <summary>
|
||||
/// This forces the render to use the viewport camera.
|
||||
/// </summary>
|
||||
public bool ForceViewportCamera { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The current scene.
|
||||
/// </summary>
|
||||
public TScene CurrentScene { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow()
|
||||
{
|
||||
ViewportCamera = new TCamera();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
DrawContext drawContext = new DrawContext()
|
||||
|
|
@ -119,6 +172,7 @@ namespace SM.Base
|
|||
SwapBuffers();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
|
@ -126,6 +180,10 @@ namespace SM.Base
|
|||
ViewportCamera.RecalculateWorld(_worldScale, Aspect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the scene.
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
public virtual void SetScene(TScene scene)
|
||||
{
|
||||
CurrentScene = scene;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue