diff options
author | Strangerke | 2014-08-03 14:06:50 +0200 |
---|---|---|
committer | Strangerke | 2014-08-03 14:47:25 +0200 |
commit | 2697c71301caaad90436b89dfd911e8a7d911457 (patch) | |
tree | ae030252fc7f7c78bf7c26a716a6cd68533eb300 | |
parent | 60a77ae6d76195180707dfe67a3d34eb95b8ca74 (diff) | |
download | scummvm-rg350-2697c71301caaad90436b89dfd911e8a7d911457.tar.gz scummvm-rg350-2697c71301caaad90436b89dfd911e8a7d911457.tar.bz2 scummvm-rg350-2697c71301caaad90436b89dfd911e8a7d911457.zip |
CGE2: Misc cleanup
-rw-r--r-- | engines/cge2/hero.cpp | 52 | ||||
-rw-r--r-- | engines/cge2/text.cpp | 7 | ||||
-rw-r--r-- | engines/cge2/vga13h.cpp | 32 |
3 files changed, 48 insertions, 43 deletions
diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 91f6354ce3..e8267b5af2 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -254,13 +254,11 @@ Sprite *Hero::setContact() { Sprite *spr; int md = _maxDist << 1; for (spr = _vm->_vga->_showQ->first(); spr; spr = spr->_next) { - if (spr->_actionCtrl[kNear]._cnt && (spr->_ref & 255) != 255) { - if (distance(spr) <= md) { - if (spr == _contact) - return nullptr; - else - break; - } + if (spr->_actionCtrl[kNear]._cnt && ((spr->_ref & 255) != 255) && (distance(spr) <= md)) { + if (spr == _contact) + return nullptr; + else + break; } } return (_contact = spr); @@ -321,8 +319,10 @@ void Hero::tick() { } if (_flags._trim) gotoxyz_(_pos2D); + if (_pos3D._z.trunc() != z) _flags._zmov = true; + if (--_funDel == 0) fun(); } @@ -345,12 +345,11 @@ int Hero::distance(Sprite *spr) { pos._x = _pos3D._x; else pos._x += mdx; - } else { - if (dx < mdx) - pos._x = _pos3D._x; - else - pos._x += mdx; - } + } else if (dx < mdx) + pos._x = _pos3D._x; + else + pos._x += mdx; + return distance(pos); } @@ -419,15 +418,14 @@ int Hero::len(V2D v) { bool Hero::findWay(){ V2D p0(_vm, _pos3D._x.round(), _pos3D._z.round()); V2D p1(_vm, _trace[_tracePtr]._x.round(), _trace[_tracePtr]._z.round()); - bool pvOk; - bool phOk; V2D ph(_vm, p1.x, p0.y); V2D pv(_vm, p0.x, p1.y); - pvOk = (!mapCross(p0, pv) && !mapCross(pv, p1)); - phOk = (!mapCross(p0, ph) && !mapCross(ph, p1)); + bool pvOk = (!mapCross(p0, pv) && !mapCross(pv, p1)); + bool phOk = (!mapCross(p0, ph) && !mapCross(ph, p1)); int md = (_maxDist >> 1); if (pvOk && (len(ph - p0) <= md || len(p1 - ph) <= md)) return true; + if (phOk && (len(pv - p0) <= md || len(p1 - pv) <= md)) return true; @@ -435,16 +433,17 @@ bool Hero::findWay(){ _trace[++_tracePtr] = V3D(pv.x, 0, pv.y); return true; } + if (phOk) { _trace[++_tracePtr] = V3D(ph.x, 0, ph.y); return true; } + return false; } int Hero::snap(int p, int q, int grid) { - int d = q - p; - d = ((d >= 0) ? d : -d) % grid; + int d = abs(q - p) % grid; if (d > (grid >> 1)) d -= grid; return (q >= p) ? (q - d) : (q + d); @@ -453,6 +452,7 @@ int Hero::snap(int p, int q, int grid) { void Hero::walkTo(V3D pos) { if (distance(pos) <= _maxDist) return; + int stp = stepSize(); pos._x = snap(_pos3D._x.round(), pos._x.round(), stp); pos._y = 0; @@ -512,26 +512,21 @@ int Hero::cross(const V2D &a, const V2D &b) { } bool CGE2Engine::cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d) { - if (contain(a, b, c)) - return true; - if (contain(a, b, d)) - return true; - if (contain(c, d, a)) - return true; - if (contain(c, d, b)) + if (contain(a, b, c) || contain(a, b, d) || contain(c, d, a) || contain(c, d, b)) return true; + return sgn(det(a, b, c)) != sgn(det(a, b, d)) && sgn(det(c, d, a)) != sgn(det(c, d, b)); } bool CGE2Engine::contain(const V2D &a, const V2D &b, const V2D &p) { if (det(a, b, p)) return false; + return ((long)(a.x - p.x) * (p.x - b.x) >= 0 && (long)(a.y - p.y) * (p.y - b.y) >= 0); } long CGE2Engine::det(const V2D &a, const V2D &b, const V2D &c) { - long n = ((long)a.x * b.y + (long)b.x * c.y + (long)c.x * a.y) - ((long)c.x * b.y + (long)b.x * a.y + (long)a.x * c.y); - return n; + return ((long)a.x * b.y + (long)b.x * c.y + (long)c.x * a.y) - ((long)c.x * b.y + (long)b.x * a.y + (long)a.x * c.y); } int CGE2Engine::sgn(long n) { @@ -543,6 +538,7 @@ int Hero::mapCross(const V2D &a, const V2D &b) { int n = (o->_scene == _scene) ? o->cross(a, b) : 0; if (!_ignoreMap) n += _vm->mapCross(a, b); + return n; } diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index ca4c33625e..605eed047f 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -157,10 +157,9 @@ void Text::say(const char *text, Sprite *spr) { if (east) { if (pos.x + sw + kTextRoundCorner + kCaptionSide >= kScrWidth) east = false; - } else { - if (pos.x <= kCaptionSide + kTextRoundCorner - sw) - east = true; - } + } else if (pos.x <= kCaptionSide + kTextRoundCorner - sw) + east = true; + if (east != (d.x > 0)) { d.x = -d.x; sw = -sw; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 486a42259f..424138f6b0 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -74,11 +74,11 @@ FXP FXP::operator/(const FXP& x) const { v1 -= v3 * v2; v3 <<= 8; - if (v1 < 0xFFFFFF) { + if (v1 < 0xFFFFFF) v1 <<= 8; - } else { + else v2 >>= 8; - } + v3 += v1 / v2; if (negFlag) @@ -231,14 +231,16 @@ void Sprite::setName(char *newName) { int Sprite::labVal(Action snq, int lab) { int lv = -1; if (active()) { - int n = _actionCtrl[snq]._cnt; + int count = _actionCtrl[snq]._cnt; CommandHandler::Command *com = snList(snq); - int i; - for (i = 0; i < n; i++) + int i = 0; + for (; i < count; i++) { if (com[i]._lab == lab) break; - if (i < n) + } + + if (i < count) return i; } else { char tmpStr[kLineMax + 1]; @@ -431,7 +433,7 @@ Sprite *Sprite::expand() { if (curSeq) { if (maxnow >= shpcnt) error("Bad PHASE in SEQ %s", fname); - if (maxnxt && maxnxt >= seqcnt) + if (maxnxt && (maxnxt >= seqcnt)) error("Bad JUMP in SEQ %s", fname); setSeq(curSeq); } else { @@ -811,9 +813,10 @@ void Queue::insert(Sprite *spr) { return; // We only queue it if it's not already queued. Sprite *s; - for (s = _head; s; s = s->_next) + for (s = _head; s; s = s->_next) { if (s->_pos3D._z < spr->_pos3D._z) break; + } if (s) insert(spr, s); @@ -829,12 +832,16 @@ inline bool contains(const Common::List<T> &l, const T &v) { Sprite *Queue::remove(Sprite *spr) { if (spr == _head) _head = spr->_next; + if (spr == _tail) _tail = spr->_prev; + if (spr->_next) spr->_next->_prev = spr->_prev; + if (spr->_prev) spr->_prev->_next = spr->_next; + spr->_prev = nullptr; spr->_next = nullptr; return spr; @@ -850,9 +857,11 @@ Sprite *Queue::locate(int ref) { bool Queue::locate(Sprite *spr) { Sprite *s; - for (s = _head; s; s = s->_next) + for (s = _head; s; s = s->_next) { if (s == spr) return true; + } + return false; } @@ -889,6 +898,7 @@ Vga::~Vga() { free(_newColors); if (_msg) buffer = Common::String(_msg); + if (_name) buffer = buffer + " [" + _name + "]"; @@ -1005,7 +1015,7 @@ void Vga::setColors(Dac *tab, int lum) { if (_mono) { destP = _newColors; for (int idx = 0; idx < kPalCount; idx++, destP++) { - // Form a greyscalce color from 30% R, 59% G, 11% B + // Form a grayscale color from 30% R, 59% G, 11% B uint8 intensity = (((int)destP->_r * 77) + ((int)destP->_g * 151) + ((int)destP->_b * 28)) >> 8; destP->_r = intensity; destP->_g = intensity; |