shapeBase.h 71 KB

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