[Scummvm-git-logs] scummvm master -> 830ee285adb3b8a3dc5593c4eb8ea22c595ae535

bluegr noreply at scummvm.org
Sat Mar 5 20:38:35 UTC 2022


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f541a938b7 CHEWY: Cleanup
b285ae3d88 CHEWY: Remove unnecessary local variable
299a81bda8 CHEWY: Use enums for open_handle()
830ee285ad CHEWY: Start refactoring item resources (ADH blocks)


Commit: f541a938b73b8db871f63fb1fd749e048a48e9bd
    https://github.com/scummvm/scummvm/commit/f541a938b73b8db871f63fb1fd749e048a48e9bd
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-05T22:38:11+02:00

Commit Message:
CHEWY: Cleanup

Changed paths:
    engines/chewy/cursor.cpp
    engines/chewy/cursor.h
    engines/chewy/dialogs/files.cpp
    engines/chewy/inits.cpp
    engines/chewy/mcga_graphics.cpp
    engines/chewy/mcga_graphics.h
    engines/chewy/mouse.cpp
    engines/chewy/mouse.h


diff --git a/engines/chewy/cursor.cpp b/engines/chewy/cursor.cpp
index 88d939261b9..0b4cc100c9e 100644
--- a/engines/chewy/cursor.cpp
+++ b/engines/chewy/cursor.cpp
@@ -30,7 +30,6 @@ Cursor::Cursor(McgaGraphics *iout, InputMgr *iin, CurBlk *curblkp) {
 	_in = iin;
 	_scrWidth = _G(scr_w);
 	_curblk = curblkp;
-	_pointer = _in->getPointer();
 
 	_visible = false;
 	_ani = nullptr;
diff --git a/engines/chewy/cursor.h b/engines/chewy/cursor.h
index 0a760af1f8d..2bfe78ce399 100644
--- a/engines/chewy/cursor.h
+++ b/engines/chewy/cursor.h
@@ -42,7 +42,6 @@ public:
 
 	McgaGraphics *_out = nullptr;
 	InputMgr *_in = nullptr;
-	KbdMouseInfo *_pointer = nullptr;
 	CurBlk *_curblk = nullptr;
 	CurAni *_ani = nullptr;
 	int _scrWidth = 0;
diff --git a/engines/chewy/dialogs/files.cpp b/engines/chewy/dialogs/files.cpp
index dc257629caf..f8fc0f4c241 100644
--- a/engines/chewy/dialogs/files.cpp
+++ b/engines/chewy/dialogs/files.cpp
@@ -144,7 +144,6 @@ int16 Files::execute(bool isInGame) {
 		if (mode[QUIT] == 1) {
 			_G(out)->printxy(120, 138, 255, 300, 0, g_engine->getLanguage() == Common::Language::DE_DEU ? QUIT_MSG_DE : QUIT_MSG_EN);
 			_G(out)->back2screen(_G(workpage));
-			_G(in)->alter_kb_handler();
 
 			key = getch();
 			if (key == 'j' || key == 'J' || key == 'y' || key == 'Y' || key == 'z' || key == 'Z') {
@@ -271,7 +270,6 @@ enter:
 			} else if (mode[SAVE]) {
 				_G(out)->back2screen(_G(workpage));
 				_G(out)->setPointer(_G(screen0));
-				_G(in)->alter_kb_handler();
 				tmp = fnames + ((text_off + active_slot) * 40);
 				key = _G(out)->scanxy(70, 68 + (active_slot * 10),
 					255, 42, 14, 0, "%36s36", tmp);
diff --git a/engines/chewy/inits.cpp b/engines/chewy/inits.cpp
index 152f41e24ce..1baf976e837 100644
--- a/engines/chewy/inits.cpp
+++ b/engines/chewy/inits.cpp
@@ -54,7 +54,6 @@ void standard_init() {
 	_G(screen0) = (byte *)g_screen->getPixels();
 	_G(in)->neuer_kb_handler(&_G(kbinfo));
 
-	_G(out)->initMouseMode(&_G(minfo));
 	_G(curblk).page_off_x = 0;
 	_G(curblk).page_off_y = 0;
 	_G(curblk).xsize = 16;
@@ -278,7 +277,6 @@ void init_load() {
 
 void tidy() {
 	sound_exit();
-	_G(in)->alter_kb_handler();
 	free_buffers();
 	_G(obj)->free_inv_spr(&_G(inv_spr)[0]);
 
diff --git a/engines/chewy/mcga_graphics.cpp b/engines/chewy/mcga_graphics.cpp
index 9c29e1a5b88..9d4f7c2007a 100644
--- a/engines/chewy/mcga_graphics.cpp
+++ b/engines/chewy/mcga_graphics.cpp
@@ -190,10 +190,6 @@ void McgaGraphics::back2screen(byte *ptr) {
 	mem2mcga(ptr);
 }
 
-void McgaGraphics::back2back(byte *ptr1, byte *ptr2) {
-	mem2mem(ptr1, ptr2);
-}
-
 void McgaGraphics::sprite_save(byte *sptr, int16 x, int16 y, int16 breite, int16 hoehe, int16 scrwidth) {
 	if (breite < 4)
 		breite = 4;
@@ -710,10 +706,6 @@ void McgaGraphics::move(int16 x, int16 y) {
 	_G(gcury) = y;
 }
 
-void McgaGraphics::initMouseMode(MouseInfo *mInfo) {
-	_mInfo = mInfo;
-}
-
 int16 McgaGraphics::devices() {
 	int16 i = 0;
 	// TODO: This is wrong. 'i' should be initialized to "button status" (BX after a call to Int33h/03
diff --git a/engines/chewy/mcga_graphics.h b/engines/chewy/mcga_graphics.h
index 02c6e01cbe5..6881d2027f8 100644
--- a/engines/chewy/mcga_graphics.h
+++ b/engines/chewy/mcga_graphics.h
@@ -34,7 +34,6 @@ public:
 
 	void init();
 	void setWriteMode(char wm);
-	void initMouseMode(MouseInfo *mInfo);
 
 	void setClip(int16 x1, int16 y1, int16 x2, int16 y2);
 	void setPointer(byte *ptr);
@@ -57,7 +56,6 @@ public:
 	             int16 col1, int16 col2, int16 back_col);
 
 	void back2screen(byte *ptr);
-	void back2back(byte *ptr1, byte *ptr2);
 
 	void sprite_save(byte *sptr, int16 x, int16 y, int16 breite,
 	                 int16 hoehe, int16 scrwidth);
@@ -86,7 +84,6 @@ private:
 	int16 _fontBr = 0, _fontH = 0;
 	uint8 _svga = 0;
 	uint8 _einfuegen = 0;
-	MouseInfo *_mInfo = nullptr;
 
 	void ltoa(long N, char *str, int base);
 	void ultoa(uint32 N, char *str, int base);
diff --git a/engines/chewy/mouse.cpp b/engines/chewy/mouse.cpp
index 8d16d1f6107..d26b3e77527 100644
--- a/engines/chewy/mouse.cpp
+++ b/engines/chewy/mouse.cpp
@@ -28,14 +28,6 @@ namespace Chewy {
 
 bool _cursorMoveFl;
 
-void set_new_kb_handler(KbdInfo *key) {
-	g_events->setKbdInfo(key);
-}
-
-void set_old_kb_handler() {
-	g_events->setKbdInfo(nullptr);
-}
-
 InputMgr::InputMgr() {
 	_kbInfoBlk = nullptr;
 }
@@ -58,21 +50,11 @@ int16 InputMgr::mouseVector(int16 x, int16 y, const int16 *tbl, int16 anz) {
 }
 
 void InputMgr::neuer_kb_handler(KbdInfo *key) {
-	set_new_kb_handler(key);
+	g_events->setKbdInfo(key);
 	_kbInfoBlk = key;
 	_kbInfoBlk->_keyCode = '\0';
 }
 
-void InputMgr::alter_kb_handler() {
-	set_old_kb_handler();
-	_kbInfoBlk = nullptr;
-	warning("STUB - InputMgr::alter_kb_handler");
-#if 0
-	while (kbhit())
-		getch();
-#endif
-}
-
 KbdMouseInfo *InputMgr::getPointer() {
 	_inzeig.kbinfo = _kbInfoBlk;
 
diff --git a/engines/chewy/mouse.h b/engines/chewy/mouse.h
index 33aba5ebe43..cff66978915 100644
--- a/engines/chewy/mouse.h
+++ b/engines/chewy/mouse.h
@@ -26,9 +26,6 @@
 
 namespace Chewy {
 
-void set_new_kb_handler(KbdInfo *key);
-void set_old_kb_handler();
-
 extern bool _cursorMoveFl;
 
 class InputMgr {
@@ -39,7 +36,6 @@ public:
 	void setMousePos(int16 x, int16 y);
 
 	void neuer_kb_handler(KbdInfo *key);
-	void alter_kb_handler();
 	int16 mouseVector(int16 x, int16 y, const int16 *tbl, int16 anz);
 
 	KbdMouseInfo *getPointer();


Commit: b285ae3d88b9db8dd04b9cc38d32b3fa8e7b8714
    https://github.com/scummvm/scummvm/commit/b285ae3d88b9db8dd04b9cc38d32b3fa8e7b8714
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-05T22:38:11+02:00

Commit Message:
CHEWY: Remove unnecessary local variable

This avoids a crash under some race conditions, where this variable
isn't fully initialized

Changed paths:
    engines/chewy/atds.cpp
    engines/chewy/atds.h


diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index 7de9976b109..ad9457f4f9a 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -111,7 +111,6 @@ Atdsys::Atdsys() {
 		_ssi[i] = init_ssi;
 	_invBlockNr = -1;
 	_invUseMem = nullptr;
-	_inzeig = _G(in)->getPointer();
 
 	_atdsStream = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
 	Common::File tmp;
@@ -590,8 +589,9 @@ void Atdsys::print_ats(int16 x, int16 y, int16 scrx, int16 scry) {
 					if (_atsv.SilentCount <= 0 && _atsv.DelayCount > _printDelayCount1) {
 						_mousePush = true;
 						_atsv.DelayCount = 0;
-						_inzeig->kbinfo->scan_code = Common::KEYCODE_INVALID;
-						_inzeig->kbinfo->_keyCode = '\0';
+						KbdInfo *kbInfo = _G(in)->getPointer()->kbinfo;
+						kbInfo->scan_code = Common::KEYCODE_INVALID;
+						kbInfo->_keyCode = '\0';
 					}
 				}
 				break;
@@ -936,8 +936,9 @@ void Atdsys::print_aad(int16 scrx, int16 scry) {
 					if (_aadv.SilentCount <= 0 && _aadv._delayCount > _printDelayCount1) {
 						_mousePush = true;
 						_aadv._delayCount = 0;
-						_inzeig->kbinfo->scan_code = Common::KEYCODE_INVALID;
-						_inzeig->kbinfo->_keyCode = '\0';
+						KbdInfo *kbInfo = _G(in)->getPointer()->kbinfo;
+						kbInfo->scan_code = Common::KEYCODE_INVALID;
+						kbInfo->_keyCode = '\0';
 					}
 				}
 				break;
diff --git a/engines/chewy/atds.h b/engines/chewy/atds.h
index 8106be22786..692fdeb198e 100644
--- a/engines/chewy/atds.h
+++ b/engines/chewy/atds.h
@@ -357,7 +357,6 @@ private:
 	int16 _invBlockNr;
 	char *_invUseMem = nullptr;
 	int16 _tmpDelay;
-	KbdMouseInfo *_inzeig = nullptr;
 	bool _hasSpeech = false;
 	int16 _mousePush = 0;
 	int _printDelayCount1 = 0;


Commit: 299a81bda8c378a4101edf109ca27e2284f7fb0d
    https://github.com/scummvm/scummvm/commit/299a81bda8c378a4101edf109ca27e2284f7fb0d
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-05T22:38:12+02:00

Commit Message:
CHEWY: Use enums for open_handle()

Changed paths:
    engines/chewy/dialogs/cinema.cpp
    engines/chewy/dialogs/credits.cpp
    engines/chewy/dialogs/files.cpp


diff --git a/engines/chewy/dialogs/cinema.cpp b/engines/chewy/dialogs/cinema.cpp
index 0fc7b7897d8..ea4a3959383 100644
--- a/engines/chewy/dialogs/cinema.cpp
+++ b/engines/chewy/dialogs/cinema.cpp
@@ -58,7 +58,7 @@ void Cinema::execute() {
 	_G(fontMgr)->setFont(_G(font6));
 	_G(atds)->load_atds(98, 1);
 
-	_G(room)->open_handle(GBOOK, 0);
+	_G(room)->open_handle(GBOOK, AAD_DATA);
 	_G(room)->load_tgp(4, &_G(room_blk), 1, 0, GBOOK);
 	showCur();
 	EVENTS_CLEAR;
@@ -197,7 +197,7 @@ void Cinema::execute() {
 		SHOULD_QUIT_RETURN;
 	}
 
-	_G(room)->open_handle(EPISODE1, 0);
+	_G(room)->open_handle(EPISODE1, AAD_DATA);
 	_G(room)->set_ak_pal(&_G(room_blk));
 	hideCur();
 	_G(uhr)->resetTimer(0, 5);
diff --git a/engines/chewy/dialogs/credits.cpp b/engines/chewy/dialogs/credits.cpp
index 82235b14814..76ae8322ea4 100644
--- a/engines/chewy/dialogs/credits.cpp
+++ b/engines/chewy/dialogs/credits.cpp
@@ -194,7 +194,7 @@ void Credits::execute() {
 	int lineScrolled = 0;
 	int fontCol;
 
-	_G(room)->open_handle(GBOOK, 0);
+	_G(room)->open_handle(GBOOK, AAD_DATA);
 	_G(room)->load_tgp(5, &_G(room_blk), 1, 0, GBOOK);
 	_G(spieler).scrollx = 0;
 	_G(spieler).scrolly = 0;
diff --git a/engines/chewy/dialogs/files.cpp b/engines/chewy/dialogs/files.cpp
index f8fc0f4c241..3a475f05272 100644
--- a/engines/chewy/dialogs/files.cpp
+++ b/engines/chewy/dialogs/files.cpp
@@ -63,7 +63,7 @@ int16 Files::execute(bool isInGame) {
 	TafInfo *ti = _G(mem)->taf_adr(OPTION_TAF);
 	EVENTS_CLEAR;
 
-	_G(room)->open_handle(GBOOK, 0);
+	_G(room)->open_handle(GBOOK, AAD_DATA);
 	_G(room)->load_tgp(1, &_G(room_blk), GBOOK_TGP, 0, GBOOK);
 	_G(out)->setPointer(_G(workptr));
 	_G(out)->map_spr2screen(_G(ablage)[_G(room_blk).AkAblage], 0, 0);
@@ -295,7 +295,7 @@ enter:
 
 	free(ti);
 
-	_G(room)->open_handle(EPISODE1, 0);
+	_G(room)->open_handle(EPISODE1, AAD_DATA);
 	_G(room)->load_tgp(_G(spieler)._personRoomNr[P_CHEWY], &_G(room_blk), EPISODE1_TGP, GED_LOAD, EPISODE1);
 
 	_G(fx_blend) = BLEND1;


Commit: 830ee285adb3b8a3dc5593c4eb8ea22c595ae535
    https://github.com/scummvm/scummvm/commit/830ee285adb3b8a3dc5593c4eb8ea22c595ae535
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-05T22:38:12+02:00

Commit Message:
CHEWY: Start refactoring item resources (ADH blocks)

This also changes the internal stream to MemorySeekableReadWriteStream
from MemoryReadWriteStream, which better suits our needs

Changed paths:
    engines/chewy/atds.cpp
    engines/chewy/atds.h
    engines/chewy/resource.cpp
    engines/chewy/resource.h


diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index ad9457f4f9a..e22fc511f83 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -112,22 +112,21 @@ Atdsys::Atdsys() {
 	_invBlockNr = -1;
 	_invUseMem = nullptr;
 
-	_atdsStream = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
-	Common::File tmp;
-	tmp.open(ADS_TXT_STEUER);
-	_atdsStreamSize = tmp.size();
-	_atdsStream->writeStream(&tmp, _atdsStreamSize);
-	tmp.close();
+	_itemResource = new ItemResource(ADS_TXT_STEUER);
 }
 
 Atdsys::~Atdsys() {
-	for (int16 i = 0; i < MAX_HANDLE; i++)
+	for (int16 i = 0; i < MAX_HANDLE; i++) {
+		if (i == ADH_HANDLE)
+			continue;
+
 		close_handle(i);
+	}
 
 	if (_invUseMem)
 		free(_invUseMem);
 
-	// NOTE: _atdsStream is deleted by close_handle() above
+	delete _itemResource;
 }
 
 void Atdsys::set_delay(int16 *delay, int16 silent) {
@@ -368,8 +367,11 @@ void Atdsys::open_handle(const char *fname, int16 mode) {
 		if (_atdsmem[mode])
 			free(_atdsmem[mode]);
 
-		_atdshandle[mode] = _atdsStream;
-		_atdsmem[mode] = (char *)MALLOC(_atdsStreamSize + 3);
+		// Set to nullptr on purpose, this shouldn't be used
+		_atdshandle[mode] = nullptr;
+		// +3 bytes to signify the end of the stream (BLOCKENDE)
+		_atdsmem[mode] = (char *)MALLOC(_itemResource->getStreamSize() + 3);
+		_itemResource->readFromStream((byte *)_atdsmem[mode]);
 		_adsBlock = (AdsBlock *)_atdsmem[mode];
 		return;
 	}
@@ -398,6 +400,9 @@ void Atdsys::close_handle(int16 mode) {
 		_atdshandle[mode] = nullptr;
 
 		for (int i = 0; i < MAX_HANDLE; ++i) {
+			if (i == ADH_HANDLE)
+				continue;
+
 			if (_atdshandle[i] == stream)
 				_atdshandle[i] = nullptr;
 		}
@@ -419,8 +424,18 @@ char *Atdsys::atds_adr(const char *fname, int16 chunk_start, int16 chunk_anz) {
 }
 
 void Atdsys::load_atds(int16 chunk_nr, int16 mode) {
-	ChunkHead Ch;
 	char *txt_adr = _atdsmem[mode];
+
+	if (mode == ADH_DATA) {
+		uint32 streamSize = _itemResource->getStreamSize();
+		_itemResource->writeToStream((byte *)_atdsmem[ADH_HANDLE]);
+		txt_adr[streamSize] = (char)BLOCKENDE;
+		txt_adr[streamSize + 1] = (char)BLOCKENDE;
+		txt_adr[streamSize + 2] = (char)BLOCKENDE;
+		return;
+	}
+
+	ChunkHead Ch;
 	Common::SeekableReadStream *stream = dynamic_cast<Common::SeekableReadStream *>(_atdshandle[mode]);
 
 	if (stream && txt_adr) {
@@ -446,25 +461,7 @@ void Atdsys::load_atds(int16 chunk_nr, int16 mode) {
 }
 
 void Atdsys::save_ads_header(int16 dia_nr) {
-	ChunkHead Ch;
-	if (_atdshandle[ADH_HANDLE]) {
-		_G(mem)->file->select_pool_item(_atdshandle[ADH_HANDLE], dia_nr);
-		Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(
-			_atdshandle[ADH_HANDLE]);
-
-		rs->seek(-ChunkHead::SIZE(), SEEK_CUR);
-
-		if (!Ch.load(rs)) {
-			error("save_ads_header error");
-		} else {
-			if (Ch.size) {
-				_atdsStream->seek(rs->pos(), SEEK_SET);
-				_atdsStream->write(_atdsmem[ADH_HANDLE], Ch.size);
-			}
-		}
-	} else {
-		error("save_ads_header error");
-	}
+	_itemResource->writeToStream((byte *)_atdsmem[ADH_HANDLE]);
 }
 
 void Atdsys::crypt(char *txt, uint32 size) {
@@ -1416,16 +1413,14 @@ int16 Atdsys::getStereoPos(int16 x) {
 }
 
 void Atdsys::saveAtdsStream(Common::WriteStream *stream) {
-	_atdsStream->seek(0, SEEK_SET);
-	stream->writeStream(_atdsStream, _atdsStreamSize);
+	_itemResource->saveStream(stream);
 }
 
 void Atdsys::loadAtdsStream(Common::SeekableReadStream* stream) {
-	_atdsStream->seek(0, SEEK_SET);
-	_atdsStream->writeStream(stream, _atdsStreamSize);
+	_itemResource->loadStream(stream);
 }
 
 uint32 Atdsys::getAtdsStreamSize() const {
-	return _atdsStreamSize;
+	return _itemResource->getStreamSize();
 }
 } // namespace Chewy
diff --git a/engines/chewy/atds.h b/engines/chewy/atds.h
index 692fdeb198e..79c7d40cbc6 100644
--- a/engines/chewy/atds.h
+++ b/engines/chewy/atds.h
@@ -23,6 +23,7 @@
 #define CHEWY_ATDS_H
 
 #include "common/memstream.h"
+#include "chewy/resource.h"
 
 namespace Chewy {
 
@@ -360,8 +361,7 @@ private:
 	bool _hasSpeech = false;
 	int16 _mousePush = 0;
 	int _printDelayCount1 = 0;
-	Common::MemoryReadWriteStream *_atdsStream;
-	uint32 _atdsStreamSize;
+	ItemResource *_itemResource;
 };
 
 } // namespace Chewy
diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp
index eba6ca00e25..53351b64051 100644
--- a/engines/chewy/resource.cpp
+++ b/engines/chewy/resource.cpp
@@ -26,6 +26,7 @@
 #include "graphics/pixelformat.h"
 #include "graphics/surface.h"
 
+#include "chewy/atds.h"
 #include "chewy/chewy.h"
 #include "chewy/resource.h"
 
@@ -327,4 +328,91 @@ Common::SeekableReadStream *VideoResource::getVideoStream(uint num) {
 	return new Common::SeekableSubReadStream(&_stream, chunk->pos, chunk->pos + chunk->size);
 }
 
+ItemResource::ItemResource(Common::String filename) : Resource(filename) {
+	_itemBuffer = new byte[_stream.size()];
+	_stream.seek(0, SEEK_SET);
+	_itemStream = new Common::MemorySeekableReadWriteStream(_itemBuffer, _stream.size());
+	_itemStream->writeStream(&_stream);
+}
+
+ItemResource::~ItemResource() {
+	delete _itemStream;
+	delete _itemBuffer;
+}
+
+ItemChunk *ItemResource::getItem(uint block) {
+	Chunk *chunk = &_chunkList[block];
+	ItemChunk *item = new ItemChunk();
+
+	_itemStream->seek(chunk->pos, SEEK_SET);
+
+	_itemStream->read(item->show, 6);
+	_itemStream->read(item->next, 6);
+	_itemStream->read(item->flags, 6);
+
+	return item;
+}
+
+bool ItemResource::isItemShown(uint block, uint num) {
+	Chunk *chunk = &_chunkList[block];
+
+	_itemStream->seek(chunk->pos, SEEK_SET);
+
+	_itemStream->skip(num);
+	return _itemStream->readByte();
+}
+
+void ItemResource::setItemShown(uint block, uint num, bool shown) {
+	Chunk *chunk = &_chunkList[block];
+
+	_itemStream->seek(chunk->pos, SEEK_SET);
+
+	_itemStream->skip(num);
+	_itemStream->writeByte(shown ? 1 : 0);
+}
+
+bool ItemResource::hasExitBit(uint block, uint num) {
+	ItemChunk *item = getItem(block);
+	const bool isExit = (item->flags[num] & ADS_EXIT_BIT) != 0;
+	delete item;
+
+	return isExit;
+}
+
+bool ItemResource::hasRestartBit(uint block, uint num) {
+	ItemChunk *item = getItem(block);
+	const bool isRestart = (item->flags[num] & ADS_RESTART_BIT) != 0;
+	delete item;
+
+	return isRestart;
+}
+
+bool ItemResource::hasShowBit(uint block, uint num) {
+	ItemChunk *item = getItem(block);
+	const bool isShown = (item->flags[num] & ADS_SHOW_BIT) != 0;
+	delete item;
+
+	return isShown;
+}
+
+void ItemResource::loadStream(Common::SeekableReadStream *s) {
+	_itemStream->seek(0, SEEK_SET);
+	_itemStream->writeStream(s, _stream.size());
+}
+
+void ItemResource::saveStream(Common::WriteStream* s) {
+	_itemStream->seek(0, SEEK_SET);
+	s->writeStream(_itemStream, _stream.size());
+}
+
+void ItemResource::readFromStream(byte *data) {
+	_itemStream->seek(0, SEEK_SET);
+	_itemStream->read(data, _stream.size());
+}
+
+void ItemResource::writeToStream(byte *data) {
+	_itemStream->seek(0, SEEK_SET);
+	_itemStream->write(data, _stream.size());
+}
+
 }
diff --git a/engines/chewy/resource.h b/engines/chewy/resource.h
index bd5399d73bb..85648e49d03 100644
--- a/engines/chewy/resource.h
+++ b/engines/chewy/resource.h
@@ -28,6 +28,7 @@
 #include "common/str.h"
 #include "common/hashmap.h"
 #include "common/hash-str.h"
+#include "common/memstream.h"
 #include "common/random.h"
 #include "common/stream.h"
 #include "graphics/surface.h"
@@ -113,6 +114,15 @@ struct VideoChunk {
 	uint32 firstFrameOffset;
 };
 
+// Item chunk header (AdsBlock)
+// Original values are in diah.adh, and are synced
+// to saved games
+struct ItemChunk {
+	bool show[6];
+	uint8 next[6];
+	uint8 flags[6];
+};
+
 enum VideoFrameType {
 	kVideoFrameNormal = 0xF1FA,
 	kVideoFrameCustom = 0xFAF1
@@ -129,6 +139,9 @@ public:
 	ResourceType getType() const {
 		return _resType;
 	}
+	uint32 getSize() const {
+		return _stream.size();
+	}
 	uint32 getChunkCount() const;
 	Chunk *getChunk(uint num);
 	virtual uint8 *getChunkData(uint num);
@@ -190,6 +203,35 @@ public:
 	Common::SeekableReadStream *getVideoStream(uint num);
 };
 
+class ItemResource : public Resource {
+public:
+	ItemResource(Common::String filename);
+	virtual ~ItemResource();
+
+	ItemChunk *getItem(uint block);
+	bool isItemShown(uint block, uint num);
+	void setItemShown(uint block, uint num, bool shown);
+	bool hasExitBit(uint block, uint num);
+	bool hasRestartBit(uint block, uint num);
+	bool hasShowBit(uint block, uint num);
+
+	void loadStream(Common::SeekableReadStream *s);
+	void saveStream(Common::WriteStream *s);
+
+	uint32 getStreamSize() const {
+		return _stream.size();
+	}
+
+	// HACK: The following functions allow direct access
+	// to the stream, and should be removed
+	void readFromStream(byte *data);
+	void writeToStream(byte *data);
+
+private:
+	Common::MemorySeekableReadWriteStream *_itemStream;
+	byte *_itemBuffer;
+};
+
 } // namespace Chewy
 
 #endif




More information about the Scummvm-git-logs mailing list