[Scummvm-cvs-logs] SF.net SVN: scummvm:[42647] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Wed Jul 22 06:42:34 CEST 2009


Revision: 42647
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42647&view=rev
Author:   dkasak13
Date:     2009-07-22 04:42:33 +0000 (Wed, 22 Jul 2009)

Log Message:
-----------
* 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.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/animation.h
    scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/sprite.h

Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp	2009-07-22 00:12:48 UTC (rev 42646)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp	2009-07-22 04:42:33 UTC (rev 42647)
@@ -33,8 +33,6 @@
 	_z = 0;
 	_relX = 0;
 	_relY = 0;
-	_scaleX = 1.0;
-	_scaleY = 1.0;
 	setPlaying(false);
 	_looping = false;
 	_tick = _vm->_system->getMillis();
@@ -54,12 +52,7 @@
 	// 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 @@
 	_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 @@
 	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 @@
 	}
 
 	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 @@
 	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 @@
 	// 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);

Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.h	2009-07-22 00:12:48 UTC (rev 42646)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.h	2009-07-22 04:42:33 UTC (rev 42647)
@@ -62,11 +62,6 @@
 	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 @@
 	int _relX;
 	int _relY;
 
-	double _scaleX;
-	double _scaleY;
-
 	uint _tick;
 	bool _playing;
 	bool _looping;

Modified: scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/game.cpp	2009-07-22 00:12:48 UTC (rev 42646)
+++ scummvm/branches/gsoc2009-draci/engines/draci/game.cpp	2009-07-22 04:42:33 UTC (rev 42647)
@@ -176,27 +176,33 @@
 			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 @@
 
 	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 @@
 		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 @@
 
 		Sprite *sp = new Sprite(spriteFile->_data, spriteFile->_length, x, y, true);
 
+		sp->setScaled(scaledWidth, scaledHeight);
+
 		if (mirror) 
 			sp->setMirrorOn();
 

Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp	2009-07-22 00:12:48 UTC (rev 42646)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp	2009-07-22 04:42:33 UTC (rev 42647)
@@ -61,8 +61,13 @@
 
 	 _width = width;
 	 _height = height;
+
+	_scaledWidth = _width;
+	_scaledHeight = _height;
+
 	 _x = x;
 	 _y = y;
+
 	_delay = 0;
 
 	_mirror = false;
@@ -86,6 +91,7 @@
 
 	 _x = x;
 	 _y = y;
+
 	_delay = 0;
 
 	_mirror = false;	
@@ -95,6 +101,9 @@
 	_width = reader.readSint16LE();
 	_height = reader.readSint16LE();
 
+	_scaledWidth = _width;
+	_scaledHeight = _height;
+
 	_data = new byte[_width * _height];
 
 	reader.read(_data, _width * _height);
@@ -118,10 +127,10 @@
 }
 
 // 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 @@
 	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,22 +271,13 @@
 	}
 }
 
-Common::Rect Sprite::getRect() const {
-	return Common::Rect(_x, _y, _x + _width, _y + _height);
+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);
 }
 
-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);
-}
-
 Text::Text(const Common::String &str, Font *font, byte fontColour, 
 				int x, int y, uint spacing) {
 	uint len = str.size();
@@ -293,6 +297,9 @@
 
 	_width = _font->getStringWidth(str, _spacing);
 	_height = _font->getFontHeight();
+
+	_scaledWidth = _width;
+	_scaledHeight = _height;
 } 
 
 Text::~Text() {

Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.h	2009-07-22 00:12:48 UTC (rev 42646)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.h	2009-07-22 04:42:33 UTC (rev 42647)
@@ -38,17 +38,21 @@
 
 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 @@
 	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,24 +94,19 @@
 
 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 Common::Rect getRect(bool scaled = true) const;
 
-	virtual uint getScaledWidth(double scaleX) const;
-	virtual uint getScaledHeight(double scaleY) const;
-
 	const byte *getBuffer() const { return _data; }
 
 private:


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list