Skip to content

Commit

Permalink
Refactor|Resources|Client|Server: Use the FS1 C++ API directly
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 17, 2014
1 parent 5b2a13f commit 9933e83
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 374 deletions.
18 changes: 11 additions & 7 deletions doomsday/client/src/audio/audiodriver_music.cpp
Expand Up @@ -68,15 +68,19 @@ static int musicPlayLump(audiointerface_music_t *iMusic, lumpnum_t lumpNum, dd_b
}

// Buffer the data using the driver's facilities.
FileHandle *hndl = F_OpenLump(lumpNum);
size_t length = FileHandle_Length(hndl);

if(!hndl) return 0;
try
{
FileHandle *hndl = reinterpret_cast<FileHandle *>(&App_FileSystem().openLump(App_FileSystem().lump(lumpNum)));
size_t const length = FileHandle_Length(hndl);
FileHandle_Read(hndl, (uint8_t *) iMusic->SongBuffer(length), length);
F_Delete(hndl);

FileHandle_Read(hndl, (uint8_t *) iMusic->SongBuffer(length), length);
F_Delete(hndl);
return iMusic->Play(looped);
}
catch(de::LumpIndex::NotFoundError const &)
{} // Ignore error.

return iMusic->Play(looped);
return 0;
}

static int musicPlayFile(audiointerface_music_t *iMusic, char const *virtualOrNativePath, dd_bool looped)
Expand Down
15 changes: 10 additions & 5 deletions doomsday/client/src/audio/s_cache.cpp
Expand Up @@ -549,7 +549,7 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
* external resource (probably a custom sound).
* @todo should be a cvar.
*/
if(info->lumpNum < 0 || !F_LumpIsCustom(info->lumpNum))
if(info->lumpNum < 0 || !App_FileSystem().lump(info->lumpNum).container().hasCustom())
{
try
{
Expand Down Expand Up @@ -580,11 +580,11 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
return 0;
}

size_t lumpLength = F_LumpLength(info->lumpNum);
size_t lumpLength = App_FileSystem().lump(info->lumpNum).size();
if(lumpLength <= 8) return 0;

int lumpIdx;
struct file1_s *file = F_FindFileForLumpNum2(info->lumpNum, &lumpIdx);
struct file1_s *file = F_FindFileForLumpNum(info->lumpNum, &lumpIdx);

char hdr[12];
F_ReadLumpSection(file, lumpIdx, (uint8_t *)hdr, 0, 12);
Expand Down Expand Up @@ -619,11 +619,16 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
}

// Probably an old-fashioned DOOM sample.
size_t lumpLength = F_LumpLength(info->lumpNum);
size_t lumpLength = 0;
if(info->lumpNum >= 0)
{
lumpLength = App_FileSystem().lump(info->lumpNum).size();
}

