From 6d5927c0c9ddbc69780c49bf358a94d2877dcf1a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 8 Sep 2015 10:51:23 -0700 Subject: [PATCH] Now with less copies. * AnimSkeleton now returns AnimPoses by const ref. * AnimDebugDraw: uses references to Poses on the stack instead of copies within inner loops. * AnimDebugDraw: Removed unnecessary universal refs in range based for loops. --- libraries/animation/src/AnimSkeleton.cpp | 4 ++-- libraries/animation/src/AnimSkeleton.h | 4 ++-- libraries/render-utils/src/AnimDebugDraw.cpp | 19 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/libraries/animation/src/AnimSkeleton.cpp b/libraries/animation/src/AnimSkeleton.cpp index fdc20db63c..5dfed265a2 100644 --- a/libraries/animation/src/AnimSkeleton.cpp +++ b/libraries/animation/src/AnimSkeleton.cpp @@ -87,11 +87,11 @@ int AnimSkeleton::getNumJoints() const { return _joints.size(); } -AnimPose AnimSkeleton::getAbsoluteBindPose(int jointIndex) const { +const AnimPose& AnimSkeleton::getAbsoluteBindPose(int jointIndex) const { return _absoluteBindPoses[jointIndex]; } -AnimPose AnimSkeleton::getRelativeBindPose(int jointIndex) const { +const AnimPose& AnimSkeleton::getRelativeBindPose(int jointIndex) const { return _relativeBindPoses[jointIndex]; } diff --git a/libraries/animation/src/AnimSkeleton.h b/libraries/animation/src/AnimSkeleton.h index 973e32232d..4a6c3c0087 100644 --- a/libraries/animation/src/AnimSkeleton.h +++ b/libraries/animation/src/AnimSkeleton.h @@ -54,10 +54,10 @@ public: int getNumJoints() const; // absolute pose, not relative to parent - AnimPose getAbsoluteBindPose(int jointIndex) const; + const AnimPose& getAbsoluteBindPose(int jointIndex) const; // relative to parent pose - AnimPose getRelativeBindPose(int jointIndex) const; + const AnimPose& getRelativeBindPose(int jointIndex) const; int getParentIndex(int jointIndex) const; diff --git a/libraries/render-utils/src/AnimDebugDraw.cpp b/libraries/render-utils/src/AnimDebugDraw.cpp index 44a58b3d67..b91db94f74 100644 --- a/libraries/render-utils/src/AnimDebugDraw.cpp +++ b/libraries/render-utils/src/AnimDebugDraw.cpp @@ -336,7 +336,7 @@ void AnimDebugDraw::update() { // figure out how many verts we will need. int numVerts = 0; - for (auto&& iter : _skeletons) { + for (auto& iter : _skeletons) { AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second); numVerts += skeleton->getNumJoints() * VERTICES_PER_BONE; for (int i = 0; i < skeleton->getNumJoints(); i++) { @@ -347,7 +347,7 @@ void AnimDebugDraw::update() { } } - for (auto&& iter : _animNodes) { + for (auto& iter : _animNodes) { AnimNode::ConstPointer& animNode = std::get<0>(iter.second); auto poses = animNode->getPosesInternal(); numVerts += poses.size() * VERTICES_PER_BONE; @@ -360,7 +360,7 @@ void AnimDebugDraw::update() { } } - for (auto&& iter : _poses) { + for (auto& iter : _poses) { AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second); numVerts += skeleton->getNumJoints() * VERTICES_PER_BONE; for (int i = 0; i < skeleton->getNumJoints(); i++) { @@ -374,7 +374,7 @@ void AnimDebugDraw::update() { data._vertexBuffer->resize(sizeof(Vertex) * numVerts); Vertex* verts = (Vertex*)data._vertexBuffer->editData(); Vertex* v = verts; - for (auto&& iter : _skeletons) { + for (auto& iter : _skeletons) { AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second); AnimPose rootPose = std::get<1>(iter.second); int hipsIndex = skeleton->nameToJointIndex("Hips"); @@ -401,7 +401,7 @@ void AnimDebugDraw::update() { } } - for (auto&& iter : _animNodes) { + for (auto& iter : _animNodes) { AnimNode::ConstPointer& animNode = std::get<0>(iter.second); AnimPose rootPose = std::get<1>(iter.second); if (animNode->_skeleton) { @@ -439,7 +439,7 @@ void AnimDebugDraw::update() { } } - for (auto&& iter : _poses) { + for (auto& iter : _poses) { AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second); AnimPoseVec& poses = std::get<1>(iter.second); AnimPose rootPose = std::get<2>(iter.second); @@ -453,15 +453,15 @@ void AnimDebugDraw::update() { absAnimPose.resize(skeleton->getNumJoints()); for (int i = 0; i < skeleton->getNumJoints(); i++) { - AnimPose pose = poses[i]; + const AnimPose& pose = poses[i]; const float radius = BONE_RADIUS / (pose.scale.x * rootPose.scale.x); auto parentIndex = skeleton->getParentIndex(i); if (parentIndex >= 0) { - absAnimPose[i] = absAnimPose[parentIndex] * poses[i]; + absAnimPose[i] = absAnimPose[parentIndex] * pose; } else { - absAnimPose[i] = poses[i]; + absAnimPose[i] = pose; } // draw bone @@ -470,7 +470,6 @@ void AnimDebugDraw::update() { // draw link to parent if (parentIndex >= 0) { assert(parentIndex < skeleton->getNumJoints()); - AnimPose parentPose = poses[parentIndex]; addLink(rootPose, absAnimPose[i], absAnimPose[parentIndex], radius, color, v); } }