Harmless Alchemy sync

CachedControls, autos, cleaner loops, remove overkill dynamic cast,
and override and final
This commit is contained in:
Liru Færs
2020-01-04 21:43:10 -05:00
parent dec0bff972
commit e81affce51
4 changed files with 93 additions and 111 deletions

View File

@@ -47,8 +47,8 @@ LLControlAvatar::LLControlAvatar(const LLUUID& id, const LLPCode pcode, LLViewer
LLVOAvatar(id, pcode, regionp),
mPlaying(false),
mGlobalScale(1.0f),
mRootVolp(NULL),
mMarkedForDeath(false),
mRootVolp(NULL),
mScaleConstraintFixup(1.0),
mRegionChanged(false)
{
@@ -60,6 +60,8 @@ LLControlAvatar::LLControlAvatar(const LLUUID& id, const LLPCode pcode, LLViewer
// virtual
LLControlAvatar::~LLControlAvatar()
{
// Should already have been unlinked before destruction
llassert(!mRootVolp);
}
// virtual
@@ -82,18 +84,12 @@ void LLControlAvatar::getNewConstraintFixups(LLVector3& new_pos_fixup, F32& new_
{
F32 max_legal_offset = MAX_LEGAL_OFFSET;
if (gSavedSettings.getControl("AnimatedObjectsMaxLegalOffset"))
{
max_legal_offset = gSavedSettings.getF32("AnimatedObjectsMaxLegalOffset");
}
max_legal_offset = llmax(max_legal_offset,0.f);
static LLCachedControl<F32> animated_object_max_legal_offset(gSavedSettings, "AnimatedObjectsMaxLegalOffset");
max_legal_offset = llmax(animated_object_max_legal_offset(),0.f);
F32 max_legal_size = MAX_LEGAL_SIZE;
if (gSavedSettings.getControl("AnimatedObjectsMaxLegalSize"))
{
max_legal_size = gSavedSettings.getF32("AnimatedObjectsMaxLegalSize");
}
max_legal_size = llmax(max_legal_size, 1.f);
static LLCachedControl<F32> animated_object_max_legal_size(gSavedSettings, "AnimatedObjectsMaxLegalSize");
max_legal_size = llmax(animated_object_max_legal_size(), 1.f);
new_pos_fixup = LLVector3();
new_scale_fixup = 1.0f;
@@ -124,22 +120,23 @@ void LLControlAvatar::getNewConstraintFixups(LLVector3& new_pos_fixup, F32& new_
F32 target_dist = (offset_dist - max_legal_offset);
new_pos_fixup = (target_dist/offset_dist)*pos_box_offset;
}
if (new_pos_fixup != mPositionConstraintFixup)
{
LL_DEBUGS("ConstraintFix") << getFullname() << " pos fix, offset_dist " << offset_dist << " pos fixup "
<< new_pos_fixup << " was " << mPositionConstraintFixup << LL_ENDL;
LL_DEBUGS("ConstraintFix") << "vol_pos " << vol_pos << LL_ENDL;
LL_DEBUGS("ConstraintFix") << "extents " << extents[0] << " " << extents[1] << LL_ENDL;
LL_DEBUGS("ConstraintFix") << "unshift_extents " << unshift_extents[0] << " " << unshift_extents[1] << LL_ENDL;
//if (new_pos_fixup != mPositionConstraintFixup)
//{
// LL_DEBUGS("ConstraintFix") << getFullname() << " pos fix, offset_dist " << offset_dist << " pos fixup "
// << new_pos_fixup << " was " << mPositionConstraintFixup << LL_ENDL;
// LL_DEBUGS("ConstraintFix") << "vol_pos " << vol_pos << LL_ENDL;
// LL_DEBUGS("ConstraintFix") << "extents " << extents[0] << " " << extents[1] << LL_ENDL;
// LL_DEBUGS("ConstraintFix") << "unshift_extents " << unshift_extents[0] << " " << unshift_extents[1] << LL_ENDL;
//
//}
}
}
/*if (box_size/mScaleConstraintFixup > max_legal_size)
{
new_scale_fixup = mScaleConstraintFixup*max_legal_size/box_size;
LL_DEBUGS("ConstraintFix") << getFullname() << " scale fix, box_size " << box_size << " fixup "
<< mScaleConstraintFixup << " max legal " << max_legal_size
<< " -> new scale " << new_scale_fixup << LL_ENDL;
//LL_DEBUGS("ConstraintFix") << getFullname() << " scale fix, box_size " << box_size << " fixup "
// << mScaleConstraintFixup << " max legal " << max_legal_size
// << " -> new scale " << new_scale_fixup << LL_ENDL;
}*/
}
}
@@ -163,6 +160,8 @@ void LLControlAvatar::matchVolumeTransform()
mPositionConstraintFixup = new_pos_fixup;
mScaleConstraintFixup = new_scale_fixup;
static LLCachedControl<F32> global_scale(gSavedSettings, "AnimatedObjectsGlobalScale", 1.f);
if (mRootVolp->isAttachment())
{
LLVOAvatar *attached_av = mRootVolp->getAvatarAncestor();
@@ -174,13 +173,12 @@ void LLControlAvatar::matchVolumeTransform()
LLVector3 joint_pos = attach->getWorldPosition();
LLQuaternion joint_rot = attach->getWorldRotation();
LLVector3 obj_pos = mRootVolp->mDrawable->getPosition();
LLQuaternion obj_rot = mRootVolp->mDrawable->getRotation();
const LLQuaternion& obj_rot = mRootVolp->mDrawable->getRotation();
obj_pos.rotVec(joint_rot);
mRoot->setWorldPosition(obj_pos + joint_pos);
mRoot->setWorldRotation(obj_rot * joint_rot);
setRotation(mRoot->getRotation());
F32 global_scale = gSavedSettings.getF32("AnimatedObjectsGlobalScale");
setGlobalScale(global_scale * mScaleConstraintFixup);
}
else
@@ -200,17 +198,7 @@ void LLControlAvatar::matchVolumeTransform()
// complexity info and such line up better. Should defer
// this until avatars also get fixed.
LLQuaternion obj_rot;
if (mRootVolp->mDrawable)
{
obj_rot = mRootVolp->mDrawable->getRotation();
}
else
{
obj_rot = mRootVolp->getRotation();
}
LLMatrix3 bind_mat;
const LLQuaternion& obj_rot = mRootVolp->mDrawable ? mRootVolp->mDrawable->getRotation() : mRootVolp->getRotation();
LLQuaternion bind_rot;
#define MATCH_BIND_SHAPE
@@ -219,7 +207,7 @@ void LLControlAvatar::matchVolumeTransform()
const LLMeshSkinInfo* skin_info = mRootVolp->getSkinInfo();
if (skin_info)
{
LL_DEBUGS("BindShape") << getFullname() << " bind shape " << skin_info->mBindShapeMatrix << LL_ENDL;
//LL_DEBUGS("BindShape") << getFullname() << " bind shape " << skin_info->mBindShapeMatrix << LL_ENDL;
bind_rot = LLSkinningUtil::getUnscaledQuaternion(skin_info->mBindShapeMatrix);
}
#endif
@@ -228,7 +216,6 @@ void LLControlAvatar::matchVolumeTransform()
setPositionAgent(vol_pos);
mRoot->setPosition(vol_pos + mPositionConstraintFixup);
F32 global_scale = gSavedSettings.getF32("AnimatedObjectsGlobalScale");
setGlobalScale(global_scale * mScaleConstraintFixup);
}
}
@@ -236,7 +223,7 @@ void LLControlAvatar::matchVolumeTransform()
void LLControlAvatar::setGlobalScale(F32 scale)
{
if (scale <= 0.0)
if (scale <= 0.0f)
{
LL_WARNS() << "invalid global scale " << scale << LL_ENDL;
return;
@@ -255,10 +242,8 @@ void LLControlAvatar::recursiveScaleJoint(LLJoint* joint, F32 factor)
{
joint->setScale(factor * joint->getScale());
for (LLJoint::child_list_t::iterator iter = joint->mChildren.begin();
iter != joint->mChildren.end(); ++iter)
for (auto child : joint->mChildren)
{
LLJoint* child = *iter;
recursiveScaleJoint(child, factor);
}
}
@@ -278,10 +263,9 @@ void LLControlAvatar::updateVolumeGeom()
mRootVolp->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
LLViewerObject::const_child_list_t& child_list = mRootVolp->getChildren();
for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
iter != child_list.end(); ++iter)
for (const auto& iter : child_list)
{
LLViewerObject* childp = *iter;
LLViewerObject* childp = iter;
if (childp && childp->mDrawable.notNull())
{
childp->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
@@ -363,7 +347,8 @@ BOOL LLControlAvatar::updateCharacter(LLAgent &agent)
//virtual
void LLControlAvatar::updateDebugText()
{
/*if (gSavedSettings.getBOOL("DebugAnimatedObjects"))
/*static LLCachedControl<bool> debug_animated_objects(gSavedSettings, "DebugAnimatedObjects");
if (debug_animated_objects)
{
S32 total_linkset_count = 0;
if (mRootVolp)
@@ -386,10 +371,8 @@ void LLControlAvatar::updateDebugText()
S32 cam_dist_count = 0;
F32 lod_radius = mRootVolp->mLODRadius;
for (std::vector<LLVOVolume*>::iterator it = volumes.begin();
it != volumes.end(); ++it)
for (auto volp : volumes)
{
LLVOVolume *volp = *it;
S32 verts = 0;
total_tris += volp->getTriangleCount(&verts);
total_verts += verts;
@@ -492,10 +475,9 @@ void LLControlAvatar::getAnimatedVolumes(std::vector<LLVOVolume*>& volumes)
volumes.push_back(mRootVolp);
LLViewerObject::const_child_list_t& child_list = mRootVolp->getChildren();
for (LLViewerObject::const_child_list_t::const_iterator iter = child_list.begin();
iter != child_list.end(); ++iter)
for (const auto& iter : child_list)
{
LLViewerObject* childp = *iter;
LLViewerObject* childp = iter;
LLVOVolume *child_volp = dynamic_cast<LLVOVolume*>(childp);
if (child_volp && child_volp->isAnimatedObject())
{
@@ -520,16 +502,16 @@ void LLControlAvatar::updateAnimations()
// Rebuild mSignaledAnimations from the associated volumes.
std::map<LLUUID, S32> anims;
for (std::vector<LLVOVolume*>::iterator vol_it = volumes.begin(); vol_it != volumes.end(); ++vol_it)
for (auto vol_it = volumes.begin(); vol_it != volumes.end(); ++vol_it)
{
LLVOVolume *volp = *vol_it;
//LL_INFOS("AnimatedObjects") << "updating anim for vol " << volp->getID() << " root " << mRootVolp->getID() << LL_ENDL;
signaled_animation_map_t& signaled_animations = LLObjectSignaledAnimationMap::instance().getMap()[volp->getID()];
for (std::map<LLUUID,S32>::iterator anim_it = signaled_animations.begin();
for (auto anim_it = signaled_animations.begin();
anim_it != signaled_animations.end();
++anim_it)
{
std::map<LLUUID,S32>::iterator found_anim_it = anims.find(anim_it->first);
auto found_anim_it = anims.find(anim_it->first);
if (found_anim_it != anims.end())
{
// Animation already present, use the larger sequence id
@@ -540,7 +522,9 @@ void LLControlAvatar::updateAnimations()
// Animation not already present, use this sequence id.
anims[anim_it->first] = anim_it->second;
}
#if LL_DEBUG
LL_DEBUGS("AnimatedObjectsNotify") << "found anim for vol " << volp->getID() << " anim " << anim_it->first << " root " << mRootVolp->getID() << LL_ENDL;
#endif
}
}
if (!mPlaying)
@@ -568,15 +552,18 @@ LLViewerObject* LLControlAvatar::lineSegmentIntersectRiggedAttachments(const LLV
LLVector4a* normal,
LLVector4a* tangent)
{
if (!mRootVolp)
{
return NULL;
}
LLViewerObject* hit = NULL;
if (lineSegmentBoundingBox(start, end))
{
LLVector4a local_end = end;
LLVector4a local_intersection;
if (mRootVolp &&
mRootVolp->lineSegmentIntersect(start, local_end, face, pick_transparent, pick_rigged, face_hit, &local_intersection, tex_coord, normal, tangent))
if (mRootVolp->lineSegmentIntersect(start, local_end, face, pick_transparent, pick_rigged, face_hit, &local_intersection, tex_coord, normal, tangent))
{
local_end = local_intersection;
if (intersection)
@@ -639,8 +626,11 @@ void LLControlAvatar::onRegionChanged()
std::vector<LLCharacter*>::iterator it = LLCharacter::sInstances.begin();
for ( ; it != LLCharacter::sInstances.end(); ++it)
{
LLControlAvatar* cav = dynamic_cast<LLControlAvatar*>(*it);
if (!cav) continue;
cav->mRegionChanged = true;
auto avatar = static_cast<LLVOAvatar*>(*it);
if (!avatar->isDead() && avatar->isControlAvatar())
{
LLControlAvatar* cav = static_cast<LLControlAvatar*>(avatar);
cav->mRegionChanged = true;
}
}
}