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

Introduce and integrate keymap #224

Merged
merged 4 commits into from
Aug 19, 2024
Merged

Conversation

kimkulling
Copy link
Owner

@kimkulling kimkulling commented Aug 19, 2024

  • Introduce keymap
  • Integrate keymap to transform controller
  • Make sure that lower- and uppercase keys are working for the transform in the modelviewers

Summary by CodeRabbit

  • New Features

    • Enhanced keyboard input handling through a new KeyboardMap struct for key bindings.
    • Added an Invalid state to better represent command validation.
  • Improvements

    • Streamlined key binding retrieval and management for improved modularity and maintainability.
    • Clarified documentation for methods in the animation control system.
  • Bug Fixes

    • Updated the representation of unknown key states to improve error handling.

@kimkulling kimkulling self-assigned this Aug 19, 2024
@kimkulling kimkulling added the Feature request All feature requests label Aug 19, 2024
Copy link

coderabbitai bot commented Aug 19, 2024

Walkthrough

The recent updates significantly improve keyboard input handling in the application by introducing a new KeyboardMap structure. This change transitions key binding management from static methods to instance-specific methods, enhancing modularity and maintainability. Additionally, external dependencies have been updated to their latest versions, ensuring the project remains robust and up-to-date while facilitating a more dynamic response to user inputs.

Changes

File(s) Change Summary
contrib/assimp, contrib/cppcore, contrib/vcpkg Updated subproject commit identifiers to newer versions; no changes to functionality noted.
samples/00_HelloWorld/HelloWorld.cpp, samples/04_terrain/TerrainRendering.cpp Updated keyboard input handling to utilize instance-specific methods for key binding retrieval, enhancing code encapsulation.
src/Engine/Animation/AnimatorBase.h Improved TransformCommandType enum with an Invalid state, added a new getKeyBinding method in AnimationControllerBase, and enhanced documentation.
src/Engine/App/TransformController.cpp, src/Engine/App/TransformController.h Reworked key binding logic to initialize mappings at construction, introduced KeyboardMap struct, and changed getKeyBinding to a non-static method overriding a base class implementation.
src/Engine/Platform/KeyTypes.h Altered KEY_UNKNOWN from 0 to -1 for improved error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant TransformController
    participant KeyboardMap

    User->>App: Press Key
    App->>TransformController: onUpdate()
    TransformController->>KeyboardMap: getKeyBinding(Key)
    KeyboardMap-->>TransformController: Return TransformCommandType
    TransformController-->>App: Return Command
    App-->>User: Execute Command
Loading

🐇 In the realm of keys, both bright and new,
A rabbit hops forth with commands that accrue.
With mappings reformed and logic refined,
The code now dances, all joyfully aligned!
So let’s leap and twirl, in this code we delight,
For in every change, our future shines bright! 🌟


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between db9a4f9 and 4d3ba7a.

Files selected for processing (9)
  • contrib/assimp (1 hunks)
  • contrib/cppcore (1 hunks)
  • contrib/vcpkg (1 hunks)
  • samples/00_HelloWorld/HelloWorld.cpp (1 hunks)
  • samples/04_terrain/TerrainRendering.cpp (1 hunks)
  • src/Engine/Animation/AnimatorBase.h (4 hunks)
  • src/Engine/App/TransformController.cpp (1 hunks)
  • src/Engine/App/TransformController.h (4 hunks)
  • src/Engine/Platform/KeyTypes.h (1 hunks)
Files skipped from review due to trivial changes (3)
  • contrib/assimp
  • contrib/cppcore
  • contrib/vcpkg
Additional comments not posted (9)
src/Engine/Animation/AnimatorBase.h (2)

Line range hint 118-128: LGTM! Improved enum structure.

The addition of Invalid and Count entries enhances error handling and command enumeration.


147-150: LGTM! New method for key binding retrieval.

The getKeyBinding method enhances the class's functionality by allowing retrieval of command codes based on key bindings.

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

39-76: LGTM! Struct for key binding management.

The KeyboardMap struct effectively encapsulates key bindings and enhances modularity and maintainability.


97-97: LGTM! Instance-specific key binding management.

Changing getKeyBinding to a non-static method allows for instance-specific key binding management.

samples/00_HelloWorld/HelloWorld.cpp (1)

108-108: LGTM! Instance-specific key binding retrieval.

Using mKeyboardTransCtrl->getKeyBinding(key) allows for more dynamic or instance-specific behavior in response to keyboard events.

src/Engine/Platform/KeyTypes.h (1)

33-33: Verify the impact of KEY_UNKNOWN value change.

Changing KEY_UNKNOWN from 0 to -1 may affect how unknown keys are handled. Ensure that this change does not introduce unintended behavior in the application.

src/Engine/App/TransformController.cpp (2)

38-40: LGTM! Improved keyboard map initialization.

The constructor now initializes mKeyboardMap and sets its default state, enhancing the setup of keyboard mappings.


43-44: LGTM! Simplified key binding retrieval.

The getKeyBinding method now uses mKeyboardMap for key retrieval, centralizing the key-command mapping logic.

samples/04_terrain/TerrainRendering.cpp (1)

189-189: Encapsulation Improvement in Key Binding Retrieval.

