Optimization tips?

Started by Cosmo, June 01, 2019, 10:56:47

Previous topic - Next topic

Cosmo

I have a game where I need to draw (32*24) = 768 tiles onscreen at any one time, of various types. Each tile is currently loaded as a pixmap. The game currently runs very slowly (5-8 fps), although before optimization it ran at 0.5 fps!

Should I use copypixmap or something similar?

Derron

#1
1.)
do not "DrawPixmap()" but "DrawImage()" (textures stay in Video Ram then - while pixmaps would get transported to your GPU on each rendered frame)


2.) if this is still too slow: store these tiles on a "atlas" (one image with all the tiles on it) and draw them from there (DrawSubImageRect() or via frames if you loaded it as an animImage)



@ 1.)
So not "LoadPixmap(url)" but "LoadImage(url)"


@ 2.)
LoadAnimImage() - or still "LoadImage(url)" but then "DrawSubImagerect()" instead of "DrawImage()".



Edit: Side note to "pixmaps". Think of them as "arrays of pixels". They allow manipulation of your image data. Means you could eg. create the image atlas "on the fly" after loading all the pixmaps:
- set how many tiles you want next to each other horizontally (eg... 40)
- calculate width of the required texture (40 * tileWidth)
- calculated required height of the texture ((tilecount/40 +1) * tileHeight)
- create a new Image ("CreateImage()")
- retrieve its pixmap ("pixmap:TPixmap = LockImage(justCreatedImage)")
- Copy all your tile pixmaps on this pixmap
- Draw via "DrawSubImageRect()"
- Alternative to "CreateImage()" would be a "CreatePixmap()" and then after copying all pixmaps on it load them via "myTiles:TImage = LoadAnimImage(uri, ...)"


bye
Ron

Cosmo

Using images worked like a treat. Thanks.

I'll probably use a texture atlas later anyway.