diff options
-rw-r--r-- | engines/titanic/events.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/game_view.cpp | 11 | ||||
-rw-r--r-- | engines/titanic/rect.cpp | 17 | ||||
-rw-r--r-- | engines/titanic/rect.h | 18 | ||||
-rw-r--r-- | engines/titanic/screen_manager.cpp | 40 | ||||
-rw-r--r-- | engines/titanic/screen_manager.h | 16 | ||||
-rw-r--r-- | engines/titanic/titanic.cpp | 3 | ||||
-rw-r--r-- | engines/titanic/titanic.h | 2 | ||||
-rw-r--r-- | engines/titanic/video_surface.cpp | 35 | ||||
-rw-r--r-- | engines/titanic/video_surface.h | 10 |
10 files changed, 136 insertions, 18 deletions
diff --git a/engines/titanic/events.cpp b/engines/titanic/events.cpp index 6fae102ccc..1f8ccce0dd 100644 --- a/engines/titanic/events.cpp +++ b/engines/titanic/events.cpp @@ -90,7 +90,7 @@ bool Events::checkForNextFrameCounter() { _vm->_debugger->onFrame(); // Display the frame - //_vm->_screen->update(); + _vm->_screen->update(); return true; } diff --git a/engines/titanic/game_view.cpp b/engines/titanic/game_view.cpp index 505e489ee8..d780b8b38e 100644 --- a/engines/titanic/game_view.cpp +++ b/engines/titanic/game_view.cpp @@ -59,13 +59,16 @@ void CGameView::createSurface(const CResourceKey &key) { void CGameView::drawView() { CScreenManager::setCurrent(); - Rect rect1 = _gameManager->_bounds; + Rect srcRect = _gameManager->_bounds; + Rect rect2(0, 0, 600, 340); rect2.translate(20, 10); + srcRect.combine2(rect2); + srcRect.translate(-20, -10); + Common::Point destPos(srcRect.left, srcRect.top); - - - warning("TODO: CGameView_Draw1"); + CScreenManager::_currentScreenManagerPtr->blitFrom(0, _surface, + &destPos, &srcRect); } /*------------------------------------------------------------------------*/ diff --git a/engines/titanic/rect.cpp b/engines/titanic/rect.cpp index deb896fb47..4642b3422c 100644 --- a/engines/titanic/rect.cpp +++ b/engines/titanic/rect.cpp @@ -24,4 +24,21 @@ namespace Titanic { +void Rect::combine1(const Rect &r) { + if (isEmpty() || r.isEmpty()) + return; + + Common::Rect::extend(r); +} + +void Rect::combine2(const Rect &r) { + if (!isEmpty()) { + if (r.isEmpty()) { + clear(); + } else { + Common::Rect::extend(r); + } + } +} + } // End of namespace Titanic diff --git a/engines/titanic/rect.h b/engines/titanic/rect.h index ffd251b4bb..b70550a607 100644 --- a/engines/titanic/rect.h +++ b/engines/titanic/rect.h @@ -35,7 +35,25 @@ public: Rect(int16 w, int16 h) : Common::Rect(w, h) {} Rect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1, y1, x2, y2) {} + /** + * Returns the top/left corner of the rect as a point + */ operator const Point() { return Point(left, top); } + + /** + * Clear the rect + */ + void clear() { left = top = right = bottom = 0; } + + /** + * Combine another rect into this one + */ + void combine1(const Rect &r); + + /** + * Combine another rect into this one + */ + void combine2(const Rect &r); }; } // End of namespace Titanic diff --git a/engines/titanic/screen_manager.cpp b/engines/titanic/screen_manager.cpp index 942bb4179f..4f9fbc2215 100644 --- a/engines/titanic/screen_manager.cpp +++ b/engines/titanic/screen_manager.cpp @@ -123,7 +123,45 @@ CVideoSurface *OSScreenManager::getSurface(int surfaceNum) const { void OSScreenManager::proc9() {} void OSScreenManager::proc10() {} -void OSScreenManager::proc11() {} + +void OSScreenManager::blitFrom(int surfaceNum, CVideoSurface *src, + const Point *destPos, const Rect *srcRect) { + // Get the dest surface + CVideoSurface *destSurface = _frontRenderSurface; + if (surfaceNum < -1) + return; + if (surfaceNum >= 0 && surfaceNum < (int)_backSurfaces.size()) + destSurface = _backSurfaces[surfaceNum]._surface; + if (!destSurface->hasSurface()) + return; + + Point destPoint = destPos ? *destPos : Point(0, 0); + Rect srcBounds = srcRect ? *srcRect : Rect(0, 0, src->getWidth(), src->getHeight()); + Rect *bounds = &srcBounds; + Rect rect2; + + if (surfaceNum >= 0 && !_backSurfaces[surfaceNum]._bounds.isEmpty()) { + // Perform clipping to the bounds of the back surface + rect2 = srcBounds; + rect2.translate(-srcBounds.left, -srcBounds.top); + rect2.translate(destPoint.x, destPoint.y); + rect2.combine2(_backSurfaces[surfaceNum]._bounds); + + rect2.translate(-destPoint.x, -destPoint.y); + rect2.translate(srcBounds.left, srcBounds.top); + + if (rect2.isEmpty()) + return; + + destPoint.x += rect2.left - srcBounds.left; + destPoint.y += rect2.top - srcBounds.top; + bounds = &rect2; + } + + if (!bounds->isEmpty()) + destSurface->blitFrom(destPoint, src, bounds); +} + void OSScreenManager::proc12() {} void OSScreenManager::proc13() {} void OSScreenManager::proc14() {} diff --git a/engines/titanic/screen_manager.h b/engines/titanic/screen_manager.h index 023aa8ea55..dc5a04236f 100644 --- a/engines/titanic/screen_manager.h +++ b/engines/titanic/screen_manager.h @@ -84,7 +84,13 @@ public: virtual CVideoSurface *getSurface(int surfaceNum) const = 0; virtual void proc9() = 0; virtual void proc10() = 0; - virtual void proc11() = 0; + + /** + * Blits a surface onto one of the screen surfaces + */ + virtual void blitFrom(int surfaceNum, CVideoSurface *src, const Point *destPos = nullptr, + const Rect *srcRect = nullptr) = 0; + virtual void proc12() = 0; virtual void proc13() = 0; virtual void proc14() = 0; @@ -160,7 +166,13 @@ public: virtual CVideoSurface *getSurface(int surfaceNum) const; virtual void proc9(); virtual void proc10(); - virtual void proc11(); + + /** + * Blits a surface onto one of the screen surfaces + */ + virtual void blitFrom(int surfaceNum, CVideoSurface *src, const Point *destPos, + const Rect *srcRect = nullptr); + virtual void proc12(); virtual void proc13(); virtual void proc14(); diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp index f29e776791..3c31731346 100644 --- a/engines/titanic/titanic.cpp +++ b/engines/titanic/titanic.cpp @@ -50,12 +50,14 @@ TitanicEngine::TitanicEngine(OSystem *syst, const TitanicGameDescription *gameDe _debugger = nullptr; _events = nullptr; _window = nullptr; + _screen = nullptr; _screenManager = nullptr; } TitanicEngine::~TitanicEngine() { delete _debugger; delete _events; + delete _screen; delete _window; delete _screenManager; CSaveableObject::freeClassList(); @@ -85,6 +87,7 @@ void TitanicEngine::initialize() { _debugger = new Debugger(this); _events = new Events(this); + _screen = new Graphics::Screen(); _screenManager = new OSScreenManager(this); _window = new CMainGameWindow(this); _window->applicationStarting(); diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h index 8ed353f413..94ba316836 100644 --- a/engines/titanic/titanic.h +++ b/engines/titanic/titanic.h @@ -29,6 +29,7 @@ #include "common/serializer.h" #include "engines/advancedDetector.h" #include "engines/engine.h" +#include "graphics/screen.h" #include "titanic/debugger.h" #include "titanic/events.h" #include "titanic/files_manager.h" @@ -96,6 +97,7 @@ public: CFilesManager _filesManager; Debugger *_debugger; Events *_events; + Graphics::Screen *_screen; OSScreenManager *_screenManager; CMainGameWindow *_window; Common::RandomSource _randomSource; diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index 17e8f0ab46..ab5bf7d39c 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -29,8 +29,8 @@ namespace Titanic { int CVideoSurface::_videoSurfaceCounter = 0; CVideoSurface::CVideoSurface(CScreenManager *screenManager) : - _screenManager(screenManager), _rawSurface(nullptr), - _field34(nullptr), _pendingLoad(false), _blitFlag(false), + _screenManager(screenManager), _rawSurface(nullptr), _field34(nullptr), + _pendingLoad(false), _blitStyleFlag(false), _blitFlag(false), _field40(0), _field44(4), _field48(0), _field50(1) { _videoSurfaceNum = _videoSurfaceCounter++; } @@ -46,14 +46,20 @@ void CVideoSurface::setSurface(CScreenManager *screenManager, DirectDrawSurface _ddSurface = surface; } -void CVideoSurface::blitFrom(const Rect &srcRect, const Rect &destRect, CVideoSurface *srcSurface) { - // TODO: Cases when _blitFlag is false - assert(_blitFlag); - error("TODO"); +void CVideoSurface::blitFrom(const Point &destPos, CVideoSurface *src, const Rect *srcRect) { + if (loadIfReady() && src->loadIfReady() && _ddSurface && src->_ddSurface) { + Rect srcBounds, destBounds; + clipBounds(srcBounds, destBounds, src, srcRect, &destPos); + + if (_blitStyleFlag) + blitRect2(srcBounds, destBounds, src); + else + blitRect1(srcBounds, destBounds, src); + } } void CVideoSurface::clipBounds(Rect &srcRect, Rect &destRect, - CVideoSurface *srcSurface, Rect *subRect, Point *pt) { + CVideoSurface *srcSurface, const Rect *subRect, const Point *pt) { if (pt) { srcRect.left = pt->x; srcRect.top = pt->y; @@ -113,6 +119,21 @@ void CVideoSurface::clipBounds(Rect &srcRect, Rect &destRect, error("Invalid rect"); } +void CVideoSurface::blitRect1(const Rect &srcRect, const Rect &destRect, CVideoSurface *src) { + src->lock(); + lock(); + + // TODO: Do it like the original does it + this->_rawSurface->blitFrom(*src->_rawSurface, srcRect, Point(destRect.left, destRect.top)); + + src->unlock(); + unlock(); +} + +void CVideoSurface::blitRect2(const Rect &srcRect, const Rect &destRect, CVideoSurface *src) { + // TODO: Do it like the original does it + blitRect1(srcRect, destRect, src); +} /*------------------------------------------------------------------------*/ diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h index 3538b1dd89..39431f1fae 100644 --- a/engines/titanic/video_surface.h +++ b/engines/titanic/video_surface.h @@ -44,8 +44,11 @@ private: /** * Calculates blitting bounds */ - void clipBounds(Rect &destRect, Rect &srcRect, - CVideoSurface *srcSurface, Rect *bounds2, Point *pt); + void clipBounds(Rect &srcRect, Rect &destRect, + CVideoSurface *srcSurface, const Rect *subRect, const Point *pt); + + void blitRect1(const Rect &srcRect, const Rect &destRect, CVideoSurface *src); + void blitRect2(const Rect &srcRect, const Rect &destRect, CVideoSurface *src); protected: static int _videoSurfaceCounter; protected: @@ -63,6 +66,7 @@ protected: int _lockCount; public: bool _blitFlag; + bool _blitStyleFlag; public: CVideoSurface(CScreenManager *screenManager); virtual ~CVideoSurface(); @@ -152,7 +156,7 @@ public: /** * Blit from another surface */ - void blitFrom(const Rect &srcRect, const Rect &destRect, CVideoSurface *srcSurface); + void blitFrom(const Point &destPos, CVideoSurface *src, const Rect *srcRect = nullptr); }; class OSVideoSurface : public CVideoSurface { |