Skip to content

Commit

Permalink
Refactor|Filesys: Minor cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 21, 2012
1 parent cc7dcd5 commit 1cf00af
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 62 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/api/dd_share.h
Expand Up @@ -1727,7 +1727,7 @@ typedef struct serverinfo_s {
char gameConfig[40];
char map[20];
char clientNames[128];
unsigned int wadNumber;
unsigned int loadedFilesCRC;
char iwad[32]; ///< Obsolete.
char pwads[128];
int data[3];
Expand Down
66 changes: 31 additions & 35 deletions doomsday/engine/include/filesys/fs_main.h
Expand Up @@ -272,19 +272,18 @@ namespace de
/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();

/**
* @post No more WADs will be loaded in startup mode.
*/
void endStartup();

/**
* @param name Unique symbolic name of this namespace. Must be at least
* @c Namespace::min_name_length characters long.
* @param flags @ref Namespace::Flag
*/
Namespace& createNamespace(String name, Namespace::Flags flags = 0);

/**
* Reset all the namespaces, returning them to an empty state and clearing
* any @ref ExtraPaths which have been registered since construction.
*/
void resetAllNamespaces();

/**
* Lookup a Namespace by symbolic name.
*
Expand All @@ -293,13 +292,14 @@ namespace de
*/
Namespace* namespaceByName(String name);

/// Returns the namespaces for efficient traversal.
Namespaces const& namespaces();

/**
* @post No more WADs will be loaded in startup mode.
* Reset all the namespaces, returning them to an empty state and clearing
* any @ref ExtraPaths which have been registered since construction.
*/
void endStartup();
void resetAllNamespaces();

/// Returns the namespaces for efficient traversal.
Namespaces const& namespaces();

/**
* Add a new path mapping from source to destination in the vfs.
Expand All @@ -309,10 +309,8 @@ namespace de

/**
* Clears all virtual path mappings.
*
* @return This instance.
*/
FS1& clearPathMappings();
void clearPathMappings();

/**
* Add a new lump mapping so that @a lumpName becomes visible at @a destination.
Expand All @@ -324,13 +322,12 @@ namespace de
*
* @return This instance.
*/
FS1& clearPathLumpMappings();
void clearPathLumpMappings();

/**
* Reset known fileId records so that the next time checkFileId() is called for
* a filepath, it will pass.
* @return @c true if a file exists at @a path which can be opened for reading.
*/
void resetFileIds();
bool accessFile(Uri const& path);

/**
* Maintains a list of identifiers already seen.
Expand All @@ -341,26 +338,28 @@ namespace de
bool checkFileId(Uri const& path);

/**
* @return @c true if a file exists at @a path which can be opened for reading.
* Reset known fileId records so that the next time checkFileId() is called for
* a filepath, it will pass.
*/
bool accessFile(Uri const& path);
void resetFileIds();

/**
* Indexes @a file (which must have been opened with this file system) into
* this file system and adds it to the list of loaded files.
*
* @param file The file to index. Assumed to have not yet been indexed!
*
* @return This instance.
*/
FS1& index(File1& file);
void index(File1& file);

/**
* Removes a file from any lump indexes.
*
* @param file File to remove from the index.
*/
FS1& deindex(File1& file);
void deindex(File1& file);

/// Clear all references to this file.
void releaseFile(File1& file);

/**
* Lookup a lump by name.
Expand Down Expand Up @@ -425,9 +424,6 @@ namespace de
*/
FileHandle& openLump(File1& lump);

/// Clear all references to this file.
void releaseFile(File1& file);

/**
* Find a single file.
*
Expand Down Expand Up @@ -529,11 +525,6 @@ namespace de
*/
void printDirectory(String path);

/**
* Calculate a CRC for the loaded file list.
*/
uint loadedFilesCRC();

/**
* Try to open the specified WAD archive into the auxiliary lump index.
*
Expand All @@ -546,11 +537,16 @@ namespace de
*/
void closeAuxiliaryPrimaryIndex();

/**
* Calculate a CRC for the loaded file list.
*/
uint loadedFilesCRC();

/**
* Unload all files loaded after startup.
* @return Number of files unloaded.
*/
FS1& unloadAllNonStartupFiles(int* numUnloaded = 0);
int unloadAllNonStartupFiles();

private:
struct Instance;
Expand Down Expand Up @@ -599,7 +595,7 @@ void F_Shutdown(void);

void F_EndStartup(void);

void F_UnloadAllNonStartupFiles(int* numUnloaded);
int F_UnloadAllNonStartupFiles();

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

Expand Down Expand Up @@ -663,7 +659,7 @@ void F_UnlockLump(struct file1_s* file, int lumpIdx);
*/
void F_ComposePWADFileList(char* outBuf, size_t outBufSize, const char* delimiter);

uint F_CRCNumber(void);
uint F_LoadedFilesCRC(void);

lumpnum_t F_OpenAuxiliary2(char const* nativePath, size_t baseOffset);
lumpnum_t F_OpenAuxiliary(char const* nativePath/*, baseOffset = 0 */);
Expand Down
35 changes: 17 additions & 18 deletions doomsday/engine/src/filesys/fs_main.cpp
Expand Up @@ -460,7 +460,13 @@ FS1::~FS1()
FS1::Namespace& FS1::createNamespace(String name, Namespace::Flags flags)
{
DENG_ASSERT(name.length() >= Namespace::min_name_length);
Namespace* fnamespace = new Namespace(name, flags);

// Ensure this is a unique name.
Namespace* fnamespace = namespaceByName(name);
if(fnamespace) return *fnamespace;

// Create a new namespace.
fnamespace = new Namespace(name, flags);
d->namespaces.insert(name.toLower(), fnamespace);
return *fnamespace;
}
Expand Down Expand Up @@ -518,7 +524,7 @@ static FS1::FileList::iterator findListFileByPath(FS1::FileList& list, String pa
return i;
}

FS1& FS1::index(de::File1& file)
void FS1::index(de::File1& file)
{
#ifdef DENG_DEBUG
// Ensure this hasn't yet been indexed.
Expand Down Expand Up @@ -560,14 +566,12 @@ FS1& FS1::index(de::File1& file)
// Add a handle to the loaded files list.
FileHandle* loadedFilesHndl = FileHandleBuilder::fromFile(file);
d->loadedFiles.push_back(loadedFilesHndl); loadedFilesHndl->setList(reinterpret_cast<struct filelist_s*>(&d->loadedFiles));

return *this;
}

FS1& FS1::deindex(de::File1& file)
void FS1::deindex(de::File1& file)
{
FileList::iterator found = findListFile(d->loadedFiles, file);
if(found == d->loadedFiles.end()) return *this; // Most peculiar..
if(found == d->loadedFiles.end()) return; // Most peculiar..

QByteArray path = file.composePath().toUtf8();
d->releaseFileId(path.constData());
Expand All @@ -579,8 +583,6 @@ FS1& FS1::deindex(de::File1& file)

d->loadedFiles.erase(found);
delete *found;

return *this;
}

de::File1& FS1::find(de::Uri const& search)
Expand Down Expand Up @@ -701,7 +703,7 @@ static void printFileList(FS1::FileList& list)
}
#endif

