Selon Kyle <[EMAIL PROTECTED]>:

> On 2/15/07, Matthieu Fertré <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I have began rewriting input management in a cleaner way but I am
> > currently in
> > front of a problem.
> >
> > First of all, let's speak about the game loop to understand!
> > ...
> >
> I have been trying to understand the game loop / keyboard input recently
> myself (in an effort to figure out why wormux pegs my cpu at 100%), and have
> come across a few questions of my own that I don't understand in the
> keyboard management.
>
> 1. Goto statements in Keyboard::HandleKeyPressed()
>   This just seems like an awful idea. Every state that doesn't return
> executes a goto, which makes me wonder why they don't just break and run the
> goto'ed code right after the switch and before the last return. Unless the
> code uses goto's for a very specific reason (and I can't see one) I would
> recommend making this change.

You're right! The goto is here because in intermediate state (probably never
commited) there was more things to do than just return, and more things to do
than just break and continue. It means there was 2 different cases so 2
different gotos because it's cleaner that copy-paste 3 lines of code on top of
each return or break.

I have removed one, the second is useless but as you know the work on input
management is not finished.

>
> 2. The reason for disabling the sdl repeat keys option and instead handling
> it via Keyboard::Refresh.
>   I believe I might understand this one, but I would like to know if I am
> right. It would seem that in using the sdl library's repeat key option, the
> event queue could quickly get swamped with events that would slow down
> rendering, so wormux handles them in a special case to make sure a held down
> key is only processed once a frame. I haven't looked at if the
> HandleKeyRefreshed_X() functions do anything different then the other key
> press functions, but I suppose using the sdl way wouldn't allow for this
> type of differentiation even if it was needed?
> This second misunderstanding isn't really important, but I am curious as to
> why wormux handles held down keys the way it does. Is any part of my hunch
> correct?

I suppose it's for historical reason. I hadn't look at the input management code
before trying to clean it.
As you probably know, Wormux was coding using Clanlib before using SDL, perhaps
it could be an explanation.
Some methods HandleKeyRefreshed_X() simply called HandleKeyPressed_X() but some
others do something different.
I can't give you more information, I don't know if it was speed up rendering or
not.

Matt(gentildemon)

_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

Répondre à