~neon/kolf/master

« back to all changes in this revision

Viewing changes to itemfactory.h

  • Committer: Stefan Majewsky
  • Date: 2010-10-31 23:23:16 UTC
  • Revision ID: git-v1:45f6fdbcc5733b0daa25631ea13b5b2f2d86f20e
Create a Box2D world, and attach Box2D bodies to all CanvasItems.

This is unfortunately a very large patch, because it touches everything
in the CanvasItem hierarchy, the ItemFactory, the KolfGame and the
shapes at once. All these objects are closely related through Box2D's
object hierarchy (world -> bodies -> fixtures -> shapes), so these
changes can hardly be split up further.

svn path=/trunk/KDE/kdegames/kolf/; revision=1191711

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#define KOLF_ITEMFACTORY_H
21
21
 
22
22
#include <QGraphicsItem>
 
23
class b2World;
23
24
 
24
25
namespace Kolf
25
26
{
34
35
        {
35
36
                public:
36
37
                        QList<Kolf::ItemMetadata> knownTypes() const;
37
 
                        QGraphicsItem* createInstance(const QString& identifier, QGraphicsItem* parent = 0) const;
 
38
                        QGraphicsItem* createInstance(const QString& identifier, QGraphicsItem* parent, b2World* world) const;
38
39
 
39
40
                        template<typename T> void registerType(const QString& identifier, const QString& name, bool addOnNewHole = false)
40
41
                        {
42
43
                                registerType(metadata, &Kolf::ItemFactory::create<T>);
43
44
                        }
44
45
                private:
45
 
                        typedef QGraphicsItem* (*ItemCreator)(QGraphicsItem* parent);
 
46
                        typedef QGraphicsItem* (*ItemCreator)(QGraphicsItem* parent, b2World* world);
46
47
                        void registerType(const Kolf::ItemMetadata& metadata, ItemCreator creator);
47
 
                        template<typename T> static QGraphicsItem* create(QGraphicsItem* parent)
 
48
                        template<typename T> static QGraphicsItem* create(QGraphicsItem* parent, b2World* world)
48
49
                        {
49
 
                                return new T(parent);
 
50
                                return new T(parent, world);
50
51
                        }
51
52
                private:
52
53
                        typedef QPair<Kolf::ItemMetadata, ItemCreator> Entry;