diff options
author | uruk | 2014-05-10 11:12:30 +0200 |
---|---|---|
committer | uruk | 2014-05-10 11:12:30 +0200 |
commit | 724899fc1939e26b1805deb9f9c9c7fc19c9a5ee (patch) | |
tree | 4a31803d6af543801481c025683b51c32b4399fd /engines/cge2 | |
parent | c75c026df8897c3a7aa4721a4e8f204e92f08daf (diff) | |
download | scummvm-rg350-724899fc1939e26b1805deb9f9c9c7fc19c9a5ee.tar.gz scummvm-rg350-724899fc1939e26b1805deb9f9c9c7fc19c9a5ee.tar.bz2 scummvm-rg350-724899fc1939e26b1805deb9f9c9c7fc19c9a5ee.zip |
CGE2: Rework Sprite a bit, make _eye an engine variable.
Also move screenToGround() during the process.
Diffstat (limited to 'engines/cge2')
-rw-r--r-- | engines/cge2/cge2.cpp | 6 | ||||
-rw-r--r-- | engines/cge2/cge2.h | 5 | ||||
-rw-r--r-- | engines/cge2/general.h | 46 | ||||
-rw-r--r-- | engines/cge2/hero.cpp | 7 | ||||
-rw-r--r-- | engines/cge2/hero.h | 13 | ||||
-rw-r--r-- | engines/cge2/vga13h.cpp | 46 | ||||
-rw-r--r-- | engines/cge2/vga13h.h | 8 |
7 files changed, 64 insertions, 67 deletions
diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index c3ec6a92eb..986c616b65 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -33,6 +33,7 @@ #include "cge2/sound.h" #include "cge2/text.h" #include "cge2/hero.h" +#include "cge2/general.h" namespace CGE2 { @@ -47,6 +48,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _text = nullptr; for (int i = 0; i < 2; i++) _heroTab[i] = nullptr; + _eye = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -65,7 +67,8 @@ void CGE2Engine::init() { _midiPlayer = new MusicPlayer(this); _text = new Text(this, "CGE"); for (int i = 0; i < 2; i++) - _heroTab[i] = new HeroTab(); + _heroTab[i] = new HeroTab(this); + _eye = new V3D(); } void CGE2Engine::deinit() { @@ -78,6 +81,7 @@ void CGE2Engine::deinit() { delete _text; for (int i = 0; i < 2; i++) delete _heroTab[i]; + delete _eye; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 79ac2c7488..e4a40426f7 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -32,7 +32,6 @@ #include "engines/advancedDetector.h" #include "common/system.h" #include "cge2/fileio.h" -#include "cge2/general.h" namespace CGE2 { @@ -43,6 +42,9 @@ class Fx; class Sound; class Text; struct HeroTab; +class V3D; +class V2D; +class Dac; #define kScrWidth 320 #define kScrHeight 240 @@ -91,6 +93,7 @@ public: Sound *_sound; Text *_text; HeroTab *_heroTab[2]; + V3D *_eye; private: void init(); void deinit(); diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 9da00be6cd..9c89f525ac 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -31,6 +31,7 @@ #include "common/file.h" #include "common/rect.h" #include "cge2/fileio.h" +#include "cge2/cge2.h" namespace CGE2 { @@ -60,49 +61,44 @@ public: }; class V2D : public Common::Point { - static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } - static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } + CGE2Engine *_vm; public: V2D& operator = (const V3D& p3) { - double m = Eye._z / (p3._z - Eye._z); - x = round((Eye._x + (Eye._x - p3._x) * m)); - y = round((Eye._y + (Eye._y - p3._y) * m)); + double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); + x = round((_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m)); + y = round((_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m)); return *this; } - V2D(void) { } - V2D(const V3D& p3) { *this = p3; } - V2D(int x, int y) : Common::Point(x, y) { } - static V3D Eye; - static void setEye(const V3D &e) { Eye = e; } - static void setEye(const V2D& e2, int z = -SCR_WID_) { - Eye._x = e2.x; Eye._y = e2.y; Eye._z = z; + V2D(CGE2Engine *vm) : _vm(vm) { } + V2D(CGE2Engine *vm, const V3D& p3) : _vm(vm) { *this = p3; } + V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } + void setEye(V3D &e) { _vm->_eye = &e; } + void setEye(const V2D& e2, int z = -SCR_WID_) { + _vm->_eye->_x = e2.x; _vm->_eye->_y = e2.y; _vm->_eye->_z = z; } - static void setEye(const char *s) { + void setEye(const char *s) { char *tempStr; strcpy(tempStr, s); - Eye._x = atoi(EncryptedStream::token(tempStr)); - Eye._y = atoi(EncryptedStream::token(tempStr)); - Eye._z = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_x = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_y = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_z = atoi(EncryptedStream::token(tempStr)); } bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } bool operator >(const V2D& p) const { return (x > p.x) && (y > p.y); } bool operator >= (const V2D& p) const { return (x >= p.x) && (y >= p.y); } - V2D operator + (const V2D& p) const { return V2D(x + p.x, y + p.y); } - V2D operator - (const V2D& p) const { return V2D(x - p.x, y - p.y); } + V2D operator + (const V2D& p) const { return V2D(_vm, x + p.x, y + p.y); } + V2D operator - (const V2D& p) const { return V2D(_vm, x - p.x, y - p.y); } uint16 area(void) { return x * y; } bool limited(const V2D& p) { return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); } V2D scale(int z) { - double m = Eye._z / (Eye._z - z); - return V2D(trunc(m * x), trunc(m * y)); - } - static V3D screenToGround(V2D pos) { - double z = V2D::Eye._z + (V2D::Eye._y*V2D::Eye._z) / (double(pos.y) - V2D::Eye._y); - double x = V2D::Eye._x - ((double(pos.x) - V2D::Eye._x) * (z - V2D::Eye._z)) / V2D::Eye._z; - return V3D(round(x), 0, round(z)); + double m = _vm->_eye->_z / (_vm->_eye->_z - z); + return V2D(_vm, trunc(m * x), trunc(m * y)); } + static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } + static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } }; } // End of namespace CGE2 diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 44ff85040d..3a6d1d2920 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -117,6 +117,13 @@ void Hero::walkTo(Sprite *spr) { warning("STUB: Hero::walkTo()"); } +V3D Hero::screenToGround(V2D pos) { + double z = _vm->_eye->_z + (_vm->_eye->_y * _vm->_eye->_z) / (double(pos.y) - _vm->_eye->_y); + double x = _vm->_eye->_x - ((double(pos.x) - _vm->_eye->_x) * (z - _vm->_eye->_z)) / _vm->_eye->_z; + return V3D(V2D::round(x), 0, V2D::round(z)); +} + + int Hero::cross(const V2D &a, const V2D &b) { warning("STUB: Hero::cross()"); return 0; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 21f4ec39e7..032a46d1b3 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -42,7 +42,15 @@ struct HeroTab { Sprite *_face; Sprite *_pocket[kPocketMax + 1]; int _pocPtr; - V2D _posTab[kCaveMax]; + V2D *_posTab[kCaveMax]; + HeroTab(CGE2Engine *vm) { + for (int i = 0; i < kCaveMax; i++) + _posTab[i] = new V2D(vm); + } + ~HeroTab() { + for (int i = 0; i < kCaveMax; i++) + delete _posTab[i]; + } }; class Hero : public Sprite { @@ -72,7 +80,8 @@ public: bool findWay(void); static int snap(int p, int q, int grid); void walkTo(V3D pos); - void walkTo(V2D pos) { walkTo(V2D::screenToGround(pos)); } + void walkTo(V2D pos) { walkTo(screenToGround(pos)); } + V3D screenToGround(V2D pos); void walkTo(Sprite *spr); void say(void) { step(_sayStart); } void fun(void); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index a696cad554..0a9add0633 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -60,10 +60,10 @@ byte Sprite::_constY = 0; byte Sprite::_follow = 0; Sprite::Sprite(CGE2Engine *vm) - : _siz(0, 0), _nearPtr(0), _takePtr(0), + : _siz(_vm, 0, 0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), _ext(NULL), _ref(-1), _scene(0), _vm(vm), - _pos2D(kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); @@ -76,10 +76,10 @@ Sprite::Sprite(CGE2Engine *vm) } Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) - : _siz(0, 0), _nearPtr(0), _takePtr(0), + : _siz(_vm, 0, 0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), _ext(NULL), _ref(-1), _scene(0), _vm(vm), - _pos2D(kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); @@ -383,18 +383,7 @@ Sprite *Sprite::backShow(bool fast) { } void Sprite::step(int nr) { - if (nr >= 0) - _seqPtr = nr; - if (_ext) { - Seq *seq; - if (nr < 0) - _seqPtr = _ext->_seq[_seqPtr]._next; - seq = _ext->_seq + _seqPtr; - if (seq->_dly >= 0) { - gotoxyz(_x + (seq->_dx), _y + (seq->_dy)); - _time = seq->_dly; - } - } + warning("STUB: Sprite::step()"); } //void Sprite::tick() { @@ -449,26 +438,13 @@ void Sprite::center() { } void Sprite::show() { - SprExt *e; - e = _ext; - e->_x0 = e->_x1; - e->_y0 = e->_y1; - e->_b0 = e->_b1; - e->_x1 = _x; - e->_y1 = _y; - e->_b1 = shp(); - if (!_flags._hide) { - if (_flags._xlat) - e->_b1->xShow(e->_x1, e->_y1); - else - e->_b1->show(e->_x1, e->_y1); - } + warning("STUB: Sprite::show()"); } void Sprite::show(uint16 pg) { Graphics::Surface *a = _vm->_vga->_page[1]; _vm->_vga->_page[1] = _vm->_vga->_page[pg & 3]; - shp()->show(_x, _y); + shp()->show(_pos2D.x, _pos2D.y); _vm->_vga->_page[1] = a; } @@ -545,9 +521,9 @@ void Sprite::sync(Common::Serializer &s) { warning("STUB: Sprite::sync() - Flags changed compared to CGE1's Sprite type."); - s.syncAsUint16LE(_x); - s.syncAsUint16LE(_y); - s.syncAsByte(_z); + s.syncAsUint16LE(_pos3D._x); + s.syncAsUint16LE(_pos3D._y); + s.syncAsByte(_pos3D._z); s.syncAsUint16LE(_w); s.syncAsUint16LE(_h); s.syncAsUint16LE(_time); @@ -614,7 +590,7 @@ void Queue::insert(Sprite *spr, Sprite *nxt) { void Queue::insert(Sprite *spr) { Sprite *s; for (s = _head; s; s = s->_next) - if (s->_z > spr->_z) + if (s->_pos3D._z > spr->_pos3D._z) break; if (s) insert(spr, s); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 8061acf411..487df10ba8 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -105,9 +105,6 @@ public: uint16 _zmov : 1; // sprite needs Z-update in queue uint16 _tran : 1; // transparent (untouchable) } _flags; - int _x; - int _y; - signed char _z; uint16 _w; uint16 _h; uint16 _time; @@ -119,6 +116,11 @@ public: Sprite *_prev; Sprite *_next; struct { byte _ptr, _cnt; } _actionCtrl[kActions]; + V2D _pos2D; + V3D _pos3D; + V2D _siz; + static byte _constY; + static byte _follow; bool works(Sprite *spr); bool seqTest(int n); |