fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
1#include "core/InputMode.hpp" 2 3#include "core/socd.hpp" 4#include "core/state.hpp" 5#include "util/state_util.hpp" 6 7InputMode ::InputMode () {} 8 9GameModeConfig * InputMode ::GetConfig () { 10return _config ; 11} 12 13void InputMode ::SetConfig (GameModeConfig & config ) { 14_config = & config ; 15} 16 17void InputMode ::HandleSocd (InputState & inputs ) { 18if (_config == nullptr ) { 19return ; 20 } 21// Handle SOCD resolution for each SOCD button pair. 22for (size_t i = 0 ;i < _config -> socd_pairs_count ;i ++ ) { 23const SocdPair & pair = _config -> socd_pairs [i ]; 24switch (pair .socd_type ) { 25case SOCD_NEUTRAL : 26 socd::neutral (inputs ,pair .button_dir1 ,pair .button_dir2 ); 27break ; 28case SOCD_2IP : 29 socd::second_input_priority ( 30inputs , 31pair .button_dir1 , 32pair .button_dir2 , 33_socd_states [i ] 34 ); 35break ; 36case SOCD_2IP_NO_REAC : 37 socd::second_input_priority_no_reactivation ( 38inputs , 39pair .button_dir1 , 40pair .button_dir2 , 41_socd_states [i ] 42 ); 43break ; 44case SOCD_DIR1_PRIORITY : 45 socd::dir1_priority (inputs ,pair .button_dir1 ,pair .button_dir2 ); 46break ; 47case SOCD_DIR2_PRIORITY : 48 socd::dir1_priority (inputs ,pair .button_dir2 ,pair .button_dir1 ); 49break ; 50case SOCD_UNSPECIFIED : 51default : 52break ; 53 } 54 } 55} 56 57void InputMode ::HandleRemap (const InputState & original_inputs ,InputState & remapped_inputs ) { 58if (_config == nullptr ) { 59return ; 60 } 61remapped_inputs .buttons = 0 ; 62 63// Keep track of which buttons have been remapped so that we can prevent macro remapping. 64uint64_t physical_buttons_already_remapped = 0 ; 65for (size_t i = 0 ;i < _config -> button_remapping_count ;i ++ ) { 66const ButtonRemap & remapping = _config -> button_remapping [i ]; 67// If this physical button was already remapped to something else, ignore this remapping. 68// This is to prevent creating macro behaviour through remapping. 69if (get_button (physical_buttons_already_remapped ,remapping .physical_button )) { 70continue ; 71 } 72 73// Either use the value of the physical button, or if the physical button is not pressed, 74// but the target button has another physical button remapped to it, and is considered to be 75// pressed, leave it as pressed. 76bool should_be_pressed = get_button (original_inputs .buttons ,remapping .physical_button )|| 77get_button (remapped_inputs .buttons ,remapping .activates ); 78set_button (remapped_inputs .buttons ,remapping .activates ,should_be_pressed ); 79 80// Track which buttons have been remapped. 81set_button (physical_buttons_already_remapped ,remapping .physical_button , true); 82 } 83 84// Copy over original button states for buttons that were not remapped. 85remapped_inputs .buttons |=original_inputs .buttons & ~physical_buttons_already_remapped ; 86}