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
|
|
@ -28,26 +28,7 @@ namespace SM.Base.Time
|
|||
protected override void Stopping(UpdateContext context)
|
||||
{
|
||||
TriggerEndAction(context);
|
||||
if (_stop)
|
||||
base.Stop();
|
||||
else Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will tell the interval to stop after the next iteration.
|
||||
/// <para>To stop immediately use <see cref="Cancel" /></para>
|
||||
/// </summary>
|
||||
public override void Stop()
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will stop the interval immediately.
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
base.Stop();
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
|
|
@ -13,20 +14,47 @@ namespace SM.Base.Time
|
|||
public class Stopwatch
|
||||
{
|
||||
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
|
||||
private bool _paused = false;
|
||||
|
||||
public bool Active { get; private set; } = false;
|
||||
|
||||
public bool Paused
|
||||
{
|
||||
get => _paused;
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
Pause();
|
||||
else
|
||||
Resume();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Running => Active && !Paused;
|
||||
|
||||
/// <summary>
|
||||
/// Contains how much time already has passed. (in seconds)
|
||||
/// </summary>
|
||||
public float Elapsed { get; private set; }
|
||||
public float Elapsed { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the TimeSpan of how much time already passed.
|
||||
/// </summary>
|
||||
public TimeSpan ElapsedSpan { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts the stopwatch.
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
if (Active) return;
|
||||
|
||||
_activeStopwatches.Add(this);
|
||||
Active = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Performs a tick.
|
||||
/// </summary>
|
||||
|
|
@ -34,6 +62,23 @@ namespace SM.Base.Time
|
|||
private protected virtual void Tick(UpdateContext context)
|
||||
{
|
||||
Elapsed += context.Deltatime;
|
||||
ElapsedSpan = TimeSpan.FromSeconds(Elapsed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resumes the timer.
|
||||
/// </summary>
|
||||
protected virtual void Resume()
|
||||
{
|
||||
_paused = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the timer.
|
||||
/// </summary>
|
||||
protected virtual void Pause()
|
||||
{
|
||||
_paused = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -41,6 +86,9 @@ namespace SM.Base.Time
|
|||
/// </summary>
|
||||
public virtual void Stop()
|
||||
{
|
||||
if (!Active) return;
|
||||
|
||||
Active = false;
|
||||
_activeStopwatches.Remove(this);
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +102,11 @@ namespace SM.Base.Time
|
|||
|
||||
internal static void PerformTicks(UpdateContext context)
|
||||
{
|
||||
for (var i = 0; i < _activeStopwatches.Count; i++) _activeStopwatches[i].Tick(context);
|
||||
for (var i = 0; i < _activeStopwatches.Count; i++)
|
||||
{
|
||||
if (_activeStopwatches[i].Paused) continue;
|
||||
_activeStopwatches[i].Tick(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ namespace SM.Base.Time
|
|||
/// </summary>
|
||||
protected virtual void Stopping(UpdateContext context)
|
||||
{
|
||||
EndAction?.Invoke(this, context);
|
||||
TriggerEndAction(context);
|
||||
Stop();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue