shapeBase.h

Engine/source/T3D/shapeBase.h

More...

Classes:

class

ShapeBase is the renderable shape from which most of the scriptable objects are derived, including the player, vehicle and items classes.

class

An image mounted on a shapebase.

class

Represent the state of a specific particle emitter on the image.

Public Typedefs

void *
Light 
ShapeBaseImageLightType 

Public Variables

Detailed Description

Public Typedefs

typedef void * Light 
typedef ShapeBaseImageData::LightType ShapeBaseImageLightType 
typedef ShapeBaseImageData::StateData::LoadedState ShapeBaseImageLoadedState 
typedef ShapeBaseImageData::StateData::RecoilState ShapeBaseImageRecoilState 
typedef ShapeBaseImageData::StateData::SpinState ShapeBaseImageSpinState 

Public Variables

const F32 gGravity 

Public Functions

collisionFilter(SceneObject * object, S32 key)

defaultFilter(SceneObject * object, S32 key)

DefineEnumType(ShapeBaseImageLightType )

DefineEnumType(ShapeBaseImageLoadedState )

DefineEnumType(ShapeBaseImageRecoilState )

DefineEnumType(ShapeBaseImageSpinState )

   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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  26// Copyright (C) 2015 Faust Logic, Inc.
  27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  28#ifndef _SHAPEBASE_H_
  29#define _SHAPEBASE_H_
  30
  31#ifndef __RESOURCE_H__
  32   #include "core/resource.h"
  33#endif
  34#ifndef _GAMEBASE_H_
  35   #include "T3D/gameBase/gameBase.h"
  36#endif
  37#ifndef _MOVEMANAGER_H_
  38   #include "T3D/gameBase/moveManager.h"
  39#endif
  40#ifndef _COLOR_H_
  41   #include "core/color.h"
  42#endif
  43#ifndef _CONVEX_H_
  44   #include "collision/convex.h"
  45#endif
  46#ifndef _SCENERENDERSTATE_H_
  47   #include "scene/sceneRenderState.h"
  48#endif
  49#ifndef _NETSTRINGTABLE_H_
  50   #include "sim/netStringTable.h"
  51#endif
  52#ifndef _RENDERPASSMANAGER_H_
  53   #include "renderInstance/renderPassManager.h"
  54#endif
  55#ifndef _TSSHAPE_H_
  56   #include "ts/tsShape.h"
  57#endif
  58#ifndef _BITVECTOR_H_
  59   #include "core/bitVector.h"
  60#endif
  61#ifndef _LIGHTINFO_H_
  62   #include "lighting/lightInfo.h"
  63#endif
  64#ifndef _REFLECTOR_H_
  65   #include "scene/reflector.h"
  66#endif
  67#ifndef _DYNAMIC_CONSOLETYPES_H_
  68   #include "console/dynamicTypes.h"
  69#endif
  70
  71#ifndef SHAPEASSET_H
  72#include "T3D/assets/ShapeAsset.h"
  73#endif 
  74
  75// Need full definition visible for SimObjectPtr<ParticleEmitter>
  76#include "T3D/fx/particleEmitter.h"
  77
  78class GFXCubemap;
  79class TSShapeInstance;
  80class SceneRenderState;
  81class TSThread;
  82class GameConnection;
  83struct CameraScopeQuery;
  84class ProjectileData;
  85class ExplosionData;
  86struct DebrisData;
  87class ShapeBase;
  88class SFXSource;
  89class SFXTrack;
  90class SFXProfile;
  91
  92typedef void* Light;
  93
  94const F32 gGravity = -20;
  95
  96//--------------------------------------------------------------------------
  97
  98extern void collisionFilter(SceneObject* object,S32 key);
  99extern void defaultFilter(SceneObject* object,S32 key);
 100
 101
 102//--------------------------------------------------------------------------
 103class ShapeBaseConvex : public Convex
 104{
 105   typedef Convex Parent;
 106   friend class ShapeBase;
 107   friend class Vehicle;
 108   friend class RigidShape;
 109
 110  protected:
 111   ShapeBase*  pShapeBase;
 112   MatrixF*    nodeTransform;
 113
 114  public:
 115   MatrixF*    transform;
 116   U32         hullId;
 117   Box3F       box;
 118
 119  public:
 120   ShapeBaseConvex() :pShapeBase(NULL), transform(NULL), hullId(NULL), nodeTransform(0) { mType = ShapeBaseConvexType; }
 121   ShapeBaseConvex(const ShapeBaseConvex& cv) {
 122      mObject    = cv.mObject;
 123      pShapeBase = cv.pShapeBase;
 124      hullId     = cv.hullId;
 125      nodeTransform = cv.nodeTransform;
 126      box        = cv.box;
 127      transform  = 0;
 128   }
 129
 130   void findNodeTransform();
 131   const MatrixF& getTransform() const;
 132   Box3F getBoundingBox() const;
 133   Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
 134   Point3F      support(const VectorF& v) const;
 135   void         getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf);
 136   void         getPolyList(AbstractPolyList* list);
 137};
 138
 139//--------------------------------------------------------------------------
 140
 141struct ShapeBaseImageData: public GameBaseData {
 142  private:
 143   typedef GameBaseData Parent;
 144
 145  public:
 146   enum Constants {
 147      MaxStates    = 31,            ///< We get one less than state bits because of
 148                                    /// the way data is packed.
 149
 150      MaxShapes    = 2,             ///< The number of allowed shapes per image.  Only
 151                                    /// the first shape is required.
 152
 153      MaxGenericTriggers = 4,       ///< The number of generic triggers for the image.
 154
 155      StandardImageShape = 0,       ///< Shape index used for the standard image shape
 156      FirstPersonImageShape = 1,    ///< Shape index used for the optional first person image shape
 157
 158      NumStateBits = 5,
 159   };
 160   enum LightType {
 161      NoLight = 0,
 162      ConstantLight,
 163      SpotLight,
 164      PulsingLight,
 165      WeaponFireLight,
 166      NumLightTypes
 167   };
 168   struct StateData {
 169      StateData();
 170      const char* name;             ///< State name
 171
 172      /// @name Transition states
 173      ///
 174      /// @{
 175
 176      ///
 177      struct Transition {
 178         S32 loaded[2];             ///< NotLoaded/Loaded
 179         S32 ammo[2];               ///< Noammo/ammo
 180         S32 target[2];             ///< target/noTarget
 181         S32 trigger[2];            ///< Trigger up/down
 182         S32 altTrigger[2];         ///< Second trigger up/down
 183         S32 wet[2];                ///< wet/notWet
 184         S32 motion[2];             ///< NoMotion/Motion
 185         S32 timeout;               ///< Transition after delay
 186         S32 genericTrigger[ShapeBaseImageData::MaxGenericTriggers][2];    ///< Generic trigger Out/In
 187      } transition;
 188      bool ignoreLoadedForReady;
 189
 190      /// @}
 191
 192      /// @name State attributes
 193      /// @{
 194
 195      bool fire;                    ///< Can only have one fire state
 196      bool altFire;                 ///< Can only have one alternate fire state
 197      bool reload;                  ///< Can only have one reload state
 198      bool ejectShell;              ///< Should we eject a shell casing in this state?
 199      bool allowImageChange;        ///< Can we switch to another image while in this state?
 200                                    ///
 201                                    ///  For instance, if we have a rocket launcher, the player
 202                                    ///  shouldn't be able to switch out <i>while</i> firing. So,
 203                                    ///  you'd set allowImageChange to false in firing states, and
 204                                    ///  true the rest of the time.
 205      bool scaleAnimation;          ///< Scale animation to fit the state timeout
 206      bool scaleAnimationFP;        ///< Scale animation to fit the state timeout while in first person
 207      bool direction;               ///< Animation direction
 208      bool sequenceTransitionIn;    ///< Do we transition to the state's sequence when we enter the state?
 209      bool sequenceTransitionOut;   ///< Do we transition to the new state's sequence when we leave the state?
 210      bool sequenceNeverTransition; ///< Never allow a transition to this sequence.  Often used for a fire sequence.
 211      F32 sequenceTransitionTime;   ///< The time to transition in or out of a sequence.
 212      bool waitForTimeout;          ///< Require the timeout to pass before advancing to the next
 213                                    ///  state.
 214      F32 timeoutValue;             ///< A timeout value; the effect of this value is determined
 215                                    ///  by the flags scaleAnimation and waitForTimeout
 216      F32 energyDrain;              ///< Sets the energy drain rate per second of this state.
 217                                    ///
 218                                    ///  Energy is drained at energyDrain units/sec as long as
 219                                    ///  we are in this state.
 220      enum LoadedState {
 221         IgnoreLoaded,              ///< Don't change loaded state.
 222         Loaded,                    ///< Set us as loaded.
 223         NotLoaded,                 ///< Set us as not loaded.
 224         NumLoadedBits = 3          ///< How many bits to allocate to representing this state. (3 states needs 2 bits)
 225      } loaded;                     ///< Is the image considered loaded?
 226      enum SpinState {
 227         IgnoreSpin,                ///< Don't change spin state.
 228         NoSpin,                    ///< Mark us as having no spin (ie, stop spinning).
 229         SpinUp,                    ///< Mark us as spinning up.
 230         SpinDown,                  ///< Mark us as spinning down.
 231         FullSpin,                  ///< Mark us as being at full spin.
 232         NumSpinBits = 3            ///< How many bits to allocate to representing this state. (5 states needs 3 bits)
 233      } spin;                       ///< Spin thread state. (Used to control spinning weapons, e.g. chainguns)
 234      enum RecoilState {
 235         NoRecoil,
 236         LightRecoil,
 237         MediumRecoil,
 238         HeavyRecoil,
 239         NumRecoilBits = 3
 240      } recoil;                     ///< Recoil thread state.
 241                                    ///
 242                                    /// @note At this point, the only check being done is to see if we're in a
 243                                    ///       state which isn't NoRecoil; ie, no differentiation is made between
 244                                    ///       Light/Medium/Heavy recoils. Player::onImageRecoil() is the place
 245                                    ///       where this is handled.
 246      bool flashSequence[MaxShapes];///< Is this a muzzle flash sequence?
 247                                    ///
 248                                    ///  A muzzle flash sequence is used as a source to randomly display frames from,
 249                                    ///  so if this is a flashSequence, we'll display a random piece each frame.
 250      S32 sequence[MaxShapes];      ///< Main thread sequence ID.
 251                                    ///
 252                                    ///
 253      S32 sequenceVis[MaxShapes];   ///< Visibility thread sequence.
 254
 255      StringTableEntry shapeSequence;  ///< Sequence that is played on mounting shape
 256      bool shapeSequenceScale;         ///< Should the mounting shape's sequence playback be scaled
 257                                       ///  to the length of the state.
 258
 259      const char* script;           ///< Function on datablock to call when we enter this state; passed the id of
 260                                    ///  the imageSlot.
 261      ParticleEmitterData* emitter; ///< A particle emitter; this emitter will emit as long as the gun is in this
 262                                    ///  this state.
 263      SFXTrack* sound;
 264      F32 emitterTime;              ///<
 265      S32 emitterNode[MaxShapes];   ///< Node ID on the shape to emit from
 266   };
 267
 268   /// @name State Data
 269   /// Individual state data used to initialize struct array
 270   /// @{
 271   const char*             fireStateName;
 272
 273   const char*             stateName                  [MaxStates];
 274
 275   const char*             stateTransitionLoaded      [MaxStates];
 276   const char*             stateTransitionNotLoaded   [MaxStates];
 277   const char*             stateTransitionAmmo        [MaxStates];
 278   const char*             stateTransitionNoAmmo      [MaxStates];
 279   const char*             stateTransitionTarget      [MaxStates];
 280   const char*             stateTransitionNoTarget    [MaxStates];
 281   const char*             stateTransitionWet         [MaxStates];
 282   const char*             stateTransitionNotWet      [MaxStates];
 283   const char*             stateTransitionMotion      [MaxStates];
 284   const char*             stateTransitionNoMotion    [MaxStates];
 285   const char*             stateTransitionTriggerUp   [MaxStates];
 286   const char*             stateTransitionTriggerDown [MaxStates];
 287   const char*             stateTransitionAltTriggerUp[MaxStates];
 288   const char*             stateTransitionAltTriggerDown[MaxStates];
 289   const char*             stateTransitionGeneric0In  [MaxStates];
 290   const char*             stateTransitionGeneric0Out [MaxStates];
 291   const char*             stateTransitionGeneric1In  [MaxStates];
 292   const char*             stateTransitionGeneric1Out [MaxStates];
 293   const char*             stateTransitionGeneric2In  [MaxStates];
 294   const char*             stateTransitionGeneric2Out [MaxStates];
 295   const char*             stateTransitionGeneric3In  [MaxStates];
 296   const char*             stateTransitionGeneric3Out [MaxStates];
 297   const char*             stateTransitionTimeout     [MaxStates];
 298   F32                     stateTimeoutValue          [MaxStates];
 299   bool                    stateWaitForTimeout        [MaxStates];
 300
 301   bool                    stateFire                  [MaxStates];
 302   bool                    stateAlternateFire         [MaxStates];
 303   bool                    stateReload                [MaxStates];
 304   bool                    stateEjectShell            [MaxStates];
 305   F32                     stateEnergyDrain           [MaxStates];
 306   bool                    stateAllowImageChange      [MaxStates];
 307   bool                    stateScaleAnimation        [MaxStates];
 308   bool                    stateScaleAnimationFP      [MaxStates];
 309   bool                    stateSequenceTransitionIn  [MaxStates];
 310   bool                    stateSequenceTransitionOut [MaxStates];
 311   bool                    stateSequenceNeverTransition [MaxStates];
 312   F32                     stateSequenceTransitionTime [MaxStates];
 313   bool                    stateDirection             [MaxStates];
 314   StateData::LoadedState  stateLoaded                [MaxStates];
 315   StateData::SpinState    stateSpin                  [MaxStates];
 316   StateData::RecoilState  stateRecoil                [MaxStates];
 317   const char*             stateSequence              [MaxStates];
 318   bool                    stateSequenceRandomFlash   [MaxStates];
 319
 320   const char*             stateShapeSequence         [MaxStates];
 321   bool                    stateScaleShapeSequence    [MaxStates];
 322
 323   bool                    stateIgnoreLoadedForReady  [MaxStates];
 324
 325   SFXTrack*               stateSound                 [MaxStates];
 326   const char*             stateScript                [MaxStates];
 327
 328   ParticleEmitterData*    stateEmitter               [MaxStates];
 329   F32                     stateEmitterTime           [MaxStates];
 330   const char*             stateEmitterNode           [MaxStates];
 331   /// @}
 332   
 333   /// @name Camera Shake ( while firing )
 334   /// @{
 335   bool              shakeCamera;
 336   VectorF           camShakeFreq;
 337   VectorF           camShakeAmp;
 338   F32               camShakeDuration;
 339   F32               camShakeRadius;
 340   F32               camShakeFalloff;
 341   /// @}
 342
 343   /// Maximum number of sounds this image can play at a time.
 344   /// Any value <= 0 indicates that it can play an infinite number of sounds.
 345   S32 maxConcurrentSounds; 
 346   
 347   /// If true it we will allow multiple timeout transitions to occur within
 348   /// a single tick ( eg. they have a very small timeout ).
 349   bool useRemainderDT;
 350
 351   //
 352   bool emap;                       ///< Environment mapping on?
 353   bool correctMuzzleVector;        ///< Adjust 1st person firing vector to eye's LOS point?
 354   bool correctMuzzleVectorTP;      ///< Adjust 3rd person firing vector to camera's LOS point?
 355   bool firstPerson;                ///< Render the image when in first person?
 356   bool useFirstPersonShape;        ///< Indicates the special first person shape should be used (true when shapeNameFP and useEyeOffset are defined)
 357   bool useEyeOffset;               ///< In first person, should we use the eyeTransform?
 358   bool useEyeNode;                 ///< In first person, should we attach the camera to the image's eye node?  Player still ultimately decides on what to do,
 359                                    ///  especially for multiple mounted images.
 360
 361   bool animateAllShapes;           ///< Indicates that all shapes should be animated in sync.
 362   bool animateOnServer;            ///< Indicates that the image should be animated on the server.  In most cases
 363                                    ///  you'll want this set if you're using useEyeNode.  You may also want to
 364                                    ///  set this if the muzzlePoint is animated while it shoots.  You can set this
 365                                    ///  to false even if these previous cases are true if the image's shape is set
 366                                    ///  up in the correct position and orientation in the 'root' pose and none of
 367                                    ///  the nodes are animated at key times, such as the muzzlePoint essentially
 368                                    ///  remaining at the same position at the start of the fire state (it could
 369                                    ///  animate just fine after the projectile is away as the muzzle vector is only
 370                                    ///  calculated at the start of the state).  You'll also want to set this to true
 371                                    ///  if you're animating the camera using an image's 'eye' node -- unless the movement
 372                                    ///  is very subtle and doesn't need to be reflected on the server.
 373
 374   F32 scriptAnimTransitionTime;    ///< The amount of time to transition between the previous sequence and new sequence
 375                                    ///< when the script prefix has changed.
 376
 377   StringTableEntry  shapeName;     ///< Name of shape to render.
 378   StringTableEntry  shapeNameFP;   ///< Name of shape to render in first person (optional).
 379
 380   StringTableEntry  imageAnimPrefix;     ///< Passed along to the mounting shape to modify
 381                                          ///  animation sequences played in 3rd person. [optional]
 382   StringTableEntry  imageAnimPrefixFP;   ///< Passed along to the mounting shape to modify
 383                                          ///  animation sequences played in first person. [optional]
 384
 385   U32               mountPoint;    ///< Mount point for the image.
 386   MatrixF           mountOffset;   ///< Mount point offset, so we know where the image is.
 387   MatrixF           eyeOffset;     ///< Offset from eye for first person.
 388
 389   ProjectileData* projectile;      ///< Information about what projectile this
 390                                    ///  image fires.
 391
 392   F32   mass;                      ///< Mass!
 393   bool  usesEnergy;                ///< Does this use energy instead of ammo?
 394   F32   minEnergy;                 ///< Minimum energy for the weapon to be operable.
 395   bool  accuFire;                  ///< Should we automatically make image's aim converge with the crosshair?
 396   bool  cloakable;                 ///< Is this image cloakable when mounted?
 397
 398   /// @name Lighting
 399   /// @{
 400   S32         lightType;           ///< Indicates the type of the light.
 401                                    ///
 402                                    ///  One of: ConstantLight, PulsingLight, WeaponFireLight.
 403   LinearColorF      lightColor;
 404   S32         lightDuration;       ///< The duration in SimTime of Pulsing or WeaponFire type lights.
 405   F32         lightRadius;         ///< Extent of light.
 406   F32         lightBrightness;     ///< Brightness of the light ( if it is WeaponFireLight ).
 407   /// @}
 408
 409   /// @name Shape Data
 410   /// @{
 411   Resource<TSShape> shape[MaxShapes]; ///< Shape handle
 412   bool shapeIsValid[MaxShapes];       ///< Indicates that the shape has been loaded and is valid
 413
 414   U32 mCRC[MaxShapes];                ///< Checksum of shape.
 415                                       ///
 416                                       ///  Calculated by the ResourceManager, see
 417                                       ///  ResourceManager::load().
 418   bool computeCRC;                    ///< Should the shape's CRC be checked?
 419   MatrixF mountTransform[MaxShapes];  ///< Transformation to get to the mountNode.
 420   /// @}
 421
 422   /// @name Nodes
 423   /// @{
 424   S32 retractNode[MaxShapes];   ///< Retraction node ID.
 425                                 ///
 426                                 ///  When the player bumps against an object and the image is retracted to
 427                                 ///  avoid having it interpenetrating the object, it is retracted towards
 428                                 ///  this node.
 429   S32 muzzleNode[MaxShapes];    ///< Muzzle node ID.
 430                                 ///
 431                                 ///
 432   S32 ejectNode[MaxShapes];     ///< Ejection node ID.
 433                                 ///
 434                                 ///  The eject node is the node on the image from which shells are ejected.
 435   S32 emitterNode[MaxShapes];   ///< Emitter node ID.
 436                                 ///
 437                                 ///  The emitter node is the node from which particles are emitted.
 438   S32 eyeMountNode[MaxShapes];  ///< eyeMount node ID.  Optionally used to mount an image to the player's
 439                                 /// eye node for first person.
 440   S32 eyeNode[MaxShapes];       ///< Eye node ID.  Optionally used to attach the camera to for camera motion
 441                                 ///  control from the image.
 442   /// @}
 443
 444   /// @name Animation
 445   /// @{
 446   S32 spinSequence[MaxShapes];     ///< ID of the spin animation sequence.
 447   S32 ambientSequence[MaxShapes];  ///< ID of the ambient animation sequence.
 448
 449   bool isAnimated[MaxShapes];      ///< This image contains at least one animated states
 450   bool hasFlash[MaxShapes];        ///< This image contains at least one muzzle flash animation state
 451   S32 fireState;                   ///< The ID of the fire state.
 452   S32 altFireState;                ///< The ID of the alternate fire state.
 453   S32 reloadState;                 ///< The ID of the reload state
 454   /// @}
 455
 456   /// @name Shell casing data
 457   /// @{
 458   DebrisData *   casing;              ///< Information about shell casings.
 459
 460   S32            casingID;            ///< ID of casing datablock.
 461                                       ///
 462                                       ///  When the network tells the client about the casing, it
 463                                       ///  it transmits the ID of the datablock. The datablocks
 464                                       ///  having previously been transmitted, all the client
 465                                       ///  needs to do is call Sim::findObject() and look up the
 466                                       ///  the datablock.
 467
 468   Point3F        shellExitDir;        ///< Vector along which to eject shells from the image.
 469   F32            shellExitVariance;   ///< Variance from this vector in degrees.
 470   F32            shellVelocity;       ///< Velocity with which to eject shell casings.
 471   /// @}
 472
 473   /// @name State Array
 474   ///
 475   /// State array is initialized onAdd from the individual state
 476   /// struct array elements.
 477   ///
 478   /// @{
 479   StateData state[MaxStates];   ///< Array of states.
 480   bool      statesLoaded;       ///< Are the states loaded yet?
 481   /// @}
 482
 483   /// @name Infrastructure
 484   ///
 485   /// Miscellaneous inherited methods.
 486   /// @{
 487
 488   DECLARE_CONOBJECT(ShapeBaseImageData);
 489   ShapeBaseImageData();
 490   ~ShapeBaseImageData();
 491   bool onAdd();
 492   bool preload(bool server, String &errorStr);
 493   S32 lookupState(const char* name);  ///< Get a state by name.
 494   static void initPersistFields();
 495   virtual void packData(BitStream* stream);
 496   virtual void unpackData(BitStream* stream);
 497   
 498   void inspectPostApply();
 499
 500   /// @}
 501
 502   /// @name Callbacks
 503   /// @{
 504   DECLARE_CALLBACK( void, onMount, ( SceneObject* obj, S32 slot, F32 dt ) );
 505   DECLARE_CALLBACK( void, onUnmount, ( SceneObject* obj, S32 slot, F32 dt ) );
 506   /// @}
 507};
 508
 509typedef ShapeBaseImageData::LightType ShapeBaseImageLightType;
 510typedef ShapeBaseImageData::StateData::LoadedState ShapeBaseImageLoadedState;
 511typedef ShapeBaseImageData::StateData::SpinState ShapeBaseImageSpinState;
 512typedef ShapeBaseImageData::StateData::RecoilState ShapeBaseImageRecoilState;
 513
 514DefineEnumType( ShapeBaseImageLightType );
 515DefineEnumType( ShapeBaseImageLoadedState );
 516DefineEnumType( ShapeBaseImageSpinState );
 517DefineEnumType( ShapeBaseImageRecoilState );
 518
 519//--------------------------------------------------------------------------
 520/// @nosubgrouping
 521struct ShapeBaseData : public GameBaseData {
 522  private:
 523   typedef GameBaseData Parent;
 524   
 525   static bool _setMass( void* object, const char* index, const char* data );
 526
 527public:
 528   /// Various constants relating to the ShapeBaseData
 529   enum Constants {
 530      MaxCollisionShapes = 8,
 531      AIRepairNode = 31
 532   };
 533
 534   // TODO: These are only really used in Basic Lighting
 535   // mode... we should probably move them somewhere else.
 536   bool shadowEnable;
 537   U32 shadowSize;
 538   F32 shadowMaxVisibleDistance;
 539   F32 shadowProjectionDistance;
 540   F32 shadowSphereAdjust;
 541
 542   DECLARE_SHAPEASSET(ShapeBaseData, Shape);
 543
 544   StringTableEntry  cloakTexName;
 545
 546   String cubeDescName;
 547   U32 cubeDescId;
 548   ReflectorDesc *reflectorDesc;
 549
 550   /// @name Destruction
 551   ///
 552   /// Everyone likes to blow things up!
 553   /// @{
 554   DebrisData *      debris;
 555   S32               debrisID;
 556   StringTableEntry  debrisShapeName;
 557   Resource<TSShape> debrisShape;
 558
 559   ExplosionData*    explosion;
 560   S32               explosionID;
 561
 562   ExplosionData*    underwaterExplosion;
 563   S32               underwaterExplosionID;
 564   /// @}
 565
 566   /// @name Physical Properties
 567   /// @{
 568   F32 mass;
 569   F32 drag;
 570   F32 density;
 571   F32 maxEnergy;
 572   F32 maxDamage;
 573   F32 repairRate;                  ///< Rate per tick.
 574
 575   F32 disabledLevel;
 576   F32 destroyedLevel;
 577   /// @}
 578
 579   /// @name 3rd Person Camera
 580   /// @{
 581   F32 cameraMaxDist;               ///< Maximum distance from eye
 582   F32 cameraMinDist;               ///< Minumumistance from eye
 583   /// @}
 584
 585   /// @name Camera FOV
 586   ///
 587   /// These are specified in degrees.
 588   /// @{
 589   F32 cameraDefaultFov;            ///< Default vertical FOV in degrees.
 590   F32 cameraMinFov;                ///< Min vertical FOV allowed in degrees.
 591   F32 cameraMaxFov;                ///< Max vertical FOV allowed in degrees.
 592   /// @}
 593
 594   /// @name Camera Misc
 595   /// @{
 596   bool cameraCanBank;              ///< If the derrived class supports it, allow the camera to bank
 597   bool mountedImagesBank;          ///< Do mounted images bank along with the camera?
 598   /// @}
 599
 600   /// @name Data initialized on preload
 601   /// @{
 602
 603   Resource<TSShape> mShape;         ///< Shape handle
 604   U32 mCRC;
 605   bool computeCRC;
 606
 607   S32 eyeNode;                         ///< Shape's eye node index
 608   S32 earNode;                         ///< Shape's ear node index
 609   S32 cameraNode;                      ///< Shape's camera node index
 610   S32 mountPointNode[SceneObject::NumMountPoints];  ///< Node index of mountPoint
 611   S32 debrisDetail;                    ///< Detail level used to generate debris
 612   S32 damageSequence;                  ///< Damage level decals
 613   S32 hulkSequence;                    ///< Destroyed hulk
 614
 615   bool              observeThroughObject;   // observe this object through its camera transform and default fov
 616
 617   /// @name Collision Data
 618   /// @{
 619   Vector<S32>   collisionDetails;  ///< Detail level used to collide with.
 620                                    ///
 621                                    /// These are detail IDs, see TSShape::findDetail()
 622   Vector<Box3F> collisionBounds;   ///< Detail level bounding boxes.
 623
 624   Vector<S32>   LOSDetails;        ///< Detail level used to perform line-of-sight queries against.
 625                                    ///
 626                                    /// These are detail IDs, see TSShape::findDetail()
 627   /// @}
 628
 629   /// @name Misc. Settings
 630   /// @{
 631   bool firstPersonOnly;            ///< Do we allow only first person view of this image?
 632   bool useEyePoint;                ///< Do we use this object's eye point to view from?
 633   bool isInvincible;               ///< If set, object cannot take damage (won't show up with damage bar either)
 634   bool renderWhenDestroyed;        ///< If set, will not render this object when destroyed.
 635
 636   bool inheritEnergyFromMount;
 637
 638   /// @}
 639
 640   virtual bool preload(bool server, String &errorStr);
 641   void computeAccelerator(U32 i);
 642   S32  findMountPoint(U32 n);
 643
 644   /// @name Infrastructure
 645   /// The derived class should provide the following:
 646   /// @{
 647   DECLARE_CONOBJECT(ShapeBaseData);
 648   ShapeBaseData();
 649   ~ShapeBaseData();
 650   static void initPersistFields();
 651   virtual void packData(BitStream* stream);
 652   virtual void unpackData(BitStream* stream);
 653   /// @}
 654
 655   /// @name Callbacks
 656   /// @{
 657   DECLARE_CALLBACK( void, onEnabled, ( ShapeBase* obj, const char* lastState ) );
 658   DECLARE_CALLBACK( void, onDisabled, ( ShapeBase* obj, const char* lastState ) );
 659   DECLARE_CALLBACK( void, onDestroyed, ( ShapeBase* obj, const char* lastState ) );
 660   DECLARE_CALLBACK( void, onImpact, ( ShapeBase* obj, SceneObject* collObj, VectorF vec, F32 len ) );
 661   DECLARE_CALLBACK( void, onCollision, ( ShapeBase* obj, SceneObject* collObj, VectorF vec, F32 len ) );
 662   DECLARE_CALLBACK( void, onDamage, ( ShapeBase* obj, F32 delta ) );
 663   DECLARE_CALLBACK( void, onTrigger, ( ShapeBase* obj, S32 index, bool state ) );
 664   DECLARE_CALLBACK(void, onEndSequence, (ShapeBase* obj, S32 slot, const char* name));
 665   DECLARE_CALLBACK( void, onForceUncloak, ( ShapeBase* obj, const char* reason ) );
 666   /// @}
 667   struct TextureTagRemapping
 668   {
 669      char* old_tag;
 670      char* new_tag;
 671   };
 672   StringTableEntry remap_txr_tags;
 673   char* remap_buffer;
 674   Vector<TextureTagRemapping> txr_tag_remappings;
 675   bool silent_bbox_check;
 676public:
 677   ShapeBaseData(const ShapeBaseData&, bool = false);
 678};
 679
 680
 681//----------------------------------------------------------------------------
 682
 683class WaterObject;
 684class CameraShake;
 685
 686/// ShapeBase is the renderable shape from which most of the scriptable objects
 687/// are derived, including the player, vehicle and items classes.  ShapeBase
 688/// provides basic shape loading, audio channels, and animation as well as damage
 689/// (and damage states), energy, and the ability to mount images and objects.
 690///
 691/// @nosubgrouping
 692class ShapeBase : public GameBase, public ISceneLight
 693{
 694   friend class ShapeBaseConvex;
 695   friend struct ShapeBaseImageData;
 696   friend void waterFind(SceneObject*, void*);
 697   friend void physicalZoneFind(SceneObject*, void*);
 698
 699public:
 700   typedef GameBase Parent;
 701
 702   enum PublicConstants {
 703      ThreadSequenceBits = 6,
 704      MaxSequenceIndex = (1 << ThreadSequenceBits) - 1,
 705      EnergyLevelBits = 5,
 706      DamageLevelBits = 6,
 707      DamageStateBits = 2,
 708      // The thread and image limits should not be changed without
 709      // also changing the ShapeBaseMasks enum values declared
 710      // further down.
 711      MaxSoundThreads =  4,            ///< Should be a power of 2
 712      MaxScriptThreads = 4,            ///< Should be a power of 2
 713      MaxMountedImages = 4,            ///< Should be a power of 2
 714      MaxImageEmitters = 3,
 715      NumImageBits = 3,
 716      CollisionTimeoutValue = 250      ///< Timeout in ms.
 717   };
 718
 719   /// This enum indexes into the sDamageStateName array
 720   enum DamageState {
 721      Enabled,
 722      Disabled,
 723      Destroyed,
 724      NumDamageStates,
 725      NumDamageStateBits = 2,   ///< Should be log2 of the number of states.
 726   };
 727
 728protected:
 729   ShapeBaseData*    mDataBlock;                ///< Datablock
 730   bool              mIsAiControlled;           ///< Is this object AI controlled?
 731   //GameConnection*   mControllingClient;        ///< Controlling client
 732   ShapeBase*        mControllingObject;        ///< Controlling object
 733   bool              mTrigger[MaxTriggerKeys];  ///< What triggers are set, if any.
 734
 735
 736   /// @name Scripted Sound
 737   /// @{
 738   struct Sound {
 739      bool play;                    ///< Are we playing this sound?
 740      SimTime timeout;              ///< Time until we stop playing this sound.
 741      SFXTrack* profile;            ///< Profile on server
 742      SFXSource* sound;             ///< Sound on client
 743   };
 744   Sound mSoundThread[MaxSoundThreads];
 745   /// @}
 746
 747   /// @name Scripted Animation Threads
 748   /// @{
 749
 750   struct Thread {
 751      /// State of the animation thread.
 752      enum State {
 753         Play, Stop, Pause, Destroy
 754      };
 755      TSThread* thread; ///< Pointer to 3space data.
 756      State state;      ///< State of the thread
 757      S32 sequence;     ///< The animation sequence which is running in this thread.
 758      F32 timescale;    ///< Timescale
 759      bool atEnd;       ///< Are we at the end of this thread?
 760      F32 position;
 761   };
 762   Thread mScriptThread[MaxScriptThreads];
 763
 764   /// @}
 765
 766   /// @name Motion
 767   /// @{
 768   bool mMoveMotion;    ///< Indicates that a Move has come in requesting x, y or z motion
 769   /// @}
 770
 771protected:
 772
 773   // ShapeBase pointer to our mount object if it is ShapeBase, else it is NULL.
 774   ShapeBase *mShapeBaseMount;
 775
 776   /// @name Mounted Images
 777   /// @{
 778
 779   /// An image mounted on a shapebase.
 780   struct MountedImage {
 781      ShapeBaseImageData* dataBlock;
 782      ShapeBaseImageData::StateData *state;
 783      ShapeBaseImageData* nextImage;
 784      NetStringHandle skinNameHandle;
 785      NetStringHandle nextSkinNameHandle;
 786      String appliedSkinName;
 787      NetStringHandle scriptAnimPrefix;      ///< The script based anim prefix
 788
 789      /// @name State
 790      ///
 791      /// Variables tracking the state machine
 792      /// representing this specific mounted image.
 793      /// @{
 794
 795      bool loaded;                  ///< Is the image loaded?
 796      bool nextLoaded;              ///< Is the next state going to result in the image being loaded?
 797      F32 delayTime;                ///< Time till next state.
 798      F32 rDT;                      ///< Remainder delta time. Used internally.
 799      U32 fireCount;                ///< Fire skip count.
 800                                    ///
 801                                    /// This is incremented every time the triggerDown bit is changed,
 802                                    /// so that the engine won't be too confused if the player toggles the
 803                                    /// trigger a bunch of times in a short period.
 804                                    ///
 805                                    /// @note The network deals with this variable at 3-bit precision, so it
 806                                    /// can only range 0-7.
 807                                    ///
 808                                    /// @see ShapeBase::setImageState()
 809      U32 altFireCount;             ///< Alternate fire skip count.
 810                                    ///< @see fireCount
 811
 812      U32 reloadCount;              ///< Reload skip count.
 813                                    ///< @see fireCount
 814
 815      bool triggerDown;             ///< Is the trigger down?
 816      bool altTriggerDown;          ///< Is the second trigger down?
 817
 818      bool ammo;                    ///< Do we have ammo?
 819                                    ///
 820                                    /// May be true based on either energy OR ammo.
 821
 822      bool target;                  ///< Have we acquired a targer?
 823      bool wet;                     ///< Is the weapon wet?
 824
 825      bool motion;                  ///< Is the player in motion?
 826
 827      bool genericTrigger[ShapeBaseImageData::MaxGenericTriggers];   ///< Generic triggers not assigned to anything in particular.  These
 828                                                                     ///  may be used to indicate some transition should occur.
 829      /// @}
 830
 831      /// @name 3space
 832      ///
 833      /// Handles to threads and shapeinstances in the 3space system.
 834      /// @{
 835      TSShapeInstance* shapeInstance[ShapeBaseImageData::MaxShapes];
 836      TSThread *ambientThread[ShapeBaseImageData::MaxShapes];
 837      TSThread *visThread[ShapeBaseImageData::MaxShapes];
 838      TSThread *animThread[ShapeBaseImageData::MaxShapes];
 839      TSThread *flashThread[ShapeBaseImageData::MaxShapes];
 840      TSThread *spinThread[ShapeBaseImageData::MaxShapes];
 841
 842      bool doAnimateAllShapes;      ///< Should all threads animate across all shapes to keep them in sync?
 843      bool forceAnimateAllShapes;   ///< If the mounted image's owner is being controlled by the client
 844                                    ///  and the image's datablock animateAllShapes field is true
 845                                    ///  then set this to true and pass along to the client.  This will help
 846                                    ///  in the cases where the client's control object is ghosted but does
 847                                    ///  not yet have its controlling client set correctly due to networking
 848                                    ///  order of operations.  All this for the MountedImage::updateDoAnimateAllShapes()
 849                                    ///  optimization.
 850      U32 lastShapeIndex;           ///< Tracks the last shape index.
 851      /// @}
 852
 853      /// @name Effects
 854      ///
 855      /// Variables relating to lights, sounds, and particles.
 856      /// @{
 857      SimTime lightStart;     ///< Starting time for light flashes.
 858      LightInfo* lightInfo;   ///< The real light (if any) associated with this weapon image.
 859
 860      Vector<SFXSource*> mSoundSources; ///< Vector of currently playing sounds
 861      void updateSoundSources(const MatrixF& renderTransform);  
 862      void addSoundSource(SFXSource* source);
 863
 864      /// Represent the state of a specific particle emitter on the image.
 865      struct ImageEmitter {
 866         S32 node;
 867         F32 time;
 868         SimObjectPtr<ParticleEmitter> emitter;
 869      };
 870      ImageEmitter emitter[MaxImageEmitters];
 871
 872      /// @}
 873
 874      //
 875      MountedImage();
 876      ~MountedImage();
 877
 878      void updateDoAnimateAllShapes(const ShapeBase* owner);
 879   };
 880   MountedImage mMountedImageList[MaxMountedImages];
 881
 882   /// @}
 883
 884   /// @name Render settings
 885   /// @{
 886
 887   TSShapeInstance*  mShapeInstance;
 888   Convex *          mConvexList;
 889   NetStringHandle   mSkinNameHandle;
 890   String            mAppliedSkinName;
 891
 892   NetStringHandle mShapeNameHandle;   ///< Name sent to client
 893   /// @}
 894
 895   /// @name Physical Properties
 896   /// @{
 897
 898   S32 mAiPose;                     ///< Current pose.
 899   F32 mEnergy;                     ///< Current enery level.
 900   F32 mRechargeRate;               ///< Energy recharge rate (in units/tick).
 901
 902   F32 mMass;                       ///< Mass.
 903   F32 mOneOverMass;                ///< Inverse of mass.
 904                                    /// @note This is used to optimize certain physics calculations.
 905
 906   /// @}
 907
 908   /// @name Physical Properties
 909   ///
 910   /// Properties for the current object, which are calculated
 911   /// based on the container we are in.
 912   ///
 913   /// @see ShapeBase::updateContainer()
 914   /// @see ShapeBase::mContainer
 915   /// @{
 916   F32 mDrag;                       ///< Drag.
 917   F32 mBuoyancy;                   ///< Buoyancy factor.
 918   String mLiquidType;              ///< Type of liquid (if any) we are in.
 919   F32 mLiquidHeight;               ///< Height of liquid around us (from 0..1).
 920   F32 mWaterCoverage;              ///< Percent of this object covered by water
 921
 922   Point3F mAppliedForce;
 923   F32 mNetGravity;
 924   /// @}
 925
 926   F32 mDamageFlash;
 927   F32 mWhiteOut;
 928
 929   bool mFlipFadeVal;
 930
 931 public:
 932
 933   /// @name Collision Notification
 934   /// This is used to keep us from spamming collision notifications. When
 935   /// a collision occurs, we add to this list; then we don't notify anyone
 936   /// of the collision until the CollisionTimeout expires (which by default
 937   /// occurs in 1/10 of a second).
 938   ///
 939   /// @see notifyCollision(), queueCollision()
 940   /// @{
 941   struct CollisionTimeout 
 942   {
 943      CollisionTimeout* next;
 944      SceneObject* object;
 945      U32 objectNumber;
 946      SimTime expireTime;
 947      VectorF vector;
 948   };
 949   CollisionTimeout* mTimeoutList;
 950   static CollisionTimeout* sFreeTimeoutList;
 951
 952   /// Go through all the items in the collision queue and call onCollision on them all
 953   /// @see onCollision
 954   void notifyCollision();
 955
 956   /// Add a collision to the queue of collisions waiting to be handled @see onCollision
 957   /// @param   object   Object collision occurs with
 958   /// @param   vec      Vector along which collision occurs
 959   void queueCollision( SceneObject *object, const VectorF &vec);
 960
 961   /// @see SceneObject
 962   virtual void onCollision( SceneObject *object, const VectorF &vec );
 963
 964   /// @}
 965 protected:
 966
 967   /// @name Damage
 968   /// @{
 969   F32  mDamage;
 970   F32  mRepairRate;
 971   F32  mRepairReserve;
 972   DamageState mDamageState;
 973   TSThread *mDamageThread;
 974   TSThread *mHulkThread;
 975   VectorF damageDir;
 976   /// @}
 977
 978   /// @name Cloaking
 979   /// @{
 980   bool mCloaked;
 981   F32  mCloakLevel;
 982//   TextureHandle mCloakTexture;
 983   /// @}
 984
 985   /// @name Fading
 986   /// @{
 987   bool  mFadeOut;
 988   bool  mFading;
 989   F32   mFadeVal;
 990   F32   mFadeElapsedTime;
 991   F32   mFadeTime;
 992   F32   mFadeDelay;
 993public:
 994   F32   getFadeVal() { return mFadeVal; }
 995   /// @}
 996protected:
 997
 998   /// @name Control info
 999   /// @{
1000   F32  mCameraFov;           ///< The camera vertical FOV in degrees.
1001   bool mIsControlled;        ///< Client side controlled flag
1002
1003   /// @}
1004public:
1005   static U32 sLastRenderFrame;
1006
1007protected:
1008
1009   U32 mLastRenderFrame;
1010   F32 mLastRenderDistance;
1011
1012   /// Do a reskin if necessary.
1013   virtual void reSkin();
1014
1015   /// This recalculates the total mass of the object, and all mounted objects
1016   void updateMass();
1017
1018   /// @name Image Manipulation
1019   /// @{
1020
1021   /// Utility function to call script functions which have to do with ShapeBase
1022   /// objects.
1023   /// @param   imageSlot  Image Slot id
1024   /// @param   function   Function
1025   void scriptCallback(U32 imageSlot,const char* function);
1026
1027   /// Assign a ShapeBaseImage to an image slot
1028   /// @param   imageSlot   Image Slot ID
1029   /// @param   imageData   ShapeBaseImageData to assign
1030   /// @param   skinNameHandle Skin texture name
1031   /// @param   loaded      Is the image loaded?
1032   /// @param   ammo        Does the image have ammo?
1033   /// @param   triggerDown Is the trigger on this image down?
1034   /// @param   altTriggerDown Is the second trigger on this image down?
1035   /// @param   target      Does the image have a target?
1036   virtual void setImage(  U32 imageSlot, 
1037                           ShapeBaseImageData* imageData, 
1038                           NetStringHandle &skinNameHandle,
1039                           bool loaded = true, bool ammo = false, 
1040                           bool triggerDown = false,
1041                           bool altTriggerDown = false,
1042                           bool motion = false,
1043                           bool genericTrigger0 = false,
1044                           bool genericTrigger1 = false,
1045                           bool genericTrigger2 = false,
1046                           bool genericTrigger3 = false,
1047                           bool target = false );
1048
1049   /// Clear out an image slot
1050   /// @param   imageSlot   Image slot id
1051   void resetImageSlot(U32 imageSlot);
1052
1053   /// Get the firing action state of the image
1054   /// @param   imageSlot   Image slot id
1055   U32  getImageFireState(U32 imageSlot);
1056
1057   /// Get the alternate firing action state of the image
1058   /// @param   imageSlot   Image slot id
1059   U32  getImageAltFireState(U32 imageSlot);
1060
1061   /// Get the reload action state of the image
1062   /// @param   imageSlot   Image slot id
1063   U32  getImageReloadState(U32 imageSlot);
1064
1065   /// Sets the state of the image by state index
1066   /// @param   imageSlot   Image slot id
1067   /// @param   state       State id
1068   /// @param   force       Force image to state or let it finish then change
1069   void setImageState(U32 imageSlot, U32 state, bool force = false);
1070
1071   void updateAnimThread(U32 imageSlot, S32 imageShapeIndex, ShapeBaseImageData::StateData* lastState=<a href="/coding/file/types_8lint_8h/#types_8lint_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
1072
1073   /// Get the animation prefix for the image
1074   /// @param   imageSlot        Image slot id
1075   /// @param   imageShapeIndex  Shape index (1st person, etc.) used to look up the prefix text
1076   virtual const char* getImageAnimPrefix(U32 imageSlot, S32 imageShapeIndex) { return ""; }
1077
1078   /// Advance animation on a image
1079   /// @param   imageSlot   Image slot id
1080   /// @param   dt          Change in time since last animation update
1081   void updateImageAnimation(U32 imageSlot, F32 dt);
1082
1083   /// Advance state of image
1084   /// @param   imageSlot   Image slot id
1085   /// @param   dt          Change in time since last state update
1086   void updateImageState(U32 imageSlot,F32 dt);
1087
1088   /// Start up the particle emitter for the this shapebase
1089   /// @param   image   Mounted image
1090   /// @param   state   State of shape base image
1091   void startImageEmitter(MountedImage &image,ShapeBaseImageData::StateData &state);
1092
1093   /// Get light information for a mounted image
1094   /// @param   imageSlot   Image slot id
1095   Light* getImageLight(U32 imageSlot);
1096
1097   /// Get the shape index to use for a mounted image
1098   /// @param   image   Mounted image
1099   U32 getImageShapeIndex(const MountedImage& image) const;
1100
1101   /// @}
1102
1103   /// Prune out non looping sounds from the sound manager which have expired
1104   void updateServerAudio();
1105
1106   /// Updates the audio state of the supplied sound
1107   /// @param   st   Sound
1108   void updateAudioState(Sound& st);
1109
1110   /// Recalculates the spacial sound based on the current position of the object
1111   /// emitting the sound.
1112   void updateAudioPos();
1113
1114   /// Update bouyency and drag properties
1115   void updateContainer();
1116
1117   /// @name Events
1118   /// @{
1119   virtual void onDeleteNotify(SimObject*);
1120   virtual void onImage(U32 imageSlot, bool unmount);
1121   virtual void onImageRecoil(U32 imageSlot,ShapeBaseImageData::StateData::RecoilState);
1122   virtual void onImageStateAnimation(U32 imageSlot, const char* seqName, bool direction, bool scaleToState, F32 stateTimeOutValue);
1123   virtual void onImageAnimThreadChange(U32 imageSlot, S32 imageShapeIndex, ShapeBaseImageData::StateData* lastState, const char* anim, F32 pos, F32 timeScale, bool reset=false);
1124   virtual void onImageAnimThreadUpdate(U32 imageSlot, S32 imageShapeIndex, F32 dt);
1125   virtual void ejectShellCasing( U32 imageSlot );
1126   virtual void shakeCamera( U32 imageSlot );
1127   virtual void updateDamageLevel();
1128   virtual void updateDamageState();
1129   virtual void onImpact(SceneObject* obj, const VectorF& vec);
1130   virtual void onImpact(const VectorF& vec);
1131   /// @}
1132
1133   /// The inner prep render function that does the 
1134   /// standard work to render the shapes.
1135   void _prepRenderImage(  SceneRenderState* state, 
1136                           bool renderSelf, 
1137                           bool renderMountedImages );
1138
1139   /// Renders the shape bounds as well as the 
1140   /// bounds of all mounted shape images.
1141   void _renderBoundingBox( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance* );
1142
1143   void emitDust( ParticleEmitter* emitter, F32 triggerHeight, const Point3F& offset, U32 numMilliseconds, const Point3F& axis = Point3F::Zero );
1144
1145public:
1146   ShapeBase();
1147   ~ShapeBase();
1148
1149   TSShapeInstance* getShapeInstance() { return mShapeInstance; }
1150
1151   static void initPersistFields();
1152   static bool _setFieldSkin( void *object, const char *index, const char *data );
1153   static const char *_getFieldSkin( void *object, const char *data );
1154
1155   /// @name Network state masks
1156   /// @{
1157
1158   ///
1159   enum ShapeBaseMasks {
1160      NameMask        = Parent::NextFreeMask,
1161      DamageMask      = Parent::NextFreeMask << 1,
1162      NoWarpMask      = Parent::NextFreeMask << 2,
1163      CloakMask       = Parent::NextFreeMask << 3,
1164      SkinMask        = Parent::NextFreeMask << 4,
1165      MeshHiddenMask  = Parent::NextFreeMask << 5,
1166      SoundMaskN      = Parent::NextFreeMask << 6,       ///< Extends + MaxSoundThreads bits
1167      ThreadMaskN     = SoundMaskN  << MaxSoundThreads,  ///< Extends + MaxScriptThreads bits
1168      ImageMaskN      = ThreadMaskN << MaxScriptThreads, ///< Extends + MaxMountedImage bits
1169      NextFreeMask    = ImageMaskN  << MaxMountedImages
1170   };
1171
1172   enum BaseMaskConstants {
1173      SoundMask      = (SoundMaskN << MaxSoundThreads) - SoundMaskN,
1174      ThreadMask     = (ThreadMaskN << MaxScriptThreads) - ThreadMaskN,
1175      ImageMask      = (ImageMaskN << MaxMountedImages) - ImageMaskN
1176   };
1177
1178   /// @}
1179
1180   static F32  sWhiteoutDec;
1181   static F32  sDamageFlashDec;
1182   static F32  sFullCorrectionDistance;
1183   static F32  sCloakSpeed;               // Time to cloak, in seconds
1184      
1185   CubeReflector mCubeReflector;
1186
1187   /// @name Initialization
1188   /// @{
1189
1190   bool onAdd();
1191   void onRemove();
1192   void onSceneRemove();
1193   static void consoleInit();
1194   bool onNewDataBlock( GameBaseData *dptr, bool reload );
1195
1196   /// @}
1197
1198   /// @name Name & Skin tags
1199   /// @{
1200   void setShapeName(const char*);
1201   const char* getShapeName();
1202   void setSkinName(const char*);
1203   const char* getSkinName();
1204   /// @}
1205
1206   /// @name Mesh Visibility
1207   /// @{
1208   
1209protected:
1210
1211   /// A bit vector of the meshes forced to be hidden.
1212   BitVector mMeshHidden;
1213
1214   /// Sync the shape instance with the hidden mesh bit vector.
1215   void _updateHiddenMeshes();               
1216
1217public:
1218
1219   /// Change the hidden state on all the meshes.
1220   void setAllMeshesHidden( bool forceHidden );  
1221
1222   /// Set the force hidden state on a mesh.
1223   void setMeshHidden( S32 meshIndex, bool forceHidden ); 
1224                        
1225   /// Set the force hidden state on a named mesh.
1226   void setMeshHidden( const char *meshName, bool forceHidden ); 
1227   
1228#ifndef TORQUE_SHIPPING
1229
1230   /// Prints the list of meshes and their visibility state
1231   /// to the console for debugging purposes.
1232   void dumpMeshVisibility();
1233                      
1234#endif   
1235
1236   /// @}
1237
1238public:
1239
1240   /// @name Basic attributes
1241   /// @{
1242
1243   /// Sets the amount of damage on this object.
1244   void setDamageLevel(F32 damage);
1245
1246   /// Changes the object's damage state.
1247   /// @param   state   New state of the object
1248   void setDamageState(DamageState state);
1249
1250   /// Changes the object's damage state, based on a named state.
1251   /// @see setDamageState
1252   /// @param   state   New state of the object as a string.
1253   bool setDamageState(const char* state);
1254
1255   /// Returns the name of the current damage state as a string.
1256   const char* getDamageStateName();
1257
1258   /// Returns the current damage state.
1259   DamageState getDamageState() { return mDamageState; }
1260
1261   /// Returns true if the object is destroyed.
1262   bool isDestroyed() { return mDamageState == Destroyed; }
1263
1264   /// Sets the rate at which the object regenerates damage.
1265   ///
1266   /// @param  rate  Repair rate in units/second.
1267   void setRepairRate(F32 rate) { mRepairRate = rate; }
1268
1269   /// Returns damage amount.
1270   F32  getDamageLevel()  { return mDamage; }
1271
1272   /// Returns the damage percentage.
1273   ///
1274   /// @return Damage factor, between 0.0 - 1.0
1275   F32  getDamageValue();
1276 
1277   /// Returns the datablock.maxDamage value  
1278   F32 getMaxDamage(); 
1279
1280   /// Returns the rate at which the object regenerates damage
1281   F32  getRepairRate() { return mRepairRate; }
1282
1283   /// Adds damage to an object
1284   /// @param   amount   Amount of of damage to add
1285   void applyDamage(F32 amount);
1286
1287   /// Removes damage to an object
1288   /// @param   amount   Amount to repair object by
1289   void applyRepair(F32 amount);
1290
1291   /// Sets the direction from which the damage is coming
1292   /// @param   vec   Vector indicating the direction of the damage
1293   void setDamageDir(const VectorF& vec)  { damageDir = vec; }
1294
1295   /// Sets the level of energy for this object
1296   /// @param   energy   Level of energy to assign to this object
1297   virtual void setEnergyLevel(F32 energy);
1298
1299   /// Sets the rate at which the energy replentishes itself
1300   /// @param   rate   Rate at which energy restores
1301   void setRechargeRate(F32 rate) { mRechargeRate = rate; }
1302
1303   /// Returns the amount of energy in the object
1304   F32  getEnergyLevel();
1305
1306   /// Returns the percentage of energy, 0.0 - 1.0
1307   F32  getEnergyValue();
1308
1309   /// Returns the recharge rate
1310   F32  getRechargeRate() { return mRechargeRate; }
1311
1312   /// Makes the shape explode.
1313   virtual void blowUp();
1314
1315   /// @}
1316
1317   /// @name Script sounds
1318   /// @{
1319
1320   /// Plays an audio sound from a mounted object
1321   /// @param   slot    Mount slot ID
1322   /// @param   track   Audio track to play
1323   void playAudio(U32 slot,SFXTrack* track);
1324   void playAudio( U32 slot, SFXProfile* profile ) { playAudio( slot, ( SFXTrack* ) profile ); }
1325
1326   /// Stops audio from a mounted object
1327   /// @param   slot   Mount slot ID
1328   void stopAudio(U32 slot);
1329   /// @}
1330
1331   /// @name Script animation
1332   /// @{
1333
1334   const char *getThreadSequenceName( U32 slot );
1335
1336   /// Sets the animation thread for a mounted object
1337   /// @param   slot   Mount slot ID
1338   /// @param    seq   Sequence id
1339   /// @param   reset   Reset the sequence
1340   bool setThreadSequence(U32 slot, S32 seq, bool reset = true);
1341
1342   /// Update the animation thread
1343   /// @param   st   Thread to update
1344   void updateThread(Thread& st);
1345
1346   /// Stop the current thread from playing on a mounted object
1347   /// @param   slot   Mount slot ID
1348   bool stopThread(U32 slot);
1349
1350   /// Destroys the given animation thread
1351   /// @param   slot   Mount slot ID
1352   bool destroyThread(U32 slot);
1353
1354   /// Pause the running animation thread
1355   /// @param   slot   Mount slot ID
1356   bool pauseThread(U32 slot);
1357
1358   /// Start playing the running animation thread again
1359   /// @param   slot   Mount slot ID
1360   bool playThread(U32 slot);
1361
1362   /// Set the thread position
1363   /// @param   slot   Mount slot ID
1364   /// @param   pos    Position
1365   bool setThreadPosition( U32 slot, F32 pos );
1366
1367   /// Toggle the thread as reversed or normal (For example, sidestep-right reversed is sidestep-left)
1368   /// @param   slot   Mount slot ID
1369   /// @param   forward   True if the animation is to be played normally
1370   bool setThreadDir(U32 slot,bool forward);
1371
1372   /// Set the thread time scale
1373   /// @param   slot   Mount slot ID
1374   /// @param   timescale   Timescale
1375   bool setThreadTimeScale( U32 slot, F32 timeScale );
1376
1377   /// Advance all animation threads attached to this shapebase
1378   /// @param   dt   Change in time from last call to this function
1379   void advanceThreads(F32 dt);
1380   /// @}
1381
1382   /// @name Cloaking
1383   /// @{
1384
1385   /// Force uncloaking of object
1386   /// @param   reason   Reason this is being forced to uncloak, this is passed directly to script control
1387   void forceUncloak(const char *reason);
1388
1389   /// Set cloaked state of object
1390   /// @param   cloaked   True if object is cloaked
1391   void setCloakedState(bool cloaked);
1392
1393   /// Returns true if object is cloaked
1394   bool getCloakedState();
1395
1396   /// Returns level of cloaking, as it's not an instant "now you see it, now you don't"
1397   F32 getCloakLevel();
1398   /// @}
1399
1400   /// @name Mounted objects
1401   /// @{   
1402   virtual void onMount( SceneObject *obj, S32 node );   
1403   virtual void onUnmount( SceneObject *obj,S32 node );   
1404   virtual void getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat );
1405   virtual void getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat );
1406   /// @}
1407
1408   /// Returns where the AI should be to repair this object
1409   ///
1410   /// @note Legacy code from Tribes 2, but still works
1411   Point3F getAIRepairPoint();
1412
1413   /// @name Mounted Images
1414   /// @{
1415
1416   /// Mount an image (ShapeBaseImage) onto an image slot
1417   /// @param   image   ShapeBaseImage to mount
1418   /// @param   imageSlot Image mount point
1419   /// @param   loaded    True if weapon is loaded (it assumes it's a weapon)
1420   /// @param   skinNameHandle   Skin name for object
1421   virtual bool mountImage(ShapeBaseImageData* image,U32 imageSlot,bool loaded, NetStringHandle &skinNameHandle);
1422
1423   /// Unmount an image from a slot
1424   /// @param   imageSlot   Mount point
1425   virtual bool unmountImage(U32 imageSlot);
1426
1427   /// Gets the information on the image mounted in a slot
1428   /// @param   imageSlot   Mount point
1429   ShapeBaseImageData* getMountedImage(U32 imageSlot);
1430
1431   /// Gets the mounted image on on a slot
1432   /// @param   imageSlot   Mount Point
1433   MountedImage* getImageStruct(U32 imageSlot);
1434
1435   TSShapeInstance* getImageShapeInstance(U32 imageSlot)
1436   {
1437      const MountedImage &image = mMountedImageList[imageSlot];
1438      U32 imageShapeIndex = getImageShapeIndex(image);
1439      if(image.dataBlock && image.shapeInstance[imageShapeIndex])
1440         return image.shapeInstance[imageShapeIndex];
1441      return NULL;
1442   }
1443
1444   /// Gets the next image which will be put in an image slot
1445   /// @see setImageState
1446   /// @param   imageSlot   mount Point
1447   ShapeBaseImageData* getPendingImage(U32 imageSlot);
1448
1449
1450   /// Returns true if the mounted image is firing
1451   /// @param   imageSlot   Mountpoint
1452   bool isImageFiring(U32 imageSlot);
1453
1454   /// Returns true if the mounted image is alternate firing
1455   /// @param   imageSlot   Mountpoint
1456   bool isImageAltFiring(U32 imageSlot);
1457
1458   /// Returns true if the mounted image is reloading
1459   /// @param   imageSlot   Mountpoint
1460   bool isImageReloading(U32 imageSlot);
1461
1462   /// This will return true if, when triggered, the object will fire.
1463   /// @param   imageSlot   mount point
1464   /// @param   ns          Used internally for recursion, do not mess with
1465   /// @param   depth       Used internally for recursion, do not mess with
1466   bool isImageReady(U32 imageSlot,U32 ns = (U32)-1,U32 depth = 0);
1467
1468   /// Returns true if the specified image is mounted
1469   /// @param   image   ShapeBase image
1470   bool isImageMounted(ShapeBaseImageData* image);
1471
1472   /// Returns the slot which the image specified is mounted on
1473   /// @param   image   Image to test for
1474   S32 getMountSlot(ShapeBaseImageData* image);
1475
1476   /// Returns the skin for the image in a slot
1477   /// @param   imageSlot   Image slot to get the skin from
1478   NetStringHandle getImageSkinTag(U32 imageSlot);
1479
1480   /// Check if the given state exists on the mounted Image
1481   /// @param   imageSlot   Image slot id
1482   /// @param   state       Image state to check for
1483   bool hasImageState(U32 imageSlot, const char* state);
1484
1485   /// Returns the image state as a string
1486   /// @param   imageSlot   Image slot to check state
1487   const char* getImageState(U32 imageSlot);
1488
1489   /// Sets the generic trigger state of the image
1490   /// @param   imageSlot   Image slot
1491   /// @param   trigger     Generic trigger number 0-3
1492   /// @param   state       True if generic trigger is down
1493   void setImageGenericTriggerState(U32 imageSlot, U32 trigger, bool state);
1494
1495   /// Returns the generic trigger state of the image
1496   /// @param   imageSlot   Image slot
1497   /// @param   trigger     Generic trigger number 0-3
1498   bool getImageGenericTriggerState(U32 imageSlot, U32 trigger);
1499
1500   /// Sets the trigger state of the image (Ie trigger pulled down on gun)
1501   /// @param   imageSlot   Image slot
1502   /// @param   trigger     True if trigger is down
1503   void setImageTriggerState(U32 imageSlot,bool trigger);
1504
1505   /// Returns the trigger state of the image
1506   /// @param   imageSlot   Image slot
1507   bool getImageTriggerState(U32 imageSlot);
1508
1509   /// Sets the alt trigger state of the image (Ie trigger pulled down on gun)
1510   /// @param   imageSlot   Image slot
1511   /// @param   trigger     True if trigger is down
1512   void setImageAltTriggerState( U32 imageSlot, bool trigger );
1513
1514   /// Returns the alt trigger state of the image
1515   /// @param   imageSlot   Image slot
1516   bool getImageAltTriggerState( U32 imageSlot );
1517
1518   /// Sets the flag if the image uses ammo or energy
1519   /// @param   imageSlot   Image slot
1520   /// @param   ammo        True if the weapon uses ammo, not energy
1521   void setImageAmmoState(U32 imageSlot,bool ammo);
1522
1523   /// Returns true if the image uses ammo, not energy
1524   /// @param   imageSlot   Image slot
1525   bool getImageAmmoState(U32 imageSlot);
1526
1527   /// Sets the image as wet or not, IE if you wanted a gun not to function underwater
1528   /// @param   imageSlot   Image slot
1529   /// @param   wet         True if image is wet
1530   void setImageWetState(U32 imageSlot,bool wet);
1531
1532   /// Returns true if image is wet
1533   /// @param   imageSlot   image slot
1534   bool getImageWetState(U32 imageSlot);
1535
1536   /// Sets the image as in motion or not, IE if you wanted a gun not to sway while the player is in motion
1537   /// @param   imageSlot   Image slot
1538   /// @param   motion     True if image is in motion
1539   void setImageMotionState(U32 imageSlot,bool motion);
1540
1541   /// Returns true if image is in motion
1542   /// @param   imageSlot   image slot
1543   bool getImageMotionState(U32 imageSlot);
1544
1545   /// Sets the flag if the image has a target
1546   /// @param   imageSlot   Image slot
1547   /// @param   ammo        True if the weapon has a target
1548   void setImageTargetState(U32 imageSlot,bool ammo);
1549
1550   /// Returns true if the image has a target
1551   /// @param   imageSlot   Image slot
1552   bool getImageTargetState(U32 imageSlot);
1553
1554   /// Sets the flag of if the image is loaded with ammo
1555   /// @param   imageSlot   Image slot
1556   /// @param   loaded      True if object is loaded with ammo
1557   void setImageLoadedState(U32 imageSlot,bool loaded);
1558
1559   /// Returns true if object is loaded with ammo
1560   /// @param   imageSlot   Image slot
1561   bool getImageLoadedState(U32 imageSlot);
1562
1563   /// Set the script animation prefix for the image
1564   /// @param   imageSlot        Image slot id
1565   /// @param   prefix           The prefix applied to the image
1566   void setImageScriptAnimPrefix(U32 imageSlot, NetStringHandle prefix);
1567
1568   /// Get the script animation prefix for the image
1569   /// @param   imageSlot        Image slot id
1570   /// @param   imageShapeIndex  Shape index (1st person, etc.) used to look up the prefix text
1571   NetStringHandle getImageScriptAnimPrefix(U32 imageSlot);
1572
1573   /// Modify muzzle, if needed, to aim at whatever is straight in front of eye.
1574   /// Returns true if result is actually modified.
1575   /// @param   muzMat   Muzzle transform (in/out)
1576   /// @param   result   Corrected muzzle vector (out)
1577   bool getCorrectedAim(const MatrixF& muzMat, VectorF* result);
1578
1579   /// Gets the muzzle vector of a specified slot
1580   /// @param   imageSlot   Image slot to check transform for
1581   /// @param   vec   Muzzle vector (out)
1582   virtual void getMuzzleVector(U32 imageSlot,VectorF* vec);
1583
1584   /// Gets the point of the muzzle of the image
1585   /// @param   imageSlot   Image slot
1586   /// @param   pos   Muzzle point (out)
1587   void getMuzzlePoint(U32 imageSlot,Point3F* pos);
1588
1589   /// @}
1590
1591   /// @name Transforms
1592   /// @{
1593
1594   /// Gets the minimum viewing distance, maximum viewing distance, camera offsetand rotation
1595   /// for this object, if the world were to be viewed through its eyes
1596   /// @param   min   Minimum viewing distance
1597   /// @param   max   Maximum viewing distance
1598   /// @param   offset Offset of the camera from the origin in local space
1599   /// @param   rot   Rotation matrix
1600   virtual void getCameraParameters(F32 *min,F32* max,Point3F* offset,MatrixF* rot);
1601
1602   /// Gets the camera to world space transform matrix
1603   /// @todo Find out what pos does
1604   /// @param   pos   TODO: Find out what this does
1605   /// @param   mat   Camera transform (out)
1606   virtual void getCameraTransform(F32* pos,MatrixF* mat);
1607
1608   /// Gets the view transform for a particular eye, taking into account the current absolute 
1609   /// orient and position values of the display device.
1610   virtual void getEyeCameraTransform( IDisplayDevice *display, U32 eyeId, MatrixF *outMat );
1611
1612   /// Gets the index of a node inside a mounted image given the name
1613   /// @param   imageSlot   Image slot
1614   /// @param   nodeName    Node name
1615   S32 getNodeIndex(U32 imageSlot,StringTableEntry nodeName);
1616
1617   /// @}
1618
1619   /// @name Object Transforms
1620   /// @{
1621
1622   /// Returns the eye transform of this shape, IE the eyes of a player
1623   /// @param   mat   Eye transform (out)
1624   virtual void getEyeTransform(MatrixF* mat);
1625
1626   /// Returns the eye transform of this shape without including mounted images, IE the eyes of a player
1627   /// @param   mat   Eye transform (out)
1628   virtual void getEyeBaseTransform(MatrixF* mat, bool includeBank);
1629
1630   /// The retraction transform is the muzzle transform in world space.
1631   ///
1632   /// If the gun is pushed back, for instance, if the player ran against something,
1633   /// the muzzle of the gun gets pushed back towards the player, towards this location.
1634   /// @param   imageSlot   Image slot
1635   /// @param   mat   Transform (out)
1636   virtual void getRetractionTransform(U32 imageSlot,MatrixF* mat);
1637
1638   /// Muzzle transform of mounted object in world space
1639   /// @param   imageSlot   Image slot
1640   /// @param   mat         Muzzle transform (out)
1641   virtual void getMuzzleTransform(U32 imageSlot,MatrixF* mat);
1642
1643   /// Gets the transform of a mounted image in world space
1644   /// @param   imageSlot   Image slot
1645   /// @param   mat    Transform (out)
1646   virtual void getImageTransform(U32 imageSlot,MatrixF* mat);
1647
1648   /// Gets the transform of a node on a mounted image in world space
1649   /// @param   imageSlot   Image Slot
1650   /// @param   node    node on image
1651   /// @param   mat   Transform (out)
1652   virtual void getImageTransform(U32 imageSlot,S32 node, MatrixF* mat);
1653
1654   /// Gets the transform of a node on a mounted image in world space
1655   /// @param   imageSlot   Image Slot
1656   /// @param   nodeName    Name of node on image
1657   /// @param   mat         Transform (out)
1658   virtual void getImageTransform(U32 imageSlot, StringTableEntry nodeName, MatrixF* mat);
1659
1660   ///@}
1661
1662   /// @name Render transforms
1663   /// Render transforms are different from object transforms in that the render transform of an object
1664   /// is where, in world space, the object is actually rendered. The object transform is the
1665   /// absolute position of the object, as in where it should be.
1666   ///
1667   /// The render transforms typically vary from object transforms due to client side prediction.
1668   ///
1669   /// Other than that, these functions are identical to their object-transform counterparts
1670   ///
1671   /// @note These are meaningless on the server.
1672   /// @{
1673   virtual void getRenderRetractionTransform(U32 index,MatrixF* mat);   
1674   virtual void getRenderMuzzleTransform(U32 index,MatrixF* mat);   
1675   virtual void getRenderImageTransform(U32 imageSlot,MatrixF* mat,bool noEyeOffset=false);
1676   virtual void getRenderImageTransform(U32 index,S32 node, MatrixF* mat);
1677   virtual void getRenderImageTransform(U32 index, StringTableEntry nodeName, MatrixF* mat);
1678   virtual void getRenderMuzzleVector(U32 imageSlot,VectorF* vec);
1679   virtual void getRenderMuzzlePoint(U32 imageSlot,Point3F* pos);
1680   virtual void getRenderEyeTransform(MatrixF* mat);
1681   virtual void getRenderEyeBaseTransform(MatrixF* mat, bool includeBank);
1682   /// @}
1683
1684
1685
1686   /// @name Screen Flashing
1687   /// @{
1688
1689   /// Returns the level of screenflash that should be used
1690   virtual F32  getDamageFlash() const;
1691
1692   /// Sets the flash level
1693   /// @param   amt   Level of flash
1694   virtual void setDamageFlash(const F32 amt);
1695
1696   /// White out is the flash-grenade blindness effect
1697   /// This returns the level of flash to create
1698   virtual F32  getWhiteOut() const;
1699
1700   /// Set the level of flash blindness
1701   virtual void setWhiteOut(const F32);
1702   /// @}
1703
1704   /// @name Movement & velocity
1705   /// @{
1706
1707   /// Sets the velocity of this object
1708   /// @param   vel   Velocity vector
1709   virtual void setVelocity(const VectorF& vel);
1710
1711   /// Applies an impulse force to this object
1712   /// @param   pos   Position where impulse came from in world space
1713   /// @param   vec   Velocity vector (Impulse force F = m * v)
1714   virtual void applyImpulse(const Point3F& pos,const VectorF& vec);
1715
1716   /// @}
1717
1718   /// @name Cameras and Control
1719   /// @{
1720
1721   /// Returns the object controlling this object
1722   ShapeBase* getControllingObject()   { return mControllingObject; }
1723
1724   /// Sets the controlling object
1725   /// @param   obj   New controlling object
1726   virtual void setControllingObject(ShapeBase* obj);
1727   
1728   ///
1729   virtual void setControllingClient( GameConnection* connection );
1730
1731   /// Returns the object this is controlling
1732   virtual ShapeBase* getControlObject();
1733
1734   /// sets the object this is controlling
1735   /// @param   obj   New controlled object
1736   virtual void setControlObject(ShapeBase *obj);
1737
1738   /// Returns true if this object is controlling by something
1739   bool isControlled() { return(mIsControlled); }
1740
1741   /// Returns true if this object is being used as a camera in first person
1742   bool isFirstPerson() const;
1743
1744   /// Returns true if the camera uses this objects eye point (defined by modeler)
1745   bool useObjsEyePoint() const;
1746
1747   /// Returns true if this object can only be used as a first person camera
1748   bool onlyFirstPerson() const;
1749
1750   /// Returns the vertical field of view in degrees for 
1751   /// this object if used as a camera.
1752   virtual F32 getCameraFov() { return mCameraFov; }
1753
1754   /// Returns the default vertical field of view in degrees
1755   /// if this object is used as a camera.
1756   virtual F32 getDefaultCameraFov() { return mDataBlock->cameraDefaultFov; }
1757
1758   /// Sets the vertical field of view in degrees for this 
1759   /// object if used as a camera.
1760   /// @param   yfov  The vertical FOV in degrees to test.
1761   virtual void setCameraFov(F32 fov);
1762
1763   /// Returns true if the vertical FOV in degrees is within 
1764   /// allowable parameters of the datablock.
1765   /// @param   yfov  The vertical FOV in degrees to test.
1766   /// @see ShapeBaseData::cameraMinFov
1767   /// @see ShapeBaseData::cameraMaxFov
1768   virtual bool isValidCameraFov(F32 fov);
1769   /// @}
1770
1771
1772   void processTick(const Move *move);
1773   void advanceTime(F32 dt);
1774
1775   /// @name Rendering
1776   /// @{
1777
1778   /// Returns the renderable shape of this object
1779   TSShape const* getShape();
1780
1781   /// @see SceneObject
1782   virtual void prepRenderImage( SceneRenderState* state );
1783
1784   /// Used from ShapeBase::_prepRenderImage() to submit render 
1785   /// instances for the main shape or its mounted elements.
1786   virtual void prepBatchRender( SceneRenderState *state, S32 mountedImageIndex );
1787
1788   /// Preprender logic
1789   virtual void calcClassRenderData() { }
1790
1791   /// Virtualize this so other classes may override it for custom reasons.
1792   virtual void renderMountedImage( U32 imageSlot, TSRenderState &rstate, SceneRenderState *state );
1793   /// @}
1794
1795   /// Control object scoping
1796   void onCameraScopeQuery(NetConnection *cr, CameraScopeQuery *camInfo);
1797
1798   bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
1799   bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo* info);
1800   bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere);
1801   void buildConvex(const Box3F& box, Convex* convex);
1802
1803   /// @name Rendering
1804   /// @{
1805
1806   /// Increments the last rendered frame number
1807   static void incRenderFrame()    { sLastRenderFrame++; }
1808
1809   /// Returns true if the last frame calculated rendered
1810   bool didRenderLastRender() { return mLastRenderFrame == sLastRenderFrame; }
1811
1812   /// Sets the state of this object as hidden or not. If an object is hidden
1813   /// it is removed entirely from collisions, it is not ghosted and is
1814   /// essentially "non existant" as far as simulation is concerned.
1815   /// @param   hidden   True if object is to be hidden
1816   virtual void setHidden(bool hidden);
1817
1818   /// Returns true if this object can be damaged
1819   bool isInvincible();
1820
1821   /// Start fade of object in/out
1822   /// @param   fadeTime Time fade should take
1823   /// @param   fadeDelay Delay before starting fade
1824   /// @param   fadeOut   True if object is fading out, false if fading in.
1825   void startFade( F32 fadeTime, F32 fadeDelay = 0.0, bool fadeOut = true );
1826
1827   /// Traverses mounted objects and registers light sources with the light manager
1828   /// @param   lightManager   Light manager to register with
1829   /// @param   lightingScene  Set to true if the scene is being lit, in which case these lights will not be used
1830   //void registerLights(LightManager * lightManager, bool lightingScene);
1831
1832   // ISceneLight
1833   virtual void submitLights( LightManager *lm, bool staticLighting );
1834   virtual LightInfo* getLight() { return NULL; }
1835
1836   /// @}
1837
1838   /// Returns true if the point specified is in the water
1839   /// @param   point    Point to test in world space
1840   bool pointInWater( Point3F &point );
1841
1842   /// Returns the percentage of this object covered by water
1843   F32 getWaterCoverage()  { return mWaterCoverage; }
1844
1845   /// Returns the height of the liquid on this object
1846   F32 getLiquidHeight()  { return mLiquidHeight; }
1847
1848   virtual WaterObject* getCurrentWaterObject();
1849
1850   void setCurrentWaterObject( WaterObject *obj );
1851   void setTransform(const MatrixF & mat);
1852   virtual F32 getMass() const { return mMass; }
1853
1854   /// @name Network
1855   /// @{
1856
1857   F32 getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips);
1858   U32  packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
1859   void unpackUpdate(NetConnection *conn, BitStream *stream);
1860   void writePacketData(GameConnection *conn, BitStream *stream);
1861   void readPacketData(GameConnection *conn, BitStream *stream);
1862
1863   /// @}
1864
1865   DECLARE_CONOBJECT(ShapeBase);
1866
1867protected:
1868   DECLARE_CALLBACK( F32, validateCameraFov, (F32 fov) );
1869public:
1870   class CollisionEventCallback
1871   {
1872   public:
1873      virtual void collisionNotify(SceneObject* shape0, SceneObject* shape1, const VectorF& vel)=0;
1874   };
1875private:
1876   Vector<CollisionEventCallback*>  collision_callbacks;
1877   void   notifyCollisionCallbacks(SceneObject*, const VectorF& vel);
1878public:
1879   void   registerCollisionCallback(CollisionEventCallback*);
1880   void   unregisterCollisionCallback(CollisionEventCallback*);
1881
1882protected:
1883   enum { 
1884      ANIM_OVERRIDDEN     = BIT(0),
1885      BLOCK_USER_CONTROL  = BIT(1),
1886      IS_DEATH_ANIM       = BIT(2),
1887      BAD_ANIM_ID         = 999999999,
1888      BLENDED_CLIP        = 0x80000000,
1889   };
1890   struct BlendThread
1891   {
1892      TSThread* thread;
1893      U32       tag;
1894   };
1895   Vector<BlendThread> blend_clips;
1896   static U32 unique_anim_tag_counter;
1897   U8 anim_clip_flags;
1898   S32 last_anim_id;
1899   U32 last_anim_tag;
1900   U32 last_anim_lock_tag;
1901   S32 saved_seq_id;
1902   F32 saved_pos;
1903   F32 saved_rate;
1904   U32 playBlendAnimation(S32 seq_id, F32 pos, F32 rate);
1905   void restoreBlendAnimation(U32 tag);
1906public:
1907   U32 playAnimation(const char* name, F32 pos, F32 rate, F32 trans, bool hold, bool wait, bool is_death_anim);
1908   F32 getAnimationDuration(const char* name);
1909
1910   virtual void restoreAnimation(U32 tag);
1911   virtual U32 getAnimationID(const char* name);
1912   virtual U32 playAnimationByID(U32 anim_id, F32 pos, F32 rate, F32 trans, bool hold, bool wait, bool is_death_anim);
1913   virtual F32 getAnimationDurationByID(U32 anim_id);
1914   virtual bool isBlendAnimation(const char* name);
1915   virtual const char* getLastClipName(U32 clip_tag);
1916   virtual void unlockAnimation(U32 tag, bool force=false) { }
1917   virtual U32 lockAnimation() { return 0; }
1918   virtual bool isAnimationLocked() const { return false; }
1919
1920   virtual void setSelectionFlags(U8 flags);
1921};
1922
1923
1924//------------------------------------------------------------------------------
1925// inlines
1926//------------------------------------------------------------------------------
1927
1928inline bool ShapeBase::getCloakedState()
1929{
1930   return(mCloaked);
1931}
1932
1933inline F32 ShapeBase::getCloakLevel()
1934{
1935   return(mCloakLevel);
1936}
1937
1938inline const char* ShapeBase::getShapeName()
1939{
1940   return mShapeNameHandle.getString();
1941}
1942
1943inline const char* ShapeBase::getSkinName()
1944{
1945   return mSkinNameHandle.getString();
1946}
1947
1948inline WaterObject* ShapeBase::getCurrentWaterObject()
1949{
1950   if ( isMounted() && mShapeBaseMount )   
1951      return mShapeBaseMount->getCurrentWaterObject();
1952   
1953   return mCurrentWaterObject;
1954}
1955
1956#endif  // _H_SHAPEBASE_
1957