[Kde-games-devel] best way to get a sprite from current theme?

Ian Wadham iandw.au at gmail.com
Wed Jun 20 23:28:42 UTC 2012


Hi Viranch,

On 20/06/2012, at 3:28 AM, Viranch Mehta wrote:
> I've almost completed the QtQuick port of KBreakout (open for alpha testing, source
> can be found here:
> http://quickgit.kde.org/index.php?p=scratch%2Fviranch%2Fkbreakout-qml.git ), so I
> am right now concentrating on retrieving the sprites from theme svgs in best possible
> and fastest manner.
> 
> Till now, what I have done is implement a QML element CanvasItem that has "spriteKey"
> property, which is used to retrieve the sprite pixmap using KGameRenderer::spritePixmap()
> method in CanvasItem's paint() method. This is synchronous and slow however.
> 
> An alternate I found after digging up the libraries was KGameRendererClient. I made
> CanvasItem its subclass, and reimplemented receivePixmap() to set and paint the pixmap
> received from KGameRendererClient instance. Since this is (as I read in the docs)
> asynchronous, it should be faster than my previous implementation, though not noticable
> on my computer.

That is good.  I'd say there is a case for adding something like your CanvasItem to the
KGameRenderer suite, to support QML games.

Performance of rendering from SVG is tricky to observe.  To be sure you are comparing
apples to apples, you need to find and delete the cache file before each test.  Then the
code will be forced to load from SVG and re-render each pixmap.

Timing depends on file size (roughly).  I see the egyptianbreakout.svgz file is quite large,
so it is a good test case for KBreakout.

Alternatively, you can often force SVG load and rendering by rapidly re-sizing
the window to a size you have not used before, but after you have done this a few
times the cache will tend to take over (as it is intended to do of course).

AFAIK the SVG load step cannot be multi-threaded and it takes a large proportion
of the time.  Asynchronous multithreaded rendering should help on large themes,
but its effect might not be noticeable on small ones.  It does allow for "lazy" rendering,
however, and that can improve response time by distributing the rendering time to
whenever the pixmap needs to be seen, rather than having a larger wait when the
game starts.  It also seemed to make resizes less "jerky" in a rough test I did.

> I also looked into KGameRenderedPixmap but I think it is intended for use by QGV.

Yes (KGameRenderedItem that is). It is for adding to a QGraphicsScene.

> So I wanted to know if there are any other options like these to even make the sprite retrieval
> faster from the theme svgs.

Not that I know of.

Cheers, Ian W.



More information about the kde-games-devel mailing list