| 36 | } |
| 37 | |
| 38 | void TileObject::removeFromMap() |
| 39 | { |
| 40 | auto thisPtr = shared_from_this(); |
| 41 | /* owner may be NULL as this can be used to set the initial position after creation */ |
| 42 | if (this->owningTile) |
| 43 | { |
| 44 | auto erased = this->owningTile->ownedObjects.erase(thisPtr); |
| 45 | if (erased != 1) |
| 46 | { |
| 47 | LogError("Nothing erased?"); |
| 48 | } |
| 49 | int layer = map.getLayer(this->type); |
| 50 | this->drawOnTile->drawnObjects[layer].erase( |
| 51 | std::remove(this->drawOnTile->drawnObjects[layer].begin(), |
| 52 | this->drawOnTile->drawnObjects[layer].end(), thisPtr), |
| 53 | this->drawOnTile->drawnObjects[layer].end()); |
| 54 | this->owningTile = nullptr; |
| 55 | } |
| 56 | for (auto *tile : this->intersectingTiles) |
| 57 | { |
| 58 | tile->intersectingObjects.erase(thisPtr); |
| 59 | } |
| 60 | this->intersectingTiles.clear(); |
| 61 | } |
| 62 | |
| 63 | namespace |
| 64 | { |