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

iris.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/iris.h"
00024 #include "engines/grim/gfx_base.h"
00025 #include "engines/grim/savegame.h"
00026 #include "engines/grim/grim.h"
00027 
00028 namespace Grim {
00029 
00030 Iris::Iris() : _playing(false), _direction(Open), _x1(0), _y1(0), _x2(0), _y2(0),
00031         _targetX(0), _targetY(0), _length(0), _currTime(0) {
00032 
00033 }
00034 
00035 Iris::~Iris() {
00036 
00037 }
00038 
00039 void Iris::play(Iris::Direction dir, int x, int y, int length) {
00040     _playing = true;
00041     _direction = dir;
00042     _targetX = x;
00043     _targetY = y;
00044     _length = length;
00045     _currTime = 0;
00046 }
00047 
00048 void Iris::draw() {
00049     if (!_playing) {
00050         if (_direction == Close && g_grim->getMode() != GrimEngine::SmushMode) {
00051             g_driver->irisAroundRegion(320, 240, 320, 240);
00052         }
00053         return;
00054     }
00055 
00056     g_driver->irisAroundRegion(_x1, _y1, _x2, _y2);
00057 }
00058 
00059 void Iris::update(int frameTime) {
00060     if (!_playing) {
00061         return;
00062     }
00063 
00064     _currTime += frameTime;
00065     if (_currTime >= _length) {
00066         _playing = false;
00067         return;
00068     }
00069 
00070     float factor = (float)_currTime / (float)_length;
00071     if (_direction == Open) {
00072         factor = 1 - factor;
00073     }
00074 
00075     _y1 = (int)(_targetY * factor);
00076     _x1 = (int)(_targetX * factor);
00077     _y2 = (int)(480 - (480 - _targetY) * factor);
00078     _x2 = (int)(640 - (640 - _targetX) * factor);
00079 }
00080 
00081 void Iris::saveState(SaveGame *state) const {
00082     state->beginSection('IRIS');
00083 
00084     state->writeBool(_playing);
00085     state->writeLEUint32((uint32)_direction);
00086     state->writeLESint32(_x1);
00087     state->writeLESint32(_y1);
00088     state->writeLESint32(_x2);
00089     state->writeLESint32(_y2);
00090     state->writeLESint32(_length);
00091     state->writeLESint32(_currTime);
00092 
00093     state->endSection();
00094 }
00095 
00096 void Iris::restoreState(SaveGame *state) {
00097     state->beginSection('IRIS');
00098 
00099     _playing = state->readBool();
00100     _direction = (Direction)state->readLEUint32();
00101     _x1 = state->readLESint32();
00102     _y1 = state->readLESint32();
00103     _x2 = state->readLESint32();
00104     _y2 = state->readLESint32();
00105     _length = state->readLESint32();
00106     _currTime = state->readLESint32();
00107 
00108     state->endSection();
00109 }
00110 
00111 }


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