Initial commit
This commit is contained in:
183
engines/stark/visual/actor.cpp
Normal file
183
engines/stark/visual/actor.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
/* 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/actor.h"
|
||||
|
||||
#include "engines/stark/model/model.h"
|
||||
#include "engines/stark/model/animhandler.h"
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
#include "engines/stark/scene.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualActor::VisualActor() :
|
||||
Visual(TYPE),
|
||||
_animHandler(nullptr),
|
||||
_model(nullptr),
|
||||
_textureSet(nullptr),
|
||||
_textureSetFacial(nullptr),
|
||||
_time(0),
|
||||
_modelIsDirty(true),
|
||||
_faceTextureName(' '),
|
||||
_castsShadow(false) {
|
||||
}
|
||||
|
||||
VisualActor::~VisualActor() {
|
||||
}
|
||||
|
||||
void VisualActor::setModel(Model *model) {
|
||||
if (_model == model) {
|
||||
return; // Nothing to do
|
||||
}
|
||||
|
||||
_model = model;
|
||||
_modelIsDirty = true;
|
||||
}
|
||||
|
||||
void VisualActor::setAnimHandler(AnimHandler *animHandler) {
|
||||
_animHandler = animHandler;
|
||||
}
|
||||
|
||||
void VisualActor::setTexture(Gfx::TextureSet *texture) {
|
||||
_textureSet = texture;
|
||||
}
|
||||
|
||||
void VisualActor::setTextureFacial(Gfx::TextureSet *textureFacial) {
|
||||
_textureSetFacial = textureFacial;
|
||||
}
|
||||
|
||||
void VisualActor::setNewFace(char shape) {
|
||||
_faceTextureName = shape;
|
||||
}
|
||||
|
||||
const Gfx::Texture *VisualActor::resolveTexture(const Material *material) const {
|
||||
const Gfx::Texture *texture = nullptr;
|
||||
// Emma's face material is incorrectly named "faceEmma".
|
||||
// This workaround enables Emma's lipsync, which does not work in the original game engine.
|
||||
if (_textureSetFacial && (material->name == "face" || material->name == "faceEmma")) {
|
||||
texture = _textureSetFacial->getTexture(Common::String::format("%c.bmp", _faceTextureName));
|
||||
|
||||
if (!texture) {
|
||||
// Default face texture in case the requested shape was not found
|
||||
texture = _textureSetFacial->getTexture("i.bmp");
|
||||
}
|
||||
}
|
||||
|
||||
if (!texture) {
|
||||
texture = _textureSet->getTexture(material->texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
void VisualActor::setTime(uint32 time) {
|
||||
_time = time;
|
||||
}
|
||||
|
||||
Math::Matrix4 VisualActor::getModelMatrix(const Math::Vector3d &position, float direction) const {
|
||||
Math::Matrix4 modelMatrix;
|
||||
modelMatrix.setPosition(position);
|
||||
|
||||
Math::Angle swayAngle = StarkScene->getSwayAngle();
|
||||
if (swayAngle != 0) {
|
||||
Math::Quaternion swayRotation = Math::Quaternion(StarkScene->getSwayDirection(), swayAngle / 2.0);
|
||||
modelMatrix = modelMatrix * swayRotation.toMatrix();
|
||||
}
|
||||
|
||||
float floatOffset = StarkScene->getFloatOffset();
|
||||
if (floatOffset != 0) {
|
||||
Math::Matrix4 floatTranslation;
|
||||
floatTranslation.setPosition(Math::Vector3d(0, 0, floatOffset));
|
||||
modelMatrix = modelMatrix * floatTranslation;
|
||||
}
|
||||
|
||||
Math::Matrix4 rot1;
|
||||
rot1.buildAroundX(90);
|
||||
|
||||
Math::Matrix4 rot2;
|
||||
rot2.buildAroundY(270 - direction);
|
||||
|
||||
Math::Matrix4 scale;
|
||||
scale.setValue(2, 2, -1.0f);
|
||||
|
||||
return modelMatrix * rot1 * rot2 * scale;
|
||||
}
|
||||
|
||||
bool VisualActor::intersectRay(const Math::Ray &ray, const Math::Vector3d &position, float direction) {
|
||||
Math::Matrix4 inverseModelMatrix = getModelMatrix(position, direction);
|
||||
inverseModelMatrix.inverse();
|
||||
|
||||
// Build an object local ray from the world ray
|
||||
Math::Ray localRay = ray;
|
||||
localRay.transform(inverseModelMatrix);
|
||||
|
||||
return _model->intersectRay(localRay);
|
||||
}
|
||||
|
||||
Common::Rect VisualActor::getBoundingRect(const Math::Vector3d &position3d, float direction) const {
|
||||
Math::Matrix4 modelMatrix = getModelMatrix(position3d, direction);
|
||||
|
||||
Math::AABB modelSpaceBB = _model->getBoundingBox();
|
||||
Math::Vector3d min = modelSpaceBB.getMin();
|
||||
Math::Vector3d max = modelSpaceBB.getMax();
|
||||
|
||||
Math::Vector3d verts[8];
|
||||
verts[0].set(min.x(), min.y(), min.z());
|
||||
verts[1].set(max.x(), min.y(), min.z());
|
||||
verts[2].set(min.x(), max.y(), min.z());
|
||||
verts[3].set(min.x(), min.y(), max.z());
|
||||
verts[4].set(max.x(), max.y(), min.z());
|
||||
verts[5].set(max.x(), min.y(), max.z());
|
||||
verts[6].set(min.x(), max.y(), max.z());
|
||||
verts[7].set(max.x(), max.y(), max.z());
|
||||
|
||||
Common::Rect boundingRect;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
modelMatrix.transform(&verts[i], true);
|
||||
Common::Point point = StarkScene->convertPosition3DToGameScreenOriginal(verts[i]);
|
||||
|
||||
if (i == 0) {
|
||||
boundingRect.top = point.y;
|
||||
boundingRect.bottom = point.y;
|
||||
boundingRect.left = point.x;
|
||||
boundingRect.right = point.x;
|
||||
} else {
|
||||
if (boundingRect.left > point.x) {
|
||||
boundingRect.left = point.x;
|
||||
}
|
||||
if (boundingRect.right < point.x) {
|
||||
boundingRect.right = point.x;
|
||||
}
|
||||
if (boundingRect.top > point.y) {
|
||||
boundingRect.top = point.y;
|
||||
}
|
||||
if (boundingRect.bottom < point.y) {
|
||||
boundingRect.bottom = point.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
88
engines/stark/visual/actor.h
Normal file
88
engines/stark/visual/actor.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_ACTOR_H
|
||||
#define STARK_VISUAL_ACTOR_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "math/matrix4.h"
|
||||
#include "math/ray.h"
|
||||
#include "math/vector3d.h"
|
||||
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Texture;
|
||||
class TextureSet;
|
||||
struct LightEntry;
|
||||
}
|
||||
|
||||
class Model;
|
||||
struct Face;
|
||||
struct Material;
|
||||
class SkeletonAnim;
|
||||
class AnimHandler;
|
||||
|
||||
|
||||
class VisualActor : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kActor;
|
||||
|
||||
VisualActor();
|
||||
~VisualActor() override;
|
||||
|
||||
void setModel(Model *model);
|
||||
void setTexture(Gfx::TextureSet *texture);
|
||||
void setTextureFacial(Gfx::TextureSet *textureFacial);
|
||||
void setNewFace(char shape);
|
||||
|
||||
void setAnimHandler(AnimHandler *animHandler);
|
||||
void setTime(uint32 time);
|
||||
|
||||
void setCastShadow(bool cast) { _castsShadow = cast; }
|
||||
|
||||
bool intersectRay(const Math::Ray &ray, const Math::Vector3d &position, float direction);
|
||||
Common::Rect getBoundingRect(const Math::Vector3d &position3d, float direction) const;
|
||||
|
||||
virtual void render(const Math::Vector3d &position, float direction, const Common::Array<Gfx::LightEntry *> &lights) = 0;
|
||||
|
||||
protected:
|
||||
AnimHandler *_animHandler;
|
||||
Model *_model;
|
||||
Gfx::TextureSet *_textureSet;
|
||||
Gfx::TextureSet *_textureSetFacial;
|
||||
char _faceTextureName;
|
||||
uint32 _time;
|
||||
bool _modelIsDirty;
|
||||
bool _castsShadow;
|
||||
|
||||
Math::Matrix4 getModelMatrix(const Math::Vector3d &position, float direction) const;
|
||||
const Gfx::Texture *resolveTexture(const Material *material) const;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_ACTOR_H
|
||||
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
|
||||
183
engines/stark/visual/explodingimage.cpp
Normal file
183
engines/stark/visual/explodingimage.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
/* 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/explodingimage.h"
|
||||
|
||||
#include "common/random.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 {
|
||||
|
||||
VisualExplodingImage::VisualExplodingImage(Gfx::Driver *gfx) :
|
||||
Visual(TYPE),
|
||||
_gfx(gfx),
|
||||
_bitmap(nullptr),
|
||||
_surface(nullptr),
|
||||
_originalWidth(0),
|
||||
_originalHeight(0) {
|
||||
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
||||
}
|
||||
|
||||
VisualExplodingImage::~VisualExplodingImage() {
|
||||
if (_surface) {
|
||||
_surface->free();
|
||||
}
|
||||
delete _surface;
|
||||
delete _bitmap;
|
||||
delete _surfaceRenderer;
|
||||
}
|
||||
|
||||
void VisualExplodingImage::initFromSurface(const Graphics::Surface *surface, uint originalWidth, uint originalHeight) {
|
||||
assert(!_surface && !_bitmap);
|
||||
|
||||
_surface = new Graphics::Surface();
|
||||
_surface->copyFrom(*surface);
|
||||
_originalWidth = originalWidth;
|
||||
_originalHeight = originalHeight;
|
||||
|
||||
_bitmap = _gfx->createBitmap(_surface);
|
||||
_bitmap->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
||||
|
||||
// Create an explosion unit for each pixel in the surface
|
||||
_units.resize(_surface->w * _surface->h);
|
||||
|
||||
Common::Point explosionCenter(_surface->w / 2, _surface->h / 2);
|
||||
Common::Point explosionAmplitude(48, 16);
|
||||
explosionAmplitude.x *= _surface->w / (float)originalWidth;
|
||||
explosionAmplitude.y *= _surface->h / (float)originalHeight;
|
||||
|
||||
uint index = 0;
|
||||
for (int y = 0; y < _surface->h; y++) {
|
||||
for (int x = 0; x < _surface->w; x++, index++) {
|
||||
_units[index].setPosition(x, y);
|
||||
_units[index].setExplosionSettings(explosionCenter, explosionAmplitude, _surface->w / (float)originalWidth);
|
||||
_units[index].setColor(*static_cast<uint32 *>(_surface->getBasePtr(x, y)), _surface->format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VisualExplodingImage::render(const Common::Point &position) {
|
||||
// Fill with transparent color
|
||||
_surface->fillRect(Common::Rect(_surface->w, _surface->h), 0);
|
||||
|
||||
for (uint i = 0; i < _units.size(); i++) {
|
||||
_units[i].update();
|
||||
_units[i].draw(_surface);
|
||||
}
|
||||
|
||||
_bitmap->update(_surface);
|
||||
_surfaceRenderer->render(_bitmap, position, _originalWidth, _originalHeight);
|
||||
}
|
||||
|
||||
VisualExplodingImage::ExplosionUnit::ExplosionUnit() :
|
||||
_scale(1.f),
|
||||
_stillImageTimeRemaining(33 * 33),
|
||||
_explosionFastAccelerationTimeRemaining(25 * 33),
|
||||
_mainColor(0),
|
||||
_darkColor(0) {
|
||||
|
||||
}
|
||||
|
||||
void VisualExplodingImage::ExplosionUnit::setPosition(int x, int y) {
|
||||
_position = Math::Vector2d(x, y);
|
||||
}
|
||||
|
||||
void VisualExplodingImage::ExplosionUnit::setExplosionSettings(const Common::Point ¢er, const Common::Point &litude, float scale) {
|
||||
_center = Math::Vector2d(center.x, center.y);
|
||||
|
||||
_speed.setX(cos(StarkRandomSource->getRandomNumber((float)M_PI * 100)) * (float)amplitude.x);
|
||||
_speed.setY(sin(StarkRandomSource->getRandomNumber((float)M_PI * 100)) * (float)amplitude.y);
|
||||
|
||||
// Really? ensuring all fragments go in the same direction?
|
||||
float magnitude = _position.getDistanceTo(_speed);
|
||||
_speed -= _position;
|
||||
_speed = _speed / _speed.getMagnitude() * -magnitude;
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
void VisualExplodingImage::ExplosionUnit::setColor(uint32 color, const Graphics::PixelFormat &format) {
|
||||
_mainColor = color;
|
||||
|
||||
byte a, r, g, b;
|
||||
format.colorToARGB(color, a, r, g, b);
|
||||
r >>= 1;
|
||||
g >>= 1;
|
||||
b >>= 1;
|
||||
|
||||
_darkColor = format.ARGBToColor(a, r, g, b);
|
||||
}
|
||||
|
||||
void VisualExplodingImage::ExplosionUnit::update() {
|
||||
if (_stillImageTimeRemaining > 0) {
|
||||
_stillImageTimeRemaining -= StarkGlobal->getMillisecondsPerGameloop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_position.getDistanceTo(_center) <= 1.f * _scale) {
|
||||
// Units near the center stay there (to make it look like they enter the chest)
|
||||
return;
|
||||
}
|
||||
|
||||
Math::Vector2d speed = _speed.getNormalized() * 0.6f * _scale;
|
||||
_position += speed;
|
||||
|
||||
// Update the acceleration to units move towards the center
|
||||
Math::Vector2d acceleration = _center - _position;
|
||||
if (_explosionFastAccelerationTimeRemaining > 0) {
|
||||
acceleration *= 3.0f;
|
||||
_explosionFastAccelerationTimeRemaining -= StarkGlobal->getMillisecondsPerGameloop();
|
||||
}
|
||||
|
||||
_speed += acceleration;
|
||||
_speed -= speed * 2.5f;
|
||||
}
|
||||
|
||||
void VisualExplodingImage::ExplosionUnit::draw(Graphics::Surface *surface) {
|
||||
if (_position.getX() <= 1.f || _position.getX() >= surface->w - 1
|
||||
|| _position.getY() <= 1.f || _position.getY() >= surface->h - 1) {
|
||||
return; // Ignore units outside of the surface
|
||||
}
|
||||
|
||||
if (_stillImageTimeRemaining <= 0 && _position.getDistanceTo(_center) <= 2.f) {
|
||||
return; // Ignore units close to the center (to make it look like they enter the chest)
|
||||
}
|
||||
|
||||
uint32 *pixel = static_cast<uint32 *>(surface->getBasePtr(_position.getX(), _position.getY() - 1));
|
||||
*pixel = _darkColor;
|
||||
|
||||
pixel = static_cast<uint32 *>(surface->getBasePtr(_position.getX() - 1, _position.getY()));
|
||||
*pixel++ = _darkColor;
|
||||
*pixel++ = _mainColor;
|
||||
*pixel = _darkColor;
|
||||
|
||||
pixel = static_cast<uint32 *>(surface->getBasePtr(_position.getX(), _position.getY() + 1));
|
||||
*pixel = _darkColor;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
98
engines/stark/visual/explodingimage.h
Normal file
98
engines/stark/visual/explodingimage.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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_EXPLODING_IMAGE_H
|
||||
#define STARK_VISUAL_EXPLODING_IMAGE_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
#include "math/vector2d.h"
|
||||
|
||||
namespace Graphics {
|
||||
struct Surface;
|
||||
}
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
class Bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* An image with an animated explosion effect
|
||||
*
|
||||
* Used by the top bar when picking up an inventory item
|
||||
*/
|
||||
class VisualExplodingImage : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kExplodingImage;
|
||||
|
||||
explicit VisualExplodingImage(Gfx::Driver *gfx);
|
||||
~VisualExplodingImage() override;
|
||||
|
||||
/** Prepare exploding the specified image */
|
||||
void initFromSurface(const Graphics::Surface *surface, uint originalWidth, uint originalHeight);
|
||||
|
||||
/** Render the image at the specified position */
|
||||
void render(const Common::Point &position);
|
||||
|
||||
private:
|
||||
struct ExplosionUnit {
|
||||
ExplosionUnit();
|
||||
|
||||
void setPosition(int x, int y);
|
||||
void setExplosionSettings(const Common::Point ¢er, const Common::Point &litude, float scale);
|
||||
void setColor(uint32 color, const Graphics::PixelFormat &format);
|
||||
void update();
|
||||
void draw(Graphics::Surface *surface);
|
||||
|
||||
Math::Vector2d _position;
|
||||
Math::Vector2d _speed;
|
||||
Math::Vector2d _center;
|
||||
float _scale;
|
||||
|
||||
int _stillImageTimeRemaining;
|
||||
int _explosionFastAccelerationTimeRemaining;
|
||||
uint32 _mainColor;
|
||||
uint32 _darkColor;
|
||||
};
|
||||
|
||||
Gfx::Driver *_gfx;
|
||||
Gfx::SurfaceRenderer *_surfaceRenderer;
|
||||
Gfx::Bitmap *_bitmap;
|
||||
Graphics::Surface *_surface;
|
||||
|
||||
uint _originalWidth;
|
||||
uint _originalHeight;
|
||||
|
||||
Common::Array<ExplosionUnit> _units;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_EXPLODING_IMAGE_H
|
||||
92
engines/stark/visual/flashingimage.cpp
Normal file
92
engines/stark/visual/flashingimage.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 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/flashingimage.h"
|
||||
|
||||
#include "common/random.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 {
|
||||
|
||||
const float VisualFlashingImage::_fadeValueMax = 0.55f;
|
||||
|
||||
VisualFlashingImage::VisualFlashingImage(Gfx::Driver *gfx) :
|
||||
Visual(TYPE),
|
||||
_gfx(gfx),
|
||||
_bitmap(nullptr),
|
||||
_fadeLevelIncreasing(true),
|
||||
_fadeLevel(0),
|
||||
_flashingTimeRemaining(150 * 33),
|
||||
_originalWidth(0),
|
||||
_originalHeight(0) {
|
||||
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
||||
}
|
||||
|
||||
VisualFlashingImage::~VisualFlashingImage() {
|
||||
delete _bitmap;
|
||||
delete _surfaceRenderer;
|
||||
}
|
||||
|
||||
void VisualFlashingImage::initFromSurface(const Graphics::Surface *surface, uint originalWidth, uint originalHeight) {
|
||||
assert(!_bitmap);
|
||||
|
||||
_originalWidth = originalWidth;
|
||||
_originalHeight = originalHeight;
|
||||
|
||||
_bitmap = _gfx->createBitmap(surface);
|
||||
_bitmap->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
||||
}
|
||||
|
||||
void VisualFlashingImage::updateFadeLevel() {
|
||||
uint millisecondsPerGameloop = StarkGlobal->getMillisecondsPerGameloop();
|
||||
if (_flashingTimeRemaining > 0) {
|
||||
_flashingTimeRemaining -= millisecondsPerGameloop;
|
||||
if (_fadeLevelIncreasing) {
|
||||
_fadeLevel += 0.0022f * millisecondsPerGameloop;
|
||||
}
|
||||
else {
|
||||
_fadeLevel -= 0.0022f * millisecondsPerGameloop;
|
||||
}
|
||||
if (ABS(_fadeLevel) >= _fadeValueMax) {
|
||||
_fadeLevelIncreasing = !_fadeLevelIncreasing;
|
||||
_fadeLevel = CLIP(_fadeLevel, -_fadeValueMax, _fadeValueMax);
|
||||
}
|
||||
} else {
|
||||
_fadeLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualFlashingImage::render(const Common::Point &position) {
|
||||
updateFadeLevel();
|
||||
|
||||
_surfaceRenderer->setFadeLevel(_fadeLevel);
|
||||
_surfaceRenderer->render(_bitmap, position, _originalWidth, _originalHeight);
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
83
engines/stark/visual/flashingimage.h
Normal file
83
engines/stark/visual/flashingimage.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* 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_FLASHING_IMAGE_H
|
||||
#define STARK_VISUAL_FLASHING_IMAGE_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
#include "math/vector2d.h"
|
||||
|
||||
namespace Graphics {
|
||||
struct Surface;
|
||||
}
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
class Bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* An image with an animated flashing effect
|
||||
*
|
||||
* Used by the top bar when a new entry has been added to the player's diary
|
||||
*/
|
||||
class VisualFlashingImage : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kFlashingImage;
|
||||
|
||||
explicit VisualFlashingImage(Gfx::Driver *gfx);
|
||||
~VisualFlashingImage() override;
|
||||
|
||||
/** Prepare flashing the specified image */
|
||||
void initFromSurface(const Graphics::Surface *surface, uint originalWidth, uint originalHeight);
|
||||
|
||||
/** Render the image at the specified position */
|
||||
void render(const Common::Point &position);
|
||||
|
||||
private:
|
||||
void updateFadeLevel();
|
||||
|
||||
Gfx::Driver *_gfx;
|
||||
Gfx::SurfaceRenderer *_surfaceRenderer;
|
||||
Gfx::Bitmap *_bitmap;
|
||||
|
||||
uint _originalWidth;
|
||||
uint _originalHeight;
|
||||
|
||||
int _flashingTimeRemaining;
|
||||
float _fadeLevel;
|
||||
bool _fadeLevelIncreasing;
|
||||
static const float _fadeValueMax;
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_FLASHING_IMAGE_H
|
||||
187
engines/stark/visual/image.cpp
Normal file
187
engines/stark/visual/image.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/* 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/image.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
#include "image/png.h"
|
||||
|
||||
#include "engines/stark/formats/xmg.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 {
|
||||
|
||||
VisualImageXMG::VisualImageXMG(Gfx::Driver *gfx) :
|
||||
Visual(TYPE),
|
||||
_gfx(gfx),
|
||||
_bitmap(nullptr),
|
||||
_surface(nullptr),
|
||||
_originalWidth(0),
|
||||
_originalHeight(0) {
|
||||
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
||||
}
|
||||
|
||||
VisualImageXMG::~VisualImageXMG() {
|
||||
if (_surface) {
|
||||
_surface->free();
|
||||
}
|
||||
delete _surface;
|
||||
delete _bitmap;
|
||||
delete _surfaceRenderer;
|
||||
}
|
||||
|
||||
void VisualImageXMG::setHotSpot(const Common::Point &hotspot) {
|
||||
_hotspot = hotspot;
|
||||
}
|
||||
|
||||
void VisualImageXMG::load(Common::ReadStream *stream) {
|
||||
assert(!_surface && !_bitmap);
|
||||
|
||||
// Decode the XMG
|
||||
_surface = Formats::XMGDecoder::decode(stream);
|
||||
_bitmap = _gfx->createBitmap(_surface);
|
||||
_bitmap->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
||||
|
||||
_originalWidth = _surface->w;
|
||||
_originalHeight = _surface->h;
|
||||
}
|
||||
|
||||
void VisualImageXMG::readOriginalSize(Common::ReadStream *stream) {
|
||||
Formats::XMGDecoder::readSize(stream, _originalWidth, _originalHeight);
|
||||
}
|
||||
|
||||
bool VisualImageXMG::loadPNG(Common::SeekableReadStream *stream) {
|
||||
assert(!_surface && !_bitmap);
|
||||
|
||||
// Decode the XMG
|
||||
Image::PNGDecoder pngDecoder;
|
||||
if (!pngDecoder.loadStream(*stream)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pngDecoder.hasPalette()) {
|
||||
warning("Indexed colors PNG images are not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (StarkSettings->shouldPreMultiplyReplacementPNGs()) {
|
||||
// We can do alpha pre-multiplication when loading for
|
||||
// convenience when testing modded graphics.
|
||||
_surface = multiplyColorWithAlpha(pngDecoder.getSurface());
|
||||
} else {
|
||||
_surface = pngDecoder.getSurface()->convertTo(Gfx::Driver::getRGBAPixelFormat());
|
||||
}
|
||||
|
||||
_bitmap = _gfx->createBitmap(_surface);
|
||||
_bitmap->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Graphics::Surface *VisualImageXMG::multiplyColorWithAlpha(const Graphics::Surface *source) {
|
||||
assert(source->format == Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
Graphics::Surface *dest = new Graphics::Surface();
|
||||
dest->create(source->w, source->h, Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
for (int y = 0; y < source->h; y++) {
|
||||
const uint8 *src = (const uint8 *) source->getBasePtr(0, y);
|
||||
uint8 *dst = (uint8 *) dest->getBasePtr(0, y);
|
||||
|
||||
for (int x = 0; x < source->w; x++) {
|
||||
uint8 a, r, g, b;
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
a = *src++;
|
||||
|
||||
if (a != 0xFF) {
|
||||
r = (int) r * a / 255;
|
||||
g = (int) g * a / 255;
|
||||
b = (int) b * a / 255;
|
||||
}
|
||||
|
||||
*dst++ = r;
|
||||
*dst++ = g;
|
||||
*dst++ = b;
|
||||
*dst++ = a;
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void VisualImageXMG::render(const Common::Point &position, bool useOffset) {
|
||||
render(position, useOffset, true);
|
||||
}
|
||||
|
||||
void VisualImageXMG::render(const Common::Point &position, bool useOffset, bool unscaled) {
|
||||
Common::Point drawPos = useOffset ? position - _hotspot : position;
|
||||
|
||||
if (!unscaled) {
|
||||
uint width = _gfx->scaleWidthOriginalToCurrent(_originalWidth);
|
||||
uint height = _gfx->scaleHeightOriginalToCurrent(_originalHeight);
|
||||
_surfaceRenderer->render(_bitmap, drawPos, width, height);
|
||||
} else {
|
||||
_surfaceRenderer->render(_bitmap, drawPos, _originalWidth, _originalHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualImageXMG::setFadeLevel(float fadeLevel) {
|
||||
_surfaceRenderer->setFadeLevel(fadeLevel);
|
||||
}
|
||||
|
||||
bool VisualImageXMG::isPointSolid(const Common::Point &point) const {
|
||||
assert(_surface);
|
||||
|
||||
if (_originalWidth < 32 || _originalHeight < 32) {
|
||||
return true; // Small images are always solid
|
||||
}
|
||||
|
||||
Common::Point scaledPoint;
|
||||
scaledPoint.x = point.x * _surface->w / _originalWidth;
|
||||
scaledPoint.y = point.y * _surface->h / _originalHeight;
|
||||
scaledPoint.x = CLIP<uint16>(scaledPoint.x, 0, _surface->w);
|
||||
scaledPoint.y = CLIP<uint16>(scaledPoint.y, 0, _surface->h);
|
||||
|
||||
// Maybe implement this method in some other way to avoid having to keep the surface in memory
|
||||
const byte *ptr = (const byte *) _surface->getBasePtr(scaledPoint.x, scaledPoint.y);
|
||||
return *(ptr + 3) == 0xFF;
|
||||
}
|
||||
|
||||
int VisualImageXMG::getWidth() const {
|
||||
return _originalWidth;
|
||||
}
|
||||
|
||||
int VisualImageXMG::getHeight() const {
|
||||
return _originalHeight;
|
||||
}
|
||||
|
||||
const Graphics::Surface *VisualImageXMG::getSurface() const {
|
||||
assert(_surface);
|
||||
return _surface;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
107
engines/stark/visual/image.h
Normal file
107
engines/stark/visual/image.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/* 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_IMAGE_H
|
||||
#define STARK_VISUAL_IMAGE_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "common/rect.h"
|
||||
#include "common/stream.h"
|
||||
|
||||
namespace Graphics {
|
||||
struct Surface;
|
||||
}
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
class Bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* XMG (still image) renderer
|
||||
*/
|
||||
class VisualImageXMG : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kImageXMG;
|
||||
|
||||
explicit VisualImageXMG(Gfx::Driver *gfx);
|
||||
~VisualImageXMG() override;
|
||||
|
||||
/**
|
||||
* Load the pixel data from a XMG image
|
||||
*/
|
||||
void load(Common::ReadStream *stream);
|
||||
|
||||
/**
|
||||
* Load the size from an XMG image
|
||||
*/
|
||||
void readOriginalSize(Common::ReadStream *stream);
|
||||
|
||||
/**
|
||||
* Load the pixel data from a PNG image
|
||||
*/
|
||||
bool loadPNG(Common::SeekableReadStream *stream);
|
||||
|
||||
void render(const Common::Point &position, bool useOffset);
|
||||
void render(const Common::Point &position, bool useOffset, bool unscaled);
|
||||
|
||||
/** Set an offset used when rendering */
|
||||
void setHotSpot(const Common::Point &hotspot);
|
||||
Common::Point getHotspot() const { return _hotspot; }
|
||||
|
||||
/**
|
||||
* The fade level is added to the color value of each pixel
|
||||
*
|
||||
* It is a value between -1 and 1
|
||||
*/
|
||||
void setFadeLevel(float fadeLevel);
|
||||
|
||||
/** Perform a transparency hit test on an image point */
|
||||
bool isPointSolid(const Common::Point &point) const;
|
||||
|
||||
/** Get the width in pixels */
|
||||
int getWidth() const;
|
||||
|
||||
/** Get the height in pixels */
|
||||
int getHeight() const;
|
||||
|
||||
/** Get a read only pointer to the surface backing the image */
|
||||
const Graphics::Surface *getSurface() const;
|
||||
|
||||
private:
|
||||
Graphics::Surface *multiplyColorWithAlpha(const Graphics::Surface *source);
|
||||
|
||||
Gfx::Driver *_gfx;
|
||||
Gfx::SurfaceRenderer *_surfaceRenderer;
|
||||
Gfx::Bitmap *_bitmap;
|
||||
Graphics::Surface *_surface;
|
||||
Common::Point _hotspot;
|
||||
uint _originalWidth;
|
||||
uint _originalHeight;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_IMAGE_H
|
||||
84
engines/stark/visual/prop.cpp
Normal file
84
engines/stark/visual/prop.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/* 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/prop.h"
|
||||
|
||||
#include "engines/stark/formats/biffmesh.h"
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualProp::VisualProp() :
|
||||
Visual(TYPE),
|
||||
_model(nullptr),
|
||||
_texture(nullptr) {
|
||||
}
|
||||
|
||||
VisualProp::~VisualProp() {
|
||||
delete _model;
|
||||
delete _texture;
|
||||
}
|
||||
|
||||
void VisualProp::setModel(Formats::BiffMesh *model) {
|
||||
assert(!_model);
|
||||
|
||||
_model = model;
|
||||
|
||||
const Common::Array<Formats::BiffMesh::Vertex> &vertices = _model->getVertices();
|
||||
for (uint i = 0; i < vertices.size(); i++) {
|
||||
_boundingBox.expand(vertices[i].position);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualProp::setTexture(Gfx::TextureSet *texture) {
|
||||
assert(!_texture);
|
||||
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
Math::Matrix4 VisualProp::getModelMatrix(const Math::Vector3d& position, float direction) {
|
||||
Math::Matrix4 posMatrix;
|
||||
posMatrix.setPosition(position);
|
||||
|
||||
Math::Matrix4 rot1;
|
||||
rot1.buildAroundX(90);
|
||||
|
||||
Math::Matrix4 rot2;
|
||||
rot2.buildAroundY(270 - direction);
|
||||
|
||||
Math::Matrix4 modelTransform = _model->getTransform();
|
||||
|
||||
return posMatrix * rot1 * rot2 * modelTransform;
|
||||
}
|
||||
|
||||
bool VisualProp::intersectRay(const Math::Ray &ray, const Math::Vector3d &position, float direction) {
|
||||
Math::Matrix4 inverseModelMatrix = getModelMatrix(position, direction);
|
||||
inverseModelMatrix.inverse();
|
||||
|
||||
// Build an object local ray from the world ray
|
||||
Math::Ray localRay = ray;
|
||||
localRay.transform(inverseModelMatrix);
|
||||
|
||||
return localRay.intersectAABB(_boundingBox);
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
65
engines/stark/visual/prop.h
Normal file
65
engines/stark/visual/prop.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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_PROP_H
|
||||
#define STARK_VISUAL_PROP_H
|
||||
|
||||
#include "math/matrix4.h"
|
||||
#include "math/ray.h"
|
||||
#include "math/vector3d.h"
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
#include "engines/stark/gfx/renderentry.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Formats {
|
||||
class BiffMesh;
|
||||
}
|
||||
|
||||
namespace Gfx {
|
||||
class TextureSet;
|
||||
}
|
||||
|
||||
class VisualProp : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kRendered;
|
||||
|
||||
VisualProp();
|
||||
~VisualProp() override;
|
||||
|
||||
void setModel(Formats::BiffMesh *model);
|
||||
void setTexture(Gfx::TextureSet *texture);
|
||||
|
||||
bool intersectRay(const Math::Ray &ray, const Math::Vector3d &position, float direction);
|
||||
virtual void render(const Math::Vector3d &position, float direction, const Gfx::LightEntryArray &lights) = 0;
|
||||
|
||||
protected:
|
||||
Formats::BiffMesh *_model;
|
||||
Gfx::TextureSet *_texture;
|
||||
Math::AABB _boundingBox;
|
||||
|
||||
Math::Matrix4 getModelMatrix(const Math::Vector3d& position, float direction);
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_PROP_H
|
||||
237
engines/stark/visual/smacker.cpp
Normal file
237
engines/stark/visual/smacker.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
/* 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/smacker.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/surfacerenderer.h"
|
||||
#include "engines/stark/gfx/bitmap.h"
|
||||
#include "engines/stark/scene.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/services/settings.h"
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/archive.h"
|
||||
|
||||
#include "video/bink_decoder.h"
|
||||
#include "video/smk_decoder.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualSmacker::VisualSmacker(Gfx::Driver *gfx) :
|
||||
Visual(TYPE),
|
||||
_gfx(gfx),
|
||||
_surface(nullptr),
|
||||
_bitmap(nullptr),
|
||||
_decoder(nullptr),
|
||||
_position(0, 0),
|
||||
_originalWidth(0),
|
||||
_originalHeight(0),
|
||||
_overridenFramerate(-1) {
|
||||
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
||||
}
|
||||
|
||||
VisualSmacker::~VisualSmacker() {
|
||||
delete _bitmap;
|
||||
delete _decoder;
|
||||
delete _surfaceRenderer;
|
||||
}
|
||||
|
||||
void VisualSmacker::loadSmacker(Common::SeekableReadStream *stream) {
|
||||
delete _bitmap;
|
||||
delete _decoder;
|
||||
|
||||
_decoder = new Video::SmackerDecoder();
|
||||
_decoder->setSoundType(Audio::Mixer::kSFXSoundType);
|
||||
_decoder->loadStream(stream);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void VisualSmacker::loadBink(Common::SeekableReadStream *stream) {
|
||||
delete _bitmap;
|
||||
delete _decoder;
|
||||
|
||||
_decoder = new Video::BinkDecoder();
|
||||
_decoder->setSoundType(Audio::Mixer::kSFXSoundType);
|
||||
_decoder->loadStream(stream);
|
||||
// We need a format with alpha transparency, so we can't use _bitmap->getBestPixelFormat() here.
|
||||
_decoder->setOutputPixelFormat(Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void VisualSmacker::init() {
|
||||
_originalWidth = _decoder->getWidth();
|
||||
_originalHeight = _decoder->getHeight();
|
||||
|
||||
rewind();
|
||||
|
||||
_bitmap = _gfx->createBitmap();
|
||||
_bitmap->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void VisualSmacker::readOriginalSize(Common::SeekableReadStream *stream) {
|
||||
Video::SmackerDecoder smacker;
|
||||
smacker.loadStream(stream);
|
||||
|
||||
_originalWidth = smacker.getWidth();
|
||||
_originalHeight = smacker.getHeight();
|
||||
}
|
||||
|
||||
void VisualSmacker::render(const Common::Point &position) {
|
||||
assert(_decoder->getCurFrame() >= 0);
|
||||
|
||||
// The position argument contains the scroll offset
|
||||
_surfaceRenderer->render(_bitmap, _position - position, _originalWidth, _originalHeight);
|
||||
}
|
||||
|
||||
void VisualSmacker::update() {
|
||||
if (_decoder->needsUpdate()) {
|
||||
_surface = _decoder->decodeNextFrame();
|
||||
const byte *palette = _decoder->getPalette();
|
||||
|
||||
if (palette) {
|
||||
// Convert the surface to RGBA
|
||||
Graphics::Surface convertedSurface;
|
||||
convertedSurface.create(_surface->w, _surface->h, Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
for (int y = 0; y < _surface->h; y++) {
|
||||
const byte *srcRow = (const byte *)_surface->getBasePtr(0, y);
|
||||
byte *dstRow = (byte *)convertedSurface.getBasePtr(0, y);
|
||||
|
||||
for (int x = 0; x < _surface->w; x++) {
|
||||
byte index = *srcRow++;
|
||||
|
||||
byte r = palette[index * 3];
|
||||
byte g = palette[index * 3 + 1];
|
||||
byte b = palette[index * 3 + 2];
|
||||
|
||||
if (r != 0 || g != 255 || b != 255) {
|
||||
*dstRow++ = r;
|
||||
*dstRow++ = g;
|
||||
*dstRow++ = b;
|
||||
*dstRow++ = 0xFF;
|
||||
} else {
|
||||
// Cyan is the transparent color
|
||||
*dstRow++ = 0;
|
||||
*dstRow++ = 0;
|
||||
*dstRow++ = 0;
|
||||
*dstRow++ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_bitmap->update(&convertedSurface);
|
||||
|
||||
convertedSurface.free();
|
||||
} else {
|
||||
_bitmap->update(_surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool VisualSmacker::isPointSolid(const Common::Point &point) const {
|
||||
if (!_decoder || !_surface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Common::Point scaledPoint;
|
||||
scaledPoint.x = point.x * _surface->w / _originalWidth;
|
||||
scaledPoint.y = point.y * _surface->h / _originalHeight;
|
||||
scaledPoint.x = CLIP<uint16>(scaledPoint.x, 0, _surface->w);
|
||||
scaledPoint.y = CLIP<uint16>(scaledPoint.y, 0, _surface->h);
|
||||
|
||||
const byte *ptr = (const byte *)_surface->getBasePtr(scaledPoint.x, scaledPoint.y);
|
||||
const byte *palette = _decoder->getPalette();
|
||||
if (palette) {
|
||||
byte r = palette[*ptr * 3];
|
||||
byte g = palette[*ptr * 3 + 1];
|
||||
byte b = palette[*ptr * 3 + 2];
|
||||
|
||||
// Cyan is the transparent color
|
||||
return r != 0x00 || g != 0xFF || b != 0xFF;
|
||||
} else {
|
||||
// Maybe implement this method in some other way to avoid having to keep the surface in memory
|
||||
return *(ptr + 3) == 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
int VisualSmacker::getFrameNumber() const {
|
||||
if (_decoder && _decoder->isPlaying()) {
|
||||
return _decoder->getCurFrame();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool VisualSmacker::isDone() {
|
||||
return getCurrentTime() >= getDuration();
|
||||
}
|
||||
|
||||
int VisualSmacker::getWidth() const {
|
||||
return _originalWidth;
|
||||
}
|
||||
|
||||
int VisualSmacker::getHeight() const {
|
||||
return _originalHeight;
|
||||
}
|
||||
|
||||
uint32 VisualSmacker::getDuration() const {
|
||||
return (_decoder->getRate().getInverse() * _decoder->getDuration().msecs()).toInt();
|
||||
}
|
||||
|
||||
void VisualSmacker::rewind() {
|
||||
_decoder->rewind();
|
||||
_decoder->start();
|
||||
|
||||
if (_overridenFramerate != -1) {
|
||||
Common::Rational originalFrameRate;
|
||||
|
||||
Video::SmackerDecoder *smacker = dynamic_cast<Video::SmackerDecoder *>(_decoder);
|
||||
if (smacker) {
|
||||
originalFrameRate = smacker->getFrameRate();
|
||||
}
|
||||
|
||||
Video::BinkDecoder *bink = dynamic_cast<Video::BinkDecoder *>(_decoder);
|
||||
if (bink) {
|
||||
originalFrameRate = bink->getFrameRate();
|
||||
}
|
||||
|
||||
Common::Rational playbackRate = _overridenFramerate / originalFrameRate;
|
||||
_decoder->setRate(playbackRate);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 VisualSmacker::getCurrentTime() const {
|
||||
return (_decoder->getRate().getInverse() * _decoder->getTime()).toInt();
|
||||
}
|
||||
|
||||
void VisualSmacker::overrideFrameRate(int32 framerate) {
|
||||
_overridenFramerate = framerate;
|
||||
}
|
||||
|
||||
void VisualSmacker::pause(bool pause) {
|
||||
_decoder->pauseVideo(pause);
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
106
engines/stark/visual/smacker.h
Normal file
106
engines/stark/visual/smacker.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* 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_SMACKER_H
|
||||
#define STARK_VISUAL_SMACKER_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "common/rect.h"
|
||||
#include "common/stream.h"
|
||||
|
||||
namespace Video {
|
||||
class VideoDecoder;
|
||||
}
|
||||
|
||||
namespace Graphics {
|
||||
struct Surface;
|
||||
}
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
class Bitmap;
|
||||
}
|
||||
|
||||
class VisualSmacker : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kSmackerStream;
|
||||
|
||||
VisualSmacker(Gfx::Driver *gfx);
|
||||
virtual ~VisualSmacker();
|
||||
|
||||
void loadSmacker(Common::SeekableReadStream *stream);
|
||||
void loadBink(Common::SeekableReadStream *stream);
|
||||
void update();
|
||||
void render(const Common::Point &position);
|
||||
bool isDone();
|
||||
|
||||
/** Reset the video to resume playing from the beginning */
|
||||
void rewind();
|
||||
|
||||
/** Perform a transparency hit test on a point */
|
||||
bool isPointSolid(const Common::Point &point) const;
|
||||
|
||||
/**
|
||||
* Load the size from a Smacker video
|
||||
*/
|
||||
void readOriginalSize(Common::SeekableReadStream *stream);
|
||||
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
|
||||
int getFrameNumber() const;
|
||||
Common::Point getPosition() const { return _position; }
|
||||
void setPosition(const Common::Point &pos) { _position = pos; }
|
||||
|
||||
/** Get the total duration in milliseconds for the video */
|
||||
uint32 getDuration() const;
|
||||
|
||||
/** Get the current time in the video since the beginning */
|
||||
uint32 getCurrentTime() const;
|
||||
|
||||
void overrideFrameRate(int32 framerate);
|
||||
|
||||
/** Pause or resume the video */
|
||||
void pause(bool pause);
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
Video::VideoDecoder *_decoder;
|
||||
const Graphics::Surface *_surface;
|
||||
|
||||
Common::Point _position;
|
||||
int32 _originalWidth;
|
||||
int32 _originalHeight;
|
||||
|
||||
Gfx::Driver *_gfx;
|
||||
Gfx::SurfaceRenderer *_surfaceRenderer;
|
||||
Gfx::Bitmap *_bitmap;
|
||||
int32 _overridenFramerate;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_SMACKER_H
|
||||
336
engines/stark/visual/text.cpp
Normal file
336
engines/stark/visual/text.cpp
Normal file
@@ -0,0 +1,336 @@
|
||||
/* 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/text.h"
|
||||
|
||||
#include "graphics/font.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
#include "engines/stark/debug.h"
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/surfacerenderer.h"
|
||||
#include "engines/stark/gfx/bitmap.h"
|
||||
#include "engines/stark/scene.h"
|
||||
#include "engines/stark/services/services.h"
|
||||
#include "engines/stark/services/settings.h"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/unicode-bidi.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
VisualText::VisualText(Gfx::Driver *gfx) :
|
||||
Visual(TYPE),
|
||||
_gfx(gfx),
|
||||
_bitmap(nullptr),
|
||||
_color(Gfx::Color(0, 0, 0)),
|
||||
_backgroundColor(Gfx::Color(0, 0, 0, 0)),
|
||||
_align(Graphics::kTextAlignLeft),
|
||||
_targetWidth(600),
|
||||
_targetHeight(600),
|
||||
_fontType(FontProvider::kBigFont),
|
||||
_fontCustomIndex(-1) {
|
||||
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
||||
_surfaceRenderer->setNoScalingOverride(true);
|
||||
_surfaceRenderer->setSnapToGrid(true);
|
||||
}
|
||||
|
||||
VisualText::~VisualText() {
|
||||
freeBitmap();
|
||||
delete _surfaceRenderer;
|
||||
}
|
||||
|
||||
Common::Rect VisualText::getRect() {
|
||||
if (!_bitmap) {
|
||||
createBitmap();
|
||||
}
|
||||
return _originalRect;
|
||||
}
|
||||
|
||||
void VisualText::setText(const Common::String &text) {
|
||||
if (_text != text) {
|
||||
freeBitmap();
|
||||
_text = text;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualText::setColor(const Gfx::Color &color) {
|
||||
if (_color == color) {
|
||||
return;
|
||||
}
|
||||
|
||||
freeBitmap();
|
||||
_color = color;
|
||||
}
|
||||
|
||||
void VisualText::setBackgroundColor(const Gfx::Color &color) {
|
||||
if (color == _backgroundColor) {
|
||||
return;
|
||||
}
|
||||
|
||||
freeBitmap();
|
||||
_backgroundColor = color;
|
||||
}
|
||||
|
||||
void VisualText::setAlign(Graphics::TextAlign align) {
|
||||
if (align != _align) {
|
||||
freeBitmap();
|
||||
_align = align;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualText::setTargetWidth(uint32 width) {
|
||||
if (width != _targetWidth) {
|
||||
freeBitmap();
|
||||
_targetWidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualText::setTargetHeight(uint32 height) {
|
||||
if (height != _targetHeight) {
|
||||
freeBitmap();
|
||||
_targetHeight = height;
|
||||
}
|
||||
}
|
||||
|
||||
void VisualText::setFont(FontProvider::FontType type, int32 customFontIndex) {
|
||||
if (type != _fontType || customFontIndex != _fontCustomIndex) {
|
||||
freeBitmap();
|
||||
_fontType = type;
|
||||
_fontCustomIndex = customFontIndex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a color component from the perceptual to the linear color space
|
||||
*
|
||||
* Gamma 1.8 seems to be an accepted value in the font rendering domain.
|
||||
*/
|
||||
static float srgbToLinear(float x) {
|
||||
if (x <= 0.0f)
|
||||
return 0.0f;
|
||||
else if (x >= 1.0f)
|
||||
return 1.0f;
|
||||
else
|
||||
return powf(x, 1.8f);
|
||||
}
|
||||
|
||||
/** Convert a color component from the linear to the perceptual color space */
|
||||
static float linearToSrgb(float x) {
|
||||
if (x <= 0.0f)
|
||||
return 0.0f;
|
||||
else if (x >= 1.0f)
|
||||
return 1.0f;
|
||||
else
|
||||
return powf(x, 1.0f / 1.8f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the color components of a surface with the alpha component
|
||||
*
|
||||
* Linear colorspace aware variant. Anti-aliased fonts at small sized
|
||||
* have a very few solid pixels. It's important the semi-transparent
|
||||
* pixels have the right value after the pre-multiplication.
|
||||
*/
|
||||
static void multiplyColorWithAlpha(Graphics::Surface *source) {
|
||||
assert(source->format == Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
for (int y = 0; y < source->h; y++) {
|
||||
const uint8 *src = (const uint8 *) source->getBasePtr(0, y);
|
||||
uint8 *dst = (uint8 *) source->getBasePtr(0, y);
|
||||
|
||||
for (int x = 0; x < source->w; x++) {
|
||||
uint8 a, r, g, b;
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
a = *src++;
|
||||
|
||||
if (a == 0) {
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
|
||||
} else if (a != 0xFF) {
|
||||
float aFloat = a / 255.f;
|
||||
float linearR = srgbToLinear(r / 255.f);
|
||||
float linearG = srgbToLinear(g / 255.f);
|
||||
float linearB = srgbToLinear(b / 255.f);
|
||||
|
||||
linearR *= aFloat;
|
||||
linearG *= aFloat;
|
||||
linearB *= aFloat;
|
||||
|
||||
r = linearToSrgb(linearR) * 255.f;
|
||||
g = linearToSrgb(linearG) * 255.f;
|
||||
b = linearToSrgb(linearB) * 255.f;
|
||||
}
|
||||
|
||||
*dst++ = r;
|
||||
*dst++ = g;
|
||||
*dst++ = b;
|
||||
*dst++ = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blend a grayscale surface with a color
|
||||
*
|
||||
* Color space aware version.
|
||||
*/
|
||||
static void blendWithColor(Graphics::Surface *source, const Gfx::Color &color) {
|
||||
assert(source->format == Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
float sRL = srgbToLinear(color.r / 255.f);
|
||||
float sGL = srgbToLinear(color.g / 255.f);
|
||||
float sBL = srgbToLinear(color.b / 255.f);
|
||||
|
||||
for (int y = 0; y < source->h; y++) {
|
||||
const uint8 *src = (const uint8 *) source->getBasePtr(0, y);
|
||||
uint8 *dst = (uint8 *) source->getBasePtr(0, y);
|
||||
|
||||
for (int x = 0; x < source->w; x++) {
|
||||
uint8 a, r, g, b;
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
src++;
|
||||
|
||||
a = r;
|
||||
if (a != 255) {
|
||||
float aFloat = a / 255.f;
|
||||
r = linearToSrgb(sRL * aFloat) * 255.f;
|
||||
g = linearToSrgb(sGL * aFloat) * 255.f;
|
||||
b = linearToSrgb(sBL * aFloat) * 255.f;
|
||||
|
||||
} else {
|
||||
r = color.r;
|
||||
g = color.g;
|
||||
b = color.b;
|
||||
}
|
||||
|
||||
*dst++ = r;
|
||||
*dst++ = g;
|
||||
*dst++ = b;
|
||||
*dst++ = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VisualText::createBitmap() {
|
||||
Common::CodePage codePage = StarkSettings->getTextCodePage();
|
||||
Common::U32String unicodeText = Common::convertToU32String(_text.c_str(), codePage);
|
||||
|
||||
// Get the font and required metrics
|
||||
const Graphics::Font *font = StarkFontProvider->getScaledFont(_fontType, _fontCustomIndex);
|
||||
uint scaledLineHeight = StarkFontProvider->getScaledFontHeight(_fontType, _fontCustomIndex);
|
||||
uint originalLineHeight = StarkFontProvider->getOriginalFontHeight(_fontType, _fontCustomIndex);
|
||||
uint maxScaledLineWidth = StarkGfx->scaleWidthOriginalToCurrent(_targetWidth);
|
||||
|
||||
// Word wrap the text
|
||||
Common::Array<Common::U32String> lines;
|
||||
font->wordWrapText(unicodeText, maxScaledLineWidth, lines);
|
||||
|
||||
// Use the actual font bounding box to prevent text from being cut off
|
||||
Common::Rect scaledRect;
|
||||
if (!lines.empty()) {
|
||||
scaledRect = font->getBoundingBox(lines[0]);
|
||||
for (uint i = 1; i < lines.size(); i++) {
|
||||
scaledRect.extend(font->getBoundingBox(lines[i], 0, scaledLineHeight * i));
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure lines have approximately consistent height regardless of the characters they use
|
||||
scaledRect.bottom = MAX<int16>(scaledRect.bottom, scaledLineHeight * lines.size());
|
||||
scaledRect.right = MAX<int16>(scaledRect.right, maxScaledLineWidth);
|
||||
|
||||
if (!isBlank()) {
|
||||
_originalRect.right = StarkGfx->scaleWidthCurrentToOriginal(scaledRect.right);
|
||||
_originalRect.bottom = originalLineHeight * lines.size();
|
||||
} else {
|
||||
// For Empty text, preserve the original width and height for being used as clicking area
|
||||
_originalRect.right = _targetWidth;
|
||||
_originalRect.bottom = _targetHeight;
|
||||
}
|
||||
|
||||
// Create a surface to render to
|
||||
Graphics::Surface surface;
|
||||
surface.create(scaledRect.right, scaledRect.bottom, Gfx::Driver::getRGBAPixelFormat());
|
||||
|
||||
// First render the text as white on a black background to produce an alpha mask
|
||||
uint32 black = surface.format.ARGBToColor(0xFF, 0, 0, 0);
|
||||
uint32 white = surface.format.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
|
||||
surface.fillRect(Common::Rect(surface.w, surface.h), black);
|
||||
|
||||
Graphics::TextAlign align = Graphics::convertTextAlignH(_align, StarkSettings->getLanguage() == Common::HE_ISR);
|
||||
|
||||
// Render the lines to the surface
|
||||
for (uint i = 0; i < lines.size(); i++) {
|
||||
Common::U32String line = convertBiDiU32String(lines[i]).visual;
|
||||
font->drawString(&surface, line, 0, scaledLineHeight * i, surface.w, white, align, 0, false);
|
||||
}
|
||||
|
||||
// Blend the text color with the alpha mask to produce an image of the text
|
||||
// of the correct color. Anti-aliased pixels use the full alpha range.
|
||||
blendWithColor(&surface, _color);
|
||||
multiplyColorWithAlpha(&surface);
|
||||
|
||||
// Create a bitmap from the surface
|
||||
_bitmap = _gfx->createBitmap(&surface);
|
||||
_bitmap->setSamplingFilter(Gfx::Bitmap::kNearest);
|
||||
|
||||
surface.free();
|
||||
}
|
||||
|
||||
void VisualText::freeBitmap() {
|
||||
delete _bitmap;
|
||||
_bitmap = nullptr;
|
||||
}
|
||||
|
||||
void VisualText::render(const Common::Point &position) {
|
||||
if (!_bitmap) {
|
||||
createBitmap();
|
||||
}
|
||||
|
||||
if (_backgroundColor.a != 0) {
|
||||
_surfaceRenderer->fill(_backgroundColor, position, _bitmap->width(), _bitmap->height());
|
||||
}
|
||||
|
||||
_surfaceRenderer->render(_bitmap, position);
|
||||
}
|
||||
|
||||
void VisualText::reset() {
|
||||
freeBitmap();
|
||||
}
|
||||
|
||||
bool VisualText::isBlank() {
|
||||
for (uint i = 0; i < _text.size(); ++i) {
|
||||
if (!Common::isSpace(_text[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
92
engines/stark/visual/text.h
Normal file
92
engines/stark/visual/text.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 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_TEXT_H
|
||||
#define STARK_VISUAL_TEXT_H
|
||||
|
||||
#include "engines/stark/visual/visual.h"
|
||||
|
||||
#include "engines/stark/services/fontprovider.h"
|
||||
#include "engines/stark/gfx/color.h"
|
||||
|
||||
#include "common/rect.h"
|
||||
#include "graphics/font.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class SurfaceRenderer;
|
||||
class Bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text renderer
|
||||
*/
|
||||
class VisualText : public Visual {
|
||||
public:
|
||||
static const VisualType TYPE = Visual::kImageText;
|
||||
|
||||
explicit VisualText(Gfx::Driver *gfx);
|
||||
~VisualText() override;
|
||||
|
||||
Common::Rect getRect();
|
||||
|
||||
void setText(const Common::String &text);
|
||||
void setColor(const Gfx::Color &color);
|
||||
void setBackgroundColor(const Gfx::Color &color);
|
||||
void setAlign(Graphics::TextAlign align);
|
||||
void setTargetWidth(uint32 width);
|
||||
void setTargetHeight(uint32 height);
|
||||
void setFont(FontProvider::FontType type, int32 customFontIndex = -1);
|
||||
|
||||
uint getTargetWidth() { return _targetWidth; }
|
||||
uint getTargetHeight() { return _targetHeight; }
|
||||
|
||||
void render(const Common::Point &position);
|
||||
void reset();
|
||||
|
||||
private:
|
||||
void createBitmap();
|
||||
void freeBitmap();
|
||||
|
||||
/** Check whether the text is blank */
|
||||
bool isBlank();
|
||||
|
||||
Gfx::Driver *_gfx;
|
||||
Gfx::SurfaceRenderer *_surfaceRenderer;
|
||||
Gfx::Bitmap *_bitmap;
|
||||
|
||||
Common::String _text;
|
||||
Gfx::Color _color;
|
||||
Gfx::Color _backgroundColor;
|
||||
Graphics::TextAlign _align;
|
||||
uint32 _targetWidth;
|
||||
uint32 _targetHeight;
|
||||
Common::Rect _originalRect;
|
||||
|
||||
FontProvider::FontType _fontType;
|
||||
int32 _fontCustomIndex;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_TEXT_H
|
||||
69
engines/stark/visual/visual.h
Normal file
69
engines/stark/visual/visual.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* 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_VISUAL_H
|
||||
#define STARK_VISUAL_VISUAL_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
class Visual {
|
||||
public:
|
||||
enum VisualType {
|
||||
kImageXMG = 2,
|
||||
kRendered = 3,
|
||||
kImageText = 4,
|
||||
kSmackerStream = 5,
|
||||
kActor = 6,
|
||||
kSmackerFMV = 7,
|
||||
kEffectFish = 8,
|
||||
kEffectBubbles = 9,
|
||||
kEffectFirefly = 10,
|
||||
kExplodingImage = 100,
|
||||
kFlashingImage = 101
|
||||
};
|
||||
|
||||
explicit Visual(VisualType type) : _type(type) {}
|
||||
virtual ~Visual() {}
|
||||
|
||||
/**
|
||||
* Returns the visual if it has the same type as the template argument
|
||||
*/
|
||||
template <class T>
|
||||
T *get();
|
||||
|
||||
private:
|
||||
VisualType _type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T *Visual::get() {
|
||||
if (_type != T::TYPE) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (T *) this;
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_VISUAL_VISUAL_H
|
||||
Reference in New Issue
Block a user