Update code style

This commit is contained in:
kalaposfos13 2024-11-15 10:33:56 +01:00
parent 9d6dd79486
commit 91e30ac62b
6 changed files with 73 additions and 76 deletions

View File

@ -701,7 +701,7 @@ void setDefaultValues() {
gpuId = -1;
}
constexpr std::string_view getDefaultKeyboardConfig() {
constexpr std::string_view GetDefaultKeyboardConfig() {
return R"(#This is the default keybinding config
#To change per-game configs, modify the CUSAXXXXX.ini files
#To change the default config that applies to new games without modifying already existing configs, modify default.ini
@ -780,7 +780,7 @@ axis_left_y_plus = s;
)";
}
std::filesystem::path getFoolproofKbmConfigFile(const std::string& game_id) {
std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id) {
// Read configuration file of the game, and if it doesn't exist, generate it from default
// If that doesn't exist either, generate that from getDefaultConfig() and try again
// If even the folder is missing, we start with that.
@ -797,7 +797,7 @@ std::filesystem::path getFoolproofKbmConfigFile(const std::string& game_id) {
// Check if the default config exists
if (!std::filesystem::exists(default_config_file)) {
// If the default config is also missing, create it from getDefaultConfig()
const auto default_config = getDefaultKeyboardConfig();
const auto default_config = GetDefaultKeyboardConfig();
std::ofstream default_config_stream(default_config_file);
if (default_config_stream) {
default_config_stream << default_config;

View File

@ -124,7 +124,7 @@ std::string getEmulatorLanguage();
void setDefaultValues();
// todo: name and function location pending
std::filesystem::path getFoolproofKbmConfigFile(const std::string& game_id = "");
std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id = "");
// settings
u32 GetLanguage();

View File

@ -81,13 +81,13 @@ ControllerOutput output_array[] = {
ControllerOutput(0, Input::Axis::AxisMax)};
// We had to go through 3 files of indirection just to update a flag
void toggleMouseEnabled() {
void ToggleMouseEnabled() {
mouse_enabled ^= true;
}
// parsing related functions
// syntax: 'name, name,name' or 'name,name' or 'name'
InputBinding getBindingFromString(std::string& line) {
InputBinding GetBindingFromString(std::string& line) {
u32 key1 = 0, key2 = 0, key3 = 0;
// Split the string by commas
@ -118,7 +118,7 @@ InputBinding getBindingFromString(std::string& line) {
}
// function that takes a controlleroutput, and returns the array's corresponding element's pointer
ControllerOutput* getOutputPointer(const ControllerOutput& parsed) {
ControllerOutput* GetOutputPointer(const ControllerOutput& parsed) {
// i wonder how long until someone notices this or I get rid of it
for (int i = 0; i[output_array] != ControllerOutput(0, Axis::AxisMax); i++) {
if (i[output_array] == parsed) {
@ -128,11 +128,11 @@ ControllerOutput* getOutputPointer(const ControllerOutput& parsed) {
return nullptr;
}
void parseInputConfig(const std::string game_id = "") {
void ParseInputConfig(const std::string game_id = "") {
const auto config_file = Config::getFoolproofKbmConfigFile(game_id);
const auto config_file = Config::GetFoolproofKbmConfigFile(game_id);
// todo: change usages of this to getFoolproofKbmConfigFile (in the gui)
// todo: change usages of this to GetFoolproofKbmConfigFile (in the gui)
if (game_id == "") {
return;
}
@ -186,15 +186,15 @@ void parseInputConfig(const std::string game_id = "") {
if (output_string == "key_toggle") {
if (comma_pos != std::string::npos) {
// handle key-to-key toggling (separate list?)
InputBinding toggle_keys = getBindingFromString(input_string);
if (toggle_keys.keyCount() != 2) {
InputBinding toggle_keys = GetBindingFromString(input_string);
if (toggle_keys.KeyCount() != 2) {
LOG_ERROR(Input,
"Syntax error: Please provide exactly 2 keys: "
"first is the toggler, the second is the key to toggle: {}",
line);
continue;
}
ControllerOutput* toggle_out = getOutputPointer(ControllerOutput(KEY_TOGGLE));
ControllerOutput* toggle_out = GetOutputPointer(ControllerOutput(KEY_TOGGLE));
BindingConnection toggle_connection =
BindingConnection(InputBinding(toggle_keys.key2), toggle_out, toggle_keys.key3);
connections.insert(connections.end(), toggle_connection);
@ -221,24 +221,24 @@ void parseInputConfig(const std::string game_id = "") {
}
// normal cases
InputBinding binding = getBindingFromString(input_string);
InputBinding binding = GetBindingFromString(input_string);
BindingConnection connection(0, nullptr);
auto button_it = string_to_cbutton_map.find(output_string);
auto axis_it = string_to_axis_map.find(output_string);
if (binding.isEmpty()) {
if (binding.IsEmpty()) {
LOG_DEBUG(Input, "Invalid format at line: {}, data: \"{}\", skipping line.", lineCount,
line);
continue;
}
if (button_it != string_to_cbutton_map.end()) {
connection =
BindingConnection(binding, getOutputPointer(ControllerOutput(button_it->second)));
BindingConnection(binding, GetOutputPointer(ControllerOutput(button_it->second)));
connections.insert(connections.end(), connection);
} else if (axis_it != string_to_axis_map.end()) {
connection = BindingConnection(
binding, getOutputPointer(ControllerOutput(0, axis_it->second.axis)),
binding, GetOutputPointer(ControllerOutput(0, axis_it->second.axis)),
axis_it->second.value);
connections.insert(connections.end(), connection);
} else {
@ -253,7 +253,7 @@ void parseInputConfig(const std::string game_id = "") {
LOG_DEBUG(Input, "Done parsing the input config!");
}
u32 getMouseWheelEvent(const SDL_Event& event) {
u32 GetMouseWheelEvent(const SDL_Event& event) {
if (event.type != SDL_EVENT_MOUSE_WHEEL && event.type != SDL_EVENT_MOUSE_WHEEL_OFF) {
LOG_DEBUG(Input, "Something went wrong with wheel input parsing!");
return 0;
@ -270,7 +270,7 @@ u32 getMouseWheelEvent(const SDL_Event& event) {
return (u32)-1;
}
u32 InputBinding::getInputIDFromEvent(const SDL_Event& e) {
u32 InputBinding::GetInputIDFromEvent(const SDL_Event& e) {
switch (e.type) {
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
@ -280,18 +280,18 @@ u32 InputBinding::getInputIDFromEvent(const SDL_Event& e) {
return (u32)e.button.button;
case SDL_EVENT_MOUSE_WHEEL:
case SDL_EVENT_MOUSE_WHEEL_OFF:
return getMouseWheelEvent(e);
return GetMouseWheelEvent(e);
default:
return (u32)-1;
}
}
GameController* ControllerOutput::controller = nullptr;
void ControllerOutput::setControllerOutputController(GameController* c) {
void ControllerOutput::GetControllerOutputController(GameController* c) {
ControllerOutput::controller = c;
}
void toggleKeyInList(u32 key) {
void ToggleKeyInList(u32 key) {
auto it = std::find(toggled_keys.begin(), toggled_keys.end(), key);
if (it == toggled_keys.end()) {
toggled_keys.insert(toggled_keys.end(), key);
@ -302,7 +302,7 @@ void toggleKeyInList(u32 key) {
}
}
void ControllerOutput::update(bool pressed, u32 param) {
void ControllerOutput::Update(bool pressed, u32 param) {
float touchpad_x = 0;
if (button != 0) {
switch (button) {
@ -321,7 +321,7 @@ void ControllerOutput::update(bool pressed, u32 param) {
break;
case KEY_TOGGLE:
if (pressed) {
toggleKeyInList(param);
ToggleKeyInList(param);
}
break;
default: // is a normal key (hopefully)
@ -358,7 +358,7 @@ void ControllerOutput::update(bool pressed, u32 param) {
LOG_DEBUG(Input, "Controller output with no values detected!");
}
}
void ControllerOutput::addUpdate(bool pressed, u32 param) {
void ControllerOutput::AddUpdate(bool pressed, u32 param) {
float touchpad_x = 0;
if (button != 0) {
@ -381,7 +381,7 @@ void ControllerOutput::addUpdate(bool pressed, u32 param) {
break;
case KEY_TOGGLE:
if (pressed) {
toggleKeyInList(param);
ToggleKeyInList(param);
}
break;
default: // is a normal key (hopefully)
@ -419,7 +419,7 @@ void ControllerOutput::addUpdate(bool pressed, u32 param) {
}
}
void updatePressedKeys(u32 value, bool is_pressed) {
void UpdatePressedKeys(u32 value, bool is_pressed) {
if (is_pressed) {
// Find the correct position for insertion to maintain order
auto it =
@ -442,7 +442,7 @@ void updatePressedKeys(u32 value, bool is_pressed) {
}
// Check if a given binding's all keys are currently active.
bool isInputActive(const InputBinding& i) {
bool IsInputActive(const InputBinding& i) {
// Extract keys from InputBinding and ignore unused (0) keys
std::list<uint32_t> input_keys = {i.key1, i.key2, i.key3};
input_keys.remove(0);
@ -484,11 +484,11 @@ bool isInputActive(const InputBinding& i) {
*flag = true;
}
LOG_DEBUG(Input, "Input found: {}", i.toString());
LOG_DEBUG(Input, "Input found: {}", i.ToString());
return true; // All keys are active
}
void activateOutputsFromInputs() {
void ActivateOutputsFromInputs() {
// LOG_DEBUG(Input, "Starting input scan... {} inputs active",
// std::distance(pressed_keys.begin(), pressed_keys.end()));
// reset everything
@ -497,7 +497,7 @@ void activateOutputsFromInputs() {
}
for (auto it = connections.begin(); it != connections.end(); it++) {
if (it->output) {
it->output->update(false, 0);
it->output->Update(false, 0);
} else {
LOG_DEBUG(Input, "Null output in BindingConnection at position {}",
std::distance(connections.begin(), it));
@ -507,13 +507,13 @@ void activateOutputsFromInputs() {
// trio is found
for (auto& it : connections) {
if (it.output) {
bool active = isInputActive(it.binding);
it.output->addUpdate(active, it.parameter);
bool active = IsInputActive(it.binding);
it.output->AddUpdate(active, it.parameter);
}
}
}
void updateMouse(GameController* controller) {
void UpdateMouse(GameController* controller) {
if (!mouse_enabled)
return;
Axis axis_x, axis_y;
@ -550,9 +550,9 @@ void updateMouse(GameController* controller) {
}
}
Uint32 mousePolling(void* param, Uint32 id, Uint32 interval) {
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval) {
auto* data = (GameController*)param;
updateMouse(data);
UpdateMouse(data);
return interval;
}

View File

@ -175,12 +175,9 @@ const std::map<std::string, u32> string_to_keyboard_key_map = {
};
// literally the only flag that needs external access
void toggleMouseEnabled();
void ToggleMouseEnabled();
// i wrapped it in a function so I can collapse it
std::string_view getDefaultKeyboardConfig();
void parseInputConfig(const std::string game_id);
void ParseInputConfig(const std::string game_id);
class InputBinding {
public:
@ -241,28 +238,28 @@ public:
// but reverse order makes it check the actual keys first instead of possible 0-s,
// potenially skipping the later expressions of the three-way AND
}
inline int keyCount() const {
inline int KeyCount() const {
return (key1 ? 1 : 0) + (key2 ? 1 : 0) + (key3 ? 1 : 0);
}
// Sorts by the amount of non zero keys - left side is 'bigger' here
bool operator<(const InputBinding& other) const {
return keyCount() > other.keyCount();
return KeyCount() > other.KeyCount();
}
inline bool isEmpty() {
inline bool IsEmpty() {
return key1 == 0 && key2 == 0 && key3 == 0;
}
std::string toString() const {
std::string ToString() const {
return fmt::format("({}, {}, {})", key1, key2, key3);
}
// returns a u32 based on the event type (keyboard, mouse buttons, or wheel)
static u32 getInputIDFromEvent(const SDL_Event& e);
static u32 GetInputIDFromEvent(const SDL_Event& e);
};
class ControllerOutput {
static GameController* controller;
public:
static void setControllerOutputController(GameController* c);
static void GetControllerOutputController(GameController* c);
u32 button;
Axis axis;
@ -280,18 +277,18 @@ public:
inline bool operator!=(const ControllerOutput& o) const {
return button != o.button || axis != o.axis;
}
std::string toString() const {
std::string ToString() const {
return fmt::format("({}, {}, {})", button, (int)axis, axis_value);
}
inline bool isButton() const {
inline bool IsButton() const {
return axis == Axis::AxisMax && button != 0;
}
inline bool isAxis() const {
inline bool IsAxis() const {
return axis != Axis::AxisMax && button == 0;
}
void update(bool pressed, u32 param = 0);
void Update(bool pressed, u32 param = 0);
// Off events are not counted
void addUpdate(bool pressed, u32 param = 0);
void AddUpdate(bool pressed, u32 param = 0);
};
class BindingConnection {
public:
@ -308,7 +305,7 @@ public:
bool operator<(const BindingConnection& other) const {
// a button is a higher priority than an axis, as buttons can influence axes
// (e.g. joystick_halfmode)
if (output->isButton() && other.output->isAxis()) {
if (output->IsButton() && other.output->IsAxis()) {
return true;
}
if (binding < other.binding) {
@ -319,16 +316,16 @@ public:
};
// Check if the 3 key input is currently active.
bool checkForInputDown(InputBinding i);
bool IsInputActive(const InputBinding& i);
// Add/remove the input that generated the event to/from the held keys container.
void updatePressedKeys(u32 button, bool is_pressed);
void UpdatePressedKeys(u32 button, bool is_pressed);
void activateOutputsFromInputs();
void ActivateOutputsFromInputs();
void updateMouse(GameController* controller);
void UpdateMouse(GameController* controller);
// Polls the mouse for changes, and simulates joystick movement from it.
Uint32 mousePolling(void* param, Uint32 id, Uint32 interval);
Uint32 MousePolling(void* param, Uint32 id, Uint32 interval);
} // namespace Input

View File

@ -79,8 +79,8 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, Input::GameController* controller_
window_info.render_surface = SDL_Metal_GetLayer(SDL_Metal_CreateView(window));
#endif
// input handler init-s
Input::ControllerOutput::setControllerOutputController(controller);
Input::parseInputConfig(std::string(Common::ElfInfo::Instance().GameSerial()));
Input::ControllerOutput::GetControllerOutputController(controller);
Input::ParseInputConfig(std::string(Common::ElfInfo::Instance().GameSerial()));
}
WindowSDL::~WindowSDL() = default;
@ -101,12 +101,12 @@ void WindowSDL::waitEvent() {
case SDL_EVENT_WINDOW_RESIZED:
case SDL_EVENT_WINDOW_MAXIMIZED:
case SDL_EVENT_WINDOW_RESTORED:
onResize();
OnResize();
break;
case SDL_EVENT_WINDOW_MINIMIZED:
case SDL_EVENT_WINDOW_EXPOSED:
is_shown = event.type == SDL_EVENT_WINDOW_EXPOSED;
onResize();
OnResize();
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
@ -114,7 +114,7 @@ void WindowSDL::waitEvent() {
case SDL_EVENT_MOUSE_WHEEL_OFF:
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
onKeyboardMouseInput(&event);
OnKeyboardMouseInput(&event);
break;
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
@ -124,7 +124,7 @@ void WindowSDL::waitEvent() {
case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN:
case SDL_EVENT_GAMEPAD_TOUCHPAD_UP:
case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION:
onGamepadEvent(&event);
OnGamepadEvent(&event);
break;
case SDL_EVENT_QUIT:
is_open = false;
@ -136,10 +136,10 @@ void WindowSDL::waitEvent() {
void WindowSDL::initTimers() {
SDL_AddTimer(100, &PollController, controller);
SDL_AddTimer(33, Input::mousePolling, (void*)controller);
SDL_AddTimer(33, Input::MousePolling, (void*)controller);
}
void WindowSDL::onResize() {
void WindowSDL::OnResize() {
SDL_GetWindowSizeInPixels(window, &width, &height);
ImGui::Core::OnResize();
}
@ -152,25 +152,25 @@ Uint32 wheelOffCallback(void* og_event, Uint32 timer_id, Uint32 interval) {
return 0;
}
void WindowSDL::onKeyboardMouseInput(const SDL_Event* event) {
void WindowSDL::OnKeyboardMouseInput(const SDL_Event* event) {
using Libraries::Pad::OrbisPadButtonDataOffset;
// get the event's id, if it's keyup or keydown
bool input_down = event->type == SDL_EVENT_KEY_DOWN ||
event->type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
event->type == SDL_EVENT_MOUSE_WHEEL;
u32 input_id = Input::InputBinding::getInputIDFromEvent(*event);
u32 input_id = Input::InputBinding::GetInputIDFromEvent(*event);
// Handle window controls outside of the input maps
if (event->type == SDL_EVENT_KEY_DOWN) {
// Reparse kbm inputs
if (input_id == SDLK_F8) {
Input::parseInputConfig(std::string(Common::ElfInfo::Instance().GameSerial()));
Input::ParseInputConfig(std::string(Common::ElfInfo::Instance().GameSerial()));
return;
}
// Toggle mouse capture and movement input
else if (input_id == SDLK_F7) {
Input::toggleMouseEnabled();
Input::ToggleMouseEnabled();
SDL_SetWindowRelativeMouseMode(this->GetSdlWindow(),
!SDL_GetWindowRelativeMouseMode(this->GetSdlWindow()));
return;
@ -196,13 +196,13 @@ void WindowSDL::onKeyboardMouseInput(const SDL_Event* event) {
}
// add/remove it from the list
Input::updatePressedKeys(input_id, input_down);
Input::UpdatePressedKeys(input_id, input_down);
// update bindings
Input::activateOutputsFromInputs();
Input::ActivateOutputsFromInputs();
}
void WindowSDL::onGamepadEvent(const SDL_Event* event) {
void WindowSDL::OnGamepadEvent(const SDL_Event* event) {
using Libraries::Pad::OrbisPadButtonDataOffset;
u32 button = 0;

View File

@ -71,9 +71,9 @@ public:
void initTimers();
private:
void onResize();
void onKeyboardMouseInput(const SDL_Event* event);
void onGamepadEvent(const SDL_Event* event);
void OnResize();
void OnKeyboardMouseInput(const SDL_Event* event);
void OnGamepadEvent(const SDL_Event* event);
int sdlGamepadToOrbisButton(u8 button);