2016-02-23 01:43:14 +00: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "titanic/game_manager.h"
|
2016-03-09 03:56:34 +00:00
|
|
|
#include "titanic/core/project_item.h"
|
2017-08-24 11:05:49 +00:00
|
|
|
#include "titanic/events.h"
|
|
|
|
#include "titanic/game_view.h"
|
2016-03-09 03:56:34 +00:00
|
|
|
#include "titanic/messages/messages.h"
|
2016-03-20 02:43:02 +00:00
|
|
|
#include "titanic/pet_control/pet_control.h"
|
2017-08-24 11:05:49 +00:00
|
|
|
#include "titanic/sound/background_sound_maker.h"
|
|
|
|
#include "titanic/support/files_manager.h"
|
|
|
|
#include "titanic/support/screen_manager.h"
|
|
|
|
#include "titanic/titanic.h"
|
2016-02-23 01:43:14 +00:00
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2016-08-05 17:11:12 +00:00
|
|
|
CGameManager::CGameManager(CProjectItem *project, CGameView *gameView, Audio::Mixer *mixer):
|
2016-03-09 03:34:51 +00:00
|
|
|
_project(project), _gameView(gameView), _trueTalkManager(this),
|
2016-10-09 12:59:58 +00:00
|
|
|
_inputHandler(this), _inputTranslator(&_inputHandler),
|
2016-08-05 17:11:12 +00:00
|
|
|
_gameState(this), _sound(this, mixer), _musicRoom(this),
|
2016-06-27 03:00:00 +00:00
|
|
|
_treeItem(nullptr), _soundMaker(nullptr), _movieRoom(nullptr),
|
2016-11-13 00:49:09 +00:00
|
|
|
_dragItem(nullptr), _transitionCtr(0), _lastDiskTicksCount(0), _tickCount2(0) {
|
2016-10-09 12:59:58 +00:00
|
|
|
|
2016-04-09 23:36:12 +00:00
|
|
|
CTimeEventInfo::_nextId = 0;
|
2016-06-27 03:00:00 +00:00
|
|
|
_movie = nullptr;
|
2016-11-29 03:50:22 +00:00
|
|
|
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
2016-03-09 03:56:34 +00:00
|
|
|
_project->setGameManager(this);
|
2016-05-10 01:03:21 +00:00
|
|
|
g_vm->_filesManager->setGameManager(this);
|
2016-02-23 01:43:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 03:00:00 +00:00
|
|
|
CGameManager::~CGameManager() {
|
|
|
|
delete _movie;
|
|
|
|
delete _movieSurface;
|
2016-07-22 16:44:14 +00:00
|
|
|
destroyTreeItem();
|
2016-06-27 03:00:00 +00:00
|
|
|
|
2016-07-22 16:44:14 +00:00
|
|
|
_project->resetGameManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::destroyTreeItem() {
|
2016-06-27 03:00:00 +00:00
|
|
|
if (_treeItem) {
|
|
|
|
_treeItem->destroyAll();
|
|
|
|
_treeItem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 01:51:44 +00:00
|
|
|
void CGameManager::save(SimpleFile *file) {
|
|
|
|
file->writeNumber(_lastDiskTicksCount);
|
|
|
|
_gameState.save(file);
|
|
|
|
_timers.save(file, 0);
|
|
|
|
_trueTalkManager.save(file);
|
|
|
|
_sound.save(file);
|
|
|
|
}
|
|
|
|
|
2016-02-24 01:59:57 +00:00
|
|
|
void CGameManager::load(SimpleFile *file) {
|
2016-03-09 03:34:51 +00:00
|
|
|
file->readNumber();
|
|
|
|
|
2016-03-10 23:44:18 +00:00
|
|
|
_gameState.load(file);
|
2016-04-09 21:12:41 +00:00
|
|
|
_timers.load(file);
|
2016-03-10 23:44:18 +00:00
|
|
|
_trueTalkManager.load(file);
|
|
|
|
_sound.load(file);
|
2016-02-24 01:59:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 11:48:23 +00:00
|
|
|
void CGameManager::preLoad() {
|
|
|
|
updateDiskTicksCount();
|
2016-04-09 21:12:41 +00:00
|
|
|
_timers.destroyContents();
|
2016-03-20 02:43:02 +00:00
|
|
|
_soundMaker = nullptr;
|
2016-03-19 11:48:23 +00:00
|
|
|
|
|
|
|
_sound.preLoad();
|
2017-08-19 02:30:38 +00:00
|
|
|
_trueTalkManager.preLoad();
|
2016-03-19 11:48:23 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
void CGameManager::postLoad(CProjectItem *project) {
|
|
|
|
if (_gameView) {
|
|
|
|
_gameView->postLoad();
|
|
|
|
|
2016-03-16 23:05:16 +00:00
|
|
|
if (!_gameView->_surface) {
|
2016-03-13 19:07:27 +00:00
|
|
|
CViewItem *view = getView();
|
|
|
|
if (view)
|
|
|
|
_gameView->setView(view);
|
2016-03-13 00:23:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-09 12:59:58 +00:00
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
// Signal to anything interested that the game has been loaded
|
2016-03-19 11:48:23 +00:00
|
|
|
CLoadSuccessMsg msg(_lastDiskTicksCount - _tickCount2);
|
2016-03-13 00:23:00 +00:00
|
|
|
msg.execute(project, nullptr, MSGFLAG_SCAN);
|
2016-03-07 13:11:06 +00:00
|
|
|
|
2016-04-09 21:12:41 +00:00
|
|
|
// Signal to any registered timers
|
|
|
|
_timers.postLoad(_lastDiskTicksCount, _project);
|
2016-03-07 13:11:06 +00:00
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
// Signal the true talk manager and sound
|
|
|
|
_trueTalkManager.postLoad();
|
|
|
|
_sound.postLoad();
|
2016-02-24 01:59:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 12:08:01 +00: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 23:36:12 +00:00
|
|
|
_timers.preSave(_lastDiskTicksCount);
|
2016-03-19 12:08:01 +00:00
|
|
|
_trueTalkManager.preSave();
|
|
|
|
_sound.preSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::postSave() {
|
2016-04-09 21:12:41 +00:00
|
|
|
_timers.postSave();
|
2016-03-19 12:08:01 +00:00
|
|
|
_trueTalkManager.postSave();
|
2016-05-08 01:54:34 +00:00
|
|
|
_sound.postSave();
|
2016-03-19 12:08:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 03:00:00 +00:00
|
|
|
void CGameManager::roomTransition(CRoomItem *oldRoom, CRoomItem *newRoom) {
|
|
|
|
delete _movie;
|
|
|
|
_movie = nullptr;
|
|
|
|
|
2017-06-19 00:29:40 +00:00
|
|
|
CResourceKey movieKey;
|
|
|
|
if (newRoom == oldRoom) {
|
|
|
|
movieKey = oldRoom->getTransitionMovieKey();
|
|
|
|
_movieRoom = oldRoom;
|
|
|
|
} else {
|
|
|
|
movieKey = oldRoom->getExitMovieKey();
|
2017-06-21 01:55:52 +00:00
|
|
|
_movieRoom = nullptr;
|
2017-06-19 00:29:40 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:45:00 +00:00
|
|
|
CString filename = movieKey.getFilename();
|
2016-06-27 03:00:00 +00:00
|
|
|
if (g_vm->_filesManager->fileExists(filename)) {
|
|
|
|
_movieSurface->freeSurface();
|
2016-07-03 21:43:37 +00:00
|
|
|
_movie = g_vm->_movieManager.createMovie(filename, _movieSurface);
|
2016-06-27 03:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-20 00:56:29 +00:00
|
|
|
void CGameManager::playClip(CMovieClip *clip, CRoomItem *oldRoom, CRoomItem *newRoom) {
|
2016-06-27 03:00:00 +00: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-26 03:10:46 +00:00
|
|
|
CMouseCursor &mouseCursor = *CScreenManager::_screenManagerPtr->_mouseCursor;
|
2016-06-27 03:00:00 +00:00
|
|
|
|
|
|
|
lockInputHandler();
|
2016-10-26 03:10:46 +00:00
|
|
|
mouseCursor.incHideCounter();
|
2016-08-14 18:57:23 +00:00
|
|
|
_movie->playCutscene(tempRect, clip->_startFrame, clip->_endFrame);
|
2016-10-26 03:10:46 +00:00
|
|
|
mouseCursor.decHideCounter();
|
2016-06-27 03:00:00 +00:00
|
|
|
unlockInputHandler();
|
|
|
|
}
|
2016-03-19 22:19:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 01:34:04 +00:00
|
|
|
void CGameManager::update() {
|
2016-04-09 00:46:03 +00:00
|
|
|
updateMovies();
|
2016-03-20 02:43:02 +00:00
|
|
|
frameMessage(getRoom());
|
2016-04-09 21:12:41 +00:00
|
|
|
_timers.update(g_vm->_events->getTicksCount());
|
2016-05-08 01:54:34 +00:00
|
|
|
_trueTalkManager.removeCompleted();
|
2016-08-30 02:43:54 +00:00
|
|
|
|
2016-03-20 02:43:02 +00:00
|
|
|
CScreenManager::_screenManagerPtr->_mouseCursor->update();
|
|
|
|
|
|
|
|
CViewItem *view = getView();
|
|
|
|
if (view) {
|
2017-07-08 00:55:12 +00:00
|
|
|
// Expand the game manager's bounds to encompass any modified
|
|
|
|
// areas of any of the view's items
|
2016-03-20 02:43:02 +00:00
|
|
|
for (CTreeItem *item = view; item; item = item->scan(view)) {
|
2016-03-22 00:53:49 +00:00
|
|
|
Rect r = item->getBounds();
|
2016-03-20 02:43:02 +00:00
|
|
|
if (!r.isEmpty())
|
2017-07-08 00:55:12 +00:00
|
|
|
_bounds.combine(r);
|
2016-03-20 02:43:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 00:55:12 +00:00
|
|
|
// Also include any modified area of the PET control
|
2016-03-20 02:43:02 +00:00
|
|
|
if (_project) {
|
|
|
|
CPetControl *pet = _project->getPetControl();
|
2017-07-24 12:09:00 +00:00
|
|
|
|
2016-03-20 02:43:02 +00:00
|
|
|
if (pet)
|
2017-07-08 00:55:12 +00:00
|
|
|
_bounds.combine(pet->getBounds());
|
2016-03-20 02:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And the text cursor
|
|
|
|
CScreenManager *screenManager = CScreenManager::_screenManagerPtr;
|
|
|
|
CTextCursor *textCursor = screenManager->_textCursor;
|
2016-03-20 03:02:41 +00:00
|
|
|
if (textCursor && textCursor->_active)
|
2017-07-08 00:55:12 +00:00
|
|
|
_bounds.combine(textCursor->getCursorBounds());
|
2016-10-09 12:59:58 +00:00
|
|
|
|
2017-07-08 00:55:12 +00:00
|
|
|
// Set the screen's modified area bounds
|
2017-07-08 20:27:05 +00:00
|
|
|
screenManager->setSurfaceBounds(SURFACE_PRIMARY, _bounds);
|
2016-03-20 02:43:02 +00:00
|
|
|
|
2017-07-08 00:55:12 +00:00
|
|
|
// Handle redrawing the view if there is any changed area
|
2016-03-20 02:43:02 +00:00
|
|
|
if (!_bounds.isEmpty()) {
|
2016-03-20 04:01:40 +00:00
|
|
|
_gameView->draw(_bounds);
|
2016-03-22 00:53:49 +00:00
|
|
|
_bounds = Rect();
|
2016-03-20 02:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_gameState.checkForViewChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 00:46:03 +00:00
|
|
|
void CGameManager::updateMovies() {
|
2016-07-20 11:38:13 +00: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 15:32:15 +00:00
|
|
|
bool repeatFlag;
|
|
|
|
do {
|
|
|
|
repeatFlag = false;
|
|
|
|
|
2016-07-20 11:38:13 +00:00
|
|
|
// Scan for a movie to process
|
2016-07-09 15:32:15 +00:00
|
|
|
for (CMovieList::iterator i = CMovie::_playingMovies->begin();
|
2016-07-20 11:38:13 +00:00
|
|
|
i != CMovie::_playingMovies->end(); ++i) {
|
2016-07-09 15:32:15 +00:00
|
|
|
CMovie *movie = *i;
|
2016-07-20 11:38:13 +00:00
|
|
|
if (movie->_handled)
|
2016-07-09 15:32:15 +00:00
|
|
|
continue;
|
|
|
|
|
2016-12-19 02:07:04 +00:00
|
|
|
// Flag the movie to have been handled
|
|
|
|
movie->_handled = true;
|
|
|
|
|
2016-07-09 15:32:15 +00: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);
|
2017-09-24 16:15:58 +00:00
|
|
|
delete movieEvent;
|
2016-07-09 15:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
repeatFlag = true;
|
2016-04-09 18:24:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-07-09 15:32:15 +00:00
|
|
|
} while (repeatFlag);
|
2016-03-19 01:34:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 11:48:23 +00:00
|
|
|
void CGameManager::updateDiskTicksCount() {
|
|
|
|
_lastDiskTicksCount = g_vm->_events->getTicksCount();
|
|
|
|
}
|
|
|
|
|
2017-06-11 20:19:54 +00:00
|
|
|
void CGameManager::roomChange() {
|
2016-06-27 03:00:00 +00:00
|
|
|
delete _movie;
|
|
|
|
delete _movieSurface;
|
2016-03-19 13:29:11 +00:00
|
|
|
|
2016-06-27 03:00:00 +00:00
|
|
|
_movie = nullptr;
|
2016-11-29 03:50:22 +00:00
|
|
|
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
2016-05-06 00:28:32 +00:00
|
|
|
_trueTalkManager.clear();
|
2016-03-19 13:29:11 +00:00
|
|
|
|
|
|
|
for (CTreeItem *treeItem = _project; treeItem; treeItem = treeItem->scan(_project))
|
2017-06-11 21:06:46 +00:00
|
|
|
treeItem->freeSurface();
|
2016-03-19 13:29:11 +00:00
|
|
|
|
2017-01-14 23:19:12 +00:00
|
|
|
markAllDirty();
|
2016-03-19 13:29:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-20 02:43:02 +00: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-17 02:34:59 +00:00
|
|
|
if (_gameState._soundMakerAllowed && !_soundMaker) {
|
2016-03-20 02:43:02 +00: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 23:19:12 +00:00
|
|
|
void CGameManager::addDirtyRect(const Rect &r) {
|
2016-03-22 11:44:45 +00:00
|
|
|
if (_bounds.isEmpty())
|
|
|
|
_bounds = r;
|
|
|
|
else
|
2016-03-23 02:36:49 +00:00
|
|
|
_bounds.combine(r);
|
2016-03-22 11:44:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 23:19:12 +00:00
|
|
|
void CGameManager::markAllDirty() {
|
|
|
|
_bounds = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:24:52 +00:00
|
|
|
CScreenManager *CGameManager::setScreenManager() const {
|
|
|
|
return CScreenManager::setCurrent();
|
|
|
|
}
|
|
|
|
|
2016-05-02 23:23:29 +00: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-13 00:23:00 +00:00
|
|
|
} // End of namespace Titanic
|