-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: master
Are you sure you want to change the base?
Custom config #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -229,9 +229,7 @@ void init_paths(Root &root_paths) { | |||||||
fs::create_directories(root_paths.get_log_path() / "texturelog"); | ||||||||
} | ||||||||
|
||||||||
bool init(EmuEnvState &state, Config &cfg, const Root &root_paths) { | ||||||||
state.cfg = std::move(cfg); | ||||||||
|
||||||||
bool init(EmuEnvState &state, const Root &root_paths) { | ||||||||
state.base_path = root_paths.get_base_path(); | ||||||||
state.default_path = root_paths.get_pref_path(); | ||||||||
state.log_path = root_paths.get_log_path(); | ||||||||
|
@@ -268,7 +266,7 @@ bool init(EmuEnvState &state, Config &cfg, const Root &root_paths) { | |||||||
|
||||||||
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") { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent handling of renderer backends. The handling of the - 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
Suggested change
|
||||||||
#ifndef __APPLE__ | ||||||||
state.backend_renderer = renderer::Backend::OpenGL; | ||||||||
#else | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,7 @@ struct Config : YamlLoader { | |
int audio_volume = 100; | ||
bool ngs_enable = true; | ||
bool pstv_mode = false; | ||
std::string backend_renderer = "OpenGL"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of the Consider adding documentation comments for the |
||
bool high_accuracy = false; | ||
float resolution_multiplier = 1.0f; | ||
bool disable_surface_sync = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The review of the
These calls need to be updated to include the
Analysis chainAddition of The Scripts ExecutedThe 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 |
||
void set_shaders_compiled_display(GuiState &gui, EmuEnvState &emuenv); | ||
void update_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); | ||
void update_last_time_app_used(GuiState &gui, EmuEnvState &emuenv, const std::string &app); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
#include <string> | ||
#include <util/fs.h> | ||
#include <util/log.h> | ||
#include <util/string_utils.h> | ||
|
||
#include <SDL.h> | ||
|
||
|
@@ -138,7 +139,7 @@ static CPUBackend config_cpu_backend; | |
* @return false A custom config for the application has not been found or a custom config has been found | ||
* but it's corrupted or invalid. | ||
*/ | ||
static bool get_custom_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) { | ||
static bool get_custom_config(EmuEnvState &emuenv, const std::string &app_path) { | ||
const auto CUSTOM_CONFIG_PATH{ emuenv.config_path / "config" / fmt::format("config_{}.xml", app_path) }; | ||
|
||
if (fs::exists(CUSTOM_CONFIG_PATH)) { | ||
|
@@ -166,6 +167,7 @@ static bool get_custom_config(GuiState &gui, EmuEnvState &emuenv, const std::str | |
// Load GPU Config | ||
if (!config_child.child("gpu").empty()) { | ||
const auto gpu_child = config_child.child("gpu"); | ||
config.backend_renderer = gpu_child.attribute("backend-renderer").as_string(); | ||
config.high_accuracy = gpu_child.attribute("high-accuracy").as_bool(); | ||
config.resolution_multiplier = gpu_child.attribute("resolution-multiplier").as_float(); | ||
config.disable_surface_sync = gpu_child.attribute("disable-surface-sync").as_bool(); | ||
|
@@ -231,11 +233,12 @@ static std::vector<std::string> list_user_lang; | |
void init_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) { | ||
// If no app-specific config file is being used for the initialized application, | ||
// set up `config` with the values set in the global emulator configuration | ||
if (!get_custom_config(gui, emuenv, app_path)) { | ||
if (!get_custom_config(emuenv, app_path)) { | ||
config.cpu_backend = emuenv.cfg.cpu_backend; | ||
config.cpu_opt = emuenv.cfg.cpu_opt; | ||
config.modules_mode = emuenv.cfg.modules_mode; | ||
config.lle_modules = emuenv.cfg.lle_modules; | ||
config.backend_renderer = emuenv.cfg.backend_renderer; | ||
config.high_accuracy = emuenv.cfg.high_accuracy; | ||
config.resolution_multiplier = emuenv.cfg.resolution_multiplier; | ||
config.disable_surface_sync = emuenv.cfg.disable_surface_sync; | ||
|
@@ -276,6 +279,14 @@ void init_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path | |
current_aniso_filter_log = static_cast<int>(log2f(static_cast<float>(config.anisotropic_filtering))); | ||
max_aniso_filter_log = static_cast<int>(log2f(static_cast<float>(emuenv.renderer->get_max_anisotropic_filtering()))); | ||
audio_backend_idx = (emuenv.cfg.audio_backend == "SDL") ? 0 : 1; | ||
#ifndef __APPLE__ | ||
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 | ||
Comment on lines
+283
to
+289
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Recommendations:
Specific Locations in the Codebase:
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 chainEnsure 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:
Recommendations:
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 executedThe 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 |
||
emuenv.app_path = app_path; | ||
emuenv.display.imgui_render = true; | ||
} | ||
|
@@ -319,6 +330,7 @@ static void save_config(GuiState &gui, EmuEnvState &emuenv) { | |
|
||
// GPU | ||
auto gpu_child = config_child.append_child("gpu"); | ||
gpu_child.append_attribute("backend-renderer") = config.backend_renderer.c_str(); | ||
gpu_child.append_attribute("high-accuracy") = config.high_accuracy; | ||
gpu_child.append_attribute("resolution-multiplier") = config.resolution_multiplier; | ||
gpu_child.append_attribute("disable-surface-sync") = config.disable_surface_sync; | ||
|
@@ -357,6 +369,7 @@ static void save_config(GuiState &gui, EmuEnvState &emuenv) { | |
emuenv.cfg.modules_mode = config.modules_mode; | ||
emuenv.cfg.lle_modules = config.lle_modules; | ||
emuenv.cfg.high_accuracy = config.high_accuracy; | ||
emuenv.cfg.backend_renderer = config.backend_renderer; | ||
emuenv.cfg.resolution_multiplier = config.resolution_multiplier; | ||
emuenv.cfg.disable_surface_sync = config.disable_surface_sync; | ||
emuenv.cfg.screen_filter = config.screen_filter; | ||
|
@@ -383,7 +396,7 @@ static void save_config(GuiState &gui, EmuEnvState &emuenv) { | |
} | ||
|
||
std::string get_cpu_backend(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) { | ||
if (!get_custom_config(gui, emuenv, app_path)) | ||
if (!get_custom_config(emuenv, app_path)) | ||
return emuenv.cfg.cpu_backend; | ||
|
||
return config.cpu_backend; | ||
|
@@ -410,17 +423,19 @@ static void set_vsync_state(const bool &state) { | |
* @param emuenv State of the emulated PlayStation Vita environment | ||
* @param app_path Path to the app or game to get the custom config for | ||
*/ | ||
void set_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) { | ||
void set_config(EmuEnvState &emuenv, const std::string &app_path, bool custom) { | ||
// If a config file is in use, call `get_custom_config()` and set the config | ||
// parameters with the values stored in the app-specific custom config file | ||
if (get_custom_config(gui, emuenv, app_path)) | ||
if (custom && get_custom_config(emuenv, app_path)) { | ||
emuenv.cfg.current_config = config; | ||
else { | ||
LOG_INFO("Using custom config for app: {}", app_path); | ||
} else { | ||
// Else inherit the values from the global emulator config | ||
emuenv.cfg.current_config.cpu_backend = emuenv.cfg.cpu_backend; | ||
emuenv.cfg.current_config.cpu_opt = emuenv.cfg.cpu_opt; | ||
emuenv.cfg.current_config.modules_mode = emuenv.cfg.modules_mode; | ||
emuenv.cfg.current_config.lle_modules = emuenv.cfg.lle_modules; | ||
emuenv.cfg.current_config.backend_renderer = emuenv.cfg.backend_renderer; | ||
emuenv.cfg.current_config.high_accuracy = emuenv.cfg.high_accuracy; | ||
emuenv.cfg.current_config.resolution_multiplier = emuenv.cfg.resolution_multiplier; | ||
emuenv.cfg.current_config.disable_surface_sync = emuenv.cfg.disable_surface_sync; | ||
|
@@ -439,6 +454,19 @@ void set_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) | |
emuenv.cfg.current_config.psn_signed_in = emuenv.cfg.psn_signed_in; | ||
} | ||
|
||
// can happen when launching directly into a game, the renderer is not even initialized yet | ||
if (!emuenv.renderer) | ||
return; | ||
|
||
#ifndef __APPLE__ | ||
if (string_utils::toupper(emuenv.cfg.current_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 | ||
|
||
// If backend render or resolution multiplier is changed when app run, reboot emu and app | ||
if (!emuenv.io.title_id.empty() && ((emuenv.renderer->current_backend != emuenv.backend_renderer) || (emuenv.renderer->res_multiplier != emuenv.cfg.current_config.resolution_multiplier))) { | ||
emuenv.load_exec = true; | ||
|
@@ -583,7 +611,7 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) { | |
#endif | ||
static const char *LIST_BACKEND_RENDERER[] = { "OpenGL", "Vulkan" }; | ||
if (ImGui::Combo(lang.gpu["backend_renderer"].c_str(), reinterpret_cast<int *>(&emuenv.backend_renderer), LIST_BACKEND_RENDERER, IM_ARRAYSIZE(LIST_BACKEND_RENDERER))) | ||
emuenv.cfg.backend_renderer = LIST_BACKEND_RENDERER[int(emuenv.backend_renderer)]; | ||
config.backend_renderer = LIST_BACKEND_RENDERER[int(emuenv.backend_renderer)]; | ||
SetTooltipEx(lang.gpu["select_backend_renderer"].c_str()); | ||
#ifdef __APPLE__ | ||
ImGui::EndDisabled(); | ||
|
@@ -593,7 +621,8 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) { | |
|
||
const bool is_vulkan = (emuenv.backend_renderer == renderer::Backend::Vulkan); | ||
const bool is_ingame = !emuenv.io.title_id.empty(); | ||
if (is_vulkan) { | ||
const bool is_renderer_changed = (emuenv.backend_renderer != emuenv.renderer->current_backend); | ||
if (is_vulkan && !is_renderer_changed) { | ||
const std::vector<std::string> gpu_list_str = emuenv.renderer->get_gpu_list(); | ||
// must convert to a vector of char* | ||
std::vector<const char *> gpu_list; | ||
|
@@ -612,7 +641,7 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) { | |
|
||
if (is_ingame) | ||
ImGui::EndDisabled(); | ||
} else { | ||
} else if (!is_vulkan) { | ||
ImGui::Checkbox(lang.gpu["v_sync"].c_str(), &config.v_sync); | ||
SetTooltipEx(lang.gpu["v_sync_description"].c_str()); | ||
ImGui::SameLine(); | ||
|
@@ -1228,7 +1257,7 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) { | |
if (ImGui::Button(is_apply ? (is_reboot ? lang.main_window["save_reboot"].c_str() : lang.main_window["save_apply"].c_str()) : lang.main_window["save"].c_str(), BUTTON_SIZE)) { | ||
save_config(gui, emuenv); | ||
if (is_apply) | ||
set_config(gui, emuenv, emuenv.io.app_path); | ||
set_config(emuenv, emuenv.io.app_path); | ||
} | ||
SetTooltipEx(lang.main_window["keep_changes"].c_str()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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{}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialization of The initialization of |
||
Config &cfg = emuenv.cfg; | ||
|
||
const auto config_err = config::init_config(cfg, argc, argv, root_paths); | ||
|
||
// to make sure config.current_config is properly initialized... | ||
gui::set_config(emuenv, "", false); | ||
|
||
fs::create_directories(cfg.get_pref_path()); | ||
|
||
if (config_err != Success) { | ||
|
@@ -197,10 +201,13 @@ int main(int argc, char *argv[]) { | |
LOG_INFO("Available ram memory: {} MiB", SDL_GetSystemRAM()); | ||
|
||
app::AppRunType run_type = app::AppRunType::Unknown; | ||
if (cfg.run_app_path) | ||
if (cfg.run_app_path) { | ||
run_type = app::AppRunType::Extracted; | ||
emuenv.config_path = root_paths.get_config_path(); | ||
gui::set_config(emuenv, *cfg.run_app_path); | ||
} | ||
|
||
if (!app::init(emuenv, cfg, root_paths)) { | ||
if (!app::init(emuenv, root_paths)) { | ||
app::error_dialog("Emulated environment initialization failed.", emuenv.window.get()); | ||
return 1; | ||
} | ||
|
@@ -319,15 +326,15 @@ int main(int argc, char *argv[]) { | |
} | ||
} | ||
|
||
gui::set_config(emuenv, emuenv.io.app_path); | ||
|
||
// When backend render is changed before boot app, reboot emu in new backend render and run app | ||
if (emuenv.renderer->current_backend != emuenv.backend_renderer) { | ||
emuenv.load_app_path = emuenv.io.app_path; | ||
run_execv(argv, emuenv); | ||
return Success; | ||
} | ||
|
||
gui::set_config(gui, emuenv, emuenv.io.app_path); | ||
|
||
const auto APP_INDEX = gui::get_app_index(gui, emuenv.io.app_path); | ||
emuenv.app_info.app_version = APP_INDEX->app_ver; | ||
emuenv.app_info.app_category = APP_INDEX->category; | ||
|
There was a problem hiding this comment.
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.