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
This commit is contained in:
Nicola Mettifogo 2007-03-13 20:41:40 +00:00
parent 3346e270ba
commit 2ad8d70152
3 changed files with 47 additions and 61 deletions

View file

@ -25,7 +25,6 @@
#include "parallaction/graphics.h" #include "parallaction/graphics.h"
#include "parallaction/parser.h" #include "parallaction/parser.h"
#include "parallaction/parallaction.h" #include "parallaction/parallaction.h"
#include "parallaction/inventory.h"
#include "parallaction/disk.h" #include "parallaction/disk.h"
#include "parallaction/zone.h" #include "parallaction/zone.h"
@ -312,7 +311,6 @@ void Gfx::copyScreen(Gfx::Buffers srcbuffer, Gfx::Buffers dstbuffer) {
return; return;
} }
void Gfx::copyRect(Gfx::Buffers srcbuffer, uint16 sx, uint16 sy, Gfx::Buffers dstbuffer, uint16 dx, uint16 dy, uint16 w, uint16 h) { 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); 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) { 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; byte *s = _buffers[srcbuffer] + x + SCREEN_WIDTH * y;
@ -1035,8 +1016,6 @@ void Gfx::initBuffers() {
_buffers[kBitFront] = (byte*)malloc(SCREEN_SIZE); _buffers[kBitFront] = (byte*)malloc(SCREEN_SIZE);
_buffers[kBitBack] = (byte*)malloc(SCREEN_SIZE); _buffers[kBitBack] = (byte*)malloc(SCREEN_SIZE);
_buffers[kBit2] = (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); _buffers[kMask0] = (byte*)malloc(SCREENMASK_WIDTH * SCREEN_HEIGHT);
return; return;
@ -1073,7 +1052,6 @@ Gfx::~Gfx() {
free(_buffers[kBitFront]); free(_buffers[kBitFront]);
free(_buffers[kBitBack]); free(_buffers[kBitBack]);
free(_buffers[kBit2]); free(_buffers[kBit2]);
free(_buffers[kBit3]);
freeCnv(&_font); freeCnv(&_font);

View file

@ -72,7 +72,6 @@ public:
kBitFront, kBitFront,
kBitBack, kBitBack,
kBit2, kBit2,
kBit3,
// mask buffers // mask buffers
kMask0 kMask0
}; };

View file

@ -31,8 +31,7 @@
namespace Parallaction { namespace Parallaction {
// //
// inventory is kept in Gfx::kBit3 at 0 offset // inventory is a grid made of (at most) 30 cells, 24x24 pixels each,
// it is a grid made of (at most) 30 cells, 24x24 pixels each,
// arranged in 6 lines // arranged in 6 lines
// //
// inventory items are stored in cnv files in a 32x24 grid // 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_WIDTH (INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH)
#define INVENTORY_HEIGHT (INVENTORY_LINES*INVENTORYITEM_HEIGHT) #define INVENTORY_HEIGHT (INVENTORY_LINES*INVENTORYITEM_HEIGHT)
extern Cnv _yourObjects; static byte *_buffer;
uint16 _numInvLines = 0; extern Cnv _yourObjects;
static Point _invPosition = { 0, 0 }; uint16 _numInvLines = 0;
static Point _invPosition = { 0, 0 };
InventoryItem _inventory[INVENTORY_MAX_ITEMS] = { InventoryItem _inventory[INVENTORY_MAX_ITEMS] = {
{ kZoneDoor, 1 }, // open/close icon { kZoneDoor, 1 }, // open/close icon
@ -187,19 +187,35 @@ void drawInventoryItem(uint16 pos, InventoryItem *item) {
uint16 line = pos / INVENTORY_ITEMS_PER_LINE; uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
uint16 col = pos % INVENTORY_ITEMS_PER_LINE; uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
_vm->_gfx->copyRect( // FIXME: this will end up in a general blit function
Gfx::kBit3, byte* s = _yourObjects._array[item->_index];
col * INVENTORYITEM_WIDTH, byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * _yourObjects._height * INVENTORY_WIDTH;
line * _yourObjects._height, for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
INVENTORYITEM_WIDTH, memcpy(d, s, INVENTORYITEM_WIDTH);
_yourObjects._height,
_yourObjects._array[item->_index], d += INVENTORY_WIDTH;
INVENTORYITEM_PITCH s += INVENTORYITEM_PITCH;
); }
return; 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 // 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 line = pos / INVENTORY_ITEMS_PER_LINE;
uint16 col = pos % INVENTORY_ITEMS_PER_LINE; uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
_vm->_gfx->drawBorder( Common::Rect r(INVENTORYITEM_WIDTH, _yourObjects._height);
Gfx::kBit3, r.moveTo(col * INVENTORYITEM_WIDTH, line * _yourObjects._height);
col * INVENTORYITEM_WIDTH,
line * _yourObjects._height, drawBorder(r, _buffer, color);
INVENTORYITEM_WIDTH,
_yourObjects._height,
color
);
return; return;
} }
@ -234,15 +246,15 @@ void extractInventoryGraphics(int16 pos, byte *dst) {
int16 line = pos / INVENTORY_ITEMS_PER_LINE; int16 line = pos / INVENTORY_ITEMS_PER_LINE;
int16 col = pos % INVENTORY_ITEMS_PER_LINE; int16 col = pos % INVENTORY_ITEMS_PER_LINE;
_vm->_gfx->grabRect( // FIXME: this will end up in a general blit function
Gfx::kBit3, byte* d = dst;
dst, byte* s = _buffer + col * INVENTORYITEM_WIDTH + line * _yourObjects._height * INVENTORY_WIDTH;
col * INVENTORYITEM_WIDTH, for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
line * _yourObjects._height, memcpy(d, s, INVENTORYITEM_WIDTH);
INVENTORYITEM_WIDTH,
_yourObjects._height, s += INVENTORY_WIDTH;
INVENTORYITEM_PITCH d += INVENTORYITEM_PITCH;
); }
return; return;
} }
@ -257,19 +269,15 @@ void jobShowInventory(void *parm, Job *j) {
_numInvLines = (_numInvLines + 4) / INVENTORY_ITEMS_PER_LINE; _numInvLines = (_numInvLines + 4) / INVENTORY_ITEMS_PER_LINE;
_vm->_gfx->copyRect( _vm->_gfx->copyRect(
Gfx::kBit3,
0,
0,
Gfx::kBitBack, Gfx::kBitBack,
_invPosition._x, _invPosition._x,
_invPosition._y, _invPosition._y,
INVENTORY_WIDTH, INVENTORY_WIDTH,
_numInvLines * INVENTORYITEM_HEIGHT _numInvLines * INVENTORYITEM_HEIGHT,
_buffer,
INVENTORY_WIDTH
); );
// printf("done\n");
return; return;
} }
@ -355,6 +363,7 @@ void redrawInventory() {
} }
void initInventory() { 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; _yourObjects._count = 0;
} }