pmtplayback.c 8.0 KB

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