[Scummvm-git-logs] scummvm master -> 0bc61bf5744964f71edb2267e4c6c1f4fc489113

mgerhardy martin.gerhardy at gmail.com
Fri Aug 13 08:42:15 UTC 2021


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:
0bc61bf574 TWINE: allow to re-use parser instances


Commit: 0bc61bf5744964f71edb2267e4c6c1f4fc489113
    https://github.com/scummvm/scummvm/commit/0bc61bf5744964f71edb2267e4c6c1f4fc489113
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-08-13T10:41:13+02:00

Commit Message:
TWINE: allow to re-use parser instances

... by resetting the previously parsed data

Changed paths:
    engines/twine/parser/anim.cpp
    engines/twine/parser/anim.h
    engines/twine/parser/blocklibrary.cpp
    engines/twine/parser/blocklibrary.h
    engines/twine/parser/body.cpp
    engines/twine/parser/body.h
    engines/twine/parser/entity.cpp
    engines/twine/parser/entity.h
    engines/twine/parser/holomap.cpp
    engines/twine/parser/holomap.h
    engines/twine/parser/parser.h
    engines/twine/parser/sprite.cpp
    engines/twine/parser/sprite.h


diff --git a/engines/twine/parser/anim.cpp b/engines/twine/parser/anim.cpp
index 3da3fdcd7c..94d96241f0 100644
--- a/engines/twine/parser/anim.cpp
+++ b/engines/twine/parser/anim.cpp
@@ -52,7 +52,12 @@ void AnimData::loadKeyFrames(Common::SeekableReadStream &stream) {
 	}
 }
 
+void AnimData::reset() {
+	_keyframes.clear();
+}
+
 bool AnimData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+	reset();
 	_numKeyframes = stream.readUint16LE();
 	_numBoneframes = stream.readUint16LE();
 	_loopFrame = stream.readUint16LE();
diff --git a/engines/twine/parser/anim.h b/engines/twine/parser/anim.h
index 318ea6191f..0d56c34f03 100644
--- a/engines/twine/parser/anim.h
+++ b/engines/twine/parser/anim.h
@@ -61,6 +61,9 @@ private:
 	uint16 _numBoneframes;
 	uint16 _loopFrame;
 
+protected:
+	void reset() override;
+
 public:
 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
 
