What Im doing wrong (Event procesing)

Hi everyone. Well I read this list since long time ago but never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t try it in
linux yet.
Sometimes while the game is runing I have a high response time, and when
the event is worked it has a reaction like if I press the key twice very fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked . I dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace?
Im not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the main. And
I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G

At what framerate do you keep your game ? Perhaps the problem is there.
Depending how do you get the input, if you read the events at each frame,
then if you are at a slow frame rate you will notice some lag.

For example: (in pseudocode)

while (run)
{
while(events_in_queue)
{
ReadInput
}
Draw
Delay //for constant framerate
}

If the Delay is too high, there will be a slowdown in the input processing.

I have never used Timers in SDL. Can you send how you did it ?

Byes.
Alejandro.> ----- Original Message -----

From: marting@webklan.com ()
To:
Sent: Thursday, December 11, 2003 11:18 AM
Subject: [SDL] What Im doing wrong (Event procesing)

              Hi everyone. Well I read this list since long time ago but

never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t try it
in
linux yet.
Sometimes while the game is runing I have a high response time, and when
the event is worked it has a reaction like if I press the key twice very
fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked . I
dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace?
Im not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the main. And
I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Sure… this is my main loop… the time issue is handled by a class… I just
move the SDL Documentation’s main loop example to oop.-------------------------------------------------------------------------------------------
.
.
.
SDL_TickTimer MiTimer ;
SDL_Event TheInput ;
.
.
.
while(!EndGame)
{
Pantalla.flip();// Swap the back buffer to the screen
TheInput = Pantalla.getEvent();

   Pantalla.blit(Fondo); // Blits the background.
   
    
               Tablero1.blitBoardImg(Pantalla);
   Tablero1.update(Pantalla,TheInput);

   Tablero2.blitBoardImg(Pantalla);
   Tablero2.update(Pantalla,TheInput);
   

   

   EndGame = Tablero1.getGameOver();

   SDL_Delay(MiTimer.getTimeLeft() );
   MiTimer.setNextTime();	   

}

My timer class is this. the tick Interval is set to 80 right now… but the problem
get worse if I use a lesser one.

class SDL_TickTimer {

public:
SDL_TickTimer();

void setTickInterval(int );
void initNextTime(void);
void setNextTime(void);
Uint32 getTimeLeft(void);

private:
//functions
//data
Uint32 uiNextTime;
int iTickInterval;
};

SDL_TickTimer::SDL_TickTimer(){
iTickInterval = 80 ;
}

void SDL_TickTimer::setTickInterval(int iNewInterval){
iTickInterval = iNewInterval;
}

Uint32 SDL_TickTimer::getTimeLeft(){
Uint32 now;

now = SDL_GetTicks();
if(uiNextTime <= now)
    return 0;
else
    return uiNextTime - now;

}

void SDL_TickTimer::initNextTime(void){
uiNextTime = SDL_GetTicks() + iTickInterval;
}

void SDL_TickTimer::setNextTime(void){
uiNextTime += iTickInterval;
}

Martin G


  > At what framerate do you keep your game ? Perhaps the problem is 

there.

Depending how do you get the input, if you read the events at each
frame, then if you are at a slow frame rate you will notice some lag.

For example: (in pseudocode)

while (run)
{
while(events_in_queue)
{
ReadInput
}
Draw
Delay //for constant framerate
}

If the Delay is too high, there will be a slowdown in the input
processing.

I have never used Timers in SDL. Can you send how you did it ?

Byes.
Alejandro.

----- Original Message -----
From:
To:
Sent: Thursday, December 11, 2003 11:18 AM
Subject: [SDL] What Im doing wrong (Event procesing)

             Hi everyone. Well I read this list since long time ago
             but

never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t try
it in
linux yet.
Sometimes while the game is runing I have a high response time, and
when the event is worked it has a reaction like if I press the key
twice very fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked .
I dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace?
Im not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the main.
And I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Im just guessing but you can try something like this: (again, pseudocode)

while (!run)
{
inicio = SDL_GetTicks();
while ( events_in_queue OR ( SDL_GetTicks - inicio <
MiTimer.getTimeLeft() ))
{
FetchEvents
}
Draw
//The Delay is not here anymore, is at the event fetching loop
}

I dont know if there is a better way, but this may work. The delay is in
the inner while; it is very CPU expensive becasue it polls every cicle for
events, opossite to the SDL_Delay that Sleeps for a while and dont uses as
CPU as the previous.

See you.

PD: Where are you from ? That “Screen” variable name sounds familiar in my
native language :P, Oh and my apoligizes for my bad English.> ----- Original Message -----

From: marting@webklan.com ()
To:
Sent: Thursday, December 11, 2003 12:34 PM
Subject: Re: [SDL] What Im doing wrong (Event procesing)

Sure… this is my main loop… the time issue is handled by a class… I
just
move the SDL Documentation’s main loop example to oop.



