[SDL] faster way?

Frank Ramsay fjramsay at erols.com
Sat Aug 14 08:54:58 PDT 1999

I need a bit of help speeding something up.
I'm porting a dos based isometric engine to SDL, and I got it running
but I'm having a speed problem.  On my PII-450 I get 16 fps at 640x480 
and on my P1-150MMX laptop I get 4.8 fps at 640x480.  Needless to say
is lousy performance.  So I really need some ideas on how to speed this 
thing up.

Here is the basic design:
The display is set to 640x480x8bpp (SDL_HWSURFACE)
the drawing functions draw to a back buffer (not an SDL surface, but 
a big old chunk o'memory pointed to by char *virtual_screen
when the drawing is done it calls my wrapper function 
display_screen(char *buffer)
I'm not worried about the map-drawing function right now because
I know it is not optimized at all.
I did some checking and the main loop runs at about 150,000 times/sec 
if neither the draw function of screen update function are called.  I 
also had these functions return right away (so I could find out how 
much time was lost with the function call overhead) and the main loop 
was still running at over 140,000 times/sec.  
If I just put in the display_screen function, it drops to around 
39 fps. (at 640x480x8bpp) and if I comment out the SDL_UpdateRects 
call it jumps up to around 440 fps, but that is useless because I 
don't see anything that way...

I was hoping that the this function would run much faster than it does
because I can't see any way to speed it up.  Does anyone have any ideas?

_screenWidth _pitch and _bufferSize are globals set when SDL is

void display_screen(char *buffer) {
  int screenOffset = 0;
  int bufferOffset;

  if (SDL_MUSTLOCK(screen))
      if (SDL_LockSurface(screen) < 0)
      for (bufferOffset = 0; bufferOffset < _bufferSize;) 
	  screenOffset += _pitch;
	  bufferOffset += _screenWidth;
      for (bufferOffset = 0; bufferOffset < _bufferSize;)  
	  screenOffset += _pitch;
	  bufferOffset += _screenWidth;

More information about the SDL mailing list