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

main_model_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/foreach.h"
00024 
00025 #include "engines/grim/model.h"
00026 #include "engines/grim/costume/model_component.h"
00027 #include "engines/grim/costume/main_model_component.h"
00028 
00029 namespace Grim {
00030 
00031 MainModelComponent::MainModelComponent(Component *p, int parentID, const char *filename, Component *prevComponent, tag32 t) :
00032         ModelComponent(p, parentID, filename, prevComponent, t), _hierShared(false), _parentModel(nullptr) {
00033     if (parentID == -2 && prevComponent && prevComponent->isComponentType('M','M','D','L')) {
00034         MainModelComponent *mmc = static_cast<MainModelComponent *>(prevComponent);
00035 
00036         if (mmc->_name == _name) {
00037             _animation = mmc->_animation;
00038             _obj = mmc->_obj;
00039             _hier = mmc->_hier;
00040             _hierShared = true;
00041             mmc->_children.push_back(this);
00042             _parentModel = mmc;
00043         }
00044     }
00045 }
00046 
00047 MainModelComponent::~MainModelComponent() {
00048     if (_hierShared) {
00049         _obj = nullptr; // Keep ~ModelComp from deleting it
00050         _animation = nullptr;
00051     }
00052 
00053     foreach (MainModelComponent *child, _children) {
00054         child->_obj = nullptr;
00055         child->_hier = nullptr;
00056         child->_parentModel = nullptr;
00057     }
00058 
00059     if (_parentModel) {
00060         _parentModel->_children.remove(this);
00061     }
00062 }
00063 
00064 void MainModelComponent::init() {
00065     ModelComponent::init();
00066     _visible = true;
00067     _hier->_hierVisible = _visible;
00068 }
00069 
00070 void MainModelComponent::setColormap(CMap *cmap) {
00071     Component::setColormap(cmap);
00072     if (_parentModel) {
00073         _parentModel->setColormap(cmap);
00074     }
00075 }
00076 
00077 void MainModelComponent::reset() {
00078     _visible = true;
00079     // Can be NULL if this was attached to another costume which
00080     // was deleted.
00081     if (_hier) {
00082         _hier->_hierVisible = _visible;
00083     }
00084 }
00085 
00086 } // end of namespace Grim


Generated on Sat Feb 16 2019 05:00:57 for ResidualVM by doxygen 1.7.1
curved edge   curved edge