shapeBase.h 71 KB

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