2 using System.Collections.Generic;
5 using DirectOutput.General.Color;
6 using DirectOutput.Cab.Toys.Layer;
8 namespace DirectOutput.FX.MatrixFX
13 public abstract class MatrixFlickerEffectBase<MatrixElementType> : MatrixEffectBase<MatrixElementType>
15 private const int RefreshIntervalMs = 30;
23 private int _Density = 10;
34 get {
return _Density; }
35 set { _Density = value.Limit(0, 100); }
39 private int _MinFlickerDurationMs = 60;
47 public int MinFlickerDurationMs
49 get {
return _MinFlickerDurationMs; }
50 set { _MinFlickerDurationMs = value.Limit(1,
int.MaxValue); }
53 private int _MaxFlickerDurationMs = 150;
62 public int MaxFlickerDurationMs
64 get {
return _MaxFlickerDurationMs; }
65 set { _MaxFlickerDurationMs = value.Limit(1,
int.MaxValue); }
74 private bool Active {
get;
set; }
77 private SortedDictionary<int, List<System.Drawing.Point>> ElementDictionary =
new SortedDictionary<int, List<System.Drawing.Point>>();
78 private int CurrentStep = 0;
79 private int CurrentValue = 0;
80 private int CurrentFlickerElements = 0;
82 private Random R =
new Random();
84 private void DoFlicker()
87 MatrixElementType I = GetEffectValue(0);
89 int V = CurrentValue.Limit(0, 255);
94 Table.Pinball.Alarms.RegisterIntervalAlarm(RefreshIntervalMs, DoFlicker);
100 if (V > 0 && FadeMode ==
FadeModeEnum.OnOff) { V = 255; }
102 D = GetEffectValue(V);
104 int NumberOfLeds = AreaWidth * AreaHeight;
105 int FlickerLeds = ((int)((
double)NumberOfLeds / 100 * Density)).Limit(1, NumberOfLeds);
107 int Min = MinFlickerDurationMs;
108 int Max = MaxFlickerDurationMs;
111 int Tmp = Min; Min = Max; Max = Tmp;
113 while (CurrentFlickerElements < FlickerLeds)
115 int S = CurrentStep + (int)((
float)(R.Next(Min ,Max)) / RefreshIntervalMs);
116 if (!ElementDictionary.ContainsKey(S))
118 ElementDictionary.Add(S,
new List<System.Drawing.Point>());
120 ElementDictionary[S].Add(
new System.Drawing.Point(R.Next(AreaLeft, AreaRight+1), R.Next(AreaTop,AreaBottom+1)));
121 CurrentFlickerElements++;
126 List<int> DropKeys =
new List<int>();
128 foreach (KeyValuePair<
int, List<System.Drawing.Point>> KV
in ElementDictionary)
130 if (KV.Key < CurrentStep)
132 foreach (System.Drawing.Point P in KV.Value)
134 MatrixLayer[P.X, P.Y] = I;
135 CurrentFlickerElements--;
137 DropKeys.Add(KV.Key);
141 foreach (System.Drawing.Point P in KV.Value)
143 MatrixLayer[P.X, P.Y] = D;
149 foreach (
int S
in DropKeys)
151 ElementDictionary.Remove(S);
163 foreach (KeyValuePair<
int, List<System.Drawing.Point>> KV
in ElementDictionary)
165 foreach (System.Drawing.Point P in KV.Value)
167 MatrixLayer[P.X, P.Y] = I;
170 ElementDictionary.Clear();
172 CurrentFlickerElements = 0;
173 Table.Pinball.Alarms.UnregisterIntervalAlarm(DoFlicker);
188 public override void Trigger(Table.TableElementData TableElementData)
190 if (MatrixLayer != null)
192 CurrentValue = TableElementData.Value;
193 if (CurrentValue > 0 && !Active)
207 protected abstract MatrixElementType GetEffectValue(
int TriggerValue);