cameratools.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifdef DIAG_DEVELOPER
  2. class CameraToolsMenuServer
  3. {
  4. ref array<Man> m_Subscribers = new array<Man>;
  5. void OnRPC(int rpc_type, ParamsReadContext ctx)
  6. {
  7. switch (rpc_type)
  8. {
  9. case ERPCs.DIAG_CAMERATOOLS_CAM_DATA:
  10. {
  11. Param4<vector, vector,float,float> p4 = new Param4<vector, vector,float,float>(vector.Zero, vector.Zero,0,0);
  12. if (ctx.Read(p4))
  13. {
  14. foreach (int index, Man p : m_Subscribers)
  15. {
  16. if (p)
  17. {
  18. GetGame().RPCSingleParam(p, ERPCs.DIAG_CAMERATOOLS_CAM_DATA, p4, true, p.GetIdentity());
  19. }
  20. else
  21. {
  22. m_Subscribers.Remove(index);
  23. }
  24. }
  25. }
  26. break;
  27. }
  28. case ERPCs.DIAG_CAMERATOOLS_CAM_SUBSCRIBE:
  29. {
  30. Param2<bool, Man> par2 = new Param2<bool, Man>(false,null);
  31. if (ctx.Read(par2))
  32. {
  33. bool enable = par2.param1;
  34. Man player = par2.param2;
  35. bool found = false;
  36. foreach (int i, Man m : m_Subscribers)
  37. {
  38. if (m == player)
  39. {
  40. if (!enable)
  41. {
  42. m_Subscribers.Remove(i);
  43. return;
  44. }
  45. found = true;
  46. m_Subscribers[i] = player;
  47. }
  48. }
  49. if (!found && enable)//not found in the array, insert it
  50. {
  51. m_Subscribers.Insert(player);
  52. }
  53. }
  54. break;
  55. }
  56. }
  57. }
  58. };
  59. class CameraToolsMenuClient
  60. {
  61. Shape m_DebugShape = null;
  62. void ~CameraToolsMenuClient()
  63. {
  64. if (m_DebugShape)
  65. {
  66. m_DebugShape.Destroy();
  67. }
  68. }
  69. void DelayedDestroy()
  70. {
  71. GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( DestroyNow, 2000);
  72. }
  73. void DestroyNow()
  74. {
  75. delete this;
  76. }
  77. void OnRPC(ParamsReadContext ctx)
  78. {
  79. if (m_DebugShape)
  80. {
  81. m_DebugShape.Destroy();
  82. m_DebugShape = null;
  83. }
  84. Param4<vector, vector,float,float> p4 = new Param4<vector, vector,float,float>(vector.Zero, vector.Zero,0,0);
  85. if ( ctx.Read( p4 ) )
  86. {
  87. vector pos = p4.param1;
  88. vector dir = p4.param2;
  89. float plane = p4.param3;
  90. float fov = p4.param4 * Math.RAD2DEG;
  91. m_DebugShape = Debug.DrawFrustum(fov, 30, 0.5);
  92. vector mat[4];
  93. Math3D.DirectionAndUpMatrix(dir,vector.Up,mat);
  94. mat[3] = pos;
  95. m_DebugShape.SetMatrix(mat);
  96. }
  97. }
  98. };
  99. #endif