summaryrefslogtreecommitdiff
path: root/indra/llcharacter
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcharacter')
-rw-r--r--indra/llcharacter/llbvhloader.cpp6
-rw-r--r--indra/llcharacter/llbvhloader.h2
-rw-r--r--indra/llcharacter/llcharacter.cpp30
-rw-r--r--indra/llcharacter/llcharacter.h24
-rw-r--r--indra/llcharacter/lljoint.cpp20
-rw-r--r--indra/llcharacter/lljoint.h2
-rw-r--r--indra/llcharacter/llkeyframemotion.cpp35
-rw-r--r--indra/llcharacter/llkeyframewalkmotion.cpp2
8 files changed, 61 insertions, 60 deletions
diff --git a/indra/llcharacter/llbvhloader.cpp b/indra/llcharacter/llbvhloader.cpp
index 9dace08e6f..581e9f62d5 100644
--- a/indra/llcharacter/llbvhloader.cpp
+++ b/indra/llcharacter/llbvhloader.cpp
@@ -131,7 +131,7 @@ LLQuaternion::Order bvhStringToOrder( char *str )
// LLBVHLoader()
//-----------------------------------------------------------------------------
-LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string>& joint_alias_map )
+LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string, std::less<>>& joint_alias_map )
{
reset();
errorLine = 0;
@@ -156,9 +156,9 @@ LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &error
}
// Recognize all names we've been told are legal.
- for (std::map<std::string, std::string>::value_type& alias_pair : joint_alias_map)
+ for (const auto& [alias, joint] : joint_alias_map)
{
- makeTranslation( alias_pair.first , alias_pair.second );
+ makeTranslation(alias, joint);
}
char error_text[128]; /* Flawfinder: ignore */
diff --git a/indra/llcharacter/llbvhloader.h b/indra/llcharacter/llbvhloader.h
index de31f76dd3..ae2e347ba1 100644
--- a/indra/llcharacter/llbvhloader.h
+++ b/indra/llcharacter/llbvhloader.h
@@ -227,7 +227,7 @@ class LLBVHLoader
friend class LLKeyframeMotion;
public:
// Constructor
- LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string>& joint_alias_map );
+ LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string, std::less<>>& joint_alias_map );
~LLBVHLoader();
/*
diff --git a/indra/llcharacter/llcharacter.cpp b/indra/llcharacter/llcharacter.cpp
index 264b9a0be1..8efcd9dd29 100644
--- a/indra/llcharacter/llcharacter.cpp
+++ b/indra/llcharacter/llcharacter.cpp
@@ -38,7 +38,7 @@
LLStringTable LLCharacter::sVisualParamNames(1024);
-std::vector< LLCharacter* > LLCharacter::sInstances;
+std::list< LLCharacter* > LLCharacter::sInstances;
bool LLCharacter::sAllowInstancesChange = true ;
//-----------------------------------------------------------------------------
@@ -53,7 +53,6 @@ LLCharacter::LLCharacter()
mSkeletonSerialNum( 0 )
{
llassert_always(sAllowInstancesChange) ;
- sInstances.push_back(this);
mMotionController.setCharacter( this );
mPauseRequest = new LLPauseRequestHandle();
@@ -66,40 +65,23 @@ LLCharacter::LLCharacter()
//-----------------------------------------------------------------------------
LLCharacter::~LLCharacter()
{
- for (LLVisualParam *param = getFirstVisualParam();
- param;
- param = getNextVisualParam())
+ for (const auto& it : mVisualParamIndexMap)
{
- delete param;
+ delete it.second;
}
- size_t i ;
- size_t size = sInstances.size() ;
- for(i = 0 ; i < size ; i++)
- {
- if(sInstances[i] == this)
- {
- break ;
- }
- }
-
- llassert_always(i < size) ;
-
llassert_always(sAllowInstancesChange) ;
- sInstances[i] = sInstances[size - 1] ;
- sInstances.pop_back() ;
}
//-----------------------------------------------------------------------------
// getJoint()
//-----------------------------------------------------------------------------
-LLJoint *LLCharacter::getJoint( const std::string &name )
+LLJoint* LLCharacter::getJoint(std::string_view name)
{
- LLJoint* joint = NULL;
+ LLJoint* joint = nullptr;
- LLJoint *root = getRootJoint();
- if (root)
+ if (LLJoint* root = getRootJoint())
{
joint = root->findJoint(name);
}
diff --git a/indra/llcharacter/llcharacter.h b/indra/llcharacter/llcharacter.h
index b390960a75..079bcd132a 100644
--- a/indra/llcharacter/llcharacter.h
+++ b/indra/llcharacter/llcharacter.h
@@ -76,7 +76,7 @@ public:
// get the specified joint
// default implementation does recursive search,
// subclasses may optimize/cache results.
- virtual LLJoint *getJoint( const std::string &name );
+ virtual LLJoint* getJoint(std::string_view name);
// get the position of the character
virtual LLVector3 getCharacterPosition() = 0;
@@ -119,6 +119,8 @@ public:
virtual void addDebugText( const std::string& text ) = 0;
+ virtual std::string getDebugName() const { return getID().asString(); }
+
virtual const LLUUID& getID() const = 0;
//-------------------------------------------------------------------------
// End Interface
@@ -245,6 +247,24 @@ public:
S32 getVisualParamCount() const { return (S32)mVisualParamIndexMap.size(); }
LLVisualParam* getVisualParam(const char *name);
+ void animateTweakableVisualParams(F32 delta)
+ {
+ for (auto& it : mVisualParamIndexMap)
+ {
+ if (it.second->isTweakable())
+ {
+ it.second->animate(delta);
+ }
+ }
+ }
+
+ void applyAllVisualParams(ESex avatar_sex)
+ {
+ for (auto& it : mVisualParamIndexMap)
+ {
+ it.second->apply(avatar_sex);
+ }
+ }
ESex getSex() const { return mSex; }
void setSex( ESex sex ) { mSex = sex; }
@@ -255,7 +275,7 @@ public:
U32 getSkeletonSerialNum() const { return mSkeletonSerialNum; }
void setSkeletonSerialNum( U32 num ) { mSkeletonSerialNum = num; }
- static std::vector< LLCharacter* > sInstances;
+ static std::list< LLCharacter* > sInstances;
static bool sAllowInstancesChange ; //debug use
virtual void setHoverOffset(const LLVector3& hover_offset, bool send_update=true) { mHoverOffset = hover_offset; }
diff --git a/indra/llcharacter/lljoint.cpp b/indra/llcharacter/lljoint.cpp
index c2a10d969f..405e62a38b 100644
--- a/indra/llcharacter/lljoint.cpp
+++ b/indra/llcharacter/lljoint.cpp
@@ -32,7 +32,6 @@
#include "lljoint.h"
#include "llmath.h"
-#include "llcallstack.h"
#include <boost/algorithm/string.hpp>
S32 LLJoint::sNumUpdates = 0;
@@ -243,21 +242,20 @@ LLJoint *LLJoint::getRoot()
//-----------------------------------------------------------------------------
// findJoint()
//-----------------------------------------------------------------------------
-LLJoint *LLJoint::findJoint( const std::string &name )
+LLJoint* LLJoint::findJoint(std::string_view name)
{
if (name == getName())
return this;
for (LLJoint* joint : mChildren)
{
- LLJoint *found = joint->findJoint(name);
- if (found)
+ if (LLJoint* found = joint->findJoint(name))
{
return found;
}
}
- return NULL;
+ return nullptr;
}
@@ -342,7 +340,6 @@ void LLJoint::setPosition( const LLVector3& requested_pos, bool apply_attachment
{
if (pos != active_override && do_debug_joint(getName()))
{
- LLScopedContextString str("setPosition");
LL_DEBUGS("Avatar") << " joint " << getName() << " requested_pos " << requested_pos
<< " overriden by attachment " << active_override << LL_ENDL;
}
@@ -350,12 +347,7 @@ void LLJoint::setPosition( const LLVector3& requested_pos, bool apply_attachment
}
if ((pos != getPosition()) && do_debug_joint(getName()))
{
- LLScopedContextString str("setPosition");
- LLCallStack cs;
- LLContextStatus con_status;
LL_DEBUGS("Avatar") << " joint " << getName() << " set pos " << pos << LL_ENDL;
- LL_DEBUGS("Avatar") << "CONTEXT:\n" << "====================\n" << con_status << "====================" << LL_ENDL;
- LL_DEBUGS("Avatar") << "STACK:\n" << "====================\n" << cs << "====================" << LL_ENDL;
}
if (pos != getPosition())
{
@@ -879,7 +871,6 @@ void LLJoint::setScale( const LLVector3& requested_scale, bool apply_attachment_
{
if (scale != active_override && do_debug_joint(getName()))
{
- LLScopedContextString str("setScale");
LL_DEBUGS("Avatar") << " joint " << getName() << " requested_scale " << requested_scale
<< " overriden by attachment " << active_override << LL_ENDL;
}
@@ -887,12 +878,7 @@ void LLJoint::setScale( const LLVector3& requested_scale, bool apply_attachment_
}
if ((mXform.getScale() != scale) && do_debug_joint(getName()))
{
- LLScopedContextString str("setScale");
- LLCallStack cs;
- LLContextStatus con_status;
LL_DEBUGS("Avatar") << " joint " << getName() << " set scale " << scale << LL_ENDL;
- LL_DEBUGS("Avatar") << "CONTEXT:\n" << "====================\n" << con_status << LL_ENDL;
- LL_DEBUGS("Avatar") << "STACK:\n" << "====================\n" << cs << "====================" << LL_ENDL;
}
mXform.setScale(scale);
touch();
diff --git a/indra/llcharacter/lljoint.h b/indra/llcharacter/lljoint.h
index 763c1e3865..b58dc797f8 100644
--- a/indra/llcharacter/lljoint.h
+++ b/indra/llcharacter/lljoint.h
@@ -222,7 +222,7 @@ public:
LLJoint *getRoot();
// search for child joints by name
- LLJoint *findJoint( const std::string &name );
+ LLJoint* findJoint(std::string_view name);
// add/remove children
void addChild( LLJoint *joint );
diff --git a/indra/llcharacter/llkeyframemotion.cpp b/indra/llcharacter/llkeyframemotion.cpp
index 12212efb66..b82734615f 100644
--- a/indra/llcharacter/llkeyframemotion.cpp
+++ b/indra/llcharacter/llkeyframemotion.cpp
@@ -2227,7 +2227,12 @@ bool LLKeyframeMotion::dumpToFile(const std::string& name)
}
S32 file_size = getFileSize();
- U8* buffer = new U8[file_size];
+ U8* buffer = new(std::nothrow) U8[file_size];
+ if (!buffer)
+ {
+ LLError::LLUserWarningMsg::showOutOfMemory();
+ LL_ERRS() << "Bad memory allocation for buffer, file: " << name << " " << file_size << LL_ENDL;
+ }
LL_DEBUGS("BVH") << "Dumping " << outfilename << LL_ENDL;
LLDataPackerBinaryBuffer dp(buffer, file_size);
@@ -2407,13 +2412,10 @@ void LLKeyframeMotion::onLoadComplete(const LLUUID& asset_uuid,
{
LLUUID* id = (LLUUID*)user_data;
- std::vector<LLCharacter* >::iterator char_iter = LLCharacter::sInstances.begin();
-
- while(char_iter != LLCharacter::sInstances.end() &&
- (*char_iter)->getID() != *id)
- {
- ++char_iter;
- }
+ auto char_iter = std::find_if(LLCharacter::sInstances.begin(), LLCharacter::sInstances.end(), [&](LLCharacter* c)
+ {
+ return c->getID() == *id;
+ });
delete id;
@@ -2425,9 +2427,15 @@ void LLKeyframeMotion::onLoadComplete(const LLUUID& asset_uuid,
LLCharacter* character = *char_iter;
// look for an existing instance of this motion
- LLKeyframeMotion* motionp = static_cast<LLKeyframeMotion*> (character->findMotion(asset_uuid));
- if (motionp)
+ if (LLMotion* asset = character->findMotion(asset_uuid))
{
+ LLKeyframeMotion* motionp = dynamic_cast<LLKeyframeMotion*>(asset);
+ if (!motionp)
+ {
+ // This motion is not LLKeyframeMotion (e.g., LLEmote)
+ return;
+ }
+
if (0 == status)
{
if (motionp->mAssetStatus == ASSET_LOADED)
@@ -2438,7 +2446,12 @@ void LLKeyframeMotion::onLoadComplete(const LLUUID& asset_uuid,
LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
S32 size = file.getSize();
- U8* buffer = new U8[size];
+ U8* buffer = new(std::nothrow) U8[size];
+ if (!buffer)
+ {
+ LLError::LLUserWarningMsg::showOutOfMemory();
+ LL_ERRS() << "Bad memory allocation for buffer of size: " << size << LL_ENDL;
+ }
file.read((U8*)buffer, size); /*Flawfinder: ignore*/
LL_DEBUGS("Animation") << "Loading keyframe data for: " << motionp->getName() << ":" << motionp->getID() << " (" << size << " bytes)" << LL_ENDL;
diff --git a/indra/llcharacter/llkeyframewalkmotion.cpp b/indra/llcharacter/llkeyframewalkmotion.cpp
index 605e15f442..f8691b5f59 100644
--- a/indra/llcharacter/llkeyframewalkmotion.cpp
+++ b/indra/llcharacter/llkeyframewalkmotion.cpp
@@ -383,7 +383,7 @@ bool LLFlyAdjustMotion::onUpdate(F32 time, U8* joint_mask)
F32 target_roll = llclamp(ang_vel.mV[VZ], -4.f, 4.f) * roll_factor;
// roll is critically damped interpolation between current roll and angular velocity-derived target roll
- mRoll = LLSmoothInterpolation::lerp(mRoll, target_roll, U32Milliseconds(100));
+ mRoll = LLSmoothInterpolation::lerp(mRoll, target_roll, F32Milliseconds(100.f));
LLQuaternion roll(mRoll, LLVector3(0.f, 0.f, 1.f));
mPelvisState->setRotation(roll);