Skip to content

Commit

Permalink
Refactor|AbstractFile: Dumped AbstractFile's now redundant C wrapper API
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 6, 2012
1 parent 42589c1 commit 52efc2a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 151 deletions.
41 changes: 4 additions & 37 deletions doomsday/engine/portable/include/abstractfile.h
Expand Up @@ -26,9 +26,6 @@
#ifndef LIBDENG_FILESYS_ABSTRACTFILE_H
#define LIBDENG_FILESYS_ABSTRACTFILE_H

#include "dfile.h"
#include "lumpinfo.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -50,6 +47,10 @@ typedef enum {
#endif

#ifdef __cplusplus

#include "dfile.h"
#include "lumpinfo.h"

namespace de {

class PathDirectoryNode;
Expand Down Expand Up @@ -281,43 +282,9 @@ class AbstractFile
extern "C" {
#endif // __cplusplus

/**
* C wrapper API:
*/

struct abstractfile_s; // The abstractfile instance (opaque)
typedef struct abstractfile_s AbstractFile;

filetype_t AbstractFile_Type(AbstractFile const* af);

LumpInfo const* AbstractFile_Info(AbstractFile const* af);

boolean AbstractFile_IsContained(AbstractFile const* af);

AbstractFile* AbstractFile_Container(AbstractFile const* af);

ddstring_t const* AbstractFile_Path(AbstractFile const* af);

uint AbstractFile_LoadOrderIndex(AbstractFile const* af);

uint AbstractFile_LastModified(AbstractFile const* af);

boolean AbstractFile_HasStartup(AbstractFile const* af);

void AbstractFile_SetStartup(AbstractFile* af, boolean yes);

boolean AbstractFile_HasCustom(AbstractFile const* af);

void AbstractFile_SetCustom(AbstractFile* af, boolean yes);

size_t AbstractFile_BaseOffset(AbstractFile const* af);

DFile* AbstractFile_Handle(AbstractFile* af);

size_t AbstractFile_ReadLump(AbstractFile* af, int lumpIdx, uint8_t* buffer);

int AbstractFile_LumpCount(AbstractFile* af);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/dfilebuilder.h
Expand Up @@ -79,15 +79,15 @@ extern "C" {
*/

/// @return File object represented by this handle.
AbstractFile* DFile_File(DFile* hndl);
struct abstractfile_s* DFile_File(DFile* hndl);

/// @return FileList object which owns this handle.
struct filelist_s* DFile_List(DFile* hndl);

DFile* DFile_SetList(DFile* hndl, struct filelist_s* list);

/// @return File object represented by this handle.
AbstractFile* DFile_File_const(DFile const* hndl);
struct abstractfile_s* DFile_File_const(DFile const* hndl);

#ifdef __cplusplus
} // extern "C"
Expand Down
8 changes: 6 additions & 2 deletions doomsday/engine/portable/include/fs_main.h
Expand Up @@ -385,11 +385,15 @@ void F_Close(struct dfile_s* file);

void F_Delete(struct dfile_s* file);

AutoStr* F_ComposeLumpPath2(struct abstractfile_s* file, int lumpIdx, char delimiter);
AutoStr* F_ComposeLumpPath(struct abstractfile_s* file, int lumpIdx); /*delimiter='/'*/
Str const* F_Path(struct abstractfile_s const* file);

void F_SetCustom(struct abstractfile_s* file, boolean yes);

LumpInfo const* F_LumpInfo(struct abstractfile_s* file, int lumpIdx);

AutoStr* F_ComposeLumpPath2(struct abstractfile_s* file, int lumpIdx, char delimiter);
AutoStr* F_ComposeLumpPath(struct abstractfile_s* file, int lumpIdx); /*delimiter='/'*/

size_t F_ReadLump(struct abstractfile_s* file, int lumpIdx, uint8_t* buffer);

size_t F_ReadLumpSection(struct abstractfile_s* file, int lumpIdx, uint8_t* buffer,
Expand Down
103 changes: 5 additions & 98 deletions doomsday/engine/portable/src/abstractfile.cpp
@@ -1,7 +1,7 @@
/**
* @file abstractfile.cpp
*
* Abstract base for all classes which represent opened files.
* Abstract base for all classes which represent loaded files.
*
* @ingroup fs
*
Expand All @@ -28,13 +28,16 @@

#include "abstractfile.h"

using de::DFile;
using namespace de;
using de::AbstractFile;
using de::DFile;

AbstractFile::AbstractFile(filetype_t _type, char const* _path, DFile& file, LumpInfo const& _info)
: file(&file), type_(_type)
{
// Used to favor newer files when duplicates are pruned.
/// @todo Does not belong at this level. Load order should be determined
/// at file system level. -ds
static uint fileCounter = 0;
DENG2_ASSERT(VALID_FILETYPE(_type));
order = fileCounter++;
Expand Down Expand Up @@ -121,99 +124,3 @@ AbstractFile& AbstractFile::setCustom(bool yes)
flags.custom = yes;
return *this;
}

/**
* C Wrapper API:
*/

#define TOINTERNAL(inst) \
(inst) != 0? reinterpret_cast<AbstractFile*>(inst) : NULL

#define TOINTERNAL_CONST(inst) \
(inst) != 0? reinterpret_cast<AbstractFile const*>(inst) : NULL

#define SELF(inst) \
DENG2_ASSERT(inst); \
AbstractFile* self = TOINTERNAL(inst)

#define SELF_CONST(inst) \
DENG2_ASSERT(inst); \
AbstractFile const* self = TOINTERNAL_CONST(inst)

filetype_t AbstractFile_Type(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->type();
}

LumpInfo const* AbstractFile_Info(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->info();
}

boolean AbstractFile_IsContained(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->isContained();
}

struct abstractfile_s* AbstractFile_Container(struct abstractfile_s const* af)
{
SELF_CONST(af);
return reinterpret_cast<struct abstractfile_s*>(&self->container());
}

size_t AbstractFile_BaseOffset(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->baseOffset();
}

struct dfile_s* AbstractFile_Handle(struct abstractfile_s* af)
{
SELF(af);
return reinterpret_cast<struct dfile_s*>(self->handle());
}

ddstring_t const* AbstractFile_Path(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->path();
}

uint AbstractFile_LoadOrderIndex(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->loadOrderIndex();
}

uint AbstractFile_LastModified(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->lastModified();
}

boolean AbstractFile_HasStartup(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->hasStartup();
}

void AbstractFile_SetStartup(struct abstractfile_s* af, boolean yes)
{
SELF(af);
self->setStartup(CPP_BOOL(yes));
}

boolean AbstractFile_HasCustom(struct abstractfile_s const* af)
{
SELF_CONST(af);
return self->hasCustom();
}

void AbstractFile_SetCustom(struct abstractfile_s* af, boolean yes)
{
SELF(af);
self->setCustom(CPP_BOOL(yes));
}
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -383,11 +383,11 @@ static void loadResource(AbstractResource* res)
ddstring_t const* path = AbstractResource_ResolvedPath(res, false/*do not locate resource*/);
if(path)
{
AbstractFile* file = F_AddFile(Str_Text(path));
struct abstractfile_s* file = F_AddFile(Str_Text(path));
if(file)
{
// Mark this as an original game resource.
AbstractFile_SetCustom(file, false);
F_SetCustom(file, false);

// Print the 'CRC' number of IWADs, so they can be identified.
/// @todo fixme
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/def_read.c
Expand Up @@ -2738,13 +2738,13 @@ int DED_Read(ded_t* ded, const char* path)
int DED_ReadLump(ded_t* ded, lumpnum_t absoluteLumpNum)
{
int lumpIdx;
AbstractFile* file = F_FindFileForLumpNum2(absoluteLumpNum, &lumpIdx);
struct abstractfile_s* file = F_FindFileForLumpNum2(absoluteLumpNum, &lumpIdx);
if(file)
{
if(F_LumpLength(absoluteLumpNum) != 0)
{
uint8_t const* lumpPtr = F_CacheLump(file, lumpIdx);
DED_ReadData(ded, (char const*)lumpPtr, Str_Text(AbstractFile_Path(file)));
DED_ReadData(ded, (char const*)lumpPtr, Str_Text(F_Path(file)));
F_UnlockLump(file, lumpIdx);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/finaleinterpreter.c
Expand Up @@ -2018,7 +2018,7 @@ DEFFC(TextFromLump)
{
int lumpIdx;
size_t lumpSize = F_LumpLength(absoluteLumpNum);
AbstractFile* fsObject = F_FindFileForLumpNum2(absoluteLumpNum, &lumpIdx);
struct abstractfile_s* fsObject = F_FindFileForLumpNum2(absoluteLumpNum, &lumpIdx);
const uint8_t* lumpPtr = F_CacheLump(fsObject, lumpIdx);
size_t bufSize = 2 * lumpSize + 1, i;
char* str, *out;
Expand Down
13 changes: 13 additions & 0 deletions doomsday/engine/portable/src/fs_main.cpp
Expand Up @@ -2504,6 +2504,19 @@ void F_Delete(struct dfile_s* hndl)
FS::deleteFile(reinterpret_cast<DFile*>(hndl));
}

Str const* F_Path(struct abstractfile_s const* file)
{
if(file) return reinterpret_cast<AbstractFile const*>(file)->path();
static de::Str zeroLengthString;
return zeroLengthString;
}

void F_SetCustom(struct abstractfile_s* file, boolean yes)
{
if(!file) return;
reinterpret_cast<AbstractFile*>(file)->setCustom(CPP_BOOL(yes));
}

LumpInfo const* F_LumpInfo(struct abstractfile_s* _file, int lumpIdx)
{
if(!_file) return 0;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -1501,7 +1501,7 @@ uint8_t* Image_LoadFromFile(image_t* img, DFile* file)

GL_InitImage(img);

fileName = Str_Text(AbstractFile_Path(DFile_File_const(file)));
fileName = Str_Text(F_Path(DFile_File_const(file)));

// Firstly try the expected format given the file name.
hdlr = findHandlerFromFileName(fileName);
Expand Down Expand Up @@ -2485,7 +2485,7 @@ static TexSource loadPatchLump(image_t* image, DFile* file, int tclass, int tmap

if(source == TEXS_NONE)
{
Con_Message("Warning: Lump \"%s\" does not appear to be a valid Patch.\n", F_PrettyPath(Str_Text(AbstractFile_Path(DFile_File(file)))));
Con_Message("Warning: Lump \"%s\" does not appear to be a valid Patch.\n", F_PrettyPath(Str_Text(F_Path(DFile_File(file)))));
return source;
}
}
Expand Down Expand Up @@ -2566,16 +2566,16 @@ TexSource GL_LoadPatchComposite(image_t* image, Texture* tex)
{
const texpatch_t* patchDef = &texDef->patches[i];
int lumpIdx;
AbstractFile* fsObject = F_FindFileForLumpNum2(patchDef->lumpNum, &lumpIdx);
const uint8_t* patch = F_CacheLump(fsObject, lumpIdx);
struct abstractfile_s* file = F_FindFileForLumpNum2(patchDef->lumpNum, &lumpIdx);
const uint8_t* patch = F_CacheLump(file, lumpIdx);

if(validPatch(patch, F_LumpInfo(fsObject, lumpIdx)->size))
if(validPatch(patch, F_LumpInfo(file, lumpIdx)->size))
{
// Draw the patch in the buffer.
loadDoomPatch(image->pixels, image->size.width, image->size.height,
(const doompatch_header_t*)patch, patchDef->offX, patchDef->offY, 0, 0, false);
}
F_UnlockLump(fsObject, lumpIdx);
F_UnlockLump(file, lumpIdx);
}

if(palettedIsMasked(image->pixels, image->size.width, image->size.height))
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/s_wav.c
Expand Up @@ -195,7 +195,7 @@ void* WAV_Load(const char* filename, int* bits, int* rate, int* samples)
// Read in the whole thing.
size = DFile_Length(file);

DEBUG_Message(("WAV_Load: Loading from %s (size %i, fpos %i)\n", Str_Text(AbstractFile_Path(DFile_File_const(file))),
DEBUG_Message(("WAV_Load: Loading from %s (size %i, fpos %i)\n", Str_Text(F_Path(DFile_File_const(file))),
(int)size, (int)DFile_Tell(file)));

data = (uint8_t*)malloc(size);
Expand Down

0 comments on commit 52efc2a

Please sign in to comment.