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
|
|
@ -4,6 +4,9 @@ using System.Reflection;
|
|||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains utility functions for handling with assemblies.
|
||||
/// </summary>
|
||||
public class AssemblyUtility
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -22,8 +25,19 @@ namespace SM.Utility
|
|||
public static string ReadAssemblyFile(string path) { return ReadAssemblyFile(Assembly.GetCallingAssembly(), path); }
|
||||
|
||||
|
||||
public static Stream GetAssemblyStream(Assembly ass, string path) { return ass.GetManifestResourceStream(ass.GetName().Name + "." + path) ?? throw new InvalidOperationException("Assembly couldn't find resource at path '" + path + "'."); }
|
||||
/// <summary>
|
||||
/// Returns a stream of a requested resource.
|
||||
/// </summary>
|
||||
/// <param name="ass">The assembly the resource is in.</param>
|
||||
/// <param name="path">The path to the resource.</param>
|
||||
/// <returns>The stream</returns>
|
||||
public static Stream GetAssemblyStream(Assembly ass, string path) { return ass.GetManifestResourceStream(path) ?? throw new InvalidOperationException("Assembly couldn't find resource at path '" + path + "'."); }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a stream of a requested resource in the calling assembly.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the resource</param>
|
||||
/// <returns>The stream</returns>
|
||||
public static Stream GetAssemblyStream(string path) { return GetAssemblyStream(Assembly.GetCallingAssembly(), path); }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace SM.Utility
|
||||
{
|
||||
public class BezierCurve
|
||||
{
|
||||
public static float Calculate(float t, params float[] points)
|
||||
{
|
||||
int pointAmount = points.Length;
|
||||
int itterations = pointAmount - 1;
|
||||
|
||||
double x = Math.Pow(1 - t, itterations) * points[0];
|
||||
for (int i = 1; i < itterations; i++)
|
||||
{
|
||||
if (i % 2 == 0) x += itterations * (1 - t) * Math.Pow(t, itterations - 1) * points[i];
|
||||
else x += itterations * Math.Pow(1 - t, itterations - 1) * t * points[i];
|
||||
}
|
||||
|
||||
x += Math.Pow(t, itterations) * points[pointAmount - 1];
|
||||
return (float)x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,40 @@
|
|||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A assistant to control the delta time.
|
||||
/// </summary>
|
||||
public class Deltatime
|
||||
{
|
||||
/// <summary>
|
||||
/// The current update delta time.
|
||||
/// </summary>
|
||||
public static float UpdateDelta { get; internal set; }
|
||||
/// <summary>
|
||||
/// The current render delta time.
|
||||
/// </summary>
|
||||
public static float RenderDelta { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, it uses <see cref="RenderDelta"/>, otherwise <see cref="UpdateDelta"/>.
|
||||
/// <para>Default: false</para>
|
||||
/// </summary>
|
||||
public bool UseRender;
|
||||
/// <summary>
|
||||
/// Scaling of the delta time.
|
||||
/// <para>Default: 1</para>
|
||||
/// </summary>
|
||||
public float Scale;
|
||||
|
||||
/// <summary>
|
||||
/// The calculated delta time.
|
||||
/// </summary>
|
||||
public float DeltaTime => (UseRender ? RenderDelta : UpdateDelta) * Scale;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a delta time assistant.
|
||||
/// </summary>
|
||||
/// <param name="scale">The start scale for the delta time. Default: 1</param>
|
||||
/// <param name="useRender">If true, it uses <see cref="RenderDelta"/>, otherwise <see cref="UpdateDelta"/>. Default: false</param>
|
||||
public Deltatime(float scale = 1, bool useRender = false)
|
||||
{
|
||||
UseRender = useRender;
|
||||
|
|
|
|||
|
|
@ -2,20 +2,51 @@
|
|||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A global helper class for randomization.
|
||||
/// </summary>
|
||||
public class Randomize
|
||||
{
|
||||
/// <summary>
|
||||
/// The randomizer.
|
||||
/// </summary>
|
||||
public static Random Randomizer = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the seed for the randomizer.
|
||||
/// </summary>
|
||||
/// <param name="seed">The specified seed.</param>
|
||||
public static void SetSeed(int seed) { Randomizer = new Random(seed); }
|
||||
|
||||
public static bool GetBool(float tolerance) { return Randomizer.NextDouble() > tolerance; }
|
||||
/// <summary>
|
||||
/// Generates a double and checks if its under the tolerance.
|
||||
/// </summary>
|
||||
public static bool GetBool(float tolerance) { return Randomizer.NextDouble() < tolerance; }
|
||||
|
||||
/// <summary>
|
||||
/// Generates a integer.
|
||||
/// </summary>
|
||||
public static int GetInt() { return Randomizer.Next(); }
|
||||
/// <summary>
|
||||
/// Generates a integer with a maximum.
|
||||
/// </summary>
|
||||
public static int GetInt(int max) { return Randomizer.Next(max); }
|
||||
/// <summary>
|
||||
/// Generates a integer with a minimum and maximum
|
||||
/// </summary>
|
||||
public static int GetInt(int min, int max) { return Randomizer.Next(min, max); }
|
||||
|
||||
/// <summary>
|
||||
/// Generates a float between 0 and 1.
|
||||
/// </summary>
|
||||
public static float GetFloat() { return (float)Randomizer.NextDouble(); }
|
||||
/// <summary>
|
||||
/// Generates a float between 0 and the specified maximum.
|
||||
/// </summary>
|
||||
public static float GetFloat(float max) { return (float)Randomizer.NextDouble() * max; }
|
||||
/// <summary>
|
||||
/// Generates a float between the specified minimum and the specified maximum.
|
||||
/// </summary>
|
||||
public static float GetFloat(float min, float max) { return (float)Randomizer.NextDouble() * max + min; }
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue