Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
pmtplayback.c
Go to the documentation of this file.
2 {
3  ref array<ParticleSource> m_ParticleSources = new array<ParticleSource>();
4 
5  // TestOnePlaying
6  int m_OnePlayingManagerID;
7  bool m_bOnePlayingTestSuccess = false;
8 
9  // TestOnePlayingStandAloneAutoDestroy
10  int m_OnePlayingSAADPSID;
11  bool m_bOnePlayingSAADEnded = false;
12 
13  // TestOnePlayingStandAlone
14  int m_OnePlayingSAPSID;
15  bool m_bOnePlayingSAEnded = false;
16 
17  // TestStop
18  int m_StopPSID;
19  float m_StopAccumulatedTime;
20  static const float STOP_ACCUMULATED_TIME_STOP_CUTOFF = 2;
21  static const float STOP_ACCUMULATED_TIME_PLAY_CUTOFF = 3;
22  bool m_bStopWasStopped = false;
23  bool m_bStopWasResumed = false;
24  bool m_bStopEnded = false;
25 
26  //---------------------------------------------------------------------------
27  // Ctor - Decides the tests to run
28  //---------------------------------------------------------------------------
29  void PMTPlayback()
30  {
31  //AddInitTest("TestOnePlaying");
32  //AddInitTest("TestOnePlayingStandAloneAutoDestroy");
33  //AddInitTest("TestOnePlayingStandAlone");
34  //AddInitTest("TestWiggleStress");
35  AddInitTest("TestStopping");
36  }
37 
38  //---------------------------------------------------------------------------
39  // Tests
40  //---------------------------------------------------------------------------
41  // Test one particle playing
42  TFResult TestOnePlaying()
43  {
44  ParticleManager pm = CreatePMFixedBlocking(1);
45  m_OnePlayingManagerID = InsertManager(pm);
46 
47  DayZPlayer player = GetGame().GetPlayer();
48 
49  ParticleSource p = pm.CreateParticleById(ParticleList.EXPLOSION_LANDMINE, new ParticleProperties(player.GetPosition() + player.GetDirection() * 3, true));
50  p.GetEvents().Event_OnParticleEnd.Insert(PassOnePlaying);
51 
52  AddFrameTest("CheckOnePlaying");
53 
54  return BTFR(p.IsParticlePlaying());
55  }
56 
57  //---------------------------------------------------------------------------
58  // Test one standalone particle playing which will auto destroy
59  TFResult TestOnePlayingStandAloneAutoDestroy()
60  {
61  DayZPlayer player = GetGame().GetPlayer();
62 
63  ParticleSource p = ParticleSource.CreateParticle(ParticleList.EXPLOSION_LANDMINE, player.GetPosition() + player.GetDirection() * 3 + player.GetDirectionAside() * 3, true);
64  p.GetEvents().Event_OnParticleEnd.Insert(OnePlayingSAADEnded);
65 
66  m_OnePlayingSAADPSID = m_ParticleSources.Insert(p);
67 
68  AddFrameTest("CheckOnePlayingSAAD");
69 
70  return BTFR(p.IsParticlePlaying());
71  }
72 
73  //---------------------------------------------------------------------------
74  // Test one standalone particle playing which will not auto destroy
75  TFResult TestOnePlayingStandAlone()
76  {
77  DayZPlayer player = GetGame().GetPlayer();
78 
79  ParticleSource p = ParticleSource.CreateParticle(ParticleList.EXPLOSION_LANDMINE, player.GetPosition() + player.GetDirection() * 3 - player.GetDirectionAside() * 3, true);
80  p.GetEvents().Event_OnParticleEnd.Insert(OnePlayingSAEnded);
81  p.DisableAutoDestroy();
82 
83  m_OnePlayingSAPSID = m_ParticleSources.Insert(p);
84 
85  AddFrameTest("CheckOnePlayingSA");
86 
87  return BTFR(p.IsParticlePlaying());
88  }
89 
90  //---------------------------------------------------------------------------
91  // Test wiggling
92  TFResult TestWiggleStress()
93  {
94  DayZPlayer player = GetGame().GetPlayer();
95 
96  ParticleSource p = ParticleSource.CreateParticle(ParticleList.ROADFLARE_BURNING_MAIN, player.GetPosition() + player.GetDirection() * 4, true);
97  p.SetWiggle(90, 0.1);
98 
99  return BTFR(p.IsParticlePlaying());
100  }
101 
102  //---------------------------------------------------------------------------
103  // Test stop
104  TFResult TestStopping()
105  {
106  DayZPlayer player = GetGame().GetPlayer();
107 
108  //ParticleSource p = ParticleSource.CreateParticle(ParticleList.EXPLOSION_LANDMINE, player.GetPosition() + player.GetDirection() * 4, true);
109  ParticleSource p = ParticleSource.CreateParticle(ParticleList.EXPLOSION_LANDMINE, vector.Zero, true, player);
110  p.GetEvents().Event_OnParticleEnd.Insert(StopEnded);
111  p.DisableAutoDestroy();
112 
113  m_StopPSID = m_ParticleSources.Insert(p);
114 
115  AddFrameTest("CheckStop");
116 
117  return BTFR(p.IsParticlePlaying());
118  }
119 
120  //---------------------------------------------------------------------------
121  // OnFrame Checks
122  //---------------------------------------------------------------------------
123  TFResult CheckOnePlaying()
124  {
125  ParticleManager pm;
126  if (GetManager(m_OnePlayingManagerID, pm))
127  {
128  if (pm)
129  {
130  ParticleSource p = pm.GetParticle(0);
131  if (p.IsParticlePlaying())
132  {
133  return NTFR(TFR.PENDING);
134  }
135  else
136  {
137  return BTFR(m_bOnePlayingTestSuccess);
138  }
139  }
140  else
141  {
142  return BTFR(Assert(false));
143  }
144  }
145  else
146  {
147  return BTFR(Assert(false));
148  }
149  }
150 
151  //---------------------------------------------------------------------------
152  TFResult CheckOnePlayingSAAD()
153  {
154  if (m_ParticleSources.IsValidIndex(m_OnePlayingSAADPSID))
155  {
156  ParticleSource p = m_ParticleSources[m_OnePlayingSAADPSID];
157  if (p)
158  {
159  if (p.IsParticlePlaying())
160  {
161  return NTFR(TFR.PENDING);
162  }
163  else
164  {
165  if (m_bOnePlayingSAADEnded)
166  {
167  // There might be one frame where it is still alive before getting cleaned up
168  return NTFR(TFR.PENDING);
169  }
170  else
171  {
172  // Should be gone when no longer playing
173  return BTFR(Assert(false));
174  }
175  }
176  }
177  else
178  {
179  // Make sure the particle ended, if it did, then success!
180  return BTFR(m_bOnePlayingSAADEnded);
181  }
182  }
183  else
184  {
185  return BTFR(Assert(false));
186  }
187  }
188 
189  //---------------------------------------------------------------------------
190  TFResult CheckOnePlayingSA()
191  {
192  if (m_ParticleSources.IsValidIndex(m_OnePlayingSAPSID))
193  {
194  ParticleSource p = m_ParticleSources[m_OnePlayingSAPSID];
195  if (p)
196  {
197  if (p.IsParticlePlaying())
198  {
199  return NTFR(TFR.PENDING);
200  }
201  else
202  {
203  // Clean up the Particle, no leaking from tests!
204  GetGame().ObjectDelete(p);
205  // Make sure the particle ended, if it did, then success!
206  return BTFR(m_bOnePlayingSAEnded);
207  }
208  }
209  else
210  {
211  // It should not be gone, no autodestroy
212  return BTFR(Assert(false));
213  }
214  }
215  else
216  {
217  return BTFR(Assert(false));
218  }
219  }
220 
221  //---------------------------------------------------------------------------
222  TFResult CheckStop(float dt)
223  {
224  m_StopAccumulatedTime += dt;
225 
226  if (m_ParticleSources.IsValidIndex(m_StopPSID))
227  {
228  ParticleSource p = m_ParticleSources[m_StopPSID];
229  if (p)
230  {
231  if (p.IsParticlePlaying())
232  {
233  if (!m_bStopWasStopped && m_StopAccumulatedTime > STOP_ACCUMULATED_TIME_STOP_CUTOFF)
234  {
235  p.StopParticle();
236  m_StopAccumulatedTime = 0;
237  m_bStopWasStopped = true;
238  }
239 
240  return NTFR(TFR.PENDING);
241  }
242  else
243  {
244  // Means it was stopped before it was supposed to
245  // Possibly because particle length is shorter than STOP_ACCUMULATED_TIME_CUTOFF
246  if (!Assert(m_bStopWasStopped))
247  {
248  return BTFR(false);
249  }
250  else if (!m_bStopWasResumed && m_StopAccumulatedTime > STOP_ACCUMULATED_TIME_PLAY_CUTOFF)
251  {
252  p.PlayParticle();
253  m_bStopWasResumed = true;
254  }
255  else if (m_bStopEnded)
256  {
257  // Clean up the Particle, no leaking from tests!
258  GetGame().ObjectDelete(p);
259  return BTFR(true);
260  }
261 
262  return NTFR(TFR.PENDING);
263  }
264  }
265  else
266  {
267  // It should not be gone, no autodestroy
268  return BTFR(Assert(false));
269  }
270  }
271  else
272  {
273  return BTFR(Assert(false));
274  }
275  }
276 
277  //---------------------------------------------------------------------------
278  // Passes
279  //---------------------------------------------------------------------------
280  void PassOnePlaying(ParticleSource p)
281  {
282  m_bOnePlayingTestSuccess = true;
283  }
284 
285  //---------------------------------------------------------------------------
286  // Helpers
287  //---------------------------------------------------------------------------
288  void OnePlayingSAADEnded(ParticleSource p)
289  {
290  m_bOnePlayingSAADEnded = true;
291  }
292 
293  //---------------------------------------------------------------------------
294  void OnePlayingSAEnded(ParticleSource p)
295  {
296  m_bOnePlayingSAEnded = true;
297  }
298 
299  //---------------------------------------------------------------------------
300  void StopEnded(ParticleSource p)
301  {
302  m_bStopEnded = true;
303  }
304 }
GetGame
proto native CGame GetGame()
NTFR
TFResult NTFR(TFR result)
Definition: testframework.c:273
PMTPlayback
Definition: pmtplayback.c:1
PMTF
Definition: pmtf.c:1
TFResult
void TFResult(TFR result)
Definition: testframework.c:12
DayZPlayer
Definition: dayzplayerimplement.c:72
AddFrameTest
protected void AddFrameTest(string test)
Definition: testframework.c:254
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
Assert
protected bool Assert(bool condition)
Definition: testframework.c:262
array< ParticleSource >
ParticleSource
Entity which has the particle instance as an ObjectComponent.
Definition: particlesource.c:123
AddInitTest
protected void AddInitTest(string test)
Definition: testframework.c:249
TFR
TFR
Definition: testframework.c:1
BTFR
TFResult BTFR(bool result)
Definition: testframework.c:278
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84