aboutsummaryrefslogtreecommitdiff
path: root/engines/draci
diff options
context:
space:
mode:
authorDenis Kasak2009-07-22 04:42:33 +0000
committerDenis Kasak2009-07-22 04:42:33 +0000
commitb3a2d186bbca722b0cc172f07222e782e79b96c1 (patch)
tree44a7118f52a60b51a86e5b09f3c223eccf1be1ac /engines/draci
parent6097828f546fd6f135bc907d6cd0586bb473d9b5 (diff)
downloadscummvm-rg350-b3a2d186bbca722b0cc172f07222e782e79b96c1.tar.gz
scummvm-rg350-b3a2d186bbca722b0cc172f07222e782e79b96c1.tar.bz2
scummvm-rg350-b3a2d186bbca722b0cc172f07222e782e79b96c1.zip
* Moved scaling support from Animation to Sprite
* Now each Sprite (and hence frame in an animation) can have a separate zoom (which is needed for some animations in the game) * Scale factors are not stored any more; instead, we only store scaled dimensions (since these are stored in the data files) and calculate the factors from those. svn-id: r42647
Diffstat (limited to 'engines/draci')
-rw-r--r--engines/draci/animation.cpp69
-rw-r--r--engines/draci/animation.h8
-rw-r--r--engines/draci/game.cpp31
-rw-r--r--engines/draci/sprite.cpp39
-rw-r--r--engines/draci/sprite.h32
5 files changed, 74 insertions, 105 deletions
diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp
index 3faa85ac63..5b1814f4c4 100644
--- a/engines/draci/animation.cpp
+++ b/engines/draci/animation.cpp
@@ -33,8 +33,6 @@ Animation::Animation(DraciEngine *vm) : _vm(vm) {
_z = 0;
_relX = 0;
_relY = 0;
- _scaleX = 1.0;
- _scaleY = 1.0;
setPlaying(false);
_looping = false;
_tick = _vm->_system->getMillis();
@@ -54,12 +52,7 @@ void Animation::setRelative(int relx, int rely) {
// Delete the previous frame
Common::Rect frameRect;
- if (isScaled()) {
- frameRect = getFrame()->getScaledRect(_scaleX, _scaleY);
- } else {
- frameRect = getFrame()->getRect();
- }
-
+ frameRect = getFrame()->getRect();
frameRect.translate(_relX, _relY);
_vm->_screen->getSurface()->markDirtyRect(frameRect);
@@ -67,24 +60,6 @@ void Animation::setRelative(int relx, int rely) {
_relY = rely;
}
-void Animation::setScaling(double scalex, double scaley) {
-
- _scaleX = scalex;
- _scaleY = scaley;
-}
-
-bool Animation::isScaled() const {
- return !(_scaleX == 1.0 && _scaleY == 1.0);
-}
-
-double Animation::getScaleX() const {
- return _scaleX;
-}
-
-double Animation::getScaleY() const {
- return _scaleY;
-}
-
void Animation::setLooping(bool looping) {
_looping = looping;
debugC(7, kDraciAnimationDebugLevel, "Setting looping to %d on animation %d",
@@ -100,12 +75,7 @@ void Animation::nextFrame(bool force) {
Drawable *frame = _frames[_currentFrame];
Common::Rect frameRect;
-
- if (isScaled()) {
- frameRect = frame->getScaledRect(_scaleX, _scaleY);
- } else {
- frameRect = frame->getRect();
- }
+ frameRect = frame->getRect();
// Translate rectangle to compensate for relative coordinates
frameRect.translate(_relX, _relY);
@@ -124,9 +94,9 @@ void Animation::nextFrame(bool force) {
}
debugC(6, kDraciAnimationDebugLevel,
- "anim=%d tick=%d delay=%d tick+delay=%d currenttime=%d frame=%d framenum=%d",
+ "anim=%d tick=%d delay=%d tick+delay=%d currenttime=%d frame=%d framenum=%d x=%d y=%d",
_id, _tick, frame->getDelay(), _tick + frame->getDelay(), _vm->_system->getMillis(),
- _currentFrame, _frames.size());
+ _currentFrame, _frames.size(), frame->getX(), frame->getY());
}
uint Animation::nextFrameNum() {
@@ -143,32 +113,29 @@ void Animation::drawFrame(Surface *surface) {
if (_frames.size() == 0 || !_playing)
return;
+ Drawable *frame = _frames[_currentFrame];
+
if (_id == kOverlayImage) {
- _frames[_currentFrame]->drawScaled(surface, _scaleX, _scaleY, false);
- }
- else {
- Drawable *ptr = _frames[_currentFrame];
+ frame->draw(surface, false);
+ } else {
- int x = ptr->getX();
- int y = ptr->getY();
+ int x = frame->getX();
+ int y = frame->getY();
// Take account relative coordinates
int newX = x + _relX;
int newY = y + _relY;
// Translate the frame to those relative coordinates
- ptr->setX(newX);
- ptr->setY(newY);
+ frame->setX(newX);
+ frame->setY(newY);
// Draw frame
- if (isScaled())
- ptr->drawScaled(surface, _scaleX, _scaleY, true);
- else
- ptr->drawScaled(surface, _scaleX, _scaleY, true);
+ frame->drawScaled(surface, true);
// Revert back to old coordinates
- ptr->setX(x);
- ptr->setY(y);
+ frame->setX(x);
+ frame->setY(y);
}
}
@@ -261,11 +228,7 @@ void AnimationManager::stop(int id) {
// Clean up the last frame that was drawn before stopping
Common::Rect frameRect;
- if (anim->isScaled()) {
- frameRect = anim->getFrame()->getScaledRect(anim->getScaleX(), anim->getScaleY());
- } else {
- frameRect = anim->getFrame()->getRect();
- }
+ frameRect = anim->getFrame()->getRect();
frameRect.translate(anim->getRelativeX(), anim->getRelativeY());
_vm->_screen->getSurface()->markDirtyRect(frameRect);
diff --git a/engines/draci/animation.h b/engines/draci/animation.h
index b54b72947d..fa28a61599 100644
--- a/engines/draci/animation.h
+++ b/engines/draci/animation.h
@@ -62,11 +62,6 @@ public:
bool isLooping();
void setLooping(bool looping);
- double getScaleX() const;
- double getScaleY() const;
- void setScaling(double scalex, double scaley);
- bool isScaled() const;
-
void setRelative(int relx, int rely);
int getRelativeX();
int getRelativeY();
@@ -82,9 +77,6 @@ private:
int _relX;
int _relY;
- double _scaleX;
- double _scaleY;
-
uint _tick;
bool _playing;
bool _looping;
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index 318246cc16..561ea78c62 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -176,27 +176,33 @@ void Game::loop() {
int animID = getObject(kDragonObject)->_anims[0];
Animation *anim = _vm->_anims->getAnimation(animID);
- Drawable *frame = anim->getFrame();
- // Calculate scaling factor
+ // Calculate scaling factors
double scaleX = _currentRoom._pers0 + _currentRoom._persStep * y;
double scaleY = scaleX;
- // Calculate scaled height of sprite
- int height = frame->getScaledHeight(scaleY);
+ Drawable *frame;
+
+ // Set the scaled dimensions for all frames
+ for (uint i = 0; i < anim->getFramesNum(); ++i) {
+ frame = anim->getFrame(i);
+
+ // Calculate scaled dimensions
+ uint scaledWidth = scaleX * frame->getWidth();
+ uint scaledHeight = scaleY * frame->getHeight();
+
+ frame->setScaled(scaledWidth, scaledHeight);
+ }
// Set the Z coordinate for the dragon's animation
anim->setZ(y+1);
// We naturally want the dragon to position its feet to the location of the
// click but sprites are drawn from their top-left corner so we subtract
- // the height of the dragon's sprite
- y -= height;
+ // the current height of the dragon's sprite
+ y -= frame->getScaledHeight();
anim->setRelative(x, y);
- // Set the scaling factor
- anim->setScaling(scaleX, scaleY);
-
// Play the animation
_vm->_anims->play(animID);
@@ -238,7 +244,6 @@ void Game::loadRoom(int roomNum) {
for (int i = 5; i >= 0; --i) {
real[i] = roomReader.readByte();
- debug(2, "%d", real[i]);
}
_currentRoom._pers0 = real_to_double(real);
@@ -372,8 +377,8 @@ int Game::loadAnimation(uint animNum, uint z) {
uint spriteNum = animationReader.readUint16LE() - 1;
int x = animationReader.readSint16LE();
int y = animationReader.readSint16LE();
- uint zoomX = animationReader.readUint16LE();
- uint zoomY = animationReader.readUint16LE();
+ uint scaledWidth = animationReader.readUint16LE();
+ uint scaledHeight = animationReader.readUint16LE();
byte mirror = animationReader.readByte();
uint sample = animationReader.readUint16LE();
uint freq = animationReader.readUint16LE();
@@ -383,6 +388,8 @@ int Game::loadAnimation(uint animNum, uint z) {
Sprite *sp = new Sprite(spriteFile->_data, spriteFile->_length, x, y, true);
+ sp->setScaled(scaledWidth, scaledHeight);
+
if (mirror)
sp->setMirrorOn();
diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp
index 9f1cb3371d..23cc386a67 100644
--- a/engines/draci/sprite.cpp
+++ b/engines/draci/sprite.cpp
@@ -61,8 +61,13 @@ Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y,
_width = width;
_height = height;
+
+ _scaledWidth = _width;
+ _scaledHeight = _height;
+
_x = x;
_y = y;
+
_delay = 0;
_mirror = false;
@@ -86,6 +91,7 @@ Sprite::Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise)
_x = x;
_y = y;
+
_delay = 0;
_mirror = false;
@@ -95,6 +101,9 @@ Sprite::Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise)
_width = reader.readSint16LE();
_height = reader.readSint16LE();
+ _scaledWidth = _width;
+ _scaledHeight = _height;
+
_data = new byte[_width * _height];
reader.read(_data, _width * _height);
@@ -118,10 +127,10 @@ void Sprite::setMirrorOff() {
}
// TODO: Research what kind of sampling the original player uses
-void Sprite::drawScaled(Surface *surface, double scaleX, double scaleY, bool markDirty) const {
+void Sprite::drawScaled(Surface *surface, bool markDirty) const {
Common::Rect sourceRect(0, 0, _width, _height);
- Common::Rect destRect(_x, _y, _x + getScaledWidth(scaleX), _y + getScaledHeight(scaleY));
+ Common::Rect destRect(_x, _y, _x + _scaledWidth, _y + _scaledHeight);
Common::Rect surfaceRect(0, 0, surface->w, surface->h);
Common::Rect clippedDestRect(destRect);
@@ -152,6 +161,10 @@ void Sprite::drawScaled(Surface *surface, double scaleX, double scaleY, bool mar
int *rowIndices = new int[rows];
int *columnIndices = new int[columns];
+ // Calculate scaling factors
+ double scaleX = double(_scaledWidth) / _width;
+ double scaleY = double(_scaledHeight) / _height;
+
// Precalculate pixel indexes
for (int i = 0; i < rows; ++i) {
rowIndices[i] = lround(i / scaleY);
@@ -258,20 +271,11 @@ void Sprite::draw(Surface *surface, bool markDirty) const {
}
}
-Common::Rect Sprite::getRect() const {
- return Common::Rect(_x, _y, _x + _width, _y + _height);
-}
-
-Common::Rect Sprite::getScaledRect(double scaleX, double scaleY) const {
- return Common::Rect(_x, _y, _x + getScaledWidth(scaleX), _y + getScaledHeight(scaleY));
-}
-
-uint Sprite::getScaledHeight(double scaleY) const {
- return lround(scaleY * _height);
-}
-
-uint Sprite::getScaledWidth(double scaleX) const {
- return lround(scaleX * _width);
+Common::Rect Sprite::getRect(bool scaled) const {
+ if (scaled)
+ return Common::Rect(_x, _y, _x + _scaledWidth, _y + _scaledHeight);
+ else
+ return Common::Rect(_x, _y, _x + _width, _y + _height);
}
Text::Text(const Common::String &str, Font *font, byte fontColour,
@@ -293,6 +297,9 @@ Text::Text(const Common::String &str, Font *font, byte fontColour,
_width = _font->getStringWidth(str, _spacing);
_height = _font->getFontHeight();
+
+ _scaledWidth = _width;
+ _scaledHeight = _height;
}
Text::~Text() {
diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h
index 88a2858671..717eebaaf0 100644
--- a/engines/draci/sprite.h
+++ b/engines/draci/sprite.h
@@ -38,16 +38,20 @@ friend class Text;
public:
virtual void draw(Surface *surface, bool markDirty = true) const = 0;
- virtual void drawScaled(Surface *surface, double scaleX, double scaleY,
- bool markDirty = true) const = 0;
+ virtual void drawScaled(Surface *surface, bool markDirty = true) const = 0;
virtual ~Drawable() {};
virtual uint16 getWidth() { return _width; }
virtual uint16 getHeight() { return _height; }
- virtual uint getScaledWidth(double scaleX) const = 0;
- virtual uint getScaledHeight(double scaleY) const = 0;
+ virtual uint getScaledWidth() const { return _scaledWidth; }
+ virtual uint getScaledHeight() const { return _scaledHeight; }
+
+ virtual void setScaled(uint width, uint height) {
+ _scaledWidth = width;
+ _scaledHeight = height;
+ }
virtual int getX() { return _x; }
virtual int getY() { return _y; }
@@ -58,13 +62,14 @@ public:
void setDelay(int delay) { _delay = delay; }
int getDelay() { return _delay; }
- virtual Common::Rect getRect() const = 0;
- virtual Common::Rect getScaledRect(double scaleX, double scaleY) const = 0;
+ virtual Common::Rect getRect(bool scaled = true) const = 0;
private:
- uint16 _width; //!< Width of the sprite
- uint16 _height; //!< Height of the sprite
- int _x, _y; //!< Sprite coordinates
+ uint16 _width; //!< Width of the sprite
+ uint16 _height; //!< Height of the sprite
+ uint _scaledWidth; //!< Scaled width of the sprite
+ uint _scaledHeight; //!< Scaled height of the sprite
+ int _x, _y; //!< Sprite coordinates
/** The time a drawable should stay on the screen
* before being replaced by another or deleted
@@ -89,23 +94,18 @@ class Sprite : public Drawable {
public:
Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y, bool columnwise);
-
Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise);
~Sprite();
void draw(Surface *surface, bool markDirty = true) const;
- void drawScaled(Surface *surface, double scaleX, double scaleY, bool markDirty = true) const;
+ void drawScaled(Surface *surface, bool markDirty = true) const;
void setMirrorOn();
void setMirrorOff();
- virtual Common::Rect getRect() const;
- Common::Rect getScaledRect(double scaleX, double scaleY) const;
-
- virtual uint getScaledWidth(double scaleX) const;
- virtual uint getScaledHeight(double scaleY) const;
+ virtual Common::Rect getRect(bool scaled = true) const;
const byte *getBuffer() const { return _data; }