turretShape.h

Engine/source/T3D/turret/turretShape.h

More...

Classes:

Public Typedefs

TurretShapeFireLinkType 

Detailed Description

Public Typedefs

typedef TurretShapeData::FireLinkType TurretShapeFireLinkType 

Public Functions

DefineEnumType(TurretShapeFireLinkType )

  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 _TURRETSHAPE_H_
 25#define _TURRETSHAPE_H_
 26
 27#ifndef _ITEM_H_
 28   #include "T3D/item.h"
 29#endif
 30
 31class PhysicsBody;
 32class TurretShape;
 33
 34//----------------------------------------------------------------------------
 35
 36class TurretShapeData: public ItemData {
 37
 38   typedef ItemData Parent;
 39
 40public:
 41
 42   enum FireLinkType {
 43      FireTogether,              ///< All weapons fire under trigger 0
 44      GroupedFire,               ///< Weapon mounts 0,2 fire under trigger 0, mounts 1,3 fire under trigger 1
 45      IndividualFire,            ///< Each weapon mount fires under its own trigger 0-3
 46      NumFireLinkTypeBits = 2
 47   };
 48
 49   FireLinkType   weaponLinkType;   ///< How are the weapons linked together and triggered
 50
 51   enum {
 52      NumMirrorDirectionNodes = 4,
 53   };
 54
 55   enum Recoil {
 56      LightRecoil,
 57      MediumRecoil,
 58      HeavyRecoil,
 59      NumRecoilSequences
 60   };
 61   S32 recoilSequence[NumRecoilSequences];
 62
 63   S32   pitchSequence;                ///< Optional sequence played when the turret pitches
 64   S32   headingSequence;              ///< Optional sequence played when the turret's heading changes
 65
 66   F32 cameraOffset;          ///< Vertical offset
 67
 68   F32 maxHeading;            ///< Max degrees to rotate from center. 180 or more indicates full rotation.
 69   F32 minPitch;              ///< Min degrees to rotate down from straight ahead
 70   F32 maxPitch;              ///< Max degrees to rotate up from straight ahead
 71
 72   F32 headingRate;           ///< Degrees per second rotation.  0 means not allowed.  Less than 0 means instantaneous.
 73   F32 pitchRate;             ///< Degrees per second rotation.  0 means not allowed.  Less than 0 means instantaneous.
 74
 75   S32 headingNode;                                   ///< Code controlled node for heading changes
 76   S32 pitchNode;                                     ///< Code controlled node for pitch changes
 77   S32 pitchNodes[NumMirrorDirectionNodes];           ///< Additional nodes that mirror the movements of the pitch node.
 78   S32 headingNodes[NumMirrorDirectionNodes];         ///< Additional nodes that mirror the movements of the heading node.
 79   S32 weaponMountNode[ShapeBase::MaxMountedImages];  ///< Where ShapeBaseImageData weapons are mounted
 80
 81   bool startLoaded;          ///< Should the turret's mounted weapon(s) start in a loaded state?
 82
 83   bool zRotOnly;             ///< Should the turret allow only z rotations (like an item)?
 84
 85public:
 86   TurretShapeData();
 87
 88   DECLARE_CONOBJECT(TurretShapeData);
 89
 90   static void initPersistFields();
 91
 92   virtual void packData(BitStream* stream);
 93   virtual void unpackData(BitStream* stream);
 94
 95   virtual bool preload(bool server, String &errorStr);
 96
 97   DECLARE_CALLBACK( void, onMountObject, ( SceneObject* turret, SceneObject* obj, S32 node ) );
 98   DECLARE_CALLBACK( void, onUnmountObject, ( SceneObject* turret, SceneObject* obj ) );
 99   DECLARE_CALLBACK( void, onStickyCollision, ( TurretShape* obj ) );
100};
101
102typedef TurretShapeData::FireLinkType TurretShapeFireLinkType;
103
104DefineEnumType( TurretShapeFireLinkType );
105
106//----------------------------------------------------------------------------
107
108class TurretShape: public Item
109{
110   typedef Item Parent;
111   typedef SceneObject GrandParent;
112
113protected:
114   enum MaskBits {
115      TurretUpdateMask     = Parent::NextFreeMask << 0,  ///< using one mask because we're running out of maskbits
116      NextFreeMask         = Parent::NextFreeMask << 1
117   };
118
119   // Client interpolation data for turret heading and pitch
120   struct TurretStateDelta {
121      Point3F rot;
122      VectorF rotVec;
123      F32     dt;
124   };
125   TurretStateDelta mTurretDelta;
126
127   Point3F mRot;           ///< Current heading and pitch
128   bool mPitchAllowed;     ///< Are pitch changes allowed
129   bool mHeadingAllowed;   ///< Are heading changes allowed
130   F32 mPitchUp;           ///< Pitch up limit, in radians
131   F32 mPitchDown;         ///< Pitch down limit, in radians
132   F32 mHeadingMax;        ///< Maximum heading limit from center, in radians
133   F32 mPitchRate;         ///< How fast the turret may pitch, in radians per second
134   F32 mHeadingRate;       ///< How fast the turret may yaw, in radians per second
135
136   bool mRespawn;
137
138   TSThread* mRecoilThread;
139   TSThread* mImageStateThread;
140
141   TSThread* mPitchThread;
142   TSThread* mHeadingThread;
143
144   // Static attributes
145   TurretShapeData* mDataBlock;
146
147   bool mSubclassTurretShapeHandlesScene;    ///< A subclass of TurretShape will handle all of the adding to the scene
148
149   void _setRotation(const Point3F& rot);
150   void _updateNodes(const Point3F& rot);
151   void _applyLimits(Point3F& rot);
152   bool _outsideLimits(Point3F& rot);        ///< Return true if any angle is outside of the limits
153
154   void onUnmount(SceneObject* obj,S32 node);
155
156   // Script level control
157   bool allowManualRotation;
158   bool allowManualFire;
159
160   void updateAnimation(F32 dt);
161
162   virtual void onImage(U32 imageSlot, bool unmount);
163   virtual void onImageRecoil(U32 imageSlot,ShapeBaseImageData::StateData::RecoilState);
164   virtual void onImageStateAnimation(U32 imageSlot, const char* seqName, bool direction, bool scaleToState, F32 stateTimeOutValue);
165
166public:
167
168   TurretShape();
169   virtual ~TurretShape();
170
171   static void initPersistFields();   
172
173   bool onAdd();
174   void onRemove();
175   bool onNewDataBlock(GameBaseData *dptr, bool reload);
176
177   const char* getStateName();
178   virtual void updateDamageLevel();
179
180   virtual void processTick(const Move *move);
181   virtual void interpolateTick(F32 dt);
182   virtual void advanceTime(F32 dt);
183
184   virtual void setTransform( const MatrixF &mat );
185
186   virtual bool getAllowManualRotation() { return allowManualRotation; }
187   virtual void setAllowManualRotation(bool allow) { setMaskBits(TurretUpdateMask); allowManualRotation = allow; }
188   virtual bool getAllowManualFire() { return allowManualFire; }
189   virtual void setAllowManualFire(bool allow) { setMaskBits(TurretUpdateMask); allowManualFire = allow; }
190
191   virtual void updateMove(const Move* move);
192
193   bool getNodeTransform(S32 node, MatrixF& mat);
194   bool getWorldNodeTransform(S32 node, MatrixF& mat);
195
196   Point3F getTurretRotation() {return mRot;}
197   void setTurretRotation(const Point3F& rot) {_setRotation(rot);}
198
199   bool doRespawn() { return mRespawn; };
200
201   virtual void mountObject( SceneObject *obj, S32 node, const MatrixF &xfm = MatrixF::Identity );
202   virtual void unmountObject( SceneObject *obj );
203
204   virtual void getCameraParameters(F32 *min,F32* max,Point3F* offset,MatrixF* rot);
205   virtual void getCameraTransform(F32* pos,MatrixF* mat);
206
207   virtual void writePacketData( GameConnection* conn, BitStream* stream );
208   virtual void readPacketData( GameConnection* conn, BitStream* stream );
209   virtual U32  packUpdate  (NetConnection *conn, U32 mask, BitStream *stream);
210   virtual void unpackUpdate(NetConnection *conn,           BitStream *stream);
211
212   virtual void getWeaponMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat );
213   virtual void getRenderWeaponMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat );
214
215   virtual void getImageTransform(U32 imageSlot,MatrixF* mat);
216   virtual void getRenderImageTransform(U32 imageSlot,MatrixF* mat,bool noEyeOffset=false);
217
218   virtual void getImageTransform(U32 imageSlot,S32 node, MatrixF* mat);
219   virtual void getRenderImageTransform(U32 imageSlot,S32 node, MatrixF* mat);
220
221   virtual void prepRenderImage( SceneRenderState* state );
222   virtual void prepBatchRender( SceneRenderState *state, S32 mountedImageIndex );
223
224   DECLARE_CONOBJECT(TurretShape);
225};
226
227#endif // _TURRETSHAPE_H_
228