From 73ee04635a08c8db5d08a1161b60da07e3b56829 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 22 Feb 2015 11:26:31 +0100 Subject: [PATCH] STARK: Load the static level --- engines/stark/console.cpp | 19 ++++++ engines/stark/console.h | 2 + engines/stark/module.mk | 1 + engines/stark/resources/level.h | 6 ++ engines/stark/services/resourceprovider.cpp | 10 ++-- engines/stark/services/services.h | 3 + engines/stark/services/staticprovider.cpp | 64 ++++++++++++++++++++ engines/stark/services/staticprovider.h | 65 +++++++++++++++++++++ engines/stark/stark.cpp | 7 +++ engines/stark/stark.h | 2 + 10 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 engines/stark/services/staticprovider.cpp create mode 100644 engines/stark/services/staticprovider.h diff --git a/engines/stark/console.cpp b/engines/stark/console.cpp index be8341682bd..9677d43af28 100644 --- a/engines/stark/console.cpp +++ b/engines/stark/console.cpp @@ -31,6 +31,7 @@ #include "engines/stark/services/global.h" #include "engines/stark/services/resourceprovider.h" #include "engines/stark/services/services.h" +#include "engines/stark/services/staticprovider.h" #include "common/file.h" @@ -38,6 +39,8 @@ namespace Stark { Console::Console() : GUI::Debugger() { registerCmd("dumpArchive", WRAP_METHOD(Console, Cmd_DumpArchive)); + registerCmd("dumpRoot", WRAP_METHOD(Console, Cmd_DumpRoot)); + registerCmd("dumpStatic", WRAP_METHOD(Console, Cmd_DumpStatic)); registerCmd("dumpGlobal", WRAP_METHOD(Console, Cmd_DumpGlobal)); registerCmd("dumpLevel", WRAP_METHOD(Console, Cmd_DumpLevel)); registerCmd("dumpLocation", WRAP_METHOD(Console, Cmd_DumpLocation)); @@ -96,6 +99,14 @@ bool Console::Cmd_DumpArchive(int argc, const char **argv) { return true; } +bool Console::Cmd_DumpRoot(int argc, const char **argv) { + Global *global = StarkServices::instance().global; + + global->getRoot()->print(); + + return true; +} + bool Console::Cmd_DumpGlobal(int argc, const char **argv) { Global *global = StarkServices::instance().global; @@ -104,6 +115,14 @@ bool Console::Cmd_DumpGlobal(int argc, const char **argv) { return true; } +bool Console::Cmd_DumpStatic(int argc, const char **argv) { + StaticProvider *staticProvider = StarkServices::instance().staticProvider; + + staticProvider->getLevel()->print(); + + return true; +} + bool Console::Cmd_DumpLevel(int argc, const char **argv) { Global *global = StarkServices::instance().global; diff --git a/engines/stark/console.h b/engines/stark/console.h index d9f94de402f..e6e663a4ea8 100644 --- a/engines/stark/console.h +++ b/engines/stark/console.h @@ -38,6 +38,8 @@ public: private: bool Cmd_DumpArchive(int argc, const char **argv); + bool Cmd_DumpRoot(int argc, const char **argv); + bool Cmd_DumpStatic(int argc, const char **argv); bool Cmd_DumpGlobal(int argc, const char **argv); bool Cmd_DumpLevel(int argc, const char **argv); bool Cmd_DumpLocation(int argc, const char **argv); diff --git a/engines/stark/module.mk b/engines/stark/module.mk index ee460238768..7678b794f71 100644 --- a/engines/stark/module.mk +++ b/engines/stark/module.mk @@ -51,6 +51,7 @@ MODULE_OBJS := \ services/resourceprovider.o \ services/services.o \ services/stateprovider.o \ + services/staticprovider.o \ services/userinterface.o \ skeleton.o \ skeleton_anim.o \ diff --git a/engines/stark/resources/level.h b/engines/stark/resources/level.h index 066ca2bbdbb..0b9f5798136 100644 --- a/engines/stark/resources/level.h +++ b/engines/stark/resources/level.h @@ -45,6 +45,12 @@ class Level : public Object { public: static const Type::ResourceType TYPE = Type::kLevel; + enum SubType { + kGlobal = 1, + kGame = 2, + kStatic = 3 + }; + Level(Object *parent, byte subType, uint16 index, const Common::String &name); virtual ~Level(); diff --git a/engines/stark/services/resourceprovider.cpp b/engines/stark/services/resourceprovider.cpp index 4d43a955751..100ed9147b5 100644 --- a/engines/stark/services/resourceprovider.cpp +++ b/engines/stark/services/resourceprovider.cpp @@ -54,11 +54,11 @@ void ResourceProvider::initGlobal() { Resources::Root *root = _archiveLoader->useRoot("x.xarc"); _global->setRoot(root); - // Resources::Resource lifecycle update + // Resources lifecycle update root->onAllLoaded(); // Find the global level node - Resources::Level *global = root->findChildWithSubtype(1); + Resources::Level *global = root->findChildWithSubtype(Resources::Level::kGlobal); // Load the global archive Common::String globalArchiveName = _archiveLoader->buildArchiveName(global); @@ -69,7 +69,7 @@ void ResourceProvider::initGlobal() { _stateProvider->restoreLevelState(global); _global->setLevel(global); - // Resources::Resource lifecycle update + // Resources lifecycle update global->onAllLoaded(); //TODO: Retrieve the inventory from the global tree @@ -172,7 +172,7 @@ void ResourceProvider::performLocationChange() { runLocationChangeScripts(previous->getLevel(), Resources::Script::kCallModeExitLocation); runLocationChangeScripts(previous->getLocation(), Resources::Script::kCallModeExitLocation); - // Resources::Resource lifecycle update + // Resources lifecycle update previous->getLocation()->onExitLocation(); previous->getLevel()->onExitLocation(); _global->getLevel()->onExitLocation(); @@ -189,7 +189,7 @@ void ResourceProvider::performLocationChange() { _restoreCurrentState = false; } - // Resources::Resource lifecycle update + // Resources lifecycle update _global->getLevel()->onEnterLocation(); current->getLevel()->onEnterLocation(); current->getLocation()->onEnterLocation(); diff --git a/engines/stark/services/services.h b/engines/stark/services/services.h index 38f1a0a36ad..dfb1928e71c 100644 --- a/engines/stark/services/services.h +++ b/engines/stark/services/services.h @@ -40,6 +40,7 @@ class ArchiveLoader; class DialogPlayer; class Global; class ResourceProvider; +class StaticProvider; class Scene; class UserInterface; @@ -56,6 +57,7 @@ public: resourceProvider = nullptr; randomSource = nullptr; scene = nullptr; + staticProvider = nullptr; userInterface = nullptr; } @@ -66,6 +68,7 @@ public: ResourceProvider *resourceProvider; Common::RandomSource *randomSource; Scene *scene; + StaticProvider *staticProvider; UserInterface *userInterface; }; diff --git a/engines/stark/services/staticprovider.cpp b/engines/stark/services/staticprovider.cpp new file mode 100644 index 00000000000..2de6204a237 --- /dev/null +++ b/engines/stark/services/staticprovider.cpp @@ -0,0 +1,64 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * 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 "engines/stark/services/staticprovider.h" + +#include "engines/stark/resources/bookmark.h" +#include "engines/stark/resources/camera.h" +#include "engines/stark/resources/floor.h" +#include "engines/stark/resources/item.h" +#include "engines/stark/resources/layer.h" +#include "engines/stark/resources/level.h" +#include "engines/stark/resources/location.h" +#include "engines/stark/resources/root.h" +#include "engines/stark/resources/script.h" +#include "engines/stark/services/archiveloader.h" +#include "engines/stark/services/global.h" +#include "engines/stark/services/stateprovider.h" + +namespace Stark { + +StaticProvider::StaticProvider(ArchiveLoader *archiveLoader, Global *global) : + _archiveLoader(archiveLoader), + _global(global), + _level(nullptr) { +} + +void StaticProvider::init() { + // Load the static archive + _archiveLoader->load("static/static.xarc"); + + // Set the root tree + _level = _archiveLoader->useRoot("static/static.xarc"); + + // Resources lifecycle update + _level->onAllLoaded(); +} + +void StaticProvider::shutdown() { + _level = nullptr; + + _archiveLoader->returnRoot("static/static.xarc"); + _archiveLoader->unloadUnused(); +} + +} // End of namespace Stark diff --git a/engines/stark/services/staticprovider.h b/engines/stark/services/staticprovider.h new file mode 100644 index 00000000000..fb1e1a8a98b --- /dev/null +++ b/engines/stark/services/staticprovider.h @@ -0,0 +1,65 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * 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. + * + */ + +#ifndef STARK_STATIC_PROVIDER_H +#define STARK_STATIC_PROVIDER_H + +#include "common/scummsys.h" + +namespace Stark { + +namespace Resources { +class Level; +} + +class ArchiveLoader; +class Global; + +/** + * Static Resource provider. + * + * Maintains the static resource trees. + * Maintained trees are the level and the location ones. + */ +class StaticProvider { +public: + StaticProvider(ArchiveLoader *archiveLoader, Global *global); + + /** Load the static level archive */ + void init(); + + /** Release the static resources */ + void shutdown(); + + /** Obtain the static level */ + Resources::Level *getLevel() const { return _level; } + +private: + ArchiveLoader *_archiveLoader; + Global *_global; + + Resources::Level *_level; +}; + +} // End of namespace Stark + +#endif // STARK_STATIC_PROVIDER_H diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp index df244446e7b..1a3b8f7b571 100644 --- a/engines/stark/stark.cpp +++ b/engines/stark/stark.cpp @@ -34,6 +34,7 @@ #include "engines/stark/services/resourceprovider.h" #include "engines/stark/services/services.h" #include "engines/stark/services/stateprovider.h" +#include "engines/stark/services/staticprovider.h" #include "engines/stark/services/userinterface.h" #include "engines/stark/gfx/driver.h" #include "engines/stark/gfx/renderentry.h" @@ -58,6 +59,7 @@ StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) : _userInterface(nullptr), _archiveLoader(nullptr), _stateProvider(nullptr), + _staticProvider(nullptr), _resourceProvider(nullptr), _randomSource(nullptr), _dialogPlayer(nullptr) { @@ -81,6 +83,7 @@ StarkEngine::~StarkEngine() { delete _scene; delete _console; delete _gfx; + delete _staticProvider; delete _resourceProvider; delete _global; delete _stateProvider; @@ -100,6 +103,7 @@ Common::Error StarkEngine::run() { _stateProvider = new StateProvider(); _global = new Global(); _resourceProvider = new ResourceProvider(_archiveLoader, _stateProvider, _global); + _staticProvider = new StaticProvider(_archiveLoader, _global); _randomSource = new Common::RandomSource("stark"); _scene = new Scene(_gfx); _dialogPlayer = new DialogPlayer(); @@ -115,9 +119,11 @@ Common::Error StarkEngine::run() { services.resourceProvider = _resourceProvider; services.randomSource = _randomSource; services.scene = _scene; + services.staticProvider = _staticProvider; // Load global resources _resourceProvider->initGlobal(); + _staticProvider->init(); // Start us up at the house of all worlds _global->setCurrentChapter(0); @@ -126,6 +132,7 @@ Common::Error StarkEngine::run() { // Start running mainLoop(); + _staticProvider->shutdown(); _resourceProvider->shutdown(); return Common::kNoError; diff --git a/engines/stark/stark.h b/engines/stark/stark.h index bfea22aab40..5823b311103 100644 --- a/engines/stark/stark.h +++ b/engines/stark/stark.h @@ -48,6 +48,7 @@ class Global; class UserInterface; class Scene; class StateProvider; +class StaticProvider; class ResourceProvider; class StarkEngine : public Engine { @@ -78,6 +79,7 @@ private: Global *_global; UserInterface *_userInterface; StateProvider *_stateProvider; + StaticProvider *_staticProvider; ResourceProvider *_resourceProvider; Common::RandomSource *_randomSource;