daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
@@ -0,0 +1,160 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeFunction.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.Text;
namespace StgSharp.Timing
{
public class TimeFunction
{
private float _beginning, _ending;
private Func<float, float> _timeRelatedCalculation;
private TimeSpanProvider _timeProvider;
internal TimeFunction() { }
public TimeFunction(
TimeSpanProvider timeSpanProvider,
Func<float, float> timeRelatedCalculation,
float range)
{
_timeProvider = timeSpanProvider;
_timeRelatedCalculation = timeRelatedCalculation;
if (timeSpanProvider == null)
{
return;
}
_beginning = _timeProvider.CurrentSecond;
_ending = _timeProvider.CurrentSecond + range;
}
public virtual bool IsComplete
{
get => _timeProvider.CurrentSecond > _ending;
}
public Func<float, float> TimeRelatedCalculation
{
get { return _timeRelatedCalculation; }
set { _timeRelatedCalculation = value; }
}
public static TimeFunction One
{
get => new TimeFunctionOne();
}
public TimeSpanProvider TimeSpanProvider
{
get { return _timeProvider; }
set { _timeProvider = value; }
}
public virtual float Calculate()
{
if (_timeProvider.CurrentSecond < _ending)
{
return 0;
}
return _timeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
}
public static TimeFunction Proportional(TimeSpanProvider time, float begin, float range)
{
return new TimeFunction(
time, (float t) => t + begin, range
);
}
public virtual TimeFunction Renew((Func<float, float> func, float range) funcPair)
{
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
}
public virtual TimeFunction Renew(Func<float, float> func, float range)
{
return new TimeFunction(_timeProvider, func, range);
}
public void Reset()
{
float range = _ending - _beginning;
_beginning = _timeProvider.CurrentSecond;
_ending = _beginning + range;
}
public virtual TimeFunction Reverse()
{
float range = _ending - _beginning;
return new TimeFunction(_timeProvider, p => _timeRelatedCalculation(range - p), range);
}
}
public sealed class TimeFunctionOne : TimeFunction
{
internal TimeFunctionOne() : base()
{
}
public override bool IsComplete
{
get => true;
}
public override float Calculate()
{
return 1;
}
public override TimeFunction Renew((Func<float, float> func, float range) funcPair)
{
throw new NotSupportedException();
}
public override TimeFunction Renew(Func<float, float> func, float range)
{
throw new NotSupportedException();
}
#pragma warning disable CA1822
public new void Reset()
#pragma warning restore CA1822
{
}
}
}
@@ -0,0 +1,92 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 StgSharp.Timing
{
public abstract class TimeSourceProviderBase
{
private SemaphoreSlim _addSubscriberSemaphore = new SemaphoreSlim(1, 1);
protected SemaphoreSlim CheckSubscriberSemaphore
{
get => _addSubscriberSemaphore;
}
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();
public abstract void StopProvidingTime();
protected abstract void AddSubscriberUnsynced(TimeSpanProvider subscriber);
protected abstract void RemoveSubscriberUnsynced(TimeSpanProvider subscriber);
}
}
@@ -0,0 +1,218 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 System;
using System.Linq;
using System.Threading;
namespace StgSharp.Timing
{
/// <summary>
/// A microsecond-accuracy timer. It will refresh every a certain time span.
/// </summary>
public class TimeSpanProvider
{
private Action _frameUpdateMissCallback = () => { };
private Action _refreshCallback;
private bool _subscribed;
private Counter<int> timeSpanCount = new Counter<int>(-1, 1, 1);
private readonly int _maxSpanCount;
private long _spanBegin;
private readonly long _spanLength;
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
private readonly TimeSourceProviderBase _timeSource;
/// <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="spanMicroSeconds"></param>
/// <param name="provider"></param>
public TimeSpanProvider(long spanMicroSeconds, TimeSourceProviderBase provider)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
_timeSource = provider;
_spanLength = spanMicroSeconds;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
_subscribed = true;
_refreshCallback = new Action(() => { });
}
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span.
/// Length of a single time span is defined in seconds.
/// </summary>
/// <param name="spanSeconds"></param>
/// <param name="provider"></param>
public TimeSpanProvider(double spanSeconds, TimeSourceProviderBase provider)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
_spanLength = (long)(spanSeconds * 1000L * 1000L);
_spanBegin = -_spanLength;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
_subscribed = true;
_refreshCallback = new Action(() => { });
}
/// <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>
/// <param name="maxSpan"></param>
/// <param name="provider"></param>
public TimeSpanProvider(long spanLength, int maxSpan, TimeSourceProviderBase provider)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
if (maxSpan <= 0)
{
maxSpan = int.MaxValue;
}
_spanLength = spanLength; _spanBegin = -_spanLength;
provider.AddSubscriber(this);
_subscribed = true;
}
/// <summary>
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
/// </summary>
public Action SpanRefreshCallback
{
get => _refreshCallback;
set => _refreshCallback = value;
}
public double SpanLength
{
get => (_spanLength * 1.0) / (1000L * 1000L);
}
public float CurrentSecond
{
get => timeSpanCount.Value * SpanLengthLowPrecession;
}
public float SpanLengthLowPrecession
{
get => (_spanLength * 1.0f) / (1000 * 1000);
}
public int CurrentSpan
{
get => timeSpanCount.Value;
}
/// <summary>
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
/// </summary>
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
public void SubscribeToTimeSource(TimeSourceProviderBase serviceHandler)
{
if (serviceHandler == null)
{
throw new ArgumentNullException(nameof(serviceHandler));
}
if (_subscribed)
{
return;
}
_subscribed = true;
serviceHandler.AddSubscriber(this);
}
public int ToInt32()
{
return timeSpanCount.Value;
}
public void WaitNextSpan()
{
_refreshSemaphore.Wait();
}
internal bool CheckTime(long microseconds)
{
//Console.Write("1 ");
if (microseconds - _spanBegin < _spanLength)
{
return true;
}
//Console.Write("2 ");
_spanBegin = microseconds;
timeSpanCount++;
//Console.Write("3 ");
if (_refreshCallback != null)
{
_refreshCallback();
}
//Console.Write("4 ");
if (_refreshSemaphore.CurrentCount == 0)
{
_refreshSemaphore.Release();
}
else
{
if (_frameUpdateMissCallback != null)
{
_frameUpdateMissCallback();
}
}
//Console.Write("5 ");
//Console.WriteLine( $"{timeSpanCount}\n" );
return timeSpanCount < _maxSpanCount;
}
public static implicit operator int(TimeSpanProvider provider)
{
if (provider == null)
{
return 0;
}
return provider.ToInt32();
}
}
}