Skip to content

Commit

Permalink
Refactor|FS1: Removed more obsolete FS1 C wrapper API functions
Browse files Browse the repository at this point in the history
- F_FindPath(2)()
- F_FindPathInList()

Plus some minor cleanup.
  • Loading branch information
danij-deng committed Feb 24, 2013
1 parent 9598da0 commit 35266a8
Show file tree
Hide file tree
Showing 14 changed files with 497 additions and 549 deletions.
54 changes: 13 additions & 41 deletions doomsday/client/include/filesys/fs_main.h
Expand Up @@ -49,6 +49,19 @@
* @defgroup fs File System
*/

/**
* @defgroup resourceLocationFlags Resource Location Flags
*
* Flags used with @ref FS1::find().
* @ingroup flags
*/
///@{
#define RLF_MATCH_EXTENSION 0x1 /// If an extension is specified in the search term the found file should have it too.

/// Default flags.
#define RLF_DEFAULT 0
///@}

namespace de {

namespace internal {
Expand Down Expand Up @@ -647,47 +660,6 @@ void F_ComposePWADFileList(char *outBuf, size_t outBufSize, char const *delimite

uint F_LoadedFilesCRC(void);

/**
* @defgroup resourceLocationFlags Resource Location Flags
*
* Flags used with the F_Find family of functions which dictate the
* logic used during resource location.
* @ingroup flags
*/
///@{
#define RLF_MATCH_EXTENSION 0x1 /// If an extension is specified in the search term the found file should have it too.

/// Default flags.
#define RLF_DEFAULT 0
///@}

/**
* Attempt to locate a named resource.
*
* @param classId Class of resource being searched for (if known).
*
* @param searchPath Path/name of the resource being searched for. Note that
* the resource class (@a classId) specified significantly
* alters search behavior. This allows text replacements of
* symbolic escape sequences in the path, allowing access to
* the engine's view of the virtual file system.
*
* @param foundPath If found, the fully qualified path is written back here.
*
* @param flags @ref resourceLocationFlags
*
* @return @c true iff a resource was found.
*/
boolean F_FindPath2(resourceclassid_t classId, struct uri_s const *searchPath, ddstring_t *foundPath, int flags);
boolean F_FindPath(resourceclassid_t classId, struct uri_s const *searchPath, ddstring_t *foundPath/*, flags = RLF_DEFAULT*/);

/**
* @return If a resource is found, the index + 1 of the path from @a searchPaths
* that was used to find it; otherwise @c 0.
*/
uint F_FindPathInList(resourceclassid_t classId, char const *searchPaths,
ddstring_t *foundPath, int flags);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
51 changes: 21 additions & 30 deletions doomsday/client/include/filesys/manifest.h
@@ -1,10 +1,7 @@
/**
* @file manifest.h
*
* Manifest. @ingroup fs
/** @file manifest.h Logical Resource Manifest
*
* @author Copyright &copy; 2010-2013 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2010-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2010-2013 Daniel Swanson <danij@dengine.net>
* @author Copyright © 2010-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -21,34 +18,31 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_MANIFEST_H
#define LIBDENG_MANIFEST_H

#ifdef __cplusplus

#include <QStringList>
#ifndef LIBDENG_RESOURCE_MANIFEST_H
#define LIBDENG_RESOURCE_MANIFEST_H

#include <de/String>
#include <QStringList>
#include "api_uri.h"

namespace de {

/**
* Stores high-level metadata for and arbitrates/facilitates
* access to the associated "physical" resource.
* Stores high-level metadata for and arbitrates/facilitates access to the
* associated "physical" game data resource.
*
* @ingroup core
*/
class Manifest
class ResourceManifest
{
public:
/**
* @param rClass Class for the associated resource.
* @param fFlags @ref fileFlags
* @param name An expected name for the associated file.
*/
Manifest(resourceclassid_t rClass, int fFlags, String* name = 0);
~Manifest();
ResourceManifest(resourceclassid_t rClass, int fFlags, String *name = 0);
~ResourceManifest();

/// @return Class of the associated resource.
resourceclassid_t resourceClass() const;
Expand All @@ -57,21 +51,21 @@ class Manifest
int fileFlags() const;

/// @return List of "identity keys" used to identify the file.
QStringList const& identityKeys() const;
QStringList const &identityKeys() const;

/// @return List of names for the associated file.
QStringList const& names() const;
QStringList const &names() const;

/**
* Attempt to locate this file by systematically resolving and then
* checking each search path.
*/
Manifest& locateFile();
ResourceManifest &locateFile();

/**
* "Forget" the currently located file if one has been found.
*/
Manifest& forgetFile();
ResourceManifest &forgetFile();

/**
* Attempt to resolve a path to (and maybe locate) this file.
Expand All @@ -82,23 +76,23 @@ class Manifest
*
* @see locateFile()
*/
String const& resolvedPath(bool tryLocate = true);
String const &resolvedPath(bool tryLocate = true);

/**
* Add a new file segment identity key to the list for this manifest.
*
* @param newIdentityKey New identity key (e.g., a lump/file name).
* @param didAdd If not @c =0, the outcome will be written here.
*/
Manifest& addIdentityKey(String newIdentityKey, bool* didAdd = 0);
ResourceManifest &addIdentityKey(String newIdentityKey, bool *didAdd = 0);

/**
* Add a new file name to the list of names for this manifest.
*
* @param newName New name for this file. Newer names have precedence.
* @param didAdd If not @c =0, the outcome will be written here.
*/
Manifest& addName(String newName, bool* didAdd = 0);
ResourceManifest &addName(String newName, bool *didAdd = 0);

/**
* Print information about a file to the console.
Expand All @@ -107,15 +101,12 @@ class Manifest
* @param showStatus @c true = print loaded/located status for the
* associated file.
*/
static void consolePrint(Manifest& manifest, bool showStatus = true);
static void consolePrint(ResourceManifest &manifest, bool showStatus = true);

private:
struct Instance;
Instance* d;
DENG2_PRIVATE(d)
};

} // namespace de

#endif // __cplusplus

#endif /* LIBDENG_MANIFEST_H */
#endif /* LIBDENG_RESOURCE_MANIFEST_H */
6 changes: 3 additions & 3 deletions doomsday/client/include/game.h
Expand Up @@ -46,7 +46,7 @@ struct gamedef_s;
namespace de {

class File1;
class Manifest;
class ResourceManifest;
class Games;

/**
Expand All @@ -58,7 +58,7 @@ class Games;
class Game
{
public:
typedef QMultiMap<resourceclassid_t, Manifest *> Manifests;
typedef QMultiMap<resourceclassid_t, ResourceManifest *> Manifests;

public:
/**
Expand Down Expand Up @@ -112,7 +112,7 @@ class Game
*
* @param manifest Manifest to add.
*/
Game &addManifest(Manifest &manifest);
Game &addManifest(ResourceManifest &manifest);

bool allStartupFilesFound() const;

Expand Down
20 changes: 13 additions & 7 deletions doomsday/client/src/audio/s_cache.cpp
Expand Up @@ -551,15 +551,21 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
*/
if(info->lumpNum < 0 || !F_LumpIsCustom(info->lumpNum))
{
de::Uri searchPath(info->lumpName, RC_SOUND);
AutoStr *foundPath = AutoStr_NewStd();

if(F_FindPath(RC_SOUND, reinterpret_cast<uri_s *>(&searchPath), foundPath) &&
(data = WAV_Load(Str_Text(foundPath), &bytesPer, &rate, &numSamples)))
try
{
// Loading was successful.
bytesPer /= 8; // Was returned as bits.
String foundPath = App_FileSystem()->findPath(de::Uri(info->lumpName, RC_SOUND),
RLF_DEFAULT, DD_ResourceClassById(RC_SOUND));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.

data = WAV_Load(foundPath.toUtf8().constData(), &bytesPer, &rate, &numSamples);
if(data)
{
// Loading was successful.
bytesPer /= 8; // Was returned as bits.
}
}
catch(FS1::NotFoundError const&)
{} // Ignore this error.
}
}

Expand Down
52 changes: 32 additions & 20 deletions doomsday/client/src/audio/s_mus.cpp
Expand Up @@ -20,9 +20,9 @@
* 02110-1301 USA</small>
*/

//#if WIN32
//# include <math.h> // for sqrt() ?
//#endif
#ifdef __SERVER__
# error "audio" is not available in a SERVER build
#endif

#include "de_base.h"
#include "de_console.h"
Expand All @@ -34,9 +34,7 @@
#include "audio/sys_audio.h"
#include "audio/m_mus2midi.h"

#ifdef __SERVER__
# error "audio" is not available in a SERVER build
#endif
using namespace de;

D_CMD(PlayMusic);
D_CMD(PauseMusic);
Expand Down Expand Up @@ -227,40 +225,54 @@ boolean Mus_IsMUSLump(lumpnum_t lumpNum)
*
* @return Non-zero if an external file of that name exists.
*/
int Mus_GetExt(ded_music_t* def, ddstring_t* retPath)
int Mus_GetExt(ded_music_t *def, ddstring_t *retPath)
{
Uri* searchPath;
int result;
LOG_AS("Mus_GetExt");

if(!musAvail || !AudioDriver_Music_Available()) return false;

// All external music files are specified relative to the base path.
if(def->path && !Str_IsEmpty(Uri_Path(def->path)))
{
AutoStr* path;
AutoStr* fullPath = AutoStr_NewStd();
// All external music files are specified relative to the base path.
AutoStr *fullPath = AutoStr_NewStd();
F_PrependBasePath(fullPath, Uri_Path(def->path));

if(F_Access(Str_Text(fullPath)))
{
if(retPath) Str_Set(retPath, Str_Text(fullPath));
return true;
}

path = Uri_ToString(def->path);
Con_Message("Warning \"%s\" for id '%s' not found.\n", Str_Text(path), def->id);
LOG_WARNING("Music file \"%s\" not found (id '%s').")
<< *reinterpret_cast<de::Uri *>(def->path) << def->id;
}

// Try the resource locator.
searchPath = Uri_NewWithPath2(def->lumpName, RC_MUSIC);
result = F_FindPath(RC_MUSIC, searchPath, retPath);
Uri_Delete(searchPath);
return result;
// Try the resource locator?
if(def->lumpName[0])
{
try
{
String foundPath = App_FileSystem()->findPath(de::Uri(def->lumpName, RC_MUSIC), RLF_DEFAULT,
DD_ResourceClassById(RC_MUSIC));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.

// Does the caller want to know the matched path?
if(retPath)
{
Str_Set(retPath, foundPath.toUtf8().constData());
}
return true;
}
catch(FS1::NotFoundError const&)
{} // Ignore this error.
}
return false;
}

/**
* @return The track number if successful else zero.
*/
int Mus_GetCD(ded_music_t* def)
int Mus_GetCD(ded_music_t *def)
{
if(!musAvail || !AudioDriver_CD() || !def)
return 0;
Expand Down

0 comments on commit 35266a8

Please sign in to comment.