diff options
author | Paul Gilbert | 2015-03-19 23:31:28 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-03-19 23:31:28 -0400 |
commit | 77a4227aa4915a860accdd761fb9695d390641dd (patch) | |
tree | fa1d9cbb7fe84bc1b851bdbb662c82c9255dab67 /engines/sherlock/scene.cpp | |
parent | a02461fcb15da3b2e7e91d9cfb1bca559a1d277b (diff) | |
download | scummvm-rg350-77a4227aa4915a860accdd761fb9695d390641dd.tar.gz scummvm-rg350-77a4227aa4915a860accdd761fb9695d390641dd.tar.bz2 scummvm-rg350-77a4227aa4915a860accdd761fb9695d390641dd.zip |
SHERLOCK: Added loading of scene objects
Diffstat (limited to 'engines/sherlock/scene.cpp')
-rw-r--r-- | engines/sherlock/scene.cpp | 127 |
1 files changed, 126 insertions, 1 deletions
diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp index 84ef44d7e1..267b02b43c 100644 --- a/engines/sherlock/scene.cpp +++ b/engines/sherlock/scene.cpp @@ -21,9 +21,37 @@ */ #include "sherlock/scene.h" +#include "sherlock/sherlock.h" +#include "sherlock/decompress.h" namespace Sherlock { +void BgFileHeader::synchronize(Common::SeekableReadStream &s) { + _numStructs = s.readUint16LE(); + _numImages = s.readUint16LE(); + _numcAnimations = s.readUint16LE(); + _descSize = s.readUint16LE(); + _seqSize = s.readUint16LE(); + _fill = s.readUint16LE(); +} + +/*----------------------------------------------------------------*/ + +void BgfileheaderInfo::synchronize(Common::SeekableReadStream &s) { + _fSize = s.readUint32LE(); + _maxFrames = s.readByte(); + + char buffer[9]; + s.read(buffer, 9); + _filename = Common::String(buffer); +} + +int _fSize; // How long images are +int _maxFrames; // How many unique frames in object +Common::String _filename; // Filename of object + +/*----------------------------------------------------------------*/ + Scene::Scene(SherlockEngine *vm): _vm(vm) { for (int idx = 0; idx < SCENES_COUNT; ++idx) Common::fill(&_stats[idx][0], &_stats[idx][9], false); @@ -32,6 +60,11 @@ Scene::Scene(SherlockEngine *vm): _vm(vm) { _numExits = 0; _windowOpen = _infoFlag = false; _menuMode = _keyboardInput = 0; + _walkedInScene = false; + _ongoingCans = 0; + _version = 0; + _lzwMode = false; + _invGraphicItems = 0; _controls = nullptr; // new ImageFile("menu.all"); } @@ -48,9 +81,101 @@ void Scene::selectScene() { _oldKey = _help = _oldHelp = 0; _oldTemp = _temp = 0; - // Set up player + // Load the scene + Common::String sceneFile = Common::String::format("res%02d", _goToRoom); + Common::String roomName = Common::String::format("res%02d.rrm", _goToRoom); + _goToRoom = -1; + + loadScene(sceneFile); +} + +/** + * Loads the data associated for a given scene. The .BGD file's format is: + * BGHEADER: Holds an index for the rest of the file + * STRUCTS: The objects for the scene + * IMAGES: The graphic information for the structures + * + * The _misc field of the structures contains the number of the graphic image + * that it should point to after loading; _misc is then set to 0. + */ +void Scene::loadScene(const Common::String &filename) { + bool flag; + + _walkedInScene = false; + _ongoingCans = 0; + + // Reset the list of walkable areas + _roomBounds.clear(); + _roomBounds.push_back(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT)); + + _descText.clear(); + _comments = ""; + _bgShapes.clear(); + _cAnim.clear(); + _sequenceBuffer.clear(); + + // + // Load background shapes from <filename>.rrm + // + + Common::String rrmFile = filename + ".rrm"; + flag = _vm->_res->exists(rrmFile); + if (flag) { + Common::SeekableReadStream *rrmStream = _vm->_res->load(rrmFile); + + rrmStream->seek(39); + _version = rrmStream->readByte(); + _lzwMode = _version == 10; + + // Go to header and read it in + rrmStream->seek(rrmStream->readUint32LE()); + BgFileHeader bgHeader; + bgHeader.synchronize(*rrmStream); + + _cAnim.resize(bgHeader._numcAnimations); + _invGraphicItems = bgHeader._numImages + 1; + + // Read in the shapes header info + Common::Array<BgfileheaderInfo> bgInfo; + bgInfo.resize(bgHeader._numStructs); + + for (uint idx = 0; idx < bgInfo.size(); ++idx) + bgInfo[idx].synchronize(*rrmStream); + + // Initialize the cAnim + for (uint idx = 0; idx < _cAnim.size(); ++idx) { + _cAnim[idx]._position.x = -1; + _cAnim[idx]._goto.x = -1; + _cAnim[idx]._teleportPos.x = -1; + } + + // Read information + Common::SeekableReadStream *infoStream = !_lzwMode ? rrmStream : + decompressLZ(*rrmStream, bgHeader._numImages * 569 + + bgHeader._descSize + bgHeader._seqSize); + + _bgShapes.resize(bgHeader._numStructs); + for (uint idx = 0; idx < _bgShapes.size(); ++idx) + _bgShapes[idx].synchronize(*infoStream); + + if (bgHeader._descSize) { + _descText.resize(bgHeader._descSize); + infoStream->read(&_descText[0], bgHeader._descSize); + } + + if (bgHeader._seqSize) { + _sequenceBuffer.resize(bgHeader._seqSize); + infoStream->read(&_sequenceBuffer[0], bgHeader._seqSize); + } + + if (_lzwMode) + delete infoStream; + // Load shapes + // TODO + delete rrmStream; + } } } // End of namespace Sherlock |