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

Custom config #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Custom config #16

wants to merge 1 commit into from

Conversation

nishinji
Copy link
Owner

No description provided.

Copy link

coderabbitai bot commented May 20, 2024

Walkthrough

The changes streamline and refine the handling of configuration settings by focusing on reducing parameter redundancy and enhancing direct access. The major alterations involve removing unnecessary parameters and introducing direct references to configuration fields. Additionally, there are updates to function signatures and some rearrangement of initialization logic.

Changes

File Path Change Summary
vita3k/app/include/app/functions.h Updated init function signature: removed Config &cfg parameter, now only takes EmuEnvState &state and const Root &root_paths.
vita3k/app/src/app.cpp Updated references to backend_renderer configuration field for window title composition.
vita3k/app/src/app_init.cpp Modified init function: removed cfg parameter, directly accessed state.cfg.current_config.backend_renderer.
vita3k/config/include/config/state.h Added std::string backend_renderer = "OpenGL" to Config struct.
vita3k/gui/include/gui/functions.h Modified set_config function signature to include a bool custom parameter.
vita3k/gui/src/settings_dialog.cpp Various adjustments to configuration struct handling and added platform-based conditional logic.
vita3k/main.cpp Adjusted initialization and usage of Config and EmuEnvState instances, including applying the new set_config signature.

Sequence Diagram(s)

sequenceDiagram
    participant Main as main.cpp
    participant App as app_init.cpp
    participant GUI as settings_dialog.cpp
    
    Main->>App: init(emuenv, root_paths)
    App-->>Main: returns boolean
    
    Main->>Main: if (init succeeded)
    activate GUI
    Main->>GUI: set_config(emuenv, "", false)
    GUI-->>Main: returns
    deactivate GUI
    
    Main->>GUI: set_config(emuenv, app_path)
    GUI-->>Main: returns
Loading
sequenceDiagram
    participant SetConfigFunction as functions.h
    participant State as state.h
    participant CustomDialog as settings_dialog.cpp
    
    SetConfigFunction->>State: Access backend_renderer
    activate State
    State-->>SetConfigFunction: Initial value "OpenGL"
    deactivate State
    
    SetConfigFunction->>CustomDialog: set_config(emuenv, app_path, custom)
    activate CustomDialog
    CustomDialog->>State: Modify backend_renderer conditionally
    State-->>CustomDialog: Returns modified backend_renderer
    deactivate CustomDialog
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6b98b77 and 75981d9.

Files selected for processing (7)
  • vita3k/app/include/app/functions.h (1 hunks)
  • vita3k/app/src/app.cpp (1 hunks)
  • vita3k/app/src/app_init.cpp (2 hunks)
  • vita3k/config/include/config/state.h (1 hunks)
  • vita3k/gui/include/gui/functions.h (1 hunks)
  • vita3k/gui/src/settings_dialog.cpp (14 hunks)
  • vita3k/main.cpp (3 hunks)
Files skipped from review as they are similar to previous changes (7)
  • vita3k/app/include/app/functions.h
  • vita3k/app/src/app.cpp
  • vita3k/app/src/app_init.cpp
  • vita3k/config/include/config/state.h
  • vita3k/gui/include/gui/functions.h
  • vita3k/gui/src/settings_dialog.cpp
  • vita3k/main.cpp

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 Configration 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

@@ -101,7 +101,7 @@ void pre_run_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path
void reset_controller_binding(EmuEnvState &emuenv);
void save_apps_cache(GuiState &gui, EmuEnvState &emuenv);
void save_user(GuiState &gui, EmuEnvState &emuenv, const std::string &user_id);
void set_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void set_config(EmuEnvState &emuenv, const std::string &app_path, bool custom = true);
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The review of the set_config function calls in main.cpp and settings_dialog.cpp reveals that not all calls include the new custom parameter. Specifically:

  • In main.cpp, two calls to set_config do not include the custom parameter.
  • In settings_dialog.cpp, one call to set_config does not include the custom parameter.

