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

Stage: Introduce 2D and 3D for stages. #241

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

kimkulling
Copy link
Owner

@kimkulling kimkulling commented Sep 20, 2024

  • Introduce 2D and 3D mode
    • Some ideas regarding this: I want to make sure that people can use 2D or 3D explicitly by defining their stages
  • Add a unittest for the class stage

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new StageMode enumeration with options for Stage2D, Stage3D, and Invalid.
    • Enhanced Stage class to support different stage modes upon instantiation.
    • Added functionality to retrieve the current stage mode.
    • Updated default stage mode to Stage3D in the application.
  • Bug Fixes

    • Improved resource management in the Stage class with a new clear() method.
  • Tests

    • Added unit tests for the Stage class, covering creation, clearing, and mode retrieval.

Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes encompass updates to multiple files, primarily focusing on the Stage and AnimatorComponent classes. Key modifications include the introduction of a new StageMode enumeration, adjustments to constructors and destructors, and enhancements to event handling in the AppBase class. Additionally, new unit tests for the Stage class have been added, ensuring coverage for its functionalities. The overall structure has been refined to improve modularity and resource management.

Changes

Files Change Summary
contrib/assimp Updated subproject commit reference from f81ea6986ccd30a016ec44a1fd46e2e5c3ff9d4c to 10df90ec144179f97803a382e4f07c0570665864.
src/Engine/Animation/AnimatorComponent.h Destructor declaration changed from ~AnimatorComponent() to ~AnimatorComponent() override. Comment above the class definition modified to be blank.
src/Engine/App/AppBase.cpp Added static methods attachMouseEventPtrs and attachKeyboardEventPtrs. Updated constructor to initialize mStageMode to StageMode::Stage3D. Modified mStage instantiation to include mStageMode. Removed previous definitions of the static functions. Several null checks updated for clarity.
src/Engine/App/AppBase.h Added include for Stage.h. Introduced member variable StageMode mStageMode.
src/Engine/App/Stage.cpp Updated Stage constructor to accept StageMode mode. Destructor updated to call clear(). Added method getStageMode().
src/Engine/App/Stage.h Introduced enum class StageMode with three modes. Updated Stage constructor to accept StageMode. Added private member variable mStageMode. Added method getStageMode(). Introduced clear() method.
test/UnitTests/CMakeLists.txt Added new source file src/App/StageTest.cpp to unit test configuration.
test/UnitTests/src/App/ProjectTest.cpp Updated Stage instantiation in accessStageTest to include StageMode::Stage3D.
test/UnitTests/src/App/StageTest.cpp Introduced new test file with unit tests for the Stage class, including createTest, clearTest, and accessStageModeTest.

Sequence Diagram(s)

sequenceDiagram
    participant AppBase
    participant Stage
    participant EventPtrArray

    AppBase->>Stage: Create Stage("test", StageMode::Stage2D)
    Stage->>Stage: Initialize mStageMode
    AppBase->>EventPtrArray: attachMouseEventPtrs(eventArray)
    AppBase->>EventPtrArray: attachKeyboardEventPtrs(eventArray)
Loading

🐇 In the code, changes abound,
New stages rise from the ground.
Modes of play, both 2D and 3D,
With tests to check, oh so free!
Hopping forward, we refine,
In this code, our dreams align! 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5f2f0f0 and 3e503d9.

Files selected for processing (1)
  • src/Engine/App/AppBase.cpp (14 hunks)
Additional comments not posted (6)
src/Engine/App/AppBase.cpp (6)

61-65: LGTM!

The attachMouseEventPtrs function encapsulates the logic for attaching mouse event pointers to the provided EventPtrArray, which improves code organization and readability.


67-70: LGTM!

The attachKeyboardEventPtrs function encapsulates the logic for attaching keyboard event pointers to the provided EventPtrArray, which improves code organization and readability.


86-86: LGTM!

The constructor of the AppBase class has been updated to initialize the mStageMode member variable to StageMode::Stage3D, indicating a change in the default stage mode used within the application. This change suggests that the stage's behavior or configuration may now depend on the specified stage mode.


288-288: LGTM!