FS1& FS1::unloadAllNonStartupFiles(int* retNumUnloaded)
int FS1::unloadAllNonStartupFiles()
{
#if _DEBUG
// List all open files with their identifiers.
Expand Down Expand Up @@ -734,8 +736,7 @@ FS1& FS1::unloadAllNonStartupFiles(int* retNumUnloaded)
}
#endif

if(retNumUnloaded) *retNumUnloaded = numUnloadedFiles;
return *this;
return numUnloadedFiles;
}

bool FS1::checkFileId(de::Uri const& path)
Expand Down Expand Up @@ -1260,10 +1261,9 @@ void FS1::mapPathToLump(String lumpName, String destination)
LOG_VERBOSE("Path \"%s\" now mapped to lump \"%s\"") << NativePath(ldm->first).pretty() << ldm->second;
}

FS1& FS1::clearPathLumpMappings()
void FS1::clearPathLumpMappings()
{
d->lumpMappings.clear();
return *this;
}

/// @return @c true iff the mapping matched the path.
Expand Down Expand Up @@ -1313,10 +1313,9 @@ void FS1::mapPath(String source, String destination)
<< NativePath(pm->second).pretty() << NativePath(pm->first).pretty();
}

FS1& FS1::clearPathMappings()
void FS1::clearPathMappings()
{
d->pathMappings.clear();
return *this;
}

void FS1::printDirectory(String path)
Expand Down Expand Up @@ -1636,9 +1635,9 @@ void F_EndStartup(void)
App_FileSystem()->endStartup();
}

void F_UnloadAllNonStartupFiles(int* numUnloaded)
int F_UnloadAllNonStartupFiles(void)
{
App_FileSystem()->unloadAllNonStartupFiles(numUnloaded);
return App_FileSystem()->unloadAllNonStartupFiles();
}

