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

biff.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/formats/biff.h"
00024 
00025 #include "engines/stark/services/archiveloader.h"
00026 
00027 namespace Stark {
00028 namespace Formats {
00029 
00030 BiffArchive::BiffArchive(ArchiveReadStream *stream, ObjectBuilder objectBuilder) :
00031     _objectBuilder(objectBuilder) {
00032     read(stream);
00033 }
00034 
00035 BiffArchive::~BiffArchive() {
00036     for (uint i = 0; i < _rootObjects.size(); i++) {
00037         delete _rootObjects[i];
00038     }
00039 }
00040 
00041 void BiffArchive::read(ArchiveReadStream *stream) {
00042     uint32 id = stream->readUint32BE();
00043     if (id != MKTAG('B', 'I', 'F', 'F')) {
00044         error("Wrong magic while reading biff archive");
00045     }
00046 
00047     _version = stream->readUint32LE();
00048     /*uint32 u1 = */stream->readUint32LE();
00049     /*uint32 u2 = */stream->readUint32LE();
00050 
00051     uint32 len = stream->readUint32LE();
00052     for (uint32 i = 0; i < len; i++) {
00053         BiffObject *object = readObject(stream, nullptr);
00054 
00055         _rootObjects.push_back(object);
00056     }
00057 }
00058 
00059 BiffObject *BiffArchive::readObject(ArchiveReadStream *stream, BiffObject *parent) {
00060     uint32 marker = stream->readUint32LE();
00061     if (marker != 0xf0f0f0f0) {
00062         error("Wrong magic while reading biff archive");
00063     }
00064 
00065     uint32 type = stream->readUint32LE();
00066     BiffObject *object = _objectBuilder(type);
00067     if (!object) {
00068         error("Unimplemented BIFF object type %x", type);
00069     }
00070 
00071     object->_parent = parent;
00072     object->_u3 = stream->readUint32LE();
00073     uint32 size = stream->readUint32LE();
00074 
00075     if (_version >= 2) {
00076         object->_version = stream->readUint32LE();
00077     }
00078 
00079     object->readData(stream, size);
00080 
00081     marker = stream->readUint32LE();
00082     if (marker != 0x0f0f0f0f) {
00083         error("Wrong magic while reading biff archive");
00084     }
00085 
00086     uint32 len = stream->readUint32LE();
00087     for (uint32 i = 0; i < len; ++i) {
00088         BiffObject *child = readObject(stream, object);
00089         object->addChild(child);
00090     }
00091 
00092     return object;
00093 }
00094 
00095 Common::Array<BiffObject *> BiffArchive::listObjects() {
00096     return _rootObjects;
00097 }
00098 
00099 BiffObject::BiffObject() :
00100     _u3(0),
00101     _version(0),
00102     _parent(nullptr),
00103     _type(0) {
00104 
00105 }
00106 
00107 uint32 BiffObject::getType() const {
00108     return _type;
00109 }
00110 
00111 void BiffObject::addChild(BiffObject *child) {
00112     _children.push_back(child);
00113 }
00114 
00115 BiffObject::~BiffObject() {
00116     // Delete the children objects
00117     Common::Array<BiffObject *>::iterator i = _children.begin();
00118     while (i != _children.end()) {
00119         delete *i;
00120         i++;
00121     }
00122 }
00123 
00124 } // End of namespace Formats
00125 } // End of namespace Stark


Generated on Sat Mar 23 2019 05:01:19 for ResidualVM by doxygen 1.7.1
curved edge   curved edge