[Scummvm-git-logs] scummvm master -> 89aefb77945b21ecb4670c1fb24356a31d08c3af

somaen noreply at scummvm.org
Thu May 26 19:10:12 UTC 2022


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

Summary:
1a2f18e421 TINSEL: Further refactor InventoryObjects
fa8e3c506b TINSEL: Replace LockMem with GetMultiInit for MULTI_INIT
ec9c630fc5 TINSEL: Replace LockMem with GetFrame for FRAME
fa7d448051 TINSEL: Refactor IsInPolygon to be partially a member-function
e92fafb955 TINSEL: Minor style-fixes
89aefb7794 TINSEL: Implement InventoryOrNotebookActive


Commit: 1a2f18e421efb221832ef8e16463ca9bc1991060
    https://github.com/scummvm/scummvm/commit/1a2f18e421efb221832ef8e16463ca9bc1991060
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T21:02:05+02:00

Commit Message:
TINSEL: Further refactor InventoryObjects

So that we don't need vtables for the InventoryObject-objects, only
for the container.

Changed paths:
    engines/tinsel/dialogs.cpp
    engines/tinsel/dialogs.h
    engines/tinsel/inv_objects.cpp
    engines/tinsel/inv_objects.h
    engines/tinsel/noir/notebook.cpp


diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp
index 42eea9948db..d9bf38c29b1 100644
--- a/engines/tinsel/dialogs.cpp
+++ b/engines/tinsel/dialogs.cpp
@@ -1185,6 +1185,18 @@ const InventoryObject *Dialogs::GetInvObject(int id) {
 	return object;
 }
 
+/**
+ * Convert item ID number to pointer to item's compiled data
+ * i.e. Image data and Glitter code.
+ */
+const InventoryObjectT3 *Dialogs::GetInvObjectT3(int id) {
+	auto object = _invObjects->GetInvObjectT3(id);
+	if (!object) {
+		error("GetInvObjectT3(%d): Trying to manipulate undefined inventory icon", id);
+	}
+	return object;
+}
+
 /**
  * Returns true if the given id represents a valid inventory object
  */
diff --git a/engines/tinsel/dialogs.h b/engines/tinsel/dialogs.h
index 9bba1f88786..923b8dd62b6 100644
--- a/engines/tinsel/dialogs.h
+++ b/engines/tinsel/dialogs.h
@@ -352,6 +352,7 @@ public:
 	void FillInInventory();
 	void InvCursor(InvCursorFN fn, int CurX, int CurY);
 	const InventoryObject *GetInvObject(int id);
+	const InventoryObjectT3 *GetInvObjectT3(int id);
 	bool UpdateString(const Common::KeyState &kbd);
 	bool InventoryIsActive() { return _inventoryState == ACTIVE_INV; }
 	bool IsMixingDeskControl() { return _invDragging == ID_MDCONT; }
