diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index 09eb206f0..dc6e48864 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -129,9 +129,10 @@ bool TerrainTile::isWater() const } CMap::CMap() - : checksum(0), grailPos(-1, -1, -1), grailRadius(0), terrain(nullptr), - guardingCreaturePositions(nullptr), - uidCounter(0) + : checksum(0) + , grailPos(-1, -1, -1) + , grailRadius(0) + , uidCounter(0) { allHeroes.resize(allowedHeroes.size()); allowedAbilities = VLC->skillh->getDefaultAllowed(); @@ -142,22 +143,6 @@ CMap::CMap() CMap::~CMap() { getEditManager()->getUndoManager().clearAll(); - - if(terrain) - { - for(int z = 0; z < levels(); z++) - { - for(int x = 0; x < width; x++) - { - delete[] terrain[z][x]; - delete[] guardingCreaturePositions[z][x]; - } - delete[] terrain[z]; - delete[] guardingCreaturePositions[z]; - } - delete [] terrain; - delete [] guardingCreaturePositions; - } for(auto obj : objects) obj.dellNull(); @@ -572,19 +557,8 @@ void CMap::removeObject(CGObjectInstance * obj) void CMap::initTerrain() { - int level = levels(); - terrain = new TerrainTile**[level]; - guardingCreaturePositions = new int3**[level]; - for(int z = 0; z < level; ++z) - { - terrain[z] = new TerrainTile*[width]; - guardingCreaturePositions[z] = new int3*[width]; - for(int x = 0; x < width; ++x) - { - terrain[z][x] = new TerrainTile[height]; - guardingCreaturePositions[z][x] = new int3[height]; - } - } + terrain.resize(boost::extents[levels()][width][height]); + guardingCreaturePositions.resize(boost::extents[levels()][width][height]); } CMapEditManager * CMap::getEditManager() diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 1638ff3b3..58a3568d2 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -142,14 +142,14 @@ public: std::map questIdentifierToId; std::unique_ptr editManager; - - int3 ***guardingCreaturePositions; + boost::multi_array guardingCreaturePositions; std::map > instanceNames; private: /// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground - TerrainTile*** terrain; + boost::multi_array terrain; + si32 uidCounter; //TODO: initialize when loading an old map public: @@ -170,50 +170,8 @@ public: h & questIdentifierToId; //TODO: viccondetails - const int level = levels(); - if(h.saving) - { - // Save terrain - for(int z = 0; z < level; ++z) - { - for(int x = 0; x < width; ++x) - { - for(int y = 0; y < height; ++y) - { - h & terrain[z][x][y]; - h & guardingCreaturePositions[z][x][y]; - } - } - } - } - else - { - // Load terrain - terrain = new TerrainTile**[level]; - guardingCreaturePositions = new int3**[level]; - for(int z = 0; z < level; ++z) - { - terrain[z] = new TerrainTile*[width]; - guardingCreaturePositions[z] = new int3*[width]; - for(int x = 0; x < width; ++x) - { - terrain[z][x] = new TerrainTile[height]; - guardingCreaturePositions[z][x] = new int3[height]; - } - } - for(int z = 0; z < level; ++z) - { - for(int x = 0; x < width; ++x) - { - for(int y = 0; y < height; ++y) - { - - h & terrain[z][x][y]; - h & guardingCreaturePositions[z][x][y]; - } - } - } - } + h & terrain; + h & guardingCreaturePositions; h & objects; h & heroesOnMap;