Loading...
Searching...
No Matches
VirtualFileSystem.hpp
#pragma once
#include <EASTL/string.h>
#include <EASTL/unordered_map.h>
#include <EASTL/vector.h>
#define JSON_NOEXCEPTION
#include "nlohmann/json.hpp"
#include "Stream/FileInputStream.hpp"
namespace mce::io {
using stream::FileInputStream;
class VirtualFileSystem {
public:
~VirtualFileSystem();
enum FileBinaryType : unsigned char {
NONE = 0,
ASSETS_FILE = 1,
SOURCE_FILE = 2,
WORLD_FILE = 4
};
union Version {
static Version makeVersion(unsigned char major, unsigned char minor, unsigned char patch);
struct {
unsigned char major, minor, patch;
};
unsigned int quad;
};
struct Config {
bool useStreamInput = false;
FileBinaryType fileType = FileBinaryType::NONE;
Version version = { 0 };
};
Config& getConfig();
bool getFile(const eastl::string_view& fileTag, eastl::vector<char>& bytes);
bool buildJSONMappingFile(const std::string& fileInName, const std::string& fileOutName);
bool loadFile(const std::string& fileName);
private:
#ifdef _DEBUG
bool loadJSONMappingFile(const std::string& fileName);
#else
bool loadVirtualFileSystem(const std::string& fileName);
#endif
struct File {
std::string path;
size_t start, end;
size_t size;
};
eastl::unordered_map<eastl::string, File> files;
Config cfg;
#ifdef _DEBUG
nlohmann::json data;
#else
FileInputStream fileInStream;
char* binary;
#endif
};
}
mce::io::FileInputStream
Definition FileInputStream.hpp:17
mce::io::VirtualFileSystem
VirtualFileSystem manages a collection of files referenced by tags.
Definition VirtualFileSystem.hpp:18
mce::io::VirtualFileSystem::getFile
bool getFile(const eastl::string_view &fileTag, eastl::vector< char > &bytes)
Retrieve a file's bytes identified by its tag.
Definition VirtualFileSystem.cpp:109
mce::io::VirtualFileSystem::loadFile
bool loadFile(const std::string &fileName)
Load the virtual file system from a file.
Definition VirtualFileSystem.cpp:301
mce::io::VirtualFileSystem::FileBinaryType
FileBinaryType
Types of virtual file collections that can be stored in a VFS file.
Definition VirtualFileSystem.hpp:24
mce::io::VirtualFileSystem::ASSETS_FILE
@ ASSETS_FILE
Definition VirtualFileSystem.hpp:26
mce::io::VirtualFileSystem::WORLD_FILE
@ WORLD_FILE
Definition VirtualFileSystem.hpp:28
mce::io::VirtualFileSystem::NONE
@ NONE
Definition VirtualFileSystem.hpp:25
mce::io::VirtualFileSystem::SOURCE_FILE
@ SOURCE_FILE
Definition VirtualFileSystem.hpp:27
mce::io::VirtualFileSystem::getConfig
Config & getConfig()
Access the runtime configuration.
Definition VirtualFileSystem.cpp:90
mce::io::VirtualFileSystem::buildJSONMappingFile
bool buildJSONMappingFile(const std::string &fileInName, const std::string &fileOutName)
Build a binary VFS file from a JSON mapping.
Definition VirtualFileSystem.cpp:185
mce::io::stream::FileInputStream
Definition FileInputStream.hpp:17
mce::io::VirtualFileSystem::Config
Configuration for how the VirtualFileSystem should operate.
Definition VirtualFileSystem.hpp:57
mce::io::VirtualFileSystem::Config::version
Version version
Definition VirtualFileSystem.hpp:60
mce::io::VirtualFileSystem::Config::useStreamInput
bool useStreamInput
Definition VirtualFileSystem.hpp:58
mce::io::VirtualFileSystem::Config::fileType
FileBinaryType fileType
Definition VirtualFileSystem.hpp:59
mce::io::VirtualFileSystem::Version
Version information for the virtual file system format.
Definition VirtualFileSystem.hpp:37
mce::io::VirtualFileSystem::Version::patch
unsigned char patch
Definition VirtualFileSystem.hpp:48
mce::io::VirtualFileSystem::Version::quad
unsigned int quad
Definition VirtualFileSystem.hpp:51
mce::io::VirtualFileSystem::Version::makeVersion
static Version makeVersion(unsigned char major, unsigned char minor, unsigned char patch)
Create a Version from components.
Definition VirtualFileSystem.cpp:38