jak-project/game/settings/settings.cpp

141 lines
4.7 KiB
C++
Raw Normal View History

#include "settings.h"
#include "common/log/log.h"
#include "common/util/json_util.h"
#include "game/runtime.h"
namespace game_settings {
void to_json(json& j, const DebugSettings& obj) {
json_serialize(version);
json_serialize(show_imgui);
json_serialize(imgui_font_size);
json_serialize(monospaced_font);
json_serialize(alternate_style);
json_serialize(ignore_hide_imgui);
json_serialize(text_filters);
json_serialize(text_check_range);
json_serialize(text_max_range);
json_serialize(hide_imgui_key);
}
void from_json(const json& j, DebugSettings& obj) {
json_deserialize_if_exists(version);
json_deserialize_if_exists(show_imgui);
json_deserialize_if_exists(imgui_font_size);
json_deserialize_if_exists(monospaced_font);
json_deserialize_if_exists(alternate_style);
json_deserialize_if_exists(ignore_hide_imgui);
json_deserialize_if_exists(text_filters);
json_deserialize_if_exists(text_check_range);
json_deserialize_if_exists(text_max_range);
json_deserialize_if_exists(hide_imgui_key);
}
DebugSettings::DebugSettings() {
try {
std::string file_path =
(file_util::get_user_misc_dir(g_game_version) / "debug-settings.json").string();
if (!file_util::file_exists(file_path)) {
return;
}
lg::info("Loading display settings at {}", file_path);
auto raw = file_util::read_text_file(file_path);
from_json(parse_commented_json(raw, "debug-settings.json"), *this);
} catch (std::exception& e) {
// do nothing
lg::error("Error encountered when attempting to load debug settings {}", e.what());
// TODO - make sure a bad debug-settings.json is fine, check others below as well
}
}
void DebugSettings::save_settings() {
json data = *this;
auto debug_settings_filename =
file_util::get_user_misc_dir(g_game_version) / "debug-settings.json";
file_util::create_dir_if_needed_for_file(debug_settings_filename);
file_util::write_text_file(debug_settings_filename, data.dump(2));
}
void to_json(json& j, const DisplaySettings& obj) {
game: disable keyboard input by default, give users a way to enable it via the imgui menu (#3295) It was narrowed down recently that a lot of people have issues with the controller input because of Steam Input working as intended. Steam Input can be configured to replicate controller inputs as keyboard inputs (for example, pressing X on your controller presses Enter on the keyboard). This results in the problem of "jumping pauses the game" and similar issues. This is a consequence of the intended behaviour of the game listening to all input sources at the same time. Since the vast majority of players are using controllers over keyboards, it makes sense to disable the keyboard input by default to solve this problem. However that makes things awkward for users that want to use the keyboard (how do they enable the setting). The solution is a new imgui option in the settings menu: ![Screenshot 2024-01-07 141224](https://github.com/open-goal/jak-project/assets/13153231/6f9ffa2d-be7a-433d-b698-15b70210e97e) **Known issue that I don't care about** -- in Jak 1's menu code, since the flags are controlled by pointers to values instead of a lambda like in jak 2, the menu won't update live with the imgui option. This has no functional impact and I don't care enough to fix it. I also made the pc-settings.gc file persist on first load if the file wasn't found. Hopefully this helps diagnose the support issues related to the black screen. # Why not just ignore the keyboard inputs for a period of time? This won't work, the keyboard is polled every frame. Therefore if you hold down the X button on your controller, steam is continuously signaling that `Enter` is held down on the keyboard. Yes it would be possible to completely disable the keyboard while the controller is being used, but this defeats the purpose of creating an input system that allows multiple input sources at the same time. With an explicit option, not only can the user decide the behaviour they want (do they want the keyboard ignored or simultaneously listened to) but we avoid breaking strange edge-cases in usage leading to never ending complexity: - ie. imagine steam input sends events to the mouse, well you can't disable the mouse while using the keyboard because most times people are using mouse and keyboard - ie. a user that wants to hold a direction with the keyboard and press buttons on the controller in tandem (something i frequently do while TAS'ing, to move in a perfect straight line)
2024-02-23 18:19:07 -05:00
json_serialize(version);
json_serialize(display_id);
json_serialize(window_xpos);
json_serialize(window_ypos);
}
void from_json(const json& j, DisplaySettings& obj) {
json_deserialize_if_exists(version);
json_deserialize_if_exists(display_id);
json_deserialize_if_exists(window_xpos);
json_deserialize_if_exists(window_ypos);
}
DisplaySettings::DisplaySettings() {
try {
std::string file_path =
(file_util::get_user_settings_dir(g_game_version) / "display-settings.json").string();
if (!file_util::file_exists(file_path)) {
return;
}
lg::info("Loading display settings at {}", file_path);
auto raw = file_util::read_text_file(file_path);
from_json(parse_commented_json(raw, "display-settings.json"), *this);
} catch (std::exception& e) {
// do nothing
lg::error("Error encountered when attempting to load display settings {}", e.what());
}
}
void DisplaySettings::save_settings() {
json data = *this;
auto file_path = file_util::get_user_settings_dir(g_game_version) / "display-settings.json";
file_util::create_dir_if_needed_for_file(file_path);
file_util::write_text_file(file_path, data.dump(2));
}
void to_json(json& j, const InputSettings& obj) {
game: disable keyboard input by default, give users a way to enable it via the imgui menu (#3295) It was narrowed down recently that a lot of people have issues with the controller input because of Steam Input working as intended. Steam Input can be configured to replicate controller inputs as keyboard inputs (for example, pressing X on your controller presses Enter on the keyboard). This results in the problem of "jumping pauses the game" and similar issues. This is a consequence of the intended behaviour of the game listening to all input sources at the same time. Since the vast majority of players are using controllers over keyboards, it makes sense to disable the keyboard input by default to solve this problem. However that makes things awkward for users that want to use the keyboard (how do they enable the setting). The solution is a new imgui option in the settings menu: ![Screenshot 2024-01-07 141224](https://github.com/open-goal/jak-project/assets/13153231/6f9ffa2d-be7a-433d-b698-15b70210e97e) **Known issue that I don't care about** -- in Jak 1's menu code, since the flags are controlled by pointers to values instead of a lambda like in jak 2, the menu won't update live with the imgui option. This has no functional impact and I don't care enough to fix it. I also made the pc-settings.gc file persist on first load if the file wasn't found. Hopefully this helps diagnose the support issues related to the black screen. # Why not just ignore the keyboard inputs for a period of time? This won't work, the keyboard is polled every frame. Therefore if you hold down the X button on your controller, steam is continuously signaling that `Enter` is held down on the keyboard. Yes it would be possible to completely disable the keyboard while the controller is being used, but this defeats the purpose of creating an input system that allows multiple input sources at the same time. With an explicit option, not only can the user decide the behaviour they want (do they want the keyboard ignored or simultaneously listened to) but we avoid breaking strange edge-cases in usage leading to never ending complexity: - ie. imagine steam input sends events to the mouse, well you can't disable the mouse while using the keyboard because most times people are using mouse and keyboard - ie. a user that wants to hold a direction with the keyboard and press buttons on the controller in tandem (something i frequently do while TAS'ing, to move in a perfect straight line)
2024-02-23 18:19:07 -05:00
json_serialize(version);
json_serialize(last_selected_controller_guid);
json_serialize(controller_port_mapping);
json_serialize(controller_binds);
json_serialize(keyboard_binds);
json_serialize(mouse_binds);
json_serialize(keyboard_enabled);
}
void from_json(const json& j, InputSettings& obj) {
json_deserialize_if_exists(version);
json_deserialize_if_exists(last_selected_controller_guid);
json_deserialize_if_exists(controller_port_mapping);
json_deserialize_if_exists(controller_binds);
json_deserialize_if_exists(keyboard_binds);
json_deserialize_if_exists(mouse_binds);
game: disable keyboard input by default, give users a way to enable it via the imgui menu (#3295) It was narrowed down recently that a lot of people have issues with the controller input because of Steam Input working as intended. Steam Input can be configured to replicate controller inputs as keyboard inputs (for example, pressing X on your controller presses Enter on the keyboard). This results in the problem of "jumping pauses the game" and similar issues. This is a consequence of the intended behaviour of the game listening to all input sources at the same time. Since the vast majority of players are using controllers over keyboards, it makes sense to disable the keyboard input by default to solve this problem. However that makes things awkward for users that want to use the keyboard (how do they enable the setting). The solution is a new imgui option in the settings menu: ![Screenshot 2024-01-07 141224](https://github.com/open-goal/jak-project/assets/13153231/6f9ffa2d-be7a-433d-b698-15b70210e97e) **Known issue that I don't care about** -- in Jak 1's menu code, since the flags are controlled by pointers to values instead of a lambda like in jak 2, the menu won't update live with the imgui option. This has no functional impact and I don't care enough to fix it. I also made the pc-settings.gc file persist on first load if the file wasn't found. Hopefully this helps diagnose the support issues related to the black screen. # Why not just ignore the keyboard inputs for a period of time? This won't work, the keyboard is polled every frame. Therefore if you hold down the X button on your controller, steam is continuously signaling that `Enter` is held down on the keyboard. Yes it would be possible to completely disable the keyboard while the controller is being used, but this defeats the purpose of creating an input system that allows multiple input sources at the same time. With an explicit option, not only can the user decide the behaviour they want (do they want the keyboard ignored or simultaneously listened to) but we avoid breaking strange edge-cases in usage leading to never ending complexity: - ie. imagine steam input sends events to the mouse, well you can't disable the mouse while using the keyboard because most times people are using mouse and keyboard - ie. a user that wants to hold a direction with the keyboard and press buttons on the controller in tandem (something i frequently do while TAS'ing, to move in a perfect straight line)
2024-02-23 18:19:07 -05:00
json_deserialize_if_exists(keyboard_enabled);
}
InputSettings::InputSettings() {
try {
keyboard_binds = DEFAULT_KEYBOARD_BINDS;
mouse_binds = DEFAULT_MOUSE_BINDS;
std::string file_path =
(file_util::get_user_settings_dir(g_game_version) / "input-settings.json").string();
if (!file_util::file_exists(file_path)) {
return;
}
lg::info("Loading display settings at {}", file_path);
auto raw = file_util::read_text_file(file_path);
from_json(parse_commented_json(raw, "input-settings.json"), *this);
} catch (std::exception& e) {
// do nothing
lg::error("Error encountered when attempting to load input settings {}", e.what());
}
}
void InputSettings::save_settings() {
json data = *this;
auto file_path = file_util::get_user_settings_dir(g_game_version) / "input-settings.json";
file_util::create_dir_if_needed_for_file(file_path);
file_util::write_text_file(file_path, data.dump(2));
}
} // namespace game_settings