From 9b5562ea4d85e6327e41cdda3eb36f2b5ece7335 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Tue, 15 Sep 2009 18:45:55 +0200 Subject: [PATCH] myst3 : The room faces are now read from the archive files --- engines/myst3/archive.cpp | 31 ++++++++++++++++++--- engines/myst3/archive.h | 43 +++++++++++++++++++++++++++-- engines/myst3/directoryentry.cpp | 11 ++++++++ engines/myst3/directoryentry.h | 2 ++ engines/myst3/directorysubentry.cpp | 20 ++++++++++++-- engines/myst3/directorysubentry.h | 5 +++- engines/myst3/myst3.cpp | 42 ++++++++++------------------ engines/myst3/room.cpp | 25 +++++++++++++---- engines/myst3/room.h | 3 ++ 9 files changed, 139 insertions(+), 43 deletions(-) diff --git a/engines/myst3/archive.cpp b/engines/myst3/archive.cpp index 5ad985a3708..e32841d3c9f 100755 --- a/engines/myst3/archive.cpp +++ b/engines/myst3/archive.cpp @@ -20,9 +20,9 @@ void Archive::_decryptHeader(Common::SeekableReadStream &inStream, Common::Write } } -void Archive::readFromStream(Common::SeekableReadStream &inStream) { +void Archive::_readDirectory() { Common::MemoryWriteStreamDynamic buf(DisposeAfterUse::YES); - _decryptHeader(inStream, buf); + _decryptHeader(_file, buf); Common::MemoryReadStream directory(buf.getData(), buf.size()); directory.skip(sizeof(uint32)); @@ -42,8 +42,31 @@ void Archive::dumpDirectory() { } } -void Archive::dumpToFiles(Common::SeekableReadStream &inStream) { +void Archive::dumpToFiles() { for (uint i = 0; i < _directory.size(); i++) { - _directory[i].dumpToFiles(inStream); + _directory[i].dumpToFiles(_file); } } + +Common::MemoryReadStream *Archive::dumpToMemory(uint16 index, uint16 face, uint16 type) { + for (uint i = 0; i < _directory.size(); i++) { + if (_directory[i].getIndex() == index) { + return _directory[i].dumpToMemory(_file, face, type); + } + } + + return 0; +} + +bool Archive::open(const char *fileName) { + if (_file.open(fileName)) { + _readDirectory(); + return true; + } + + return false; +} + +void Archive::close() { + _file.close(); +} diff --git a/engines/myst3/archive.h b/engines/myst3/archive.h index 480b6f00ec2..dc0d98d6bfe 100755 --- a/engines/myst3/archive.h +++ b/engines/myst3/archive.h @@ -1,14 +1,51 @@ +/* Residual - A 3D game interpreter + * + * Residual 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + * $URL$ + * $Id$ + * + */ + +#ifndef MYST3_ARCHIVE_H +#define MYST3_ARCHIVE_H + #include "engines/myst3/directoryentry.h" #include "common/stream.h" #include "common/array.h" +#include "common/file.h" class Archive { private: + Common::File _file; Common::Array _directory; + void _decryptHeader(Common::SeekableReadStream &inStream, Common::WriteStream &outStream); - + void _readDirectory(); public: - void readFromStream(Common::SeekableReadStream &inStream); + + Common::MemoryReadStream *dumpToMemory(uint16 index, uint16 face, uint16 type); void dumpDirectory(); - void dumpToFiles(Common::SeekableReadStream &inStream); + void dumpToFiles(); + + bool open(const char *fileName); + void close(); }; + +#endif diff --git a/engines/myst3/directoryentry.cpp b/engines/myst3/directoryentry.cpp index 838544c68ad..316f7a2f7f6 100755 --- a/engines/myst3/directoryentry.cpp +++ b/engines/myst3/directoryentry.cpp @@ -36,3 +36,14 @@ void DirectoryEntry::dumpToFiles(Common::SeekableReadStream &inStream) { _subentries[i].dumpToFile(inStream, _index); } } + +Common::MemoryReadStream *DirectoryEntry::dumpToMemory(Common::SeekableReadStream &inStream, uint16 face, uint16 type) { + for (uint i = 0; i < _subentries.size(); i++) { + if (_subentries[i].getFace() == face + && _subentries[i].getType() == type) { + return _subentries[i].dumpToMemory(inStream); + } + } + + return 0; +} diff --git a/engines/myst3/directoryentry.h b/engines/myst3/directoryentry.h index b169b07312a..8dc148d699b 100755 --- a/engines/myst3/directoryentry.h +++ b/engines/myst3/directoryentry.h @@ -12,5 +12,7 @@ class DirectoryEntry { void readFromStream(Common::SeekableReadStream &inStream); void dump(); void dumpToFiles(Common::SeekableReadStream &inStream); + Common::MemoryReadStream *dumpToMemory(Common::SeekableReadStream &inStream, uint16 face, uint16 type); bool hasSubEntries(); + uint16 getIndex() { return _index; } }; diff --git a/engines/myst3/directorysubentry.cpp b/engines/myst3/directorysubentry.cpp index 011b80049eb..4b89d161e0b 100755 --- a/engines/myst3/directorysubentry.cpp +++ b/engines/myst3/directorysubentry.cpp @@ -2,7 +2,7 @@ #include "common/str.h" #include "common/debug.h" #include "common/file.h" -#include "common/stream.h" +#include "common/memstream.h" void DirectorySubEntry::readFromStream(Common::SeekableReadStream &inStream) { _offset = inStream.readUint32LE(); @@ -13,7 +13,18 @@ void DirectorySubEntry::readFromStream(Common::SeekableReadStream &inStream) { dump(); - inStream.skip(_padding * sizeof(uint32)); + if (_padding == 2) { + uint32 _padding2 = inStream.readUint32LE(); + uint32 _padding3 = inStream.readUint32LE(); + debug("position x %d y %d", _padding2, _padding3); + } /*else if (_padding == 10) { + uint32 _padding2 = inStream.readUint32LE(); + uint32 _padding3 = inStream.readUint32LE(); + inStream.skip(8 * sizeof(uint32)); + debug("position x %d y %d", _padding2, _padding3); + }*/ else { + inStream.skip(_padding * sizeof(uint32)); + } } void DirectorySubEntry::dump() { @@ -56,3 +67,8 @@ void DirectorySubEntry::dumpToFile(Common::SeekableReadStream &inStream, uint16 outFile.close(); } + +Common::MemoryReadStream *DirectorySubEntry::dumpToMemory(Common::SeekableReadStream &inStream) { + inStream.seek(_offset); + return static_cast(inStream.readStream(_size)); +} diff --git a/engines/myst3/directorysubentry.h b/engines/myst3/directorysubentry.h index 7b2ae289621..d52f35392cd 100755 --- a/engines/myst3/directorysubentry.h +++ b/engines/myst3/directorysubentry.h @@ -1,4 +1,4 @@ -#include "common/stream.h" +#include "common/memstream.h" class DirectorySubEntry { private: @@ -12,4 +12,7 @@ class DirectorySubEntry { void readFromStream(Common::SeekableReadStream &inStream); void dump(); void dumpToFile(Common::SeekableReadStream &inStream, uint16 index); + Common::MemoryReadStream *dumpToMemory(Common::SeekableReadStream &inStream); + uint16 getFace() { return _face; } + uint16 getType() { return _type; } }; diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp index 1904fb2262d..d9c4acfba44 100644 --- a/engines/myst3/myst3.cpp +++ b/engines/myst3/myst3.cpp @@ -24,9 +24,11 @@ */ #include "common/events.h" +#include "common/error.h" #include "common/config-manager.h" #include "common/file.h" #include "common/util.h" +#include "common/textconsole.h" #include "engines/engine.h" @@ -51,25 +53,16 @@ Room room; float CAMERA_Pitch = 0.0f; float CAMERA_Yaw = 0.0f; -void sbInit() { +void sbInit(const char *fileName, int index) { - for (int i = 0; i < 6; i++) { - char fileName[250]; - sprintf(fileName, "1-%d.jpg", i + 1); + Archive archive; + if (!archive.open(fileName)) { + error("Unable to open archive"); + } - Common::File jpegFile; - if (!jpegFile.open(fileName)) { - error("Unable to open cube face %d", i); - } - - Graphics::JPEG jpeg; - jpeg.read(&jpegFile); - - room.setFaceTextureJPEG(i, &jpeg); - - jpegFile.close(); - - } + room.load(archive, index); + + archive.close(); } void DrawSkyBox(float camera_yaw, float camera_pitch) @@ -109,17 +102,14 @@ void Render(float camera_yaw, float camera_pitch) } void Myst3Engine::dumpArchive(const char *fileName) { - Common::File archiveFile; - if (!archiveFile.open(fileName)) { + Archive archive; + if (!archive.open(fileName)) { error("Unable to open archive"); } - Archive archive; - archive.readFromStream(archiveFile); archive.dumpDirectory(); - archive.dumpToFiles(archiveFile); - - archiveFile.close(); + archive.dumpToFiles(); + archive.close(); } Myst3Engine::Myst3Engine(OSystem *syst, int gameFlags) : @@ -132,8 +122,6 @@ Myst3Engine::~Myst3Engine() { } Common::Error Myst3Engine::run() { - //dumpArchive("MAISnodes.m3a"); - int w = 800; int h = 600; @@ -148,7 +136,7 @@ Common::Error Myst3Engine::run() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - sbInit(); + sbInit("MAISnodes.m3a", 2); diff --git a/engines/myst3/room.cpp b/engines/myst3/room.cpp index 31168a6bf94..b6a36b15e07 100644 --- a/engines/myst3/room.cpp +++ b/engines/myst3/room.cpp @@ -28,15 +28,15 @@ namespace Myst3 { void Room::setFaceTextureJPEG(int face, Graphics::JPEG *jpeg) { - Graphics::Surface *texture = new Graphics::Surface(); - texture->create(jpeg->getComponent(1)->w, jpeg->getComponent(1)->h, 3); + Graphics::Surface texture; + texture.create(jpeg->getComponent(1)->w, jpeg->getComponent(1)->h, Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0)); byte *y = (byte *)jpeg->getComponent(1)->getBasePtr(0, 0); byte *u = (byte *)jpeg->getComponent(2)->getBasePtr(0, 0); byte *v = (byte *)jpeg->getComponent(3)->getBasePtr(0, 0); - byte *ptr = (byte *)texture->getBasePtr(0, 0); - for (int i = 0; i < texture->w * texture->h; i++) { + byte *ptr = (byte *)texture.getBasePtr(0, 0); + for (int i = 0; i < texture.w * texture.h; i++) { byte r, g, b; Graphics::YUV2RGB(*y++, *u++, *v++, r, g, b); *ptr++ = r; @@ -44,9 +44,9 @@ void Room::setFaceTextureJPEG(int face, Graphics::JPEG *jpeg) { *ptr++ = b; } - setFaceTextureRGB(face, texture); + setFaceTextureRGB(face, &texture); - delete texture; + texture.free(); } void Room::setFaceTextureRGB(int face, Graphics::Surface *texture) { @@ -61,6 +61,19 @@ void Room::setFaceTextureRGB(int face, Graphics::Surface *texture) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } +void Room::load(Archive &archive, uint16 index) { + for (int i = 0; i < 6; i++) { + Common::MemoryReadStream *jpegStream = archive.dumpToMemory(index, i + 1, 0); + + if (jpegStream) { + Graphics::JPEG jpeg; + jpeg.read(jpegStream); + + setFaceTextureJPEG(i, &jpeg); + } + } +} + void Room::draw() { // Taille du cube float t = 1.0f; diff --git a/engines/myst3/room.h b/engines/myst3/room.h index 3f9818cb92b..8bc5e41a3d5 100644 --- a/engines/myst3/room.h +++ b/engines/myst3/room.h @@ -33,6 +33,8 @@ #include #endif +#include "engines/myst3/archive.h" + #include "graphics/surface.h" #include "graphics/jpeg.h" #include "graphics/conversion.h" @@ -48,6 +50,7 @@ class Room { void setFaceTextureRGB(int face, Graphics::Surface *texture); void setFaceTextureJPEG(int face, Graphics::JPEG *jpeg); void draw(); + void load(Archive &archive, uint16 index); }; } // end of namespace Myst3