2016-02-22 20:43:14 -05:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-13 15:30:12 -04:00
|
|
|
#include "titanic/titanic.h"
|
2016-02-22 20:43:14 -05:00
|
|
|
#include "titanic/game_manager.h"
|
2016-03-12 19:23:00 -05:00
|
|
|
#include "titanic/game_view.h"
|
2016-04-03 16:16:35 -04:00
|
|
|
#include "titanic/support/screen_manager.h"
|
2016-03-08 22:56:34 -05:00
|
|
|
#include "titanic/core/project_item.h"
|
|
|
|
#include "titanic/messages/messages.h"
|
2016-03-19 22:43:02 -04:00
|
|
|
#include "titanic/pet_control/pet_control.h"
|
2016-02-22 20:43:14 -05:00
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2016-08-05 13:11:12 -04:00
|
|
|
CGameManager::CGameManager(CProjectItem *project, CGameView *gameView, Audio::Mixer *mixer):
|
2016-03-08 22:34:51 -05:00
|
|
|
_project(project), _gameView(gameView), _trueTalkManager(this),
|
2016-10-09 14:59:58 +02:00
|
|
|
_inputHandler(this), _inputTranslator(&_inputHandler),
|
2016-08-05 13:11:12 -04:00
|
|
|
_gameState(this), _sound(this, mixer), _musicRoom(this),
|
2016-06-26 23:00:00 -04:00
|
|
|
_treeItem(nullptr), _soundMaker(nullptr), _movieRoom(nullptr),
|
2016-11-12 19:49:09 -05:00
|
|
|
_dragItem(nullptr), _transitionCtr(0), _lastDiskTicksCount(0), _tickCount2(0) {
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2016-04-09 19:36:12 -04:00
|
|
|
CTimeEventInfo::_nextId = 0;
|
2016-06-26 23:00:00 -04:00
|
|
|
_movie = nullptr;
|
2016-11-28 22:50:22 -05:00
|
|
|
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
2016-03-08 22:56:34 -05:00
|
|
|
_project->setGameManager(this);
|
2016-05-09 21:03:21 -04:00
|
|
|
g_vm->_filesManager->setGameManager(this);
|
2016-02-22 20:43:14 -05:00
|
|
|
}
|
|
|
|
|
2016-06-26 23:00:00 -04:00
|
|
|
CGameManager::~CGameManager() {
|
|
|
|
delete _movie;
|
|
|
|
delete _movieSurface;
|
2016-07-22 12:44:14 -04:00
|
|
|
destroyTreeItem();
|
2016-06-26 23:00:00 -04:00
|
|
|
|
2016-07-22 12:44:14 -04:00
|
|
|
_project->resetGameManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::destroyTreeItem() {
|
2016-06-26 23:00:00 -04:00
|
|
|
if (_treeItem) {
|
|
|
|
_treeItem->destroyAll();
|
|
|
|
_treeItem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:51:44 -04:00
|
|
|
void CGameManager::save(SimpleFile *file) {
|
|
|
|
file->writeNumber(_lastDiskTicksCount);
|
|
|
|
_gameState.save(file);
|
|
|
|
_timers.save(file, 0);
|
|
|
|
_trueTalkManager.save(file);
|
|
|
|
_sound.save(file);
|
|
|
|
}
|
|
|
|
|
2016-02-23 20:59:57 -05:00
|
|
|
void CGameManager::load(SimpleFile *file) {
|
2016-03-08 22:34:51 -05:00
|
|
|
file->readNumber();
|
|
|
|
|
2016-03-10 18:44:18 -05:00
|
|
|
_gameState.load(file);
|
2016-04-09 17:12:41 -04:00
|
|
|
_timers.load(file);
|
2016-03-10 18:44:18 -05:00
|
|
|
_trueTalkManager.load(file);
|
|
|
|
_sound.load(file);
|
2016-02-23 20:59:57 -05:00
|
|
|
}
|
|
|
|
|
2016-03-19 07:48:23 -04:00
|
|
|
void CGameManager::preLoad() {
|
|
|
|
updateDiskTicksCount();
|
2016-04-09 17:12:41 -04:00
|
|
|
_timers.destroyContents();
|
2016-03-19 22:43:02 -04:00
|
|
|
_soundMaker = nullptr;
|
2016-03-19 07:48:23 -04:00
|
|
|
|
|
|
|
_trueTalkManager.preLoad();
|
|
|
|
_sound.preLoad();
|
|
|
|
}
|
|
|
|
|
2016-03-12 19:23:00 -05:00
|
|
|
void CGameManager::postLoad(CProjectItem *project) {
|
|
|
|
if (_gameView) {
|
|
|
|
_gameView->postLoad();
|
|
|
|
|
2016-03-16 19:05:16 -04:00
|
|
|
if (!_gameView->_surface) {
|
2016-03-13 15:07:27 -04:00
|
|
|
CViewItem *view = getView();
|
|
|
|
if (view)
|
|
|
|
_gameView->setView(view);
|
2016-03-12 19:23:00 -05:00
|
|
|
}
|
|
|
|
}
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2016-03-12 19:23:00 -05:00
|
|
|
// Signal to anything interested that the game has been loaded
|
2016-03-19 07:48:23 -04:00
|
|
|
CLoadSuccessMsg msg(_lastDiskTicksCount - _tickCount2);
|
2016-03-12 19:23:00 -05:00
|
|
|
msg.execute(project, nullptr, MSGFLAG_SCAN);
|
2016-03-07 08:11:06 -05:00
|
|
|
|
2016-04-09 17:12:41 -04:00
|
|
|
// Signal to any registered timers
|
|
|
|
_timers.postLoad(_lastDiskTicksCount, _project);
|
2016-03-07 08:11:06 -05:00
|
|
|
|
2016-03-12 19:23:00 -05:00
|
|
|
// Signal the true talk manager and sound
|
|
|
|
_trueTalkManager.postLoad();
|
|
|
|
_sound.postLoad();
|
2016-02-23 20:59:57 -05:00
|
|
|
}
|
|
|
|
|
2016-03-19 08:08:01 -04:00
|
|
|
void CGameManager::preSave(CProjectItem *project) {
|
|
|
|
// Generate a message that a save is being done
|
|
|
|
updateDiskTicksCount();
|
|
|
|
CPreSaveMsg msg(_lastDiskTicksCount);
|
|
|
|
msg.execute(project, nullptr, MSGFLAG_SCAN);
|
|
|
|
|
|
|
|
// Notify sub-objects of the save
|
2016-04-09 19:36:12 -04:00
|
|
|
_timers.preSave(_lastDiskTicksCount);
|
2016-03-19 08:08:01 -04:00
|
|
|
_trueTalkManager.preSave();
|
|
|
|
_sound.preSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::postSave() {
|
2016-04-09 17:12:41 -04:00
|
|
|
_timers.postSave();
|
2016-03-19 08:08:01 -04:00
|
|
|
_trueTalkManager.postSave();
|
2016-05-07 21:54:34 -04:00
|
|
|
_sound.postSave();
|
2016-03-19 08:08:01 -04:00
|
|
|
}
|
|
|
|
|
2016-06-26 23:00:00 -04:00
|
|
|
void CGameManager::roomTransition(CRoomItem *oldRoom, CRoomItem *newRoom) {
|
|
|
|
delete _movie;
|
|
|
|
_movie = nullptr;
|
|
|
|
|
2017-06-18 20:29:40 -04:00
|
|
|
CResourceKey movieKey;
|
|
|
|
if (newRoom == oldRoom) {
|
|
|
|
movieKey = oldRoom->getTransitionMovieKey();
|
|
|
|
_movieRoom = oldRoom;
|
|
|
|
} else {
|
|
|
|
movieKey = oldRoom->getExitMovieKey();
|
|
|
|
}
|
|
|
|
|
2017-02-27 19:45:00 -05:00
|
|
|
CString filename = movieKey.getFilename();
|
2016-06-26 23:00:00 -04:00
|
|
|
if (g_vm->_filesManager->fileExists(filename)) {
|
|
|
|
_movieSurface->freeSurface();
|
2016-07-03 17:43:37 -04:00
|
|
|
_movie = g_vm->_movieManager.createMovie(filename, _movieSurface);
|
2016-06-26 23:00:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 20:56:29 -04:00
|
|
|
void CGameManager::playClip(CMovieClip *clip, CRoomItem *oldRoom, CRoomItem *newRoom) {
|
2016-06-26 23:00:00 -04:00
|
|
|
if (oldRoom != newRoom || newRoom != _movieRoom || !_movie)
|
|
|
|
roomTransition(oldRoom, newRoom);
|
|
|
|
|
|
|
|
if (clip && clip->_startFrame != clip->_endFrame && _movie) {
|
|
|
|
// Clip details specifying a sub-section of movie to play
|
|
|
|
Rect tempRect(20, 10, SCREEN_WIDTH - 20, 350);
|
2016-10-25 23:10:46 -04:00
|
|
|
CMouseCursor &mouseCursor = *CScreenManager::_screenManagerPtr->_mouseCursor;
|
2016-06-26 23:00:00 -04:00
|
|
|
|
|
|
|
lockInputHandler();
|
2016-10-25 23:10:46 -04:00
|
|
|
mouseCursor.incHideCounter();
|
2016-08-14 14:57:23 -04:00
|
|
|
_movie->playCutscene(tempRect, clip->_startFrame, clip->_endFrame);
|
2016-10-25 23:10:46 -04:00
|
|
|
mouseCursor.decHideCounter();
|
2016-06-26 23:00:00 -04:00
|
|
|
unlockInputHandler();
|
|
|
|
}
|
2016-03-19 18:19:45 -04:00
|
|
|
}
|
|
|
|
|
2016-03-18 21:34:04 -04:00
|
|
|
void CGameManager::update() {
|
2016-04-08 20:46:03 -04:00
|
|
|
updateMovies();
|
2016-03-19 22:43:02 -04:00
|
|
|
frameMessage(getRoom());
|
2016-04-09 17:12:41 -04:00
|
|
|
_timers.update(g_vm->_events->getTicksCount());
|
2016-05-07 21:54:34 -04:00
|
|
|
_trueTalkManager.removeCompleted();
|
2016-08-29 22:43:54 -04:00
|
|
|
|
2016-03-19 22:43:02 -04:00
|
|
|
CScreenManager::_screenManagerPtr->_mouseCursor->update();
|
|
|
|
|
|
|
|
CViewItem *view = getView();
|
|
|
|
if (view) {
|
|
|
|
// Expand the game manager's bounds to encompass all the view's items
|
|
|
|
for (CTreeItem *item = view; item; item = item->scan(view)) {
|
2016-03-21 20:53:49 -04:00
|
|
|
Rect r = item->getBounds();
|
2016-03-19 22:43:02 -04:00
|
|
|
if (!r.isEmpty())
|
|
|
|
_bounds.extend(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also include the PET control in the bounds
|
|
|
|
if (_project) {
|
|
|
|
CPetControl *pet = _project->getPetControl();
|
|
|
|
if (pet)
|
|
|
|
_bounds.extend(pet->getBounds());
|
|
|
|
}
|
|
|
|
|
|
|
|
// And the text cursor
|
|
|
|
CScreenManager *screenManager = CScreenManager::_screenManagerPtr;
|
|
|
|
CTextCursor *textCursor = screenManager->_textCursor;
|
2016-03-19 23:02:41 -04:00
|
|
|
if (textCursor && textCursor->_active)
|
2016-04-26 22:18:21 -04:00
|
|
|
_bounds.extend(textCursor->getCursorBounds());
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2016-03-19 22:43:02 -04:00
|
|
|
// Set the surface bounds
|
2016-03-22 21:54:26 -04:00
|
|
|
screenManager->setSurfaceBounds(SURFACE_BACKBUFFER, _bounds);
|
2016-03-19 22:43:02 -04:00
|
|
|
|
2016-03-20 00:01:40 -04:00
|
|
|
// Handle redrawing the view
|
2016-03-19 22:43:02 -04:00
|
|
|
if (!_bounds.isEmpty()) {
|
2016-03-20 00:01:40 -04:00
|
|
|
_gameView->draw(_bounds);
|
2016-03-21 20:53:49 -04:00
|
|
|
_bounds = Rect();
|
2016-03-19 22:43:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_gameState.checkForViewChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 20:46:03 -04:00
|
|
|
void CGameManager::updateMovies() {
|
2016-07-20 07:38:13 -04:00
|
|
|
// Initial iteration to mark all the movies as not yet handled
|
|
|
|
for (CMovieList::iterator i = CMovie::_playingMovies->begin();
|
|
|
|
i != CMovie::_playingMovies->end(); ++i)
|
|
|
|
(*i)->_handled = false;
|
|
|
|
|
2016-07-09 11:32:15 -04:00
|
|
|
bool repeatFlag;
|
|
|
|
do {
|
|
|
|
repeatFlag = false;
|
|
|
|
|
2016-07-20 07:38:13 -04:00
|
|
|
// Scan for a movie to process
|
2016-07-09 11:32:15 -04:00
|
|
|
for (CMovieList::iterator i = CMovie::_playingMovies->begin();
|
2016-07-20 07:38:13 -04:00
|
|
|
i != CMovie::_playingMovies->end(); ++i) {
|
2016-07-09 11:32:15 -04:00
|
|
|
CMovie *movie = *i;
|
2016-07-20 07:38:13 -04:00
|
|
|
if (movie->_handled)
|
2016-07-09 11:32:15 -04:00
|
|
|
continue;
|
|
|
|
|
2016-12-18 21:07:04 -05:00
|
|
|
// Flag the movie to have been handled
|
|
|
|
movie->_handled = true;
|
|
|
|
|
2016-07-09 11:32:15 -04:00
|
|
|
CMovieEventList eventsList;
|
|
|
|
if (!movie->handleEvents(eventsList))
|
|
|
|
movie->removeFromPlayingMovies();
|
|
|
|
|
|
|
|
while (!eventsList.empty()) {
|
|
|
|
CMovieEvent *movieEvent = eventsList.front();
|
|
|
|
|
|
|
|
switch (movieEvent->_type) {
|
|
|
|
case MET_MOVIE_END: {
|
|
|
|
CMovieEndMsg endMsg(movieEvent->_startFrame, movieEvent->_endFrame);
|
|
|
|
endMsg.execute(movieEvent->_gameObject);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MET_FRAME: {
|
|
|
|
CMovieFrameMsg frameMsg(movieEvent->_initialFrame, 0);
|
|
|
|
frameMsg.execute(movieEvent->_gameObject);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
eventsList.remove(movieEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
repeatFlag = true;
|
2016-04-09 14:24:52 -04:00
|
|
|
break;
|
|
|
|
}
|
2016-07-09 11:32:15 -04:00
|
|
|
} while (repeatFlag);
|
2016-03-18 21:34:04 -04:00
|
|
|
}
|
|
|
|
|
2016-03-19 07:48:23 -04:00
|
|
|
void CGameManager::updateDiskTicksCount() {
|
|
|
|
_lastDiskTicksCount = g_vm->_events->getTicksCount();
|
|
|
|
}
|
|
|
|
|
2017-06-11 16:19:54 -04:00
|
|
|
void CGameManager::roomChange() {
|
2016-06-26 23:00:00 -04:00
|
|
|
delete _movie;
|
|
|
|
delete _movieSurface;
|
2016-03-19 09:29:11 -04:00
|
|
|
|
2016-06-26 23:00:00 -04:00
|
|
|
_movie = nullptr;
|
2016-11-28 22:50:22 -05:00
|
|
|
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
2016-05-05 20:28:32 -04:00
|
|
|
_trueTalkManager.clear();
|
2016-03-19 09:29:11 -04:00
|
|
|
|
|
|
|
for (CTreeItem *treeItem = _project; treeItem; treeItem = treeItem->scan(_project))
|
2017-06-11 17:06:46 -04:00
|
|
|
treeItem->freeSurface();
|
2016-03-19 09:29:11 -04:00
|
|
|
|
2017-01-14 18:19:12 -05:00
|
|
|
markAllDirty();
|
2016-03-19 09:29:11 -04:00
|
|
|
}
|
|
|
|
|
2016-03-19 22:43:02 -04:00
|
|
|
void CGameManager::frameMessage(CRoomItem *room) {
|
|
|
|
if (room) {
|
|
|
|
// Signal the next frame
|
|
|
|
CFrameMsg frameMsg(g_vm->_events->getTicksCount());
|
|
|
|
frameMsg.execute(room, nullptr, MSGFLAG_SCAN);
|
|
|
|
|
2017-02-16 21:34:59 -05:00
|
|
|
if (_gameState._soundMakerAllowed && !_soundMaker) {
|
2016-03-19 22:43:02 -04:00
|
|
|
// Check for a sound maker in the room
|
|
|
|
_soundMaker = dynamic_cast<CBackgroundSoundMaker *>(
|
|
|
|
_project->findByName("zBackgroundSoundMaker"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's a sound maker, dispatch the event to it as well
|
|
|
|
if (_soundMaker)
|
|
|
|
frameMsg.execute(_soundMaker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:19:12 -05:00
|
|
|
void CGameManager::addDirtyRect(const Rect &r) {
|
2016-03-22 07:44:45 -04:00
|
|
|
if (_bounds.isEmpty())
|
|
|
|
_bounds = r;
|
|
|
|
else
|
2016-03-22 22:36:49 -04:00
|
|
|
_bounds.combine(r);
|
2016-03-22 07:44:45 -04:00
|
|
|
}
|
|
|
|
|
2017-01-14 18:19:12 -05:00
|
|
|
void CGameManager::markAllDirty() {
|
|
|
|
_bounds = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2016-04-09 14:24:52 -04:00
|
|
|
CScreenManager *CGameManager::setScreenManager() const {
|
|
|
|
return CScreenManager::setCurrent();
|
|
|
|
}
|
|
|
|
|
2016-05-02 19:23:29 -04:00
|
|
|
CString CGameManager::getFullViewName() {
|
|
|
|
CViewItem *view = getView();
|
|
|
|
CNodeItem *node = view->findNode();
|
|
|
|
CRoomItem *room = node->findRoom();
|
|
|
|
|
|
|
|
return CString::format("%s.%s.%s", room->getName().c_str(),
|
|
|
|
node->getName().c_str(), view->getName().c_str());
|
|
|
|
}
|
|
|
|
|
2016-03-12 19:23:00 -05:00
|
|
|
} // End of namespace Titanic
|