summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorBrad Payne (Vir Linden) <vir@lindenlab.com>2014-10-17 15:00:18 -0400
committerBrad Payne (Vir Linden) <vir@lindenlab.com>2014-10-17 15:00:18 -0400
commit5c8d902c1bab6f0577750e8e2470384a31880947 (patch)
tree19046e5cc3577deeda467004bc4f6af6151407c5 /indra
parentdc0abe48c624775f06cfebf1ea4d20222a7b7086 (diff)
SL-93 WIP - refactoring LLPosOverrideMap for reusability
Diffstat (limited to 'indra')
-rwxr-xr-xindra/llcharacter/lljoint.cpp88
-rwxr-xr-xindra/llcharacter/lljoint.h22
2 files changed, 80 insertions, 30 deletions
diff --git a/indra/llcharacter/lljoint.cpp b/indra/llcharacter/lljoint.cpp
index 7c75c4920f..5e54215739 100755
--- a/indra/llcharacter/lljoint.cpp
+++ b/indra/llcharacter/lljoint.cpp
@@ -36,18 +36,57 @@
S32 LLJoint::sNumUpdates = 0;
S32 LLJoint::sNumTouches = 0;
+template <class T>
+bool attachment_map_iter_compare_key(const T& a, const T& b)
+{
+ return a.first < b.first;
+}
-//-----------------------------------------------------------------------------
-// LLJoint::AttachmentOverrideRecord::AttachmentOverrideRecord()
-//-----------------------------------------------------------------------------
-LLJoint::AttachmentOverrideRecord::AttachmentOverrideRecord()
+bool LLPosOverrideMap::findActiveOverride(LLUUID& mesh_id, LLVector3& pos) const
{
+ pos = LLVector3(0,0,0);
+ mesh_id = LLUUID();
+ bool found = false;
+
+ map_type::const_iterator it = std::max_element(m_map.begin(),
+ m_map.end(),
+ attachment_map_iter_compare_key<map_type::value_type>);
+ if (it != m_map.end())
+ {
+ found = true;
+ pos = it->second;
+ mesh_id = it->first;
+ }
+ return found;
}
-template <class T>
-bool attachment_map_iter_compare_key(const T& a, const T& b)
+void LLPosOverrideMap::showJointPosOverrides( std::ostringstream& os ) const
{
- return a.first < b.first;
+ map_type::const_iterator max_it = std::max_element(m_map.begin(),
+ m_map.end(),
+ attachment_map_iter_compare_key<map_type::value_type>);
+ for (map_type::const_iterator it = m_map.begin();
+ it != m_map.end(); ++it)
+ {
+ const LLVector3& pos = it->second;
+ os << " " << "[" << it->first <<": " << pos << "]" << ((it==max_it) ? "*" : "");
+ }
+}
+
+U32 LLPosOverrideMap::count() const
+{
+ return m_map.size();
+}
+
+void LLPosOverrideMap::add(const LLUUID& mesh_id, const LLVector3& pos)
+{
+ m_map[mesh_id] = pos;
+}
+
+bool LLPosOverrideMap::remove(const LLUUID& mesh_id)
+{
+ U32 remove_count = m_map.erase(mesh_id);
+ return (remove_count > 0);
}
//-----------------------------------------------------------------------------
@@ -254,6 +293,14 @@ void LLJoint::setPosition( const LLVector3& pos )
touch(MATRIX_DIRTY | POSITION_DIRTY);
}
+void showJointPosOverrides( const LLJoint& joint, const std::string& note, const std::string& av_info )
+{
+ std::ostringstream os;
+ os << joint.m_posBeforeOverrides;
+ joint.m_attachmentOverrides.showJointPosOverrides(os);
+ LL_DEBUGS("Avatar") << av_info << " joint " << joint.getName() << " " << note << " " << os.str() << LL_ENDL;
+}
+
//--------------------------------------------------------------------
// addAttachmentPosOverride()
//--------------------------------------------------------------------
@@ -263,14 +310,12 @@ void LLJoint::addAttachmentPosOverride( const LLVector3& pos, const LLUUID& mesh
{
return;
}
- if (m_attachmentOverrides.empty())
+ if (!m_attachmentOverrides.count())
{
LL_DEBUGS("Avatar") << "av " << av_info << " joint " << getName() << " saving m_posBeforeOverrides " << getPosition() << LL_ENDL;
m_posBeforeOverrides = getPosition();
}
- AttachmentOverrideRecord rec;
- rec.pos = pos;
- m_attachmentOverrides[mesh_id] = rec;
+ m_attachmentOverrides.add(mesh_id,pos);
LL_DEBUGS("Avatar") << "av " << av_info << " joint " << getName() << " addAttachmentPosOverride for mesh " << mesh_id << " pos " << pos << LL_ENDL;
updatePos(av_info);
}
@@ -284,11 +329,11 @@ void LLJoint::removeAttachmentPosOverride( const LLUUID& mesh_id, const std::str
{
return;
}
- attachment_map_t::iterator it = m_attachmentOverrides.find(mesh_id);
- if (it != m_attachmentOverrides.end())
+ if (m_attachmentOverrides.remove(mesh_id))
{
- LL_DEBUGS("Avatar") << "av " << av_info << " joint " << getName() << " removeAttachmentPosOverride for " << mesh_id << LL_ENDL;
- m_attachmentOverrides.erase(it);
+ LL_DEBUGS("Avatar") << "av " << av_info << " joint " << getName()
+ << " removeAttachmentPosOverride for " << mesh_id << LL_ENDL;
+ showJointPosOverrides(*this, "remove", av_info);
updatePos(av_info);
}
@@ -299,15 +344,12 @@ void LLJoint::removeAttachmentPosOverride( const LLUUID& mesh_id, const std::str
//--------------------------------------------------------------------
void LLJoint::updatePos(const std::string& av_info)
{
- LLVector3 pos;
- attachment_map_t::iterator it = std::max_element(m_attachmentOverrides.begin(),
- m_attachmentOverrides.end(),
- attachment_map_iter_compare_key<LLJoint::attachment_map_t::value_type>);
- if (it != m_attachmentOverrides.end())
+ LLVector3 pos, found_pos;
+ LLUUID mesh_id;
+ if (m_attachmentOverrides.findActiveOverride(mesh_id,found_pos))
{
- AttachmentOverrideRecord& rec = it->second;
- LL_DEBUGS("Avatar") << "av " << av_info << " joint " << getName() << " updatePos, winner of " << m_attachmentOverrides.size() << " is mesh " << it->first << " pos " << rec.pos << LL_ENDL;
- pos = rec.pos;
+ LL_DEBUGS("Avatar") << "av " << av_info << " joint " << getName() << " updatePos, winner of " << m_attachmentOverrides.count() << " is mesh " << mesh_id << " pos " << found_pos << LL_ENDL;
+ pos = found_pos;
}
else
{
diff --git a/indra/llcharacter/lljoint.h b/indra/llcharacter/lljoint.h
index 951cafad94..f8639af3de 100755
--- a/indra/llcharacter/lljoint.h
+++ b/indra/llcharacter/lljoint.h
@@ -46,6 +46,20 @@ const U32 LL_FACE_JOINT_NUM = 30;
const S32 LL_CHARACTER_MAX_PRIORITY = 7;
const F32 LL_MAX_PELVIS_OFFSET = 5.f;
+class LLPosOverrideMap
+{
+public:
+ LLPosOverrideMap() {}
+ bool findActiveOverride(LLUUID& mesh_id, LLVector3& pos) const;
+ void showJointPosOverrides(std::ostringstream& os) const;
+ U32 count() const;
+ void add(const LLUUID& mesh_id, const LLVector3& pos);
+ bool remove(const LLUUID& mesh_id);
+private:
+ typedef std::map<LLUUID,LLVector3> map_type;
+ map_type m_map;
+};
+
//-----------------------------------------------------------------------------
// class LLJoint
//-----------------------------------------------------------------------------
@@ -99,13 +113,7 @@ public:
static S32 sNumTouches;
static S32 sNumUpdates;
- struct AttachmentOverrideRecord
- {
- AttachmentOverrideRecord();
- LLVector3 pos;
- };
- typedef std::map<LLUUID,AttachmentOverrideRecord> attachment_map_t;
- attachment_map_t m_attachmentOverrides;
+ LLPosOverrideMap m_attachmentOverrides;
LLVector3 m_posBeforeOverrides;
void updatePos(const std::string& av_info);