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

Add hasExitTime and fix error when set state startTime and transition duration is 0 #2359

Merged
merged 27 commits into from
Sep 11, 2024

Conversation

luzhuang
Copy link
Contributor

@luzhuang luzhuang commented Aug 26, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features

    • Enhanced handling of animation transitions with improved exit time logic.
    • Introduced hasExitTime property for more nuanced control over transitions.
    • Added support for solo state tracking in transitions for better animation management.
    • Integrated a new AnimatorStateTransitionCollection for structured transition management.
  • Bug Fixes

    • Streamlined calculations for playback time to ensure accuracy during animation transitions.
  • Documentation

    • Updated comments to clarify the behavior of transition methods and properties.
  • Tests

    • Added new test cases to validate animator state transitions and exit timing behavior.

@luzhuang luzhuang added the animation Built-in animation system related functions label Aug 26, 2024
@luzhuang luzhuang added the bug Something isn't working label Aug 26, 2024
Copy link

coderabbitai bot commented Aug 26, 2024

Walkthrough

The changes encompass enhancements to the animation system, focusing on state transitions and exit time management. Key modifications include the introduction of the hasExitTime property across various classes, refined transition logic, and updates to method signatures for improved clarity. Additionally, the AnimatorStateTransitionCollection class has been introduced to streamline transition management, consolidating logic for adding and removing transitions.

Changes

Files Change Summary
packages/core/src/animation/Animator.ts, packages/core/src/animation/AnimatorStateMachine.ts, packages/core/src/animation/AnimatorStateTransition.ts, packages/core/src/animation/AnimatorState.ts Enhanced transition handling with the introduction of hasExitTime, refined state transition logic, and improved method signatures for clarity.
packages/core/src/animation/AnimatorStateTransitionCollection.ts Added AnimatorStateTransitionCollection class for centralized management of animator state transitions, including methods for adding, removing, and updating transitions.
tests/src/core/Animator.test.ts Introduced Entity class for state management, removed outdated transition time calculations, and added new tests for validating transition behaviors.

Sequence Diagram(s)

sequenceDiagram
    participant Animator
    participant AnimatorStateMachine
    participant AnimatorStateTransition

    Animator->>AnimatorStateMachine: Request transition
    AnimatorStateMachine->>AnimatorStateTransition: Check hasExitTime
    alt hasExitTime is true
        AnimatorStateTransition->>AnimatorStateMachine: Retrieve exit time
        AnimatorStateMachine->>AnimatorStateTransition: Determine transition order
    else hasExitTime is false
        AnimatorStateTransition->>AnimatorStateMachine: Add transition to front
    end
    AnimatorStateMachine->>Animator: Execute transition
Loading

🐇 In the world of hops and leaps,
New transitions dance and sweep.
With exit times now clear and bright,
Our animations take to flight!
So let us cheer, with joy and glee,
For smoother moves, oh what a spree! 🎉


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0027bbe and e684bd1.

