Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Count events pending  (Read 1859 times)

0 Members and 1 Guest are viewing this topic.

Brikinhos

  • Newbie
  • *
  • Posts: 8
    • View Profile
Count events pending
« on: July 24, 2019, 09:07:26 pm »
Hi all. I need to know how many events of a specific type are pending before processing all of them because when I process the last event I need to call to a function. Is there a way to iterate all events pending? Thanks in advance.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Count events pending
« Reply #1 on: July 25, 2019, 07:49:25 am »
Sounds like a XY problem. You're trying to find how to do that, because you think it's the solution to another problem. But the real question is: why do you need to call a function when you process the last event?
Laurent Gomila - SFML developer

Brikinhos

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Count events pending
« Reply #2 on: July 25, 2019, 06:12:31 pm »
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:

UPDOWNLEFTRIGHTCOMMAND
0000-
0001R
0010L
0011-
0100D
0101DR
0110DL
0111D
1000U
1001UR
1010UL
1011U
1100-
1101R
1110L
1111-

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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: Count events pending
« Reply #3 on: July 25, 2019, 06:33:09 pm »
You can just have a normal event loop as shown in the tutorials, process all inputs and afterwards call your function.

As for the question, no there isn't a way to query that.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Brikinhos

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Count events pending
« Reply #4 on: July 25, 2019, 07:03:49 pm »
The idea is doesn't call translate function every frame, only when specific events occurs. I will use flags for detecting it then. Anyway, thanks.