2014-09-21 18:19:07 +02:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2009-09-07 23:51:12 +09:30
|
|
|
*
|
2014-09-21 18:19:07 +02:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2009-09-07 23:51:12 +09:30
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2014-09-21 18:19:07 +02:00
|
|
|
* 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,
|
2009-09-07 23:51:12 +09:30
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-09-21 18:19:07 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-09-07 23:51:12 +09:30
|
|
|
*
|
2014-09-21 18:19:07 +02:00
|
|
|
* 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.
|
2009-09-07 23:51:12 +09:30
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/stark.h"
|
2014-12-27 19:48:17 +01:00
|
|
|
#include "engines/stark/archiveloader.h"
|
2014-09-21 17:09:55 +02:00
|
|
|
#include "engines/stark/console.h"
|
2010-01-27 19:14:07 +01:00
|
|
|
#include "engines/stark/debug.h"
|
2014-12-27 19:48:17 +01:00
|
|
|
#include "engines/stark/resourceprovider.h"
|
2014-12-28 11:50:12 +01:00
|
|
|
#include "engines/stark/resources/level.h"
|
|
|
|
#include "engines/stark/resources/location.h"
|
2014-09-21 17:26:20 +02:00
|
|
|
#include "engines/stark/scene.h"
|
2014-12-28 18:22:25 +01:00
|
|
|
#include "engines/stark/stateprovider.h"
|
2014-09-21 17:26:20 +02:00
|
|
|
#include "engines/stark/gfx/driver.h"
|
2009-09-07 23:51:12 +09:30
|
|
|
|
2010-01-24 23:23:39 +08:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/events.h"
|
2015-01-02 10:33:42 +01:00
|
|
|
#include "common/random.h"
|
2014-12-29 23:11:22 +01:00
|
|
|
#include "common/savefile.h"
|
2011-09-14 02:09:51 +02:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "audio/mixer.h"
|
2009-09-07 23:51:12 +09:30
|
|
|
|
2015-01-01 21:13:33 +01:00
|
|
|
namespace Common {
|
|
|
|
DECLARE_SINGLETON(Stark::StarkServices);
|
|
|
|
}
|
|
|
|
|
2009-09-07 23:51:12 +09:30
|
|
|
namespace Stark {
|
|
|
|
|
2014-09-21 17:09:55 +02:00
|
|
|
StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) :
|
2014-12-27 19:48:17 +01:00
|
|
|
Engine(syst),
|
|
|
|
_gameDescription(gameDesc),
|
|
|
|
_gfx(nullptr),
|
|
|
|
_scene(nullptr),
|
|
|
|
_console(nullptr),
|
|
|
|
_global(nullptr),
|
|
|
|
_archiveLoader(nullptr),
|
2014-12-28 18:22:25 +01:00
|
|
|
_stateProvider(nullptr),
|
2015-01-02 10:33:42 +01:00
|
|
|
_resourceProvider(nullptr),
|
|
|
|
_randomSource(nullptr) {
|
2009-09-07 23:51:12 +09:30
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, 127);
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
2010-01-27 19:14:07 +01:00
|
|
|
|
|
|
|
// Add the available debug channels
|
2011-09-14 02:09:51 +02:00
|
|
|
DebugMan.addDebugChannel(kDebugArchive, "Archive", "Debug the archive loading");
|
|
|
|
DebugMan.addDebugChannel(kDebugXMG, "XMG", "Debug the loading of XMG images");
|
|
|
|
DebugMan.addDebugChannel(kDebugXRC, "XRC", "Debug the loading of XRC resource trees");
|
|
|
|
DebugMan.addDebugChannel(kDebugUnknown, "Unknown", "Debug unknown values on the data");
|
2009-09-07 23:51:12 +09:30
|
|
|
}
|
|
|
|
|
|
|
|
StarkEngine::~StarkEngine() {
|
2015-01-02 10:33:42 +01:00
|
|
|
delete _randomSource;
|
2010-01-27 19:14:07 +01:00
|
|
|
delete _scene;
|
2014-09-21 17:09:55 +02:00
|
|
|
delete _console;
|
2014-12-27 19:48:17 +01:00
|
|
|
delete _gfx;
|
|
|
|
delete _resourceProvider;
|
|
|
|
delete _global;
|
2014-12-28 18:22:25 +01:00
|
|
|
delete _stateProvider;
|
2014-12-27 19:48:17 +01:00
|
|
|
delete _archiveLoader;
|
2015-01-01 21:13:33 +01:00
|
|
|
|
|
|
|
StarkServices::destroy();
|
2009-09-07 23:51:12 +09:30
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error StarkEngine::run() {
|
2014-09-21 17:09:55 +02:00
|
|
|
_console = new Console(this);
|
2010-01-25 17:42:19 +01:00
|
|
|
_gfx = GfxDriver::create();
|
2010-01-21 20:29:34 +10:30
|
|
|
|
2010-01-21 21:26:06 +10:30
|
|
|
// Get the screen prepared
|
2010-01-25 17:42:19 +01:00
|
|
|
_gfx->setupScreen(640, 480, ConfMan.getBool("fullscreen"));
|
2010-01-21 20:29:34 +10:30
|
|
|
|
2014-12-27 19:48:17 +01:00
|
|
|
_archiveLoader = new ArchiveLoader();
|
2014-12-28 18:22:25 +01:00
|
|
|
_stateProvider = new StateProvider();
|
2014-12-27 19:48:17 +01:00
|
|
|
_global = new Global();
|
2014-12-28 18:22:25 +01:00
|
|
|
_resourceProvider = new ResourceProvider(_archiveLoader, _stateProvider, _global);
|
2015-01-02 10:33:42 +01:00
|
|
|
_randomSource = new Common::RandomSource("stark");
|
2014-12-27 19:48:17 +01:00
|
|
|
|
2015-01-01 21:13:33 +01:00
|
|
|
// Setup the public services
|
|
|
|
StarkServices &services = StarkServices::instance();
|
|
|
|
services.archiveLoader = _archiveLoader;
|
|
|
|
services.resourceProvider = _resourceProvider;
|
|
|
|
services.global = _global;
|
2015-01-02 10:33:42 +01:00
|
|
|
services.randomSource = _randomSource;
|
2015-01-01 21:13:33 +01:00
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
// Load global resources
|
2014-12-27 19:48:17 +01:00
|
|
|
_resourceProvider->initGlobal();
|
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
// Start us up at the house of all worlds
|
|
|
|
_resourceProvider->requestLocationChange(0x45, 0x00);
|
|
|
|
|
2010-01-21 21:26:06 +10:30
|
|
|
// Start running
|
2010-01-24 23:23:39 +08:00
|
|
|
mainLoop();
|
2009-09-07 23:51:12 +09:30
|
|
|
|
2014-12-27 19:48:17 +01:00
|
|
|
_resourceProvider->shutdown();
|
|
|
|
|
2009-09-07 23:51:12 +09:30
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2010-01-24 23:23:39 +08:00
|
|
|
void StarkEngine::mainLoop() {
|
2010-01-27 19:14:07 +01:00
|
|
|
// Load the initial scene
|
|
|
|
_scene = new Scene(_gfx);
|
|
|
|
|
2010-01-27 01:28:41 +01:00
|
|
|
while (!shouldQuit()) {
|
2010-01-21 20:29:34 +10:30
|
|
|
// Process events
|
|
|
|
Common::Event e;
|
|
|
|
while (g_system->getEventManager()->pollEvent(e)) {
|
|
|
|
// Handle any buttons, keys and joystick operations
|
|
|
|
if (e.type == Common::EVENT_KEYDOWN) {
|
|
|
|
if (e.kbd.ascii == 'q') {
|
2010-01-27 01:28:41 +01:00
|
|
|
quitGame();
|
2010-01-21 20:29:34 +10:30
|
|
|
break;
|
2014-09-21 17:09:55 +02:00
|
|
|
} else if (e.kbd.keycode == Common::KEYCODE_d) {
|
|
|
|
if (e.kbd.flags & Common::KBD_CTRL) {
|
|
|
|
_console->attach();
|
|
|
|
_console->onFrame();
|
|
|
|
}
|
2010-01-21 20:29:34 +10:30
|
|
|
} else {
|
|
|
|
//handleChars(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii);
|
|
|
|
}
|
2014-09-21 17:09:55 +02:00
|
|
|
|
2010-01-21 20:29:34 +10:30
|
|
|
}
|
|
|
|
/*if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_KEYUP) {
|
|
|
|
handleControls(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii);
|
|
|
|
}*/
|
|
|
|
// Check for "Hard" quit"
|
2010-01-27 01:28:41 +01:00
|
|
|
//if (e.type == Common::EVENT_QUIT)
|
|
|
|
// return;
|
2010-01-21 20:29:34 +10:30
|
|
|
/*if (event.type == Common::EVENT_SCREEN_CHANGED)
|
|
|
|
_refreshDrawNeeded = true;*/
|
|
|
|
}
|
|
|
|
|
2014-12-29 23:11:22 +01:00
|
|
|
if (_resourceProvider->hasLocationChangeRequest()) {
|
|
|
|
_resourceProvider->performLocationChange();
|
|
|
|
}
|
|
|
|
|
2010-01-21 20:29:34 +10:30
|
|
|
updateDisplayScene();
|
|
|
|
g_system->delayMillis(50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-24 23:23:39 +08:00
|
|
|
void StarkEngine::updateDisplayScene() {
|
2010-09-04 22:31:13 +09:30
|
|
|
// Get frame delay
|
|
|
|
static uint32 lastFrame = g_system->getMillis();
|
|
|
|
uint32 delta = g_system->getMillis() - lastFrame;
|
|
|
|
lastFrame += delta;
|
|
|
|
|
2010-01-27 19:14:07 +01:00
|
|
|
// Clear the screen
|
2010-01-25 17:42:19 +01:00
|
|
|
_gfx->clearScreen();
|
2010-01-21 20:29:34 +10:30
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
// Update the game resources
|
|
|
|
_global->getLevel()->onGameLoop(delta);
|
|
|
|
_global->getCurrent()->getLevel()->onGameLoop(delta);
|
|
|
|
_global->getCurrent()->getLocation()->onGameLoop(delta);
|
|
|
|
|
2010-01-27 19:14:07 +01:00
|
|
|
// Render the current scene
|
2010-09-04 22:31:13 +09:30
|
|
|
_scene->render(delta);
|
2010-01-21 20:29:34 +10:30
|
|
|
|
2010-01-25 17:42:19 +01:00
|
|
|
// Swap buffers
|
|
|
|
_gfx->flipBuffer();
|
2010-01-21 20:29:34 +10:30
|
|
|
}
|
2010-01-24 23:23:39 +08:00
|
|
|
|
2014-12-29 23:11:22 +01:00
|
|
|
bool StarkEngine::hasFeature(EngineFeature f) const {
|
|
|
|
return
|
|
|
|
(f == kSupportsLoadingDuringRuntime) ||
|
|
|
|
(f == kSupportsSavingDuringRuntime);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StarkEngine::canLoadGameStateCurrently() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error StarkEngine::loadGameState(int slot) {
|
|
|
|
// Open the save file
|
|
|
|
Common::String filename = Common::String::format("Save%02d.tlj", slot);
|
2014-12-30 21:10:36 +01:00
|
|
|
Common::InSaveFile *save = _saveFileMan->openForLoading(filename);
|
|
|
|
if (!save) {
|
|
|
|
return _saveFileMan->getError();
|
|
|
|
}
|
|
|
|
|
|
|
|
StateReadStream *stream = new StateReadStream(save);
|
|
|
|
|
|
|
|
// 1. Read the header
|
|
|
|
// Save description
|
|
|
|
Common::String desc = stream->readString();
|
2014-12-29 23:11:22 +01:00
|
|
|
|
2014-12-30 21:10:36 +01:00
|
|
|
// Level
|
|
|
|
Common::String level = stream->readString();
|
|
|
|
uint levelIndex = strtol(level.c_str(), nullptr, 16);
|
2014-12-29 23:11:22 +01:00
|
|
|
|
2014-12-30 21:10:36 +01:00
|
|
|
// Location
|
|
|
|
Common::String location = stream->readString();
|
|
|
|
uint locationIndex = strtol(location.c_str(), nullptr, 16);
|
|
|
|
|
|
|
|
// Version
|
|
|
|
Common::String version = stream->readString();
|
|
|
|
//TODO: Check the version
|
|
|
|
|
|
|
|
// 2. Read the resource trees state
|
|
|
|
_stateProvider->readStateFromStream(stream);
|
2014-12-29 23:11:22 +01:00
|
|
|
|
|
|
|
//TODO: Read the rest of the state
|
|
|
|
|
2014-12-30 21:10:36 +01:00
|
|
|
delete stream;
|
2014-12-29 23:11:22 +01:00
|
|
|
|
|
|
|
_resourceProvider->shutdown();
|
|
|
|
_resourceProvider->initGlobal();
|
|
|
|
|
|
|
|
//TODO: Restore to the correct location
|
2014-12-30 21:10:36 +01:00
|
|
|
_resourceProvider->requestLocationChange(levelIndex, locationIndex);
|
2014-12-29 23:11:22 +01:00
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StarkEngine::canSaveGameStateCurrently() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error StarkEngine::saveGameState(int slot, const Common::String &desc) {
|
|
|
|
// Ensure the state store is up to date
|
|
|
|
_resourceProvider->commitActiveLocationsState();
|
|
|
|
|
|
|
|
// Open the save file
|
|
|
|
Common::String filename = Common::String::format("Save%02d.tlj", slot);
|
2014-12-30 21:10:36 +01:00
|
|
|
Common::OutSaveFile *save = _saveFileMan->openForSaving(filename);
|
|
|
|
if (!save) {
|
|
|
|
return _saveFileMan->getError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. Write the header
|
|
|
|
// Save description
|
|
|
|
save->writeUint32LE(desc.size());
|
|
|
|
save->writeString(desc);
|
|
|
|
|
|
|
|
// Level
|
|
|
|
Common::String level = _global->getCurrent()->getLevel()->getIndexAsString();
|
|
|
|
save->writeUint32LE(level.size());
|
|
|
|
save->writeString(level);
|
|
|
|
|
|
|
|
// Location
|
|
|
|
Common::String location = _global->getCurrent()->getLocation()->getIndexAsString();
|
|
|
|
save->writeUint32LE(location.size());
|
|
|
|
save->writeString(location);
|
2014-12-29 23:11:22 +01:00
|
|
|
|
2014-12-30 21:10:36 +01:00
|
|
|
// Version
|
|
|
|
Common::String version = "Version:\t06";
|
|
|
|
save->writeUint32LE(version.size());
|
|
|
|
save->writeString(version);
|
2014-12-29 23:11:22 +01:00
|
|
|
|
2014-12-30 21:10:36 +01:00
|
|
|
// 2. Write the resource trees state
|
2014-12-29 23:11:22 +01:00
|
|
|
_stateProvider->writeStateToStream(save);
|
|
|
|
|
|
|
|
//TODO: Write the rest of the state
|
|
|
|
//TODO: Write a screenshot
|
|
|
|
|
|
|
|
delete save;
|
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2010-01-24 23:23:39 +08:00
|
|
|
} // End of namespace Stark
|