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

objectstate.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/objectstate.h"
00024 #include "engines/grim/savegame.h"
00025 #include "engines/grim/resource.h"
00026 #include "engines/grim/bitmap.h"
00027 
00028 namespace Grim {
00029 
00030 ObjectState::ObjectState(int setup, ObjectState::Position position, const char *bitmap, const char *zbitmap, bool transparency) :
00031         _setupID(setup), _pos(position), _visibility(false) {
00032 
00033     _bitmap = Bitmap::create(bitmap);
00034     if (zbitmap) {
00035         _zbitmap = Bitmap::create(zbitmap);
00036     } else
00037         _zbitmap = nullptr;
00038 }
00039 
00040 ObjectState::ObjectState() :
00041         _bitmap(nullptr), _zbitmap(nullptr) {
00042 
00043 }
00044 
00045 ObjectState::~ObjectState() {
00046     delete _bitmap;
00047     delete _zbitmap;
00048 }
00049 
00050 const Common::String &ObjectState::getBitmapFilename() const {
00051     return _bitmap->getFilename();
00052 }
00053 
00054 void ObjectState::setActiveImage(int val) {
00055     if (val) {
00056         assert(_bitmap);
00057         _bitmap->setActiveImage(val);
00058         if (_zbitmap && val <= _zbitmap->getNumImages()) {
00059             _zbitmap->setActiveImage(val);
00060         }
00061     }
00062 
00063     _visibility = val != 0;
00064 }
00065 
00066 void ObjectState::draw() {
00067     if (!_visibility)
00068         return;
00069 
00070     assert(_bitmap);
00071     _bitmap->draw();
00072     // The only OBJSTATE_UNDERLAY which has a zbuffer is the bonewagon in set bv. Original doesn't draw that zbuffer,
00073     // so we don't either, otherwise this bug will appear: https://github.com/residualvm/residualvm/issues/143
00074     if (_zbitmap && _pos != OBJSTATE_UNDERLAY)
00075         _zbitmap->draw();
00076 }
00077 
00078 void ObjectState::saveState(SaveGame *savedState) const {
00079     savedState->writeBool(_visibility);
00080     savedState->writeLESint32(_setupID);
00081     savedState->writeLESint32(_pos);
00082 
00083     //_bitmap
00084     if (_bitmap) {
00085         savedState->writeLESint32(_bitmap->getId());
00086     } else {
00087         savedState->writeLESint32(0);
00088     }
00089 
00090     //_zbitmap
00091     if (_zbitmap) {
00092         savedState->writeLESint32(_zbitmap->getId());
00093     } else {
00094         savedState->writeLESint32(0);
00095     }
00096 }
00097 
00098 bool ObjectState::restoreState(SaveGame *savedState) {
00099     _visibility = savedState->readBool();
00100     _setupID    = savedState->readLESint32();
00101     _pos        = (Position) savedState->readLESint32();
00102 
00103     _bitmap = Bitmap::getPool().getObject(savedState->readLESint32());
00104     _zbitmap = Bitmap::getPool().getObject(savedState->readLESint32());
00105 
00106     return true;
00107 }
00108 
00109 } // end of namespace Grim


Generated on Sat Feb 23 2019 05:01:12 for ResidualVM by doxygen 1.7.1
curved edge   curved edge