diff options
author | Paul Gilbert | 2014-08-01 11:16:39 -0400 |
---|---|---|
committer | Paul Gilbert | 2014-08-01 11:16:39 -0400 |
commit | 0d662566bd2706919e8ed9c7abf79c5f0767f591 (patch) | |
tree | 272143a3076f75a3bcc7e81e39f6ee62f29ffeae /engines/cge2 | |
parent | 6d278157e16927f483d6cc397c0fe2d959cf22bb (diff) | |
download | scummvm-rg350-0d662566bd2706919e8ed9c7abf79c5f0767f591.tar.gz scummvm-rg350-0d662566bd2706919e8ed9c7abf79c5f0767f591.tar.bz2 scummvm-rg350-0d662566bd2706919e8ed9c7abf79c5f0767f591.zip |
CGE2: Further fixes to FXP operators to fix pathfinding
Diffstat (limited to 'engines/cge2')
-rw-r--r-- | engines/cge2/vga13h.cpp | 45 | ||||
-rw-r--r-- | engines/cge2/vga13h.h | 4 |
2 files changed, 47 insertions, 2 deletions
diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 9340abf09e..cdf683d380 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -45,6 +45,51 @@ void V3D::sync(Common::Serializer &s) { _z.sync(s); } +FXP FXP::operator*(const FXP& x) const { + FXP y; + int32 t1 = (v >> 8) * x.v; + int32 t2 = (v & 0xFF) * x.v; + + y.v = t1 + t2; + return y; +} + +FXP FXP::operator/(const FXP& x) const { + FXP y; + if (x.v != 0) { + int32 v1 = this->v; + int32 v2 = x.v; + bool negFlag = false; + + if (v1 < 0) { + v1 = -v1; + negFlag = true; + } + if (v2 < 0) { + v2 = -v2; + negFlag ^= true; + } + + int32 v3 = v1 / v2; + v1 -= v3 * v2; + v3 <<= 8; + + if (v1 < 0xFFFFFF) { + v1 <<= 8; + } else { + v2 >>= 8; + } + v3 += v1 / v2; + + if (negFlag) + v3 = -v3; + + y.v = v3; + } + + return y; +} + void FXP::sync(Common::Serializer &s) { s.syncAsSint32LE(v); } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index f3354c5489..52efd39849 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -60,8 +60,8 @@ public: FXP& operator=(const int& x) { v = x << 8; return *this; } FXP operator+(const FXP& x) const { FXP y; y.v = v + x.v; return y; } FXP operator-(const FXP& x) const { FXP y; y.v = v - x.v; return y; } - FXP operator*(const FXP& x) const { FXP y; y.v = v * x.v / 256; return y; } - FXP operator/(const FXP& x) const { FXP y; y.v = (x.v == 0) ? 0 : v * 256 / x.v; return y; } + FXP operator*(const FXP& x) const; + FXP operator/(const FXP& x) const; //int& operator = (int& a, const FXP& b) { return a = b.i; } friend int& operator+=(int& a, const FXP& b) { return a += b.trunc(); } |