shapeBase.h 71 KB

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