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

Make CCD read only when kinematic is enabled and vice versa #13890

Conversation

amzn-ahmadkrm
Copy link
Contributor

Signed-off-by: amzn-ahmadkrm ahmadkrm@amazon.com

What does this PR do?

This PR updates the UI to disallow the user to set a Rigid Body Component to Kinematic mode while CCD is enabled and vice versa, these are not compatible in PhysX and results in a warning. This PR makes it so it doesn't get to the point of the PhysX warning and informs the user that only one setting can be used at once.

devenv_C9X5GRLxQv
devenv_LlneAyonsK

How was this PR tested?

Manual testing.
Please describe any testing performed.

Signed-off-by: amzn-ahmadkrm <ahmadkrm@amazon.com>
Comment on lines 205 to 223
AZStd::string RigidBodyConfiguration::GetCcdTooltip() const
{
if (m_kinematic)
{
return ccdDescription +
"<b>CCD cannot be enabled if the rigid body is kinematic, set the rigid body as non-kinematic to allow changes to be made.</b>";
}
return ccdDescription;
}

AZStd::string RigidBodyConfiguration::GetKinematicTooltip() const
{
if (m_ccdEnabled)
{
return kinematicDescription +
"<b>The rigid body cannot be set as Kinematic if CCD is enabled, disable CCD to allow changes to be made.</b>";
}
return kinematicDescription;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This setup forces the system to allocate a new string every time the function is called. Since the outcomes of the function are known at compile time, it may be simpler to change this so that there is no memory allocation involved:

(I'll write examples for just the kinematic part for clarity)

  1. Define all possible strings as constexpr AZStd::string_view constants:
    constexpr AZStd::string_view kinematicDescription =
        "When active, the rigid body is not affected by gravity or other forces and is moved by script. ";
    const AZStd::string kinematicDescriptionReadOnly =
        "When active, the rigid body is not affected by gravity or other forces and is moved by script. <b>The rigid body cannot be set as Kinematic if CCD is enabled, disable CCD to allow changes to be made.</b>"";

or even better, if the compiler lets you do it:

    constexpr AZStd::string_view kinematicDescription =
        "When active, the rigid body is not affected by gravity or other forces and is moved by script. ";
    const AZStd::string kinematicDescriptionReadOnly =
       kinematicDescription + "<b>The rigid body cannot be set as Kinematic if CCD is enabled, disable CCD to allow changes to be made.</b>"";
  1. Change the function signature to return a const AZStd::string_view
const AZStd::string_view RigidBodyConfiguration::GetKinematicTooltip() const
  1. Just return one string or the other in the function body
return (m_ccdEnabled) ? kinematicDescriptionReadOnly : kinematicDescription;

I'm writing this off the top of my mind, so the exact types may need to be adjusted a bit (maybe a string instead of string view, or it may be even simpler to just use const char*) but I think it conveys the base idea :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this :) I changed it to a string view but no the compiler didn't let me concatenate string views :( 👎

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense now that I think about it again lol. One could replace it with a macro I guess, but given it's that simple I wouldn't overcomplicate it.

Signed-off-by: amzn-ahmadkrm <ahmadkrm@amazon.com>
@amzn-ahmadkrm amzn-ahmadkrm marked this pull request as ready for review January 4, 2023 11:46
@amzn-ahmadkrm amzn-ahmadkrm requested review from a team as code owners January 4, 2023 11:46
Copy link
Contributor

@greerdv greerdv left a comment

Choose a reason for hiding this comment

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

Looks good, nice work

@@ -104,6 +105,24 @@ namespace AzPhysics
}
}

constexpr AZStd::string_view kinematicDescription =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the coding standards have upper camel case for constant names like this https://github.com/o3de/sig-core/blob/main/governance/Coding-Standards-and-Style-Guide.md#constant-names (e.g. KinematicDescription rather than kinematicDescription).


AZStd::string_view RigidBodyConfiguration::GetCcdTooltip() const
{
return (m_kinematic) ? ccdDescriptionReadOnly : ccdDescription;
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick - not a big deal but I think the brackets are redundant here and on line 222

Copy link
Contributor

Choose a reason for hiding this comment

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

I usually add them as well cause they help me with readability, but yes they are not needed.

Copy link
Contributor

@hultonha hultonha left a comment

Choose a reason for hiding this comment

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

Really nice change, and this is definitely nicer than having the other option switch back and forward, the additional tooltip is a nice addition! 🙂

Comment on lines +40 to +41
AZStd::string_view GetCcdTooltip() const;
AZStd::string_view GetKinematicTooltip() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw @AMZN-daimini's earlier comments and as the strings are known at compile time (constant) then returning a string_view is safe but it's definitely something to be careful about because if this code ever changes there's the risk of a dangling reference. Unless it's performance critical return by value is often safer but in this case I totally understand how it's justified.

Signed-off-by: amzn-ahmadkrm <ahmadkrm@amazon.com>
@hultonha
Copy link
Contributor

hultonha commented Jan 6, 2023

Just kicked off a build @amzn-ahmadkrm 👍

@cgalvan cgalvan merged commit a6943b6 into o3de:development Jan 9, 2023
@cgalvan cgalvan deleted the ahmadkrm/disallow-kinematic-and-ccd-enabled-at-the-same-time branch January 9, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants