Skip to content

Commit

Permalink
Refactor|libdoomsday|FS1: Removed F_ReadLumpSection(), F_CacheLump(),…
Browse files Browse the repository at this point in the history
… F_UnlockLump()
  • Loading branch information
danij-deng committed Jun 18, 2014
1 parent fd9f649 commit 0ddc270
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 75 deletions.
14 changes: 6 additions & 8 deletions doomsday/client/src/audio/s_cache.cpp
Expand Up @@ -584,17 +584,15 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
if(lump.size() <= 8) return 0;

char hdr[12];
F_ReadLumpSection(&lump.container(), lump.info().lumpIdx,
(uint8_t *)hdr, 0, 12);
lump.read((uint8_t *)hdr, 0, 12);

// Is this perhaps a WAV sound?
if(WAV_CheckFormat(hdr))
{
// Load as WAV, then.
uint8_t const *sp = F_CacheLump(&lump.container(), lump.info().lumpIdx);

uint8_t const *sp = lump.cache();
data = WAV_MemoryLoad((byte const *) sp, lump.size(), &bytesPer, &rate, &numSamples);
F_UnlockLump(&lump.container(), lump.info().lumpIdx);
lump.unlock();

if(!data)
{
Expand Down Expand Up @@ -625,7 +623,7 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
if(lump.size() > 8)
{
uint8_t hdr[8];
F_ReadLumpSection(&lump.container(), lump.info().lumpIdx, hdr, 0, 8);
lump.read(hdr, 0, 8);
int head = SHORT(*(short const *) (hdr));
rate = SHORT(*(short const *) (hdr + 2));
numSamples = de::max(0, LONG(*(int const *) (hdr + 4)));
Expand All @@ -635,13 +633,13 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
if(head == 3 && numSamples > 0 && (unsigned) numSamples <= lumpLength - 8)
{
// The sample data can be used as-is - load directly from the lump cache.
uint8_t const *data = F_CacheLump(&lump.container(), lump.info().lumpIdx) + 8; // Skip the header.
uint8_t const *data = lump.cache() + 8; // Skip the header.

// Insert a copy of this into the cache.
SfxCache *node = Sfx_CacheInsert(id, data, bytesPer * numSamples, numSamples,
bytesPer, rate, info->group);

F_UnlockLump(&lump.container(), lump.info().lumpIdx);
lump.unlock();

return &node->sample;
}
Expand Down
6 changes: 2 additions & 4 deletions doomsday/client/src/audio/s_mus.cpp
Expand Up @@ -210,10 +210,8 @@ dd_bool Mus_IsMUSLump(lumpnum_t lumpNum)
{
try
{
File1 const &lump = App_FileSystem().lump(lumpNum);

char buf[4];
F_ReadLumpSection(&lump.container(), lump.info().lumpIdx, (uint8_t *)buf, 0, 4);
App_FileSystem().lump(lumpNum).read((uint8_t *)buf, 0, 4);

// ASCII "MUS" and CTRL-Z (hex 4d 55 53 1a)
return !strncmp(buf, "MUS\x01a", 4);
Expand Down Expand Up @@ -316,7 +314,7 @@ int Mus_StartLump(lumpnum_t lumpNum, dd_bool looped, dd_bool canPlayMUS)
File1 &lump = App_FileSystem().lump(lumpNum);
uint8_t *buf = (uint8_t *) M_Malloc(lump.size());

F_ReadLumpSection(&lump.container(), lump.info().lumpIdx, buf, 0, lump.size());
lump.read(buf, 0, lump.size());
M_Mus2Midi((void *)buf, lump.size(), Str_Text(srcFile));

M_Free(buf);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/finaleinterpreter.cpp
Expand Up @@ -2102,7 +2102,7 @@ DEFFC(TextFromLump)
if(lumpNum >= 0)
{
de::File1 &lump = App_FileSystem().lump(lumpNum);
uint8_t const *data = F_CacheLump(&lump.container(), lump.info().lumpIdx);
uint8_t const *data = lump.cache();

size_t bufSize = 2 * lump.size() + 1;
char *str = (char *) M_Calloc(bufSize);
Expand All @@ -2122,7 +2122,7 @@ DEFFC(TextFromLump)
*out++ = ch;
}
}
F_UnlockLump(&lump.container(), lump.info().lumpIdx);
lump.unlock();

FIData_TextCopy(obj, str);
free(str);
Expand Down
8 changes: 0 additions & 8 deletions doomsday/libdoomsday/include/doomsday/filesys/fs_main.h
Expand Up @@ -587,13 +587,5 @@ LIBDOOMSDAY_PUBLIC void F_Init();
/// Shutdown this module.
LIBDOOMSDAY_PUBLIC void F_Shutdown();

LIBDOOMSDAY_PUBLIC void F_Delete(de::FileHandle *hndl);

LIBDOOMSDAY_PUBLIC size_t F_ReadLumpSection(de::File1 *file, int lumpIdx, uint8_t *buffer, size_t startOffset, size_t length);

LIBDOOMSDAY_PUBLIC uint8_t const *F_CacheLump(de::File1 *file, int lumpIdx);

LIBDOOMSDAY_PUBLIC void F_UnlockLump(de::File1 *file, int lumpIdx);

#endif // __cplusplus
#endif /* LIBDENG_FILESYS_MAIN_H */
6 changes: 3 additions & 3 deletions doomsday/libdoomsday/src/defs/dedfile.cpp
Expand Up @@ -64,13 +64,13 @@ int DED_ReadLump(ded_t *ded, lumpnum_t lumpNum)
{
try
{
File1 const &lump = App_FileSystem().lump(lumpNum);
File1 &lump = App_FileSystem().lump(lumpNum);
if(lump.size() > 0)
{
uint8_t const *data = F_CacheLump(&lump.container(), lump.info().lumpIdx);
uint8_t const *data = lump.cache();
String sourcePath = lump.container().composePath();
DED_ReadData(ded, (char const *)data, sourcePath.toUtf8().constData());
F_UnlockLump(&lump.container(), lump.info().lumpIdx);
lump.unlock();
}
return true;
}
Expand Down
51 changes: 1 addition & 50 deletions doomsday/libdoomsday/src/filesys/fs_main.cpp
Expand Up @@ -1274,8 +1274,7 @@ FS1 &App_FileSystem()

String App_BasePath()
{
/// @todo Shouldn't this end in '/'? It causes failure to locate doomsday.pk3...
return App::app().nativeBasePath().withSeparators('/'); // + '/';
return App::app().nativeBasePath().withSeparators('/');
}

void F_Init()
Expand All @@ -1289,51 +1288,3 @@ void F_Shutdown()
if(!fileSystem) return;
delete fileSystem; fileSystem = 0;
}

size_t F_ReadLumpSection(File1 *file, int lumpIdx, uint8_t *buffer,
size_t startOffset, size_t length)
{
if(!file) return 0;

if(de::Wad *wad = file->maybeAs<de::Wad>())
{
return wad->lump(lumpIdx).read(buffer, startOffset, length);
}
if(de::Zip *zip = file->maybeAs<de::Zip>())
{
return zip->lump(lumpIdx).read(buffer, startOffset, length);
}
return file->read(buffer, startOffset, length);
}

uint8_t const *F_CacheLump(File1 *file, int lumpIdx)
{
if(!file) return 0;

if(de::Wad *wad = file->maybeAs<de::Wad>())
{
return wad->lump(lumpIdx).cache();
}
if(de::Zip *zip = file->maybeAs<de::Zip>())
{
return zip->lump(lumpIdx).cache();
}
return file->cache();
}

void F_UnlockLump(File1 *file, int lumpIdx)
{
if(!file) return;

if(de::Wad *wad = file->maybeAs<de::Wad>())
{
wad->unlockLump(lumpIdx);
return;
}
if(de::Zip *zip = file->maybeAs<de::Zip>())
{
zip->unlockLump(lumpIdx);
return;
}
file->unlock();
}

0 comments on commit 0ddc270

Please sign in to comment.