Skip to content

Commit

Permalink
WIP commit (partially functional), replacing the Game preference page…
Browse files Browse the repository at this point in the history
… with the GameSetupDialog.

Moving VirtualFileSystem classes into vfs namespace.
Adjust VirtualFileSystem interface to take all necessary arguments in its initialise() call, instead of pulling it from the GameManager itself.
Introduced GameConfiguration class and refactored lots of GameManager stuff, trying to simplify the logic.
  • Loading branch information
codereader committed Dec 3, 2017
1 parent cb8a754 commit e6eeeda
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 420 deletions.
89 changes: 59 additions & 30 deletions include/ifilesystem.h
Expand Up @@ -8,7 +8,10 @@

#include <cstddef>
#include <string>
#include <list>
#include <set>
#include <functional>
#include <algorithm>

#include "imodule.h"

Expand All @@ -18,9 +21,25 @@ class ArchiveTextFile;
typedef std::shared_ptr<ArchiveTextFile> ArchiveTextFilePtr;
class Archive;

class ModuleObserver;
namespace vfs
{

const std::string MODULE_VIRTUALFILESYSTEM("VirtualFileSystem");
// Extension of std::list to check for existing paths before inserting new ones
class SearchPaths :
public std::list<std::string>
{
public:
bool insertIfNotExists(const std::string& path)
{
if (std::find(begin(), end(), path) != end())
{
return false;
}

push_back(path);
return true;
}
};

/**
* Main interface for the virtual filesystem.
Expand All @@ -36,20 +55,22 @@ class VirtualFileSystem :
public RegisterableModule
{
public:
virtual ~VirtualFileSystem() {}

// Functor taking the filename as argument. The filename is relative
// to the base path passed to the GlobalFileSystem().foreach*() method.
typedef std::function<void (const std::string& filename)> VisitorFunc;
// to the base path passed to the GlobalFileSystem().foreach*() method.
typedef std::function<void(const std::string& filename)> VisitorFunc;

/**
* Interface for VFS observers.
*
* A VFS observer is automatically notified of events relating to the
* VFS, including startup and shutdown.
*/
class Observer {
class Observer
{
public:
virtual ~Observer() {}
virtual ~Observer() {}

/**
* Notification of VFS initialisation.
Expand All @@ -72,9 +93,10 @@ class VirtualFileSystem :
/// Called before \c initialise.
virtual void initDirectory(const std::string& path) = 0;

/// \brief Initialises the filesystem.
/// Called after all root search paths have been added.
virtual void initialise() = 0;
typedef std::set<std::string> ExtensionSet;

// Initialises the filesystem using the given search order.
virtual void initialise(const SearchPaths& vfsSearchPaths, const ExtensionSet& allowedArchiveExtensions) = 0;

/// \brief Shuts down the filesystem.
virtual void shutdown() = 0;
Expand All @@ -90,45 +112,52 @@ class VirtualFileSystem :
// greebo: Note: expects the filename to be normalised (forward slashes, trailing slash).
virtual ArchiveFilePtr openFile(const std::string& filename) = 0;

/// \brief Returns the file identified by \p filename opened in binary mode, or 0 if not found.
// This is a variant of openFile taking an absolute path as argument.
virtual ArchiveFilePtr openFileInAbsolutePath(const std::string& filename) = 0;
/// \brief Returns the file identified by \p filename opened in binary mode, or 0 if not found.
// This is a variant of openFile taking an absolute path as argument.
virtual ArchiveFilePtr openFileInAbsolutePath(const std::string& filename) = 0;

/// \brief Returns the file identified by \p filename opened in text mode, or 0 if not found.
virtual ArchiveTextFilePtr openTextFile(const std::string& filename) = 0;

/// \brief Returns the file identified by \p filename opened in text mode, or NULL if not found.
/// This is a variant of openTextFile taking an absolute path as argument.
virtual ArchiveTextFilePtr openTextFileInAbsolutePath(const std::string& filename) = 0;
/// \brief Returns the file identified by \p filename opened in text mode, or NULL if not found.
/// This is a variant of openTextFile taking an absolute path as argument.
virtual ArchiveTextFilePtr openTextFileInAbsolutePath(const std::string& filename) = 0;

/// \brief Calls the visitor function for each file under \p basedir matching \p extension.
/// Use "*" as \p extension to match all file extensions.
virtual void forEachFile(const std::string& basedir,
const std::string& extension,
const VisitorFunc& visitorFunc,
std::size_t depth = 1) = 0;

// Similar to forEachFile, this routine traverses an absolute path
// searching for files matching a certain extension and invoking
// the givne visitor functor on each occurrence.
virtual void forEachFileInAbsolutePath(const std::string& path,
const std::string& extension,
const VisitorFunc& visitorFunc,
std::size_t depth = 1) = 0;
virtual void forEachFile(const std::string& basedir,
const std::string& extension,
const VisitorFunc& visitorFunc,
std::size_t depth = 1) = 0;

// Similar to forEachFile, this routine traverses an absolute path
// searching for files matching a certain extension and invoking
// the givne visitor functor on each occurrence.
virtual void forEachFileInAbsolutePath(const std::string& path,
const std::string& extension,
const VisitorFunc& visitorFunc,
std::size_t depth = 1) = 0;

/// \brief Returns the absolute filename for a relative \p name, or "" if not found.
virtual std::string findFile(const std::string& name) = 0;

/// \brief Returns the filesystem root for an absolute \p name, or "" if not found.
/// This can be used to convert an absolute name to a relative name.
virtual std::string findRoot(const std::string& name) = 0;

// Returns the list of registered VFS paths, ordered by search priority
virtual const SearchPaths& getVfsSearchPaths() = 0;
};

inline VirtualFileSystem& GlobalFileSystem()
}

const char* const MODULE_VIRTUALFILESYSTEM("VirtualFileSystem");

inline vfs::VirtualFileSystem& GlobalFileSystem()
{
// Cache the reference locally
static VirtualFileSystem& _vfs(
*std::static_pointer_cast<VirtualFileSystem>(
static vfs::VirtualFileSystem& _vfs(
*std::static_pointer_cast<vfs::VirtualFileSystem>(
module::GlobalModuleRegistry().getModule(MODULE_VIRTUALFILESYSTEM)
)
);
Expand Down
8 changes: 5 additions & 3 deletions libs/os/path.h
Expand Up @@ -89,13 +89,15 @@ namespace os
}

/** greebo: OS Folder names have forward slashes and a trailing slash
* at the end by convention.
* at the end by convention. Empty strings are returned unchanged.
*/
inline std::string standardPathWithSlash(const std::string& input) {
inline std::string standardPathWithSlash(const std::string& input)
{
std::string output = standardPath(input);

// Append a slash at the end, if there isn't already one
if (!string::ends_with(output, "/")) {
if (!output.empty() && !string::ends_with(output, "/"))
{
output += "/";
}
return output;
Expand Down
2 changes: 1 addition & 1 deletion plugins/eclassmgr/EClassManager.h
Expand Up @@ -32,7 +32,7 @@ namespace eclass
*/
class EClassManager :
public IEntityClassManager,
public VirtualFileSystem::Observer
public vfs::VirtualFileSystem::Observer
{
// Whether the entity classes have been realised
bool _realised;
Expand Down
6 changes: 3 additions & 3 deletions plugins/shaders/Doom3ShaderSystem.h
Expand Up @@ -21,9 +21,9 @@ namespace shaders
* \brief
* Implementation of the MaterialManager for Doom 3 .
*/
class Doom3ShaderSystem
: public MaterialManager,
public VirtualFileSystem::Observer
class Doom3ShaderSystem :
public MaterialManager,
public vfs::VirtualFileSystem::Observer
{
// The shaderlibrary stores all the known shaderdefinitions
// as well as the active shaders
Expand Down

0 comments on commit e6eeeda

Please sign in to comment.