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

mesh_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/debug.h"
00026 #include "engines/grim/model.h"
00027 #include "engines/grim/savegame.h"
00028 #include "engines/grim/costume/mesh_component.h"
00029 #include "engines/grim/costume/model_component.h"
00030 
00031 namespace Grim {
00032 
00033 MeshComponent::MeshComponent(Component *p, int parentID, const char *name, tag32 t) :
00034         Component(p, parentID, name, t), _node(nullptr) {
00035     if (sscanf(name, "mesh %d", &_num) < 1)
00036         error("Couldn't parse mesh name %s", name);
00037 
00038 }
00039 
00040 void MeshComponent::init() {
00041     if (_parent->isComponentType('M','M','D','L') ||
00042         _parent->isComponentType('M','O','D','L')) {
00043         ModelComponent *mc = static_cast<ModelComponent *>(_parent);
00044         _node = mc->getHierarchy() + _num;
00045         _model = mc->getModel();
00046     } else {
00047         Debug::warning(Debug::Costumes, "Parent of mesh %d was not a model", _num);
00048         _node = nullptr;
00049         _model = nullptr;
00050     }
00051 }
00052 
00053 CMap *MeshComponent::cmap() {
00054     if (_parent->isComponentType('M','M','D','L') ||
00055         _parent->isComponentType('M','O','D','L')) {
00056         ModelComponent *mc = static_cast<ModelComponent *>(_parent);
00057         return mc->getCMap();
00058     }
00059     return nullptr;
00060 }
00061 
00062 void MeshComponent::setKey(int val) {
00063     _node->_meshVisible = (val != 0);
00064 }
00065 
00066 void MeshComponent::reset() {
00067     // NOTE: Setting the visibility to true here causes a bug with the thunderboy costume:
00068     // closing the inventory causes the hat to appear, while it shouldn't.
00069     // This could however introduce regressions somewhere else, so if there is something
00070     // disappearing or not behaving properly in a costume the cause might be here.
00071 //  _node->_meshVisible = true;
00072 }
00073 
00074 int MeshComponent::update(uint /*time*/) {
00075     _node->setMatrix(_matrix);
00076     return 0;
00077 }
00078 
00079 void MeshComponent::saveState(SaveGame *state) {
00080     state->writeBool(_node->_meshVisible);
00081     state->writeVector3d(_matrix.getPosition());
00082 }
00083 
00084 void MeshComponent::restoreState(SaveGame *state) {
00085     _node->_meshVisible = state->readBool();
00086     if (state->saveMinorVersion() >= 14) {
00087         _matrix.setPosition(state->readVector3d());
00088         _node->setMatrix(_matrix);
00089     }
00090 }
00091 
00092 } // end of namespace Grim


Generated on Sat May 18 2019 05:01:09 for ResidualVM by doxygen 1.7.1
curved edge   curved edge