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

flashingimage.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 AUTHORS
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/stark/visual/flashingimage.h"
00024 
00025 #include "common/random.h"
00026 #include "graphics/surface.h"
00027 
00028 #include "engines/stark/gfx/driver.h"
00029 #include "engines/stark/gfx/surfacerenderer.h"
00030 #include "engines/stark/gfx/texture.h"
00031 
00032 #include "engines/stark/services/global.h"
00033 #include "engines/stark/services/services.h"
00034 #include "engines/stark/services/settings.h"
00035 
00036 namespace Stark {
00037 
00038 const float VisualFlashingImage::_fadeValueMax = 0.55f;
00039 
00040 VisualFlashingImage::VisualFlashingImage(Gfx::Driver *gfx) :
00041         Visual(TYPE),
00042         _gfx(gfx),
00043         _texture(nullptr),
00044         _fadeLevelIncreasing(true),
00045         _fadeLevel(0),
00046         _flashingTimeRemaining(150 * 33) {
00047     _surfaceRenderer = _gfx->createSurfaceRenderer();
00048 }
00049 
00050 VisualFlashingImage::~VisualFlashingImage() {
00051     delete _texture;
00052     delete _surfaceRenderer;
00053 }
00054 
00055 void VisualFlashingImage::initFromSurface(const Graphics::Surface *surface) {
00056     assert(!_texture);
00057 
00058     _texture = _gfx->createTexture(surface);
00059     _texture->setSamplingFilter(StarkSettings->getImageSamplingFilter());
00060 }
00061 
00062 void VisualFlashingImage::updateFadeLevel() {
00063     uint millisecondsPerGameloop = StarkGlobal->getMillisecondsPerGameloop();
00064     if (_flashingTimeRemaining > 0) {
00065         _flashingTimeRemaining -= millisecondsPerGameloop;
00066         if (_fadeLevelIncreasing) {
00067             _fadeLevel += 0.0022f * millisecondsPerGameloop;
00068         }
00069         else {
00070             _fadeLevel -= 0.0022f * millisecondsPerGameloop;
00071         }
00072         if (ABS(_fadeLevel) >= _fadeValueMax) {
00073             _fadeLevelIncreasing = !_fadeLevelIncreasing;
00074             _fadeLevel = CLIP(_fadeLevel, -_fadeValueMax, _fadeValueMax);
00075         }
00076     } else {
00077         _fadeLevel = 0;
00078     }
00079 }
00080 
00081 void VisualFlashingImage::render(const Common::Point &position) {
00082     updateFadeLevel();
00083 
00084     _surfaceRenderer->setFadeLevel(_fadeLevel);
00085     _surfaceRenderer->render(_texture, position);
00086 }
00087 
00088 } // End of namespace Stark


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