shapeBase.h 75 KB

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