fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

Jonathan HaylettSOCD revamp (#57)1f92ae6

v0.1.0
4.1 KiB127 linesraw
1#include "modes/extra/MultiVersus.hpp"
2
3#define ANALOG_STICK_MIN 0
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 255
6
7MultiVersus::MultiVersus(socd::SocdType socd_type) {
8    _socd_pair_count = 4;
9    _socd_pairs = new socd::SocdPair[_socd_pair_count]{
10        socd::SocdPair{&InputState::left,    &InputState::right,   socd_type},
11        socd::SocdPair{ &InputState::down,   &InputState::up,      socd_type},
12        socd::SocdPair{ &InputState::c_left, &InputState::c_right, socd_type},
13        socd::SocdPair{ &InputState::c_down, &InputState::c_up,    socd_type},
14    };
15}
16
17void MultiVersus::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
18    // Bind X and Y to "jump" in-game.
19    outputs.x = inputs.x;
20    outputs.y = inputs.y;
21
22    outputs.start = !inputs.mod_y && inputs.start;
23
24    // Select, MS, or MY + Start for "Reset" in the Lab. Not supported by GameCube adapter.
25    outputs.select = inputs.select || inputs.midshield || (inputs.mod_y && inputs.start);
26
27    // Home not supported by GameCube adapter.
28    outputs.home = inputs.home;
29
30    // L or Nunchuk Z = LT. Bind to "dodge" in-game.
31    if (inputs.nunchuk_connected) {
32        outputs.triggerLDigital = inputs.nunchuk_z;
33    } else {
34        outputs.triggerLDigital = inputs.l;
35    }
36
37    // R = RT. Can be bound to "pickup item" or left unbound.
38    outputs.triggerRDigital = inputs.r;
39
40    if (!inputs.mod_x) {
41        // Bind A to "attack" in-game.
42        outputs.a = inputs.a;
43
44        // Bind B to "special" in-game.
45        outputs.b = inputs.b;
46
47        // Z = RB. Bind to "dodge" in-game.
48        outputs.buttonR = inputs.z;
49
50        // LS = LB. Not supported by GameCube adapter.
51        outputs.buttonL = inputs.lightshield;
52    }
53
54    // MX activates a layer for "neutral" binds. Uses D-Pad buttons.
55    if (inputs.mod_x && !inputs.mod_y) {
56        // MX + A = D-Pad Left. Bind to "neutral attack" in-game.
57        outputs.dpadLeft = inputs.a;
58
59        // MX + B = D-Pad Right. Bind to "neutral special" in-game.
60        outputs.dpadRight = inputs.b;
61
62        // MX + Z = D-Pad Down. Bind to "neutral evade" in-game.
63        outputs.dpadDown = inputs.z;
64
65        // MX + LS = D-Pad Up. Bind to "taunt 1" in-game.
66        outputs.dpadUp = inputs.lightshield;
67    }
68
69    // MY activates C-Stick to D-Pad conversion.
70    if (inputs.mod_y && !inputs.mod_x) {
71        outputs.dpadLeft = inputs.c_left;
72        outputs.dpadRight = inputs.c_right;
73        outputs.dpadDown = inputs.c_down;
74        outputs.dpadUp = inputs.c_up;
75    }
76}
77
78void MultiVersus::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
79    // Coordinate calculations to make modifier handling simpler.
80    UpdateDirections(
81        inputs.left,
82        inputs.right,
83        inputs.down,
84        inputs.up,
85        inputs.c_left,
86        inputs.c_right,
87        inputs.c_down,
88        inputs.c_up,
89        ANALOG_STICK_MIN,
90        ANALOG_STICK_NEUTRAL,
91        ANALOG_STICK_MAX,
92        outputs
93    );
94
95    if (inputs.mod_y && !inputs.mod_x) {
96        // MY slows down the cursor for easier menu navigation.
97        // Menu cursor speed can also be turned down in-game under "Interface" settings.
98        // 128 ± 76 results in the slowest cursor that still actuates directional inputs in-game.
99        outputs.leftStickX = ANALOG_STICK_NEUTRAL + directions.x * 76;
100        outputs.leftStickY = ANALOG_STICK_NEUTRAL + directions.y * 76;
101
102        if (directions.diagonal) {
103            // Maintain a consistent cursor velocity when MY is held.
104            // ⌊76 × √2/2⌋ = 53
105            outputs.leftStickX = ANALOG_STICK_NEUTRAL + directions.x * 53;
106            outputs.leftStickY = ANALOG_STICK_NEUTRAL + directions.y * 53;
107        }
108
109        // Also shut off C-Stick for D-Pad conversion.
110        outputs.rightStickX = ANALOG_STICK_NEUTRAL;
111        outputs.rightStickY = ANALOG_STICK_NEUTRAL;
112    }
113
114    if (outputs.triggerLDigital) {
115        outputs.triggerLAnalog = 140;
116    }
117
118    if (outputs.triggerRDigital) {
119        outputs.triggerRAnalog = 140;
120    }
121
122    // Nunchuk overrides left stick.
123    if (inputs.nunchuk_connected) {
124        outputs.leftStickX = inputs.nunchuk_x;
125        outputs.leftStickY = inputs.nunchuk_y;
126    }
127}