Initial commit
This commit is contained in:
211
engines/stark/visual/effects/bubbles.cpp
Normal file
211
engines/stark/visual/effects/bubbles.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/visual/effects/bubbles.h"
|
||||
|
||||
#include "common/random.h"
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/surfacerenderer.h"
|
||||
#include "engines/stark/gfx/bitmap.h"
|
||||
|
||||
#include "engines/stark/services/global.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/services/settings.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualEffectBubbles::VisualEffectBubbles(Gfx::Driver *gfx, const Common::Point &size) :
|
||||
VisualEffect(TYPE, size, gfx),
|
||||
_bubbleCount(50),
|
||||
_kind(kSmall),
|
||||
_sourcePositionRatioX(50),
|
||||
_maxVerticalSpeed(3),
|
||||
_maxHorizontalSpeed(1),
|
||||
_mainColorR(128),
|
||||
_mainColorG(128),
|
||||
_mainColorB(180),
|
||||
_mainColor(0),
|
||||
_darkColor(0) {
|
||||
}
|
||||
|
||||
VisualEffectBubbles::~VisualEffectBubbles() {
|
||||
}
|
||||
|
||||
void VisualEffectBubbles::render(const Common::Point &position) {
|
||||
// Stop rendering if special effect is off
|
||||
if (!StarkSettings->getBoolSetting(Settings::kSpecialFX)) return;
|
||||
|
||||
_timeRemainingUntilNextUpdate -= StarkGlobal->getMillisecondsPerGameloop();
|
||||
if (_timeRemainingUntilNextUpdate <= 0) {
|
||||
update();
|
||||
_timeRemainingUntilNextUpdate = _timeBetweenTwoUpdates;
|
||||
}
|
||||
|
||||
// Fill with transparent color
|
||||
_surface->fillRect(Common::Rect(_surface->w, _surface->h), 0);
|
||||
|
||||
for (uint i = 0; i < _bubbles.size(); i++) {
|
||||
drawBubble(_bubbles[i]);
|
||||
}
|
||||
|
||||
_bitmap->update(_surface);
|
||||
_surfaceRenderer->render(_bitmap, position);
|
||||
}
|
||||
|
||||
void VisualEffectBubbles::setParams(const Common::String ¶ms) {
|
||||
Common::StringTokenizer tokenizer(params, "(), ");
|
||||
|
||||
// Example input: GFX_Bubbles( 1, 25, 3, 50, 3, 2, (50, 50, 75))
|
||||
|
||||
int index = 0;
|
||||
while (!tokenizer.empty()) {
|
||||
Common::String token = tokenizer.nextToken();
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (token != "GFX_Bubbles") {
|
||||
error("Unexpected effect type '%s'", token.c_str());
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
_timeBetweenTwoUpdates = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 0, 1000) * 33;
|
||||
break;
|
||||
case 2:
|
||||
_bubbleCount = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 1, 300);
|
||||
break;
|
||||
case 3:
|
||||
_kind = static_cast<Kind>(CLIP<int>(strtol(token.c_str(), nullptr, 10), 1, 3));
|
||||
break;
|
||||
case 4:
|
||||
_sourcePositionRatioX = CLIP<int>(strtol(token.c_str(), nullptr, 10), 0, 100);
|
||||
break;
|
||||
case 5:
|
||||
_maxVerticalSpeed = CLIP<int>(strtol(token.c_str(), nullptr, 10), 1, 5);
|
||||
break;
|
||||
case 6:
|
||||
_maxHorizontalSpeed = CLIP<int>(strtol(token.c_str(), nullptr, 10), 1, 10);
|
||||
break;
|
||||
case 7:
|
||||
_mainColorR = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 8:
|
||||
_mainColorG = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 9:
|
||||
_mainColorB = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
default:
|
||||
warning("Unexpected parameter %d: %s", index, token.c_str());
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
_sourcePosition.x = _size.x * _sourcePositionRatioX / 100;
|
||||
_sourcePosition.y = _size.y;
|
||||
|
||||
_mainColor = _surface->format.RGBToColor(_mainColorR, _mainColorG, _mainColorB);
|
||||
|
||||
byte darkColorR = 3 * (_mainColorR >> 2);
|
||||
byte darkColorG = 3 * (_mainColorG >> 2);
|
||||
byte darkColorB = 3 * (_mainColorB >> 2);
|
||||
_darkColor = _surface->format.RGBToColor(darkColorR, darkColorG, darkColorB);
|
||||
|
||||
_bubbles.resize(_bubbleCount);
|
||||
for (uint i = 0; i < _bubbles.size(); i++) {
|
||||
Bubble &bubble = _bubbles[i];
|
||||
bubble.position.x = -1;
|
||||
bubble.position.y = -1;
|
||||
|
||||
if (_kind == kRandom) {
|
||||
bubble.kind = (StarkRandomSource->getRandomNumber(255) & 3) ? kLarge : kSmall;
|
||||
} else {
|
||||
bubble.kind = _kind;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VisualEffectBubbles::update() {
|
||||
for (uint i = 0; i < _bubbles.size(); i++) {
|
||||
Bubble &bubble = _bubbles[i];
|
||||
|
||||
if (bubble.position.x == -1 && bubble.position.y == -1) {
|
||||
bubble.position = _sourcePosition;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bubble.position.y <= 1) {
|
||||
bubble.position = _sourcePosition;
|
||||
} else {
|
||||
uint deltaUp = StarkRandomSource->getRandomNumberRng(1, _maxVerticalSpeed);
|
||||
int deltaLeft = (bubble.position.x > _maxHorizontalSpeed) * StarkRandomSource->getRandomNumberRng(0, _maxHorizontalSpeed);
|
||||
int deltaRight = (bubble.position.x < _size.x - _maxHorizontalSpeed) * StarkRandomSource->getRandomNumberRng(0, _maxHorizontalSpeed);
|
||||
|
||||
bubble.position.x += deltaRight - deltaLeft;
|
||||
bubble.position.y -= deltaUp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VisualEffectBubbles::drawBubble(const Bubble &bubble) const {
|
||||
if (bubble.position.x == -1 && bubble.position.y == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bubble.kind == kSmall) {
|
||||
drawSmallBubble(bubble);
|
||||
} else {
|
||||
drawLargeBubble(bubble);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualEffectBubbles::drawSmallBubble(const Bubble &bubble) const {
|
||||
if (bubble.position.x < 0 || bubble.position.x >= _surface->w
|
||||
|| bubble.position.y < 0 || bubble.position.y >= _surface->h) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 *pixel = static_cast<uint32 *>(_surface->getBasePtr(bubble.position.x, bubble.position.y));
|
||||
*pixel = _mainColor;
|
||||
}
|
||||
|
||||
void VisualEffectBubbles::drawLargeBubble(const Bubble &bubble) const {
|
||||
if (bubble.position.x < 1 || bubble.position.x >= _surface->w - 1
|
||||
|| bubble.position.y < 1 || bubble.position.y >= _surface->h - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 *pixel = static_cast<uint32 *>(_surface->getBasePtr(bubble.position.x, bubble.position.y - 1));
|
||||
*pixel = _darkColor;
|
||||
|
||||
pixel = static_cast<uint32 *>(_surface->getBasePtr(bubble.position.x - 1, bubble.position.y));
|
||||
*pixel++ = _darkColor;
|
||||
*pixel++ = _mainColor;
|
||||
*pixel = _darkColor;
|
||||
|
||||
pixel = static_cast<uint32 *>(_surface->getBasePtr(bubble.position.x, bubble.position.y + 1));
|
||||
*pixel = _darkColor;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
90
engines/stark/visual/effects/bubbles.h
Normal file
90
engines/stark/visual/effects/bubbles.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_VISUAL_EFFECTS_BUBBLES_H
|
||||
#define STARK_VISUAL_EFFECTS_BUBBLES_H
|
||||
|
||||
#include "engines/stark/visual/effects/effect.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* A visual effect for drawing small bubbles moving up on top of the scene
|
||||
*/
|
||||
class VisualEffectBubbles : public VisualEffect {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kEffectBubbles;
|
||||
|
||||
explicit VisualEffectBubbles(Gfx::Driver *gfx, const Common::Point &size);
|
||||
~VisualEffectBubbles() override;
|
||||
|
||||
/** Set the effect's parameters using the string based data format found in the game data files */
|
||||
void setParams(const Common::String ¶ms);
|
||||
|
||||
/** Draw the effect at the designated position */
|
||||
void render(const Common::Point &position);
|
||||
|
||||
private:
|
||||
|
||||
enum Kind {
|
||||
kSmall = 1,
|
||||
kLarge = 2,
|
||||
kRandom = 3
|
||||
};
|
||||
|
||||
struct Bubble {
|
||||
Common::Point position;
|
||||
Kind kind;
|
||||
};
|
||||
|
||||
// Parameters
|
||||
uint _bubbleCount;
|
||||
Kind _kind;
|
||||
int _sourcePositionRatioX;
|
||||
int _maxVerticalSpeed;
|
||||
int _maxHorizontalSpeed;
|
||||
byte _mainColorR;
|
||||
byte _mainColorG;
|
||||
byte _mainColorB;
|
||||
|
||||
// State
|
||||
Common::Point _sourcePosition;
|
||||
uint32 _mainColor;
|
||||
uint32 _darkColor;
|
||||
Common::Array<Bubble> _bubbles;
|
||||
|
||||
void update();
|
||||
void drawBubble(const Bubble &bubble) const;
|
||||
void drawSmallBubble(const Bubble &bubble) const;
|
||||
void drawLargeBubble(const Bubble &bubble) const;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_EFFECTS_BUBBLES_H
|
||||
58
engines/stark/visual/effects/effect.cpp
Normal file
58
engines/stark/visual/effects/effect.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/visual/effects/effect.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/surfacerenderer.h"
|
||||
#include "engines/stark/gfx/bitmap.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/services/settings.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualEffect::VisualEffect(VisualType type, const Common::Point &size, Gfx::Driver *gfx) :
|
||||
Visual(type),
|
||||
_size(size),
|
||||
_gfx(gfx),
|
||||
_timeBetweenTwoUpdates(3 * 33), // ms (frames @ 30 fps)
|
||||
_timeRemainingUntilNextUpdate(0) {
|
||||
_surface = new Graphics::Surface();
|
||||
_surface->create(size.x, size.y, Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
_bitmap = _gfx->createBitmap(_surface);
|
||||
_bitmap->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
||||
|
||||
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
||||
}
|
||||
|
||||
VisualEffect::~VisualEffect() {
|
||||
if (_surface) {
|
||||
_surface->free();
|
||||
}
|
||||
delete _surface;
|
||||
delete _bitmap;
|
||||
delete _surfaceRenderer;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
66
engines/stark/visual/effects/effect.h
Normal file
66
engines/stark/visual/effects/effect.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_VISUAL_EFFECTS_EFFECT_H
|
||||
#define STARK_VISUAL_EFFECTS_EFFECT_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
namespace Graphics {
|
||||
struct Surface;
|
||||
}
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
class Bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2D visual effect overlay
|
||||
*
|
||||
* The backing surface is alpha blended on top of the scene
|
||||
*/
|
||||
class VisualEffect : public Visual {
|
||||
public:
|
||||
explicit VisualEffect(VisualType type, const Common::Point &size, Gfx::Driver *gfx);
|
||||
~VisualEffect() override;
|
||||
|
||||
protected:
|
||||
Gfx::Driver *_gfx;
|
||||
Gfx::SurfaceRenderer *_surfaceRenderer;
|
||||
Gfx::Bitmap *_bitmap;
|
||||
Graphics::Surface *_surface;
|
||||
|
||||
uint _timeBetweenTwoUpdates;
|
||||
int _timeRemainingUntilNextUpdate;
|
||||
Common::Point _size;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_EFFECTS_EFFECT_H
|
||||
181
engines/stark/visual/effects/fireflies.cpp
Normal file
181
engines/stark/visual/effects/fireflies.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/visual/effects/fireflies.h"
|
||||
|
||||
#include "common/random.h"
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/surfacerenderer.h"
|
||||
#include "engines/stark/gfx/bitmap.h"
|
||||
|
||||
#include "engines/stark/services/global.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/services/settings.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualEffectFireFlies::VisualEffectFireFlies(Gfx::Driver *gfx, const Common::Point &size) :
|
||||
VisualEffect(TYPE, size, gfx),
|
||||
_fireFlyCount(10),
|
||||
_mainColorR(44),
|
||||
_mainColorG(20),
|
||||
_mainColorB(33) {
|
||||
}
|
||||
|
||||
VisualEffectFireFlies::~VisualEffectFireFlies() {
|
||||
}
|
||||
|
||||
void VisualEffectFireFlies::render(const Common::Point &position) {
|
||||
// Stop rendering if special effect is off
|
||||
if (!StarkSettings->getBoolSetting(Settings::kSpecialFX)) return;
|
||||
|
||||
_timeRemainingUntilNextUpdate -= StarkGlobal->getMillisecondsPerGameloop();
|
||||
if (_timeRemainingUntilNextUpdate <= 0) {
|
||||
update();
|
||||
_timeRemainingUntilNextUpdate = _timeBetweenTwoUpdates;
|
||||
}
|
||||
|
||||
// Fill with transparent color
|
||||
_surface->fillRect(Common::Rect(_surface->w, _surface->h), 0);
|
||||
|
||||
for (uint i = 0; i < _fireFlies.size(); i++) {
|
||||
drawFireFly(_fireFlies[i]);
|
||||
}
|
||||
|
||||
_bitmap->update(_surface);
|
||||
_surfaceRenderer->render(_bitmap, position);
|
||||
}
|
||||
|
||||
void VisualEffectFireFlies::setParams(const Common::String ¶ms) {
|
||||
// Example input: GFX_FireFlies( 2, 70 )
|
||||
Common::StringTokenizer tokenizer(params, "(), ");
|
||||
|
||||
int index = 0;
|
||||
while (!tokenizer.empty()) {
|
||||
Common::String token = tokenizer.nextToken();
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (token != "GFX_FireFlies") {
|
||||
error("Unexpected effect type '%s'", token.c_str());
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
_timeBetweenTwoUpdates = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 0, 1000) * 33;
|
||||
break;
|
||||
case 2:
|
||||
_fireFlyCount = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 1, 300);
|
||||
break;
|
||||
case 3:
|
||||
_mainColorR = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 4:
|
||||
_mainColorG = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 5:
|
||||
_mainColorB = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
default:
|
||||
warning("Unexpected parameter %d: %s", index, token.c_str());
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
_frames.resize(40);
|
||||
for (uint i = 0; i < _frames.size(); i++) {
|
||||
Frame &frame = _frames[i];
|
||||
|
||||
// Barycentric coordinates
|
||||
float t = (cos((_frames.size() - i) / (float)_frames.size() * 2.1415f + 0.5f) + 1.0f) * 0.5f;
|
||||
frame.weight1 = (1.0f - t) * (1.0f - t) * (1.0f - t) / 6.0f;
|
||||
frame.weight2 = (t * t * t * 3.0f - t * t * 6.0f + 4.0f) / 6.0f;
|
||||
frame.weight3 = (((3.0f - t * 3.0f) * t + 3.0f) * t + 1.0f) / 6.0f;
|
||||
frame.weight4 = t * t * t / 6.0f;
|
||||
|
||||
int green;
|
||||
if (i < 5) {
|
||||
green = _mainColorG + (255 - _mainColorG) * (5 - i) / 5;
|
||||
} else if (i + 4 >= _frames.size()) {
|
||||
green = _mainColorG + (255 - _mainColorG) * (i + 4 - _frames.size()) / 5;
|
||||
} else {
|
||||
green = _mainColorG;
|
||||
}
|
||||
frame.color = _surface->format.RGBToColor(_mainColorR, green, _mainColorB);
|
||||
}
|
||||
|
||||
_fireFlies.resize(_fireFlyCount);
|
||||
for (uint i = 0; i < _fireFlies.size(); i++) {
|
||||
FireFly &fireFly = _fireFlies[i];
|
||||
|
||||
fireFly.point1.x = StarkRandomSource->getRandomNumber(_size.x - 1);
|
||||
fireFly.point1.y = StarkRandomSource->getRandomNumber(_size.y - 1);
|
||||
fireFly.point2.x = StarkRandomSource->getRandomNumber(_size.x - 1);
|
||||
fireFly.point2.y = StarkRandomSource->getRandomNumber(_size.y - 1);
|
||||
fireFly.point3.x = StarkRandomSource->getRandomNumber(_size.x - 1);
|
||||
fireFly.point3.y = StarkRandomSource->getRandomNumber(_size.y - 1);
|
||||
fireFly.point4.x = StarkRandomSource->getRandomNumber(_size.x - 1);
|
||||
fireFly.point4.y = StarkRandomSource->getRandomNumber(_size.y - 1);
|
||||
fireFly.currentFrame = StarkRandomSource->getRandomNumber(_frames.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualEffectFireFlies::update() {
|
||||
for (uint i = 0; i < _fireFlies.size(); i++) {
|
||||
FireFly &fireFly = _fireFlies[i];
|
||||
fireFly.currentFrame++;
|
||||
|
||||
if (fireFly.currentFrame >= _frames.size()) {
|
||||
fireFly.currentFrame %= _frames.size();
|
||||
|
||||
fireFly.point1 = fireFly.point2;
|
||||
fireFly.point2 = fireFly.point3;
|
||||
fireFly.point3 = fireFly.point4;
|
||||
fireFly.point4.x = StarkRandomSource->getRandomNumber(_size.x - 1);
|
||||
fireFly.point4.y = StarkRandomSource->getRandomNumber(_size.y - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint i = 0; i < _fireFlies.size(); i++) {
|
||||
FireFly &fireFly = _fireFlies[i];
|
||||
const Frame &frame = _frames[fireFly.currentFrame];
|
||||
|
||||
fireFly.currentPosition.x = fireFly.point1.x * frame.weight1 + fireFly.point2.x * frame.weight2
|
||||
+ fireFly.point3.x * frame.weight3 + fireFly.point4.x * frame.weight4;
|
||||
fireFly.currentPosition.y = fireFly.point1.y * frame.weight1 + fireFly.point2.y * frame.weight2
|
||||
+ fireFly.point3.y * frame.weight3 + fireFly.point4.y * frame.weight4;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualEffectFireFlies::drawFireFly(const FireFly &fly) {
|
||||
if (fly.currentPosition.x < 0 || fly.currentPosition.x >= _surface->w
|
||||
|| fly.currentPosition.y < 0 || fly.currentPosition.y >= _surface->h) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 *pixel = static_cast<uint32 *>(_surface->getBasePtr(fly.currentPosition.x, fly.currentPosition.y));
|
||||
*pixel = _frames[fly.currentFrame].color;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
88
engines/stark/visual/effects/fireflies.h
Normal file
88
engines/stark/visual/effects/fireflies.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_VISUAL_EFFECTS_FIREFLIES_H
|
||||
#define STARK_VISUAL_EFFECTS_FIREFLIES_H
|
||||
|
||||
#include "engines/stark/visual/effects/effect.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* A visual effect for drawing fire flies glowing on top of the scene
|
||||
*/
|
||||
class VisualEffectFireFlies : public VisualEffect {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kEffectFirefly;
|
||||
|
||||
explicit VisualEffectFireFlies(Gfx::Driver *gfx, const Common::Point &size);
|
||||
~VisualEffectFireFlies() override;
|
||||
|
||||
/** Set the effect's parameters using the string based data format found in the game data files */
|
||||
void setParams(const Common::String ¶ms);
|
||||
|
||||
/** Draw the effect at the designated position */
|
||||
void render(const Common::Point &position);
|
||||
|
||||
private:
|
||||
|
||||
struct Frame {
|
||||
float weight1;
|
||||
float weight2;
|
||||
float weight3;
|
||||
float weight4;
|
||||
uint32 color;
|
||||
};
|
||||
|
||||
struct FireFly {
|
||||
Common::Point currentPosition;
|
||||
uint32 currentFrame;
|
||||
Common::Point point1;
|
||||
Common::Point point2;
|
||||
Common::Point point3;
|
||||
Common::Point point4;
|
||||
};
|
||||
|
||||
// Parameters
|
||||
uint _fireFlyCount;
|
||||
byte _mainColorR;
|
||||
byte _mainColorG;
|
||||
byte _mainColorB;
|
||||
|
||||
// State
|
||||
Common::Array<Frame> _frames;
|
||||
Common::Array<FireFly> _fireFlies;
|
||||
|
||||
void update();
|
||||
void drawFireFly(const FireFly &fly);
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_EFFECTS_FIREFLIES_H
|
||||
250
engines/stark/visual/effects/fish.cpp
Normal file
250
engines/stark/visual/effects/fish.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/stark/visual/effects/fish.h"
|
||||
|
||||
#include "common/random.h"
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/surfacerenderer.h"
|
||||
#include "engines/stark/gfx/bitmap.h"
|
||||
|
||||
#include "engines/stark/services/global.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/services/settings.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualEffectFish::VisualEffectFish(Gfx::Driver *gfx, const Common::Point &size) :
|
||||
VisualEffect(TYPE, size, gfx),
|
||||
_fishCount(10),
|
||||
_currentFrame(0),
|
||||
_numFrames(20),
|
||||
_maxRadius(100),
|
||||
_fishPathWidthRatio(20),
|
||||
_fishPathHeightRatio(30),
|
||||
_fishPathWidth(0),
|
||||
_fishPathHeight(0),
|
||||
_masterPathWidth(0),
|
||||
_masterPathHeight(0),
|
||||
_mainColorR(44),
|
||||
_mainColorG(97),
|
||||
_mainColorB(133),
|
||||
_mainColor(0),
|
||||
_otherColor(0) {
|
||||
}
|
||||
|
||||
VisualEffectFish::~VisualEffectFish() {
|
||||
}
|
||||
|
||||
void VisualEffectFish::render(const Common::Point &position) {
|
||||
// Stop rendering if special effect is off
|
||||
if (!StarkSettings->getBoolSetting(Settings::kSpecialFX)) return;
|
||||
|
||||
_timeRemainingUntilNextUpdate -= StarkGlobal->getMillisecondsPerGameloop();
|
||||
if (_timeRemainingUntilNextUpdate <= 0) {
|
||||
update();
|
||||
_timeRemainingUntilNextUpdate = _timeBetweenTwoUpdates;
|
||||
}
|
||||
|
||||
// Fill with transparent color
|
||||
_surface->fillRect(Common::Rect(_surface->w, _surface->h), 0);
|
||||
|
||||
for (uint i = 0; i < _fishList.size(); i++) {
|
||||
drawFish(_fishList[i]);
|
||||
}
|
||||
|
||||
_bitmap->update(_surface);
|
||||
_surfaceRenderer->render(_bitmap, position);
|
||||
}
|
||||
|
||||
void VisualEffectFish::setParams(const Common::String ¶ms) {
|
||||
// Example input: GFX_Fish( 2, 30, 20, 30, (20, 50, 70), 20, 100 )
|
||||
Common::StringTokenizer tokenizer(params, "(), ");
|
||||
|
||||
int index = 0;
|
||||
while (!tokenizer.empty()) {
|
||||
Common::String token = tokenizer.nextToken();
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (token != "GFX_Fish") {
|
||||
error("Unexpected effect type '%s'", token.c_str());
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
_timeBetweenTwoUpdates = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 0, 1000) * 33;
|
||||
break;
|
||||
case 2:
|
||||
_fishCount = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 1, 300);
|
||||
break;
|
||||
case 3:
|
||||
_fishPathWidthRatio = CLIP<int>(strtol(token.c_str(), nullptr, 10), 0, 100);
|
||||
break;
|
||||
case 4:
|
||||
_fishPathHeightRatio = CLIP<int>(strtol(token.c_str(), nullptr, 10), 0, 100);
|
||||
break;
|
||||
case 5:
|
||||
_mainColorR = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 6:
|
||||
_mainColorG = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 7:
|
||||
_mainColorB = strtol(token.c_str(), nullptr, 10);
|
||||
break;
|
||||
case 8:
|
||||
_numFrames = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 10, 100);
|
||||
break;
|
||||
case 9:
|
||||
_maxRadius = CLIP<uint>(strtol(token.c_str(), nullptr, 10), 30, 200);
|
||||
break;
|
||||
default:
|
||||
warning("Unexpected parameter %d: %s", index, token.c_str());
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
_mainColor = _surface->format.RGBToColor(_mainColorR, _mainColorG, _mainColorB);
|
||||
_otherColor = _surface->format.RGBToColor(
|
||||
_mainColorR + (255 - _mainColorR) / 4,
|
||||
_mainColorG + (255 - _mainColorG) / 4,
|
||||
_mainColorB + (255 - _mainColorB) / 3
|
||||
);
|
||||
|
||||
_fishPathWidth = _size.x * _fishPathWidthRatio / 100;
|
||||
_fishPathHeight = _size.y * _fishPathHeightRatio / 100;
|
||||
_masterPathWidth = _size.x - _fishPathWidth;
|
||||
_masterPathHeight = _size.y - _fishPathHeight;
|
||||
|
||||
_numFrames = 20; // The original also ignores the parameter
|
||||
_frames.resize(_numFrames);
|
||||
for (uint i = 0; i < _frames.size(); i++) {
|
||||
Frame &frame = _frames[i];
|
||||
|
||||
// Barycentric coordinates
|
||||
float t = (i + 1) / (float)_frames.size();
|
||||
frame.weight1 = (1.0f - t) * (1.0f - t) * (1.0f - t) / 6.0f;
|
||||
frame.weight2 = (t * t * t * 3.0f - t * t * 6.0f + 4.0f) / 6.0f;
|
||||
frame.weight3 = (((3.0f - t * 3.0f) * t + 3.0f) * t + 1.0f) / 6.0f;
|
||||
frame.weight4 = t * t * t / 6.0f;
|
||||
}
|
||||
|
||||
_fishList.resize(_fishCount);
|
||||
for (uint i = 0; i < _fishList.size(); i++) {
|
||||
Fish &fish = _fishList[i];
|
||||
|
||||
fish.point1.x = StarkRandomSource->getRandomNumber(_fishPathWidth - 1);
|
||||
fish.point1.y = StarkRandomSource->getRandomNumber(_fishPathHeight - 1);
|
||||
fish.point2.x = StarkRandomSource->getRandomNumber(_fishPathWidth - 1);
|
||||
fish.point2.y = StarkRandomSource->getRandomNumber(_fishPathHeight - 1);
|
||||
fish.point3.x = StarkRandomSource->getRandomNumber(_fishPathWidth - 1);
|
||||
fish.point3.y = StarkRandomSource->getRandomNumber(_fishPathHeight - 1);
|
||||
fish.point4.x = StarkRandomSource->getRandomNumber(_fishPathWidth - 1);
|
||||
fish.point4.y = StarkRandomSource->getRandomNumber(_fishPathHeight - 1);
|
||||
}
|
||||
|
||||
_masterPath.point1.x = StarkRandomSource->getRandomNumber(_masterPathWidth - 1);
|
||||
_masterPath.point1.y = StarkRandomSource->getRandomNumber(_masterPathHeight - 1);
|
||||
_masterPath.point2 = _masterPath.point1;
|
||||
_masterPath.point3 = _masterPath.point1;
|
||||
_masterPath.point4 = _masterPath.point1;
|
||||
}
|
||||
|
||||
void VisualEffectFish::update() {
|
||||
_currentFrame++;
|
||||
if (_currentFrame >= _frames.size()) {
|
||||
_currentFrame %= _frames.size();
|
||||
|
||||
for (uint i = 0; i < _fishList.size(); i++) {
|
||||
Fish &fish = _fishList[i];
|
||||
fish.point1 = fish.point2;
|
||||
fish.point2 = fish.point3;
|
||||
fish.point3 = fish.point4;
|
||||
fish.point4.x = StarkRandomSource->getRandomNumber(_fishPathWidth - 1);
|
||||
fish.point4.y = StarkRandomSource->getRandomNumber(_fishPathHeight - 1);
|
||||
}
|
||||
|
||||
_masterPath.point1 = _masterPath.point2;
|
||||
_masterPath.point2 = _masterPath.point3;
|
||||
_masterPath.point3 = _masterPath.point4;
|
||||
|
||||
uint radius;
|
||||
do {
|
||||
_masterPath.point4.x = StarkRandomSource->getRandomNumber(_masterPathWidth - 1);
|
||||
_masterPath.point4.y = StarkRandomSource->getRandomNumber(_masterPathHeight - 1);
|
||||
|
||||
int deltaX = _masterPath.point4.x - _masterPath.point3.x;
|
||||
int deltaY = _masterPath.point4.y - _masterPath.point3.y;
|
||||
radius = sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
} while (radius > _maxRadius);
|
||||
}
|
||||
|
||||
const Frame &frame = _frames[_currentFrame];
|
||||
|
||||
_masterPath.currentPosition.x = _masterPath.point1.x * frame.weight1 + _masterPath.point2.x * frame.weight2
|
||||
+ _masterPath.point3.x * frame.weight3 + _masterPath.point4.x * frame.weight4;
|
||||
_masterPath.currentPosition.y = _masterPath.point1.y * frame.weight1 + _masterPath.point2.y * frame.weight2
|
||||
+ _masterPath.point3.y * frame.weight3 + _masterPath.point4.y * frame.weight4;
|
||||
|
||||
for (uint i = 0; i < _fishList.size(); i++) {
|
||||
Fish &fish = _fishList[i];
|
||||
|
||||
fish.previousPosition = fish.currentPosition;
|
||||
fish.currentPosition.x = fish.point1.x * frame.weight1 + fish.point2.x * frame.weight2
|
||||
+ fish.point3.x * frame.weight3 + fish.point4.x * frame.weight4;
|
||||
fish.currentPosition.y = fish.point1.y * frame.weight1 + fish.point2.y * frame.weight2
|
||||
+ fish.point3.y * frame.weight3 + fish.point4.y * frame.weight4;
|
||||
|
||||
fish.currentPosition += _masterPath.currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualEffectFish::drawFish(const Fish &fish) {
|
||||
if (fish.currentPosition.x < 0 || fish.currentPosition.x >= _surface->w
|
||||
|| fish.currentPosition.y < 0 || fish.currentPosition.y >= _surface->h) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fish.previousPosition.x < 0 || fish.previousPosition.x >= _surface->w
|
||||
|| fish.previousPosition.y < 0 || fish.previousPosition.y >= _surface->h) {
|
||||
return;
|
||||
}
|
||||
|
||||
int dot = (fish.previousPosition.x - fish.currentPosition.x)
|
||||
* (fish.previousPosition.x - fish.currentPosition.x)
|
||||
+ (fish.previousPosition.y - fish.currentPosition.y)
|
||||
* (fish.previousPosition.y - fish.currentPosition.y);
|
||||
|
||||
uint color;
|
||||
if (dot >= 4) {
|
||||
color = _mainColor;
|
||||
} else {
|
||||
color = _otherColor;
|
||||
}
|
||||
_surface->drawLine(fish.previousPosition.x, fish.previousPosition.y,
|
||||
fish.currentPosition.x, fish.currentPosition.y, color);
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
99
engines/stark/visual/effects/fish.h
Normal file
99
engines/stark/visual/effects/fish.h
Normal file
@@ -0,0 +1,99 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STARK_VISUAL_EFFECTS_FISH_H
|
||||
#define STARK_VISUAL_EFFECTS_FISH_H
|
||||
|
||||
#include "engines/stark/visual/effects/effect.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* A visual effect for drawing a group of fish swimming around on top of the scene
|
||||
*/
|
||||
class VisualEffectFish : public VisualEffect {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kEffectFish;
|
||||
|
||||
explicit VisualEffectFish(Gfx::Driver *gfx, const Common::Point &size);
|
||||
~VisualEffectFish() override;
|
||||
|
||||
/** Set the effect's parameters using the string based data format found in the game data files */
|
||||
void setParams(const Common::String ¶ms);
|
||||
|
||||
/** Draw the effect at the designated position */
|
||||
void render(const Common::Point &position);
|
||||
|
||||
private:
|
||||
|
||||
struct Frame {
|
||||
float weight1;
|
||||
float weight2;
|
||||
float weight3;
|
||||
float weight4;
|
||||
};
|
||||
|
||||
struct Fish {
|
||||
Common::Point currentPosition;
|
||||
Common::Point previousPosition;
|
||||
Common::Point point1;
|
||||
Common::Point point2;
|
||||
Common::Point point3;
|
||||
Common::Point point4;
|
||||
};
|
||||
|
||||
// Parameters
|
||||
uint _fishCount;
|
||||
int _fishPathWidthRatio;
|
||||
int _fishPathHeightRatio;
|
||||
int _fishPathWidth;
|
||||
int _fishPathHeight;
|
||||
int _masterPathWidth;
|
||||
int _masterPathHeight;
|
||||
byte _mainColorR;
|
||||
byte _mainColorG;
|
||||
byte _mainColorB;
|
||||
uint32 _mainColor;
|
||||
uint32 _otherColor;
|
||||
uint _numFrames;
|
||||
uint _maxRadius;
|
||||
|
||||
// State
|
||||
uint32 _currentFrame;
|
||||
Common::Array<Frame> _frames;
|
||||
Common::Array<Fish> _fishList;
|
||||
Fish _masterPath;
|
||||
|
||||
void update();
|
||||
void drawFish(const Fish &fish);
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_EFFECTS_FISH_H
|
||||
Reference in New Issue
Block a user