WorldRegions memory management update
This commit is contained in:
parent
5d4e67fdb1
commit
69a17c25ea
@ -78,9 +78,6 @@ WorldFiles::WorldFiles(fs::path directory, const DebugSettings& settings)
|
|||||||
|
|
||||||
WorldFiles::~WorldFiles(){
|
WorldFiles::~WorldFiles(){
|
||||||
delete[] compressionBuffer;
|
delete[] compressionBuffer;
|
||||||
for (auto it : regions){
|
|
||||||
delete it.second;
|
|
||||||
}
|
|
||||||
regions.clear();
|
regions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,14 +85,14 @@ WorldRegion* WorldFiles::getRegion(regionsmap& regions, int x, int z) {
|
|||||||
auto found = regions.find(glm::ivec2(x, z));
|
auto found = regions.find(glm::ivec2(x, z));
|
||||||
if (found == regions.end())
|
if (found == regions.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return found->second;
|
return found->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldRegion* WorldFiles::getOrCreateRegion(regionsmap& regions, int x, int z) {
|
WorldRegion* WorldFiles::getOrCreateRegion(regionsmap& regions, int x, int z) {
|
||||||
WorldRegion* region = getRegion(regions, x, z);
|
WorldRegion* region = getRegion(regions, x, z);
|
||||||
if (region == nullptr) {
|
if (region == nullptr) {
|
||||||
region = new WorldRegion();
|
region = new WorldRegion();
|
||||||
regions[glm::ivec2(x, z)] = region;
|
regions[glm::ivec2(x, z)].reset(region);
|
||||||
}
|
}
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
@ -354,8 +351,8 @@ void WorldFiles::writeRegion(int x, int z, WorldRegion* entry, fs::path folder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldFiles::writeRegions(regionsmap& regions, const fs::path& folder, int layer) {
|
void WorldFiles::writeRegions(regionsmap& regions, const fs::path& folder, int layer) {
|
||||||
for (auto it : regions){
|
for (auto& it : regions){
|
||||||
WorldRegion* region = it.second;
|
WorldRegion* region = it.second.get();
|
||||||
if (region->getChunks() == nullptr || !region->isUnsaved())
|
if (region->getChunks() == nullptr || !region->isUnsaved())
|
||||||
continue;
|
continue;
|
||||||
glm::ivec2 key = it.first;
|
glm::ivec2 key = it.first;
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public:
|
|||||||
uint32_t* getSizes() const;
|
uint32_t* getSizes() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unordered_map<glm::ivec2, WorldRegion*> regionsmap;
|
typedef std::unordered_map<glm::ivec2, std::unique_ptr<WorldRegion>> regionsmap;
|
||||||
class WorldFiles {
|
class WorldFiles {
|
||||||
std::unordered_map<glm::ivec3, std::unique_ptr<files::rafile>> openRegFiles;
|
std::unordered_map<glm::ivec3, std::unique_ptr<files::rafile>> openRegFiles;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user