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

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Sat Jul 4 20:29:02 CEST 2009


Revision: 42100
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42100&view=rev
Author:   dkasak13
Date:     2009-07-04 18:29:01 +0000 (Sat, 04 Jul 2009)

Log Message:
-----------
* Removed tracking of Z coordinates in Drawable since it's not used
* Made columnwise parameter mandatory
* Made Sprite coordinates signed (the engine sometimes uses negative coordinates)
* Prevented overflow when drawing sprites in some cases

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

Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp	2009-07-04 17:39:43 UTC (rev 42099)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp	2009-07-04 18:29:01 UTC (rev 42100)
@@ -53,14 +53,15 @@
 
 /**
  *  Constructor for loading sprites from a raw data buffer, one byte per pixel.
- */ 
-Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint x, uint y, 
-			   uint z, bool columnwise) : _data(NULL) {
+ */
+Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y, 
+	bool columnwise) : _data(NULL) {
+
 	 _width = width;
 	 _height = height;
 	 _x = x;
 	 _y = y;
-	 _z = z;
+
 	_mirror = false;
 
 	_data = new byte[width * height];
@@ -73,22 +74,22 @@
 	}	
 }
 
-
 /**
  *  Constructor for loading sprites from a sprite-formatted buffer, one byte per 
  *	pixel.
  */
-Sprite::Sprite(byte *sprite_data, uint16 length, uint x, uint y, uint z,
-			   bool columnwise) : _data(NULL) {
+Sprite::Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise) 
+	: _data(NULL) {
+
 	 _x = x;
 	 _y = y;
-	 _z = z;
+
 	_mirror = false;	
 
 	Common::MemoryReadStream reader(sprite_data, length);
 
-	_width = reader.readUint16LE();
-	_height = reader.readUint16LE();
+	_width = reader.readSint16LE();
+	_height = reader.readSint16LE();
 
 	_data = new byte[_width * _height];
 
@@ -122,19 +123,27 @@
 	byte *dst = (byte *)surface->getBasePtr(_x, _y);
 	byte *src = _data;	
 	
+	// Determine how many pixels to draw horizontally (to prevent overflow)
+	int xSpaceLeft = surface->w - _x - 1;	
+	int xPixelsToDraw = (_width < xSpaceLeft) ? _width : xSpaceLeft;
+
+	// Determine how many pixels to draw vertically
+	int ySpaceLeft = surface->h - _y - 1;	
+	int yPixelsToDraw = (_height < ySpaceLeft) ? _height : ySpaceLeft;
+
 	// Blit the sprite to the surface
-	for (int i = 0; i < _height; ++i) {
+	for (int i = 0; i < yPixelsToDraw; ++i) {
 
 		// Draw the sprite mirrored if the _mirror flag is set
 		if (_mirror) {
-			for(int j = _width - 1; j >= 0; --j, ++src) {
+			for (int j = xPixelsToDraw - 1; j >= 0; --j, ++src) {
 
 				// Don't blit if the pixel is transparent on the target surface
 				if (*src != surface->getTransparentColour())			
 					dst[j] = *src;
 			}		
 		} else {
-			for(int j = 0; j < _width; ++j, ++src) {
+			for (int j = 0; j < xPixelsToDraw; ++j, ++src) {
 
 				// Don't blit if the pixel is transparent on the target surface
 				if (*src != surface->getTransparentColour())			
@@ -142,6 +151,7 @@
 			}
 		}
 
+		src += _width - xPixelsToDraw;
 		dst += surface->pitch;
 	}
 
@@ -157,13 +167,12 @@
 }
 
 Text::Text(const Common::String &str, Font *font, byte fontColour, 
-				uint x, uint y, uint z, uint spacing) {
+				int x, int y, uint spacing) {
 	uint len = str.size();
 	_length = len;
 	
 	_x = x;
 	_y = y;
-	_z = z;
 	
 	_text = new byte[len];
 	memcpy(_text, str.c_str(), len);

Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.h	2009-07-04 17:39:43 UTC (rev 42099)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.h	2009-07-04 18:29:01 UTC (rev 42100)
@@ -43,21 +43,18 @@
 	virtual uint16 getWidth() { return _width; }
 	virtual uint16 getHeight() { return _height; }
 
-	virtual uint getX() { return _x; }
-	virtual uint getY() { return _y; }
-	virtual uint getZ() { return _z; }
+	virtual int getX() { return _x; }
+	virtual int getY() { return _y; }
 
-	virtual void setX(uint x) { _x = x; }
-	virtual void setY(uint y) { _y = y; }
-	virtual void setZ(uint z) { _z = z; }
+	virtual void setX(int x) { _x = x; }
+	virtual void setY(int y) { _y = y; }
 
 	virtual Common::Rect getRect() const = 0;
 	
 private:
 	uint16 _width;	//!< Width of the sprite
 	uint16 _height;	//!< Height of the sprite
-	uint _x, _y;	//!< Sprite coordinates
-	uint _z; 		//!< Sprite depth position
+	int _x, _y;	//!< Sprite coordinates
 };
 
 /**
@@ -76,12 +73,10 @@
 class Sprite : public Drawable {
 
 public:
-	Sprite(byte *raw_data, uint16 width, uint16 height, uint x, uint y, 
-		uint z, bool columnwise = true); 
+	Sprite(byte *raw_data, uint16 width, uint16 height, int x, int y, bool columnwise);
 
 	
-	Sprite(byte *sprite_data, uint16 length, uint x, uint y, 
-		uint z, bool columnwise = true); 
+	Sprite(byte *sprite_data, uint16 length, int x, int y, bool columnwise); 
 
 	~Sprite();
 
@@ -90,7 +85,6 @@
 	void setMirrorOn();
 	void setMirrorOff();
 
-
 	virtual Common::Rect getRect() const;
 	const byte *getBuffer() const { return _data; }
 
@@ -103,7 +97,7 @@
 	
 public:
 	Text(const Common::String &str, Font *font, byte fontColour, 
-		uint x, uint y, uint z, uint spacing = 0);
+		int x, int y, uint spacing = 0);
 	~Text();
 	
 	void setText(const Common::String &str);


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