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

mgerhardy martin.gerhardy at gmail.com
Thu Jan 7 21:01:44 UTC 2021


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:
4b7dd811a4 TWINE: added helper methods to get rid of SCREEN_WIDTH and SCREEN_HEIGHT
3cf6eee18b TWINE: replaced hardcoded resolution constants with function calls
d093c23f3b TWINE: use new rect() method
92499991cf TWINE: hide gameFlags array
473a834840 TWINE: renamed member and method for game flags
e32d338324 TWINE: use rect() method


Commit: 4b7dd811a4174f0c90e71bf0c8ff4e9784e443db
    https://github.com/scummvm/scummvm/commit/4b7dd811a4174f0c90e71bf0c8ff4e9784e443db
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-01-07T21:58:21+01:00

Commit Message:
TWINE: added helper methods to get rid of SCREEN_WIDTH and SCREEN_HEIGHT

Changed paths:
    engines/twine/twine.h


diff --git a/engines/twine/twine.h b/engines/twine/twine.h
index 063de30c3e..73ac110a9a 100644
--- a/engines/twine/twine.h
+++ b/engines/twine/twine.h
@@ -251,6 +251,10 @@ public:
 	 * Contains all the data used in the engine to configurated the game in particulary ways. */
 	ConfigFile cfgfile;
 
+	int width() const;
+	int height() const;
+	Common::Rect rect() const;
+
 	/** Initialize LBA engine */
 	void initEngine();
 	void initMCGA();
@@ -347,6 +351,18 @@ public:
 	void drawText(int32 x, int32 y, const char *string, int32 center);
 };
 
+inline int TwinEEngine::width() const {
+	return frontVideoBuffer.w;
+}
+
+inline int TwinEEngine::height() const {
+	return frontVideoBuffer.h;
+}
+
+inline Common::Rect TwinEEngine::rect() const {
+	return Common::Rect(0, 0, frontVideoBuffer.w - 1, frontVideoBuffer.h - 1);
+}
+
 } // namespace TwinE
 
 #endif


Commit: 3cf6eee18b1a9238af06d600e60f78ef7a03e44c
    https://github.com/scummvm/scummvm/commit/3cf6eee18b1a9238af06d600e60f78ef7a03e44c
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-01-07T21:58:21+01:00

Commit Message:
TWINE: replaced hardcoded resolution constants with function calls

Changed paths:
    engines/twine/debugger/debug.cpp
    engines/twine/holomap.cpp
    engines/twine/menu/interface.cpp
    engines/twine/menu/interface.h
    engines/twine/menu/menu.cpp
    engines/twine/menu/menuoptions.cpp
    engines/twine/renderer/redraw.cpp
    engines/twine/renderer/renderer.cpp
    engines/twine/renderer/renderer.h
    engines/twine/scene/gamestate.cpp
    engines/twine/scene/grid.cpp
    engines/twine/scene/grid.h
    engines/twine/script/script_life_v1.cpp
    engines/twine/text.cpp
    engines/twine/twine.cpp
    engines/twine/twine.h


