Skip to content

Instantly share code, notes, and snippets.

@Zazcallabah
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zazcallabah/b9a05536b6a1031115e3 to your computer and use it in GitHub Desktop.
Save Zazcallabah/b9a05536b6a1031115e3 to your computer and use it in GitHub Desktop.
dolphin analog triggers transformation
template <typename C, typename S>
void GetState(C* const digital, const C* bitmasks, S* analog, const unsigned int range)
{
const unsigned int trig_count = ((unsigned int) (controls.size() / 2));
for (unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog)
{
if (controls[i]->control_ref->State() == 0)
flag[i] = false; // reset out of transition state if button is no longer pressed
if (controls[i]->control_ref->State() > settings[0]->value) //threshold
{
*analog = range;
if (!flag[i])
{
flag[i] = true;
}
else
{
*digital |= *bitmasks;
}
}
else
{
*analog = S(controls[i+trig_count]->control_ref->State() * range);
}
}
}
@Zazcallabah
Copy link
Author

This, unfortunately, moves state into the MixedTriggers class. Instead of only fetching a snapshot of the current gamepad state it stores a transition flag. Could this make it vulnerable to bugs regarding different types of gamepads, key bindings, and changing bindings while the game is running?

Anyway the class currently has two states, decided by the if clause on line 9. Either the trigger is depressed past the threshold, in which case both digital and analog values are set. Otherwise only the analog values are set.

My problem with this is a game that needs the transition states inbetween these bits, combined with the fact that I've bound both the digital trigger button (controls[0] and controls[1]) and the analog trigger counterparts (controls[2] and controls[3]) to the same buttons. This because my game pad has only digital buttons to choose from.

So I added a third state, a transition state, denoted by the flag aptly named 'flag'. (lines 7,8,12-19) In this state only the analog value is set, despite the button being pressed past the threshold value.

This solves the problem, unless the game lags too much. I think. Maybe a longer transition state is needed? One update may not be enough in every case. On the other hand that may cause the input to start feeling laggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment