llvoavatarself.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /**
  2. * @file llvoavatarself.h
  3. * @brief Declaration of LLVOAvatarSelf class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVOAVATARSELF_H
  33. #define LL_LLVOAVATARSELF_H
  34. #include "llvoavatar.h"
  35. struct LocalTextureData;
  36. // Globals (see also gAgentAvatarp at the end of this file)
  37. extern bool gAttachmentsListDirty;
  38. extern LLFrameTimer gAttachmentsTimer;
  39. // Must be declared early since it is used in inlined methods below
  40. extern U32 gMaxSelfAttachments;
  41. constexpr F32 DEFAULT_ATTACHMENT_UPDATE_PERIOD = 0.1f;
  42. class LLVOAvatarSelf final : public LLVOAvatar
  43. {
  44. protected:
  45. LOG_CLASS(LLVOAvatarSelf);
  46. /******************************************************************************
  47. ** INITIALIZATION
  48. **/
  49. public:
  50. LLVOAvatarSelf(const LLUUID& id, LLViewerRegion* regionp);
  51. ~LLVOAvatarSelf() override;
  52. void markDead() override;
  53. // Called after construction to initialize the class.
  54. void initInstance() override;
  55. protected:
  56. bool loadAvatar() override;
  57. bool loadAvatarSelf();
  58. bool buildSkeletonSelf(const LLAvatarSkeletonInfo* info);
  59. bool buildMenus();
  60. /** Initialization
  61. ** **
  62. *****************************************************************************/
  63. /******************************************************************************
  64. ** INHERITED
  65. **/
  66. //-------------------------------------------------------------------------
  67. // LLViewerObject interface and related
  68. //-------------------------------------------------------------------------
  69. public:
  70. void onSimulatorFeaturesReceived(const LLUUID&);
  71. void updateRegion(LLViewerRegion* regionp) override;
  72. void idleUpdate(F64 time) override;
  73. //-------------------------------------------------------------------------
  74. // LLCharacter interface and related
  75. //-------------------------------------------------------------------------
  76. bool hasMotionFromSource(const LLUUID& source_id) override;
  77. void stopMotionFromSource(const LLUUID& source_id) override;
  78. void requestStopMotion(LLMotion* motion) override;
  79. LLJoint* getJoint(U32 key) override;
  80. bool setVisualParamWeight(const LLVisualParam* which_param, F32 weight,
  81. bool upload_bake = false) override;
  82. bool setVisualParamWeight(const char* param_name, F32 weight,
  83. bool upload_bake = false) override;
  84. bool setVisualParamWeight(S32 index, F32 weight,
  85. bool upload_bake = false) override;
  86. void writeWearablesToAvatar();
  87. void idleUpdateAppearanceAnimation() override;
  88. U32 processUpdateMessage(LLMessageSystem* mesgsys, void** user_data,
  89. U32 block_num, EObjectUpdateType upd_type,
  90. LLDataPacker* dp) override;
  91. #if 0
  92. void computeBodySize(bool force = false) override;
  93. #endif
  94. private:
  95. // helper function. Passed in param is assumed to be in avatar's parameter
  96. // list.
  97. bool setParamWeight(const LLViewerVisualParam* param, F32 weight,
  98. bool upload_bake = false);
  99. /*****************************************************************************/
  100. LLUUID mInitialBakeIDs[LLAvatarAppearanceDefines::BAKED_NUM_INDICES];
  101. bool mInitialBakesLoaded;
  102. /******************************************************************************
  103. ** STATE
  104. **/
  105. public:
  106. LL_INLINE bool isSelf() const override { return true; }
  107. // This is used only in LLDriverParam::setDrivenWeight(). HB
  108. bool isValid() const override;
  109. //-------------------------------------------------------------------------
  110. // Updates
  111. //-------------------------------------------------------------------------
  112. bool updateCharacter() override;
  113. void idleUpdateTractorBeam();
  114. //-------------------------------------------------------------------------
  115. // Loading state
  116. //-------------------------------------------------------------------------
  117. bool getIsCloud() override;
  118. //-------------------------------------------------------------------------
  119. // Region state
  120. //-------------------------------------------------------------------------
  121. LL_INLINE void resetRegionCrossingTimer() { mRegionCrossingTimer.reset(); }
  122. private:
  123. U64 mLastRegionHandle;
  124. LLFrameTimer mRegionCrossingTimer;
  125. S32 mRegionCrossingCount;
  126. /** State
  127. *****************************************************************************/
  128. /******************************************************************************
  129. ** RENDERING
  130. **/
  131. //-------------------------------------------------------------------------
  132. // Render beam
  133. //-------------------------------------------------------------------------
  134. protected:
  135. bool needsRenderBeam();
  136. private:
  137. LLPointer<LLHUDEffectSpiral> mBeam;
  138. LLFrameTimer mBeamTimer;
  139. boost::signals2::connection mTeleportFinishedSlot;
  140. public:
  141. void resetHUDAttachments();
  142. void refreshAttachments();
  143. void handleTeleportFinished();
  144. #if 0 // Empty
  145. LL_INLINE void rebuildHUD() {}
  146. #endif
  147. LL_INLINE bool isVisuallyMuted() override
  148. {
  149. return false;
  150. }
  151. LL_INLINE bool isImpostor() override { return false; }
  152. /** Rendering
  153. *****************************************************************************/
  154. /******************************************************************************
  155. ** TEXTURES
  156. **/
  157. //-------------------------------------------------------------------------
  158. // Loading status
  159. //-------------------------------------------------------------------------
  160. bool hasPendingBakedUploads();
  161. S32 getLocalDiscardLevel(LLAvatarAppearanceDefines::ETextureIndex type,
  162. U32 wearable_idx);
  163. bool areTexturesCurrent();
  164. bool isLocalTextureDataAvailable(LLViewerTexLayerSet* layersetp);
  165. bool isLocalTextureDataFinal(LLViewerTexLayerSet* layersetp);
  166. bool isBakedTextureFinal(LLAvatarAppearanceDefines::EBakedTextureIndex i);
  167. // If you want to check all textures of a given type, pass
  168. // gAgentWearables.getWearableCount() for index
  169. bool isTextureDefined(LLAvatarAppearanceDefines::ETextureIndex type,
  170. U32 index) const override;
  171. bool isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type,
  172. U32 index = 0) const override;
  173. bool isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type,
  174. LLViewerWearable* wearable) const override;
  175. //-------------------------------------------------------------------------
  176. // Local Textures
  177. //-------------------------------------------------------------------------
  178. LLViewerFetchedTexture* getLocalTextureGL(LLAvatarAppearanceDefines::ETextureIndex type,
  179. U32 index) const;
  180. const LLUUID& getLocalTextureID(LLAvatarAppearanceDefines::ETextureIndex type,
  181. U32 index) const;
  182. void setLocalTextureTE(U8 te, LLViewerTexture* texp, U32 index);
  183. void setLocalTexture(LLAvatarAppearanceDefines::ETextureIndex type,
  184. LLViewerTexture* texp, bool baked_version_exits,
  185. U32 index) override;
  186. protected:
  187. void setBakedReady(LLAvatarAppearanceDefines::ETextureIndex type,
  188. bool baked_version_exists, U32 index) override;
  189. void localTextureLoaded(bool succcess, LLViewerFetchedTexture* texp,
  190. LLImageRaw* src_imagep, LLImageRaw* aux_src_imagep,
  191. S32 discard_level, bool is_final, void* userdata);
  192. void getLocalTextureByteCount(S32* gl_byte_count);
  193. void addLocalTextureStats(LLAvatarAppearanceDefines::ETextureIndex i,
  194. LLViewerFetchedTexture* imagep,
  195. F32 texel_area_ratio, bool rendered,
  196. bool covered_by_baked) override;
  197. LLLocalTextureObject* getLocalTextureObject(LLAvatarAppearanceDefines::ETextureIndex i,
  198. U32 index) const;
  199. private:
  200. static void onLocalTextureLoaded(bool succcess,
  201. LLViewerFetchedTexture* texp,
  202. LLImageRaw* src_imagep,
  203. LLImageRaw* aux_src_imagep,
  204. S32 discard_level, bool is_final,
  205. void* userdata);
  206. void setImage(U8 te, LLViewerTexture* imagep, U32 index) override;
  207. LLViewerTexture* getImage(U8 te, U32 index) const override;
  208. //-------------------------------------------------------------------------
  209. // Baked textures
  210. //-------------------------------------------------------------------------
  211. public:
  212. LLAvatarAppearanceDefines::ETextureIndex getBakedTE(const LLViewerTexLayerSet* layerset) const;
  213. void setNewBakedTexture(LLAvatarAppearanceDefines::EBakedTextureIndex i,
  214. const LLUUID& uuid);
  215. void setNewBakedTexture(LLAvatarAppearanceDefines::ETextureIndex i,
  216. const LLUUID& uuid);
  217. void setCachedBakedTexture(LLAvatarAppearanceDefines::ETextureIndex i,
  218. const LLUUID& uuid);
  219. void forceBakeAllTextures(bool slam_for_debug = false);
  220. static void processRebakeAvatarTextures(LLMessageSystem* msg, void**);
  221. protected:
  222. void removeMissingBakedTextures() override;
  223. //-------------------------------------------------------------------------
  224. // Layers
  225. //-------------------------------------------------------------------------
  226. public:
  227. void requestLayerSetUploads();
  228. void requestLayerSetUpload(LLAvatarAppearanceDefines::EBakedTextureIndex i);
  229. void requestLayerSetUpdate(LLAvatarAppearanceDefines::ETextureIndex i);
  230. LLViewerTexLayerSet* getLayerSet(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index);
  231. LLViewerTexLayerSet* getLayerSet(LLAvatarAppearanceDefines::ETextureIndex index);
  232. //-------------------------------------------------------------------------
  233. // Composites
  234. //-------------------------------------------------------------------------
  235. void invalidateComposite(LLTexLayerSet* layerset, bool upload) override;
  236. void invalidateAll() override;
  237. void setCompositeUpdatesEnabled(bool b) override; // Only works for self
  238. void setCompositeUpdatesEnabled(U32 index, bool b) override;
  239. bool isCompositeUpdateEnabled(U32 index) override;
  240. void setupComposites();
  241. void updateComposites();
  242. const LLUUID& grabBakedTexture(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index) const;
  243. bool canGrabBakedTexture(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index) const;
  244. /** Textures
  245. *****************************************************************************/
  246. protected:
  247. void restoreMeshData() override;
  248. /******************************************************************************
  249. ** WEARABLES
  250. **/
  251. public:
  252. void wearableUpdated(LLWearableType::EType type, bool upload_result);
  253. protected:
  254. U32 getNumWearables(LLAvatarAppearanceDefines::ETextureIndex i) const;
  255. //-------------------------------------------------------------------------
  256. // Attachments
  257. //-------------------------------------------------------------------------
  258. public:
  259. void updateAttachmentVisibility(U32 camera_mode);
  260. bool isWearingAttachment(const LLUUID& inv_item_id) const;
  261. LLViewerObject* getWornAttachment(const LLUUID& inv_item_id);
  262. const std::string getAttachedPointName(const LLUUID& inv_item_id,
  263. bool translate = false) const;
  264. LL_INLINE bool canAttachMoreObjects() const
  265. {
  266. return getNumAttachments() < gMaxSelfAttachments;
  267. }
  268. LL_INLINE bool canAttachMoreObjects(U32 n) const
  269. {
  270. return getNumAttachments() + n <= gMaxSelfAttachments;
  271. }
  272. S32 getMaxAnimatedObjectAttachments() const override;
  273. const LLViewerJointAttachment* attachObject(LLViewerObject* vobj) override;
  274. bool detachObject(LLViewerObject* vobj) override;
  275. static bool detachAttachmentIntoInventory(const LLUUID& item_id);
  276. private:
  277. LLViewerJoint* mScreenp; // Special purpose joint for HUD attachments
  278. /** WEARABLES
  279. *****************************************************************************/
  280. /******************************************************************************
  281. ** ANIMATIONS
  282. **/
  283. public:
  284. void updateMotions(e_update_t update_type) override;
  285. void setAttachmentUpdatePeriod(F32 period_sec);
  286. LL_INLINE void setAttachmentUpdateEnabled(bool b)
  287. {
  288. mAttachmentUpdateEnabled = b;
  289. }
  290. LL_INLINE bool getAttachmentUpdateEnabled() const
  291. {
  292. return mAttachmentUpdateEnabled;
  293. }
  294. private:
  295. F32 mAttachmentUpdatePeriod; // In seconds
  296. F32 mAttachmentUpdateExpiry; // In seconds
  297. bool mAttachmentUpdateEnabled;
  298. /** ANIMATIONS
  299. *****************************************************************************/
  300. /******************************************************************************
  301. ** APPEARANCE
  302. **/
  303. public:
  304. static bool canUseServerBaking();
  305. static void onCustomizeStart();
  306. static void onCustomizeEnd();
  307. //-------------------------------------------------------------------------
  308. // Visibility
  309. //-------------------------------------------------------------------------
  310. public:
  311. void sendAppearanceMessage(LLMessageSystem* mesgsys) const;
  312. // Care and feeding of hover height.
  313. static bool useAvatarHoverHeight();
  314. void scheduleHoverUpdate();
  315. void setHoverOffset(const LLVector3& hover_offset,
  316. bool send_update = true) override;
  317. bool shouldRenderRigged() const override;
  318. public:
  319. LLTimer mOffsetUpdateDelay;
  320. private:
  321. void setHoverIfRegionEnabled();
  322. void sendHoverHeight() const;
  323. private:
  324. mutable LLVector3 mLastHoverOffsetSent;
  325. /** Appearance
  326. *****************************************************************************/
  327. /******************************************************************************
  328. ** DIAGNOSTICS
  329. **/
  330. public:
  331. static void dumpTotalLocalTextureByteCount();
  332. void dumpLocalTextures();
  333. struct LLAvatarTexData
  334. {
  335. LLAvatarTexData(const LLUUID& id,
  336. LLAvatarAppearanceDefines::ETextureIndex index)
  337. : mAvatarID(id),
  338. mIndex(index)
  339. {
  340. }
  341. LLUUID mAvatarID;
  342. LLAvatarAppearanceDefines::ETextureIndex mIndex;
  343. };
  344. };
  345. // Another global
  346. extern LLPointer<LLVOAvatarSelf> gAgentAvatarp;
  347. LL_INLINE bool isAgentAvatarValid()
  348. {
  349. return gAgentAvatarp.notNull() && !gAgentAvatarp->isDead() &&
  350. gAgentAvatarp->getRegion();
  351. }
  352. #endif // LL_VO_AVATARSELF_H