if(lumpLength > 8)
{
int lumpIdx;
struct file1_s *file = F_FindFileForLumpNum2(info->lumpNum, &lumpIdx);
struct file1_s *file = F_FindFileForLumpNum(info->lumpNum, &lumpIdx);

uint8_t hdr[8];
F_ReadLumpSection(file, lumpIdx, hdr, 0, 8);
Expand Down
22 changes: 11 additions & 11 deletions doomsday/client/src/audio/s_mus.cpp
Expand Up @@ -210,7 +210,7 @@ dd_bool Mus_IsMUSLump(lumpnum_t lumpNum)
{
char buf[4];
int lumpIdx;
struct file1_s* file = F_FindFileForLumpNum2(lumpNum, &lumpIdx);
struct file1_s* file = F_FindFileForLumpNum(lumpNum, &lumpIdx);
if(!file) return false;

F_ReadLumpSection(file, lumpIdx, (uint8_t*)buf, 0, 4);
Expand Down Expand Up @@ -292,18 +292,18 @@ int Mus_GetCD(ded_music_t *def)
* @return 1, if music was started. 0, if attempted to start but failed.
* -1, if it was MUS data and @a canPlayMUS says we can't play it.
*/
int Mus_StartLump(lumpnum_t lump, dd_bool looped, dd_bool canPlayMUS)
int Mus_StartLump(lumpnum_t lumpNum, dd_bool looped, dd_bool canPlayMUS)
{
if(!AudioDriver_Music_Available() || lump < 0) return 0;
if(!AudioDriver_Music_Available() || lumpNum < 0) return 0;

if(Mus_IsMUSLump(lump))
if(Mus_IsMUSLump(lumpNum))
{
// Lump is in DOOM's MUS format. We must first convert it to MIDI.
AutoStr* srcFile = 0;
struct file1_s* file;
AutoStr *srcFile = 0;
struct file1_s *file;
size_t lumpLength;
int lumpIdx;
uint8_t* buf;
uint8_t *buf;

if(!canPlayMUS)
return -1;
Expand All @@ -315,9 +315,9 @@ int Mus_StartLump(lumpnum_t lump, dd_bool looped, dd_bool canPlayMUS)
// any player which relies on the it for format recognition works as
// expected.

lumpLength = F_LumpLength(lump);
buf = (uint8_t*) M_Malloc(lumpLength);
file = F_FindFileForLumpNum2(lump, &lumpIdx);
lumpLength = App_FileSystem().lump(lumpNum).size();
buf = (uint8_t *) M_Malloc(lumpLength);
file = F_FindFileForLumpNum(lumpNum, &lumpIdx);
F_ReadLumpSection(file, lumpIdx, buf, 0, lumpLength);
M_Mus2Midi((void*)buf, lumpLength, Str_Text(srcFile));
M_Free(buf);
Expand All @@ -326,7 +326,7 @@ int Mus_StartLump(lumpnum_t lump, dd_bool looped, dd_bool canPlayMUS)
}
else
{
return AudioDriver_Music_PlayLump(lump, looped);
return AudioDriver_Music_PlayLump(lumpNum, looped);
}
}

Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -2156,7 +2156,7 @@ static int DD_StartupWorker(void * /*context*/)
/*
* No more lumps/packages will be loaded in startup mode after this point.
*/
F_EndStartup();
App_FileSystem().endStartup();

// Load engine help resources.
DD_InitHelp();
Expand Down Expand Up @@ -2262,7 +2262,7 @@ static int DD_UpdateEngineStateWorker(void *context)
}

// Reset file IDs so previously seen files can be processed again.
F_ResetFileIds();
App_FileSystem().resetFileIds();
// Re-read definitions.
Def_Read();

Expand Down Expand Up @@ -2474,7 +2474,7 @@ int DD_GetInteger(int ddvalue)
#endif

case DD_NUMLUMPS:
return F_LumpCount();
return App_FileSystem().lumpCount();

case DD_MAP_MUSIC:
if(App_WorldSystem().hasMap())
Expand Down Expand Up @@ -2596,7 +2596,7 @@ void *DD_GetVariable(int ddvalue)

case DD_NUMLUMPS: {
static int count;
count = F_LumpCount();
count = App_FileSystem().lumpCount();
return &count; }

default: break;
Expand Down Expand Up @@ -3244,7 +3244,7 @@ static void consoleRegister()
#endif

DD_RegisterLoop();
F_Register();
FS1::consoleRegister();
Con_Register();
Games::consoleRegister();
DH_Register();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -335,7 +335,7 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw)

