Skip to content

Commit

Permalink
Refactor|FileSys: Derive WadFile from de::File1
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 20, 2012
1 parent f101436 commit c673c83
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 2 additions & 0 deletions doomsday/engine/portable/include/file.h
Expand Up @@ -35,7 +35,9 @@ extern "C" {
typedef enum {
FT_FILE, ///< Generic file
FT_ZIP,
FT_ZIPFILE,
FT_WAD,
FT_WADFILE,
FT_LUMPFILEADAPTOR,
FILETYPE_COUNT
} filetype_t;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/filehandle.cpp
Expand Up @@ -125,12 +125,12 @@ FileHandle* FileHandleBuilder::fromFileLump(File1& container, int lumpIdx, bool
{
if(!container.isValidIndex(lumpIdx)) return 0;

FileInfo const& info = container.lumpInfo(lumpIdx);
de::FileHandle* file = new de::FileHandle();
// Init and load in the lump data.
file->d->flags.open = true;
if(!dontBuffer)
{
FileInfo const& info = container.lumpInfo(lumpIdx);
file->d->size = info.size;
file->d->pos = file->d->data = (uint8_t*) M_Malloc(file->d->size);
if(!file->d->data)
Expand Down
18 changes: 8 additions & 10 deletions doomsday/engine/portable/src/wad.cpp
Expand Up @@ -55,16 +55,13 @@ typedef struct {
} wadlumprecord_t;
#pragma pack()

class WadFile
class WadFile : public File1
{
public:
explicit WadFile(FileInfo const& _info) : crc_(0), info_(_info)
WadFile::WadFile(FileHandle& hndl, char const* path, FileInfo const& info)
: File1(FT_WADFILE, path, hndl, info), crc_(0)
{}

FileInfo const& info() const {
return info_;
}

uint crc() const { return crc_; }

/**
Expand All @@ -77,9 +74,9 @@ class WadFile
*/
WadFile& updateCRC()
{
crc_ = uint(info_.size);
crc_ = uint(info().size);

de::PathDirectoryNode const& node = info().container->lumpDirectoryNode(info_.lumpIdx);
de::PathDirectoryNode const& node = container().lumpDirectoryNode(info().lumpIdx);
ddstring_t const* name = node.pathFragment();
int const nameLen = Str_Length(name);
for(int k = 0; k < nameLen; ++k)
Expand All @@ -91,7 +88,6 @@ class WadFile

private:
uint crc_;
FileInfo info_;
};

struct Wad::Instance
Expand Down Expand Up @@ -258,7 +254,9 @@ struct Wad::Instance
F_PrependBasePath(&absPath, &absPath); // Make it absolute.

WadFile* lump =
new WadFile(FileInfo(self->lastModified(), // Inherited from the container (note recursion).
new WadFile(*FileHandleBuilder::fromFileLump(*self, i, true/*don't buffer*/),
Str_Text(&absPath),
FileInfo(self->lastModified(), // Inherited from the container (note recursion).
i,
littleEndianByteOrder.toNative(arcRecord->filePos),
littleEndianByteOrder.toNative(arcRecord->size),
Expand Down

0 comments on commit c673c83

Please sign in to comment.