Permalink
Browse files

GRIM: Clean up model slightly

  • Loading branch information...
1 parent 62fe2e6 commit 228187b21406474707773c3efe4bfc4d0104e579 @klusark klusark committed Apr 25, 2012
Showing with 27 additions and 25 deletions.
  1. +2 −2 engines/grim/material.cpp
  2. +1 −1 engines/grim/material.h
  3. +13 −13 engines/grim/model.cpp
  4. +10 −8 engines/grim/model.h
  5. +1 −1 engines/grim/resource.cpp
@@ -40,11 +40,11 @@ MaterialData::MaterialData(const Common::String &filename, Common::SeekableReadS
if (g_grim->getGameType() == GType_MONKEY4) {
initEMI(data);
} else {
- initGrim(data, cmap);
+ initGrim(data);
}
}
-void MaterialData::initGrim(Common::SeekableReadStream *data, CMap *cmap) {
+void MaterialData::initGrim(Common::SeekableReadStream *data) {
uint32 tag = data->readUint32BE();
if (tag != MKTAG('M','A','T',' '))
error("invalid magic loading texture");
View
@@ -55,7 +55,7 @@ class MaterialData {
int _refCount;
private:
- void initGrim(Common::SeekableReadStream *data, CMap *cmap);
+ void initGrim(Common::SeekableReadStream *data);
void initEMI(Common::SeekableReadStream *data);
};
View
@@ -51,11 +51,11 @@ Model::Model(const Common::String &filename, Common::SeekableReadStream *data, C
if (g_grim->getGameType() == GType_MONKEY4) {
loadEMI(data);
} else if (data->readUint32BE() == MKTAG('L','D','O','M'))
- loadBinary(data, cmap);
+ loadBinary(data);
else {
data->seek(0, SEEK_SET);
TextSplitter ts(data);
- loadText(&ts, cmap);
+ loadText(&ts);
}
Math::Vector3d max;
@@ -130,7 +130,7 @@ void Model::loadEMI(Common::SeekableReadStream *data) {
if (memcmp(_materialNames[i], "specialty", 9) == 0) {
_materials[i] = 0;
} else {
- loadMaterial(i, 0);
+ loadMaterial(i);
}
data->seek(4, SEEK_CUR);
}
@@ -139,7 +139,7 @@ void Model::loadEMI(Common::SeekableReadStream *data) {
}
-void Model::loadBinary(Common::SeekableReadStream *data, CMap *cmap) {
+void Model::loadBinary(Common::SeekableReadStream *data) {
char v3[4 * 3], f[4];
_numMaterials = data->readUint32LE();
_materials = new Material*[_numMaterials];
@@ -149,7 +149,7 @@ void Model::loadBinary(Common::SeekableReadStream *data, CMap *cmap) {
data->read(_materialNames[i], 32);
_materialsShared[i] = false;
_materials[i] = NULL;
- loadMaterial(i, cmap);
+ loadMaterial(i);
}
data->seek(32, SEEK_CUR); // skip name
data->seek(4, SEEK_CUR);
@@ -170,7 +170,7 @@ void Model::loadBinary(Common::SeekableReadStream *data, CMap *cmap) {
_insertOffset = Math::Vector3d::get_vector3d(v3);
}
-void Model::loadText(TextSplitter *ts, CMap *cmap) {
+void Model::loadText(TextSplitter *ts) {
ts->expectString("section: header");
int major, minor;
ts->scanString("3do %d.%d", 2, &major, &minor);
@@ -187,7 +187,7 @@ void Model::loadText(TextSplitter *ts, CMap *cmap) {
ts->scanString("%d: %32s", 2, &num, materialName);
strcpy(_materialNames[num], materialName);
- loadMaterial(num, cmap);
+ loadMaterial(num);
}
ts->expectString("section: geometrydef");
@@ -258,32 +258,32 @@ ModelNode *Model::getHierarchy() const {
}
void Model::reload(CMap *cmap) {
+ _cmap = cmap;
// Load the new colormap
for (int i = 0; i < _numMaterials; i++) {
- loadMaterial(i, cmap);
+ loadMaterial(i);
}
for (int i = 0; i < _numGeosets; i++)
_geosets[i].changeMaterials(_materials);
- _cmap = cmap;
}
-void Model::loadMaterial(int index, CMap *cmap) {
+void Model::loadMaterial(int index) {
Material *mat = NULL;
if (!_materialsShared[index]) {
mat = _materials[index];
}
_materials[index] = NULL;
if (_parent) {
- _materials[index] = _parent->findMaterial(_materialNames[index], cmap);
+ _materials[index] = _parent->findMaterial(_materialNames[index], _cmap);
if (_materials[index]) {
_materialsShared[index] = true;
}
}
if (!_materials[index]) {
- if (mat && cmap->getFilename() == _cmap->getFilename()) {
+ if (mat && _cmap->getFilename() == _cmap->getFilename()) {
_materials[index] = mat;
} else {
- _materials[index] = g_resourceloader->loadMaterial(_materialNames[index], cmap);
+ _materials[index] = g_resourceloader->loadMaterial(_materialNames[index], _cmap);
}
_materialsShared[index] = false;
}
View
@@ -53,22 +53,18 @@ class Model : public Object {
public:
// Construct a 3D model from the given data.
Model(const Common::String &filename, Common::SeekableReadStream *data, CMap *cmap, Model *parent = NULL);
- void loadBinary(Common::SeekableReadStream *data, CMap *cmap);
- void loadText(TextSplitter *ts, CMap *cmap);
- void loadEMI(Common::SeekableReadStream *data);
+
void reload(CMap *cmap);
void draw() const;
Material *findMaterial(const char *name, CMap *cmap) const;
~Model();
-
- Common::String _fname;
- ObjectPtr<CMap> _cmap;
+ const Common::String &getFilename() const { return _fname; }
+ const ObjectPtr<CMap> &getCMap() const { return _cmap; }
ModelNode *getHierarchy() const;
int getNumNodes() const { return _numHierNodes; }
-//private:
struct Geoset {
void loadBinary(Common::SeekableReadStream *data, Material *materials[]);
void loadText(TextSplitter *ts, Material *materials[]);
@@ -80,8 +76,14 @@ class Model : public Object {
Mesh *_meshes;
};
- void loadMaterial(int index, CMap *cmap);
+//private:
+ void loadMaterial(int index);
+ void loadBinary(Common::SeekableReadStream *data);
+ void loadText(TextSplitter *ts);
+ void loadEMI(Common::SeekableReadStream *data);
+ Common::String _fname;
+ ObjectPtr<CMap> _cmap;
Model *_parent;
int _numMaterials;
char (*_materialNames)[32];
@@ -501,7 +501,7 @@ ModelPtr ResourceLoader::getModel(const Common::String &fname, CMap *c) {
filename.toLowercase();
for (Common::List<Model *>::const_iterator i = _models.begin(); i != _models.end(); ++i) {
Model *m = *i;
- if (filename == m->_fname && *m->_cmap == *c) {
+ if (filename == m->getFilename() && *m->getCMap() == *c) {
return m;
}
}

0 comments on commit 228187b

Please sign in to comment.