flyingVehicle.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _FLYINGVEHICLE_H_
  23. #define _FLYINGVEHICLE_H_
  24. #ifndef _VEHICLE_H_
  25. #include "T3D/vehicles/vehicle.h"
  26. #endif
  27. #ifndef _CLIPPEDPOLYLIST_H_
  28. #include "collision/clippedPolyList.h"
  29. #endif
  30. class ParticleEmitter;
  31. class ParticleEmitterData;
  32. //----------------------------------------------------------------------------
  33. struct FlyingVehicleData: public VehicleData {
  34. typedef VehicleData Parent;
  35. enum Sounds {
  36. JetSound,
  37. EngineSound,
  38. MaxSounds,
  39. };
  40. SFXProfile* sound[MaxSounds];
  41. enum Jets {
  42. // These enums index into a static name list.
  43. ForwardJetEmitter, // Thrust forward
  44. BackwardJetEmitter, // Thrust backward
  45. DownwardJetEmitter, // Thrust down
  46. TrailEmitter, // Contrail
  47. MaxJetEmitters,
  48. };
  49. ParticleEmitterData* jetEmitter[MaxJetEmitters];
  50. F32 minTrailSpeed;
  51. //
  52. F32 maneuveringForce;
  53. F32 horizontalSurfaceForce;
  54. F32 verticalSurfaceForce;
  55. F32 autoInputDamping;
  56. F32 steeringForce;
  57. F32 steeringRollForce;
  58. F32 rollForce;
  59. F32 autoAngularForce;
  60. F32 rotationalDrag;
  61. F32 maxAutoSpeed;
  62. F32 autoLinearForce;
  63. F32 hoverHeight;
  64. F32 createHoverHeight;
  65. F32 vertThrustMultiple;
  66. // Initialized in preload
  67. ClippedPolyList rigidBody;
  68. F32 maxSpeed;
  69. enum JetNodes {
  70. // These enums index into a static name list.
  71. ForwardJetNode,
  72. ForwardJetNode1,
  73. BackwardJetNode,
  74. BackwardJetNode1,
  75. DownwardJetNode,
  76. DownwardJetNode1,
  77. //
  78. TrailNode,
  79. TrailNode1,
  80. TrailNode2,
  81. TrailNode3,
  82. //
  83. MaxJetNodes,
  84. MaxDirectionJets = 2,
  85. ThrustJetStart = ForwardJetNode,
  86. NumThrustJets = TrailNode,
  87. MaxTrails = 4,
  88. };
  89. static const char *sJetNode[MaxJetNodes];
  90. S32 jetNode[MaxJetNodes];
  91. //
  92. FlyingVehicleData();
  93. DECLARE_CONOBJECT(FlyingVehicleData);
  94. static void initPersistFields();
  95. bool preload(bool server, String &errorStr);
  96. void packData(BitStream* stream);
  97. void unpackData(BitStream* stream);
  98. };
  99. //----------------------------------------------------------------------------
  100. class FlyingVehicle: public Vehicle
  101. {
  102. typedef Vehicle Parent;
  103. FlyingVehicleData* mDataBlock;
  104. SFXSource* mJetSound;
  105. SFXSource* mEngineSound;
  106. enum NetMaskBits {
  107. InitMask = BIT(0),
  108. HoverHeight = BIT(1)
  109. };
  110. bool createHeightOn;
  111. F32 mCeilingFactor;
  112. enum ThrustDirection {
  113. // Enums index into sJetActivationTable
  114. ThrustForward,
  115. ThrustBackward,
  116. ThrustDown,
  117. NumThrustDirections,
  118. NumThrustBits = 3
  119. };
  120. Point2F mThrust;
  121. ThrustDirection mThrustDirection;
  122. // Jet Threads
  123. enum Jets {
  124. // These enums index into a static name list.
  125. BackActivate,
  126. BackMaintain,
  127. BottomActivate,
  128. BottomMaintain,
  129. JetAnimCount
  130. };
  131. static const char* sJetSequence[FlyingVehicle::JetAnimCount];
  132. TSThread* mJetThread[JetAnimCount];
  133. S32 mJetSeq[JetAnimCount];
  134. bool mBackMaintainOn;
  135. bool mBottomMaintainOn;
  136. // Jet Particles
  137. struct JetActivation {
  138. // Convert thrust direction into nodes & emitters
  139. S32 node;
  140. S32 emitter;
  141. };
  142. static JetActivation sJetActivation[NumThrustDirections];
  143. SimObjectPtr<ParticleEmitter> mJetEmitter[FlyingVehicleData::MaxJetNodes];
  144. //
  145. bool onNewDataBlock(GameBaseData* dptr,bool reload);
  146. void updateMove(const Move *move);
  147. void updateForces(F32);
  148. // bool collideBody(const MatrixF& mat,Collision* info);
  149. F32 getHeight();
  150. // Client sounds & particles
  151. void updateJet(F32 dt);
  152. void updateEngineSound(F32 level);
  153. void updateEmitter(bool active,F32 dt,ParticleEmitterData *emitter,S32 idx,S32 count);
  154. U32 getCollisionMask();
  155. public:
  156. DECLARE_CONOBJECT(FlyingVehicle);
  157. static void initPersistFields();
  158. FlyingVehicle();
  159. ~FlyingVehicle();
  160. bool onAdd();
  161. void onRemove();
  162. void advanceTime(F32 dt);
  163. void writePacketData(GameConnection *conn, BitStream *stream);
  164. void readPacketData(GameConnection *conn, BitStream *stream);
  165. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
  166. void unpackUpdate(NetConnection *conn, BitStream *stream);
  167. void useCreateHeight(bool val);
  168. };
  169. #endif