corrade-vassal

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 15  →  ?path2? @ 16
/wasSharp/Time.cs
@@ -14,7 +14,7 @@
 
namespace wasSharp
{
public class Time
public static class Time
{
public delegate void TimerCallback(object state);
 
@@ -131,7 +131,7 @@
/// another lined-up event. This is mostly used to check that throttles
/// are being respected.
/// </summary>
public class TimedThrottle : IDisposable
public sealed class TimedThrottle : IDisposable
{
private readonly uint EventsAllowed;
private readonly object LockObject = new object();
@@ -170,8 +170,13 @@
GC.SuppressFinalize(this);
}
 
protected virtual void Dispose(bool dispose)
~TimedThrottle()
{
Dispose(false);
}
 
private void Dispose(bool dispose)
{
if (timer != null)
{
timer.Dispose();
@@ -190,16 +195,16 @@
/// <remarks>
/// (C) Wizardry and Steamworks 2013 - License: GNU GPLv3
/// </remarks>
public class DecayingAlarm : IDisposable
public sealed class DecayingAlarm : IDisposable
{
[Flags]
public enum DECAY_TYPE
{
[XmlEnum(Name = "none")] NONE = 0,
[XmlEnum(Name = "arithmetic")] ARITHMETIC = 1,
[XmlEnum(Name = "geometric")] GEOMETRIC = 2,
[XmlEnum(Name = "harmonic")] HARMONIC = 4,
[XmlEnum(Name = "weighted")] WEIGHTED = 5
[Reflection.NameAttribute("none")] [XmlEnum(Name = "none")] NONE = 0,
[Reflection.NameAttribute("arithmetic")] [XmlEnum(Name = "arithmetic")] ARITHMETIC = 1,
[Reflection.NameAttribute("geometric")] [XmlEnum(Name = "geometric")] GEOMETRIC = 2,
[Reflection.NameAttribute("harmonic")] [XmlEnum(Name = "harmonic")] HARMONIC = 4,
[Reflection.NameAttribute("weighted")] [XmlEnum(Name = "weighted")] WEIGHTED = 5
}
 
private readonly DECAY_TYPE decay = DECAY_TYPE.NONE;
@@ -234,6 +239,11 @@
GC.SuppressFinalize(this);
}
 
~DecayingAlarm()
{
Dispose(false);
}
 
public void Alarm(double deadline)
{
lock (LockObject)
@@ -264,8 +274,8 @@
(int) ((deadline + times.Aggregate((a, b) => b + a))/(1f + times.Count)), 0);
break;
case DECAY_TYPE.GEOMETRIC:
alarm?.Change((int) (Math.Pow(deadline*times.Aggregate((a, b) => b*a),
1f/(1f + times.Count))), 0);
alarm?.Change((int) Math.Pow(deadline*times.Aggregate((a, b) => b*a),
1f/(1f + times.Count)), 0);
break;
case DECAY_TYPE.HARMONIC:
alarm?.Change((int) ((1f + times.Count)/
@@ -272,10 +282,10 @@
(1f/deadline + times.Aggregate((a, b) => 1f/b + 1f/a))), 0);
break;
case DECAY_TYPE.WEIGHTED:
HashSet<double> d = new HashSet<double>(times) {deadline};
double total = d.Aggregate((a, b) => b + a);
var d = new HashSet<double>(times) {deadline};
var total = d.Aggregate((a, b) => b + a);
alarm?.Change(
(int) (d.Aggregate((a, b) => Math.Pow(a, 2)/total + Math.Pow(b, 2)/total)), 0);
(int) d.Aggregate((a, b) => Math.Pow(a, 2)/total + Math.Pow(b, 2)/total), 0);
break;
default:
alarm?.Change((int) deadline, 0);
@@ -288,7 +298,7 @@
}
}
 
protected virtual void Dispose(bool dispose)
private void Dispose(bool dispose)
{
if (alarm != null)
{
@@ -296,6 +306,11 @@
alarm = null;
}
}
 
public DecayingAlarm Clone()
{
return new DecayingAlarm(decay);
}
}
}
}