[Scummvm-git-logs] scummvm master -> c11f089402fff487a1cbe72396716b8e6fe4c2b1

bluegr noreply at scummvm.org
Sun Apr 10 18:27:18 UTC 2022


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

Summary:
c11f089402 CHEWY: Remove the Data class


Commit: c11f089402fff487a1cbe72396716b8e6fe4c2b1
    https://github.com/scummvm/scummvm/commit/c11f089402fff487a1cbe72396716b8e6fe4c2b1
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-04-10T21:26:59+03:00

Commit Message:
CHEWY: Remove the Data class

Its functionality is included in the Resource class

Changed paths:
  R engines/chewy/data.cpp
  R engines/chewy/data.h
    engines/chewy/atds.cpp
    engines/chewy/memory.cpp
    engines/chewy/memory.h
    engines/chewy/module.mk
    engines/chewy/ngstypes.cpp
    engines/chewy/ngstypes.h
    engines/chewy/resource.cpp
    engines/chewy/resource.h


diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index 770a43da2de..a33f2cae44c 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -348,8 +348,7 @@ void Atdsys::set_split_win(int16 nr, int16 x, int16 y) {
 }
 
 void Atdsys::set_handle(const char *fname, int16 mode, int16 chunkStart, int16 chunkNr) {
-	ChunkHead Ch;
-	uint32 size = _G(mem)->file->getPoolSize(fname, chunkStart, chunkNr);
+	uint32 size = _text->findLargestChunk(chunkStart, chunkStart + chunkNr);
 	char *tmp_adr = size ? (char *)MALLOC(size + 3) : nullptr;
 
 	if (_atdsMem[mode])
@@ -358,51 +357,31 @@ void Atdsys::set_handle(const char *fname, int16 mode, int16 chunkStart, int16 c
 	_atdsPoolOff[mode] = chunkStart;
 
 	if (mode == INV_USE_DATA) {
-		_G(mem)->file->selectPoolItem(_atdsHandle, _atdsPoolOff[mode]);
-		_atdsHandle->seek(-ChunkHead::SIZE(), SEEK_CUR);
-
-		if (!Ch.load(_atdsHandle))
-			error("Error reading from %s", fname);
+		const uint32 size = _text->getChunk(chunkStart)->size;
+		const uint8 *chunkData = _text->getChunkData(chunkStart);
 
 		free(_invUseMem);
-		_invUseMem = (char *)MALLOC(Ch.size + 3l);
+		_invUseMem = (char *)MALLOC(size + 3l);
+		memcpy(_invUseMem, chunkData, size);
+		delete[] chunkData;
 
-		if (Ch.size) {
-			if (!_atdsHandle->read(_invUseMem, Ch.size)) {
-				error("Error reading from %s", fname);
-			} else {
-				crypt(_invUseMem, Ch.size);
-			}
-		}
-		_invUseMem[Ch.size] = (char)BLOCKENDE;
-		_invUseMem[Ch.size + 1] = (char)BLOCKENDE;
-		_invUseMem[Ch.size + 2] = (char)BLOCKENDE;
+		_invUseMem[size] = (char)BLOCKENDE;
+		_invUseMem[size + 1] = (char)BLOCKENDE;
+		_invUseMem[size + 2] = (char)BLOCKENDE;
 	}
 }
 
 void Atdsys::load_atds(int16 chunkNr, int16 mode) {
 	char *txt_adr = _atdsMem[mode];
 
-	ChunkHead Ch;
 	if (_atdsHandle && txt_adr) {
-		_G(mem)->file->selectPoolItem(_atdsHandle, chunkNr + _atdsPoolOff[mode]);
-		_atdsHandle->seek(-ChunkHead::SIZE(), SEEK_CUR);
-		if (!Ch.load(_atdsHandle)) {
-			error("load_atds error");
-		} else {
-			if (Ch.size) {
-				if (_atdsHandle->read(txt_adr, Ch.size) != Ch.size) {
-					error("load_atds error");
-				} else {
-					crypt(txt_adr, Ch.size);
-				}
-			}
-			txt_adr[Ch.size] = (char)BLOCKENDE;
-			txt_adr[Ch.size + 1] = (char)BLOCKENDE;
-			txt_adr[Ch.size + 2] = (char)BLOCKENDE;
-		}
-	} else {
-		error("load_atds error");
+		const uint32 size = _text->getChunk(chunkNr + _atdsPoolOff[mode])->size;
+		const uint8 *chunkData = _text->getChunkData(chunkNr + _atdsPoolOff[mode]);
+		memcpy(txt_adr, chunkData, size);
+		delete[] chunkData;
+		txt_adr[size] = (char)BLOCKENDE;
+		txt_adr[size + 1] = (char)BLOCKENDE;
+		txt_adr[size + 2] = (char)BLOCKENDE;
 	}
 }
 
diff --git a/engines/chewy/data.cpp b/engines/chewy/data.cpp
deleted file mode 100644
index 5d6aaa7f2c7..00000000000
--- a/engines/chewy/data.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "common/debug.h"
-#include "common/system.h"
-#include "chewy/data.h"
-#include "chewy/ngsdefs.h"
-#include "chewy/globals.h"
-
-namespace Chewy {
-
-void Data::selectPoolItem(Common::File *stream, uint16 nr) {
-	if (stream) {
-		stream->seek(0, SEEK_SET);
-		NewPhead ph;
-		if (!ph.load(stream))
-			error("selectPoolItem error");
-
-		if (!strncmp(ph._id, "NGS", 3)) {
-			if (nr >= ph._poolNr)
-				nr = ph._poolNr - 1;
-
-			stream->seek(-(int)((ph._poolNr - nr) * sizeof(uint32)), SEEK_END);
-			uint32 tmp1 = stream->readUint32LE();
-			stream->seek(tmp1, SEEK_SET);
-		}
-	}
-}
-
-uint32 Data::getPoolSize(const char *filename, int16 chunkStart, int16 chunkNr) {
-	uint32 size = 0;
-
-	Common::File f;
-	if (!f.open(filename))
-		error("getPoolSize error");
-
-	NewPhead Nph;
-	if (!Nph.load(&f))
-		error("getPoolSize error");
-
-	if (!strncmp(Nph._id, "NGS", 3)) {
-		selectPoolItem(&f, chunkStart);
-		f.seek(-ChunkHead::SIZE(), SEEK_CUR);
-
-		for (int16 i = chunkStart; (i < Nph._poolNr) && i < (chunkStart + chunkNr); i++) {
-			ChunkHead ch;
-			if (!ch.load(&f))
-				error("getPoolSize error");
-
-			if (ch.size > size)
-				size = ch.size;
-
-			f.seek(ch.size, SEEK_CUR);
-		}
-	}
-
-	f.close();
-
-	return size;
-}
-
-} // namespace Chewy
diff --git a/engines/chewy/data.h b/engines/chewy/data.h
deleted file mode 100644
index 372233d04f8..00000000000
--- a/engines/chewy/data.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef CHEWY_DATA_H
-#define CHEWY_DATA_H
-
-#include "chewy/chewy.h"
-#include "common/file.h"
-
-namespace Chewy {
-
-class Data {
-public:
-	Data() {}
-	~Data() {}
-
-	void selectPoolItem(Common::File *stream, uint16 nr);
-	uint32 getPoolSize(const char *filename, int16 chunkStart, int16 chunkNr);
-};
-
-} // namespace Chewy
-
-#endif
diff --git a/engines/chewy/memory.cpp b/engines/chewy/memory.cpp
index 1c963782a12..17c1db0de39 100644
--- a/engines/chewy/memory.cpp
+++ b/engines/chewy/memory.cpp
@@ -27,14 +27,6 @@
 
 namespace Chewy {
 
-Memory::Memory() {
-	file = new Data();
-}
-
-Memory::~Memory() {
-	delete (file);
-}
-
 TafInfo *Memory::taf_adr(const char *filename) {
 	SpriteResource *res = new SpriteResource(filename);
 	int32 imageCount = res->getChunkCount();
diff --git a/engines/chewy/memory.h b/engines/chewy/memory.h
index 5d0476d77b1..b8e786f58e8 100644
--- a/engines/chewy/memory.h
+++ b/engines/chewy/memory.h
@@ -22,20 +22,17 @@
 #ifndef CHEWY_MEMORY_H
 #define CHEWY_MEMORY_H
 
-#include "chewy/data.h"
 #include "chewy/ngstypes.h"
 
 namespace Chewy {
 
 class Memory {
 public:
-	Memory();
-	~Memory();
+	Memory() {}
+	~Memory() {}
 
 	TafInfo *taf_adr(const char *filename);
 	TafSeqInfo *taf_seq_adr(int16 image_start, int16 image_anz);
-
-	Data *file;
 };
 
 } // namespace Chewy
diff --git a/engines/chewy/module.mk b/engines/chewy/module.mk
index 3d5f35b6fb6..7319a544f85 100644
--- a/engines/chewy/module.mk
+++ b/engines/chewy/module.mk
@@ -4,7 +4,6 @@ MODULE_OBJS = \
 	atds.o \
 	chewy.o \
 	cursor.o \
-	data.o \
 	debugger.o \
 	detail.o \
 	effect.o \
diff --git a/engines/chewy/ngstypes.cpp b/engines/chewy/ngstypes.cpp
index e29aa501343..0681a0f2aa1 100644
--- a/engines/chewy/ngstypes.cpp
+++ b/engines/chewy/ngstypes.cpp
@@ -48,11 +48,4 @@ bool GedChunkHeader::load(Common::SeekableReadStream *src) {
 	return true;
 }
 
-bool ChunkHead::load(Common::SeekableReadStream *src) {
-	size = src->readUint32LE();
-	type = src->readUint16LE();
-
-	return true;
-}
-
 } // namespace Chewy
diff --git a/engines/chewy/ngstypes.h b/engines/chewy/ngstypes.h
index a569d036d26..ba110a965e8 100644
--- a/engines/chewy/ngstypes.h
+++ b/engines/chewy/ngstypes.h
@@ -86,14 +86,6 @@ struct CurAni {
 	int16 _delay = 0;
 };
 
-struct ChunkHead {
-	uint32 size = 0;
-	uint16 type = 0;
-
-	bool load(Common::SeekableReadStream *src);
-	static constexpr int SIZE() { return 6; }
-};
-
 struct CustomInfo {
 	byte *TempArea = 0;
 };
diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp
index b4ebd8a9d7f..1f918523bf6 100644
--- a/engines/chewy/resource.cpp
+++ b/engines/chewy/resource.cpp
@@ -114,6 +114,15 @@ Chunk *Resource::getChunk(uint num) {
 	return &_chunkList[num];
 }
 
+uint32 Resource::findLargestChunk(uint start, uint end) {
+	uint32 maxSize = 0;
+	for (uint i = start; i < end; i++) {
+		if (_chunkList[i].size > maxSize)
+			maxSize = _chunkList[i].size;
+	}
+	return maxSize;
+}
+
 uint8 *Resource::getChunkData(uint num) {
 	assert(num < _chunkList.size());
 
diff --git a/engines/chewy/resource.h b/engines/chewy/resource.h
index 4237f5317fb..4dbea93900a 100644
--- a/engines/chewy/resource.h
+++ b/engines/chewy/resource.h
@@ -143,6 +143,7 @@ public:
 	uint32 getSize() const {
 		return _stream.size();
 	}
+	uint32 findLargestChunk(uint start, uint end);
 	uint32 getChunkCount() const;
 	Chunk *getChunk(uint num);
 	virtual uint8 *getChunkData(uint num);




More information about the Scummvm-git-logs mailing list