vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
resource.h
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <string>
6
7#include <nlohmann/json_fwd.hpp>
8
9namespace Vkm::Engine {
10
17class Resource {
18 public:
19 // Out of line: destroying and cloning the source needs the full json type.
20 Resource();
21 ~Resource();
22
31 Resource(const Resource& other);
32 // Deleted: it would drop the uid and version. Replace contents through the manager -
33 // add() under a taken name, or swapValue.
34 Resource& operator=(const Resource& other) = delete;
35
36 Resource(Resource && other) noexcept;
37 Resource& operator=(Resource && other) noexcept;
38
39 public:
41 const std::string& name() const noexcept { return m_name; }
42
44 uint64_t uid() const noexcept { return m_uid; }
45
47 uint64_t version() const noexcept { return m_version; }
48
50 bool isHidden() const noexcept { return m_hidden; }
51
52 bool hasSource() const noexcept { return m_source != nullptr; }
53
61 nlohmann::json& sourceJson();
62
68 const nlohmann::json& sourceJson() const;
69
70 private:
71 friend class ResourceManager;
72
73 private:
74 uint64_t m_version = 1;
75 uint64_t m_uid = 0;
76 std::string m_name;
77 bool m_hidden = false;
78
80 std::unique_ptr<nlohmann::json> m_source;
81};
82
83} // namespace Vkm::Engine
uint64_t uid() const noexcept
Process-unique id stamped by add(); names the asset, not the slot it sits in.
Definition resource.h:44
const std::string & name() const noexcept
Serializable identity; non-empty and unique within its type once added.
Definition resource.h:41
Resource(const Resource &other)
Duplicate other's contents and name, but not its identity.
nlohmann::json & sourceJson()
Mutable source JSON, allocating a null document if there is none.
uint64_t version() const noexcept
Change counter the backend keys GPU re-uploads on; moved by commit().
Definition resource.h:47
const nlohmann::json & sourceJson() const
Const source JSON; asserts hasSource(), so guard the call with it.
bool isHidden() const noexcept
Added by ResourceManager::addPrivate: not user-facing, not saved.
Definition resource.h:50