[Scummvm-cvs-logs] SF.net SVN: scummvm:[33355] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Mon Jul 28 08:06:35 CEST 2008


Revision: 33355
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33355&view=rev
Author:   peres001
Date:     2008-07-28 06:06:35 +0000 (Mon, 28 Jul 2008)

Log Message:
-----------
Inventory is now properly rendered. Item selection is not yet working.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/graphics.cpp
    scummvm/trunk/engines/parallaction/graphics.h
    scummvm/trunk/engines/parallaction/inventory.cpp
    scummvm/trunk/engines/parallaction/inventory.h

Modified: scummvm/trunk/engines/parallaction/graphics.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.cpp	2008-07-28 05:38:24 UTC (rev 33354)
+++ scummvm/trunk/engines/parallaction/graphics.cpp	2008-07-28 06:06:35 UTC (rev 33355)
@@ -153,6 +153,13 @@
 		_data[index*3+2] = blue & 0xFF;
 }
 
+void Palette::getEntry(uint index, int &red, int &green, int &blue) {
+	assert(index < _colors);
+	red   = _data[index*3];
+	green = _data[index*3+1];
+	blue  = _data[index*3+2];
+}
+
 void Palette::makeGrayscale() {
 	byte v;
 	for (uint16 i = 0; i < _colors; i++) {
@@ -797,6 +804,14 @@
 
 	registerVar("draw_path_zones", 0);
 
+	if ((_vm->getGameType() == GType_BRA) && (_vm->getPlatform() == Common::kPlatformPC)) {
+	// this loads the backup palette needed by the PC version of BRA (see setBackground()).
+		BackgroundInfo	paletteInfo;
+		_disk->loadSlide(paletteInfo, "pointer");
+		_backupPal.clone(paletteInfo.palette);
+		paletteInfo.free();
+	}
+
 	return;
 }
 
@@ -867,6 +882,18 @@
 
 	if (type == kBackgroundLocation) {
 		_disk->loadScenery(_backgroundInfo, name, mask, path);
+
+		// The PC version of BRA needs the entries 20-31 of the palette to be constant, but
+		// the background resource files are screwed up. The right colors come from an unused
+		// bitmap (pointer.bmp). Nothing is known about the Amiga version so far.
+		if ((_vm->getGameType() == GType_BRA) && (_vm->getPlatform() == Common::kPlatformPC)) {
+			int r, g, b;
+			for (uint i = 16; i < 32; i++) {
+				_backupPal.getEntry(i, r, g, b);
+				_backgroundInfo.palette.setEntry(i, r, g, b);
+			}
+		}
+
 		setPalette(_backgroundInfo.palette);
 		_palette.clone(_backgroundInfo.palette);
 	} else {

Modified: scummvm/trunk/engines/parallaction/graphics.h
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.h	2008-07-28 05:38:24 UTC (rev 33354)
+++ scummvm/trunk/engines/parallaction/graphics.h	2008-07-28 06:06:35 UTC (rev 33355)
@@ -261,6 +261,7 @@
 
 	void makeBlack();
 	void setEntries(byte* data, uint first, uint num);
+	void getEntry(uint index, int &red, int &green, int &blue);
 	void setEntry(uint index, int red, int green, int blue);
 	void makeGrayscale();
 	void fadeTo(const Palette& target, uint step);
@@ -558,6 +559,9 @@
 	Common::Point		_hbCirclePos;
 	int				_hbCircleRadius;
 
+	// BRA specific
+	Palette				_backupPal;
+
 	// frame data stored in programmable variables
 	int32				_varBackgroundMode;	// 1 = normal, 2 = only mask
 	int32				_varScrollX;

Modified: scummvm/trunk/engines/parallaction/inventory.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.cpp	2008-07-28 05:38:24 UTC (rev 33354)
+++ scummvm/trunk/engines/parallaction/inventory.cpp	2008-07-28 06:06:35 UTC (rev 33355)
@@ -37,7 +37,7 @@
 //	inventory items are stored in cnv files in a 32x24 grid
 //	but only 24x24 pixels are actually copied to graphic memory
 //
-
+/*
 #define INVENTORYITEM_PITCH			32
 #define INVENTORYITEM_WIDTH			24
 #define INVENTORYITEM_HEIGHT		24
@@ -50,8 +50,32 @@
 
 #define INVENTORY_WIDTH				(INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH)
 #define INVENTORY_HEIGHT			(INVENTORY_LINES*INVENTORYITEM_HEIGHT)
+*/
 
+InventoryProperties	_invProps_NS = {
+	32, 		// INVENTORYITEM_PITCH
+	24, 		// INVENTORYITEM_WIDTH
+	24, 		// INVENTORYITEM_HEIGHT
+	30, 		// INVENTORY_MAX_ITEMS
+	4, 			// INVENTORY_FIRST_ITEM		// first four entries are used up by verbs
+	5, 			// INVENTORY_ITEMS_PER_LINE
+	6, 			// INVENTORY_LINES
+	5 * 24, 	// INVENTORY_WIDTH =(INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH)
+	6 * 24		// INVENTORY_HEIGHT = (INVENTORY_LINES*INVENTORYITEM_HEIGHT)
+};
 
+InventoryProperties	_invProps_BR = {
+	51, 		// INVENTORYITEM_PITCH
+	51, 		// INVENTORYITEM_WIDTH
+	51, 		// INVENTORYITEM_HEIGHT
+	48, 		// INVENTORY_MAX_ITEMS
+	4, 			// INVENTORY_FIRST_ITEM		// first four entries are used up by verbs
+	6, 			// INVENTORY_ITEMS_PER_LINE
+	8, 			// INVENTORY_LINES
+	6 * 51, 		// INVENTORY_WIDTH =(INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH)
+	8 * 51			// INVENTORY_HEIGHT = (INVENTORY_LINES*INVENTORYITEM_HEIGHT)
+};
+
 int16 Parallaction::getHoverInventoryItem(int16 x, int16 y) {
 	return _inventoryRenderer->hitTest(Common::Point(x,y));
 }
@@ -95,8 +119,16 @@
 }
 
 void Parallaction::initInventory() {
-	_inventory = new Inventory(INVENTORY_MAX_ITEMS);
-	_inventoryRenderer = new InventoryRenderer(this);
+	InventoryProperties *props;
+
+	if (getGameType() == GType_Nippon) {
+		props = &_invProps_NS;
+	} else {
+		props = &_invProps_BR;
+	}
+
+	_inventory = new Inventory(props);
+	_inventoryRenderer = new InventoryRenderer(this, props);
 	_inventoryRenderer->bindInventory(_inventory);
 }
 
@@ -123,8 +155,8 @@
 
 
 
-InventoryRenderer::InventoryRenderer(Parallaction *vm) : _vm(vm) {
-	_surf.create(INVENTORY_WIDTH, INVENTORY_HEIGHT, 1);
+InventoryRenderer::InventoryRenderer(Parallaction *vm, InventoryProperties *props) : _vm(vm), _props(props) {
+	_surf.create(_props->_width, _props->_height, 1);
 }
 
 InventoryRenderer::~InventoryRenderer() {
@@ -135,15 +167,13 @@
 	if (!_inv)
 		error("InventoryRenderer not bound to inventory");
 
-//	_engineFlags |= kEngineInventory;
-
 	uint16 lines = getNumLines();
 
 	Common::Point p;
 	_vm->_input->getCursorPos(p);
 
-	_pos.x = CLIP(p.x - (INVENTORY_WIDTH / 2), 0, (int)(_vm->_screenWidth - INVENTORY_WIDTH));
-	_pos.y = CLIP(p.y - 2 - (lines * INVENTORYITEM_HEIGHT), 0, (int)(_vm->_screenHeight - lines * INVENTORYITEM_HEIGHT));
+	_pos.x = CLIP((int)(p.x - (_props->_width / 2)), 0, (int)(_vm->_screenWidth - _props->_width));
+	_pos.y = CLIP((int)(p.y - 2 - (lines * _props->_itemHeight)), 0, (int)(_vm->_screenHeight - lines * _props->_itemHeight));
 
 	refresh();
 }
@@ -154,8 +184,8 @@
 }
 
 void InventoryRenderer::getRect(Common::Rect& r) const {
-	r.setWidth(INVENTORY_WIDTH);
-	r.setHeight(INVENTORYITEM_HEIGHT * getNumLines());
+	r.setWidth(_props->_width);
+	r.setHeight(_props->_itemHeight * getNumLines());
 	r.moveTo(_pos);
 }
 
@@ -165,35 +195,36 @@
 	if (!r.contains(p))
 		return -1;
 
-	return ((p.x - _pos.x) / INVENTORYITEM_WIDTH) + (INVENTORY_ITEMS_PER_LINE * ((p.y - _pos.y) / INVENTORYITEM_HEIGHT));
+	return ((p.x - _pos.x) / _props->_itemWidth) + (_props->_itemsPerLine * ((p.y - _pos.y) / _props->_itemHeight));
 }
 
