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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-13 19:30:12 +00:00
|
|
|
#include "titanic/titanic.h"
|
2016-02-23 01:43:14 +00:00
|
|
|
#include "titanic/game_manager.h"
|
2016-03-13 00:23:00 +00:00
|
|
|
#include "titanic/game_view.h"
|
2016-02-23 02:15:20 +00:00
|
|
|
#include "titanic/screen_manager.h"
|
2016-03-09 03:56:34 +00:00
|
|
|
#include "titanic/core/project_item.h"
|
|
|
|
#include "titanic/messages/messages.h"
|
2016-03-20 02:43:02 +00:00
|
|
|
#include "titanic/pet_control/pet_control.h"
|
2016-02-23 01:43:14 +00:00
|
|
|
|
|
|
|
namespace Titanic {
|
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
void CGameManagerList::postLoad(uint ticks, CProjectItem *project) {
|
|
|
|
for (iterator i = begin(); i != end(); ++i)
|
|
|
|
(*i)->postLoad(ticks, project);
|
|
|
|
}
|
|
|
|
|
2016-03-19 12:08:01 +00:00
|
|
|
void CGameManagerList::preSave() {
|
|
|
|
for (iterator i = begin(); i != end(); ++i)
|
|
|
|
(*i)->preSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManagerList::postSave() {
|
|
|
|
for (iterator i = begin(); i != end(); ++i)
|
|
|
|
(*i)->postSave();
|
|
|
|
}
|
|
|
|
|
2016-03-20 02:43:02 +00:00
|
|
|
void CGameManagerList::update(uint ticks) {
|
|
|
|
warning("TODO: CGameManagerList::update");
|
|
|
|
}
|
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void CGameManagerListItem::postLoad(uint ticks, CProjectItem *project) {
|
|
|
|
warning("TODO");
|
|
|
|
}
|
|
|
|
|
2016-03-19 12:08:01 +00:00
|
|
|
void CGameManagerListItem::preSave() {
|
|
|
|
warning("TODO: CGameManagerListItem::preSave");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManagerListItem::postSave() {
|
|
|
|
warning("TODO: CGameManagerListItem::postSave");
|
|
|
|
}
|
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2016-02-23 01:43:14 +00:00
|
|
|
CGameManager::CGameManager(CProjectItem *project, CGameView *gameView):
|
2016-03-09 03:34:51 +00:00
|
|
|
_project(project), _gameView(gameView), _trueTalkManager(this),
|
|
|
|
_inputHandler(this), _inputTranslator(&_inputHandler),
|
|
|
|
_gameState(this), _sound(this), _musicRoom(this),
|
2016-03-20 02:43:02 +00:00
|
|
|
_field30(0), _soundMaker(nullptr), _field4C(0),
|
2016-03-19 11:48:23 +00:00
|
|
|
_dragItem(nullptr), _field54(0), _lastDiskTicksCount(0), _tickCount2(0) {
|
2016-03-15 03:09:57 +00:00
|
|
|
|
|
|
|
_videoSurface1 = nullptr;
|
|
|
|
_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
2016-03-09 03:56:34 +00:00
|
|
|
_project->setGameManager(this);
|
2016-03-15 03:09:57 +00:00
|
|
|
g_vm->_filesManager.setGameManager(this);
|
2016-02-23 01:43:14 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
_list.load(file);
|
|
|
|
_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();
|
|
|
|
_list.destroyContents();
|
2016-03-20 02:43:02 +00:00
|
|
|
_soundMaker = nullptr;
|
2016-03-19 11:48:23 +00:00
|
|
|
|
|
|
|
_trueTalkManager.preLoad();
|
|
|
|
_sound.preLoad();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-03-13 00:23:00 +00:00
|
|
|
// Signal to any registered list items
|
2016-03-19 11:48:23 +00:00
|
|
|
_list.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
|
|
|
|
_list.preSave();
|
|
|
|
_trueTalkManager.preSave();
|
|
|
|
_sound.preSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::postSave() {
|
|
|
|
_list.postSave();
|
|
|
|
_trueTalkManager.postSave();
|
|
|
|
}
|
|
|
|
|
2016-03-13 19:30:12 +00:00
|
|
|
void CGameManager::initBounds() {
|
2016-03-22 00:53:49 +00:00
|
|
|
_bounds = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
2016-03-13 19:30:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:49:18 +00:00
|
|
|
void CGameManager::fn2() {
|
|
|
|
warning("TODO");
|
|
|
|
}
|
|
|
|
|
2016-03-20 00:56:29 +00:00
|
|
|
void CGameManager::playClip(CMovieClip *clip, CRoomItem *oldRoom, CRoomItem *newRoom) {
|
|
|
|
warning("TODO: CGameManager::playClip");
|
2016-03-19 22:19:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 01:34:04 +00:00
|
|
|
void CGameManager::update() {
|
2016-03-20 02:43:02 +00:00
|
|
|
handleMovies();
|
|
|
|
frameMessage(getRoom());
|
|
|
|
_list.update(g_vm->_events->getTicksCount());
|
|
|
|
_trueTalkManager.update1();
|
|
|
|
_trueTalkManager.update2();
|
|
|
|
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-22 00:53:49 +00:00
|
|
|
Rect r = item->getBounds();
|
2016-03-20 02:43:02 +00: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-20 03:02:41 +00:00
|
|
|
if (textCursor && textCursor->_active)
|
2016-03-20 02:43:02 +00:00
|
|
|
_bounds.extend(textCursor->getBounds());
|
|
|
|
|
|
|
|
// Set the surface bounds
|
|
|
|
screenManager->setSurfaceBounds(0, _bounds);
|
|
|
|
|
2016-03-20 04:01:40 +00:00
|
|
|
// Handle redrawing the view
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::handleMovies() {
|
|
|
|
warning("TODO: CGameManager::handleMovies");
|
2016-03-19 01:34:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 11:48:23 +00:00
|
|
|
void CGameManager::updateDiskTicksCount() {
|
|
|
|
_lastDiskTicksCount = g_vm->_events->getTicksCount();
|
|
|
|
}
|
|
|
|
|
2016-03-19 13:29:11 +00:00
|
|
|
void CGameManager::viewChange() {
|
|
|
|
delete _videoSurface1;
|
|
|
|
delete _videoSurface2;
|
|
|
|
|
|
|
|
_videoSurface1 = nullptr;
|
|
|
|
_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
|
|
|
_trueTalkManager.viewChange();
|
|
|
|
|
|
|
|
for (CTreeItem *treeItem = _project; treeItem; treeItem = treeItem->scan(_project))
|
|
|
|
treeItem->viewChange();
|
|
|
|
|
|
|
|
initBounds();
|
|
|
|
}
|
|
|
|
|
2016-03-20 02:43:02 +00:00
|
|
|
CRoomItem *CGameManager::getRoom() {
|
|
|
|
return _gameState._gameLocation.getRoom();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameManager::frameMessage(CRoomItem *room) {
|
|
|
|
if (room) {
|
|
|
|
// Signal the next frame
|
|
|
|
CFrameMsg frameMsg(g_vm->_events->getTicksCount());
|
|
|
|
frameMsg.execute(room, nullptr, MSGFLAG_SCAN);
|
|
|
|
|
|
|
|
if (!_soundMaker) {
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-13 00:23:00 +00:00
|
|
|
} // End of namespace Titanic
|