From 73204984098c96ecc28a1367a5da9613e7103a35 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 25 Mar 2016 00:01:15 -0400 Subject: [PATCH] TITANIC: Implementing more CTelevision code, CGameState movie list --- engines/titanic/core/game_object.cpp | 16 +++++++++++++ engines/titanic/core/game_object.h | 5 ++++ engines/titanic/core/list.h | 12 ++++++++++ engines/titanic/game/television.cpp | 2 +- engines/titanic/game_state.cpp | 36 +++++++++++++++++++--------- engines/titanic/game_state.h | 18 ++++++++++---- engines/titanic/movie.cpp | 9 ++++++- engines/titanic/movie.h | 10 ++++++-- engines/titanic/titanic.h | 2 ++ engines/titanic/video_surface.cpp | 5 ++++ engines/titanic/video_surface.h | 6 ++++- 11 files changed, 101 insertions(+), 20 deletions(-) diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index a442f099374..a2156339322 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -304,4 +304,20 @@ void CGameObject::fn1(int val1, int val2, int val3) { warning("TODO: CGameObject::fn1"); } +void CGameObject::changeStatus(int newStatus) { + if (_frameNumber == -1 && !_resource.empty()) { + loadResource(_resource); + _resource.clear(); + } + + CVideoSurface *surface = (newStatus & 4) ? _surface : nullptr; + if (_surface) { + _surface->proc32(newStatus, surface); + + if (newStatus & 0x10) { + getGameManager()->_gameState.addMovie(_surface->_movie); + } + } +} + } // End of namespace Titanic diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 46ec502c56c..2f56f599a0e 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -130,6 +130,11 @@ public: bool checkPoint(const Point &pt, int v0, int v1); void fn1(int val1, int val2, int val3); + + /** + * Change the object's status + */ + void changeStatus(int newStatus); }; } // End of namespace Titanic diff --git a/engines/titanic/core/list.h b/engines/titanic/core/list.h index e3623c15b4f..63bd6227b98 100644 --- a/engines/titanic/core/list.h +++ b/engines/titanic/core/list.h @@ -71,6 +71,8 @@ public: template class List : public CSaveableObject, public Common::List { public: + virtual ~List() { destroyContents(); } + /** * Save the data for the class to file */ @@ -145,6 +147,16 @@ public: Common::List::push_back(item); return item; } + + bool contains(const T *item) const { + for (Common::List::const_iterator i = Common::List::begin(); + i != Common::List::end(); ++i) { + if (*i == item) + return true; + } + + return false; + } }; } // End of namespace Titanic diff --git a/engines/titanic/game/television.cpp b/engines/titanic/game/television.cpp index cb59647cc15..8149b8d0173 100644 --- a/engines/titanic/game/television.cpp +++ b/engines/titanic/game/television.cpp @@ -164,7 +164,7 @@ bool CTelevision::handleMessage(CPETDownMsg &msg) { bool CTelevision::handleMessage(CStatusChangeMsg &msg) { if (_isOn) { stopMovie(); - // TODO: + changeStatus(1); } warning("TODO"); diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp index 2885b3ad0c1..d191d982b0d 100644 --- a/engines/titanic/game_state.cpp +++ b/engines/titanic/game_state.cpp @@ -27,9 +27,18 @@ namespace Titanic { -bool CGameStateList::isViewChanging() const { - warning("TODO: CGameStateList::isViewChanging"); - return false; +bool CGameStateMovieList::clear() { + for (iterator i = begin(); i != end(); ) { + CMovieListItem *listItem = *i; + ++i; + + if (!g_vm->_movieList.contains(listItem->_item)) { + remove(listItem); + delete listItem; + } + } + + return size() > 0; } /*------------------------------------------------------------------------*/ @@ -98,20 +107,20 @@ void CGameState::enterNode() { void CGameState::enterView() { CViewItem *oldView = _gameLocation.getView(); - CViewItem *newView = _list._view; + CViewItem *newView = _movieList._view; oldView->preEnterView(newView); _gameManager->_gameView->setView(newView); CRoomItem *oldRoom = oldView->findNode()->findRoom(); CRoomItem *newRoom = newView->findNode()->findRoom(); - _gameManager->playClip(_list._movieClip, oldRoom, newRoom); + _gameManager->playClip(_movieList._movieClip, oldRoom, newRoom); _gameManager->_sound.preEnterView(newView, newRoom != oldRoom); _gameManager->dec54(); oldView->enterView(newView); - _list._view = nullptr; - _list._movieClip = nullptr; + _movieList._view = nullptr; + _movieList._movieClip = nullptr; } void CGameState::triggerLink(CLinkItem *link) { @@ -128,8 +137,8 @@ void CGameState::changeView(CViewItem *newView, CMovieClip *clip) { clip = nullptr; if (_mode == GSMODE_2) { - _list._view = newView; - _list._movieClip = clip; + _movieList._view = newView; + _movieList._movieClip = clip; } else { oldView->preEnterView(newView); _gameManager->_gameView->setView(newView); @@ -147,11 +156,16 @@ void CGameState::changeView(CViewItem *newView, CMovieClip *clip) { } void CGameState::checkForViewChange() { - if (_mode == GSMODE_2 && _list.isViewChanging()) { + if (_mode == GSMODE_2 && _movieList.clear()) { setMode(GSMODE_1); - if (_list._view) + if (_movieList._view) enterView(); } } +void CGameState::addMovie(CMovie *movie) { + _movieList.push_back(new CMovieListItem(movie)); + setMode(GSMODE_2); +} + } // End of namespace Titanic diff --git a/engines/titanic/game_state.h b/engines/titanic/game_state.h index 49bcbcdd97c..49180aa38c8 100644 --- a/engines/titanic/game_state.h +++ b/engines/titanic/game_state.h @@ -27,6 +27,7 @@ #include "titanic/core/link_item.h" #include "titanic/simple_file.h" #include "titanic/game_location.h" +#include "titanic/movie.h" namespace Titanic { @@ -34,21 +35,25 @@ class CGameManager; enum GameStateMode { GSMODE_0 = 0, GSMODE_1 = 1, GSMODE_2 = 2, GSMODE_3 = 3, GSMODE_4 = 4, GSMODE_5 = 5 }; -class CGameStateList : public List { +PTR_LIST_ITEM(CMovie); +class CGameStateMovieList : public List { public: CViewItem *_view; CMovieClip *_movieClip; public: - CGameStateList() : List(), _view(nullptr), _movieClip(nullptr) {} + CGameStateMovieList() : List(), _view(nullptr), _movieClip(nullptr) {} - bool isViewChanging() const; + /** + * Clear the movie list + */ + bool clear(); }; class CGameState { public: CGameManager *_gameManager; CGameLocation _gameLocation; - CGameStateList _list; + CGameStateMovieList _movieList; int _field8; int _fieldC; GameStateMode _mode; @@ -108,6 +113,11 @@ public: * Check for whether it's time to change the active view */ void checkForViewChange(); + + /** + * Adds a movie to the movie list + */ + void addMovie(CMovie *movie); }; } // End of namespace Titanic diff --git a/engines/titanic/movie.cpp b/engines/titanic/movie.cpp index 58da09e61f1..09c02a7964c 100644 --- a/engines/titanic/movie.cpp +++ b/engines/titanic/movie.cpp @@ -21,6 +21,7 @@ */ #include "titanic/movie.h" +#include "titanic/titanic.h" namespace Titanic { @@ -28,7 +29,7 @@ OSMovie::OSMovie(const CResourceKey &name, CVideoSurface *surface) : _videoSurfa // _aviDecoder.loadFile(name.getString()); } -void OSMovie::proc8() { +void OSMovie::proc8(int v1, CVideoSurface *surface) { warning("TODO: OSMovie::proc8"); } @@ -91,4 +92,10 @@ void *OSMovie::proc21() { return nullptr; } +bool OSMovie::isInGlobalList() const { + return g_vm->_movieList.contains(this); +} + +/*------------------------------------------------------------------------*/ + } // End of namespace Titanic diff --git a/engines/titanic/movie.h b/engines/titanic/movie.h index 44097128096..4a5777aa03f 100644 --- a/engines/titanic/movie.h +++ b/engines/titanic/movie.h @@ -33,7 +33,7 @@ class CVideoSurface; class CMovie : public ListItem { public: - virtual void proc8() = 0; + virtual void proc8(int v1, CVideoSurface *surface) = 0; virtual void proc9() = 0; virtual void proc10() = 0; virtual void proc11() = 0; @@ -56,7 +56,7 @@ private: public: OSMovie(const CResourceKey &name, CVideoSurface *surface); - virtual void proc8(); + virtual void proc8(int v1, CVideoSurface *surface); virtual void proc9(); virtual void proc10(); virtual void proc11(); @@ -75,6 +75,12 @@ public: virtual void proc19(); virtual void proc20(); virtual void *proc21(); + + bool isInGlobalList() const; +}; + +class CGlobalMovies : public List { +public: }; } // End of namespace Titanic diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h index 94ba3168363..512dfc39ad2 100644 --- a/engines/titanic/titanic.h +++ b/engines/titanic/titanic.h @@ -33,6 +33,7 @@ #include "titanic/debugger.h" #include "titanic/events.h" #include "titanic/files_manager.h" +#include "titanic/movie.h" #include "titanic/screen_manager.h" #include "titanic/main_game_window.h" @@ -101,6 +102,7 @@ public: OSScreenManager *_screenManager; CMainGameWindow *_window; Common::RandomSource _randomSource; + CGlobalMovies _movieList; public: TitanicEngine(OSystem *syst, const TitanicGameDescription *gameDesc); virtual ~TitanicEngine(); diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index 7a4aba565f0..e8f0e031360 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -299,6 +299,11 @@ void OSVideoSurface::shiftColors() { unlock(); } +void OSVideoSurface::proc32(int v1, CVideoSurface *surface) { + if (loadIfReady() && _movie) + _movie->proc8(v1, surface); +} + void OSVideoSurface::stopMovie() { if (_movie) _movie->stop(); diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h index f3459b456fa..b2390fb3587 100644 --- a/engines/titanic/video_surface.h +++ b/engines/titanic/video_surface.h @@ -57,7 +57,6 @@ protected: CResourceKey _resourceKey; DirectDrawSurface *_ddSurface; Graphics::ManagedSurface *_rawSurface; - CMovie *_movie; bool _pendingLoad; void *_field40; int _field44; @@ -66,6 +65,7 @@ protected: int _field50; int _lockCount; public: + CMovie *_movie; bool _blitFlag; bool _blitStyleFlag; public: @@ -139,6 +139,8 @@ public: */ virtual void shiftColors() = 0; + virtual void proc32(int v1, CVideoSurface *surface) = 0; + /** * Stops any movie currently attached to the surface */ @@ -248,6 +250,8 @@ public: */ virtual void shiftColors(); + virtual void proc32(int v1, CVideoSurface *surface); + /** * Stops any movie currently attached to the surface */