diff options
author | lukaslw | 2014-07-24 13:13:16 +0200 |
---|---|---|
committer | lukaslw | 2014-07-24 13:13:16 +0200 |
commit | c54699721a5c92755a51608ef478c8a049445ac6 (patch) | |
tree | c919ea614c2ac9ddcc7d40748f8c42c7dfb4d531 | |
parent | 58cb15e89276106c29f95508b2451915c716b0f7 (diff) | |
download | scummvm-rg350-c54699721a5c92755a51608ef478c8a049445ac6.tar.gz scummvm-rg350-c54699721a5c92755a51608ef478c8a049445ac6.tar.bz2 scummvm-rg350-c54699721a5c92755a51608ef478c8a049445ac6.zip |
PRINCE: initZoomIn(), initZoomOut(), doZoomIn(), doZoomOut(), freeZoomObject(). showObject() update
-rw-r--r-- | engines/prince/object.cpp | 8 | ||||
-rw-r--r-- | engines/prince/object.h | 8 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 178 | ||||
-rw-r--r-- | engines/prince/prince.h | 4 |
4 files changed, 152 insertions, 46 deletions
diff --git a/engines/prince/object.cpp b/engines/prince/object.cpp index df241a0daf..1edabb63e0 100644 --- a/engines/prince/object.cpp +++ b/engines/prince/object.cpp @@ -32,8 +32,8 @@ namespace Prince { -Object::Object() : _surface(NULL), _x(0), _y(0), _z(0), _mask(0), _width(0), - _height(0), _zoomInSource(0), _zoomInLen(0), _zoomInAddr(0), _zoomInTime(0) +Object::Object() : _surface(nullptr), _x(0), _y(0), _z(0), _flags(0), _width(0), + _height(0), _zoomTime(0), _zoomSurface(nullptr) { } @@ -41,7 +41,7 @@ Object::~Object() { if (_surface) { _surface->free(); delete _surface; - _surface = NULL; + _surface = nullptr; } } @@ -72,7 +72,7 @@ bool Object::loadFromStream(Common::SeekableReadStream &stream) { } delete obStream; - _mask = stream.readUint16LE(); + _flags = stream.readUint16LE(); _z = stream.readUint16LE(); stream.seek(pos + 16); diff --git a/engines/prince/object.h b/engines/prince/object.h index 3d0257cad4..4a67336c5f 100644 --- a/engines/prince/object.h +++ b/engines/prince/object.h @@ -38,11 +38,9 @@ public: int32 _z; uint16 _width; uint16 _height; - int32 _mask; // or flags - int32 _zoomInSource; - int32 _zoomInLen; - int32 _zoomInAddr; - int32 _zoomInTime; + int32 _flags; + int32 _zoomTime; + Graphics::Surface *_zoomSurface; // Used instead of offset in setData and getData enum AttrId { diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 8f1710593d..b48ba76308 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -1474,58 +1474,162 @@ void PrinceEngine::grabMap() { } void PrinceEngine::initZoomIn(int slot) { - //TODO + freeZoomObject(slot); + Object *object = _objList[slot]; + if (object != nullptr) { + Graphics::Surface *zoomSource = object->getSurface(); + if (zoomSource != nullptr) { + object->_flags |= 0x8000; + object->_zoomSurface = new Graphics::Surface(); + object->_zoomSurface->create(zoomSource->w, zoomSource->h, Graphics::PixelFormat::createFormatCLUT8()); + object->_zoomTime = 20; + } + } } void PrinceEngine::initZoomOut(int slot) { - //TODO + freeZoomObject(slot); + Object *object = _objList[slot]; + if (object != nullptr) { + Graphics::Surface *zoomSource = object->getSurface(); + if (zoomSource != nullptr) { + object->_flags |= 0x4000; + object->_zoomSurface = new Graphics::Surface(); + object->_zoomSurface->copyFrom(*zoomSource); + object->_zoomTime = 10; + } + } +} + +void PrinceEngine::doZoomIn(int slot) { + Object *object = _objList[slot]; + if (object != nullptr) { + Graphics::Surface *orgSurface = object->getSurface(); + if (orgSurface != nullptr) { + byte *src1 = (byte *)orgSurface->getBasePtr(0, 0); + byte *dst1 = (byte *)object->_zoomSurface->getBasePtr(0, 0); + int x = 0; + int w, rand; + for (int y = 0; y < orgSurface->h; y++) { + byte *src2 = src1; + byte *dst2 = dst1; + w = orgSurface->w - x; + src2 += x; + dst2 += x; + while (w > 0) { + rand = _randomSource.getRandomNumber(zoomInStep - 1); + if (rand < w) { + *(dst2 + rand) = *(src2 + rand); + src2 += zoomInStep; + dst2 += zoomInStep; + } else { + *(dst1 + orgSurface->pitch + rand - w) = *(src1 + orgSurface->pitch + rand - w); + } + w -= zoomInStep; + } + x = -1 * w; + src1 += orgSurface->pitch; + dst1 += orgSurface->pitch; + } + } + } +} + +void PrinceEngine::doZoomOut(int slot) { + Object *object = _objList[slot]; + if (object != nullptr) { + Graphics::Surface *orgSurface = object->getSurface(); + if (orgSurface != nullptr) { + byte *dst1 = (byte *)object->_zoomSurface->getBasePtr(0, 0); + int x = 0; + int w, rand; + for (int y = 0; y < orgSurface->h; y++) { + byte *dst2 = dst1; + w = orgSurface->w - x; + dst2 += x; + while (w > 0) { + rand = _randomSource.getRandomNumber(zoomInStep - 1); + if (rand < w) { + *(dst2 + rand) = 255; + dst2 += zoomInStep; + } else { + *(dst1 + orgSurface->pitch + rand - w) = 255; + } + w -= zoomInStep; + } + x = -1 * w; + dst1 += orgSurface->pitch; + } + } + } +} + +void PrinceEngine::freeZoomObject(int slot) { + Object *object = _objList[slot]; + if (object != nullptr) { + if (object->_zoomSurface != nullptr) { + object->_zoomSurface->free(); + delete object->_zoomSurface; + object->_zoomSurface = nullptr; + } + } } void PrinceEngine::showObjects() { for (int i = 0; i < kMaxObjects; i++) { int nr = _objSlot[i]; if (nr != -1) { - if ((_objList[nr]->_mask & 0x8000)) { - _objList[nr]->_zoomInTime--; - if (!_objList[nr]->_zoomInTime) { - _objList[nr]->_mask &= 0x7FFF; + Graphics::Surface *objSurface = nullptr; + if ((_objList[nr]->_flags & 0x8000)) { + _objList[nr]->_zoomTime--; + if (!_objList[nr]->_zoomTime) { + freeZoomObject(nr); + _objList[nr]->_flags &= 0x7FFF; + objSurface = _objList[nr]->getSurface(); } else { - // doZoomIn(); - // mov edx, d [esi.Obj_ZoomInAddr] + doZoomIn(nr); + objSurface = _objList[nr]->_zoomSurface; } - } - if ((_objList[nr]->_mask & 0x4000)) { - _objList[nr]->_zoomInTime--; - if (!_objList[nr]->_zoomInTime) { - _objList[nr]->_mask &= 0xBFFF; + } else if ((_objList[nr]->_flags & 0x4000)) { + _objList[nr]->_zoomTime--; + if (!_objList[nr]->_zoomTime) { + freeZoomObject(nr); + _objList[nr]->_flags &= 0xBFFF; + objSurface = _objList[nr]->getSurface(); } else { - // doZoomOut(); - // mov edx, d [esi.Obj_ZoomInAddr] + doZoomOut(nr); + objSurface = _objList[nr]->_zoomSurface; } + } else { + objSurface = _objList[nr]->getSurface(); } - Graphics::Surface *objSurface = _objList[nr]->getSurface(); - if (spriteCheck(objSurface->w, objSurface->h, _objList[nr]->_x, _objList[nr]->_y)) { - if ((_objList[i]->_mask & 0x0200) == 0) { - int destX = _objList[nr]->_x - _picWindowX; - int destY = _objList[nr]->_y - _picWindowY; - DrawNode newDrawNode; - newDrawNode.posX = destX; - newDrawNode.posY = destY; - newDrawNode.posZ = _objList[nr]->_z; - newDrawNode.width = 0; - newDrawNode.height = 0; - newDrawNode.s = objSurface; - newDrawNode.originalRoomSurface = nullptr; - newDrawNode.data = nullptr; - newDrawNode.freeSurfaceSMemory = false; - newDrawNode.drawFunction = &_graph->drawTransparentDrawNode; - _drawNodeList.push_back(newDrawNode); - } else { - // showBackSprite(); + + if (objSurface != nullptr) { + if (spriteCheck(objSurface->w, objSurface->h, _objList[nr]->_x, _objList[nr]->_y)) { + if ((_objList[i]->_flags & 0x0200) == 0) { + int destX = _objList[nr]->_x - _picWindowX; + int destY = _objList[nr]->_y - _picWindowY; + DrawNode newDrawNode; + newDrawNode.posX = destX; + newDrawNode.posY = destY; + newDrawNode.posZ = _objList[nr]->_z; + newDrawNode.width = 0; + newDrawNode.height = 0; + newDrawNode.s = objSurface; + newDrawNode.originalRoomSurface = nullptr; + newDrawNode.data = nullptr; + newDrawNode.freeSurfaceSMemory = false; + newDrawNode.drawFunction = &_graph->drawTransparentDrawNode; + _drawNodeList.push_back(newDrawNode); + } else { + // showBackSprite(); + error("showBackSprite() - showObjects"); + } + } + + if ((_objList[nr]->_flags & 1)) { + checkMasks(_objList[nr]->_x, _objList[nr]->_y, objSurface->w, objSurface->h, _objList[nr]->_z); } - } - if ((_objList[nr]->_mask & 1)) { - checkMasks(_objList[nr]->_x, _objList[nr]->_y, objSurface->w, objSurface->h, _objList[nr]->_z); } } } diff --git a/engines/prince/prince.h b/engines/prince/prince.h index 4bab84b1d0..239a3b2311 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -432,8 +432,12 @@ public: void talkHero(int slot); void doTalkAnim(int animNumber, int slot, AnimType animType); + static const uint8 zoomInStep = 8; void initZoomIn(int slot); void initZoomOut(int slot); + void doZoomIn(int slot); + void doZoomOut(int slot); + void freeZoomObject(int slot); // Pathfinding static const int16 kPathGridStep = 2; |