.
.
.
SDL_TickTimer MiTimer ;
SDL_Event TheInput ;
.
.
.
while(!EndGame)
{
Pantalla.flip();// Swap the back buffer to the screen
TheInput = Pantalla.getEvent();

Pantalla.blit(Fondo); // Blits the background.

               Tablero1.blitBoardImg(Pantalla);

Tablero1.update(Pantalla,TheInput);

Tablero2.blitBoardImg(Pantalla);
Tablero2.update(Pantalla,TheInput);

EndGame = Tablero1.getGameOver();

SDL_Delay(MiTimer.getTimeLeft() );
MiTimer.setNextTime();
}


My timer class is this. the tick Interval is set to 80 right now… but the
problem
get worse if I use a lesser one.


class SDL_TickTimer {

public:
SDL_TickTimer();

void setTickInterval(int );
void initNextTime(void);
void setNextTime(void);
Uint32 getTimeLeft(void);

private:
//functions
//data
Uint32 uiNextTime;
int iTickInterval;
};

SDL_TickTimer::SDL_TickTimer(){
iTickInterval = 80 ;
}

void SDL_TickTimer::setTickInterval(int iNewInterval){
iTickInterval = iNewInterval;
}

Uint32 SDL_TickTimer::getTimeLeft(){
Uint32 now;

now = SDL_GetTicks();
if(uiNextTime <= now)
    return 0;
else
    return uiNextTime - now;

}

void SDL_TickTimer::initNextTime(void){
uiNextTime = SDL_GetTicks() + iTickInterval;
}

void SDL_TickTimer::setNextTime(void){
uiNextTime += iTickInterval;
}


Martin G


  > At what framerate do you keep your game ? Perhaps the problem is

there.

Depending how do you get the input, if you read the events at each
frame, then if you are at a slow frame rate you will notice some lag.

For example: (in pseudocode)

while (run)
{
while(events_in_queue)
{
ReadInput
}
Draw
Delay //for constant framerate
}

If the Delay is too high, there will be a slowdown in the input
processing.

I have never used Timers in SDL. Can you send how you did it ?

Byes.
Alejandro.

----- Original Message -----
From:
To:
Sent: Thursday, December 11, 2003 11:18 AM
Subject: [SDL] What Im doing wrong (Event procesing)

             Hi everyone. Well I read this list since long time ago
             but

never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t try
it in
linux yet.
Sometimes while the game is runing I have a high response time, and
when the event is worked it has a reaction like if I press the key
twice very fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked .
I dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace?
Im not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the main.
And I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I’ll try it … anyway I still open to others tips…
Im from Argentina.

Martin G
ICQ: 29379123
MSN: mgqw at hotmail.com> Im just guessing but you can try something like this: (again,

pseudocode)

