myst3 : The room faces are now read from the archive files

This commit is contained in:
Bastien Bouclet 2009-09-15 18:45:55 +02:00
parent e7ef82a6a4
commit 9b5562ea4d
9 changed files with 139 additions and 43 deletions

View File

@ -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();
}

View File

@ -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<DirectoryEntry> _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

View File

@ -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;
}

View File

@ -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; }
};

View File

@ -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<Common::MemoryReadStream *>(inStream.readStream(_size));
}

View File

@ -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; }
};

View File

@ -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);

View File

@ -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;

View File

@ -33,6 +33,8 @@
#include <GL/glu.h>
#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