Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
filesystem.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/core/asset-loader.h"
6
7#include <cstdint>
8#include <filesystem>
9#include <optional>
10#include <string>
11#include <utility>
12#include <vector>
13
14namespace Flint {
15
31 class FileSystem final : public IAssetLoader {
32 public:
39 explicit FileSystem(std::filesystem::path root)
40 : m_root(std::move(root)) {
41 }
42
53 std::vector<char> getAsset(const std::string &path) override;
54
65 uint64_t getAssetRevision(const std::string &path) const override;
66
73 bool hasAsset(const std::string &path) const override;
74
80 bool isDoneLoading() const override {
81 return true;
82 }
83
84 private:
97 std::optional<std::filesystem::path> tryResolvePath(const std::string &path) const;
98
109 std::filesystem::path resolvePath(const std::string &path) const;
110
112 std::filesystem::path m_root;
113 };
114
115}
uint64_t getAssetRevision(const std::string &path) const override
Return the file's last-write-time tick count as a revision.
bool hasAsset(const std::string &path) const override
Check whether a regular file exists at path.
bool isDoneLoading() const override
Always true; FileSystem is synchronous with no background loading phase.
Definition filesystem.h:80
FileSystem(std::filesystem::path root)
Construct a FileSystem rooted at root.
Definition filesystem.h:39
std::vector< char > getAsset(const std::string &path) override
Read the entire file at path and return its bytes.
Disk-backed implementation of IAssetLoader.
Definition filesystem.h:31
Abstract interface for loading raw asset data by path.