Torque3D Documentation / _generateds / flyingVehicle.h

flyingVehicle.h

Engine/source/T3D/vehicles/flyingVehicle.h

More...

Classes:

Detailed Description

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