From 4e2e1d5fcfbc5837932b84ee73cfaf705dd2a5fa Mon Sep 17 00:00:00 2001 From: SupSuper Date: Mon, 22 Feb 2021 00:29:56 +0000 Subject: [PATCH] TRECISION: Clean up maths --- engines/trecision/nl/3d/3drend.cpp | 18 ++++++++---------- engines/trecision/nl/3d/3dwalk.cpp | 8 ++++---- engines/trecision/nl/schedule.cpp | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/engines/trecision/nl/3d/3drend.cpp b/engines/trecision/nl/3d/3drend.cpp index 954dbf64021..b4ac954ad1d 100644 --- a/engines/trecision/nl/3d/3drend.cpp +++ b/engines/trecision/nl/3d/3drend.cpp @@ -772,8 +772,7 @@ void drawCharacter(uint8 flag) { pa2 /= t; tz = acos((pa0 * l0) + (pa1 * l1) + (pa2 * l2)) * 360.0 / PI2; - tz = (tz > 180) ? 180 : tz; - tz = (tz < 0) ? 0 : tz; + tz = CLIP(tz, 0.f, 180.f); // tx falloff // ty hospot @@ -826,8 +825,7 @@ void drawCharacter(uint8 flag) { pa2 = _vertex->_nz; lint = (int)((acos(pa0 * l0 + pa1 * l1 + pa2 * l2) * 360.0) / PI); - lint = (lint > 180) ? 180 : lint; - lint = (lint < 0) ? 0 : lint; + lint = CLIP(lint, 0, 180); _vVertex[a]._angle -= (180 - lint); _vertex++; @@ -875,13 +873,13 @@ void drawCharacter(uint8 flag) { _vVertex[a]._y = (short)_y2d; _vVertex[a]._z = (short)((dist - l2) * 128.0); - _actor._lim[0] = (_x2d < _actor._lim[0]) ? _x2d : _actor._lim[0]; - _actor._lim[1] = (_x2d > _actor._lim[1]) ? _x2d : _actor._lim[1]; - _actor._lim[2] = (_y2d < _actor._lim[2]) ? _y2d : _actor._lim[2]; - _actor._lim[3] = (_y2d > _actor._lim[3]) ? _y2d : _actor._lim[3]; + _actor._lim[0] = MIN(_x2d, _actor._lim[0]); + _actor._lim[1] = MAX(_x2d, _actor._lim[1]); + _actor._lim[2] = MIN(_y2d, _actor._lim[2]); + _actor._lim[3] = MAX(_y2d, _actor._lim[3]); - _actor._lim[4] = (_vVertex[a]._z < _actor._lim[4]) ? _vVertex[a]._z : _actor._lim[4]; - _actor._lim[5] = (_vVertex[a]._z > _actor._lim[5]) ? _vVertex[a]._z : _actor._lim[5]; + _actor._lim[4] = MIN(_vVertex[a]._z, _actor._lim[4]); + _actor._lim[5] = MAX(_vVertex[a]._z, _actor._lim[5]); _vertex++; } diff --git a/engines/trecision/nl/3d/3dwalk.cpp b/engines/trecision/nl/3d/3dwalk.cpp index a0430371ad9..9c3d5670803 100644 --- a/engines/trecision/nl/3d/3dwalk.cpp +++ b/engines/trecision/nl/3d/3dwalk.cpp @@ -1605,10 +1605,10 @@ int intersectLinePanel(struct SPan *p, float x, float y, float z) { _y3d = y1 + dy * t; _z3d = z1 + dz * t; - float minx = (p->_x1 < p->_x2) ? p->_x1 - 1.5 : p->_x2 - 1.5; - float maxx = (p->_x1 > p->_x2) ? p->_x1 + 1.5 : p->_x2 + 1.5; - float minz = (p->_z1 < p->_z2) ? p->_z1 - 1.5 : p->_z2 - 1.5; - float maxz = (p->_z1 > p->_z2) ? p->_z1 + 1.5 : p->_z2 + 1.5; + float minx = MIN(p->_x1, p->_x2) - 1.5; + float maxx = MAX(p->_x1, p->_x2) + 1.5; + float minz = MIN(p->_z1, p->_z2) - 1.5; + float maxz = MAX(p->_z1, p->_z2) + 1.5; // check if it fits inside the panel if ((_x3d >= minx) && (_x3d <= maxx) && (_y3d >= 0.0) && (_y3d <= p->_h) && (_z3d >= minz) && (_z3d <= maxz)) diff --git a/engines/trecision/nl/schedule.cpp b/engines/trecision/nl/schedule.cpp index bbab399c1e8..11462649ed2 100644 --- a/engines/trecision/nl/schedule.cpp +++ b/engines/trecision/nl/schedule.cpp @@ -222,7 +222,7 @@ void MessageQueue::orderEvents() { /* TESTEMPTYQUEUE */ /*-------------------------------------------------------------------------*/ bool MessageQueue::testEmptyQueue(uint8 cls) { - for (uint8 pos = _head; pos != _tail; pos = (pos == MAXMESSAGE - 1) ? 0 : pos + 1) { + for (uint8 pos = _head; pos != _tail; pos = (pos + 1) % MAXMESSAGE) { if (_event[pos]->_class != cls) return false; } @@ -234,7 +234,7 @@ bool MessageQueue::testEmptyQueue(uint8 cls) { /* TESTEMPTYCHARACTERQUEUE4SCRIPT */ /*-------------------------------------------------------------------------*/ bool MessageQueue::testEmptyCharacterQueue4Script() { - for (uint8 pos = _head; pos != _tail; pos = (pos == MAXMESSAGE - 1) ? 0 : pos + 1) { + for (uint8 pos = _head; pos != _tail; pos = (pos + 1) % MAXMESSAGE) { if (_event[pos]->_class != MC_CHARACTER) continue;