mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
TITANIC: Implemented CStdCWADFile class
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
|
||||
namespace Titanic {
|
||||
|
||||
CJPEGDecode::CJPEGDecode(const CString &name): _file(name),
|
||||
_width(0), _height(0) {
|
||||
CJPEGDecode::CJPEGDecode(const CString &name) : _width(0), _height(0) {
|
||||
_file.open(name);
|
||||
}
|
||||
|
||||
void CJPEGDecode::decode(OSVideoSurface &surface) {
|
||||
@@ -35,8 +35,7 @@ void CJPEGDecode::decode(OSVideoSurface &surface) {
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
CTargaDecode::CTargaDecode(const CString &name) : _file(name),
|
||||
_width(0), _height(0) {
|
||||
CTargaDecode::CTargaDecode(const CString &name) : _width(0), _height(0) {
|
||||
}
|
||||
|
||||
void CTargaDecode::decode(OSVideoSurface &surface) {
|
||||
|
||||
@@ -25,6 +25,13 @@
|
||||
|
||||
namespace Titanic {
|
||||
|
||||
bool File::open(const Common::String &name) {
|
||||
if (!Common::File::open(name))
|
||||
error("Could not open file - %s", name.c_str());
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
SimpleFile::SimpleFile(): _inStream(nullptr), _outStream(nullptr), _lineCount(1) {
|
||||
}
|
||||
|
||||
@@ -333,11 +340,45 @@ void SimpleFile::writeClassEnd(int indent) {
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
StdCWadFile::StdCWadFile(const CString &name): SimpleFile() {
|
||||
if (!_file.open(name))
|
||||
error("Could not open file - %s", name.c_str());
|
||||
void StdCWadFile::open(const CString &name) {
|
||||
File f;
|
||||
|
||||
open(&_file);
|
||||
// Check for whether it is indeed a file/resource pair
|
||||
int idx = name.indexOf('#');
|
||||
|
||||
if (idx < 0) {
|
||||
// Nope, so open up file for standard reading
|
||||
assert(!name.empty());
|
||||
f.open(name);
|
||||
|
||||
SimpleFile::open(f.readStream(f.size()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Split up the name and resource, and get the resource index
|
||||
CString filename = name.left(idx) + ".st";
|
||||
int extPos = name.lastIndexOf('.');
|
||||
CString resStr = name.mid(idx + 1, extPos - idx - 1);
|
||||
int resIndex = resStr.readInt();
|
||||
|
||||
// Open up the index for access
|
||||
f.open(filename);
|
||||
int indexSize = f.readUint32LE() / 4;
|
||||
assert(resIndex < indexSize);
|
||||
|
||||
// Get the specific resource's offset, and size by also
|
||||
// getting the offset of the following resource
|
||||
f.seek(resIndex * 4);
|
||||
uint resOffset = f.readUint32LE();
|
||||
uint nextOffset = (resIndex == (indexSize - 1)) ? f.size() :
|
||||
f.readUint32LE();
|
||||
|
||||
// Read in the resource
|
||||
f.seek(resOffset);
|
||||
Common::SeekableReadStream *stream = f.readStream(nextOffset - resOffset);
|
||||
SimpleFile::open(stream);
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
||||
@@ -35,6 +35,15 @@ namespace Titanic {
|
||||
class Decompressor;
|
||||
class DecompressorData;
|
||||
|
||||
/**
|
||||
* Simple ScummVM File descendent that throws a wobbly if
|
||||
* the file it tries to open isn't present
|
||||
*/
|
||||
class File : public Common::File {
|
||||
public:
|
||||
virtual bool open(const Common::String &name);
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements basic reading and writing to files
|
||||
*/
|
||||
@@ -203,11 +212,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Derived file that handles WAD archives containing multiple files
|
||||
*/
|
||||
class StdCWadFile : public SimpleFile {
|
||||
private:
|
||||
Common::File _file;
|
||||
public:
|
||||
StdCWadFile(const CString &name);
|
||||
StdCWadFile() : SimpleFile() {}
|
||||
virtual ~StdCWadFile() {}
|
||||
|
||||
/**
|
||||
* Open up the specified file
|
||||
*/
|
||||
void open(const CString &name);
|
||||
};
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
||||
@@ -48,12 +48,12 @@ CString CString::mid(uint start) const {
|
||||
return mid(start, strSize - start);
|
||||
}
|
||||
|
||||
int CString::indexOf(char c) {
|
||||
int CString::indexOf(char c) const {
|
||||
const char *charP = strchr(c_str(), c);
|
||||
return charP ? charP - c_str() : -1;
|
||||
}
|
||||
|
||||
int CString::lastIndexOf(char c) {
|
||||
int CString::lastIndexOf(char c) const {
|
||||
const char *charP = strrchr(c_str(), c);
|
||||
return charP ? charP - c_str() : -1;
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public:
|
||||
/**
|
||||
* Returns the index of the first occurance of a given character
|
||||
*/
|
||||
int indexOf(char c);
|
||||
int indexOf(char c) const;
|
||||
|
||||
/**
|
||||
* Returns the index of the last occurance of a given character
|
||||
*/
|
||||
int lastIndexOf(char c);
|
||||
int lastIndexOf(char c) const;
|
||||
|
||||
/**
|
||||
* Returns the type of a filename based on it's extension
|
||||
@@ -85,6 +85,13 @@ public:
|
||||
* Returns the type of an image filename based on it's extension
|
||||
*/
|
||||
ImageType imageTypeSuffix() const;
|
||||
|
||||
/**
|
||||
* Parses the string as an integer and returns the value
|
||||
*/
|
||||
int readInt() const {
|
||||
return atoi(c_str());
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
||||
@@ -79,10 +79,8 @@ void OSVideoSurface::loadTarga(const CResourceKey &key) {
|
||||
}
|
||||
|
||||
void OSVideoSurface::loadJPEG(const CResourceKey &key) {
|
||||
CString filename = key.exists();
|
||||
|
||||
// Decode the image
|
||||
CJPEGDecode decoder(filename);
|
||||
CJPEGDecode decoder(key.getString());
|
||||
decoder.decode(*this);
|
||||
|
||||
if (proc26() == 2)
|
||||
|
||||
Reference in New Issue
Block a user