diff --git a/engines/twine/debugger/debug.cpp b/engines/twine/debugger/debug.cpp
index ddc47a274f..66ace9af2e 100644
--- a/engines/twine/debugger/debug.cpp
+++ b/engines/twine/debugger/debug.cpp
@@ -37,7 +37,7 @@ namespace TwinE {
 
 void Debug::debugFillButton(int32 x, int32 y, int32 width, int32 height, int8 color) {
 	uint8 *ptr = (uint8 *)_engine->frontVideoBuffer.getBasePtr(x, y);
-	const int32 offset = SCREEN_WIDTH - width;
+	const int32 offset = _engine->width() - width;
 
 	for (int32 i = 0; i < height; i++) {
 		for (int32 j = 0; j < width; j++) {
@@ -406,7 +406,7 @@ void Debug::debugPlasmaWindow(const char *text, int32 color) {
 		_engine->_menu->plasmaEffectPtr[_engine->getRandomNumber() % PLASMA_WIDTH * 10 + 6400] = 255;
 	}
 	const int32 textSize = _engine->_text->getTextSize(text);
-	_engine->_text->drawText((SCREEN_WIDTH / 2) - (textSize / 2), 10, text);
+	_engine->_text->drawText((_engine->width() / 2) - (textSize / 2), 10, text);
 	const Common::Rect rect(5, 5, 634, 50);
 	_engine->_menu->drawBox(rect);
 	_engine->copyBlockPhys(rect);
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 7280d6f7b9..72d6b9fa03 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -159,9 +159,9 @@ void Holomap::drawHolomapLocation() {
 	const int padding = 17;
 	Common::Rect rect;
 	rect.left = padding - 1;
-	rect.top = SCREEN_HEIGHT - 146;
-	rect.right = SCREEN_WIDTH - padding;
-	rect.bottom = SCREEN_HEIGHT - padding;
+	rect.top = _engine->height() - 146;
+	rect.right = _engine->width() - padding;
+	rect.bottom = _engine->height() - padding;
 	_engine->_menu->drawBox(rect);
 	rect.grow(-1);
 	_engine->_interface->drawTransparentBox(rect, 3);
@@ -183,12 +183,12 @@ void Holomap::processHolomap() {
 	_engine->setPalette(_engine->_screens->paletteRGBA);
 
 	loadHolomapGFX();
-	_engine->_renderer->setCameraPosition(SCREEN_WIDTH / 2, 190, 128, 1024, 1024);
+	_engine->_renderer->setCameraPosition(_engine->width() / 2, 190, 128, 1024, 1024);
 
 	_engine->_text->initTextBank(TextBankId::Inventory_Intro_and_Holomap);
 	_engine->_text->setFontCrossColor(9);
 
-	drawHolomapText(SCREEN_WIDTH / 2, 25, "Holomap"); // TODO: fix the index
+	drawHolomapText(_engine->width() / 2, 25, "Holomap"); // TODO: fix the index
 	drawHolomapLocation();
 	_engine->flip();
 
diff --git a/engines/twine/menu/interface.cpp b/engines/twine/menu/interface.cpp
index 9480da2692..d4312a424b 100644
--- a/engines/twine/menu/interface.cpp
+++ b/engines/twine/menu/interface.cpp
@@ -97,7 +97,7 @@ void Interface::drawLine(int32 startWidth, int32 startHeight, int32 endWidth, in
 		}
 	}
 
-	int32 pitch = SCREEN_WIDTH;
+	int32 pitch = _engine->width();
 	endWidth -= startWidth;
 	endHeight -= startHeight;
 	if (endHeight < 0) {
@@ -147,21 +147,21 @@ void Interface::blitBox(const Common::Rect &rect, const Graphics::ManagedSurface
 }
 
 void Interface::drawTransparentBox(const Common::Rect &rect, int32 colorAdj) {
-	const int32 left = MAX((int32)SCREEN_TEXTLIMIT_LEFT, (int32)rect.left);
-	const int32 top = MAX((int32)SCREEN_TEXTLIMIT_TOP, (int32)rect.top);
-	const int32 right = MIN((int32)SCREEN_TEXTLIMIT_RIGHT, (int32)rect.right);
-	const int32 bottom = MIN((int32)SCREEN_TEXTLIMIT_BOTTOM, (int32)rect.bottom);
+	const int32 left = MAX((int32)0, (int32)rect.left);
+	const int32 top = MAX((int32)0, (int32)rect.top);
+	const int32 right = MIN((int32)(_engine->width() - 1), (int32)rect.right);
+	const int32 bottom = MIN((int32)(_engine->height() - 1), (int32)rect.bottom);
 
-	if (left > SCREEN_TEXTLIMIT_RIGHT) {
+	if (left > (_engine->width() - 1)) {
 		return;
 	}
-	if (right < SCREEN_TEXTLIMIT_LEFT) {
+	if (right < 0) {
 		return;
 	}
-	if (top > SCREEN_TEXTLIMIT_BOTTOM) {
+	if (top > (_engine->height() - 1)) {
 		return;
 	}
-	if (bottom < SCREEN_TEXTLIMIT_TOP) {
+	if (bottom < 0) {
 		return;
 	}
 
@@ -186,10 +186,10 @@ void Interface::drawSplittedBox(const Common::Rect &rect, uint8 colorIndex) {
 }
 
 void Interface::setClip(const Common::Rect &rect) {
-	textWindow.left = MAX((int32)SCREEN_TEXTLIMIT_LEFT, (int32)rect.left);
-	textWindow.top = MAX((int32)SCREEN_TEXTLIMIT_TOP, (int32)rect.top);
-	textWindow.right = MIN((int32)SCREEN_TEXTLIMIT_RIGHT, (int32)rect.right);
-	textWindow.bottom = MIN((int32)SCREEN_TEXTLIMIT_BOTTOM, (int32)rect.bottom);
+	textWindow.left = MAX((int32)0, (int32)rect.left);
+	textWindow.top = MAX((int32)0, (int32)rect.top);
+	textWindow.right = MIN((int32)(_engine->width() - 1), (int32)rect.right);
+	textWindow.bottom = MIN((int32)(_engine->height() - 1), (int32)rect.bottom);
 }
 
 void Interface::saveClip() {
@@ -201,10 +201,10 @@ void Interface::loadClip() {
 }
 
 void Interface::resetClip() {
-	textWindow.top = SCREEN_TEXTLIMIT_TOP;
-	textWindow.left = SCREEN_TEXTLIMIT_LEFT;
-	textWindow.right = SCREEN_TEXTLIMIT_RIGHT;
-	textWindow.bottom = SCREEN_TEXTLIMIT_BOTTOM;
+	textWindow.top = 0;
+	textWindow.left = 0;
+	textWindow.right = (_engine->width() - 1);
+	textWindow.bottom = (_engine->height() - 1);
 }
 
 } // namespace TwinE
diff --git a/engines/twine/menu/interface.h b/engines/twine/menu/interface.h
index 6406552777..a46589dc4b 100644
--- a/engines/twine/menu/interface.h
+++ b/engines/twine/menu/interface.h
@@ -32,15 +32,6 @@ class ManagedSurface;
 
 namespace TwinE {
 
-/** Screen top limit to display the texts */
-#define SCREEN_TEXTLIMIT_TOP 0
-/** Screen left limit to display the texts */
-#define SCREEN_TEXTLIMIT_LEFT 0
-/** Screen right limit to display the texts */
-#define SCREEN_TEXTLIMIT_RIGHT (SCREEN_WIDTH - 1)
-/** Screen bottom limit to display the texts */
-#define SCREEN_TEXTLIMIT_BOTTOM (SCREEN_HEIGHT - 1)
-
 class TwinEEngine;
 
 class Interface {
diff --git a/engines/twine/menu/menu.cpp b/engines/twine/menu/menu.cpp
index 21c92f89b7..1a7054d657 100644
--- a/engines/twine/menu/menu.cpp
+++ b/engines/twine/menu/menu.cpp
@@ -300,7 +300,7 @@ void Menu::drawButtonGfx(const MenuSettings *menuSettings, const Common::Rect &r
 	_engine->_text->setFontColor(15);
 	_engine->_text->setFontParameters(2, 8);
 	const int32 textSize = _engine->_text->getTextSize(dialText);
-	_engine->_text->drawText((SCREEN_WIDTH / 2) - (textSize / 2), rect.top + 7, dialText);
+	_engine->_text->drawText((_engine->width() / 2) - (textSize / 2), rect.top + 7, dialText);
 
 	_engine->copyBlockPhys(rect);
 }
@@ -366,7 +366,7 @@ int16 Menu::drawButtons(MenuSettings *menuSettings, bool hover) {
 		const char *text = menuSettings->getButtonText(_engine->_text, i);
 		const int32 border = 45;
 		const int32 mainMenuButtonHeightHalf = 25;
-		const Common::Rect rect(border, topHeight - mainMenuButtonHeightHalf, SCREEN_WIDTH - border, topHeight + mainMenuButtonHeightHalf);
+		const Common::Rect rect(border, topHeight - mainMenuButtonHeightHalf, _engine->width() - border, topHeight + mainMenuButtonHeightHalf);
 		if (hover) {
 			if (i == buttonNumber) {
 				drawButtonGfx(menuSettings, rect, menuItemId, text, hover);
@@ -921,7 +921,7 @@ void Menu::drawBehaviour(HeroBehaviourType behaviour, int32 angle, bool cantDraw
 		char dialText[256];
 		_engine->_text->getMenuText(_engine->_actor->getTextIdForBehaviour(), dialText, sizeof(dialText));
 
-		_engine->_text->drawText(SCREEN_WIDTH / 2 - _engine->_text->getTextSize(dialText) / 2, titleBoxTop + 1, dialText);
+		_engine->_text->drawText(_engine->width() / 2 - _engine->_text->getTextSize(dialText) / 2, titleBoxTop + 1, dialText);
 		_engine->copyBlockPhys(titleRect);
 	} else {
 		_engine->_interface->drawSplittedBox(boxRect, 0);
diff --git a/engines/twine/menu/menuoptions.cpp b/engines/twine/menu/menuoptions.cpp
index 00f3c288cc..b3b1290cca 100644
--- a/engines/twine/menu/menuoptions.cpp
+++ b/engines/twine/menu/menuoptions.cpp
@@ -212,7 +212,7 @@ void MenuOptions::drawSelectableCharacters() {
 
 void MenuOptions::drawPlayerName(int32 centerx, int32 top, int32 type) {
 	const int32 left = 10;
-	const int right = SCREEN_WIDTH - left;
+	const int right = _engine->width() - left;
 	const int bottom = top + PLASMA_HEIGHT;
 	const Common::Rect rect(left, top, right, bottom);
 	if (type == 1) {
@@ -254,9 +254,9 @@ bool MenuOptions::enterPlayerName(int32 textIdx) {
 	char buffer[256];
 	_engine->_text->getMenuText(textIdx, buffer, sizeof(buffer));
 	_engine->_text->setFontColor(15);
-	const int halfScreenWidth = (SCREEN_WIDTH / 2);
+	const int halfScreenWidth = (_engine->width() / 2);
 	_engine->_text->drawText(halfScreenWidth - (_engine->_text->getTextSize(buffer) / 2), 20, buffer);
-	_engine->copyBlockPhys(0, 0, SCREEN_WIDTH - 1, 99);
+	_engine->copyBlockPhys(0, 0, _engine->width() - 1, 99);
 	_engine->flip();
 
 	Common::fill(&_onScreenKeyboardDirty[0], &_onScreenKeyboardDirty[ARRAYSIZE(_onScreenKeyboardDirty)], 1);
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index c8bdbeee89..6c19272598 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -60,7 +60,7 @@ void Redraw::addRedrawCurrentArea(const Common::Rect &redrawArea) {
 			rect.left = leftValue;
 			rect.top = topValue;
 			rect.right = rightValue;
-			rect.bottom = MIN<int32>(SCREEN_TEXTLIMIT_BOTTOM, bottomValue);
+			rect.bottom = MIN<int32>((_engine->height() - 1), bottomValue);
 
 			assert(rect.left <= rect.right);
 			assert(rect.top <= rect.bottom);
@@ -72,7 +72,7 @@ void Redraw::addRedrawCurrentArea(const Common::Rect &redrawArea) {
 	rect.left = redrawArea.left;
 	rect.top = redrawArea.top;
 	rect.right = redrawArea.right;
-	rect.bottom = MIN<int32>(SCREEN_TEXTLIMIT_BOTTOM, redrawArea.bottom);
+	rect.bottom = MIN<int32>((_engine->height() - 1), redrawArea.bottom);
 
 	assert(rect.left <= rect.right);
 	assert(rect.top <= rect.bottom);
@@ -88,17 +88,17 @@ void Redraw::addRedrawArea(const Common::Rect &rect) {
 }
 
 void Redraw::addRedrawArea(int32 left, int32 top, int32 right, int32 bottom) {
-	if (left < SCREEN_TEXTLIMIT_LEFT) {
-		left = SCREEN_TEXTLIMIT_LEFT;
+	if (left < 0) {
+		left = 0;
 	}
-	if (top < SCREEN_TEXTLIMIT_TOP) {
-		top = SCREEN_TEXTLIMIT_TOP;
+	if (top < 0) {
+		top = 0;
 	}
-	if (right >= SCREEN_WIDTH) {
-		right = SCREEN_TEXTLIMIT_RIGHT;
+	if (right >= _engine->width()) {
+		right = (_engine->width() - 1);
 	}
-	if (bottom >= SCREEN_HEIGHT) {
-		bottom = SCREEN_TEXTLIMIT_BOTTOM;
+	if (bottom >= _engine->height()) {
+		bottom = (_engine->height() - 1);
 	}
 
 	if (left > right || top > bottom) {
@@ -201,7 +201,7 @@ int32 Redraw::fillActorDrawingList(bool bgRedraw) {
 			_engine->_renderer->projectPositionOnScreen(actor->x - _engine->_grid->cameraX, actor->y - _engine->_grid->cameraY, actor->z - _engine->_grid->cameraZ);
 
 			// check if actor is visible on screen, otherwise don't display it
-			if (_engine->_renderer->projPosX > -50 && _engine->_renderer->projPosX < SCREEN_WIDTH + 40 && _engine->_renderer->projPosY > -30 && _engine->_renderer->projPosY < SCREEN_HEIGHT + 100) {
+			if (_engine->_renderer->projPosX > -50 && _engine->_renderer->projPosX < _engine->width() + 40 && _engine->_renderer->projPosY > -30 && _engine->_renderer->projPosY < _engine->height() + 100) {
 				actor->dynamicFlags.bIsVisible = 1;
 			}
 			continue;
@@ -213,8 +213,8 @@ int32 Redraw::fillActorDrawingList(bool bgRedraw) {
 		// get actor position on screen
 		_engine->_renderer->projectPositionOnScreen(actor->x - _engine->_grid->cameraX, actor->y - _engine->_grid->cameraY, actor->z - _engine->_grid->cameraZ);
 
-		if ((actor->staticFlags.bUsesClipping && _engine->_renderer->projPosX > -112 && _engine->_renderer->projPosX < SCREEN_WIDTH + 112 && _engine->_renderer->projPosY > -50 && _engine->_renderer->projPosY < SCREEN_HEIGHT + 171) ||
-		    ((!actor->staticFlags.bUsesClipping) && _engine->_renderer->projPosX > -50 && _engine->_renderer->projPosX < SCREEN_WIDTH + 40 && _engine->_renderer->projPosY > -30 && _engine->_renderer->projPosY < SCREEN_HEIGHT + 100)) {
+		if ((actor->staticFlags.bUsesClipping && _engine->_renderer->projPosX > -112 && _engine->_renderer->projPosX < _engine->width() + 112 && _engine->_renderer->projPosY > -50 && _engine->_renderer->projPosY < _engine->height() + 171) ||
+		    ((!actor->staticFlags.bUsesClipping) && _engine->_renderer->projPosX > -50 && _engine->_renderer->projPosX < _engine->width() + 40 && _engine->_renderer->projPosY > -30 && _engine->_renderer->projPosY < _engine->height() + 100)) {
 
 			int32 tmpVal = actor->z + actor->x - _engine->_grid->cameraX - _engine->_grid->cameraZ;
 
@@ -281,7 +281,7 @@ int32 Redraw::fillExtraDrawingList(int32 drawListPos) {
 		if ((extra->type & ExtraType::TIME_OUT) || (extra->type & ExtraType::FLASH) || (extra->payload.lifeTime + extra->spawnTime - 150 < _engine->lbaTime) || (!((_engine->lbaTime + extra->spawnTime) & 8))) {
 			_engine->_renderer->projectPositionOnScreen(extra->x - _engine->_grid->cameraX, extra->y - _engine->_grid->cameraY, extra->z - _engine->_grid->cameraZ);
 
-			if (_engine->_renderer->projPosX > -50 && _engine->_renderer->projPosX < SCREEN_WIDTH + 40 && _engine->_renderer->projPosY > -30 && _engine->_renderer->projPosY < SCREEN_HEIGHT + 100) {
+			if (_engine->_renderer->projPosX > -50 && _engine->_renderer->projPosX < _engine->width() + 40 && _engine->_renderer->projPosY > -30 && _engine->_renderer->projPosY < _engine->height() + 100) {
 				drawList[drawListPos].posValue = extra->x - _engine->_grid->cameraX + extra->z - _engine->_grid->cameraZ;
 				drawList[drawListPos].actorIdx = i;
 				drawList[drawListPos].type = DrawListType::DrawExtras;
@@ -348,20 +348,20 @@ void Redraw::processDrawListActors(const DrawListStruct &drawCmd, bool bgRedraw)
 		return;
 	}
 
-	if (renderRect.left < SCREEN_TEXTLIMIT_LEFT) {
-		renderRect.left = SCREEN_TEXTLIMIT_LEFT;
+	if (renderRect.left < 0) {
+		renderRect.left = 0;
 	}
 
-	if (renderRect.top < SCREEN_TEXTLIMIT_TOP) {
-		renderRect.top = SCREEN_TEXTLIMIT_TOP;
+	if (renderRect.top < 0) {
+		renderRect.top = 0;
 	}
 
-	if (renderRect.right >= SCREEN_WIDTH) {
-		renderRect.right = SCREEN_TEXTLIMIT_RIGHT;
+	if (renderRect.right >= _engine->width()) {
+		renderRect.right = (_engine->width() - 1);
 	}
 
-	if (renderRect.bottom >= SCREEN_HEIGHT) {
-		renderRect.bottom = SCREEN_TEXTLIMIT_BOTTOM;
+	if (renderRect.bottom >= _engine->height()) {
+		renderRect.bottom = (_engine->height() - 1);
 	}
 
 	_engine->_interface->setClip(renderRect);
@@ -642,20 +642,20 @@ void Redraw::renderOverlays() {
 				renderRect.right = overlay->x + (textLength / 2);
 				renderRect.bottom = overlay->y + textHeight;
 
-				if (renderRect.left < SCREEN_TEXTLIMIT_LEFT) {
-					renderRect.left = SCREEN_TEXTLIMIT_LEFT;
+				if (renderRect.left < 0) {
+					renderRect.left = 0;
 				}
 
-				if (renderRect.top < SCREEN_TEXTLIMIT_TOP) {
-					renderRect.top = SCREEN_TEXTLIMIT_TOP;
+				if (renderRect.top < 0) {
+					renderRect.top = 0;
 				}
 
-				if (renderRect.right > SCREEN_TEXTLIMIT_RIGHT) {
-					renderRect.right = SCREEN_TEXTLIMIT_RIGHT;
+				if (renderRect.right > (_engine->width() - 1)) {
+					renderRect.right = (_engine->width() - 1);
 				}
 
-				if (renderRect.bottom > SCREEN_TEXTLIMIT_BOTTOM) {
-					renderRect.bottom = SCREEN_TEXTLIMIT_BOTTOM;
+				if (renderRect.bottom > (_engine->height() - 1)) {
+					renderRect.bottom = (_engine->height() - 1);
 				}
 
 				_engine->_interface->setClip(renderRect);
@@ -788,8 +788,8 @@ void Redraw::zoomScreenScale() {
 			*dest++ = *src;
 			*dest++ = *src++;
 		}
-		//memcpy(dest, dest - SCREEN_WIDTH, SCREEN_WIDTH);
-		//dest += SCREEN_WIDTH;
+		//memcpy(dest, dest - _engine->width(), _engine->width());
+		//dest += _engine->width();
 	}
 	_engine->_screens->copyScreen(_engine->workVideoBuffer, _engine->frontVideoBuffer);
 	zoomWorkVideoBuffer.free();
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 176100f6b2..62b8f8ca33 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -375,8 +375,8 @@ void Renderer::computeBoundingBox(Vertex *vertices, int32 numVertices, int &vlef
 	vright = vbottom = SCENE_SIZE_MIN;
 
 	for (int32 i = 0; i < numVertices; i++) {
-		vertices[i].x = clamp(vertices[i].x, 0, SCREEN_WIDTH - 1);
-		vertices[i].y = clamp(vertices[i].y, 0, SCREEN_HEIGHT - 1);
+		vertices[i].x = clamp(vertices[i].x, 0, _engine->width() - 1);
+		vertices[i].y = clamp(vertices[i].y, 0, _engine->height() - 1);
 		const int vertexX = vertices[i].x;
 		vleft = MIN(vleft, vertexX);
 		vright = MAX(vright, vertexX);
@@ -434,7 +434,7 @@ void Renderer::computePolygons(int16 polyRenderType, Vertex *vertices, int32 num
 			cvalue = (oldVertexParam << 8) + ((vertexParam2 - oldVertexParam) << 8) % vsize;
 			cdelta = ((vertexParam2 - oldVertexParam) << 8) / vsize;
 		}
-		int16 *outPtr = &polyTab[ypos + (up ? SCREEN_HEIGHT : 0)]; // outPtr is the output ptr in the renderTab
+		int16 *outPtr = &polyTab[ypos + (up ? _engine->height() : 0)]; // outPtr is the output ptr in the renderTab
 
 		float slope = (float)hsize / (float)vsize;
 		slope = up ? -slope : slope;
@@ -450,7 +450,7 @@ void Renderer::computePolygons(int16 polyRenderType, Vertex *vertices, int32 num
 		}
 
 		if (polyRenderType >= POLYGONTYPE_GOURAUD) { // we must compute the color progression
-			int16 *outPtr2 = &polyTab2[ypos + (up ? SCREEN_HEIGHT : 0)];
+			int16 *outPtr2 = &polyTab2[ypos + (up ? _engine->height() : 0)];
 
 			for (int32 i = 0; i < vsize + 2; i++) {
 				if (outPtr2 - polyTab2 < ARRAYSIZE(polyTab2)) {
@@ -469,9 +469,9 @@ void Renderer::renderPolygonsCopper(uint8 *out, int vtop, int32 vsize, int32 col
 	const int16 *ptr1 = &polyTab[vtop];
 	int32 currentLine = vtop;
 	do {
-		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
+		if (currentLine >= 0 && currentLine < _engine->height()) {
 			int16 start = ptr1[0];
-			int16 stop = ptr1[SCREEN_HEIGHT];
+			int16 stop = ptr1[_engine->height()];
 
 			ptr1++;
 			int32 hsize = stop - start;
@@ -489,7 +489,7 @@ void Renderer::renderPolygonsCopper(uint8 *out, int vtop, int32 vsize, int32 col
 					start += mask;
 					start = (start & 0xFF00) | ((start & 0xFF) & (uint8)(dx >> 8));
 					start = (start & 0xFF00) | ((start & 0xFF) + (dx & 0xFF));
-					if (j >= 0 && j < SCREEN_WIDTH) {
+					if (j >= 0 && j < _engine->width()) {
 						out[j] = start & 0xFF;
 					}
 					mask = (mask << 2) | (mask >> 14);
@@ -497,7 +497,7 @@ void Renderer::renderPolygonsCopper(uint8 *out, int vtop, int32 vsize, int32 col
 				}
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		currentLine++;
 	} while (--vsize);
 }
@@ -506,9 +506,9 @@ void Renderer::renderPolygonsBopper(uint8 *out, int vtop, int32 vsize, int32 col
 	const int16 *ptr1 = &polyTab[vtop];
 	int32 currentLine = vtop;
 	do {
-		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
+		if (currentLine >= 0 && currentLine < _engine->height()) {
 			int16 start = ptr1[0];
-			int16 stop = ptr1[SCREEN_HEIGHT];
+			int16 stop = ptr1[_engine->height()];
 			ptr1++;
 			int32 hsize = stop - start;
 
@@ -516,14 +516,14 @@ void Renderer::renderPolygonsBopper(uint8 *out, int vtop, int32 vsize, int32 col
 				hsize++;
 				for (int32 j = start; j < hsize + start; j++) {
 					if ((start + (vtop % 1)) & 1) {
-						if (j >= 0 && j < SCREEN_WIDTH) {
+						if (j >= 0 && j < _engine->width()) {
 							out[j] = color;
 						}
 					}
 				}
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		currentLine++;
 	} while (--vsize);
 }
@@ -532,22 +532,22 @@ void Renderer::renderPolygonsFlat(uint8 *out, int vtop, int32 vsize, int32 color
 	const int16 *ptr1 = &polyTab[vtop];
 	int32 currentLine = vtop;
 	do {
-		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
+		if (currentLine >= 0 && currentLine < _engine->height()) {
 			int16 start = ptr1[0];
-			int16 stop = ptr1[SCREEN_HEIGHT];
+			int16 stop = ptr1[_engine->height()];
 			ptr1++;
 			int32 hsize = stop - start;
 
 			if (hsize >= 0) {
 				hsize++;
 				for (int32 j = start; j < hsize + start; j++) {
-					if (j >= 0 && j < SCREEN_WIDTH) {
+					if (j >= 0 && j < _engine->width()) {
 						out[j] = color;
 					}
 				}
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		currentLine++;
 	} while (--vsize);
 }
@@ -562,7 +562,7 @@ void Renderer::renderPolygonsTele(uint8 *out, int vtop, int32 vsize, int32 color
 		int32 hsize;
 		while (1) {
 			start = ptr1[0];
-			stop = ptr1[SCREEN_HEIGHT];
+			stop = ptr1[_engine->height()];
 			ptr1++;
 			hsize = stop - start;
 
@@ -575,7 +575,7 @@ void Renderer::renderPolygonsTele(uint8 *out, int vtop, int32 vsize, int32 color
 
 			color = *(out2 + 1);
 
-			out += SCREEN_WIDTH;
+			out += _engine->width();
 
 			--renderLoop;
 			if (!renderLoop) {
@@ -626,7 +626,7 @@ void Renderer::renderPolygonsTele(uint8 *out, int vtop, int32 vsize, int32 color
 			}
 		}
 
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		--renderLoop;
 
 	} while (renderLoop);
@@ -639,7 +639,7 @@ void Renderer::renderPolygonsTras(uint8 *out, int vtop, int32 vsize, int32 color
 		unsigned short int bx;
 
 		int16 start = ptr1[0];
-		int16 stop = ptr1[SCREEN_HEIGHT];
+		int16 stop = ptr1[_engine->height()];
 
 		ptr1++;
 		int32 hsize = stop - start;
@@ -660,7 +660,7 @@ void Renderer::renderPolygonsTras(uint8 *out, int vtop, int32 vsize, int32 color
 				out2++;
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 	} while (--vsize);
 }
 
@@ -671,9 +671,9 @@ void Renderer::renderPolygonTrame(uint8 *out, int vtop, int32 vsize, int32 color
 
 	int32 currentLine = vtop;
 	do {
-		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
+		if (currentLine >= 0 && currentLine < _engine->height()) {
 			int16 start = ptr1[0];
-			int16 stop = ptr1[SCREEN_HEIGHT];
+			int16 stop = ptr1[_engine->height()];
 			ptr1++;
 			int32 hsize = stop - start;
 
@@ -698,7 +698,7 @@ void Renderer::renderPolygonTrame(uint8 *out, int vtop, int32 vsize, int32 color
 				}
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		currentLine++;
 	} while (--vsize);
 }
@@ -709,20 +709,20 @@ void Renderer::renderPolygonsGouraud(uint8 *out, int vtop, int32 vsize, int32 co
 	int32 renderLoop = vsize;
 	int32 currentLine = vtop;
 	do {
-		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
+		if (currentLine >= 0 && currentLine < _engine->height()) {
 			uint16 startColor = ptr2[0];
-			uint16 stopColor = ptr2[SCREEN_HEIGHT];
+			uint16 stopColor = ptr2[_engine->height()];
 
 			int16 colorSize = stopColor - startColor;
 
-			int16 stop = ptr1[SCREEN_HEIGHT]; // stop
+			int16 stop = ptr1[_engine->height()]; // stop
 			int16 start = ptr1[0];            // start
 
 			ptr1++;
 			uint8 *out2 = start + out;
 			int32 hsize = stop - start;
 
-			//varf2 = ptr2[SCREEN_HEIGHT];
+			//varf2 = ptr2[_engine->height()];
 			//varf3 = ptr2[0];
 
 			ptr2++;
@@ -730,28 +730,28 @@ void Renderer::renderPolygonsGouraud(uint8 *out, int vtop, int32 vsize, int32 co
 			//varf4 = (float)((int32)varf2 - (int32)varf3);
 
 			if (hsize == 0) {
-				if (start >= 0 && start < SCREEN_WIDTH) {
+				if (start >= 0 && start < _engine->width()) {
 					*out2 = ((startColor + stopColor) / 2) >> 8; // moyenne des 2 couleurs
 				}
 			} else if (hsize > 0) {
 				if (hsize == 1) {
-					if (start >= -1 && start < SCREEN_WIDTH - 1) {
+					if (start >= -1 && start < _engine->width() - 1) {
 						*(out2 + 1) = stopColor >> 8;
 					}
 
-					if (start >= 0 && start < SCREEN_WIDTH) {
+					if (start >= 0 && start < _engine->width()) {
 						*(out2) = startColor >> 8;
 					}
 				} else if (hsize == 2) {
-					if (start >= -2 && start < SCREEN_WIDTH - 2) {
+					if (start >= -2 && start < _engine->width() - 2) {
 						*(out2 + 2) = stopColor >> 8;
 					}
 
-					if (start >= -1 && start < SCREEN_WIDTH - 1) {
+					if (start >= -1 && start < _engine->width() - 1) {
 						*(out2 + 1) = ((startColor + stopColor) / 2) >> 8;
 					}
 
-					if (start >= 0 && start < SCREEN_WIDTH) {
+					if (start >= 0 && start < _engine->width()) {
 						*(out2) = startColor >> 8;
 					}
 				} else {
@@ -761,7 +761,7 @@ void Renderer::renderPolygonsGouraud(uint8 *out, int vtop, int32 vsize, int32 co
 
 					if (hsize % 2) {
 						hsize /= 2;
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2) = startColor >> 8;
 						}
 						out2++;
@@ -772,14 +772,14 @@ void Renderer::renderPolygonsGouraud(uint8 *out, int vtop, int32 vsize, int32 co
 					}
 
 					do {
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2) = startColor >> 8;
 						}
 
 						currentXPos++;
 						startColor += colorSize;
 
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2 + 1) = startColor >> 8;
 						}
 
@@ -790,7 +790,7 @@ void Renderer::renderPolygonsGouraud(uint8 *out, int vtop, int32 vsize, int32 co
 				}
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		currentLine++;
 	} while (--renderLoop);
 }
@@ -802,22 +802,22 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 
 	int32 currentLine = vtop;
 	do {
-		if (currentLine >= 0 && currentLine < SCREEN_HEIGHT) {
-			int16 stop = ptr1[SCREEN_HEIGHT]; // stop
+		if (currentLine >= 0 && currentLine < _engine->height()) {
+			int16 stop = ptr1[_engine->height()]; // stop
 			int16 start = ptr1[0];            // start
 			ptr1++;
 			int32 hsize = stop - start;
 
 			if (hsize >= 0) {
 				uint16 startColor = ptr2[0];
-				uint16 stopColor = ptr2[SCREEN_HEIGHT];
+				uint16 stopColor = ptr2[_engine->height()];
 				int32 currentXPos = start;
 
 				uint8 *out2 = start + out;
 				ptr2++;
 
 				if (hsize == 0) {
-					if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+					if (currentXPos >= 0 && currentXPos < _engine->width()) {
 						*(out2) = (uint8)(((startColor + stopColor) / 2) >> 8);
 					}
 				} else {
@@ -829,7 +829,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 
 						currentColor &= 0xFF;
 						currentColor += startColor;
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2) = currentColor >> 8;
 						}
 
@@ -839,7 +839,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 						currentColor += startColor;
 
 						currentXPos++;
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2 + 1) = currentColor >> 8;
 						}
 					} else if (hsize == 2) {
@@ -851,7 +851,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 						colorSize /= 2;
 						currentColor = ((currentColor & (0xFF00)) | ((((currentColor & 0xFF) << (hsize & 0xFF))) & 0xFF));
 						currentColor += startColor;
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2) = currentColor >> 8;
 						}
 
@@ -862,7 +862,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 						currentColor &= 0xFF;
 						currentColor += startColor;
 
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2) = currentColor >> 8;
 						}
 
@@ -872,7 +872,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 						currentColor += startColor;
 
 						currentXPos++;
-						if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+						if (currentXPos >= 0 && currentXPos < _engine->width()) {
 							*(out2 + 1) = currentColor >> 8;
 						}
 					} else {
@@ -885,7 +885,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 							currentColor &= 0xFF;
 							currentColor = ((currentColor & (0xFF00)) | ((((currentColor & 0xFF) << (hsize & 0xFF))) & 0xFF));
 							currentColor += startColor;
-							if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+							if (currentXPos >= 0 && currentXPos < _engine->width()) {
 								*(out2) = currentColor >> 8;
 							}
 							out2++;
@@ -897,7 +897,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 						do {
 							currentColor &= 0xFF;
 							currentColor += startColor;
-							if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+							if (currentXPos >= 0 && currentXPos < _engine->width()) {
 								*(out2) = currentColor >> 8;
 							}
 							currentXPos++;
@@ -905,7 +905,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 							startColor += colorSize;
 							currentColor = ((currentColor & (0xFF00)) | ((((currentColor & 0xFF) << (hsize & 0xFF))) & 0xFF));
 							currentColor += startColor;
-							if (currentXPos >= 0 && currentXPos < SCREEN_WIDTH) {
+							if (currentXPos >= 0 && currentXPos < _engine->width()) {
 								*(out2 + 1) = currentColor >> 8;
 							}
 							currentXPos++;
@@ -916,7 +916,7 @@ void Renderer::renderPolygonsDither(uint8 *out, int vtop, int32 vsize, int32 col
 				}
 			}
 		}
-		out += SCREEN_WIDTH;
+		out += _engine->width();
 		currentLine++;
 	} while (--renderLoop);
 }
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index ceb9770d98..c30d69c047 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -39,7 +39,8 @@
 #define POLYGONTYPE_GOURAUD 7
 #define POLYGONTYPE_DITHER 8
 
-#define POLYTABSIZE (SCREEN_HEIGHT * 2)
+// TODO: this depends on the actual used resolution
+#define POLYTABSIZE (SCREEN_WIDTH * 2)
 
 namespace Common {
 class MemoryReadStream;
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index f509a82cc9..889fb9bbc9 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -460,7 +460,7 @@ void GameState::processGameoverAnimation() {
 	Renderer::prepareIsoModel(gameOverPtr);
 	_engine->_sound->stopSamples();
 	_engine->_music->stopMidiMusic(); // stop fade music
-	_engine->_renderer->setCameraPosition(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 128, 200, 200);
+	_engine->_renderer->setCameraPosition(_engine->width() / 2, _engine->height() / 2, 128, 200, 200);
 	int32 startLbaTime = _engine->lbaTime;
 	_engine->_interface->setClip(rect);
 
diff --git a/engines/twine/scene/grid.cpp b/engines/twine/scene/grid.cpp
index bcf611aa1d..0d58b7afe3 100644
--- a/engines/twine/scene/grid.cpp
+++ b/engines/twine/scene/grid.cpp
@@ -76,7 +76,7 @@ void Grid::copyGridMask(int32 index, int32 x, int32 y, const Graphics::ManagedSu
 		return;
 	}
 
-	int32 offset = -((right - left) - SCREEN_WIDTH) - 1;
+	int32 offset = -((right - left) - _engine->width()) - 1;
 
 	right++;
 	bottom++;
@@ -619,13 +619,13 @@ void Grid::drawColumnGrid(int32 blockIdx, int32 brickBlockIdx, int32 x, int32 y,
 	if (brickPixelPosX < -24) {
 		return;
 	}
-	if (brickPixelPosX >= SCREEN_WIDTH) {
+	if (brickPixelPosX >= _engine->width()) {
 		return;
 	}
 	if (brickPixelPosY < -38) {
 		return;
 	}
-	if (brickPixelPosY >= SCREEN_HEIGHT) {
+	if (brickPixelPosY >= _engine->height()) {
 		return;
 	}
 
diff --git a/engines/twine/scene/grid.h b/engines/twine/scene/grid.h
index 3b44890943..436a882071 100644
--- a/engines/twine/scene/grid.h
+++ b/engines/twine/scene/grid.h
@@ -82,6 +82,7 @@ struct BrickEntry {
 #define BRICK_SIZE 512
 #define BRICK_HEIGHT 256
 
+// TODO: this depends on the actual used resolution
 #define NUMBRICKENTRIES (1 + (SCREEN_WIDTH + 24) / 24)
 #define MAXBRICKS 150
 
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index c8832bf857..249404d811 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -1712,7 +1712,7 @@ static int32 lPROJ_3D(TwinEEngine *engine, LifeScriptContext &ctx) {
 	engine->flip();
 	engine->_scene->changeRoomVar10 = false;
 
-	engine->_renderer->setCameraPosition(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 128, 1024, 1024);
+	engine->_renderer->setCameraPosition(engine->width() / 2, engine->height() / 2, 128, 1024, 1024);
 	engine->_renderer->setCameraAngle(0, 1500, 0, 25, -128, 0, 13000);
 	engine->_renderer->setLightVector(896, 950, ANGLE_0);
 
@@ -1741,8 +1741,8 @@ static int32 lTEXT(TwinEEngine *engine, LifeScriptContext &ctx) {
 		int32 textBoxRight = textSize;
 		engine->_text->setFontColor(15);
 		engine->_text->drawText(0, drawVar1, textStr);
-		if (textSize > SCREEN_WIDTH - 1) {
-			textBoxRight = SCREEN_WIDTH - 1;
+		if (textSize > engine->width() - 1) {
+			textBoxRight = engine->width() - 1;
 		}
 
 		drawVar1 += 40;
@@ -1759,7 +1759,7 @@ static int32 lTEXT(TwinEEngine *engine, LifeScriptContext &ctx) {
  */
 static int32 lCLEAR_TEXT(TwinEEngine *engine, LifeScriptContext &ctx) {
 	drawVar1 = 0;
-	const Common::Rect rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2);
+	const Common::Rect rect(0, 0, engine->width() - 1, engine->height() / 2);
 	engine->_interface->drawSplittedBox(rect, 0);
 	engine->copyBlockPhys(rect);
 	return 0;
diff --git a/engines/twine/text.cpp b/engines/twine/text.cpp
index b7ffdd8e0f..542705e91d 100644
--- a/engines/twine/text.cpp
+++ b/engines/twine/text.cpp
@@ -191,7 +191,7 @@ void Text::drawCharacter(int32 x, int32 y, uint8 character) { // drawCharacter
 			tempX += jump;
 			uint8* basePtr = (uint8 *)_engine->frontVideoBuffer.getBasePtr(tempX, tempY);
 			for (uint8 i = 0; i < number; i++) {
-				if (tempX >= SCREEN_TEXTLIMIT_LEFT && tempX < SCREEN_TEXTLIMIT_RIGHT && tempY >= SCREEN_TEXTLIMIT_TOP && tempY < SCREEN_TEXTLIMIT_BOTTOM) {
+				if (tempX >= 0 && tempX < (_engine->width() - 1) && tempY >= 0 && tempY < (_engine->height() - 1)) {
 					*basePtr = usedColor;
 				}
 
@@ -740,11 +740,11 @@ void Text::textClipFull() {
 	const int32 padding = 8;
 	_dialTextBox.left = margin;
 	_dialTextBox.top = margin;
-	_dialTextBox.right = SCREEN_WIDTH - margin;
-	_dialTextBox.bottom = SCREEN_HEIGHT - margin;
+	_dialTextBox.right = _engine->width() - margin;
+	_dialTextBox.bottom = _engine->height() - margin;
 
 	_dialTextBoxLines = (int32)(_dialTextBox.height() / _lineHeight) - 1;
-	_dialTextBoxMaxX = SCREEN_WIDTH - 2 * margin - 2 * padding;
+	_dialTextBoxMaxX = _engine->width() - 2 * margin - 2 * padding;
 }
 
 void Text::textClipSmall() {
@@ -754,11 +754,11 @@ void Text::textClipSmall() {
 	const int32 textHeight = _dialTextBoxLines * _lineHeight;
 
 	_dialTextBox.left = margin;
-	_dialTextBox.top = SCREEN_HEIGHT - textHeight - margin - padding;
-	_dialTextBox.right = SCREEN_WIDTH - margin;
-	_dialTextBox.bottom = SCREEN_HEIGHT - margin;
+	_dialTextBox.top = _engine->height() - textHeight - margin - padding;
+	_dialTextBox.right = _engine->width() - margin;
+	_dialTextBox.bottom = _engine->height() - margin;
 
-	_dialTextBoxMaxX = SCREEN_WIDTH - 2 * margin - 2 * padding;
+	_dialTextBoxMaxX = _engine->width() - 2 * margin - 2 * padding;
 }
 
 void Text::drawAskQuestion(int32 index) {
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 0f00d1f1a1..2eec70a76f 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -197,8 +197,10 @@ Common::Error TwinEEngine::run() {
 	debug("(c) 1994 by Adeline Software International, All Rights Reserved.");
 
 	syncSoundSettings();
-	initGraphics(SCREEN_WIDTH, SCREEN_HEIGHT);
-	allocVideoMemory();
+	const int32 w = 640;
+	const int32 h = 480;
+	initGraphics(w, h);
+	allocVideoMemory(w, h);
 	initAll();
 	initEngine();
 	_sound->stopSamples();
@@ -304,13 +306,13 @@ void TwinEEngine::autoSave() {
 	saveGameState(getAutosaveSlot(), _gameState->playerName, true);
 }
 
-void TwinEEngine::allocVideoMemory() {
+void TwinEEngine::allocVideoMemory(int32 w, int32 h) {
 	const Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8();
 
-	imageBuffer.create(640, 480, format); // original lba1 resolution for a lot of images.
+	imageBuffer.create(SCREEN_WIDTH, SCREEN_HEIGHT, format); // original lba1 resolution for a lot of images.
 
-	workVideoBuffer.create(SCREEN_WIDTH, SCREEN_HEIGHT, format);
-	frontVideoBuffer.create(SCREEN_WIDTH, SCREEN_HEIGHT, format);
+	workVideoBuffer.create(w, h, format);
+	frontVideoBuffer.create(w, h, format);
 }
 
 static int getLanguageTypeIndex(const char *languageName) {
@@ -464,8 +466,8 @@ void TwinEEngine::initAll() {
 
 	_scene->sceneHero = _scene->getActor(OWN_ACTOR_SCENE_INDEX);
 
-	_redraw->renderRect.right = SCREEN_TEXTLIMIT_RIGHT;
-	_redraw->renderRect.bottom = SCREEN_TEXTLIMIT_BOTTOM;
+	_redraw->renderRect.right = (width() - 1);
+	_redraw->renderRect.bottom = (height() - 1);
 	// Set clip to fullscreen by default, allows main menu to render properly after load
 	_interface->resetClip();
 
@@ -641,7 +643,7 @@ void TwinEEngine::centerScreenOnActor() {
 	_renderer->projectPositionOnScreen(actor->x - (_grid->newCameraX * BRICK_SIZE),
 	                                   actor->y - (_grid->newCameraY * BRICK_HEIGHT),
 	                                   actor->z - (_grid->newCameraZ * BRICK_SIZE));
-	if (_renderer->projPosX < 80 || _renderer->projPosX >= SCREEN_WIDTH - 60 || _renderer->projPosY < 80 || _renderer->projPosY >= SCREEN_HEIGHT - 50) {
+	if (_renderer->projPosX < 80 || _renderer->projPosX >= width() - 60 || _renderer->projPosY < 80 || _renderer->projPosY >= height() - 50) {
 		_grid->newCameraX = ((actor->x + BRICK_HEIGHT) / BRICK_SIZE) + (((actor->x + BRICK_HEIGHT) / BRICK_SIZE) - _grid->newCameraX) / 2;
 		_grid->newCameraY = actor->y / BRICK_HEIGHT;
 		_grid->newCameraZ = ((actor->z + BRICK_HEIGHT) / BRICK_SIZE) + (((actor->z + BRICK_HEIGHT) / BRICK_SIZE) - _grid->newCameraZ) / 2;
@@ -1037,11 +1039,11 @@ void TwinEEngine::copyBlockPhys(int32 left, int32 top, int32 right, int32 bottom
 	assert(top <= bottom);
 	int32 width = right - left + 1;
 	int32 height = bottom - top + 1;
-	if (left + width > SCREEN_WIDTH) {
-		width = SCREEN_WIDTH - left;
+	if (left + width > this->width()) {
+		width = this->width() - left;
 	}
-	if (top + height > SCREEN_HEIGHT) {
-		height = SCREEN_HEIGHT - top;
+	if (top + height > this->height()) {
+		height = this->height() - top;
 	}
 	if (width <= 0 || height <= 0) {
 		return;
diff --git a/engines/twine/twine.h b/engines/twine/twine.h
index 73ac110a9a..6bc0937027 100644
--- a/engines/twine/twine.h
+++ b/engines/twine/twine.h
@@ -272,7 +272,7 @@ public:
 	 */
 	int32 runGameEngine();
 	/** Allocate video memory, both front and back buffers */
-	void allocVideoMemory();
+	void allocVideoMemory(int32 w, int32 h);
 	/**
 	 * @return A random value between [0-max)
 	 */


Commit: d093c23f3b48ff7ea968cefcdc62e895152583cb
    https://github.com/scummvm/scummvm/commit/d093c23f3b48ff7ea968cefcdc62e895152583cb
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-01-07T21:58:21+01:00

Commit Message:
TWINE: use new rect() method

Changed paths:
    engines/twine/menu/interface.cpp
    engines/twine/twine.cpp


diff --git a/engines/twine/menu/interface.cpp b/engines/twine/menu/interface.cpp
index d4312a424b..cba2047d45 100644
--- a/engines/twine/menu/interface.cpp
+++ b/engines/twine/menu/interface.cpp
@@ -201,10 +201,7 @@ void Interface::loadClip() {
 }
 
 void Interface::resetClip() {
-	textWindow.top = 0;
-	textWindow.left = 0;
-	textWindow.right = (_engine->width() - 1);
-	textWindow.bottom = (_engine->height() - 1);
+	textWindow = _engine->rect();
 }
 
 } // namespace TwinE
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 2eec70a76f..7fd75c3a36 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -466,8 +466,7 @@ void TwinEEngine::initAll() {
 
 	_scene->sceneHero = _scene->getActor(OWN_ACTOR_SCENE_INDEX);
 
-	_redraw->renderRect.right = (width() - 1);
-	_redraw->renderRect.bottom = (height() - 1);
+	_redraw->renderRect = rect();
 	// Set clip to fullscreen by default, allows main menu to render properly after load
 	_interface->resetClip();
 


Commit: 92499991cf1dbe92f6975a5a09e12f2af35521b3
    https://github.com/scummvm/scummvm/commit/92499991cf1dbe92f6975a5a09e12f2af35521b3
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-01-07T21:58:21+01:00

Commit Message:
TWINE: hide gameFlags array

Changed paths:
    engines/twine/debugger/console.cpp
    engines/twine/scene/gamestate.h
    engines/twine/script/script_life_v1.cpp


diff --git a/engines/twine/debugger/console.cpp b/engines/twine/debugger/console.cpp
index af4e59a3f4..edbfef944a 100644
--- a/engines/twine/debugger/console.cpp
+++ b/engines/twine/debugger/console.cpp
@@ -133,7 +133,7 @@ bool TwinEConsole::doSetGameFlag(int argc, const char **argv) {
 
 	const uint8 idx = atoi(argv[1]);
 	const uint8 val = argc == 3 ? atoi(argv[2]) : 0;
-	_engine->_gameState->gameFlags[idx] = val;
+	_engine->_gameState->setFlag(idx, val);
 
 	return true;
 }
@@ -141,13 +141,13 @@ bool TwinEConsole::doSetGameFlag(int argc, const char **argv) {
 bool TwinEConsole::doPrintGameFlag(int argc, const char **argv) {
 	if (argc <= 1) {
 		for (int i = 0; i < NUM_GAME_FLAGS; ++i) {
-			debugPrintf("[%03d] = %d\n", i, _engine->_gameState->gameFlags[i]);
+			debugPrintf("[%03d] = %d\n", i, _engine->_gameState->hasGameFlag(i));
 		}
 		return true;
 	}
 
 	const uint8 idx = atoi(argv[1]);
-	debugPrintf("[%03d] = %d\n", idx, _engine->_gameState->gameFlags[idx]);
+	debugPrintf("[%03d] = %d\n", idx, _engine->_gameState->hasGameFlag(idx));
 
 	return true;
 }
@@ -224,10 +224,10 @@ bool TwinEConsole::doChangeScene(int argc, const char **argv) {
 bool TwinEConsole::doGiveAllItems(int argc, const char **argv) {
 	GameState* state = _engine->_gameState;
 	for (int32 i = 0; i < NUM_INVENTORY_ITEMS; ++i) {
-		state->gameFlags[i] = 1;
+		state->setFlag(i, 1);
 		state->inventoryFlags[i] = 1;
 	}
-	_engine->_gameState->gameFlags[GAMEFLAG_INVENTORY_DISABLED] = 0;
+	_engine->_gameState->setFlag(GAMEFLAG_INVENTORY_DISABLED, 0);
 	int amount = 1;
 	if (argc >= 2) {
 		amount = atoi(argv[1]);
diff --git a/engines/twine/scene/gamestate.h b/engines/twine/scene/gamestate.h
index b099f5a35d..75b20b81e7 100644
--- a/engines/twine/scene/gamestate.h
+++ b/engines/twine/scene/gamestate.h
@@ -91,6 +91,27 @@ private:
 
 	MenuSettings gameChoicesSettings;
 
+	/**
+	 * LBA engine game flags to save quest states
+	 *
+	 * 0-27: inventory related
+	 * 28-199: story related
+	 * 200-255: video related
+	 *
+	 * 35: If 0, a zommed sequence of opening the ventilation shaft will be played when Twinsen escapes
+	 * his house after arresting Zoe. Set to 1 after the sequence (also if Twinsen is killed during the arrest).
+	 * 47: Value of 1 indicates that Twinsen has opened the door to the Citadel Island Tavern's basement.
+	 * The door will be always open from now on.
+	 * 70: Set to 1 if inventory items are taken from Twinsen when he goes to jail (inventory is empty),
+	 * set to 0 after he gets back his stuff.
+	 * 92: Set to 1 if the green grobo in the Citadel Island Tavern has told Twinsen about taking Zoe to the
+	 * port and leaving for another island.
+	 * 107: Set to 1 after Twinsen kills yellow groboclone in the Citadel Island Tavern (after the Tavern has
+	 * been closed down). Makes the Tavern open again and groboclone not appear any more.
+	 */
+	// TODO: why not NUM_GAME_FLAGS?
+	uint8 gameFlags[256];
+
 public:
 	GameState(TwinEEngine *engine);
 
@@ -114,32 +135,15 @@ public:
 		gameFlags[item] = 0;
 	}
 
+	inline uint8 hasGameFlag(uint8 index) const {
+		return gameFlags[index];
+	}
+
 	inline void setFlag(uint8 index, uint8 value) {
 		gameFlags[index] = value;
 		debug(2, "Set gameflag[%u]=%u", index, value);
 	}
 
-	/**
-	 * LBA engine game flags to save quest states
-	 *
-	 * 0-27: inventory related
-	 * 28-199: story related
-	 * 200-255: video related
-	 *
-	 * 35: If 0, a zommed sequence of opening the ventilation shaft will be played when Twinsen escapes
-	 * his house after arresting Zoe. Set to 1 after the sequence (also if Twinsen is killed during the arrest).
-	 * 47: Value of 1 indicates that Twinsen has opened the door to the Citadel Island Tavern's basement.
-	 * The door will be always open from now on.
-	 * 70: Set to 1 if inventory items are taken from Twinsen when he goes to jail (inventory is empty),
-	 * set to 0 after he gets back his stuff.
-	 * 92: Set to 1 if the green grobo in the Citadel Island Tavern has told Twinsen about taking Zoe to the
-	 * port and leaving for another island.
-	 * 107: Set to 1 after Twinsen kills yellow groboclone in the Citadel Island Tavern (after the Tavern has
-	 * been closed down). Makes the Tavern open again and groboclone not appear any more.
-	 */
-	// TODO: why not NUM_GAME_FLAGS?
-	uint8 gameFlags[256];
-
 	/**
 	 * LBA engine chapter
 	 *  0: Inprisoned
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index 249404d811..08f7b699b0 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -263,7 +263,7 @@ static int32 processLifeConditions(TwinEEngine *engine, LifeScriptContext &ctx)
 		int32 flagIdx = ctx.stream.readByte();
 		if (!engine->_gameState->inventoryDisabled() ||
 		    (engine->_gameState->inventoryDisabled() && flagIdx >= MaxInventoryItems)) {
-			engine->_scene->currentScriptValue = engine->_gameState->gameFlags[flagIdx];
+			engine->_scene->currentScriptValue = engine->_gameState->hasGameFlag(flagIdx);
 		} else {
 			if (flagIdx == GAMEFLAG_INVENTORY_DISABLED) {
 				// TODO: this case should already get handled in the above if branch as the flagIdx is bigger than MaxInventoryItems


Commit: 473a834840bd3c49329a7712ffbfca93256b14cb
    https://github.com/scummvm/scummvm/commit/473a834840bd3c49329a7712ffbfca93256b14cb
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-01-07T21:58:21+01:00

Commit Message:
TWINE: renamed member and method for game flags

Changed paths:
    engines/twine/debugger/console.cpp
    engines/twine/scene/gamestate.cpp
    engines/twine/scene/gamestate.h
    engines/twine/script/script_life_v1.cpp


diff --git a/engines/twine/debugger/console.cpp b/engines/twine/debugger/console.cpp
index edbfef944a..98f689438a 100644
--- a/engines/twine/debugger/console.cpp
+++ b/engines/twine/debugger/console.cpp
@@ -133,7 +133,7 @@ bool TwinEConsole::doSetGameFlag(int argc, const char **argv) {
 
 	const uint8 idx = atoi(argv[1]);
 	const uint8 val = argc == 3 ? atoi(argv[2]) : 0;
-	_engine->_gameState->setFlag(idx, val);
+	_engine->_gameState->setGameFlag(idx, val);
 
 	return true;
 }
@@ -224,10 +224,10 @@ bool TwinEConsole::doChangeScene(int argc, const char **argv) {
 bool TwinEConsole::doGiveAllItems(int argc, const char **argv) {
 	GameState* state = _engine->_gameState;
 	for (int32 i = 0; i < NUM_INVENTORY_ITEMS; ++i) {
-		state->setFlag(i, 1);
+		state->setGameFlag(i, 1);
 		state->inventoryFlags[i] = 1;
 	}
-	_engine->_gameState->setFlag(GAMEFLAG_INVENTORY_DISABLED, 0);
+	_engine->_gameState->setGameFlag(GAMEFLAG_INVENTORY_DISABLED, 0);
 	int amount = 1;
 	if (argc >= 2) {
 		amount = atoi(argv[1]);
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index 889fb9bbc9..be3400e183 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -50,7 +50,7 @@
 namespace TwinE {
 
 GameState::GameState(TwinEEngine *engine) : _engine(engine) {
-	Common::fill(&gameFlags[0], &gameFlags[256], 0);
+	Common::fill(&_gameStateFlags[0], &_gameStateFlags[NUM_GAME_FLAGS], 0);
 	Common::fill(&inventoryFlags[0], &inventoryFlags[NUM_INVENTORY_ITEMS], 0);
 	Common::fill(&holomapFlags[0], &holomapFlags[NUM_LOCATIONS], 0);
 	playerName[0] = '\0';
@@ -75,19 +75,12 @@ void GameState::initGameStateVars() {
 		_engine->_scene->sceneFlags[i] = 0;
 	}
 
-	for (int32 i = 0; i < ARRAYSIZE(gameFlags); i++) {
-		gameFlags[i] = 0;
-	}
-
-	for (int32 i = 0; i < ARRAYSIZE(inventoryFlags); i++) {
-		inventoryFlags[i] = 0;
-	}
+	Common::fill(&_gameStateFlags[0], &_gameStateFlags[NUM_GAME_FLAGS], 0);
+	Common::fill(&inventoryFlags[0], &inventoryFlags[NUM_INVENTORY_ITEMS], 0);
 
 	_engine->_scene->initSceneVars();
 
-	for (int32 i = 0; i < ARRAYSIZE(holomapFlags); i++) {
-		holomapFlags[i] = 0;
-	}
+	Common::fill(&holomapFlags[0], &holomapFlags[NUM_LOCATIONS], 0);
 
 	_engine->_actor->clearBodyTable();
 }
@@ -180,7 +173,7 @@ bool GameState::loadGame(Common::SeekableReadStream *file) {
 		warning("Failed to load gameflags. Expected %u, but got %u", NUM_GAME_FLAGS, numGameFlags);
 		return false;
 	}
-	file->read(gameFlags, NUM_GAME_FLAGS);
+	file->read(_gameStateFlags, NUM_GAME_FLAGS);
 	_engine->_scene->needChangeScene = file->readByte(); // scene index
 	gameChapter = file->readByte();
 
@@ -231,7 +224,7 @@ bool GameState::saveGame(Common::WriteStream *file) {
 	file->writeString(playerName);
 	file->writeByte('\0');
 	file->writeByte(NUM_GAME_FLAGS);
-	file->write(gameFlags, NUM_GAME_FLAGS);
+	file->write(_gameStateFlags, NUM_GAME_FLAGS);
 	file->writeByte(_engine->_scene->currentSceneIdx);
 	file->writeByte(gameChapter);
 	file->writeByte((byte)_engine->_actor->heroBehaviour);
diff --git a/engines/twine/scene/gamestate.h b/engines/twine/scene/gamestate.h
index 75b20b81e7..846e79431e 100644
--- a/engines/twine/scene/gamestate.h
+++ b/engines/twine/scene/gamestate.h
@@ -110,38 +110,38 @@ private:
 	 * been closed down). Makes the Tavern open again and groboclone not appear any more.
 	 */
 	// TODO: why not NUM_GAME_FLAGS?
-	uint8 gameFlags[256];
+	uint8 _gameStateFlags[256];
 
 public:
 	GameState(TwinEEngine *engine);
 
 	inline bool inventoryDisabled() const {
-		return gameFlags[GAMEFLAG_INVENTORY_DISABLED] != 0;
+		return _gameStateFlags[GAMEFLAG_INVENTORY_DISABLED] != 0;
 	}
 
 	inline bool hasOpenedFunfrocksSafe() const {
-		return gameFlags[30] != 0;
+		return _gameStateFlags[30] != 0;
 	}
 
 	inline bool hasItem(InventoryItems item) const {
-		return gameFlags[item] != 0;
+		return _gameStateFlags[item] != 0;
 	}
 
 	inline void giveItem(InventoryItems item) {
-		gameFlags[item] = 1;
+		_gameStateFlags[item] = 1;
 	}
 
 	inline void removeItem(InventoryItems item) {
-		gameFlags[item] = 0;
+		_gameStateFlags[item] = 0;
 	}
 
 	inline uint8 hasGameFlag(uint8 index) const {
-		return gameFlags[index];
+		return _gameStateFlags[index];
 	}
 
-	inline void setFlag(uint8 index, uint8 value) {
-		gameFlags[index] = value;
-		debug(2, "Set gameflag[%u]=%u", index, value);
+	inline void setGameFlag(uint8 index, uint8 value) {
+		_gameStateFlags[index] = value;
+		debug(2, "Set gameStateFlags[%u]=%u", index, value);
 	}
 
 	/**
diff --git a/engines/twine/script/script_life_v1.cpp b/engines/twine/script/script_life_v1.cpp
index 08f7b699b0..efc0c880bf 100644
--- a/engines/twine/script/script_life_v1.cpp
+++ b/engines/twine/script/script_life_v1.cpp
@@ -789,7 +789,7 @@ static int32 lEND_COMPORTEMENT(TwinEEngine *engine, LifeScriptContext &ctx) {
 static int32 lSET_FLAG_GAME(TwinEEngine *engine, LifeScriptContext &ctx) {
 	const uint8 flagIdx = ctx.stream.readByte();
 	const uint8 flagValue = ctx.stream.readByte();
-	engine->_gameState->setFlag(flagIdx, flagValue);
+	engine->_gameState->setGameFlag(flagIdx, flagValue);
 	return 0;
 }
 


Commit: e32d338324a4ec9f4674c4e6071c5fba7c275054
    https://github.com/scummvm/scummvm/commit/e32d338324a4ec9f4674c4e6071c5fba7c275054
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2021-01-07T22:00:23+01:00

Commit Message:
TWINE: use rect() method

Changed paths:
    engines/twine/menu/interface.cpp


diff --git a/engines/twine/menu/interface.cpp b/engines/twine/menu/interface.cpp
index cba2047d45..c95b05554b 100644
--- a/engines/twine/menu/interface.cpp
+++ b/engines/twine/menu/interface.cpp
@@ -147,28 +147,16 @@ void Interface::blitBox(const Common::Rect &rect, const Graphics::ManagedSurface
 }
 
 void Interface::drawTransparentBox(const Common::Rect &rect, int32 colorAdj) {
-	const int32 left = MAX((int32)0, (int32)rect.left);
-	const int32 top = MAX((int32)0, (int32)rect.top);
-	const int32 right = MIN((int32)(_engine->width() - 1), (int32)rect.right);
-	const int32 bottom = MIN((int32)(_engine->height() - 1), (int32)rect.bottom);
-
-	if (left > (_engine->width() - 1)) {
-		return;
-	}
-	if (right < 0) {
-		return;
-	}
-	if (top > (_engine->height() - 1)) {
-		return;
-	}
-	if (bottom < 0) {
+	Common::Rect r = rect;
+	r.clip(_engine->rect());
+	if (r.isEmpty()) {
 		return;
 	}
 
-	uint8 *pos = (uint8*)_engine->frontVideoBuffer.getBasePtr(0, top);
+	uint8 *pos = (uint8*)_engine->frontVideoBuffer.getBasePtr(0, rect.top);
 
-	for (int32 y = top; y < bottom; ++y) {
-		for (int32 x = left; x < right; ++x) {
+	for (int32 y = rect.top; y < rect.bottom; ++y) {
+		for (int32 x = rect.left; x < rect.right; ++x) {
 			const int8 color = (pos[x] & 0x0F) - colorAdj;
 			const int8 color2 = pos[x] & 0xF0;
 			if (color < 0) {




More information about the Scummvm-git-logs mailing list