* Irrlicht keeps a Mesh and Texture Cache - no need to duplicate that

This commit is contained in:
shlainn 2011-09-16 22:44:57 +02:00
parent eae3e6cc9a
commit 74d4945a72
4 changed files with 55 additions and 33 deletions

View File

@ -26,9 +26,8 @@ CMDHReadFile::CMDHReadFile(void* memory, long len, const c8* fileName)
CMDHReadFile::~CMDHReadFile() CMDHReadFile::~CMDHReadFile()
{ {
// We should not drop the memory here... this model will possibly be loaded more than once // Drop the Memory, Irrlicht keeps a Model Cache of loaded models
//if(getReferenceCount() <= 1) MemoryDataHolder::Delete(getFileName());
// MemoryDataHolder::Delete(getFileName());
} }

View File

@ -310,14 +310,22 @@ for(u32 i=0;i<submeshes.size();i++)//The mesh has to be split into submeshes bec
// std::transform(TexName.begin(), TexName.end(), TexName.begin(), tolower); // std::transform(TexName.begin(), TexName.end(), TexName.begin(), tolower);
char buf[1000]; char buf[1000];
MemoryDataHolder::MakeTextureFilename(buf,WMOMTextureFiles[WMOMTexData[lastindex].textureID].c_str()); MemoryDataHolder::MakeTextureFilename(buf,WMOMTextureFiles[WMOMTexData[lastindex].textureID].c_str());
io::IReadFile* TexFile = io::IrrCreateIReadFileBasic(Device, buf); video::ITexture* tex = Device->getVideoDriver()->findTexture(buf);
if (!TexFile) if(!tex)
{ {
logerror("Error! Texture file not found: %s", buf); io::IReadFile* TexFile = io::IrrCreateIReadFileBasic(Device, buf);
continue; // 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) if(WMOMTexDefinition[WMOMTexData[lastindex].textureID].blendMode==1)
MeshBuffer->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL; MeshBuffer->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
MeshBuffer->recalculateBoundingBox(); MeshBuffer->recalculateBoundingBox();

View File

@ -634,13 +634,23 @@ void SceneWorld::UpdateTerrain(void)
//because there is no point in loading them separately //because there is no point in loading them separately
// logdebug("loading Doodad %s",filename.c_str()); // logdebug("loading Doodad %s",filename.c_str());
io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str()); scene::IAnimatedMesh *mesh;
if (!modelfile) if(!smgr->getMeshCache()->isMeshLoaded(filename.c_str()))
{ {
logerror("Error! modelfile not found: %s", d->MPQpath.c_str()); io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str());
continue; if (!modelfile)
} {
scene::IAnimatedMesh *mesh = smgr->getMesh(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) if(mesh)
{ {
scene::IAnimatedMeshSceneNode *doodad = smgr->addAnimatedMeshSceneNode(mesh); scene::IAnimatedMeshSceneNode *doodad = smgr->addAnimatedMeshSceneNode(mesh);
@ -674,6 +684,10 @@ void SceneWorld::UpdateTerrain(void)
_doodads[d->uniqueid] = gp; _doodads[d->uniqueid] = gp;
} }
} }
else
{
logerror("No mesh provided");
}
} }
} }
// create WorldMapObjects (WMOs) // create WorldMapObjects (WMOs)
@ -692,14 +706,24 @@ void SceneWorld::UpdateTerrain(void)
{ {
filename= wmo->model.c_str(); filename= wmo->model.c_str();
} }
// logdebug("loading WMO %s",filename.c_str());
io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str()); scene::IAnimatedMesh *mesh;
if (!modelfile) if(!smgr->getMeshCache()->isMeshLoaded(filename.c_str()))
{ {
logerror("Error! WMO file not found: %s", wmo->MPQpath.c_str()); io::IReadFile* modelfile = io::IrrCreateIReadFileBasic(device, filename.c_str());
continue; if (!modelfile)
} {
scene::IAnimatedMesh *mesh = smgr->getMesh(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) if(mesh)
{ {
scene::IAnimatedMeshSceneNode *wmo_node = smgr->addAnimatedMeshSceneNode(mesh); scene::IAnimatedMeshSceneNode *wmo_node = smgr->addAnimatedMeshSceneNode(mesh);

View File

@ -22,16 +22,7 @@ struct OpcodeHandler
void (WorldSession::*handler)(WorldPacket& recvPacket); void (WorldSession::*handler)(WorldPacket& recvPacket);
}; };
uint32 Object::maxvalues[TYPEID_MAX]={ 0, uint32 Object::maxvalues[TYPEID_MAX];
0,
0,
0,
0,
0,
0,
0,
0,
0};
WorldSession::WorldSession(PseuInstance *in) WorldSession::WorldSession(PseuInstance *in)
{ {