void F_AddVirtualDirectoryMapping(char const* nativeSourcePath, char const* nativeDestinationPath)
Expand Down Expand Up @@ -2027,7 +2026,7 @@ void F_ComposePWADFileList(char* outBuf, size_t outBufSize, char const* delimite
strncpy(outBuf, strUtf8.constData(), outBufSize);
}

uint F_CRCNumber(void)
uint F_LoadedFilesCRC(void)
{
return App_FileSystem()->loadedFilesCRC();
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/network/net_main.c
Expand Up @@ -888,7 +888,7 @@ void Net_PrintServerInfo(int index, serverinfo_t *info)
info->canJoin ? ' ' : '*', info->version, info->plugin,
info->address, info->port);
Con_Printf(" %s p:%ims %-40s\n", info->map, info->ping, info->description);
Con_Printf(" %s (crc:%x) %s\n", info->gameIdentityKey, info->wadNumber, info->gameConfig);
Con_Printf(" %s (crc:%x) %s\n", info->gameIdentityKey, info->loadedFilesCRC, info->gameConfig);

// Optional: PWADs in use.
if(info->pwads[0])
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/src/network/ui_mpi.c
Expand Up @@ -334,7 +334,7 @@ void MPIUpdateServerInfo(ui_object_t *ob)

sprintf(warningString,
"This server is using %x, " "but you have %x. "
"Errors may occur during game play.", info.wadNumber, myCrc);
"Errors may occur during game play.", info.loadedFilesCRC, myCrc);

// Show IWAD warning?
if(!(lst_found.count >= 1 && lst_found.selection >= 0 &&
Expand Down Expand Up @@ -469,7 +469,7 @@ void MPIUpdateServerList(void)
memset(&info, 0, sizeof(info));
N_GetHostInfo(i, &info);
MPIFormatServerInfo(lstit_found[i].text, &info);
lstit_found[i].data = info.wadNumber;
lstit_found[i].data = info.loadedFilesCRC;
lstit_found[i].data2 = i;
}
lst_found.count = num;
Expand All @@ -495,7 +495,7 @@ void MPIUpdateServerList(void)
}

MPIFormatServerInfo(lstit_found[k].text, &info);
lstit_found[k].data = info.wadNumber;
lstit_found[k].data = info.loadedFilesCRC;
// Connection will be formed using this index.
lstit_found[k].data2 = i;
k++;
Expand Down Expand Up @@ -656,7 +656,7 @@ void DD_NetSetup(int serverMode)
UI_FlagGroup(ob_client, 4, UIF_HIDDEN, searchMode == SEARCH_MASTER);
lst_found.selection = -1;
lst_found.count = 0;
myCrc = F_CRCNumber();
myCrc = F_LoadedFilesCRC();
UI_FlagGroup(ob_client, 5, UIF_DISABLED, true); // warnings
UI_FlagGroup(ob_client, UIG_CONNECT, UIF_DISABLED, true);
MPIUpdateServerList();
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/src/server/sv_main.c
Expand Up @@ -118,7 +118,7 @@ void Sv_GetInfo(serverinfo_t* info)
F_ComposePWADFileList(info->pwads, sizeof(info->pwads), ";");

// This should be a CRC number that describes all the loaded data.
info->wadNumber = F_CRCNumber();
info->loadedFilesCRC = F_LoadedFilesCRC();
}

/**
Expand All @@ -136,7 +136,7 @@ size_t Sv_InfoToString(serverinfo_t* info, ddstring_t* msg)
Str_Appendf(msg, "mode:%s\n", info->gameIdentityKey);
Str_Appendf(msg, "setup:%s\n", info->gameConfig);
Str_Appendf(msg, "iwad:%s\n", info->iwad);
Str_Appendf(msg, "wcrc:%i\n", info->wadNumber);
Str_Appendf(msg, "wcrc:%i\n", info->loadedFilesCRC);
Str_Appendf(msg, "pwads:%s\n", info->pwads);
Str_Appendf(msg, "map:%s\n", info->map);
Str_Appendf(msg, "nump:%i\n", info->numPlayers);
Expand Down Expand Up @@ -247,7 +247,7 @@ boolean Sv_StringToInfo(const char *valuePair, serverinfo_t *info)
}
else if(!strcmp(label, "wcrc"))
{
info->wadNumber = strtol(value, 0, 0);
info->loadedFilesCRC = strtol(value, 0, 0);
}
else if(!strcmp(label, "pwads"))
{
Expand Down

0 comments on commit 1cf00af

Please sign in to comment.