DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
MinDurationEffect.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Xml.Serialization;
6 
7 namespace DirectOutput.FX.TimmedFX
8 {
16  {
17  private RetriggerBehaviourEnum _RetriggerBehaviour;
18 
27  public RetriggerBehaviourEnum RetriggerBehaviour
28  {
29  get { return _RetriggerBehaviour; }
30  set { _RetriggerBehaviour = value; }
31  }
32 
33  private int _DurationMs = 500;
34 
41  public int MinDurationMs
42  {
43  get { return _DurationMs; }
44  set { _DurationMs = value; }
45  }
46 
47 
48 
55  [XmlIgnoreAttribute]
56  public bool Active { get; private set; }
57 
58  private Queue<Table.TableElementData> UntriggerData = new Queue<Table.TableElementData>();
59 
65  public override void Trigger(Table.TableElementData TableElementData)
66  {
67  if (TargetEffect != null)
68  {
69  Table.TableElementData TED = TableElementData;
70  if (TED.Value != 0)
71  {
72  TargetEffect.Trigger(TED);
73  if (!Active || RetriggerBehaviour == RetriggerBehaviourEnum.RestartEffect)
74  {
75  Table.Pinball.Alarms.RegisterAlarm(MinDurationMs, MinDurationEnd);
76  Active = true;
77  }
78  }
79  else
80  {
81  if (Active)
82  {
83  //Min duration is active, put data in queue
84  UntriggerData.Enqueue(TED.Clone());
85  }
86  else
87  {
88  //Min duration has ended call target effect directly
89  TargetEffect.Trigger(TED);
90  }
91 
92  }
93  }
94  }
95 
96 
97 
98  private void MinDurationEnd()
99  {
100  while (UntriggerData.Count>0)
101  {
102  TargetEffect.Trigger(UntriggerData.Dequeue());
103  }
104  Active = false;
105  }
106 
107 
108 
112  public override void Finish()
113  {
114 
115  try
116  {
117  Table.Pinball.Alarms.UnregisterAlarm(MinDurationEnd);
118  }
119  catch {}
120  MinDurationEnd();
121  Active = false;
122  base.Finish();
123  }
124 
125 
126 
127  }
128 }