ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

material_component.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/textconsole.h"
00024 
00025 #include "engines/grim/costume.h"
00026 #include "engines/grim/debug.h"
00027 #include "engines/grim/model.h"
00028 #include "engines/grim/material.h"
00029 #include "engines/grim/savegame.h"
00030 
00031 #include "engines/grim/costume/material_component.h"
00032 #include "engines/grim/costume/model_component.h"
00033 
00034 namespace Grim {
00035 
00036 
00037 MaterialComponent::MaterialComponent(Component *p, int parentID, const char *filename, tag32 t) :
00038         Component(p, parentID, filename, t) {
00039 
00040     Debug::debug(Debug::Costumes, "Constructing MaterialComponent %s", filename);
00041 }
00042 
00043 void MaterialComponent::init() {
00044     _mat = nullptr;
00045     if (_parent->isComponentType('M','M','D','L') ||
00046         _parent->isComponentType('M','O','D','L')) {
00047         ModelComponent *p = static_cast<ModelComponent *>(_parent);
00048         Model *model = p->getModel();
00049         if (model) {
00050             for (int i = 0; i < model->_numMaterials; ++i) {
00051                 if (_name.compareToIgnoreCase(model->_materials[i]->getFilename()) == 0) {
00052                     _mat = model->_materials[i];
00053                     return;
00054                 }
00055             }
00056         }
00057     } else {
00058         warning("Parent of a MaterialComponent not a ModelComponent. %s %s", _name.c_str(), _cost->getFilename().c_str());
00059     }
00060 }
00061 
00062 void MaterialComponent::setKey(int val) {
00063     _mat->setActiveTexture(val);
00064 }
00065 
00066 void MaterialComponent::reset() {
00067     _mat->setActiveTexture(0);
00068 }
00069 
00070 void MaterialComponent::resetColormap() {
00071     init();
00072 }
00073 
00074 void MaterialComponent::saveState(SaveGame *state) {
00075     state->writeLESint32(_mat->getActiveTexture());
00076 }
00077 
00078 void MaterialComponent::restoreState(SaveGame *state) {
00079     _mat->setActiveTexture(state->readLESint32());
00080 }
00081 
00082 } // end of namespace Grim


Generated on Sat Mar 16 2019 05:01:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge