why do you need to call a function when you process the last event?
I'm making an Input Handler System that contains a circular buffer, capturing all inputs (pressed and released), only of buttons I previously defined for player asociated to the Input Handler.
The circular buffer stores tuples like this std::tuple <Game::Buttons, int , bool>; First one is an action I can do asociated to a key, second one is realtive delay between this button and the last one, and the third one indicates if button was pushed or released.
[Game::UP_BUTTON, 0, 1]
[Game::UP_BUTTON, 1, 1]
[Game::UP_BUTTON, 1, 1]
[Game::UP_BUTTON, 0, 0]
[Game::UP_DOWN, 2, 1]
[Game::UP_LEFT, 1, 1]
[Game::UP_DOWN, 2, 0]
[Game::A_BUTTON, 3, 1]
[Game::B_BUTTON, 0, 1]
My Input Handler System calculates what commands were released in each frame. For example, according to the table above:
- In the first frame with events only UP was pressed. Is equal to U (UP).
* Buffer: U
- In the second frame with events only UP was released. Is equal to -.
* Buffer: U
- In the next frame with events there was two events, press and release UP, then is equal to - (nothing happends).
* Buffer: U
- In the next frame with events DOWN is pressed. Is equal to D (DOWN).
*Buffer: U D
- In the next frame with events LEFT is pressed (and DOWN is still pressed). Is equal to DL (DOWN-LEFT).
* Buffer: U D DL
- In the next frame with events DOWN is released (DOWN and LEFT were pressed). Is equal to L.
* Buffer: U D DL L
- In the next frame with events A and B are pressed at the same time. Is equal to A + B.
* Buffer: U D DL L A+B
My translation system from buffer to commands works perfectly, but I have to call this function after capturing all inputs. If I translate them while I capture each event there are problems, for example: I press and release UP at the same frame, then my system translate it to: "U" (UP), but "U" was released, then, it should happends nothing. Other example is when I calculate move inputs: I need to know what move commands where pressed or released at the same time to calculate a move command according to the next logic table:
UP | DOWN | LEFT | RIGHT | COMMAND |
0 | 0 | 0 | 0 | - |
0 | 0 | 0 | 1 | R |
0 | 0 | 1 | 0 | L |
0 | 0 | 1 | 1 | - |
0 | 1 | 0 | 0 | D |
0 | 1 | 0 | 1 | DR |
0 | 1 | 1 | 0 | DL |
0 | 1 | 1 | 1 | D |
1 | 0 | 0 | 0 | U |
1 | 0 | 0 | 1 | UR |
1 | 0 | 1 | 0 | UL |
1 | 0 | 1 | 1 | U |
1 | 1 | 0 | 0 | - |
1 | 1 | 0 | 1 | R |
1 | 1 | 1 | 0 | L |
1 | 1 | 1 | 1 | - |
Because of I need to have captured all events for translating buffer to readable commands thats the reason I need to call translate function after all events are polled.
Sorry if my English is bad, and sorry about writting to much xD.