2
0

shapeBase.h 74 KB

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