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

refactor: Use a temp vector for delta calculations of FollowBehavior #3230

Merged
merged 2 commits into from
Jul 21, 2024

Conversation

ufrshubham
Copy link
Member

Description

This PR add a temp vector in FollowBehavior to avoid creating a new vector every frame for the delta calculations.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

NA

if (delta.x != 0 || delta.y != 0) {
owner.position = delta..add(owner.position);
if (_tempDelta.x != 0 || _tempDelta.y != 0) {
owner.position = _tempDelta..add(owner.position);
Copy link
Member

Choose a reason for hiding this comment

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

to go all the way avoiding object creation entirely, this could be owner.position.setValues(owner.position.x + delta.x, ...)

sadly we lose all the easiness of using vectorial math at all when doing things like this

Copy link
Member Author

Choose a reason for hiding this comment

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

this could be owner.position.setValues(owner.position.x + delta.x, ...)

I thought the same. But unfortunately doing so causes some of the tests to fail, because the .setValues bypasses the position setter of PositionProvider. Some components do extra stuff in that setter.

Copy link
Member

Choose a reason for hiding this comment

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

oof, seems like a footgun waiting to happen :(

Copy link
Member

@luanpotter luanpotter left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm

@spydon spydon merged commit 524793d into main Jul 21, 2024
8 checks passed
@spydon spydon deleted the devkage/refactor-follow-behavior-delta branch July 21, 2024 09:42
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.

3 participants