shapeBase.h 74 KB

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