Files selected for processing (1)
  • packages/core/src/animation/Animator.ts (19 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/animation/Animator.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fec392e and f3d3d78.

Files selected for processing (6)
  • packages/core/src/animation/Animator.ts (8 hunks)
  • packages/core/src/animation/AnimatorState.ts (1 hunks)
  • packages/core/src/animation/AnimatorStateMachine.ts (3 hunks)
  • packages/core/src/animation/AnimatorStateTransition.ts (1 hunks)
  • packages/loader/src/AnimatorControllerLoader.ts (3 hunks)
  • tests/src/core/Animator.test.ts (6 hunks)
Additional comments not posted (31)
packages/core/src/animation/AnimatorStateTransition.ts (1)

20-21: LGTM!

The hasExitTime property is correctly added and initialized.

The code changes are approved.

packages/core/src/animation/AnimatorStateMachine.ts (3)

97-98: LGTM!

The comment update enhances the clarity of the method behavior.

The code changes are approved.


121-122: LGTM!

The comment update enhances the clarity of the method behavior.

The code changes are approved.


145-145: LGTM!

The initialization of hasExitTime to false ensures consistent default behavior for transitions.

The code changes are approved.

packages/loader/src/AnimatorControllerLoader.ts (2)

118-118: LGTM!

The assignment of hasExitTime ensures that the property is correctly propagated from the transition data to the transition object.

The code changes are approved.


159-159: LGTM!

The addition of hasExitTime to ITransitionData enhances the data structure to include additional state information.

The code changes are approved.

packages/core/src/animation/AnimatorState.ts (3)

115-115: Ensure proper handling of transition source state.

The transition's source state is correctly set to this.

The code changes are approved.


116-125: Handle transitions with exit time correctly.

The logic correctly handles transitions with hasExitTime by inserting them in the appropriate position based on their exitTime.

The code changes are approved.


127-127: Handle transitions without exit time correctly.

The logic correctly handles transitions without hasExitTime by adding them to the front of the _transitions array.

The code changes are approved.

tests/src/core/Animator.test.ts (14)

567-568: Ensure proper instantiation of Entity and Animator components.

The Entity and Animator components are correctly instantiated and added.

The code changes are approved.


568-568: Ensure proper instantiation of AnimatorController.

The AnimatorController is correctly instantiated and assigned to the animator.

The code changes are approved.


645-646: Ensure proper instantiation of Entity and Animator components.

The Entity and Animator components are correctly instantiated and added.

The code changes are approved.


646-646: Ensure proper instantiation of AnimatorController.

The AnimatorController is correctly instantiated and assigned to the animator.

The code changes are approved.


713-714: Ensure proper handling of animatorController and layerData.

The animatorController and layerData are correctly handled.

The code changes are approved.


714-717: Ensure proper addition of parameter and state machine transitions.

The playRun parameter is correctly added, and state machine transitions are correctly handled.

The code changes are approved.


725-725: Ensure proper handling of clipStartTime.

The clipStartTime is correctly set to 0.5 for the walkState.

The code changes are approved.


733-737: Ensure proper handling of transition conditions and duration.

The transition conditions and duration are correctly handled.

The code changes are approved.


739-747: Ensure proper handling of animator play and update logic.

The animator play and update logic are correctly handled.

The code changes are approved.


749-751: Ensure proper handling of animatorController and layerData.

The animatorController and layerData are correctly handled.

The code changes are approved.


751-755: Ensure proper addition of parameter and state machine transitions.

The triggerIdle parameter is correctly added, and state machine transitions are correctly handled.

The code changes are approved.


763-767: Ensure proper handling of state transitions.

The state transitions for idleState, walkState, and runState are correctly handled.

The code changes are approved.


771-775: Ensure proper handling of transition properties.

The transition properties hasExitTime, exitTime, and duration are correctly handled.

The code changes are approved.


776-797: Ensure proper handling of animator play and update logic.

The animator play and update logic are correctly handled.

The code changes are approved.

packages/core/src/animation/Animator.ts (8)

556-567: LGTM!

The method _applyStateTransitions is correctly implemented with the additional parameters.

The code changes are approved.


667-672: LGTM!

The method _updateCrossFadeState correctly uses the new parameter crossFadeTransition and updates the logic for calculating transitionDuration.

The code changes are approved.


Line range hint 1107-1133: LGTM!

The method _checkSubTransition correctly includes logic for handling hasExitTime.

The code changes are approved.


1142-1148: LGTM!

The method _checkBackwardsSubTransition correctly includes logic for handling hasExitTime.

The code changes are approved.


Line range hint 1155-1164: LGTM!

The method _applyTransitionsByCondition has been correctly replaced with _applyStateTransitions.

The code changes are approved.


Line range hint 1185-1211: LGTM!

The method _prepareCrossFadeByTransition correctly includes logic for handling crossFadeTransition.

The code changes are approved.


819-819: LGTM!

The method _updateCrossFadeFromPoseState correctly uses the new parameter crossFadeTransition and updates the logic for calculating transitionDuration.

The code changes are approved.


Line range hint 72-72: Verify the impact of the method signature change.

The parameter aniUpdate has been replaced with deltaTime. Ensure that all calls to the update method have been updated accordingly.

Run the following script to verify the method usage:

Verification successful

Method Signature Change Verified

The change in the update method's signature from aniUpdate to deltaTime has been correctly propagated throughout the codebase. Test files such as tests/src/core/Animator.test.ts are using the method with the expected argument type. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to the `update` method match the new signature.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'update('

Length of output: 94


Script:

#!/bin/bash
# Description: Verify all calls to the `update` method match the new signature.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'update\\('

Length of output: 52523

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f3d3d78 and e127b27.

Files selected for processing (5)
  • packages/core/src/animation/Animator.ts (7 hunks)
  • packages/core/src/animation/AnimatorStateMachine.ts (3 hunks)
  • packages/core/src/animation/AnimatorStateTransition.ts (1 hunks)
  • packages/loader/src/AnimatorControllerLoader.ts (3 hunks)
  • tests/src/core/Animator.test.ts (6 hunks)
Files skipped from review due to trivial changes (1)
  • packages/core/src/animation/AnimatorStateMachine.ts
Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/animation/Animator.ts
  • packages/core/src/animation/AnimatorStateTransition.ts
  • packages/loader/src/AnimatorControllerLoader.ts
Additional comments not posted (5)
tests/src/core/Animator.test.ts (5)

19-19: LGTM!

The import statement for Entity is correct.

The code changes are approved.


567-568: LGTM!

The code correctly creates an Entity and adds an Animator component to it.

The code changes are approved.


645-646: LGTM!

The code correctly creates an Entity and adds an Animator component to it.

The code changes are approved.


713-747: LGTM!

The test case correctly tests the anyTransition feature. It ensures that the animator transitions to the correct state when the playRun parameter is set to 1.

The code changes are approved.


749-797: LGTM!

The test case correctly tests the hasExitTime feature. It ensures that the animator transitions to the correct state based on the hasExitTime and exitTime properties.

The code changes are approved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e127b27 and 8e7e20a.

Files selected for processing (2)
  • packages/core/src/animation/AnimatorState.ts (2 hunks)
  • packages/core/src/animation/AnimatorStateTransition.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/animation/AnimatorState.ts
  • packages/core/src/animation/AnimatorStateTransition.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8e7e20a and 562b900.

Files selected for processing (3)
  • packages/core/src/animation/Animator.ts (7 hunks)
  • packages/core/src/animation/AnimatorState.ts (2 hunks)
  • packages/core/src/animation/AnimatorStateTransition.ts (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/animation/Animator.ts
  • packages/core/src/animation/AnimatorState.ts
  • packages/core/src/animation/AnimatorStateTransition.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 562b900 and 64d825e.

Files selected for processing (6)
  • packages/core/src/animation/Animator.ts (17 hunks)
  • packages/core/src/animation/AnimatorState.ts (5 hunks)
  • packages/core/src/animation/AnimatorStateMachine.ts (6 hunks)
  • packages/core/src/animation/AnimatorStateTransition.ts (4 hunks)
  • packages/core/src/animation/internal/AnimatorLayerData.ts (1 hunks)
  • packages/core/src/animation/internal/TransitionSource.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/animation/AnimatorStateMachine.ts
Additional comments not posted (25)
packages/core/src/animation/internal/AnimatorLayerData.ts (1)

17-17: LGTM! But verify the property usage in the codebase.

The property anyTransitionIndex is correctly added to the class. Ensure that it is used appropriately in the codebase.

The code changes are approved.

Run the following script to verify the property usage:

Verification successful

Property anyTransitionIndex is used correctly in the codebase.

The anyTransitionIndex property is integrated into the logic of the Animator.ts file, where it is used to manage transition indices appropriately. No issues were found with its usage.

  • Files Involved:
    • packages/core/src/animation/Animator.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `anyTransitionIndex` in the codebase.

# Test: Search for the property usage. Expect: Appropriate usage across the codebase.
rg --type python -A 5 $'anyTransitionIndex'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify all usages of `anyTransitionIndex` in the codebase.

# Test: Search for the property usage. Expect: Appropriate usage across the codebase.
rg --type ts -A 5 'anyTransitionIndex'

Length of output: 3789

packages/core/src/animation/internal/TransitionSource.ts (5)

8-8: LGTM!

The abstract method _updateTransitionsIndex is correctly defined.

The code changes are approved.


9-9: LGTM!

The abstract method _updateSoloTransition is correctly defined.

The code changes are approved.


11-31: LGTM!

The method _addTransition is correctly implemented and handles both AnimatorStateTransition and AnimatorState appropriately.

The code changes are approved.


33-37: LGTM!

The method _removeTransition is correctly implemented and handles the removal of transitions appropriately.

The code changes are approved.


39-53: LGTM!

The method _addHasExitTimeTransition is correctly implemented and handles the addition of transitions with exit times appropriately.

The code changes are approved.

packages/core/src/animation/AnimatorStateTransition.ts (7)

5-5: LGTM!

The import statement for TransitionSource is correctly added.

The code changes are approved.


25-25: LGTM!

The property _isEntry is correctly added and initialized to false.

The code changes are approved.


27-27: LGTM!

The property _isAny is correctly added and initialized to false.

The code changes are approved.


33-33: LGTM!

The property _hasExitTime is correctly added and initialized to true.

The code changes are approved.


52-52: LGTM!

The setter for solo is correctly implemented and includes logic to update the transition index through the _source.

The code changes are approved.


64-72: LGTM!

The getter and setter for hasExitTime are correctly implemented. The setter includes logic to update the transition index through the _source.

The code changes are approved.


23-23: LGTM! But verify the property usage in the codebase.

The property _source is correctly added to the class. Ensure that it is used appropriately in the codebase.

The code changes are approved.

Run the following script to verify the property usage:

Verification successful

The _source property is used appropriately across the codebase.

The _source property is integrated and utilized in various files, indicating that it is functioning as intended.

  • Files with _source usage:
    • packages/shader-lab/src/lexer/Lexer.ts
    • packages/shader-lab/src/contentParser/Scanner.ts
    • packages/shader-lab/src/preprocessor/PpScanner.ts
    • packages/shader-lab/src/common/BaseScanner.ts
    • packages/core/src/animation/AnimatorStateTransition.ts
    • packages/core/src/animation/Animator.ts
    • packages/core/src/animation/internal/TransitionSource.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `_source` in the codebase.

# Test: Search for the property usage. Expect: Appropriate usage across the codebase.
rg --type python -A 5 $'_source'

Length of output: 62


Script:

#!/bin/bash
# Description: Verify all usages of `_source` in the TypeScript codebase.

# Test: Search for the property usage. Expect: Appropriate usage across the codebase.
rg --type ts -A 5 '_source'

Length of output: 14009

packages/core/src/animation/AnimatorState.ts (6)

11-11: LGTM!

The class extension is correctly implemented.

The code changes are approved.


107-108: LGTM!

The refactoring improves readability and maintainability.

The code changes are approved.


121-121: LGTM!

The refactoring improves readability and maintainability.

The code changes are approved.


128-132: LGTM!

The refactoring improves readability and maintainability.

The code changes are approved.


203-211: LGTM!

The method improves the control flow and logic of the class.

The code changes are approved.


216-216: LGTM!

The refactoring improves the handling of transitions based on their exit status.

The code changes are approved.

packages/core/src/animation/Animator.ts (6)

557-569: LGTM!

The refactoring improves the calculation of play cost time during animations.

The code changes are approved.


590-609: LGTM!

The refactoring improves the accuracy of play cost time calculations.

The code changes are approved.


689-697: LGTM!

The refactoring improves the handling of cross fade transitions.

The code changes are approved.


Line range hint 924-936: LGTM!

The refactoring improves the handling of finished states.

The code changes are approved.


Line range hint 1005-1103: LGTM!

The method improves the control flow and logic of the class.

The code changes are approved.


1128-1147: LGTM!

The refactoring improves the handling of sub transitions.

The code changes are approved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 64d825e and 5ddc513.

Files selected for processing (3)
  • packages/core/src/animation/Animator.ts (17 hunks)
  • packages/core/src/animation/AnimatorStateMachine.ts (6 hunks)
  • tests/src/core/Animator.test.ts (6 hunks)
Additional comments not posted (17)
packages/core/src/animation/AnimatorStateMachine.ts (7)

3-3: LGTM!

The new inheritance from TransitionSource enhances the capabilities of AnimatorStateMachine for transition management.

The code changes are approved.

Also applies to: 11-11


22-22: LGTM!

The new internal properties _entryHasSolo and _anyHasSolo effectively track the solo state of transitions.

The code changes are approved.

Also applies to: 25-25


104-104: LGTM!

The updated logic in addEntryStateTransition ensures that entry transitions are correctly flagged and solo states are updated.

The code changes are approved.

Also applies to: 111-114


123-123: LGTM!

The updated logic in removeEntryStateTransition correctly resets the _isEntry flag.

The code changes are approved.


132-132: LGTM!

The updated logic in addAnyStateTransition ensures that any state transitions are correctly flagged and solo states are updated.

The code changes are approved.

Also applies to: 138-141


150-150: LGTM!

The updated logic in removeAnyStateTransition correctly resets the _isAny flag.

The code changes are approved.


156-162: LGTM!

The new internal methods _updateTransitionsIndex and _updateSoloTransition enhance the transition management capabilities of the state machine.

The code changes are approved.

Also applies to: 169-186

tests/src/core/Animator.test.ts (4)

19-19: LGTM!

The addition of Entity is appropriate for the new test cases.

The code changes are approved.


719-753: LGTM!

The new test case for anyTransition ensures that the functionality is correctly validated.

The code changes are approved.


755-803: LGTM!

The new test case for hasExitTime ensures that the functionality is correctly validated.

The code changes are approved.


Line range hint 651-703: LGTM!

The new test case for stateMachineScript ensures that the functionality is correctly validated.

The code changes are approved.

packages/core/src/animation/Animator.ts (6)

13-13: LGTM!

The import of AnimatorStateMachine is necessary for the new transition logic.

The code changes are approved.


Line range hint 100-100: LGTM!

The change in the method signature from aniUpdate: boolean to deltaTime: number improves clarity and aligns with standard practices. The logic inside the method correctly handles the new parameter.

The code changes are approved.


557-569: LGTM!

The replacement of _applyTransitionsByCondition with _applyStateTransitions provides a more detailed and conditionally nuanced approach to managing transitions. The additional parameters improve the flexibility and accuracy of the transition logic.

The code changes are approved.


590-609: LGTM!

The updated logic correctly handles the hasExitTime property, ensuring accurate calculations of playCostTime based on the playback direction.

The code changes are approved.


689-697: LGTM!

The refined handling of crossFadeTransition ensures that the transition duration is accurately calculated based on the current state data.

The code changes are approved.


Line range hint 1005-1103: LGTM!

The introduction of _applyStateTransitions with additional parameters and refined logic improves the robustness and adaptability of the state transition management.

The code changes are approved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ddc513 and 66bc753.

Files selected for processing (1)
  • packages/core/src/animation/Animator.ts (17 hunks)
Additional comments not posted (12)
packages/core/src/animation/Animator.ts (12)

557-569: LGTM!

The _applyStateTransitions method has been updated to handle state transitions with exit times. The additional parameters and logic enhance the transition handling.

The code changes are approved.


590-609: LGTM!

The _updatePlayingState method has been updated to include logic for calculating playCostTime based on transition.hasExitTime. This enhances the accuracy of the animation state updates.

The code changes are approved.


689-697: LGTM!

The _updateCrossFadeState method has been updated to include logic for calculating dstPlayCostTime based on transitionDuration. This enhances the accuracy of the cross-fade state updates.

The code changes are approved.


Line range hint 924-936: LGTM!

The _updateFinishedState method has been updated to include logic for applying state transitions with exit times. This enhances the accuracy of the finished state updates.

The code changes are approved.


1214-1231: LGTM!

The _applyTransitionsByCondition method has been updated to include logic for applying transitions with exit times. This enhances the accuracy of the transition handling based on conditions.

The code changes are approved.


1123-1148: LGTM!

The _checkSubTransition method has been updated to include logic for checking and applying transitions with exit times. This enhances the accuracy of the sub-transition handling.

The code changes are approved.


1168-1196: LGTM!

The _checkBackwardsSubTransition method has been updated to include logic for checking and applying backwards transitions with exit times. This enhances the accuracy of the backwards sub-transition handling.

The code changes are approved.


Line range hint 1258-1273: LGTM!

The _prepareCrossFadeByTransition method has been updated to include logic for preparing cross-fade transitions with exit times. This enhances the accuracy of the cross-fade preparation.

The code changes are approved.


Line range hint 1275-1295: LGTM!

The _checkConditions method has been updated to include logic for checking conditions for transitions with exit times. This enhances the accuracy of the condition checking.

The code changes are approved.


Line range hint 69-69: LGTM!

The update method signature has been updated to include deltaTime. This enhances the clarity and accuracy of the update process.

The code changes are approved.


Line range hint 1204-1204: LGTM!

The _fireAnimationEvents method has been updated to include logic for firing animation events based on transitions with exit times. This enhances the accuracy of the event handling.

The code changes are approved.


Line range hint 1204-1204: LGTM!

The _fireBackwardSubAnimationEvents method has been updated to include logic for firing backward sub-animation events based on transitions with exit times. This enhances the accuracy of the event handling.

The code changes are approved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66bc753 and 9f59d49.

Files selected for processing (4)
  • packages/core/src/animation/AnimatorState.ts (4 hunks)
  • packages/core/src/animation/AnimatorStateMachine.ts (4 hunks)
  • packages/core/src/animation/AnimatorStateTransition.ts (4 hunks)
  • packages/core/src/animation/internal/TransitionUtil.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/animation/AnimatorStateMachine.ts
Additional context used
Biome
packages/core/src/animation/internal/TransitionUtil.ts

[error] 8-50: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 25-25: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (12)
packages/core/src/animation/internal/TransitionUtil.ts (1)

8-50: Refactor to use simple functions and replace this with the class name.

The class contains only static methods, which can be refactored to use simple functions. Using this in a static context can be confusing and should be replaced with the class name.

Apply this diff to refactor the class:

-export class TransitionUtil {
-  static addTransition(
-    source: AnimatorState | AnimatorStateMachine,
-    transitionOrAnimatorState: AnimatorStateTransition | AnimatorState,
-    transitions: AnimatorStateTransition[]
-  ): AnimatorStateTransition {
+export function addTransition(
+  source: AnimatorState | AnimatorStateMachine,
+  transitionOrAnimatorState: AnimatorStateTransition | AnimatorState,
+  transitions: AnimatorStateTransition[]
+): AnimatorStateTransition {
     let transition: AnimatorStateTransition;
     if (transitionOrAnimatorState instanceof AnimatorState) {
       transition = new AnimatorStateTransition();
       transition.hasExitTime = false;
       transition.destinationState = transitionOrAnimatorState;
     } else {
       transition = transitionOrAnimatorState;
     }
     transition._source = source;

     if (transition.hasExitTime) {
-      this.addHasExitTimeTransition(transition, transitions);
+      addHasExitTimeTransition(transition, transitions);
     } else {
       transitions.unshift(transition);
     }
     return transition;
-  }
+}

-  static removeTransition(transition: AnimatorStateTransition, transitions: AnimatorStateTransition[]): void {
+export function removeTransition(transition: AnimatorStateTransition, transitions: AnimatorStateTransition[]): void {
     const index = transitions.indexOf(transition);
     index !== -1 && transitions.splice(index, 1);
     transition._source = null;
-  }
+}

-  static addHasExitTimeTransition(transition: AnimatorStateTransition, transitions: AnimatorStateTransition[]): void {
+export function addHasExitTimeTransition(transition: AnimatorStateTransition, transitions: AnimatorStateTransition[]): void {
     const time = transition.exitTime;
     const count = transitions.length;
     const maxExitTime = count ? transitions[count - 1].exitTime : 0;
     if (time >= maxExitTime) {
       transitions.push(transition);
     } else {
       let index = count;
       while (--index >= 0 && time < transitions[index].exitTime);
       transitions.splice(index + 1, 0, transition);
     }
-  }
-}
+}
Tools
Biome

[error] 8-50: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 25-25: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

packages/core/src/animation/AnimatorStateTransition.ts (5)

23-23: LGTM!

The updated type for _source provides more flexibility in representing the source of the transition.

The code changes are approved.


25-25: LGTM!

The new _isEntry property enhances the state management capabilities within the animator.

The code changes are approved.


27-27: LGTM!

The new _isAny property enhances the state management capabilities within the animator.

The code changes are approved.


33-33: LGTM!

The new _hasExitTime property provides better control over the transition's exit time condition.

The code changes are approved.


64-72: LGTM!

The hasExitTime getter and setter provide better encapsulation and control over the transition's exit time condition. The setter's logic ensures that the transition index is updated correctly.

The code changes are approved.

packages/core/src/animation/AnimatorState.ts (6)

5-5: LGTM!

The import statement for TransitionUtil is necessary for utilizing the class.

The code changes are approved.


106-107: LGTM!

The refactoring of the addTransition method simplifies the logic and improves readability.

The code changes are approved.


120-120: LGTM!

The update to the addExitTransition method promotes code reuse and maintainability.

The code changes are approved.


127-131: LGTM!

The update to the removeTransition method centralizes the logic for removing transitions and enhances clarity.

The code changes are approved.


202-210: LGTM!

The new _updateTransitionsIndex method refines the control flow and logic within the class by handling the ordering of transitions based on their exit times.

The code changes are approved.


215-215: LGTM!

The modification to the _updateSoloTransition method allows it to manage transitions more effectively based on their exit status.

The code changes are approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
animation Built-in animation system related functions bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants