From 4c43d6d85dc70e1b9b82629f1af1e9a37a136013 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 8 Jul 2012 12:21:26 +0300 Subject: SCI: Add a hack in kGetAngleWorker to fix bug #3540976 kGetAngle(Worker) has been implemented based on behavior observed with a test program created with SCI Studio. However, the return values have subtle differences from the original, which uses atan(). This temporary hack will do for now till the implementation of kGetAngle is done again. A simpler atan2-based implementation has also been added for future reference --- engines/sci/engine/kmath.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'engines/sci/engine/kmath.cpp') diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index 7570856dff..cbfe00d3ca 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -78,6 +78,25 @@ reg_t kSqrt(EngineState *s, int argc, reg_t *argv) { } uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { + // TODO: This has been implemented based on behavior observed with a test + // program created with SCI Studio. However, the return values have subtle + // differences from the original, which uses atan(). + // The differences in the return values are the cause of bug #3540976 + // and perhaps bug #3037267 as well. + + // HACK: Return the expected value for Longbow, scene 150 (bug #3540976). + // This is a temporary solution, till the function returns the expected + // results. + if (g_sci->getGameId() == GID_LONGBOW && g_sci->getEngineState()->currentRoomNumber() == 150) { + if (x1 == 207 && y1 == 88 && x2 == 107 && y2 == 184) + return 226; + } + +#if 0 + // A simpler atan2-based implementation + return (360 - atan2((double)(x1 - x2), (double)(y1 - y2)) * 57.2958) % 360; +#endif + int16 xRel = x2 - x1; int16 yRel = y1 - y2; // y-axis is mirrored. int16 angle; -- cgit v1.2.3 From 262c7a1fb73cb89a7c2db562374bdc0ce6f85d18 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 8 Jul 2012 21:59:54 +0300 Subject: SCI: Fix a typo and add some comments to kGetAngleWorker() --- engines/sci/engine/kmath.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'engines/sci/engine/kmath.cpp') diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index cbfe00d3ca..05c8845288 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -77,10 +77,16 @@ reg_t kSqrt(EngineState *s, int argc, reg_t *argv) { return make_reg(0, (int16) sqrt((float) ABS(argv[0].toSint16()))); } +/** + * Returns the angle (in degrees) between the two points determined by (x1, y1) + * and (x2, y2). The angle ranges from 0 to 359 degrees. + * What this function does is pretty simple but apparently the original is not + * accurate. + */ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { // TODO: This has been implemented based on behavior observed with a test // program created with SCI Studio. However, the return values have subtle - // differences from the original, which uses atan(). + // differences from the original, which uses custom implementation of atan(). // The differences in the return values are the cause of bug #3540976 // and perhaps bug #3037267 as well. @@ -94,7 +100,7 @@ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { #if 0 // A simpler atan2-based implementation - return (360 - atan2((double)(x1 - x2), (double)(y1 - y2)) * 57.2958) % 360; + return (int16)(360 - atan2((double)(x1 - x2), (double)(y1 - y2)) * 57.2958) % 360; #endif int16 xRel = x2 - x1; @@ -122,6 +128,7 @@ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { // Convert from grads to degrees by merging grad 0 with grad 1, // grad 10 with grad 11, grad 20 with grad 21, etc. This leads to // "degrees" that equal either one or two grads. + // This subtraction is meant to change from 400 "degrees" into 360 degrees angle -= (angle + 9) / 10; return angle; } -- cgit v1.2.3 From 078c09c13e5ffa2266bccfd85c38a93d730a02e6 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 9 Jul 2012 01:27:39 +0300 Subject: SCI: Update comments in kGetAngleWorker() --- engines/sci/engine/kmath.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/sci/engine/kmath.cpp') diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index 05c8845288..a643fbe37a 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -89,6 +89,9 @@ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { // differences from the original, which uses custom implementation of atan(). // The differences in the return values are the cause of bug #3540976 // and perhaps bug #3037267 as well. + // The results of this function match the expected results of SCI0, but not + // SCI1 (hence the bug in Longbow). We need to find the point in history + // when this function was changed. // HACK: Return the expected value for Longbow, scene 150 (bug #3540976). // This is a temporary solution, till the function returns the expected @@ -128,7 +131,6 @@ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { // Convert from grads to degrees by merging grad 0 with grad 1, // grad 10 with grad 11, grad 20 with grad 21, etc. This leads to // "degrees" that equal either one or two grads. - // This subtraction is meant to change from 400 "degrees" into 360 degrees angle -= (angle + 9) / 10; return angle; } -- cgit v1.2.3