GRIM: Reload the shared materials with the new colormap. Fix #299

This commit is contained in:
Giulio Camuffo 2011-07-27 18:07:35 +02:00
parent 075c1cae7d
commit cc4fcd3ffc
4 changed files with 22 additions and 4 deletions

View file

@ -26,6 +26,7 @@
#include "engines/grim/material.h"
#include "engines/grim/gfx_base.h"
#include "engines/grim/colormap.h"
#include "engines/grim/resource.h"
namespace Grim {
@ -95,6 +96,20 @@ Material::Material(const Common::String &filename, const char *data, int len, CM
_data = MaterialData::getMaterialData(filename, data, len, cmap);
}
void Material::reload(CMap *cmap) {
Common::String fname = _data->_fname;
--_data->_refCount;
if (_data->_refCount < 1) {
delete _data;
}
Material *m = g_resourceloader->loadMaterial(fname, cmap);
// Steal the data from the new material and discard it.
_data = m->_data;
++_data->_refCount;
delete m;
}
void Material::select() const {
if (_data->_width && _data->_height)
g_driver->selectMaterial(this);

View file

@ -50,6 +50,7 @@ public:
// Load a texture from the given data.
Material(const Common::String &filename, const char *data, int len, CMap *cmap);
void reload(CMap *cmap);
// Load this texture into the GL context
void select() const;

View file

@ -242,13 +242,13 @@ void Model::loadMaterial(int index, CMap *cmap) {
}
_materials[index] = NULL;
if (_parent) {
_materials[index] = _parent->findMaterial(_materialNames[index]);
_materials[index] = _parent->findMaterial(_materialNames[index], cmap);
if (_materials[index]) {
_materialsShared[index] = true;
}
}
if (!_materials[index]) {
if (mat && cmap == _cmap) {
if (mat && cmap->getFilename() == _cmap->getFilename()) {
_materials[index] = mat;
} else {
_materials[index] = g_resourceloader->loadMaterial(_materialNames[index], cmap);
@ -260,9 +260,11 @@ void Model::loadMaterial(int index, CMap *cmap) {
}
}
Material *Model::findMaterial(const char *name) const {
Material *Model::findMaterial(const char *name, CMap *cmap) const {
for (int i = 0; i < _numMaterials; ++i) {
if (scumm_stricmp(name, _materialNames[i]) == 0) {
if (cmap->getFilename() != _cmap->getFilename())
_materials[i]->reload(cmap);
return _materials[i];
}
}

View file

@ -55,7 +55,7 @@ public:
void loadEMI(Common::MemoryReadStream &ms);
void reload(CMap *cmap);
void draw() const;
Material *findMaterial(const char *name) const;
Material *findMaterial(const char *name, CMap *cmap) const;
~Model();