Input changes between 1.2.8 and 1.2.14

I am developing a game which utilises SDL, and have run into a few problems. Basically the game was created to be OS-independent, and when it was started, SDL 1.2.8 was the latest one. On Windows it wouldn’t be much of a problem, the older DLLs can be supplied and that’s all, but with Linux it’s not as easy, since packages are automatically updated and thus only SDL 1.2.14 binaries are available there. And while that wouldn’t normally be a problem, but in my case it is, since there were some changes done to the input handling. In short, when you click on a card in the game, it’s supposed to play it, wait for it to finish, then wait for your input again. However, with SDL 1.2.14, it no longer waits for your input, but repeats the last input, so if I clicked on a card, it would click on it again once my turn comes, ad infinitum. So what was changed that is causing such behaviour?

Here is the input loop code that I am using for the game’s events:

Code:
while (!quit && !Winner(0) && !Winner(1))
{

    while(SDL_PollEvent(&event));//GE: Delete all events from the event queue before our turn.

		while (!quit)
		{
			SDL_Delay(CPUWAIT);
			SDL_PollEvent(&event);
			quit=(event.type==SDL_KEYUP&&event.key.keysym.sym==SDLK_ESCAPE);
			if (event.type!=SDL_MOUSEBUTTONUP || event.button.button>3) continue;
			discrd=(event.button.button==2)||(event.button.button==3);
			if (InRect(event.button.x,event.button.y,  8,342,  8+94,468)&&(discrd||Requisite(&Player[turn],0))) {crd=0;break;}
			if (InRect(event.button.x,event.button.y,114,342,114+94,468)&&(discrd||Requisite(&Player[turn],1))) {crd=1;break;}
		}

        if (!quit)
        {
			netcard = Player[turn].Hand[crd];
			PlayCard(crd,discrd);
			if (netplayer!=-1)
				NetLocPlay(crd,discrd,netcard);
        }
	SDL_Delay(CPUWAIT);
}

There. You’re not checking the return code, so event is either valid or undefined.

Frank.On 03/10/2011 03:28 PM, GreatEmerald wrote:

I am developing a game which utilises SDL, and have run into a few problems.
Basically the game was created to be OS-independent, and when it was started,
SDL 1.2.8 was the latest one. On Windows it wouldn’t be much of a problem, the
older DLLs can be supplied and that’s all, but with Linux it’s not as easy,
since packages are automatically updated and thus only SDL 1.2.14 binaries are
available there. And while that wouldn’t normally be a problem, but in my case
it is, since there were some changes done to the input handling. In short,
when you click on a card in the game, it’s supposed to play it, wait for it to
finish, then wait for your input again. However, with SDL 1.2.14, it no longer
waits for your input, but repeats the last input, so if I clicked on a card,
it would click on it again once my turn comes, ad infinitum. So what was
changed that is causing such behaviour?

Here is the input loop code that I am using for the game’s events:

Code:

while (!quit && !Winner(0) && !Winner(1))
{

    while(SDL_PollEvent(&event));//GE: Delete all events from the event

queue before our turn.

     while (!quit)
     {
        SDL_Delay(CPUWAIT);
        SDL_PollEvent(&event);

So you mean that I need to have it like this?

Code:
while (!quit && !Winner(0) && !Winner(1))
{

    while(SDL_PollEvent(&event));//GE: Delete all events from the event queue before our turn.

     while (!quit)
     {
        SDL_Delay(CPUWAIT);
        if (SDL_PollEvent(&event))
            continue;
        quit=(event.type==SDL_KEYUP&&event.key.keysym.sym==SDLK_ESCAPE);
        if (event.type!=SDL_MOUSEBUTTONUP || event.button.button>3) continue;
        discrd=(event.button.button==2)||(event.button.button==3);
        if (InRect(event.button.x,event.button.y,  8,342,  8+94,468)&&(discrd||Requisite(&Player[turn],0))) {crd=0;break;}
        if (InRect(event.button.x,event.button.y,114,342,114+94,468)&&(discrd||Requisite(&Player[turn],1))) {crd=1;break;}
     }

        if (!quit)
        {
         netcard = Player[turn].Hand[crd];
         PlayCard(crd,discrd);
         if (netplayer!=-1)
            NetLocPlay(crd,discrd,netcard);
        }
  SDL_Delay(CPUWAIT);

}

The idiom is to have a while(SDL_PollEvent()) loop, with all your input
handling in the loop body or in functions called by the loop body. This
ensures you process all outstanding input the first time you can, which
reduces input latency. For example, mouse motion generates lots of events,
if you are vsynced at 60FPS and you have 20 events built up, the user will
have to wait 20 * 16.6 milliseconds or approximately a 1/3 of a second
before the last event is processed. This is a delay even the puny humans can
notice.

OK, so my code there worked just fine and didn’t break the breaks :slight_smile: It’s quite the same as the while method anyway.