STARK: Load the static level

This commit is contained in:
Bastien Bouclet 2015-02-22 11:26:31 +01:00
parent 756a8bf383
commit 73ee04635a
10 changed files with 174 additions and 5 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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 \

View file

@ -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();

View file

@ -54,11 +54,11 @@ void ResourceProvider::initGlobal() {
Resources::Root *root = _archiveLoader->useRoot<Resources::Root>("x.xarc");
_global->setRoot(root);
// Resources::Resource lifecycle update
// Resources lifecycle update
root->onAllLoaded();
// Find the global level node
Resources::Level *global = root->findChildWithSubtype<Resources::Level>(1);
Resources::Level *global = root->findChildWithSubtype<Resources::Level>(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();

View file

@ -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;
};

View file

@ -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<Resources::Level>("static/static.xarc");
// Resources lifecycle update
_level->onAllLoaded();
}
void StaticProvider::shutdown() {
_level = nullptr;
_archiveLoader->returnRoot("static/static.xarc");
_archiveLoader->unloadUnused();
}
} // End of namespace Stark

View file

@ -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

View file

@ -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;

View file

@ -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;