From f141b337177bb0bd001c753f8cb17999b6ea2bf9 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 27 Jun 2016 19:19:04 -0400 Subject: TITANIC: Adding CGameObject methods --- engines/titanic/core/game_object.cpp | 151 ++++++++++++++++++++++---------- engines/titanic/core/game_object.h | 50 ++++++++++- engines/titanic/core/tree_item.h | 10 ++- engines/titanic/support/video_surface.h | 2 +- 4 files changed, 159 insertions(+), 54 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 72a6e9249b..795ed92236 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -143,6 +143,70 @@ void CGameObject::load(SimpleFile *file) { CNamedItem::load(file); } +void CGameObject::draw(CScreenManager *screenManager) { + if (!_visible) + return; + if (_credits) { + error("TODO: Block in CGameObject::draw"); + } + + if (_field40) { + if (_field90) { + if (_bounds.intersects(getGameManager()->_bounds)) + warning("TODO: _field90(screenManager);"); + } + } + else { + if (!_surface) { + if (!_resource.empty()) { + loadResource(_resource); + _resource = ""; + } + } + + if (_surface) { + _bounds.setWidth(_surface->getWidth()); + _bounds.setHeight(_surface->getHeight()); + + if (!_bounds.width() || !_bounds.height()) + return; + + if (_frameNumber >= 0) { + loadFrame(_frameNumber); + _frameNumber = -1; + } + + if (!_clipList2.empty()) + processClipList2(); + + if (_bounds.intersects(getGameManager()->_bounds)) { + if (_surface) { + Point destPos(_bounds.left, _bounds.top); + screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &destPos); + } + + if (_field90) + warning("TODO: sub_415f80(screenManager);"); + } + } + } +} + +Rect CGameObject::getBounds() const { + return (_surface && _surface->proc45()) ? _bounds : Rect(); +} + +void CGameObject::viewChange() { + // Handle freeing the surfaces of objects when their view is left + if (_surface) { + _resource = _surface->_resourceKey.getString(); + _initialFrame = getMovieFrame(); + + delete _surface; + _surface = nullptr; + } +} + void CGameObject::stopMovie() { if (_surface) _surface->stopMovie(); @@ -214,54 +278,6 @@ void CGameObject::draw(CScreenManager *screenManager, const Point &destPos, cons draw(screenManager, Rect(destPos.x, destPos.y, destPos.x + 52, destPos.y + 52), srcRect); } -void CGameObject::draw(CScreenManager *screenManager) { - if (!_visible) - return; - if (_credits) { - error("TODO: Block in CGameObject::draw"); - } - - if (_field40) { - if (_field90) { - if (_bounds.intersects(getGameManager()->_bounds)) - warning("TODO: _field90(screenManager);"); - } - } else { - if (!_surface) { - if (!_resource.empty()) { - loadResource(_resource); - _resource = ""; - } - } - - if (_surface) { - _bounds.setWidth(_surface->getWidth()); - _bounds.setHeight(_surface->getHeight()); - - if (!_bounds.width() || !_bounds.height()) - return; - - if (_frameNumber >= 0) { - loadFrame(_frameNumber); - _frameNumber = -1; - } - - if (!_clipList2.empty()) - processClipList2(); - - if (_bounds.intersects(getGameManager()->_bounds)) { - if (_surface) { - Point destPos(_bounds.left, _bounds.top); - screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &destPos); - } - - if (_field90) - warning("TODO: sub_415f80(screenManager);"); - } - } - } -} - bool CGameObject::isPet() const { return isInstanceOf(CPetControl::_type); } @@ -369,6 +385,10 @@ bool CGameObject::soundFn1(int handle) { return false; } +void CGameObject::soundFn2(const CString &resName, int v1, int v2, int v3, int handleIndex) { + warning("TODO: CGameObject::soundFn2"); +} + void CGameObject::soundFn3(int handle, int val2, int val3) { if (handle != 0 && handle != -1) { CGameManager *gameManager = getGameManager(); @@ -377,6 +397,14 @@ void CGameObject::soundFn3(int handle, int val2, int val3) { } } +void CGameObject::soundFn4(int v1, int v2, int v3) { + warning("CGameObject::soundFn4"); +} + +void CGameObject::soundFn5(int v1, int v2, int v3) { + warning("CGameObject::soundFn5"); +} + void CGameObject::setVisible(bool val) { if (val != _visible) { _visible = val; @@ -402,6 +430,24 @@ void CGameObject::petShowCursor() { pet->showCursor(); } +void CGameObject::petShow() { + CGameManager *gameManager = getGameManager(); + if (gameManager) { + gameManager->_gameState._petActive = true; + gameManager->_gameState.setMode(GSMODE_SELECTED); + gameManager->initBounds(); + } +} + +void CGameObject::petHide() { + CGameManager *gameManager = getGameManager(); + if (gameManager) { + gameManager->_gameState._petActive = false; + gameManager->_gameState.setMode(GSMODE_SELECTED); + gameManager->initBounds(); + } +} + void CGameObject::petSetRemoteTarget() { CPetControl *pet = getPetControl(); if (pet) @@ -886,6 +932,11 @@ void CGameObject::petClear() const { petControl->resetActiveNPC(); } +CDontSaveFileItem *CGameObject::getDontSave() const { + CProjectItem *project = getRoot(); + return project ? project->getDontSaveFileItem() : nullptr; +} + CPetControl *CGameObject::getPetControl() const { return static_cast(getDontSaveChild(CPetControl::_type)); } @@ -1005,6 +1056,10 @@ int CGameObject::getClipDuration(const CString &name, int frameRate) const { return clip ? (clip->_endFrame - clip->_startFrame) * 1000 / frameRate : 0; } +uint32 CGameObject::getTickCount() { + return g_vm->_events->getTicksCount(); +} + bool CGameObject::compareRoomFlags(int mode, uint flags1, uint flags2) { switch (mode) { case 1: diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 4d53bd3e6e..a744cd116a 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -36,6 +36,7 @@ namespace Titanic { enum Find { FIND_GLOBAL = 1, FIND_ROOM = 2, FIND_PET = 4, FIND_MAILMAN = 8 }; enum Found { FOUND_NONE = 0, FOUND_GLOBAL = 1, FOUND_ROOM = 2, FOUND_PET = 3, FOUND_MAILMAN = 4 }; +class CDontSaveFileItem; class CMailMan; class CMusicRoom; class CRoomItem; @@ -157,8 +158,14 @@ protected: bool soundFn1(int handle); + void soundFn2(const CString &resName, int v1, int v2, int v3, int handleIndex); + void soundFn3(int handle, int val2, int val3); + void soundFn4(int v1, int v2, int v3); + + void soundFn5(int v1, int v2, int v3); + /** * Adds a timer */ @@ -289,6 +296,11 @@ protected: */ CMailMan *getMailMan() const; + /** + * Gets the don't save container object + */ + CDontSaveFileItem *getDontSave() const; + /** * Returns a child of the Dont Save area of the project of the given class */ @@ -337,6 +349,11 @@ protected: */ int getClipDuration(const CString &name, int frameRate = 14) const; + /** + * Returns the current system tick count + */ + uint32 getTickCount(); + void setState1C(bool flag); /** @@ -409,25 +426,40 @@ public: */ virtual void load(SimpleFile *file); + /** + * Returns the clip list, if any, associated with the item + */ + virtual const CMovieClipList *getClipList() const { return &_clipList1; } + /** * Allows the item to draw itself */ - void draw(CScreenManager *screenManager, const Rect &destRect, const Rect &srcRect); + virtual void draw(CScreenManager *screenManager); + + /** + * Gets the bounds occupied by the item + */ + virtual Rect getBounds() const; + + /** + * Called when the view changes + */ + virtual void viewChange(); /** * Allows the item to draw itself */ - void draw(CScreenManager *screenManager, const Point &destPos); + void draw(CScreenManager *screenManager, const Rect &destRect, const Rect &srcRect); /** * Allows the item to draw itself */ - void draw(CScreenManager *screenManager, const Point &destPos, const Rect &srcRect); + void draw(CScreenManager *screenManager, const Point &destPos); /** * Allows the item to draw itself */ - virtual void draw(CScreenManager *screenManager); + void draw(CScreenManager *screenManager, const Point &destPos, const Rect &srcRect); /** * Returns true if the item is the PET control @@ -608,6 +640,11 @@ public: int petGetRooms1D0() const; + /** + * Hide the PET + */ + void petHide(); + /** * Hides the text cursor in the current section, if applicable */ @@ -645,6 +682,11 @@ public: void petSetRooms1D0(int val); + /** + * Show the PET + */ + void petShow(); + /** * Shows the text cursor in the current section, if applicable */ diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h index 2ea7b4249e..77d7aa59b5 100644 --- a/engines/titanic/core/tree_item.h +++ b/engines/titanic/core/tree_item.h @@ -29,6 +29,7 @@ namespace Titanic { class CGameManager; +class CMovieClipList; class CNamedItem; class CProjectItem; class CScreenManager; @@ -128,6 +129,13 @@ public: */ virtual int compareTo(const CString &name, int maxLen) const { return false; } + virtual int proc23() const { return 0; } + + /** + * Returns the clip list, if any, associated with the item + */ + virtual const CMovieClipList *getClipList() const { return nullptr; } + /** * Returns true if the given item connects to another specified view */ @@ -141,7 +149,7 @@ public: /** * Gets the bounds occupied by the item */ - virtual Rect getBounds() { return Rect(); } + virtual Rect getBounds() const { return Rect(); } /** * Called when the view changes diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h index 8d0dd2ffac..6f707a39ff 100644 --- a/engines/titanic/support/video_surface.h +++ b/engines/titanic/support/video_surface.h @@ -54,7 +54,6 @@ protected: static int _videoSurfaceCounter; protected: CScreenManager *_screenManager; - CResourceKey _resourceKey; Graphics::ManagedSurface *_rawSurface; bool _pendingLoad; void *_field40; @@ -68,6 +67,7 @@ public: DirectDrawSurface *_ddSurface; bool _blitFlag; bool _blitStyleFlag; + CResourceKey _resourceKey; public: CVideoSurface(CScreenManager *screenManager); virtual ~CVideoSurface(); -- cgit v1.2.3