daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+73 -42
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ArrayList.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Graphics;
using System;
using System.Collections;
@@ -14,6 +44,7 @@ namespace StgSharp.Logic
[StructLayout(LayoutKind.Explicit, Size = 8)]
internal struct LogSeperator
{
[FieldOffset(0)] public ulong all;
[FieldOffset(0)] public long all_s;
@@ -28,6 +59,7 @@ namespace StgSharp.Logic
this.high = high;
this.low = low;
}
}
/// <summary>
@@ -38,6 +70,7 @@ namespace StgSharp.Logic
/// <typeparam name="T"></typeparam>
public class DynamicArrayList<T>
{
private List<T[]> arrayIndexList;
private LogSeperator indexpair;
private int lastMain = 0;
@@ -139,10 +172,10 @@ namespace StgSharp.Logic
{
indexpair.all_s = index;
if (
indexpair.low_s > lastSub ||
indexpair.high_s > lastMain ||
indexpair.low_s < 0 ||
indexpair.high_s < 0)
(indexpair.low_s > lastSub) ||
(indexpair.high_s > lastMain) ||
(indexpair.low_s < 0) ||
(indexpair.high_s < 0))
{
throw new IndexOutOfRangeException();
}
@@ -152,10 +185,10 @@ namespace StgSharp.Logic
{
indexpair.all_s = index;
if (
indexpair.low_s > lastSub ||
indexpair.high_s > lastMain ||
indexpair.low_s < 0 ||
indexpair.high_s < 0)
(indexpair.low_s > lastSub) ||
(indexpair.high_s > lastMain) ||
(indexpair.low_s < 0) ||
(indexpair.high_s < 0))
{
throw new IndexOutOfRangeException();
}
@@ -163,30 +196,11 @@ namespace StgSharp.Logic
}
}
public void CopyTo(DynamicArrayList<T> target)
{
target.arrayIndexList.Clear();
int length = 1;
foreach (T[] tList in target.arrayIndexList)
{
T[] newIndex = new T[length];
Buffer.BlockCopy(tList, 0, newIndex, 0, length);
target.arrayIndexList.Add(newIndex);
length <<= 1;
}
target.lastMain = lastMain;
target.lastSub = lastSub;
target.length = length;
target.unusedMainIndex = new Queue<int>(unusedMainIndex.ToArray());
target.unusedSubIndex = new Queue<int>(unusedSubIndex.ToArray());
}
public T this[int index]
{
get
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -195,7 +209,7 @@ namespace StgSharp.Logic
}
set
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -208,7 +222,7 @@ namespace StgSharp.Logic
{
get
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -217,7 +231,7 @@ namespace StgSharp.Logic
}
set
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -231,10 +245,7 @@ namespace StgSharp.Logic
/// <summary>
/// Length of this <see cref="DynamicArrayList{T}"/>
/// </summary>
public int Length
{
get { return length; }
}
public int Length => length;
public int Add(T item)
{
@@ -297,6 +308,25 @@ namespace StgSharp.Logic
return false;
}
public void CopyTo(DynamicArrayList<T> target)
{
target.arrayIndexList.Clear();
int length = 1;
foreach (T[] tList in target.arrayIndexList)
{
T[] newIndex = new T[length];
Buffer.BlockCopy(tList, 0, newIndex, 0, length);
target.arrayIndexList.Add(newIndex);
length <<= 1;
}
target.lastMain = lastMain;
target.lastSub = lastSub;
target.length = length;
target.unusedMainIndex = new Queue<int>(unusedMainIndex.ToArray());
target.unusedSubIndex = new Queue<int>(unusedSubIndex.ToArray());
}
public int IndexOf(T item)
{
int index = 1;
@@ -307,7 +337,7 @@ namespace StgSharp.Logic
{
if (i.Equals(item))
{
return index + subindex - 1;
return (index + subindex) - 1;
}
subindex++;
}
@@ -328,11 +358,11 @@ namespace StgSharp.Logic
if (i.Equals(item))
{
list[subindex] = default;
if (subindex == lastSub && index == lastMain)
if ((subindex == lastSub) && (index == lastMain))
{
if (lastSub == 0)
{
lastMain = lastMain == 0 ? 0 : lastMain - 1;
lastMain = (lastMain == 0) ? 0 : (lastMain - 1);
lastSub = arrayIndexList[lastMain].Length - 1;
}
else
@@ -356,7 +386,7 @@ namespace StgSharp.Logic
[Obsolete("This method is not same, you may read data form an empty index.", false)]
public void RemoveAt(int index)
{
if (index > length || index < 0)
if ((index > length) || (index < 0))
{
throw new ArgumentOutOfRangeException(nameof(index));
}
@@ -402,7 +432,7 @@ namespace StgSharp.Logic
mainindex++;
}
indexpair.high_s = mainindex;
indexpair.low >>= (int)(32 - mainindex);
indexpair.low >>= 32 - mainindex;
}
private void SeprateIndex(int longIndex)
@@ -415,7 +445,8 @@ namespace StgSharp.Logic
mainindex++;
}
indexpair.high_s = mainindex;
indexpair.low >>= (int)(32 - mainindex);
indexpair.low >>= 32 - mainindex;
}
}
}
+35 -3
View File
@@ -1,4 +1,34 @@
using StgSharp.Entities;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Control.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Entities;
using StgSharp.Geometries;
using StgSharp.Math;
@@ -6,15 +36,17 @@ namespace StgSharp
{
public partial class Control
{
internal Line bottomBoader;
internal Line leftBoader;
internal Line rightBoader;
internal Line topBoader;
internal Line bottomBoader;
public Line BottomBoarder => bottomBoader;
public Line LeftBoarder => leftBoader;
public Line RightBoarder => rightBoader;
public Line TopBoarder => topBoader;
public Line BottomBoarder => bottomBoader;
private void initContainers()
+56 -75
View File
@@ -1,80 +1,48 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Counter.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Xml.Serialization;
namespace StgSharp
{
public delegate void TimeSourceProvider(TimeProvider subscriber);
public class TimeProvider
{
private readonly long _spanLength;
private long _spanBegin;
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
public static TimeSourceProvider DefaultProvider
{
get
{
return new(StgSharp.SubscribeTimeProvider);
}
}
public TimeProvider(
long spanLength
)
{
_spanLength = spanLength;
}
internal void CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
{
_spanBegin = microseconds;
timeSpanCount++;
}
}
public void SubcsribeToTimeSource(TimeSourceProvider serviceHandler)
{
serviceHandler(this);
}
public static implicit operator uint(TimeProvider provider)
{
return provider.timeSpanCount.Value;
}
}
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
{
internal readonly T _defualtValue;
internal readonly T _defualtAddValue;
internal readonly T _defualtSubValue;
internal readonly T _defualtValue;
internal dynamic _value;
public T Value
{
get { return _value; }
set { _value = value; }
}
public T Span
{
get { return _value - _defualtValue; }
}
public T Increament
{
get { return _defualtAddValue; }
}
public T Decreament
{
get { return _defualtSubValue; }
}
public Counter(T defualtValue, T defualtAddValue, T defualtSubValue)
{
var type = Type.GetTypeCode(defualtValue.GetType());
@@ -120,6 +88,18 @@ namespace StgSharp
_defualtSubValue = defualtSubValue;
}
public T Decreament => _defualtSubValue;
public T Increament => _defualtAddValue;
public T Span => _value - _defualtValue;
public T Value
{
get => _value;
set => _value = value;
}
public void Add(T value)
{
_value += value;
@@ -130,11 +110,6 @@ namespace StgSharp
_value += _defualtAddValue;
}
public void Sub(T value)
{
_value -= value;
}
public void QuickSub()
{
_value -= _defualtSubValue;
@@ -145,10 +120,14 @@ namespace StgSharp
_value = _defualtValue;
}
public static Counter<T> operator ++(Counter<T> counter)
public void Sub(T value)
{
counter.QuickAdd();
return counter;
_value -= value;
}
public override string ToString()
{
return Value.ToString();
}
public static Counter<T> operator --(Counter<T> counter)
@@ -157,14 +136,16 @@ namespace StgSharp
return counter;
}
public override string ToString()
public static Counter<T> operator ++(Counter<T> counter)
{
return Value.ToString();
counter.QuickAdd();
return counter;
}
public static implicit operator T(Counter<T> counter)
{
return counter.Value;
}
}
}
+37 -6
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Exception.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Graphics;
using System;
using System.Collections.Generic;
@@ -11,6 +41,12 @@ namespace StgSharp.Logic
[System.Serializable]
internal class FrameTimeoutException : Exception
{
protected FrameTimeoutException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
internal FrameTimeoutException()
{ }
@@ -22,10 +58,5 @@ namespace StgSharp.Logic
{
}
protected FrameTimeoutException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="LogicValue.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
@@ -13,6 +43,7 @@ namespace StgSharp.Logic
[StructLayout(LayoutKind.Explicit, Size = 2)]
public struct Bool2
{
/// <summary>
/// A <see cref="ushort"/> value.
/// The lower byte is <see cref="bool0"/>,
@@ -33,5 +64,6 @@ namespace StgSharp.Logic
[FieldOffset(1)] public bool bool1;
[FieldOffset(1)] public bool byte1;
}
}
+43 -14
View File
@@ -1,4 +1,34 @@
using StgSharp.Geometries;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Sensor.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Geometries;
namespace StgSharp
{
@@ -7,26 +37,30 @@ namespace StgSharp
public class Sensor<T>
{
internal PlainGeometry _boarder;
internal PlainGeometry _target;
internal SensorRuleHandler _rule;
internal PlainGeometry _target;
public PlainGeometry boarder
public PlainGeometry boarder => _boarder;
public SensorRuleHandler Rule
{
get { return _boarder; }
get => _rule;
set => _rule = value;
}
public PlainGeometry target
{
get { return _target; }
set { _target = value; }
get => _target;
set => _target = value;
}
public SensorRuleHandler Rule
public static Sensor<T> operator -(Sensor<T> sensor, SensorRuleHandler rule)
{
get { return _rule; }
set { _rule = value; }
sensor._rule -= rule;
return sensor;
}
public static Sensor<T> operator +(Sensor<T> sensor, SensorRuleHandler rule)
@@ -35,10 +69,5 @@ namespace StgSharp
return sensor;
}
public static Sensor<T> operator -(Sensor<T> sensor, SensorRuleHandler rule)
{
sensor._rule -= rule;
return sensor;
}
}
}
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeSourceProvider.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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;
using System;
using System.Linq;
using System.Threading;
namespace StgSharpDebug.Logic
{
public abstract class TimeSourceProviderBase
{
private SemaphoreSlim _addSubscriberSemaphore = new SemaphoreSlim(1, 1);
public void AddSubscriber(TimeSpanProvider subscriber)
{
_addSubscriberSemaphore.Wait();
try
{
AddSubscriberUnsynced(subscriber);
}
catch (Exception)
{
throw;
}
finally
{
_addSubscriberSemaphore.Release();
}
}
public void RemoveSubscriber(TimeSpanProvider subscriber)
{
_addSubscriberSemaphore.Wait();
try
{
RemoveSubscriberUnsynced(subscriber);
}
catch (Exception)
{
throw;
}
finally
{
_addSubscriberSemaphore.Release();
}
}
public abstract void StartProvidingTime();
protected abstract void AddSubscriberUnsynced(TimeSpanProvider subscriber);
protected abstract void RemoveSubscriberUnsynced(TimeSpanProvider subscriber);
}
}
@@ -0,0 +1,122 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeSpanProvider.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharpDebug.Logic;
using System;
using System.Linq;
namespace StgSharp
{
public delegate void TimeSpanRefeshCallback();
/// <summary>
/// A microsecond-accuracy timer. It will refresh every a certain time span.
/// </summary>
public class TimeSpanProvider
{
private readonly int _maxSpanCount;
private TimeSpanRefeshCallback _refeshCallback;
private long _spanBegin;
private readonly long _spanLength;
private bool _subscribed;
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
/// </summary>
/// <param name="spanLength"></param>
/// <parma name="provider"></parma>
public TimeSpanProvider(long spanLength, TimeSourceProviderBase provider)
{
_spanLength = spanLength;
provider.AddSubscriber(this);
_subscribed = true;
}
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
/// </summary>
/// <param name="spanLength"></param>
/// <parma name="provider"></parma>
public TimeSpanProvider(long spanLength, uint maxSpan, TimeSourceProviderBase provider)
{
_spanLength = spanLength;
provider.AddSubscriber(this);
_subscribed = true;
}
/// <summary>
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
/// </summary>
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
/// <summary>
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
/// </summary>
public TimeSpanRefeshCallback SpanRefreshCallback
{
get => _refeshCallback;
set => _refeshCallback = value;
}
public void SubcsribeToTimeSource(TimeSourceProviderBase serviceHandler)
{
if (_subscribed)
{
return;
}
_subscribed = true;
serviceHandler.AddSubscriber(this);
}
internal bool CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
{
_spanBegin = microseconds;
timeSpanCount++;
}
if (timeSpanCount > _maxSpanCount)
{
return false;
}
return true;
}
public static implicit operator uint(TimeSpanProvider provider)
{
return provider.timeSpanCount.Value;
}
}
}
+205 -174
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glParamQueue.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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.Graphics;
using StgSharp.Math;
using System;
@@ -16,9 +46,10 @@ namespace StgSharp.Logic
{
internal unsafe class GLparamQueue
{
internal GLcontext* context;
private ConcurrentQueue<M128> paramQueue;
private ConcurrentQueue<glArrayHandle> streamQueue;
internal GLcontext* context;
public GLparamQueue()
{
@@ -47,6 +78,45 @@ namespace StgSharp.Logic
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(glHandle handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0)
{
M128 m = default;
m.Write<int>(0, i0);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(string str)
{
byte[] code = Encoding.UTF8.GetBytes(str);
streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue<T>(T[] array) where T : struct
{
streamQueue.Enqueue(glArrayHandle.Alloc<T>(array));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1)
{
@@ -65,6 +135,33 @@ namespace StgSharp.Logic
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p0, IntPtr p1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p0);
m.Write<ulong>(1, (ulong)p1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(glHandle handle, glHandle handle1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write<ulong>(1, (ulong)handle1.valuePtr);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1, uint u2)
{
@@ -84,6 +181,16 @@ namespace StgSharp.Logic
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2, float f3)
{
@@ -95,67 +202,6 @@ namespace StgSharp.Logic
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p0, IntPtr p1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p0);
m.Write<ulong>(1, (ulong)p1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(glHandle handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(glHandle handle, glHandle handle1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write<ulong>(1, (ulong)handle1.valuePtr);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0)
{
M128 m = default;
m.Write<int>(0, i0);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2, int i3)
{
@@ -167,21 +213,6 @@ namespace StgSharp.Logic
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(string str)
{
byte[] code = Encoding.UTF8.GetBytes(str);
streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue<T>(T[] array) where T : struct
{
streamQueue.Enqueue(glArrayHandle.Alloc<T>(array));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out glArrayHandle arrayHandle)
{
@@ -244,6 +275,36 @@ namespace StgSharp.Logic
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p = (IntPtr)ret.Read<ulong>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1)
{
@@ -260,6 +321,38 @@ namespace StgSharp.Logic
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p0, out IntPtr p1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p0 = (IntPtr)ret.Read<ulong>(0);
p1 = (IntPtr)ret.Read<ulong>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1, out int i2)
{
@@ -277,6 +370,40 @@ namespace StgSharp.Logic
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
f0 = ret.Read<uint>(0);
f1 = ret.Read<uint>(1);
f2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
u2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1, out int i2, out int i3)
{
@@ -295,37 +422,6 @@ namespace StgSharp.Logic
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p = (IntPtr)ret.Read<ulong>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p0, out IntPtr p1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p0 = (IntPtr)ret.Read<ulong>(0);
p1 = (IntPtr)ret.Read<ulong>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2, out float f3)
{
@@ -344,71 +440,6 @@ namespace StgSharp.Logic
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
f0 = ret.Read<uint>(0);
f1 = ret.Read<uint>(1);
f2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
u2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2, out uint u3)
{