Drawable.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Drawable.h ///////////////////////////////////////////////////////////////////////////////
  24. // Simple base drawable
  25. // Author: Michael S. Booth, March 2001
  26. #pragma once
  27. #ifndef _DRAWABLE_H_
  28. #define _DRAWABLE_H_
  29. #include "Common/AudioEventRTS.h"
  30. #include "Common/GameType.h"
  31. #include "Common/ModelState.h"
  32. #include "Common/ModuleFactory.h"
  33. #include "Common/Thing.h"
  34. #include "Common/Geometry.h"
  35. #include "GameClient/Color.h"
  36. #include "WWMath/Matrix3D.h"
  37. #include "GameClient/DrawableInfo.h"
  38. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  39. class PositionalSound;
  40. class ThingTemplate;
  41. class Particle;
  42. class DisplayString;
  43. class FXList;
  44. class DrawModule;
  45. class ClientUpdateModule;
  46. class View;
  47. class Locomotor;
  48. class Anim2D;
  49. class Shadow;
  50. class ModuleInfo;
  51. class Anim2DTemplate;
  52. class Image;
  53. enum BodyDamageType;
  54. // this is a very worthwhile performance win. left conditionally defined for now, just
  55. // in case, but probably should be made permanent soon. (srj)
  56. #define DIRTY_CONDITION_FLAGS
  57. #define DEFAULT_TINT_COLOR_FADE_RATE (0.6f) // fast fade
  58. #define DEF_ATTACK_FRAMES (1)
  59. #define DEF_SUSTAIN_FRAMES (1)
  60. #define DEF_DECAY_FRAMES (4)
  61. #define SUSTAIN_INDEFINITELY (0xfffffffe) // forever and ever, amen.
  62. //-----------------------------------------------------------------------------
  63. //@TODO -- The drawable icon system needs to be implemented in a proper manner -- KM
  64. // Fact 1: Every drawable in the world shouldn't have to have a pointer
  65. // and frame counter for every possible icon type. It should be a dynamic vector.
  66. // Fact 2: It's polling every frame for every object on screen for every possible icon condition...
  67. // KM : I moved this into Drawable.cpp so I don't have to recompile the entire project
  68. // each time I add a new icon, and made the arrays dynamic...
  69. // CD: No so good, core engine components should not be made dynamic in this way
  70. enum DrawableIconType
  71. {
  72. /** NOTE: This enum MUST appear in the same order as TheDrawableIconNames array to be
  73. * indexed correctly using that array */
  74. ICON_INVALID = -1,
  75. ICON_FIRST = 0,
  76. ICON_DEFAULT_HEAL = ICON_FIRST,
  77. ICON_STRUCTURE_HEAL,
  78. ICON_VEHICLE_HEAL,
  79. #ifdef ALLOW_DEMORALIZE
  80. ICON_DEMORALIZED,
  81. #else
  82. ICON_DEMORALIZED_OBSOLETE,
  83. #endif
  84. ICON_BOMB_TIMED,
  85. ICON_BOMB_REMOTE,
  86. ICON_DISABLED,
  87. ICON_BATTLEPLAN_BOMBARD,
  88. ICON_BATTLEPLAN_HOLDTHELINE,
  89. ICON_BATTLEPLAN_SEARCHANDDESTROY,
  90. ICON_EMOTICON,
  91. ICON_ENTHUSIASTIC,
  92. ICON_ENTHUSIASTIC_SUBLIMINAL,
  93. ICON_CARBOMB,
  94. MAX_ICONS ///< keep this last
  95. };
  96. //-----------------------------------------------------------------------------
  97. class DrawableIconInfo : public MemoryPoolObject
  98. {
  99. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(DrawableIconInfo, "DrawableIconInfo" )
  100. public:
  101. Anim2D* m_icon[MAX_ICONS];
  102. UnsignedInt m_keepTillFrame[MAX_ICONS];
  103. DrawableIconInfo();
  104. //~DrawableIconInfo();
  105. void clear();
  106. void killIcon(DrawableIconType t);
  107. };
  108. //-----------------------------------------------------------------------------
  109. struct TWheelInfo
  110. {
  111. Real m_frontLeftHeightOffset; ///< Height offsets for tires due to suspension sway
  112. Real m_frontRightHeightOffset;
  113. Real m_rearLeftHeightOffset;
  114. Real m_rearRightHeightOffset;
  115. Real m_wheelAngle; ///< Wheel angle. 0 = straight, >0 left, <0 right.
  116. Int m_framesAirborneCounter; ///< Counter.
  117. Int m_framesAirborne; ///< How many frames it was in the air.
  118. };
  119. //-----------------------------------------------------------------------------
  120. class DrawableLocoInfo : public MemoryPoolObject
  121. {
  122. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(DrawableLocoInfo, "DrawableLocoInfo" )
  123. public:
  124. Real m_pitch; ///< pitch of the entire drawable
  125. Real m_pitchRate; ///< rate of change of pitch
  126. Real m_roll; ///< roll of the entire drawable
  127. Real m_rollRate; ///< rate of change of roll
  128. Real m_yaw; ///< yaw for entire drawable
  129. Real m_accelerationPitch; ///< pitch of the drawable due to impact/acceleration
  130. Real m_accelerationPitchRate; ///< rate of change of pitch
  131. Real m_accelerationRoll; ///< roll of the entire drawable
  132. Real m_accelerationRollRate; ///< rate of change of roll
  133. Real m_overlapZVel; ///< fake Z velocity
  134. Real m_overlapZ; ///< current height (additional)
  135. Real m_wobble; ///< for wobbling
  136. TWheelInfo m_wheelInfo; ///< Wheel offset & angle info for a wheeled type locomotor.
  137. DrawableLocoInfo();
  138. };
  139. //-----------------------------------------------------------------------------
  140. //* TintEnvelope handles the fading of the tint color up, down stable etc...
  141. //* assumes that 0,0,0, is the color for the AT REST state, used as decay target
  142. //* works like an ADSR envelope,
  143. //* except that SUSTAIN and RELEASE are randomly (or never) triggered, externally
  144. class TintEnvelope : public MemoryPoolObject, public Snapshot
  145. {
  146. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(TintEnvelope, "TintEnvelope" )
  147. public:
  148. TintEnvelope(void);
  149. void update(void); ///< does all the work
  150. void play(const RGBColor *peak,
  151. UnsignedInt atackFrames = DEF_ATTACK_FRAMES,
  152. UnsignedInt decayFrames = DEF_DECAY_FRAMES,
  153. UnsignedInt sustainAtPeak = DEF_SUSTAIN_FRAMES ); // ask MLorenzen
  154. void sustain(void) { m_envState = ENVELOPE_STATE_SUSTAIN; }
  155. void release(void) { m_envState = ENVELOPE_STATE_DECAY; }
  156. void rest(void) { m_envState = ENVELOPE_STATE_REST; } // goes away now!
  157. Bool isEffective() const { return m_affect; }
  158. const Vector3* getColor() const { return &m_currentColor; }
  159. protected:
  160. // snapshot methods
  161. virtual void crc( Xfer *xfer );
  162. virtual void xfer( Xfer *xfer );
  163. virtual void loadPostProcess( void );
  164. private:
  165. void setAttackFrames(UnsignedInt frames);
  166. void setDecayFrames( UnsignedInt frames);
  167. void setPeakColor( const RGBColor *peak) {m_peakColor = Vector3( peak->red, peak->green, peak->blue );};
  168. void setPeakColor( Real r, Real g, Real b ) {m_peakColor.Set( r, g, b );};
  169. enum EnvelopeStatesEnum
  170. {
  171. ENVELOPE_STATE_REST,
  172. ENVELOPE_STATE_ATTACK,
  173. ENVELOPE_STATE_DECAY,
  174. ENVELOPE_STATE_SUSTAIN ///< RELEASE IS THE LOGICAL COMPLIMENT TO SUSTAIN
  175. };
  176. Vector3 m_attackRate; ///< step amount to make tint turn on slow or fast
  177. Vector3 m_decayRate; ///< step amount to make tint turn off slow or fast
  178. Vector3 m_peakColor; ///< um, the peak color, what color we are headed toward during attack
  179. Vector3 m_currentColor; ///< um, the current color, how we are colored, now
  180. UnsignedInt m_sustainCounter;
  181. Byte m_envState; ///< a randomly switchable SUSTAIN state, release is compliment
  182. Bool m_affect; ///< set TRUE if this has any effect (has a non 0,0,0 color).
  183. };
  184. EMPTY_DTOR(TintEnvelope)
  185. //-----------------------------------------------------------------------------
  186. enum StealthLookType
  187. {
  188. STEALTHLOOK_NONE, ///< unit is not stealthed at all
  189. STEALTHLOOK_VISIBLE_FRIENDLY, ///< unit is stealthed-but-visible due to friendly status
  190. STEALTHLOOK_DISGUISED_ENEMY, ///< we can have units that are disguised (instead of invisible)
  191. STEALTHLOOK_VISIBLE_DETECTED, ///< unit is stealthed and invisible, but a second material pass
  192. ///< is added to reveal the invisible unit as with heat vision
  193. STEALTHLOOK_VISIBLE_FRIENDLY_DETECTED, ///< unit is stealthed-but-visible due to being detected,
  194. ///< and rendered in heatvision effect second material pass
  195. STEALTHLOOK_INVISIBLE ///< unit is stealthed-and-invisible
  196. };
  197. // ------------------------------------------------------------------------------------------------
  198. /** Drawable status bits */
  199. // ------------------------------------------------------------------------------------------------
  200. enum DrawableStatus
  201. {
  202. DRAWABLE_STATUS_NONE = 0x00000000, ///< no status
  203. DRAWABLE_STATUS_DRAWS_IN_MIRROR = 0x00000001, ///< drawable can reflect
  204. DRAWABLE_STATUS_SHADOWS = 0x00000002, ///< use setShadowsEnabled() access method
  205. DRAWABLE_STATUS_TINT_COLOR_LOCKED = 0x00000004, ///< drawable tint color is "locked" and won't fade to normal
  206. DRAWABLE_STATUS_NO_STATE_PARTICLES = 0x00000008, ///< do *not* auto-create particle systems based on model condition
  207. DRAWABLE_STATUS_NO_SAVE = 0x00000010, ///< do *not* save this drawable (UI fluff only). ignored (error, actually) if attached to an object
  208. };
  209. enum TintStatus
  210. {
  211. TINT_STATUS_DISABLED = 0x00000001,///< drawable tint color is deathly dark grey
  212. TINT_STATUS_IRRADIATED = 0x00000002,///< drawable tint color is sickly green
  213. TINT_STATUS_POISONED = 0x00000004,///< drawable tint color is open-sore red
  214. };
  215. //-----------------------------------------------------------------------------
  216. //Keep this enum in sync with the TerrainDecalTextureName array in drawable.cpp
  217. //
  218. // Note: these values are saved in save files, so you MUST NOT REMOVE OR CHANGE
  219. // existing values!
  220. //
  221. enum TerrainDecalType
  222. {
  223. #ifdef ALLOW_DEMORALIZE
  224. TERRAIN_DECAL_DEMORALIZED = 0,
  225. #else
  226. TERRAIN_DECAL_DEMORALIZED_OBSOLETE = 0,
  227. #endif
  228. TERRAIN_DECAL_HORDE,
  229. TERRAIN_DECAL_HORDE_WITH_NATIONALISM_UPGRADE,
  230. TERRAIN_DECAL_HORDE_VEHICLE,
  231. TERRAIN_DECAL_HORDE_WITH_NATIONALISM_UPGRADE_VEHICLE,
  232. TERRAIN_DECAL_CRATE,
  233. TERRAIN_DECAL_NONE,
  234. TERRAIN_DECAL_MAX ///< keep this last
  235. };
  236. //-----------------------------------------------------------------------------
  237. const Int DRAWABLE_FRAMES_PER_FLASH = LOGICFRAMES_PER_SECOND / 2;
  238. //-----------------------------------------------------------------------------
  239. /**
  240. * A Drawable is a graphical entity which is generally associated
  241. * with a GameLogic object. Drawables are managed by TheGameClient.
  242. */
  243. class Drawable : public Thing,
  244. public Snapshot
  245. {
  246. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(Drawable, "Drawable" )
  247. public:
  248. Drawable( const ThingTemplate *thing, DrawableStatus statusBits = DRAWABLE_STATUS_NONE );
  249. void onDestroy( void ); ///< run from GameClient::destroyDrawable
  250. Drawable *getNextDrawable( void ) const { return m_nextDrawable; } ///< return the next drawable in the global list
  251. Drawable *getPrevDrawable( void ) const { return m_prevDrawable; } ///< return the prev drawable in the global list
  252. DrawableID getID( void ) const; ///< return this drawable's unique ID
  253. void friend_bindToObject( Object *obj ); ///< bind this drawable to an object ID. for use ONLY by GameLogic!
  254. void setIndicatorColor(Color color);
  255. void setTintStatus( TintStatus statusBits ) { BitSet( m_tintStatus, statusBits ); };
  256. void clearTintStatus( TintStatus statusBits ) { BitClear( m_tintStatus, statusBits ); };
  257. Bool testTintStatus( TintStatus statusBits ) const { return BitTest( m_tintStatus, statusBits ); };
  258. TintEnvelope *getColorTintEnvelope( void ) { return m_colorTintEnvelope; }
  259. void setColorTintEnvelope( TintEnvelope &source ) { if (m_colorTintEnvelope) *m_colorTintEnvelope = source; }
  260. void setTerrainDecal(TerrainDecalType type); ///<decal that is to appear under the drawable
  261. void setTerrainDecalSize(Real x, Real y);
  262. void setTerrainDecalFadeTarget(Real target, Real rate = 0.1f);
  263. inline Object *getObject( void ) { return m_object; } ///< return object ID bound to this drawble
  264. inline const Object *getObject( void ) const { return m_object; } ///< return object ID bound to this drawble
  265. inline DrawableInfo *getDrawableInfo(void) {return &m_drawableInfo;}
  266. void setDrawableHidden( Bool hidden ); ///< hide or unhide drawable
  267. //
  268. // note that this is not necessarily the 'get' reflection of setDrawableHidden, since drawables
  269. // can spontaneously hide via stealth. (srj)
  270. //
  271. inline Bool isDrawableEffectivelyHidden() const { return m_hidden || m_hiddenByStealth; }
  272. void setSelectable( Bool selectable ); ///< Changes the drawables selectability
  273. Bool isSelectable( void ) const;
  274. Bool isMassSelectable( void ) const;
  275. void setStealthLook(StealthLookType look);
  276. StealthLookType getStealthLook() const { return m_stealthLook; }
  277. void updateDrawableClipStatus( UnsignedInt shotsRemaining, UnsignedInt maxShots, WeaponSlotType slot ); ///< This will do the show/hide work if ProjectileBoneFeedbackEnabled is set.
  278. void updateDrawableSupplyStatus( Int maxSupply, Int currentSupply ); ///< This will do visual feedback on Supplies carried
  279. void notifyDrawableDependencyCleared();///< If any of your draw modules were waiting for something, it's ready now.
  280. // Override.
  281. void setPosition( const Coord3D *pos );
  282. void reactToGeometryChange();
  283. const GeometryInfo& getDrawableGeometryInfo() const;
  284. void reactToBodyDamageStateChange(BodyDamageType newState);
  285. const Real getScale (void) const ;
  286. // access to modules
  287. //---------------------------------------------------------------------------
  288. // since most things don't have CU modules, we allow this to be null!
  289. ClientUpdateModule** getClientUpdateModules() { return (ClientUpdateModule**)getModuleList(MODULETYPE_CLIENT_UPDATE); }
  290. ClientUpdateModule const** getClientUpdateModules() const { return (ClientUpdateModule const**)getModuleList(MODULETYPE_CLIENT_UPDATE); }
  291. ClientUpdateModule* findClientUpdateModule( NameKeyType key );
  292. DrawModule** getDrawModules();
  293. DrawModule const** getDrawModules() const;
  294. //---------------------------------------------------------------------------
  295. void setDrawableStatus( DrawableStatus bit ) { BitSet( m_status, bit ); }
  296. void clearDrawableStatus( DrawableStatus bit ) { BitClear( m_status, bit ); }
  297. inline Bool testDrawableStatus( DrawableStatus bit ) const { return (m_status & bit) != 0; }
  298. void setShroudClearFrame( UnsignedInt frame ) { m_shroudClearFrame = frame; }
  299. UnsignedInt getShroudClearFrame( void ) { return m_shroudClearFrame; }
  300. void setShadowsEnabled(Bool enable);
  301. Bool getShadowsEnabled() const { return BitTest(m_status, DRAWABLE_STATUS_SHADOWS); }
  302. void releaseShadows(void); ///< frees all shadow resources used by this module - used by Options screen.
  303. void allocateShadows(void); ///< create shadow resources if not already present. Used by Options screen.
  304. void setFullyObscuredByShroud(Bool fullyObscured);
  305. inline Bool getFullyObscuredByShroud(void) {return m_drawableFullyObscuredByShroud;}
  306. Bool getDrawsInMirror() const { return BitTest(m_status, DRAWABLE_STATUS_DRAWS_IN_MIRROR) || isKindOf(KINDOF_CAN_CAST_REFLECTIONS); }
  307. void colorFlash( const RGBColor *color, UnsignedInt decayFrames = DEF_DECAY_FRAMES, UnsignedInt attackFrames = 0, UnsignedInt sustainAtPeak = FALSE ); ///< flash a drawable in the color specified for a short time
  308. void colorTint( const RGBColor *color ); ///< tint this drawable the color specified
  309. void setTintEnvelope( const RGBColor *color, Real attack, Real decay ); ///< how to transition color
  310. void flashAsSelected( const RGBColor *color = NULL ); ///< drawable takes care of the details if you spec no color
  311. /// Return true if drawable has been marked as "selected"
  312. Bool isSelected( void ) const { return m_selected; }
  313. void onSelected(); ///< Work unrelated to selection that must happen at time of selection
  314. void onUnselected(); ///< Work unrelated to selection that must happen at time of unselection
  315. //---------------------------------------------------------------------------
  316. // an "instance" matrix defines the local transform of the Drawable, and is concatenated with the global transform
  317. void setInstanceMatrix( const Matrix3D *instance ); ///< set the Drawable's instance transform
  318. const Matrix3D *getInstanceMatrix( void ) const { return &m_instance; } ///< get drawable instance transform
  319. inline Bool isInstanceIdentity() const { return m_instanceIsIdentity; }
  320. inline Real getInstanceScale( void ) const { return m_instanceScale; } ///< get scale that will be applied to instance matrix
  321. void setInstanceScale(Real value) { m_instanceScale = value;} ///< set scale that will be applied to instance matrix before rendering.
  322. const Matrix3D *getTransformMatrix( void ) const; ///< return the world transform
  323. void draw( View *view ); ///< render the drawable to the given view
  324. void updateDrawable(); ///< update the drawable
  325. void drawIconUI( void ); ///< draw "icon"(s) needed on drawable (health bars, veterency, etc)
  326. void startAmbientSound();
  327. void stopAmbientSound( void );
  328. void enableAmbientSound( Bool enable );
  329. void setTimeOfDay( TimeOfDay tod );
  330. void prependToList(Drawable **pListHead);
  331. void removeFromList(Drawable **pListHead);
  332. void setID( DrawableID id ); ///< set this drawable's unique ID
  333. inline const ModelConditionFlags& getModelConditionFlags( void ) const { return m_conditionState; }
  334. //
  335. // NOTE: avoid repeated calls to the set and clear for the condition state as they
  336. // reconstruct and load models which is expensive ... wrap up all our bit flags to
  337. // set and clear into one function call
  338. //
  339. void clearModelConditionState( ModelConditionFlagType a ) { clearAndSetModelConditionState(a, MODELCONDITION_INVALID); }
  340. void setModelConditionState( ModelConditionFlagType a ) { clearAndSetModelConditionState(MODELCONDITION_INVALID, a); }
  341. void clearAndSetModelConditionState( ModelConditionFlagType clr, ModelConditionFlagType set );
  342. void clearModelConditionFlags( const ModelConditionFlags& clr ) { ModelConditionFlags empty; clearAndSetModelConditionFlags(clr, empty); }
  343. void setModelConditionFlags( const ModelConditionFlags& set ) { ModelConditionFlags empty; clearAndSetModelConditionFlags(empty, set); }
  344. void clearAndSetModelConditionFlags( const ModelConditionFlags& clr, const ModelConditionFlags& set );
  345. void replaceModelConditionFlags( const ModelConditionFlags &flags, Bool forceReplace = FALSE );
  346. void attachToParticleSystem( Particle *p ); ///< attach this Drawable to a particle system
  347. void detachFromParticleSystem( void ); ///< detach this from any particle system
  348. Bool handleWeaponFireFX(
  349. WeaponSlotType wslot,
  350. Int specificBarrelToUse,
  351. const FXList* fxl,
  352. Real weaponSpeed,
  353. Real recoilAmount,
  354. Real recoilAngle,
  355. const Coord3D* victimPos,
  356. Real damageRadius
  357. );
  358. Int getBarrelCount(WeaponSlotType wslot) const;
  359. // when our Object changes teams, it calls us to let us know, so
  360. // we can update our model, etc., if necessary. NOTE, we don't guarantee
  361. // that the new team is different from the old team, nor do we guarantee
  362. // that the team is nonnull.
  363. void changedTeam();
  364. const TWheelInfo *getWheelInfo(void) const { return m_locoInfo ? &m_locoInfo->m_wheelInfo : NULL; }
  365. // this method must ONLY be called from the client, NEVER From the logic, not even indirectly.
  366. Bool clientOnly_getFirstRenderObjInfo(Coord3D* pos, Real* boundingSphereRadius, Matrix3D* transform);
  367. /**
  368. Find the bone(s) with the given name and return their positions and/or transforms in the given arrays.
  369. We look for a bone named "boneNamePrefixQQ", where QQ is 01, 02, 03, etc, starting at the
  370. value of "startIndex". Want to look for just a specific boneName with no numeric suffix?
  371. just pass zero (0) for startIndex. (no, we never look for "boneNamePrefix00".)
  372. We copy up to 'maxBones' into the array(s), and return the total count found.
  373. NOTE: this returns the positions and transform for the "ideal" model... that is,
  374. at its default rotation and scale, located at (0,0,0). You'll have to concatenate
  375. an Object's position and transform onto these in order to move 'em into "world space"!
  376. NOTE: this isn't very fast. Please call it sparingly and cache the result.
  377. */
  378. Int getPristineBonePositions(const char* boneNamePrefix, Int startIndex, Coord3D* positions, Matrix3D* transforms, Int maxBones) const;
  379. Int getCurrentClientBonePositions(const char* boneNamePrefix, Int startIndex, Coord3D* positions, Matrix3D* transforms, Int maxBones) const;
  380. // this is a special-purpose call for W3DModelDraw. (srj)
  381. Bool getCurrentWorldspaceClientBonePositions(const char* boneName, Matrix3D& transform) const;
  382. Bool getProjectileLaunchOffset(WeaponSlotType wslot, Int specificBarrelToUse, Matrix3D* launchPos, WhichTurretType tur, Coord3D* turretRotPos, Coord3D* turretPitchPos = NULL) const;
  383. /**
  384. This call says, "I want the current animation (if any) to take n frames to complete a single cycle".
  385. If it's a looping anim, each loop will take n frames. someday, we may want to add the option to insert
  386. "pad" frames at the start and/or end, but for now, we always just "stretch" the animation to fit.
  387. Note that you must call this AFTER setting the condition codes.
  388. */
  389. void setAnimationLoopDuration(UnsignedInt numFrames);
  390. /**
  391. similar to the above, but assumes that the current state is a "ONCE",
  392. and is smart about transition states... if there is a transition state
  393. "inbetween", it is included in the completion time.
  394. */
  395. void setAnimationCompletionTime(UnsignedInt numFrames);
  396. void updateSubObjects();
  397. void showSubObject( const AsciiString& name, Bool show );
  398. #ifdef ALLOW_ANIM_INQUIRIES
  399. // srj sez: not sure if this is a good idea, for net sync reasons...
  400. Real getAnimationScrubScalar( void ) const; // lorenzen // returns 0 to 1... where are we between start and finish?
  401. #endif
  402. UnsignedInt getExpirationDate() const { return m_expirationDate; }
  403. void setExpirationDate(UnsignedInt frame) { m_expirationDate = frame; }
  404. //
  405. // *ONLY* the InGameUI should do the actual drawable selection and de-selection
  406. //
  407. void friend_setSelected( void ); ///< mark drawable as "selected"
  408. void friend_clearSelected( void ); ///< clear drawable's "selected"
  409. Vector3 * getAmbientLight( void ); ///< get color value to add to ambient light when drawing
  410. void setAmbientLight( Vector3 *ambient ); ///< set color value to add to ambient light when drawing
  411. const Vector3 * getTintColor( void ) const; ///< get FX color value to add to ALL LIGHTS when drawing
  412. const Vector3 * getSelectionColor( void ) const; ///< get FX color value to add to ALL LIGHTS when drawing
  413. inline TerrainDecalType getTerrainDecalType( void ) const { return m_terrainDecalType; }
  414. inline void setDrawableOpacity( Real value ) { m_explicitOpacity = value; } ///< set alpha/opacity value used to override defaults when drawing.
  415. // note that this is not the 'get' inverse of setDrawableOpacity, since stealthing can also affect the effective opacity!
  416. inline Real getEffectiveOpacity() const { return m_explicitOpacity * m_effectiveStealthOpacity; } ///< get alpha/opacity value used to override defaults when drawing.
  417. void setEffectiveOpacity( Real pulseFactor, Real explicitOpacity = -1.0f );
  418. // this is for the heatvision effect which operates completely independently of the stealth opacity effects. Draw() does the fading every frame.
  419. inline Real getHeatVisionOpacity() const { return m_heatVisionOpacity; } ///< get alpha/opacity value used to render add'l heatvision rendering pass.
  420. void setHeatVisionOpacity( Real op ) { m_heatVisionOpacity = op; }; ///< set alpha/opacity value used to render add'l heatvision rendering pass.
  421. // both of these assume that you are starting at one extreme 100% or 0% opacity and are trying to go to the other!! -- amit
  422. void fadeOut( UnsignedInt frames ); ///< fade object out...how gradually this is done is determined by frames
  423. void fadeIn( UnsignedInt frames ); ///< fade object in...how gradually this is done is determined by frames
  424. void preloadAssets( TimeOfDay timeOfDay ); ///< preload the assets
  425. Bool isVisible(); ///< for limiting tree sway, etc to visible objects
  426. Bool getShouldAnimate( Bool considerPower ) const;
  427. void friend_setParticle( Particle *particle ) { m_particle = particle; }
  428. // flash drawable methods ---------------------------------------------------------
  429. Int getFlashCount( void ) { return m_flashCount; }
  430. void setFlashCount( Int count ) { m_flashCount = count; }
  431. void setFlashColor( Color color ) { m_flashColor = color; }
  432. void saturateRGB(RGBColor& color, Real factor);// not strictly for flash color, but it is the only practical use for this
  433. //---------------------------------------------------------------------------------
  434. // caption text methods -----------------------------------------------------------
  435. void setCaptionText( const UnicodeString& captionText );
  436. void clearCaptionText( void );
  437. UnicodeString getCaptionText( void );
  438. //---------------------------------------------------------------------------------
  439. DrawableIconInfo* getIconInfo(); ///< lazily allocates, if necessary
  440. void killIcon(DrawableIconType t) { if (m_iconInfo) m_iconInfo->killIcon(t); }
  441. Bool hasIconInfo() const { return m_iconInfo != NULL; }
  442. protected:
  443. // snapshot methods
  444. virtual void crc( Xfer *xfer );
  445. virtual void xfer( Xfer *xfer );
  446. virtual void loadPostProcess( void );
  447. void xferDrawableModules( Xfer *xfer );
  448. void startAmbientSound(BodyDamageType dt, TimeOfDay tod);
  449. Drawable *asDrawableMeth() { return this; }
  450. const Drawable *asDrawableMeth() const { return this; }
  451. inline Module** getModuleList(ModuleType i)
  452. {
  453. Module** m = m_modules[i - FIRST_DRAWABLE_MODULE_TYPE];
  454. return m;
  455. }
  456. inline Module* const* getModuleList(ModuleType i) const
  457. {
  458. Module** m = m_modules[i - FIRST_DRAWABLE_MODULE_TYPE];
  459. return m;
  460. }
  461. void applyPhysicsXform(Matrix3D* mtx);
  462. struct PhysicsXformInfo
  463. {
  464. Real m_totalPitch; ///< Current total pitch for this frame.
  465. Real m_totalRoll; ///< Current total roll for this frame.
  466. Real m_totalYaw; ///< Current total yaw for this frame
  467. Real m_totalZ;
  468. PhysicsXformInfo() : m_totalPitch(0), m_totalRoll(0), m_totalYaw(0), m_totalZ(0) { }
  469. };
  470. Bool calcPhysicsXform(PhysicsXformInfo& info);
  471. void calcPhysicsXformThrust(const Locomotor *locomotor, PhysicsXformInfo& info);
  472. void calcPhysicsXformHoverOrWings(const Locomotor *locomotor, PhysicsXformInfo& info);
  473. void calcPhysicsXformTreads(const Locomotor *locomotor, PhysicsXformInfo& info);
  474. void calcPhysicsXformWheels(const Locomotor *locomotor, PhysicsXformInfo& info);
  475. const AudioEventRTS& getAmbientSoundByDamage(BodyDamageType dt);
  476. #ifdef _DEBUG
  477. void validatePos() const;
  478. #endif
  479. virtual void reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle);
  480. void updateHiddenStatus();
  481. private:
  482. // note, these are lazily allocated!
  483. TintEnvelope* m_selectionFlashEnvelope; ///< used for selection flash, works WITH m_colorTintEnvelope
  484. TintEnvelope* m_colorTintEnvelope; ///< house color flashing, etc... works WITH m_selectionFlashEnvelope
  485. // this used to use m_ambientLight... but this replaces it
  486. // int most places. It works harder to change the drawable's
  487. // color, by tinting all four scene lights, not just ambient
  488. // zero = no effect
  489. // 1 = full effect
  490. TerrainDecalType m_terrainDecalType; ///<current decal in use by m_terrainDecal
  491. Real m_explicitOpacity; ///< opacity level. 1.0f == Solid/Opaque.
  492. Real m_stealthOpacity; ///< <<minimum>> opacity due to stealth. pulse is between opaque and this
  493. Real m_effectiveStealthOpacity; ///< opacity actually used to render with, after the pulse and stuff.
  494. Real m_decalOpacityFadeTarget;
  495. Real m_decalOpacityFadeRate;
  496. Real m_decalOpacity;
  497. Object *m_object; ///< object (if any) that this drawable represents
  498. Particle *m_particle; ///< particle (if any) that this Drawable is associated with
  499. DrawableID m_id; ///< this drawable's unique ID
  500. Drawable *m_nextDrawable;
  501. Drawable *m_prevDrawable; ///< list links
  502. UnsignedInt m_status; ///< status bits (see DrawableStatus enum)
  503. UnsignedInt m_tintStatus; ///< tint color status bits (see TintStatus enum)
  504. UnsignedInt m_prevTintStatus;///< for edge testing with m_tintStatus
  505. enum FadingMode
  506. {
  507. FADING_NONE,
  508. FADING_IN,
  509. FADING_OUT
  510. };
  511. FadingMode m_fadeMode;
  512. UnsignedInt m_timeElapsedFade; ///< for how many frames have i been fading
  513. UnsignedInt m_timeToFade; ///< how slowly am I fading
  514. UnsignedInt m_shroudClearFrame; ///< Last frame the local player saw this drawable "OBJECTSHROUD_CLEAR"
  515. DrawableLocoInfo* m_locoInfo; // lazily allocated
  516. DynamicAudioEventRTS* m_ambientSound; ///< sound module for ambient sound (lazily allocated)
  517. Bool m_ambientSoundEnabled;
  518. Module** m_modules[NUM_DRAWABLE_MODULE_TYPES];
  519. StealthLookType m_stealthLook;
  520. Int m_flashCount; ///< number of times to flash the drawable
  521. Color m_flashColor; ///< color to flash the drawable
  522. Matrix3D m_instance; ///< The instance matrix that holds the initial/default position & orientation
  523. Real m_instanceScale; ///< the uniform scale factor applied to the instance matrix before it is sent to W3D.
  524. DrawableInfo m_drawableInfo; ///< structure pointed to by W3D render objects so they know which drawable they belong to.
  525. ModelConditionFlags m_conditionState; ///< The Drawables current behavior state
  526. Real m_lastConstructDisplayed; ///< last construct percent used to make the string
  527. DisplayString* m_constructDisplayString; ///< string to display construction % complete
  528. DisplayString* m_captionDisplayString; ///< string to display caption
  529. DisplayString* m_groupNumber; ///< string to display the group number of this drawable
  530. UnsignedInt m_expirationDate; ///< if nonzero, Drawable should destroy itself at this frame
  531. DrawableIconInfo* m_iconInfo; ///< lazily allocated!
  532. Real m_heatVisionOpacity; ///< drawable draws for everybody in the heatvision special effect
  533. // --------- BYTE-SIZED THINGS GO HERE
  534. Byte m_selected; ///< drawable is selected or not
  535. Bool m_hidden; ///< drawable is "hidden" or not (overrides stealth effects)
  536. Bool m_hiddenByStealth; ///< drawable is hidden due to stealth
  537. Bool m_instanceIsIdentity; ///< If true, instance matrix can be skipped
  538. Bool m_drawableFullyObscuredByShroud; ///<drawable is hidden by shroud/fog
  539. #ifdef DIRTY_CONDITION_FLAGS
  540. mutable Bool m_isModelDirty; ///< if true, must call replaceModelConditionState() before drawing or accessing drawmodule info
  541. #endif
  542. //*******************************************
  543. //Perhaps we can move this out of Drawable???
  544. public:
  545. static void killStaticImages();
  546. #ifdef DIRTY_CONDITION_FLAGS
  547. // only for StDrawableDirtyStuffLocker!
  548. static void friend_lockDirtyStuffForIteration();
  549. static void friend_unlockDirtyStuffForIteration();
  550. #endif
  551. //For now, you can only have one emoticon at a time. Changing it will clear the previous one.
  552. void clearEmoticon();
  553. void setEmoticon( const AsciiString &name, Int duration );
  554. void drawUIText( void ); ///< draw the group number of this unit // public so gameclient can call
  555. private:
  556. // "icon" drawing methods **************
  557. void drawConstructPercent( const IRegion2D *healthBarRegion ); ///< display % construction complete
  558. void drawCaption( const IRegion2D *healthBarRegion ); ///< draw caption
  559. void drawAmmo( const IRegion2D *healthBarRegion ); ///< draw icons
  560. void drawContained( const IRegion2D *healthBarRegion ); ///< draw icons
  561. void drawVeterancy( const IRegion2D *healthBarRegion ); ///< draw veterency information
  562. void drawEmoticon( const IRegion2D* healthBarRegion );
  563. void drawHealthBar( const IRegion2D* healthBarRegion ); ///< draw heath bar
  564. void drawHealing( const IRegion2D* healthBarRegion ); ///< draw icons
  565. void drawEnthusiastic( const IRegion2D* healthBarRegin ); ///< draw icons
  566. #ifdef ALLOW_DEMORALIZE
  567. void drawDemoralized( const IRegion2D* healthBarRegion ); ///< draw icons
  568. #endif
  569. void drawBombed( const IRegion2D* healthBarRegion ); ///< draw icons
  570. void drawDisabled( const IRegion2D* healthBarRegion ); ///< draw icons
  571. void drawBattlePlans( const IRegion2D* healthBarRegion ); ///< Icons rendering for active battle plan statii
  572. Bool drawsAnyUIText( void );
  573. static Bool s_staticImagesInited;
  574. static const Image* s_veterancyImage[LEVEL_COUNT];
  575. static const Image* s_fullAmmo;
  576. static const Image* s_emptyAmmo;
  577. static const Image* s_fullContainer;
  578. static const Image* s_emptyContainer;
  579. static Anim2DTemplate** s_animationTemplates;
  580. #ifdef DIRTY_CONDITION_FLAGS
  581. static Int s_modelLockCount;
  582. #endif
  583. static void initStaticImages();
  584. //*******************************************
  585. };
  586. #ifdef DIRTY_CONDITION_FLAGS
  587. class StDrawableDirtyStuffLocker
  588. {
  589. public:
  590. StDrawableDirtyStuffLocker()
  591. {
  592. Drawable::friend_lockDirtyStuffForIteration();
  593. }
  594. ~StDrawableDirtyStuffLocker()
  595. {
  596. Drawable::friend_unlockDirtyStuffForIteration();
  597. }
  598. };
  599. #endif
  600. #endif // _DRAWABLE_H_