Slow blitter

Started by
5 comments, last by Ravuya 20 years, 10 months ago
void PaintLevel()
{
        for(int r = 0; r <= 10; r++) { // row
                temprect.y = r * 48;
                for(int c = 0; c<=14;c++) { // column
                        temprect.x = c * 48; 
                        switch(level[r][c]) {
                                case ''0'':  
                                        SDL_BlitSurface(tGrass,NULL,screen,&temp
rect);
                                        break;
                                case ''1'':  
                                        SDL_BlitSurface(tWall,NULL,screen,&tempr
ect);
                                        break;
                                case ''2'':  
                                        SDL_BlitSurface(tWater,NULL,screen,&temp
rect);
                                        break;
                                case ''5'':
                                        SDL_BlitSurface(tSidewalk,NULL,screen,&t
emprect);
                                        break;
                                default:
                                    SDL_BlitSurface(tGrass,NULL,screen,&temp
rect);
                        }
                }
        }
} 
Jeez.. I hope that indented right. Anyway, when I turned this thing on, my framerate dropped to about 1fps. The images and the screen surface are both 24-bit, and the tiles are pre-loaded PNGs. Any help would be appreciated; I figure this is the best place to ask. Resist everyone Talk on RavForum(tm)
Advertisement
I don''t know much about blitting, but the switch is definitely slowing you down. Also, assembly I think is the fasting way to set pixels.
Draw your level once to a buffer. When rendering, copy this buffer to your backbuffer and paint the sprites/etc on top of it. If part of the level map changes, only blit the changing part to your special map buffer, then copy (memcpy, not blit) the map buffer into the backbuffer and render as normal.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

quote:Original post by okonomiyaki
I don''t know much about blitting, but the switch is definitely slowing you down. Also, assembly I think is the fasting way to set pixels.


I pulled out the switch. Much faster now, although I need to improve it a little bit -- probably going to do the dual buffers thing as was recommended also.

Thanks

Resist everyone
Talk on RavForum(tm)
For me, 24bpp is rather slow. The processor moves based on a power of 2. 8, 16, and 32 are powers of 2 and 24 is not. To use 24bpp, the processor must perform extra calculations, which may be causing slowdowns. I recommend that you use 16bpp or 32bpp.
Look up dirty rectangles... it''s an old technique to cut down on blitting the parts of the screen that haven''t changed.

------------
- outRider -
I''ve fixed it for the most part. I set the whole thing up as a kind of mutated loop, using an array of possible tiles, and then used SDL_ConvertSurface to convert each one of them to exactly the same bit depth, etc. as the screen surface, greatly increasing speed (and cutting out auto-conversion).

Thanks for your help guys, really sped it up.

Resist everyone
Talk on RavForum(tm)

This topic is closed to new replies.

Advertisement