hoverVehicle.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 _HOVERVEHICLE_H_
  23. #define _HOVERVEHICLE_H_
  24. #ifndef _VEHICLE_H_
  25. #include "T3D/vehicles/vehicle.h"
  26. #endif
  27. class ParticleEmitter;
  28. class ParticleEmitterData;
  29. // -------------------------------------------------------------------------
  30. class HoverVehicleData : public VehicleData
  31. {
  32. typedef VehicleData Parent;
  33. protected:
  34. bool onAdd();
  35. //-------------------------------------- Console set variables
  36. public:
  37. enum Sounds {
  38. JetSound,
  39. EngineSound,
  40. FloatSound,
  41. MaxSounds
  42. };
  43. SFXProfile* sound[MaxSounds];
  44. enum Jets {
  45. // These enums index into a static name list.
  46. ForwardJetEmitter, // Thrust forward
  47. BackwardJetEmitter, // Thrust backward
  48. DownwardJetEmitter, // Thrust down
  49. MaxJetEmitters,
  50. };
  51. ParticleEmitterData* jetEmitter[MaxJetEmitters];
  52. enum JetNodes {
  53. // These enums index into a static name list.
  54. ForwardJetNode,
  55. ForwardJetNode1,
  56. BackwardJetNode,
  57. BackwardJetNode1,
  58. DownwardJetNode,
  59. DownwardJetNode1,
  60. //
  61. MaxJetNodes,
  62. MaxDirectionJets = 2,
  63. ThrustJetStart = ForwardJetNode,
  64. MaxTrails = 4,
  65. };
  66. static const char *sJetNode[MaxJetNodes];
  67. S32 jetNode[MaxJetNodes];
  68. F32 dragForce;
  69. F32 vertFactor;
  70. F32 floatingThrustFactor;
  71. F32 mainThrustForce;
  72. F32 reverseThrustForce;
  73. F32 strafeThrustForce;
  74. F32 turboFactor;
  75. F32 stabLenMin;
  76. F32 stabLenMax;
  77. F32 stabSpringConstant;
  78. F32 stabDampingConstant;
  79. F32 gyroDrag;
  80. F32 normalForce;
  81. F32 restorativeForce;
  82. F32 steeringForce;
  83. F32 rollForce;
  84. F32 pitchForce;
  85. F32 floatingGravMag;
  86. F32 brakingForce;
  87. F32 brakingActivationSpeed;
  88. ParticleEmitterData * dustTrailEmitter;
  89. S32 dustTrailID;
  90. Point3F dustTrailOffset;
  91. F32 triggerTrailHeight;
  92. F32 dustTrailFreqMod;
  93. //-------------------------------------- load set variables
  94. public:
  95. F32 maxThrustSpeed;
  96. public:
  97. HoverVehicleData();
  98. ~HoverVehicleData();
  99. void packData(BitStream*);
  100. void unpackData(BitStream*);
  101. bool preload(bool server, String &errorStr);
  102. DECLARE_CONOBJECT(HoverVehicleData);
  103. static void initPersistFields();
  104. };
  105. // -------------------------------------------------------------------------
  106. class HoverVehicle : public Vehicle
  107. {
  108. typedef Vehicle Parent;
  109. private:
  110. HoverVehicleData* mDataBlock;
  111. SimObjectPtr<ParticleEmitter> mDustTrailEmitter;
  112. protected:
  113. bool onAdd();
  114. void onRemove();
  115. bool onNewDataBlock(GameBaseData *dptr,bool reload);
  116. void updateDustTrail( F32 dt );
  117. // Vehicle overrides
  118. protected:
  119. void updateMove(const Move *move);
  120. // Physics
  121. protected:
  122. void updateForces(F32);
  123. F32 getBaseStabilizerLength() const;
  124. bool mFloating;
  125. F32 mThrustLevel;
  126. F32 mForwardThrust;
  127. F32 mReverseThrust;
  128. F32 mLeftThrust;
  129. F32 mRightThrust;
  130. SFXSource* mJetSound;
  131. SFXSource* mEngineSound;
  132. SFXSource* mFloatSound;
  133. enum ThrustDirection {
  134. // Enums index into sJetActivationTable
  135. ThrustForward,
  136. ThrustBackward,
  137. ThrustDown,
  138. NumThrustDirections,
  139. NumThrustBits = 3
  140. };
  141. ThrustDirection mThrustDirection;
  142. // Jet Threads
  143. enum Jets {
  144. // These enums index into a static name list.
  145. BackActivate,
  146. BackMaintain,
  147. JetAnimCount
  148. };
  149. static const char* sJetSequence[HoverVehicle::JetAnimCount];
  150. TSThread* mJetThread[JetAnimCount];
  151. S32 mJetSeq[JetAnimCount];
  152. bool mBackMaintainOn;
  153. // Jet Particles
  154. struct JetActivation {
  155. // Convert thrust direction into nodes & emitters
  156. S32 node;
  157. S32 emitter;
  158. };
  159. static JetActivation sJetActivation[NumThrustDirections];
  160. SimObjectPtr<ParticleEmitter> mJetEmitter[HoverVehicleData::MaxJetNodes];
  161. U32 getCollisionMask();
  162. void updateJet(F32 dt);
  163. void updateEmitter(bool active,F32 dt,ParticleEmitterData *emitter,S32 idx,S32 count);
  164. public:
  165. HoverVehicle();
  166. ~HoverVehicle();
  167. // Time/Move Management
  168. public:
  169. void advanceTime(F32 dt);
  170. DECLARE_CONOBJECT(HoverVehicle);
  171. // static void initPersistFields();
  172. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  173. void unpackUpdate(NetConnection *conn, BitStream *stream);
  174. };
  175. #endif // _H_HOVERVEHICLE