shapeBase.h 74 KB

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