summaryrefslogtreecommitdiff
path: root/indra/newview/llvoavatarself.h
blob: 77556c8412e9d81b16af9a58bd50c6e5fd9f5c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/**
 * @file llvoavatarself.h
 * @brief Declaration of LLVOAvatar class which is a derivation fo
 * LLViewerObject
 *
 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#ifndef LL_LLVOAVATARSELF_H
#define LL_LLVOAVATARSELF_H

#include "llviewertexture.h"
#include "llvoavatar.h"
#include <map>
#include "lleventcoro.h"
#include "llcoros.h"

struct LocalTextureData;
class LLInventoryCallback;


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// LLVOAvatarSelf
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLVOAvatarSelf :
    public LLVOAvatar
{
    LOG_CLASS(LLVOAvatarSelf);

/********************************************************************************
 **                                                                            **
 **                    INITIALIZATION
 **/

public:
    LLVOAvatarSelf(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
    virtual                 ~LLVOAvatarSelf();
    virtual void            markDead();
    virtual void            initInstance(); // Called after construction to initialize the class.
    void                    cleanup();
protected:
    /*virtual*/ bool        loadAvatar();
    bool                    loadAvatarSelf();
    bool                    buildSkeletonSelf(const LLAvatarSkeletonInfo *info);
    bool                    buildMenus();

/**                    Initialization
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    INHERITED
 **/

    //--------------------------------------------------------------------
    // LLViewerObject interface and related
    //--------------------------------------------------------------------
public:
    boost::signals2::connection                   mRegionChangedSlot;

    void                    onSimulatorFeaturesReceived(const LLUUID& region_id);
    /*virtual*/ void        updateRegion(LLViewerRegion *regionp);
    /*virtual*/ void        idleUpdate(LLAgent &agent, const F64 &time);

    //--------------------------------------------------------------------
    // LLCharacter interface and related
    //--------------------------------------------------------------------
public:
    /*virtual*/ bool        hasMotionFromSource(const LLUUID& source_id);
    /*virtual*/ void        stopMotionFromSource(const LLUUID& source_id);
    /*virtual*/ void        requestStopMotion(LLMotion* motion);
    /*virtual*/ LLJoint*    getJoint(const std::string &name);

    /*virtual*/ bool setVisualParamWeight(const LLVisualParam *which_param, F32 weight);
    /*virtual*/ bool setVisualParamWeight(const char* param_name, F32 weight);
    /*virtual*/ bool setVisualParamWeight(S32 index, F32 weight);
    /*virtual*/ void updateVisualParams();
    void writeWearablesToAvatar();
    /*virtual*/ void idleUpdateAppearanceAnimation();

private:
    // helper function. Passed in param is assumed to be in avatar's parameter list.
    bool setParamWeight(const LLViewerVisualParam *param, F32 weight);

/********************************************************************************
 **                                                                            **
 **                    STATE
 **/

public:
    /*virtual*/ bool    isSelf() const { return true; }
        virtual bool    isBuddy() const { return false; }
    /*virtual*/ bool    isValid() const;

    //--------------------------------------------------------------------
    // Updates
    //--------------------------------------------------------------------
public:
    /*virtual*/ bool    updateCharacter(LLAgent &agent);
    /*virtual*/ void    idleUpdateTractorBeam();
    bool                checkStuckAppearance();

    //--------------------------------------------------------------------
    // Loading state
    //--------------------------------------------------------------------
public:
    /*virtual*/ bool    getIsCloud() const;

    //--------------------------------------------------------------------
    // Region state
    //--------------------------------------------------------------------
    void            resetRegionCrossingTimer()  { mRegionCrossingTimer.reset(); }

private:
    U64             mLastRegionHandle;
    LLFrameTimer    mRegionCrossingTimer;
    S32             mRegionCrossingCount;

/**                    State
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    RENDERING
 **/

    //--------------------------------------------------------------------
    // Render beam
    //--------------------------------------------------------------------
protected:
    bool        needsRenderBeam();
private:
    LLPointer<LLHUDEffectSpiral> mBeam;
    LLFrameTimer mBeamTimer;

    //--------------------------------------------------------------------
    // LLVOAvatar Constants
    //--------------------------------------------------------------------
public:
    /*virtual*/ LLViewerTexture::EBoostLevel    getAvatarBoostLevel() const { return LLGLTexture::BOOST_AVATAR_SELF; }
    /*virtual*/ LLViewerTexture::EBoostLevel    getAvatarBakedBoostLevel() const { return LLGLTexture::BOOST_AVATAR_BAKED_SELF; }
    /*virtual*/ S32                         getTexImageSize() const { return LLVOAvatar::getTexImageSize()*4; }

/**                    Rendering
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    TEXTURES
 **/

    //--------------------------------------------------------------------
    // Loading status
    //--------------------------------------------------------------------
public:
    S32                 getLocalDiscardLevel(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const;
    bool                areTexturesCurrent() const;
    bool                isLocalTextureDataAvailable(const LLViewerTexLayerSet* layerset) const;
    bool                isLocalTextureDataFinal(const LLViewerTexLayerSet* layerset) const;
    // If you want to check all textures of a given type, pass gAgentWearables.getWearableCount() for index
    /*virtual*/ bool    isTextureDefined(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const;
    /*virtual*/ bool    isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type, U32 index = 0) const;
    /*virtual*/ bool    isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type, LLViewerWearable *wearable) const;


    //--------------------------------------------------------------------
    // Local Textures
    //--------------------------------------------------------------------
public:
    bool                getLocalTextureGL(LLAvatarAppearanceDefines::ETextureIndex type, LLViewerTexture** image_gl_pp, U32 index) const;
    LLViewerFetchedTexture* getLocalTextureGL(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const;
    const LLUUID&       getLocalTextureID(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const;
    void                setLocalTextureTE(U8 te, LLViewerTexture* image, U32 index);
    /*virtual*/ void    setLocalTexture(LLAvatarAppearanceDefines::ETextureIndex type, LLViewerTexture* tex, bool baked_version_exits, U32 index);
protected:
    /*virtual*/ void    setBakedReady(LLAvatarAppearanceDefines::ETextureIndex type, bool baked_version_exists, U32 index);
    void                localTextureLoaded(bool succcess, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, bool final, void* userdata);
    void                getLocalTextureByteCount(S32* gl_byte_count) const;
    /*virtual*/ void    addLocalTextureStats(LLAvatarAppearanceDefines::ETextureIndex i, LLViewerFetchedTexture* imagep, F32 texel_area_ratio, bool rendered, bool covered_by_baked);
    LLLocalTextureObject* getLocalTextureObject(LLAvatarAppearanceDefines::ETextureIndex i, U32 index) const;

private:
    static void         onLocalTextureLoaded(bool succcess, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, bool final, void* userdata);

    /*virtual*/ void    setImage(const U8 te, LLViewerTexture *imagep, const U32 index);
    /*virtual*/ LLViewerTexture* getImage(const U8 te, const U32 index) const;


    //--------------------------------------------------------------------
    // Baked textures
    //--------------------------------------------------------------------
public:
    LLAvatarAppearanceDefines::ETextureIndex getBakedTE(const LLViewerTexLayerSet* layerset ) const;
    // SUNSHINE CLEANUP - dead? or update to just call request appearance update?
    void                forceBakeAllTextures(bool slam_for_debug = false);
protected:
    /*virtual*/ void    removeMissingBakedTextures();

    //--------------------------------------------------------------------
    // Layers
    //--------------------------------------------------------------------
public:
    void                requestLayerSetUpdate(LLAvatarAppearanceDefines::ETextureIndex i);
    LLViewerTexLayerSet* getLayerSet(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index) const;
    LLViewerTexLayerSet* getLayerSet(LLAvatarAppearanceDefines::ETextureIndex index) const;


    //--------------------------------------------------------------------
    // Composites
    //--------------------------------------------------------------------
public:
    /* virtual */ void  invalidateComposite(LLTexLayerSet* layerset);
    /* virtual */ void  invalidateAll();
    /* virtual */ void  setCompositeUpdatesEnabled(bool b); // only works for self
    /* virtual */ void  setCompositeUpdatesEnabled(U32 index, bool b);
    /* virtual */ bool  isCompositeUpdateEnabled(U32 index);
    void                setupComposites();
    void                updateComposites();

    const LLUUID&       grabBakedTexture(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index) const;
    bool                canGrabBakedTexture(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index) const;


    //--------------------------------------------------------------------
    // Scratch textures (used for compositing)
    //--------------------------------------------------------------------
public:
    static void     deleteScratchTextures();
private:
    static S32Bytes sScratchTexBytes;
    static std::map< LLGLenum, LLGLuint*> sScratchTexNames;

/**                    Textures
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    MESHES
 **/
protected:
    /*virtual*/ void   restoreMeshData();

/**                    Meshes
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    WEARABLES
 **/

public:
    void                wearableUpdated(LLWearableType::EType type);
protected:
    U32 getNumWearables(LLAvatarAppearanceDefines::ETextureIndex i) const;

    //--------------------------------------------------------------------
    // Attachments
    //--------------------------------------------------------------------
public:
    void                updateAttachmentVisibility(U32 camera_mode);
    bool                isWearingAttachment(const LLUUID& inv_item_id) const;
    LLViewerObject*     getWornAttachment(const LLUUID& inv_item_id);
    bool                getAttachedPointName(const LLUUID& inv_item_id, std::string& name) const;
    /*virtual*/ const LLViewerJointAttachment *attachObject(LLViewerObject *viewer_object);
    /*virtual*/ bool    detachObject(LLViewerObject *viewer_object);
    static bool         detachAttachmentIntoInventory(const LLUUID& item_id);

    bool hasAttachmentsInTrash();

    //--------------------------------------------------------------------
    // HUDs
    //--------------------------------------------------------------------
private:
    LLViewerJoint*      mScreenp; // special purpose joint for HUD attachments

/**                    Attachments
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    APPEARANCE
 **/

public:
    static void     onCustomizeStart(bool disable_camera_switch = false);
    static void     onCustomizeEnd(bool disable_camera_switch = false);
    LLPointer<LLInventoryCallback> mEndCustomizeCallback;

    //--------------------------------------------------------------------
    // Visibility
    //--------------------------------------------------------------------

    /* virtual */ bool shouldRenderRigged() const;

public:
    bool            sendAppearanceMessage(LLMessageSystem *mesgsys) const;

    // -- care and feeding of hover height.
    void            setHoverIfRegionEnabled();
    void            sendHoverHeight() const;
    /*virtual*/ void setHoverOffset(const LLVector3& hover_offset, bool send_update=true);

private:
    mutable LLVector3 mLastHoverOffsetSent;

/**                    Appearance
 **                                                                            **
 *******************************************************************************/

/********************************************************************************
 **                                                                            **
 **                    DIAGNOSTICS
 **/

    //--------------------------------------------------------------------
    // General
    //--------------------------------------------------------------------
public:
    static void     dumpTotalLocalTextureByteCount();
    void            dumpLocalTextures() const;
    static void     dumpScratchTextureByteCount();
    void            dumpWearableInfo(LLAPRFile& outfile);

    //--------------------------------------------------------------------
    // Avatar Rez Metrics
    //--------------------------------------------------------------------
public:
    struct LLAvatarTexData
    {
        LLAvatarTexData(const LLUUID& id, LLAvatarAppearanceDefines::ETextureIndex index) :
            mAvatarID(id),
            mIndex(index)
        {}
        LLUUID          mAvatarID;
        LLAvatarAppearanceDefines::ETextureIndex    mIndex;
    };

    LLTimer                 mTimeSinceLastRezMessage;
    bool                    updateAvatarRezMetrics(bool force_send);

    std::vector<LLSD>       mPendingTimerRecords;
    void                    addMetricsTimerRecord(const LLSD& record);

    void                    debugWearablesLoaded() { mDebugTimeWearablesLoaded = mDebugSelfLoadTimer.getElapsedTimeF32(); }
    void                    debugAvatarVisible() { mDebugTimeAvatarVisible = mDebugSelfLoadTimer.getElapsedTimeF32(); }
    void                    outputRezDiagnostics() const;
    void                    outputRezTiming(const std::string& msg) const;
    void                    reportAvatarRezTime() const;
    void                    debugBakedTextureUpload(LLAvatarAppearanceDefines::EBakedTextureIndex index, bool finished);
    static void             debugOnTimingLocalTexLoaded(bool success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, bool final, void* userdata);

    bool                    isAllLocalTextureDataFinal() const;

    const LLViewerTexLayerSet*  debugGetLayerSet(LLAvatarAppearanceDefines::EBakedTextureIndex index) const { return (LLViewerTexLayerSet*)(mBakedTextureDatas[index].mTexLayerSet); }
    const std::string       verboseDebugDumpLocalTextureDataInfo(const LLViewerTexLayerSet* layerset) const; // Lists out state of this particular baked texture layer
    void                    dumpAllTextures() const;
    const std::string       debugDumpLocalTextureDataInfo(const LLViewerTexLayerSet* layerset) const; // Lists out state of this particular baked texture layer
    const std::string       debugDumpAllLocalTextureDataInfo() const; // Lists out which baked textures are at highest LOD
    void                    sendViewerAppearanceChangeMetrics(); // send data associated with completing a change.
private:
    LLFrameTimer            mDebugSelfLoadTimer;
    F32                     mDebugTimeWearablesLoaded;
    F32                     mDebugTimeAvatarVisible;
    F32                     mDebugTextureLoadTimes[LLAvatarAppearanceDefines::TEX_NUM_INDICES][MAX_DISCARD_LEVEL+1]; // load time for each texture at each discard level
    F32                     mDebugBakedTextureTimes[LLAvatarAppearanceDefines::BAKED_NUM_INDICES][2]; // time to start upload and finish upload of each baked texture
    void                    debugTimingLocalTexLoaded(bool success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, bool final, void* userdata);

    void                    appearanceChangeMetricsCoro(std::string url);
    bool                    mInitialMetric;
    S32                     mMetricSequence;
/**                    Diagnostics
 **                                                                            **
 *******************************************************************************/

};

extern LLPointer<LLVOAvatarSelf> gAgentAvatarp;

bool isAgentAvatarValid();

void selfStartPhase(const std::string& phase_name);
void selfStopPhase(const std::string& phase_name, bool err_check = true);
void selfClearPhases();

#endif // LL_VO_AVATARSELF_H