use individual panel define as compute unit, kernel is now storage and loading unit
This commit is contained in:
@@ -35,6 +35,7 @@ using StgSharp.Timing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
@@ -58,6 +59,7 @@ namespace StgSharp.Controls
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => marker.TextureCoord;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace StgSharp.Internal
|
||||
return;
|
||||
}
|
||||
for (int i = begin; i < 255; i++) {
|
||||
Data[i] = Scaler.Random<byte>();
|
||||
Data[i] = Scalar.Random<byte>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace StgSharp.Mathematics
|
||||
public static partial class GeometryScaler
|
||||
{
|
||||
|
||||
internal const float DegToRad = 180 / Scaler.Pi;
|
||||
internal const float DegToRad = 180 / Scalar.Pi;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Radius r)
|
||||
@@ -168,7 +168,7 @@ namespace StgSharp.Mathematics
|
||||
|
||||
public static implicit operator Degree(Radius r)
|
||||
{
|
||||
return new Degree((r._radius * 180) / Scaler.Pi);
|
||||
return new Degree((r._radius * 180) / Scalar.Pi);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,13 @@ namespace StgSharp.Graphics.OpenGL
|
||||
[FieldOffset(0)] internal int SignedValue;
|
||||
[FieldOffset(0)] internal uint Value;
|
||||
|
||||
public GlHandle()
|
||||
{
|
||||
Unsafe.SkipInit(out Value);
|
||||
Unsafe.SkipInit(out SignedValue);
|
||||
Unsafe.SkipInit(out this);
|
||||
}
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IMatrixPanel"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.HighPerformance
|
||||
{
|
||||
public interface IMatrixPanel<T> : IDisposable where T: unmanaged,INumber<T>
|
||||
{
|
||||
|
||||
static abstract int KernelColumnCount { get; }
|
||||
|
||||
static abstract int KernelRowCount { get; }
|
||||
|
||||
static abstract int ElementCount { get; }
|
||||
|
||||
static abstract nuint Size { get; }
|
||||
|
||||
void Dispose();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Buffer for SSE targeted matrix panel, size of a panel is 4x4 elements, and no smaller than
|
||||
/// 16 bytes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of matrix element.
|
||||
/// </typeparam>
|
||||
public unsafe struct MatrixPanelSSE<T> : IMatrixPanel<T> where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private MatrixKernel<T> _buffer;
|
||||
|
||||
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
|
||||
public MatrixPanelSSE() { }
|
||||
|
||||
public static int KernelColumnCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
int size = sizeof(T);
|
||||
return size < 4 ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static int KernelRowCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
int size = sizeof(T);
|
||||
return size < 4 ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ElementCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
int size = sizeof(T);
|
||||
return size < 4 ? 64 / size : 16;
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe nuint Size
|
||||
{
|
||||
get
|
||||
{
|
||||
nuint size = (nuint)sizeof(T);
|
||||
return size < 4 ? 64 : 16 * size;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MatrixPanelSSE<T>* Create()
|
||||
{
|
||||
MatrixPanelSSE<T>* kernel = (MatrixPanelSSE<T>*)NativeMemory.AlignedAlloc(Size, 16);
|
||||
return kernel;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Destroy(MatrixPanelSSE<T>* kernel)
|
||||
{
|
||||
NativeMemory.AlignedFree(kernel);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (MatrixPanelSSE<T>* thisPtr = &this) {
|
||||
NativeMemory.AlignedFree(thisPtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Buffer for AVX targeted matrix panel, size of a panel is 4x4 elements, and no smaller than
|
||||
/// 16 bytes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of matrix element.
|
||||
/// </typeparam>
|
||||
public unsafe struct MatrixPanelAVX<T> : IMatrixPanel<T> where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private M512 _buffer;
|
||||
|
||||
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
|
||||
public MatrixPanelAVX() { }
|
||||
|
||||
public static unsafe int ElementCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
int size = sizeof(T);
|
||||
return size < 4 ? 128 / size : 16;
|
||||
}
|
||||
}
|
||||
|
||||
public static int KernelColumnCount => 2;
|
||||
|
||||
public static int KernelRowCount => 2;
|
||||
|
||||
public static unsafe nuint Size
|
||||
{
|
||||
get
|
||||
{
|
||||
nuint size = (nuint)sizeof(T);
|
||||
return size < 4 ? 128 : 16 * size;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MatrixPanelAVX<T>* Create()
|
||||
{
|
||||
MatrixPanelAVX<T>* kernel = (MatrixPanelAVX<T>*)NativeMemory.AlignedAlloc(Size, 16);
|
||||
return kernel;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Destroy(MatrixPanelAVX<T>* kernel)
|
||||
{
|
||||
NativeMemory.AlignedFree(kernel);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (MatrixPanelAVX<T>* thisPtr = &this) {
|
||||
NativeMemory.AlignedFree(thisPtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Buffer for AVX512 targeted matrix panel, size of a panel is 4x4 elements, and no smaller
|
||||
/// than 16 bytes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of matrix element.
|
||||
/// </typeparam>
|
||||
public unsafe struct MatrixComputeKernelAVX512<T> : IMatrixPanel<T> where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private M512 _buffer;
|
||||
|
||||
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
|
||||
public MatrixComputeKernelAVX512() { }
|
||||
|
||||
public readonly unsafe int ElementCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
int size = sizeof(T);
|
||||
return size < 4 ? 128 / size : 16;
|
||||
}
|
||||
}
|
||||
|
||||
public static int KernelColumnCount { get; }
|
||||
|
||||
public static int KernelRowCount { get; }
|
||||
|
||||
public static unsafe nuint Size
|
||||
{
|
||||
get
|
||||
{
|
||||
nuint size = (nuint)sizeof(T);
|
||||
return size < 4 ? 128 : 16 * size;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MatrixComputeKernelAVX512<T>* Create()
|
||||
{
|
||||
MatrixComputeKernelAVX512<T>* kernel = (MatrixComputeKernelAVX512<T>*)NativeMemory.AlignedAlloc(Size, 16);
|
||||
return kernel;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Destroy(MatrixComputeKernelAVX512<T>* kernel)
|
||||
{
|
||||
NativeMemory.AlignedFree(kernel);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (MatrixComputeKernelAVX512<T>* thisPtr = &this) {
|
||||
NativeMemory.AlignedFree(thisPtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
far = distance + depthRange.back,
|
||||
offsetX = offset.X,
|
||||
offsetY = offset.Y,
|
||||
width = Scaler.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
||||
width = Scalar.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
||||
height = width * size.Y / size.X;
|
||||
|
||||
_projection.column[0].X = 2 * near / width;
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public static float GetAngle(Vec2 vec1, Vec2 vec2)
|
||||
{
|
||||
return Scaler.ACos(
|
||||
return Scalar.ACos(
|
||||
1 / (vec1.GetLength() * vec2.GetLength()));
|
||||
}
|
||||
|
||||
public static float GetAngle(Vec3 vec1, Vec3 vec2)
|
||||
{
|
||||
return Scaler.ACos((vec1 * vec2) / (vec1.GetLength() * vec2.GetLength()));
|
||||
return Scalar.ACos((vec1 * vec2) / (vec1.GetLength() * vec2.GetLength()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public static float GetLength(this Vec3 vec)
|
||||
{
|
||||
return Scaler.Sqrt(vec.Dot(vec));
|
||||
return Scalar.Sqrt(vec.Dot(vec));
|
||||
}
|
||||
|
||||
public static float GetLength(this Vec2 vec)
|
||||
{
|
||||
return Scaler.Sqrt(vec.Dot(vec));
|
||||
return Scalar.Sqrt(vec.Dot(vec));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -29,7 +29,7 @@ using System;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
private const float
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -33,7 +33,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
public static float MaxOf(params float[] stream)
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace StgSharp.Mathematics
|
||||
{
|
||||
public unsafe delegate float ScalarCalcHandler(float* x);
|
||||
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
private const uint MEM_COMMIT = 0x1000;
|
||||
@@ -40,7 +40,7 @@ namespace StgSharp.Mathematics
|
||||
private const uint MEM_RESERVE = 0x2000;
|
||||
private const uint PAGE_EXECUTE_READWRITE = 0x40;
|
||||
|
||||
static Scaler() { }
|
||||
static Scalar() { }
|
||||
|
||||
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
|
||||
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
public const float E = 2.718281828f;
|
||||
|
||||
@@ -29,7 +29,7 @@ using System;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
private static readonly uint[] factorialResult = [
|
||||
|
||||
@@ -29,7 +29,7 @@ using System;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
private static readonly float[] logArray = {
|
||||
|
||||
@@ -29,7 +29,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -81,7 +81,7 @@ namespace StgSharp.Mathematics
|
||||
return 0;
|
||||
}
|
||||
|
||||
z = Scaler.Log(x) * y;
|
||||
z = Scalar.Log(x) * y;
|
||||
|
||||
bool sign = false;
|
||||
if (z < 0)
|
||||
|
||||
@@ -38,7 +38,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
private static byte[] randomSeed;
|
||||
@@ -61,9 +61,9 @@ namespace StgSharp.Mathematics
|
||||
{
|
||||
float seed = currentSeed;
|
||||
|
||||
float sample = Scaler.Pow(Scaler.SeedSqrt(seed), 2);
|
||||
float sample = Scalar.Pow(Scalar.SeedSqrt(seed), 2);
|
||||
float sample2 = (sample - seed) / seed;
|
||||
sample2 = Scaler.Abs(sample2);
|
||||
sample2 = Scalar.Abs(sample2);
|
||||
|
||||
if (sample == 1) {
|
||||
sample = sample2;
|
||||
@@ -76,7 +76,7 @@ namespace StgSharp.Mathematics
|
||||
if (result == 0)
|
||||
{
|
||||
currentSeed = sample2 + 0.1f;
|
||||
result = Scaler.LowProceisionRandom();
|
||||
result = Scalar.LowProceisionRandom();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
public static unsafe partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
public const float Pi = 3.1415926f;
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
public static unsafe float SeedSqrt(float x)
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class Scaler
|
||||
public static partial class Scalar
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace StgSharp.Stg
|
||||
public void Init(Radius angleStride, string name)
|
||||
{
|
||||
primeArgs = new ViewPort(
|
||||
1, (int)((new Radius(Scaler.Pi)) / angleStride), name, IntPtr.Zero);
|
||||
1, (int)((new Radius(Scalar.Pi)) / angleStride), name, IntPtr.Zero);
|
||||
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace StgSharp.Timing
|
||||
{
|
||||
|
||||
private float _beginning, _ending;
|
||||
private Func<float, float> _timeRelatedCalculation;
|
||||
private TimeSpanProvider _timeProvider;
|
||||
|
||||
internal TimeFunction() { }
|
||||
@@ -44,7 +43,7 @@ namespace StgSharp.Timing
|
||||
public TimeFunction(TimeSpanProvider timeSpanProvider, Func<float, float> timeRelatedCalculation, float range)
|
||||
{
|
||||
_timeProvider = timeSpanProvider;
|
||||
_timeRelatedCalculation = timeRelatedCalculation;
|
||||
TimeRelatedCalculation = timeRelatedCalculation;
|
||||
if (timeSpanProvider == null) {
|
||||
return;
|
||||
}
|
||||
@@ -58,14 +57,7 @@ namespace StgSharp.Timing
|
||||
get => _timeProvider.CurrentSecond > _ending;
|
||||
}
|
||||
|
||||
public Func<float, float> TimeRelatedCalculation
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeRelatedCalculation;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => _timeRelatedCalculation = value;
|
||||
}
|
||||
public Func<float, float> TimeRelatedCalculation { get; set; }
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
@@ -86,7 +78,7 @@ namespace StgSharp.Timing
|
||||
if (_timeProvider.CurrentSecond < _ending) {
|
||||
return 0;
|
||||
}
|
||||
return _timeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
|
||||
return TimeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
|
||||
}
|
||||
|
||||
public static TimeFunction Proportional(TimeSpanProvider time, float begin, float range)
|
||||
@@ -115,7 +107,7 @@ namespace StgSharp.Timing
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
return new TimeFunction(
|
||||
_timeProvider, p => _timeRelatedCalculation(range - p), range);
|
||||
_timeProvider, p => TimeRelatedCalculation(range - p), range);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TimeSequence"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Common.Timing
|
||||
{
|
||||
public abstract class TimeSequence
|
||||
{
|
||||
|
||||
public ulong BeginningTick { get; protected set; }
|
||||
|
||||
public ulong EndingTick { get; protected set; }
|
||||
|
||||
public ulong FrameLength { get; protected set; }
|
||||
|
||||
public static TimeSequence CreateLinear(ulong timeout, ulong length)
|
||||
{
|
||||
return new LinearTimeSequence(timeout, timeout + length, length);
|
||||
}
|
||||
|
||||
public abstract bool IsNextFrameReady(ulong currentTick);
|
||||
|
||||
}
|
||||
|
||||
internal sealed class LogTimeSequence : TimeSequence
|
||||
{
|
||||
|
||||
private float _rate ;
|
||||
|
||||
public LogTimeSequence(ulong beginningTick, ulong endingTick, ulong tickPerDecade)
|
||||
{
|
||||
BeginningTick = beginningTick;
|
||||
EndingTick = endingTick;
|
||||
_rate = Scalar.Pow(10, 1 / tickPerDecade);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool IsNextFrameReady(ulong currentTick)
|
||||
{
|
||||
return (ulong)Math.Log(currentTick - BeginningTick + 1) >= FrameLength;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal sealed class LinearTimeSequence : TimeSequence
|
||||
{
|
||||
|
||||
public LinearTimeSequence(ulong beginningTick, ulong endingTick, ulong tickPerFrame)
|
||||
{
|
||||
BeginningTick = beginningTick;
|
||||
EndingTick = endingTick;
|
||||
FrameLength = tickPerFrame;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool IsNextFrameReady(ulong currentTick)
|
||||
{
|
||||
return currentTick - BeginningTick >= FrameLength;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user