-
 void InventoryRenderer::drawItem(ItemPosition pos, ItemName name) {
-
 	Common::Rect r;
 	getItemRect(pos, r);
+	byte* d = (byte*)_surf.getBasePtr(r.left, r.top);
+	drawItem(name, d, _surf.pitch);
+}
 
-	// FIXME: this will end up in a general blit function
-
+void InventoryRenderer::drawItem(ItemName name, byte *buffer, uint pitch) {
 	byte* s = _vm->_char._objs->getData(name);
-	byte* d = (byte*)_surf.getBasePtr(r.left, r.top);
-	for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
-		memcpy(d, s, INVENTORYITEM_WIDTH);
+	byte* d = buffer;
+	for (uint i = 0; i < _props->_itemHeight; i++) {
+		memcpy(d, s, _props->_itemWidth);
 
-		d += INVENTORY_WIDTH;
-		s += INVENTORYITEM_PITCH;
+		s += _props->_itemPitch;
+		d += pitch;
 	}
 }
 
+
 int16 InventoryRenderer::getNumLines() const {
 	int16 num = _inv->getNumItems();
-	return (num / INVENTORY_ITEMS_PER_LINE) + ((num % INVENTORY_ITEMS_PER_LINE) > 0 ? 1 : 0);
+	return (num / _props->_itemsPerLine) + ((num % _props->_itemsPerLine) > 0 ? 1 : 0);
 }
 
 
 void InventoryRenderer::refresh() {
-	for (uint16 i = 0; i < INVENTORY_MAX_ITEMS; i++) {
+	for (uint16 i = 0; i < _props->_maxItems; i++) {
 		ItemName name = _inv->getItemName(i);
 		drawItem(i, name);
 	}
@@ -214,31 +245,19 @@
 
 void InventoryRenderer::getItemRect(ItemPosition pos, Common::Rect &r) {
 
-	r.setHeight(INVENTORYITEM_HEIGHT);
-	r.setWidth(INVENTORYITEM_WIDTH);
+	r.setHeight(_props->_itemHeight);
+	r.setWidth(_props->_itemWidth);
 
-	uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
-	uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
+	uint16 line = pos / _props->_itemsPerLine;
+	uint16 col = pos % _props->_itemsPerLine;
 
-	r.moveTo(col * INVENTORYITEM_WIDTH, line * INVENTORYITEM_HEIGHT);
+	r.moveTo(col * _props->_itemWidth, line * _props->_itemHeight);
 
 }
 
-void InventoryRenderer::drawItem(ItemName name, byte *buffer, uint pitch) {
-	byte* s = _vm->_char._objs->getData(name);
-	byte* d = buffer;
-	for (uint i = 0; i < INVENTORYITEM_HEIGHT; i++) {
-		memcpy(d, s, INVENTORYITEM_WIDTH);
+Inventory::Inventory(InventoryProperties *props) : _numItems(0), _props(props) {
+	_items = (InventoryItem*)calloc(_props->_maxItems, sizeof(InventoryItem));
 
-		s += INVENTORYITEM_PITCH;
-		d += pitch;
-	}
-}
-
-
-Inventory::Inventory(uint16 maxItems) : _maxItems(maxItems), _numItems(0) {
-	_items = (InventoryItem*)calloc(_maxItems, sizeof(InventoryItem));
-
 	addItem(1, kZoneDoor);
 	addItem(3, kZoneExamine);
 	addItem(2, kZoneGet);
@@ -253,7 +272,7 @@
 ItemPosition Inventory::addItem(ItemName name, uint32 value) {
 	debugC(1, kDebugInventory, "addItem(%i, %i)", name, value);
 
-	if (_numItems == INVENTORY_MAX_ITEMS) {
+	if (_numItems == _props->_maxItems) {
 		debugC(3, kDebugInventory, "addItem: inventory is full");
 		return -1;
 	}
@@ -312,9 +331,9 @@
 void Inventory::clear(bool keepVerbs) {
 	debugC(1, kDebugInventory, "clearInventory()");
 
-	uint first = (keepVerbs ? INVENTORY_FIRST_ITEM : 0);
+	uint first = (keepVerbs ? _props->_firstItem : 0);
 
-	for (uint16 slot = first; slot < _maxItems; slot++) {
+	for (uint16 slot = first; slot < _props->_maxItems; slot++) {
 		_items[slot]._id = 0;
 		_items[slot]._index = 0;
 	}
@@ -324,7 +343,7 @@
 
 
 ItemName Inventory::getItemName(ItemPosition pos) const {
-	return (pos >= 0 && pos < INVENTORY_MAX_ITEMS) ? _items[pos]._index : 0;
+	return (pos >= 0 && pos < _props->_maxItems) ? _items[pos]._index : 0;
 }
 
 const InventoryItem* Inventory::getItem(ItemPosition pos) const {

Modified: scummvm/trunk/engines/parallaction/inventory.h
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.h	2008-07-28 05:38:24 UTC (rev 33354)
+++ scummvm/trunk/engines/parallaction/inventory.h	2008-07-28 06:06:35 UTC (rev 33355)
@@ -38,6 +38,21 @@
 	uint16		_index;			// index to frame in objs file
 };
 
+struct InventoryProperties {
+	uint _itemPitch;
+	uint _itemWidth;
+	uint _itemHeight;
+
+	int _maxItems;
+	int _firstItem;
+
+	int _itemsPerLine;
+	int _maxLines;
+
+	int _width;
+	int _height;
+};
+
 #define MAKE_INVENTORY_ID(x) (((x) & 0xFFFF) << 16)
 
 typedef int16 ItemPosition;
@@ -47,11 +62,11 @@
 
 protected:
 	InventoryItem	*_items;
-	uint16			_maxItems;
 	uint16			_numItems;
+	InventoryProperties *_props;
 
 public:
-	Inventory(uint16 maxItems);
+	Inventory(InventoryProperties *props);
 	virtual ~Inventory();
 
 	ItemPosition addItem(ItemName name, uint32 value);
@@ -71,6 +86,8 @@
 
 class InventoryRenderer {
 	Parallaction	*_vm;
+	InventoryProperties *_props;
+
 	Inventory		*_inv;
 	Common::Point	_pos;
 
@@ -83,7 +100,7 @@
 	void refresh();
 
 public:
-	InventoryRenderer(Parallaction *vm);
+	InventoryRenderer(Parallaction *vm, InventoryProperties *props);
 	virtual ~InventoryRenderer();
 
 	void bindInventory(Inventory *inv) { _inv = inv; }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list