diff options
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index fc638f7..f0a5de3 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include "sceneholder.h" | 1 | #include "sceneholder.h" |
| 2 | #include "constants.h" | 2 | #include "constants.h" |
| 3 | #include "pixmapitem.h" | 3 | #include "gameentity.h" |
| 4 | #include "block.h" | 4 | #include "block.h" |
| 5 | #include "actor.h" | 5 | #include "actor.h" |
| 6 | #include "bonuspoint.h" | 6 | #include "bonuspoint.h" |
| @@ -20,6 +20,18 @@ SceneHolder::SceneHolder(QObject *parent) | |||
| 20 | 20 | ||
| 21 | void SceneHolder::updateMap(const Transmission::map_t& map) | 21 | void SceneHolder::updateMap(const Transmission::map_t& map) |
| 22 | { | 22 | { |
| 23 | /* remove items that got marked for removal from scene */ | ||
| 24 | QMutableListIterator<GameEntity *> i(m_oldItems); | ||
| 25 | while(i.hasNext()) | ||
| 26 | { | ||
| 27 | i.next(); | ||
| 28 | GameEntity *item = i.value(); | ||
| 29 | removeItem(item); | ||
| 30 | i.remove(); | ||
| 31 | delete item; | ||
| 32 | } | ||
| 33 | |||
| 34 | /* process update */ | ||
| 23 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) | 35 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) |
| 24 | { | 36 | { |
| 25 | for (unsigned int y = 0; y < Constants::map_size.height; ++y) | 37 | for (unsigned int y = 0; y < Constants::map_size.height; ++y) |
| @@ -29,17 +41,16 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 29 | continue; | 41 | continue; |
| 30 | 42 | ||
| 31 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); | 43 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); |
| 32 | PixmapItem* item = NULL; | 44 | GameEntity* item = NULL; |
| 33 | 45 | ||
| 34 | if (cur & Transmission::empty) | 46 | if (cur & Transmission::empty) |
| 35 | { | 47 | { |
| 36 | PixmapItem *oldItem = visualMap[x][y]; | 48 | GameEntity *oldItem = visualMap[x][y]; |
| 37 | /* special handling for purging field | 49 | /* special handling for purging field |
| 38 | * remove elements (in case it's not an actor) | 50 | * remove elements (in case it's not an actor) |
| 39 | */ | 51 | */ |
| 40 | if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL) | 52 | if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL) |
| 41 | { | 53 | { |
| 42 | removeItem(oldItem); | ||
| 43 | visualMap[x][y] = NULL; | 54 | visualMap[x][y] = NULL; |
| 44 | Actor *actor = NULL; | 55 | Actor *actor = NULL; |
| 45 | foreach (Actor *tmp, m_actors) | 56 | foreach (Actor *tmp, m_actors) |
| @@ -51,10 +62,13 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 51 | } | 62 | } |
| 52 | } | 63 | } |
| 53 | 64 | ||
| 54 | /* no actor removed that item */ | 65 | /* an item must be removed by an actor */ |
| 55 | if (actor == NULL) | 66 | if (actor == NULL) |
| 56 | Q_ASSERT(false); | 67 | Q_ASSERT(false); |
| 57 | oldItem->onDie(actor); | 68 | oldItem->onDie(actor); |
| 69 | |||
| 70 | /* register item for removal in next update */ | ||
| 71 | m_oldItems.append(oldItem); | ||
| 58 | } | 72 | } |
| 59 | } | 73 | } |
| 60 | 74 | ||
| @@ -122,7 +136,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 122 | { | 136 | { |
| 123 | addItem(item); | 137 | addItem(item); |
| 124 | item->setPos(mapPositionToCoord(x, y)); | 138 | item->setPos(mapPositionToCoord(x, y)); |
| 125 | PixmapItem *oldItem = visualMap[x][y]; | 139 | GameEntity *oldItem = visualMap[x][y]; |
| 126 | visualMap[x][y] = item; | 140 | visualMap[x][y] = item; |
| 127 | if (oldItem != NULL) | 141 | if (oldItem != NULL) |
| 128 | { | 142 | { |
