Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaSimulationCore] Clean free motion animation loop #1930

Merged
merged 8 commits into from
Apr 2, 2021

Conversation

alxbilger
Copy link
Contributor

Minor cleaning:

  • Remove includes and prefer forward declaration
  • Name scope timers to avoid immediate destruction (however, I had a runtime error with this one:
    sofa::helper::ScopedAdvancedTimer("ComputeBBox: " + (*object)->getName());
    )
  • Condition is evaluated at compile-time instead of run-time (although I guess the compiler is smart enough).
  • A private Data is removed
  • A local variable was shadowed by another local variable (dx)

By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@hugtalbot hugtalbot added pr: clean Cleaning the code pr: status to review To notify reviewers to review this pull-request labels Mar 17, 2021
@@ -59,7 +57,7 @@ class SOFA_SOFACONSTRAINT_API FreeMotionAnimationLoop : public sofa::simulation:
~FreeMotionAnimationLoop() override ;

sofa::core::behavior::ConstraintSolver *constraintSolver;
component::constraintset::LCPConstraintSolver::SPtr defaultSolver;
sofa::core::behavior::ConstraintSolver::SPtr defaultSolver;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a description for the doxy doc:

///< pointers towards a possible ConstraintSolver present in the scene graph
///< pointers towards a default ConstraintSolver used in case none was found in the scene graph

@alxbilger
Copy link
Contributor Author

[ci-build][with-all-tests]

@@ -140,11 +140,12 @@ void DefaultAnimationLoop::step(const core::ExecParams* params, SReal dt)
}
sofa::helper::AdvancedTimer::stepEnd("UpdateMapping");

if (!SOFA_NO_UPDATE_BBOX)
#if SOFA_NO_UPDATE_BBOX == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi alex,

If possible, the rules is to do as much as possible

if(SOFA_NO_UPDATE_BBOX)
{
    ....
}

The rational behind is that the conditional content is still compiled (eg: in the CI) so this ease maintenance and code refactoring while the compiler's optimizer can strip-out the if() when it is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since SOFA_NO_UPDATE_BBOX is a preprocessor variable, it makes more sense to me to use a preprocessor condition on it. IDEs would color the code differently on a deactivated code.
If you put the condition in a traditional condition, I am not sure the compiler compiles the code if the condition is false. IMO it sees it is false and does not bother compiling it. But I may be wrong, I don't know it for a fact.
The preprocessor condition would also remove the warning "the condition is always true".
A third alternative is
if constexpr (SOFA_NO_UPDATE_BBOX) { }
What do you think about this one?

Honestly, I don't have a strong preference. I don't mind reverting this change

@@ -286,11 +259,12 @@ void FreeMotionAnimationLoop::step(const sofa::core::ExecParams* params, SReal d
}
}

if (!SOFA_NO_UPDATE_BBOX)
#if SOFA_NO_UPDATE_BBOX == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it seems to you are doing the inverse move from what I consider the best way to do...could you elaborate a bit why ?

@hugtalbot hugtalbot added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Mar 31, 2021
@alxbilger alxbilger added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Apr 1, 2021
@alxbilger
Copy link
Contributor Author

[ci-build][with-all-tests]

@hugtalbot
Copy link
Contributor

Looks fine to me and to the CI as well

@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Apr 1, 2021
@epernod epernod merged commit 2e6d93d into sofa-framework:master Apr 2, 2021
@guparan guparan added this to the v21.06 milestone Jun 28, 2021
@alxbilger alxbilger deleted the cleanFreeMotion branch June 28, 2022 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants