Skip to content

Commit

Permalink
File system refactoring continues:
Browse files Browse the repository at this point in the history
* Moved baseOffset out of LumpInfo and up into AbstractFile
* Record an AbstractFile pointer to the container from which the
  lump was loaded plus it's relative index in LumpInfo.

Rotating the references like this results in a cleaner and more
logical hierarchy, while also reducing the need to copy LumpInfos
around during the file load/access processes.
  • Loading branch information
danij-deng committed Sep 19, 2011
1 parent 63d3e34 commit 6490f30
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 208 deletions.
22 changes: 20 additions & 2 deletions doomsday/engine/portable/include/abstractfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,38 @@ typedef struct abstractfile_s {
/// File stream abstraction wrapper/handle.
streamfile_t _stream;

/// Offset from start of owning package.
size_t _baseOffset;

/// Info descriptor (file metadata).
lumpinfo_t _info;

/// Load order depth index.
uint _order;
} abstractfile_t;

/// Initialize this resource.
void AbstractFile_Init(abstractfile_t* file, filetype_t type, const lumpinfo_t* info);
/**
* Initialize this resource.
*
* @param type File type identifier.
* @param baseOffset Offset from the start of the file in bytes to begin.
* @param info Lump info descriptor for the file. A copy is made.
* @param sf Stream file handle/wrapper to the file being interpreted.
* A copy is made unless @c NULL in which case a default-stream is initialized.
* @return Same as @a file for convenience (chaining).
*/
abstractfile_t* AbstractFile_Init(abstractfile_t* file, filetype_t type, size_t baseOffset,
const lumpinfo_t* info, streamfile_t* sf);

/// @return Type of this resource @see filetype_t
filetype_t AbstractFile_Type(const abstractfile_t* file);

/// @return Immutable copy of the info descriptor for this resource.
const lumpinfo_t* AbstractFile_Info(abstractfile_t* file);

/// @return Owning package else @c NULL if not contained.
abstractfile_t* AbstractFile_Container(const abstractfile_t* file);

/**
* Accessors:
*/
Expand All @@ -101,6 +117,8 @@ boolean AbstractFile_HasIWAD(const abstractfile_t* file);
/// Mark this resource as "IWAD".
void AbstractFile_SetIWAD(abstractfile_t* file, boolean yes);

size_t AbstractFile_BaseOffset(const abstractfile_t* file);

/**
* Abstract interface (minimal, data caching interface not expected):
*/
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/lumpfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef struct lumpfile_s {
void** _cacheData;
} lumpfile_t;

lumpfile_t* LumpFile_New(const lumpinfo_t* info);
lumpfile_t* LumpFile_New(size_t baseOffset, const lumpinfo_t* info, streamfile_t* sf);
void LumpFile_Delete(lumpfile_t* lump);

/// Close this file if open and release any acquired file identifiers.
Expand Down
11 changes: 7 additions & 4 deletions doomsday/engine/portable/include/lumpinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@

#include "dd_string.h"

struct abstractfile_s;

/**
* LumpInfo record. POD.
* @ingroup fs
*/
typedef struct {
lumpname_t name; /// Ends in '\0'. Used with WAD lumps.
ddstring_t path; /// Absolute variable-length path in the vfs.
size_t baseOffset; /// Offset from start of owning package.
uint lastModified; /// Unix timestamp.
int lumpIdx; /// Relative index of this lump in the owning package else zero.
size_t size; /// Size of the uncompressed file.
size_t compressedSize; /// Size of the original file compressed.
uint lastModified; /// Unix timestamp.
struct abstractfile_s* container; /// Owning package else @c NULL.
lumpname_t name; /// Ends in '\0'. Used with WAD lumps.
ddstring_t path; /// Absolute variable-length path in the vfs.
} lumpinfo_t;

void F_InitLumpInfo(lumpinfo_t* info);
Expand Down
15 changes: 9 additions & 6 deletions doomsday/engine/portable/include/wadfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
#ifndef LIBDENG_FILESYS_WADFILE_H
#define LIBDENG_FILESYS_WADFILE_H

#include <stdio.h>

#include "lumpinfo.h"
#include "abstractfile.h"

struct lumpdirectory_s;

typedef struct {
size_t baseOffset;
lumpinfo_t info;
} wadfile_lumprecord_t;

