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

Author Topic: Custom Events!  (Read 8325 times)

0 Members and 1 Guest are viewing this topic.

telaviv

  • Newbie
  • *
  • Posts: 2
    • View Profile
Custom Events!
« on: May 29, 2009, 03:09:32 am »
Hello I'm currently considering moving all my code from pygame to pysfml. Most of the conversion seems straightforward but the main thing thats stopping me is event handling. The first problem is that I heavily use custom events that are put on the event queue using timers. Is there any way to simulate this without using multithreading? Also, probably the most important one is that I would like to poll for events, but having it block when no events are on the queue. Is this possible?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Custom Events!
« Reply #1 on: May 29, 2009, 07:51:05 am »
Quote
The first problem is that I heavily use custom events that are put on the event queue using timers. Is there any way to simulate this without using multithreading?

No, there's no custom events in SFML. But you can easily have your own custom events loop, you don't have to use SFML's one.

Quote
Also, probably the most important one is that I would like to poll for events, but having it block when no events are on the queue. Is this possible?

That will be implemented in SFML 2.0.
For now, you can simulate it with a blocking loop which polls events and sleeps if there's none.
Laurent Gomila - SFML developer

telaviv

  • Newbie
  • *
  • Posts: 2
    • View Profile
Custom Events!
« Reply #2 on: May 29, 2009, 07:59:44 am »
Cool thanks a lot! I still don't understand how to implement blocking though. If i check that there's nothing in the event queue, how will my thread wake up when something comes on the queue? Do you mean:
check->sleep-an-arbitrary-amount-of-time->check ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Custom Events!
« Reply #3 on: May 29, 2009, 10:27:11 am »
Rather
check->sleep-an-arbitrary-small-amount-of-time->check ;)
Laurent Gomila - SFML developer

HiroshimaCC

  • Newbie
  • *
  • Posts: 4
    • View Profile
Custom Events!
« Reply #4 on: August 19, 2009, 04:37:30 pm »
Hi!
Is this something that could be added in a future release ? Or is it something you want to avoid ?
Because I (and a lot of other people I think) am porting a lot of code from old SDL apps, and since some of them use the custom events system of SDL, it would be much simpler if it was possible to have something similar in SFML.
And since all of my apps use the main events loop of SFML, it would be much more elegant too :) (I REALLY want to get rid of SDL in my apps :p) !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Custom Events!
« Reply #5 on: August 19, 2009, 04:42:12 pm »
Everyone wants this feature in order not to break existing SDL code. But obviously the best choice would be to implement your own custom event system, so that in the future when you switch from SFML to XYZ you won't have to ask again and again for a custom event feature.

Don't you think?
Laurent Gomila - SFML developer

HiroshimaCC

  • Newbie
  • *
  • Posts: 4
    • View Profile
Custom Events!
« Reply #6 on: August 20, 2009, 05:40:05 pm »
It's one way to think, but as SFML intend to be an abstraction for the windowing system, I think it should be natural that it support custom events, like most others windowing libraries (Win32, Qt, wxWidgets...). And as I said, it would be more elegant to handle events in one unique way, rather than wrapping SFML events into a custom made events system just for adding trivial custom events.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Custom Events!
« Reply #7 on: August 20, 2009, 05:51:51 pm »
The fact that everyone else does it doesn't mean that I have to do it ;)

SFML is not a framework into which you can insert your own features, it's a low-level building block on top of which you have to design your own higher-level classes. Why would SFML support a feature that is completely external (I mean, SFML really doesn't care about events other than the ones it defines)?

When people want a window class with more features they build their own one that wraps a sf::RenderWindow. The same strategy applies for any class. So why not sf::Event?
Laurent Gomila - SFML developer

 

anything