GLuint GL_PrepareRawTexture(rawtex_t &raw)
{
if(raw.lumpNum < 0 || raw.lumpNum >= F_LumpCount()) return 0;
if(raw.lumpNum < 0 || raw.lumpNum >= App_FileSystem().lumpCount()) return 0;

if(!raw.tex)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/m_misc.cpp
Expand Up @@ -398,7 +398,7 @@ DENG_EXTERN_C int M_ScreenShot(char const *name, int bits)
DENG2_UNUSED(bits);

de::String fullName(name);
if(de::String(name).fileNameExtension().isEmpty())
if(fullName.fileNameExtension().isEmpty())
{
fullName += ".png"; // Default format.
}
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -2587,9 +2587,10 @@ patchid_t ResourceSystem::declarePatch(String encodedName)
rawtex_t *ResourceSystem::rawTexture(lumpnum_t lumpNum)
{
LOG_AS("ResourceSystem::rawTexture");
if(-1 == lumpNum || lumpNum >= F_LumpCount())
if(-1 == lumpNum || lumpNum >= App_FileSystem().lumpCount())
{
LOGDEV_RES_WARNING("LumpNum #%i out of bounds (%i), returning 0") << lumpNum << F_LumpCount();
LOGDEV_RES_WARNING("LumpNum #%i out of bounds (%i), returning 0")
<< lumpNum << App_FileSystem().lumpCount();
return 0;
}

Expand All @@ -2604,10 +2605,10 @@ rawtex_t *ResourceSystem::rawTexture(lumpnum_t lumpNum)
rawtex_t *ResourceSystem::declareRawTexture(lumpnum_t lumpNum)
{
LOG_AS("ResourceSystem::rawTexture");
if(-1 == lumpNum || lumpNum >= F_LumpCount())
if(-1 == lumpNum || lumpNum >= App_FileSystem().lumpCount())
{
LOGDEV_RES_WARNING("LumpNum #%i out of range %s, returning 0")
<< lumpNum << Rangeui(0, F_LumpCount()).asText();
<< lumpNum << Rangeui(0, App_FileSystem().lumpCount()).asText();
return 0;
}

Expand Down
14 changes: 7 additions & 7 deletions doomsday/client/src/ui/finaleinterpreter.cpp
Expand Up @@ -2102,15 +2102,15 @@ DEFFC(TextFromLump)
if(lumpNum >= 0)
{
int lumpIdx;
size_t lumpSize = F_LumpLength(lumpNum);
struct file1_s* file = F_FindFileForLumpNum2(lumpNum, &lumpIdx);
const uint8_t* lumpPtr = F_CacheLump(file, lumpIdx);
size_t bufSize = 2 * lumpSize + 1, i;
char* str, *out;
size_t lumpSize = App_FileSystem().lump(lumpNum).size();
struct file1_s *file = F_FindFileForLumpNum(lumpNum, &lumpIdx);
uint8_t const *lumpPtr = F_CacheLump(file, lumpIdx);

str = (char*) M_Calloc(bufSize);
size_t bufSize = 2 * lumpSize + 1;
char *str = (char *) M_Calloc(bufSize);

for(i = 0, out = str; i < lumpSize; ++i)
char *out = str;
for(size_t i = 0; i < lumpSize; ++i)
{
char ch = (char)(lumpPtr[i]);
if(ch == '\r') continue;
Expand Down
53 changes: 3 additions & 50 deletions doomsday/libdoomsday/include/doomsday/filesys/fs_main.h
Expand Up @@ -422,6 +422,8 @@ class LIBDOOMSDAY_PUBLIC FS1
*/
inline File1 &lump(lumpnum_t lumpnum) const { return nameIndex()[lumpnum]; }

inline int lumpCount() const { return nameIndex().size(); }

/**
* Opens the given file (will be translated) for reading.
*
Expand Down Expand Up @@ -593,66 +595,24 @@ extern "C" {
struct filelist_s;
typedef struct filelist_s FileList;

LIBDOOMSDAY_PUBLIC void F_Register(void);

/// Initialize this module. Cannot be re-initialized, must shutdown first.
LIBDOOMSDAY_PUBLIC void F_Init(void);

/// Shutdown this module.
LIBDOOMSDAY_PUBLIC void F_Shutdown(void);

LIBDOOMSDAY_PUBLIC void F_EndStartup(void);

LIBDOOMSDAY_PUBLIC int F_UnloadAllNonStartupFiles();

LIBDOOMSDAY_PUBLIC void F_AddVirtualDirectoryMapping(char const *nativeSourcePath, char const *nativeDestinationPath);

LIBDOOMSDAY_PUBLIC void F_AddLumpDirectoryMapping(char const *lumpName, char const *nativeDestinationPath);

LIBDOOMSDAY_PUBLIC void F_ResetFileIds(void);

LIBDOOMSDAY_PUBLIC dd_bool F_CheckFileId(char const *nativePath);

LIBDOOMSDAY_PUBLIC int F_LumpCount(void);

LIBDOOMSDAY_PUBLIC int F_Access(char const *nativePath);

LIBDOOMSDAY_PUBLIC void F_Index(struct file1_s *file);

LIBDOOMSDAY_PUBLIC void F_Deindex(struct file1_s *file);

LIBDOOMSDAY_PUBLIC FileHandle *F_Open3(char const *nativePath, char const *mode, size_t baseOffset, dd_bool allowDuplicate);
LIBDOOMSDAY_PUBLIC FileHandle *F_Open2(char const *nativePath, char const *mode, size_t baseOffset/*, allowDuplicate = true */);
LIBDOOMSDAY_PUBLIC FileHandle *F_Open(char const *nativePath, char const *mode/*, baseOffset = 0 */);

LIBDOOMSDAY_PUBLIC FileHandle *F_OpenLump(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC dd_bool F_IsValidLumpNum(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC lumpnum_t F_LumpNumForName(char const *name);

LIBDOOMSDAY_PUBLIC AutoStr *F_ComposeLumpFilePath(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC dd_bool F_LumpIsCustom(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC AutoStr *F_LumpName(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC size_t F_LumpLength(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC uint F_LumpLastModified(lumpnum_t lumpNum);

LIBDOOMSDAY_PUBLIC struct file1_s *F_FindFileForLumpNum2(lumpnum_t lumpNum, int *lumpIdx);
LIBDOOMSDAY_PUBLIC struct file1_s *F_FindFileForLumpNum(lumpnum_t lumpNum/*, lumpIdx = 0 */);
LIBDOOMSDAY_PUBLIC struct file1_s *F_FindFileForLumpNum(lumpnum_t lumpNum, int *lumpIdx);

LIBDOOMSDAY_PUBLIC void F_Delete(struct filehandle_s *file);

LIBDOOMSDAY_PUBLIC AutoStr *F_ComposePath(struct file1_s const *file);

LIBDOOMSDAY_PUBLIC void F_SetCustom(struct file1_s *file, dd_bool yes);

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

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

LIBDOOMSDAY_PUBLIC size_t F_ReadLumpSection(struct file1_s *file, int lumpIdx, uint8_t *buffer,
Expand All @@ -662,13 +622,6 @@ LIBDOOMSDAY_PUBLIC uint8_t const *F_CacheLump(struct file1_s *file, int lumpIdx)

LIBDOOMSDAY_PUBLIC void F_UnlockLump(struct file1_s *file, int lumpIdx);

/**
* Compiles a list of file names, separated by @a delimiter.
*/
LIBDOOMSDAY_PUBLIC void F_ComposePWADFileList(char *outBuf, size_t outBufSize, char const *delimiter);

LIBDOOMSDAY_PUBLIC uint F_LoadedFilesCRC(void);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libdoomsday/include/doomsday/filesys/fs_util.h
Expand Up @@ -40,6 +40,8 @@ extern "C" {

LIBDOOMSDAY_PUBLIC int F_FileExists(char const *path);

LIBDOOMSDAY_PUBLIC dd_bool F_MakePath(char const *path);

/**
* Converts directory slashes to our internal '/'.
* @return @c true iff the path was modified.
Expand Down Expand Up @@ -80,6 +82,8 @@ LIBDOOMSDAY_PUBLIC dd_bool F_IsAbsolute(ddstring_t const *path);
*/
LIBDOOMSDAY_PUBLIC dd_bool F_ExpandBasePath(ddstring_t *dst, ddstring_t const *src);

LIBDOOMSDAY_PUBLIC char const *F_PrettyPath(char const *path);

/**
* Write the data associated with the specified lump index to @a outputPath.
*
Expand All @@ -103,10 +107,6 @@ LIBDOOMSDAY_PUBLIC dd_bool F_DumpFile(de::File1 &file, char const *outputPath);
*/
LIBDOOMSDAY_PUBLIC dd_bool F_Dump(void const *data, size_t size, char const *path);

LIBDOOMSDAY_PUBLIC char const *F_PrettyPath(char const *path);

LIBDOOMSDAY_PUBLIC dd_bool F_MakePath(char const *path);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
12 changes: 6 additions & 6 deletions doomsday/libdoomsday/src/defs/dedfile.cpp
Expand Up @@ -60,16 +60,16 @@ void Def_ReadProcessDED(ded_t *defs, char const* path)
}
}

int DED_ReadLump(ded_t* ded, lumpnum_t lumpNum)
int DED_ReadLump(ded_t *ded, lumpnum_t lumpNum)
{
int lumpIdx;
struct file1_s* file = F_FindFileForLumpNum2(lumpNum, &lumpIdx);
if(file)
if(struct file1_s *file = F_FindFileForLumpNum(lumpNum, &lumpIdx))
{
if(F_LumpLength(lumpNum) != 0)
if(App_FileSystem().lump(lumpNum).size() != 0)
{
uint8_t const* lumpPtr = F_CacheLump(file, lumpIdx);
DED_ReadData(ded, (char const*)lumpPtr, Str_Text(F_ComposePath(file)));
uint8_t const *lumpPtr = F_CacheLump(file, lumpIdx);
String sourcePath = reinterpret_cast<de::File1 *>(file)->composePath();
DED_ReadData(ded, (char const *)lumpPtr, sourcePath.toUtf8().constData());
F_UnlockLump(file, lumpIdx);
}
return true;
Expand Down

0 comments on commit 9933e83

Please sign in to comment.