From 2ad8d7015250d5c8c8db69bbf93e1e1447f6da99 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Tue, 13 Mar 2007 20:41:40 +0000 Subject: Moved inventory surface management into inventory.cpp, thus removing Graphics::kBit3. Some duplicated code now exists in graphics.cpp and inventory.cpp. svn-id: r26123 --- engines/parallaction/graphics.cpp | 22 ---------- engines/parallaction/graphics.h | 1 - engines/parallaction/inventory.cpp | 85 +++++++++++++++++++++----------------- 3 files changed, 47 insertions(+), 61 deletions(-) diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index 4f50d28dc7..c60900a962 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -25,7 +25,6 @@ #include "parallaction/graphics.h" #include "parallaction/parser.h" #include "parallaction/parallaction.h" -#include "parallaction/inventory.h" #include "parallaction/disk.h" #include "parallaction/zone.h" @@ -312,7 +311,6 @@ void Gfx::copyScreen(Gfx::Buffers srcbuffer, Gfx::Buffers dstbuffer) { return; } - void Gfx::copyRect(Gfx::Buffers srcbuffer, uint16 sx, uint16 sy, Gfx::Buffers dstbuffer, uint16 dx, uint16 dy, uint16 w, uint16 h) { byte *s = _buffers[srcbuffer] + (sx + sy * SCREEN_WIDTH); @@ -957,23 +955,6 @@ void Gfx::copyRect(Gfx::Buffers dstbuffer, uint16 x, uint16 y, uint16 w, uint16 } -void Gfx::drawBorder(Gfx::Buffers buffer, uint16 x, uint16 y, uint16 w, uint16 h, byte color) { - - byte *d = _buffers[buffer] + x + SCREEN_WIDTH * y; - - memset(d, color, w); - - for (uint16 i = 0; i < h; i++) { - d[i * SCREEN_WIDTH] = color; - d[i * SCREEN_WIDTH + w - 1] = color; - } - - d = _buffers[buffer] + x + SCREEN_WIDTH * (y + h - 1); - memset(d, color, w); - - return; -} - void Gfx::grabRect(Gfx::Buffers srcbuffer, byte *dst, uint16 x, uint16 y, uint16 w, uint16 h, uint16 pitch) { byte *s = _buffers[srcbuffer] + x + SCREEN_WIDTH * y; @@ -1035,8 +1016,6 @@ void Gfx::initBuffers() { _buffers[kBitFront] = (byte*)malloc(SCREEN_SIZE); _buffers[kBitBack] = (byte*)malloc(SCREEN_SIZE); _buffers[kBit2] = (byte*)malloc(SCREEN_SIZE); - _buffers[kBit3] = (byte*)malloc(SCREEN_SIZE); // this buffer is also used by menu so it must stay this size - _buffers[kMask0] = (byte*)malloc(SCREENMASK_WIDTH * SCREEN_HEIGHT); return; @@ -1073,7 +1052,6 @@ Gfx::~Gfx() { free(_buffers[kBitFront]); free(_buffers[kBitBack]); free(_buffers[kBit2]); - free(_buffers[kBit3]); freeCnv(&_font); diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index ba7dc05823..af4ed190a9 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -72,7 +72,6 @@ public: kBitFront, kBitBack, kBit2, - kBit3, // mask buffers kMask0 }; diff --git a/engines/parallaction/inventory.cpp b/engines/parallaction/inventory.cpp index 2aa2f8c818..9ec5611154 100644 --- a/engines/parallaction/inventory.cpp +++ b/engines/parallaction/inventory.cpp @@ -31,8 +31,7 @@ namespace Parallaction { // -// inventory is kept in Gfx::kBit3 at 0 offset -// it is a grid made of (at most) 30 cells, 24x24 pixels each, +// inventory is a grid made of (at most) 30 cells, 24x24 pixels each, // arranged in 6 lines // // inventory items are stored in cnv files in a 32x24 grid @@ -51,9 +50,10 @@ namespace Parallaction { #define INVENTORY_WIDTH (INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH) #define INVENTORY_HEIGHT (INVENTORY_LINES*INVENTORYITEM_HEIGHT) -extern Cnv _yourObjects; -uint16 _numInvLines = 0; -static Point _invPosition = { 0, 0 }; +static byte *_buffer; +extern Cnv _yourObjects; +uint16 _numInvLines = 0; +static Point _invPosition = { 0, 0 }; InventoryItem _inventory[INVENTORY_MAX_ITEMS] = { { kZoneDoor, 1 }, // open/close icon @@ -187,19 +187,35 @@ void drawInventoryItem(uint16 pos, InventoryItem *item) { uint16 line = pos / INVENTORY_ITEMS_PER_LINE; uint16 col = pos % INVENTORY_ITEMS_PER_LINE; - _vm->_gfx->copyRect( - Gfx::kBit3, - col * INVENTORYITEM_WIDTH, - line * _yourObjects._height, - INVENTORYITEM_WIDTH, - _yourObjects._height, - _yourObjects._array[item->_index], - INVENTORYITEM_PITCH - ); + // FIXME: this will end up in a general blit function + byte* s = _yourObjects._array[item->_index]; + byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * _yourObjects._height * INVENTORY_WIDTH; + for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) { + memcpy(d, s, INVENTORYITEM_WIDTH); + + d += INVENTORY_WIDTH; + s += INVENTORYITEM_PITCH; + } return; } +void drawBorder(const Common::Rect& r, byte *buffer, byte color) { + + byte *d = buffer + r.left + INVENTORY_WIDTH * r.top; + + memset(d, color, r.width()); + + for (uint16 i = 0; i < r.height(); i++) { + d[i * INVENTORY_WIDTH] = color; + d[i * INVENTORY_WIDTH + r.width() - 1] = color; + } + + d = buffer + r.left + INVENTORY_WIDTH * (r.bottom - 1); + memset(d, color, r.width()); + + return; +} // // draws a color border around the specified position in the inventory @@ -213,14 +229,10 @@ void highlightInventoryItem(int16 pos, byte color) { uint16 line = pos / INVENTORY_ITEMS_PER_LINE; uint16 col = pos % INVENTORY_ITEMS_PER_LINE; - _vm->_gfx->drawBorder( - Gfx::kBit3, - col * INVENTORYITEM_WIDTH, - line * _yourObjects._height, - INVENTORYITEM_WIDTH, - _yourObjects._height, - color - ); + Common::Rect r(INVENTORYITEM_WIDTH, _yourObjects._height); + r.moveTo(col * INVENTORYITEM_WIDTH, line * _yourObjects._height); + + drawBorder(r, _buffer, color); return; } @@ -234,15 +246,15 @@ void extractInventoryGraphics(int16 pos, byte *dst) { int16 line = pos / INVENTORY_ITEMS_PER_LINE; int16 col = pos % INVENTORY_ITEMS_PER_LINE; - _vm->_gfx->grabRect( - Gfx::kBit3, - dst, - col * INVENTORYITEM_WIDTH, - line * _yourObjects._height, - INVENTORYITEM_WIDTH, - _yourObjects._height, - INVENTORYITEM_PITCH - ); + // FIXME: this will end up in a general blit function + byte* d = dst; + byte* s = _buffer + col * INVENTORYITEM_WIDTH + line * _yourObjects._height * INVENTORY_WIDTH; + for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) { + memcpy(d, s, INVENTORYITEM_WIDTH); + + s += INVENTORY_WIDTH; + d += INVENTORYITEM_PITCH; + } return; } @@ -257,19 +269,15 @@ void jobShowInventory(void *parm, Job *j) { _numInvLines = (_numInvLines + 4) / INVENTORY_ITEMS_PER_LINE; _vm->_gfx->copyRect( - Gfx::kBit3, - 0, - 0, Gfx::kBitBack, _invPosition._x, _invPosition._y, INVENTORY_WIDTH, - _numInvLines * INVENTORYITEM_HEIGHT + _numInvLines * INVENTORYITEM_HEIGHT, + _buffer, + INVENTORY_WIDTH ); - -// printf("done\n"); - return; } @@ -355,6 +363,7 @@ void redrawInventory() { } void initInventory() { + _buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT); // this buffer is also used by menu so it must stay this size _yourObjects._count = 0; } -- cgit v1.2.3