shapeBase.h 72 KB

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