componententitydebug.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. class ComponentEntityDebug extends Component
  2. {
  3. protected Shape m_DebugShapeBBox;
  4. protected Shape m_DebugShapeDirection;
  5. protected float m_DebugShapeDirectionDist;
  6. // -------------------------------------------------------------------------
  7. override Shape DebugBBoxDraw()
  8. {
  9. #ifndef DEVELOPER
  10. return null;
  11. #endif
  12. if ( m_DebugShapeBBox )
  13. m_DebugShapeBBox.Destroy();
  14. vector min_max[2];
  15. if (!m_ThisEntityAI.GetCollisionBox(min_max))
  16. return null;
  17. m_DebugShapeBBox = Debug.DrawBox(min_max[0], min_max[1]);
  18. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(OnDrawing, 0, true);
  19. m_ThisEntityAI.SetEventMask(EntityEvent.FRAME);
  20. return null;
  21. }
  22. // -------------------------------------------------------------------------
  23. override void DebugBBoxSetColor(int color)
  24. {
  25. if ( m_DebugShapeBBox )
  26. {
  27. m_DebugShapeBBox.SetColor(color);
  28. }
  29. }
  30. // -------------------------------------------------------------------------
  31. override void DebugBBoxDelete()
  32. {
  33. #ifndef DEVELOPER
  34. return;
  35. #endif
  36. if ( m_DebugShapeBBox )
  37. {
  38. m_DebugShapeBBox.Destroy();
  39. m_DebugShapeBBox = null;
  40. }
  41. if ( !m_DebugShapeDirection && !m_DebugShapeBBox )
  42. {
  43. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Remove(OnDrawing);
  44. }
  45. }
  46. // -------------------------------------------------------------------------
  47. override Shape DebugDirectionDraw(float distance = 1)
  48. {
  49. #ifndef DEVELOPER
  50. return null;
  51. #endif
  52. if ( m_DebugShapeDirection )
  53. {
  54. m_DebugShapeDirection.Destroy();
  55. }
  56. vector p1 = "0 0 0";
  57. vector p2 = m_ThisEntityAI.GetDirection() * m_DebugShapeDirectionDist;
  58. m_DebugShapeDirectionDist = distance;
  59. m_DebugShapeDirection = Debug.DrawArrow(p1, p2);
  60. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(OnDrawing, 0, true);
  61. m_ThisEntityAI.SetEventMask(EntityEvent.FRAME);
  62. return null;
  63. }
  64. // -------------------------------------------------------------------------
  65. override void DebugDirectionDelete()
  66. {
  67. #ifndef DEVELOPER
  68. return;
  69. #endif
  70. if ( m_DebugShapeDirection )
  71. {
  72. m_DebugShapeDirection.Destroy();
  73. m_DebugShapeDirection = null;
  74. }
  75. if ( !m_DebugShapeDirection && !m_DebugShapeBBox )
  76. {
  77. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Remove(OnDrawing);
  78. }
  79. }
  80. void OnDrawing()
  81. {
  82. #ifndef DEVELOPER
  83. return;
  84. #endif
  85. if ( m_DebugShapeBBox || m_DebugShapeDirection )
  86. {
  87. vector mat[4];
  88. m_ThisEntityAI.GetTransform(mat);
  89. if ( m_DebugShapeBBox )
  90. {
  91. m_DebugShapeBBox.SetMatrix(mat);
  92. }
  93. if ( m_DebugShapeDirection )
  94. {
  95. m_DebugShapeDirection.SetMatrix(mat);
  96. }
  97. }
  98. }
  99. }