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

Fix CharactorController move not effect with transform changed in update func #2322

Merged
merged 10 commits into from
Aug 13, 2024

Conversation

luzhuang
Copy link
Contributor

@luzhuang luzhuang commented Aug 8, 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

  • Bug Fixes

    • Improved the timing of script execution during physics updates, potentially enhancing the accuracy of the physics simulation.
  • New Features

    • Introduced a new method for retrieving world position, streamlining the CharacterController functionality.
    • Enhanced readability and maintainability of the CharacterController class with updated logic centralization.
    • Added functionality to update physics colliders during the late update phase, improving synchronization between scene transformations and colliders.

@luzhuang luzhuang requested a review from GuoLei1990 August 8, 2024 07:59
Copy link

coderabbitai bot commented Aug 8, 2024

Warning

Rate limit exceeded

@luzhuang has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 22 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 11fb4fe and 34faf6d.

Walkthrough

The updates to the PhysicsScene, CharacterController, and Engine classes enhance the clarity and performance of physics updates. The PhysicsScene adjusts method call order to improve interaction timing with colliders. The CharacterController centralizes world position retrieval, boosting maintainability. Additionally, the Engine class introduces synchronization of scene transformations with colliders during late updates, optimizing physics processing prior to rendering. Collectively, these changes refine the physics simulation workflow.

Changes

File Path Change Summary
packages/core/src/physics/PhysicsScene.ts Reordered method calls in the physics update loop, moving callScriptOnPhysicsUpdate() before callColliderOnUpdate().
packages/core/src/physics/CharacterController.ts Updated move method to store return value in flags, added _getWorldPositionFromBackend, and simplified _onLateUpdate.
packages/core/src/Engine.ts Added logic to update physics colliders for active scenes during the late update phase, improving synchronization with transformations.

Poem

🐰 In the realm of physics, a dance so fine,
The scripts now leap before the colliders align.
With timing adjusted, they play their sweet part,
In the world of updates, they share a new heart.
So hop along, dear friends, let the changes be bright,
In the garden of code, we celebrate tonight! 🌟


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@luzhuang luzhuang changed the title Fix the time fo physicsUpdate called Fix the time fo physicsUpdate be called Aug 8, 2024
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 1fe6043 and 71b9734.

Files selected for processing (1)
  • packages/core/src/physics/PhysicsScene.ts (1 hunks)
Additional comments not posted (1)
packages/core/src/physics/PhysicsScene.ts (1)

354-354: Verify the impact of reordering method calls.

The call to componentsManager.callScriptOnPhysicsUpdate() has been moved before this._callColliderOnUpdate(). This change may affect the timing and interaction between script updates and collider updates. Ensure that this alteration maintains the intended behavior of the physics simulation.

@luzhuang luzhuang changed the title Fix the time fo physicsUpdate be called Fix CharactorController move not effect with transform changed in update func Aug 9, 2024
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 71b9734 and de9cf78.

Files selected for processing (1)
  • packages/core/src/physics/CharacterController.ts (4 hunks)
Additional comments not posted (3)
packages/core/src/physics/CharacterController.ts (3)

94-96: Encapsulation and readability improvements.

The changes to the move method enhance readability by storing the return value in flags and encapsulating the world position retrieval logic in _getWorldPositionFromBackend.


141-142: Centralized logic for world position retrieval.

The _onLateUpdate method now calls _getWorldPositionFromBackend, which centralizes the logic for obtaining the world position and adheres to the DRY principle.


169-172: Encapsulation of world position retrieval logic.

The new private method _getWorldPositionFromBackend encapsulates the logic for obtaining the world position from the backend, enhancing code organization and clarity.

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 de9cf78 and 205ca91.

Files selected for processing (1)
  • packages/core/src/Engine.ts (1 hunks)
Additional comments not posted (1)
packages/core/src/Engine.ts (1)

390-397: Verify _callColliderOnUpdate implementation.

The new block of code updates colliders for active scenes, which is a good enhancement. Ensure that the _callColliderOnUpdate method in the PhysicsScene class is correctly implemented to handle this update efficiently.

Verification successful

_callColliderOnUpdate Implementation Verified

The _callColliderOnUpdate method is correctly implemented in the PhysicsScene class. It iterates over colliders and calls _onUpdate on each, ensuring that collider states are updated appropriately. This supports the changes made in Engine.ts for physics synchronization.

  • File: packages/core/src/physics/PhysicsScene.ts
  • Method: _callColliderOnUpdate
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `_callColliderOnUpdate` in the `PhysicsScene` class.

# Test: Search for the method implementation. Expect: Correct handling of collider updates.
ast-grep --lang typescript --pattern $'class PhysicsScene {
  $$$
  _callColliderOnUpdate() {
    $$$
  }
  $$$  
}'

Length of output: 117


Script:

#!/bin/bash
# Search for the `_callColliderOnUpdate` method across all TypeScript files to locate its implementation.
rg '_callColliderOnUpdate' --type ts --context 5

Length of output: 2262

@GuoLei1990 GuoLei1990 added bug Something isn't working physics Engine's physical system labels Aug 13, 2024
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 205ca91 and 11fb4fe.

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

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.53%. Comparing base (55df470) to head (11fb4fe).
Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2322      +/-   ##
==========================================
+ Coverage   69.47%   69.53%   +0.06%     
==========================================
  Files         523      524       +1     
  Lines       27380    27405      +25     
  Branches     4098     4100       +2     
==========================================
+ Hits        19021    19056      +35     
+ Misses       6866     6849      -17     
- Partials     1493     1500       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GuoLei1990 GuoLei1990 merged commit 2428ed1 into galacean:main Aug 13, 2024
7 checks passed
singlecoder pushed a commit to singlecoder/engine that referenced this pull request Aug 29, 2024
…ate func (galacean#2322)

* fix: CharactorController move not effect with transform changed in update func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working physics Engine's physical system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants