SystemProxy.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #include "SystemProxy.h"
  2. #include "..\emitters\point.h"
  3. #include "..\..\manager\particlemanager.h"
  4. //Создание/удаление
  5. ParticleSystemProxy::ParticleSystemProxy(ParticleManager* serv, ParticleSystem* async_system)
  6. {
  7. m_async_system = async_system;
  8. AutoDeleted = false;
  9. pMaster = serv;
  10. DeleteWithGeomEntity = true;
  11. AttachedToGeom.reset();
  12. pAttachedScene = NULL;
  13. AutoDeleted = false;
  14. pMaster = serv;
  15. DeleteWithGeomEntity = true;
  16. packet.out.mTransformType = MOVE_NONE;
  17. packet.out.bAutoHide = false;
  18. packet.out.bCancelHide = false;
  19. packet.out.EmissionPause = false;
  20. packet.out.fTimeScale = 1.0f;
  21. packet.out.fScale = 1.0f;
  22. packet.out.addVelocity = 0.0f;
  23. packet.out.bLocalMode = false;
  24. packet.in.bIsAlive = true;
  25. UseTheTeleport = true;
  26. }
  27. ParticleSystemProxy::~ParticleSystemProxy()
  28. {
  29. if (pAttachedScene) pAttachedScene->UnSubscribeDeletionEvent(this);
  30. pAttachedScene = NULL;
  31. AttachedToGeom.reset();
  32. }
  33. bool ParticleSystemProxy::DeleteIfNeed ()
  34. {
  35. if (!IsAlive())
  36. {
  37. pMaster->DefferedDelete(this);
  38. return true;
  39. }
  40. return false;
  41. }
  42. void _cdecl ParticleSystemProxy::GeomEntityDeleted ()
  43. {
  44. AttachedToGeom.reset();
  45. if (DeleteWithGeomEntity)
  46. {
  47. Release();
  48. }
  49. pAttachedScene = NULL;
  50. }
  51. bool ParticleSystemProxy::Release ()
  52. {
  53. if (pAttachedScene) pAttachedScene->UnSubscribeDeletionEvent(this);
  54. pAttachedScene = NULL;
  55. AttachedToGeom.reset();
  56. pMaster->RemoveResource(this);
  57. return false;
  58. }
  59. void ParticleSystemProxy::Restart (DWORD RandomSeed)
  60. {
  61. UseTheTeleport = true;
  62. packet.in.bIsAlive = true;
  63. packet.out.bNeedRestart = true;
  64. packet.out.dwRestartRandomSeed = RandomSeed;
  65. }
  66. void ParticleSystemProxy::PauseEmission (bool bPause)
  67. {
  68. packet.out.EmissionPause = bPause;
  69. }
  70. //Установить автоудаляемая система или обычная...
  71. void ParticleSystemProxy::AutoDelete (bool Enabled)
  72. {
  73. AutoDeleted = Enabled;
  74. }
  75. //Установить матрицу трансформации для системы
  76. void ParticleSystemProxy::SetTransform (const Matrix& transform)
  77. {
  78. packet.out.mTransformType = MOVE_SETTRANSFORM;
  79. packet.out.mTransform = transform;
  80. }
  81. void ParticleSystemProxy::Teleport (const Matrix &transform)
  82. {
  83. packet.out.mTransformType = MOVE_TELEPORT;
  84. packet.out.mTransform = transform;
  85. }
  86. void ParticleSystemProxy::SetName (const char* Name)
  87. {
  88. systemName = Name;
  89. }
  90. const char* ParticleSystemProxy::GetName ()
  91. {
  92. return systemName.c_str();
  93. }
  94. //Прикрепить систему к геометрии
  95. void ParticleSystemProxy::AttachTo (IGMXScene* scene, GMXHANDLE node, bool bDestroyWithGeometry)
  96. {
  97. if (pAttachedScene) pAttachedScene->UnSubscribeDeletionEvent(this);
  98. pAttachedScene = NULL;
  99. AttachedToGeom.reset();
  100. if (scene && node.isValid())
  101. {
  102. AttachedToGeom = node;
  103. pAttachedScene = scene;
  104. scene->SubscribeDeletionEvent(this, (GMX_EVENT)&ParticleSystemProxy::GeomEntityDeleted);
  105. DeleteWithGeomEntity = bDestroyWithGeometry;
  106. } else
  107. {
  108. DeleteWithGeomEntity = false;
  109. }
  110. }
  111. //автоматически спрячется на следующий кадр, если не вызвать CancelHide каждый кадр
  112. void ParticleSystemProxy::AutoHide (bool Enabled)
  113. {
  114. packet.out.bAutoHide = Enabled;
  115. packet.out.bCancelHide = false;
  116. }
  117. void ParticleSystemProxy::CancelHide()
  118. {
  119. packet.out.bCancelHide = true;
  120. }
  121. //Скорость времени для партикловой системы
  122. void ParticleSystemProxy::SetTimeScale (float _fTimeScale)
  123. {
  124. packet.out.fTimeScale = _fTimeScale;
  125. }
  126. //Размеры партикловой системы
  127. void ParticleSystemProxy::SetScale (float _fScale)
  128. {
  129. packet.out.fScale = _fScale;
  130. }
  131. void ParticleSystemProxy::AdditionalStartVelocity (const Vector& additionalVelocity)
  132. {
  133. packet.out.addVelocity = additionalVelocity;
  134. }
  135. bool ParticleSystemProxy::IsActive()
  136. {
  137. if (packet.out.EmissionPause) return false;
  138. if (packet.out.bAutoHide == false || packet.out.bCancelHide == true) return true;
  139. return false;
  140. }
  141. void ParticleSystemProxy::SendReceivePackets ()
  142. {
  143. if (AttachedToGeom.isValid() && pAttachedScene)
  144. {
  145. Matrix m;
  146. pAttachedScene->GetNodeWorldTransform(AttachedToGeom, m);
  147. SetTransform(m);
  148. }
  149. if (packet.out.bNeedRestart)
  150. {
  151. m_async_system->Restart(packet.out.dwRestartRandomSeed);
  152. packet.out.bNeedRestart = false;
  153. }
  154. if (AutoDeleted)
  155. {
  156. if (DeleteIfNeed ())
  157. {
  158. return;
  159. }
  160. }
  161. //receive...
  162. packet.in.bIsAlive = m_async_system->IsAlive();
  163. //send...
  164. m_async_system->AutoHide(packet.out.bAutoHide);
  165. if (packet.out.bCancelHide)
  166. {
  167. m_async_system->CancelHide();
  168. }
  169. packet.out.bCancelHide = false;
  170. m_async_system->PauseEmission(packet.out.EmissionPause);
  171. m_async_system->SetTimeScale(packet.out.fTimeScale);
  172. m_async_system->SetScale(packet.out.fScale);
  173. m_async_system->AdditionalStartVelocity(packet.out.addVelocity);
  174. m_async_system->SetLocalMode(packet.out.bLocalMode);
  175. if (packet.out.mTransformType == MOVE_TELEPORT)
  176. {
  177. m_async_system->Teleport(packet.out.mTransform);
  178. }
  179. if (packet.out.mTransformType == MOVE_SETTRANSFORM)
  180. {
  181. if (UseTheTeleport)
  182. {
  183. m_async_system->Teleport(packet.out.mTransform);
  184. UseTheTeleport = false;
  185. } else
  186. {
  187. m_async_system->SetTransform(packet.out.mTransform);
  188. }
  189. }
  190. packet.out.mTransformType = MOVE_NONE;
  191. }
  192. ParticleSystem* ParticleSystemProxy::system_GetGUID_dontUSE_for_WORK_use_LOCK ()
  193. {
  194. return m_async_system;
  195. }
  196. ParticleSystem* ParticleSystemProxy::Lock ()
  197. {
  198. #ifdef ENABLE_PARTICLE_THREADS
  199. pMaster->Lock();
  200. #endif
  201. return m_async_system;
  202. }
  203. void ParticleSystemProxy::Unlock ()
  204. {
  205. #ifdef ENABLE_PARTICLE_THREADS
  206. pMaster->Unlock();
  207. #endif
  208. }
  209. IGMXScene * ParticleSystemProxy::GetAttachedSceneToGeom()
  210. {
  211. return pAttachedScene;
  212. }
  213. GMXHANDLE ParticleSystemProxy::GetAttachedToGeom ()
  214. {
  215. return AttachedToGeom;
  216. }
  217. bool ParticleSystemProxy::IsAutoDeleted ()
  218. {
  219. return AutoDeleted;
  220. }
  221. bool ParticleSystemProxy::IsAlive ()
  222. {
  223. return packet.in.bIsAlive;
  224. }
  225. bool ParticleSystemProxy::IsLooped ()
  226. {
  227. return false;
  228. }
  229. void ParticleSystemProxy::SetLocalMode (bool bLocalModeEnable)
  230. {
  231. packet.out.bLocalMode = bLocalModeEnable;
  232. }