DirectOuput Framework R2
DirectOutput framework R2 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 using DirectOutput.Table;
7 
8 namespace DirectOutput.FX.TimmedFX
9 {
17  {
18  private RetriggerBehaviourEnum _RetriggerBehaviour = RetriggerBehaviourEnum.Restart;
19 
28  public RetriggerBehaviourEnum RetriggerBehaviour
29  {
30  get { return _RetriggerBehaviour; }
31  set { _RetriggerBehaviour = value; }
32  }
33 
34  private int _DurationMs = 500;
35 
42  public int MinDurationMs
43  {
44  get { return _DurationMs; }
45  set { _DurationMs = value; }
46  }
47 
48 
49 
56  [XmlIgnoreAttribute]
57  public bool Active { get; private set; }
58 
59  private TableElementData UntriggerData;
60  private DateTime DurationStart = DateTime.MinValue;
61 
67  public override void Trigger(TableElementData TableElementData)
68  {
69  if (TargetEffect != null)
70  {
71  if (TableElementData.Value != 0)
72  {
73  if (!Active || RetriggerBehaviour == RetriggerBehaviourEnum.Restart)
74  {
75  DurationStart = DateTime.Now;
76  UntriggerData = TableElementData;
77  TriggerTargetEffect(TableElementData);
78  Active = true;
79  }
80  }
81  else
82  {
83  if (Active && UntriggerData.TableElementType==TableElementData.TableElementType && UntriggerData.Number==TableElementData.Number)
84  {
85  if ((DateTime.Now - DurationStart).TotalMilliseconds >= MinDurationMs)
86  {
87  MinDurationEnd();
88  }
89  else
90  {
91  Table.Pinball.Alarms.RegisterAlarm(MinDurationMs - (int)(DateTime.Now - DurationStart).TotalMilliseconds, MinDurationEnd);
92  }
93  }
94 
95  }
96 
97  }
98  }
99 
100 
101 
102  private void MinDurationEnd()
103  {
104  if (Active)
105  {
106  TableElementData D = UntriggerData;
107  D.Value = 0;
108  TriggerTargetEffect(D);
109  }
110  Active = false;
111  }
112 
113 
114 
118  public override void Finish()
119  {
120 
121  try
122  {
123  Table.Pinball.Alarms.UnregisterAlarm(MinDurationEnd);
124  }
125  catch { }
126  //MinDurationEnd();
127  Active = false;
128  base.Finish();
129  }
130 
131 
132 
133  }
134 }