shapeBase.h 73 KB

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