[Kde-games-devel] kspaceduel: porting to Graphics View

Dmitry Suzdalev dimsuz at gmail.com
Thu Dec 28 20:20:42 CET 2006


Hi, Dirk!

On Thursday 28 December 2006 18:02, Dirk wrote:
> As animation support is removed from QGraphicsPixmapItem which seems to
> be the replacement for QCanvasPixmap, I took some code from the "Ported
> Asteroids Example"
> http://doc.trolltech.com/4.2/graphicsview-portedasteroids.html
> This code is GPL 2. kspaceduel is "GPL 2 or later". Is this a problem?
> And is there maybe alrady existing code which meets better kspaceduel's
> requirements?
I think this is ok, since Qt's asteroids example was once taken from kdegames' 
game "kasteroids" :-).
Btw, I was the one who ported kasteroids to QGV, so you can look there for 
similar QGV-based class. IIRC it is in kasteroids/sprite.h file and is named 
KAstSprite. But IIRC it was created from same QGV porting example as you 
did :-).

Perhaps we should create some common class in libkdegames? Already several 
games are using a variant of it. kasteroids, kbounce, now kspaceduel. Perhaps 
some other, I don't remember.

> In addition I encountered heavy performance problems when using a
> QPixmap as background (field.setBackgroundBrush(QBrush(backgr));), so I
> set the background to pure black. Maybe anyone has a solution for this?
Yup. You should tell your view class to cache its background.
Use QGraphicsView::setCacheMode( CacheBackground ) call for that.

But you need to remember that if your background changes you must explicitly 
call QGraphicsView::resetCachedContent() - it will repaint background then.

> Another problem I encountered and couldn't solve by now is that you can
> clicking on the view. If you do so, the arrow keys are "bound" to the
> view and you can't navigate your ship anymore.
Why? Are you using QGraphicsScene event handlers? If not, I think you should. 
Perhaps this will involve some code redesign though.

> I'm thinking about porting kspaceduel to SVG, as this seems the way to
> go for kdegames. This is meant as a first step, although I don't know
> whether it's a correct one.
I think it is :).

> There is still some porting to Qt4 left and after that, I will have to
> do a lot of clean ups and some refactoring. But wanted to post this first.
Great!

Here are some notes about your patch:

Instead of using
QList<QGraphicsItem*>::Iterator it;
for(it=unexact.begin(); it != unexact.end(); ++it) { ... }
you can use:
foreach( QGraphicsItem* sprite, unexact ) { ... }

That looks more nicer IMO :).
There are several for-loops in your patch that can use foreach instead of 
iterators...

Little thing: no need to #include <QGraphicsSimpleTextItem> in mainview.h:
forward declaration in .h and moving #include<QGSTI> to .cpp is better :).
Same with #include <QGraphicsScene> in sprites.h

Otherwise patch looks quite good for me! :-)
( Of course, I might have missed something - I'm not that experienced "patch 
reader" :-) )

Thank you, Dirk!
Keep it up! :)

Cheers,
Dmitry.


More information about the kde-games-devel mailing list