diff options
author | Nicola Mettifogo | 2007-08-06 19:13:51 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-08-06 19:13:51 +0000 |
commit | 6c0288044b99f1c5a6d945dafcd635be285d61f8 (patch) | |
tree | c58a2787af74a11104fbfa4583f63623b8ec13fd /engines | |
parent | 872a6edfc69011eff0ea40c467e84245c1b2a7e4 (diff) | |
download | scummvm-rg350-6c0288044b99f1c5a6d945dafcd635be285d61f8.tar.gz scummvm-rg350-6c0288044b99f1c5a6d945dafcd635be285d61f8.tar.bz2 scummvm-rg350-6c0288044b99f1c5a6d945dafcd635be285d61f8.zip |
Changed graphics mask to a more generic BitBuffer object.
svn-id: r28471
Diffstat (limited to 'engines')
-rw-r--r-- | engines/parallaction/callables_ns.cpp | 6 | ||||
-rw-r--r-- | engines/parallaction/graphics.cpp | 29 | ||||
-rw-r--r-- | engines/parallaction/graphics.h | 47 |
3 files changed, 59 insertions, 23 deletions
diff --git a/engines/parallaction/callables_ns.cpp b/engines/parallaction/callables_ns.cpp index 011c1b5ce9..e603f8c7a5 100644 --- a/engines/parallaction/callables_ns.cpp +++ b/engines/parallaction/callables_ns.cpp @@ -600,8 +600,8 @@ void Parallaction_ns::_c_moveSheet(void *parm) { return; } -void plotPixel(int x, int y, int color, void *data) { - _vm->_gfx->plotMaskPixel(x, y, color); +void zeroMask(int x, int y, int color, void *data) { + _vm->_gfx->zeroMaskValue(x, y, color); } void Parallaction_ns::_c_sketch(void *parm) { @@ -614,7 +614,7 @@ void Parallaction_ns::_c_sketch(void *parm) { uint16 oldy = _rightHandPositions[2*(index-1)+1]; uint16 oldx = _rightHandPositions[2*(index-1)]; - Graphics::drawLine(oldx, oldy, newx, newy, 0, plotPixel, NULL); + Graphics::drawLine(oldx, oldy, newx, newy, 0, zeroMask, NULL); _rightHandAnim->_left = newx; _rightHandAnim->_top = newy - 20; diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index ae845cf47e..46be534b53 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -357,21 +357,14 @@ void Gfx::blit(const Common::Rect& r, uint16 z, byte *data, Gfx::Buffers buffer) byte *s = data + q.left + q.top * r.width(); byte *d = (byte*)_buffers[buffer]->getBasePtr(dp.x, dp.y); - for (uint16 i = q.top; i < q.bottom; i++) { - - uint16 n = dp.x % 4; - byte *m = _depthMask + dp.x/4 + (dp.y + i - q.top)*_vm->_screenMaskWidth; + for (uint16 i = 0; i < q.height(); i++) { - for (uint16 j = q.left; j < q.right; j++) { + for (uint16 j = 0; j < q.width(); j++) { if (*s != 0) { - uint16 v = ((3 << (n << 1)) & *m) >> (n << 1); + byte v = _depthMask->getValue(dp.x + j, dp.y + i); if (z >= v) *d = *s; } - n++; - if (n==4) m++; - n &= 0x3; - s++; d++; } @@ -768,7 +761,7 @@ void Gfx::setBackground(byte *background) { } void Gfx::setMask(byte *mask) { - memcpy(_depthMask, mask, _vm->_screenMaskSize); + memcpy(_depthMask->data, mask, _vm->_screenMaskSize); } @@ -808,10 +801,10 @@ void Gfx::grabRect(byte *dst, const Common::Rect& r, Gfx::Buffers srcbuffer, uin so they shouldn't be modified when adding support for other games */ -void Gfx::plotMaskPixel(uint16 x, uint16 y, byte color) { +void Gfx::zeroMaskValue(uint16 x, uint16 y, byte color) { uint16 _ax = x + y * _vm->_screenWidth; - _depthMask[_ax >> 2] &= ~(3 << ((_ax & 3) << 1)); + _depthMask->data[_ax >> 2] &= ~(3 << ((_ax & 3) << 1)); return; } @@ -820,7 +813,7 @@ void Gfx::fillMaskRect(const Common::Rect& r, byte color) { uint16 _di = r.left/4 + r.top * _vm->_screenMaskWidth; for (uint16 _si = r.top; _si < r.bottom; _si++) { - memset(&_depthMask[_di], color, r.width()/4+1); + memset(_depthMask->data + _di, color, r.width()/4+1); _di += _vm->_screenMaskWidth; } @@ -828,7 +821,7 @@ void Gfx::fillMaskRect(const Common::Rect& r, byte color) { } void Gfx::intGrottaHackMask() { - memset(_depthMask + 3600, 0, 3600); + memset(_depthMask->data + 3600, 0, 3600); _bgLayers[1] = 500; return; } @@ -857,7 +850,8 @@ Gfx::Gfx(Parallaction* vm) : _buffers[kBit2] = new Graphics::Surface; _buffers[kBit2]->create(_vm->_screenWidth, _vm->_screenHeight, 1); - _depthMask = (byte*)malloc(_vm->_screenMaskWidth * _vm->_screenHeight); + _depthMask = new BitBuffer; + _depthMask->create(_vm->_screenWidth, _vm->_screenHeight); setBlackPalette(); @@ -878,7 +872,8 @@ Gfx::Gfx(Parallaction* vm) : Gfx::~Gfx() { - free(_depthMask); + _depthMask->free(); + delete _depthMask; _buffers[kBitFront]->free(); delete _buffers[kBitFront]; diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index 9c1b962ae5..3ceb6b0ce9 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -146,6 +146,47 @@ enum Fonts { kFontMenu = 2 }; +struct BitBuffer { + // handles a 2-bit depth buffer used for z-buffering + + // TODO: generalize to handle 1-bit buffers, so that + // path buffers can be handled as well (use templates?) + + uint16 w; + uint16 internalWidth; + uint16 h; + uint size; + byte *data; + +public: + BitBuffer() : w(0), internalWidth(0), h(0), data(0) { + } + + ~BitBuffer() { + free(); + } + + void create(uint16 width, uint16 height) { + w = width; + internalWidth = w >> 2; + h = height; + size = (internalWidth * h); + data = (byte*)malloc(size); + } + + void free() { + if (data) + ::free(data); + } + + inline byte getValue(uint16 x, uint16 y) { + byte m = data[(x >> 2) + y * internalWidth]; + uint n = (x & 3) << 1; + return ((3 << n) & m) >> n; + } + +}; + class Gfx { public: @@ -184,9 +225,9 @@ public: void intGrottaHackMask(); void restoreBackground(const Common::Rect& r); - // intro + // intro hacks for Nippon Safes void fillMaskRect(const Common::Rect& r, byte color); - void plotMaskPixel(uint16 x, uint16 y, byte color); + void zeroMaskValue(uint16 x, uint16 y, byte color); // low level void swapBuffers(); @@ -233,7 +274,7 @@ public: protected: Parallaction* _vm; Graphics::Surface *_buffers[NUM_BUFFERS]; - byte *_depthMask; + BitBuffer *_depthMask; static byte _mouseArrow[256]; StaticCnv *_mouseComposedArrow; Font *_font; |