aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2017-12-17 11:08:09 -0500
committerPaul Gilbert2017-12-17 11:08:09 -0500
commita124b1d26a6b2e7d121a48b45d5aaf9f413dbe80 (patch)
tree4d0d888f68ab5e82ad3bfde0989124c40cb80c1e /engines
parent93a89024e9306a1a3ee181ac66201f38bdfc077e (diff)
downloadscummvm-rg350-a124b1d26a6b2e7d121a48b45d5aaf9f413dbe80.tar.gz
scummvm-rg350-a124b1d26a6b2e7d121a48b45d5aaf9f413dbe80.tar.bz2
scummvm-rg350-a124b1d26a6b2e7d121a48b45d5aaf9f413dbe80.zip
XEEN: Cleanup and comments for SpriteResource class
Diffstat (limited to 'engines')
-rw-r--r--engines/xeen/sprites.cpp18
-rw-r--r--engines/xeen/sprites.h46
2 files changed, 47 insertions, 17 deletions
diff --git a/engines/xeen/sprites.cpp b/engines/xeen/sprites.cpp
index 430505e7d2..5a217e05d9 100644
--- a/engines/xeen/sprites.cpp
+++ b/engines/xeen/sprites.cpp
@@ -37,13 +37,11 @@ SpriteResource::SpriteResource() {
_filesize = 0;
_data = nullptr;
_scaledWidth = _scaledHeight = 0;
- Common::fill(&_lineDist[0], &_lineDist[SCREEN_WIDTH], false);
}
SpriteResource::SpriteResource(const Common::String &filename) {
_data = nullptr;
_scaledWidth = _scaledHeight = 0;
- Common::fill(&_lineDist[0], &_lineDist[SCREEN_WIDTH], false);
load(filename);
}
@@ -101,18 +99,19 @@ void SpriteResource::clear() {
}
void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Point &pt,
- const Common::Rect &clipRect, int flags, int scale) {
+ const Common::Rect &clipRect, uint flags, int scale) {
static const uint SCALE_TABLE[] = {
0xFFFF, 0xFFEF, 0xEFEF, 0xEFEE, 0xEEEE, 0xEEAE, 0xAEAE, 0xAEAA,
0xAAAA, 0xAA8A, 0x8A8A, 0x8A88, 0x8888, 0x8880, 0x8080, 0x8000
};
static const int PATTERN_STEPS[] = { 0, 1, 1, 1, 2, 2, 3, 3, 0, -1, -1, -1, -2, -2, -3, -3 };
- uint16 scaleMask = SCALE_TABLE[scale & 0x7fff];
+ assert(ABS(scale) < 16);
+ uint16 scaleMask = SCALE_TABLE[ABS(scale)];
uint16 scaleMaskX = scaleMask, scaleMaskY = scaleMask;
bool flipped = (flags & SPRFLAG_HORIZ_FLIPPED) != 0;
int xInc = flipped ? -1 : 1;
- bool enlarge = (scale & 0x8000) != 0;
+ bool enlarge = scale < 0;
// Get cell header
Common::MemoryReadStream f(_data, _filesize);
@@ -299,24 +298,25 @@ void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Poi
}
void SpriteResource::draw(XSurface &dest, int frame, const Common::Point &destPos,
- int flags, int scale) {
+ uint flags, int scale) {
draw(dest, frame, destPos, Common::Rect(0, 0, dest.w, dest.h), flags, scale);
}
void SpriteResource::draw(Window &dest, int frame, const Common::Point &destPos,
- int flags, int scale) {
+ uint flags, int scale) {
draw(dest, frame, destPos, dest.getBounds(), flags, scale);
}
void SpriteResource::draw(int windowIndex, int frame, const Common::Point &destPos,
- int flags, int scale) {
+ uint flags, int scale) {
Window &win = (*g_vm->_windows)[windowIndex];
draw(win, frame, destPos, flags, scale);
}
void SpriteResource::draw(XSurface &dest, int frame, const Common::Point &destPos,
- const Common::Rect &bounds, int flags, int scale) {
+ const Common::Rect &bounds, uint flags, int scale) {
+ // Sprites can consist of separate background & foreground
drawOffset(dest, _index[frame]._offset1, destPos, bounds, flags, scale);
if (_index[frame]._offset2)
drawOffset(dest, _index[frame]._offset2, destPos, bounds, flags, scale);
diff --git a/engines/xeen/sprites.h b/engines/xeen/sprites.h
index b94b7c9b7e..1970f35ef8 100644
--- a/engines/xeen/sprites.h
+++ b/engines/xeen/sprites.h
@@ -49,7 +49,6 @@ private:
Common::Array<IndexEntry> _index;
int32 _filesize;
byte *_data;
- bool _lineDist[320];
int _scaledWidth, _scaledHeight;
/**
@@ -61,19 +60,19 @@ private:
* Draw the sprite onto the given surface
*/
void draw(XSurface &dest, int frame, const Common::Point &destPos,
- const Common::Rect &bounds, int flags = 0, int scale = 0);
+ const Common::Rect &bounds, uint flags = 0, int scale = 0);
/**
* Draw the sprite onto a given window
*/
void draw(int windowNum, int frame, const Common::Point &destPos,
- const Common::Rect &bounds, int flags = 0, int scale = 0);
+ const Common::Rect &bounds, uint flags = 0, int scale = 0);
/**
* Draw a sprite frame based on a passed offset into the data stream
*/
void drawOffset(XSurface &dest, uint16 offset, const Common::Point &pt,
- const Common::Rect &clipRect, int flags, int scale);
+ const Common::Rect &clipRect, uint flags, int scale);
/**
* Scale a co-ordinate value based on the passed scaling mask
@@ -107,34 +106,65 @@ public:
/**
* Draw a sprite onto a surface
+ * @param dest Destination surface
+ * @param frame Frame number
+ * @param destPos Destination position
+ * @param flags Flags
+ * @param scale Scale: 0=No scale
+ * 1..15 -> reduces the sprite: the higher, the smaller it'll be.
+ * -1..-15 -> enlarges the sprite
*/
void draw(XSurface &dest, int frame, const Common::Point &destPos,
- int flags = 0, int scale = 0);
+ uint flags = 0, int scale = 0);
/**
* Draw a sprite onto a specific window
+ * @param dest Destination window
+ * @param frame Frame number
+ * @param destPos Destination position
+ * @param flags Flags
+ * @param scale Scale: 0=No scale
+ * 1..15 -> reduces the sprite: the higher, the smaller it'll be.
+ * -1..-15 -> enlarges the sprite
*/
void draw(Window &dest, int frame, const Common::Point &destPos,
- int flags = 0, int scale = 0);
+ uint flags = 0, int scale = 0);
/**
* Draw a sprite onto a given window
+ * @param windowIndex Destination window number
+ * @param frame Frame number
+ * @param destPos Destination position
+ * @param flags Flags
+ * @param scale Scale: 0=No scale
+ * 1..15 -> reduces the sprite: the higher, the smaller it'll be.
+ * -1..-15 -> enlarges the sprite
*/
void draw(int windowIndex, int frame, const Common::Point &destPos,
- int flags = 0, int scale = 0);
+ uint flags = 0, int scale = 0);
/**
* Draw the sprite onto the given surface
+ * @param dest Destination surface
+ * @param frame Frame number
*/
void draw(XSurface &dest, int frame);
/**
* Draw the sprite onto the given window
+ * @param windowIndex Destination window number
+ * @param frame Frame number
*/
void draw(int windowIndex, int frame);
- int size() const { return _index.size(); }
+ /**
+ * Returns the number of frames the sprite resource has
+ */
+ size_t size() const { return _index.size(); }
+ /**
+ * Returns true if the sprite resource is empty (ie. nothing is loaded)
+ */
bool empty() const { return _index.size() == 0; }
};