I got some drawing lag

I have created a function to make a bounding box(the box that is created
when you click and drag the mouse to select units or folders etc… Well I
have set my app to HdAcell, doublebuff now in the window version the box
gets drawn. In full screen the box doesnt get drawn. That is one problem.
The other is, when the box gets drawn there is lag. For example, if I make
boxes really fast for about 10 sec, and once I stop, I am not moving the
mouse or clicking any buttons, a few more boxes will be drawn, I dont know
how to fix this and I would like some ideas an how to correct the problem.
Thank you.

I have created a function to make a bounding box(the box that is
created when you click and drag the mouse to select units or
folders etc… Well I have set my app to HdAcell, doublebuff now in
the window version the box gets drawn. In full screen the box
doesnt get drawn. That is one problem.

Lots of things could cause this… Do you flip the display surface
after drawing the rectangle? How do you calcuate the color value for
the rect? When do you calculate the color value? Do you get
different pixel formats in fullscreen and windowed modes?

The other is, when the box
gets drawn there is lag. For example, if I make boxes really fast
for about 10 sec, and once I stop, I am not moving the mouse or
clicking any buttons, a few more boxes will be drawn, I dont know
how to fix this and I would like some ideas an how to correct the
problem. Thank you.

Don’t assume that you can render one frame for each mouse move event,
because you most probably can’t. Mice can generate up to 200 events
per second, while the maximum frame rate is usually way below that,
either because of s/w rendering or because flipping is retrace
sync’ed. As a result, rendering one frame for each event means events
build up in the queue, which is what causes the lag.

What you do is basically process events in a fast, tight loop (no
rendering), only rendering a new frame when the queue is empty.

With SDL, you can either do that directly, or you can use
SDL_GetMouseState() to just get the current state without processing
the events yourself.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Friday 11 April 2003 07.50, David wrote:

> > With SDL, you can either do that directly, or you can use > SDL_GetMouseState() to just get the current state without processing > the events yourself.

I do the former, with a simple:

int done;
SDL_Event event;

done = 0;

do
{
/* Deal with any pending events: */

while (SDL_PollEvent(&event) > 0)
{
  if (event.type == SDL_QUIT)
    done = 1;
  ...
}

/* Now I can render... */

...

}
while (!done);

For my games, I typically have what I call an “FPS Throttle” in there, too,
to make sure the loop doesn’t go TOO fast.

The speed differences becomes apparent when it’s going 100FPS most of the
time, but then drops down to something like 50FPS when there’s tons of
stuff being drawn on the screen.

I usually just say “50 FPS is suitable”, and then my timing stays the same
the whole time, which makes doing animation and stuff much easier (for me) :slight_smile:

My throttle is usually something like:

Uint32 cur_time, last_time;

done = 0;

do
{
cur_time = SDL_GetTicks();

... events ...

... render ...


/* Throttle! */

last_time = SDL_GetTicks();

if (last_time < cur_time + (1000 / FPS))
  SDL_Delay(cur_time + (1000 / FPS) - last_time);

}
while (!done);

Enjoy!On Fri, Apr 11, 2003 at 10:13:29AM +0200, David Olofson wrote:


bill at newbreedsoftware.com Hire me!
http://newbreedsoftware.com/bill/ http://newbreedsoftware.com/bill/resume/

Well I fixed the mouse lag problem and I sent in a question about FPS
but this issue was fixed also. Here is what I am doing to get the box
I check to see if the mouse btn was pressed, after the qeue is empty
I then check the value to see if the mouse btn is down, then I run the
function to create the box. This function calls 4 line drawing functions
and in that function it locks the surface and makes the lines. then when
I draw my images and then flip the image.

I have a color defined in a helper class I have
SDL_Color GREEN = { 0, 255, 0, 0 };
the bounding box accepts these params (surface to draw on, x, y, sdl_color)
then the color and coords are passed to make rects and those rects are used
with 4 line drawing functions to make the lines.

Before I had the app use 32bit color for window and fullscreen
now I am using 16bit color, but my desktop is 32bit, but in window mode
it draws the box fine and fullscreen with no luck============================================
Message: 22
From: david@olofson.net (David Olofson)
To: sdl at libsdl.org
Subject: Re: [SDL] I got some drawing lag
Date: Fri, 11 Apr 2003 10:13:29 +0200
Reply-To: sdl at libsdl.org

On Friday 11 April 2003 07.50, David wrote:

I have created a function to make a bounding box(the box that is
created when you click and drag the mouse to select units or
folders etc… Well I have set my app to HdAcell, doublebuff now in
the window version the box gets drawn. In full screen the box
doesnt get drawn. That is one problem.

Lots of things could cause this… Do you flip the display surface=20
after drawing the rectangle? How do you calcuate the color value for=20
the rect? When do you calculate the color value? Do you get=20
different pixel formats in fullscreen and windowed modes?