diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-11 14:12:18 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-11 14:12:23 +0100 |
commit | ba57aa3eedf09f32a1ed003ce26ca54666796aef (patch) | |
tree | d91ea049c4e81c751112d1fede14db2209de5b41 /src | |
parent | f066f988ac60571304b2301c57d5fbbf5da332cf (diff) | |
download | manaserv-ba57aa3eedf09f32a1ed003ce26ca54666796aef.tar.gz manaserv-ba57aa3eedf09f32a1ed003ce26ca54666796aef.tar.bz2 manaserv-ba57aa3eedf09f32a1ed003ce26ca54666796aef.tar.xz manaserv-ba57aa3eedf09f32a1ed003ce26ca54666796aef.zip |
Moved freeing of map position to Actor destructor
It was done in both the Character and the Monster destructors, but I
don't see how any Actor should be excluded from this. Now it also
happens for NPC, Effect and Item, though only NPC has a relevant
walkmask.
Also fixed a small issue introduced in 97e0a9eb170499 and added an
assert to freeTile. We should be able to assert that a tile can only be
freed if it was blocked.
Reviewed-by: Stefan Dombrowski
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/actor.cpp | 23 | ||||
-rw-r--r-- | src/game-server/actor.h | 2 | ||||
-rw-r--r-- | src/game-server/character.cpp | 12 | ||||
-rw-r--r-- | src/game-server/character.h | 2 | ||||
-rw-r--r-- | src/game-server/map.cpp | 3 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 10 |
6 files changed, 22 insertions, 30 deletions
diff --git a/src/game-server/actor.cpp b/src/game-server/actor.cpp index 68430bca..8325c6d8 100644 --- a/src/game-server/actor.cpp +++ b/src/game-server/actor.cpp @@ -25,11 +25,25 @@ #include <cassert> +Actor::~Actor() +{ + // Free the map position + if (MapComposite *mapComposite = getMap()) + { + Map *map = mapComposite->getMap(); + int tileWidth = map->getTileWidth(); + int tileHeight = map->getTileHeight(); + Point oldP = getPosition(); + map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, getBlockType()); + } +} + void Actor::setPosition(const Point &p) { // Update blockmap - if (Map *map = getMap()->getMap()) + if (MapComposite *mapComposite = getMap()) { + Map *map = mapComposite->getMap(); int tileWidth = map->getTileWidth(); int tileHeight = map->getTileHeight(); if ((mPos.x / tileWidth != p.x / tileWidth @@ -46,11 +60,10 @@ void Actor::setPosition(const Point &p) void Actor::setMap(MapComposite *mapComposite) { - assert (mapComposite); - MapComposite *oldMapComposite = getMap(); - Point p = getPosition(); + assert(mapComposite); + const Point p = getPosition(); - if (oldMapComposite) + if (MapComposite *oldMapComposite = getMap()) { Map *oldMap = oldMapComposite->getMap(); int oldTileWidth = oldMap->getTileWidth(); diff --git a/src/game-server/actor.h b/src/game-server/actor.h index e345d579..dc3e7ad1 100644 --- a/src/game-server/actor.h +++ b/src/game-server/actor.h @@ -58,6 +58,8 @@ class Actor : public Thing mSize(0) {} + ~Actor(); + /** * Sets the coordinates. Also updates the walkmap of the map the actor * is on. diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 62464023..4688956f 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -651,18 +651,6 @@ void Character::disconnected() } } -Character::~Character() -{ - if (getMap()) - { - Map *map = getMap()->getMap(); - int tileWidth = map->getTileWidth(); - int tileHeight = map->getTileHeight(); - Point oldP = getPosition(); - map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, getBlockType()); - } -} - void Character::giveSpecial(int id) { if (mSpecials.find(id) == mSpecials.end()) diff --git a/src/game-server/character.h b/src/game-server/character.h index 5a826908..ade13a5d 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -61,8 +61,6 @@ class Character : public Being */ Character(MessageIn &msg); - ~Character(); - /** * recalculates the level when necessary and calls Being::update */ diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp index d48546a2..16368e91 100644 --- a/src/game-server/map.cpp +++ b/src/game-server/map.cpp @@ -157,8 +157,9 @@ void Map::freeTile(int x, int y, BlockType type) return; MetaTile &metaTile = mMetaTiles[x + y * mWidth]; + assert(metaTile.occupation[type] > 0); - if (metaTile.occupation[type] > 0 && !(--metaTile.occupation[type])) + if (!(--metaTile.occupation[type])) { switch (type) { diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 07916d0e..fe23ba5f 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -133,16 +133,6 @@ Monster::~Monster() { i->first->removeListener(&mTargetListener); } - - // Free the map position - if (getMap()) - { - Point oldP = getPosition(); - Map *map = getMap()->getMap(); - int tileWidth = map->getTileWidth(); - int tileHeight = map->getTileHeight(); - map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, getBlockType()); - } } void Monster::perform() |