2
0

shapeBase.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  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. 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, ( ShapeBase* obj, S32 slot, F32 dt ) );
  433. DECLARE_CALLBACK( void, onUnmount, ( ShapeBase* 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. F32 mEnergy; ///< Current enery level.
  747. F32 mRechargeRate; ///< Energy recharge rate (in units/tick).
  748. F32 mMass; ///< Mass.
  749. F32 mOneOverMass; ///< Inverse of mass.
  750. /// @note This is used to optimize certain physics calculations.
  751. /// @}
  752. /// @name Physical Properties
  753. ///
  754. /// Properties for the current object, which are calculated
  755. /// based on the container we are in.
  756. ///
  757. /// @see ShapeBase::updateContainer()
  758. /// @see ShapeBase::mContainer
  759. /// @{
  760. F32 mDrag; ///< Drag.
  761. F32 mBuoyancy; ///< Buoyancy factor.
  762. String mLiquidType; ///< Type of liquid (if any) we are in.
  763. F32 mLiquidHeight; ///< Height of liquid around us (from 0..1).
  764. F32 mWaterCoverage; ///< Percent of this object covered by water
  765. Point3F mAppliedForce;
  766. F32 mGravityMod;
  767. /// @}
  768. F32 mDamageFlash;
  769. F32 mWhiteOut;
  770. bool mFlipFadeVal;
  771. public:
  772. /// @name Collision Notification
  773. /// This is used to keep us from spamming collision notifications. When
  774. /// a collision occurs, we add to this list; then we don't notify anyone
  775. /// of the collision until the CollisionTimeout expires (which by default
  776. /// occurs in 1/10 of a second).
  777. ///
  778. /// @see notifyCollision(), queueCollision()
  779. /// @{
  780. struct CollisionTimeout
  781. {
  782. CollisionTimeout* next;
  783. SceneObject* object;
  784. U32 objectNumber;
  785. SimTime expireTime;
  786. VectorF vector;
  787. };
  788. CollisionTimeout* mTimeoutList;
  789. static CollisionTimeout* sFreeTimeoutList;
  790. /// Go through all the items in the collision queue and call onCollision on them all
  791. /// @see onCollision
  792. void notifyCollision();
  793. /// Add a collision to the queue of collisions waiting to be handled @see onCollision
  794. /// @param object Object collision occurs with
  795. /// @param vec Vector along which collision occurs
  796. void queueCollision( SceneObject *object, const VectorF &vec);
  797. /// @see SceneObject
  798. virtual void onCollision( SceneObject *object, const VectorF &vec );
  799. /// @}
  800. protected:
  801. /// @name Damage
  802. /// @{
  803. F32 mDamage;
  804. F32 mRepairRate;
  805. F32 mRepairReserve;
  806. DamageState mDamageState;
  807. TSThread *mDamageThread;
  808. TSThread *mHulkThread;
  809. VectorF damageDir;
  810. /// @}
  811. /// @name Cloaking
  812. /// @{
  813. bool mCloaked;
  814. F32 mCloakLevel;
  815. // TextureHandle mCloakTexture;
  816. /// @}
  817. /// @name Fading
  818. /// @{
  819. bool mFadeOut;
  820. bool mFading;
  821. F32 mFadeVal;
  822. F32 mFadeElapsedTime;
  823. F32 mFadeTime;
  824. F32 mFadeDelay;
  825. public:
  826. F32 getFadeVal() { return mFadeVal; }
  827. /// @}
  828. protected:
  829. /// @name Control info
  830. /// @{
  831. F32 mCameraFov; ///< The camera vertical FOV in degrees.
  832. bool mIsControlled; ///< Client side controlled flag
  833. /// @}
  834. public:
  835. static U32 sLastRenderFrame;
  836. protected:
  837. U32 mLastRenderFrame;
  838. F32 mLastRenderDistance;
  839. /// Do a reskin if necessary.
  840. virtual void reSkin();
  841. /// This recalculates the total mass of the object, and all mounted objects
  842. void updateMass();
  843. /// @name Image Manipulation
  844. /// @{
  845. /// Utility function to call script functions which have to do with ShapeBase
  846. /// objects.
  847. /// @param imageSlot Image Slot id
  848. /// @param function Function
  849. void scriptCallback(U32 imageSlot,const char* function);
  850. /// Assign a ShapeBaseImage to an image slot
  851. /// @param imageSlot Image Slot ID
  852. /// @param imageData ShapeBaseImageData to assign
  853. /// @param skinNameHandle Skin texture name
  854. /// @param loaded Is the image loaded?
  855. /// @param ammo Does the image have ammo?
  856. /// @param triggerDown Is the trigger on this image down?
  857. /// @param altTriggerDown Is the second trigger on this image down?
  858. /// @param target Does the image have a target?
  859. virtual void setImage( U32 imageSlot,
  860. ShapeBaseImageData* imageData,
  861. NetStringHandle &skinNameHandle,
  862. bool loaded = true, bool ammo = false,
  863. bool triggerDown = false,
  864. bool altTriggerDown = false,
  865. bool motion = false,
  866. bool genericTrigger0 = false,
  867. bool genericTrigger1 = false,
  868. bool genericTrigger2 = false,
  869. bool genericTrigger3 = false,
  870. bool target = false );
  871. /// Clear out an image slot
  872. /// @param imageSlot Image slot id
  873. void resetImageSlot(U32 imageSlot);
  874. /// Get the firing action state of the image
  875. /// @param imageSlot Image slot id
  876. U32 getImageFireState(U32 imageSlot);
  877. /// Get the alternate firing action state of the image
  878. /// @param imageSlot Image slot id
  879. U32 getImageAltFireState(U32 imageSlot);
  880. /// Get the reload action state of the image
  881. /// @param imageSlot Image slot id
  882. U32 getImageReloadState(U32 imageSlot);
  883. /// Sets the state of the image by state index
  884. /// @param imageSlot Image slot id
  885. /// @param state State id
  886. /// @param force Force image to state or let it finish then change
  887. void setImageState(U32 imageSlot, U32 state, bool force = false);
  888. void updateAnimThread(U32 imageSlot, S32 imageShapeIndex, ShapeBaseImageData::StateData* lastState=NULL);
  889. /// Get the animation prefix for the image
  890. /// @param imageSlot Image slot id
  891. /// @param imageShapeIndex Shape index (1st person, etc.) used to look up the prefix text
  892. virtual const char* getImageAnimPrefix(U32 imageSlot, S32 imageShapeIndex) { return ""; }
  893. /// Advance animation on a image
  894. /// @param imageSlot Image slot id
  895. /// @param dt Change in time since last animation update
  896. void updateImageAnimation(U32 imageSlot, F32 dt);
  897. /// Advance state of image
  898. /// @param imageSlot Image slot id
  899. /// @param dt Change in time since last state update
  900. void updateImageState(U32 imageSlot,F32 dt);
  901. /// Start up the particle emitter for the this shapebase
  902. /// @param image Mounted image
  903. /// @param state State of shape base image
  904. void startImageEmitter(MountedImage &image,ShapeBaseImageData::StateData &state);
  905. /// Get light information for a mounted image
  906. /// @param imageSlot Image slot id
  907. Light* getImageLight(U32 imageSlot);
  908. /// Get the shape index to use for a mounted image
  909. /// @param image Mounted image
  910. U32 getImageShapeIndex(const MountedImage& image) const;
  911. /// @}
  912. /// Prune out non looping sounds from the sound manager which have expired
  913. void updateServerAudio();
  914. /// Updates the audio state of the supplied sound
  915. /// @param st Sound
  916. void updateAudioState(Sound& st);
  917. /// Recalculates the spacial sound based on the current position of the object
  918. /// emitting the sound.
  919. void updateAudioPos();
  920. /// Update bouyency and drag properties
  921. void updateContainer();
  922. /// @name Events
  923. /// @{
  924. virtual void onDeleteNotify(SimObject*);
  925. virtual void onImage(U32 imageSlot, bool unmount);
  926. virtual void onImageRecoil(U32 imageSlot,ShapeBaseImageData::StateData::RecoilState);
  927. virtual void onImageStateAnimation(U32 imageSlot, const char* seqName, bool direction, bool scaleToState, F32 stateTimeOutValue);
  928. virtual void onImageAnimThreadChange(U32 imageSlot, S32 imageShapeIndex, ShapeBaseImageData::StateData* lastState, const char* anim, F32 pos, F32 timeScale, bool reset=false);
  929. virtual void onImageAnimThreadUpdate(U32 imageSlot, S32 imageShapeIndex, F32 dt);
  930. virtual void ejectShellCasing( U32 imageSlot );
  931. virtual void shakeCamera( U32 imageSlot );
  932. virtual void updateDamageLevel();
  933. virtual void updateDamageState();
  934. virtual void onImpact(SceneObject* obj, VectorF vec);
  935. virtual void onImpact(VectorF vec);
  936. /// @}
  937. /// The inner prep render function that does the
  938. /// standard work to render the shapes.
  939. void _prepRenderImage( SceneRenderState* state,
  940. bool renderSelf,
  941. bool renderMountedImages );
  942. /// Renders the shape bounds as well as the
  943. /// bounds of all mounted shape images.
  944. void _renderBoundingBox( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance* );
  945. void emitDust( ParticleEmitter* emitter, F32 triggerHeight, const Point3F& offset, U32 numMilliseconds, const Point3F& axis = Point3F::Zero );
  946. public:
  947. ShapeBase();
  948. ~ShapeBase();
  949. TSShapeInstance* getShapeInstance() { return mShapeInstance; }
  950. static void initPersistFields();
  951. static bool _setFieldSkin( void *object, const char *index, const char *data );
  952. static const char *_getFieldSkin( void *object, const char *data );
  953. /// @name Network state masks
  954. /// @{
  955. ///
  956. enum ShapeBaseMasks {
  957. NameMask = Parent::NextFreeMask,
  958. DamageMask = Parent::NextFreeMask << 1,
  959. NoWarpMask = Parent::NextFreeMask << 2,
  960. CloakMask = Parent::NextFreeMask << 3,
  961. SkinMask = Parent::NextFreeMask << 4,
  962. MeshHiddenMask = Parent::NextFreeMask << 5,
  963. SoundMaskN = Parent::NextFreeMask << 6, ///< Extends + MaxSoundThreads bits
  964. ThreadMaskN = SoundMaskN << MaxSoundThreads, ///< Extends + MaxScriptThreads bits
  965. ImageMaskN = ThreadMaskN << MaxScriptThreads, ///< Extends + MaxMountedImage bits
  966. NextFreeMask = ImageMaskN << MaxMountedImages
  967. };
  968. enum BaseMaskConstants {
  969. SoundMask = (SoundMaskN << MaxSoundThreads) - SoundMaskN,
  970. ThreadMask = (ThreadMaskN << MaxScriptThreads) - ThreadMaskN,
  971. ImageMask = (ImageMaskN << MaxMountedImages) - ImageMaskN
  972. };
  973. /// @}
  974. static F32 sWhiteoutDec;
  975. static F32 sDamageFlashDec;
  976. static F32 sFullCorrectionDistance;
  977. static F32 sCloakSpeed; // Time to cloak, in seconds
  978. CubeReflector mCubeReflector;
  979. /// @name Initialization
  980. /// @{
  981. bool onAdd();
  982. void onRemove();
  983. void onSceneRemove();
  984. static void consoleInit();
  985. bool onNewDataBlock( GameBaseData *dptr, bool reload );
  986. /// @}
  987. /// @name Name & Skin tags
  988. /// @{
  989. void setShapeName(const char*);
  990. const char* getShapeName();
  991. void setSkinName(const char*);
  992. const char* getSkinName();
  993. /// @}
  994. /// @name Mesh Visibility
  995. /// @{
  996. protected:
  997. /// A bit vector of the meshes forced to be hidden.
  998. BitVector mMeshHidden;
  999. /// Sync the shape instance with the hidden mesh bit vector.
  1000. void _updateHiddenMeshes();
  1001. public:
  1002. /// Change the hidden state on all the meshes.
  1003. void setAllMeshesHidden( bool forceHidden );
  1004. /// Set the force hidden state on a mesh.
  1005. void setMeshHidden( S32 meshIndex, bool forceHidden );
  1006. /// Set the force hidden state on a named mesh.
  1007. void setMeshHidden( const char *meshName, bool forceHidden );
  1008. #ifndef TORQUE_SHIPPING
  1009. /// Prints the list of meshes and their visibility state
  1010. /// to the console for debugging purposes.
  1011. void dumpMeshVisibility();
  1012. #endif
  1013. /// @}
  1014. public:
  1015. /// @name Basic attributes
  1016. /// @{
  1017. /// Sets the amount of damage on this object.
  1018. void setDamageLevel(F32 damage);
  1019. /// Changes the object's damage state.
  1020. /// @param state New state of the object
  1021. void setDamageState(DamageState state);
  1022. /// Changes the object's damage state, based on a named state.
  1023. /// @see setDamageState
  1024. /// @param state New state of the object as a string.
  1025. bool setDamageState(const char* state);
  1026. /// Returns the name of the current damage state as a string.
  1027. const char* getDamageStateName();
  1028. /// Returns the current damage state.
  1029. DamageState getDamageState() { return mDamageState; }
  1030. /// Returns true if the object is destroyed.
  1031. bool isDestroyed() { return mDamageState == Destroyed; }
  1032. /// Sets the rate at which the object regenerates damage.
  1033. ///
  1034. /// @param rate Repair rate in units/second.
  1035. void setRepairRate(F32 rate) { mRepairRate = rate; }
  1036. /// Returns damage amount.
  1037. F32 getDamageLevel() { return mDamage; }
  1038. /// Returns the damage percentage.
  1039. ///
  1040. /// @return Damage factor, between 0.0 - 1.0
  1041. F32 getDamageValue();
  1042. /// Returns the datablock.maxDamage value
  1043. F32 getMaxDamage();
  1044. /// Returns the rate at which the object regenerates damage
  1045. F32 getRepairRate() { return mRepairRate; }
  1046. /// Adds damage to an object
  1047. /// @param amount Amount of of damage to add
  1048. void applyDamage(F32 amount);
  1049. /// Removes damage to an object
  1050. /// @param amount Amount to repair object by
  1051. void applyRepair(F32 amount);
  1052. /// Sets the direction from which the damage is coming
  1053. /// @param vec Vector indicating the direction of the damage
  1054. void setDamageDir(const VectorF& vec) { damageDir = vec; }
  1055. /// Sets the level of energy for this object
  1056. /// @param energy Level of energy to assign to this object
  1057. virtual void setEnergyLevel(F32 energy);
  1058. /// Sets the rate at which the energy replentishes itself
  1059. /// @param rate Rate at which energy restores
  1060. void setRechargeRate(F32 rate) { mRechargeRate = rate; }
  1061. /// Returns the amount of energy in the object
  1062. F32 getEnergyLevel();
  1063. /// Returns the percentage of energy, 0.0 - 1.0
  1064. F32 getEnergyValue();
  1065. /// Returns the recharge rate
  1066. F32 getRechargeRate() { return mRechargeRate; }
  1067. /// Makes the shape explode.
  1068. virtual void blowUp();
  1069. /// @}
  1070. /// @name Script sounds
  1071. /// @{
  1072. /// Plays an audio sound from a mounted object
  1073. /// @param slot Mount slot ID
  1074. /// @param track Audio track to play
  1075. void playAudio(U32 slot,SFXTrack* track);
  1076. void playAudio( U32 slot, SFXProfile* profile ) { playAudio( slot, ( SFXTrack* ) profile ); }
  1077. /// Stops audio from a mounted object
  1078. /// @param slot Mount slot ID
  1079. void stopAudio(U32 slot);
  1080. /// @}
  1081. /// @name Script animation
  1082. /// @{
  1083. const char *getThreadSequenceName( U32 slot );
  1084. /// Sets the animation thread for a mounted object
  1085. /// @param slot Mount slot ID
  1086. /// @param seq Sequence id
  1087. /// @param reset Reset the sequence
  1088. bool setThreadSequence(U32 slot, S32 seq, bool reset = true);
  1089. /// Update the animation thread
  1090. /// @param st Thread to update
  1091. void updateThread(Thread& st);
  1092. /// Stop the current thread from playing on a mounted object
  1093. /// @param slot Mount slot ID
  1094. bool stopThread(U32 slot);
  1095. /// Destroys the given animation thread
  1096. /// @param slot Mount slot ID
  1097. bool destroyThread(U32 slot);
  1098. /// Pause the running animation thread
  1099. /// @param slot Mount slot ID
  1100. bool pauseThread(U32 slot);
  1101. /// Start playing the running animation thread again
  1102. /// @param slot Mount slot ID
  1103. bool playThread(U32 slot);
  1104. /// Set the thread position
  1105. /// @param slot Mount slot ID
  1106. /// @param pos Position
  1107. bool setThreadPosition( U32 slot, F32 pos );
  1108. /// Toggle the thread as reversed or normal (For example, sidestep-right reversed is sidestep-left)
  1109. /// @param slot Mount slot ID
  1110. /// @param forward True if the animation is to be played normally
  1111. bool setThreadDir(U32 slot,bool forward);
  1112. /// Set the thread time scale
  1113. /// @param slot Mount slot ID
  1114. /// @param timescale Timescale
  1115. bool setThreadTimeScale( U32 slot, F32 timeScale );
  1116. /// Advance all animation threads attached to this shapebase
  1117. /// @param dt Change in time from last call to this function
  1118. void advanceThreads(F32 dt);
  1119. /// @}
  1120. /// @name Cloaking
  1121. /// @{
  1122. /// Force uncloaking of object
  1123. /// @param reason Reason this is being forced to uncloak, this is passed directly to script control
  1124. void forceUncloak(const char *reason);
  1125. /// Set cloaked state of object
  1126. /// @param cloaked True if object is cloaked
  1127. void setCloakedState(bool cloaked);
  1128. /// Returns true if object is cloaked
  1129. bool getCloakedState();
  1130. /// Returns level of cloaking, as it's not an instant "now you see it, now you don't"
  1131. F32 getCloakLevel();
  1132. /// @}
  1133. /// @name Mounted objects
  1134. /// @{
  1135. virtual void onMount( SceneObject *obj, S32 node );
  1136. virtual void onUnmount( SceneObject *obj,S32 node );
  1137. virtual void getMountTransform( S32 index, const MatrixF &xfm, MatrixF *outMat );
  1138. virtual void getRenderMountTransform( F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat );
  1139. /// @}
  1140. /// Returns where the AI should be to repair this object
  1141. ///
  1142. /// @note Legacy code from Tribes 2, but still works
  1143. Point3F getAIRepairPoint();
  1144. /// @name Mounted Images
  1145. /// @{
  1146. /// Mount an image (ShapeBaseImage) onto an image slot
  1147. /// @param image ShapeBaseImage to mount
  1148. /// @param imageSlot Image mount point
  1149. /// @param loaded True if weapon is loaded (it assumes it's a weapon)
  1150. /// @param skinNameHandle Skin name for object
  1151. virtual bool mountImage(ShapeBaseImageData* image,U32 imageSlot,bool loaded, NetStringHandle &skinNameHandle);
  1152. /// Unmount an image from a slot
  1153. /// @param imageSlot Mount point
  1154. virtual bool unmountImage(U32 imageSlot);
  1155. /// Gets the information on the image mounted in a slot
  1156. /// @param imageSlot Mount point
  1157. ShapeBaseImageData* getMountedImage(U32 imageSlot);
  1158. /// Gets the mounted image on on a slot
  1159. /// @param imageSlot Mount Point
  1160. MountedImage* getImageStruct(U32 imageSlot);
  1161. TSShapeInstance* getImageShapeInstance(U32 imageSlot)
  1162. {
  1163. const MountedImage &image = mMountedImageList[imageSlot];
  1164. U32 imageShapeIndex = getImageShapeIndex(image);
  1165. if(image.dataBlock && image.shapeInstance[imageShapeIndex])
  1166. return image.shapeInstance[imageShapeIndex];
  1167. return NULL;
  1168. }
  1169. /// Gets the next image which will be put in an image slot
  1170. /// @see setImageState
  1171. /// @param imageSlot mount Point
  1172. ShapeBaseImageData* getPendingImage(U32 imageSlot);
  1173. /// Returns true if the mounted image is firing
  1174. /// @param imageSlot Mountpoint
  1175. bool isImageFiring(U32 imageSlot);
  1176. /// Returns true if the mounted image is alternate firing
  1177. /// @param imageSlot Mountpoint
  1178. bool isImageAltFiring(U32 imageSlot);
  1179. /// Returns true if the mounted image is reloading
  1180. /// @param imageSlot Mountpoint
  1181. bool isImageReloading(U32 imageSlot);
  1182. /// This will return true if, when triggered, the object will fire.
  1183. /// @param imageSlot mount point
  1184. /// @param ns Used internally for recursion, do not mess with
  1185. /// @param depth Used internally for recursion, do not mess with
  1186. bool isImageReady(U32 imageSlot,U32 ns = (U32)-1,U32 depth = 0);
  1187. /// Returns true if the specified image is mounted
  1188. /// @param image ShapeBase image
  1189. bool isImageMounted(ShapeBaseImageData* image);
  1190. /// Returns the slot which the image specified is mounted on
  1191. /// @param image Image to test for
  1192. S32 getMountSlot(ShapeBaseImageData* image);
  1193. /// Returns the skin for the image in a slot
  1194. /// @param imageSlot Image slot to get the skin from
  1195. NetStringHandle getImageSkinTag(U32 imageSlot);
  1196. /// Check if the given state exists on the mounted Image
  1197. /// @param imageSlot Image slot id
  1198. /// @param state Image state to check for
  1199. bool hasImageState(U32 imageSlot, const char* state);
  1200. /// Returns the image state as a string
  1201. /// @param imageSlot Image slot to check state
  1202. const char* getImageState(U32 imageSlot);
  1203. /// Sets the generic trigger state of the image
  1204. /// @param imageSlot Image slot
  1205. /// @param trigger Generic trigger number 0-3
  1206. /// @param state True if generic trigger is down
  1207. void setImageGenericTriggerState(U32 imageSlot, U32 trigger, bool state);
  1208. /// Returns the generic trigger state of the image
  1209. /// @param imageSlot Image slot
  1210. /// @param trigger Generic trigger number 0-3
  1211. bool getImageGenericTriggerState(U32 imageSlot, U32 trigger);
  1212. /// Sets the trigger state of the image (Ie trigger pulled down on gun)
  1213. /// @param imageSlot Image slot
  1214. /// @param trigger True if trigger is down
  1215. void setImageTriggerState(U32 imageSlot,bool trigger);
  1216. /// Returns the trigger state of the image
  1217. /// @param imageSlot Image slot
  1218. bool getImageTriggerState(U32 imageSlot);
  1219. /// Sets the alt trigger state of the image (Ie trigger pulled down on gun)
  1220. /// @param imageSlot Image slot
  1221. /// @param trigger True if trigger is down
  1222. void setImageAltTriggerState( U32 imageSlot, bool trigger );
  1223. /// Returns the alt trigger state of the image
  1224. /// @param imageSlot Image slot
  1225. bool getImageAltTriggerState( U32 imageSlot );
  1226. /// Sets the flag if the image uses ammo or energy
  1227. /// @param imageSlot Image slot
  1228. /// @param ammo True if the weapon uses ammo, not energy
  1229. void setImageAmmoState(U32 imageSlot,bool ammo);
  1230. /// Returns true if the image uses ammo, not energy
  1231. /// @param imageSlot Image slot
  1232. bool getImageAmmoState(U32 imageSlot);
  1233. /// Sets the image as wet or not, IE if you wanted a gun not to function underwater
  1234. /// @param imageSlot Image slot
  1235. /// @param wet True if image is wet
  1236. void setImageWetState(U32 imageSlot,bool wet);
  1237. /// Returns true if image is wet
  1238. /// @param imageSlot image slot
  1239. bool getImageWetState(U32 imageSlot);
  1240. /// Sets the image as in motion or not, IE if you wanted a gun not to sway while the player is in motion
  1241. /// @param imageSlot Image slot
  1242. /// @param motion True if image is in motion
  1243. void setImageMotionState(U32 imageSlot,bool motion);
  1244. /// Returns true if image is in motion
  1245. /// @param imageSlot image slot
  1246. bool getImageMotionState(U32 imageSlot);
  1247. /// Sets the flag if the image has a target
  1248. /// @param imageSlot Image slot
  1249. /// @param ammo True if the weapon has a target
  1250. void setImageTargetState(U32 imageSlot,bool ammo);
  1251. /// Returns true if the image has a target
  1252. /// @param imageSlot Image slot
  1253. bool getImageTargetState(U32 imageSlot);
  1254. /// Sets the flag of if the image is loaded with ammo
  1255. /// @param imageSlot Image slot
  1256. /// @param loaded True if object is loaded with ammo
  1257. void setImageLoadedState(U32 imageSlot,bool loaded);
  1258. /// Returns true if object is loaded with ammo
  1259. /// @param imageSlot Image slot
  1260. bool getImageLoadedState(U32 imageSlot);
  1261. /// Set the script animation prefix for the image
  1262. /// @param imageSlot Image slot id
  1263. /// @param prefix The prefix applied to the image
  1264. void setImageScriptAnimPrefix(U32 imageSlot, NetStringHandle prefix);
  1265. /// Get the script animation prefix for the image
  1266. /// @param imageSlot Image slot id
  1267. /// @param imageShapeIndex Shape index (1st person, etc.) used to look up the prefix text
  1268. NetStringHandle getImageScriptAnimPrefix(U32 imageSlot);
  1269. /// Modify muzzle, if needed, to aim at whatever is straight in front of eye.
  1270. /// Returns true if result is actually modified.
  1271. /// @param muzMat Muzzle transform (in/out)
  1272. /// @param result Corrected muzzle vector (out)
  1273. bool getCorrectedAim(const MatrixF& muzMat, VectorF* result);
  1274. /// Gets the muzzle vector of a specified slot
  1275. /// @param imageSlot Image slot to check transform for
  1276. /// @param vec Muzzle vector (out)
  1277. virtual void getMuzzleVector(U32 imageSlot,VectorF* vec);
  1278. /// Gets the point of the muzzle of the image
  1279. /// @param imageSlot Image slot
  1280. /// @param pos Muzzle point (out)
  1281. void getMuzzlePoint(U32 imageSlot,Point3F* pos);
  1282. /// @}
  1283. /// @name Transforms
  1284. /// @{
  1285. /// Gets the minimum viewing distance, maximum viewing distance, camera offsetand rotation
  1286. /// for this object, if the world were to be viewed through its eyes
  1287. /// @param min Minimum viewing distance
  1288. /// @param max Maximum viewing distance
  1289. /// @param offset Offset of the camera from the origin in local space
  1290. /// @param rot Rotation matrix
  1291. virtual void getCameraParameters(F32 *min,F32* max,Point3F* offset,MatrixF* rot);
  1292. /// Gets the camera to world space transform matrix
  1293. /// @todo Find out what pos does
  1294. /// @param pos TODO: Find out what this does
  1295. /// @param mat Camera transform (out)
  1296. virtual void getCameraTransform(F32* pos,MatrixF* mat);
  1297. /// Gets the index of a node inside a mounted image given the name
  1298. /// @param imageSlot Image slot
  1299. /// @param nodeName Node name
  1300. S32 getNodeIndex(U32 imageSlot,StringTableEntry nodeName);
  1301. /// @}
  1302. /// @name Object Transforms
  1303. /// @{
  1304. /// Returns the eye transform of this shape, IE the eyes of a player
  1305. /// @param mat Eye transform (out)
  1306. virtual void getEyeTransform(MatrixF* mat);
  1307. /// Returns the eye transform of this shape without including mounted images, IE the eyes of a player
  1308. /// @param mat Eye transform (out)
  1309. virtual void getEyeBaseTransform(MatrixF* mat, bool includeBank);
  1310. /// The retraction transform is the muzzle transform in world space.
  1311. ///
  1312. /// If the gun is pushed back, for instance, if the player ran against something,
  1313. /// the muzzle of the gun gets pushed back towards the player, towards this location.
  1314. /// @param imageSlot Image slot
  1315. /// @param mat Transform (out)
  1316. virtual void getRetractionTransform(U32 imageSlot,MatrixF* mat);
  1317. /// Muzzle transform of mounted object in world space
  1318. /// @param imageSlot Image slot
  1319. /// @param mat Muzzle transform (out)
  1320. virtual void getMuzzleTransform(U32 imageSlot,MatrixF* mat);
  1321. /// Gets the transform of a mounted image in world space
  1322. /// @param imageSlot Image slot
  1323. /// @param mat Transform (out)
  1324. virtual void getImageTransform(U32 imageSlot,MatrixF* mat);
  1325. /// Gets the transform of a node on a mounted image in world space
  1326. /// @param imageSlot Image Slot
  1327. /// @param node node on image
  1328. /// @param mat Transform (out)
  1329. virtual void getImageTransform(U32 imageSlot,S32 node, MatrixF* mat);
  1330. /// Gets the transform of a node on a mounted image in world space
  1331. /// @param imageSlot Image Slot
  1332. /// @param nodeName Name of node on image
  1333. /// @param mat Transform (out)
  1334. virtual void getImageTransform(U32 imageSlot, StringTableEntry nodeName, MatrixF* mat);
  1335. ///@}
  1336. /// @name Render transforms
  1337. /// Render transforms are different from object transforms in that the render transform of an object
  1338. /// is where, in world space, the object is actually rendered. The object transform is the
  1339. /// absolute position of the object, as in where it should be.
  1340. ///
  1341. /// The render transforms typically vary from object transforms due to client side prediction.
  1342. ///
  1343. /// Other than that, these functions are identical to their object-transform counterparts
  1344. ///
  1345. /// @note These are meaningless on the server.
  1346. /// @{
  1347. virtual void getRenderRetractionTransform(U32 index,MatrixF* mat);
  1348. virtual void getRenderMuzzleTransform(U32 index,MatrixF* mat);
  1349. virtual void getRenderImageTransform(U32 imageSlot,MatrixF* mat,bool noEyeOffset=false);
  1350. virtual void getRenderImageTransform(U32 index,S32 node, MatrixF* mat);
  1351. virtual void getRenderImageTransform(U32 index, StringTableEntry nodeName, MatrixF* mat);
  1352. virtual void getRenderMuzzleVector(U32 imageSlot,VectorF* vec);
  1353. virtual void getRenderMuzzlePoint(U32 imageSlot,Point3F* pos);
  1354. virtual void getRenderEyeTransform(MatrixF* mat);
  1355. virtual void getRenderEyeBaseTransform(MatrixF* mat, bool includeBank);
  1356. /// @}
  1357. /// @name Screen Flashing
  1358. /// @{
  1359. /// Returns the level of screenflash that should be used
  1360. virtual F32 getDamageFlash() const;
  1361. /// Sets the flash level
  1362. /// @param amt Level of flash
  1363. virtual void setDamageFlash(const F32 amt);
  1364. /// White out is the flash-grenade blindness effect
  1365. /// This returns the level of flash to create
  1366. virtual F32 getWhiteOut() const;
  1367. /// Set the level of flash blindness
  1368. virtual void setWhiteOut(const F32);
  1369. /// @}
  1370. /// @name Movement & velocity
  1371. /// @{
  1372. /// Sets the velocity of this object
  1373. /// @param vel Velocity vector
  1374. virtual void setVelocity(const VectorF& vel);
  1375. /// Applies an impulse force to this object
  1376. /// @param pos Position where impulse came from in world space
  1377. /// @param vec Velocity vector (Impulse force F = m * v)
  1378. virtual void applyImpulse(const Point3F& pos,const VectorF& vec);
  1379. /// @}
  1380. /// @name Cameras and Control
  1381. /// @{
  1382. /// Returns the object controlling this object
  1383. ShapeBase* getControllingObject() { return mControllingObject; }
  1384. /// Sets the controlling object
  1385. /// @param obj New controlling object
  1386. virtual void setControllingObject(ShapeBase* obj);
  1387. ///
  1388. virtual void setControllingClient( GameConnection* connection );
  1389. /// Returns the object this is controlling
  1390. virtual ShapeBase* getControlObject();
  1391. /// sets the object this is controlling
  1392. /// @param obj New controlled object
  1393. virtual void setControlObject(ShapeBase *obj);
  1394. /// Returns true if this object is controlling by something
  1395. bool isControlled() { return(mIsControlled); }
  1396. /// Returns true if this object is being used as a camera in first person
  1397. bool isFirstPerson() const;
  1398. /// Returns true if the camera uses this objects eye point (defined by modeler)
  1399. bool useObjsEyePoint() const;
  1400. /// Returns true if this object can only be used as a first person camera
  1401. bool onlyFirstPerson() const;
  1402. /// Returns the vertical field of view in degrees for
  1403. /// this object if used as a camera.
  1404. virtual F32 getCameraFov() { return mCameraFov; }
  1405. /// Returns the default vertical field of view in degrees
  1406. /// if this object is used as a camera.
  1407. virtual F32 getDefaultCameraFov() { return mDataBlock->cameraDefaultFov; }
  1408. /// Sets the vertical field of view in degrees for this
  1409. /// object if used as a camera.
  1410. /// @param yfov The vertical FOV in degrees to test.
  1411. virtual void setCameraFov(F32 fov);
  1412. /// Returns true if the vertical FOV in degrees is within
  1413. /// allowable parameters of the datablock.
  1414. /// @param yfov The vertical FOV in degrees to test.
  1415. /// @see ShapeBaseData::cameraMinFov
  1416. /// @see ShapeBaseData::cameraMaxFov
  1417. virtual bool isValidCameraFov(F32 fov);
  1418. /// @}
  1419. void processTick(const Move *move);
  1420. void advanceTime(F32 dt);
  1421. /// @name Rendering
  1422. /// @{
  1423. /// Returns the renderable shape of this object
  1424. TSShape const* getShape();
  1425. /// @see SceneObject
  1426. virtual void prepRenderImage( SceneRenderState* state );
  1427. /// Used from ShapeBase::_prepRenderImage() to submit render
  1428. /// instances for the main shape or its mounted elements.
  1429. virtual void prepBatchRender( SceneRenderState *state, S32 mountedImageIndex );
  1430. /// Preprender logic
  1431. virtual void calcClassRenderData() { }
  1432. /// Virtualize this so other classes may override it for custom reasons.
  1433. virtual void renderMountedImage( U32 imageSlot, TSRenderState &rstate, SceneRenderState *state );
  1434. /// @}
  1435. /// Control object scoping
  1436. void onCameraScopeQuery(NetConnection *cr, CameraScopeQuery *camInfo);
  1437. bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
  1438. bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo* info);
  1439. bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere);
  1440. void buildConvex(const Box3F& box, Convex* convex);
  1441. /// @name Rendering
  1442. /// @{
  1443. /// Increments the last rendered frame number
  1444. static void incRenderFrame() { sLastRenderFrame++; }
  1445. /// Returns true if the last frame calculated rendered
  1446. bool didRenderLastRender() { return mLastRenderFrame == sLastRenderFrame; }
  1447. /// Sets the state of this object as hidden or not. If an object is hidden
  1448. /// it is removed entirely from collisions, it is not ghosted and is
  1449. /// essentially "non existant" as far as simulation is concerned.
  1450. /// @param hidden True if object is to be hidden
  1451. virtual void setHidden(bool hidden);
  1452. /// Returns true if this object can be damaged
  1453. bool isInvincible();
  1454. /// Start fade of object in/out
  1455. /// @param fadeTime Time fade should take
  1456. /// @param fadeDelay Delay before starting fade
  1457. /// @param fadeOut True if object is fading out, false if fading in.
  1458. void startFade( F32 fadeTime, F32 fadeDelay = 0.0, bool fadeOut = true );
  1459. /// Traverses mounted objects and registers light sources with the light manager
  1460. /// @param lightManager Light manager to register with
  1461. /// @param lightingScene Set to true if the scene is being lit, in which case these lights will not be used
  1462. //void registerLights(LightManager * lightManager, bool lightingScene);
  1463. // ISceneLight
  1464. virtual void submitLights( LightManager *lm, bool staticLighting );
  1465. virtual LightInfo* getLight() { return NULL; }
  1466. /// @}
  1467. /// Returns true if the point specified is in the water
  1468. /// @param point Point to test in world space
  1469. bool pointInWater( Point3F &point );
  1470. /// Returns the percentage of this object covered by water
  1471. F32 getWaterCoverage() { return mWaterCoverage; }
  1472. /// Returns the height of the liquid on this object
  1473. F32 getLiquidHeight() { return mLiquidHeight; }
  1474. virtual WaterObject* getCurrentWaterObject();
  1475. void setCurrentWaterObject( WaterObject *obj );
  1476. virtual F32 getMass() const { return mMass; }
  1477. /// @name Network
  1478. /// @{
  1479. F32 getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips);
  1480. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
  1481. void unpackUpdate(NetConnection *conn, BitStream *stream);
  1482. void writePacketData(GameConnection *conn, BitStream *stream);
  1483. void readPacketData(GameConnection *conn, BitStream *stream);
  1484. /// @}
  1485. DECLARE_CONOBJECT(ShapeBase);
  1486. protected:
  1487. DECLARE_CALLBACK( F32, validateCameraFov, (F32 fov) );
  1488. };
  1489. //------------------------------------------------------------------------------
  1490. // inlines
  1491. //------------------------------------------------------------------------------
  1492. inline bool ShapeBase::getCloakedState()
  1493. {
  1494. return(mCloaked);
  1495. }
  1496. inline F32 ShapeBase::getCloakLevel()
  1497. {
  1498. return(mCloakLevel);
  1499. }
  1500. inline const char* ShapeBase::getShapeName()
  1501. {
  1502. return mShapeNameHandle.getString();
  1503. }
  1504. inline const char* ShapeBase::getSkinName()
  1505. {
  1506. return mSkinNameHandle.getString();
  1507. }
  1508. inline WaterObject* ShapeBase::getCurrentWaterObject()
  1509. {
  1510. if ( isMounted() && mShapeBaseMount )
  1511. return mShapeBaseMount->getCurrentWaterObject();
  1512. return mCurrentWaterObject;
  1513. }
  1514. #endif // _H_SHAPEBASE_