shapeBase.h 73 KB

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