These calls need to be updated to include the custom parameter to ensure consistent and correct usage of the function.

  • main.cpp

    • Line: gui::set_config(emuenv, *cfg.run_app_path);
    • Line: gui::set_config(emuenv, emuenv.io.app_path);
  • settings_dialog.cpp

    • Line: set_config(emuenv, emuenv.io.app_path);
Analysis chain

Addition of custom parameter allows for flexible configuration handling.


The rg output indicates that not all calls to set_config include the new custom parameter. Specifically, the calls in main.cpp and settings_dialog.cpp need to be reviewed to ensure they are correctly updated.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `set_config` include the new `custom` parameter.

# Test: Search for the function usage. Expect: All calls include the new parameter.
rg --type cpp $'set_config'

Length of output: 1162



Script:

#!/bin/bash
# Description: Verify specific lines in `main.cpp` and `settings_dialog.cpp` for correct usage of `set_config`.

# Display lines around the calls to `set_config` in `main.cpp`.
rg --context 5 --type cpp $'set_config' vita3k/main.cpp

# Display lines around the calls to `set_config` in `settings_dialog.cpp`.
rg --context 5 --type cpp $'set_config' vita3k/gui/src/settings_dialog.cpp

Length of output: 2594

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

Outside diff range and nitpick comments (2)
vita3k/main.cpp (1)

329-329: Review the necessity of re-setting the configuration on GUI state change.

The call to gui::set_config might be redundant if the GUI configuration is already set correctly in previous steps. Consider removing this call if it is confirmed to be unnecessary to streamline the code.

vita3k/gui/src/settings_dialog.cpp (1)

Line range hint 142-170: Refactor get_custom_config and init_config functions for better maintainability.

The get_custom_config and init_config functions are quite long and perform multiple tasks which could be separated into smaller, more manageable functions. This would improve readability and maintainability. Consider breaking down these functions into smaller ones that handle specific parts of the configuration loading and initialization process.

Also applies to: 236-241

