View previous topic - View next topic |
Author |
Message |
Gardon Scholar
Joined: 05 Feb 2006 Posts: 157
|
Posted: Fri Mar 17, 2006 7:38 pm Post subject: |
[quote] |
|
Yes, but how do I do event driven states in SDL?
it has the SDL_PollFunction, which you have to poll for events. Yes, it's stored in a queue, but it's nothing like java listeners that automatically handle the event when processed.
What can I do in C++?
Thanks,
Jason
|
|
Back to top |
|
|
zenogais Slightly Deformed Faerie Princess
Joined: 10 Jan 2006 Posts: 34
|
Posted: Fri Mar 17, 2006 10:06 pm Post subject: |
[quote] |
|
In your event polling loop, you check for different event types (SDL_KEYDOWN, SDL_KEYUP, SDL_MOUSEMOTION etc.). You then call all of your listeners on each event based on whether they are a keyboard listener or a mouse listener. This can be done very very easily using STL vectors or STL lists (probably you want vectors though). In this way when the event is processed it is dispatched to everyone who wants it, and that's event driven event handling in a nutshell.
|
|
Back to top |
|
|
Gardon Scholar
Joined: 05 Feb 2006 Posts: 157
|
Posted: Sat Mar 18, 2006 4:15 am Post subject: |
[quote] |
|
I guess when I say listeners I'm thinking about java, or even the WINAPI, as in you don't have to control when they take place, but just tell them what to do when they happen.
With SDL, I have to specifially poll for events, which is once per frame, and update accordingly. If it was different, I wouldn't have to worry about using vectors (which I'm currently doing), beacuse everything would happen based on the queue of events.
Jason
|
|
Back to top |
|
|
zenogais Slightly Deformed Faerie Princess
Joined: 10 Jan 2006 Posts: 34
|
Posted: Sat Mar 18, 2006 4:27 am Post subject: |
[quote] |
|
C++ != Java, sometimes some stuff takes a bit more work, but works the same...tough luck. SDL is definitely not meant to work like Java, so it takes a little more work. The method I just proposed works exactly like the Java method, you just have to get a little bit more into the nitty-gritty details.
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Sat Mar 18, 2006 11:44 am Post subject: |
[quote] |
|
zenogais wrote: | C++ != Java, sometimes some stuff takes a bit more work, but works the same...tough luck. SDL is definitely not meant to work like Java, so it takes a little more work. The method I just proposed works exactly like the Java method, you just have to get a little bit more into the nitty-gritty details. |
Basicly what he's saying here is that if you want it to behave like listeners you first need to understand them then simply implement something that works the same way.
Welcome to the world of explorative programming :)
Good starting points could be to google the MVC (model view controller) and Observer (design) patterns.
Should give you a good design overview of applicable techniques. _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
Gardon Scholar
Joined: 05 Feb 2006 Posts: 157
|
Posted: Sat Mar 18, 2006 9:51 pm Post subject: |
[quote] |
|
thank you
|
|
Back to top |
|
|
|
Page 2 of 2 |
All times are GMT Goto page Previous 1, 2
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|