diff --git a/engines/twine/parser/blocklibrary.cpp b/engines/twine/parser/blocklibrary.cpp
index 17bc705b3e..3024df9841 100644
--- a/engines/twine/parser/blocklibrary.cpp
+++ b/engines/twine/parser/blocklibrary.cpp
@@ -25,7 +25,12 @@
 
 namespace TwinE {
 
+void BlockLibraryData::reset() {
+	_layouts.clear();
+}
+
 bool BlockLibraryData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+	reset();
 	const uint32 numLayouts = stream.readUint32LE() / 4;
 	_layouts.resize(numLayouts);
 	stream.seek(0);
diff --git a/engines/twine/parser/blocklibrary.h b/engines/twine/parser/blocklibrary.h
index 0e135ee6af..df9f2796ec 100644
--- a/engines/twine/parser/blocklibrary.h
+++ b/engines/twine/parser/blocklibrary.h
@@ -48,7 +48,8 @@ class BlockLibraryData : public Parser {
 private:
 	Common::Array<BlockData> _layouts;
 	bool parseLayout(BlockData &blockData, Common::SeekableReadStream &stream, bool lba1);
-
+protected:
+	void reset() override;
 public:
 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
 	const BlockData *getLayout(int index) const;
diff --git a/engines/twine/parser/body.cpp b/engines/twine/parser/body.cpp
index e92c74b5a1..eca1a05875 100644
--- a/engines/twine/parser/body.cpp
+++ b/engines/twine/parser/body.cpp
@@ -26,9 +26,17 @@
 
 namespace TwinE {
 
+void BodyData::reset() {
+	_vertices.clear();
+	_bones.clear();
+	_shades.clear();
+	_polygons.clear();
+	_spheres.clear();
+	_lines.clear();
+}
+
 void BodyData::loadVertices(Common::SeekableReadStream &stream) {
 	const uint16 numVertices = stream.readUint16LE();
-	_vertices.clear();
 	_vertices.reserve(numVertices);
 	for (uint16 i = 0U; i < numVertices; ++i) {
 		const int16 x = stream.readSint16LE();
@@ -41,7 +49,6 @@ void BodyData::loadVertices(Common::SeekableReadStream &stream) {
 
 void BodyData::loadBones(Common::SeekableReadStream &stream) {
 	const uint16 numBones = stream.readUint16LE();
-	_bones.clear();
 	_bones.reserve(numBones);
 	for (uint16 i = 0; i < numBones; ++i) {
 		const int16 firstPoint = stream.readSint16LE() / 6;
@@ -81,7 +88,6 @@ void BodyData::loadBones(Common::SeekableReadStream &stream) {
 
 void BodyData::loadShades(Common::SeekableReadStream &stream) {
 	const uint16 numShades = stream.readUint16LE();
-	_shades.clear();
 	_shades.reserve(numShades);
 	for (uint16 i = 0; i < numShades; ++i) {
 		BodyShade shape;
@@ -95,7 +101,6 @@ void BodyData::loadShades(Common::SeekableReadStream &stream) {
 
 void BodyData::loadPolygons(Common::SeekableReadStream &stream) {
 	const uint16 numPolygons = stream.readUint16LE();
-	_polygons.clear();
 	_polygons.reserve(numPolygons);
 	for (uint16 i = 0; i < numPolygons; ++i) {
 		BodyPolygon poly;
@@ -125,7 +130,6 @@ void BodyData::loadPolygons(Common::SeekableReadStream &stream) {
 
 void BodyData::loadLines(Common::SeekableReadStream &stream) {
 	const uint16 numLines = stream.readUint16LE();
-	_lines.clear();
 	_lines.reserve(numLines);
 	for (uint16 i = 0; i < numLines; ++i) {
 		BodyLine line;
@@ -140,7 +144,6 @@ void BodyData::loadLines(Common::SeekableReadStream &stream) {
 
 void BodyData::loadSpheres(Common::SeekableReadStream &stream) {
 	const uint16 numSpheres = stream.readUint16LE();
-	_spheres.clear();
 	_spheres.reserve(numSpheres);
 	for (uint16 i = 0; i < numSpheres; ++i) {
 		BodySphere sphere;
@@ -154,6 +157,7 @@ void BodyData::loadSpheres(Common::SeekableReadStream &stream) {
 }
 
 bool BodyData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+	reset();
 	if (lba1) {
 		bodyFlag.value = stream.readUint16LE();
 		bbox.mins.x = stream.readSint16LE();
diff --git a/engines/twine/parser/body.h b/engines/twine/parser/body.h
index 1b5d541b2a..d1d44e84b9 100644
--- a/engines/twine/parser/body.h
+++ b/engines/twine/parser/body.h
@@ -100,6 +100,9 @@ private:
 
 	BoneFrame _boneStates[560];
 
+protected:
+	void reset() override;
+
 public:
 	union BodyFlags {
 		struct BitMask {
diff --git a/engines/twine/parser/entity.cpp b/engines/twine/parser/entity.cpp
index 3b7204a27d..392c436e28 100644
--- a/engines/twine/parser/entity.cpp
+++ b/engines/twine/parser/entity.cpp
@@ -155,9 +155,13 @@ bool EntityData::loadAnim(Common::SeekableReadStream &stream) {
 	return !stream.err();
 }
 
-bool EntityData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+void EntityData::reset() {
 	_animations.clear();
 	_bodies.clear();
+}
+
+bool EntityData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+	reset();
 	do {
 		const uint8 opcode = stream.readByte();
 		if (opcode == 1) {
diff --git a/engines/twine/parser/entity.h b/engines/twine/parser/entity.h
index 47e673bd90..7cc1f28b7d 100644
--- a/engines/twine/parser/entity.h
+++ b/engines/twine/parser/entity.h
@@ -75,6 +75,9 @@ private:
 	bool loadBody(Common::SeekableReadStream &stream);
 	bool loadAnim(Common::SeekableReadStream &stream);
 
+protected:
+	void reset() override;
+
 public:
 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
 
diff --git a/engines/twine/parser/holomap.cpp b/engines/twine/parser/holomap.cpp
index 3d0dbee960..d5480a3d90 100644
--- a/engines/twine/parser/holomap.cpp
+++ b/engines/twine/parser/holomap.cpp
@@ -26,8 +26,12 @@
 
 namespace TwinE {
 
-bool TrajectoryData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+void TrajectoryData::reset() {
 	_trajectories.clear();
+}
+
+bool TrajectoryData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
+	reset();
 	_trajectories.reserve(100); // this is the lba1 amount of trajectories
 	while (stream.pos() < stream.size()) {
 		Trajectory data;
diff --git a/engines/twine/parser/holomap.h b/engines/twine/parser/holomap.h
index ca84def84f..0960a388a0 100644
--- a/engines/twine/parser/holomap.h
+++ b/engines/twine/parser/holomap.h
@@ -73,7 +73,8 @@ struct Trajectory {
 class TrajectoryData : public Parser {
 private:
 	Common::Array<Trajectory> _trajectories;
-
+protected:
+	void reset() override;
 public:
 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
 
diff --git a/engines/twine/parser/parser.h b/engines/twine/parser/parser.h
index a679a1b29f..ae4ca3c759 100644
--- a/engines/twine/parser/parser.h
+++ b/engines/twine/parser/parser.h
@@ -31,8 +31,12 @@
 namespace TwinE {
 
 class Parser {
+protected:
+	virtual void reset() {}
 public:
-	virtual ~Parser() {}
+	virtual ~Parser() {
+		reset();
+	}
 	virtual bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) = 0;
 
 	bool loadFromBuffer(const uint8 *buf, uint32 size, bool lba1);
diff --git a/engines/twine/parser/sprite.cpp b/engines/twine/parser/sprite.cpp
index 64e78c0eff..e1f9c8f645 100644
--- a/engines/twine/parser/sprite.cpp
+++ b/engines/twine/parser/sprite.cpp
@@ -46,11 +46,7 @@ bool SpriteBoundingBoxData::loadFromStream(Common::SeekableReadStream &stream, b
 	return !stream.err();
 }
 
-SpriteData::~SpriteData() {
-	clear();
-}
-
-void SpriteData::clear() {
+void SpriteData::reset() {
 	for (int i = 0; i < _sprites; ++i) {
 		_surfaces[i].free();
 	}
@@ -58,7 +54,7 @@ void SpriteData::clear() {
 }
 
 bool SpriteData::loadFromStream(Common::SeekableReadStream &stream, bool lba1) {
-	clear();
+	reset();
 	if (_bricks) {
 		// brick sprites don't have the offsets
 		return loadSprite(stream, 0);
diff --git a/engines/twine/parser/sprite.h b/engines/twine/parser/sprite.h
index 853cd75025..5252b7ec70 100644
--- a/engines/twine/parser/sprite.h
+++ b/engines/twine/parser/sprite.h
@@ -74,10 +74,8 @@ protected:
 	bool _bricks = false;
 
 	bool loadSprite(Common::SeekableReadStream &stream, uint32 offset);
-	void clear();
+	void reset() override;
 public:
-	~SpriteData();
-
 	bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
 
 	inline const Graphics::ManagedSurface &surface(int index = 0) const {




More information about the Scummvm-git-logs mailing list