vita3k/gui/src/settings_dialog.cpp Outdated Show resolved Hide resolved
bool init(EmuEnvState &state, Config &cfg, const Root &root_paths) {
state.cfg = std::move(cfg);

bool init(EmuEnvState &state, const Root &root_paths) {
Copy link

Choose a reason for hiding this comment

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

Refactor the initialization function to improve modularity.

Consider breaking down the init function into smaller, more focused functions. This could improve readability and maintainability, especially as the function grows in complexity with more configuration parameters and initialization steps.

@@ -268,7 +266,7 @@

state.backend_renderer = renderer::Backend::Vulkan;

if (string_utils::toupper(state.cfg.backend_renderer) == "OPENGL") {
if (string_utils::toupper(state.cfg.current_config.backend_renderer) == "OPENGL") {
Copy link

Choose a reason for hiding this comment

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

Ensure consistent handling of renderer backends.

The handling of the backend_renderer setting seems inconsistent. For OpenGL, you're setting state.backend_renderer directly, but for Vulkan, you're modifying state.cfg.backend_renderer and serializing the configuration. This could lead to unexpected behavior or bugs.

-        state.cfg.backend_renderer = "Vulkan";
-        config::serialize_config(state.cfg, state.cfg.config_path);
+        state.backend_renderer = renderer::Backend::Vulkan;

Consider aligning the handling of these settings to ensure consistency.

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
if (string_utils::toupper(state.cfg.current_config.backend_renderer) == "OPENGL") {
if (string_utils::toupper(state.cfg.current_config.backend_renderer) == "OPENGL") {
state.backend_renderer = renderer::Backend::Vulkan;

@@ -124,10 +124,14 @@ int main(int argc, char *argv[]) {
LOG_CRITICAL("PLEASE. DO NOT RUN VITA3K AS ADMIN OR WITH ADMIN PRIVILEGES.");
}

Config cfg{};
EmuEnvState emuenv;
EmuEnvState emuenv{};
Copy link

Choose a reason for hiding this comment

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

Initialization of EmuEnvState could be streamlined.

The initialization of EmuEnvState and its configuration could be encapsulated into a constructor or a dedicated initialization method within the EmuEnvState class. This would improve the structure and readability of the code.

Comment on lines +283 to +289
if (string_utils::toupper(config.backend_renderer) == "OPENGL")
emuenv.backend_renderer = renderer::Backend::OpenGL;
else
emuenv.backend_renderer = renderer::Backend::Vulkan;
#else
emuenv.backend_renderer = renderer::Backend::Vulkan;
#endif
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results confirm that there are multiple instances where the handling of the graphics backend renderer is platform-specific, particularly for Apple. This scattered approach can indeed lead to inconsistencies and maintenance challenges.

Key Findings:

  • Platform-Specific Handling: The code includes several #ifdef __APPLE__ directives to handle backend renderer selection differently for Apple.
  • Backend Renderer Selection: In non-Apple platforms, the backend renderer can be either OpenGL or Vulkan, while for Apple, it defaults to Vulkan.
  • Multiple Files Affected: The platform-specific handling is spread across various files, including settings_dialog.cpp, app_init.cpp, and others.

Recommendations:

  1. Centralize Backend Selection Logic: Abstract the platform-specific differences into a separate function or configuration structure to centralize the backend selection logic.
  2. Refactor and Simplify: Minimize the use of platform-specific preprocessor directives by refactoring the code to handle platform differences in a more unified manner.

Specific Locations in the Codebase:

  • vita3k/gui/src/settings_dialog.cpp
  • vita3k/app/src/app_init.cpp
  • vita3k/main.cpp
  • vita3k/config/src/config.cpp

Actionable Directive:

Refactor the code to centralize the handling of the graphics backend renderer. This will ensure consistency across platforms and simplify future maintenance.

Analysis chain

Ensure consistent handling of graphics backend across platforms.

The handling of the graphics backend renderer differs between Apple and other platforms. This could lead to inconsistencies and maintenance challenges. Consider abstracting the platform-specific differences into a separate function or configuration structure to centralize the backend selection logic.

Also applies to: 462-468


The search results indicate several instances where platform-specific handling is implemented, particularly for Apple. This includes various configurations and adjustments specific to Apple's platform, which might lead to inconsistencies in the graphics backend handling.

To ensure consistent handling of the graphics backend across platforms, it is essential to centralize the backend selection logic. The current implementation has scattered platform-specific conditions that can lead to maintenance challenges and potential inconsistencies.

Specific locations in the codebase that need attention:

  • vita3k/renderer/src/vulkan/pipeline_cache.cpp
  • vita3k/renderer/src/vulkan/renderer.cpp
  • vita3k/renderer/src/vulkan/scene.cpp
  • vita3k/mem/src/mem.cpp
  • vita3k/gui/src/vita3k_update.cpp

Recommendations:

  1. Centralize Platform-Specific Logic: Abstract the platform-specific differences into a separate function or configuration structure. This will help maintain consistency and make the code easier to manage.
  2. Review and Refactor: Go through the platform-specific conditions and ensure they are necessary. If possible, refactor the code to minimize platform-specific branches.

Next Steps:

To gather more specific information about the handling of the graphics backend, I will generate a script to search for any additional platform-specific conditions related to the graphics backend selection.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure that the handling of graphics backend is consistent across all platform-specific code sections.

# Test: Search for platform-specific handling of graphics backend. Expect: Consistency in handling.
rg --type cpp -e "ifdef __APPLE__" -A 10 -B 10

Length of output: 24712



Script:

#!/bin/bash
# Description: Ensure that the handling of graphics backend is consistent across all platform-specific code sections.

# Test: Search for platform-specific handling of graphics backend. Expect: Consistency in handling.
rg --type cpp -e "backend_renderer" -A 10 -B 10

Length of output: 45645

@@ -129,6 +129,7 @@ struct Config : YamlLoader {
int audio_volume = 100;
bool ngs_enable = true;
bool pstv_mode = false;
std::string backend_renderer = "OpenGL";
Copy link

Choose a reason for hiding this comment

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

The addition of the backend_renderer field to the Config struct is consistent with the changes in other parts of the codebase. This field should be properly documented to explain its usage and potential values.

Consider adding documentation comments for the backend_renderer field to clarify its purpose and usage within the emulator settings.

@nishinji nishinji force-pushed the custom_config branch 5 times, most recently from b123c7f to 6b98b77 Compare June 14, 2024 13:51
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