The change to use mKeyboardTransCtrl->getKeyBinding(key) enhances encapsulation by retrieving key bindings through the instance's method. This likely improves modularity and maintainability by allowing context-specific behavior for key binding management.

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

Outside diff range, codebase verification and nitpick comments (1)
src/Engine/App/TransformController.h (1)

83-88: Clarify comment typo in get method.

The comment for the get method contains a typo: "actieve" should be "active".

- /// @brief Get the actieve mapping.
+ /// @brief Get the active mapping.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4d3ba7a and 82e47f1.

Files selected for processing (1)
  • src/Engine/App/TransformController.h (4 hunks)
Additional comments not posted (2)
src/Engine/App/TransformController.h (2)

52-56: Ensure the array size matches the key range.

The init method initializes the array with Animation::TransformCommandType::Invalid. Ensure that Platform::KEY_LAST accurately represents the total number of keys to avoid out-of-bounds errors.

Verification successful

Verification Successful: Array size matches key range.

The Platform::KEY_LAST is correctly used to represent the total number of keys, as it follows the last enumerated key (KEY_UNDO = 322) in the enumeration. This ensures the array size matches the key range, preventing out-of-bounds errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that Platform::KEY_LAST matches the total number of keys defined.

# Test: Check the definition of Platform::KEY_LAST.
rg --type cpp --word-regexp 'KEY_LAST'

Length of output: 452


Script:

#!/bin/bash
# Description: Locate the definition of Platform::KEY_LAST in KeyTypes.h.

# Test: Find the definition of KEY_LAST in the suspected file.
rg --type cpp --word-regexp 'KEY_LAST' -A 5 src/Engine/Platform/KeyTypes.h

Length of output: 135


Script:

#!/bin/bash
# Description: Locate the complete context of Platform::KEY_LAST definition in KeyTypes.h.

# Test: Find the definition of KEY_LAST with more context lines before it.
rg --type cpp --word-regexp 'KEY_LAST' -B 10 src/Engine/Platform/KeyTypes.h

Length of output: 373


111-111: Ensure getKeyBinding method consistency.

The getKeyBinding method is now non-static and overrides a base class method. Ensure that all instances of TransformController are correctly instantiated and that this change doesn't break existing functionality.

Verification successful

getKeyBinding Method Change is Consistent

The getKeyBinding method's change to a non-static version is consistent with the codebase, as TransformController is instantiated through getTransformController in AppBase.cpp. This ensures that instances are correctly created and used throughout the codebase.

  • AppBase.cpp: Instantiates TransformController using getTransformController.
  • HelloWorld.cpp, TerrainRendering.cpp, OsreEdApp.cpp: Use the getTransformController method to obtain instances.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all instances of TransformController are correctly instantiated.

# Test: Search for TransformController instantiations.
rg --type cpp 'TransformController\s+\w+\s*\('

Length of output: 48


Script:

#!/bin/bash
# Description: Broaden the search for TransformController instantiations, including header files and potential indirect instantiation patterns.

# Search for TransformController instantiations in both source and header files.
rg --type-add 'cpp-header:*.{h,hpp}' --type cpp --type cpp-header 'TransformController'

# Search for any factory methods or patterns that might instantiate TransformController.
rg --type cpp 'create.*TransformController'

Length of output: 193


Script:

#!/bin/bash
# Description: Correct the syntax error and search for TransformController instantiations across source and header files.

# Corrected search for TransformController instantiations in both source and header files.
rg --type-add 'cpp:*.{cpp,h,hpp}' 'TransformController'

# Re-run the search for any factory methods or patterns that might instantiate TransformController.
rg --type cpp 'create.*TransformController'

Length of output: 2082

src/Engine/App/TransformController.h Show resolved Hide resolved
src/Engine/App/TransformController.h Show resolved Hide resolved
src/Engine/App/TransformController.h Outdated Show resolved Hide resolved
src/Engine/App/TransformController.h Show resolved Hide resolved
Fix review findings.
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 82e47f1 and 36bd8b3.

Files selected for processing (1)
  • src/Engine/App/TransformController.h (4 hunks)
Additional comments not posted (4)
src/Engine/App/TransformController.h (4)

39-41: Existing Comment: Consider using a more dynamic container for key mappings.

The use of cppcore::TStaticArray limits flexibility in handling key mappings. Consider using a more dynamic container like std::unordered_map for easier management and potential future extensions.


58-74: Existing Comment: Consolidate key-command mappings.

The setDefault method duplicates mappings for uppercase and lowercase keys. Consider using a helper function to reduce redundancy and improve readability.


79-86: Existing Comment: Validate key input in set method.

The set method directly assigns values to KeyArray without validation. Consider adding checks to ensure the key is within valid bounds.


127-127: Existing Comment: Consider encapsulating KeyboardMap initialization.

The mKeyboardMap member is directly instantiated. Consider initializing it with a default key mapping within the constructor to ensure consistent behavior across instances.

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 36bd8b3 and 1131ed8.

Files selected for processing (1)
  • src/Engine/App/TransformController.h (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Engine/App/TransformController.h

@kimkulling kimkulling merged commit 60aa628 into master Aug 19, 2024
2 checks passed
@kimkulling kimkulling deleted the kimkulling/introduce_keymap branch August 19, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request All feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants