Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ravuya

Slow blitter

This topic is 5658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Look up dirty rectangles... it''s an old technique to cut down on blitting the parts of the screen that haven''t changed.

------------
- outRider -

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!