The instantiation of the mStage object has been modified to pass mStageMode as an argument to the Stage constructor, replacing the previous single-argument constructor call. This change suggests that the stage's behavior or configuration may now depend on the specified stage mode.


288-288: Resource not released in destructor.

Resource mStage is acquired by class AppBase but not released in the destructor. It is released from onDestroy on line 358, so this function may need to be called from the destructor.


351-351: LGTM!

The change adds a null check for mPlatformInterface before destroying it. This change improves the safety of the code by ensuring that mPlatformInterface is not null before attempting to destroy it.


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>, please review it.
    -- 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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: 1

Outside diff range and nitpick comments (2)
test/UnitTests/src/App/StageTest.cpp (2)

35-43: LGTM! Consider adding more test cases.

The test case is correctly checking if a Stage object can be created without throwing an exception. However, consider adding more test cases to improve coverage:

  • Test case to check if the Stage object is created with the correct name and mode.
  • Test case to check the behavior of the Stage object in case of invalid inputs (e.g., empty name, invalid mode).
Tools
cppcheck

[error] 35-35: syntax error

(syntaxError)


55-61: LGTM! Consider adding a test case for invalid input.

The test case is correctly checking if the getStageMode method of the Stage class returns the correct stage mode for each Stage object. However, consider adding a test case to check the behavior of the getStageMode method in case of an invalid stage mode.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bba21ed and 5f2f0f0.

Files selected for processing (9)
  • contrib/assimp (1 hunks)
  • src/Engine/Animation/AnimatorComponent.h (1 hunks)
  • src/Engine/App/AppBase.cpp (3 hunks)
  • src/Engine/App/AppBase.h (2 hunks)
  • src/Engine/App/Stage.cpp (1 hunks)
  • src/Engine/App/Stage.h (5 hunks)
  • test/UnitTests/CMakeLists.txt (1 hunks)
  • test/UnitTests/src/App/ProjectTest.cpp (1 hunks)
  • test/UnitTests/src/App/StageTest.cpp (1 hunks)
Files skipped from review due to trivial changes (1)
  • contrib/assimp
Additional context used
cppcheck
test/UnitTests/src/App/StageTest.cpp

[error] 35-35: syntax error

(syntaxError)

Additional comments not posted (19)
test/UnitTests/src/App/StageTest.cpp (1)

45-53: LGTM!

The test case is correctly checking if the clear method of the Stage class works as expected. It checks if the number of worlds is 0 and if the Stage object is empty after calling the clear method.

src/Engine/Animation/AnimatorComponent.h (1)

57-57: LGTM!

The addition of the override specifier for the destructor is a good practice. It improves code clarity and helps catch potential errors related to virtual function overriding.

test/UnitTests/src/App/ProjectTest.cpp (1)

77-77: Verify the test's behavior with the explicit stage mode.

The Stage constructor call has been correctly updated to match the new constructor signature that includes the StageMode argument.

Please review the test's behavior and assertions to ensure they are still valid with the stage explicitly set to Stage3D mode. Update the test as needed.

src/Engine/App/Stage.cpp (4)

41-42: LGTM!

Calling clear() in the destructor is a good practice to ensure proper resource management.


44-50: LGTM!

The clear() method is a good addition to improve resource management. It ensures that resources are properly released and the arrays are cleared.


52-53: LGTM!

The getStageMode() method is a useful addition that provides access to the current stage mode. It aligns with the PR objective and can be helpful for other parts of the codebase.


32-34: Verify the constructor usage across the codebase.

The constructor change aligns with the PR objective of introducing explicit support for 2D and 3D modes. However, it is a breaking change that would require updates to all existing code that instantiates the Stage class.

Run the following script to verify the constructor usage:

test/UnitTests/CMakeLists.txt (1)

33-33: LGTM!

The addition of the src/App/StageTest.cpp file to the unittest_app_src variable is consistent with the PR objective of adding unit tests for the Stage class. This change ensures that the new unit test file is included in the build process.

src/Engine/App/Stage.h (5)

39-44: LGTM!

The StageMode enum class is well-defined and follows a clear naming convention. The Invalid value set to -1 is a good practice to indicate an invalid state, and the Count value can be used to determine the total number of valid enum values.


59-60: LGTM!

