summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-17 19:54:02 +0200
committermanuel <manuel@mausz.at>2011-04-17 19:54:02 +0200
commit19c9c38d28cdaafcc1b496027f53dcd1914037cf (patch)
tree416d1efa5ed1dd9fdcea55cb5794fdb25d3bbb87 /pacman-c++
parent65195fdab6262d31056c74f922376de3b009943c (diff)
downloadfoop-19c9c38d28cdaafcc1b496027f53dcd1914037cf.tar.gz
foop-19c9c38d28cdaafcc1b496027f53dcd1914037cf.tar.bz2
foop-19c9c38d28cdaafcc1b496027f53dcd1914037cf.zip
get rid of two dynamic_casts and use qgraphicitem_cast which is A LOT faster (it makes use of static casts)
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/actor.cpp2
-rw-r--r--pacman-c++/actor.h8
-rw-r--r--pacman-c++/block.cpp2
-rw-r--r--pacman-c++/block.h5
-rw-r--r--pacman-c++/bonuspoint.cpp2
-rw-r--r--pacman-c++/bonuspoint.h6
-rw-r--r--pacman-c++/gameentity.cpp4
-rw-r--r--pacman-c++/gameentity.h14
-rw-r--r--pacman-c++/point.cpp2
-rw-r--r--pacman-c++/point.h7
-rw-r--r--pacman-c++/sceneholder.cpp4
11 files changed, 50 insertions, 6 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index e8f5496..fb4b38a 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -13,6 +13,8 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent)
13 : GameEntity(color, parent),m_direction(Actor::None), m_local(local), 13 : GameEntity(color, parent),m_direction(Actor::None), m_local(local),
14 m_wakaPlayer(NULL), m_roundPoints(0), m_gamePoints(0) 14 m_wakaPlayer(NULL), m_roundPoints(0), m_gamePoints(0)
15{ 15{
16 m_type = Type;
17
16 /* DON'T set any pixmap here. we've a pixmap in the animation 18 /* DON'T set any pixmap here. we've a pixmap in the animation
17 * but we need a sprite for the collision detection 19 * but we need a sprite for the collision detection
18 */ 20 */
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h
index 507a8e2..0738593 100644
--- a/pacman-c++/actor.h
+++ b/pacman-c++/actor.h
@@ -14,7 +14,8 @@ class Actor
14Q_OBJECT 14Q_OBJECT
15 15
16public: 16public:
17 enum Movement { 17 enum Movement
18 {
18 None = 0, 19 None = 0,
19 Left, 20 Left,
20 Right, 21 Right,
@@ -22,6 +23,11 @@ public:
22 Down, 23 Down,
23 }; 24 };
24 25
26 enum
27 {
28 Type = UserType + Transmission::pacman
29 };
30
25 Actor(Color::Color color, bool local = false, QGraphicsItem *parent = 0); 31 Actor(Color::Color color, bool local = false, QGraphicsItem *parent = 0);
26 virtual ~Actor() 32 virtual ~Actor()
27 {}; 33 {};
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp
index eb51d89..4087662 100644
--- a/pacman-c++/block.cpp
+++ b/pacman-c++/block.cpp
@@ -9,6 +9,8 @@ QMap<Color::Color, QPixmap> Block::m_pixmaps;
9Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent) 9Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent)
10 : GameEntity(color, parent), m_neighbours(neighbours) 10 : GameEntity(color, parent), m_neighbours(neighbours)
11{ 11{
12 m_type = Type;
13
12 /* empty object for servers */ 14 /* empty object for servers */
13 if (Constants::server) 15 if (Constants::server)
14 return; 16 return;
diff --git a/pacman-c++/block.h b/pacman-c++/block.h
index 6d97a9a..2e47646 100644
--- a/pacman-c++/block.h
+++ b/pacman-c++/block.h
@@ -18,6 +18,11 @@ public:
18 Down = (1 << 3) 18 Down = (1 << 3)
19 }; 19 };
20 20
21 enum
22 {
23 Type = UserType + Transmission::block
24 };
25
21public: 26public:
22 Block(Color::Color color, unsigned int neighbours = None, QGraphicsItem *parent = 0); 27 Block(Color::Color color, unsigned int neighbours = None, QGraphicsItem *parent = 0);
23 virtual ~Block() 28 virtual ~Block()
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp
index 6e1c9d0..8cb8c7e 100644
--- a/pacman-c++/bonuspoint.cpp
+++ b/pacman-c++/bonuspoint.cpp
@@ -12,6 +12,8 @@ namespace
12BonusPoint::BonusPoint(QGraphicsItem *parent) 12BonusPoint::BonusPoint(QGraphicsItem *parent)
13 : GameEntity(parent) 13 : GameEntity(parent)
14{ 14{
15 m_type = Type;
16
15 /* empty object for servers */ 17 /* empty object for servers */
16 if (Constants::server) 18 if (Constants::server)
17 return; 19 return;
diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h
index 2c5a07d..fbb5ba2 100644
--- a/pacman-c++/bonuspoint.h
+++ b/pacman-c++/bonuspoint.h
@@ -7,6 +7,12 @@ class BonusPoint
7 : public GameEntity 7 : public GameEntity
8{ 8{
9public: 9public:
10 enum
11 {
12 Type = UserType + Transmission::bonuspoint
13 };
14
15public:
10 BonusPoint(QGraphicsItem *parent=0); 16 BonusPoint(QGraphicsItem *parent=0);
11 virtual ~BonusPoint() 17 virtual ~BonusPoint()
12 {}; 18 {};
diff --git a/pacman-c++/gameentity.cpp b/pacman-c++/gameentity.cpp
index 9dc72ec..156deda 100644
--- a/pacman-c++/gameentity.cpp
+++ b/pacman-c++/gameentity.cpp
@@ -1,9 +1,9 @@
1#include "gameentity.h" 1#include "gameentity.h"
2 2
3GameEntity::GameEntity(Color::Color color, QGraphicsItem *parent) 3GameEntity::GameEntity(Color::Color color, QGraphicsItem *parent)
4 : PixmapItem(parent), m_eaten(false), m_color(color) 4 : PixmapItem(parent), m_type(Type), m_eaten(false), m_color(color)
5{} 5{}
6 6
7GameEntity::GameEntity(QGraphicsItem *parent) 7GameEntity::GameEntity(QGraphicsItem *parent)
8 : PixmapItem(parent), m_eaten(false), m_color(Color::none) 8 : PixmapItem(parent), m_type(Type), m_eaten(false), m_color(Color::none)
9{} 9{}
diff --git a/pacman-c++/gameentity.h b/pacman-c++/gameentity.h
index 2fde095..92b485e 100644
--- a/pacman-c++/gameentity.h
+++ b/pacman-c++/gameentity.h
@@ -4,6 +4,7 @@
4#include "constants.h" 4#include "constants.h"
5#include "pixmapitem.h" 5#include "pixmapitem.h"
6#include <QtGlobal> 6#include <QtGlobal>
7#include <QDebug>
7 8
8class Actor; 9class Actor;
9 10
@@ -14,6 +15,12 @@ class GameEntity
14 : public PixmapItem 15 : public PixmapItem
15{ 16{
16public: 17public:
18 enum
19 {
20 Type = UserType + 1
21 };
22
23public:
17 GameEntity(Color::Color color = Color::none, QGraphicsItem *parent = 0); 24 GameEntity(Color::Color color = Color::none, QGraphicsItem *parent = 0);
18 GameEntity(QGraphicsItem *parent); 25 GameEntity(QGraphicsItem *parent);
19 virtual ~GameEntity() 26 virtual ~GameEntity()
@@ -52,7 +59,14 @@ public:
52 virtual void onDie(Actor *) 59 virtual void onDie(Actor *)
53 {}; 60 {};
54 61
62 /* enable the use of qgraphicsitem_cast with this item */
63 int type() const
64 {
65 return m_type;
66 }
67
55protected: 68protected:
69 int m_type;
56 bool m_eaten; 70 bool m_eaten;
57 Color::Color m_color; 71 Color::Color m_color;
58}; 72};
diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp
index 7be09c0..2257b12 100644
--- a/pacman-c++/point.cpp
+++ b/pacman-c++/point.cpp
@@ -10,6 +10,8 @@ namespace
10Point::Point(QGraphicsItem *parent) 10Point::Point(QGraphicsItem *parent)
11 : GameEntity(parent) 11 : GameEntity(parent)
12{ 12{
13 m_type = Type;
14
13 /* empty object for servers */ 15 /* empty object for servers */
14 if (Constants::server) 16 if (Constants::server)
15 return; 17 return;
diff --git a/pacman-c++/point.h b/pacman-c++/point.h
index 9fd9929..a406194 100644
--- a/pacman-c++/point.h
+++ b/pacman-c++/point.h
@@ -7,12 +7,17 @@ class Point
7 : public GameEntity 7 : public GameEntity
8{ 8{
9public: 9public:
10 enum
11 {
12 Type = UserType + Transmission::point
13 };
14
15public:
10 Point(QGraphicsItem *parent=0); 16 Point(QGraphicsItem *parent=0);
11 virtual ~Point() 17 virtual ~Point()
12 {}; 18 {};
13 19
14 virtual bool enter(Actor *actor); 20 virtual bool enter(Actor *actor);
15
16 virtual void onDie(Actor *actor); 21 virtual void onDie(Actor *actor);
17}; 22};
18 23
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 38b49e5..6879ea1 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -59,7 +59,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
59 /* special handling for purging field 59 /* special handling for purging field
60 * remove elements (in case it's not an actor) 60 * remove elements (in case it's not an actor)
61 */ 61 */
62 if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL) 62 if (oldItem != NULL && qgraphicsitem_cast<Actor *>(oldItem) == NULL)
63 { 63 {
64 visualMap[x][y] = NULL; 64 visualMap[x][y] = NULL;
65 Actor *actor = NULL; 65 Actor *actor = NULL;
@@ -94,7 +94,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
94 // check for old block first 94 // check for old block first
95 if (visualMap[x][y] != NULL) 95 if (visualMap[x][y] != NULL)
96 { 96 {
97 Block *oldItem = dynamic_cast<Block *>(visualMap[x][y]); 97 Block *oldItem = qgraphicsitem_cast<Block *>(visualMap[x][y]);
98 if (oldItem != NULL) 98 if (oldItem != NULL)
99 neighbours = oldItem->neighbours(); 99 neighbours = oldItem->neighbours();
100 } 100 }