shapeBase.h 74 KB

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