Very slow blitting, trying to optimize

Hello,

I’m coding a 2D map editor for a small game engine on MSW and I’m
running into blitting problems. The bigger my map is, the longer it
takes to blit a
tile on it. sometimes, when I try to draw a tile to fast, it even fails
completely at blitting and I have to close and reopen the program for it
to work again.

I have attached the main drawing methods to this post.

How it works:

  1. I have a custom cache class that creates and retrieves bitmaps on
    demand to speed up things a bit. Used especially when using tiles,
    layers or the whole tilemap bitmap. All get_X_bitmap methods you see are
    used to retrieve bitmaps from cache.

  2. The draw_layer and draw_tilemap methods have a rect argument. When
    not nil, only the region specified by this rect is redrawn. Again, this
    is to speed up the whole process.

I did some basic speed test using the Time class to see how log it takes
to blit a tile depending on the map size, using 32x32 tiles.

On a 20x20 map, the whole process takes around 0.032 to 0.041 seconds
On a 100x100 map, it can take up to 0.5 seconds

The most weird part is when I try to draw tiles to fast on a big map.
It starts to blit the first few tiles (with a log of lag) and then it
completly fails. Blitting now takes 0.0 seconds and nothing is drawn on
screen.

Any idea on how I can fix this?
And pease tell me if there is not enough imformation or source code, i
can provide more.:slight_smile:

Thank you very much!

  • Sasha

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs