diff --git a/GroundMaterialConfiguration.cpp b/GroundMaterialConfiguration.cpp index 6a19c0d4..60caab90 100644 --- a/GroundMaterialConfiguration.cpp +++ b/GroundMaterialConfiguration.cpp @@ -6,6 +6,7 @@ #include "GUI.h" #include "ContentLoader.h" #include "EnumToString.h" +#include "MiscUtils.h" using namespace std; using namespace DFHack; @@ -41,16 +42,6 @@ TerrainConfiguration::TerrainConfiguration() //dont really care about the rest of the sprite right now. } -TerrainConfiguration::~TerrainConfiguration() -{ - uint32_t currentsize = (uint32_t)terrainMaterials.size(); - for (uint32_t i = 0; i < currentsize; i++) { - if (terrainMaterials[i] != NULL) { - delete(terrainMaterials[i]); - } - } -} - void DumpInorganicMaterialNamesToDisk() { FILE* fp = fopen("dump.txt", "w"); @@ -261,13 +252,13 @@ void parseWallFloorSpriteElement(TiXmlElement* elemWallFloorSprite, vectorterrainMaterials.size() <= (uint32_t)elemIndex) { + while (tConfig->terrainMaterials.size() <= (uint32_t)elemIndex) { // dont make a full size vector in advance- most of the time // we will only need the first few - tConfig->terrainMaterials.resize(elemIndex + 1, NULL); + tConfig->terrainMaterials.push_back(nullptr); } - if (tConfig->terrainMaterials[elemIndex] == NULL) { - tConfig->terrainMaterials[elemIndex] = new TerrainMaterialConfiguration(); + if (tConfig->terrainMaterials[elemIndex] == nullptr) { + tConfig->terrainMaterials[elemIndex] = dts::make_unique(); } // only update if not set by earlier configs, //FIXME: figure out how to manage priorities here. @@ -296,13 +287,13 @@ void parseWallFloorSpriteElement(TiXmlElement* elemWallFloorSprite, vectorterrainMaterials.size() <= (uint32_t)elemIndex) { + while (tConfig->terrainMaterials.size() <= (uint32_t)elemIndex) { //dont make a full size vector in advance- we wont need it except //for those who insist on Soap Fortresses - tConfig->terrainMaterials.resize(elemIndex + 1, NULL); + tConfig->terrainMaterials.push_back(nullptr); } - if (tConfig->terrainMaterials[elemIndex] == NULL) { - tConfig->terrainMaterials[elemIndex] = new TerrainMaterialConfiguration(); + if (tConfig->terrainMaterials[elemIndex] == nullptr) { + tConfig->terrainMaterials[elemIndex] = dts::make_unique(); } // add to map (if not already present) for (int j = 0; j < NUM_FORMS; j++) { diff --git a/GroundMaterialConfiguration.h b/GroundMaterialConfiguration.h index 5cdb5e97..52c374af 100644 --- a/GroundMaterialConfiguration.h +++ b/GroundMaterialConfiguration.h @@ -16,16 +16,14 @@ class TerrainMaterialConfiguration std::vector> > overridingMaterials; TerrainMaterialConfiguration(); - ~TerrainMaterialConfiguration() {} }; class TerrainConfiguration { public: - std::vector terrainMaterials; + std::vector> terrainMaterials; std::vector> defaultSprite; TerrainConfiguration(); - ~TerrainConfiguration(); }; bool addSingleTerrainConfig( TiXmlElement* elemRoot); diff --git a/SpriteMaps.cpp b/SpriteMaps.cpp index 2d1bafe0..f9f01334 100644 --- a/SpriteMaps.cpp +++ b/SpriteMaps.cpp @@ -49,8 +49,8 @@ c_sprite * GetTerrainSpriteMap(int in, t_matglossPair material, vectorterrainMaterials[material.type]; - if (terrainMat == NULL) { + TerrainMaterialConfiguration* terrainMat = terrain->terrainMaterials[material.type].get(); + if (terrainMat == nullptr) { if (terrain->defaultSprite[tempform].first.get_sheetindex() == UNCONFIGURED_INDEX) { return &(terrain->defaultSprite[0].first); } else {