/**
* WadFile. Runtime representation of a WAD file.
*
Expand All @@ -42,11 +45,11 @@ typedef struct wadfile_s {
abstractfile_t _base;
int _lumpCount;
size_t _lumpRecordsOffset;
lumpinfo_t* _lumpInfo;
wadfile_lumprecord_t* _lumpRecords;
void** _lumpCache;
} wadfile_t;

wadfile_t* WadFile_New(const lumpinfo_t* info, streamfile_t* sf);
wadfile_t* WadFile_New(size_t baseOffset, const lumpinfo_t* info, streamfile_t* sf);
void WadFile_Delete(wadfile_t* wad);

/// Close this file if open and release any acquired file identifiers.
Expand Down Expand Up @@ -120,10 +123,10 @@ int WadFile_LumpCount(wadfile_t* wad);

/**
* Does the specified file appear to be in WAD format.
* @param sf Stream file handle/wrapper to the file being interpreted.
* @param baseOffset Offset from the start of the file in bytes to begin.
* @param sf Stream file handle/wrapper to the file being interpreted.
* @return @c true iff this is a file that can be represented using WadFile.
*/
boolean WadFile_Recognise(streamfile_t* sf, size_t baseOffset);
boolean WadFile_Recognise(size_t baseOffset, streamfile_t* sf);

#endif /* LIBDENG_FILESYS_WADFILE_H */
15 changes: 9 additions & 6 deletions doomsday/engine/portable/include/zipfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
#ifndef LIBDENG_FILESYS_ZIPFILE_H
#define LIBDENG_FILESYS_ZIPFILE_H

#include <stdio.h>

#include "lumpinfo.h"
#include "abstractfile.h"

struct lumpdirectory_s;

typedef struct {
size_t baseOffset;
lumpinfo_t info;
} zipfile_lumprecord_t;

/**
* ZipFile. Runtime representation of Zip files.
*
Expand All @@ -43,11 +46,11 @@ typedef struct {
// Base file.
abstractfile_t _base;
int _lumpCount;
lumpinfo_t* _lumpInfo;
zipfile_lumprecord_t* _lumpRecords;
void** _lumpCache;
} zipfile_t;

zipfile_t* ZipFile_New(const lumpinfo_t* info, streamfile_t* sf);
zipfile_t* ZipFile_New(size_t baseOffset, const lumpinfo_t* info, streamfile_t* sf);
void ZipFile_Delete(zipfile_t* zip);

/// Close this file if open and release any acquired file identifiers.
Expand Down Expand Up @@ -115,10 +118,10 @@ int ZipFile_LumpCount(zipfile_t* zip);

/**
* Does the specified file appear to be in Zip format.
* @param sf Stream file handle/wrapper to the file being interpreted.
* @param baseOffset Offset from the start of the file in bytes to begin.
* @param sf Stream file handle/wrapper to the file being interpreted.
* @return @c true iff this is a file that can be represented using ZipFile.
*/
boolean ZipFile_Recognise(streamfile_t* sf, size_t baseOffset);
boolean ZipFile_Recognise(size_t baseOffset, streamfile_t* sf);

#endif
37 changes: 30 additions & 7 deletions doomsday/engine/portable/src/abstractfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,36 @@

#include "abstractfile.h"

void AbstractFile_Init(abstractfile_t* file, filetype_t type, const lumpinfo_t* info)
abstractfile_t* AbstractFile_Init(abstractfile_t* file, filetype_t type,
size_t baseOffset, const lumpinfo_t* info, streamfile_t* sf)
{
// Used to favor newer files when duplicates are pruned.
static uint fileCounter = 0;
assert(NULL != file && NULL != info);
assert(NULL != file && VALID_FILETYPE(type) && NULL != info);

file->_order = fileCounter++;
file->_type = type;
file->_flags.open = false;
file->_flags.startup = false;
file->_flags.iwad = false;
file->_baseOffset = baseOffset;

F_CopyLumpInfo(&file->_info, info);

file->_stream.eof = false;
file->_stream.size = 0;
file->_stream.hndl = NULL;
file->_stream.data = NULL;
file->_stream.pos = 0;
if(sf)
{
// Copy the stream handle.
memcpy(&file->_stream, sf, sizeof(file->_stream));
}
else
{
file->_stream.eof = false;
file->_stream.size = 0;
file->_stream.hndl = NULL;
file->_stream.data = NULL;
file->_stream.pos = 0;
}
return file;
}

filetype_t AbstractFile_Type(const abstractfile_t* file)
Expand All @@ -60,6 +71,18 @@ const lumpinfo_t* AbstractFile_Info(abstractfile_t* file)
return &file->_info;
}

abstractfile_t* AbstractFile_Container(const abstractfile_t* file)
{
assert(NULL != file);
return file->_info.container;
}

size_t AbstractFile_BaseOffset(const abstractfile_t* file)
{
assert(NULL != file);
return file->_baseOffset;
}

const ddstring_t* AbstractFile_Path(const abstractfile_t* file)
{
assert(NULL != file);
Expand Down
Loading

0 comments on commit 6490f30

Please sign in to comment.