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         _originalWidth(0),
00048         _originalHeight(0) {
00049     _surfaceRenderer = _gfx->createSurfaceRenderer();
00050 }
00051 
00052 VisualFlashingImage::~VisualFlashingImage() {
00053     delete _texture;
00054     delete _surfaceRenderer;
00055 }
00056 
00057 void VisualFlashingImage::initFromSurface(const Graphics::Surface *surface, uint originalWidth, uint originalHeight) {
00058     assert(!_texture);
00059 
00060     _originalWidth  = originalWidth;
00061     _originalHeight = originalHeight;
00062 
00063     _texture = _gfx->createTexture(surface);
00064     _texture->setSamplingFilter(StarkSettings->getImageSamplingFilter());
00065 }
00066 
00067 void VisualFlashingImage::updateFadeLevel() {
00068     uint millisecondsPerGameloop = StarkGlobal->getMillisecondsPerGameloop();
00069     if (_flashingTimeRemaining > 0) {
00070         _flashingTimeRemaining -= millisecondsPerGameloop;
00071         if (_fadeLevelIncreasing) {
00072             _fadeLevel += 0.0022f * millisecondsPerGameloop;
00073         }
00074         else {
00075             _fadeLevel -= 0.0022f * millisecondsPerGameloop;
00076         }
00077         if (ABS(_fadeLevel) >= _fadeValueMax) {
00078             _fadeLevelIncreasing = !_fadeLevelIncreasing;
00079             _fadeLevel = CLIP(_fadeLevel, -_fadeValueMax, _fadeValueMax);
00080         }
00081     } else {
00082         _fadeLevel = 0;
00083     }
00084 }
00085 
00086 void VisualFlashingImage::render(const Common::Point &position) {
00087     updateFadeLevel();
00088 
00089     _surfaceRenderer->setFadeLevel(_fadeLevel);
00090     _surfaceRenderer->render(_texture, position, _originalWidth, _originalHeight);
00091 }
00092 
00093 } // End of namespace Stark


Generated on Sat Aug 17 2019 05:00:43 for ResidualVM by doxygen 1.7.1
curved edge   curved edge