ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

staticprovider.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/services/staticprovider.h"
00024 
00025 #include "engines/stark/resources/anim.h"
00026 #include "engines/stark/resources/animscript.h"
00027 #include "engines/stark/resources/container.h"
00028 #include "engines/stark/resources/image.h"
00029 #include "engines/stark/resources/item.h"
00030 #include "engines/stark/resources/level.h"
00031 #include "engines/stark/resources/location.h"
00032 #include "engines/stark/resources/sound.h"
00033 #include "engines/stark/services/archiveloader.h"
00034 #include "engines/stark/services/global.h"
00035 #include "engines/stark/visual/image.h"
00036 
00037 namespace Stark {
00038 
00039 StaticProvider::StaticProvider(ArchiveLoader *archiveLoader) :
00040         _archiveLoader(archiveLoader),
00041         _level(nullptr),
00042         _location(nullptr) {
00043 }
00044 
00045 void StaticProvider::init() {
00046     // Load the static archive
00047     _archiveLoader->load("static/static.xarc");
00048 
00049     // Set the root tree
00050     _level = _archiveLoader->useRoot<Resources::Level>("static/static.xarc");
00051 
00052     // Resources lifecycle update
00053     _level->onAllLoaded();
00054 
00055     Resources::Item *staticItem = _level->findChild<Resources::Item>();
00056     _stockAnims = staticItem->listChildren<Resources::Anim>();
00057 
00058     for (uint i = 0; i< _stockAnims.size(); i++) {
00059         _stockAnims[i]->applyToItem(nullptr);
00060     }
00061 
00062     Resources::Anim *imagesAnim = _stockAnims[kImages];
00063     _stockImages = imagesAnim->listChildrenRecursive<Resources::Image>();
00064 }
00065 
00066 void StaticProvider::onGameLoop() {
00067     _level->onGameLoop();
00068 }
00069 
00070 void StaticProvider::shutdown() {
00071     if (_location) {
00072         unloadLocation(_location);
00073     }
00074 
00075     _level = nullptr;
00076 
00077     _archiveLoader->returnRoot("static/static.xarc");
00078     _archiveLoader->unloadUnused();
00079 }
00080 
00081 VisualImageXMG *StaticProvider::getCursorImage(uint32 cursor) const {
00082     Resources::Anim *anim = _stockAnims[cursor];
00083     return anim->getVisual()->get<VisualImageXMG>();
00084 }
00085 
00086 VisualImageXMG *StaticProvider::getUIElement(UIElement element) const {
00087     return getCursorImage(element);
00088 }
00089 
00090 VisualImageXMG *StaticProvider::getUIElement(UIElement element, uint32 index) const {
00091     Resources::Anim *anim = _stockAnims[element];
00092 
00093     uint32 prevIndex = anim->getCurrentFrame();
00094     anim->selectFrame(index);
00095     VisualImageXMG *visualImage = anim->getVisual()->get<VisualImageXMG>();
00096     anim->selectFrame(prevIndex);
00097     
00098     return visualImage;
00099 }
00100 
00101 VisualImageXMG *StaticProvider::getUIImage(UIImage image) const {
00102     Resources::Image *anim = _stockImages[image];
00103     return anim->getVisual()->get<VisualImageXMG>();
00104 }
00105 
00106 void StaticProvider::goToAnimScriptStatement(StaticProvider::UIElement stockUIElement, int animScriptItemIndex) {
00107     Resources::Anim *anim = _stockAnims[stockUIElement];
00108     Resources::AnimScript *animScript = anim->findChild<Resources::AnimScript>();
00109     Resources::AnimScriptItem *animScriptItem = animScript->findChildWithIndex<Resources::AnimScriptItem>(animScriptItemIndex);
00110     animScript->goToScriptItem(animScriptItem);
00111 }
00112 
00113 Resources::Sound *StaticProvider::getUISound(UISound sound) const {
00114     Resources::Item *staticLevelItem = _level->findChild<Resources::Item>();
00115     Resources::Anim *anim = staticLevelItem->findChildWithOrder<Resources::Anim>(4);
00116     Resources::Container *sounds = anim->findChildWithSubtype<Resources::Container>(Resources::Container::kSounds);
00117     return sounds->findChildWithOrder<Resources::Sound>(sound);
00118 }
00119 
00120 Common::String StaticProvider::buildLocationArchiveName(const char *locationName) const {
00121     return Common::String::format("static/%s/%s.xarc", locationName, locationName);
00122 }
00123 
00124 Resources::Location *StaticProvider::loadLocation(const char *locationName) {
00125     assert(!_location);
00126 
00127     Common::String archiveName = buildLocationArchiveName(locationName);
00128 
00129     _archiveLoader->load(archiveName);
00130     _location = _archiveLoader->useRoot<Resources::Location>(archiveName);
00131 
00132     _location->onAllLoaded();
00133     _location->onEnterLocation();
00134 
00135     // Start background music
00136     Common::Array<Resources::Sound *> sounds = _location->listChildren<Resources::Sound>(Resources::Sound::kSoundBackground);
00137     for (uint i = 0; i < sounds.size(); i++) {
00138         sounds[i]->play();
00139     }
00140 
00141     return _location;
00142 }
00143 
00144 void StaticProvider::unloadLocation(Resources::Location *location) {
00145     assert(_location == location);
00146 
00147     location->onExitLocation();
00148 
00149     Common::String archiveName = buildLocationArchiveName(location->getName().c_str());
00150     _archiveLoader->returnRoot(archiveName);
00151     _archiveLoader->unloadUnused();
00152 
00153     _location = nullptr;
00154 }
00155 
00156 bool StaticProvider::isStaticLocation() const {
00157     return _location != nullptr;
00158 }
00159 
00160 Resources::Location *StaticProvider::getLocation() const {
00161     return _location;
00162 }
00163 
00164 Resources::Sound *StaticProvider::getLocationSound(uint16 index) const {
00165     assert(_location);
00166 
00167     Resources::Container *sounds = _location->findChildWithSubtype<Resources::Container>(Resources::Container::kSounds);
00168     return sounds->findChildWithIndex<Resources::Sound>(index);
00169 }
00170 
00171 } // End of namespace Stark


Generated on Sat Oct 19 2019 05:01:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge