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 XR camera clear flag error #2281

Merged
merged 3 commits into from
Aug 1, 2024

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Jul 31, 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 clarity in rendering operations through refined access logic.
  • Bug Fixes
    • Improved condition checks for camera clear flags, ensuring better functionality in camera management.
  • Refactor
    • Renamed methods to better reflect their purpose regarding camera clear flags, aiding in code readability and maintenance.

@cptbtptpbcptdtptp cptbtptpbcptdtptp added the xr XR related functions label Jul 31, 2024
@cptbtptpbcptdtptp cptbtptpbcptdtptp self-assigned this Jul 31, 2024
Copy link

coderabbitai bot commented Jul 31, 2024

Walkthrough

Recent changes enhance the clarity and maintainability of the Camera and XRManager classes. The Camera class improves how engine context is accessed and refines conditions for rendering operations. Meanwhile, the XRManager and its extended counterpart rename methods to better reflect their focus on ignoring clear flags. These updates streamline the codebase, promoting a better understanding for developers while preserving the underlying functionality.

Changes

Files Change Summary
packages/core/src/Camera.ts Streamlined engine context access with a local variable; improved clarity in the render method with updated conditions for ignoreClear and _renderCount.
packages/core/src/xr/XRManager.ts Renamed method from _getCameraClearFlagsMask to _getCameraIgnoreClearFlags, reflecting a focus on ignoring clear flags while maintaining the same return value.
packages/xr/src/XRManagerExtended.ts Similar renaming of the method _getCameraClearFlagsMask to _getCameraIgnoreClearFlags, ensuring consistency in method naming across classes.
packages/xr/src/feature/camera/XRCameraManager.ts Renamed method _getCameraClearFlagsMask to _getIgnoreClearFlags, reinforcing clarity in the method's purpose related to camera management in XR scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Camera
    participant Engine
    participant RenderTarget

    Camera->>Engine: Access _engine
    Engine->>Camera: Provide context
    Camera->>RenderTarget: Check conditions for rendering
    RenderTarget-->>Camera: Render output
Loading
sequenceDiagram
    participant XRManager
    participant XRManagerExtended
    participant XRCameraManager

    XRManager->>XRManagerExtended: Call _getCameraIgnoreClearFlags
    XRManagerExtended-->>XRManager: Return CameraClearFlags
    XRManagerExtended->>XRCameraManager: Call _getIgnoreClearFlags
    XRCameraManager-->>XRManagerExtended: Return CameraClearFlags
Loading

Poem

🐇 In the code where bunnies play,
Changes hop in, brightening the day!
Engines purr, flags now ignored,
With clearer paths, our spirits soared.
Let’s celebrate with a joyful dance,
For cleaner code gives us a chance! 🌟


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.

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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4f6d954 and c29b3e1.

Files selected for processing (2)
  • packages/core/src/Camera.ts (2 hunks)
  • packages/xr/src/input/XRInputManager.ts (6 hunks)
Additional context used
Biome
packages/xr/src/input/XRInputManager.ts

[error] 77-77: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 129-129: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (4)
packages/xr/src/input/XRInputManager.ts (3)

1-3: Approved: Import statements and class property update.

The import of SafeLoopArray and IXRListener is necessary for the new listener management system. The _listeners property update is appropriate.

Also applies to: 26-26


69-69: Approved: Listener addition update.

The update to add listeners as objects with a fn property to the SafeLoopArray is appropriate and enhances listener management.


84-84: Approved: Listener retrieval and invocation update.

The update to retrieve listeners via getLoopArray and check if a listener is destroyed before invoking it is appropriate and improves robustness.

Also applies to: 117-120

packages/core/src/Camera.ts (1)

602-603: Approved: Streamlined engine context access and improved control flow.

The introduction of a local variable engine improves readability and potentially enhances performance. The additional checks for _renderTarget and independentCanvasEnabled provide more nuanced control flow.

Also applies to: 634-640, 643-643

if (index >= 0) {
listeners.splice(index, 1);
}
this._listeners.findAndRemove((value) => (value.fn === listener ? (value.destroyed = true) : false));
Copy link

Choose a reason for hiding this comment

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

Refactor: Avoid assignment in expression.

The assignment within the expression is confusing and should be refactored for clarity.

- this._listeners.findAndRemove((value) => (value.fn === listener ? (value.destroyed = true) : false));
+ this._listeners.findAndRemove((value) => {
+   if (value.fn === listener) {
+     value.destroyed = true;
+     return true;
+   }
+   return false;
+ });
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this._listeners.findAndRemove((value) => (value.fn === listener ? (value.destroyed = true) : false));
this._listeners.findAndRemove((value) => {
if (value.fn === listener) {
value.destroyed = true;
return true;
}
return false;
});
Tools
Biome

[error] 77-77: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

@@ -128,7 +126,7 @@
* @internal
*/
_onDestroy(): void {
this._listeners.length = 0;
this._listeners.findAndRemove((value) => (value.destroyed = true));
Copy link

Choose a reason for hiding this comment

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

Refactor: Avoid assignment in expression.

The assignment within the expression is confusing and should be refactored for clarity.

- this._listeners.findAndRemove((value) => (value.destroyed = true));
+ this._listeners.findAndRemove((value) => {
+   value.destroyed = true;
+   return true;
+ });
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this._listeners.findAndRemove((value) => (value.destroyed = true));
this._listeners.findAndRemove((value) => {
value.destroyed = true;
return true;
});
Tools
Biome

[error] 129-129: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

@GuoLei1990 GuoLei1990 added the bug Something isn't working label Aug 1, 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 c29b3e1 and 6a8c213.

Files selected for processing (4)
  • packages/core/src/Camera.ts (2 hunks)
  • packages/core/src/xr/XRManager.ts (1 hunks)
  • packages/xr/src/XRManagerExtended.ts (2 hunks)
  • packages/xr/src/feature/camera/XRCameraManager.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/Camera.ts
Additional comments not posted (4)
packages/core/src/xr/XRManager.ts (1)

41-41: Method renamed for clarity.

The method _getCameraClearFlagsMask has been renamed to _getCameraIgnoreClearFlags. This change improves clarity regarding the method's purpose within the context of camera management in XR scenarios.

packages/xr/src/feature/camera/XRCameraManager.ts (1)

128-128: Method renamed for clarity.

The method _getCameraClearFlagsMask has been renamed to _getCameraIgnoreClearFlags. This change improves clarity regarding the method's purpose within the context of camera management in XR scenarios.

packages/xr/src/XRManagerExtended.ts (2)

147-148: Method renamed for clarity.

The method _getCameraClearFlagsMask has been renamed to _getCameraIgnoreClearFlags. This change improves clarity regarding the method's purpose within the context of camera management in XR scenarios.


293-293: Method renamed for clarity.

The method _getCameraClearFlagsMask has been renamed to _getCameraIgnoreClearFlags in the module augmentation for @galacean/engine. This change improves clarity regarding the method's purpose within the context of camera management in XR scenarios.

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 6a8c213 and 56ac4e1.

Files selected for processing (3)
  • packages/core/src/Camera.ts (2 hunks)
  • packages/xr/src/XRManagerExtended.ts (2 hunks)
  • packages/xr/src/feature/camera/XRCameraManager.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/Camera.ts
  • packages/xr/src/XRManagerExtended.ts
  • packages/xr/src/feature/camera/XRCameraManager.ts

@GuoLei1990 GuoLei1990 merged commit 361bc2f into galacean:dev/1.3 Aug 1, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working xr XR related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants