diff options
author | Walter van Niftrik | 2017-02-27 10:17:21 +0100 |
---|---|---|
committer | Walter van Niftrik | 2017-03-05 21:16:57 +0100 |
commit | 6bd7ca75f9ed6510b1a6efa82157e02364c65e50 (patch) | |
tree | 3b659c779d82c68677f599c1851f8b3879c989a0 /engines | |
parent | e97973a9307941b7accee46ba420e74d3b28c7f6 (diff) | |
download | scummvm-rg350-6bd7ca75f9ed6510b1a6efa82157e02364c65e50.tar.gz scummvm-rg350-6bd7ca75f9ed6510b1a6efa82157e02364c65e50.tar.bz2 scummvm-rg350-6bd7ca75f9ed6510b1a6efa82157e02364c65e50.zip |
ADL: Move shape drawing into base gfx class
Diffstat (limited to 'engines')
-rw-r--r-- | engines/adl/adl.h | 4 | ||||
-rw-r--r-- | engines/adl/graphics.cpp | 106 | ||||
-rw-r--r-- | engines/adl/graphics.h | 41 | ||||
-rw-r--r-- | engines/adl/hires0.cpp | 2 | ||||
-rw-r--r-- | engines/adl/hires1.cpp | 17 | ||||
-rw-r--r-- | engines/adl/hires2.cpp | 2 | ||||
-rw-r--r-- | engines/adl/hires4.cpp | 2 | ||||
-rw-r--r-- | engines/adl/hires5.cpp | 2 | ||||
-rw-r--r-- | engines/adl/hires6.cpp | 2 |
9 files changed, 86 insertions, 92 deletions
diff --git a/engines/adl/adl.h b/engines/adl/adl.h index 75c6485a1f..7076ab2394 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -148,14 +148,14 @@ struct Item { byte region; byte room; byte picture; - bool isLineArt; + bool isShape; Common::Point position; int state; byte description; Common::Array<byte> roomPictures; bool isOnScreen; - Item() : id(0), noun(0), region(0), room(0), picture(0), isLineArt(false), state(0), description(0), isOnScreen(false) { } + Item() : id(0), noun(0), region(0), room(0), picture(0), isShape(false), state(0), description(0), isOnScreen(false) { } }; struct Time { diff --git a/engines/adl/graphics.cpp b/engines/adl/graphics.cpp index cf906657b5..0f80bac988 100644 --- a/engines/adl/graphics.cpp +++ b/engines/adl/graphics.cpp @@ -77,44 +77,7 @@ void GraphicsMan::putPixel(const Common::Point &p, byte color) const { _display.putPixel(p, color); } -void Graphics_v1::drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) { - byte x, y; - bool bNewLine = false; - byte oldX = 0, oldY = 0; - while (1) { - x = pic.readByte(); - y = pic.readByte(); - - if (pic.err() || pic.eos()) - error("Error reading picture"); - - if (x == 0xff && y == 0xff) - return; - - if (x == 0 && y == 0) { - bNewLine = true; - continue; - } - - x += pos.x; - y += pos.y; - - if (y > 160) - y = 160; - - if (bNewLine) { - putPixel(Common::Point(x, y), 0x7f); - bNewLine = false; - } else { - drawLine(Common::Point(oldX, oldY), Common::Point(x, y), 0x7f); - } - - oldX = x; - oldY = y; - } -} - -void Graphics_v1::drawCornerPixel(Common::Point &p, byte color, byte bits, byte quadrant) const { +void GraphicsMan::drawShapePixel(Common::Point &p, byte color, byte bits, byte quadrant) const { if (bits & 4) putPixel(p, color); @@ -126,7 +89,7 @@ void Graphics_v1::drawCornerPixel(Common::Point &p, byte color, byte bits, byte p.y += (bits & 2 ? 1 : -1); } -void Graphics_v1::drawCorners(Common::ReadStream &corners, const Common::Point &pos, byte rotation, byte scaling, byte color) const { +void GraphicsMan::drawShape(Common::ReadStream &corners, Common::Point &pos, byte rotation, byte scaling, byte color) const { const byte stepping[] = { 0xff, 0xfe, 0xfa, 0xf4, 0xec, 0xe1, 0xd4, 0xc5, 0xb4, 0xa1, 0x8d, 0x78, 0x61, 0x49, 0x31, 0x18, @@ -138,8 +101,6 @@ void Graphics_v1::drawCorners(Common::ReadStream &corners, const Common::Point & byte xStep = stepping[rotation]; byte yStep = stepping[(rotation ^ 0xf) + 1] + 1; - Common::Point p(pos); - while (true) { byte b = corners.readByte(); @@ -154,10 +115,10 @@ void Graphics_v1::drawCorners(Common::ReadStream &corners, const Common::Point & byte yFrac = 0x80; for (uint j = 0; j < scaling; ++j) { if (xFrac + xStep + 1 > 255) - drawCornerPixel(p, color, b, quadrant); + drawShapePixel(pos, color, b, quadrant); xFrac += xStep + 1; if (yFrac + yStep > 255) - drawCornerPixel(p, color, b, quadrant + 1); + drawShapePixel(pos, color, b, quadrant + 1); yFrac += yStep; } b >>= 3; @@ -165,6 +126,43 @@ void Graphics_v1::drawCorners(Common::ReadStream &corners, const Common::Point & } } +void GraphicsMan::drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) { + byte x, y; + bool bNewLine = false; + byte oldX = 0, oldY = 0; + while (1) { + x = pic.readByte(); + y = pic.readByte(); + + if (pic.err() || pic.eos()) + error("Error reading picture"); + + if (x == 0xff && y == 0xff) + return; + + if (x == 0 && y == 0) { + bNewLine = true; + continue; + } + + x += pos.x; + y += pos.y; + + if (y > 160) + y = 160; + + if (bNewLine) { + putPixel(Common::Point(x, y), 0x7f); + bNewLine = false; + } else { + drawLine(Common::Point(oldX, oldY), Common::Point(x, y), 0x7f); + } + + oldX = x; + oldY = y; + } +} + #define NUM_PATTERNS 22 #define PATTERN_LEN 4 static const byte fillPatterns[NUM_PATTERNS][PATTERN_LEN] = { @@ -219,7 +217,7 @@ static const byte fillPatterns[NUM_PATTERNS][PATTERN_LEN] = { p.y += _offset.y; \ } while (0) -void Graphics_v2::drawCorners(Common::SeekableReadStream &pic, bool yFirst) { +void GraphicsMan_v2::drawCorners(Common::SeekableReadStream &pic, bool yFirst) { Common::Point p; READ_POINT(p); @@ -253,7 +251,7 @@ doYStep: } } -void Graphics_v2::drawRelativeLines(Common::SeekableReadStream &pic) { +void GraphicsMan_v2::drawRelativeLines(Common::SeekableReadStream &pic) { Common::Point p1; READ_POINT(p1); @@ -283,7 +281,7 @@ void Graphics_v2::drawRelativeLines(Common::SeekableReadStream &pic) { } } -void Graphics_v2::drawAbsoluteLines(Common::SeekableReadStream &pic) { +void GraphicsMan_v2::drawAbsoluteLines(Common::SeekableReadStream &pic) { Common::Point p1; READ_POINT(p1); @@ -308,11 +306,11 @@ static byte getPatternColor(const Common::Point &p, byte pattern) { return fillPatterns[pattern][offset % PATTERN_LEN]; } -bool Graphics_v2::canFillAt(const Common::Point &p, const bool stopBit) { +bool GraphicsMan_v2::canFillAt(const Common::Point &p, const bool stopBit) { return _display.getPixelBit(p) != stopBit && _display.getPixelBit(Common::Point(p.x + 1, p.y)) != stopBit; } -void Graphics_v2::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { +void GraphicsMan_v2::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { byte color = getPatternColor(p, pattern); while (--p.x >= _bounds.left) { @@ -326,7 +324,7 @@ void Graphics_v2::fillRowLeft(Common::Point p, const byte pattern, const bool st } } -void Graphics_v2::fillRow(Common::Point p, const byte pattern, const bool stopBit) { +void GraphicsMan_v2::fillRow(Common::Point p, const byte pattern, const bool stopBit) { // Set pixel at p and palette byte color = getPatternColor(p, pattern); _display.setPixelPalette(p, color); @@ -348,7 +346,7 @@ void Graphics_v2::fillRow(Common::Point p, const byte pattern, const bool stopBi } } -void Graphics_v2::fillAt(Common::Point p, const byte pattern) { +void GraphicsMan_v2::fillAt(Common::Point p, const byte pattern) { const bool stopBit = !_display.getPixelBit(p); // Move up into the open space above p @@ -359,7 +357,7 @@ void Graphics_v2::fillAt(Common::Point p, const byte pattern) { fillRow(p, pattern, stopBit); } -void Graphics_v2::fill(Common::SeekableReadStream &pic) { +void GraphicsMan_v2::fill(Common::SeekableReadStream &pic) { byte pattern; READ_BYTE(pattern); @@ -372,7 +370,7 @@ void Graphics_v2::fill(Common::SeekableReadStream &pic) { } } -void Graphics_v2::drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) { +void GraphicsMan_v2::drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) { // NOTE: The original engine only resets the color for overlays. As a result, room // pictures that draw without setting a color or clearing the screen, will use the // last color set by the previous picture. We assume this is unintentional and do @@ -441,7 +439,7 @@ void Graphics_v2::drawPic(Common::SeekableReadStream &pic, const Common::Point & } } -void Graphics_v3::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { +void GraphicsMan_v3::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { byte color = getPatternColor(p, pattern); while (--p.x >= _bounds.left) { @@ -456,7 +454,7 @@ void Graphics_v3::fillRowLeft(Common::Point p, const byte pattern, const bool st } } -void Graphics_v3::fillAt(Common::Point p, const byte pattern) { +void GraphicsMan_v3::fillAt(Common::Point p, const byte pattern) { // If the row at p cannot be filled, we do nothing if (!canFillAt(p)) return; diff --git a/engines/adl/graphics.h b/engines/adl/graphics.h index c0d1780a33..38dc2b25aa 100644 --- a/engines/adl/graphics.h +++ b/engines/adl/graphics.h @@ -20,8 +20,8 @@ * */ -#ifndef ADL_PICTURE_H -#define ADL_PICTURE_H +#ifndef ADL_GRAPHICS_H +#define ADL_GRAPHICS_H #include "common/rect.h" @@ -33,40 +33,35 @@ namespace Adl { class Display; +// Used in hires1 class GraphicsMan { public: + GraphicsMan(Display &display) : _bounds(280, 160), _display(display) { } virtual ~GraphicsMan() { } - virtual void drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) = 0; + + // Applesoft BASIC HLINE + void drawLine(const Common::Point &p1, const Common::Point &p2, byte color) const; + // Applesoft BASIC DRAW + void drawShape(Common::ReadStream &shape, Common::Point &pos, byte rotation = 0, byte scaling = 1, byte color = 0x7f) const; + + virtual void drawPic(Common::SeekableReadStream &pic, const Common::Point &pos); void clearScreen() const; void putPixel(const Common::Point &p, byte color) const; + void setBounds(const Common::Rect &r) { _bounds = r; } protected: - GraphicsMan(Display &display) : _bounds(280, 160), _display(display) { } - void drawLine(const Common::Point &p1, const Common::Point &p2, byte color) const; - Display &_display; Common::Rect _bounds; private: - virtual byte getClearColor() const = 0; -}; - -// Used in hires1 -class Graphics_v1 : public GraphicsMan { -public: - Graphics_v1(Display &display) : GraphicsMan(display) { } - void drawPic(Common::SeekableReadStream &pic, const Common::Point &pos); - void drawCorners(Common::ReadStream &corners, const Common::Point &pos, byte rotation = 0, byte scaling = 1, byte color = 0x7f) const; - -private: - void drawCornerPixel(Common::Point &p, byte color, byte bits, byte quadrant) const; - byte getClearColor() const { return 0x00; } + void drawShapePixel(Common::Point &p, byte color, byte bits, byte quadrant) const; + virtual byte getClearColor() const { return 0x00; } }; // Used in hires0 and hires2-hires4 -class Graphics_v2 : public GraphicsMan { +class GraphicsMan_v2 : public GraphicsMan { public: - Graphics_v2(Display &display) : GraphicsMan(display), _color(0) { } + GraphicsMan_v2(Display &display) : GraphicsMan(display), _color(0) { } void drawPic(Common::SeekableReadStream &pic, const Common::Point &pos); protected: @@ -87,9 +82,9 @@ private: }; // Used in hires5, hires6 and gelfling (possibly others as well) -class Graphics_v3 : public Graphics_v2 { +class GraphicsMan_v3 : public GraphicsMan_v2 { public: - Graphics_v3(Display &display) : Graphics_v2(display) { } + GraphicsMan_v3(Display &display) : GraphicsMan_v2(display) { } private: void fillRowLeft(Common::Point p, const byte pattern, const bool stopBit); diff --git a/engines/adl/hires0.cpp b/engines/adl/hires0.cpp index 9a0af05d20..0165170699 100644 --- a/engines/adl/hires0.cpp +++ b/engines/adl/hires0.cpp @@ -56,7 +56,7 @@ private: }; void HiRes0Engine::init() { - _graphics = new Graphics_v2(*_display); + _graphics = new GraphicsMan_v2(*_display); _disk = new DiskImage(); if (!_disk->open(IDS_HR0_DISK_IMAGE)) diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp index 239792d4f7..41436ac2af 100644 --- a/engines/adl/hires1.cpp +++ b/engines/adl/hires1.cpp @@ -83,7 +83,7 @@ namespace Adl { #define IDI_HR1_OFS_MSGS 0x4d00 #define IDI_HR1_OFS_ITEM_OFFSETS 0x68ff -#define IDI_HR1_OFS_CORNERS 0x4f00 +#define IDI_HR1_OFS_SHAPES 0x4f00 #define IDI_HR1_OFS_VERBS 0x3800 #define IDI_HR1_OFS_NOUNS 0x0f00 @@ -229,7 +229,7 @@ void HiRes1Engine::init() { } else _files = new Files_Plain(); - _graphics = new Graphics_v1(*_display); + _graphics = new GraphicsMan(*_display); StreamPtr stream(_files->createReadStream(IDS_HR1_EXE_1)); @@ -279,11 +279,11 @@ void HiRes1Engine::init() { stream->seek(IDI_HR1_OFS_ITEM_OFFSETS); loadDroppedItemOffsets(*stream, IDI_HR1_NUM_ITEM_OFFSETS); - // Load right-angle line art - stream->seek(IDI_HR1_OFS_CORNERS); + // Load shapes + stream->seek(IDI_HR1_OFS_SHAPES); uint16 cornersCount = stream->readUint16LE(); for (uint i = 0; i < cornersCount; ++i) - _corners.push_back(_files->getDataBlock(IDS_HR1_EXE_1, IDI_HR1_OFS_CORNERS + stream->readUint16LE())); + _corners.push_back(_files->getDataBlock(IDS_HR1_EXE_1, IDI_HR1_OFS_SHAPES + stream->readUint16LE())); if (stream->eos() || stream->err()) error("Failed to read game data from '" IDS_HR1_EXE_1 "'"); @@ -324,7 +324,7 @@ void HiRes1Engine::initGameState() { item.noun = stream->readByte(); item.room = stream->readByte(); item.picture = stream->readByte(); - item.isLineArt = stream->readByte(); + item.isShape = stream->readByte(); item.position.x = stream->readByte(); item.position.y = stream->readByte(); item.state = stream->readByte(); @@ -416,9 +416,10 @@ void HiRes1Engine::drawItems() { } void HiRes1Engine::drawItem(Item &item, const Common::Point &pos) { - if (item.isLineArt) { + if (item.isShape) { StreamPtr stream(_corners[item.picture - 1]->createReadStream()); - static_cast<Graphics_v1 *>(_graphics)->drawCorners(*stream, pos); + Common::Point p(pos); + _graphics->drawShape(*stream, p); } else drawPic(item.picture, pos); } diff --git a/engines/adl/hires2.cpp b/engines/adl/hires2.cpp index 9562095ec9..ac1ee57fac 100644 --- a/engines/adl/hires2.cpp +++ b/engines/adl/hires2.cpp @@ -80,7 +80,7 @@ void HiRes2Engine::runIntro() { } void HiRes2Engine::init() { - _graphics = new Graphics_v2(*_display); + _graphics = new GraphicsMan_v2(*_display); _disk = new DiskImage(); if (!_disk->open(IDS_HR2_DISK_IMAGE)) diff --git a/engines/adl/hires4.cpp b/engines/adl/hires4.cpp index 3775a2d1eb..9b085e35d4 100644 --- a/engines/adl/hires4.cpp +++ b/engines/adl/hires4.cpp @@ -83,7 +83,7 @@ HiRes4Engine_Atari::~HiRes4Engine_Atari() { } void HiRes4Engine_Atari::init() { - _graphics = new Graphics_v2(*_display); + _graphics = new GraphicsMan_v2(*_display); _boot = new DiskImage(); if (!_boot->open(atariDisks[0])) diff --git a/engines/adl/hires5.cpp b/engines/adl/hires5.cpp index e0f61ba2d3..efe69a7e58 100644 --- a/engines/adl/hires5.cpp +++ b/engines/adl/hires5.cpp @@ -325,7 +325,7 @@ void HiRes5Engine::runIntro() { } void HiRes5Engine::init() { - _graphics = new Graphics_v3(*_display); + _graphics = new GraphicsMan_v3(*_display); insertDisk(2); diff --git a/engines/adl/hires6.cpp b/engines/adl/hires6.cpp index 0eb47de7fc..02ef0f022a 100644 --- a/engines/adl/hires6.cpp +++ b/engines/adl/hires6.cpp @@ -289,7 +289,7 @@ void HiRes6Engine::runIntro() { } void HiRes6Engine::init() { - _graphics = new Graphics_v3(*_display); + _graphics = new GraphicsMan_v3(*_display); insertDisk(0); |