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

tm.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/tm.h"
00024 
00025 #include "graphics/surface.h"
00026 
00027 #include "engines/stark/gfx/driver.h"
00028 #include "engines/stark/gfx/texture.h"
00029 
00030 #include "engines/stark/formats/biff.h"
00031 
00032 #include "engines/stark/services/archiveloader.h"
00033 #include "engines/stark/services/services.h"
00034 
00035 namespace Stark {
00036 namespace Formats {
00037 
00038 enum TextureSetType {
00039     kTextureSetGroup   = 0x02faf082,
00040     kTextureSetTexture = 0x02faf080
00041 };
00042 
00043 class TextureGroup : public BiffObject {
00044 public:
00045     static const uint32 TYPE = kTextureSetGroup;
00046 
00047     TextureGroup() :
00048             BiffObject(),
00049             _palette(nullptr) {
00050         _type = TYPE;
00051     }
00052 
00053     virtual ~TextureGroup() {
00054         delete[] _palette;
00055     }
00056 
00057     const byte *getPalette() {
00058         return _palette;
00059     }
00060 
00061     // BiffObject API
00062     void readData(ArchiveReadStream *stream, uint32 dataLength) override {
00063         int entries = stream->readUint32LE();
00064         _palette = new byte[entries * 3];
00065 
00066         byte *ptr = _palette;
00067         for (int i = 0; i < entries; ++i) {
00068             *ptr++ = (byte) stream->readUint16LE();
00069             *ptr++ = (byte) stream->readUint16LE();
00070             *ptr++ = (byte) stream->readUint16LE();
00071         }
00072     }
00073 
00074 private:
00075     byte *_palette;
00076 };
00077 
00078 class Texture : public BiffObject {
00079 public:
00080     static const uint32 TYPE = kTextureSetTexture;
00081 
00082     Texture() :
00083             BiffObject(),
00084             _texture(nullptr),
00085             _u(0) {
00086         _type = TYPE;
00087     }
00088 
00089     virtual ~Texture() {
00090         delete _texture;
00091     }
00092 
00093     Common::String getName() const {
00094         return _name;
00095     }
00096 
00097     Gfx::Texture *acquireTexturePointer() {
00098         Gfx::Texture *texture = _texture;
00099         _texture = nullptr;
00100 
00101         return texture;
00102     }
00103 
00104     // BiffObject API
00105     void readData(ArchiveReadStream *stream, uint32 dataLength) override {
00106         TextureGroup *textureGroup = static_cast<TextureGroup *>(_parent);
00107 
00108         _name = stream->readString16();
00109         _u = stream->readByte();
00110 
00111         uint32 w = stream->readUint32LE();
00112         uint32 h = stream->readUint32LE();
00113         uint32 levels = stream->readUint32LE();
00114 
00115         _texture = StarkGfx->createTexture();
00116         _texture->setLevelCount(levels);
00117 
00118         for (uint32 i = 0; i < levels; ++i) {
00119             // Read the pixel data to a surface
00120             Graphics::Surface level;
00121             level.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
00122             stream->read(level.getPixels(), level.w * level.h);
00123 
00124             // Add the mipmap level to the texture
00125             _texture->addLevel(i, &level, textureGroup->getPalette());
00126 
00127             level.free();
00128 
00129             w /= 2;
00130             h /= 2;
00131         }
00132     }
00133 
00134 private:
00135     Common::String _name;
00136     Gfx::Texture *_texture;
00137     byte _u;
00138 };
00139 
00140 Gfx::TextureSet *TextureSetReader::read(ArchiveReadStream *stream) {
00141     BiffArchive archive = BiffArchive(stream, &biffObjectBuilder);
00142 
00143     Common::Array<Texture *> textures = archive.listObjectsRecursive<Texture>();
00144 
00145     Gfx::TextureSet *textureSet = new Gfx::TextureSet();
00146     for (uint i = 0; i < textures.size(); i++) {
00147         textureSet->addTexture(textures[i]->getName(), textures[i]->acquireTexturePointer());
00148     }
00149 
00150     return textureSet;
00151 }
00152 
00153 BiffObject *TextureSetReader::biffObjectBuilder(uint32 type) {
00154     switch (type) {
00155         case kTextureSetGroup:
00156             return new TextureGroup();
00157         case kTextureSetTexture:
00158             return new Texture();
00159         default:
00160             return nullptr;
00161     }
00162 }
00163 
00164 } // End of namespace Formats
00165 } // End of namespace Stark


Generated on Sat Apr 20 2019 05:04:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge