2012-04-25 02:49:49 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-25 23:43:55 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/algorithm.h"
|
2012-04-29 01:23:02 +00:00
|
|
|
#include "common/config-manager.h"
|
2012-05-06 11:24:55 +00:00
|
|
|
#include "common/debug-channels.h"
|
2012-05-05 10:54:21 +00:00
|
|
|
#include "common/events.h"
|
2012-04-25 23:43:55 +00:00
|
|
|
#include "common/file.h"
|
2012-05-28 20:56:31 +00:00
|
|
|
#include "common/installshield_cab.h"
|
2012-04-25 02:49:49 +00:00
|
|
|
#include "tony/tony.h"
|
2012-05-06 02:21:29 +00:00
|
|
|
#include "tony/custom.h"
|
2012-05-21 14:29:27 +00:00
|
|
|
#include "tony/debugger.h"
|
2012-05-01 13:00:03 +00:00
|
|
|
#include "tony/game.h"
|
2012-04-25 23:43:55 +00:00
|
|
|
#include "tony/mpal/mpal.h"
|
2012-04-25 02:49:49 +00:00
|
|
|
|
|
|
|
namespace Tony {
|
|
|
|
|
2012-08-22 12:00:46 +00:00
|
|
|
TonyEngine *g_vm;
|
2012-04-25 02:49:49 +00:00
|
|
|
|
2012-05-21 21:53:13 +00:00
|
|
|
TonyEngine::TonyEngine(OSystem *syst, const TonyGameDescription *gameDesc) : Engine(syst),
|
|
|
|
_gameDescription(gameDesc), _randomSource("tony") {
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm = this;
|
2012-05-18 12:57:25 +00:00
|
|
|
_loadSlotNumber = -1;
|
2012-05-06 11:24:55 +00:00
|
|
|
|
2012-06-17 07:04:10 +00:00
|
|
|
// Set the up the debugger
|
2012-05-21 14:29:27 +00:00
|
|
|
_debugger = new Debugger();
|
2012-05-06 11:24:55 +00:00
|
|
|
DebugMan.addDebugChannel(kTonyDebugAnimations, "animations", "Animations debugging");
|
|
|
|
DebugMan.addDebugChannel(kTonyDebugActions, "actions", "Actions debugging");
|
|
|
|
DebugMan.addDebugChannel(kTonyDebugSound, "sound", "Sound debugging");
|
|
|
|
DebugMan.addDebugChannel(kTonyDebugMusic, "music", "Music debugging");
|
2012-05-15 14:05:48 +00:00
|
|
|
|
2012-06-06 13:18:56 +00:00
|
|
|
// Add folders to the search directory list
|
|
|
|
const Common::FSNode gameDataDir(ConfMan.get("path"));
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "Voices");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "Roasted");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "Music");
|
|
|
|
|
2012-05-15 14:05:48 +00:00
|
|
|
// Set up load slot number
|
2012-05-18 12:57:25 +00:00
|
|
|
_initialLoadSlotNumber = -1;
|
2012-05-15 14:05:48 +00:00
|
|
|
if (ConfMan.hasKey("save_slot")) {
|
|
|
|
int slotNumber = ConfMan.getInt("save_slot");
|
|
|
|
if (slotNumber >= 0 && slotNumber <= 99)
|
2012-05-18 12:57:25 +00:00
|
|
|
_initialLoadSlotNumber = slotNumber;
|
2012-05-15 14:05:48 +00:00
|
|
|
}
|
2012-06-15 06:42:24 +00:00
|
|
|
|
2012-06-17 07:04:10 +00:00
|
|
|
// Load the ScummVM sound settings
|
|
|
|
syncSoundSettings();
|
|
|
|
|
2012-06-15 06:42:24 +00:00
|
|
|
_hEndOfFrame = 0;
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
_stream[i] = NULL;
|
|
|
|
for (int i = 0; i < MAX_SFX_CHANNELS; i++) {
|
|
|
|
_sfx[i] = NULL;
|
|
|
|
_utilSfx[i] = NULL;
|
|
|
|
}
|
|
|
|
_bPaused = false;
|
|
|
|
_bDrawLocation = false;
|
|
|
|
_startTime = 0;
|
|
|
|
_curThumbnail = NULL;
|
|
|
|
_bQuitNow = false;
|
|
|
|
_bTimeFreezed = false;
|
|
|
|
_nTimeFreezed = 0;
|
2012-04-25 02:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TonyEngine::~TonyEngine() {
|
2012-04-29 01:23:02 +00:00
|
|
|
// Close the voice database
|
2012-06-04 21:45:36 +00:00
|
|
|
closeVoiceDatabase();
|
2012-05-11 13:15:59 +00:00
|
|
|
|
|
|
|
// Reset the coroutine scheduler
|
|
|
|
CoroScheduler.reset();
|
2012-05-21 14:29:27 +00:00
|
|
|
|
|
|
|
delete _debugger;
|
2012-04-25 02:49:49 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 23:43:55 +00:00
|
|
|
/**
|
|
|
|
* Run the game
|
|
|
|
*/
|
2012-04-25 02:49:49 +00:00
|
|
|
Common::Error TonyEngine::run() {
|
2012-06-04 21:45:36 +00:00
|
|
|
Common::ErrorCode result = init();
|
2012-04-25 23:43:55 +00:00
|
|
|
if (result != Common::kNoError)
|
|
|
|
return result;
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
play();
|
|
|
|
close();
|
2012-04-30 13:16:19 +00:00
|
|
|
|
2012-04-25 23:43:55 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-17 16:36:23 +00:00
|
|
|
* Initialize the game
|
2012-04-25 23:43:55 +00:00
|
|
|
*/
|
2012-06-04 21:45:36 +00:00
|
|
|
Common::ErrorCode TonyEngine::init() {
|
2012-05-28 20:56:31 +00:00
|
|
|
if (isCompressed()) {
|
|
|
|
Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember("data1.cab");
|
|
|
|
if (!stream)
|
|
|
|
error("Failed to open data1.cab");
|
|
|
|
|
|
|
|
Common::Archive *cabinet = Common::makeInstallShieldArchive(stream);
|
|
|
|
if (!cabinet)
|
|
|
|
error("Failed to parse data1.cab");
|
|
|
|
|
|
|
|
SearchMan.add("data1.cab", cabinet);
|
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
_hEndOfFrame = CoroScheduler.createEvent(false, false);
|
2012-04-30 13:16:19 +00:00
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
_bPaused = false;
|
|
|
|
_bDrawLocation = true;
|
|
|
|
_startTime = g_system->getMillis();
|
2012-04-30 13:16:19 +00:00
|
|
|
|
2012-05-21 21:53:13 +00:00
|
|
|
// Init static class fields
|
2012-06-05 06:39:55 +00:00
|
|
|
RMText::initStatics();
|
|
|
|
RMTony::initStatics();
|
2012-05-13 13:05:41 +00:00
|
|
|
|
2012-05-06 02:21:29 +00:00
|
|
|
// Reset the scheduler
|
2012-05-11 13:15:59 +00:00
|
|
|
CoroScheduler.reset();
|
2012-05-06 02:21:29 +00:00
|
|
|
|
2012-06-17 16:36:23 +00:00
|
|
|
// Initialize the graphics window
|
2012-06-05 06:39:55 +00:00
|
|
|
_window.init();
|
2012-05-05 10:54:21 +00:00
|
|
|
|
2012-06-17 16:36:23 +00:00
|
|
|
// Initialize the function list
|
2012-06-04 21:45:36 +00:00
|
|
|
Common::fill(_funcList, _funcList + 300, (LPCUSTOMFUNCTION)NULL);
|
|
|
|
initCustomFunctionMap();
|
2012-04-25 23:43:55 +00:00
|
|
|
|
|
|
|
// Initializes MPAL system, passing the custom functions list
|
|
|
|
Common::File f;
|
|
|
|
if (!f.open("ROASTED.MPC"))
|
|
|
|
return Common::kReadingFailed;
|
|
|
|
f.close();
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
if (!mpalInit("ROASTED.MPC", "ROASTED.MPR", _funcList, _funcListStrings))
|
2012-04-25 23:43:55 +00:00
|
|
|
return Common::kUnknownError;
|
|
|
|
|
2012-06-17 16:36:23 +00:00
|
|
|
// Initialize the update resources
|
2012-06-07 06:42:35 +00:00
|
|
|
_resUpdate.init("ROASTED.MPU");
|
2012-04-29 00:49:14 +00:00
|
|
|
|
2012-06-17 16:36:23 +00:00
|
|
|
// Initialize the music
|
2012-06-04 21:45:36 +00:00
|
|
|
initMusic();
|
2012-04-29 01:23:02 +00:00
|
|
|
|
2012-06-17 16:36:23 +00:00
|
|
|
// Initialize the voices database
|
2012-06-04 21:45:36 +00:00
|
|
|
if (!openVoiceDatabase())
|
2012-04-29 01:23:02 +00:00
|
|
|
return Common::kReadingFailed;
|
|
|
|
|
2012-06-17 16:36:23 +00:00
|
|
|
// Initialize the boxes
|
2012-06-07 05:58:01 +00:00
|
|
|
_theBoxes.init();
|
2012-04-29 13:19:30 +00:00
|
|
|
|
2012-04-29 23:27:12 +00:00
|
|
|
// Link to the custom graphics engine
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.initCustomDll();
|
|
|
|
_theEngine.init();
|
2012-05-01 13:00:03 +00:00
|
|
|
|
2012-05-20 03:54:59 +00:00
|
|
|
// Allocate space for thumbnails when saving the game
|
2012-06-04 21:45:36 +00:00
|
|
|
_curThumbnail = new uint16[160 * 120];
|
2012-05-01 13:00:03 +00:00
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
_bQuitNow = false;
|
2012-04-29 23:27:12 +00:00
|
|
|
|
2012-04-25 02:49:49 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::initCustomFunctionMap() {
|
|
|
|
INIT_CUSTOM_FUNCTION(_funcList, _funcListStrings);
|
2012-05-06 02:21:29 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 23:43:55 +00:00
|
|
|
/**
|
|
|
|
* Display an error message
|
|
|
|
*/
|
|
|
|
void TonyEngine::GUIError(const Common::String &msg) {
|
|
|
|
GUIErrorMessage(msg);
|
|
|
|
}
|
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
void TonyEngine::playMusic(int nChannel, const Common::String &fname, int nFX, bool bLoop, int nSync) {
|
2012-05-11 13:23:05 +00:00
|
|
|
if (nChannel < 4)
|
2012-06-08 06:44:14 +00:00
|
|
|
if (GLOBALS._flipflop)
|
2012-05-11 13:23:05 +00:00
|
|
|
nChannel = nChannel + 1;
|
2012-05-21 21:53:13 +00:00
|
|
|
|
2012-05-11 13:23:05 +00:00
|
|
|
switch (nFX) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2012-06-16 09:32:50 +00:00
|
|
|
_stream[nChannel]->stop();
|
|
|
|
_stream[nChannel]->unloadFile();
|
2012-05-11 13:23:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 22:
|
|
|
|
break;
|
|
|
|
}
|
2012-05-21 21:53:13 +00:00
|
|
|
|
|
|
|
if (nFX == 22) { // Sync a tempo
|
2012-06-19 10:50:48 +00:00
|
|
|
GLOBALS._curChannel = nChannel;
|
|
|
|
GLOBALS._nextLoop = bLoop;
|
|
|
|
GLOBALS._nextSync = nSync;
|
2012-06-19 12:37:56 +00:00
|
|
|
GLOBALS._nextMusic = fname;
|
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
if (GLOBALS._flipflop)
|
|
|
|
GLOBALS._nextChannel = nChannel - 1;
|
2012-05-11 13:23:05 +00:00
|
|
|
else
|
2012-06-19 10:50:48 +00:00
|
|
|
GLOBALS._nextChannel = nChannel + 1;
|
|
|
|
|
2012-06-19 12:37:56 +00:00
|
|
|
uint32 hThread = CoroScheduler.createProcess(doNextMusic, NULL, 0);
|
2012-06-19 10:50:48 +00:00
|
|
|
assert(hThread != CORO_INVALID_PID_VALUE);
|
|
|
|
|
2012-05-21 21:53:13 +00:00
|
|
|
} else if (nFX == 44) { // Cambia canale e lascia finire il primo
|
2012-06-19 10:50:48 +00:00
|
|
|
if (GLOBALS._flipflop)
|
|
|
|
GLOBALS._nextChannel = nChannel - 1;
|
2012-05-11 13:23:05 +00:00
|
|
|
else
|
2012-06-19 10:50:48 +00:00
|
|
|
GLOBALS._nextChannel = nChannel + 1;
|
2012-05-11 13:23:05 +00:00
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
_stream[GLOBALS._nextChannel]->stop();
|
|
|
|
_stream[GLOBALS._nextChannel]->unloadFile();
|
2012-05-12 10:49:36 +00:00
|
|
|
|
|
|
|
if (!getIsDemo()) {
|
2012-06-19 10:50:48 +00:00
|
|
|
if (!_stream[GLOBALS._nextChannel]->loadFile(fname, FPCODEC_ADPCM, nSync))
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->abortGame();
|
2012-05-12 10:49:36 +00:00
|
|
|
} else {
|
2012-06-19 10:50:48 +00:00
|
|
|
_stream[GLOBALS._nextChannel]->loadFile(fname, FPCODEC_ADPCM, nSync);
|
2012-05-12 10:49:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
_stream[GLOBALS._nextChannel]->setLoop(bLoop);
|
|
|
|
_stream[GLOBALS._nextChannel]->play();
|
2012-05-11 13:23:05 +00:00
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
GLOBALS._flipflop = 1 - GLOBALS._flipflop;
|
2012-05-21 21:53:13 +00:00
|
|
|
} else {
|
2012-05-12 10:49:36 +00:00
|
|
|
if (!getIsDemo()) {
|
2012-06-19 10:50:48 +00:00
|
|
|
if (!_stream[nChannel]->loadFile(fname, FPCODEC_ADPCM, nSync))
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->abortGame();
|
2012-05-12 10:49:36 +00:00
|
|
|
} else {
|
2012-06-19 10:50:48 +00:00
|
|
|
_stream[nChannel]->loadFile(fname, FPCODEC_ADPCM, nSync);
|
2012-05-12 10:49:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
_stream[nChannel]->setLoop(bLoop);
|
|
|
|
_stream[nChannel]->play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TonyEngine::doNextMusic(CORO_PARAM, const void *param) {
|
|
|
|
CORO_BEGIN_CONTEXT;
|
|
|
|
Common::String fn;
|
|
|
|
CORO_END_CONTEXT(_ctx);
|
|
|
|
|
2012-08-22 12:00:46 +00:00
|
|
|
FPStream **streams = g_vm->_stream;
|
2012-06-19 10:50:48 +00:00
|
|
|
|
|
|
|
CORO_BEGIN_CODE(_ctx);
|
|
|
|
|
2012-08-22 12:00:46 +00:00
|
|
|
if (!g_vm->getIsDemo()) {
|
2012-06-19 10:50:48 +00:00
|
|
|
if (!streams[GLOBALS._nextChannel]->loadFile(GLOBALS._nextMusic, FPCODEC_ADPCM, GLOBALS._nextSync))
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->abortGame();
|
2012-06-19 10:50:48 +00:00
|
|
|
} else {
|
|
|
|
streams[GLOBALS._nextChannel]->loadFile(GLOBALS._nextMusic, FPCODEC_ADPCM, GLOBALS._nextSync);
|
2012-05-11 13:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 10:50:48 +00:00
|
|
|
streams[GLOBALS._nextChannel]->setLoop(GLOBALS._nextLoop);
|
2012-06-20 15:58:01 +00:00
|
|
|
//streams[GLOBALS._nextChannel]->prefetch();
|
2012-06-19 10:50:48 +00:00
|
|
|
|
|
|
|
streams[GLOBALS._curChannel]->stop(true);
|
|
|
|
streams[GLOBALS._curChannel]->waitForSync(streams[GLOBALS._nextChannel]);
|
|
|
|
|
|
|
|
streams[GLOBALS._curChannel]->unloadFile();
|
|
|
|
|
|
|
|
GLOBALS._flipflop = 1 - GLOBALS._flipflop;
|
|
|
|
|
|
|
|
CORO_END_CODE;
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::playSFX(int nChannel, int nFX) {
|
|
|
|
if (_sfx[nChannel] == NULL)
|
2012-05-03 14:11:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (nFX) {
|
|
|
|
case 0:
|
2012-06-16 09:32:50 +00:00
|
|
|
_sfx[nChannel]->setLoop(false);
|
2012-05-03 14:11:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2012-06-16 09:32:50 +00:00
|
|
|
_sfx[nChannel]->setLoop(true);
|
2012-05-03 14:11:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
_sfx[nChannel]->play();
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::stopMusic(int nChannel) {
|
2012-05-13 12:34:40 +00:00
|
|
|
// g_system->lockMutex(csMusic);
|
2012-05-11 13:23:05 +00:00
|
|
|
|
|
|
|
if (nChannel < 4)
|
2012-06-16 09:32:50 +00:00
|
|
|
_stream[nChannel + GLOBALS._flipflop]->stop();
|
2012-05-11 13:23:05 +00:00
|
|
|
else
|
2012-06-16 09:32:50 +00:00
|
|
|
_stream[nChannel]->stop();
|
2012-05-11 13:23:05 +00:00
|
|
|
|
2012-05-13 12:34:40 +00:00
|
|
|
// g_system->unlockMutex(csMusic);
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::stopSFX(int nChannel) {
|
2012-06-16 09:32:50 +00:00
|
|
|
_sfx[nChannel]->stop();
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::playUtilSFX(int nChannel, int nFX) {
|
|
|
|
if (_utilSfx[nChannel] == NULL)
|
2012-05-11 13:23:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (nFX) {
|
|
|
|
case 0:
|
2012-06-16 09:32:50 +00:00
|
|
|
_utilSfx[nChannel]->setLoop(false);
|
2012-05-11 13:23:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2012-06-16 09:32:50 +00:00
|
|
|
_utilSfx[nChannel]->setLoop(true);
|
2012-05-11 13:23:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
_utilSfx[nChannel]->setVolume(52);
|
|
|
|
_utilSfx[nChannel]->play();
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::stopUtilSFX(int nChannel) {
|
2012-06-16 09:32:50 +00:00
|
|
|
_utilSfx[nChannel]->stop();
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::preloadSFX(int nChannel, const char *fn) {
|
|
|
|
if (_sfx[nChannel] != NULL) {
|
2012-06-16 09:32:50 +00:00
|
|
|
_sfx[nChannel]->stop();
|
|
|
|
_sfx[nChannel]->release();
|
2012-06-04 21:45:36 +00:00
|
|
|
_sfx[nChannel] = NULL;
|
2012-05-03 14:11:38 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
_theSound.createSfx(&_sfx[nChannel]);
|
2012-05-03 14:11:38 +00:00
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
_sfx[nChannel]->loadFile(fn, FPCODEC_ADPCM);
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
FPSfx *TonyEngine::createSFX(Common::SeekableReadStream *stream) {
|
|
|
|
FPSfx *sfx;
|
2012-05-21 21:53:13 +00:00
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
_theSound.createSfx(&sfx);
|
2012-06-09 22:09:54 +00:00
|
|
|
sfx->loadWave(stream);
|
2012-05-03 14:11:38 +00:00
|
|
|
return sfx;
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::preloadUtilSFX(int nChannel, const char *fn) {
|
2012-08-22 12:28:08 +00:00
|
|
|
// No preloading is needed in ScummVM
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::unloadAllSFX() {
|
2012-08-22 12:28:08 +00:00
|
|
|
// No preloading is needed in ScummVM
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::unloadAllUtilSFX() {
|
2012-08-22 12:28:08 +00:00
|
|
|
// No preloading is needed in ScummVM
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::initMusic() {
|
2012-05-03 14:11:38 +00:00
|
|
|
int i;
|
|
|
|
|
2012-06-16 09:32:50 +00:00
|
|
|
_theSound.init(/*_window*/);
|
|
|
|
_theSound.setMasterVolume(63);
|
2012-05-21 21:53:13 +00:00
|
|
|
|
2012-05-03 14:11:38 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
2012-06-16 09:32:50 +00:00
|
|
|
_theSound.createStream(&_stream[i]);
|
2012-05-03 14:11:38 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_SFX_CHANNELS; i++) {
|
2012-06-04 21:45:36 +00:00
|
|
|
_sfx[i] = _utilSfx[i] = NULL;
|
2012-05-03 14:11:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-20 03:54:59 +00:00
|
|
|
// Create the mutex for controlling music access
|
2012-05-13 12:34:40 +00:00
|
|
|
// csMusic = g_system->createMutex();
|
2012-05-03 14:11:38 +00:00
|
|
|
|
2012-05-20 03:54:59 +00:00
|
|
|
// Preload sound effects
|
2012-06-04 21:45:36 +00:00
|
|
|
preloadUtilSFX(0, "U01.ADP"); // Reversed!!
|
|
|
|
preloadUtilSFX(1, "U02.ADP");
|
2012-06-11 02:20:12 +00:00
|
|
|
|
|
|
|
// Start check processes for sound
|
2012-06-16 09:32:50 +00:00
|
|
|
CoroScheduler.createProcess(FPSfx::soundCheckProcess, NULL);
|
2012-04-29 01:23:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::closeMusic() {
|
2012-05-03 14:11:38 +00:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2012-06-16 09:32:50 +00:00
|
|
|
_stream[i]->stop();
|
|
|
|
_stream[i]->unloadFile();
|
|
|
|
_stream[i]->release();
|
2012-05-03 14:11:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 12:34:40 +00:00
|
|
|
// g_system->deleteMutex(csMusic);
|
2012-05-03 14:11:38 +00:00
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
unloadAllSFX();
|
|
|
|
unloadAllUtilSFX();
|
2012-04-29 01:23:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::pauseSound(bool bPause) {
|
2012-04-29 01:23:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::setMusicVolume(int nChannel, int volume) {
|
2012-04-29 01:23:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
int TonyEngine::getMusicVolume(int nChannel) {
|
2012-04-29 01:23:02 +00:00
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
Common::String TonyEngine::getSaveStateFileName(int n) {
|
2012-05-12 11:54:37 +00:00
|
|
|
return Common::String::format("tony.%03d", n);
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::autoSave(CORO_PARAM) {
|
2012-05-08 14:42:27 +00:00
|
|
|
CORO_BEGIN_CONTEXT;
|
2012-05-21 21:53:13 +00:00
|
|
|
Common::String buf;
|
2012-05-08 14:42:27 +00:00
|
|
|
CORO_END_CONTEXT(_ctx);
|
|
|
|
|
|
|
|
CORO_BEGIN_CODE(_ctx);
|
2012-05-03 12:49:30 +00:00
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
grabThumbnail();
|
2012-06-04 23:15:25 +00:00
|
|
|
CORO_INVOKE_0(mainWaitFrame);
|
|
|
|
CORO_INVOKE_0(mainWaitFrame);
|
|
|
|
mainFreeze();
|
2012-06-04 21:45:36 +00:00
|
|
|
_ctx->buf = getSaveStateFileName(0);
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.saveState(_ctx->buf, (byte *)_curThumbnail, "Autosave");
|
2012-06-04 23:15:25 +00:00
|
|
|
mainUnfreeze();
|
2012-05-08 14:42:27 +00:00
|
|
|
|
|
|
|
CORO_END_CODE;
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::saveState(int n, const char *name) {
|
|
|
|
Common::String buf = getSaveStateFileName(n);
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.saveState(buf.c_str(), (byte *)_curThumbnail, name);
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::loadState(CORO_PARAM, int n) {
|
2012-05-09 13:15:41 +00:00
|
|
|
CORO_BEGIN_CONTEXT;
|
2012-05-21 21:53:13 +00:00
|
|
|
Common::String buf;
|
2012-05-09 13:15:41 +00:00
|
|
|
CORO_END_CONTEXT(_ctx);
|
2012-05-03 12:49:30 +00:00
|
|
|
|
2012-05-09 13:15:41 +00:00
|
|
|
CORO_BEGIN_CODE(_ctx);
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
_ctx->buf = getSaveStateFileName(n);
|
2012-06-04 23:04:53 +00:00
|
|
|
CORO_INVOKE_1(_theEngine.loadState, _ctx->buf.c_str());
|
2012-05-09 13:15:41 +00:00
|
|
|
|
|
|
|
CORO_END_CODE;
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
bool TonyEngine::openVoiceDatabase() {
|
2012-04-29 01:23:02 +00:00
|
|
|
char id[4];
|
|
|
|
uint32 numfiles;
|
|
|
|
|
|
|
|
// Open the voices database
|
|
|
|
if (!_vdbFP.open("voices.vdb"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_vdbFP.seek(-8, SEEK_END);
|
|
|
|
numfiles = _vdbFP.readUint32LE();
|
|
|
|
_vdbFP.read(id, 4);
|
|
|
|
|
|
|
|
if (id[0] != 'V' || id[1] != 'D' || id[2] != 'B' || id[3] != '1') {
|
|
|
|
_vdbFP.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read in the index
|
|
|
|
_vdbFP.seek(-8 - (numfiles * VOICE_HEADER_SIZE), SEEK_END);
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < numfiles; ++i) {
|
|
|
|
VoiceHeader vh;
|
2012-06-04 21:45:36 +00:00
|
|
|
vh._offset = _vdbFP.readUint32LE();
|
|
|
|
vh._code = _vdbFP.readUint32LE();
|
|
|
|
vh._parts = _vdbFP.readUint32LE();
|
2012-04-29 01:23:02 +00:00
|
|
|
|
|
|
|
_voices.push_back(vh);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::closeVoiceDatabase() {
|
2012-04-29 01:23:02 +00:00
|
|
|
if (_vdbFP.isOpen())
|
|
|
|
_vdbFP.close();
|
|
|
|
|
|
|
|
if (_voices.size() > 0)
|
|
|
|
_voices.clear();
|
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::grabThumbnail() {
|
2012-06-06 06:04:33 +00:00
|
|
|
_window.grabThumbnail(_curThumbnail);
|
2012-04-30 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::optionScreen() {
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::openInitLoadMenu(CORO_PARAM) {
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.openOptionScreen(coroParam, 1);
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::openInitOptions(CORO_PARAM) {
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.openOptionScreen(coroParam, 2);
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::abortGame() {
|
2012-06-04 21:45:36 +00:00
|
|
|
_bQuitNow = true;
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 13:15:41 +00:00
|
|
|
/**
|
|
|
|
* Main process for playing the game.
|
|
|
|
*
|
2012-05-21 21:53:13 +00:00
|
|
|
* @remarks This needs to be in a separate process, since there are some things that can briefly
|
2012-05-09 13:15:41 +00:00
|
|
|
* block the execution of process. For now, all ScummVm event handling is dispatched to within the context of this
|
|
|
|
* process. If it ever proves a problem, we may have to look into whether it's feasible to have it still remain
|
|
|
|
* in the outer 'main' process.
|
|
|
|
*/
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::playProcess(CORO_PARAM, const void *param) {
|
2012-05-09 13:15:41 +00:00
|
|
|
CORO_BEGIN_CONTEXT;
|
2012-05-21 21:53:13 +00:00
|
|
|
Common::String fn;
|
2012-05-09 13:15:41 +00:00
|
|
|
CORO_END_CONTEXT(_ctx);
|
2012-05-05 12:33:13 +00:00
|
|
|
|
2012-05-15 14:05:48 +00:00
|
|
|
|
2012-05-09 13:15:41 +00:00
|
|
|
CORO_BEGIN_CODE(_ctx);
|
2012-05-05 10:54:21 +00:00
|
|
|
|
2012-05-15 14:05:48 +00:00
|
|
|
// Game loop. We rely on the outer main process to detect if a shutdown is required,
|
2012-05-09 13:15:41 +00:00
|
|
|
// and kill the scheudler and all the processes, including this one
|
|
|
|
for (;;) {
|
2012-05-15 14:05:48 +00:00
|
|
|
// If a savegame needs to be loaded, then do so
|
2012-08-22 12:00:46 +00:00
|
|
|
if (g_vm->_loadSlotNumber != -1 && GLOBALS._gfxEngine != NULL) {
|
|
|
|
_ctx->fn = getSaveStateFileName(g_vm->_loadSlotNumber);
|
2012-06-10 20:02:31 +00:00
|
|
|
CORO_INVOKE_1(GLOBALS._gfxEngine->loadState, _ctx->fn);
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->_loadSlotNumber = -1;
|
2012-05-15 14:05:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 13:15:41 +00:00
|
|
|
// Wait for the next frame
|
2012-05-11 13:15:59 +00:00
|
|
|
CORO_INVOKE_1(CoroScheduler.sleep, 50);
|
2012-05-06 02:21:29 +00:00
|
|
|
|
2012-05-21 21:53:13 +00:00
|
|
|
// Call the engine to handle the next frame
|
2012-08-22 12:00:46 +00:00
|
|
|
CORO_INVOKE_1(g_vm->_theEngine.doFrame, g_vm->_bDrawLocation);
|
2012-05-01 13:44:02 +00:00
|
|
|
|
2012-05-05 12:33:13 +00:00
|
|
|
// Warns that a frame is finished
|
2012-08-22 12:00:46 +00:00
|
|
|
CoroScheduler.pulseEvent(g_vm->_hEndOfFrame);
|
2012-05-01 13:44:02 +00:00
|
|
|
|
2012-05-05 12:33:13 +00:00
|
|
|
// Handle drawing the frame
|
2012-08-22 12:00:46 +00:00
|
|
|
if (!g_vm->_bPaused) {
|
|
|
|
if (!g_vm->_theEngine._bWiping)
|
|
|
|
g_vm->_window.getNewFrame(g_vm->_theEngine, NULL);
|
2012-05-01 13:44:02 +00:00
|
|
|
else
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->_window.getNewFrame(g_vm->_theEngine, &g_vm->_theEngine._rcWipeEllipse);
|
2012-05-01 13:44:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 12:33:13 +00:00
|
|
|
// Paint the frame onto the screen
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->_window.repaint();
|
2012-05-21 14:29:27 +00:00
|
|
|
|
|
|
|
// Signal the ScummVM debugger
|
2012-08-22 12:00:46 +00:00
|
|
|
g_vm->_debugger->onFrame();
|
2012-05-09 13:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CORO_END_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Play the game
|
|
|
|
*/
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::play() {
|
2012-05-09 13:15:41 +00:00
|
|
|
// Create the game player process
|
2012-06-04 21:45:36 +00:00
|
|
|
CoroScheduler.createProcess(playProcess, NULL);
|
2012-05-09 13:15:41 +00:00
|
|
|
|
|
|
|
// Loop through calling the scheduler until it's time for the game to quit
|
2012-06-04 21:45:36 +00:00
|
|
|
while (!shouldQuit() && !_bQuitNow) {
|
2012-05-09 13:15:41 +00:00
|
|
|
// Delay for a brief amount
|
|
|
|
g_system->delayMillis(10);
|
|
|
|
|
|
|
|
// Call any scheduled processes
|
2012-05-11 13:15:59 +00:00
|
|
|
CoroScheduler.schedule();
|
2012-05-05 12:33:13 +00:00
|
|
|
}
|
2012-05-01 13:44:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::close() {
|
2012-06-04 21:45:36 +00:00
|
|
|
closeMusic();
|
|
|
|
CoroScheduler.closeEvent(_hEndOfFrame);
|
2012-06-07 05:58:01 +00:00
|
|
|
_theBoxes.close();
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.close();
|
2012-06-06 06:04:33 +00:00
|
|
|
_window.close();
|
2012-06-09 03:05:48 +00:00
|
|
|
mpalFree();
|
2012-06-08 15:20:08 +00:00
|
|
|
FreeMpc();
|
2012-06-04 21:45:36 +00:00
|
|
|
delete[] _curThumbnail;
|
2012-05-01 13:44:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 21:45:36 +00:00
|
|
|
void TonyEngine::switchFullscreen(bool bFull) {
|
2012-06-06 06:04:33 +00:00
|
|
|
_window.switchFullscreen(bFull);
|
2012-06-04 23:04:53 +00:00
|
|
|
_theEngine.switchFullscreen(bFull);
|
2012-05-01 13:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TonyEngine::GDIControl(bool bCon) {
|
|
|
|
_theEngine.GDIControl(bCon);
|
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::freezeTime() {
|
2012-06-04 21:45:36 +00:00
|
|
|
_bTimeFreezed = true;
|
|
|
|
_nTimeFreezed = getTime() - _startTime;
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 06:24:33 +00:00
|
|
|
void TonyEngine::unfreezeTime() {
|
2012-06-04 21:45:36 +00:00
|
|
|
_bTimeFreezed = false;
|
2012-05-03 12:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the millisecond timer
|
|
|
|
*/
|
2012-06-04 21:45:36 +00:00
|
|
|
uint32 TonyEngine::getTime() {
|
2012-05-03 12:49:30 +00:00
|
|
|
return g_system->getMillis();
|
|
|
|
}
|
|
|
|
|
2012-05-15 14:05:48 +00:00
|
|
|
bool TonyEngine::canLoadGameStateCurrently() {
|
2012-06-10 20:02:31 +00:00
|
|
|
return GLOBALS._gfxEngine != NULL && GLOBALS._gfxEngine->canLoadSave();
|
2012-05-15 14:05:48 +00:00
|
|
|
}
|
|
|
|
bool TonyEngine::canSaveGameStateCurrently() {
|
2012-06-10 20:02:31 +00:00
|
|
|
return GLOBALS._gfxEngine != NULL && GLOBALS._gfxEngine->canLoadSave();
|
2012-05-15 14:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TonyEngine::loadGameState(int slot) {
|
|
|
|
_loadSlotNumber = slot;
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TonyEngine::saveGameState(int slot, const Common::String &desc) {
|
2012-06-10 20:02:31 +00:00
|
|
|
if (!GLOBALS._gfxEngine)
|
2012-05-15 14:05:48 +00:00
|
|
|
return Common::kUnknownError;
|
|
|
|
|
2012-06-16 00:57:35 +00:00
|
|
|
RMGfxTargetBuffer &bigBuf = *GLOBALS._gfxEngine;
|
2012-05-15 14:05:48 +00:00
|
|
|
RMSnapshot s;
|
2012-06-16 00:57:35 +00:00
|
|
|
s.grabScreenshot(bigBuf, 4, _curThumbnail);
|
2012-05-15 14:05:48 +00:00
|
|
|
|
2012-06-10 20:02:31 +00:00
|
|
|
GLOBALS._gfxEngine->saveState(getSaveStateFileName(slot), (byte *)_curThumbnail, desc);
|
2012-05-15 14:05:48 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2012-06-17 07:04:10 +00:00
|
|
|
void TonyEngine::syncSoundSettings() {
|
|
|
|
Engine::syncSoundSettings();
|
|
|
|
|
|
|
|
GLOBALS._bCfgDubbing = !ConfMan.getBool("mute") && !ConfMan.getBool("speech_mute");
|
|
|
|
GLOBALS._bCfgSFX = !ConfMan.getBool("mute") && !ConfMan.getBool("sfx_mute");
|
|
|
|
GLOBALS._bCfgMusic = !ConfMan.getBool("mute") && !ConfMan.getBool("music_mute");
|
|
|
|
|
|
|
|
GLOBALS._nCfgDubbingVolume = ConfMan.getInt("speech_volume") * 10 / 256;
|
|
|
|
GLOBALS._nCfgSFXVolume = ConfMan.getInt("sfx_volume") * 10 / 256;
|
|
|
|
GLOBALS._nCfgMusicVolume = ConfMan.getInt("music_volume") * 10 / 256;
|
|
|
|
|
|
|
|
GLOBALS._bShowSubtitles = ConfMan.getBool("subtitles");
|
|
|
|
GLOBALS._nCfgTextSpeed = ConfMan.getInt("talkspeed") * 10 / 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TonyEngine::saveSoundSettings() {
|
|
|
|
ConfMan.setBool("speech_mute", GLOBALS._bCfgDubbing);
|
|
|
|
ConfMan.setBool("sfx_mute", GLOBALS._bCfgSFX);
|
|
|
|
ConfMan.setBool("music_mute", GLOBALS._bCfgMusic);
|
|
|
|
|
|
|
|
ConfMan.setInt("speech_volume", GLOBALS._nCfgDubbingVolume * 256 / 10);
|
|
|
|
ConfMan.setInt("sfx_volume", GLOBALS._nCfgSFXVolume * 256 / 10);
|
|
|
|
ConfMan.setInt("music_volume", GLOBALS._nCfgMusicVolume * 256 / 10);
|
|
|
|
|
|
|
|
ConfMan.setBool("subtitles", GLOBALS._bShowSubtitles);
|
2012-08-22 19:52:22 +00:00
|
|
|
ConfMan.setInt("talkspeed", GLOBALS._nCfgTextSpeed * 256 / 10);
|
2012-06-17 07:04:10 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 02:49:49 +00:00
|
|
|
} // End of namespace Tony
|