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/api.h"
6#include "flint/core/asset-loader.h"
7
8#include <cstdint>
9#include <filesystem>
10#include <optional>
11#include <string>
12#include <utility>
13#include <vector>
14
15namespace Flint {
16
32 class FileSystem final : public IAssetLoader {
33 public:
40 explicit FileSystem(std::filesystem::path root)
41 : m_root(std::move(root)) {
42 }
43
54 FLINT_API std::vector<char> getAsset(const std::string &path) override;
55
66 FLINT_API uint64_t getAssetRevision(const std::string &path) const override;
67
74 FLINT_API bool hasAsset(const std::string &path) const override;
75
81 bool isDoneLoading() const override {
82 return true;
83 }
84
85 private:
98 std::optional<std::filesystem::path> tryResolvePath(const std::string &path) const;
99
110 std::filesystem::path resolvePath(const std::string &path) const;
111
113 std::filesystem::path m_root;
114 };
115
116}
Disk-backed implementation of IAssetLoader.
Definition filesystem.h:32
FLINT_API std::vector< char > getAsset(const std::string &path) override
Read the entire file at path and return its bytes.
bool isDoneLoading() const override
Always true; FileSystem is synchronous with no background loading phase.
Definition filesystem.h:81
FileSystem(std::filesystem::path root)
Construct a FileSystem rooted at root.
Definition filesystem.h:40
FLINT_API bool hasAsset(const std::string &path) const override
Check whether a regular file exists at path.
FLINT_API uint64_t getAssetRevision(const std::string &path) const override
Return the file's last-write-time tick count as a revision.
Abstract interface for loading raw asset data by path.