diff --git a/src/Client/GUI/CMDHMemoryReadFile.cpp b/src/Client/GUI/CMDHMemoryReadFile.cpp index fe362cf..9492755 100644 --- a/src/Client/GUI/CMDHMemoryReadFile.cpp +++ b/src/Client/GUI/CMDHMemoryReadFile.cpp @@ -26,9 +26,8 @@ CMDHReadFile::CMDHReadFile(void* memory, long len, const c8* fileName) CMDHReadFile::~CMDHReadFile() { - // We should not drop the memory here... this model will possibly be loaded more than once - //if(getReferenceCount() <= 1) - // MemoryDataHolder::Delete(getFileName()); + // Drop the Memory, Irrlicht keeps a Model Cache of loaded models + MemoryDataHolder::Delete(getFileName()); } diff --git a/src/Client/GUI/CWMOMeshFileLoader.cpp b/src/Client/GUI/CWMOMeshFileLoader.cpp index c3bb481..8526512 100644 --- a/src/Client/GUI/CWMOMeshFileLoader.cpp +++ b/src/Client/GUI/CWMOMeshFileLoader.cpp @@ -310,14 +310,22 @@ for(u32 i=0;igetVideoDriver()->findTexture(buf); + if(!tex) { - logerror("Error! Texture file not found: %s", buf); - continue; + io::IReadFile* TexFile = io::IrrCreateIReadFileBasic(Device, buf); +// logdebug("Texture %s loading",M2MTextureFiles[M2MTextureLookup[M2MTextureUnit[j].textureIndex]].c_str()); + if (!TexFile) + { + logerror("CM2MeshFileLoader: Texture file not found: %s", buf); + continue; + } +// logdebug("Texture %s loaded",M2MTextureFiles[M2MTextureLookup[M2MTextureUnit[j].textureIndex]].c_str()); + tex = Device->getVideoDriver()->getTexture(TexFile); + TexFile->drop(); } - MeshBuffer->getMaterial().setTexture(0,Device->getVideoDriver()->getTexture(TexFile)); + MeshBuffer->getMaterial().setTexture(0,tex); if(WMOMTexDefinition[WMOMTexData[lastindex].textureID].blendMode==1) MeshBuffer->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL; MeshBuffer->recalculateBoundingBox(); diff --git a/src/Client/GUI/SceneWorld.cpp b/src/Client/GUI/SceneWorld.cpp index 857864a..0888dd9 100644 --- a/src/Client/GUI/SceneWorld.cpp +++ b/src/Client/GUI/SceneWorld.cpp @@ -634,13 +634,23 @@ void SceneWorld::UpdateTerrain(void) //because there is no point in loading them separately // logdebug("loading Doodad %s",filename.c_str()); - io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str()); - if (!modelfile) - { - logerror("Error! modelfile not found: %s", d->MPQpath.c_str()); - continue; - } - scene::IAnimatedMesh *mesh = smgr->getMesh(modelfile); + scene::IAnimatedMesh *mesh; + if(!smgr->getMeshCache()->isMeshLoaded(filename.c_str())) + { + io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str()); + if (!modelfile) + { + logerror("Error! modelfile not found: %s", filename.c_str()); + continue; + } + mesh = smgr->getMesh(modelfile); + modelfile->drop(); + } + else + { + mesh = smgr->getMeshCache()->getMeshByFilename(filename.c_str()); + } + if(mesh) { scene::IAnimatedMeshSceneNode *doodad = smgr->addAnimatedMeshSceneNode(mesh); @@ -674,6 +684,10 @@ void SceneWorld::UpdateTerrain(void) _doodads[d->uniqueid] = gp; } } + else + { + logerror("No mesh provided"); + } } } // create WorldMapObjects (WMOs) @@ -692,14 +706,24 @@ void SceneWorld::UpdateTerrain(void) { filename= wmo->model.c_str(); } -// logdebug("loading WMO %s",filename.c_str()); - io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str()); - if (!modelfile) - { - logerror("Error! WMO file not found: %s", wmo->MPQpath.c_str()); - continue; - } - scene::IAnimatedMesh *mesh = smgr->getMesh(modelfile); + + scene::IAnimatedMesh *mesh; + if(!smgr->getMeshCache()->isMeshLoaded(filename.c_str())) + { + io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str()); + if (!modelfile) + { + logerror("Error! modelfile not found: %s", filename.c_str()); + continue; + } + mesh = smgr->getMesh(modelfile); + modelfile->drop(); + } + else + { + mesh = smgr->getMeshCache()->getMeshByFilename(filename.c_str()); + } + if(mesh) { scene::IAnimatedMeshSceneNode *wmo_node = smgr->addAnimatedMeshSceneNode(mesh); diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 7e2607a..6aa6206 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -22,16 +22,7 @@ struct OpcodeHandler void (WorldSession::*handler)(WorldPacket& recvPacket); }; -uint32 Object::maxvalues[TYPEID_MAX]={ 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0}; +uint32 Object::maxvalues[TYPEID_MAX]; WorldSession::WorldSession(PseuInstance *in) {