The constructor change aligns with the PR objective of introducing 2D and 3D modes for stages. The additional mode parameter of type StageMode allows specifying the stage mode during instantiation, which is a good design choice.


65-70: Ensure proper implementation of the clear() method.

The addition of the clear() and getStageMode() methods is a good design choice. The clear() method provides a way to reset the stage to its initial state, while the getStageMode() method allows retrieving the current stage mode.

Please ensure that the clear() method is properly implemented in the corresponding source file to perform the necessary cleanup and reset operations.


99-101: Verify the usage of the index parameter.

The change to the getActiveWorld() method to accept an index parameter is a good addition, as it suggests support for multiple active worlds in a stage. Returning a pointer is appropriate to handle cases where no active world exists at the given index.

Please ensure that the index parameter is properly validated and handled in the implementation to avoid out-of-bounds access.


Line range hint 111-129: LGTM!

Moving the implementation of the isEmpty() method outside the class definition is a valid coding style choice and doesn't affect the functionality. The method relies on the isEmpty() method of the mRenderWorlds array to determine if the stage is empty, which is a straightforward and easy-to-understand approach.

src/Engine/App/AppBase.cpp (4)

61-65: LGTM!

The attachMouseEventPtrs function correctly adds the necessary mouse event pointers to the provided EventPtrArray, improving code organization.


67-70: LGTM!

The attachKeyboardEventPtrs function correctly adds the necessary keyboard event pointers to the provided EventPtrArray, improving code organization.


86-86: LGTM!

The constructor change correctly initializes the mStageMode member variable to StageMode::Stage3D, indicating the default stage mode for the application.


283-283: LGTM!

The mStage object instantiation correctly passes the mStageMode as an argument to the Stage constructor, allowing the stage to be configured based on the specified mode.

src/Engine/App/AppBase.h (2)

27-27: LGTM!

The inclusion of the Stage.h header file in AppBase.h is necessary to enable the AppBase class to access and manage the Stage instances, which aligns with the PR objective of introducing 2D and 3D modes for stages.


293-293: Verify the usage of mStageMode in the codebase.

The addition of the mStageMode member variable to the AppBase class is necessary to keep track of the current stage mode (2D or 3D), which aligns with the PR objective. Please ensure that the mStageMode is properly initialized and used throughout the codebase to influence the behavior or interactions of the AppBase class based on the current stage mode.

Run the following script to verify the usage of mStageMode:

Verification successful

Approval: mStageMode is properly initialized and used

The verification process confirms that mStageMode is correctly implemented and utilized in the codebase:

  • Initialized in AppBase constructor with StageMode::Stage3D
  • Used to create the Stage object in AppBase
  • Present in both AppBase and Stage classes for consistent stage mode handling
  • Accessible through a getter method in Stage class

These findings indicate that the mStageMode member variable is well-integrated into the relevant parts of the codebase, supporting the PR objective of introducing explicit 2D and 3D mode support.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `mStageMode` in the codebase.

# Test: Search for the initialization of `mStageMode`. Expect: At least one occurrence.
rg --type cpp $'mStageMode\s*='

# Test: Search for the usage of `mStageMode`. Expect: Multiple occurrences.
rg --type cpp $'mStageMode'

Length of output: 397

@@ -49,12 +49,12 @@ struct AnimationTrack {
//-------------------------------------------------------------------------------------------------
/// @ingroup Engine
///
/// @brief Describes the base class for all components.
/// @brief
Copy link

Choose a reason for hiding this comment

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

Add a brief description for the class.

The brief comment for the class AnimatorComponent has been left empty. It's important to provide a concise description of the class to help readers understand its purpose and functionality.

Consider adding a brief description, such as:

/// @brief Represents a component that manages animation tracks and updates the owner entity's animation state.

src/Engine/App/AppBase.cpp Dismissed Show dismissed Hide dismissed
- Add debug statements for better debugging cabs.
@kimkulling kimkulling merged commit 12d1cf5 into master Sep 20, 2024
3 checks passed
@kimkulling kimkulling deleted the kimkulling/feature_introduce_stagemodes branch September 20, 2024 20:23
@coderabbitai coderabbitai bot mentioned this pull request Dec 22, 2024
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.

1 participant