flyingVehicle.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. DECLARE_SOUNDASSET_ARRAY(FlyingVehicleData, FlyingSounds, Sounds::MaxSounds);
  41. DECLARE_ASSET_ARRAY_SETGET(FlyingVehicleData, FlyingSounds);
  42. enum Jets {
  43. // These enums index into a static name list.
  44. ForwardJetEmitter, // Thrust forward
  45. BackwardJetEmitter, // Thrust backward
  46. DownwardJetEmitter, // Thrust down
  47. TrailEmitter, // Contrail
  48. MaxJetEmitters,
  49. };
  50. ParticleEmitterData* jetEmitter[MaxJetEmitters];
  51. F32 minTrailSpeed;
  52. //
  53. F32 maneuveringForce;
  54. F32 horizontalSurfaceForce;
  55. F32 verticalSurfaceForce;
  56. F32 autoInputDamping;
  57. F32 steeringForce;
  58. F32 steeringRollForce;
  59. F32 rollForce;
  60. F32 autoAngularForce;
  61. F32 rotationalDrag;
  62. F32 maxAutoSpeed;
  63. F32 autoLinearForce;
  64. F32 hoverHeight;
  65. F32 createHoverHeight;
  66. F32 vertThrustMultiple;
  67. // Initialized in preload
  68. ClippedPolyList rigidBody;
  69. F32 maxSpeed;
  70. enum JetNodes {
  71. // These enums index into a static name list.
  72. ForwardJetNode,
  73. ForwardJetNode1,
  74. BackwardJetNode,
  75. BackwardJetNode1,
  76. DownwardJetNode,
  77. DownwardJetNode1,
  78. //
  79. TrailNode,
  80. TrailNode1,
  81. TrailNode2,
  82. TrailNode3,
  83. //
  84. MaxJetNodes,
  85. MaxDirectionJets = 2,
  86. ThrustJetStart = ForwardJetNode,
  87. NumThrustJets = TrailNode,
  88. MaxTrails = 4,
  89. };
  90. static const char *sJetNode[MaxJetNodes];
  91. S32 jetNode[MaxJetNodes];
  92. //
  93. FlyingVehicleData();
  94. DECLARE_CONOBJECT(FlyingVehicleData);
  95. static void initPersistFields();
  96. bool preload(bool server, String &errorStr) override;
  97. void packData(BitStream* stream) override;
  98. void unpackData(BitStream* stream) override;
  99. };
  100. //----------------------------------------------------------------------------
  101. class FlyingVehicle: public Vehicle
  102. {
  103. typedef Vehicle Parent;
  104. FlyingVehicleData* mDataBlock;
  105. SFXSource* mJetSound;
  106. SFXSource* mEngineSound;
  107. enum NetMaskBits {
  108. InitMask = BIT(0),
  109. HoverHeight = BIT(1)
  110. };
  111. bool createHeightOn;
  112. F32 mCeilingFactor;
  113. enum ThrustDirection {
  114. // Enums index into sJetActivationTable
  115. ThrustForward,
  116. ThrustBackward,
  117. ThrustDown,
  118. NumThrustDirections,
  119. NumThrustBits = 3
  120. };
  121. Point2F mThrust;
  122. ThrustDirection mThrustDirection;
  123. // Jet Threads
  124. enum Jets {
  125. // These enums index into a static name list.
  126. BackActivate,
  127. BackMaintain,
  128. BottomActivate,
  129. BottomMaintain,
  130. JetAnimCount
  131. };
  132. static const char* sJetSequence[FlyingVehicle::JetAnimCount];
  133. TSThread* mJetThread[JetAnimCount];
  134. S32 mJetSeq[JetAnimCount];
  135. bool mBackMaintainOn;
  136. bool mBottomMaintainOn;
  137. // Jet Particles
  138. struct JetActivation {
  139. // Convert thrust direction into nodes & emitters
  140. S32 node;
  141. S32 emitter;
  142. };
  143. static JetActivation sJetActivation[NumThrustDirections];
  144. SimObjectPtr<ParticleEmitter> mJetEmitter[FlyingVehicleData::MaxJetNodes];
  145. //
  146. bool onNewDataBlock(GameBaseData* dptr,bool reload) override;
  147. void updateMove(const Move *move) override;
  148. void updateForces(F32) override;
  149. // bool collideBody(const MatrixF& mat,Collision* info);
  150. F32 getHeight();
  151. // Client sounds & particles
  152. void updateJet(F32 dt);
  153. void updateEngineSound(F32 level);
  154. void updateEmitter(bool active,F32 dt,ParticleEmitterData *emitter,S32 idx,S32 count);
  155. U32 getCollisionMask() override;
  156. public:
  157. DECLARE_CONOBJECT(FlyingVehicle);
  158. DECLARE_CATEGORY("Actor \t Controllable");
  159. static void initPersistFields();
  160. FlyingVehicle();
  161. ~FlyingVehicle();
  162. bool onAdd() override;
  163. void onRemove() override;
  164. void interpolateTick(F32 dt) override;
  165. void advanceTime(F32 dt) override;
  166. void writePacketData(GameConnection *conn, BitStream *stream) override;
  167. void readPacketData(GameConnection *conn, BitStream *stream) override;
  168. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream) override;
  169. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  170. void useCreateHeight(bool val);
  171. };
  172. #endif