DebugInfoShower.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include "DebugInfoShower.h"
  2. void DebugInfoShower::InfoGroup::Reset()
  3. {
  4. aInfo.DelAll();
  5. }
  6. void DebugInfoShower::InfoGroup::AddInfo(const InfoCommon & info)
  7. {
  8. aInfo.Add( info );
  9. }
  10. DebugInfoShower::DebugInfoShower() :
  11. m_aGroup( _FL_ )
  12. {
  13. m_dwCounter = 0;
  14. }
  15. DebugInfoShower::~DebugInfoShower()
  16. {
  17. m_aGroup.DelAll();
  18. m_dwCounter = 0;
  19. }
  20. bool DebugInfoShower::Create(MOPReader & reader)
  21. {
  22. SetUpdate(&DebugInfoShower::Work, ML_DEBUG);
  23. return true;
  24. }
  25. void _cdecl DebugInfoShower::Work(float fDeltaTime, long level)
  26. {
  27. // перейдем к новому кадру
  28. m_dwCounter++;
  29. // выведем сохраненную дебаг инфу
  30. for( long n=0; n<m_aGroup; n++ )
  31. ShowGroup(n);
  32. }
  33. void DebugInfoShower::AddInfo(const char* pcGroupID, InfoType type, const InfoCommon & info)
  34. {
  35. long n = CreateGroup( pcGroupID, type );
  36. if( n<0 ) return;
  37. // обновление на новом кадре? тогда сбрасываем старые данные
  38. if( m_aGroup[n].dwLastCounter != m_dwCounter )
  39. {
  40. m_aGroup[n].Reset();
  41. m_aGroup[n].dwLastCounter = m_dwCounter;
  42. }
  43. m_aGroup[n].AddInfo( info );
  44. }
  45. long DebugInfoShower::FindGroup(const char* pcGroupID, InfoType type)
  46. {
  47. for( long n=0; n<m_aGroup; n++ )
  48. if( m_aGroup[n].sID == pcGroupID && m_aGroup[n].type == type )
  49. return n;
  50. return -1;
  51. }
  52. long DebugInfoShower::CreateGroup(const char* pcGroupID, InfoType type)
  53. {
  54. long n = FindGroup(pcGroupID, type);
  55. if( n>=0 ) return n;
  56. n = m_aGroup.Add();
  57. m_aGroup[n].sID = pcGroupID;
  58. m_aGroup[n].type = type;
  59. m_aGroup[n].dwLastCounter = m_dwCounter;
  60. return n;
  61. }
  62. void DebugInfoShower::ShowGroup(long ngrp)
  63. {
  64. if( ngrp<0 || ngrp>=m_aGroup )
  65. return;
  66. switch( m_aGroup[ngrp].type )
  67. {
  68. case it_line: ShowLines( m_aGroup[ngrp].aInfo ); break;
  69. case it_sphere: ShowSpheres( m_aGroup[ngrp].aInfo ); break;
  70. case it_poligon4: ShowPoligons4( m_aGroup[ngrp].aInfo ); break;
  71. }
  72. }
  73. void DebugInfoShower::ShowLines(array<InfoCommon> & aInfo)
  74. {
  75. for( long n=0; n<aInfo; n++ )
  76. {
  77. Render().DrawLine( aInfo[n].src, aInfo[n].col, aInfo[n].dst, aInfo[n].col );
  78. }
  79. }
  80. void DebugInfoShower::ShowSpheres(array<InfoCommon> & aInfo)
  81. {
  82. for( long n=0; n<aInfo; n++ )
  83. {
  84. Render().DrawSphere( aInfo[n].centr, aInfo[n].rad, aInfo[n].col );
  85. }
  86. }
  87. void DebugInfoShower::ShowPoligons4(array<InfoCommon> & aInfo)
  88. {
  89. for( long n=0; n<aInfo; n++ )
  90. {
  91. Render().DrawPolygon( aInfo[n].v4, 4, Color(aInfo[n].col) );
  92. }
  93. }
  94. DebugInfoShower* DebugInfoShower::FindShower(MissionObject* mo)
  95. {
  96. if( !mo ) return NULL;
  97. MOSafePointer safeptr;
  98. static const ConstString id_DebugInfoShower("DebugInfoShower");
  99. mo->FindObject( id_DebugInfoShower, safeptr );
  100. if( !safeptr.Ptr() || !safeptr.Ptr()->Is(id_DebugInfoShower) ) return NULL;
  101. return (DebugInfoShower*)safeptr.Ptr();
  102. }
  103. void DebugInfoShower::AddPoligon4(MissionObject* mo, const char* grpID, const char* addictID, dword col, Vector& v1, Vector& v2, Vector& v3, Vector& v4)
  104. {
  105. DebugInfoShower* pmo = FindShower(mo);
  106. if( pmo )
  107. {
  108. string sID = grpID;
  109. sID += addictID;
  110. InfoCommon info;
  111. info.col = col;
  112. info.v4[0] = v1;
  113. info.v4[1] = v2;
  114. info.v4[2] = v3;
  115. info.v4[3] = v4;
  116. pmo->AddInfo(sID,it_poligon4,info);
  117. }
  118. }
  119. void DebugInfoShower::AddLine(MissionObject* mo, const char* grpID, const char* addictID, dword col, Vector& src, Vector& dst)
  120. {
  121. DebugInfoShower* pmo = FindShower(mo);
  122. if( pmo )
  123. {
  124. string sID = grpID;
  125. sID += addictID;
  126. InfoCommon info;
  127. info.col = col;
  128. info.src = src;
  129. info.dst = dst;
  130. pmo->AddInfo(sID,it_line,info);
  131. }
  132. }
  133. void DebugInfoShower::AddSphere(MissionObject* mo, const char* grpID, const char* addictID, dword col, Vector& center, float rad)
  134. {
  135. DebugInfoShower* pmo = FindShower(mo);
  136. if( pmo )
  137. {
  138. string sID = grpID;
  139. sID += addictID;
  140. InfoCommon info;
  141. info.col = col;
  142. info.centr = center;
  143. info.rad = rad;
  144. pmo->AddInfo(sID,it_sphere,info);
  145. }
  146. }
  147. MOP_BEGINLISTCG(DebugInfoShower, "DebugInfoShower", '1.00', 100, "Object for collect and output debug info", "Arcade Sea");
  148. MOP_ENDLIST(DebugInfoShower)