diff options
Diffstat (limited to 'src/common/Collision/Management/VMapManager2.cpp')
-rw-r--r-- | src/common/Collision/Management/VMapManager2.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index ed4e5535250..3a45a12e556 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -32,6 +32,18 @@ using G3D::Vector3; namespace VMAP { + class ManagedModel + { + public: + ManagedModel() : iRefCount(0) { } + WorldModel* getModel() { return &iModel; } + void incRefCount() { ++iRefCount; } + int decRefCount() { return --iRefCount; } + protected: + WorldModel iModel; + int iRefCount; + }; + bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len) { if (fread(dest, sizeof(char), len, rf) != len) return false; @@ -51,7 +63,7 @@ namespace VMAP delete i->second; for (auto i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i) - delete i->second.getModel(); + delete i->second; } InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const @@ -358,8 +370,8 @@ namespace VMAP auto model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) { - WorldModel* worldmodel = new WorldModel(); - if (!worldmodel->readFile(basepath + filename + ".vmo")) + ManagedModel* worldmodel = new ManagedModel(); + if (!worldmodel->getModel()->readFile(basepath + filename + ".vmo")) { TC_LOG_ERROR("misc", "VMapManager2: could not load '%s%s.vmo'", basepath.c_str(), filename.c_str()); delete worldmodel; @@ -367,13 +379,13 @@ namespace VMAP } TC_LOG_DEBUG("maps", "VMapManager2: loading file '%s%s'", basepath.c_str(), filename.c_str()); - worldmodel->Flags = flags; + worldmodel->getModel()->SetName(filename); + worldmodel->getModel()->Flags = flags; - model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel>(filename, ManagedModel())).first; - model->second.setModel(worldmodel); + model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel*>(filename, worldmodel)).first; } - model->second.incRefCount(); - return model->second.getModel(); + model->second->incRefCount(); + return model->second->getModel(); } void VMapManager2::releaseModelInstance(const std::string &filename) @@ -387,10 +399,10 @@ namespace VMAP TC_LOG_ERROR("misc", "VMapManager2: trying to unload non-loaded file '%s'", filename.c_str()); return; } - if (model->second.decRefCount() == 0) + if (model->second->decRefCount() == 0) { TC_LOG_DEBUG("maps", "VMapManager2: unloading file '%s'", filename.c_str()); - delete model->second.getModel(); + delete model->second; iLoadedModelFiles.erase(model); } } |