diff --git a/engines/tinsel/inv_objects.cpp b/engines/tinsel/inv_objects.cpp
index b754a76dcf2..00082576da8 100644
--- a/engines/tinsel/inv_objects.cpp
+++ b/engines/tinsel/inv_objects.cpp
@@ -29,55 +29,19 @@ InventoryObject::InventoryObject(Common::MemoryReadStreamEndian &stream) {
 	_id = stream.readUint32();
 	_hIconFilm = stream.readUint32();
 	_hScript = stream.readUint32();
-}
-
-int32 InventoryObject::getUnknown() const {
-	error("Querying Noir-value from non-Noir game");
-}
-
-int32 InventoryObject::getTitle() const {
-	error("Querying Noir-value from non-Noir game");
-}
-
-class InventoryObjectT1 : public InventoryObject {
-public:
-	InventoryObjectT1(Common::MemoryReadStreamEndian &stream) : InventoryObject(stream) {
+	if (TinselVersion == 0) {
+		_attribute = 0;
+	} else {
 		_attribute = stream.readUint32();
 	}
-	// Tinsel1+
-	virtual int32 getAttribute() const {
-		return _attribute;
-	};
-	static const int SIZE = InventoryObject::SIZE + 4;
-private:
-	int32 _attribute;
-};
-
-class InventoryObjectT3 : public InventoryObjectT1 {
-public:
-	InventoryObjectT3(Common::MemoryReadStreamEndian &stream) : InventoryObjectT1(stream) {
-		_unknown = stream.readUint32();
-		_title = stream.readUint32();
-	}
-	// Noir:
-	virtual int32 getUnknown() const {
-		return _unknown;
-	}
-	virtual int32 getTitle() const {
-		return _title;
-	}
-	static const int SIZE = InventoryObjectT1::SIZE + 8;
-private:
-	int32 _unknown;
-	int32 _title;
-};
+}
 
 template<typename T>
 class InventoryObjectsImpl : public InventoryObjects {
 public:
 	InventoryObjectsImpl(const byte *objects, int numObjects) {
 		bool bigEndian = (TinselV1Mac || TinselV1Saturn);
-		auto stream = new Common::MemoryReadStreamEndian(objects, T::SIZE * numObjects, bigEndian, DisposeAfterUse::NO);
+		auto stream = new Common::MemoryReadStreamEndian(objects, T::SIZE() * numObjects, bigEndian, DisposeAfterUse::NO);
 		for (int i = 0; i < numObjects; i++) {
 			_objects.push_back(T(*stream));
 		}
@@ -85,22 +49,24 @@ public:
 		delete stream;
 	}
 	~InventoryObjectsImpl(){};
-	const InventoryObject *GetInvObject(int id) {
+	const InventoryObject *GetInvObject(int id) override {
 		auto index = GetObjectIndexIfExists(id);
 		if (index != -1) {
 			return _objects.data() + index;
 		}
 		return nullptr;
 	}
-	const InventoryObject *GetObjectByIndex(int index) const {
+	const InventoryObjectT3 *GetInvObjectT3(int id) override;
+
+	const InventoryObject *GetObjectByIndex(int index) const override {
 		assert(index >= 0 && index < numObjects());
 		return _objects.data() + index;
 	}
-	void SetObjectFilm(int id, SCNHANDLE hFilm) {
+	void SetObjectFilm(int id, SCNHANDLE hFilm) override {
 		int index = GetObjectIndexIfExists(id);
 		_objects[index].setIconFilm(hFilm);
 	}
-	int GetObjectIndexIfExists(int id) const {
+	int GetObjectIndexIfExists(int id) const override {
 		for (uint i = 0; i < _objects.size(); i++) {
 			if (_objects[i].getId() == id) {
 				return i;
@@ -108,21 +74,33 @@ public:
 		}
 		return -1;
 	};
-	int numObjects() const {
+	int numObjects() const override {
 		return _objects.size();
 	}
 private:
 	Common::Array<T> _objects;
 };
 
+template<>
+const InventoryObjectT3 *InventoryObjectsImpl<InventoryObjectT3>::GetInvObjectT3(int id) {
+	auto index = GetObjectIndexIfExists(id);
+	if (index != -1) {
+		return _objects.data() + index;
+	}
+	return nullptr;
+}
+
+template<>
+const InventoryObjectT3 *InventoryObjectsImpl<InventoryObject>::GetInvObjectT3(int id) {
+	error("Can't query Noir inventory objects from non Noir-game");
+}
+
 InventoryObjects *InstantiateInventoryObjects(const byte *invObjects, int numObjects) {
 	switch (TinselVersion) {
-	case 0:
-		return new InventoryObjectsImpl<InventoryObject>(invObjects, numObjects);
 	case 3:
 		return new InventoryObjectsImpl<InventoryObjectT3>(invObjects, numObjects);
 	default:
-		return new InventoryObjectsImpl<InventoryObjectT1>(invObjects, numObjects);
+		return new InventoryObjectsImpl<InventoryObject>(invObjects, numObjects);
 	}
 }
 
diff --git a/engines/tinsel/inv_objects.h b/engines/tinsel/inv_objects.h
index daa9fb5a45d..3add4afd52b 100644
--- a/engines/tinsel/inv_objects.h
+++ b/engines/tinsel/inv_objects.h
@@ -23,6 +23,7 @@
 #define TINSEL_INV_OBJECT_H
 
 #include "common/memstream.h"
+#include "tinsel/tinsel.h"
 #include "tinsel/dw.h"
 
 namespace Tinsel {
@@ -49,7 +50,6 @@ enum class InvObjAttr {
 class InventoryObject {
 public:
 	InventoryObject(Common::MemoryReadStreamEndian &stream);
-	virtual ~InventoryObject() {}
 	int32 getId() const { return _id; }
 	SCNHANDLE getIconFilm() const { return _hIconFilm; };
 	void setIconFilm(SCNHANDLE hIconFilm) { _hIconFilm = hIconFilm; }
@@ -58,25 +58,52 @@ public:
 	bool hasAttribute(InvObjAttr attribute) const {
 		return getAttribute() & (int32)attribute;
 	}
-	// Noir:
-	virtual int32 getUnknown() const;
-	virtual int32 getTitle() const;
-	static const int SIZE = 12;
+
+	// Data size consumed by constructor
+	static int SIZE() {
+		return (TinselVersion == 0 ? T0_SIZE : T1_SIZE);
+	}
 protected:
+	static const int T0_SIZE = 3 * 4;
+	static const int T1_SIZE = T0_SIZE + 4; // Versions above 0 have attributes
 	// Tinsel 1+
-	virtual int32 getAttribute() const {
-		return 0;
+	int32 getAttribute() const {
+		return _attribute;
 	};
 private:
 	int32 _id;            // inventory objects id
 	SCNHANDLE _hIconFilm; // inventory objects animation film
 	SCNHANDLE _hScript;   // inventory objects event handling script
+	int32 _attribute = 0;
+};
+
+class InventoryObjectT3 : public InventoryObject {
+public:
+	InventoryObjectT3(Common::MemoryReadStreamEndian &stream) : InventoryObject(stream) {
+		_unknown = stream.readUint32();
+		_title = stream.readUint32();
+	}
+	// Noir:
+	int32 getUnknown() const {
+		return _unknown;
+	}
+	int32 getTitle() const {
+		return _title;
+	}
+	// Data size consumed by constructor
+	static int SIZE() {
+		return InventoryObject::SIZE() + 8;
+	}
+private:
+	int32 _unknown;
+	int32 _title;
 };
 
 class InventoryObjects {
 public:
 	virtual ~InventoryObjects() {};
 	virtual const InventoryObject *GetInvObject(int id) = 0;
+	virtual const InventoryObjectT3 *GetInvObjectT3(int id) = 0;
 	virtual const InventoryObject *GetObjectByIndex(int index) const = 0;
 	virtual void SetObjectFilm(int id, SCNHANDLE hFilm) = 0;
 	virtual int GetObjectIndexIfExists(int id) const = 0;
diff --git a/engines/tinsel/noir/notebook.cpp b/engines/tinsel/noir/notebook.cpp
index b8022c0319d..21e93b04632 100644
--- a/engines/tinsel/noir/notebook.cpp
+++ b/engines/tinsel/noir/notebook.cpp
@@ -26,14 +26,14 @@
 namespace Tinsel {
 
 void Notebook::AddHyperlink(int32 id1, int32 id2) {
-	auto *invObject = _vm->_dialogs->GetInvObject(id1);
+	auto *invObject = _vm->_dialogs->GetInvObjectT3(id1);
 
 	if (invObject->getTitle() != 0) {
 		error("A clue can only be hyperlinked if it only has one title!");
 		return;
 	}
 
-	invObject = _vm->_dialogs->GetInvObject(id2);
+	invObject = _vm->_dialogs->GetInvObjectT3(id2);
 
 	if (invObject->getTitle() != 0) {
 		error("A clue can only be hyperlinked if it only has one title!");


Commit: fa8e3c506b93b272271d33663fee85bd86651526
    https://github.com/scummvm/scummvm/commit/fa8e3c506b93b272271d33663fee85bd86651526
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T21:04:36+02:00

Commit Message:
TINSEL: Replace LockMem with GetMultiInit for MULTI_INIT

Changed paths:
  A engines/tinsel/film.cpp
    engines/tinsel/bg.cpp
    engines/tinsel/cursor.cpp
    engines/tinsel/dialogs.cpp
    engines/tinsel/film.h
    engines/tinsel/module.mk
    engines/tinsel/movers.cpp
    engines/tinsel/multiobj.cpp
    engines/tinsel/play.cpp


diff --git a/engines/tinsel/bg.cpp b/engines/tinsel/bg.cpp
index d3af752cf70..db9468cfd72 100644
--- a/engines/tinsel/bg.cpp
+++ b/engines/tinsel/bg.cpp
@@ -64,7 +64,7 @@ void BGmainProcess(CORO_PARAM, const void *param) {
 			pReel = (const FREEL *)param;
 
 			// Get the MULTI_INIT structure
-			pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pReel->mobj));
+			pmi = pReel->GetMultiInit();
 
 			// Initialize and insert the object, and initialize its script.
 			_vm->_bg->_pBG[0] = MultiInitObject(pmi);
@@ -79,7 +79,7 @@ void BGmainProcess(CORO_PARAM, const void *param) {
 			int i;
 			for (i = 0; i < _vm->_bg->_bgReels; i++) {
 				// Get the MULTI_INIT structure
-				pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pFilm->reels[i].mobj));
+				pmi = pFilm->reels[i].GetMultiInit();
 
 				// Initialize and insert the object, and initialize its script.
 				_vm->_bg->_pBG[i] = MultiInitObject(pmi);
@@ -138,7 +138,7 @@ void BGotherProcess(CORO_PARAM, const void *param) {
 	CORO_END_CONTEXT(_ctx);
 
 	const FREEL *pReel = (const FREEL *)param;
-	const MULTI_INIT *pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pReel->mobj));
+	const MULTI_INIT *pmi = pReel->GetMultiInit();
 
 	CORO_BEGIN_CODE(_ctx);
 
@@ -168,7 +168,7 @@ void Background::StartupBackground(CORO_PARAM, SCNHANDLE hFilm) {
 	const FREEL *pfr = &pfilm->reels[0];
 
 	if (TinselVersion != 3) {
-		const MULTI_INIT *pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfr->mobj));
+		const MULTI_INIT *pmi = pfr->GetMultiInit();
 		const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
 		const IMAGE *pim = _vm->_handle->GetImage(READ_32(pFrame));
 		SetBackPal(pim->hImgPal);
diff --git a/engines/tinsel/cursor.cpp b/engines/tinsel/cursor.cpp
index 9cbc534c366..a6d3ccc388c 100644
--- a/engines/tinsel/cursor.cpp
+++ b/engines/tinsel/cursor.cpp
@@ -89,7 +89,7 @@ void Cursor::InitCurTrailObj(int i, int x, int y) {
 
 	const FILM *pFilm = (const FILM *)_vm->_handle->LockMem(_cursorFilm);
 	const FREEL *pfr = (const FREEL *)&pFilm->reels[i + 1];
-	const MULTI_INIT *pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfr->mobj));
+	const MULTI_INIT *pmi = pfr->GetMultiInit();
 
 	PokeInPalette(pmi);
 
@@ -303,7 +303,7 @@ void Cursor::DelAuxCursor() {
 void Cursor::SetAuxCursor(SCNHANDLE hFilm) {
 	const FILM *pfilm = (const FILM *)_vm->_handle->LockMem(hFilm);
 	const FREEL *pfr = &pfilm->reels[0];
-	const MULTI_INIT *pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfr->mobj));
+	const MULTI_INIT *pmi = pfr->GetMultiInit();
 	const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
 	const IMAGE *pim;
 	int	x, y;		// Cursor position
@@ -418,7 +418,7 @@ void Cursor::DoCursorMove() {
 void Cursor::InitCurObj() {
 	const FILM *pFilm = (const FILM *)_vm->_handle->LockMem(_cursorFilm);
 	const FREEL *pfr = (const FREEL *)&pFilm->reels[0];
-	const MULTI_INIT *pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfr->mobj));
+	const MULTI_INIT *pmi = pfr->GetMultiInit();
 
 	if (TinselVersion != 3) {
 		PokeInPalette(pmi);
diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp
index d9bf38c29b1..cb414a6bc53 100644
--- a/engines/tinsel/dialogs.cpp
+++ b/engines/tinsel/dialogs.cpp
@@ -2266,7 +2266,7 @@ OBJECT *Dialogs::AddInvObject(int num, const FREEL **pfreel, const FILM **pfilm)
 	auto invObj = GetInvObject(num);
 	const FILM *pFilm = (const FILM *)_vm->_handle->LockMem(invObj->getIconFilm());
 	const FREEL *pfr = (const FREEL *)&pFilm->reels[0];
-	const MULTI_INIT *pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfr->mobj));
+	const MULTI_INIT *pmi = pfr->GetMultiInit();
 	OBJECT *pPlayObj; // The object we insert
 
 	*pfreel = pfr;
@@ -2397,7 +2397,7 @@ void Dialogs::AddTitle(OBJECT **title, const Common::Rect &bounds) {
  * Insert a part of the inventory window frame onto the display list.
  */
 OBJECT *Dialogs::AddObject(const FREEL *pfreel, int num) {
-	const MULTI_INIT *pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfreel->mobj));
+	const MULTI_INIT *pmi = pfreel->GetMultiInit();
 	const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
 	const IMAGE *pim;
 	OBJECT *pPlayObj;
@@ -3144,7 +3144,7 @@ bool Dialogs::RePosition() {
 void Dialogs::AlterCursor(int num) {
 	const FILM *pFilm = (const FILM *)_vm->_handle->LockMem(_hWinParts);
 	const FREEL *pfr = (const FREEL *)&pFilm->reels[num];
-	const MULTI_INIT *pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfr->mobj));
+	const MULTI_INIT *pmi = pfr->GetMultiInit();
 
 	PokeInPalette(pmi);
 
diff --git a/engines/tinsel/film.cpp b/engines/tinsel/film.cpp
new file mode 100644
index 00000000000..10a6f2d03fc
--- /dev/null
+++ b/engines/tinsel/film.cpp
@@ -0,0 +1,36 @@
+/* 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 "tinsel/film.h"
+#include "tinsel/handle.h"
+#include "tinsel/tinsel.h"
+
+namespace Tinsel {
+
+MULTI_INIT *FREEL::GetMultiInit() {
+	return (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(mobj));
+}
+
+const MULTI_INIT *FREEL::GetMultiInit() const {
+	return (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(mobj));
+}
+
+} // End of namespace Tinsel
diff --git a/engines/tinsel/film.h b/engines/tinsel/film.h
index 74ac52245e5..37d8621fc1b 100644
--- a/engines/tinsel/film.h
+++ b/engines/tinsel/film.h
@@ -28,9 +28,13 @@ namespace Tinsel {
 
 #include "common/pack-start.h"	// START STRUCT PACKING
 
+struct MULTI_INIT;
 struct FREEL {
 	SCNHANDLE mobj;
 	SCNHANDLE script;
+
+	MULTI_INIT *GetMultiInit();
+	const MULTI_INIT *GetMultiInit() const;
 } PACKED_STRUCT;
 
 struct FILM {
diff --git a/engines/tinsel/module.mk b/engines/tinsel/module.mk
index 7edd3eacb3d..5a5f2693196 100644
--- a/engines/tinsel/module.mk
+++ b/engines/tinsel/module.mk
@@ -17,6 +17,7 @@ MODULE_OBJS := \
 	effect.o \
 	events.o \
 	faders.o \
+	film.o \
 	font.o \
 	graphics.o \
 	handle.o \
diff --git a/engines/tinsel/movers.cpp b/engines/tinsel/movers.cpp
index 94b52c09565..d44bedad29a 100644
--- a/engines/tinsel/movers.cpp
+++ b/engines/tinsel/movers.cpp
@@ -718,7 +718,7 @@ static void InitialPathChecks(MOVER *pMover, int xpos, int ypos) {
 
 static void MoverProcessHelper(int X, int Y, int id, MOVER *pMover) {
 	const FILM *pfilm = (const FILM *)_vm->_handle->LockMem(pMover->walkReels[0][FORWARD]);
-	const MULTI_INIT *pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pfilm->reels[0].mobj));
+	const MULTI_INIT *pmi = pfilm->reels[0].GetMultiInit();
 
 	assert(_vm->_bg->BgPal()); // Can't start actor without a background palette
 	assert(pMover->walkReels[0][FORWARD]); // Starting actor process without walk reels
@@ -812,7 +812,7 @@ void T2MoverProcess(CORO_PARAM, const void *param) {
 	MOVER *pMover = rpos->pMover;
 	int i;
 	FILM *pFilm;
-	MULTI_INIT *pmi;
+	const MULTI_INIT *pmi;
 
 	CORO_BEGIN_CODE(_ctx);
 
@@ -826,7 +826,7 @@ void T2MoverProcess(CORO_PARAM, const void *param) {
 	InitialPathChecks(pMover, rpos->X, rpos->Y);
 
 	pFilm = (FILM *)_vm->_handle->LockMem(pMover->walkReels[i][FORWARD]); // Any old reel
-	pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pFilm->reels[0].mobj));
+	pmi = pFilm->reels[0].GetMultiInit();
 
 	// Poke in the background palette
 	PokeInPalette(pmi);
diff --git a/engines/tinsel/multiobj.cpp b/engines/tinsel/multiobj.cpp
index 1ec2c944b41..50aeb6a24f8 100644
--- a/engines/tinsel/multiobj.cpp
+++ b/engines/tinsel/multiobj.cpp
@@ -86,7 +86,7 @@ OBJECT *MultiInitObject(const MULTI_INIT *pInitTbl) {
 }
 
 OBJECT *InsertReelObj(const FREEL *reels) {
-	const MULTI_INIT *pmi = (const MULTI_INIT*)_vm->_handle->LockMem(reels->mobj);
+	const MULTI_INIT *pmi = reels->GetMultiInit();
 	// Verify that there is an image defined
 	const FRAME *frame = (const FRAME*)_vm->_handle->LockMem(pmi->hMulFrame);
 	const IMAGE *image = (const IMAGE*)_vm->_handle->LockMem(*frame);
diff --git a/engines/tinsel/play.cpp b/engines/tinsel/play.cpp
index a92fb36135c..0b33cd7de7c 100644
--- a/engines/tinsel/play.cpp
+++ b/engines/tinsel/play.cpp
@@ -235,10 +235,8 @@ static void SoundReel(CORO_PARAM, SCNHANDLE hFilm, int column, int speed,
 	CORO_BEGIN_CODE(_ctx);
 
 	if (actorCol) {
-		MULTI_INIT *pmi;		// MULTI_INIT structure
-
 		pReel = GetReel(hFilm, actorCol - 1);
-		pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pReel->mobj));
+		const MULTI_INIT *pmi = pReel->GetMultiInit();
 		_ctx->reelActor = (int32)FROM_32(pmi->mulID);
 	} else
 		_ctx->reelActor = 0;
@@ -451,7 +449,7 @@ static void t1PlayReel(CORO_PARAM, const PPINIT *ppi) {
 	_ctx->pfreel = &pfilm->reels[ppi->column];
 
 	// Get the MULTI_INIT structure
-	pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(_ctx->pfreel->mobj));
+	pmi = _ctx->pfreel->GetMultiInit();
 
 	// Save actor's ID
 	_ctx->reelActor = (int32)FROM_32(pmi->mulID);
@@ -705,7 +703,7 @@ static void t2PlayReel(CORO_PARAM, int x, int y, bool bRestore, int speed, SCNHA
 
 	// Get the reel and MULTI_INIT structure
 	_ctx->pFreel = GetReel(hFilm, column);
-	_ctx->pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(_ctx->pFreel->mobj));
+	_ctx->pmi = _ctx->pFreel->GetMultiInit();
 
 	if ((int32)FROM_32(_ctx->pmi->mulID) == -2) {
 		CORO_INVOKE_ARGS(SoundReel, (CORO_SUBCTX, hFilm, column, speed, myescEvent,
@@ -958,7 +956,7 @@ void NewestFilm(SCNHANDLE film, const FREEL *reel) {
 	const MULTI_INIT *pmi;		// MULTI_INIT structure
 
 	// Get the MULTI_INIT structure
-	pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(reel->mobj));
+	pmi = reel->GetMultiInit();
 
 	if ((TinselVersion <= 1) || ((int32)FROM_32(pmi->mulID) != -2))
 		_vm->_actor->SetActorLatestFilm((int32)FROM_32(pmi->mulID), film);
@@ -1162,7 +1160,7 @@ void RestoreActorReels(SCNHANDLE hFilm, int actor, int x, int y) {
 	// Search backwards for now as later column will be the one
 	for (i = (int)FROM_32(pFilm->numreels) - 1; i >= 0; i--) {
 		pFreel = &pFilm->reels[i];
-		pmi = (MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pFreel->mobj));
+		pmi = pFreel->GetMultiInit();
 		if ((int32)FROM_32(pmi->mulID) == actor) {
 			ppi.column = (short)i;
 			NewestFilm(hFilm, &pFilm->reels[i]);
@@ -1181,7 +1179,7 @@ void RestoreActorReels(SCNHANDLE hFilm, int actor, int x, int y) {
 int ExtractActor(SCNHANDLE hFilm) {
 	const FILM *pFilm = (const FILM *)_vm->_handle->LockMem(hFilm);
 	const FREEL *pReel = &pFilm->reels[0];
-	const MULTI_INIT *pmi = (const MULTI_INIT *)_vm->_handle->LockMem(FROM_32(pReel->mobj));
+	const MULTI_INIT *pmi = pReel->GetMultiInit();
 	return (int)FROM_32(pmi->mulID);
 }
 


Commit: ec9c630fc5b2b0613f5adda182421d501a061ad8
    https://github.com/scummvm/scummvm/commit/ec9c630fc5b2b0613f5adda182421d501a061ad8
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T21:04:41+02:00

Commit Message:
TINSEL: Replace LockMem with GetFrame for FRAME

Changed paths:
    engines/tinsel/bg.cpp
    engines/tinsel/cursor.cpp
    engines/tinsel/dialogs.cpp
    engines/tinsel/multiobj.cpp
    engines/tinsel/multiobj.h
    engines/tinsel/play.cpp


diff --git a/engines/tinsel/bg.cpp b/engines/tinsel/bg.cpp
index db9468cfd72..f59b8287dc9 100644
--- a/engines/tinsel/bg.cpp
+++ b/engines/tinsel/bg.cpp
@@ -169,7 +169,7 @@ void Background::StartupBackground(CORO_PARAM, SCNHANDLE hFilm) {
 
 	if (TinselVersion != 3) {
 		const MULTI_INIT *pmi = pfr->GetMultiInit();
-		const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
+		const FRAME *pFrame = pmi->GetFrame();
 		const IMAGE *pim = _vm->_handle->GetImage(READ_32(pFrame));
 		SetBackPal(pim->hImgPal);
 		delete pim;
diff --git a/engines/tinsel/cursor.cpp b/engines/tinsel/cursor.cpp
index a6d3ccc388c..7e1d7988aab 100644
--- a/engines/tinsel/cursor.cpp
+++ b/engines/tinsel/cursor.cpp
@@ -304,7 +304,7 @@ void Cursor::SetAuxCursor(SCNHANDLE hFilm) {
 	const FILM *pfilm = (const FILM *)_vm->_handle->LockMem(hFilm);
 	const FREEL *pfr = &pfilm->reels[0];
 	const MULTI_INIT *pmi = pfr->GetMultiInit();
-	const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
+	const FRAME *pFrame = pmi->GetFrame();
 	const IMAGE *pim;
 	int	x, y;		// Cursor position
 
diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp
index cb414a6bc53..1a0cfa1270e 100644
--- a/engines/tinsel/dialogs.cpp
+++ b/engines/tinsel/dialogs.cpp
@@ -2398,7 +2398,7 @@ void Dialogs::AddTitle(OBJECT **title, const Common::Rect &bounds) {
  */
 OBJECT *Dialogs::AddObject(const FREEL *pfreel, int num) {
 	const MULTI_INIT *pmi = pfreel->GetMultiInit();
-	const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
+	const FRAME *pFrame = pmi->GetFrame();
 	const IMAGE *pim;
 	OBJECT *pPlayObj;
 
diff --git a/engines/tinsel/multiobj.cpp b/engines/tinsel/multiobj.cpp
index 50aeb6a24f8..466cb301b79 100644
--- a/engines/tinsel/multiobj.cpp
+++ b/engines/tinsel/multiobj.cpp
@@ -30,6 +30,10 @@
 
 namespace Tinsel {
 
+const FRAME *MULTI_INIT::GetFrame() const {
+	return (const FRAME *)_vm->_handle->LockMem(FROM_32(hMulFrame));
+}
+
 /**
  * Initialize a multi-part object using a list of images to init
  * each object piece. One object is created for each image in the list.
@@ -40,11 +44,11 @@ namespace Tinsel {
 OBJECT *MultiInitObject(const MULTI_INIT *pInitTbl) {
 	OBJ_INIT obj_init;	// object init table
 	OBJECT *pFirst, *pObj;	// object pointers
-	FRAME *pFrame;		// list of images for the multi-part object
+	const FRAME *pFrame;		// list of images for the multi-part object
 
 	if (FROM_32(pInitTbl->hMulFrame)) {
 		// we have a frame handle
-		pFrame = (FRAME *)_vm->_handle->LockMem(FROM_32(pInitTbl->hMulFrame));
+		pFrame = pInitTbl->GetFrame();
 
 		obj_init.hObjImg  = READ_32(pFrame);	// first objects shape
 	} else {	// this must be a animation list for a NULL object
@@ -88,7 +92,7 @@ OBJECT *MultiInitObject(const MULTI_INIT *pInitTbl) {
 OBJECT *InsertReelObj(const FREEL *reels) {
 	const MULTI_INIT *pmi = reels->GetMultiInit();
 	// Verify that there is an image defined
-	const FRAME *frame = (const FRAME*)_vm->_handle->LockMem(pmi->hMulFrame);
+	const FRAME *frame = pmi->GetFrame();
 	const IMAGE *image = (const IMAGE*)_vm->_handle->LockMem(*frame);
 	assert(image);
 
diff --git a/engines/tinsel/multiobj.h b/engines/tinsel/multiobj.h
index 67efe282127..386406d0f20 100644
--- a/engines/tinsel/multiobj.h
+++ b/engines/tinsel/multiobj.h
@@ -43,6 +43,8 @@ struct MULTI_INIT {
 	int32 mulY;				///< multi-objects initial y ani position
 	int32 mulZ;				///< multi-objects initial z position
 	uint32 otherFlags;		///< multi-objects Tinsel 2 - other flags
+
+	const FRAME *GetFrame() const;
 } PACKED_STRUCT;
 
 #include "common/pack-end.h"	// END STRUCT PACKING
diff --git a/engines/tinsel/play.cpp b/engines/tinsel/play.cpp
index 0b33cd7de7c..d754dcd8f3b 100644
--- a/engines/tinsel/play.cpp
+++ b/engines/tinsel/play.cpp
@@ -101,7 +101,7 @@ static void PokeInPalette(SCNHANDLE hMulFrame) {
 void PokeInPalette(const MULTI_INIT *pmi) {
 	// Could be an empty column
 	if (pmi->hMulFrame) {
-		const FRAME *pFrame = (const FRAME *)_vm->_handle->LockMem(FROM_32(pmi->hMulFrame));
+		const FRAME *pFrame = pmi->GetFrame();
 		_vm->_handle->SetImagePalette(READ_32(pFrame), _vm->_bg->BgPal());
 	}
 }


Commit: fa7d4480512d4e7af766a6aa433b253d48b2e537
    https://github.com/scummvm/scummvm/commit/fa7d4480512d4e7af766a6aa433b253d48b2e537
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T21:06:27+02:00

Commit Message:
TINSEL: Refactor IsInPolygon to be partially a member-function

Changed paths:
    engines/tinsel/polygons.cpp


diff --git a/engines/tinsel/polygons.cpp b/engines/tinsel/polygons.cpp
index 3a601a3fb5d..93bd2358372 100644
--- a/engines/tinsel/polygons.cpp
+++ b/engines/tinsel/polygons.cpp
@@ -109,6 +109,7 @@ struct POLYGON {
 	 */
 	POLYGON *adjpaths[MAXADJ];
 
+	bool containsPoint(const Common::Point &point) const;
 };
 
 #define MAXONROUTE 40
@@ -404,13 +405,8 @@ static HPOLYGON PolygonIndex(const POLYGON *pp) {
  * have two polygon corners above it and two corners to the left of it.
  */
 bool IsInPolygon(int xt, int yt, HPOLYGON hp) {
-	const POLYGON *pp;
-	int	i;
-	bool BeenTested = false;
-	int	pl = 0, pa = 0;
-
 	CHECK_HP_OR(hp, "Out of range polygon handle (1)");
-	pp = Polys[hp];
+	const POLYGON *pp = Polys[hp];
 	assert(pp != NULL); // Testing whether in a NULL polygon
 
 	// Shift cursor for relative polygons
@@ -419,18 +415,26 @@ bool IsInPolygon(int xt, int yt, HPOLYGON hp) {
 		yt -= volatileStuff[hp].yoff;
 	}
 
+	return pp->containsPoint(Common::Point(xt, yt));
+}
+
+bool POLYGON::containsPoint(const Common::Point &point) const {
+	int xt = point.x;
+	int yt = point.y;
 	/* Is point within the external rectangle? */
-	if (xt < pp->pleft || xt > pp->pright || yt < pp->ptop || yt > pp->pbottom)
+	if (point.x < this->pleft || point.x > this->pright || yt < this->ptop || yt > this->pbottom)
 		return false;
 
+	bool BeenTested = false;
+
 	// For each corner/side
-	for (i = 0; i < 4; i++)	{
+	for (int i = 0; i < 4; i++)	{
 		// If within this side's 'testable' area
 		// i.e. within the width of the line in y direction of end of line
 		// or within the height of the line in x direction of end of line
-		if ((xt >= pp->lleft[i] && xt <= pp->lright[i]  && ((yt > pp->cy[i]) == (pp->cy[(i+1)%4] > pp->cy[i])))
-		 || (yt >= pp->ltop[i]  && yt <= pp->lbottom[i] && ((xt > pp->cx[i]) == (pp->cx[(i+1)%4] > pp->cx[i])))) {
-			if (((long)xt*pp->a[i] + (long)yt*pp->b[i]) < pp->c[i])
+		if ((xt >= this->lleft[i] && xt <= this->lright[i]  && ((yt > this->cy[i]) == (this->cy[(i+1)%4] > this->cy[i])))
+		 || (yt >= this->ltop[i]  && yt <= this->lbottom[i] && ((xt > this->cx[i]) == (this->cx[(i+1)%4] > this->cx[i])))) {
+			if (((long)xt*this->a[i] + (long)yt*this->b[i]) < this->c[i])
 				return false;
 			else
 				BeenTested = true;
@@ -439,21 +443,23 @@ bool IsInPolygon(int xt, int yt, HPOLYGON hp) {
 
 	if (BeenTested) {
 		// New dodgy code 29/12/94
-		if (pp->polyType == BLOCK) {
+		if (this->polyType == BLOCK) {
 			// For each corner/side
-			for (i = 0; i < 4; i++) {
+			for (int i = 0; i < 4; i++) {
 				// Pretend the corners of blocking polys are not in the poly.
-				if (xt == pp->cx[i] && yt == pp->cy[i])
+				if (xt == this->cx[i] && yt == this->cy[i])
 					return false;
 			}
 		}
 		return true;
 	} else {
+		int	pl = 0, pa = 0;
+
 		// Is point within the internal rectangle?
-		for (i = 0; i < 4; i++) {
-			if (pp->cx[i] < xt)
+		for (int i = 0; i < 4; i++) {
+			if (this->cx[i] < xt)
 				pl++;
-			if (pp->cy[i] < yt)
+			if (this->cy[i] < yt)
 				pa++;
 		}
 


Commit: e92fafb9558dfef3adc283a2fff8349d48651b26
    https://github.com/scummvm/scummvm/commit/e92fafb9558dfef3adc283a2fff8349d48651b26
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T21:06:58+02:00

Commit Message:
TINSEL: Minor style-fixes

Changed paths:
    engines/tinsel/multiobj.h


diff --git a/engines/tinsel/multiobj.h b/engines/tinsel/multiobj.h
index 386406d0f20..c7688b829b2 100644
--- a/engines/tinsel/multiobj.h
+++ b/engines/tinsel/multiobj.h
@@ -135,11 +135,11 @@ void MultiForceRedraw(
 	OBJECT *pMultiObj);	// multi-part object to be forced
 
 struct FREEL;
-OBJECT* InsertReelObj(const FREEL *reels);
+OBJECT *InsertReelObj(const FREEL *reels);
 struct FILM;
 enum class SysReel;
-const FILM* GetSystemReelFilm(SysReel reelIndex);
-OBJECT* InsertSystemReelObj(SysReel reelIndex);
+const FILM *GetSystemReelFilm(SysReel reelIndex);
+OBJECT *InsertSystemReelObj(SysReel reelIndex);
 
 } // End of namespace Tinsel
 


Commit: 89aefb77945b21ecb4670c1fb24356a31d08c3af
    https://github.com/scummvm/scummvm/commit/89aefb77945b21ecb4670c1fb24356a31d08c3af
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T21:07:21+02:00

Commit Message:
TINSEL: Implement InventoryOrNotebookActive

Changed paths:
    engines/tinsel/dialogs.cpp
    engines/tinsel/dialogs.h
    engines/tinsel/events.cpp


diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp
index 1a0cfa1270e..2e0ba004644 100644
--- a/engines/tinsel/dialogs.cpp
+++ b/engines/tinsel/dialogs.cpp
@@ -1289,7 +1289,11 @@ void Dialogs::InventoryIconCursor(bool bNewItem) {
  * Returns true if the inventory is active.
  */
 bool Dialogs::InventoryActive() {
-	return (_inventoryState == ACTIVE_INV);
+	return _inventoryState == ACTIVE_INV;
+}
+
+bool Dialogs::InventoryOrNotebookActive() {
+	return InventoryActive() || ((TinselVersion == 3) && _vm->_notebook->IsOpen());
 }
 
 int Dialogs::WhichInventoryOpen() {
diff --git a/engines/tinsel/dialogs.h b/engines/tinsel/dialogs.h
index 923b8dd62b6..703bb95bea6 100644
--- a/engines/tinsel/dialogs.h
+++ b/engines/tinsel/dialogs.h
@@ -298,6 +298,7 @@ public:
 	void idec_invMain(SCNHANDLE text, int MaxContents);
 
 	bool InventoryActive();
+	bool InventoryOrNotebookActive();
 
 	void PermaConvIcon(int icon, bool bEnd = false);
 
diff --git a/engines/tinsel/events.cpp b/engines/tinsel/events.cpp
index cbc51fa6fa9..75e67d24ac6 100644
--- a/engines/tinsel/events.cpp
+++ b/engines/tinsel/events.cpp
@@ -160,7 +160,7 @@ void ControlOn() {
 		_vm->_cursor->UnHideCursor();
 
 		// Turn tags back on
-		if (!_vm->_dialogs->InventoryActive())
+		if (!_vm->_dialogs->InventoryOrNotebookActive())
 			EnableTags();
 	}
 }
@@ -433,7 +433,7 @@ void PlayerEvent(PLR_EVENT pEvent, const Common::Point &coOrds) {
 	if (!ControlIsOn() && (pEvent != PLR_DRAG1_END))
 		return;
 
-	if ((TinselVersion >= 2) && _vm->_dialogs->InventoryActive()) {
+	if ((TinselVersion >= 2) && _vm->_dialogs->InventoryOrNotebookActive()) {
 		int x, y;
 		_vm->_bg->PlayfieldGetPos(FIELD_WORLD, &x, &y);
 		_vm->_dialogs->EventToInventory(pEvent, Common::Point(coOrds.x - x, coOrds.y - y));




More information about the Scummvm-git-logs mailing list