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

sprite_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 "engines/grim/debug.h"
00024 #include "engines/grim/savegame.h"
00025 #include "engines/grim/model.h"
00026 #include "engines/grim/sprite.h"
00027 #include "engines/grim/material.h"
00028 #include "engines/grim/resource.h"
00029 #include "engines/grim/costume/mesh_component.h"
00030 #include "engines/grim/costume/model_component.h"
00031 #include "engines/grim/costume/sprite_component.h"
00032 
00033 namespace Grim {
00034 
00035 SpriteComponent::SpriteComponent(Component *p, int parentID, const char *filename, tag32 t) :
00036         Component(p, parentID, filename, t), _sprite(nullptr) {
00037 
00038 }
00039 
00040 SpriteComponent::~SpriteComponent() {
00041     if (_sprite) {
00042         if (_parent) {
00043             MeshComponent *mc = static_cast<MeshComponent *>(_parent);
00044             if (mc) {
00045                 if (mc->getParent()->isComponentType('M','M','D','L') ||
00046                     mc->getParent()->isComponentType('M','O','D','L')) {
00047                     ModelComponent *mdlc = static_cast<ModelComponent *>(mc->getParent());
00048                     if (mdlc->getHierarchy())
00049                         mc->getNode()->removeSprite(_sprite);
00050                 }
00051             }
00052         }
00053         delete _sprite->_material;
00054         delete _sprite;
00055     }
00056 }
00057 
00058 void SpriteComponent::init() {
00059     const char *comma = strchr(_name.c_str(), ',');
00060 
00061     Common::String name(_name.c_str(), comma);
00062 
00063     if (_sprite) {
00064         if (_parent) {
00065             MeshComponent *mc = static_cast<MeshComponent *>(_parent);
00066             mc->getNode()->removeSprite(_sprite);
00067         }
00068         delete _sprite;
00069         _sprite = nullptr;
00070     }
00071 
00072     if (comma) {
00073         _sprite = new Sprite();
00074         _sprite->loadGrim(name, comma, getCMap());
00075 
00076         if (_parent) {
00077             if (_parent->isComponentType('M','E','S','H')) {
00078                 MeshComponent *mc = static_cast<MeshComponent *>(_parent);
00079                 mc->getNode()->addSprite(_sprite);
00080             } else
00081                 Debug::warning(Debug::Costumes, "Parent of sprite %s wasn't a mesh", _name.c_str());
00082         }
00083     }
00084 }
00085 
00086 void SpriteComponent::setKey(int val) {
00087     if (!_sprite)
00088         return;
00089 
00090     if (val == 0) {
00091         _sprite->_visible = false;
00092     } else {
00093         _sprite->_visible = true;
00094         _sprite->_material->setActiveTexture(val - 1);
00095     }
00096 }
00097 
00098 void SpriteComponent::reset() {
00099     if (_sprite)
00100         _sprite->_visible = false;
00101 }
00102 
00103 void SpriteComponent::saveState(SaveGame *state) {
00104     state->writeBool(_sprite->_visible);
00105     state->writeLESint32(_sprite->_material->getActiveTexture());
00106 }
00107 
00108 void SpriteComponent::restoreState(SaveGame *state) {
00109     _sprite->_visible = state->readBool();
00110     _sprite->_material->setActiveTexture(state->readLESint32());
00111 }
00112 
00113 } // end of namespace Grim


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