[Scummvm-git-logs] scummvm master -> 4fb6e147a88767a81bddab69cb3315c9d70546c9

sev- noreply at scummvm.org
Sat Jun 4 18:03:28 UTC 2022


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

Summary:
4fb6e147a8 DIRECTOR: LINGO: Fixed arithmetic operations with POINT and RECT


Commit: 4fb6e147a88767a81bddab69cb3315c9d70546c9
    https://github.com/scummvm/scummvm/commit/4fb6e147a88767a81bddab69cb3315c9d70546c9
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2022-06-04T20:02:49+02:00

Commit Message:
DIRECTOR: LINGO: Fixed arithmetic operations with POINT and RECT

And added relevant tests

Changed paths:
    engines/director/lingo/lingo-code.cpp
    engines/director/lingo/tests/lists.lingo


diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index a6214235f70..11160c862c8 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -641,26 +641,52 @@ void LC::c_swap() {
 	g_lingo->push(d1);
 }
 
+static bool isArray(Datum &d1) {
+	if (d1.type == ARRAY || d1.type == POINT || d1.type == RECT)
+		return true;
+
+	return false;
+}
+
+static DatumType getArrayAlignedType(Datum &d1, Datum &d2) {
+	if (d1.type == POINT && d2.type == ARRAY && d2.u.farr->arr.size() < 2)
+		return ARRAY;
+
+	if (d1.type == POINT)
+		return POINT;
+
+	if (d1.type == RECT && (d2.type == POINT || (d2.type == ARRAY && d2.u.farr->arr.size() < 4)))
+		return ARRAY;
+
+	if (d1.type == RECT)
+		return RECT;
+
+	if (!isArray(d1))
+		return d2.type;
+
+	return ARRAY;
+}
+
 Datum LC::mapBinaryOp(Datum (*mapFunc)(Datum &, Datum &), Datum &d1, Datum &d2) {
 	// At least one of d1 and d2 must be an array
 	uint arraySize;
-	if (d1.type == ARRAY && d2.type == ARRAY) {
+	if (isArray(d1) && isArray(d2)) {
 		arraySize = MIN(d1.u.farr->arr.size(), d2.u.farr->arr.size());
-	} else if (d1.type == ARRAY) {
+	} else if (isArray(d1)) {
 		arraySize = d1.u.farr->arr.size();
 	} else {
 		arraySize = d2.u.farr->arr.size();
 	}
 	Datum res;
-	res.type = ARRAY;
+	res.type = getArrayAlignedType(d1, d2);
 	res.u.farr = new FArray(arraySize);
 	Datum a = d1;
 	Datum b = d2;
 	for (uint i = 0; i < arraySize; i++) {
-		if (d1.type == ARRAY) {
+		if (isArray(d1)) {
 			a = d1.u.farr->arr[i];
 		}
-		if (d2.type == ARRAY) {
+		if (isArray(d2)) {
 			b = d2.u.farr->arr[i];
 		}
 		res.u.farr->arr[i] = mapFunc(a, b);
@@ -669,7 +695,7 @@ Datum LC::mapBinaryOp(Datum (*mapFunc)(Datum &, Datum &), Datum &d1, Datum &d2)
 }
 
 Datum LC::addData(Datum &d1, Datum &d2) {
-	if (d1.type == ARRAY || d2.type == ARRAY) {
+	if (isArray(d1) || isArray(d2)) {
 		return LC::mapBinaryOp(LC::addData, d1, d2);
 	}
 
@@ -693,7 +719,7 @@ void LC::c_add() {
 }
 
 Datum LC::subData(Datum &d1, Datum &d2) {
-	if (d1.type == ARRAY || d2.type == ARRAY) {
+	if (isArray(d1) || isArray(d2)) {
 		return LC::mapBinaryOp(LC::subData, d1, d2);
 	}
 
@@ -717,7 +743,7 @@ void LC::c_sub() {
 }
 
 Datum LC::mulData(Datum &d1, Datum &d2) {
-	if (d1.type == ARRAY || d2.type == ARRAY) {
+	if (isArray(d1) || isArray(d2)) {
 		return LC::mapBinaryOp(LC::mulData, d1, d2);
 	}
 
@@ -741,7 +767,7 @@ void LC::c_mul() {
 }
 
 Datum LC::divData(Datum &d1, Datum &d2) {
-	if (d1.type == ARRAY || d2.type == ARRAY) {
+	if (isArray(d1) || isArray(d2)) {
 		return LC::mapBinaryOp(LC::divData, d1, d2);
 	}
 
@@ -775,7 +801,7 @@ void LC::c_div() {
 }
 
 Datum LC::modData(Datum &d1, Datum &d2) {
-	if (d1.type == ARRAY || d2.type == ARRAY) {
+	if (isArray(d1) || isArray(d2)) {
 		return LC::mapBinaryOp(LC::modData, d1, d2);
 	}
 
@@ -797,10 +823,10 @@ void LC::c_mod() {
 }
 
 Datum LC::negateData(Datum &d) {
-	if (d.type == ARRAY) {
+	if (isArray(d)) {
 		uint arraySize = d.u.farr->arr.size();
 		Datum res;
-		res.type = ARRAY;
+		res.type = d.type;
 		res.u.farr = new FArray(arraySize);
 		for (uint i = 0; i < arraySize; i++) {
 			res.u.farr->arr[i] = LC::negateData(d.u.farr->arr[i]);
diff --git a/engines/director/lingo/tests/lists.lingo b/engines/director/lingo/tests/lists.lingo
index 11524ff29a1..f6a336dfe14 100644
--- a/engines/director/lingo/tests/lists.lingo
+++ b/engines/director/lingo/tests/lists.lingo
@@ -93,3 +93,30 @@ set gA to getAt(rct, 3)
 scummvmAssertEqual(gA, 100)
 setAt rct, 2, 20
 scummvmAssertEqual(getAt(rct, 2), 20)
+
+-- array conversions
+set a to point(10, 10)
+set b to rect(20, 20, 20, 20)
+set c to [30]
+set d to [40, 40]
+set e to [50, 50, 50]
+set f to [60, 60, 60, 60]
+set g to [70, 70, 70, 70]
+put a + d -- point(50, 50)
+put d + a -- [50, 50]
+put b + f -- rect(80, 80, 80, 80)
+put f + b -- [80, 80, 80, 80]
+put a + c -- [40.0000f]
+put a + d -- point(50, 50)
+put a + e -- point(60, 60)
+put a + f -- point(70, 70)
+put f + a -- [70, 70]
+put b + a -- [30, 30]
+put b + c -- [50]
+put b + e -- [70, 70, 70]
+put b + f -- rect(80, 80, 80, 80)
+put b + g -- rect(90, 90, 90, 90)
+put a + 5 -- point(15, 15)
+put 5 + a -- point(15, 15)
+put b + 5 -- rect(25, 25, 25, 25)
+put 5 + b -- rect(25, 25, 25, 25)




More information about the Scummvm-git-logs mailing list