while (!run)
{
inicio = SDL_GetTicks();
while ( events_in_queue OR ( SDL_GetTicks - inicio
To:
Sent: Thursday, December 11, 2003 12:34 PM
Subject: Re: [SDL] What Im doing wrong (Event procesing)

Sure… this is my main loop… the time issue is handled by a class…
I just
move the SDL Documentation’s main loop example to oop.



.
.
.
SDL_TickTimer MiTimer ;
SDL_Event TheInput ;
.
.
.
while(!EndGame)
{
Pantalla.flip();// Swap the back buffer to the screen
TheInput = Pantalla.getEvent();

Pantalla.blit(Fondo); // Blits the background.

              Tablero1.blitBoardImg(Pantalla);

Tablero1.update(Pantalla,TheInput);

Tablero2.blitBoardImg(Pantalla);
Tablero2.update(Pantalla,TheInput);

EndGame = Tablero1.getGameOver();

SDL_Delay(MiTimer.getTimeLeft() );
MiTimer.setNextTime();
}


My timer class is this. the tick Interval is set to 80 right now… but
the problem
get worse if I use a lesser one.


class SDL_TickTimer {

public:
SDL_TickTimer();

void setTickInterval(int );
void initNextTime(void);
void setNextTime(void);
Uint32 getTimeLeft(void);

private:
//functions
//data
Uint32 uiNextTime;
int iTickInterval;
};

SDL_TickTimer::SDL_TickTimer(){
iTickInterval = 80 ;
}

void SDL_TickTimer::setTickInterval(int iNewInterval){
iTickInterval = iNewInterval;
}

Uint32 SDL_TickTimer::getTimeLeft(){
Uint32 now;

now = SDL_GetTicks();
if(uiNextTime At what framerate do you keep your game ? Perhaps the
problem is
there.

Depending how do you get the input, if you read the events at each
frame, then if you are at a slow frame rate you will notice some lag.

For example: (in pseudocode)

while (run)
{
while(events_in_queue)
{
ReadInput
}
Draw
Delay //for constant framerate
}

If the Delay is too high, there will be a slowdown in the input
processing.

I have never used Timers in SDL. Can you send how you did it ?

Byes.
Alejandro.

----- Original Message -----
From:
To:
Sent: Thursday, December 11, 2003 11:18 AM
Subject: [SDL] What Im doing wrong (Event procesing)

             Hi everyone. Well I read this list since long time
             ago but

never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t
try it in
linux yet.
Sometimes while the game is runing I have a high response time, and
when the event is worked it has a reaction like if I press the key
twice very fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked
. I dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace? Im
not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the
main. And I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

So am I , che. I’m open to others suggestions, especially because what I
said is not the best way to do it…

I was wondering… would be great a callback system for events. Just an idea
:slight_smile:

Alejandro.> ----- Original Message -----

From: marting@webklan.com ()
To:
Sent: Thursday, December 11, 2003 2:20 PM
Subject: Re: [SDL] What Im doing wrong (Event procesing)

I’ll try it … anyway I still open to others tips…
Im from Argentina.

Martin G
ICQ: 29379123
MSN: mgqw at hotmail.com

Why don’t you use the key state at the very moment your are asking its
status. I explain: when you enter your frame processing function, check
for UP/DOWN/LEFT/RIGHT at that moment, and not anywhere else in your
event loop. You’ll have proper response whatever your framerate is.On key statusk, here is the first pointer: http://sdldoc.csn.ul.ie/sdlgetkeystate.php Couannette :slight_smile: Alejandro Santos wrote:

At what framerate do you keep your game ? Perhaps the problem is there.
Depending how do you get the input, if you read the events at each frame,
then if you are at a slow frame rate you will notice some lag.

For example: (in pseudocode)

while (run)
{
while(events_in_queue)
{
ReadInput
}
Draw
Delay //for constant framerate
}

If the Delay is too high, there will be a slowdown in the input processing.

I have never used Timers in SDL. Can you send how you did it ?

Byes.
Alejandro.

----- Original Message -----
From:
To:
Sent: Thursday, December 11, 2003 11:18 AM
Subject: [SDL] What Im doing wrong (Event procesing)

              Hi everyone. Well I read this list since long time ago but

never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t try it
in
linux yet.
Sometimes while the game is runing I have a high response time, and when
the event is worked it has a reaction like if I press the key twice very
fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked . I
dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace?
Im not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the main. And
I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

the problem is that keystate returns not the keys pressed at the moment,
but the keys pressed when SDL_Poll / Push /… Event was called.

i have a similar problem: in my tetris i have a delay of ~40 ms (worst
case) and if the player presses and releases a key during this time, the
key will show up as being not pressed in the keystate array
-> pollevent receives keydown, keyup, (otherevents) and fills keystate
with this info

my solution was to fill my own keystate array just with keydown messages
and set every key to up at the beginning of a frame. (i miss constantly
pressed keys in this way, but i don’t need them anyway).

i know you have a different problem, but maybe this helps.

peace, florian hufsky

Couannette wrote:

Why don’t you use the key state at the very moment your are asking its
status. I explain: when you enter your frame processing function, check
for UP/DOWN/LEFT/RIGHT at that moment, and not anywhere else in your
event loop. You’ll have proper response whatever your framerate is.On key statusk, here is the first pointer: Couannette :slight_smile: Alejandro Santos wrote:

At what framerate do you keep your game ? Perhaps the problem is there.
Depending how do you get the input, if you read the events at each frame,
then if you are at a slow frame rate you will notice some lag.

For example: (in pseudocode)

while (run)
{
while(events_in_queue)
{
ReadInput
}
Draw
Delay //for constant framerate
}

If the Delay is too high, there will be a slowdown in the input processing.

I have never used Timers in SDL. Can you send how you did it ?

Byes.
Alejandro.

----- Original Message -----
From:
To:
Sent: Thursday, December 11, 2003 11:18 AM
Subject: [SDL] What Im doing wrong (Event procesing)

               Hi everyone. Well I read this list since long time ago but

never
sent any msg, so here I am.
I am having some problems with the performance picking up input events
from the keyboard and I dont know what Im doing wrong.
I have some kind of lag between the moment when I press a key and the
moment when the event is processed. Im working on Windows, I didn’t try it
in
linux yet.
Sometimes while the game is runing I have a high response time, and when
the event is worked it has a reaction like if I press the key twice very
fast .
Is a simple app is a tetris.
When I press the rotation key the most of the time it works fine but
sometimes the tetramino rotate twice just like the event stay stucked . I
dont
know if Im beeing clear.
Could you give me some tips about of how to raise the performace?
Im not using opengl, I use HW surfaces and SW surfaces, and use double
buffering when use software. I have de SDL_Event structure in the main. And
I use the sdl timer to keep the frame rate uniform.
If you want more detail just ask.
Thanks

Martin G


SDL mailing list
SDL@libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL@libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL@libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl