shapeBase.h 75 KB

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