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

Author Topic: having a time based loop within a blocking based program  (Read 1640 times)

0 Members and 1 Guest are viewing this topic.

barnack

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
having a time based loop within a blocking based program
« on: August 19, 2018, 03:14:12 am »
Hi,
i was enjoying working more or less flawlessly in my project (not a game). Since its an utility and it doesnt have to eat resources as a game while not being used, i opted for waitEvent instead of pollEvent.
However working on workspace navigation i ended up with a "oh shit" situation.
I planned using both mouse-near-borders and arrow keys to navigate on the working zone in case it is bigger than the window.
And yeah i cant do that with waitEvent, because once the mouse gets to the border and the event triggers once, everything stops.

Indeed thinking later about that, programs like paint and paint.net, event notepad++ have keyboard navigation based on operating system simulated key repetition when the arrow is being held; which i could pretty much do as well.

The point is, is there any workaround you can suggest me to have it work with mouse-near-borders, like in rts games?

My only idea now was putting all the draw part in a function, and have my main loop looking like that (i know its ugly)

Code: [Select]
if waitEvent(event)
    {
    //stuff happens
    switch(event)
        {
        case mouse on border:
            while pollEvent(tmp_event)
                if mouse on border
                    move screen
                    draw()
                else
                    break out of poll event
        case other events:
        }
    draw();
    }



eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: having a time based loop within a blocking based program
« Reply #1 on: August 19, 2018, 02:10:09 pm »
I don't fully understand the problem you're encountering (mouse near border?). Can you maybe rephrase it somehow?

User inputs such as key presses, mouse movement, etc will trigger an event, so waitEvent will return in those cases.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

barnack

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: having a time based loop within a blocking based program
« Reply #2 on: August 19, 2018, 04:15:46 pm »
catching mouseMoved, if its coordinates are, let's say, within 2 pixels from left border, the view should constantly move left until mouse is moved out of that position. Pretty stright to do with pollEvent since the cycle will continue even if there are no events. But i dont want my program to keep doing cycles when the user is doing nothing, except for that single case, when the mouse is near the border.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: having a time based loop within a blocking based program
« Reply #3 on: August 19, 2018, 04:27:20 pm »
You may have to switch to using poll event to track the mouse in real-time. However, you can do this only when you expect to need this tracking. For example, when you move "close" to the border, you can switch a state to use poll event until the mouse either moves away from this zone or leaves the window and then switch back to waiting for the event.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything